fixed code style
This commit is contained in:
@@ -43,7 +43,8 @@ static void dfs(SAPFOR::BasicBlock* block, map<int, int>& visit, vector<pair<SAP
|
||||
dfs(i, visit, startAndEnd, block);
|
||||
}
|
||||
|
||||
static void printBlock(SAPFOR::BasicBlock* block) {
|
||||
static void printBlock(SAPFOR::BasicBlock* block)
|
||||
{
|
||||
cout << "block - " << block->getNumber() << endl;
|
||||
cout << "next -";
|
||||
for (auto i : block->getNext())
|
||||
@@ -59,17 +60,20 @@ static void printBlock(SAPFOR::BasicBlock* block) {
|
||||
string resValue = "";
|
||||
string arg1Value = "";
|
||||
string arg2Value = "";
|
||||
if (i->getInstruction()->getResult() != NULL && i->getInstruction()->getResult()->getType() == SAPFOR::CFG_ARG_TYPE::VAR) {
|
||||
if (i->getInstruction()->getResult() != NULL && i->getInstruction()->getResult()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
||||
{
|
||||
resValue = i->getInstruction()->getResult()->getValue();
|
||||
i->getInstruction()->getResult()->setValue(i->getInstruction()->getResult()->getValue() + to_string(i->getInstruction()->getResult()->getNumber()));
|
||||
}
|
||||
|
||||
if (i->getInstruction()->getArg1() != NULL && i->getInstruction()->getArg1()->getType() == SAPFOR::CFG_ARG_TYPE::VAR) {
|
||||
if (i->getInstruction()->getArg1() != NULL && i->getInstruction()->getArg1()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
||||
{
|
||||
arg1Value = i->getInstruction()->getArg1()->getValue();
|
||||
i->getInstruction()->getArg1()->setValue(i->getInstruction()->getArg1()->getValue() + to_string(i->getInstruction()->getArg1()->getNumber()));
|
||||
}
|
||||
|
||||
if (i->getInstruction()->getArg2() != NULL && i->getInstruction()->getArg2()->getType() == SAPFOR::CFG_ARG_TYPE::VAR) {
|
||||
if (i->getInstruction()->getArg2() != NULL && i->getInstruction()->getArg2()->getType() == SAPFOR::CFG_ARG_TYPE::VAR)
|
||||
{
|
||||
arg2Value = i->getInstruction()->getArg2()->getValue();
|
||||
i->getInstruction()->getArg2()->setValue(i->getInstruction()->getArg2()->getValue() + to_string(i->getInstruction()->getArg2()->getNumber()));
|
||||
}
|
||||
@@ -105,7 +109,7 @@ static void getLoopBody(SAPFOR::BasicBlock* loopHeader, const set<SAPFOR::BasicB
|
||||
continue;
|
||||
visited.insert(block);
|
||||
|
||||
for (auto succ : block->getNext())
|
||||
for (auto& succ : block->getNext())
|
||||
{
|
||||
if (loopExits.count(succ))
|
||||
continue;
|
||||
@@ -128,12 +132,12 @@ static void getLoopBody(SAPFOR::BasicBlock* loopHeader, const set<SAPFOR::BasicB
|
||||
continue;
|
||||
backReachable.insert(block);
|
||||
|
||||
for (auto pred : block->getPrev())
|
||||
for (auto& pred : block->getPrev())
|
||||
if (visited.count(pred) && !backReachable.count(pred))
|
||||
reverseStack.push(pred);
|
||||
}
|
||||
|
||||
for (auto block : visited)
|
||||
for (auto& block : visited)
|
||||
if (backReachable.count(block))
|
||||
loopBody.push_back(block);
|
||||
}
|
||||
@@ -171,9 +175,9 @@ static set<SAPFOR::Argument*> findRegisterSourceVariables(const std::vector<SAPF
|
||||
|
||||
visited.insert(variable);
|
||||
|
||||
for (auto block : blocks)
|
||||
for (auto& block : blocks)
|
||||
{
|
||||
for (auto instrWrapper : block->getInstructions())
|
||||
for (auto& instrWrapper : block->getInstructions())
|
||||
{
|
||||
auto instr = instrWrapper->getInstruction();
|
||||
if (!instr || instr->getResult() != variable)
|
||||
@@ -279,9 +283,9 @@ static void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
|
||||
set<string> inductiveVars;
|
||||
set<SAPFOR::BasicBlock*> relevantBlocks = { loopHeader };
|
||||
|
||||
for (auto block : relevantBlocks)
|
||||
for (auto& block : relevantBlocks)
|
||||
{
|
||||
for (auto instrWrapper : block->getInstructions())
|
||||
for (auto& instrWrapper : block->getInstructions())
|
||||
{
|
||||
auto instr = instrWrapper->getInstruction();
|
||||
if (!instr)
|
||||
@@ -300,7 +304,7 @@ static void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
|
||||
if (arg1 && arg1->getType() == SAPFOR::CFG_ARG_TYPE::REG)
|
||||
{
|
||||
auto foundVariables = findRegisterSourceVariables(blocks, arg1);
|
||||
for (auto var : foundVariables)
|
||||
for (auto& var : foundVariables)
|
||||
inductiveVars.insert(var->getValue());
|
||||
}
|
||||
}
|
||||
@@ -309,7 +313,7 @@ static void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
|
||||
|
||||
set<string> finalInductiveVars;
|
||||
|
||||
for (auto instrWrapper : loopHeader->getInstructions())
|
||||
for (auto& instrWrapper : loopHeader->getInstructions())
|
||||
{
|
||||
auto instr = instrWrapper->getInstruction();
|
||||
if (!instr || instr->getOperation() != SAPFOR::CFG_OP::F_CALL || !instr->getArg1() || instr->getArg1()->getValue() != "FI_FUNCTION")
|
||||
@@ -347,7 +351,7 @@ static void findInductiveVars(const std::vector<SAPFOR::BasicBlock*>& blocks,
|
||||
finalInductiveVars.insert(phiRes->getValue());
|
||||
}
|
||||
|
||||
for (auto i : finalInductiveVars)
|
||||
for (auto& i : finalInductiveVars)
|
||||
cout << "Confirmed inductive variable: " << i << endl;
|
||||
|
||||
if (finalInductiveVars.empty())
|
||||
@@ -358,15 +362,15 @@ static SAPFOR::Instruction* findInstructionAfterLoop(const std::vector<SAPFOR::B
|
||||
{
|
||||
set<SAPFOR::BasicBlock*> loopSet(loopBody.begin(), loopBody.end());
|
||||
|
||||
for (auto block : loopBody)
|
||||
for (auto& block : loopBody)
|
||||
{
|
||||
for (auto succ : block->getNext())
|
||||
for (auto& succ : block->getNext())
|
||||
{
|
||||
if (!loopSet.count(succ))
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
auto instructions = succ->getInstructions();
|
||||
for (auto wrapper : instructions)
|
||||
for (auto& wrapper : instructions)
|
||||
if (auto instr = wrapper->getInstruction())
|
||||
return instr;
|
||||
}
|
||||
@@ -380,14 +384,14 @@ void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR
|
||||
{
|
||||
for (auto& i : fullIR_SSA)
|
||||
{
|
||||
//for (auto j : i.second)
|
||||
//for (auto& j : i.second)
|
||||
// printblock(j);
|
||||
|
||||
if (fileName != i.first->fileName)
|
||||
continue;
|
||||
|
||||
map<int, int> visited;
|
||||
for (auto i : i.second)
|
||||
for (auto& i : i.second)
|
||||
visited[i->getNumber()] = UNVISITED;
|
||||
|
||||
//vector<int> visited(i.second.size(), UNVISITED);
|
||||
@@ -399,11 +403,9 @@ void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR
|
||||
for (auto& [tail, header] : startAndEnd) {
|
||||
set<SAPFOR::BasicBlock*> loopExits;
|
||||
|
||||
for (auto succ : tail->getNext()) {
|
||||
if (succ != header) {
|
||||
for (auto& succ : tail->getNext())
|
||||
if (succ != header)
|
||||
loopExits.insert(succ);
|
||||
}
|
||||
}
|
||||
|
||||
vector<SAPFOR::BasicBlock*> loopBody;
|
||||
getLoopBody(header, loopExits, loopBody);
|
||||
@@ -412,16 +414,15 @@ void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR
|
||||
cout << " Header: " << header->getNumber() << endl;
|
||||
cout << " Tail: " << tail->getNumber() << endl;
|
||||
cout << " Body blocks: ";
|
||||
for (auto block : loopBody) {
|
||||
for (auto& block : loopBody)
|
||||
cout << block->getNumber() << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
findInductiveVars(i.second, loopBody, header, loopExits);
|
||||
|
||||
SAPFOR::Instruction* instructionAfterLoop = findInstructionAfterLoop(loopBody);
|
||||
|
||||
if (instructionAfterLoop == NULL) {
|
||||
if (instructionAfterLoop == NULL)
|
||||
{
|
||||
cout << "Warning: instruction after loop not found!" << endl;
|
||||
continue;
|
||||
}
|
||||
@@ -437,24 +438,25 @@ void findImplicitLoops(const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR
|
||||
tmpLoop->lineNum = firstInstruction->getOperator()->lineNumber();
|
||||
tmpLoop->lineNumAfterLoop = instructionAfterLoop->getOperator()->lineNumber();
|
||||
|
||||
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
|
||||
if (firstInstruction->getOperator()->variant() == FOR_NODE)
|
||||
{
|
||||
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
|
||||
cout << "for loop" << endl;// << stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
|
||||
else if (firstInstruction->getOperator()->variant() == WHILE_NODE)
|
||||
{
|
||||
SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
|
||||
cout << (stmt->conditional() == NULL ? "infinit" : "") << "while loop" << endl;//<< stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE) {
|
||||
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE)
|
||||
{
|
||||
SgWhileStmt* stmt = isSgDoWhileStmt(firstInstruction->getOperator());
|
||||
cout << "do while loop" << endl;// << stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == LOOP_NODE) {
|
||||
else if (firstInstruction->getOperator()->variant() == LOOP_NODE)
|
||||
cout << "not known loop" << endl;// << firstInstruction->getOperator()->sunparse() << endl;
|
||||
}
|
||||
else {
|
||||
else
|
||||
cout << "goto loop" << endl;// firstInstruction->getOperator()->sunparse() << endl;
|
||||
}
|
||||
|
||||
cout << "loop start line " << tmpLoop->lineNum << endl;
|
||||
cout << "after loop line " << tmpLoop->lineNumAfterLoop << endl << endl;
|
||||
|
||||
Reference in New Issue
Block a user