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