Files
SAPFOR/src/PrivateAnalyzer/private_arrays_search.h

122 lines
3.7 KiB
C
Raw Normal View History

2025-03-31 02:50:30 +03:00
#pragma once
2025-05-19 20:50:35 +03:00
#include<vector>
#include<map>
#include<unordered_set>
2025-03-31 02:50:30 +03:00
#include "../GraphLoop/graph_loops.h"
#include "../CFGraph/CFGraph.h"
struct ArrayDimension
{
uint64_t start, step, tripCount;
};
class AccessingSet {
private:
2025-05-19 20:50:35 +03:00
std::vector<std::vector<ArrayDimension>> allElements;
2025-03-31 02:50:30 +03:00
public:
2025-05-19 20:50:35 +03:00
AccessingSet(std::vector<std::vector<ArrayDimension>> input) : allElements(input) {};
2025-03-31 02:50:30 +03:00
AccessingSet() {};
2025-05-19 20:50:35 +03:00
std::vector<std::vector<ArrayDimension>> GetElements() const;
void Insert(const std::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;
2025-05-19 20:50:35 +03:00
bool ContainsElement(const std::vector<ArrayDimension>& element) const;
void FindCoveredBy(const std::vector<ArrayDimension>& element, std::vector<std::vector<ArrayDimension>>& result) const;
void FindUncovered(const std::vector<ArrayDimension>& element, std::vector<std::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
};
2025-05-19 20:50:35 +03:00
using ArrayAccessingIndexes = std::map<std::string, AccessingSet>;
2025-03-31 02:50:30 +03:00
class Region: public SAPFOR::BasicBlock {
public:
Region()
{
header = nullptr;
2025-03-31 02:50:30 +03:00
}
2025-03-31 02:50:30 +03:00
Region(SAPFOR::BasicBlock block) : SAPFOR::BasicBlock::BasicBlock(block)
{
header = nullptr;
}
2025-05-19 20:50:35 +03:00
Region(LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*>& Blocks);
Region* getHeader()
2025-03-31 02:50:30 +03:00
{
return header;
}
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*>& getBasickBlocks()
2025-03-31 02:50:30 +03:00
{
return basickBlocks;
}
void addBasickBlocks(Region* region)
{
basickBlocks.insert(region);
}
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*> getPrevRegions()
2025-03-31 02:50:30 +03:00
{
return prevRegions;
}
2025-05-19 20:50:35 +03:00
std::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
{
nextRegions.insert(region);
2025-03-31 02:50:30 +03:00
}
void replaceInPrevRegions(Region* source, Region* destination)
2025-03-31 02:50:30 +03:00
{
prevRegions.erase(destination);
prevRegions.insert(source);
2025-03-31 02:50:30 +03:00
}
void replaceInNextRegions(Region* source, Region* destination)
2025-03-31 02:50:30 +03:00
{
nextRegions.erase(destination);
nextRegions.insert(source);
2025-03-31 02:50:30 +03:00
}
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*> getSubRegions()
{
return subRegions;
}
void addSubRegions(Region* region)
{
subRegions.insert(region);
}
2025-05-19 20:50:35 +03:00
ArrayAccessingIndexes array_def, array_use, array_out, array_in, array_priv;
2025-03-31 02:50:30 +03:00
private:
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*> subRegions, basickBlocks;
/*next Region which is BB for current BB Region*/
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*> nextRegions;
/*prev Regions which is BBs for current BB Region*/
2025-05-19 20:50:35 +03:00
std::unordered_set<Region*> prevRegions;
Region* header;
2025-03-31 02:50:30 +03:00
};
2025-03-31 02:50:30 +03:00
void Collapse(Region* region);
2025-05-19 20:50:35 +03:00
std::map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
void GetDimensionInfo(LoopGraph* loop, std::map<DIST::Array*, std::vector<std::vector<ArrayDimension>>>& loopDimensionsInfo, int level);
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);