diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-12-11 10:29:10 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-12-11 10:29:10 +0000 |
commit | 1e14053d84bc31f0f3cecf21816a4733f952be68 (patch) | |
tree | d457e3a6e8f1e226510a3f8f78c8c9dd325d0859 /llvm/lib/Analysis/PtrUseVisitor.cpp | |
parent | b31465b09b31a77cc4964b502d969441a25127af (diff) | |
download | bcm5719-llvm-1e14053d84bc31f0f3cecf21816a4733f952be68.tar.gz bcm5719-llvm-1e14053d84bc31f0f3cecf21816a4733f952be68.zip |
Hoist the GEP constant address offset computation to a common home on
the GEP instruction class.
This is part of the continued refactoring and cleaning of the
infrastructure used by SROA. This particular operation is also done in
a few other places which I'll try to refactor to share this
implementation.
llvm-svn: 169852
Diffstat (limited to 'llvm/lib/Analysis/PtrUseVisitor.cpp')
-rw-r--r-- | llvm/lib/Analysis/PtrUseVisitor.cpp | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/llvm/lib/Analysis/PtrUseVisitor.cpp b/llvm/lib/Analysis/PtrUseVisitor.cpp index b48e86ea6e2..0a342b2167e 100644 --- a/llvm/lib/Analysis/PtrUseVisitor.cpp +++ b/llvm/lib/Analysis/PtrUseVisitor.cpp @@ -32,27 +32,5 @@ bool detail::PtrUseVisitorBase::adjustOffsetForGEP(GetElementPtrInst &GEPI) { if (!IsOffsetKnown) return false; - for (gep_type_iterator GTI = gep_type_begin(GEPI), GTE = gep_type_end(GEPI); - GTI != GTE; ++GTI) { - ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand()); - if (!OpC) - return false; - if (OpC->isZero()) - continue; - - // Handle a struct index, which adds its field offset to the pointer. - if (StructType *STy = dyn_cast<StructType>(*GTI)) { - unsigned ElementIdx = OpC->getZExtValue(); - const StructLayout *SL = DL.getStructLayout(STy); - Offset += APInt(Offset.getBitWidth(), - SL->getElementOffset(ElementIdx)); - continue; - } - - // For array or vector indices, scale the index by the size of the type. - APInt Index = OpC->getValue().sextOrTrunc(Offset.getBitWidth()); - Offset += Index * APInt(Offset.getBitWidth(), - DL.getTypeAllocSize(GTI.getIndexedType())); - } - return true; + return GEPI.accumulateConstantOffset(DL, Offset); } |