update in new order

This commit is contained in:
Egor Mayorov
2025-05-24 23:15:30 +03:00
committed by Alexander
parent 3d7c18773d
commit 37f8064427

View File

@@ -17,6 +17,8 @@ using namespace std;
unordered_set<int> loop_tags = {FOR_NODE/*, FORALL_NODE, WHILE_NODE, DO_WHILE_NODE*/};
unordered_set<int> importantDepsTags = {FOR_NODE, IF_NODE, ELSEIF_NODE};
unordered_set<int> importantEndTags = {CONTROL_END};
vector<SAPFOR::IR_Block*> findInstructionsFromOperator(SgStatement* st, vector<SAPFOR::BasicBlock*> Blocks)
@@ -124,19 +126,34 @@ map<SgStatement*, set<SgStatement*>> AnalyzeLoopAndFindDeps(SgForStmt* forStatem
return result;
}
// int PrintSmthFromLoop(int firstLine, int lastLine, map<SgStatement*, unordered_set<SgStatement*>> moveRules) {
// // only cout done yet ((
// cout << "LOOP ANALYZE FROM " << firstLine << " TO " << lastLine << " RES\n" << endl;
// for (auto r: moveRules) {
// cout << "OPERATOR: " << endl;
// cout << r.first -> lineNumber() << r.first -> sunparse();
// cout << "DEPENDS FROM NEXT: " << endl;
// for (SgStatement* st: r.second)
// cout << st -> lineNumber() << endl;
// }
// cout << "\n\n\n";
// return 0;
// }
void buildAdditionalDeps(SgForStmt* forStatement, map<SgStatement*, set<SgStatement*>>& dependencies)
{
SgStatement* lastNode = forStatement->lastNodeOfStmt();
vector<SgStatement*> importantDeps;
SgStatement* st = (SgStatement*) forStatement;
SgStatement* logIfOp = NULL;
importantDeps.push_back(st);
while (st && st != lastNode)
{
if (st != importantDeps.back()) {
dependencies[st].insert(importantDeps.back());
}
if (logIfOp != NULL) {
dependencies[st].insert(logIfOp);
logIfOp = NULL;
}
if (st -> variant() == LOGIF_NODE) {
logIfOp = st;
}
if (importantDepsTags.find(st -> variant()) != importantDepsTags.end()) {
importantDeps.push_back(st);
}
if (importantEndTags.find(st -> variant()) != importantEndTags.end()) {
importantDeps.pop_back();
}
st = st -> lexNext();
}
}
void GenNodesOfGraph(
const map<SgStatement*, set<SgStatement*>>& dependencies,
@@ -254,23 +271,25 @@ void runSwapOperators(SgFile *file, std::map<std::string, std::vector<LoopGraph*
{
map<SgStatement*, set<SgStatement*>> dependencyGraph = AnalyzeLoopAndFindDeps(loopForAnalyze.first, loopForAnalyze.second, FullIR);
// TODO: Write a function that will go through the operators and update all dependencies so that there are no mix-ups and splits inside the semantic blocks (for if, do and may be some other cases)
buildAdditionalDeps(loopForAnalyze.first, dependencyGraph);
cout << "\n\n";
for (auto v: dependencyGraph) {
cout << "OPERATOR: " << v.first -> lineNumber() << "\nDEPENDS ON:" << endl;
for (auto vv: v.second) {
cout << vv -> lineNumber() << " ";
}
cout << endl;
}
int firstLine = loopForAnalyze.first -> lineNumber();
int lastLine = loopForAnalyze.first -> lastNodeOfStmt() -> lineNumber();
// for (auto v: dependencyGraph) {
// cout << "OPERATOR: " << v.first -> lineNumber() << "\nDEPENDS ON:" << endl;
// if (v.second.size() != 0)
// for (auto vv: v.second) {
// if (vv -> lineNumber() > firstLine)
// cout << vv -> lineNumber() << " ";
// }
// cout << endl;
// }
if (dependencyGraph.size() != 0) {
int firstLine = loopForAnalyze.first -> lineNumber();
int lastLine = loopForAnalyze.first -> lastNodeOfStmt() -> lineNumber();
// countOfTransform += PrintSmthFromLoop(firstLine, lastLine, dependencyGraph);
vector<SgStatement*> new_order = SortNoInterleaving(dependencyGraph);
cout << "\n\nLOOP ANALYZE FROM " << firstLine << " TO " << lastLine << " RES\n" << endl;
for (auto v: new_order)
if (v -> lineNumber() > firstLine)
cout << v -> lineNumber() << " ";
cout << v -> lineNumber() << endl;
}
}
}