fixed code style

This commit is contained in:
ALEXks
2025-05-30 12:45:05 +03:00
parent 8dcbd587ec
commit 26e36bed46
6 changed files with 86 additions and 158 deletions

View File

@@ -39,25 +39,17 @@ void Collapse(Region* region)
} }
ArrayAccessingIndexes useUnion; ArrayAccessingIndexes useUnion;
for (auto& byBlock : region->getBasickBlocks()) for (auto& byBlock : region->getBasickBlocks())
{
for (auto& [arrayName, arrayRanges] : byBlock->array_use) for (auto& [arrayName, arrayRanges] : byBlock->array_use)
{
useUnion[arrayName] = useUnion[arrayName].Union(byBlock->array_use[arrayName]); useUnion[arrayName] = useUnion[arrayName].Union(byBlock->array_use[arrayName]);
}
}
for (auto& [arrayName, arrayRanges] : useUnion) for (auto& [arrayName, arrayRanges] : useUnion)
{
region->array_priv[arrayName] = useUnion[arrayName].Diff(region->array_use[arrayName]); region->array_priv[arrayName] = useUnion[arrayName].Diff(region->array_use[arrayName]);
}
for (Region* prevBlock : region->getHeader()->getPrevRegions()) for (Region* prevBlock : region->getHeader()->getPrevRegions())
{
prevBlock->replaceInNextRegions(region, region->getHeader()); prevBlock->replaceInNextRegions(region, region->getHeader());
}
for (Region* nextBlock : region->getHeader()->getNextRegions()) for (Region* nextBlock : region->getHeader()->getNextRegions())
{
nextBlock->replaceInPrevRegions(region, region->getHeader()); nextBlock->replaceInPrevRegions(region, region->getHeader());
}
} }
static void SolveDataFlowIteratively(Region* DFG) static void SolveDataFlowIteratively(Region* DFG)
@@ -85,49 +77,35 @@ static void SolveDataFlowIteratively(Region* DFG)
for (const auto& [arrayName, accessSet] : prevBlock->array_out) for (const auto& [arrayName, accessSet] : prevBlock->array_out)
{ {
if (newIn.find(arrayName) != newIn.end()) if (newIn.find(arrayName) != newIn.end())
{
newIn[arrayName] = newIn[arrayName].Intersect(accessSet); newIn[arrayName] = newIn[arrayName].Intersect(accessSet);
}
else else
{
newIn[arrayName] = AccessingSet(); newIn[arrayName] = AccessingSet();
}
} }
} }
} }
b->array_in = move(newIn); b->array_in = move(newIn);
ArrayAccessingIndexes newOut; ArrayAccessingIndexes newOut;
if (b->array_def.empty()) if (b->array_def.empty())
{
newOut = b->array_in; newOut = b->array_in;
}
else if (b->array_in.empty()) else if (b->array_in.empty())
{
newOut = b->array_def; newOut = b->array_def;
}
else else
{ {
for (auto& [arrayName, accessSet] : b->array_def) for (auto& [arrayName, accessSet] : b->array_def)
{ {
if (newOut.find(arrayName) != newOut.end()) if (newOut.find(arrayName) != newOut.end())
{
newOut[arrayName] = b->array_def[arrayName].Union(b->array_in[arrayName]); newOut[arrayName] = b->array_def[arrayName].Union(b->array_in[arrayName]);
}
else else
{
newOut[arrayName] = accessSet; newOut[arrayName] = accessSet;
}
} }
} }
/* can not differ */ /* can not differ */
if (newOut != b->array_out) if (newOut != b->array_out)
{
b->array_out = newOut; b->array_out = newOut;
}
else else
{
worklist.erase(b); worklist.erase(b);
}
} }
while (!worklist.empty()); while (!worklist.empty());
} }
@@ -136,11 +114,10 @@ static void SolveDataFlow(Region* DFG)
{ {
if (!DFG) if (!DFG)
return; return;
SolveDataFlowIteratively(DFG); SolveDataFlowIteratively(DFG);
for (Region* subRegion : DFG->getSubRegions()) for (Region* subRegion : DFG->getSubRegions())
{
SolveDataFlow(subRegion); SolveDataFlow(subRegion);
}
Collapse(DFG); Collapse(DFG);
} }

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include<vector> #include <vector>
#include<map> #include <map>
#include<unordered_set> #include <unordered_set>
#include "range_structures.h" #include "range_structures.h"
#include "region.h" #include "region.h"

