[llvm-commits] CVS: llvm/lib/Transforms/Scalar/SCCP.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Sep 25 22:29:03 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
SCCP.cpp updated: 1.124 -> 1.125
---
Log message:
Eliminate GetGEPGlobalInitializer in favor of the more powerful
ConstantFoldLoadThroughGEPConstantExpr function in the utils lib.
---
Diffs of the changes: (+1 -27)
SCCP.cpp | 28 +---------------------------
1 files changed, 1 insertion(+), 27 deletions(-)
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.124 llvm/lib/Transforms/Scalar/SCCP.cpp:1.125
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.124 Sat Apr 23 16:38:35 2005
+++ llvm/lib/Transforms/Scalar/SCCP.cpp Mon Sep 26 00:28:52 2005
@@ -756,32 +756,6 @@
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 @@
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;
}
More information about the llvm-commits
mailing list