diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/CFGraph.h b/sapfor/experts/Sapfor_2017/_src/CFGraph/CFGraph.h index dbe790d..e47447c 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/CFGraph.h +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/CFGraph.h @@ -31,8 +31,8 @@ namespace SAPFOR //live variables [arg -> blocks with usages] std::map> live_in, live_out, live_inout; - bool addLive(const std::map>& to_add, bool in); - std::map> getLive(bool in) const; + bool addLive(const std::map>& to_add, bool in); + std::map> getLive(bool in) const; bool removeLive(SAPFOR::Argument* to_remove, bool in); public: BasicBlock() { num = lastNumBlock++; } @@ -70,14 +70,14 @@ namespace SAPFOR /* * FOR LIVE ANALYSIS */ - bool addLiveIn(const std::map>& to_add) { return addLive(to_add, true); }; - bool addLiveOut(const std::map>& to_add) { return addLive(to_add, false); }; + bool addLiveIn(const std::map>& to_add) { return addLive(to_add, true); }; + bool addLiveOut(const std::map>& to_add) { return addLive(to_add, false); }; bool removeLiveIn(SAPFOR::Argument* to_remove) { return removeLive(to_remove, true); }; bool removeLiveOut(SAPFOR::Argument* to_remove) { return removeLive(to_remove, false); }; - std::map> getLiveIn() const { return getLive(true); }; - std::map> getLiveOut() const { return getLive(false); }; + std::map> getLiveIn() const { return getLive(true); }; + std::map> getLiveOut() const { return getLive(false); }; void compressLives(); /* 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 ccd933e..0836b52 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/live_variable_analysis.cpp @@ -21,15 +21,15 @@ using LIVE_VARIABLES::fcall; namespace SAPFOR { - bool BasicBlock::addLive(const map>& to_add, bool in) { + bool BasicBlock::addLive(const map>& to_add, bool in) { std::map>& current_set = (in ? live_in : live_out); std::map>& opposite_set = (!in ? live_in : live_out); bool inserted = false; for (const auto& byNew : to_add) { - const set& add_in_live = byNew.second; - set new_in_live = {}; + const vector& add_in_live = byNew.second; + vector new_in_live = {}; auto current_set_iter = current_set.find(byNew.first); @@ -128,14 +128,19 @@ namespace SAPFOR return removed; }; - map> BasicBlock::getLive(bool in) const { + map> BasicBlock::getLive(bool in) const { auto& current_set = in ? live_in : live_out; - map> res; + map> res; for (auto& by_source : { current_set, live_inout }) + { for (auto& by_pair : by_source) - res[by_pair.first].insert(by_pair.second.begin(), by_pair.second.end()); + { + auto& dest = res[by_pair.first]; + dest.insert(dest.end(), by_pair.second.begin(), by_pair.second.end()); + } + } return res; } @@ -219,31 +224,31 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, vector& formal_parameters, vector& fcalls, const map& funcByName, bool interprocedural); -class LiveVarAnalysisNode : public DataFlowAnalysisNode>> { +class LiveVarAnalysisNode : public DataFlowAnalysisNode>> { private: set live, dead; public: - map> getIn() + map> getIn() { return getBlock()->getLiveOut(); }; - map> getOut() + map> getOut() { return getBlock()->getLiveIn(); }; - bool addIn(const map>& data) + bool addIn(const map>& data) { return getBlock()->addLiveOut(data); }; - bool addOut(const map>& data) + bool addOut(const map>& data) { return getBlock()->addLiveIn(data); }; - bool forwardData(const map>& data) + bool forwardData(const map>& data) { bool inserted = false; @@ -266,7 +271,7 @@ public: } }; -class LiveVarAnalysis : public BackwardDataFlowAnalysis>, LiveVarAnalysisNode> { +class LiveVarAnalysis : public BackwardDataFlowAnalysis>, LiveVarAnalysisNode> { protected: vector& formal_parameters; vector& fcalls; @@ -694,10 +699,13 @@ void runLiveVariableAnalysis(const map>& { for (const auto& byArg : live_after) { - if (exit->addIn({ byArg })) + map> converted; + converted[byArg.first] = vector(byArg.second.begin(), byArg.second.end()); + + if (exit->addIn(converted)) { exit->setInCnt(max_cnt); - if (exit->forwardData({ byArg })) + if (exit->forwardData(converted)) exit->setOutCnt(max_cnt); } } diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 3c9c548..9280ecd 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -126,7 +126,7 @@ static void buildUseDef(SAPFOR::BasicBlock* block, set& use, } -class DeadCodeAnalysisNode : public DataFlowAnalysisNode>> { +class DeadCodeAnalysisNode : public DataFlowAnalysisNode>> { private: vector useful; bool useful_block = false; @@ -188,15 +188,15 @@ public: return updated; } - map> getIn() { + map> getIn() { return getBlock()->getLiveOut(); }; - map> getOut() { + map> getOut() { return getBlock()->getLiveIn(); }; - bool addIn(const map>& data) { + bool addIn(const map>& data) { bool inserted = getBlock()->addLiveOut(data); if (!useful_block) @@ -207,11 +207,11 @@ public: return inserted; }; - bool addOut(const map>& data) { + bool addOut(const map>& data) { return getBlock()->addLiveIn(data); }; - bool forwardData(const map>& data) { + bool forwardData(const map>& data) { bool inserted = false; SAPFOR::BasicBlock* bb= getBlock(); @@ -298,7 +298,7 @@ public: const vector& getResult() { return useful; }; }; -class DeadCodeAnalysis : public BackwardDataFlowAnalysis>, DeadCodeAnalysisNode> { +class DeadCodeAnalysis : public BackwardDataFlowAnalysis>, DeadCodeAnalysisNode> { protected: vector& formal_parameters;