diff options
author | Dan Gohman <gohman@apple.com> | 2009-07-17 23:55:56 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-07-17 23:55:56 +0000 |
commit | ae402b0e137410b231faca960e4440f76ccf48df (patch) | |
tree | d851a88d72bc9c18dd42143f0fdbef05a31bd405 /lib/VMCore | |
parent | 87409502e7551f359947c62bd6dfef57a22b8ebe (diff) | |
download | external_llvm-ae402b0e137410b231faca960e4440f76ccf48df.zip external_llvm-ae402b0e137410b231faca960e4440f76ccf48df.tar.gz external_llvm-ae402b0e137410b231faca960e4440f76ccf48df.tar.bz2 |
Convert more code to use Operator instead of explicitly handling both
ConstantExpr and Instruction. This involves duplicating some code
between GetElementPtrInst and GEPOperator, but it's not a lot.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76265 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Value.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 3322c68..66fcaf3 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -343,23 +343,12 @@ Value *Value::stripPointerCasts() { return this; Value *V = this; do { - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { - if (CE->getOpcode() == Instruction::GetElementPtr) { - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - if (!CE->getOperand(i)->isNullValue()) - return V; - V = CE->getOperand(0); - } else if (CE->getOpcode() == Instruction::BitCast) { - V = CE->getOperand(0); - } else { - return V; - } - } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V)) { + if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) { if (!GEP->hasAllZeroIndices()) return V; - V = GEP->getOperand(0); - } else if (BitCastInst *CI = dyn_cast<BitCastInst>(V)) { - V = CI->getOperand(0); + V = GEP->getPointerOperand(); + } else if (Operator::getOpcode(V) == Instruction::BitCast) { + V = cast<Operator>(V)->getOperand(0); } else { return V; } @@ -373,12 +362,12 @@ Value *Value::getUnderlyingObject() { Value *V = this; unsigned MaxLookup = 6; do { - if (Operator *O = dyn_cast<Operator>(V)) { - if (O->getOpcode() != Instruction::BitCast && - (O->getOpcode() != Instruction::GetElementPtr || - !cast<GEPOperator>(V)->hasNoPointerOverflow())) + if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) { + if (GEP->hasNoPointerOverflow()) return V; - V = O->getOperand(0); + V = GEP->getPointerOperand(); + } else if (Operator::getOpcode(V) == Instruction::BitCast) { + V = cast<Operator>(V)->getOperand(0); } else { return V; } |