View File

@@ -1,7 +1,7 @@
#include<vector> #include <vector>
#include<map> #include <map>
#include<unordered_set> #include <unordered_set>
#include<string> #include <string>
#include <numeric> #include <numeric>
#include "range_structures.h" #include "range_structures.h"
@@ -17,9 +17,7 @@ static vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const
{ {
uint64_t rightPart = dim2.start + j * dim2.step; uint64_t rightPart = dim2.start + j * dim2.step;
if (leftPart == rightPart) if (leftPart == rightPart)
{
return { i, j }; return { i, j };
}
} }
} }
return {}; return {};
@@ -30,9 +28,8 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
{ {
vector<uint64_t> partSolution = FindParticularSolution(dim1, dim2); vector<uint64_t> partSolution = FindParticularSolution(dim1, dim2);
if (partSolution.empty()) if (partSolution.empty())
{
return NULL; return NULL;
}
int64_t x0 = partSolution[0], y0 = partSolution[1]; int64_t x0 = partSolution[0], y0 = partSolution[1];
/* x = x_0 + c * t */ /* x = x_0 + c * t */
/* y = y_0 + d * t */ /* y = y_0 + d * t */
@@ -46,9 +43,8 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
int64_t tMin = max(tXMin, tYMin); int64_t tMin = max(tXMin, tYMin);
uint64_t tMax = min(tXMax, tYMax); uint64_t tMax = min(tXMax, tYMax);
if (tMin > tMax) if (tMin > tMax)
{
return NULL; return NULL;
}
uint64_t start3 = dim1.start + x0 * dim1.step; uint64_t start3 = dim1.start + x0 * dim1.step;
uint64_t step3 = c * dim1.step; uint64_t step3 = c * dim1.step;
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 }; ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 };
@@ -60,15 +56,13 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
{ {
ArrayDimension* intersection = DimensionIntersection(dim1, dim2); ArrayDimension* intersection = DimensionIntersection(dim1, dim2);
if (!intersection) if (!intersection)
{
return { dim1 }; return { dim1 };
}
vector<ArrayDimension> result; vector<ArrayDimension> result;
/* add the part before intersection */ /* add the part before intersection */
if (dim1.start < intersection->start) if (dim1.start < intersection->start)
{
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step }); result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step });
}
/* add the parts between intersection steps */ /* add the parts between intersection steps */
uint64_t start = (intersection->start - dim1.start) / dim1.step; uint64_t start = (intersection->start - dim1.start) / dim1.step;
uint64_t interValue = intersection->start; uint64_t interValue = intersection->start;
@@ -103,11 +97,11 @@ static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const A
vector<ArrayDimension> res; vector<ArrayDimension> res;
ArrayDimension* inter = DimensionIntersection(dim1, dim2); ArrayDimension* inter = DimensionIntersection(dim1, dim2);
if (!inter) if (!inter)
{
return { dim1, dim2 }; return { dim1, dim2 };
}
res.push_back(*inter); res.push_back(*inter);
delete(inter); delete(inter);
vector<ArrayDimension> diff1, diff2; vector<ArrayDimension> diff1, diff2;
diff1 = DimensionDifference(dim1, dim2); diff1 = DimensionDifference(dim1, dim2);
diff2 = DimensionDifference(dim2, dim1); diff2 = DimensionDifference(dim2, dim1);
@@ -118,29 +112,24 @@ static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const A
static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement) static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
{ {
if (firstElement.empty() || secondElement.empty()) { if (firstElement.empty() || secondElement.empty())
return {}; return {};
}
size_t dimAmount = firstElement.size(); size_t dimAmount = firstElement.size();
/* check if there is no intersecction */ /* check if there is no intersecction */
for (size_t i = 0; i < dimAmount; i++) for (size_t i = 0; i < dimAmount; i++)
{ if (FindParticularSolution(firstElement[i], secondElement[i]).empty())
if (FindParticularSolution(firstElement[i], secondElement[i]).empty()) {
return {}; return {};
}
}
vector<ArrayDimension> result(dimAmount); vector<ArrayDimension> result(dimAmount);
for (size_t i = 0; i < dimAmount; i++) for (size_t i = 0; i < dimAmount; i++)
{ {
ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]); ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]);
if (resPtr) if (resPtr)
{
result[i] = *resPtr; result[i] = *resPtr;
}
else else
{
return {}; return {};
}
} }
return result; return result;
} }
@@ -148,15 +137,14 @@ static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>&
static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement, static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement,
const vector<ArrayDimension>& secondElement) const vector<ArrayDimension>& secondElement)
{ {
if (firstElement.empty() || secondElement.empty()) { if (firstElement.empty() || secondElement.empty())
return {}; return {};
}
vector<ArrayDimension> intersection = ElementsIntersection(firstElement, secondElement); vector<ArrayDimension> intersection = ElementsIntersection(firstElement, secondElement);
vector<vector<ArrayDimension>> result; vector<vector<ArrayDimension>> result;
if (intersection.empty()) if (intersection.empty())
{
return { firstElement }; return { firstElement };
}
for (int i = 0; i < firstElement.size(); i++) for (int i = 0; i < firstElement.size(); i++)
{ {
auto dimDiff = DimensionDifference(firstElement[i], secondElement[i]); auto dimDiff = DimensionDifference(firstElement[i], secondElement[i]);
@@ -212,9 +200,8 @@ void AccessingSet::FindCoveredBy(const vector<ArrayDimension>& element, vector<v
for (const auto& currentElement : allElements) for (const auto& currentElement : allElements)
{ {
auto intersection = ElementsIntersection(element, currentElement); auto intersection = ElementsIntersection(element, currentElement);
if (!intersection.empty()) { if (!intersection.empty())
result.push_back(intersection); result.push_back(intersection);
}
} }
} }
@@ -229,13 +216,11 @@ void AccessingSet::Insert(const vector<ArrayDimension>& element)
AccessingSet AccessingSet::Union(const AccessingSet& source) { AccessingSet AccessingSet::Union(const AccessingSet& source) {
AccessingSet result; AccessingSet result;
for (auto& element : source.GetElements()) { for (auto& element : source.GetElements())
result.Insert(element); result.Insert(element);
}
for (auto& element : allElements) for (auto& element : allElements)
{
result.Insert(element); result.Insert(element);
}
return result; return result;
} }
@@ -244,22 +229,20 @@ AccessingSet AccessingSet::Intersect(const AccessingSet& secondSet) const
vector<vector<ArrayDimension>> result; vector<vector<ArrayDimension>> result;
if (secondSet.GetElements().empty() || this->allElements.empty()) if (secondSet.GetElements().empty() || this->allElements.empty())
return AccessingSet(result); return AccessingSet(result);
for (const auto& element : allElements) for (const auto& element : allElements)
{ {
if (secondSet.ContainsElement(element)) if (secondSet.ContainsElement(element))
{
result.push_back(element); result.push_back(element);
}
else else
{ {
vector<vector<ArrayDimension>> coveredBy; vector<vector<ArrayDimension>> coveredBy;
secondSet.FindCoveredBy(element, coveredBy); secondSet.FindCoveredBy(element, coveredBy);
if (!coveredBy.empty()) if (!coveredBy.empty())
{
result.insert(result.end(), coveredBy.begin(), coveredBy.end()); result.insert(result.end(), coveredBy.begin(), coveredBy.end());
}
} }
} }
return AccessingSet(result); return AccessingSet(result);
} }
@@ -267,6 +250,7 @@ AccessingSet AccessingSet::Diff(const AccessingSet& secondSet) const
{ {
if (secondSet.GetElements().empty() || allElements.empty()) if (secondSet.GetElements().empty() || allElements.empty())
return *this; return *this;
AccessingSet intersection = this->Intersect(secondSet); AccessingSet intersection = this->Intersect(secondSet);
AccessingSet uncovered = *this; AccessingSet uncovered = *this;
vector<vector<ArrayDimension>> result; vector<vector<ArrayDimension>> result;
@@ -288,30 +272,21 @@ bool operator!=(const ArrayDimension& lhs, const ArrayDimension& rhs)
bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs) bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs)
{ {
for (size_t i = 0; i < lhs.allElements.size(); i++) for (size_t i = 0; i < lhs.allElements.size(); i++)
{
for (size_t j = 0; j < lhs.allElements[i].size(); j++) for (size_t j = 0; j < lhs.allElements[i].size(); j++)
{
if (lhs.allElements[i][j] != rhs.allElements[i][j]) if (lhs.allElements[i][j] != rhs.allElements[i][j])
{
return true; return true;
}
}
}
return false; return false;
} }
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs) bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs)
{ {
if (lhs.size() != rhs.size()) if (lhs.size() != rhs.size())
{
return true; return true;
}
for (auto& [key, value] : lhs) for (auto& [key, value] : lhs)
{
if (rhs.find(key) == rhs.end()) if (rhs.find(key) == rhs.end())
{
return true; return true;
}
}
return false; return false;
} }

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include<vector> #include <vector>
#include<map> #include <map>
#include<unordered_set> #include <unordered_set>
#include<string> #include <string>
struct ArrayDimension struct ArrayDimension
{ {

View File

@@ -16,9 +16,8 @@ static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
{ {
for (; stmt; stmt = stmt->controlParent()) for (; stmt; stmt = stmt->controlParent())
if (stmt == parent) if (stmt == parent)
{
return true; return true;
}
return false; return false;
} }
@@ -31,9 +30,8 @@ pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForL
for (const auto& block : blocks) for (const auto& block : blocks)
{ {
if (!block || (block->getInstructions().size() == 0)) if (!block || (block->getInstructions().size() == 0))
{
continue; continue;
}
SgStatement* first = block->getInstructions().front()->getInstruction()->getOperator(); SgStatement* first = block->getInstructions().front()->getInstruction()->getOperator();
SgStatement* last = block->getInstructions().back()->getInstruction()->getOperator(); SgStatement* last = block->getInstructions().back()->getInstruction()->getOperator();
if (isParentStmt(first, loop_operator) && isParentStmt(last, loop_operator)) if (isParentStmt(first, loop_operator) && isParentStmt(last, loop_operator))
@@ -55,36 +53,39 @@ pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForL
static void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) { static void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
string index = loop->loopSymbol; string index = loop->loopSymbol;
loopForIndex[index] = loop; loopForIndex[index] = loop;
for (const auto& childLoop : loop->children) {
for (const auto& childLoop : loop->children)
BuildLoopIndex(loopForIndex, childLoop); BuildLoopIndex(loopForIndex, childLoop);
}
} }
static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) { static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
unordered_set<SAPFOR::Argument*> args = { block->getInstructions()[pos]->getInstruction()->getArg1() }; unordered_set<SAPFOR::Argument*> args = { block->getInstructions()[pos]->getInstruction()->getArg1() };
for (int i = pos - 1; i >= 0; i--) { for (int i = pos - 1; i >= 0; i--)
{
SAPFOR::Argument* res = block->getInstructions()[i]->getInstruction()->getResult(); SAPFOR::Argument* res = block->getInstructions()[i]->getInstruction()->getResult();
if (res && args.find(res) != args.end()) { if (res && args.find(res) != args.end())
{
SAPFOR::Argument* arg1 = block->getInstructions()[i]->getInstruction()->getArg1(); SAPFOR::Argument* arg1 = block->getInstructions()[i]->getInstruction()->getArg1();
SAPFOR::Argument* arg2 = block->getInstructions()[i]->getInstruction()->getArg2(); SAPFOR::Argument* arg2 = block->getInstructions()[i]->getInstruction()->getArg2();
if (arg1) { if (arg1)
{
string name = arg1->getValue(); string name = arg1->getValue();
int idx = name.find('%'); int idx = name.find('%');
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end()) if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
return name.substr(idx + 1); return name.substr(idx + 1);
else { else
args.insert(arg1); args.insert(arg1);
}
} }
if (arg2) {
if (arg2)
{
string name = arg2->getValue(); string name = arg2->getValue();
int idx = name.find('%'); int idx = name.find('%');
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end()) if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
return name.substr(idx + 1); return name.substr(idx + 1);
else { else
args.insert(arg2); args.insert(arg2);
}
} }
} }
} }
@@ -98,9 +99,9 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
for (int i = 0; i < instructions.size(); i++) for (int i = 0; i < instructions.size(); i++)
{ {
auto instruction = instructions[i]; auto instruction = instructions[i];
if (!instruction->getInstruction()->getArg1()) { if (!instruction->getInstruction()->getArg1())
continue; continue;
}
auto operation = instruction->getInstruction()->getOperation(); auto operation = instruction->getInstruction()->getOperation();
auto type = instruction->getInstruction()->getArg1()->getType(); auto type = instruction->getInstruction()->getArg1()->getType();
if ((operation == SAPFOR::CFG_OP::STORE || operation == SAPFOR::CFG_OP::LOAD) && type == SAPFOR::CFG_ARG_TYPE::ARRAY) if ((operation == SAPFOR::CFG_OP::STORE || operation == SAPFOR::CFG_OP::LOAD) && type == SAPFOR::CFG_ARG_TYPE::ARRAY)
@@ -109,13 +110,10 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
vector<int> refPos; vector<int> refPos;
string array_name; string array_name;
if (operation == SAPFOR::CFG_OP::STORE) if (operation == SAPFOR::CFG_OP::STORE)
{
array_name = instruction->getInstruction()->getArg1()->getValue(); array_name = instruction->getInstruction()->getArg1()->getValue();
}
else else
{
array_name = instruction->getInstruction()->getArg2()->getValue(); array_name = instruction->getInstruction()->getArg2()->getValue();
}
int j = i - 1; int j = i - 1;
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF) while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
{ {
@@ -123,12 +121,12 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
refPos.push_back(j); refPos.push_back(j);
j--; j--;
} }
/*to choose correct dimension*/ /*to choose correct dimension*/
int n = index_vars.size(); int n = index_vars.size();
vector<ArrayDimension> accessPoint(n); vector<ArrayDimension> accessPoint(n);
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression()); auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
vector<pair<int, int>> coefsForDims; vector<pair<int, int>> coefsForDims;
for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i) for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i)
{ {
@@ -147,52 +145,48 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
int currentVarPos = refPos.back(); int currentVarPos = refPos.back();
pair currentCoefs = coefsForDims.back(); pair currentCoefs = coefsForDims.back();
ArrayDimension current_dim; ArrayDimension current_dim;
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST) { if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
current_dim = { stoul(var->getValue()), 1, 1 }; current_dim = { stoul(var->getValue()), 1, 1 };
}
else else
{ {
string name, full_name = var->getValue(); string name, full_name = var->getValue();
int pos = full_name.find('%'); int pos = full_name.find('%');
LoopGraph* currentLoop; LoopGraph* currentLoop;
if (pos != -1) { if (pos != -1)
{
name = full_name.substr(pos + 1); name = full_name.substr(pos + 1);
if (loopForIndex.find(name) != loopForIndex.end()) { if (loopForIndex.find(name) != loopForIndex.end())
currentLoop = loopForIndex[name]; currentLoop = loopForIndex[name];
} else
else {
return -1; return -1;
}
} }
else { else
{
name = FindIndexName(currentVarPos, block, loopForIndex); name = FindIndexName(currentVarPos, block, loopForIndex);
if (name == "") { if (name == "")
return -1; return -1;
}
if (loopForIndex.find(name) != loopForIndex.end()) { if (loopForIndex.find(name) != loopForIndex.end())
currentLoop = loopForIndex[name]; currentLoop = loopForIndex[name];
} else
else {
return -1; return -1;
}
} }
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second; uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
uint64_t step = currentCoefs.first; uint64_t step = currentCoefs.first;
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters }; current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters };
} }
accessPoint[n - index_vars.size()] = current_dim; accessPoint[n - index_vars.size()] = current_dim;
index_vars.pop_back(); index_vars.pop_back();
refPos.pop_back(); refPos.pop_back();
coefsForDims.pop_back(); coefsForDims.pop_back();
} }
if (operation == SAPFOR::CFG_OP::STORE) if (operation == SAPFOR::CFG_OP::STORE)
{
def[array_name].Insert(accessPoint); def[array_name].Insert(accessPoint);
}
else else
{
use[array_name].Insert(accessPoint); use[array_name].Insert(accessPoint);
}
} }
} }
return 0; return 0;
@@ -204,19 +198,12 @@ static void SetConnections(unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegi
for (SAPFOR::BasicBlock* block : blockSet) for (SAPFOR::BasicBlock* block : blockSet)
{ {
for (SAPFOR::BasicBlock* nextBlock : block->getNext()) for (SAPFOR::BasicBlock* nextBlock : block->getNext())
{
if (bbToRegion.find(nextBlock) != bbToRegion.end()) if (bbToRegion.find(nextBlock) != bbToRegion.end())
{
bbToRegion[block]->addNextRegion(bbToRegion[nextBlock]); bbToRegion[block]->addNextRegion(bbToRegion[nextBlock]);
}
}
for (SAPFOR::BasicBlock* prevBlock : block->getPrev()) for (SAPFOR::BasicBlock* prevBlock : block->getPrev())
{
if (bbToRegion.find(prevBlock) != bbToRegion.end()) if (bbToRegion.find(prevBlock) != bbToRegion.end())
{
bbToRegion[block]->addPrevRegion(bbToRegion[prevBlock]); bbToRegion[block]->addPrevRegion(bbToRegion[prevBlock]);
}
}
} }
} }
@@ -225,24 +212,17 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
Region* region = new Region; Region* region = new Region;
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks); auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
if (bbToRegion.find(header) != bbToRegion.end()) if (bbToRegion.find(header) != bbToRegion.end())
{
region->setHeader(bbToRegion.at(header)); region->setHeader(bbToRegion.at(header));
}
else else
{
return NULL; return NULL;
}
for (SAPFOR::BasicBlock* block : blockSet) for (SAPFOR::BasicBlock* block : blockSet)
{
if (bbToRegion.find(block) != bbToRegion.end()) if (bbToRegion.find(block) != bbToRegion.end())
{
region->addBasickBlocks(bbToRegion.at(block)); region->addBasickBlocks(bbToRegion.at(block));
}
}
for (LoopGraph* childLoop : loop->children) for (LoopGraph* childLoop : loop->children)
{
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion)); region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
}
cout << header << endl; cout << header << endl;
return region; return region;
} }
@@ -262,7 +242,5 @@ Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
SetConnections(bbToRegion, blockSet); SetConnections(bbToRegion, blockSet);
//create subRegions //create subRegions
for (LoopGraph* childLoop : loop->children) for (LoopGraph* childLoop : loop->children)
{
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion)); subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
}
} }

View File

@@ -1030,9 +1030,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks); countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
} }
else if (curr_regime == FIND_PRIVATE_ARRAYS) else if (curr_regime == FIND_PRIVATE_ARRAYS)
{
FindPrivateArrays(loopGraph, fullIR); FindPrivateArrays(loopGraph, fullIR);
}
else if (curr_regime == TEST_PASS) else if (curr_regime == TEST_PASS)
{ {
//test pass //test pass