[llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon May 2 22:43:44 PDT 2005
Changes in directory llvm/lib/VMCore:
Instructions.cpp updated: 1.15 -> 1.16
---
Log message:
add direct support for making GEP instrs with one index
---
Diffs of the changes: (+31 -0)
Instructions.cpp | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+)
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.15 llvm/lib/VMCore/Instructions.cpp:1.16
--- llvm/lib/VMCore/Instructions.cpp:1.15 Sun Apr 24 02:28:37 2005
+++ llvm/lib/VMCore/Instructions.cpp Tue May 3 00:43:30 2005
@@ -603,6 +603,13 @@
OL[2].init(Idx1, this);
}
+void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
+ NumOperands = 2;
+ Use *OL = OperandList = new Use[2];
+ OL[0].init(Ptr, this);
+ OL[1].init(Idx, this);
+}
+
GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
@@ -619,6 +626,20 @@
init(Ptr, Idx);
}
+GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
+ const std::string &Name, Instruction *InBe)
+ : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
+ GetElementPtr, 0, 0, Name, InBe) {
+ init(Ptr, Idx);
+}
+
+GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
+ const std::string &Name, BasicBlock *IAE)
+ : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
+ GetElementPtr, 0, 0, Name, IAE) {
+ init(Ptr, Idx);
+}
+
GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
@@ -700,6 +721,16 @@
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!
+
+ // Check the pointer index.
+ if (!PTy->indexValid(Idx)) return 0;
+
+ return PTy;
+}
+
//===----------------------------------------------------------------------===//
// BinaryOperator Class
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list