Some fixes

This commit is contained in:
Egor Mayorov
2024-12-26 01:09:22 +03:00
parent f4644fafc3
commit 672f03a81f
3 changed files with 22 additions and 25 deletions

View File

@@ -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<SAPFOR::BasicBlock*> blocks)
SAPFOR::BasicBlock* GetBasicBlocksForLoop(const LoopGraph* loop, const vector<SAPFOR::BasicBlock*> blocks)
{
unordered_set<SAPFOR::BasicBlock*> block_loop;
SAPFOR::BasicBlock* head_block = nullptr;
@@ -81,7 +81,7 @@ vector<FuncInfo*> FindFuncInfoVec(string funcname, const map<string, vector<Func
}
/*returns BasicBlock vector for function by FuncInfo*/
vector<SAPFOR::BasicBlock*> FindBlocksVec(FuncInfo* func, const map<FuncInfo*, vector<SAPFOR::BasicBlock*>> &fullIR){
vector<SAPFOR::BasicBlock*> FindBlocksVec(const FuncInfo* func, const map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& fullIR){
for(const pair<FuncInfo*, vector<SAPFOR::BasicBlock*>>& p: fullIR) {
if(p.first == func){
return p.second;
@@ -92,7 +92,7 @@ vector<SAPFOR::BasicBlock*> FindBlocksVec(FuncInfo* func, const map<FuncInfo*, v
}
/*returns LoopGraph vector by filename*/
vector<LoopGraph*> FindLoopsWithFilename(string filename, const map<string, vector<LoopGraph*>> loopGraph){
vector<LoopGraph*> FindLoopsWithFilename(string filename, const map<string, vector<LoopGraph*>>& loopGraph){
for(pair<string, vector<LoopGraph*>> p: loopGraph) {
if(p.first == filename){
return p.second;
@@ -103,7 +103,7 @@ vector<LoopGraph*> FindLoopsWithFilename(string filename, const map<string, vect
}
/*checks if instruction is found for result*/
bool CheckIfInstructionIsFound(vector<pair<int, SAPFOR::Instruction*>> found, int block_num, SAPFOR::Instruction* instr){
bool CheckIfInstructionIsFound(const vector<pair<int, SAPFOR::Instruction*>> found, int block_num, const SAPFOR::Instruction* instr){
for(pair<int, SAPFOR::Instruction*> p: found){
if(p.first == block_num && p.second == instr){
return true;
@@ -113,7 +113,7 @@ bool CheckIfInstructionIsFound(vector<pair<int, SAPFOR::Instruction*>> found, in
}
/*main pass function*/
map<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>>
map<pair<string, int>, set<string>>
findParameters(const map<string, vector<DefUseList>> &defUseByFunctions,
const map<string, CommonBlock*> &commonBlocks,
const map<string, vector<FuncInfo*>> &allFuncInfo,
@@ -136,7 +136,7 @@ map<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>>
}
/*find instructions with read operaton which affects on number iterations for loops*/
map<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>> finalInstructions;
map<pair<string, int>, set<string>> finalInstructions;
/*for each function*/
for(const auto lookedFunc: mapFuncLoops){
/*for each loop in function*/
@@ -162,18 +162,17 @@ map<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>>
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<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>>
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<FuncInfo*, vector<pair<int, SAPFOR::Instruction*>>>
}
}
/*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;

View File

@@ -21,7 +21,7 @@
#include "../CFGraph/CFGraph.h"
#include "../CFGraph/IR.h"
std::map<FuncInfo*, std::vector<std::pair<int, SAPFOR::Instruction*>>>
std::map<std::pair<std::string, int>, std::set<std::string>>
findParameters(const std::map<std::string, std::vector<DefUseList>> &defUseByFunctions,
const std::map<std::string, CommonBlock*> &commonBlocks,
const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo,

View File

@@ -168,7 +168,7 @@ std::map<int, UserFiles> filesInfo; // information about open,close,write and re
//
//for FIND_PARAMETERS
std::map<FuncInfo*, std::vector<std::pair<int, SAPFOR::Instruction*>>> parametersOfProject; // FuncInfo -> vector[BlockNum, Instruction]
std::map<std::pair<std::string, int>, std::set<std::string>> parametersOfProject; // [file, line] -> set[vars]
//
//for GET_MIN_MAX_BLOCK_DIST