From e33fe45a2b9baf7bfe74d6abe8fad9605b52e55d Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sun, 7 Apr 2024 16:38:57 +0300 Subject: [PATCH 1/6] handle contains statement while removing dead code, fix getLive method --- .../_src/CFGraph/live_variable_analysis.cpp | 7 +++- .../_src/Transformations/dead_code.cpp | 33 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) 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 ad41626..05f6bfb 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp @@ -8,6 +8,7 @@ #include #include #include +#include using std::string; using std::pair; @@ -138,7 +139,11 @@ namespace SAPFOR for (auto& by_pair : by_source) { auto& dest = res[by_pair.first]; - dest.insert(dest.end(), by_pair.second.begin(), by_pair.second.end()); + auto dest_copy = dest; + + dest.resize(dest_copy.size() + by_pair.second.size()); + + set_union(dest_copy.begin(), dest_copy.end(), by_pair.second.begin(), by_pair.second.end(), dest.begin()); } } diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 659eef7..0db25af 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -503,12 +503,29 @@ void removeDeadCode(SgStatement* func, READ_STAT }; + set skip = + { + PROG_HEDR, + PROC_HEDR, + FUNC_HEDR + }; + vector remove; SgStatement* start = intervalDelStart ? intervalDelStart : func; SgStatement* end = intervalDelEnd ? intervalDelEnd : func->lastNodeOfStmt(); - for (auto st = start; st != end; st = st->lexNext()) + auto st = start; + if (skip.find(st->variant()) != skip.end()) + st = st->lexNext(); + + for (; st != end; st = st->lexNext()) { + if (skip.find(st->variant()) != skip.end()) + { + st = st->lastNodeOfStmt(); + continue; + } + if (removable.find(st->variant()) != removable.end() && useful.find(st) == useful.end()) { remove.push_back(st); @@ -526,9 +543,21 @@ void removeDeadCode(SgStatement* func, do { remove.clear(); - for (auto st = start; st != end; st = st->lexNext()) + + st = start; + if (skip.find(st->variant()) != skip.end()) + st = st->lexNext(); + + for (; st != end; st = st->lexNext()) { const int var = st->variant(); + + if (skip.find(var) != skip.end()) + { + st = st->lastNodeOfStmt(); + continue; + } + if ((var == FOR_NODE || var == WHILE_NODE || var == SWITCH_NODE) && st->lexNext()->variant() == CONTROL_END) { From 9bc4fa246cc5d2c9e4736e05196266e72b662e17 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sun, 7 Apr 2024 17:40:30 +0300 Subject: [PATCH 2/6] dead code: improve perfomance by removing unnecessary checks --- .../_src/Transformations/dead_code.cpp | 57 +++---------------- 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 0db25af..5befc48 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -16,39 +16,6 @@ using std::remove_if; #define PRINT_USELESS_STATEMENTS 1 #define DEBUG_IR 0 -// detect wich registers are used at more than one block -// such registers should participate in live analysis to spread information about useful instructions -// such registers appears at loops -static void fillSharedRegs(const map>& cfg, set& shared_regs) -{ - map used_at; - - for (const auto& byFunc : cfg) - { - for (const auto& byBlock : byFunc.second) - { - for (const auto& byIrBlock : byBlock->getInstructions()) - { - auto instr = byIrBlock->getInstruction(); - - set used = { instr->getResult(), instr->getArg1(), instr->getArg2() }; - for (auto arg : used) - { - if(arg && arg->getType() == SAPFOR::CFG_ARG_TYPE::REG) - { - auto it = used_at.find(arg); - - if (it == used_at.end()) - used_at[arg] = byBlock; - else if(it->second != byBlock) - shared_regs.insert(arg); - } - } - } - } - } -} - static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, set& use, set& def, vector& formal_parameters, @@ -179,7 +146,6 @@ private: vector& formal_parameters; const map& funcByName; - const set& shared_regs; public: bool updateJumpStatus() { @@ -284,8 +250,7 @@ public: for (SAPFOR::Argument* arg : use) { - if(arg && (arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR || - (arg->getType() == SAPFOR::CFG_ARG_TYPE::REG && shared_regs.find(arg) != shared_regs.end()))) + if(arg && (arg->getType() == SAPFOR::CFG_ARG_TYPE::VAR || arg->getType() == SAPFOR::CFG_ARG_TYPE::REG)) { bool this_block = usedByThisBlock.find(arg) != usedByThisBlock.end(); @@ -344,12 +309,10 @@ public: DeadCodeAnalysisNode(SAPFOR::BasicBlock* block, vector& formal_parameters, - const map& funcByName, - const set& shared_regs) + const map& funcByName) : formal_parameters(formal_parameters), - funcByName(funcByName), - shared_regs(shared_regs) + funcByName(funcByName) { setBlock(block); useful.resize(block->getInstructions().size(), false); @@ -363,20 +326,17 @@ class DeadCodeAnalysis : public BackwardDataFlowAnalysis protected: vector& formal_parameters; const map& funcByName; - const set& shared_regs; DeadCodeAnalysisNode* createNode(SAPFOR::BasicBlock* block) override { - return new DeadCodeAnalysisNode(block, formal_parameters, funcByName, shared_regs); + return new DeadCodeAnalysisNode(block, formal_parameters, funcByName); } public: DeadCodeAnalysis(vector& formal_parameters, - const map& funcByName, - const set& shared_regs) + const map& funcByName) : formal_parameters(formal_parameters), - funcByName(funcByName), - shared_regs(shared_regs) + funcByName(funcByName) { } }; @@ -459,11 +419,8 @@ void removeDeadCode(SgStatement* func, for (auto& byFile : allFuncs) for (auto byFunc : byFile.second) funcByName[byFunc->funcName] = byFunc; - - set shared_regs; - fillSharedRegs({ cfg_pair }, shared_regs); - DeadCodeAnalysis analysis_object(func_parameters, funcByName, shared_regs); + DeadCodeAnalysis analysis_object(func_parameters, funcByName); analysis_object.fit(cfg_pair.second); analysis_object.analyze(); From 494a70593002380145f768f24dfce6299f12654c Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sun, 7 Apr 2024 19:06:33 +0300 Subject: [PATCH 3/6] data flow: perfomance improvement --- .../_src/CFGraph/DataFlow/data_flow_impl.h | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/DataFlow/data_flow_impl.h b/sapfor/experts/Sapfor_2017/_src/CFGraph/DataFlow/data_flow_impl.h index db33e73..cb8ae41 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/DataFlow/data_flow_impl.h +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/DataFlow/data_flow_impl.h @@ -33,20 +33,18 @@ void DataFlowAnalysisNode::doStep() { if (in_cnt < next->out_cnt) { - for (const auto& byOut : next->getOut()) + const auto& byOut = next->getOut(); + bool inserted = addIn( byOut); + + if (inserted) { - bool inserted = addIn({ byOut }); + if (next->out_cnt > in_max_cnt) + in_max_cnt = next->out_cnt; - if (inserted) - { - if (next->out_cnt > in_max_cnt) - in_max_cnt = next->out_cnt; + inserted = forwardData(byOut); - inserted = forwardData({ byOut }); - - if (inserted && next->out_cnt > out_max_cnt) - out_max_cnt = next->out_cnt; - } + if (inserted && next->out_cnt > out_max_cnt) + out_max_cnt = next->out_cnt; } } } From ff2a1c69d87968c69d7c131b5bbbba48d62453ce Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Wed, 10 Apr 2024 18:58:46 +0300 Subject: [PATCH 4/6] dead code: fix for entry statements, improve perfomance --- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 3 ++- .../Sapfor_2017/_src/Transformations/dead_code.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index e17ee2c..a99aa49 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -1028,7 +1028,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne { auto funcsForFile = getObjectForFileFromMap(file_name, allFuncInfo); for (auto& func : funcsForFile) - removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks); + if(func->funcPointer->variant() != ENTRY_STAT) + removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks); } else if (curr_regime == TEST_PASS) { diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 5befc48..1e11a48 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -228,7 +228,9 @@ public: updated |= updateNextNotEmpty(); updated |= updateJumpStatus(); - updated |= this->forwardData({ }); + + if(updated) + this->forwardData({ }); return updated; } @@ -316,6 +318,7 @@ public: { setBlock(block); useful.resize(block->getInstructions().size(), false); + this->forwardData({ }); } const vector& getResult() { return useful; } @@ -371,7 +374,8 @@ void removeDeadCode(SgStatement* func, set reachable; for (auto b : cfg_pair.second) - if(b->getInstructions().front()->isHeader()) + if(b->getInstructions().front()->isHeader() || + b->getInstructions().front()->getInstruction()->getOperation() == SAPFOR::CFG_OP::ENTRY) reachable.insert(b); set worklist = reachable; From aace0bf06f6ec6852a4ae06410506c2dafaf6e93 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Wed, 10 Apr 2024 19:04:25 +0300 Subject: [PATCH 5/6] dead code: add static const qualifier to constant sets --- .../experts/Sapfor_2017/_src/Transformations/dead_code.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 1e11a48..b9f58c7 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -52,7 +52,7 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru if (!useful) { - set always_useful = + static const set always_useful = { SAPFOR::CFG_OP::POINTER_ASS, SAPFOR::CFG_OP::STORE, @@ -456,7 +456,7 @@ void removeDeadCode(SgStatement* func, } // remove dead statements - set removable = + static const set removable = { ASSIGN_STAT, PROC_STAT, @@ -464,7 +464,7 @@ void removeDeadCode(SgStatement* func, READ_STAT }; - set skip = + static const set skip = { PROG_HEDR, PROC_HEDR, From a827c405438b13dafcd79da24465f299df39e108 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Wed, 10 Apr 2024 22:03:27 +0300 Subject: [PATCH 6/6] dead code: handle STORE and LOAD instructions --- .../_src/CFGraph/live_variable_analysis.cpp | 138 ++++++++++-------- .../_src/CFGraph/live_variable_analysis.h | 3 +- .../_src/Transformations/dead_code.cpp | 35 +++-- 3 files changed, 101 insertions(+), 75 deletions(-) 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 05f6bfb..841882e 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp @@ -294,39 +294,46 @@ public: void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, set& use, set& def, vector& formal_parameters, vector& fcalls, - vector& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, + vector& arg_stack, int& arg_stack_index, int& arg_stack_size, + bool& last_stack_op, string& fName, const map& funcByName, bool interprocedural) { for (auto arg : { instr->getArg1(), instr->getArg2(), instr->getResult() }) if (arg && arg->getMemType() == SAPFOR::CFG_MEM_TYPE::FUNC_PARAM_) formal_parameters[getParamIndex(arg, formal_parameters.size())] = arg; + last_stack_op = false; SAPFOR::Argument* res_arg = NULL; static const set skip = { SAPFOR::CFG_OP::ENTRY }; SAPFOR::CFG_OP instr_operation = instr->getOperation(); - if (hasStoreStructure(instr_operation)) + if (instr_operation == SAPFOR::CFG_OP::F_CALL || + instr_operation == SAPFOR::CFG_OP::STORE || + instr_operation == SAPFOR::CFG_OP::LOAD) + { + res_arg = (instr_operation == SAPFOR::CFG_OP::STORE ? instr->getArg1() : instr->getResult()); + if(instr_operation != SAPFOR::CFG_OP::F_CALL) + use.insert(instr_operation != SAPFOR::CFG_OP::STORE ? instr->getArg1() : instr->getResult()); + + arg_stack_size = stoi(instr->getArg2()->getValue()); + + arg_stack.clear(); + arg_stack.resize(arg_stack_size); + + arg_stack_index = arg_stack_size - 1; + + if(instr_operation == SAPFOR::CFG_OP::F_CALL) + fName = instr->getArg1()->getValue(); + } + else if (hasStoreStructure(instr_operation)) { res_arg = instr->getArg1(); set instr_args = { instr->getResult(), instr->getArg2() }; use.insert(instr_args.begin(), instr_args.end()); } - else if (instr_operation == SAPFOR::CFG_OP::PARAM) + else if (instr_operation == SAPFOR::CFG_OP::PARAM || instr_operation == SAPFOR::CFG_OP::REF) { - lastParamRef[last_param_ref_index--] = instr->getArg1(); - } - else if (instr_operation == SAPFOR::CFG_OP::F_CALL) - { - res_arg = instr->getResult(); - - last_param_ref_size = stoi(instr->getArg2()->getValue()); - - lastParamRef.clear(); - lastParamRef.resize(last_param_ref_size); - - last_param_ref_index = last_param_ref_size - 1; - - fName = instr->getArg1()->getValue(); + arg_stack[arg_stack_index--] = instr->getArg1(); } else if (skip.find(instr_operation) == skip.end()) { @@ -341,50 +348,60 @@ void getUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* ins return; } - if ((instr_operation == SAPFOR::CFG_OP::F_CALL || instr_operation == SAPFOR::CFG_OP::PARAM) && last_param_ref_index < 0) { - auto func_it = funcByName.find(fName); - if (interprocedural && func_it != funcByName.end()) + if (arg_stack_index < 0) { + if(instr_operation == SAPFOR::CFG_OP::PARAM || instr_operation == SAPFOR::CFG_OP::F_CALL) { - fcalls.push_back(LiveDeadVarsForCall(func_it->second, block, lastParamRef)); - - auto r_it = fcalls.rbegin(); - auto r_end = fcalls.rend(); - - for (auto e : def) - r_it->make_dead(e); - - for (auto e : use) - r_it->make_live(e, block); - } - - set make_live, make_dead; - if (fName == "_READ") - def.insert(lastParamRef.begin(), lastParamRef.end()); - else if (interprocedural && getLiveDead(lastParamRef, fName, make_live, make_dead)) - { - use.insert(make_live.begin(), make_live.end()); - def.insert(make_dead.begin(), make_dead.end()); - } - else if (func_it != funcByName.end()) - { - int arg_num = lastParamRef.size(); - for (int i = 0; i < arg_num; i++) + auto func_it = funcByName.find(fName); + if (interprocedural && func_it != funcByName.end()) { - if(func_it->second->funcParams.isArgOut(i)) - def.insert(lastParamRef[i]); + fcalls.push_back(LiveDeadVarsForCall(func_it->second, block, arg_stack)); - if (func_it->second->funcParams.isArgIn(i)) - use.insert(lastParamRef[i]); + auto r_it = fcalls.rbegin(); + auto r_end = fcalls.rend(); + + for (auto e : def) + r_it->make_dead(e); + + for (auto e : use) + r_it->make_live(e, block); } + + set make_live, make_dead; + if (fName == "_READ") + def.insert(arg_stack.begin(), arg_stack.end()); + else if (interprocedural && getLiveDead(arg_stack, fName, make_live, make_dead)) + { + use.insert(make_live.begin(), make_live.end()); + def.insert(make_dead.begin(), make_dead.end()); + } + else if (func_it != funcByName.end()) + { + int arg_num = arg_stack.size(); + for (int i = 0; i < arg_num; i++) + { + if(func_it->second->funcParams.isArgOut(i)) + def.insert(arg_stack[i]); + + if (func_it->second->funcParams.isArgIn(i)) + use.insert(arg_stack[i]); + } + } + else + use.insert(arg_stack.begin(), arg_stack.end()); + + fName = ""; + } + else + { + use.insert(arg_stack.begin(), arg_stack.end()); } - else - use.insert(lastParamRef.begin(), lastParamRef.end()); - last_param_ref_index = 0; - last_param_ref_size = 0; + arg_stack_index = 0; + arg_stack_size = 0; - lastParamRef.clear(); - fName = ""; + arg_stack.clear(); + + last_stack_op = true; } if (res_arg) @@ -394,15 +411,16 @@ 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& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, + vector& arg_stack, int& arg_stack_index, int& arg_stack_size, string& fName, const map& funcByName, bool interprocedural) { set res, args; - + bool last_stack_op; getUseDefForInstruction(block, instr, args, res, formal_parameters, fcalls, - lastParamRef, last_param_ref_index, last_param_ref_size, + arg_stack, arg_stack_index, arg_stack_size, + last_stack_op, fName, funcByName, interprocedural ); @@ -431,8 +449,8 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, vector& formal_parameters, vector& fcalls, const map& funcByName, bool interprocedural) { - vector lastParamRef; - int last_param_ref_index = 0, last_param_ref_size = 0; + vector arg_stack; + int arg_stack_index = 0, arg_stack_size = 0; string fName; const auto& instructions = block->getInstructions(); @@ -443,7 +461,7 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, updateUseDefForInstruction(block, (*ir_block_it)->getInstruction(), use, def, formal_parameters, fcalls, - lastParamRef, last_param_ref_index, last_param_ref_size, + arg_stack, arg_stack_index, arg_stack_size, fName, funcByName, interprocedural ); 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 7e6cd73..9b92523 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.h @@ -42,7 +42,8 @@ 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& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, + std::vector& arg_stack, int& arg_stack_index, int& arg_stack_size, + bool& last_stack_op, std::string& fName, const std::map& funcByName, bool interprocedural); void runLiveVariableAnalysis(const std::map>& CFGraph_for_project); diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index b9f58c7..fb4cfba 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -19,23 +19,27 @@ using std::remove_if; static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instruction* instr, set& use, set& def, vector& formal_parameters, - vector& lastParamRef, int& last_param_ref_index, int& last_param_ref_size, + vector& arg_stack, int& arg_stack_index, int& arg_stack_size, string& fName, const map& funcByName, - bool& useful, bool& last_fcall_useful, + bool& useful, bool& last_stack_op_useful, set& usedByThisBlock) { set res, args; + bool last_stack_op; vector fcalls; getUseDefForInstruction(block, instr, args, res, formal_parameters, fcalls, - lastParamRef, last_param_ref_index, last_param_ref_size, + arg_stack, arg_stack_index, arg_stack_size, + last_stack_op, fName, funcByName, false ); + const auto instr_operation = instr->getOperation(); + if (!useful) { for (SAPFOR::Argument* r : res) @@ -64,21 +68,24 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru SAPFOR::CFG_OP::SPF_DIR }; - if (always_useful.find(instr->getOperation()) != always_useful.end()) + if (always_useful.find(instr_operation) != always_useful.end()) useful = true; - else if (instr->getOperation() == SAPFOR::CFG_OP::F_CALL) + else if (instr_operation == SAPFOR::CFG_OP::F_CALL) { auto func_it = funcByName.find(instr->getArg1()->getValue()); useful |= func_it == funcByName.end() || !(func_it->second->isPure); } - else if (instr->getOperation() == SAPFOR::CFG_OP::PARAM) - useful |= last_fcall_useful; + else if (instr_operation == SAPFOR::CFG_OP::PARAM || + instr_operation == SAPFOR::CFG_OP::REF) + useful |= last_stack_op_useful; } if (useful) { - if (instr->getOperation() == SAPFOR::CFG_OP::F_CALL) - last_fcall_useful = true; + if (instr_operation == SAPFOR::CFG_OP::F_CALL || + instr_operation == SAPFOR::CFG_OP::LOAD || + instr_operation == SAPFOR::CFG_OP::STORE) + last_stack_op_useful = true; for (auto e : res) { @@ -95,8 +102,8 @@ static void updateUseDefForInstruction(SAPFOR::BasicBlock* block, SAPFOR::Instru usedByThisBlock.insert(args.begin(), args.end()); } - if ((instr->getOperation() == SAPFOR::CFG_OP::F_CALL || instr->getOperation() == SAPFOR::CFG_OP::PARAM) && fName == "") - last_fcall_useful = false; + if (last_stack_op) + last_stack_op_useful = false; } @@ -107,8 +114,8 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, { set use_with_regs = use, def_with_regs = def; - vector lastParamRef; - int last_param_ref_index = 0, last_param_ref_size = 0; + vector arg_stack; + int arg_stack_index = 0, arg_stack_size = 0; string fName = ""; bool last_fcall_useful = false; @@ -122,7 +129,7 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, updateUseDefForInstruction(block, instructions[i]->getInstruction(), use_with_regs, def_with_regs, formal_parameters, - lastParamRef, last_param_ref_index, last_param_ref_size, + arg_stack, arg_stack_index, arg_stack_size, fName, funcByName, u, last_fcall_useful, usedByThisBlock