This commit is contained in:
Egor Mayorov
2024-12-11 23:44:25 +03:00
parent ba963634c2
commit 7bb30a3edf

View File

@@ -99,14 +99,14 @@ vector<LoopGraph*> FindLoopsWithFilename(string filename, const map<string, vect
return a; return a;
} }
// bool CheckIfInstructionIsFound(vector<pair<int, SAPFOR::Instruction*>> found, int block_num, SAPFOR::Instruction* instr){ bool CheckIfInstructionIsFound(vector<pair<int, SAPFOR::Instruction*>> found, int block_num, SAPFOR::Instruction* instr){
// for(pair<int, SAPFOR::Instruction*> p: found){ for(pair<int, SAPFOR::Instruction*> p: found){
// if(p.first == block_num && p.second == instr){ if(p.first == block_num && p.second == instr){
// return true; return true;
// } }
// } }
// return return false;
// } }
map< pair<string, int>, set<string>> map< pair<string, int>, set<string>>
findParameters(const map<string, vector<DefUseList>> &defUseByFunctions, findParameters(const map<string, vector<DefUseList>> &defUseByFunctions,
@@ -157,6 +157,7 @@ map< pair<string, int>, set<string>>
} }
} }
} }
*/
cout << "\n\nLoopGraph" << endl; cout << "\n\nLoopGraph" << endl;
for(const pair<string, vector<LoopGraph*>>& p: loopGraph){ for(const pair<string, vector<LoopGraph*>>& p: loopGraph){
cout << "file name = " << p.first << endl; cout << "file name = " << p.first << endl;
@@ -180,7 +181,7 @@ map< pair<string, int>, set<string>>
} }
} }
} }
*/
// Находим для каждой функции блоки, с которых начинаются циклы // Находим для каждой функции блоки, с которых начинаются циклы
@@ -207,7 +208,7 @@ map< pair<string, int>, set<string>>
} }
} }
map<FuncInfo*, vector<SAPFOR::Instruction*>> finalInstructions; map<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>> finalInstructions;
for(const auto lookedFunc: mapFuncLoops){ for(const auto lookedFunc: mapFuncLoops){
for(const auto& v: lookedFunc.second){ for(const auto& v: lookedFunc.second){
// cout << "NEW LOOP SEARCH" << endl; // cout << "NEW LOOP SEARCH" << endl;
@@ -219,6 +220,9 @@ map< pair<string, int>, set<string>>
int block_ind = 0; int block_ind = 0;
// for(auto pr: argumentsForLook){cout << "FIRST ARGUMENT TO FIND: " << pr->getValue() << endl;} // for(auto pr: argumentsForLook){cout << "FIRST ARGUMENT TO FIND: " << pr->getValue() << endl;}
while(block_ind < blocks.size()){ while(block_ind < blocks.size()){
if(argumentsForLook.empty()){
break;
}
vector<SAPFOR::IR_Block*> blockInstructions = blocks[block_ind]->getInstructions(); vector<SAPFOR::IR_Block*> blockInstructions = blocks[block_ind]->getInstructions();
int vec_size = blockInstructions.size(); int vec_size = blockInstructions.size();
// cout << "NUMBER OF INSTRUCTIONS IN BLOCK " << blocks[block_ind]->getNumber() << " IS: " << vec_size << endl; // cout << "NUMBER OF INSTRUCTIONS IN BLOCK " << blocks[block_ind]->getNumber() << " IS: " << vec_size << endl;
@@ -231,7 +235,7 @@ map< pair<string, int>, set<string>>
// cout << "Instruction Operation (type): " << SAPFOR::CFG_OP_S[(int)cur->getOperation()] << endl; // cout << "Instruction Operation (type): " << SAPFOR::CFG_OP_S[(int)cur->getOperation()] << endl;
if(cur->getOperation() == SAPFOR::CFG_OP::F_CALL){ if(cur->getOperation() == SAPFOR::CFG_OP::F_CALL){
if(cur->getArg1()->getValue() == "_READ"){ if(cur->getArg1()->getValue() == "_READ"){
cout << "READ OPERATION FOUND" << endl; // cout << "READ OPERATION FOUND" << endl;
int numParams = std::stoi(cur->getArg2()->getValue()); int numParams = std::stoi(cur->getArg2()->getValue());
bool flag = false; bool flag = false;
for(int j=i-1; j>i-numParams-1; j--){ for(int j=i-1; j>i-numParams-1; j--){
@@ -241,12 +245,12 @@ map< pair<string, int>, set<string>>
flag = true; flag = true;
} }
} }
if(flag && find(finalInstructions[lookedFunc.first].begin(), finalInstructions[lookedFunc.first].end(), cur) == finalInstructions[lookedFunc.first].end()){ // if(flag && find(finalInstructions[lookedFunc.first].begin(), finalInstructions[lookedFunc.first].end(), cur) == finalInstructions[lookedFunc.first].end()){
finalInstructions[lookedFunc.first].push_back(cur); // finalInstructions[lookedFunc.first].push_back(cur);
}
// if(flag && CheckIfInstructionIsFound(finalInstructions[lookedFunc.first], blocks[block_ind]->getNumber(), cur)){
// finalInstructions[lookedFunc.first].push_back({blocks[block_ind]->getNumber(), cur});
// } // }
if(flag && !CheckIfInstructionIsFound(finalInstructions[lookedFunc.first], blocks[block_ind]->getNumber(), cur)){
finalInstructions[lookedFunc.first].push_back({blocks[block_ind]->getNumber(), cur});
}
i = i-numParams; i = i-numParams;
continue; continue;
} }
@@ -314,9 +318,10 @@ map< pair<string, int>, set<string>>
for(auto m: finalInstructions){ for(auto m: finalInstructions){
cout << "func: " << m.first->funcName << endl; cout << "func: " << m.first->funcName << endl;
for(auto v: m.second){ for(auto v: m.second){
cout << "instruction num: " << v->getNumber() << endl; cout << "Block num: " << v.first << endl;
cout << v->dump() << endl; cout << "Istruction num in block: " << v.second->getNumber() << endl;
cout << v->getOperator()->sunparse() << endl; cout << "Instruction dump: " << v.second->dump() << endl;
cout << "Operator" << v.second->getOperator()->sunparse() << endl;
} }
} }