From 9bc4fa246cc5d2c9e4736e05196266e72b662e17 Mon Sep 17 00:00:00 2001 From: Mikhail Kocharmin Date: Sun, 7 Apr 2024 17:40:30 +0300 Subject: [PATCH] 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();