From: David Blaikie Date: Mon, 30 Mar 2015 21:41:43 +0000 (+0000) Subject: [opaque pointer type] Change GetElementPtrInst::getIndexedType to take the pointee... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=25e3d2d6d3f9924328485d1f3937f4674381d34c [opaque pointer type] Change GetElementPtrInst::getIndexedType to take the pointee type This pushes the use of PointerType::getElementType up into several callers - I'll essentially just have to keep pushing that up the stack until I can eliminate every call to it... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233604 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 847c931c8e5..d4fb71f01e3 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -882,9 +882,9 @@ public: /// Null is returned if the indices are invalid for the specified /// pointer type. /// - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); - static Type *getIndexedType(Type *Ptr, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); + static Type *getIndexedType(Type *Ty, ArrayRef IdxList); inline op_iterator idx_begin() { return op_begin()+1; } inline const_op_iterator idx_begin() const { return op_begin()+1; } @@ -915,9 +915,12 @@ public: /// GetGEPReturnType - Returns the pointer type returned by the GEP /// instruction, which may be a vector of pointers. static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) { - Type *PtrTy = PointerType::get(checkGEPType( - getIndexedType(Ptr->getType(), IdxList)), - Ptr->getType()->getPointerAddressSpace()); + Type *PtrTy = + PointerType::get(checkGEPType(getIndexedType( + cast(Ptr->getType()->getScalarType()) + ->getElementType(), + IdxList)), + Ptr->getType()->getPointerAddressSpace()); // Vector GEP if (Ptr->getType()->isVectorTy()) { unsigned NumElem = cast(Ptr->getType())->getNumElements(); diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index be2282f299f..2767e41bee0 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -932,14 +932,14 @@ aliasSameBasePointerGEPs(const GEPOperator *GEP1, uint64_t V1Size, // Also, check that they all index through arrays. for (unsigned i = 1, e = GEP1->getNumIndices() - 1; i != e; ++i) { if (!isa(GetElementPtrInst::getIndexedType( - GEP1->getPointerOperandType(), IntermediateIndices))) + GEP1->getSourceElementType(), IntermediateIndices))) return AliasAnalysis::MayAlias; IntermediateIndices.push_back(GEP1->getOperand(i + 1)); } StructType *LastIndexedStruct = dyn_cast(GetElementPtrInst::getIndexedType( - GEP1->getPointerOperandType(), IntermediateIndices)); + GEP1->getSourceElementType(), IntermediateIndices)); if (!LastIndexedStruct) return AliasAnalysis::MayAlias; diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 995465dcb24..5bc84f43f9e 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -681,8 +681,9 @@ static Constant *CastGEPIndices(ArrayRef Ops, Type *ResultTy, for (unsigned i = 1, e = Ops.size(); i != e; ++i) { if ((i == 1 || !isa(GetElementPtrInst::getIndexedType( - Ops[0]->getType(), - Ops.slice(1, i - 1)))) && + cast(Ops[0]->getType()->getScalarType()) + ->getElementType(), + Ops.slice(1, i - 1)))) && Ops[i]->getType() != IntPtrTy) { Any = true; NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i], diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 99c477d4623..e88232368fd 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -3251,7 +3251,8 @@ static Value *SimplifyGEPInst(ArrayRef Ops, const Query &Q, unsigned) { return Ops[0]; // Compute the (pointer) type returned by the GEP instruction. - Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.slice(1)); + Type *LastType = + GetElementPtrInst::getIndexedType(PtrTy->getElementType(), Ops.slice(1)); Type *GEPTy = PointerType::get(LastType, AS); if (VectorType *VT = dyn_cast(Ops[0]->getType())) GEPTy = VectorType::get(GEPTy, VT->getNumElements()); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 75ff79094a2..dc348e4d4b7 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2831,7 +2831,10 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) { !BasePointerType->getElementType()->isSized(&Visited)) return Error(ID.Loc, "base element of getelementptr must be sized"); - if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices)) + if (!GetElementPtrInst::getIndexedType( + cast(Elts[0]->getType()->getScalarType()) + ->getElementType(), + Indices)) return Error(ID.Loc, "invalid getelementptr indices"); ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices, InBounds); @@ -5523,7 +5526,9 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) { !BasePointerType->getElementType()->isSized(&Visited)) return Error(Loc, "base element of getelementptr must be sized"); - if (!GetElementPtrInst::getIndexedType(BaseType, Indices)) + if (!GetElementPtrInst::getIndexedType( + cast(BaseType->getScalarType())->getElementType(), + Indices)) return Error(Loc, "invalid getelementptr indices"); Inst = GetElementPtrInst::Create(Ty, Ptr, Indices); if (InBounds) diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index 500696ec647..94a39441a13 100644 --- a/lib/IR/ConstantFold.cpp +++ b/lib/IR/ConstantFold.cpp @@ -2031,7 +2031,8 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, if (isa(C)) { PointerType *Ptr = cast(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs); + Type *Ty = GetElementPtrInst::getIndexedType( + cast(Ptr->getScalarType())->getElementType(), Idxs); assert(Ty && "Invalid indices for GEP!"); return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace())); } @@ -2045,7 +2046,8 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C, } if (isNull) { PointerType *Ptr = cast(C->getType()); - Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs); + Type *Ty = GetElementPtrInst::getIndexedType( + cast(Ptr->getScalarType())->getElementType(), Idxs); assert(Ty && "Invalid indices for GEP!"); return ConstantPointerNull::get(PointerType::get(Ty, Ptr->getAddressSpace())); diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index e51a396a0bf..8c6eda2a772 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -2010,7 +2010,8 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, ArrayRef Idxs, return FC; // Fold a few common cases. // Get the result type of the getelementptr! - Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs); + Type *Ty = GetElementPtrInst::getIndexedType( + cast(C->getType()->getScalarType())->getElementType(), Idxs); assert(Ty && "GEP indices invalid!"); unsigned AS = C->getType()->getPointerAddressSpace(); Type *ReqTy = Ty->getPointerTo(AS); diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index af2aeb9ec62..f1dfea956c5 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -1258,11 +1258,7 @@ GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI) /// pointer type. /// template -static Type *getIndexedTypeInternal(Type *Ptr, ArrayRef IdxList) { - PointerType *PTy = dyn_cast(Ptr->getScalarType()); - if (!PTy) return nullptr; // Type isn't a pointer type! - Type *Agg = PTy->getElementType(); - +static Type *getIndexedTypeInternal(Type *Agg, ArrayRef IdxList) { // Handle the special case of the empty set index set, which is always valid. if (IdxList.empty()) return Agg; @@ -1283,17 +1279,17 @@ static Type *getIndexedTypeInternal(Type *Ptr, ArrayRef IdxList) { return CurIdx == IdxList.size() ? Agg : nullptr; } -Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef IdxList) { - return getIndexedTypeInternal(Ptr, IdxList); +Type *GetElementPtrInst::getIndexedType(Type *Ty, ArrayRef IdxList) { + return getIndexedTypeInternal(Ty, IdxList); } -Type *GetElementPtrInst::getIndexedType(Type *Ptr, +Type *GetElementPtrInst::getIndexedType(Type *Ty, ArrayRef IdxList) { - return getIndexedTypeInternal(Ptr, IdxList); + return getIndexedTypeInternal(Ty, IdxList); } -Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef IdxList) { - return getIndexedTypeInternal(Ptr, IdxList); +Type *GetElementPtrInst::getIndexedType(Type *Ty, ArrayRef IdxList) { + return getIndexedTypeInternal(Ty, IdxList); } /// hasAllZeroIndices - Return true if all of the indices of this GEP are diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index a30fedd119d..e5488593b8f 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -2344,7 +2344,7 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { SmallVector Idxs(GEP.idx_begin(), GEP.idx_end()); Type *ElTy = - GetElementPtrInst::getIndexedType(GEP.getPointerOperandType(), Idxs); + GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); Assert(ElTy, "Invalid indices for GEP pointer type!", &GEP); Assert(GEP.getType()->getScalarType()->isPointerTy() && diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 46480bd785a..430df3db486 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -674,8 +674,9 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F, for (ScalarizeTable::iterator SI = ArgIndices.begin(), E = ArgIndices.end(); SI != E; ++SI) { // not allowed to dereference ->begin() if size() is 0 - Params.push_back( - GetElementPtrInst::getIndexedType(I->getType(), SI->second)); + Params.push_back(GetElementPtrInst::getIndexedType( + cast(I->getType()->getScalarType())->getElementType(), + SI->second)); assert(Params.back()); } diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 6b0f268c9c8..3b6f4dbeb20 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -611,8 +611,10 @@ static bool canReplaceGEPIdxWithZero(InstCombiner &IC, GetElementPtrInst *GEPI, return false; SmallVector Ops(GEPI->idx_begin(), GEPI->idx_begin() + Idx); - Type *AllocTy = - GetElementPtrInst::getIndexedType(GEPI->getOperand(0)->getType(), Ops); + Type *AllocTy = GetElementPtrInst::getIndexedType( + cast(GEPI->getOperand(0)->getType()->getScalarType()) + ->getElementType(), + Ops); if (!AllocTy || !AllocTy->isSized()) return false; const DataLayout &DL = IC.getDataLayout();