From: Peter Collingbourne Date: Tue, 25 Oct 2016 01:58:26 +0000 (+0000) Subject: GlobalDCE: Deduplicate code. NFCI. X-Git-Tag: llvmorg-4.0.0-rc1~6380 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7695cb6da8021ef610ffbcf3b296a16688c7930d;p=platform%2Fupstream%2Fllvm.git GlobalDCE: Deduplicate code. NFCI. llvm-svn: 285048 --- diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp index 4c74698..aaa9f89 100644 --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -162,45 +162,28 @@ PreservedAnalyses GlobalDCEPass::run(Module &M, ModuleAnalysisManager &) { GIF.setResolver(nullptr); } - if (!DeadFunctions.empty()) { - // Now that all interferences have been dropped, delete the actual objects - // themselves. - for (Function *F : DeadFunctions) { - RemoveUnusedGlobalValue(*F); - M.getFunctionList().erase(F); - } - NumFunctions += DeadFunctions.size(); + // Now that all interferences have been dropped, delete the actual objects + // themselves. + auto EraseUnusedGlobalValue = [&](GlobalValue *GV) { + RemoveUnusedGlobalValue(*GV); + GV->eraseFromParent(); Changed = true; - } + }; - if (!DeadGlobalVars.empty()) { - for (GlobalVariable *GV : DeadGlobalVars) { - RemoveUnusedGlobalValue(*GV); - M.getGlobalList().erase(GV); - } - NumVariables += DeadGlobalVars.size(); - Changed = true; - } + NumFunctions += DeadFunctions.size(); + for (Function *F : DeadFunctions) + EraseUnusedGlobalValue(F); - // Now delete any dead aliases. - if (!DeadAliases.empty()) { - for (GlobalAlias *GA : DeadAliases) { - RemoveUnusedGlobalValue(*GA); - M.getAliasList().erase(GA); - } - NumAliases += DeadAliases.size(); - Changed = true; - } + NumVariables += DeadGlobalVars.size(); + for (GlobalVariable *GV : DeadGlobalVars) + EraseUnusedGlobalValue(GV); - // Now delete any dead aliases. - if (!DeadIFuncs.empty()) { - for (GlobalIFunc *GIF : DeadIFuncs) { - RemoveUnusedGlobalValue(*GIF); - M.getIFuncList().erase(GIF); - } - NumIFuncs += DeadIFuncs.size(); - Changed = true; - } + NumAliases += DeadAliases.size(); + for (GlobalAlias *GA : DeadAliases) + EraseUnusedGlobalValue(GA); + + for (GlobalIFunc *GIF : DeadIFuncs) + EraseUnusedGlobalValue(GIF); // Make sure that all memory is released AliveGlobals.clear();