diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-05-03 05:43:30 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-05-03 05:43:30 +0000 |
| commit | 8298120f17f43a78bb57c0b9ab8d4f95fc1c917a (patch) | |
| tree | 9c41551b59b1b5b95f7a38b58c50a61636c6f825 /llvm/lib | |
| parent | cc427556335b07f3043c1e34ddab1691cf3aedcc (diff) | |
| download | bcm5719-llvm-8298120f17f43a78bb57c0b9ab8d4f95fc1c917a.tar.gz bcm5719-llvm-8298120f17f43a78bb57c0b9ab8d4f95fc1c917a.zip | |
add direct support for making GEP instrs with one index
llvm-svn: 21665
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index c2e7254e93a..8404e0bad8e 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -603,6 +603,13 @@ void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) { 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 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx, 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 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, 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 //===----------------------------------------------------------------------===// |

