diff options
| author | Devang Patel <dpatel@apple.com> | 2009-03-04 01:22:23 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2009-03-04 01:22:23 +0000 |
| commit | 812459613b657ed45bb40e7c63eed9a3ea3c90dd (patch) | |
| tree | ee77f06df9d02e2f9ef62f886f3073af55ae39bb /llvm/lib | |
| parent | 0365d3b8b566dea07c554e0aa28a2fbc683ddd5a (diff) | |
| download | bcm5719-llvm-812459613b657ed45bb40e7c63eed9a3ea3c90dd.tar.gz bcm5719-llvm-812459613b657ed45bb40e7c63eed9a3ea3c90dd.zip | |
If a global constant is dead then global's debug info should not prevent the optimizer in deleting the global. And while deleting global, delete global's debug info also.
llvm-svn: 65994
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 0a35fa93e43..28cd902472d 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -137,15 +137,23 @@ struct VISIBILITY_HIDDEN GlobalStatus { } /// ConstantIsDead - Return true if the specified constant is (transitively) -/// dead. The constant may be used by other constants (e.g. constant arrays and -/// constant exprs) as long as they are dead, but it cannot be used by anything -/// else. -static bool ConstantIsDead(Constant *C) { +/// dead. The constant may be used by other constants (e.g. constant arrays, +/// constant exprs, constant global variables) as long as they are dead, +/// but it cannot be used by anything else. If DeadGVs is not null then +/// record dead constant GV users. +static bool ConstantIsDead(Constant *C, + SmallPtrSet<GlobalVariable *, 4> *DeadGVs = false) { + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) + if (GV->hasLocalLinkage() && GV->use_empty()) { + if (DeadGVs) + DeadGVs->insert(GV); + return true; + } if (isa<GlobalValue>(C)) return false; for (Value::use_iterator UI = C->use_begin(), E = C->use_end(); UI != E; ++UI) if (Constant *CU = dyn_cast<Constant>(*UI)) { - if (!ConstantIsDead(CU)) return false; + if (!ConstantIsDead(CU, DeadGVs)) return false; } else return false; return true; @@ -338,7 +346,13 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) { } else if (Constant *C = dyn_cast<Constant>(U)) { // If we have a chain of dead constantexprs or other things dangling from // us, and if they are all dead, nuke them without remorse. - if (ConstantIsDead(C)) { + SmallPtrSet<GlobalVariable *, 4> DeadGVs; + if (ConstantIsDead(C, &DeadGVs)) { + for (SmallPtrSet<GlobalVariable *, 4>::iterator TI = DeadGVs.begin(), + TE = DeadGVs.end(); TI != TE; ) { + GlobalVariable *TGV = *TI; ++TI; + TGV->eraseFromParent(); + } C->destroyConstant(); // This could have invalidated UI, start over from scratch. CleanupConstantGlobalUsers(V, Init); |

