From: Chris Lattner Date: Tue, 25 Nov 2003 20:19:55 +0000 (+0000) Subject: Do not depend on index type to determine whether it is a structure or sequential... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fa3711a0f894a67ad0e022f4a638b53ed3036784;p=oota-llvm.git Do not depend on index type to determine whether it is a structure or sequential index git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10221 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp index a7cf854c47e..5cafefaff44 100644 --- a/lib/Analysis/DataStructure/Local.cpp +++ b/lib/Analysis/DataStructure/Local.cpp @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" +#include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/InstVisitor.h" #include "llvm/Target/TargetData.h" #include "Support/CommandLine.h" @@ -366,12 +367,17 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) { // All of these subscripts are indexing INTO the elements we have... unsigned Offset = 0; - for (unsigned i = 2, e = GEP.getNumOperands(); i < e; ++i) - if (GEP.getOperand(i)->getType() == Type::LongTy) { - // Get the type indexing into... - const SequentialType *STy = cast(CurTy); - CurTy = STy->getElementType(); + for (gep_type_iterator I = gep_type_begin(GEP), E = gep_type_end(GEP); + I != E; ++I) + if (const StructType *STy = dyn_cast(*I)) { + unsigned FieldNo = cast(I.getOperand())->getValue(); + Offset += TD.getStructLayout(STy)->MemberOffsets[FieldNo]; + } + + #if 0 + if (const SequentialType *STy = cast(*I)) { + CurTy = STy->getElementType(); if (ConstantSInt *CS = dyn_cast(GEP.getOperand(i))) { Offset += CS->getValue()*TD.getTypeSize(CurTy); } else { @@ -394,13 +400,8 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) { N->mergeIndexes(RawOffset+j, RawOffset+i*ElSize+j); } } -#endif - } else if (GEP.getOperand(i)->getType() == Type::UByteTy) { - unsigned FieldNo = cast(GEP.getOperand(i))->getValue(); - const StructType *STy = cast(CurTy); - Offset += TD.getStructLayout(STy)->MemberOffsets[FieldNo]; - CurTy = STy->getContainedType(FieldNo); } +#endif // Add in the offset calculated... Value.setOffset(Value.getOffset()+Offset);