finalyze first version of private arrays search

This commit is contained in:
ALEXks
2025-12-11 12:26:39 +03:00
committed by Egor Mayorov
parent 13e4b6dff6
commit d94cb3c062
8 changed files with 32 additions and 16 deletions

View File

@@ -12,6 +12,7 @@
#include "SgUtils.h"
#include "graph_loops.h"
#include "CFGraph/CFGraph.h"
#include "utils.h"
using namespace std;
@@ -136,11 +137,11 @@ unsigned long long CalculateLength(const AccessingSet& array)
return result;
}
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
{
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
spfStat->setlineNumber(loop->lineNum);
spfStat->setFileName((char*)loop->loop->fileName());
spfStat->setlineNumber(loop->loop->lineNumber());
spfStat->setFileName(loop->loop->fileName());
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
set<SgSymbol*> arraysToInsert;
for (const auto& [_, accessingSet] : privates)
@@ -171,11 +172,15 @@ void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
}
toAdd->setLhs(new SgVarRefExp(elem));
}
if (arraysToInsert.size() == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
loop->loop->addAttribute(SPF_ANALYSIS_DIR, spfStat, sizeof(SgStatement));
loop->loop->insertStmtBefore(*spfStat, *loop->loop->controlParent());
insertedPrivates.insert(spfStat);
}
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR, set<SgStatement*> &insertedPrivates)
{
map<LoopGraph*, ArrayAccessingIndexes> result;
for (const auto& [fileName, loops] : loopGraph)
@@ -203,11 +208,9 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
delete(loopRegion);
}
}
if (result.find(loop) != result.end() && !result[loop].empty())
{
AddPrivateArraysToLoop(loop, result[loop]);
}
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
}
}
return result;
}

View File

@@ -2,11 +2,12 @@
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include "range_structures.h"
#include "graph_loops.h"
#include "CFGraph/CFGraph.h"
std::map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);