diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp index 0919566..48bdff8 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp @@ -17,7 +17,7 @@ using std::set; using std::unordered_map; using std::list; -using LIVE_VARIABLES::fcall; +using LIVE_VARIABLES::LiveDeadVarsForCall; namespace SAPFOR { @@ -152,7 +152,7 @@ namespace SAPFOR } } -bool fcall::tryInsert(set& dest, SAPFOR::BasicBlock* b) +bool LiveDeadVarsForCall::tryInsert(set& dest, SAPFOR::BasicBlock* b) { if (b == block || dest.find(block) == dest.end()) { @@ -163,7 +163,7 @@ bool fcall::tryInsert(set& dest, SAPFOR::BasicBlock* b) return false; } -fcall::fcall(FuncInfo* f, SAPFOR::BasicBlock* b, const vector& p) +LiveDeadVarsForCall::LiveDeadVarsForCall(FuncInfo* f, SAPFOR::BasicBlock* b, const vector& p) { block = b; func = f; @@ -176,7 +176,7 @@ fcall::fcall(FuncInfo* f, SAPFOR::BasicBlock* b, const vector params[i] = p[i]; } -void fcall::make_live(SAPFOR::Argument* arg, SAPFOR::BasicBlock* b) +void LiveDeadVarsForCall::make_live(SAPFOR::Argument* arg, SAPFOR::BasicBlock* b) { if (arg->getMemType() == SAPFOR::CFG_MEM_TYPE::COMMON_ || arg->getMemType() == SAPFOR::CFG_MEM_TYPE::MODULE_) { @@ -193,7 +193,7 @@ void fcall::make_live(SAPFOR::Argument* arg, SAPFOR::BasicBlock* b) } } -void fcall::make_dead(SAPFOR::Argument* arg) +void LiveDeadVarsForCall::make_dead(SAPFOR::Argument* arg) { if (arg->getMemType() == SAPFOR::CFG_MEM_TYPE::COMMON_ || arg->getMemType() == SAPFOR::CFG_MEM_TYPE::MODULE_) { @@ -210,7 +210,7 @@ void fcall::make_dead(SAPFOR::Argument* arg) } } -void fcall::updateFromOut() +void LiveDeadVarsForCall::updateFromOut() { for (const auto& p : block->getLiveOut()) for (auto b : p.second) @@ -221,7 +221,7 @@ static bool getLiveDead(const vector& params, const string& f set& live, set& dead); static void buildUseDef(SAPFOR::BasicBlock* block, set& use, set& def, - vector& formal_parameters, vector& fcalls, + vector& formal_parameters, vector& fcalls, const map& funcByName, bool interprocedural); class LiveVarAnalysisNode : public DataFlowAnalysisNode>> { @@ -260,7 +260,7 @@ public: }; LiveVarAnalysisNode(SAPFOR::BasicBlock* block, vector& formal_parameters, - vector& fcalls, const map& funcByName) + vector& fcalls, const map& funcByName) { setBlock(block); @@ -274,21 +274,21 @@ public: class LiveVarAnalysis : public BackwardDataFlowAnalysis>, LiveVarAnalysisNode> { protected: vector& formal_parameters; - vector& fcalls; + vector& fcalls; const map& funcByName; LiveVarAnalysisNode* createNode(SAPFOR::BasicBlock* block) override { return new LiveVarAnalysisNode(block, formal_parameters, fcalls, funcByName); }; public: - LiveVarAnalysis(vector& formal_parameters, vector& fcalls, + LiveVarAnalysis(vector& formal_parameters, vector& fcalls, const map& funcByName) : formal_parameters(formal_parameters), fcalls(fcalls), funcByName(funcByName) { }; }; void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, set& use, set& def, - vector& formal_parameters, vector& fcalls, + vector& formal_parameters, vector& fcalls, vector& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, string& fName, const map& funcByName, bool interprocedural) { @@ -340,7 +340,7 @@ void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* ins auto func_it = funcByName.find(fName); if (func_it != funcByName.end()) { - fcalls.push_back(fcall(func_it->second, block, lastParamRef)); + fcalls.push_back(LiveDeadVarsForCall(func_it->second, block, lastParamRef)); auto r_it = fcalls.rbegin(); auto r_end = fcalls.rend(); @@ -376,7 +376,7 @@ void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* ins static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, set& use, set& def, - vector& formal_parameters, vector& fcalls, + vector& formal_parameters, vector& fcalls, vector& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, string& fName, const map& funcByName, bool interprocedural) { @@ -411,7 +411,7 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru //Build use and def sets of block. Result are stored in use and def static void buildUseDef(SAPFOR::BasicBlock* block, set& use, set& def, - vector& formal_parameters, vector& fcalls, + vector& formal_parameters, vector& fcalls, const map& funcByName, bool interprocedural) { vector lastParamRef; @@ -610,7 +610,7 @@ void runLiveVariableAnalysis(const map>& map func_to_analysis_object; map> func_to_parameters; - list> live_for_fcalls; + list> live_for_fcalls; //TODO: take into account ssc structure // main stage @@ -639,7 +639,7 @@ void runLiveVariableAnalysis(const map>& // interprocedural analysis for (auto& calls_vector : live_for_fcalls) { - map assembled_fcalls; + map assembled_fcalls; for (auto& call : calls_vector) { call.updateFromOut(); @@ -649,7 +649,7 @@ void runLiveVariableAnalysis(const map>& auto it = assembled_fcalls.find(call.func); if (it == assembled_fcalls.end()) - it = assembled_fcalls.insert({ call.func, fcall(call.func, call.block, {}) }).first; + it = assembled_fcalls.insert({ call.func, LiveDeadVarsForCall(call.func, call.block, {}) }).first; for (const auto& p : call.live_after) it->second.live_after[p.first].insert(p.second.begin(), p.second.end()); diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h index a697273..d4a2c6a 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h @@ -5,7 +5,9 @@ namespace LIVE_VARIABLES { - struct fcall + /* Store information about live and dead variables after call operator */ + /* (needed for interprocedural part of live variable analysis) */ + class LiveDeadVarsForCall { private: bool tryInsert(std::set& dest, SAPFOR::BasicBlock* b); @@ -21,7 +23,7 @@ namespace LIVE_VARIABLES std::vector params; SAPFOR::BasicBlock* block; - fcall(FuncInfo* f, SAPFOR::BasicBlock* b, const std::vector& p); + LiveDeadVarsForCall(FuncInfo* f, SAPFOR::BasicBlock* b, const std::vector& p); void make_live(SAPFOR::Argument* arg, SAPFOR::BasicBlock* b); void make_dead(SAPFOR::Argument* arg); @@ -39,7 +41,7 @@ void insertIfVar(IT begin, IT end, DEST& to) { void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, std::set& use, std::set& def, - std::vector& formal_parameters, std::vector& fcalls, + std::vector& formal_parameters, std::vector& fcalls, std::vector& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, std::string& fName, const std::map& funcByName, bool interprocedural); diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 9280ecd..f1ad920 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -23,7 +23,7 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru if (fName == "") last_fcall_useful = false; - vector fcalls; + vector fcalls; getUseDefForInstruction(block, instr,