summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp8
-rw-r--r--llvm/lib/VMCore/ConstantFold.h3
-rw-r--r--llvm/lib/VMCore/Constants.cpp4
-rw-r--r--llvm/lib/VMCore/Instructions.cpp73
-rw-r--r--llvm/lib/VMCore/Verifier.cpp2
5 files changed, 11 insertions, 79 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index c950e8d07ff..fb2e65f6ba6 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -1350,7 +1350,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
}
Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
- Constant* const *Idxs,
+ Constant* const *Idxs,
unsigned NumIdx) {
if (NumIdx == 0 ||
(NumIdx == 1 && Idxs[0]->isNullValue()))
@@ -1358,7 +1358,8 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
if (isa<UndefValue>(C)) {
const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
- (Value**)Idxs, NumIdx,
+ (Value **)Idxs,
+ (Value **)Idxs+NumIdx,
true);
assert(Ty != 0 && "Invalid indices for GEP!");
return UndefValue::get(PointerType::get(Ty));
@@ -1374,7 +1375,8 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
}
if (isNull) {
const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(),
- (Value**)Idxs, NumIdx,
+ (Value**)Idxs,
+ (Value**)Idxs+NumIdx,
true);
assert(Ty != 0 && "Invalid indices for GEP!");
return ConstantPointerNull::get(PointerType::get(Ty));
diff --git a/llvm/lib/VMCore/ConstantFold.h b/llvm/lib/VMCore/ConstantFold.h
index e01fa770840..ffb7b1057e5 100644
--- a/llvm/lib/VMCore/ConstantFold.h
+++ b/llvm/lib/VMCore/ConstantFold.h
@@ -19,6 +19,8 @@
#ifndef CONSTANTFOLDING_H
#define CONSTANTFOLDING_H
+#include <iterator>
+
namespace llvm {
class Value;
class Constant;
@@ -46,6 +48,7 @@ namespace llvm {
Constant *ConstantFoldCompareInstruction(unsigned short predicate,
const Constant *C1,
const Constant *C2);
+
Constant *ConstantFoldGetElementPtr(const Constant *C,
Constant* const *Idxs, unsigned NumIdx);
} // End llvm namespace
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 8e3d946ec47..f7cbe82e72a 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -1799,7 +1799,7 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
Value* const *Idxs,
unsigned NumIdx) {
- assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true) &&
+ assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true) &&
"GEP indices invalid!");
if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs, NumIdx))
@@ -1821,7 +1821,7 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
unsigned NumIdx) {
// Get the result type of the getelementptr!
const Type *Ty =
- GetElementPtrInst::getIndexedType(C->getType(), Idxs, NumIdx, true);
+ GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx, true);
assert(Ty && "GEP indices invalid!");
return getGetElementPtrTy(PointerType::get(Ty), C, Idxs, NumIdx);
}
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index bb11a4b87bc..369e98afe37 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -864,14 +864,6 @@ void StoreInst::setAlignment(unsigned Align) {
// GetElementPtrInst Implementation
//===----------------------------------------------------------------------===//
-// checkType - Simple wrapper function to give a better assertion failure
-// message on bad indexes for a gep instruction.
-//
-static inline const Type *checkType(const Type *Ty) {
- assert(Ty && "Invalid GetElementPtrInst indices for type!");
- return Ty;
-}
-
void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
NumOperands = 1+NumIdx;
Use *OL = OperandList = new Use[NumOperands];
@@ -881,14 +873,6 @@ void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
OL[i+1].init(Idx[i], this);
}
-void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) {
- NumOperands = 3;
- Use *OL = OperandList = new Use[3];
- OL[0].init(Ptr, this);
- OL[1].init(Idx0, this);
- OL[2].init(Idx1, this);
-}
-
void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
NumOperands = 2;
Use *OL = OperandList = new Use[2];
@@ -896,27 +880,6 @@ void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
OL[1].init(Idx, this);
}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
- unsigned NumIdx,
- const std::string &Name, Instruction *InBe)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx, NumIdx, true))),
- GetElementPtr, 0, 0, InBe) {
- init(Ptr, Idx, NumIdx);
- setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
- unsigned NumIdx,
- const std::string &Name, BasicBlock *IAE)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx, NumIdx, true))),
- GetElementPtr, 0, 0, IAE) {
- init(Ptr, Idx, NumIdx);
- setName(Name);
-}
-
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
@@ -933,24 +896,6 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
setName(Name);
}
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
- const std::string &Name, Instruction *InBe)
- : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx0, Idx1, true))),
- GetElementPtr, 0, 0, InBe) {
- init(Ptr, Idx0, Idx1);
- setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
- const std::string &Name, BasicBlock *IAE)
- : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
- Idx0, Idx1, true))),
- GetElementPtr, 0, 0, IAE) {
- init(Ptr, Idx0, Idx1);
- setName(Name);
-}
-
GetElementPtrInst::~GetElementPtrInst() {
delete[] OperandList;
}
@@ -999,24 +944,6 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
return CurIdx == NumIdx ? Ptr : 0;
}
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
- Value *Idx0, Value *Idx1,
- bool AllowCompositeLeaf) {
- const PointerType *PTy = dyn_cast<PointerType>(Ptr);
- if (!PTy) return 0; // Type isn't a pointer type!
-
- // Check the pointer index.
- if (!PTy->indexValid(Idx0)) return 0;
-
- const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType());
- if (!CT || !CT->indexValid(Idx1)) return 0;
-
- const Type *ElTy = CT->getTypeAtIndex(Idx1);
- if (AllowCompositeLeaf || ElTy->isFirstClassType())
- return ElTy;
- return 0;
-}
-
const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
const PointerType *PTy = dyn_cast<PointerType>(Ptr);
if (!PTy) return 0; // Type isn't a pointer type!
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp
index 49f6abd0807..58bf485512a 100644
--- a/llvm/lib/VMCore/Verifier.cpp
+++ b/llvm/lib/VMCore/Verifier.cpp
@@ -913,7 +913,7 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
SmallVector<Value*, 16> Idxs(GEP.idx_begin(), GEP.idx_end());
const Type *ElTy =
GetElementPtrInst::getIndexedType(GEP.getOperand(0)->getType(),
- &Idxs[0], Idxs.size(), true);
+ Idxs.begin(), Idxs.end(), true);
Assert1(ElTy, "Invalid indices for GEP pointer type!", &GEP);
Assert2(isa<PointerType>(GEP.getType()) &&
cast<PointerType>(GEP.getType())->getElementType() == ElTy,
OpenPOWER on IntegriCloud