[opaque pointer type] Start migrating GEP creation to explicitly specify the pointee type

I'm just going to migrate these in a pretty ad-hoc & incremental way -
providing the backwards compatible API for now, then locally removing
it, fixing a few callers, adding it back in and commiting those callers.
Rinse, repeat.

The assertions should ensure that if I get this wrong we'll find out
about it and not just have one giant patch to revert, recommit, revert,
recommit, etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232240 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2015-03-14 01:53:18 +00:00
parent 4a2d95826e
commit fb5115d02a
6 changed files with 88 additions and 58 deletions

View File

@@ -794,28 +794,41 @@ class GetElementPtrInst : public Instruction {
/// list of indices. The first ctor can optionally insert before an existing
/// instruction, the second appends the new instruction to the specified
/// BasicBlock.
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
unsigned Values, const Twine &NameStr,
Instruction *InsertBefore);
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
unsigned Values, const Twine &NameStr,
BasicBlock *InsertAtEnd);
inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr, Instruction *InsertBefore);
inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr, BasicBlock *InsertAtEnd);
protected:
GetElementPtrInst *clone_impl() const override;
public:
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
return Create(nullptr, Ptr, IdxList, NameStr, InsertBefore);
}
static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
unsigned Values = 1 + unsigned(IdxList.size());
return new(Values)
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertBefore);
}
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
return Create(nullptr, Ptr, NameStr, InsertAtEnd);
}
static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
unsigned Values = 1 + unsigned(IdxList.size());
return new(Values)
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertAtEnd);
}
/// Create an "inbounds" getelementptr. See the documentation for the
@@ -824,7 +837,14 @@ public:
ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr){
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
}
static GetElementPtrInst *
CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
GetElementPtrInst *GEP =
Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
GEP->setIsInBounds(true);
return GEP;
}
@@ -832,7 +852,14 @@ public:
ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
}
static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
GetElementPtrInst *GEP =
Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
GEP->setIsInBounds(true);
return GEP;
}
@@ -850,6 +877,8 @@ public:
->getElementType();
}
Type *getResultElementType() const { return getType()->getElementType(); }
/// \brief Returns the address space of this instruction's pointer type.
unsigned getAddressSpace() const {
// Note that this is always the same as the pointer operand's address space
@@ -958,27 +987,25 @@ struct OperandTraits<GetElementPtrInst> :
public VariadicOperandTraits<GetElementPtrInst, 1> {
};
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
ArrayRef<Value *> IdxList,
unsigned Values,
GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr,
Instruction *InsertBefore)
: Instruction(getGEPReturnType(Ptr, IdxList),
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertBefore) {
: Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertBefore) {
init(Ptr, IdxList, NameStr);
assert(!PointeeType || PointeeType == getSourceElementType());
}
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
ArrayRef<Value *> IdxList,
unsigned Values,
GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr,
BasicBlock *InsertAtEnd)
: Instruction(getGEPReturnType(Ptr, IdxList),
GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertAtEnd) {
: Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertAtEnd) {
init(Ptr, IdxList, NameStr);
assert(!PointeeType || PointeeType == getSourceElementType());
}