aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-09-26 05:28:52 +0000
committerChris Lattner <sabre@nondot.org>2005-09-26 05:28:52 +0000
commitebe61201d182123b699241e31d5123206836515c (patch)
treeb86e4a1e7b5ddc2945fa0d54861c98196b1f5a8f
parent363f2a26d599a76905972e63457cee412c18fc85 (diff)
Eliminate GetGEPGlobalInitializer in favor of the more powerful
ConstantFoldLoadThroughGEPConstantExpr function in the utils lib. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23446 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp28
1 files changed, 1 insertions, 27 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index d9d74ca8ea..491ca73fa3 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -756,32 +756,6 @@ void SCCPSolver::visitGetElementPtrInst(GetElementPtrInst &I) {
markConstant(IV, &I, ConstantExpr::getGetElementPtr(Ptr, Operands));
}
-/// GetGEPGlobalInitializer - Given a constant and a getelementptr constantexpr,
-/// return the constant value being addressed by the constant expression, or
-/// null if something is funny.
-///
-static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
- if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType()))
- return 0; // Do not allow stepping over the value!
-
- // Loop over all of the operands, tracking down which value we are
- // addressing...
- for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i)
- if (ConstantUInt *CU = dyn_cast<ConstantUInt>(CE->getOperand(i))) {
- ConstantStruct *CS = dyn_cast<ConstantStruct>(C);
- if (CS == 0) return 0;
- if (CU->getValue() >= CS->getNumOperands()) return 0;
- C = CS->getOperand((unsigned)CU->getValue());
- } else if (ConstantSInt *CS = dyn_cast<ConstantSInt>(CE->getOperand(i))) {
- ConstantArray *CA = dyn_cast<ConstantArray>(C);
- if (CA == 0) return 0;
- if ((uint64_t)CS->getValue() >= CA->getNumOperands()) return 0;
- C = CA->getOperand((unsigned)CS->getValue());
- } else
- return 0;
- return C;
-}
-
void SCCPSolver::visitStoreInst(Instruction &SI) {
if (TrackedGlobals.empty() || !isa<GlobalVariable>(SI.getOperand(1)))
return;
@@ -838,7 +812,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0)))
if (GV->isConstant() && !GV->isExternal())
if (Constant *V =
- GetGEPGlobalInitializer(GV->getInitializer(), CE)) {
+ ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE)) {
markConstant(IV, &I, V);
return;
}