2025-03-31 02:50:30 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "../GraphLoop/graph_loops.h"
|
|
|
|
|
#include "../CFGraph/CFGraph.h"
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::map;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::set;
|
2025-04-08 15:25:39 +03:00
|
|
|
using std::unordered_set;
|
|
|
|
|
using std::pair;
|
2025-03-31 02:50:30 +03:00
|
|
|
|
|
|
|
|
struct ArrayDimension
|
|
|
|
|
{
|
|
|
|
|
uint64_t start, step, tripCount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AccessingSet {
|
|
|
|
|
private:
|
|
|
|
|
vector<vector<ArrayDimension>> allElements;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AccessingSet(vector<vector<ArrayDimension>> input) : allElements(input) {};
|
|
|
|
|
AccessingSet() {};
|
|
|
|
|
vector<vector<ArrayDimension>> GetElements() const;
|
|
|
|
|
void Insert(const vector<ArrayDimension>& element);
|
2025-04-29 17:55:51 +03:00
|
|
|
AccessingSet Union(const AccessingSet& source);
|
2025-03-31 02:50:30 +03:00
|
|
|
AccessingSet Intersect(const AccessingSet& secondSet) const;
|
|
|
|
|
AccessingSet Diff(const AccessingSet& secondSet) const;
|
|
|
|
|
bool ContainsElement(const vector<ArrayDimension>& element) const;
|
|
|
|
|
void FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
|
|
|
|
void FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
2025-05-05 21:53:34 +03:00
|
|
|
friend bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs);
|
2025-03-31 02:50:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using ArrayAccessingIndexes = map<string, AccessingSet>;
|
|
|
|
|
|
|
|
|
|
class Region: public SAPFOR::BasicBlock {
|
|
|
|
|
public:
|
|
|
|
|
Region()
|
|
|
|
|
{
|
2025-04-08 15:25:39 +03:00
|
|
|
header = nullptr;
|
2025-03-31 02:50:30 +03:00
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
2025-03-31 02:50:30 +03:00
|
|
|
Region(SAPFOR::BasicBlock block) : SAPFOR::BasicBlock::BasicBlock(block)
|
|
|
|
|
{
|
|
|
|
|
header = nullptr;
|
2025-04-08 15:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Region(LoopGraph* loop, vector<SAPFOR::BasicBlock*>& Blocks);
|
|
|
|
|
|
|
|
|
|
Region* getHeader()
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
|
|
|
|
return header;
|
|
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
unordered_set<Region*>& getBasickBlocks()
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
|
|
|
|
return basickBlocks;
|
|
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
void addBasickBlocks(Region* region)
|
|
|
|
|
{
|
|
|
|
|
basickBlocks.insert(region);
|
|
|
|
|
}
|
|
|
|
|
unordered_set<Region*> getPrevRegions()
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
|
|
|
|
return prevRegions;
|
|
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
unordered_set<Region*> getNextRegions()
|
|
|
|
|
{
|
|
|
|
|
return nextRegions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addPrevRegion(Region* region)
|
|
|
|
|
{
|
|
|
|
|
prevRegions.insert(region);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addNextRegion(Region* region)
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
2025-04-08 15:25:39 +03:00
|
|
|
nextRegions.insert(region);
|
2025-03-31 02:50:30 +03:00
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
void replaceInPrevRegions(Region* source, Region* destination)
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
2025-04-08 15:25:39 +03:00
|
|
|
prevRegions.erase(destination);
|
|
|
|
|
prevRegions.insert(source);
|
2025-03-31 02:50:30 +03:00
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
void replaceInNextRegions(Region* source, Region* destination)
|
2025-03-31 02:50:30 +03:00
|
|
|
{
|
2025-04-08 15:25:39 +03:00
|
|
|
nextRegions.erase(destination);
|
|
|
|
|
nextRegions.insert(source);
|
2025-03-31 02:50:30 +03:00
|
|
|
}
|
2025-04-08 15:25:39 +03:00
|
|
|
|
|
|
|
|
unordered_set<Region*> getSubRegions()
|
|
|
|
|
{
|
|
|
|
|
return subRegions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addSubRegions(Region* region)
|
|
|
|
|
{
|
|
|
|
|
subRegions.insert(region);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 02:50:30 +03:00
|
|
|
ArrayAccessingIndexes array_def, array_use, array_out, array_in;
|
2025-04-08 15:25:39 +03:00
|
|
|
|
2025-03-31 02:50:30 +03:00
|
|
|
private:
|
2025-04-08 15:25:39 +03:00
|
|
|
unordered_set<Region*> subRegions, basickBlocks;
|
|
|
|
|
/*next Region which is BB for current BB Region*/
|
|
|
|
|
unordered_set<Region*> nextRegions;
|
|
|
|
|
/*prev Regions which is BBs for current BB Region*/
|
|
|
|
|
unordered_set<Region*> prevRegions;
|
|
|
|
|
Region* header;
|
2025-03-31 02:50:30 +03:00
|
|
|
};
|
|
|
|
|
|
2025-04-08 15:25:39 +03:00
|
|
|
|
2025-03-31 02:50:30 +03:00
|
|
|
void Collapse(Region* region);
|
|
|
|
|
void FindPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR);
|
|
|
|
|
void GetDimensionInfo(LoopGraph* loop, map<DIST::Array*, vector<vector<ArrayDimension>>>& loopDimensionsInfo, int level);
|
2025-04-08 15:25:39 +03:00
|
|
|
pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(LoopGraph* loop, vector<SAPFOR::BasicBlock*> blocks);
|