llvm.org GIT mirror llvm / a920310
Convert GetElementPtrInst to use ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135904 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 9 years ago
25 changed file(s) with 106 addition(s) and 311 deletion(s). Raw diff Collapse all Expand all
638638
  • FindInsertedValue (in llvm/Analysis/ValueTracking.h)
  • 639639
  • gep_type_begin (in llvm/Support/GetElementPtrTypeIterator.h)
  • 640640
  • gep_type_end (in llvm/Support/GetElementPtrTypeIterator.h)
  • 641
  • GetElementPtrInst::Create
  • 642
  • GetElementPtrInst::CreateInBounds
  • 643
  • GetElementPtrInst::getIndexedType
  • 641644
  • InsertValueInst::Create
  • 642645
  • InsertValueInst::getIndices
  • 643646
  • InvokeInst::Create
  • 284284 ///
    285285 class GetElementPtrInst : public Instruction {
    286286 GetElementPtrInst(const GetElementPtrInst &GEPI);
    287 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
    288 const Twine &NameStr);
    289 void init(Value *Ptr, Value *Idx, const Twine &NameStr);
    290
    291 template
    292 void init(Value *Ptr,
    293 RandomAccessIterator IdxBegin,
    294 RandomAccessIterator IdxEnd,
    295 const Twine &NameStr,
    296 // This argument ensures that we have an iterator we can
    297 // do arithmetic on in constant time
    298 std::random_access_iterator_tag) {
    299 unsigned NumIdx = static_cast(std::distance(IdxBegin, IdxEnd));
    300
    301 if (NumIdx > 0) {
    302 // This requires that the iterator points to contiguous memory.
    303 init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
    304 // we have to build an array here
    305 }
    306 else {
    307 init(Ptr, 0, NumIdx, NameStr);
    308 }
    309 }
    310
    311 /// getIndexedType - Returns the type of the element that would be loaded with
    312 /// a load instruction with the specified parameters.
    313 ///
    314 /// Null is returned if the indices are invalid for the specified
    315 /// pointer type.
    316 ///
    317 template
    318 static Type *getIndexedType(Type *Ptr,
    319 RandomAccessIterator IdxBegin,
    320 RandomAccessIterator IdxEnd,
    321 // This argument ensures that we
    322 // have an iterator we can do
    323 // arithmetic on in constant time
    324 std::random_access_iterator_tag) {
    325 unsigned NumIdx = static_cast(std::distance(IdxBegin, IdxEnd));
    326
    327 if (NumIdx > 0)
    328 // This requires that the iterator points to contiguous memory.
    329 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
    330 else
    331 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
    332 }
    287 void init(Value *Ptr, ArrayRef IdxList, const Twine &NameStr);
    333288
    334289 /// Constructors - Create a getelementptr instruction with a base pointer an
    335290 /// list of indices. The first ctor can optionally insert before an existing
    336291 /// instruction, the second appends the new instruction to the specified
    337292 /// BasicBlock.
    338 template
    339 inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
    340 RandomAccessIterator IdxEnd,
    341 unsigned Values,
    342 const Twine &NameStr,
    293 inline GetElementPtrInst(Value *Ptr, ArrayRef IdxList,
    294 unsigned Values, const Twine &NameStr,
    343295 Instruction *InsertBefore);
    344 template
    345 inline GetElementPtrInst(Value *Ptr,
    346 RandomAccessIterator IdxBegin,
    347 RandomAccessIterator IdxEnd,
    348 unsigned Values,
    349 const Twine &NameStr, BasicBlock *InsertAtEnd);
    350
    351 /// Constructors - These two constructors are convenience methods because one
    352 /// and two index getelementptr instructions are so common.
    353 GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
    354 Instruction *InsertBefore = 0);
    355 GetElementPtrInst(Value *Ptr, Value *Idx,
    356 const Twine &NameStr, BasicBlock *InsertAtEnd);
    296 inline GetElementPtrInst(Value *Ptr, ArrayRef IdxList,
    297 unsigned Values, const Twine &NameStr,
    298 BasicBlock *InsertAtEnd);
    357299 protected:
    358300 virtual GetElementPtrInst *clone_impl() const;
    359301 public:
    360 template
    361 static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
    362 RandomAccessIterator IdxEnd,
    302 static GetElementPtrInst *Create(Value *Ptr, ArrayRef IdxList,
    363303 const Twine &NameStr = "",
    364304 Instruction *InsertBefore = 0) {
    365 typename std::iterator_traits::difference_type
    366 Values = 1 + std::distance(IdxBegin, IdxEnd);
    305 unsigned Values = 1 + unsigned(IdxList.size());
    367306 return new(Values)
    368 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
    369 }
    370 template
    371 static GetElementPtrInst *Create(Value *Ptr,
    372 RandomAccessIterator IdxBegin,
    373 RandomAccessIterator IdxEnd,
    307 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
    308 }
    309 static GetElementPtrInst *Create(Value *Ptr, ArrayRef IdxList,
    374310 const Twine &NameStr,
    375311 BasicBlock *InsertAtEnd) {
    376 typename std::iterator_traits::difference_type
    377 Values = 1 + std::distance(IdxBegin, IdxEnd);
    312 unsigned Values = 1 + unsigned(IdxList.size());
    378313 return new(Values)
    379 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
    380 }
    381
    382 /// Constructors - These two creators are convenience methods because one
    383 /// index getelementptr instructions are so common.
    384 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
    385 const Twine &NameStr = "",
    386 Instruction *InsertBefore = 0) {
    387 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
    388 }
    389 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
    390 const Twine &NameStr,
    391 BasicBlock *InsertAtEnd) {
    392 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
    314 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
    393315 }
    394316
    395317 /// Create an "inbounds" getelementptr. See the documentation for the
    396318 /// "inbounds" flag in LangRef.html for details.
    397 template
    398319 static GetElementPtrInst *CreateInBounds(Value *Ptr,
    399 RandomAccessIterator IdxBegin,
    400 RandomAccessIterator IdxEnd,
    320 ArrayRef IdxList,
    401321 const Twine &NameStr = "",
    402322 Instruction *InsertBefore = 0) {
    403 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
    404 NameStr, InsertBefore);
    323 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
    405324 GEP->setIsInBounds(true);
    406325 return GEP;
    407326 }
    408 template
    409327 static GetElementPtrInst *CreateInBounds(Value *Ptr,
    410 RandomAccessIterator IdxBegin,
    411 RandomAccessIterator IdxEnd,
    328 ArrayRef IdxList,
    412329 const Twine &NameStr,
    413330 BasicBlock *InsertAtEnd) {
    414 GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
    415 NameStr, InsertAtEnd);
    416 GEP->setIsInBounds(true);
    417 return GEP;
    418 }
    419 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
    420 const Twine &NameStr = "",
    421 Instruction *InsertBefore = 0) {
    422 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
    423 GEP->setIsInBounds(true);
    424 return GEP;
    425 }
    426 static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
    427 const Twine &NameStr,
    428 BasicBlock *InsertAtEnd) {
    429 GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
    331 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
    430332 GEP->setIsInBounds(true);
    431333 return GEP;
    432334 }
    445347 /// Null is returned if the indices are invalid for the specified
    446348 /// pointer type.
    447349 ///
    448 template
    449 static Type *getIndexedType(Type *Ptr, RandomAccessIterator IdxBegin,
    450 RandomAccessIterator IdxEnd) {
    451 return getIndexedType(Ptr, IdxBegin, IdxEnd,
    452 typename std::iterator_traits::
    453 iterator_category());
    454 }
    455
    456 // FIXME: Use ArrayRef
    457 static Type *getIndexedType(Type *Ptr,
    458 Value* const *Idx, unsigned NumIdx);
    459 static Type *getIndexedType(Type *Ptr,
    460 Constant* const *Idx, unsigned NumIdx);
    461
    462 static Type *getIndexedType(Type *Ptr,
    463 uint64_t const *Idx, unsigned NumIdx);
    464 static Type *getIndexedType(Type *Ptr, Value *Idx);
    350 static Type *getIndexedType(Type *Ptr, ArrayRef IdxList);
    351 static Type *getIndexedType(Type *Ptr, ArrayRef IdxList);
    352 static Type *getIndexedType(Type *Ptr, ArrayRef IdxList);
    465353
    466354 inline op_iterator idx_begin() { return op_begin()+1; }
    467355 inline const_op_iterator idx_begin() const { return op_begin()+1; }
    529417 public VariadicOperandTraits {
    530418 };
    531419
    532 template
    533420 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
    534 RandomAccessIterator IdxBegin,
    535 RandomAccessIterator IdxEnd,
    421 ArrayRef IdxList,
    536422 unsigned Values,
    537423 const Twine &NameStr,
    538424 Instruction *InsertBefore)
    539425 : Instruction(PointerType::get(checkGEPType(
    540 getIndexedType(Ptr->getType(),
    541 IdxBegin, IdxEnd)),
    426 getIndexedType(Ptr->getType(), IdxList)),
    542427 cast(Ptr->getType())
    543428 ->getAddressSpace()),
    544429 GetElementPtr,
    545430 OperandTraits::op_end(this) - Values,
    546431 Values, InsertBefore) {
    547 init(Ptr, IdxBegin, IdxEnd, NameStr,
    548 typename std::iterator_traits
    549 ::iterator_category());
    432 init(Ptr, IdxList, NameStr);
    550433 }
    551 template
    552434 GetElementPtrInst::GetElementPtrInst(Value *Ptr,
    553 RandomAccessIterator IdxBegin,
    554 RandomAccessIterator IdxEnd,
    435 ArrayRef IdxList,
    555436 unsigned Values,
    556437 const Twine &NameStr,
    557438 BasicBlock *InsertAtEnd)
    558439 : Instruction(PointerType::get(checkGEPType(
    559 getIndexedType(Ptr->getType(),
    560 IdxBegin, IdxEnd)),
    440 getIndexedType(Ptr->getType(), IdxList)),
    561441 cast(Ptr->getType())
    562442 ->getAddressSpace()),
    563443 GetElementPtr,
    564444 OperandTraits::op_end(this) - Values,
    565445 Values, InsertAtEnd) {
    566 init(Ptr, IdxBegin, IdxEnd, NameStr,
    567 typename std::iterator_traits
    568 ::iterator_category());
    446 init(Ptr, IdxList, NameStr);
    569447 }
    570448
    571449
    772772 if (i == e)
    773773 return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
    774774 }
    775 return Insert(GetElementPtrInst::Create(Ptr, IdxList.begin(),
    776 IdxList.end()),
    777 Name);
    775 return Insert(GetElementPtrInst::Create(Ptr, IdxList), Name);
    778776 }
    779777 Value *CreateInBoundsGEP(Value *Ptr, ArrayRef IdxList,
    780778 const Twine &Name = "") {
    787785 if (i == e)
    788786 return Insert(Folder.CreateInBoundsGetElementPtr(PC, IdxList), Name);
    789787 }
    790 return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList.begin(),
    791 IdxList.end()),
    792 Name);
    788 return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList), Name);
    793789 }
    794790 Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
    795791 if (Constant *PC = dyn_cast(Ptr))
    830826 if (Constant *PC = dyn_cast(Ptr))
    831827 return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
    832828
    833 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
    829 return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
    834830 }
    835831 Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
    836832 const Twine &Name = "") {
    842838 if (Constant *PC = dyn_cast(Ptr))
    843839 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
    844840
    845 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
    841 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
    846842 }
    847843 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
    848844 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
    871867 if (Constant *PC = dyn_cast(Ptr))
    872868 return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
    873869
    874 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
    870 return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
    875871 }
    876872 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
    877873 const Twine &Name = "") {
    883879 if (Constant *PC = dyn_cast(Ptr))
    884880 return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
    885881
    886 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
    882 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
    887883 }
    888884 Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
    889885 return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
    182182 }
    183183 Instruction *CreateGetElementPtr(Constant *C,
    184184 ArrayRef IdxList) const {
    185 return GetElementPtrInst::Create(C, IdxList.begin(), IdxList.end());
    185 return GetElementPtrInst::Create(C, IdxList);
    186186 }
    187187
    188188 Constant *CreateInBoundsGetElementPtr(Constant *C,
    191191 }
    192192 Instruction *CreateInBoundsGetElementPtr(Constant *C,
    193193 ArrayRef IdxList) const {
    194 return GetElementPtrInst::CreateInBounds(C, IdxList.begin(), IdxList.end());
    194 return GetElementPtrInst::CreateInBounds(C, IdxList);
    195195 }
    196196
    197197 //===--------------------------------------------------------------------===//
    546546 for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
    547547 if ((i == 1 ||
    548548 !isa(GetElementPtrInst::getIndexedType(Ops[0]->getType(),
    549 Ops.data() + 1,
    550 i-1))) &&
    549 Ops.slice(1, i-1)))) &&
    551550 Ops[i]->getType() != IntPtrTy) {
    552551 Any = true;
    553552 NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
    22292229
    22302230 if (isa(Ops[0])) {
    22312231 // Compute the (pointer) type returned by the GEP instruction.
    2232 Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.data() + 1,
    2233 Ops.size() - 1);
    2232 Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.slice(1));
    22342233 Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
    22352234 return UndefValue::get(GEPTy);
    22362235 }
    406406 }
    407407
    408408 GetElementPtrInst *Result =
    409 GetElementPtrInst::Create(GEPOps[0], GEPOps.begin()+1, GEPOps.end(),
    410 InVal->getName()+".phi.trans.insert",
    411 PredBB->getTerminator());
    409 GetElementPtrInst::Create(GEPOps[0],
    410 makeArrayRef(GEPOps.begin() + 1, GEPOps.end()),
    411 InVal->getName()+".phi.trans.insert",
    412 PredBB->getTerminator());
    412413 Result->setIsInBounds(GEP->isInBounds());
    413414 NewInsts.push_back(Result);
    414415 return Result;
    22732273 return Error(ID.Loc, "getelementptr requires pointer operand");
    22742274
    22752275 ArrayRef Indices(Elts.begin() + 1, Elts.end());
    2276 if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
    2277 (Value**)(Elts.data() + 1),
    2278 Elts.size() - 1))
    2276 if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices))
    22792277 return Error(ID.Loc, "invalid indices for getelementptr");
    22802278 ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices,
    22812279 InBounds);
    36593657 Indices.push_back(Val);
    36603658 }
    36613659
    3662 if (!GetElementPtrInst::getIndexedType(Ptr->getType(),
    3663 Indices.begin(), Indices.end()))
    3660 if (!GetElementPtrInst::getIndexedType(Ptr->getType(), Indices))
    36643661 return Error(Loc, "invalid getelementptr indices");
    3665 Inst = GetElementPtrInst::Create(Ptr, Indices.begin(), Indices.end());
    3662 Inst = GetElementPtrInst::Create(Ptr, Indices);
    36663663 if (InBounds)
    36673664 cast(Inst)->setIsInBounds(true);
    36683665 return AteExtraComma ? InstExtraComma : InstNormal;
    21802180 GEPIdx.push_back(Op);
    21812181 }
    21822182
    2183 I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
    2183 I = GetElementPtrInst::Create(BasePtr, GEPIdx);
    21842184 InstructionList.push_back(I);
    21852185 if (BitCode == bitc::FUNC_CODE_INST_INBOUNDS_GEP)
    21862186 cast(I)->setIsInBounds(true);
    385385 // We need to also keep around a reference to the call_site field
    386386 Idxs[0] = Zero;
    387387 Idxs[1] = ConstantInt::get(Int32Ty, 1);
    388 CallSite = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
    389 "call_site",
    388 CallSite = GetElementPtrInst::Create(FunctionContext, Idxs, "call_site",
    390389 EntryBB->getTerminator());
    391390
    392391 // The exception selector comes back in context->data[1]
    393392 Idxs[1] = ConstantInt::get(Int32Ty, 2);
    394 Value *FCData = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
    395 "fc_data",
    393 Value *FCData = GetElementPtrInst::Create(FunctionContext, Idxs, "fc_data",
    396394 EntryBB->getTerminator());
    397395 Idxs[1] = ConstantInt::get(Int32Ty, 1);
    398 Value *SelectorAddr = GetElementPtrInst::Create(FCData, Idxs, Idxs+2,
    396 Value *SelectorAddr = GetElementPtrInst::Create(FCData, Idxs,
    399397 "exc_selector_gep",
    400398 EntryBB->getTerminator());
    401399 // The exception value comes back in context->data[0]
    402400 Idxs[1] = Zero;
    403 Value *ExceptionAddr = GetElementPtrInst::Create(FCData, Idxs, Idxs+2,
    401 Value *ExceptionAddr = GetElementPtrInst::Create(FCData, Idxs,
    404402 "exception_gep",
    405403 EntryBB->getTerminator());
    406404
    465463 Idxs[0] = Zero;
    466464 Idxs[1] = ConstantInt::get(Int32Ty, 4);
    467465 Value *LSDAFieldPtr =
    468 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
    469 "lsda_gep",
    466 GetElementPtrInst::Create(FunctionContext, Idxs, "lsda_gep",
    470467 EntryBB->getTerminator());
    471468 Value *LSDA = CallInst::Create(LSDAAddrFn, "lsda_addr",
    472469 EntryBB->getTerminator());
    474471
    475472 Idxs[1] = ConstantInt::get(Int32Ty, 3);
    476473 Value *PersonalityFieldPtr =
    477 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
    478 "lsda_gep",
    474 GetElementPtrInst::Create(FunctionContext, Idxs, "lsda_gep",
    479475 EntryBB->getTerminator());
    480476 new StoreInst(PersonalityFn, PersonalityFieldPtr, true,
    481477 EntryBB->getTerminator());
    483479 // Save the frame pointer.
    484480 Idxs[1] = ConstantInt::get(Int32Ty, 5);
    485481 Value *JBufPtr
    486 = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
    487 "jbuf_gep",
    482 = GetElementPtrInst::Create(FunctionContext, Idxs, "jbuf_gep",
    488483 EntryBB->getTerminator());
    489484 Idxs[1] = ConstantInt::get(Int32Ty, 0);
    490485 Value *FramePtr =
    491 GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_fp_gep",
    486 GetElementPtrInst::Create(JBufPtr, Idxs, "jbuf_fp_gep",
    492487 EntryBB->getTerminator());
    493488
    494489 Value *Val = CallInst::Create(FrameAddrFn,
    500495 // Save the stack pointer.
    501496 Idxs[1] = ConstantInt::get(Int32Ty, 2);
    502497 Value *StackPtr =
    503 GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_sp_gep",
    498 GetElementPtrInst::Create(JBufPtr, Idxs, "jbuf_sp_gep",
    504499 EntryBB->getTerminator());
    505500
    506501 Val = CallInst::Create(StackAddrFn, "sp", EntryBB->getTerminator());
    575575 for (ScalarizeTable::iterator SI = ArgIndices.begin(),
    576576 E = ArgIndices.end(); SI != E; ++SI) {
    577577 // not allowed to dereference ->begin() if size() is 0
    578 Params.push_back(GetElementPtrInst::getIndexedType(I->getType(),
    579 SI->begin(),
    580 SI->end()));
    578 Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), *SI));
    581579 assert(Params.back());
    582580 }
    583581
    667665 ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), 0 };
    668666 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
    669667 Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
    670 Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
    668 Value *Idx = GetElementPtrInst::Create(*AI, Idxs,
    671669 (*AI)->getName()+"."+utostr(i),
    672670 Call);
    673671 // TODO: Tell AA about the new values?
    698696 ElTy = cast(ElTy)->getTypeAtIndex(*II);
    699697 }
    700698 // And create a GEP to extract those indices.
    701 V = GetElementPtrInst::Create(V, Ops.begin(), Ops.end(),
    702 V->getName()+".idx", Call);
    699 V = GetElementPtrInst::Create(V, Ops, V->getName()+".idx", Call);
    703700 Ops.clear();
    704701 AA.copyValue(OrigLoad->getOperand(0), V);
    705702 }
    800797 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
    801798 Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
    802799 Value *Idx =
    803 GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
    800 GetElementPtrInst::Create(TheAlloca, Idxs,
    804801 TheAlloca->getName()+"."+Twine(i),
    805802 InsertPt);
    806803 I2->setName(I->getName()+"."+Twine(i));
    602602 Idxs.push_back(NullInt);
    603603 for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
    604604 Idxs.push_back(GEPI->getOperand(i));
    605 NewPtr = GetElementPtrInst::Create(NewPtr, Idxs.begin(), Idxs.end(),
    605 NewPtr = GetElementPtrInst::Create(NewPtr, Idxs,
    606606 GEPI->getName()+"."+Twine(Val),GEPI);
    607607 }
    608608 }
    12421242 GEPIdx.push_back(GEPI->getOperand(1));
    12431243 GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end());
    12441244
    1245 Value *NGEPI = GetElementPtrInst::Create(NewPtr,
    1246 GEPIdx.begin(), GEPIdx.end(),
    1245 Value *NGEPI = GetElementPtrInst::Create(NewPtr, GEPIdx,
    12471246 GEPI->getName(), GEPI);
    12481247 GEPI->replaceAllUsesWith(NGEPI);
    12491248 GEPI->eraseFromParent();
    16921692 // If we found a path from the src to dest, create the getelementptr now.
    16931693 if (SrcElTy == DstElTy) {
    16941694 SmallVector Idxs(NumZeros+1, ZeroUInt);
    1695 return GetElementPtrInst::CreateInBounds(Src, Idxs.begin(), Idxs.end());
    1695 return GetElementPtrInst::CreateInBounds(Src, Idxs);
    16961696 }
    16971697 }
    16981698
    5757 Idx[0] = NullIdx;
    5858 Idx[1] = NullIdx;
    5959 Instruction *GEP =
    60 GetElementPtrInst::CreateInBounds(New, Idx, Idx + 2,
    61 New->getName()+".sub");
    60 GetElementPtrInst::CreateInBounds(New, Idx, New->getName()+".sub");
    6261 InsertNewInstBefore(GEP, *It);
    6362
    6463 // Now make everything use the getelementptr instead of the original
    228228
    229229 Value *Base = FixedOperands[0];
    230230 GetElementPtrInst *NewGEP =
    231 GetElementPtrInst::Create(Base, FixedOperands.begin()+1,
    232 FixedOperands.end());
    231 GetElementPtrInst::Create(Base, makeArrayRef(FixedOperands.begin() + 1,
    232 FixedOperands.end()));
    233233 if (AllInBounds) NewGEP->setIsInBounds();
    234234 NewGEP->setDebugLoc(FirstInst->getDebugLoc());
    235235 return NewGEP;
    850850
    851851 if (!Indices.empty())
    852852 return (GEP.isInBounds() && Src->isInBounds()) ?
    853 GetElementPtrInst::CreateInBounds(Src->getOperand(0), Indices.begin(),
    854 Indices.end(), GEP.getName()) :
    855 GetElementPtrInst::Create(Src->getOperand(0), Indices.begin(),
    856 Indices.end(), GEP.getName());
    853 GetElementPtrInst::CreateInBounds(Src->getOperand(0), Indices,
    854 GEP.getName()) :
    855 GetElementPtrInst::Create(Src->getOperand(0), Indices, GEP.getName());
    857856 }
    858857
    859858 // Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
    882881 // -> GEP i8* X, ...
    883882 SmallVector Idx(GEP.idx_begin()+1, GEP.idx_end());
    884883 GetElementPtrInst *Res =
    885 GetElementPtrInst::Create(StrippedPtr, Idx.begin(),
    886 Idx.end(), GEP.getName());
    884 GetElementPtrInst::Create(StrippedPtr, Idx, GEP.getName());
    887885 Res->setIsInBounds(GEP.isInBounds());
    888886 return Res;
    889887 }
    10281028 gepIndices[1] = incValue;
    10291029
    10301030 GetElementPtrInst* pcPointer =
    1031 GetElementPtrInst::Create(dag->getCounterArray(),
    1032 gepIndices.begin(), gepIndices.end(),
    1031 GetElementPtrInst::Create(dag->getCounterArray(), gepIndices,
    10331032 "counterInc", insertPoint);
    10341033
    10351034 // Load from the array - call it oldPC
    20852085 }
    20862086 Instruction *Val = NewElts[Idx];
    20872087 if (NewArgs.size() > 1) {
    2088 Val = GetElementPtrInst::CreateInBounds(Val, NewArgs.begin(),
    2089 NewArgs.end(), "", GEPI);
    2088 Val = GetElementPtrInst::CreateInBounds(Val, NewArgs, "", GEPI);
    20902089 Val->takeName(GEPI);
    20912090 }
    20922091 if (Val->getType() != GEPI->getType())
    21622161 if (OtherPtr) {
    21632162 Value *Idx[2] = { Zero,
    21642163 ConstantInt::get(Type::getInt32Ty(MI->getContext()), i) };
    2165 OtherElt = GetElementPtrInst::CreateInBounds(OtherPtr, Idx, Idx + 2,
    2164 OtherElt = GetElementPtrInst::CreateInBounds(OtherPtr, Idx,
    21662165 OtherPtr->getName()+"."+Twine(i),
    21672166 MI);
    21682167 uint64_t EltOffset;
    316316 Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), i);
    317317 TerminatorInst *TI = newFunction->begin()->getTerminator();
    318318 GetElementPtrInst *GEP =
    319 GetElementPtrInst::Create(AI, Idx, Idx+2,
    320 "gep_" + inputs[i]->getName(), TI);
    319 GetElementPtrInst::Create(AI, Idx, "gep_" + inputs[i]->getName(), TI);
    321320 RewriteVal = new LoadInst(GEP, "loadgep_" + inputs[i]->getName(), TI);
    322321 } else
    323322 RewriteVal = AI++;
    419418 Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
    420419 Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i);
    421420 GetElementPtrInst *GEP =
    422 GetElementPtrInst::Create(Struct, Idx, Idx + 2,
    421 GetElementPtrInst::Create(Struct, Idx,
    423422 "gep_" + StructValues[i]->getName());
    424423 codeReplacer->getInstList().push_back(GEP);
    425424 StoreInst *SI = new StoreInst(StructValues[i], GEP);
    445444 Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
    446445 Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), FirstOut + i);
    447446 GetElementPtrInst *GEP
    448 = GetElementPtrInst::Create(Struct, Idx, Idx + 2,
    447 = GetElementPtrInst::Create(Struct, Idx,
    449448 "gep_reload_" + outputs[i]->getName());
    450449 codeReplacer->getInstList().push_back(GEP);
    451450 Output = GEP;
    560559 Idx[1] = ConstantInt::get(Type::getInt32Ty(Context),
    561560 FirstOut+out);
    562561 GetElementPtrInst *GEP =
    563 GetElementPtrInst::Create(OAI, Idx, Idx + 2,
    562 GetElementPtrInst::Create(OAI, Idx,
    564563 "gep_" + outputs[out]->getName(),
    565564 NTRet);
    566565 new StoreInst(outputs[out], GEP, NTRet);
    454454
    455455 Value *Idx[] = { Constant::getNullValue(Type::getInt32Ty(F.getContext())),
    456456 ConstantInt::get(Type::getInt32Ty(F.getContext()), 1) };
    457 OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, &Idx[0], &Idx[2],
    458 "OldBuf",
    457 OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx, "OldBuf",
    459458 EntryBB->getTerminator());
    460459
    461460 // Copy the JBListHead to the alloca.
    501500 "setjmp.cont");
    502501
    503502 Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 0);
    504 Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, &Idx[0], &Idx[2],
    505 "TheJmpBuf",
    503 Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx, "TheJmpBuf",
    506504 EntryBB->getTerminator());
    507505 JmpBufPtr = new BitCastInst(JmpBufPtr,
    508506 Type::getInt8PtrTy(F.getContext()),
    556554 // Get a pointer to the jmpbuf and longjmp.
    557555 Value *Idx[] = { Constant::getNullValue(Type::getInt32Ty(F.getContext())),
    558556 ConstantInt::get(Type::getInt32Ty(F.getContext()), 0) };
    559 Idx[0] = GetElementPtrInst::Create(BufPtr, &Idx[0], &Idx[2], "JmpBuf",
    560 UnwindBlock);
    557 Idx[0] = GetElementPtrInst::Create(BufPtr, Idx, "JmpBuf", UnwindBlock);
    561558 Idx[0] = new BitCastInst(Idx[0],
    562559 Type::getInt8PtrTy(F.getContext()),
    563560 "tmp", UnwindBlock);
    21722172
    21732173 if (isa(C)) {
    21742174 PointerType *Ptr = cast(C->getType());
    2175 Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs.begin(), Idxs.end());
    2175 Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs);
    21762176 assert(Ty != 0 && "Invalid indices for GEP!");
    21772177 return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
    21782178 }
    21862186 }
    21872187 if (isNull) {
    21882188 PointerType *Ptr = cast(C->getType());
    2189 Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs.begin(),
    2190 Idxs.end());
    2189 Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs);
    21912190 assert(Ty != 0 && "Invalid indices for GEP!");
    21922191 return ConstantPointerNull::get(PointerType::get(Ty,
    21932192 Ptr->getAddressSpace()));
    15971597 return FC; // Fold a few common cases.
    15981598
    15991599 // Get the result type of the getelementptr!
    1600 Type *Ty =
    1601 GetElementPtrInst::getIndexedType(C->getType(), Idxs.begin(), Idxs.end());
    1600 Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs);
    16021601 assert(Ty && "GEP indices invalid!");
    16031602 unsigned AS = cast(C->getType())->getAddressSpace();
    16041603 Type *ReqTy = Ty->getPointerTo(AS);
    998998 // GetElementPtrInst Implementation
    999999 //===----------------------------------------------------------------------===//
    10001000
    1001 static unsigned retrieveAddrSpace(const Value *Val) {
    1002 return cast(Val->getType())->getAddressSpace();
    1003 }
    1004
    1005 void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
    1001 void GetElementPtrInst::init(Value *Ptr, ArrayRef IdxList,
    10061002 const Twine &Name) {
    1007 assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
    1008 Use *OL = OperandList;
    1009 OL[0] = Ptr;
    1010
    1011 for (unsigned i = 0; i != NumIdx; ++i)
    1012 OL[i+1] = Idx[i];
    1013
    1014 setName(Name);
    1015 }
    1016
    1017 void GetElementPtrInst::init(Value *Ptr, Value *Idx, const Twine &Name) {
    1018 assert(NumOperands == 2 && "NumOperands not initialized?");
    1019 Use *OL = OperandList;
    1020 OL[0] = Ptr;
    1021 OL[1] = Idx;
    1022
    1003 assert(NumOperands == 1 + IdxList.size() && "NumOperands not initialized?");
    1004 OperandList[0] = Ptr;
    1005 std::copy(IdxList.begin(), IdxList.end(), op_begin() + 1);
    10231006 setName(Name);
    10241007 }
    10251008
    10281011 OperandTraits::op_end(this)
    10291012 - GEPI.getNumOperands(),
    10301013 GEPI.getNumOperands()) {
    1031 Use *OL = OperandList;
    1032 Use *GEPIOL = GEPI.OperandList;
    1033 for (unsigned i = 0, E = NumOperands; i != E; ++i)
    1034 OL[i] = GEPIOL[i];
    1014 std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
    10351015 SubclassOptionalData = GEPI.SubclassOptionalData;
    1036 }
    1037
    1038 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
    1039 const Twine &Name, Instruction *InBe)
    1040 : Instruction(PointerType::get(
    1041 checkGEPType(getIndexedType(Ptr->getType(),Idx)), retrieveAddrSpace(Ptr)),
    1042 GetElementPtr,
    1043 OperandTraits::op_end(this) - 2,
    1044 2, InBe) {
    1045 init(Ptr, Idx, Name);
    1046 }
    1047
    1048 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
    1049 const Twine &Name, BasicBlock *IAE)
    1050 : Instruction(PointerType::get(
    1051 checkGEPType(getIndexedType(Ptr->getType(),Idx)),
    1052 retrieveAddrSpace(Ptr)),
    1053 GetElementPtr,
    1054 OperandTraits::op_end(this) - 2,
    1055 2, IAE) {
    1056 init(Ptr, Idx, Name);
    10571016 }
    10581017
    10591018 /// getIndexedType - Returns the type of the element that would be accessed with
    10661025 /// pointer type.
    10671026 ///
    10681027 template
    1069 static Type *getIndexedTypeInternal(Type *Ptr, IndexTy const *Idxs,
    1070 unsigned NumIdx) {
    1028 static Type *getIndexedTypeInternal(Type *Ptr, ArrayRef IdxList) {
    10711029 PointerType *PTy = dyn_cast(Ptr);
    10721030 if (!PTy) return 0; // Type isn't a pointer type!
    10731031 Type *Agg = PTy->getElementType();
    10741032
    10751033 // Handle the special case of the empty set index set, which is always valid.
    1076 if (NumIdx == 0)
    1034 if (IdxList.empty())
    10771035 return Agg;
    10781036
    10791037 // If there is at least one index, the top level type must be sized, otherwise
    10821040 return 0;
    10831041
    10841042 unsigned CurIdx = 1;
    1085 for (; CurIdx != NumIdx; ++CurIdx) {
    1043 for (; CurIdx != IdxList.size(); ++CurIdx) {
    10861044 CompositeType *CT = dyn_cast(Agg);
    10871045 if (!CT || CT->isPointerTy()) return 0;
    1088 IndexTy Index = Idxs[CurIdx];
    1046 IndexTy Index = IdxList[CurIdx];
    10891047 if (!CT->indexValid(Index)) return 0;
    10901048 Agg = CT->getTypeAtIndex(Index);
    10911049 }
    1092 return CurIdx == NumIdx ? Agg : 0;
    1093 }
    1094
    1095 Type *GetElementPtrInst::getIndexedType(Type *Ptr, Value* const *Idxs,
    1096 unsigned NumIdx) {
    1097 return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
    1050 return CurIdx == IdxList.size() ? Agg : 0;
    1051 }
    1052
    1053 Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef IdxList) {
    1054 return getIndexedTypeInternal(Ptr, IdxList);
    10981055 }
    10991056
    11001057 Type *GetElementPtrInst::getIndexedType(Type *Ptr,
    1101 Constant* const *Idxs,
    1102 unsigned NumIdx) {
    1103 return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
    1104 }
    1105
    1106 Type *GetElementPtrInst::getIndexedType(Type *Ptr,
    1107 uint64_t const *Idxs,
    1108 unsigned NumIdx) {
    1109 return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
    1110 }
    1111
    1112 Type *GetElementPtrInst::getIndexedType(Type *Ptr, Value *Idx) {
    1113 PointerType *PTy = dyn_cast(Ptr);
    1114 if (!PTy) return 0; // Type isn't a pointer type!
    1115
    1116 // Check the pointer index.
    1117 if (!PTy->indexValid(Idx)) return 0;
    1118
    1119 return PTy->getElementType();
    1120 }
    1121
    1058 ArrayRef IdxList) {
    1059 return getIndexedTypeInternal(Ptr, IdxList);
    1060 }
    1061
    1062 Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef IdxList) {
    1063 return getIndexedTypeInternal(Ptr, IdxList);
    1064 }
    11221065
    11231066 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
    11241067 /// zeros. If so, the result pointer and the first operand have the same
    12751275 void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
    12761276 SmallVector Idxs(GEP.idx_begin(), GEP.idx_end());
    12771277 Type *ElTy =
    1278 GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(),
    1279 Idxs.begin(), Idxs.end());
    1278 GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(), Idxs);
    12801279 Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
    12811280 Assert2(GEP.getType()->isPointerTy() &&
    12821281 cast(GEP.getType())->getElementType() == ElTy,
    123123 Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
    124124 std::vector ops;
    125125 ops.push_back(Z);
    126 GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
    126 GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops);
    127127 EXPECT_FALSE(this->clone(GEP)->isInBounds());
    128128
    129129 GEP->setIsInBounds();