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