Skip to content

Commit

Permalink
StoreMerging: [NFC] Add an helper function to reorder internal data
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed Sep 27, 2023
1 parent 8d01183 commit 5895e18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/Cheerp/StoreMerging.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class StoreMerging
std::pair<const llvm::Value*, int> findBasePointerAndOffset(const llvm::Value* pointer);
std::pair<bool, int> compatibleAndOffset(const llvm::Value* currPtr, const llvm::Value* referencePtr);
static void filterAlreadyProcessedStores(std::vector<StoreAndOffset>& groupedSamePointer);
static void sortStores(std::vector<StoreAndOffset>& groupedSamePointer);
bool processBlockOfStores(std::vector<StoreAndOffset>& groupedSamePointer);
bool processBlockOfStores(const uint32_t dim, std::vector<StoreAndOffset> & groupedSamePointer);
bool runOnBasicBlock(llvm::BasicBlock& BB);
Expand Down
22 changes: 15 additions & 7 deletions llvm/lib/CheerpUtils/StoreMerging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ bool StoreMerging::runOnBasicBlock(BasicBlock& BB)
return Changed;
}

void StoreMerging::sortStores(std::vector<StoreAndOffset>& groupedSamePointer)
{
// We find candidates for merging by scanning this vector and looking
// at adjacent value. The order should be:
// 1) By size, since we can only merge stores of the same size
// 2) By offset, since we want adjacent values to be close to each other
std::sort(groupedSamePointer.begin(), groupedSamePointer.end(),
[](const StoreAndOffset& left, const StoreAndOffset& right) -> bool
{
return left.offset < right.offset;
});

}

void StoreMerging::filterAlreadyProcessedStores(std::vector<StoreAndOffset>& groupedSamePointer)
{
//Bookkeeping 3: remove the stores with size set to 0
Expand All @@ -101,13 +115,7 @@ bool StoreMerging::processBlockOfStores(std::vector<StoreAndOffset>& groupedSame
if (groupedSamePointer.size() < 2)
return false;

//Sort based on the offset
std::sort(groupedSamePointer.begin(), groupedSamePointer.end(),
[](const StoreAndOffset& left, const StoreAndOffset& right) -> bool
{
return left.offset < right.offset;
});

sortStores(groupedSamePointer);
const uint32_t N = groupedSamePointer.size();
bool overlap = false;
for (uint32_t i=0; i+1<N; i++)
Expand Down

0 comments on commit 5895e18

Please sign in to comment.