diff options
author | Dan Gohman <gohman@apple.com> | 2009-09-07 22:31:26 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-09-07 22:31:26 +0000 |
commit | fd54a898be08e8da12cb2e99dbb63015083940a3 (patch) | |
tree | fd04d912a722306548770f6c8fb9689ae28c96b5 | |
parent | b73e4aec2e1a45b54130f635699fc32aac8b9750 (diff) | |
download | external_llvm-fd54a898be08e8da12cb2e99dbb63015083940a3.zip external_llvm-fd54a898be08e8da12cb2e99dbb63015083940a3.tar.gz external_llvm-fd54a898be08e8da12cb2e99dbb63015083940a3.tar.bz2 |
Simplify this code by using hasDefinitiveInitializer().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81161 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 4deb3f4..594243c 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2024,20 +2024,21 @@ static Constant *getVal(DenseMap<Value*, Constant*> &ComputedValues, /// we punt. We basically just support direct accesses to globals and GEP's of /// globals. This should be kept up to date with CommitValueTo. static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) { - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { - if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage()) - return false; // do not allow weak/linkonce/dllimport/dllexport linkage. - return !GV->isDeclaration(); // reject external globals. - } + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) + // Do not allow weak/linkonce/dllimport/dllexport linkage or + // external globals. + return GV->hasDefinitiveInitializer(); + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) // Handle a constantexpr gep. if (CE->getOpcode() == Instruction::GetElementPtr && isa<GlobalVariable>(CE->getOperand(0))) { GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0)); - if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage()) - return false; // do not allow weak/linkonce/dllimport/dllexport linkage. - return GV->hasInitializer() && - ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, + // Do not allow weak/linkonce/dllimport/dllexport linkage or + // external globals. + if (!GV->hasDefinitiveInitializer()) + return false; + return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE, Context); } return false; |