X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FPtrUseVisitor.cpp;h=68c7535ea59438c4871db05ea5c588f9069cd314;hb=813f44a29fd0fd140127023222d0633e23783bcc;hp=b48e86ea6e203a5b36de43e181fe25b82526f1b7;hpb=ed90ed077a58d6eff6aede206273ae0aeefa3a94;p=oota-llvm.git diff --git a/lib/Analysis/PtrUseVisitor.cpp b/lib/Analysis/PtrUseVisitor.cpp index b48e86ea6e2..68c7535ea59 100644 --- a/lib/Analysis/PtrUseVisitor.cpp +++ b/lib/Analysis/PtrUseVisitor.cpp @@ -16,14 +16,13 @@ using namespace llvm; void detail::PtrUseVisitorBase::enqueueUsers(Instruction &I) { - for (Value::use_iterator UI = I.use_begin(), UE = I.use_end(); - UI != UE; ++UI) { - if (VisitedUses.insert(&UI.getUse())) { + for (Use &U : I.uses()) { + if (VisitedUses.insert(&U).second) { UseToVisit NewU = { - UseToVisit::UseAndIsOffsetKnownPair(&UI.getUse(), IsOffsetKnown), + UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown), Offset }; - Worklist.push_back(llvm_move(NewU)); + Worklist.push_back(std::move(NewU)); } } } @@ -32,27 +31,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(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(*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); }