add dataflow solvation
This commit is contained in:
@@ -464,10 +464,12 @@ void AccessingSet::Insert(const vector<ArrayDimension>& element)
|
|||||||
allElements.insert(allElements.end(), tails.begin(), tails.end());
|
allElements.insert(allElements.end(), tails.begin(), tails.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccessingSet::Union(const AccessingSet& source) {
|
AccessingSet AccessingSet::Union(const AccessingSet& source) {
|
||||||
|
AccessingSet result;
|
||||||
for(auto& element: source.GetElements()) {
|
for(auto& element: source.GetElements()) {
|
||||||
Insert(element);
|
result.Insert(element);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessingSet AccessingSet::Intersect(const AccessingSet& secondSet) const
|
AccessingSet AccessingSet::Intersect(const AccessingSet& secondSet) const
|
||||||
@@ -506,6 +508,27 @@ AccessingSet AccessingSet::Diff(const AccessingSet& secondSet) const
|
|||||||
return uncovered;
|
return uncovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const ArrayDimension& lhs, const ArrayDimension& rhs)
|
||||||
|
{
|
||||||
|
return lhs.start == rhs.start && lhs.step == rhs.step && lhs.tripCount == rhs.tripCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool operator==(const AccessingSet& lhs, const AccessingSet& rhs)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < lhs.allElements.size(); i++)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < lhs.allElements[i].size(); j++)
|
||||||
|
{
|
||||||
|
if (lhs.allElements[i][j] != rhs.allElements[i][j])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Collapse(Region* region)
|
void Collapse(Region* region)
|
||||||
{
|
{
|
||||||
//Region* newBlock = new Region();
|
//Region* newBlock = new Region();
|
||||||
@@ -514,7 +537,7 @@ void Collapse(Region* region)
|
|||||||
for (Region* byBlock : region->getBasickBlocks())
|
for (Region* byBlock : region->getBasickBlocks())
|
||||||
{
|
{
|
||||||
AccessingSet intersection = byBlock->array_def[arrayName].Intersect(arrayRanges);
|
AccessingSet intersection = byBlock->array_def[arrayName].Intersect(arrayRanges);
|
||||||
region->array_def[arrayName].Union(intersection);
|
region->array_def[arrayName] = region->array_def[arrayName].Union(intersection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,7 +545,7 @@ void Collapse(Region* region)
|
|||||||
for (auto& [arrayName, arrayRanges] : byBlock->array_use)
|
for (auto& [arrayName, arrayRanges] : byBlock->array_use)
|
||||||
{
|
{
|
||||||
AccessingSet diff = byBlock->array_use[arrayName].Diff(byBlock->array_in[arrayName]);
|
AccessingSet diff = byBlock->array_use[arrayName].Diff(byBlock->array_in[arrayName]);
|
||||||
region->array_use[arrayName].Union(diff);
|
region->array_use[arrayName] = region->array_use[arrayName].Union(diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,6 +603,7 @@ Region::Region(LoopGraph* loop, vector<SAPFOR::BasicBlock*>& Blocks)
|
|||||||
{
|
{
|
||||||
bbToRegion[poiner] = new Region(*poiner);
|
bbToRegion[poiner] = new Region(*poiner);
|
||||||
}
|
}
|
||||||
|
this->header = bbToRegion[header];
|
||||||
SetConnections(bbToRegion, blockSet);
|
SetConnections(bbToRegion, blockSet);
|
||||||
//create subRegions
|
//create subRegions
|
||||||
for (LoopGraph* childLoop : loop->children)
|
for (LoopGraph* childLoop : loop->children)
|
||||||
@@ -588,9 +612,42 @@ Region::Region(LoopGraph* loop, vector<SAPFOR::BasicBlock*>& Blocks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SolveDataFlowIteratively(Region* DFG)
|
||||||
|
{
|
||||||
|
unordered_set<Region*> worklist(DFG->getBasickBlocks());
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Region* b = *worklist.begin();
|
||||||
|
ArrayAccessingIndexes newIn;
|
||||||
|
for (Region* prevBlock : b->getPrevRegions())
|
||||||
|
{
|
||||||
|
for (const auto& [arrayName, accessSet] : prevBlock->array_out)
|
||||||
|
{
|
||||||
|
newIn[arrayName] = newIn[arrayName].Intersect(accessSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b->array_in = newIn;
|
||||||
|
ArrayAccessingIndexes newOut;
|
||||||
|
for (auto& [arrayName, accessSet] : b->array_in)
|
||||||
|
{
|
||||||
|
newOut[arrayName] = b->array_in[arrayName].Union(b->array_def[arrayName]);
|
||||||
|
}
|
||||||
|
/* can not differ */
|
||||||
|
if (newOut != b->array_out)
|
||||||
|
{
|
||||||
|
b->array_out = newOut;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
worklist.erase(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!worklist.empty());
|
||||||
|
}
|
||||||
|
|
||||||
void SolveDataFlow(Region* DFG)
|
void SolveDataFlow(Region* DFG)
|
||||||
{
|
{
|
||||||
//SolveDataFlowIteratively(DFG)
|
SolveDataFlowIteratively(DFG);
|
||||||
for (Region* subRegion : DFG->getSubRegions())
|
for (Region* subRegion : DFG->getSubRegions())
|
||||||
{
|
{
|
||||||
SolveDataFlow(subRegion);
|
SolveDataFlow(subRegion);
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ class AccessingSet {
|
|||||||
AccessingSet() {};
|
AccessingSet() {};
|
||||||
vector<vector<ArrayDimension>> GetElements() const;
|
vector<vector<ArrayDimension>> GetElements() const;
|
||||||
void Insert(const vector<ArrayDimension>& element);
|
void Insert(const vector<ArrayDimension>& element);
|
||||||
void Union(const AccessingSet& source);
|
AccessingSet Union(const AccessingSet& source);
|
||||||
AccessingSet Intersect(const AccessingSet& secondSet) const;
|
AccessingSet Intersect(const AccessingSet& secondSet) const;
|
||||||
AccessingSet Diff(const AccessingSet& secondSet) const;
|
AccessingSet Diff(const AccessingSet& secondSet) const;
|
||||||
bool ContainsElement(const vector<ArrayDimension>& element) const;
|
bool ContainsElement(const vector<ArrayDimension>& element) const;
|
||||||
void FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
void FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
||||||
void FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
void FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const;
|
||||||
|
friend bool operator==(const AccessingSet& lhs, const AccessingSet& rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
using ArrayAccessingIndexes = map<string, AccessingSet>;
|
using ArrayAccessingIndexes = map<string, AccessingSet>;
|
||||||
|
|||||||
Reference in New Issue
Block a user