From 6a50d83b33e63f77dfec4acdfa3c8a610c807eee Mon Sep 17 00:00:00 2001 From: Egor Mayorov Date: Sat, 24 May 2025 23:15:30 +0300 Subject: [PATCH] update in new order --- src/SwapOperators/swapOperators.cpp | 67 ++++++++++++++++++----------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/SwapOperators/swapOperators.cpp b/src/SwapOperators/swapOperators.cpp index 078c872..d9483c7 100644 --- a/src/SwapOperators/swapOperators.cpp +++ b/src/SwapOperators/swapOperators.cpp @@ -17,6 +17,8 @@ using namespace std; unordered_set loop_tags = {FOR_NODE/*, FORALL_NODE, WHILE_NODE, DO_WHILE_NODE*/}; +unordered_set importantDepsTags = {FOR_NODE, IF_NODE, ELSEIF_NODE}; +unordered_set importantEndTags = {CONTROL_END}; vector findInstructionsFromOperator(SgStatement* st, vector Blocks) @@ -124,19 +126,34 @@ map> AnalyzeLoopAndFindDeps(SgForStmt* forStatem return result; } -// int PrintSmthFromLoop(int firstLine, int lastLine, map> 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>& dependencies) +{ + SgStatement* lastNode = forStatement->lastNodeOfStmt(); + vector 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>& dependencies, @@ -254,23 +271,25 @@ void runSwapOperators(SgFile *file, std::map> 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 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; } } }