mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 15:36:21 +00:00
Convert GetElementPtrInst to use ArrayRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135904 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b7fbcc9696
commit
a9203109f4
@ -639,6 +639,9 @@ from the previous release.</p>
|
||||
<li><code>FindInsertedValue</code> (in <code>llvm/Analysis/ValueTracking.h</code>)</li>
|
||||
<li><code>gep_type_begin</code> (in <code>llvm/Support/GetElementPtrTypeIterator.h</code>)</li>
|
||||
<li><code>gep_type_end</code> (in <code>llvm/Support/GetElementPtrTypeIterator.h</code>)</li>
|
||||
<li><code>GetElementPtrInst::Create</code></li>
|
||||
<li><code>GetElementPtrInst::CreateInBounds</code></li>
|
||||
<li><code>GetElementPtrInst::getIndexedType</code></li>
|
||||
<li><code>InsertValueInst::Create</code></li>
|
||||
<li><code>InsertValueInst::getIndices</code></li>
|
||||
<li><code>InvokeInst::Create</code></li>
|
||||
|
@ -285,149 +285,51 @@ static inline Type *checkGEPType(Type *Ty) {
|
||||
///
|
||||
class GetElementPtrInst : public Instruction {
|
||||
GetElementPtrInst(const GetElementPtrInst &GEPI);
|
||||
void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
|
||||
const Twine &NameStr);
|
||||
void init(Value *Ptr, Value *Idx, const Twine &NameStr);
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
void init(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
const Twine &NameStr,
|
||||
// This argument ensures that we have an iterator we can
|
||||
// do arithmetic on in constant time
|
||||
std::random_access_iterator_tag) {
|
||||
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
||||
|
||||
if (NumIdx > 0) {
|
||||
// This requires that the iterator points to contiguous memory.
|
||||
init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case
|
||||
// we have to build an array here
|
||||
}
|
||||
else {
|
||||
init(Ptr, 0, NumIdx, NameStr);
|
||||
}
|
||||
}
|
||||
|
||||
/// getIndexedType - Returns the type of the element that would be loaded with
|
||||
/// a load instruction with the specified parameters.
|
||||
///
|
||||
/// Null is returned if the indices are invalid for the specified
|
||||
/// pointer type.
|
||||
///
|
||||
template<typename RandomAccessIterator>
|
||||
static Type *getIndexedType(Type *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
// This argument ensures that we
|
||||
// have an iterator we can do
|
||||
// arithmetic on in constant time
|
||||
std::random_access_iterator_tag) {
|
||||
unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
|
||||
|
||||
if (NumIdx > 0)
|
||||
// This requires that the iterator points to contiguous memory.
|
||||
return getIndexedType(Ptr, &*IdxBegin, NumIdx);
|
||||
else
|
||||
return getIndexedType(Ptr, (Value *const*)0, NumIdx);
|
||||
}
|
||||
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
|
||||
|
||||
/// Constructors - Create a getelementptr instruction with a base pointer an
|
||||
/// list of indices. The first ctor can optionally insert before an existing
|
||||
/// instruction, the second appends the new instruction to the specified
|
||||
/// BasicBlock.
|
||||
template<typename RandomAccessIterator>
|
||||
inline GetElementPtrInst(Value *Ptr, RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
unsigned Values,
|
||||
const Twine &NameStr,
|
||||
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
unsigned Values, const Twine &NameStr,
|
||||
Instruction *InsertBefore);
|
||||
template<typename RandomAccessIterator>
|
||||
inline GetElementPtrInst(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
unsigned Values,
|
||||
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
||||
|
||||
/// Constructors - These two constructors are convenience methods because one
|
||||
/// and two index getelementptr instructions are so common.
|
||||
GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "",
|
||||
Instruction *InsertBefore = 0);
|
||||
GetElementPtrInst(Value *Ptr, Value *Idx,
|
||||
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
||||
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
unsigned Values, const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd);
|
||||
protected:
|
||||
virtual GetElementPtrInst *clone_impl() const;
|
||||
public:
|
||||
template<typename RandomAccessIterator>
|
||||
static GetElementPtrInst *Create(Value *Ptr, RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
const Twine &NameStr = "",
|
||||
Instruction *InsertBefore = 0) {
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type
|
||||
Values = 1 + std::distance(IdxBegin, IdxEnd);
|
||||
unsigned Values = 1 + unsigned(IdxList.size());
|
||||
return new(Values)
|
||||
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore);
|
||||
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
|
||||
}
|
||||
template<typename RandomAccessIterator>
|
||||
static GetElementPtrInst *Create(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd) {
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type
|
||||
Values = 1 + std::distance(IdxBegin, IdxEnd);
|
||||
unsigned Values = 1 + unsigned(IdxList.size());
|
||||
return new(Values)
|
||||
GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd);
|
||||
}
|
||||
|
||||
/// Constructors - These two creators are convenience methods because one
|
||||
/// index getelementptr instructions are so common.
|
||||
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
|
||||
const Twine &NameStr = "",
|
||||
Instruction *InsertBefore = 0) {
|
||||
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore);
|
||||
}
|
||||
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
|
||||
const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd) {
|
||||
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
|
||||
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
|
||||
}
|
||||
|
||||
/// Create an "inbounds" getelementptr. See the documentation for the
|
||||
/// "inbounds" flag in LangRef.html for details.
|
||||
template<typename RandomAccessIterator>
|
||||
static GetElementPtrInst *CreateInBounds(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
ArrayRef<Value *> IdxList,
|
||||
const Twine &NameStr = "",
|
||||
Instruction *InsertBefore = 0) {
|
||||
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
|
||||
NameStr, InsertBefore);
|
||||
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
|
||||
GEP->setIsInBounds(true);
|
||||
return GEP;
|
||||
}
|
||||
template<typename RandomAccessIterator>
|
||||
static GetElementPtrInst *CreateInBounds(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
ArrayRef<Value *> IdxList,
|
||||
const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd) {
|
||||
GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd,
|
||||
NameStr, InsertAtEnd);
|
||||
GEP->setIsInBounds(true);
|
||||
return GEP;
|
||||
}
|
||||
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
|
||||
const Twine &NameStr = "",
|
||||
Instruction *InsertBefore = 0) {
|
||||
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore);
|
||||
GEP->setIsInBounds(true);
|
||||
return GEP;
|
||||
}
|
||||
static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx,
|
||||
const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd) {
|
||||
GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd);
|
||||
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
|
||||
GEP->setIsInBounds(true);
|
||||
return GEP;
|
||||
}
|
||||
@ -446,23 +348,9 @@ public:
|
||||
/// Null is returned if the indices are invalid for the specified
|
||||
/// pointer type.
|
||||
///
|
||||
template<typename RandomAccessIterator>
|
||||
static Type *getIndexedType(Type *Ptr, RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd) {
|
||||
return getIndexedType(Ptr, IdxBegin, IdxEnd,
|
||||
typename std::iterator_traits<RandomAccessIterator>::
|
||||
iterator_category());
|
||||
}
|
||||
|
||||
// FIXME: Use ArrayRef
|
||||
static Type *getIndexedType(Type *Ptr,
|
||||
Value* const *Idx, unsigned NumIdx);
|
||||
static Type *getIndexedType(Type *Ptr,
|
||||
Constant* const *Idx, unsigned NumIdx);
|
||||
|
||||
static Type *getIndexedType(Type *Ptr,
|
||||
uint64_t const *Idx, unsigned NumIdx);
|
||||
static Type *getIndexedType(Type *Ptr, Value *Idx);
|
||||
static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
|
||||
static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
|
||||
static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
|
||||
|
||||
inline op_iterator idx_begin() { return op_begin()+1; }
|
||||
inline const_op_iterator idx_begin() const { return op_begin()+1; }
|
||||
@ -530,43 +418,33 @@ struct OperandTraits<GetElementPtrInst> :
|
||||
public VariadicOperandTraits<GetElementPtrInst, 1> {
|
||||
};
|
||||
|
||||
template<typename RandomAccessIterator>
|
||||
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
ArrayRef<Value *> IdxList,
|
||||
unsigned Values,
|
||||
const Twine &NameStr,
|
||||
Instruction *InsertBefore)
|
||||
: Instruction(PointerType::get(checkGEPType(
|
||||
getIndexedType(Ptr->getType(),
|
||||
IdxBegin, IdxEnd)),
|
||||
getIndexedType(Ptr->getType(), IdxList)),
|
||||
cast<PointerType>(Ptr->getType())
|
||||
->getAddressSpace()),
|
||||
GetElementPtr,
|
||||
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
||||
Values, InsertBefore) {
|
||||
init(Ptr, IdxBegin, IdxEnd, NameStr,
|
||||
typename std::iterator_traits<RandomAccessIterator>
|
||||
::iterator_category());
|
||||
init(Ptr, IdxList, NameStr);
|
||||
}
|
||||
template<typename RandomAccessIterator>
|
||||
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
||||
RandomAccessIterator IdxBegin,
|
||||
RandomAccessIterator IdxEnd,
|
||||
ArrayRef<Value *> IdxList,
|
||||
unsigned Values,
|
||||
const Twine &NameStr,
|
||||
BasicBlock *InsertAtEnd)
|
||||
: Instruction(PointerType::get(checkGEPType(
|
||||
getIndexedType(Ptr->getType(),
|
||||
IdxBegin, IdxEnd)),
|
||||
getIndexedType(Ptr->getType(), IdxList)),
|
||||
cast<PointerType>(Ptr->getType())
|
||||
->getAddressSpace()),
|
||||
GetElementPtr,
|
||||
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
||||
Values, InsertAtEnd) {
|
||||
init(Ptr, IdxBegin, IdxEnd, NameStr,
|
||||
typename std::iterator_traits<RandomAccessIterator>
|
||||
::iterator_category());
|
||||
init(Ptr, IdxList, NameStr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -773,9 +773,7 @@ public:
|
||||
if (i == e)
|
||||
return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
|
||||
}
|
||||
return Insert(GetElementPtrInst::Create(Ptr, IdxList.begin(),
|
||||
IdxList.end()),
|
||||
Name);
|
||||
return Insert(GetElementPtrInst::Create(Ptr, IdxList), Name);
|
||||
}
|
||||
Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
const Twine &Name = "") {
|
||||
@ -788,9 +786,7 @@ public:
|
||||
if (i == e)
|
||||
return Insert(Folder.CreateInBoundsGetElementPtr(PC, IdxList), Name);
|
||||
}
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList.begin(),
|
||||
IdxList.end()),
|
||||
Name);
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList), Name);
|
||||
}
|
||||
Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
@ -831,7 +827,7 @@ public:
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
|
||||
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
|
||||
}
|
||||
Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
|
||||
const Twine &Name = "") {
|
||||
@ -843,7 +839,7 @@ public:
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
|
||||
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
|
||||
}
|
||||
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
|
||||
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
|
||||
@ -872,7 +868,7 @@ public:
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
|
||||
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
|
||||
}
|
||||
Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
|
||||
const Twine &Name = "") {
|
||||
@ -884,7 +880,7 @@ public:
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
|
||||
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
|
||||
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
|
||||
}
|
||||
Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
|
||||
return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
|
||||
|
@ -183,7 +183,7 @@ public:
|
||||
}
|
||||
Instruction *CreateGetElementPtr(Constant *C,
|
||||
ArrayRef<Value *> IdxList) const {
|
||||
return GetElementPtrInst::Create(C, IdxList.begin(), IdxList.end());
|
||||
return GetElementPtrInst::Create(C, IdxList);
|
||||
}
|
||||
|
||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||
@ -192,7 +192,7 @@ public:
|
||||
}
|
||||
Instruction *CreateInBoundsGetElementPtr(Constant *C,
|
||||
ArrayRef<Value *> IdxList) const {
|
||||
return GetElementPtrInst::CreateInBounds(C, IdxList.begin(), IdxList.end());
|
||||
return GetElementPtrInst::CreateInBounds(C, IdxList);
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
@ -547,8 +547,7 @@ static Constant *CastGEPIndices(ArrayRef<Constant *> Ops,
|
||||
for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
|
||||
if ((i == 1 ||
|
||||
!isa<StructType>(GetElementPtrInst::getIndexedType(Ops[0]->getType(),
|
||||
Ops.data() + 1,
|
||||
i-1))) &&
|
||||
Ops.slice(1, i-1)))) &&
|
||||
Ops[i]->getType() != IntPtrTy) {
|
||||
Any = true;
|
||||
NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i],
|
||||
|
@ -2230,8 +2230,7 @@ Value *llvm::SimplifyGEPInst(ArrayRef<Value *> Ops,
|
||||
|
||||
if (isa<UndefValue>(Ops[0])) {
|
||||
// Compute the (pointer) type returned by the GEP instruction.
|
||||
Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.data() + 1,
|
||||
Ops.size() - 1);
|
||||
Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, Ops.slice(1));
|
||||
Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
|
||||
return UndefValue::get(GEPTy);
|
||||
}
|
||||
|
@ -407,9 +407,10 @@ InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
|
||||
}
|
||||
|
||||
GetElementPtrInst *Result =
|
||||
GetElementPtrInst::Create(GEPOps[0], GEPOps.begin()+1, GEPOps.end(),
|
||||
InVal->getName()+".phi.trans.insert",
|
||||
PredBB->getTerminator());
|
||||
GetElementPtrInst::Create(GEPOps[0],
|
||||
makeArrayRef(GEPOps.begin() + 1, GEPOps.end()),
|
||||
InVal->getName()+".phi.trans.insert",
|
||||
PredBB->getTerminator());
|
||||
Result->setIsInBounds(GEP->isInBounds());
|
||||
NewInsts.push_back(Result);
|
||||
return Result;
|
||||
|
@ -2274,9 +2274,7 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
||||
return Error(ID.Loc, "getelementptr requires pointer operand");
|
||||
|
||||
ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
|
||||
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
|
||||
(Value**)(Elts.data() + 1),
|
||||
Elts.size() - 1))
|
||||
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices))
|
||||
return Error(ID.Loc, "invalid indices for getelementptr");
|
||||
ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices,
|
||||
InBounds);
|
||||
@ -3660,10 +3658,9 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
|
||||
Indices.push_back(Val);
|
||||
}
|
||||
|
||||
if (!GetElementPtrInst::getIndexedType(Ptr->getType(),
|
||||
Indices.begin(), Indices.end()))
|
||||
if (!GetElementPtrInst::getIndexedType(Ptr->getType(), Indices))
|
||||
return Error(Loc, "invalid getelementptr indices");
|
||||
Inst = GetElementPtrInst::Create(Ptr, Indices.begin(), Indices.end());
|
||||
Inst = GetElementPtrInst::Create(Ptr, Indices);
|
||||
if (InBounds)
|
||||
cast<GetElementPtrInst>(Inst)->setIsInBounds(true);
|
||||
return AteExtraComma ? InstExtraComma : InstNormal;
|
||||
|
@ -2181,7 +2181,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
||||
GEPIdx.push_back(Op);
|
||||
}
|
||||
|
||||
I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
|
||||
I = GetElementPtrInst::Create(BasePtr, GEPIdx);
|
||||
InstructionList.push_back(I);
|
||||
if (BitCode == bitc::FUNC_CODE_INST_INBOUNDS_GEP)
|
||||
cast<GetElementPtrInst>(I)->setIsInBounds(true);
|
||||
|
@ -386,22 +386,20 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
|
||||
// We need to also keep around a reference to the call_site field
|
||||
Idxs[0] = Zero;
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 1);
|
||||
CallSite = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
|
||||
"call_site",
|
||||
CallSite = GetElementPtrInst::Create(FunctionContext, Idxs, "call_site",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
// The exception selector comes back in context->data[1]
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 2);
|
||||
Value *FCData = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
|
||||
"fc_data",
|
||||
Value *FCData = GetElementPtrInst::Create(FunctionContext, Idxs, "fc_data",
|
||||
EntryBB->getTerminator());
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 1);
|
||||
Value *SelectorAddr = GetElementPtrInst::Create(FCData, Idxs, Idxs+2,
|
||||
Value *SelectorAddr = GetElementPtrInst::Create(FCData, Idxs,
|
||||
"exc_selector_gep",
|
||||
EntryBB->getTerminator());
|
||||
// The exception value comes back in context->data[0]
|
||||
Idxs[1] = Zero;
|
||||
Value *ExceptionAddr = GetElementPtrInst::Create(FCData, Idxs, Idxs+2,
|
||||
Value *ExceptionAddr = GetElementPtrInst::Create(FCData, Idxs,
|
||||
"exception_gep",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
@ -466,8 +464,7 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
|
||||
Idxs[0] = Zero;
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 4);
|
||||
Value *LSDAFieldPtr =
|
||||
GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
|
||||
"lsda_gep",
|
||||
GetElementPtrInst::Create(FunctionContext, Idxs, "lsda_gep",
|
||||
EntryBB->getTerminator());
|
||||
Value *LSDA = CallInst::Create(LSDAAddrFn, "lsda_addr",
|
||||
EntryBB->getTerminator());
|
||||
@ -475,8 +472,7 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
|
||||
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 3);
|
||||
Value *PersonalityFieldPtr =
|
||||
GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
|
||||
"lsda_gep",
|
||||
GetElementPtrInst::Create(FunctionContext, Idxs, "lsda_gep",
|
||||
EntryBB->getTerminator());
|
||||
new StoreInst(PersonalityFn, PersonalityFieldPtr, true,
|
||||
EntryBB->getTerminator());
|
||||
@ -484,12 +480,11 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
|
||||
// Save the frame pointer.
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 5);
|
||||
Value *JBufPtr
|
||||
= GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2,
|
||||
"jbuf_gep",
|
||||
= GetElementPtrInst::Create(FunctionContext, Idxs, "jbuf_gep",
|
||||
EntryBB->getTerminator());
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 0);
|
||||
Value *FramePtr =
|
||||
GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_fp_gep",
|
||||
GetElementPtrInst::Create(JBufPtr, Idxs, "jbuf_fp_gep",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
Value *Val = CallInst::Create(FrameAddrFn,
|
||||
@ -501,7 +496,7 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
|
||||
// Save the stack pointer.
|
||||
Idxs[1] = ConstantInt::get(Int32Ty, 2);
|
||||
Value *StackPtr =
|
||||
GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_sp_gep",
|
||||
GetElementPtrInst::Create(JBufPtr, Idxs, "jbuf_sp_gep",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
Val = CallInst::Create(StackAddrFn, "sp", EntryBB->getTerminator());
|
||||
|
@ -576,9 +576,7 @@ 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->begin(),
|
||||
SI->end()));
|
||||
Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), *SI));
|
||||
assert(Params.back());
|
||||
}
|
||||
|
||||
@ -668,7 +666,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
||||
ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), 0 };
|
||||
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
|
||||
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
|
||||
Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
|
||||
Value *Idx = GetElementPtrInst::Create(*AI, Idxs,
|
||||
(*AI)->getName()+"."+utostr(i),
|
||||
Call);
|
||||
// TODO: Tell AA about the new values?
|
||||
@ -699,8 +697,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
||||
ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(*II);
|
||||
}
|
||||
// And create a GEP to extract those indices.
|
||||
V = GetElementPtrInst::Create(V, Ops.begin(), Ops.end(),
|
||||
V->getName()+".idx", Call);
|
||||
V = GetElementPtrInst::Create(V, Ops, V->getName()+".idx", Call);
|
||||
Ops.clear();
|
||||
AA.copyValue(OrigLoad->getOperand(0), V);
|
||||
}
|
||||
@ -801,7 +798,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
||||
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
|
||||
Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
|
||||
Value *Idx =
|
||||
GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
|
||||
GetElementPtrInst::Create(TheAlloca, Idxs,
|
||||
TheAlloca->getName()+"."+Twine(i),
|
||||
InsertPt);
|
||||
I2->setName(I->getName()+"."+Twine(i));
|
||||
|
@ -603,7 +603,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) {
|
||||
Idxs.push_back(NullInt);
|
||||
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
|
||||
Idxs.push_back(GEPI->getOperand(i));
|
||||
NewPtr = GetElementPtrInst::Create(NewPtr, Idxs.begin(), Idxs.end(),
|
||||
NewPtr = GetElementPtrInst::Create(NewPtr, Idxs,
|
||||
GEPI->getName()+"."+Twine(Val),GEPI);
|
||||
}
|
||||
}
|
||||
@ -1243,8 +1243,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
|
||||
GEPIdx.push_back(GEPI->getOperand(1));
|
||||
GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end());
|
||||
|
||||
Value *NGEPI = GetElementPtrInst::Create(NewPtr,
|
||||
GEPIdx.begin(), GEPIdx.end(),
|
||||
Value *NGEPI = GetElementPtrInst::Create(NewPtr, GEPIdx,
|
||||
GEPI->getName(), GEPI);
|
||||
GEPI->replaceAllUsesWith(NGEPI);
|
||||
GEPI->eraseFromParent();
|
||||
|
@ -1693,7 +1693,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
|
||||
// If we found a path from the src to dest, create the getelementptr now.
|
||||
if (SrcElTy == DstElTy) {
|
||||
SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt);
|
||||
return GetElementPtrInst::CreateInBounds(Src, Idxs.begin(), Idxs.end());
|
||||
return GetElementPtrInst::CreateInBounds(Src, Idxs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,7 @@ Instruction *InstCombiner::visitAllocaInst(AllocaInst &AI) {
|
||||
Idx[0] = NullIdx;
|
||||
Idx[1] = NullIdx;
|
||||
Instruction *GEP =
|
||||
GetElementPtrInst::CreateInBounds(New, Idx, Idx + 2,
|
||||
New->getName()+".sub");
|
||||
GetElementPtrInst::CreateInBounds(New, Idx, New->getName()+".sub");
|
||||
InsertNewInstBefore(GEP, *It);
|
||||
|
||||
// Now make everything use the getelementptr instead of the original
|
||||
|
@ -229,8 +229,8 @@ Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
|
||||
|
||||
Value *Base = FixedOperands[0];
|
||||
GetElementPtrInst *NewGEP =
|
||||
GetElementPtrInst::Create(Base, FixedOperands.begin()+1,
|
||||
FixedOperands.end());
|
||||
GetElementPtrInst::Create(Base, makeArrayRef(FixedOperands.begin() + 1,
|
||||
FixedOperands.end()));
|
||||
if (AllInBounds) NewGEP->setIsInBounds();
|
||||
NewGEP->setDebugLoc(FirstInst->getDebugLoc());
|
||||
return NewGEP;
|
||||
|
@ -851,10 +851,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
|
||||
if (!Indices.empty())
|
||||
return (GEP.isInBounds() && Src->isInBounds()) ?
|
||||
GetElementPtrInst::CreateInBounds(Src->getOperand(0), Indices.begin(),
|
||||
Indices.end(), GEP.getName()) :
|
||||
GetElementPtrInst::Create(Src->getOperand(0), Indices.begin(),
|
||||
Indices.end(), GEP.getName());
|
||||
GetElementPtrInst::CreateInBounds(Src->getOperand(0), Indices,
|
||||
GEP.getName()) :
|
||||
GetElementPtrInst::Create(Src->getOperand(0), Indices, GEP.getName());
|
||||
}
|
||||
|
||||
// Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
|
||||
@ -883,8 +882,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
// -> GEP i8* X, ...
|
||||
SmallVector<Value*, 8> Idx(GEP.idx_begin()+1, GEP.idx_end());
|
||||
GetElementPtrInst *Res =
|
||||
GetElementPtrInst::Create(StrippedPtr, Idx.begin(),
|
||||
Idx.end(), GEP.getName());
|
||||
GetElementPtrInst::Create(StrippedPtr, Idx, GEP.getName());
|
||||
Res->setIsInBounds(GEP.isInBounds());
|
||||
return Res;
|
||||
}
|
||||
|
@ -1029,8 +1029,7 @@ void PathProfiler::insertCounterIncrement(Value* incValue,
|
||||
gepIndices[1] = incValue;
|
||||
|
||||
GetElementPtrInst* pcPointer =
|
||||
GetElementPtrInst::Create(dag->getCounterArray(),
|
||||
gepIndices.begin(), gepIndices.end(),
|
||||
GetElementPtrInst::Create(dag->getCounterArray(), gepIndices,
|
||||
"counterInc", insertPoint);
|
||||
|
||||
// Load from the array - call it oldPC
|
||||
|
@ -2086,8 +2086,7 @@ void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
|
||||
}
|
||||
Instruction *Val = NewElts[Idx];
|
||||
if (NewArgs.size() > 1) {
|
||||
Val = GetElementPtrInst::CreateInBounds(Val, NewArgs.begin(),
|
||||
NewArgs.end(), "", GEPI);
|
||||
Val = GetElementPtrInst::CreateInBounds(Val, NewArgs, "", GEPI);
|
||||
Val->takeName(GEPI);
|
||||
}
|
||||
if (Val->getType() != GEPI->getType())
|
||||
@ -2163,7 +2162,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
|
||||
if (OtherPtr) {
|
||||
Value *Idx[2] = { Zero,
|
||||
ConstantInt::get(Type::getInt32Ty(MI->getContext()), i) };
|
||||
OtherElt = GetElementPtrInst::CreateInBounds(OtherPtr, Idx, Idx + 2,
|
||||
OtherElt = GetElementPtrInst::CreateInBounds(OtherPtr, Idx,
|
||||
OtherPtr->getName()+"."+Twine(i),
|
||||
MI);
|
||||
uint64_t EltOffset;
|
||||
|
@ -317,8 +317,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
||||
Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), i);
|
||||
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(AI, Idx, Idx+2,
|
||||
"gep_" + inputs[i]->getName(), TI);
|
||||
GetElementPtrInst::Create(AI, Idx, "gep_" + inputs[i]->getName(), TI);
|
||||
RewriteVal = new LoadInst(GEP, "loadgep_" + inputs[i]->getName(), TI);
|
||||
} else
|
||||
RewriteVal = AI++;
|
||||
@ -420,7 +419,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
|
||||
Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i);
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||
GetElementPtrInst::Create(Struct, Idx,
|
||||
"gep_" + StructValues[i]->getName());
|
||||
codeReplacer->getInstList().push_back(GEP);
|
||||
StoreInst *SI = new StoreInst(StructValues[i], GEP);
|
||||
@ -446,7 +445,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
|
||||
Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), FirstOut + i);
|
||||
GetElementPtrInst *GEP
|
||||
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||
= GetElementPtrInst::Create(Struct, Idx,
|
||||
"gep_reload_" + outputs[i]->getName());
|
||||
codeReplacer->getInstList().push_back(GEP);
|
||||
Output = GEP;
|
||||
@ -561,7 +560,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
Idx[1] = ConstantInt::get(Type::getInt32Ty(Context),
|
||||
FirstOut+out);
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
|
||||
GetElementPtrInst::Create(OAI, Idx,
|
||||
"gep_" + outputs[out]->getName(),
|
||||
NTRet);
|
||||
new StoreInst(outputs[out], GEP, NTRet);
|
||||
|
@ -455,8 +455,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
|
||||
Value *Idx[] = { Constant::getNullValue(Type::getInt32Ty(F.getContext())),
|
||||
ConstantInt::get(Type::getInt32Ty(F.getContext()), 1) };
|
||||
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, &Idx[0], &Idx[2],
|
||||
"OldBuf",
|
||||
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx, "OldBuf",
|
||||
EntryBB->getTerminator());
|
||||
|
||||
// Copy the JBListHead to the alloca.
|
||||
@ -502,8 +501,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
"setjmp.cont");
|
||||
|
||||
Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 0);
|
||||
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, &Idx[0], &Idx[2],
|
||||
"TheJmpBuf",
|
||||
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx, "TheJmpBuf",
|
||||
EntryBB->getTerminator());
|
||||
JmpBufPtr = new BitCastInst(JmpBufPtr,
|
||||
Type::getInt8PtrTy(F.getContext()),
|
||||
@ -557,8 +555,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
// Get a pointer to the jmpbuf and longjmp.
|
||||
Value *Idx[] = { Constant::getNullValue(Type::getInt32Ty(F.getContext())),
|
||||
ConstantInt::get(Type::getInt32Ty(F.getContext()), 0) };
|
||||
Idx[0] = GetElementPtrInst::Create(BufPtr, &Idx[0], &Idx[2], "JmpBuf",
|
||||
UnwindBlock);
|
||||
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx, "JmpBuf", UnwindBlock);
|
||||
Idx[0] = new BitCastInst(Idx[0],
|
||||
Type::getInt8PtrTy(F.getContext()),
|
||||
"tmp", UnwindBlock);
|
||||
|
@ -2173,7 +2173,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
||||
|
||||
if (isa<UndefValue>(C)) {
|
||||
PointerType *Ptr = cast<PointerType>(C->getType());
|
||||
Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs.begin(), Idxs.end());
|
||||
Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs);
|
||||
assert(Ty != 0 && "Invalid indices for GEP!");
|
||||
return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
|
||||
}
|
||||
@ -2187,8 +2187,7 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
||||
}
|
||||
if (isNull) {
|
||||
PointerType *Ptr = cast<PointerType>(C->getType());
|
||||
Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs.begin(),
|
||||
Idxs.end());
|
||||
Type *Ty = GetElementPtrInst::getIndexedType(Ptr, Idxs);
|
||||
assert(Ty != 0 && "Invalid indices for GEP!");
|
||||
return ConstantPointerNull::get(PointerType::get(Ty,
|
||||
Ptr->getAddressSpace()));
|
||||
|
@ -1598,8 +1598,7 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, ArrayRef<Value *> Idxs,
|
||||
return FC; // Fold a few common cases.
|
||||
|
||||
// Get the result type of the getelementptr!
|
||||
Type *Ty =
|
||||
GetElementPtrInst::getIndexedType(C->getType(), Idxs.begin(), Idxs.end());
|
||||
Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), Idxs);
|
||||
assert(Ty && "GEP indices invalid!");
|
||||
unsigned AS = cast<PointerType>(C->getType())->getAddressSpace();
|
||||
Type *ReqTy = Ty->getPointerTo(AS);
|
||||
|
@ -999,28 +999,11 @@ void StoreInst::setAlignment(unsigned Align) {
|
||||
// GetElementPtrInst Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static unsigned retrieveAddrSpace(const Value *Val) {
|
||||
return cast<PointerType>(Val->getType())->getAddressSpace();
|
||||
}
|
||||
|
||||
void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
|
||||
void GetElementPtrInst::init(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||
const Twine &Name) {
|
||||
assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
|
||||
Use *OL = OperandList;
|
||||
OL[0] = Ptr;
|
||||
|
||||
for (unsigned i = 0; i != NumIdx; ++i)
|
||||
OL[i+1] = Idx[i];
|
||||
|
||||
setName(Name);
|
||||
}
|
||||
|
||||
void GetElementPtrInst::init(Value *Ptr, Value *Idx, const Twine &Name) {
|
||||
assert(NumOperands == 2 && "NumOperands not initialized?");
|
||||
Use *OL = OperandList;
|
||||
OL[0] = Ptr;
|
||||
OL[1] = Idx;
|
||||
|
||||
assert(NumOperands == 1 + IdxList.size() && "NumOperands not initialized?");
|
||||
OperandList[0] = Ptr;
|
||||
std::copy(IdxList.begin(), IdxList.end(), op_begin() + 1);
|
||||
setName(Name);
|
||||
}
|
||||
|
||||
@ -1029,34 +1012,10 @@ GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
|
||||
OperandTraits<GetElementPtrInst>::op_end(this)
|
||||
- GEPI.getNumOperands(),
|
||||
GEPI.getNumOperands()) {
|
||||
Use *OL = OperandList;
|
||||
Use *GEPIOL = GEPI.OperandList;
|
||||
for (unsigned i = 0, E = NumOperands; i != E; ++i)
|
||||
OL[i] = GEPIOL[i];
|
||||
std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
|
||||
SubclassOptionalData = GEPI.SubclassOptionalData;
|
||||
}
|
||||
|
||||
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
|
||||
const Twine &Name, Instruction *InBe)
|
||||
: Instruction(PointerType::get(
|
||||
checkGEPType(getIndexedType(Ptr->getType(),Idx)), retrieveAddrSpace(Ptr)),
|
||||
GetElementPtr,
|
||||
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
|
||||
2, InBe) {
|
||||
init(Ptr, Idx, Name);
|
||||
}
|
||||
|
||||
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
|
||||
const Twine &Name, BasicBlock *IAE)
|
||||
: Instruction(PointerType::get(
|
||||
checkGEPType(getIndexedType(Ptr->getType(),Idx)),
|
||||
retrieveAddrSpace(Ptr)),
|
||||
GetElementPtr,
|
||||
OperandTraits<GetElementPtrInst>::op_end(this) - 2,
|
||||
2, IAE) {
|
||||
init(Ptr, Idx, Name);
|
||||
}
|
||||
|
||||
/// getIndexedType - Returns the type of the element that would be accessed with
|
||||
/// a gep instruction with the specified parameters.
|
||||
///
|
||||
@ -1067,14 +1026,13 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
|
||||
/// pointer type.
|
||||
///
|
||||
template <typename IndexTy>
|
||||
static Type *getIndexedTypeInternal(Type *Ptr, IndexTy const *Idxs,
|
||||
unsigned NumIdx) {
|
||||
static Type *getIndexedTypeInternal(Type *Ptr, ArrayRef<IndexTy> IdxList) {
|
||||
PointerType *PTy = dyn_cast<PointerType>(Ptr);
|
||||
if (!PTy) return 0; // Type isn't a pointer type!
|
||||
Type *Agg = PTy->getElementType();
|
||||
|
||||
// Handle the special case of the empty set index set, which is always valid.
|
||||
if (NumIdx == 0)
|
||||
if (IdxList.empty())
|
||||
return Agg;
|
||||
|
||||
// If there is at least one index, the top level type must be sized, otherwise
|
||||
@ -1083,44 +1041,29 @@ static Type *getIndexedTypeInternal(Type *Ptr, IndexTy const *Idxs,
|
||||
return 0;
|
||||
|
||||
unsigned CurIdx = 1;
|
||||
for (; CurIdx != NumIdx; ++CurIdx) {
|
||||
for (; CurIdx != IdxList.size(); ++CurIdx) {
|
||||
CompositeType *CT = dyn_cast<CompositeType>(Agg);
|
||||
if (!CT || CT->isPointerTy()) return 0;
|
||||
IndexTy Index = Idxs[CurIdx];
|
||||
IndexTy Index = IdxList[CurIdx];
|
||||
if (!CT->indexValid(Index)) return 0;
|
||||
Agg = CT->getTypeAtIndex(Index);
|
||||
}
|
||||
return CurIdx == NumIdx ? Agg : 0;
|
||||
return CurIdx == IdxList.size() ? Agg : 0;
|
||||
}
|
||||
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr, Value* const *Idxs,
|
||||
unsigned NumIdx) {
|
||||
return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList) {
|
||||
return getIndexedTypeInternal(Ptr, IdxList);
|
||||
}
|
||||
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr,
|
||||
Constant* const *Idxs,
|
||||
unsigned NumIdx) {
|
||||
return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
|
||||
ArrayRef<Constant *> IdxList) {
|
||||
return getIndexedTypeInternal(Ptr, IdxList);
|
||||
}
|
||||
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr,
|
||||
uint64_t const *Idxs,
|
||||
unsigned NumIdx) {
|
||||
return getIndexedTypeInternal(Ptr, Idxs, NumIdx);
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList) {
|
||||
return getIndexedTypeInternal(Ptr, IdxList);
|
||||
}
|
||||
|
||||
Type *GetElementPtrInst::getIndexedType(Type *Ptr, Value *Idx) {
|
||||
PointerType *PTy = dyn_cast<PointerType>(Ptr);
|
||||
if (!PTy) return 0; // Type isn't a pointer type!
|
||||
|
||||
// Check the pointer index.
|
||||
if (!PTy->indexValid(Idx)) return 0;
|
||||
|
||||
return PTy->getElementType();
|
||||
}
|
||||
|
||||
|
||||
/// hasAllZeroIndices - Return true if all of the indices of this GEP are
|
||||
/// zeros. If so, the result pointer and the first operand have the same
|
||||
/// value, just potentially different types.
|
||||
|
@ -1276,8 +1276,7 @@ void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) {
|
||||
void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
|
||||
Type *ElTy =
|
||||
GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(),
|
||||
Idxs.begin(), Idxs.end());
|
||||
GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(), Idxs);
|
||||
Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
|
||||
Assert2(GEP.getType()->isPointerTy() &&
|
||||
cast<PointerType>(GEP.getType())->getElementType() == ElTy,
|
||||
|
@ -124,7 +124,7 @@ TEST_F(CloneInstruction, Inbounds) {
|
||||
Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
|
||||
std::vector<Value *> ops;
|
||||
ops.push_back(Z);
|
||||
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
|
||||
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops);
|
||||
EXPECT_FALSE(this->clone(GEP)->isInBounds());
|
||||
|
||||
GEP->setIsInBounds();
|
||||
|
Loading…
x
Reference in New Issue
Block a user