summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-10-25 01:58:26 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-10-25 01:58:26 +0000
commit7695cb6da8021ef610ffbcf3b296a16688c7930d (patch)
tree677539396e32cbdeb2d4dd3ad08be42b1c7b9559
parent9825ab04332a6b1b4692385ca86e715eb3f99190 (diff)
downloadbcm5719-llvm-7695cb6da8021ef610ffbcf3b296a16688c7930d.tar.gz
bcm5719-llvm-7695cb6da8021ef610ffbcf3b296a16688c7930d.zip
GlobalDCE: Deduplicate code. NFCI.
llvm-svn: 285048
-rw-r--r--llvm/lib/Transforms/IPO/GlobalDCE.cpp53
1 files changed, 18 insertions, 35 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index 4c74698a1b6..aaa9f899144 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();
OpenPOWER on IntegriCloud