diff --git a/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.cpp b/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.cpp index 4cf0b11..15b9964 100644 --- a/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.cpp +++ b/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.cpp @@ -31,7 +31,7 @@ set instructionsToLook = {SAPFOR::CFG_OP::LOAD, SAPFOR::CFG_OP::STORE, SAPFOR::C SAPFOR::CFG_OP::ADD, SAPFOR::CFG_OP::MULT, SAPFOR::CFG_OP::DIV, SAPFOR::CFG_OP::SUBT, SAPFOR::CFG_OP::UN_ADD, SAPFOR::CFG_OP::UN_MINUS, SAPFOR::CFG_OP::POW, SAPFOR::CFG_OP::CONCAT, SAPFOR::CFG_OP::ASSIGN}; -static bool isParentStmt(SgStatement* stmt, SgStatement* parent) +static bool isParentStmt(SgStatement* stmt, const SgStatement* parent) { for (; stmt; stmt = stmt->controlParent()) if (stmt == parent) @@ -42,7 +42,7 @@ static bool isParentStmt(SgStatement* stmt, SgStatement* parent) } /*returns head block and loop*/ -SAPFOR::BasicBlock* GetBasicBlocksForLoop(LoopGraph* loop, vector blocks) +SAPFOR::BasicBlock* GetBasicBlocksForLoop(const LoopGraph* loop, const vector blocks) { unordered_set block_loop; SAPFOR::BasicBlock* head_block = nullptr; @@ -70,7 +70,7 @@ SAPFOR::BasicBlock* GetBasicBlocksForLoop(LoopGraph* loop, vector FindFuncInfoVec(string funcname, const map> &allFuncInfo){ +vector FindFuncInfoVec(string funcname, const map>& allFuncInfo){ for(pair> p: allFuncInfo) { if(p.first == funcname){ return p.second; @@ -81,7 +81,7 @@ vector FindFuncInfoVec(string funcname, const map FindBlocksVec(FuncInfo* func, const map> &fullIR){ +vector FindBlocksVec(const FuncInfo* func, const map>& fullIR){ for(const pair>& p: fullIR) { if(p.first == func){ return p.second; @@ -92,7 +92,7 @@ vector FindBlocksVec(FuncInfo* func, const map FindLoopsWithFilename(string filename, const map> loopGraph){ +vector FindLoopsWithFilename(string filename, const map>& loopGraph){ for(pair> p: loopGraph) { if(p.first == filename){ return p.second; @@ -103,7 +103,7 @@ vector FindLoopsWithFilename(string filename, const map> found, int block_num, SAPFOR::Instruction* instr){ +bool CheckIfInstructionIsFound(const vector> found, int block_num, const SAPFOR::Instruction* instr){ for(pair p: found){ if(p.first == block_num && p.second == instr){ return true; @@ -113,7 +113,7 @@ bool CheckIfInstructionIsFound(vector> found, in } /*main pass function*/ -map>> +map, set> findParameters(const map> &defUseByFunctions, const map &commonBlocks, const map> &allFuncInfo, @@ -136,7 +136,7 @@ map>> } /*find instructions with read operaton which affects on number iterations for loops*/ - map>> finalInstructions; + map, set> finalInstructions; /*for each function*/ for(const auto lookedFunc: mapFuncLoops){ /*for each loop in function*/ @@ -162,18 +162,17 @@ map>> if(cur->getArg1()->getValue() == "_READ"){ int numParams = std::stoi(cur->getArg2()->getValue()); bool flag = false; - /*drop all found arguments from argumentsForLook*/ + /*drop all found arguments from argumentsForLook and add them to answer*/ for(int j=i-1; j>i-numParams-1; j--){ auto iter = find(argumentsForLook.begin(), argumentsForLook.end(), blockInstructions[j]->getInstruction()->getArg1()); if(iter != argumentsForLook.end()){ + int delimeterPosition = (*iter)->getValue().find("%"); + finalInstructions[{blockInstructions[j]->getInstruction()->getOperator()->fileName(), + blockInstructions[j]->getInstruction()->getLine()}].insert((*iter)->getValue().substr(delimeterPosition+1)); argumentsForLook.erase(iter); flag = true; } } - /*add read instruction to result vector if needed*/ - if(flag && !CheckIfInstructionIsFound(finalInstructions[lookedFunc.first], blocks[blockInd]->getNumber(), cur)){ - finalInstructions[lookedFunc.first].push_back({blocks[blockInd]->getNumber(), cur}); - } i = i-numParams; continue; } @@ -202,13 +201,13 @@ map>> int dist = distance(argumentsForLook.begin(), it); /*add arguments of operation to argumentsForLook vector if they are not there*/ if(cur->getArg1() != NULL && find(argumentsForLook.begin(), argumentsForLook.end(), cur->getArg1()) == argumentsForLook.end()){ - /*add argument only if it's type is register or variable because constants are nnot needed here*/ + /*add argument only if it's type is register or variable because constants are not needed here*/ if(goodArgTypes.find(cur->getArg1()->getType()) != goodArgTypes.end()){ argumentsForLook.push_back(cur->getArg1()); } } if(cur->getArg2() != NULL && find(argumentsForLook.begin(), argumentsForLook.end(), cur->getArg2()) == argumentsForLook.end()){ - /*add argument only if it's type is register or variable because constants are nnot needed here*/ + /*add argument only if it's type is register or variable because constants are not needed here*/ if(goodArgTypes.find(cur->getArg2()->getType()) != goodArgTypes.end()){ argumentsForLook.push_back(cur->getArg2()); } @@ -234,19 +233,17 @@ map>> } } + /*here should be part of founding istructions for allocates!!*/ + /*print found instructions for each function or program*/ cout << "\n\nFINAL INSTRUCTIONS" << endl; for(auto m: finalInstructions){ - cout << "func: " << m.first->funcName << endl; + cout << "file: " << m.first.first << endl; + cout << "line: " << m.first.second << endl; for(auto v: m.second){ - cout << "\tFilename: " << v.second->getOperator()->fileName() << endl; - cout << "\tLine number: " << v.second->getLine() << endl; - cout << "\tBlock num: " << v.first << endl; - cout << "\tIstruction num in block: " << v.second->getNumber() << endl; - cout << "\tInstruction dump: " << v.second->dump() << endl; - cout << "\tOperator" << v.second->getOperator()->sunparse() << endl; - cout << "\n"; + cout << "\tvar: " << v << endl; } + cout << "\n"; } return finalInstructions; diff --git a/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.h b/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.h index f461a52..00030fb 100644 --- a/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.h +++ b/sapfor/experts/Sapfor_2017/_src/ProjectParameters/projectParameters.h @@ -21,7 +21,7 @@ #include "../CFGraph/CFGraph.h" #include "../CFGraph/IR.h" -std::map>> +std::map, std::set> findParameters(const std::map> &defUseByFunctions, const std::map &commonBlocks, const std::map> &allFuncInfo, diff --git a/sapfor/experts/Sapfor_2017/_src/SapforData.h b/sapfor/experts/Sapfor_2017/_src/SapforData.h index eb8613a..bcd056c 100644 --- a/sapfor/experts/Sapfor_2017/_src/SapforData.h +++ b/sapfor/experts/Sapfor_2017/_src/SapforData.h @@ -168,7 +168,7 @@ std::map filesInfo; // information about open,close,write and re // //for FIND_PARAMETERS -std::map>> parametersOfProject; // FuncInfo -> vector[BlockNum, Instruction] +std::map, std::set> parametersOfProject; // [file, line] -> set[vars] // //for GET_MIN_MAX_BLOCK_DIST