summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-03-06 01:37:41 +0000
committerDevang Patel <dpatel@apple.com>2009-03-06 01:37:41 +0000
commit743cdf8edf21d96b3d155eb322578936aebc4876 (patch)
treeb9f9f2b4bed8797d9e1ce21979bdf4befed5098b
parent5c6bf65a090e799462af8ce6afbbb6dc1f3f78f5 (diff)
downloadllvm-743cdf8edf21d96b3d155eb322578936aebc4876.tar.gz
llvm-743cdf8edf21d96b3d155eb322578936aebc4876.tar.bz2
llvm-743cdf8edf21d96b3d155eb322578936aebc4876.tar.xz
Revert rev. 66167.
We are still not out of woods yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66232 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp40
-rw-r--r--test/Transforms/GlobalOpt/2009-03-03-dbg.ll1
2 files changed, 10 insertions, 31 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 69753b399d..8362e8c893 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -138,28 +138,17 @@ 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,
-/// 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) {
+/// 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) {
if (isa<GlobalValue>(C)) return false;
- for (Value::use_iterator UI = C->use_begin(), E = C->use_end(); UI != E; ++UI) {
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*UI)) {
- if (!GV->isConstant() || !GV->hasLocalLinkage() || !GV->use_empty())
- return false;
- else {
- if (DeadGVs)
- DeadGVs->insert(GV);
- }
- }
- else if (Constant *CU = dyn_cast<Constant>(*UI)) {
- if (!ConstantIsDead(CU, DeadGVs)) 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;
} else
return false;
- }
return true;
}
@@ -350,19 +339,8 @@ 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.
- 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;
- if (TGV == C)
- C = NULL;
- TGV->eraseFromParent();
- }
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
- GV->eraseFromParent();
- else if (C)
- C->destroyConstant();
+ if (ConstantIsDead(C)) {
+ C->destroyConstant();
// This could have invalidated UI, start over from scratch.
CleanupConstantGlobalUsers(V, Init);
return true;
diff --git a/test/Transforms/GlobalOpt/2009-03-03-dbg.ll b/test/Transforms/GlobalOpt/2009-03-03-dbg.ll
index 13d2f45d7a..1996f62191 100644
--- a/test/Transforms/GlobalOpt/2009-03-03-dbg.ll
+++ b/test/Transforms/GlobalOpt/2009-03-03-dbg.ll
@@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -globalopt | llvm-dis | not grep global_variable42
+; XFAIL: *
%llvm.dbg.anchor.type = type { i32, i32 }
%llvm.dbg.basictype.type = type { i32, { }*, i8*, { }*, i32, i64, i64, i64, i32, i32 }