add directives

This commit is contained in:
2025-12-04 08:54:09 +03:00
committed by Egor Mayorov
parent 24f261961d
commit 13e4b6dff6
4 changed files with 77 additions and 13 deletions

View File

@@ -121,6 +121,60 @@ static void SolveDataFlow(Region* DFG)
Collapse(DFG);
}
unsigned long long CalculateLength(const AccessingSet& array)
{
if (array.GetElements().empty())
return 0;
unsigned long long result = 1;
for (const auto& range : array.GetElements())
{
for (const auto& dim : range)
{
result *= (dim.step * dim.tripCount);
}
}
return result;
}
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
{
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
spfStat->setlineNumber(loop->lineNum);
spfStat->setFileName((char*)loop->loop->fileName());
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
set<SgSymbol*> arraysToInsert;
for (const auto& [_, accessingSet] : privates)
{
for (const auto& arrayElement : accessingSet.GetElements())
{
if (arrayElement.empty())
continue;
arraysToInsert.insert(arrayElement[0].array->symbol());
}
}
spfStat->setExpression(0, *toAdd);
toAdd = toAdd->lhs();
bool first = true;
for (auto& elem : arraysToInsert)
{
if (first)
{
toAdd->setLhs(new SgExpression(EXPR_LIST));
toAdd = toAdd->lhs();
first = false;
}
else
{
toAdd->setRhs(new SgExpression(EXPR_LIST));
toAdd = toAdd->rhs();
}
toAdd->setLhs(new SgVarRefExp(elem));
}
loop->loop->addAttribute(SPF_ANALYSIS_DIR, spfStat, sizeof(SgStatement));
}
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
{
map<LoopGraph*, ArrayAccessingIndexes> result;
@@ -149,6 +203,10 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
delete(loopRegion);
}
}
if (result.find(loop) != result.end() && !result[loop].empty())
{
AddPrivateArraysToLoop(loop, result[loop]);
}
}
}
return result;