WIP add afterLoopLine

This commit is contained in:
2024-05-26 13:53:47 +03:00
committed by ALEXks
parent 392ad97738
commit d062e52dd6

View File

@@ -1660,6 +1660,11 @@ void testIR(map<FuncInfo*, vector<SAPFOR::BasicBlock*>> fullIR) {
for (auto j : i.second) for (auto j : i.second)
printBlock(j); printBlock(j);
vector<IR_Block*> all;
for (auto j : i.second)
for (auto k : j->getInstructions())
all.push_back(k);
vector<int> visited(i.second.size(), 0); vector<int> visited(i.second.size(), 0);
vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> startAndEnd; vector<pair<SAPFOR::BasicBlock*, SAPFOR::BasicBlock*>> startAndEnd;
dfs(i.second[0], visited, startAndEnd, NULL); dfs(i.second[0], visited, startAndEnd, NULL);
@@ -1668,23 +1673,39 @@ void testIR(map<FuncInfo*, vector<SAPFOR::BasicBlock*>> fullIR) {
vector<LoopGraph*> loops; vector<LoopGraph*> loops;
for (auto j : startAndEnd) for (auto j : startAndEnd)
{ {
auto instruction = j.second->getInstructions()[0]->getInstruction(); auto firstInstruction = j.second->getInstructions()[0]->getInstruction();
if (instruction->getOperator()->variant() == FOR_NODE) { auto lastInstruction = j.first->getInstructions().back()->getInstruction();
SgForStmt* stmt = isSgForStmt(instruction->getOperator()); Instruction* instructionAfterLoop;
for (auto a : fullIR)
for(auto b : a.second)
for (auto c : b->getInstructions())
if (c->getInstruction()->getNumber() == lastInstruction->getNumber() + 1)
{
instructionAfterLoop = c->getInstruction();
break;
}
//auto instructionAfterLoop = getInstructionByNumber(all, lastInstruction->getNumber() + 1);
cout << "first - " << firstInstruction->getNumber() << " last - " << lastInstruction->getNumber() << " after - " << instructionAfterLoop->getNumber() << endl;
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
auto tmpLoop = new LoopGraph(); auto tmpLoop = new LoopGraph();
tmpLoop->isFor = true; tmpLoop->isFor = true;
tmpLoop->lineNum = instruction->getOperator()->lineNumber(); tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
cout << "for" << endl << stmt->sunparse() << endl; cout << "for" << endl << stmt->sunparse() << endl;
cout << "loop start line " << tmpLoop->lineNum << endl << endl; cout << "loop start line " << tmpLoop->lineNum << endl;
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
loops.push_back(tmpLoop); loops.push_back(tmpLoop);
} else if (instruction->getOperator()->variant() == WHILE_NODE) { } else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
SgWhileStmt* stmt = isSgWhileStmt(instruction->getOperator()); SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
auto tmpLoop = new LoopGraph(); auto tmpLoop = new LoopGraph();
tmpLoop->lineNum = instruction->getOperator()->lineNumber(); tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
if (stmt->conditional() == NULL) if (stmt->conditional() == NULL)
{ {
@@ -1697,14 +1718,15 @@ void testIR(map<FuncInfo*, vector<SAPFOR::BasicBlock*>> fullIR) {
cout << "while " << endl << stmt->sunparse(); cout << "while " << endl << stmt->sunparse();
} }
cout << "loop start line " << tmpLoop->lineNum << endl << endl; cout << "loop start line " << tmpLoop->lineNum << endl;
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
loops.push_back(tmpLoop); loops.push_back(tmpLoop);
} else if (instruction->getOperator()->variant() == LOOP_NODE) { } else if (firstInstruction->getOperator()->variant() == LOOP_NODE) {
cout << "not known loop" << endl << instruction->getOperator()->sunparse() << endl; cout << "not known loop" << endl << firstInstruction->getOperator()->sunparse() << endl;
} }
else { else {
cout << "goto loop - " << instruction->getOperator()->sunparse() << endl; cout << "goto loop - " << firstInstruction->getOperator()->sunparse() << endl;
} }
} }