Convert ConstantExpr::getGetElementPtr and
ConstantExpr::getInBoundsGetElementPtr to use ArrayRef. llvm-svn: 135673
This commit is contained in:
parent
95f1ebd41b
commit
ed8db7d9df
|
@ -964,7 +964,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
|
||||||
if (!Offset->isNullValue()) {
|
if (!Offset->isNullValue()) {
|
||||||
llvm::Type *Type = llvm::Type::getInt8PtrTy(VMContext);
|
llvm::Type *Type = llvm::Type::getInt8PtrTy(VMContext);
|
||||||
llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Type);
|
llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Type);
|
||||||
Casted = llvm::ConstantExpr::getGetElementPtr(Casted, &Offset, 1);
|
Casted = llvm::ConstantExpr::getGetElementPtr(Casted, Offset);
|
||||||
C = llvm::ConstantExpr::getBitCast(Casted, C->getType());
|
C = llvm::ConstantExpr::getBitCast(Casted, C->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ protected:
|
||||||
llvm::Constant *MakeConstantString(const std::string &Str,
|
llvm::Constant *MakeConstantString(const std::string &Str,
|
||||||
const std::string &Name="") {
|
const std::string &Name="") {
|
||||||
llvm::Constant *ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
|
llvm::Constant *ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
|
||||||
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros, 2);
|
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros);
|
||||||
}
|
}
|
||||||
/// Emits a linkonce_odr string, whose name is the prefix followed by the
|
/// Emits a linkonce_odr string, whose name is the prefix followed by the
|
||||||
/// string value. This allows the linker to combine the strings between
|
/// string value. This allows the linker to combine the strings between
|
||||||
|
@ -186,7 +186,7 @@ protected:
|
||||||
ConstStr = new llvm::GlobalVariable(TheModule, value->getType(), true,
|
ConstStr = new llvm::GlobalVariable(TheModule, value->getType(), true,
|
||||||
llvm::GlobalValue::LinkOnceODRLinkage, value, prefix + Str);
|
llvm::GlobalValue::LinkOnceODRLinkage, value, prefix + Str);
|
||||||
}
|
}
|
||||||
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros, 2);
|
return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros);
|
||||||
}
|
}
|
||||||
/// Generates a global structure, initialized by the elements in the vector.
|
/// Generates a global structure, initialized by the elements in the vector.
|
||||||
/// The element types must match the types of the structure elements in the
|
/// The element types must match the types of the structure elements in the
|
||||||
|
@ -918,7 +918,7 @@ llvm::Constant *CGObjCGNU::GetEHType(QualType T) {
|
||||||
llvm::GlobalValue::ExternalLinkage, 0, vtableName);
|
llvm::GlobalValue::ExternalLinkage, 0, vtableName);
|
||||||
}
|
}
|
||||||
llvm::Constant *Two = llvm::ConstantInt::get(IntTy, 2);
|
llvm::Constant *Two = llvm::ConstantInt::get(IntTy, 2);
|
||||||
Vtable = llvm::ConstantExpr::getGetElementPtr(Vtable, &Two, 1);
|
Vtable = llvm::ConstantExpr::getGetElementPtr(Vtable, Two);
|
||||||
Vtable = llvm::ConstantExpr::getBitCast(Vtable, PtrToInt8Ty);
|
Vtable = llvm::ConstantExpr::getBitCast(Vtable, PtrToInt8Ty);
|
||||||
|
|
||||||
llvm::Constant *typeName =
|
llvm::Constant *typeName =
|
||||||
|
@ -1976,7 +1976,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
|
||||||
offsetPointerIndexes[2] = llvm::ConstantInt::get(IndexTy, i);
|
offsetPointerIndexes[2] = llvm::ConstantInt::get(IndexTy, i);
|
||||||
// Get the correct ivar field
|
// Get the correct ivar field
|
||||||
llvm::Constant *offsetValue = llvm::ConstantExpr::getGetElementPtr(
|
llvm::Constant *offsetValue = llvm::ConstantExpr::getGetElementPtr(
|
||||||
IvarList, offsetPointerIndexes, 4);
|
IvarList, offsetPointerIndexes);
|
||||||
// Get the existing variable, if one exists.
|
// Get the existing variable, if one exists.
|
||||||
llvm::GlobalVariable *offset = TheModule.getNamedGlobal(Name);
|
llvm::GlobalVariable *offset = TheModule.getNamedGlobal(Name);
|
||||||
if (offset) {
|
if (offset) {
|
||||||
|
@ -2129,7 +2129,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), i), Zeros[0]};
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), i), Zeros[0]};
|
||||||
// FIXME: We're generating redundant loads and stores here!
|
// FIXME: We're generating redundant loads and stores here!
|
||||||
llvm::Constant *SelPtr = llvm::ConstantExpr::getGetElementPtr(SelectorList,
|
llvm::Constant *SelPtr = llvm::ConstantExpr::getGetElementPtr(SelectorList,
|
||||||
Idxs, 2);
|
makeArrayRef(Idxs, 2));
|
||||||
// If selectors are defined as an opaque type, cast the pointer to this
|
// If selectors are defined as an opaque type, cast the pointer to this
|
||||||
// type.
|
// type.
|
||||||
SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, SelectorTy);
|
SelPtr = llvm::ConstantExpr::getBitCast(SelPtr, SelectorTy);
|
||||||
|
|
|
@ -1375,7 +1375,7 @@ static llvm::Constant *getConstantGEP(llvm::LLVMContext &VMContext,
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx0),
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx0),
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx1)
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx1)
|
||||||
};
|
};
|
||||||
return llvm::ConstantExpr::getGetElementPtr(C, Idxs, 2);
|
return llvm::ConstantExpr::getGetElementPtr(C, Idxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// hasObjCExceptionAttribute - Return true if this class or any super
|
/// hasObjCExceptionAttribute - Return true if this class or any super
|
||||||
|
@ -6096,7 +6096,7 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 2);
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 2);
|
||||||
|
|
||||||
std::vector<llvm::Constant*> Values(3);
|
std::vector<llvm::Constant*> Values(3);
|
||||||
Values[0] = llvm::ConstantExpr::getGetElementPtr(VTableGV, &VTableIdx, 1);
|
Values[0] = llvm::ConstantExpr::getGetElementPtr(VTableGV, VTableIdx);
|
||||||
Values[1] = GetClassName(ID->getIdentifier());
|
Values[1] = GetClassName(ID->getIdentifier());
|
||||||
Values[2] = GetClassGlobal(ClassName);
|
Values[2] = GetClassGlobal(ClassName);
|
||||||
llvm::Constant *Init =
|
llvm::Constant *Init =
|
||||||
|
|
|
@ -484,7 +484,7 @@ void RTTIBuilder::BuildVTablePointer(const Type *Ty) {
|
||||||
|
|
||||||
// The vtable address point is 2.
|
// The vtable address point is 2.
|
||||||
llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
|
llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
|
||||||
VTable = llvm::ConstantExpr::getInBoundsGetElementPtr(VTable, &Two, 1);
|
VTable = llvm::ConstantExpr::getInBoundsGetElementPtr(VTable, Two);
|
||||||
VTable = llvm::ConstantExpr::getBitCast(VTable, Int8PtrTy);
|
VTable = llvm::ConstantExpr::getBitCast(VTable, Int8PtrTy);
|
||||||
|
|
||||||
Fields.push_back(VTable);
|
Fields.push_back(VTable);
|
||||||
|
|
|
@ -208,7 +208,7 @@ void VTTBuilder::AddVTablePointer(BaseSubobject Base, llvm::Constant *VTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
llvm::Constant *Init =
|
llvm::Constant *Init =
|
||||||
llvm::ConstantExpr::getInBoundsGetElementPtr(VTable, Idxs, 2);
|
llvm::ConstantExpr::getInBoundsGetElementPtr(VTable, Idxs);
|
||||||
|
|
||||||
llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
|
llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
|
||||||
Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
|
Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
|
||||||
|
|
|
@ -1715,7 +1715,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
||||||
"__CFConstantStringClassReference");
|
"__CFConstantStringClassReference");
|
||||||
// Decay array -> ptr
|
// Decay array -> ptr
|
||||||
CFConstantStringClassRef =
|
CFConstantStringClassRef =
|
||||||
llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
|
llvm::ConstantExpr::getGetElementPtr(GV, Zeros);
|
||||||
}
|
}
|
||||||
|
|
||||||
QualType CFTy = getContext().getCFConstantStringType();
|
QualType CFTy = getContext().getCFConstantStringType();
|
||||||
|
@ -1763,7 +1763,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
|
||||||
CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
|
CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
|
||||||
GV->setAlignment(Align.getQuantity());
|
GV->setAlignment(Align.getQuantity());
|
||||||
}
|
}
|
||||||
Fields[2] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
|
Fields[2] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros);
|
||||||
|
|
||||||
// String length.
|
// String length.
|
||||||
Ty = getTypes().ConvertType(getContext().LongTy);
|
Ty = getTypes().ConvertType(getContext().LongTy);
|
||||||
|
@ -1816,7 +1816,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) {
|
||||||
GV = CreateRuntimeVariable(PTy, str);
|
GV = CreateRuntimeVariable(PTy, str);
|
||||||
// Decay array -> ptr
|
// Decay array -> ptr
|
||||||
ConstantStringClassRef =
|
ConstantStringClassRef =
|
||||||
llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
|
llvm::ConstantExpr::getGetElementPtr(GV, Zeros);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1844,7 +1844,7 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) {
|
||||||
GV->setUnnamedAddr(true);
|
GV->setUnnamedAddr(true);
|
||||||
CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
|
CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
|
||||||
GV->setAlignment(Align.getQuantity());
|
GV->setAlignment(Align.getQuantity());
|
||||||
Fields[1] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
|
Fields[1] = llvm::ConstantExpr::getGetElementPtr(GV, Zeros);
|
||||||
|
|
||||||
// String length.
|
// String length.
|
||||||
llvm::Type *Ty = getTypes().ConvertType(getContext().UnsignedIntTy);
|
llvm::Type *Ty = getTypes().ConvertType(getContext().UnsignedIntTy);
|
||||||
|
|
|
@ -623,6 +623,8 @@ from the previous release.</p>
|
||||||
<li><code>ComputeLinearIndex</code> (in <code>llvm/CodeGen/Analysis.h</code>)</li>
|
<li><code>ComputeLinearIndex</code> (in <code>llvm/CodeGen/Analysis.h</code>)</li>
|
||||||
<li><code>ConstantArray::get</code></li>
|
<li><code>ConstantArray::get</code></li>
|
||||||
<li><code>ConstantExpr::getExtractElement</code></li>
|
<li><code>ConstantExpr::getExtractElement</code></li>
|
||||||
|
<li><code>ConstantExpr::getGetElementPtr</code></li>
|
||||||
|
<li><code>ConstantExpr::getInBoundsGetElementPtr</code></li>
|
||||||
<li><code>ConstantExpr::getIndices</code></li>
|
<li><code>ConstantExpr::getIndices</code></li>
|
||||||
<li><code>ConstantExpr::getInsertElement</code></li>
|
<li><code>ConstantExpr::getInsertElement</code></li>
|
||||||
<li><code>ConstantExpr::getWithOperands</code></li>
|
<li><code>ConstantExpr::getWithOperands</code></li>
|
||||||
|
|
|
@ -162,8 +162,7 @@ void BrainF::header(LLVMContext& C) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Constant *msgptr = ConstantExpr::
|
Constant *msgptr = ConstantExpr::
|
||||||
getGetElementPtr(aberrormsg, gep_params,
|
getGetElementPtr(aberrormsg, gep_params);
|
||||||
array_lengthof(gep_params));
|
|
||||||
|
|
||||||
Value *puts_params[] = {
|
Value *puts_params[] = {
|
||||||
msgptr
|
msgptr
|
||||||
|
|
|
@ -788,25 +788,40 @@ public:
|
||||||
/// all elements must be Constant's.
|
/// all elements must be Constant's.
|
||||||
///
|
///
|
||||||
static Constant *getGetElementPtr(Constant *C,
|
static Constant *getGetElementPtr(Constant *C,
|
||||||
Constant *const *IdxList, unsigned NumIdx,
|
ArrayRef<Constant *> IdxList,
|
||||||
bool InBounds = false) {
|
bool InBounds = false) {
|
||||||
return getGetElementPtr(C, (Value**)IdxList, NumIdx, InBounds);
|
return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
|
||||||
|
IdxList.size()),
|
||||||
|
InBounds);
|
||||||
}
|
}
|
||||||
static Constant *getGetElementPtr(Constant *C,
|
static Constant *getGetElementPtr(Constant *C,
|
||||||
Value *const *IdxList, unsigned NumIdx,
|
Constant *Idx,
|
||||||
|
bool InBounds = false) {
|
||||||
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
|
// ArrayRef<Value *>.
|
||||||
|
return getGetElementPtr(C, cast<Value>(Idx), InBounds);
|
||||||
|
}
|
||||||
|
static Constant *getGetElementPtr(Constant *C,
|
||||||
|
ArrayRef<Value *> IdxList,
|
||||||
bool InBounds = false);
|
bool InBounds = false);
|
||||||
|
|
||||||
/// Create an "inbounds" getelementptr. See the documentation for the
|
/// Create an "inbounds" getelementptr. See the documentation for the
|
||||||
/// "inbounds" flag in LangRef.html for details.
|
/// "inbounds" flag in LangRef.html for details.
|
||||||
static Constant *getInBoundsGetElementPtr(Constant *C,
|
static Constant *getInBoundsGetElementPtr(Constant *C,
|
||||||
Constant *const *IdxList,
|
ArrayRef<Constant *> IdxList) {
|
||||||
unsigned NumIdx) {
|
return getGetElementPtr(C, IdxList, true);
|
||||||
return getGetElementPtr(C, IdxList, NumIdx, true);
|
|
||||||
}
|
}
|
||||||
static Constant *getInBoundsGetElementPtr(Constant *C,
|
static Constant *getInBoundsGetElementPtr(Constant *C,
|
||||||
Value* const *IdxList,
|
Constant *Idx) {
|
||||||
unsigned NumIdx) {
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
return getGetElementPtr(C, IdxList, NumIdx, true);
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
|
// ArrayRef<Value *>.
|
||||||
|
return getGetElementPtr(C, Idx, true);
|
||||||
|
}
|
||||||
|
static Constant *getInBoundsGetElementPtr(Constant *C,
|
||||||
|
ArrayRef<Value *> IdxList) {
|
||||||
|
return getGetElementPtr(C, IdxList, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Constant *getExtractElement(Constant *Vec, Constant *Idx);
|
static Constant *getExtractElement(Constant *Vec, Constant *Idx);
|
||||||
|
|
|
@ -120,34 +120,32 @@ public:
|
||||||
|
|
||||||
Constant *CreateGetElementPtr(Constant *C,
|
Constant *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
|
return ConstantExpr::getGetElementPtr(C, IdxList);
|
||||||
}
|
}
|
||||||
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
|
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
|
||||||
// This form of the function only exists to avoid ambiguous overload
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
// ArrayRef<Value *>.
|
// ArrayRef<Value *>.
|
||||||
return ConstantExpr::getGetElementPtr(C, &Idx, 1);
|
return ConstantExpr::getGetElementPtr(C, Idx);
|
||||||
}
|
}
|
||||||
Constant *CreateGetElementPtr(Constant *C,
|
Constant *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
|
return ConstantExpr::getGetElementPtr(C, IdxList);
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
|
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
|
||||||
IdxList.size());
|
|
||||||
}
|
}
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
|
Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
|
||||||
// This form of the function only exists to avoid ambiguous overload
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
// ArrayRef<Value *>.
|
// ArrayRef<Value *>.
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1);
|
return ConstantExpr::getInBoundsGetElementPtr(C, Idx);
|
||||||
}
|
}
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
|
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
|
||||||
IdxList.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
|
|
@ -179,7 +179,7 @@ public:
|
||||||
|
|
||||||
Constant *CreateGetElementPtr(Constant *C,
|
Constant *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return ConstantExpr::getGetElementPtr(C, IdxList.data(), IdxList.size());
|
return ConstantExpr::getGetElementPtr(C, IdxList);
|
||||||
}
|
}
|
||||||
Instruction *CreateGetElementPtr(Constant *C,
|
Instruction *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
|
@ -188,8 +188,7 @@ public:
|
||||||
|
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
|
return ConstantExpr::getInBoundsGetElementPtr(C, IdxList);
|
||||||
IdxList.size());
|
|
||||||
}
|
}
|
||||||
Instruction *CreateInBoundsGetElementPtr(Constant *C,
|
Instruction *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
|
|
|
@ -132,36 +132,32 @@ public:
|
||||||
|
|
||||||
Constant *CreateGetElementPtr(Constant *C,
|
Constant *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
|
return Fold(ConstantExpr::getGetElementPtr(C, IdxList));
|
||||||
IdxList.size()));
|
|
||||||
}
|
}
|
||||||
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
|
Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const {
|
||||||
// This form of the function only exists to avoid ambiguous overload
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
// ArrayRef<Value *>.
|
// ArrayRef<Value *>.
|
||||||
return Fold(ConstantExpr::getGetElementPtr(C, &Idx, 1));
|
return Fold(ConstantExpr::getGetElementPtr(C, Idx));
|
||||||
}
|
}
|
||||||
Constant *CreateGetElementPtr(Constant *C,
|
Constant *CreateGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
return Fold(ConstantExpr::getGetElementPtr(C, IdxList.data(),
|
return Fold(ConstantExpr::getGetElementPtr(C, IdxList));
|
||||||
IdxList.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Constant *> IdxList) const {
|
ArrayRef<Constant *> IdxList) const {
|
||||||
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
|
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList));
|
||||||
IdxList.size()));
|
|
||||||
}
|
}
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
|
Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const {
|
||||||
// This form of the function only exists to avoid ambiguous overload
|
// This form of the function only exists to avoid ambiguous overload
|
||||||
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
// warnings about whether to convert Idx to ArrayRef<Constant *> or
|
||||||
// ArrayRef<Value *>.
|
// ArrayRef<Value *>.
|
||||||
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, &Idx, 1));
|
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, Idx));
|
||||||
}
|
}
|
||||||
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
Constant *CreateInBoundsGetElementPtr(Constant *C,
|
||||||
ArrayRef<Value *> IdxList) const {
|
ArrayRef<Value *> IdxList) const {
|
||||||
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList.data(),
|
return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList));
|
||||||
IdxList.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
|
|
@ -562,7 +562,7 @@ static Constant *CastGEPIndices(ArrayRef<Constant *> Ops,
|
||||||
if (!Any) return 0;
|
if (!Any) return 0;
|
||||||
|
|
||||||
Constant *C =
|
Constant *C =
|
||||||
ConstantExpr::getGetElementPtr(Ops[0], &NewIdxs[0], NewIdxs.size());
|
ConstantExpr::getGetElementPtr(Ops[0], NewIdxs);
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
|
||||||
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
if (Constant *Folded = ConstantFoldConstantExpression(CE, TD))
|
||||||
C = Folded;
|
C = Folded;
|
||||||
|
@ -702,7 +702,7 @@ static Constant *SymbolicallyEvaluateGEP(ArrayRef<Constant *> Ops,
|
||||||
|
|
||||||
// Create a GEP.
|
// Create a GEP.
|
||||||
Constant *C =
|
Constant *C =
|
||||||
ConstantExpr::getGetElementPtr(Ptr, &NewIdxs[0], NewIdxs.size());
|
ConstantExpr::getGetElementPtr(Ptr, NewIdxs);
|
||||||
assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
|
assert(cast<PointerType>(C->getType())->getElementType() == Ty &&
|
||||||
"Computed GetElementPtr has unexpected type!");
|
"Computed GetElementPtr has unexpected type!");
|
||||||
|
|
||||||
|
@ -889,8 +889,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
|
||||||
if (Constant *C = SymbolicallyEvaluateGEP(Ops, DestTy, TD))
|
if (Constant *C = SymbolicallyEvaluateGEP(Ops, DestTy, TD))
|
||||||
return C;
|
return C;
|
||||||
|
|
||||||
return ConstantExpr::getGetElementPtr(Ops[0], Ops.data() + 1,
|
return ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1));
|
||||||
Ops.size() - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2254,9 +2254,7 @@ Value *llvm::SimplifyGEPInst(ArrayRef<Value *> Ops,
|
||||||
if (!isa<Constant>(Ops[i]))
|
if (!isa<Constant>(Ops[i]))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return ConstantExpr::getGetElementPtr(cast<Constant>(Ops[0]),
|
return ConstantExpr::getGetElementPtr(cast<Constant>(Ops[0]), Ops.slice(1));
|
||||||
(Constant *const*)Ops.data() + 1,
|
|
||||||
Ops.size() - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SimplifyPHINode - See if we can fold the given phi. If not, returns null.
|
/// SimplifyPHINode - See if we can fold the given phi. If not, returns null.
|
||||||
|
|
|
@ -494,7 +494,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
||||||
// Fold a GEP with constant operands.
|
// Fold a GEP with constant operands.
|
||||||
if (Constant *CLHS = dyn_cast<Constant>(V))
|
if (Constant *CLHS = dyn_cast<Constant>(V))
|
||||||
if (Constant *CRHS = dyn_cast<Constant>(Idx))
|
if (Constant *CRHS = dyn_cast<Constant>(Idx))
|
||||||
return ConstantExpr::getGetElementPtr(CLHS, &CRHS, 1);
|
return ConstantExpr::getGetElementPtr(CLHS, CRHS);
|
||||||
|
|
||||||
// Do a quick scan to see if we have this GEP nearby. If so, reuse it.
|
// Do a quick scan to see if we have this GEP nearby. If so, reuse it.
|
||||||
unsigned ScanLimit = 6;
|
unsigned ScanLimit = 6;
|
||||||
|
|
|
@ -2273,16 +2273,14 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
||||||
if (Elts.size() == 0 || !Elts[0]->getType()->isPointerTy())
|
if (Elts.size() == 0 || !Elts[0]->getType()->isPointerTy())
|
||||||
return Error(ID.Loc, "getelementptr requires pointer operand");
|
return Error(ID.Loc, "getelementptr requires pointer operand");
|
||||||
|
|
||||||
|
ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
|
||||||
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
|
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
|
||||||
(Value**)(Elts.data() + 1),
|
(Value**)(Elts.data() + 1),
|
||||||
Elts.size() - 1))
|
Elts.size() - 1))
|
||||||
return Error(ID.Loc, "invalid indices for getelementptr");
|
return Error(ID.Loc, "invalid indices for getelementptr");
|
||||||
ID.ConstantVal = InBounds ?
|
ID.ConstantVal = InBounds ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(Elts[0],
|
ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices) :
|
||||||
Elts.data() + 1,
|
ConstantExpr::getGetElementPtr(Elts[0], Indices);
|
||||||
Elts.size() - 1) :
|
|
||||||
ConstantExpr::getGetElementPtr(Elts[0],
|
|
||||||
Elts.data() + 1, Elts.size() - 1);
|
|
||||||
} else if (Opc == Instruction::Select) {
|
} else if (Opc == Instruction::Select) {
|
||||||
if (Elts.size() != 3)
|
if (Elts.size() != 3)
|
||||||
return Error(ID.Loc, "expected three operands to select");
|
return Error(ID.Loc, "expected three operands to select");
|
||||||
|
|
|
@ -1351,12 +1351,11 @@ bool BitcodeReader::ParseConstants() {
|
||||||
if (!ElTy) return Error("Invalid CE_GEP record");
|
if (!ElTy) return Error("Invalid CE_GEP record");
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
||||||
}
|
}
|
||||||
|
ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
|
||||||
if (BitCode == bitc::CST_CODE_CE_INBOUNDS_GEP)
|
if (BitCode == bitc::CST_CODE_CE_INBOUNDS_GEP)
|
||||||
V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], &Elts[1],
|
V = ConstantExpr::getInBoundsGetElementPtr(Elts[0], Indices);
|
||||||
Elts.size()-1);
|
|
||||||
else
|
else
|
||||||
V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1],
|
V = ConstantExpr::getGetElementPtr(Elts[0], Indices);
|
||||||
Elts.size()-1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
||||||
|
|
|
@ -150,7 +150,7 @@ bool ARMGlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
|
||||||
ConstantInt::get(Int32Ty, 0),
|
ConstantInt::get(Int32Ty, 0),
|
||||||
ConstantInt::get(Int32Ty, k-i)
|
ConstantInt::get(Int32Ty, k-i)
|
||||||
};
|
};
|
||||||
Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx, 2);
|
Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx);
|
||||||
Globals[k]->replaceAllUsesWith(GEP);
|
Globals[k]->replaceAllUsesWith(GEP);
|
||||||
Globals[k]->eraseFromParent();
|
Globals[k]->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -596,8 +596,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) {
|
||||||
Idxs.push_back(NullInt);
|
Idxs.push_back(NullInt);
|
||||||
for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
|
for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
|
||||||
Idxs.push_back(CE->getOperand(i));
|
Idxs.push_back(CE->getOperand(i));
|
||||||
NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr),
|
NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr), Idxs);
|
||||||
&Idxs[0], Idxs.size());
|
|
||||||
} else {
|
} else {
|
||||||
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
|
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
|
||||||
SmallVector<Value*, 8> Idxs;
|
SmallVector<Value*, 8> Idxs;
|
||||||
|
@ -753,8 +752,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) {
|
||||||
break;
|
break;
|
||||||
if (Idxs.size() == GEPI->getNumOperands()-1)
|
if (Idxs.size() == GEPI->getNumOperands()-1)
|
||||||
Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
|
Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
|
||||||
ConstantExpr::getGetElementPtr(NewV, &Idxs[0],
|
ConstantExpr::getGetElementPtr(NewV, Idxs));
|
||||||
Idxs.size()));
|
|
||||||
if (GEPI->use_empty()) {
|
if (GEPI->use_empty()) {
|
||||||
Changed = true;
|
Changed = true;
|
||||||
GEPI->eraseFromParent();
|
GEPI->eraseFromParent();
|
||||||
|
@ -2410,8 +2408,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
||||||
i != e; ++i)
|
i != e; ++i)
|
||||||
GEPOps.push_back(getVal(Values, *i));
|
GEPOps.push_back(getVal(Values, *i));
|
||||||
InstResult = cast<GEPOperator>(GEP)->isInBounds() ?
|
InstResult = cast<GEPOperator>(GEP)->isInBounds() ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(P, &GEPOps[0], GEPOps.size()) :
|
ConstantExpr::getInBoundsGetElementPtr(P, GEPOps) :
|
||||||
ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size());
|
ConstantExpr::getGetElementPtr(P, GEPOps);
|
||||||
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
|
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
|
||||||
if (LI->isVolatile()) return false; // no volatile accesses.
|
if (LI->isVolatile()) return false; // no volatile accesses.
|
||||||
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
|
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
|
||||||
|
|
|
@ -51,8 +51,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
|
||||||
Constant::getNullValue(Type::getInt32Ty(Context)));
|
Constant::getNullValue(Type::getInt32Ty(Context)));
|
||||||
unsigned NumElements = 0;
|
unsigned NumElements = 0;
|
||||||
if (Array) {
|
if (Array) {
|
||||||
Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0],
|
Args[2] = ConstantExpr::getGetElementPtr(Array, GEPIndices);
|
||||||
GEPIndices.size());
|
|
||||||
NumElements =
|
NumElements =
|
||||||
cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
|
cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,7 +119,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
|
||||||
Indices[0] = Constant::getNullValue(Type::getInt32Ty(Context));
|
Indices[0] = Constant::getNullValue(Type::getInt32Ty(Context));
|
||||||
Indices[1] = ConstantInt::get(Type::getInt32Ty(Context), CounterNum);
|
Indices[1] = ConstantInt::get(Type::getInt32Ty(Context), CounterNum);
|
||||||
Constant *ElementPtr =
|
Constant *ElementPtr =
|
||||||
ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], Indices.size());
|
ConstantExpr::getGetElementPtr(CounterArray, Indices);
|
||||||
|
|
||||||
// Load, increment and store the value back.
|
// Load, increment and store the value back.
|
||||||
Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
|
Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
|
||||||
|
|
|
@ -920,7 +920,7 @@ static int AnalyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
|
||||||
llvm::Type::getInt8PtrTy(Src->getContext()));
|
llvm::Type::getInt8PtrTy(Src->getContext()));
|
||||||
Constant *OffsetCst =
|
Constant *OffsetCst =
|
||||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||||
Src = ConstantExpr::getGetElementPtr(Src, &OffsetCst, 1);
|
Src = ConstantExpr::getGetElementPtr(Src, OffsetCst);
|
||||||
Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
|
Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
|
||||||
if (ConstantFoldLoadFromConstPtr(Src, &TD))
|
if (ConstantFoldLoadFromConstPtr(Src, &TD))
|
||||||
return Offset;
|
return Offset;
|
||||||
|
@ -1081,7 +1081,7 @@ static Value *GetMemInstValueForLoad(MemIntrinsic *SrcInst, unsigned Offset,
|
||||||
llvm::Type::getInt8PtrTy(Src->getContext()));
|
llvm::Type::getInt8PtrTy(Src->getContext()));
|
||||||
Constant *OffsetCst =
|
Constant *OffsetCst =
|
||||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||||
Src = ConstantExpr::getGetElementPtr(Src, &OffsetCst, 1);
|
Src = ConstantExpr::getGetElementPtr(Src, OffsetCst);
|
||||||
Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
|
Src = ConstantExpr::getBitCast(Src, PointerType::getUnqual(LoadTy));
|
||||||
return ConstantFoldLoadFromConstPtr(Src, &TD);
|
return ConstantFoldLoadFromConstPtr(Src, &TD);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1180,8 +1180,8 @@ void SCCPSolver::visitGetElementPtrInst(GetElementPtrInst &I) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *Ptr = Operands[0];
|
Constant *Ptr = Operands[0];
|
||||||
markConstant(&I, ConstantExpr::getGetElementPtr(Ptr, &Operands[0]+1,
|
ArrayRef<Constant *> Indices(Operands.begin() + 1, Operands.end());
|
||||||
Operands.size()-1));
|
markConstant(&I, ConstantExpr::getGetElementPtr(Ptr, Indices));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SCCPSolver::visitStoreInst(StoreInst &SI) {
|
void SCCPSolver::visitStoreInst(StoreInst &SI) {
|
||||||
|
|
|
@ -127,8 +127,7 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
|
||||||
|
|
||||||
if (ElTy == DPTy->getElementType())
|
if (ElTy == DPTy->getElementType())
|
||||||
// This GEP is inbounds because all indices are zero.
|
// This GEP is inbounds because all indices are zero.
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0],
|
return ConstantExpr::getInBoundsGetElementPtr(V, IdxList);
|
||||||
IdxList.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle casts from one vector constant to another. We know that the src
|
// Handle casts from one vector constant to another. We know that the src
|
||||||
|
@ -2146,9 +2145,9 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
|
||||||
/// isInBoundsIndices - Test whether the given sequence of *normalized* indices
|
/// isInBoundsIndices - Test whether the given sequence of *normalized* indices
|
||||||
/// is "inbounds".
|
/// is "inbounds".
|
||||||
template<typename IndexTy>
|
template<typename IndexTy>
|
||||||
static bool isInBoundsIndices(IndexTy const *Idxs, size_t NumIdx) {
|
static bool isInBoundsIndices(ArrayRef<IndexTy> Idxs) {
|
||||||
// No indices means nothing that could be out of bounds.
|
// No indices means nothing that could be out of bounds.
|
||||||
if (NumIdx == 0) return true;
|
if (Idxs.empty()) return true;
|
||||||
|
|
||||||
// If the first index is zero, it's in bounds.
|
// If the first index is zero, it's in bounds.
|
||||||
if (cast<Constant>(Idxs[0])->isNullValue()) return true;
|
if (cast<Constant>(Idxs[0])->isNullValue()) return true;
|
||||||
|
@ -2157,7 +2156,7 @@ static bool isInBoundsIndices(IndexTy const *Idxs, size_t NumIdx) {
|
||||||
// by the one-past-the-end rule.
|
// by the one-past-the-end rule.
|
||||||
if (!cast<ConstantInt>(Idxs[0])->isOne())
|
if (!cast<ConstantInt>(Idxs[0])->isOne())
|
||||||
return false;
|
return false;
|
||||||
for (unsigned i = 1, e = NumIdx; i != e; ++i)
|
for (unsigned i = 1, e = Idxs.size(); i != e; ++i)
|
||||||
if (!cast<Constant>(Idxs[i])->isNullValue())
|
if (!cast<Constant>(Idxs[i])->isNullValue())
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -2234,11 +2233,8 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
||||||
NewIndices.append(Idxs.begin() + 1, Idxs.end());
|
NewIndices.append(Idxs.begin() + 1, Idxs.end());
|
||||||
return (inBounds && cast<GEPOperator>(CE)->isInBounds()) ?
|
return (inBounds && cast<GEPOperator>(CE)->isInBounds()) ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(CE->getOperand(0),
|
ConstantExpr::getInBoundsGetElementPtr(CE->getOperand(0),
|
||||||
&NewIndices[0],
|
NewIndices) :
|
||||||
NewIndices.size()) :
|
ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
|
||||||
ConstantExpr::getGetElementPtr(CE->getOperand(0),
|
|
||||||
&NewIndices[0],
|
|
||||||
NewIndices.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2256,9 +2252,9 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
||||||
if (CAT->getElementType() == SAT->getElementType())
|
if (CAT->getElementType() == SAT->getElementType())
|
||||||
return inBounds ?
|
return inBounds ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(
|
ConstantExpr::getInBoundsGetElementPtr(
|
||||||
(Constant*)CE->getOperand(0), Idxs.data(), Idxs.size()) :
|
(Constant*)CE->getOperand(0), Idxs) :
|
||||||
ConstantExpr::getGetElementPtr(
|
ConstantExpr::getGetElementPtr(
|
||||||
(Constant*)CE->getOperand(0), Idxs.data(), Idxs.size());
|
(Constant*)CE->getOperand(0), Idxs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2314,16 +2310,15 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
|
||||||
for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
|
for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
|
||||||
if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
|
if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
|
||||||
return inBounds ?
|
return inBounds ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(C, NewIdxs.data(),
|
ConstantExpr::getInBoundsGetElementPtr(C, NewIdxs) :
|
||||||
NewIdxs.size()) :
|
ConstantExpr::getGetElementPtr(C, NewIdxs);
|
||||||
ConstantExpr::getGetElementPtr(C, NewIdxs.data(), NewIdxs.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all indices are known integers and normalized, we can do a simple
|
// If all indices are known integers and normalized, we can do a simple
|
||||||
// check for the "inbounds" property.
|
// check for the "inbounds" property.
|
||||||
if (!Unknown && !inBounds &&
|
if (!Unknown && !inBounds &&
|
||||||
isa<GlobalVariable>(C) && isInBoundsIndices(Idxs.data(), Idxs.size()))
|
isa<GlobalVariable>(C) && isInBoundsIndices(Idxs))
|
||||||
return ConstantExpr::getInBoundsGetElementPtr(C, Idxs.data(), Idxs.size());
|
return ConstantExpr::getInBoundsGetElementPtr(C, Idxs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -840,12 +840,12 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const {
|
||||||
Ops[i-1] = getOperand(i);
|
Ops[i-1] = getOperand(i);
|
||||||
if (OpNo == 0)
|
if (OpNo == 0)
|
||||||
return cast<GEPOperator>(this)->isInBounds() ?
|
return cast<GEPOperator>(this)->isInBounds() ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(Op, &Ops[0], Ops.size()) :
|
ConstantExpr::getInBoundsGetElementPtr(Op, Ops) :
|
||||||
ConstantExpr::getGetElementPtr(Op, &Ops[0], Ops.size());
|
ConstantExpr::getGetElementPtr(Op, Ops);
|
||||||
Ops[OpNo-1] = Op;
|
Ops[OpNo-1] = Op;
|
||||||
return cast<GEPOperator>(this)->isInBounds() ?
|
return cast<GEPOperator>(this)->isInBounds() ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(getOperand(0), &Ops[0],Ops.size()):
|
ConstantExpr::getInBoundsGetElementPtr(getOperand(0), Ops) :
|
||||||
ConstantExpr::getGetElementPtr(getOperand(0), &Ops[0], Ops.size());
|
ConstantExpr::getGetElementPtr(getOperand(0), Ops);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assert(getNumOperands() == 2 && "Must be binary operator?");
|
assert(getNumOperands() == 2 && "Must be binary operator?");
|
||||||
|
@ -892,8 +892,8 @@ getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const {
|
||||||
return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
|
return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2]);
|
||||||
case Instruction::GetElementPtr:
|
case Instruction::GetElementPtr:
|
||||||
return cast<GEPOperator>(this)->isInBounds() ?
|
return cast<GEPOperator>(this)->isInBounds() ?
|
||||||
ConstantExpr::getInBoundsGetElementPtr(Ops[0], &Ops[1], Ops.size()-1) :
|
ConstantExpr::getInBoundsGetElementPtr(Ops[0], Ops.slice(1)) :
|
||||||
ConstantExpr::getGetElementPtr(Ops[0], &Ops[1], Ops.size()-1);
|
ConstantExpr::getGetElementPtr(Ops[0], Ops.slice(1));
|
||||||
case Instruction::ICmp:
|
case Instruction::ICmp:
|
||||||
case Instruction::FCmp:
|
case Instruction::FCmp:
|
||||||
return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);
|
return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1]);
|
||||||
|
@ -1518,7 +1518,7 @@ Constant *ConstantExpr::getSizeOf(Type* Ty) {
|
||||||
// Note that a non-inbounds gep is used, as null isn't within any object.
|
// Note that a non-inbounds gep is used, as null isn't within any object.
|
||||||
Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
|
Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
|
||||||
Constant *GEP = getGetElementPtr(
|
Constant *GEP = getGetElementPtr(
|
||||||
Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1);
|
Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
|
||||||
return getPtrToInt(GEP,
|
return getPtrToInt(GEP,
|
||||||
Type::getInt64Ty(Ty->getContext()));
|
Type::getInt64Ty(Ty->getContext()));
|
||||||
}
|
}
|
||||||
|
@ -1532,7 +1532,7 @@ Constant *ConstantExpr::getAlignOf(Type* Ty) {
|
||||||
Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0);
|
Constant *Zero = ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0);
|
||||||
Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
|
Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1);
|
||||||
Constant *Indices[2] = { Zero, One };
|
Constant *Indices[2] = { Zero, One };
|
||||||
Constant *GEP = getGetElementPtr(NullPtr, Indices, 2);
|
Constant *GEP = getGetElementPtr(NullPtr, Indices);
|
||||||
return getPtrToInt(GEP,
|
return getPtrToInt(GEP,
|
||||||
Type::getInt64Ty(Ty->getContext()));
|
Type::getInt64Ty(Ty->getContext()));
|
||||||
}
|
}
|
||||||
|
@ -1550,7 +1550,7 @@ Constant *ConstantExpr::getOffsetOf(Type* Ty, Constant *FieldNo) {
|
||||||
FieldNo
|
FieldNo
|
||||||
};
|
};
|
||||||
Constant *GEP = getGetElementPtr(
|
Constant *GEP = getGetElementPtr(
|
||||||
Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx, 2);
|
Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx);
|
||||||
return getPtrToInt(GEP,
|
return getPtrToInt(GEP,
|
||||||
Type::getInt64Ty(Ty->getContext()));
|
Type::getInt64Ty(Ty->getContext()));
|
||||||
}
|
}
|
||||||
|
@ -1592,15 +1592,14 @@ Constant *ConstantExpr::getSelect(Constant *C, Constant *V1, Constant *V2) {
|
||||||
return pImpl->ExprConstants.getOrCreate(V1->getType(), Key);
|
return pImpl->ExprConstants.getOrCreate(V1->getType(), Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
|
Constant *ConstantExpr::getGetElementPtr(Constant *C, ArrayRef<Value *> Idxs,
|
||||||
unsigned NumIdx, bool InBounds) {
|
bool InBounds) {
|
||||||
if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds,
|
if (Constant *FC = ConstantFoldGetElementPtr(C, InBounds, Idxs))
|
||||||
makeArrayRef(Idxs, NumIdx)))
|
|
||||||
return FC; // Fold a few common cases.
|
return FC; // Fold a few common cases.
|
||||||
|
|
||||||
// Get the result type of the getelementptr!
|
// Get the result type of the getelementptr!
|
||||||
Type *Ty =
|
Type *Ty =
|
||||||
GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
|
GetElementPtrInst::getIndexedType(C->getType(), Idxs.begin(), Idxs.end());
|
||||||
assert(Ty && "GEP indices invalid!");
|
assert(Ty && "GEP indices invalid!");
|
||||||
unsigned AS = cast<PointerType>(C->getType())->getAddressSpace();
|
unsigned AS = cast<PointerType>(C->getType())->getAddressSpace();
|
||||||
Type *ReqTy = Ty->getPointerTo(AS);
|
Type *ReqTy = Ty->getPointerTo(AS);
|
||||||
|
@ -1609,9 +1608,9 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
|
||||||
"Non-pointer type for constant GetElementPtr expression");
|
"Non-pointer type for constant GetElementPtr expression");
|
||||||
// Look up the constant in the table first to ensure uniqueness
|
// Look up the constant in the table first to ensure uniqueness
|
||||||
std::vector<Constant*> ArgVec;
|
std::vector<Constant*> ArgVec;
|
||||||
ArgVec.reserve(NumIdx+1);
|
ArgVec.reserve(1 + Idxs.size());
|
||||||
ArgVec.push_back(C);
|
ArgVec.push_back(C);
|
||||||
for (unsigned i = 0; i != NumIdx; ++i)
|
for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
|
||||||
ArgVec.push_back(cast<Constant>(Idxs[i]));
|
ArgVec.push_back(cast<Constant>(Idxs[i]));
|
||||||
const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
|
const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec, 0,
|
||||||
InBounds ? GEPOperator::IsInBounds : 0);
|
InBounds ? GEPOperator::IsInBounds : 0);
|
||||||
|
@ -2092,8 +2091,7 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
|
||||||
if (Val == From) Val = To;
|
if (Val == From) Val = To;
|
||||||
Indices.push_back(Val);
|
Indices.push_back(Val);
|
||||||
}
|
}
|
||||||
Replacement = ConstantExpr::getGetElementPtr(Pointer,
|
Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices,
|
||||||
&Indices[0], Indices.size(),
|
|
||||||
cast<GEPOperator>(this)->isInBounds());
|
cast<GEPOperator>(this)->isInBounds());
|
||||||
} else if (getOpcode() == Instruction::ExtractValue) {
|
} else if (getOpcode() == Instruction::ExtractValue) {
|
||||||
Constant *Agg = getOperand(0);
|
Constant *Agg = getOperand(0);
|
||||||
|
|
|
@ -792,18 +792,19 @@ LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
|
||||||
|
|
||||||
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
|
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
|
||||||
LLVMValueRef *ConstantIndices, unsigned NumIndices) {
|
LLVMValueRef *ConstantIndices, unsigned NumIndices) {
|
||||||
|
ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
|
||||||
|
NumIndices);
|
||||||
return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
|
return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
|
||||||
unwrap<Constant>(ConstantIndices,
|
IdxList));
|
||||||
NumIndices),
|
|
||||||
NumIndices));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
|
LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
|
||||||
LLVMValueRef *ConstantIndices,
|
LLVMValueRef *ConstantIndices,
|
||||||
unsigned NumIndices) {
|
unsigned NumIndices) {
|
||||||
Constant* Val = unwrap<Constant>(ConstantVal);
|
Constant* Val = unwrap<Constant>(ConstantVal);
|
||||||
Constant** Idxs = unwrap<Constant>(ConstantIndices, NumIndices);
|
ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
|
||||||
return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices));
|
NumIndices);
|
||||||
|
return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
|
||||||
|
|
|
@ -834,8 +834,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
|
||||||
// GetElementPtr *funcName, ulong 0, ulong 0
|
// GetElementPtr *funcName, ulong 0, ulong 0
|
||||||
std::vector<Constant*> GEPargs(2,
|
std::vector<Constant*> GEPargs(2,
|
||||||
Constant::getNullValue(Type::getInt32Ty(F->getContext())));
|
Constant::getNullValue(Type::getInt32Ty(F->getContext())));
|
||||||
Value *GEP =
|
Value *GEP = ConstantExpr::getGetElementPtr(funcName, GEPargs);
|
||||||
ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
|
|
||||||
std::vector<Value*> ResolverArgs;
|
std::vector<Value*> ResolverArgs;
|
||||||
ResolverArgs.push_back(GEP);
|
ResolverArgs.push_back(GEP);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue