Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 1 | //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 2 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 7 | // |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file exposes the class definitions of all of the subclasses of the |
| 11 | // Instruction class. This is meant to be an easy way to get access to all |
| 12 | // instruction subclasses. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_INSTRUCTIONS_H |
| 17 | #define LLVM_INSTRUCTIONS_H |
| 18 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 19 | #include "llvm/InstrTypes.h" |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 20 | #include "llvm/DerivedTypes.h" |
Devang Patel | eaf42ab | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 21 | #include "llvm/Attributes.h" |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 22 | #include "llvm/BasicBlock.h" |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 23 | #include "llvm/CallingConv.h" |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 24 | #include "llvm/LLVMContext.h" |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
Dan Gohman | d68a076 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 26 | #include <iterator> |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 27 | |
| 28 | namespace llvm { |
| 29 | |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 30 | class ConstantInt; |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 31 | class ConstantRange; |
| 32 | class APInt; |
Benjamin Kramer | 12ddd40 | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 33 | class LLVMContext; |
Dan Gohman | bccfc24 | 2009-09-03 15:34:35 +0000 | [diff] [blame] | 34 | class DominatorTree; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 35 | |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | // AllocationInst Class |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | /// AllocationInst - This class is the common base class of MallocInst and |
| 41 | /// AllocaInst. |
| 42 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 43 | class AllocationInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 44 | protected: |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 45 | AllocationInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 46 | unsigned iTy, unsigned Align, const Twine &Name = "", |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 47 | Instruction *InsertBefore = 0); |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 48 | AllocationInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 49 | unsigned iTy, unsigned Align, const Twine &Name, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 50 | BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 51 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 52 | // Out of line virtual method, so the vtable, etc. has a home. |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 53 | virtual ~AllocationInst(); |
| 54 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 55 | /// isArrayAllocation - Return true if there is an allocation size parameter |
| 56 | /// to the allocation instruction that is not 1. |
| 57 | /// |
| 58 | bool isArrayAllocation() const; |
| 59 | |
Dan Gohman | 18476ee | 2009-07-07 20:47:48 +0000 | [diff] [blame] | 60 | /// getArraySize - Get the number of elements allocated. For a simple |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 61 | /// allocation of a single element, this will return a constant 1 value. |
| 62 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 63 | const Value *getArraySize() const { return getOperand(0); } |
| 64 | Value *getArraySize() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 65 | |
| 66 | /// getType - Overload to return most specific pointer type |
| 67 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 68 | const PointerType *getType() const { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 69 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /// getAllocatedType - Return the type that is being allocated by the |
| 73 | /// instruction. |
| 74 | /// |
| 75 | const Type *getAllocatedType() const; |
| 76 | |
Nate Begeman | 14b0529 | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 77 | /// getAlignment - Return the alignment of the memory that is being allocated |
| 78 | /// by the instruction. |
| 79 | /// |
Dan Gohman | 5283707 | 2008-03-24 16:55:58 +0000 | [diff] [blame] | 80 | unsigned getAlignment() const { return (1u << SubclassData) >> 1; } |
| 81 | void setAlignment(unsigned Align); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 82 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 83 | virtual AllocationInst *clone() const = 0; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 84 | |
| 85 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 86 | static inline bool classof(const AllocationInst *) { return true; } |
| 87 | static inline bool classof(const Instruction *I) { |
| 88 | return I->getOpcode() == Instruction::Alloca || |
| 89 | I->getOpcode() == Instruction::Malloc; |
| 90 | } |
| 91 | static inline bool classof(const Value *V) { |
| 92 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | //===----------------------------------------------------------------------===// |
| 98 | // MallocInst Class |
| 99 | //===----------------------------------------------------------------------===// |
| 100 | |
| 101 | /// MallocInst - an instruction to allocated memory on the heap |
| 102 | /// |
| 103 | class MallocInst : public AllocationInst { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 104 | public: |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 105 | explicit MallocInst(const Type *Ty, Value *ArraySize = 0, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 106 | const Twine &NameStr = "", |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 107 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 108 | : AllocationInst(Ty, ArraySize, Malloc, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 109 | 0, NameStr, InsertBefore) {} |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 110 | MallocInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 111 | const Twine &NameStr, BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 112 | : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {} |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 113 | |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 114 | MallocInst(const Type *Ty, const Twine &NameStr, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 115 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 116 | : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {} |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 117 | MallocInst(const Type *Ty, const Twine &NameStr, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 118 | BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 119 | : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {} |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 120 | |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 121 | MallocInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 122 | unsigned Align, const Twine &NameStr, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 123 | BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 124 | : AllocationInst(Ty, ArraySize, Malloc, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 125 | Align, NameStr, InsertAtEnd) {} |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 126 | MallocInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 127 | unsigned Align, const Twine &NameStr = "", |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 128 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 129 | : AllocationInst(Ty, ArraySize, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 130 | Malloc, Align, NameStr, InsertBefore) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 131 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 132 | virtual MallocInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 133 | |
| 134 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 135 | static inline bool classof(const MallocInst *) { return true; } |
| 136 | static inline bool classof(const Instruction *I) { |
| 137 | return (I->getOpcode() == Instruction::Malloc); |
| 138 | } |
| 139 | static inline bool classof(const Value *V) { |
| 140 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | //===----------------------------------------------------------------------===// |
| 146 | // AllocaInst Class |
| 147 | //===----------------------------------------------------------------------===// |
| 148 | |
| 149 | /// AllocaInst - an instruction to allocate memory on the stack |
| 150 | /// |
| 151 | class AllocaInst : public AllocationInst { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 152 | public: |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 153 | explicit AllocaInst(const Type *Ty, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 154 | Value *ArraySize = 0, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 155 | const Twine &NameStr = "", |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 156 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 157 | : AllocationInst(Ty, ArraySize, Alloca, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 158 | 0, NameStr, InsertBefore) {} |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 159 | AllocaInst(const Type *Ty, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 160 | Value *ArraySize, const Twine &NameStr, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 161 | BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 162 | : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {} |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 163 | |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 164 | AllocaInst(const Type *Ty, const Twine &NameStr, |
Chris Lattner | b77780e | 2006-05-10 04:38:35 +0000 | [diff] [blame] | 165 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 166 | : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {} |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 167 | AllocaInst(const Type *Ty, const Twine &NameStr, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 168 | BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 169 | : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 170 | |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 171 | AllocaInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 172 | unsigned Align, const Twine &NameStr = "", |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 173 | Instruction *InsertBefore = 0) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 174 | : AllocationInst(Ty, ArraySize, Alloca, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 175 | Align, NameStr, InsertBefore) {} |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 176 | AllocaInst(const Type *Ty, Value *ArraySize, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 177 | unsigned Align, const Twine &NameStr, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 178 | BasicBlock *InsertAtEnd) |
Owen Anderson | 50dead0 | 2009-07-15 23:53:25 +0000 | [diff] [blame] | 179 | : AllocationInst(Ty, ArraySize, Alloca, |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 180 | Align, NameStr, InsertAtEnd) {} |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 181 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 182 | virtual AllocaInst *clone() const; |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 183 | |
Chris Lattner | c5dd22a | 2008-11-26 02:54:17 +0000 | [diff] [blame] | 184 | /// isStaticAlloca - Return true if this alloca is in the entry block of the |
| 185 | /// function and is a constant size. If so, the code generator will fold it |
| 186 | /// into the prolog/epilog code, so it is basically free. |
| 187 | bool isStaticAlloca() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 188 | |
| 189 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 190 | static inline bool classof(const AllocaInst *) { return true; } |
| 191 | static inline bool classof(const Instruction *I) { |
| 192 | return (I->getOpcode() == Instruction::Alloca); |
| 193 | } |
| 194 | static inline bool classof(const Value *V) { |
| 195 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | |
| 200 | //===----------------------------------------------------------------------===// |
| 201 | // FreeInst Class |
| 202 | //===----------------------------------------------------------------------===// |
| 203 | |
| 204 | /// FreeInst - an instruction to deallocate memory |
| 205 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 206 | class FreeInst : public UnaryInstruction { |
| 207 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 208 | public: |
| 209 | explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0); |
| 210 | FreeInst(Value *Ptr, BasicBlock *InsertAfter); |
| 211 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 212 | virtual FreeInst *clone() const; |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 213 | |
Owen Anderson | c9edf0b | 2007-07-06 23:13:31 +0000 | [diff] [blame] | 214 | // Accessor methods for consistency with other memory operations |
| 215 | Value *getPointerOperand() { return getOperand(0); } |
| 216 | const Value *getPointerOperand() const { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 217 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 218 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 219 | static inline bool classof(const FreeInst *) { return true; } |
| 220 | static inline bool classof(const Instruction *I) { |
| 221 | return (I->getOpcode() == Instruction::Free); |
| 222 | } |
| 223 | static inline bool classof(const Value *V) { |
| 224 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | //===----------------------------------------------------------------------===// |
| 230 | // LoadInst Class |
| 231 | //===----------------------------------------------------------------------===// |
| 232 | |
Chris Lattner | 88fe29a | 2005-02-05 01:44:18 +0000 | [diff] [blame] | 233 | /// LoadInst - an instruction for reading from memory. This uses the |
| 234 | /// SubclassData field in Value to store whether or not the load is volatile. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 235 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 236 | class LoadInst : public UnaryInstruction { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 237 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 238 | public: |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 239 | LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore); |
| 240 | LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd); |
Daniel Dunbar | 3603d7a | 2009-08-11 18:11:15 +0000 | [diff] [blame] | 241 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false, |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 242 | Instruction *InsertBefore = 0); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 243 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 244 | unsigned Align, Instruction *InsertBefore = 0); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 245 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 246 | BasicBlock *InsertAtEnd); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 247 | LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 248 | unsigned Align, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 249 | |
Daniel Dunbar | 3603d7a | 2009-08-11 18:11:15 +0000 | [diff] [blame] | 250 | LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore); |
| 251 | LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd); |
| 252 | explicit LoadInst(Value *Ptr, const char *NameStr = 0, |
| 253 | bool isVolatile = false, Instruction *InsertBefore = 0); |
| 254 | LoadInst(Value *Ptr, const char *NameStr, bool isVolatile, |
| 255 | BasicBlock *InsertAtEnd); |
| 256 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 257 | /// isVolatile - Return true if this is a load from a volatile memory |
| 258 | /// location. |
| 259 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 260 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 261 | |
| 262 | /// setVolatile - Specify whether this is a volatile load or not. |
| 263 | /// |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 264 | void setVolatile(bool V) { |
| 265 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 266 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 267 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 268 | virtual LoadInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 269 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 270 | /// getAlignment - Return the alignment of the access that is being performed |
| 271 | /// |
| 272 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 273 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 274 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 275 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 276 | void setAlignment(unsigned Align); |
| 277 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 278 | Value *getPointerOperand() { return getOperand(0); } |
| 279 | const Value *getPointerOperand() const { return getOperand(0); } |
| 280 | static unsigned getPointerOperandIndex() { return 0U; } |
| 281 | |
Chris Lattner | a07ae6b | 2009-08-30 19:45:21 +0000 | [diff] [blame] | 282 | unsigned getPointerAddressSpace() const { |
| 283 | return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace(); |
| 284 | } |
| 285 | |
| 286 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 287 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 288 | static inline bool classof(const LoadInst *) { return true; } |
| 289 | static inline bool classof(const Instruction *I) { |
| 290 | return I->getOpcode() == Instruction::Load; |
| 291 | } |
| 292 | static inline bool classof(const Value *V) { |
| 293 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 294 | } |
| 295 | }; |
| 296 | |
| 297 | |
| 298 | //===----------------------------------------------------------------------===// |
| 299 | // StoreInst Class |
| 300 | //===----------------------------------------------------------------------===// |
| 301 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 302 | /// StoreInst - an instruction for storing to memory |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 303 | /// |
| 304 | class StoreInst : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 305 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 306 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 307 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 308 | // allocate space for exactly two operands |
| 309 | void *operator new(size_t s) { |
| 310 | return User::operator new(s, 2); |
| 311 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 312 | StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore); |
| 313 | StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); |
| 314 | StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, |
| 315 | Instruction *InsertBefore = 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 316 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 317 | unsigned Align, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 318 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd); |
Dan Gohman | 6ab2d18 | 2007-07-18 20:51:11 +0000 | [diff] [blame] | 319 | StoreInst(Value *Val, Value *Ptr, bool isVolatile, |
| 320 | unsigned Align, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 321 | |
| 322 | |
| 323 | /// isVolatile - Return true if this is a load from a volatile memory |
| 324 | /// location. |
| 325 | /// |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 326 | bool isVolatile() const { return SubclassData & 1; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 327 | |
| 328 | /// setVolatile - Specify whether this is a volatile load or not. |
| 329 | /// |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 330 | void setVolatile(bool V) { |
| 331 | SubclassData = (SubclassData & ~1) | (V ? 1 : 0); |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 332 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 333 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 334 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 335 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 336 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 337 | /// getAlignment - Return the alignment of the access that is being performed |
| 338 | /// |
| 339 | unsigned getAlignment() const { |
Christopher Lamb | 032507d | 2007-04-22 22:22:02 +0000 | [diff] [blame] | 340 | return (1 << (SubclassData>>1)) >> 1; |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 341 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 342 | |
Christopher Lamb | 43c7f37 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 343 | void setAlignment(unsigned Align); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 344 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 345 | virtual StoreInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 346 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 347 | Value *getPointerOperand() { return getOperand(1); } |
| 348 | const Value *getPointerOperand() const { return getOperand(1); } |
| 349 | static unsigned getPointerOperandIndex() { return 1U; } |
| 350 | |
Chris Lattner | a07ae6b | 2009-08-30 19:45:21 +0000 | [diff] [blame] | 351 | unsigned getPointerAddressSpace() const { |
| 352 | return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace(); |
| 353 | } |
| 354 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 355 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 356 | static inline bool classof(const StoreInst *) { return true; } |
| 357 | static inline bool classof(const Instruction *I) { |
| 358 | return I->getOpcode() == Instruction::Store; |
| 359 | } |
| 360 | static inline bool classof(const Value *V) { |
| 361 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 362 | } |
| 363 | }; |
| 364 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 365 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 366 | struct OperandTraits<StoreInst> : public FixedNumOperandTraits<2> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 370 | |
| 371 | //===----------------------------------------------------------------------===// |
| 372 | // GetElementPtrInst Class |
| 373 | //===----------------------------------------------------------------------===// |
| 374 | |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 375 | // checkType - Simple wrapper function to give a better assertion failure |
| 376 | // message on bad indexes for a gep instruction. |
| 377 | // |
| 378 | static inline const Type *checkType(const Type *Ty) { |
| 379 | assert(Ty && "Invalid GetElementPtrInst indices for type!"); |
| 380 | return Ty; |
| 381 | } |
| 382 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 383 | /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to |
| 384 | /// access elements of arrays and structs |
| 385 | /// |
| 386 | class GetElementPtrInst : public Instruction { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 387 | GetElementPtrInst(const GetElementPtrInst &GEPI); |
Matthijs Kooijman | cfd5b7d | 2008-06-05 07:26:15 +0000 | [diff] [blame] | 388 | void init(Value *Ptr, Value* const *Idx, unsigned NumIdx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 389 | const Twine &NameStr); |
| 390 | void init(Value *Ptr, Value *Idx, const Twine &NameStr); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 391 | |
| 392 | template<typename InputIterator> |
| 393 | void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 394 | const Twine &NameStr, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 395 | // This argument ensures that we have an iterator we can |
| 396 | // do arithmetic on in constant time |
| 397 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 398 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 399 | |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 400 | if (NumIdx > 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 401 | // This requires that the iterator points to contiguous memory. |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 402 | init(Ptr, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 403 | // we have to build an array here |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 404 | } |
| 405 | else { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 406 | init(Ptr, 0, NumIdx, NameStr); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 407 | } |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 411 | /// a load instruction with the specified parameters. |
| 412 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 413 | /// Null is returned if the indices are invalid for the specified |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 414 | /// pointer type. |
| 415 | /// |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 416 | template<typename InputIterator> |
| 417 | static const Type *getIndexedType(const Type *Ptr, |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 418 | InputIterator IdxBegin, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 419 | InputIterator IdxEnd, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 420 | // This argument ensures that we |
| 421 | // have an iterator we can do |
| 422 | // arithmetic on in constant time |
| 423 | std::random_access_iterator_tag) { |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 424 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 425 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 426 | if (NumIdx > 0) |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 427 | // This requires that the iterator points to contiguous memory. |
David Greene | 2d5a0b9 | 2008-10-29 00:30:54 +0000 | [diff] [blame] | 428 | return getIndexedType(Ptr, &*IdxBegin, NumIdx); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 429 | else |
| 430 | return getIndexedType(Ptr, (Value *const*)0, NumIdx); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 433 | /// Constructors - Create a getelementptr instruction with a base pointer an |
| 434 | /// list of indices. The first ctor can optionally insert before an existing |
| 435 | /// instruction, the second appends the new instruction to the specified |
| 436 | /// BasicBlock. |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 437 | template<typename InputIterator> |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 438 | inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 439 | InputIterator IdxEnd, |
| 440 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 441 | const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 442 | Instruction *InsertBefore); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 443 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 444 | inline GetElementPtrInst(Value *Ptr, |
| 445 | InputIterator IdxBegin, InputIterator IdxEnd, |
| 446 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 447 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 448 | |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 449 | /// Constructors - These two constructors are convenience methods because one |
| 450 | /// and two index getelementptr instructions are so common. |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 451 | GetElementPtrInst(Value *Ptr, Value *Idx, const Twine &NameStr = "", |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 452 | Instruction *InsertBefore = 0); |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 453 | GetElementPtrInst(Value *Ptr, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 454 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 455 | public: |
| 456 | template<typename InputIterator> |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 457 | static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 458 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 459 | const Twine &NameStr = "", |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 460 | Instruction *InsertBefore = 0) { |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 461 | typename std::iterator_traits<InputIterator>::difference_type Values = |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 462 | 1 + std::distance(IdxBegin, IdxEnd); |
| 463 | return new(Values) |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 464 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 465 | } |
| 466 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 467 | static GetElementPtrInst *Create(Value *Ptr, |
| 468 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 469 | const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 470 | BasicBlock *InsertAtEnd) { |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 471 | typename std::iterator_traits<InputIterator>::difference_type Values = |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 472 | 1 + std::distance(IdxBegin, IdxEnd); |
| 473 | return new(Values) |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 474 | GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 477 | /// Constructors - These two creators are convenience methods because one |
| 478 | /// index getelementptr instructions are so common. |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 479 | static GetElementPtrInst *Create(Value *Ptr, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 480 | const Twine &NameStr = "", |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 481 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 482 | return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 483 | } |
| 484 | static GetElementPtrInst *Create(Value *Ptr, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 485 | const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 486 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 487 | return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 488 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 489 | |
Dan Gohman | e2574d3 | 2009-08-11 17:57:01 +0000 | [diff] [blame] | 490 | /// Create an "inbounds" getelementptr. See the documentation for the |
| 491 | /// "inbounds" flag in LangRef.html for details. |
| 492 | template<typename InputIterator> |
| 493 | static GetElementPtrInst *CreateInBounds(Value *Ptr, InputIterator IdxBegin, |
| 494 | InputIterator IdxEnd, |
| 495 | const Twine &NameStr = "", |
| 496 | Instruction *InsertBefore = 0) { |
| 497 | GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd, |
| 498 | NameStr, InsertBefore); |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 499 | GEP->setIsInBounds(true); |
Dan Gohman | e2574d3 | 2009-08-11 17:57:01 +0000 | [diff] [blame] | 500 | return GEP; |
| 501 | } |
| 502 | template<typename InputIterator> |
| 503 | static GetElementPtrInst *CreateInBounds(Value *Ptr, |
| 504 | InputIterator IdxBegin, |
| 505 | InputIterator IdxEnd, |
| 506 | const Twine &NameStr, |
| 507 | BasicBlock *InsertAtEnd) { |
| 508 | GetElementPtrInst *GEP = Create(Ptr, IdxBegin, IdxEnd, |
| 509 | NameStr, InsertAtEnd); |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 510 | GEP->setIsInBounds(true); |
Dan Gohman | e2574d3 | 2009-08-11 17:57:01 +0000 | [diff] [blame] | 511 | return GEP; |
| 512 | } |
| 513 | static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx, |
| 514 | const Twine &NameStr = "", |
| 515 | Instruction *InsertBefore = 0) { |
| 516 | GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertBefore); |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 517 | GEP->setIsInBounds(true); |
Dan Gohman | e2574d3 | 2009-08-11 17:57:01 +0000 | [diff] [blame] | 518 | return GEP; |
| 519 | } |
| 520 | static GetElementPtrInst *CreateInBounds(Value *Ptr, Value *Idx, |
| 521 | const Twine &NameStr, |
| 522 | BasicBlock *InsertAtEnd) { |
| 523 | GetElementPtrInst *GEP = Create(Ptr, Idx, NameStr, InsertAtEnd); |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 524 | GEP->setIsInBounds(true); |
Dan Gohman | e2574d3 | 2009-08-11 17:57:01 +0000 | [diff] [blame] | 525 | return GEP; |
| 526 | } |
| 527 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 528 | virtual GetElementPtrInst *clone() const; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 529 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 530 | /// Transparently provide more efficient getOperand methods. |
| 531 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 532 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 533 | // getType - Overload to return most specific pointer type... |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 534 | const PointerType *getType() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 535 | return reinterpret_cast<const PointerType*>(Instruction::getType()); |
| 536 | } |
| 537 | |
| 538 | /// getIndexedType - Returns the type of the element that would be loaded with |
| 539 | /// a load instruction with the specified parameters. |
| 540 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 541 | /// Null is returned if the indices are invalid for the specified |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 542 | /// pointer type. |
| 543 | /// |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 544 | template<typename InputIterator> |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 545 | static const Type *getIndexedType(const Type *Ptr, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 546 | InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 547 | InputIterator IdxEnd) { |
| 548 | return getIndexedType(Ptr, IdxBegin, IdxEnd, |
David Greene | b8f7479 | 2007-09-04 15:46:09 +0000 | [diff] [blame] | 549 | typename std::iterator_traits<InputIterator>:: |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 550 | iterator_category()); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 551 | } |
Matthijs Kooijman | e2afded | 2008-07-29 08:46:11 +0000 | [diff] [blame] | 552 | |
| 553 | static const Type *getIndexedType(const Type *Ptr, |
| 554 | Value* const *Idx, unsigned NumIdx); |
| 555 | |
| 556 | static const Type *getIndexedType(const Type *Ptr, |
| 557 | uint64_t const *Idx, unsigned NumIdx); |
| 558 | |
Chris Lattner | 38bacf2 | 2005-05-03 05:43:30 +0000 | [diff] [blame] | 559 | static const Type *getIndexedType(const Type *Ptr, Value *Idx); |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 560 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 561 | inline op_iterator idx_begin() { return op_begin()+1; } |
| 562 | inline const_op_iterator idx_begin() const { return op_begin()+1; } |
| 563 | inline op_iterator idx_end() { return op_end(); } |
| 564 | inline const_op_iterator idx_end() const { return op_end(); } |
| 565 | |
| 566 | Value *getPointerOperand() { |
| 567 | return getOperand(0); |
| 568 | } |
| 569 | const Value *getPointerOperand() const { |
| 570 | return getOperand(0); |
| 571 | } |
| 572 | static unsigned getPointerOperandIndex() { |
| 573 | return 0U; // get index for modifying correct operand |
| 574 | } |
Chris Lattner | 8a67ac5 | 2009-08-30 20:06:40 +0000 | [diff] [blame] | 575 | |
| 576 | unsigned getPointerAddressSpace() const { |
| 577 | return cast<PointerType>(getType())->getAddressSpace(); |
| 578 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 579 | |
Chris Lattner | 3bc6ced | 2009-01-09 05:27:40 +0000 | [diff] [blame] | 580 | /// getPointerOperandType - Method to return the pointer operand as a |
| 581 | /// PointerType. |
| 582 | const PointerType *getPointerOperandType() const { |
| 583 | return reinterpret_cast<const PointerType*>(getPointerOperand()->getType()); |
| 584 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 585 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 586 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 587 | unsigned getNumIndices() const { // Note: always non-negative |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 588 | return getNumOperands() - 1; |
| 589 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 590 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 591 | bool hasIndices() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 592 | return getNumOperands() > 1; |
| 593 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 594 | |
Chris Lattner | 6f771d4 | 2007-04-14 00:12:57 +0000 | [diff] [blame] | 595 | /// hasAllZeroIndices - Return true if all of the indices of this GEP are |
| 596 | /// zeros. If so, the result pointer and the first operand have the same |
| 597 | /// value, just potentially different types. |
| 598 | bool hasAllZeroIndices() const; |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 599 | |
Chris Lattner | 6b0974c | 2007-04-27 20:35:56 +0000 | [diff] [blame] | 600 | /// hasAllConstantIndices - Return true if all of the indices of this GEP are |
| 601 | /// constant integers. If so, the result pointer and the first operand have |
| 602 | /// a constant offset between them. |
| 603 | bool hasAllConstantIndices() const; |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 604 | |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 605 | /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction. |
| 606 | /// See LangRef.html for the meaning of inbounds on a getelementptr. |
Nick Lewycky | ae05e7d | 2009-09-27 21:33:04 +0000 | [diff] [blame] | 607 | void setIsInBounds(bool b = true); |
| 608 | |
| 609 | /// isInBounds - Determine whether the GEP has the inbounds flag. |
| 610 | bool isInBounds() const; |
Dan Gohman | f8dbee7 | 2009-09-07 23:54:19 +0000 | [diff] [blame] | 611 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 612 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 613 | static inline bool classof(const GetElementPtrInst *) { return true; } |
| 614 | static inline bool classof(const Instruction *I) { |
| 615 | return (I->getOpcode() == Instruction::GetElementPtr); |
| 616 | } |
| 617 | static inline bool classof(const Value *V) { |
| 618 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 619 | } |
| 620 | }; |
| 621 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 622 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 623 | struct OperandTraits<GetElementPtrInst> : public VariadicOperandTraits<1> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 624 | }; |
| 625 | |
| 626 | template<typename InputIterator> |
| 627 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 628 | InputIterator IdxBegin, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 629 | InputIterator IdxEnd, |
| 630 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 631 | const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 632 | Instruction *InsertBefore) |
| 633 | : Instruction(PointerType::get(checkType( |
| 634 | getIndexedType(Ptr->getType(), |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 635 | IdxBegin, IdxEnd)), |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 636 | cast<PointerType>(Ptr->getType()) |
| 637 | ->getAddressSpace()), |
| 638 | GetElementPtr, |
| 639 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 640 | Values, InsertBefore) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 641 | init(Ptr, IdxBegin, IdxEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 642 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 643 | } |
| 644 | template<typename InputIterator> |
| 645 | GetElementPtrInst::GetElementPtrInst(Value *Ptr, |
| 646 | InputIterator IdxBegin, |
| 647 | InputIterator IdxEnd, |
| 648 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 649 | const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 650 | BasicBlock *InsertAtEnd) |
| 651 | : Instruction(PointerType::get(checkType( |
| 652 | getIndexedType(Ptr->getType(), |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 653 | IdxBegin, IdxEnd)), |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 654 | cast<PointerType>(Ptr->getType()) |
| 655 | ->getAddressSpace()), |
| 656 | GetElementPtr, |
| 657 | OperandTraits<GetElementPtrInst>::op_end(this) - Values, |
| 658 | Values, InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 659 | init(Ptr, IdxBegin, IdxEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 660 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 661 | } |
| 662 | |
| 663 | |
| 664 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value) |
| 665 | |
| 666 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 667 | //===----------------------------------------------------------------------===// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 668 | // ICmpInst Class |
| 669 | //===----------------------------------------------------------------------===// |
| 670 | |
| 671 | /// This instruction compares its operands according to the predicate given |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 672 | /// to the constructor. It only operates on integers or pointers. The operands |
| 673 | /// must be identical types. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 674 | /// @brief Represent an integer comparison operator. |
| 675 | class ICmpInst: public CmpInst { |
| 676 | public: |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 677 | /// @brief Constructor with insert-before-instruction semantics. |
| 678 | ICmpInst( |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 679 | Instruction *InsertBefore, ///< Where to insert |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 680 | Predicate pred, ///< The predicate to use for the comparison |
| 681 | Value *LHS, ///< The left-hand-side of the expression |
| 682 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 683 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 684 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 685 | Instruction::ICmp, pred, LHS, RHS, NameStr, |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 686 | InsertBefore) { |
| 687 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 688 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 689 | "Invalid ICmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 690 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 691 | "Both operands to ICmp instruction are not of the same type!"); |
| 692 | // Check that the operands are the right type |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 693 | assert((getOperand(0)->getType()->isIntOrIntVector() || |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 694 | isa<PointerType>(getOperand(0)->getType())) && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 695 | "Invalid operand types for ICmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 698 | /// @brief Constructor with insert-at-end semantics. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 699 | ICmpInst( |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 700 | BasicBlock &InsertAtEnd, ///< Block to insert into. |
| 701 | Predicate pred, ///< The predicate to use for the comparison |
| 702 | Value *LHS, ///< The left-hand-side of the expression |
| 703 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 704 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 705 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 706 | Instruction::ICmp, pred, LHS, RHS, NameStr, |
| 707 | &InsertAtEnd) { |
| 708 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 709 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 710 | "Invalid ICmp predicate value"); |
| 711 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 712 | "Both operands to ICmp instruction are not of the same type!"); |
| 713 | // Check that the operands are the right type |
| 714 | assert((getOperand(0)->getType()->isIntOrIntVector() || |
| 715 | isa<PointerType>(getOperand(0)->getType())) && |
| 716 | "Invalid operand types for ICmp instruction"); |
| 717 | } |
| 718 | |
| 719 | /// @brief Constructor with no-insertion semantics |
| 720 | ICmpInst( |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 721 | Predicate pred, ///< The predicate to use for the comparison |
| 722 | Value *LHS, ///< The left-hand-side of the expression |
| 723 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 724 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 725 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 726 | Instruction::ICmp, pred, LHS, RHS, NameStr) { |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 727 | assert(pred >= CmpInst::FIRST_ICMP_PREDICATE && |
| 728 | pred <= CmpInst::LAST_ICMP_PREDICATE && |
| 729 | "Invalid ICmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 730 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 731 | "Both operands to ICmp instruction are not of the same type!"); |
| 732 | // Check that the operands are the right type |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 733 | assert((getOperand(0)->getType()->isIntOrIntVector() || |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 734 | isa<PointerType>(getOperand(0)->getType())) && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 735 | "Invalid operand types for ICmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 738 | /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc. |
| 739 | /// @returns the predicate that would be the result if the operand were |
| 740 | /// regarded as signed. |
| 741 | /// @brief Return the signed version of the predicate |
| 742 | Predicate getSignedPredicate() const { |
| 743 | return getSignedPredicate(getPredicate()); |
| 744 | } |
| 745 | |
| 746 | /// This is a static version that you can use without an instruction. |
| 747 | /// @brief Return the signed version of the predicate. |
| 748 | static Predicate getSignedPredicate(Predicate pred); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 749 | |
Nick Lewycky | 4189a53 | 2008-01-28 03:48:02 +0000 | [diff] [blame] | 750 | /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc. |
| 751 | /// @returns the predicate that would be the result if the operand were |
| 752 | /// regarded as unsigned. |
| 753 | /// @brief Return the unsigned version of the predicate |
| 754 | Predicate getUnsignedPredicate() const { |
| 755 | return getUnsignedPredicate(getPredicate()); |
| 756 | } |
| 757 | |
| 758 | /// This is a static version that you can use without an instruction. |
| 759 | /// @brief Return the unsigned version of the predicate. |
| 760 | static Predicate getUnsignedPredicate(Predicate pred); |
| 761 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 762 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 763 | /// tests for commutativity. |
| 764 | static bool isEquality(Predicate P) { |
| 765 | return P == ICMP_EQ || P == ICMP_NE; |
| 766 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 767 | |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 768 | /// isEquality - Return true if this predicate is either EQ or NE. This also |
| 769 | /// tests for commutativity. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 770 | bool isEquality() const { |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 771 | return isEquality(getPredicate()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 772 | } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 773 | |
| 774 | /// @returns true if the predicate of this ICmpInst is commutative |
| 775 | /// @brief Determine if this relation is commutative. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 776 | bool isCommutative() const { return isEquality(); } |
| 777 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 778 | /// isRelational - Return true if the predicate is relational (not EQ or NE). |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 779 | /// |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 780 | bool isRelational() const { |
| 781 | return !isEquality(); |
| 782 | } |
| 783 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 784 | /// isRelational - Return true if the predicate is relational (not EQ or NE). |
Chris Lattner | c2bfadb | 2007-11-22 23:43:29 +0000 | [diff] [blame] | 785 | /// |
| 786 | static bool isRelational(Predicate P) { |
| 787 | return !isEquality(P); |
| 788 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 789 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 790 | /// @returns true if the predicate of this ICmpInst is signed, false otherwise |
| 791 | /// @brief Determine if this instruction's predicate is signed. |
Chris Lattner | 5bda9e4 | 2007-09-15 06:51:03 +0000 | [diff] [blame] | 792 | bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); } |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 793 | |
| 794 | /// @returns true if the predicate provided is signed, false otherwise |
| 795 | /// @brief Determine if the predicate is signed. |
| 796 | static bool isSignedPredicate(Predicate pred); |
| 797 | |
Nick Lewycky | fc1efbb | 2008-05-17 07:33:39 +0000 | [diff] [blame] | 798 | /// @returns true if the specified compare predicate is |
| 799 | /// true when both operands are equal... |
| 800 | /// @brief Determine if the icmp is true when both operands are equal |
| 801 | static bool isTrueWhenEqual(ICmpInst::Predicate pred) { |
| 802 | return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE || |
| 803 | pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE || |
| 804 | pred == ICmpInst::ICMP_SLE; |
| 805 | } |
| 806 | |
| 807 | /// @returns true if the specified compare instruction is |
| 808 | /// true when both operands are equal... |
| 809 | /// @brief Determine if the ICmpInst returns true when both operands are equal |
| 810 | bool isTrueWhenEqual() { |
| 811 | return isTrueWhenEqual(getPredicate()); |
| 812 | } |
| 813 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 814 | /// Initialize a set of values that all satisfy the predicate with C. |
Reid Spencer | 3da4384 | 2007-02-28 22:00:54 +0000 | [diff] [blame] | 815 | /// @brief Make a ConstantRange for a relation with a constant value. |
| 816 | static ConstantRange makeConstantRange(Predicate pred, const APInt &C); |
| 817 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 818 | /// Exchange the two operands to this instruction in such a way that it does |
| 819 | /// not modify the semantics of the instruction. The predicate value may be |
| 820 | /// changed to retain the same result if the predicate is order dependent |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 821 | /// (e.g. ult). |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 822 | /// @brief Swap operands and adjust predicate. |
| 823 | void swapOperands() { |
| 824 | SubclassData = getSwappedPredicate(); |
Gabor Greif | 94fb68b | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 825 | Op<0>().swap(Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 828 | virtual ICmpInst *clone() const; |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 829 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 830 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 831 | static inline bool classof(const ICmpInst *) { return true; } |
| 832 | static inline bool classof(const Instruction *I) { |
| 833 | return I->getOpcode() == Instruction::ICmp; |
| 834 | } |
| 835 | static inline bool classof(const Value *V) { |
| 836 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 837 | } |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 838 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | //===----------------------------------------------------------------------===// |
| 842 | // FCmpInst Class |
| 843 | //===----------------------------------------------------------------------===// |
| 844 | |
| 845 | /// This instruction compares its operands according to the predicate given |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 846 | /// to the constructor. It only operates on floating point values or packed |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 847 | /// vectors of floating point values. The operands must be identical types. |
| 848 | /// @brief Represents a floating point comparison operator. |
| 849 | class FCmpInst: public CmpInst { |
| 850 | public: |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 851 | /// @brief Constructor with insert-before-instruction semantics. |
| 852 | FCmpInst( |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 853 | Instruction *InsertBefore, ///< Where to insert |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 854 | Predicate pred, ///< The predicate to use for the comparison |
| 855 | Value *LHS, ///< The left-hand-side of the expression |
| 856 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 857 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 858 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 859 | Instruction::FCmp, pred, LHS, RHS, NameStr, |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 860 | InsertBefore) { |
| 861 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && |
| 862 | "Invalid FCmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 863 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 864 | "Both operands to FCmp instruction are not of the same type!"); |
| 865 | // Check that the operands are the right type |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 866 | assert(getOperand(0)->getType()->isFPOrFPVector() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 867 | "Invalid operand types for FCmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 868 | } |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 869 | |
| 870 | /// @brief Constructor with insert-at-end semantics. |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 871 | FCmpInst( |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 872 | BasicBlock &InsertAtEnd, ///< Block to insert into. |
| 873 | Predicate pred, ///< The predicate to use for the comparison |
| 874 | Value *LHS, ///< The left-hand-side of the expression |
| 875 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 876 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 877 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 878 | Instruction::FCmp, pred, LHS, RHS, NameStr, |
| 879 | &InsertAtEnd) { |
| 880 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && |
| 881 | "Invalid FCmp predicate value"); |
| 882 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
| 883 | "Both operands to FCmp instruction are not of the same type!"); |
| 884 | // Check that the operands are the right type |
| 885 | assert(getOperand(0)->getType()->isFPOrFPVector() && |
| 886 | "Invalid operand types for FCmp instruction"); |
| 887 | } |
| 888 | |
| 889 | /// @brief Constructor with no-insertion semantics |
| 890 | FCmpInst( |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 891 | Predicate pred, ///< The predicate to use for the comparison |
| 892 | Value *LHS, ///< The left-hand-side of the expression |
| 893 | Value *RHS, ///< The right-hand-side of the expression |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 894 | const Twine &NameStr = "" ///< Name of the instruction |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 895 | ) : CmpInst(makeCmpResultType(LHS->getType()), |
Owen Anderson | 333c400 | 2009-07-09 23:48:35 +0000 | [diff] [blame] | 896 | Instruction::FCmp, pred, LHS, RHS, NameStr) { |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 897 | assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && |
| 898 | "Invalid FCmp predicate value"); |
Nate Begeman | 31cd33a | 2008-05-14 20:28:31 +0000 | [diff] [blame] | 899 | assert(getOperand(0)->getType() == getOperand(1)->getType() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 900 | "Both operands to FCmp instruction are not of the same type!"); |
| 901 | // Check that the operands are the right type |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 902 | assert(getOperand(0)->getType()->isFPOrFPVector() && |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 903 | "Invalid operand types for FCmp instruction"); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 906 | /// @returns true if the predicate of this instruction is EQ or NE. |
| 907 | /// @brief Determine if this is an equality predicate. |
| 908 | bool isEquality() const { |
| 909 | return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE || |
| 910 | SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE; |
| 911 | } |
Dan Gohman | 793df07 | 2008-09-16 16:44:00 +0000 | [diff] [blame] | 912 | |
| 913 | /// @returns true if the predicate of this instruction is commutative. |
| 914 | /// @brief Determine if this is a commutative predicate. |
| 915 | bool isCommutative() const { |
| 916 | return isEquality() || |
| 917 | SubclassData == FCMP_FALSE || |
| 918 | SubclassData == FCMP_TRUE || |
| 919 | SubclassData == FCMP_ORD || |
| 920 | SubclassData == FCMP_UNO; |
| 921 | } |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 922 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 923 | /// @returns true if the predicate is relational (not EQ or NE). |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 924 | /// @brief Determine if this a relational predicate. |
| 925 | bool isRelational() const { return !isEquality(); } |
| 926 | |
| 927 | /// Exchange the two operands to this instruction in such a way that it does |
| 928 | /// not modify the semantics of the instruction. The predicate value may be |
| 929 | /// changed to retain the same result if the predicate is order dependent |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 930 | /// (e.g. ult). |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 931 | /// @brief Swap operands and adjust predicate. |
| 932 | void swapOperands() { |
| 933 | SubclassData = getSwappedPredicate(); |
Gabor Greif | 94fb68b | 2008-05-13 22:51:52 +0000 | [diff] [blame] | 934 | Op<0>().swap(Op<1>()); |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 935 | } |
| 936 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 937 | virtual FCmpInst *clone() const; |
Chris Lattner | cd406fe | 2007-08-24 20:48:18 +0000 | [diff] [blame] | 938 | |
Reid Spencer | 45fb3f3 | 2006-11-20 01:22:35 +0000 | [diff] [blame] | 939 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 940 | static inline bool classof(const FCmpInst *) { return true; } |
| 941 | static inline bool classof(const Instruction *I) { |
| 942 | return I->getOpcode() == Instruction::FCmp; |
| 943 | } |
| 944 | static inline bool classof(const Value *V) { |
| 945 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 946 | } |
| 947 | }; |
| 948 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 949 | //===----------------------------------------------------------------------===// |
| 950 | // CallInst Class |
| 951 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 952 | /// CallInst - This class represents a function call, abstracting a target |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 953 | /// machine's calling convention. This class uses low bit of the SubClassData |
| 954 | /// field to indicate whether or not this is a tail call. The rest of the bits |
| 955 | /// hold the calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 956 | /// |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 957 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 958 | class CallInst : public Instruction { |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 959 | AttrListPtr AttributeList; ///< parameter attributes for call |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 960 | CallInst(const CallInst &CI); |
Chris Lattner | d54f432 | 2007-02-13 00:58:44 +0000 | [diff] [blame] | 961 | void init(Value *Func, Value* const *Params, unsigned NumParams); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 962 | void init(Value *Func, Value *Actual1, Value *Actual2); |
| 963 | void init(Value *Func, Value *Actual); |
| 964 | void init(Value *Func); |
| 965 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 966 | template<typename InputIterator> |
| 967 | void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 968 | const Twine &NameStr, |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 969 | // This argument ensures that we have an iterator we can |
| 970 | // do arithmetic on in constant time |
| 971 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 972 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 973 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 974 | // This requires that the iterator points to contiguous memory. |
| 975 | init(Func, NumArgs ? &*ArgBegin : 0, NumArgs); |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 976 | setName(NameStr); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 977 | } |
| 978 | |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 979 | /// Construct a CallInst given a range of arguments. InputIterator |
| 980 | /// must be a random-access iterator pointing to contiguous storage |
| 981 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 982 | /// random-accessness but not for contiguous storage as that would |
| 983 | /// incur runtime overhead. |
| 984 | /// @brief Construct a CallInst from a range of arguments |
| 985 | template<typename InputIterator> |
| 986 | CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 987 | const Twine &NameStr, Instruction *InsertBefore); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 988 | |
| 989 | /// Construct a CallInst given a range of arguments. InputIterator |
| 990 | /// must be a random-access iterator pointing to contiguous storage |
| 991 | /// (e.g. a std::vector<>::iterator). Checks are made for |
| 992 | /// random-accessness but not for contiguous storage as that would |
| 993 | /// incur runtime overhead. |
| 994 | /// @brief Construct a CallInst from a range of arguments |
| 995 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 996 | inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 997 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
David Greene | 52eec54 | 2007-08-01 03:43:44 +0000 | [diff] [blame] | 998 | |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 999 | CallInst(Value *F, Value *Actual, const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1000 | Instruction *InsertBefore); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1001 | CallInst(Value *F, Value *Actual, const Twine &NameStr, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1002 | BasicBlock *InsertAtEnd); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1003 | explicit CallInst(Value *F, const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1004 | Instruction *InsertBefore); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1005 | CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1006 | public: |
| 1007 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1008 | static CallInst *Create(Value *Func, |
| 1009 | InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1010 | const Twine &NameStr = "", |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1011 | Instruction *InsertBefore = 0) { |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 1012 | return new((unsigned)(ArgEnd - ArgBegin + 1)) |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1013 | CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1014 | } |
| 1015 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1016 | static CallInst *Create(Value *Func, |
| 1017 | InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1018 | const Twine &NameStr, BasicBlock *InsertAtEnd) { |
Bill Wendling | c2e7353 | 2008-05-10 19:59:59 +0000 | [diff] [blame] | 1019 | return new((unsigned)(ArgEnd - ArgBegin + 1)) |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1020 | CallInst(Func, ArgBegin, ArgEnd, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1021 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1022 | static CallInst *Create(Value *F, Value *Actual, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1023 | const Twine &NameStr = "", |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1024 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1025 | return new(2) CallInst(F, Actual, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1026 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1027 | static CallInst *Create(Value *F, Value *Actual, const Twine &NameStr, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1028 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1029 | return new(2) CallInst(F, Actual, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1030 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1031 | static CallInst *Create(Value *F, const Twine &NameStr = "", |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1032 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1033 | return new(1) CallInst(F, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1034 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1035 | static CallInst *Create(Value *F, const Twine &NameStr, |
Evan Cheng | 34cd4a4 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 1036 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1037 | return new(1) CallInst(F, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1038 | } |
Evan Cheng | fabcb91 | 2009-09-10 04:36:43 +0000 | [diff] [blame] | 1039 | /// CreateMalloc - Generate the IR for a call to malloc: |
| 1040 | /// 1. Compute the malloc call's argument as the specified type's size, |
| 1041 | /// possibly multiplied by the array size if the array size is not |
| 1042 | /// constant 1. |
| 1043 | /// 2. Call malloc with that argument. |
| 1044 | /// 3. Bitcast the result of the malloc call to the specified type. |
Victor Hernandez | 88d9839 | 2009-09-18 19:20:02 +0000 | [diff] [blame] | 1045 | static Value *CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy, |
| 1046 | const Type *AllocTy, Value *ArraySize = 0, |
| 1047 | const Twine &Name = ""); |
| 1048 | static Value *CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy, |
| 1049 | const Type *AllocTy, Value *ArraySize = 0, |
Victor Hernandez | 3e0c99a | 2009-09-25 18:11:52 +0000 | [diff] [blame] | 1050 | const Twine &Name = ""); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1051 | |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1052 | ~CallInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1053 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1054 | bool isTailCall() const { return SubclassData & 1; } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1055 | void setTailCall(bool isTC = true) { |
| 1056 | SubclassData = (SubclassData & ~1) | unsigned(isTC); |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1059 | virtual CallInst *clone() const; |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 1060 | |
| 1061 | /// Provide fast operand accessors |
| 1062 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1063 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1064 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 1065 | /// function call. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1066 | CallingConv::ID getCallingConv() const { |
| 1067 | return static_cast<CallingConv::ID>(SubclassData >> 1); |
| 1068 | } |
| 1069 | void setCallingConv(CallingConv::ID CC) { |
| 1070 | SubclassData = (SubclassData & 1) | (static_cast<unsigned>(CC) << 1); |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 1071 | } |
Chris Lattner | ddb6db4 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1072 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1073 | /// getAttributes - Return the parameter attributes for this call. |
Chris Lattner | 041221c | 2008-03-13 04:33:03 +0000 | [diff] [blame] | 1074 | /// |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1075 | const AttrListPtr &getAttributes() const { return AttributeList; } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1076 | |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 1077 | /// setAttributes - Set the parameter attributes for this call. |
| 1078 | /// |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1079 | void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1080 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1081 | /// addAttribute - adds the attribute to the list of attributes. |
| 1082 | void addAttribute(unsigned i, Attributes attr); |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1083 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1084 | /// removeAttribute - removes the attribute from the list of attributes. |
| 1085 | void removeAttribute(unsigned i, Attributes attr); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 1086 | |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1087 | /// @brief Determine whether the call or the callee has the given attribute. |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 1088 | bool paramHasAttr(unsigned i, Attributes attr) const; |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 1089 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1090 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1091 | unsigned getParamAlignment(unsigned i) const { |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1092 | return AttributeList.getParamAlignment(i); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1093 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 1094 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1095 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1096 | bool doesNotAccessMemory() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1097 | return paramHasAttr(~0, Attribute::ReadNone); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1098 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1099 | void setDoesNotAccessMemory(bool NotAccessMemory = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1100 | if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); |
| 1101 | else removeAttribute(~0, Attribute::ReadNone); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1104 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1105 | bool onlyReadsMemory() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1106 | return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1107 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1108 | void setOnlyReadsMemory(bool OnlyReadsMemory = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1109 | if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); |
| 1110 | else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1113 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1114 | bool doesNotReturn() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1115 | return paramHasAttr(~0, Attribute::NoReturn); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1116 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1117 | void setDoesNotReturn(bool DoesNotReturn = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1118 | if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); |
| 1119 | else removeAttribute(~0, Attribute::NoReturn); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 1120 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 1121 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1122 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1123 | bool doesNotThrow() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1124 | return paramHasAttr(~0, Attribute::NoUnwind); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1125 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1126 | void setDoesNotThrow(bool DoesNotThrow = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1127 | if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); |
| 1128 | else removeAttribute(~0, Attribute::NoUnwind); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 1129 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 1130 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1131 | /// @brief Determine if the call returns a structure through first |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 1132 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1133 | bool hasStructRetAttr() const { |
| 1134 | // Be friendly and also check the callee. |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1135 | return paramHasAttr(1, Attribute::StructRet); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1136 | } |
Reid Spencer | 4746ecf | 2007-04-09 15:01:12 +0000 | [diff] [blame] | 1137 | |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1138 | /// @brief Determine if any call argument is an aggregate passed by value. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1139 | bool hasByValArgument() const { |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1140 | return AttributeList.hasAttrSomewhere(Attribute::ByVal); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 1141 | } |
Evan Cheng | f4a5498 | 2008-01-12 18:57:32 +0000 | [diff] [blame] | 1142 | |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 1143 | /// getCalledFunction - Return the function called, or null if this is an |
| 1144 | /// indirect function invocation. |
| 1145 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1146 | Function *getCalledFunction() const { |
Gabor Greif | 7e07c00 | 2009-03-12 23:13:03 +0000 | [diff] [blame] | 1147 | return dyn_cast<Function>(Op<0>()); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 1148 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1149 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1150 | /// getCalledValue - Get a pointer to the function that is invoked by this |
Reid Spencer | c25ec25 | 2006-12-29 04:10:59 +0000 | [diff] [blame] | 1151 | /// instruction |
Gabor Greif | 7e07c00 | 2009-03-12 23:13:03 +0000 | [diff] [blame] | 1152 | const Value *getCalledValue() const { return Op<0>(); } |
| 1153 | Value *getCalledValue() { return Op<0>(); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1154 | |
| 1155 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1156 | static inline bool classof(const CallInst *) { return true; } |
| 1157 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1158 | return I->getOpcode() == Instruction::Call; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1159 | } |
| 1160 | static inline bool classof(const Value *V) { |
| 1161 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1162 | } |
| 1163 | }; |
| 1164 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1165 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1166 | struct OperandTraits<CallInst> : public VariadicOperandTraits<1> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1167 | }; |
| 1168 | |
| 1169 | template<typename InputIterator> |
| 1170 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1171 | const Twine &NameStr, BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1172 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1173 | ->getElementType())->getReturnType(), |
| 1174 | Instruction::Call, |
| 1175 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1176 | (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1177 | init(Func, ArgBegin, ArgEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1178 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1179 | } |
| 1180 | |
| 1181 | template<typename InputIterator> |
| 1182 | CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1183 | const Twine &NameStr, Instruction *InsertBefore) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1184 | : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 1185 | ->getElementType())->getReturnType(), |
| 1186 | Instruction::Call, |
| 1187 | OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1), |
Bill Wendling | 1b2f729 | 2008-05-10 11:26:52 +0000 | [diff] [blame] | 1188 | (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) { |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1189 | init(Func, ArgBegin, ArgEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1190 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1191 | } |
| 1192 | |
| 1193 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value) |
| 1194 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1195 | //===----------------------------------------------------------------------===// |
| 1196 | // SelectInst Class |
| 1197 | //===----------------------------------------------------------------------===// |
| 1198 | |
| 1199 | /// SelectInst - This class represents the LLVM 'select' instruction. |
| 1200 | /// |
| 1201 | class SelectInst : public Instruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1202 | void init(Value *C, Value *S1, Value *S2) { |
Chris Lattner | b76ec32 | 2008-12-29 00:12:50 +0000 | [diff] [blame] | 1203 | assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1204 | Op<0>() = C; |
| 1205 | Op<1>() = S1; |
| 1206 | Op<2>() = S2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1209 | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1210 | Instruction *InsertBefore) |
| 1211 | : Instruction(S1->getType(), Instruction::Select, |
| 1212 | &Op<0>(), 3, InsertBefore) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1213 | init(C, S1, S2); |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1214 | setName(NameStr); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1215 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1216 | SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1217 | BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1218 | : Instruction(S1->getType(), Instruction::Select, |
| 1219 | &Op<0>(), 3, InsertAtEnd) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1220 | init(C, S1, S2); |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1221 | setName(NameStr); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1222 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1223 | public: |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1224 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1225 | const Twine &NameStr = "", |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1226 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1227 | return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1228 | } |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1229 | static SelectInst *Create(Value *C, Value *S1, Value *S2, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1230 | const Twine &NameStr, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1231 | BasicBlock *InsertAtEnd) { |
| 1232 | return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1233 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1234 | |
Chris Lattner | 9715912 | 2009-09-08 03:32:53 +0000 | [diff] [blame] | 1235 | const Value *getCondition() const { return Op<0>(); } |
| 1236 | const Value *getTrueValue() const { return Op<1>(); } |
| 1237 | const Value *getFalseValue() const { return Op<2>(); } |
| 1238 | Value *getCondition() { return Op<0>(); } |
| 1239 | Value *getTrueValue() { return Op<1>(); } |
| 1240 | Value *getFalseValue() { return Op<2>(); } |
| 1241 | |
Chris Lattner | b76ec32 | 2008-12-29 00:12:50 +0000 | [diff] [blame] | 1242 | /// areInvalidOperands - Return a string if the specified operands are invalid |
| 1243 | /// for a select operation, otherwise return null. |
| 1244 | static const char *areInvalidOperands(Value *Cond, Value *True, Value *False); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1245 | |
| 1246 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1247 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1248 | |
| 1249 | OtherOps getOpcode() const { |
| 1250 | return static_cast<OtherOps>(Instruction::getOpcode()); |
| 1251 | } |
| 1252 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1253 | virtual SelectInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1254 | |
| 1255 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1256 | static inline bool classof(const SelectInst *) { return true; } |
| 1257 | static inline bool classof(const Instruction *I) { |
| 1258 | return I->getOpcode() == Instruction::Select; |
| 1259 | } |
| 1260 | static inline bool classof(const Value *V) { |
| 1261 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1262 | } |
| 1263 | }; |
| 1264 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1265 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1266 | struct OperandTraits<SelectInst> : public FixedNumOperandTraits<3> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1267 | }; |
| 1268 | |
| 1269 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value) |
| 1270 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1271 | //===----------------------------------------------------------------------===// |
| 1272 | // VAArgInst Class |
| 1273 | //===----------------------------------------------------------------------===// |
| 1274 | |
| 1275 | /// VAArgInst - This class represents the va_arg llvm instruction, which returns |
Andrew Lenharth | f542821 | 2005-06-18 18:31:30 +0000 | [diff] [blame] | 1276 | /// an argument of the specified type given a va_list and increments that list |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1277 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1278 | class VAArgInst : public UnaryInstruction { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1279 | public: |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1280 | VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "", |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1281 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1282 | : UnaryInstruction(Ty, VAArg, List, InsertBefore) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1283 | setName(NameStr); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1284 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1285 | VAArgInst(Value *List, const Type *Ty, const Twine &NameStr, |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1286 | BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1287 | : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1288 | setName(NameStr); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1291 | virtual VAArgInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1292 | |
| 1293 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1294 | static inline bool classof(const VAArgInst *) { return true; } |
| 1295 | static inline bool classof(const Instruction *I) { |
| 1296 | return I->getOpcode() == VAArg; |
| 1297 | } |
| 1298 | static inline bool classof(const Value *V) { |
| 1299 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1300 | } |
| 1301 | }; |
| 1302 | |
| 1303 | //===----------------------------------------------------------------------===// |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1304 | // ExtractElementInst Class |
| 1305 | //===----------------------------------------------------------------------===// |
| 1306 | |
| 1307 | /// ExtractElementInst - This instruction extracts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1308 | /// element from a VectorType value |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1309 | /// |
| 1310 | class ExtractElementInst : public Instruction { |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1311 | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "", |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1312 | Instruction *InsertBefore = 0); |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1313 | ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr, |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1314 | BasicBlock *InsertAtEnd); |
Eric Christopher | a3500da | 2009-07-25 02:28:41 +0000 | [diff] [blame] | 1315 | public: |
Eric Christopher | a3500da | 2009-07-25 02:28:41 +0000 | [diff] [blame] | 1316 | static ExtractElementInst *Create(Value *Vec, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1317 | const Twine &NameStr = "", |
Eric Christopher | a3500da | 2009-07-25 02:28:41 +0000 | [diff] [blame] | 1318 | Instruction *InsertBefore = 0) { |
| 1319 | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore); |
| 1320 | } |
| 1321 | static ExtractElementInst *Create(Value *Vec, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1322 | const Twine &NameStr, |
Eric Christopher | a3500da | 2009-07-25 02:28:41 +0000 | [diff] [blame] | 1323 | BasicBlock *InsertAtEnd) { |
| 1324 | return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd); |
| 1325 | } |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1326 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1327 | /// isValidOperands - Return true if an extractelement instruction can be |
| 1328 | /// formed with the specified operands. |
| 1329 | static bool isValidOperands(const Value *Vec, const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1330 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1331 | virtual ExtractElementInst *clone() const; |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1332 | |
Chris Lattner | 9715912 | 2009-09-08 03:32:53 +0000 | [diff] [blame] | 1333 | Value *getVectorOperand() { return Op<0>(); } |
| 1334 | Value *getIndexOperand() { return Op<1>(); } |
| 1335 | const Value *getVectorOperand() const { return Op<0>(); } |
| 1336 | const Value *getIndexOperand() const { return Op<1>(); } |
| 1337 | |
| 1338 | const VectorType *getVectorOperandType() const { |
Chris Lattner | c8dee3f | 2009-09-08 03:39:55 +0000 | [diff] [blame] | 1339 | return reinterpret_cast<const VectorType*>(getVectorOperand()->getType()); |
Chris Lattner | 9715912 | 2009-09-08 03:32:53 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1343 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1344 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1345 | |
| 1346 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1347 | static inline bool classof(const ExtractElementInst *) { return true; } |
| 1348 | static inline bool classof(const Instruction *I) { |
| 1349 | return I->getOpcode() == Instruction::ExtractElement; |
| 1350 | } |
| 1351 | static inline bool classof(const Value *V) { |
| 1352 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1353 | } |
| 1354 | }; |
| 1355 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1356 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1357 | struct OperandTraits<ExtractElementInst> : public FixedNumOperandTraits<2> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value) |
| 1361 | |
Robert Bocchino | 49b78a5 | 2006-01-10 19:04:13 +0000 | [diff] [blame] | 1362 | //===----------------------------------------------------------------------===// |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1363 | // InsertElementInst Class |
| 1364 | //===----------------------------------------------------------------------===// |
| 1365 | |
| 1366 | /// InsertElementInst - This instruction inserts a single (scalar) |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1367 | /// element into a VectorType value |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1368 | /// |
| 1369 | class InsertElementInst : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1370 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1371 | const Twine &NameStr = "", |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1372 | Instruction *InsertBefore = 0); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1373 | InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1374 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1375 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1376 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1377 | const Twine &NameStr = "", |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1378 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1379 | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1380 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1381 | static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1382 | const Twine &NameStr, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1383 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1384 | return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1385 | } |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1386 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1387 | /// isValidOperands - Return true if an insertelement instruction can be |
| 1388 | /// formed with the specified operands. |
| 1389 | static bool isValidOperands(const Value *Vec, const Value *NewElt, |
| 1390 | const Value *Idx); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1391 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1392 | virtual InsertElementInst *clone() const; |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1393 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1394 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1395 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1396 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1397 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1398 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1399 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1400 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1401 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1402 | |
| 1403 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1404 | static inline bool classof(const InsertElementInst *) { return true; } |
| 1405 | static inline bool classof(const Instruction *I) { |
| 1406 | return I->getOpcode() == Instruction::InsertElement; |
| 1407 | } |
| 1408 | static inline bool classof(const Value *V) { |
| 1409 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1410 | } |
| 1411 | }; |
| 1412 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1413 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1414 | struct OperandTraits<InsertElementInst> : public FixedNumOperandTraits<3> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1415 | }; |
| 1416 | |
| 1417 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value) |
| 1418 | |
Robert Bocchino | f999344 | 2006-01-17 20:05:59 +0000 | [diff] [blame] | 1419 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1420 | // ShuffleVectorInst Class |
| 1421 | //===----------------------------------------------------------------------===// |
| 1422 | |
| 1423 | /// ShuffleVectorInst - This instruction constructs a fixed permutation of two |
| 1424 | /// input vectors. |
| 1425 | /// |
| 1426 | class ShuffleVectorInst : public Instruction { |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1427 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1428 | // allocate space for exactly three operands |
| 1429 | void *operator new(size_t s) { |
| 1430 | return User::operator new(s, 3); |
| 1431 | } |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1432 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1433 | const Twine &NameStr = "", |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1434 | Instruction *InsertBefor = 0); |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1435 | ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1436 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1437 | |
Chris Lattner | fa49584 | 2006-04-08 04:04:54 +0000 | [diff] [blame] | 1438 | /// isValidOperands - Return true if a shufflevector instruction can be |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1439 | /// formed with the specified operands. |
| 1440 | static bool isValidOperands(const Value *V1, const Value *V2, |
| 1441 | const Value *Mask); |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1442 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1443 | virtual ShuffleVectorInst *clone() const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1444 | |
Reid Spencer | ac9dcb9 | 2007-02-15 03:39:18 +0000 | [diff] [blame] | 1445 | /// getType - Overload to return most specific vector type. |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1446 | /// |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 1447 | const VectorType *getType() const { |
Reid Spencer | 9d6565a | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 1448 | return reinterpret_cast<const VectorType*>(Instruction::getType()); |
Chris Lattner | 6a56ed4 | 2006-04-14 22:20:07 +0000 | [diff] [blame] | 1449 | } |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1450 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1451 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1452 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1453 | |
Chris Lattner | 8728f19 | 2008-03-02 05:28:33 +0000 | [diff] [blame] | 1454 | /// getMaskValue - Return the index from the shuffle mask for the specified |
| 1455 | /// output result. This is either -1 if the element is undef or a number less |
| 1456 | /// than 2*numelements. |
| 1457 | int getMaskValue(unsigned i) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1458 | |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1459 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1460 | static inline bool classof(const ShuffleVectorInst *) { return true; } |
| 1461 | static inline bool classof(const Instruction *I) { |
| 1462 | return I->getOpcode() == Instruction::ShuffleVector; |
| 1463 | } |
| 1464 | static inline bool classof(const Value *V) { |
| 1465 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1466 | } |
| 1467 | }; |
| 1468 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1469 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1470 | struct OperandTraits<ShuffleVectorInst> : public FixedNumOperandTraits<3> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1471 | }; |
| 1472 | |
| 1473 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value) |
Chris Lattner | 9fc18d2 | 2006-04-08 01:15:18 +0000 | [diff] [blame] | 1474 | |
| 1475 | //===----------------------------------------------------------------------===// |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1476 | // ExtractValueInst Class |
| 1477 | //===----------------------------------------------------------------------===// |
| 1478 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1479 | /// ExtractValueInst - This instruction extracts a struct member or array |
| 1480 | /// element value from an aggregate value. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1481 | /// |
Gabor Greif | d4f268b | 2008-06-06 20:28:12 +0000 | [diff] [blame] | 1482 | class ExtractValueInst : public UnaryInstruction { |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1483 | SmallVector<unsigned, 4> Indices; |
| 1484 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1485 | ExtractValueInst(const ExtractValueInst &EVI); |
Gabor Greif | 76aca6f | 2008-06-06 21:06:32 +0000 | [diff] [blame] | 1486 | void init(const unsigned *Idx, unsigned NumIdx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1487 | const Twine &NameStr); |
| 1488 | void init(unsigned Idx, const Twine &NameStr); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1489 | |
| 1490 | template<typename InputIterator> |
Gabor Greif | 76aca6f | 2008-06-06 21:06:32 +0000 | [diff] [blame] | 1491 | void init(InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1492 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1493 | // This argument ensures that we have an iterator we can |
| 1494 | // do arithmetic on in constant time |
| 1495 | std::random_access_iterator_tag) { |
| 1496 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1497 | |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1498 | // There's no fundamental reason why we require at least one index |
| 1499 | // (other than weirdness with &*IdxBegin being invalid; see |
| 1500 | // getelementptr's init routine for example). But there's no |
| 1501 | // present need to support it. |
| 1502 | assert(NumIdx > 0 && "ExtractValueInst must have at least one index"); |
| 1503 | |
| 1504 | // This requires that the iterator points to contiguous memory. |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1505 | init(&*IdxBegin, NumIdx, NameStr); // FIXME: for the general case |
Matthijs Kooijman | 444099f6 | 2008-06-04 14:40:55 +0000 | [diff] [blame] | 1506 | // we have to build an array here |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1510 | /// with an extractvalue instruction with the specified parameters. |
| 1511 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1512 | /// Null is returned if the indices are invalid for the specified |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1513 | /// pointer type. |
| 1514 | /// |
| 1515 | static const Type *getIndexedType(const Type *Agg, |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1516 | const unsigned *Idx, unsigned NumIdx); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1517 | |
| 1518 | template<typename InputIterator> |
| 1519 | static const Type *getIndexedType(const Type *Ptr, |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1520 | InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1521 | InputIterator IdxEnd, |
| 1522 | // This argument ensures that we |
| 1523 | // have an iterator we can do |
| 1524 | // arithmetic on in constant time |
| 1525 | std::random_access_iterator_tag) { |
| 1526 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
| 1527 | |
| 1528 | if (NumIdx > 0) |
| 1529 | // This requires that the iterator points to contiguous memory. |
Dan Gohman | 19a8163 | 2008-06-23 16:38:10 +0000 | [diff] [blame] | 1530 | return getIndexedType(Ptr, &*IdxBegin, NumIdx); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1531 | else |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1532 | return getIndexedType(Ptr, (const unsigned *)0, NumIdx); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1535 | /// Constructors - Create a extractvalue instruction with a base aggregate |
| 1536 | /// value and a list of indices. The first ctor can optionally insert before |
| 1537 | /// an existing instruction, the second appends the new instruction to the |
| 1538 | /// specified BasicBlock. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1539 | template<typename InputIterator> |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1540 | inline ExtractValueInst(Value *Agg, InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1541 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1542 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1543 | Instruction *InsertBefore); |
| 1544 | template<typename InputIterator> |
| 1545 | inline ExtractValueInst(Value *Agg, |
| 1546 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1547 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1548 | |
Dan Gohman | 8e64041 | 2008-05-31 19:09:47 +0000 | [diff] [blame] | 1549 | // allocate space for exactly one operand |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1550 | void *operator new(size_t s) { |
| 1551 | return User::operator new(s, 1); |
| 1552 | } |
| 1553 | |
Gabor Greif | d4f268b | 2008-06-06 20:28:12 +0000 | [diff] [blame] | 1554 | public: |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1555 | template<typename InputIterator> |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1556 | static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1557 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1558 | const Twine &NameStr = "", |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1559 | Instruction *InsertBefore = 0) { |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1560 | return new |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1561 | ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1562 | } |
| 1563 | template<typename InputIterator> |
| 1564 | static ExtractValueInst *Create(Value *Agg, |
| 1565 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1566 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1567 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1568 | return new ExtractValueInst(Agg, IdxBegin, IdxEnd, NameStr, InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | /// Constructors - These two creators are convenience methods because one |
| 1572 | /// index extractvalue instructions are much more common than those with |
| 1573 | /// more than one. |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1574 | static ExtractValueInst *Create(Value *Agg, unsigned Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1575 | const Twine &NameStr = "", |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1576 | Instruction *InsertBefore = 0) { |
Dan Gohman | 2f27e17 | 2008-06-23 16:48:17 +0000 | [diff] [blame] | 1577 | unsigned Idxs[1] = { Idx }; |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1578 | return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1579 | } |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1580 | static ExtractValueInst *Create(Value *Agg, unsigned Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1581 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1582 | BasicBlock *InsertAtEnd) { |
Dan Gohman | 2f27e17 | 2008-06-23 16:48:17 +0000 | [diff] [blame] | 1583 | unsigned Idxs[1] = { Idx }; |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1584 | return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1587 | virtual ExtractValueInst *clone() const; |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1588 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1589 | /// getIndexedType - Returns the type of the element that would be extracted |
| 1590 | /// with an extractvalue instruction with the specified parameters. |
| 1591 | /// |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1592 | /// Null is returned if the indices are invalid for the specified |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1593 | /// pointer type. |
| 1594 | /// |
| 1595 | template<typename InputIterator> |
| 1596 | static const Type *getIndexedType(const Type *Ptr, |
| 1597 | InputIterator IdxBegin, |
| 1598 | InputIterator IdxEnd) { |
| 1599 | return getIndexedType(Ptr, IdxBegin, IdxEnd, |
| 1600 | typename std::iterator_traits<InputIterator>:: |
| 1601 | iterator_category()); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1602 | } |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1603 | static const Type *getIndexedType(const Type *Ptr, unsigned Idx); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1604 | |
Owen Anderson | 5678d6e | 2008-06-19 17:15:57 +0000 | [diff] [blame] | 1605 | typedef const unsigned* idx_iterator; |
| 1606 | inline idx_iterator idx_begin() const { return Indices.begin(); } |
| 1607 | inline idx_iterator idx_end() const { return Indices.end(); } |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1608 | |
| 1609 | Value *getAggregateOperand() { |
| 1610 | return getOperand(0); |
| 1611 | } |
| 1612 | const Value *getAggregateOperand() const { |
| 1613 | return getOperand(0); |
| 1614 | } |
| 1615 | static unsigned getAggregateOperandIndex() { |
| 1616 | return 0U; // get index for modifying correct operand |
| 1617 | } |
| 1618 | |
| 1619 | unsigned getNumIndices() const { // Note: always non-negative |
Bill Wendling | 67944fc | 2008-06-05 07:35:27 +0000 | [diff] [blame] | 1620 | return (unsigned)Indices.size(); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | bool hasIndices() const { |
Dan Gohman | 35651cd | 2008-05-31 19:09:08 +0000 | [diff] [blame] | 1624 | return true; |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1625 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1626 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1627 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1628 | static inline bool classof(const ExtractValueInst *) { return true; } |
| 1629 | static inline bool classof(const Instruction *I) { |
| 1630 | return I->getOpcode() == Instruction::ExtractValue; |
| 1631 | } |
| 1632 | static inline bool classof(const Value *V) { |
| 1633 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1634 | } |
| 1635 | }; |
| 1636 | |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1637 | template<typename InputIterator> |
| 1638 | ExtractValueInst::ExtractValueInst(Value *Agg, |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1639 | InputIterator IdxBegin, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1640 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1641 | const Twine &NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1642 | Instruction *InsertBefore) |
Gabor Greif | d4f268b | 2008-06-06 20:28:12 +0000 | [diff] [blame] | 1643 | : UnaryInstruction(checkType(getIndexedType(Agg->getType(), |
Bill Wendling | 85f4054 | 2008-07-22 07:14:12 +0000 | [diff] [blame] | 1644 | IdxBegin, IdxEnd)), |
| 1645 | ExtractValue, Agg, InsertBefore) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1646 | init(IdxBegin, IdxEnd, NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1647 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1648 | } |
| 1649 | template<typename InputIterator> |
| 1650 | ExtractValueInst::ExtractValueInst(Value *Agg, |
| 1651 | InputIterator IdxBegin, |
| 1652 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1653 | const Twine &NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1654 | BasicBlock *InsertAtEnd) |
Gabor Greif | d4f268b | 2008-06-06 20:28:12 +0000 | [diff] [blame] | 1655 | : UnaryInstruction(checkType(getIndexedType(Agg->getType(), |
Bill Wendling | 85f4054 | 2008-07-22 07:14:12 +0000 | [diff] [blame] | 1656 | IdxBegin, IdxEnd)), |
| 1657 | ExtractValue, Agg, InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1658 | init(IdxBegin, IdxEnd, NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1659 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1660 | } |
| 1661 | |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1662 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1663 | //===----------------------------------------------------------------------===// |
| 1664 | // InsertValueInst Class |
| 1665 | //===----------------------------------------------------------------------===// |
| 1666 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1667 | /// InsertValueInst - This instruction inserts a struct field of array element |
| 1668 | /// value into an aggregate value. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1669 | /// |
| 1670 | class InsertValueInst : public Instruction { |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1671 | SmallVector<unsigned, 4> Indices; |
| 1672 | |
| 1673 | void *operator new(size_t, unsigned); // Do not implement |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1674 | InsertValueInst(const InsertValueInst &IVI); |
Matthijs Kooijman | cfd5b7d | 2008-06-05 07:26:15 +0000 | [diff] [blame] | 1675 | void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1676 | const Twine &NameStr); |
| 1677 | void init(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1678 | |
| 1679 | template<typename InputIterator> |
| 1680 | void init(Value *Agg, Value *Val, |
| 1681 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1682 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1683 | // This argument ensures that we have an iterator we can |
| 1684 | // do arithmetic on in constant time |
| 1685 | std::random_access_iterator_tag) { |
| 1686 | unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd)); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1687 | |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1688 | // There's no fundamental reason why we require at least one index |
| 1689 | // (other than weirdness with &*IdxBegin being invalid; see |
| 1690 | // getelementptr's init routine for example). But there's no |
| 1691 | // present need to support it. |
| 1692 | assert(NumIdx > 0 && "InsertValueInst must have at least one index"); |
| 1693 | |
| 1694 | // This requires that the iterator points to contiguous memory. |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1695 | init(Agg, Val, &*IdxBegin, NumIdx, NameStr); // FIXME: for the general case |
Matthijs Kooijman | 444099f6 | 2008-06-04 14:40:55 +0000 | [diff] [blame] | 1696 | // we have to build an array here |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1699 | /// Constructors - Create a insertvalue instruction with a base aggregate |
| 1700 | /// value, a value to insert, and a list of indices. The first ctor can |
| 1701 | /// optionally insert before an existing instruction, the second appends |
| 1702 | /// the new instruction to the specified BasicBlock. |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1703 | template<typename InputIterator> |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1704 | inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin, |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1705 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1706 | const Twine &NameStr, |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1707 | Instruction *InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1708 | template<typename InputIterator> |
| 1709 | inline InsertValueInst(Value *Agg, Value *Val, |
Dan Gohman | e2d896f | 2008-05-15 23:35:32 +0000 | [diff] [blame] | 1710 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1711 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1712 | |
| 1713 | /// Constructors - These two constructors are convenience methods because one |
| 1714 | /// and two index insertvalue instructions are so common. |
| 1715 | InsertValueInst(Value *Agg, Value *Val, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1716 | unsigned Idx, const Twine &NameStr = "", |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1717 | Instruction *InsertBefore = 0); |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1718 | InsertValueInst(Value *Agg, Value *Val, unsigned Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1719 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1720 | public: |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1721 | // allocate space for exactly two operands |
| 1722 | void *operator new(size_t s) { |
| 1723 | return User::operator new(s, 2); |
| 1724 | } |
| 1725 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1726 | template<typename InputIterator> |
Matthijs Kooijman | cfd5b7d | 2008-06-05 07:26:15 +0000 | [diff] [blame] | 1727 | static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1728 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1729 | const Twine &NameStr = "", |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1730 | Instruction *InsertBefore = 0) { |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1731 | return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1732 | NameStr, InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1733 | } |
| 1734 | template<typename InputIterator> |
| 1735 | static InsertValueInst *Create(Value *Agg, Value *Val, |
| 1736 | InputIterator IdxBegin, InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1737 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1738 | BasicBlock *InsertAtEnd) { |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1739 | return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1740 | NameStr, InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /// Constructors - These two creators are convenience methods because one |
| 1744 | /// index insertvalue instructions are much more common than those with |
| 1745 | /// more than one. |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1746 | static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1747 | const Twine &NameStr = "", |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1748 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1749 | return new InsertValueInst(Agg, Val, Idx, NameStr, InsertBefore); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1750 | } |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1751 | static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1752 | const Twine &NameStr, |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1753 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1754 | return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1757 | virtual InsertValueInst *clone() const; |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1758 | |
| 1759 | /// Transparently provide more efficient getOperand methods. |
| 1760 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1761 | |
Owen Anderson | 5678d6e | 2008-06-19 17:15:57 +0000 | [diff] [blame] | 1762 | typedef const unsigned* idx_iterator; |
| 1763 | inline idx_iterator idx_begin() const { return Indices.begin(); } |
| 1764 | inline idx_iterator idx_end() const { return Indices.end(); } |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1765 | |
| 1766 | Value *getAggregateOperand() { |
| 1767 | return getOperand(0); |
| 1768 | } |
| 1769 | const Value *getAggregateOperand() const { |
| 1770 | return getOperand(0); |
| 1771 | } |
| 1772 | static unsigned getAggregateOperandIndex() { |
| 1773 | return 0U; // get index for modifying correct operand |
| 1774 | } |
| 1775 | |
| 1776 | Value *getInsertedValueOperand() { |
| 1777 | return getOperand(1); |
| 1778 | } |
| 1779 | const Value *getInsertedValueOperand() const { |
| 1780 | return getOperand(1); |
| 1781 | } |
| 1782 | static unsigned getInsertedValueOperandIndex() { |
| 1783 | return 1U; // get index for modifying correct operand |
| 1784 | } |
| 1785 | |
| 1786 | unsigned getNumIndices() const { // Note: always non-negative |
Bill Wendling | 67944fc | 2008-06-05 07:35:27 +0000 | [diff] [blame] | 1787 | return (unsigned)Indices.size(); |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | bool hasIndices() const { |
Dan Gohman | 35651cd | 2008-05-31 19:09:08 +0000 | [diff] [blame] | 1791 | return true; |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1792 | } |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1793 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1794 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 1795 | static inline bool classof(const InsertValueInst *) { return true; } |
| 1796 | static inline bool classof(const Instruction *I) { |
| 1797 | return I->getOpcode() == Instruction::InsertValue; |
| 1798 | } |
| 1799 | static inline bool classof(const Value *V) { |
| 1800 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 1801 | } |
| 1802 | }; |
| 1803 | |
| 1804 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 1805 | struct OperandTraits<InsertValueInst> : public FixedNumOperandTraits<2> { |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1806 | }; |
| 1807 | |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1808 | template<typename InputIterator> |
| 1809 | InsertValueInst::InsertValueInst(Value *Agg, |
| 1810 | Value *Val, |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 1811 | InputIterator IdxBegin, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1812 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1813 | const Twine &NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1814 | Instruction *InsertBefore) |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1815 | : Instruction(Agg->getType(), InsertValue, |
| 1816 | OperandTraits<InsertValueInst>::op_begin(this), |
| 1817 | 2, InsertBefore) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1818 | init(Agg, Val, IdxBegin, IdxEnd, NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1819 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1820 | } |
| 1821 | template<typename InputIterator> |
| 1822 | InsertValueInst::InsertValueInst(Value *Agg, |
| 1823 | Value *Val, |
| 1824 | InputIterator IdxBegin, |
| 1825 | InputIterator IdxEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1826 | const Twine &NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1827 | BasicBlock *InsertAtEnd) |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 1828 | : Instruction(Agg->getType(), InsertValue, |
| 1829 | OperandTraits<InsertValueInst>::op_begin(this), |
| 1830 | 2, InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1831 | init(Agg, Val, IdxBegin, IdxEnd, NameStr, |
Dan Gohman | e456994 | 2008-05-23 00:36:11 +0000 | [diff] [blame] | 1832 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 1833 | } |
| 1834 | |
Dan Gohman | 041e2eb | 2008-05-15 19:50:34 +0000 | [diff] [blame] | 1835 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value) |
| 1836 | |
| 1837 | //===----------------------------------------------------------------------===// |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1838 | // PHINode Class |
| 1839 | //===----------------------------------------------------------------------===// |
| 1840 | |
| 1841 | // PHINode - The PHINode class is used to represent the magical mystical PHI |
| 1842 | // node, that can not exist in nature, but can be synthesized in a computer |
| 1843 | // scientist's overactive imagination. |
| 1844 | // |
| 1845 | class PHINode : public Instruction { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1846 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1847 | /// ReservedSpace - The number of operands actually allocated. NumOperands is |
| 1848 | /// the number actually in use. |
| 1849 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1850 | PHINode(const PHINode &PN); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1851 | // allocate space for exactly zero operands |
| 1852 | void *operator new(size_t s) { |
| 1853 | return User::operator new(s, 0); |
| 1854 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1855 | explicit PHINode(const Type *Ty, const Twine &NameStr = "", |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1856 | Instruction *InsertBefore = 0) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1857 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1858 | ReservedSpace(0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1859 | setName(NameStr); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1862 | PHINode(const Type *Ty, const Twine &NameStr, BasicBlock *InsertAtEnd) |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 1863 | : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd), |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1864 | ReservedSpace(0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1865 | setName(NameStr); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1866 | } |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1867 | public: |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1868 | static PHINode *Create(const Type *Ty, const Twine &NameStr = "", |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1869 | Instruction *InsertBefore = 0) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1870 | return new PHINode(Ty, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1871 | } |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 1872 | static PHINode *Create(const Type *Ty, const Twine &NameStr, |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 1873 | BasicBlock *InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 1874 | return new PHINode(Ty, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1875 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 1876 | ~PHINode(); |
| 1877 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1878 | /// reserveOperandSpace - This method can be used to avoid repeated |
| 1879 | /// reallocation of PHI operand lists by reserving space for the correct |
| 1880 | /// number of operands before adding them. Unlike normal vector reserves, |
| 1881 | /// this method can also be used to trim the operand space. |
| 1882 | void reserveOperandSpace(unsigned NumValues) { |
| 1883 | resizeOperands(NumValues*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 1886 | virtual PHINode *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1887 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1888 | /// Provide fast operand accessors |
| 1889 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 1890 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1891 | /// getNumIncomingValues - Return the number of incoming edges |
| 1892 | /// |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1893 | unsigned getNumIncomingValues() const { return getNumOperands()/2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1894 | |
Reid Spencer | c773de6 | 2006-05-19 19:07:54 +0000 | [diff] [blame] | 1895 | /// getIncomingValue - Return incoming value number x |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1896 | /// |
| 1897 | Value *getIncomingValue(unsigned i) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1898 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1899 | return getOperand(i*2); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1900 | } |
| 1901 | void setIncomingValue(unsigned i, Value *V) { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1902 | assert(i*2 < getNumOperands() && "Invalid value number!"); |
| 1903 | setOperand(i*2, V); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1904 | } |
Dan Gohman | b45088c | 2009-03-23 15:48:29 +0000 | [diff] [blame] | 1905 | static unsigned getOperandNumForIncomingValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1906 | return i*2; |
| 1907 | } |
Dan Gohman | b45088c | 2009-03-23 15:48:29 +0000 | [diff] [blame] | 1908 | static unsigned getIncomingValueNumForOperand(unsigned i) { |
| 1909 | assert(i % 2 == 0 && "Invalid incoming-value operand index!"); |
| 1910 | return i/2; |
| 1911 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1912 | |
Chris Lattner | ceaa457 | 2009-10-10 07:42:42 +0000 | [diff] [blame] | 1913 | /// getIncomingBlock - Return incoming basic block #i. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1914 | /// |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1915 | BasicBlock *getIncomingBlock(unsigned i) const { |
Chris Lattner | fc61aef | 2009-10-10 08:01:27 +0000 | [diff] [blame^] | 1916 | return cast<BasicBlock>(getOperand(i*2+1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1917 | } |
Chris Lattner | ceaa457 | 2009-10-10 07:42:42 +0000 | [diff] [blame] | 1918 | |
| 1919 | /// getIncomingBlock - Return incoming basic block corresponding |
| 1920 | /// to an operand of the PHI. |
| 1921 | /// |
| 1922 | BasicBlock *getIncomingBlock(const Use &U) const { |
| 1923 | assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?"); |
Chris Lattner | fc61aef | 2009-10-10 08:01:27 +0000 | [diff] [blame^] | 1924 | return cast<BasicBlock>((&U + 1)->get()); |
Chris Lattner | ceaa457 | 2009-10-10 07:42:42 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | /// getIncomingBlock - Return incoming basic block corresponding |
| 1928 | /// to value use iterator. |
| 1929 | /// |
| 1930 | template <typename U> |
| 1931 | BasicBlock *getIncomingBlock(value_use_iterator<U> I) const { |
| 1932 | return getIncomingBlock(I.getUse()); |
| 1933 | } |
| 1934 | |
| 1935 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1936 | void setIncomingBlock(unsigned i, BasicBlock *BB) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1937 | setOperand(i*2+1, BB); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1938 | } |
Dan Gohman | b45088c | 2009-03-23 15:48:29 +0000 | [diff] [blame] | 1939 | static unsigned getOperandNumForIncomingBlock(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1940 | return i*2+1; |
| 1941 | } |
Dan Gohman | b45088c | 2009-03-23 15:48:29 +0000 | [diff] [blame] | 1942 | static unsigned getIncomingBlockNumForOperand(unsigned i) { |
| 1943 | assert(i % 2 == 1 && "Invalid incoming-block operand index!"); |
| 1944 | return i/2; |
| 1945 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1946 | |
| 1947 | /// addIncoming - Add an incoming value to the end of the PHI list |
| 1948 | /// |
| 1949 | void addIncoming(Value *V, BasicBlock *BB) { |
Anton Korobeynikov | 351b0d4 | 2008-02-27 22:37:28 +0000 | [diff] [blame] | 1950 | assert(V && "PHI node got a null value!"); |
| 1951 | assert(BB && "PHI node got a null basic block!"); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1952 | assert(getType() == V->getType() && |
| 1953 | "All operands to PHI node must be the same type as the PHI node!"); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1954 | unsigned OpNo = NumOperands; |
| 1955 | if (OpNo+2 > ReservedSpace) |
| 1956 | resizeOperands(0); // Get more space! |
| 1957 | // Initialize some new operands. |
| 1958 | NumOperands = OpNo+2; |
Gabor Greif | 6c80c38 | 2008-05-26 21:33:52 +0000 | [diff] [blame] | 1959 | OperandList[OpNo] = V; |
| 1960 | OperandList[OpNo+1] = BB; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1961 | } |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1962 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1963 | /// removeIncomingValue - Remove an incoming value. This is useful if a |
| 1964 | /// predecessor basic block is deleted. The value removed is returned. |
| 1965 | /// |
| 1966 | /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty |
| 1967 | /// is true), the PHI node is destroyed and any uses of it are replaced with |
| 1968 | /// dummy values. The only time there should be zero incoming values to a PHI |
| 1969 | /// node is when the block is dead, so this strategy is sound. |
| 1970 | /// |
| 1971 | Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); |
| 1972 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1973 | Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1974 | int Idx = getBasicBlockIndex(BB); |
| 1975 | assert(Idx >= 0 && "Invalid basic block argument to remove!"); |
| 1976 | return removeIncomingValue(Idx, DeletePHIIfEmpty); |
| 1977 | } |
| 1978 | |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1979 | /// getBasicBlockIndex - Return the first index of the specified basic |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1980 | /// block in the value list for this PHI. Returns -1 if no instance. |
| 1981 | /// |
| 1982 | int getBasicBlockIndex(const BasicBlock *BB) const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 1983 | Use *OL = OperandList; |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 1984 | for (unsigned i = 0, e = getNumOperands(); i != e; i += 2) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 1985 | if (OL[i+1].get() == BB) return i/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 1986 | return -1; |
| 1987 | } |
| 1988 | |
| 1989 | Value *getIncomingValueForBlock(const BasicBlock *BB) const { |
| 1990 | return getIncomingValue(getBasicBlockIndex(BB)); |
| 1991 | } |
| 1992 | |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 1993 | /// hasConstantValue - If the specified PHI node always merges together the |
Nate Begeman | a83ba0f | 2005-08-04 23:24:19 +0000 | [diff] [blame] | 1994 | /// same value, return the value, otherwise return null. |
| 1995 | /// |
Dan Gohman | bccfc24 | 2009-09-03 15:34:35 +0000 | [diff] [blame] | 1996 | /// If the PHI has undef operands, but all the rest of the operands are |
| 1997 | /// some unique value, return that value if it can be proved that the |
| 1998 | /// value dominates the PHI. If DT is null, use a conservative check, |
| 1999 | /// otherwise use DT to test for dominance. |
| 2000 | /// |
| 2001 | Value *hasConstantValue(DominatorTree *DT = 0) const; |
Chris Lattner | f56a8db | 2006-10-03 17:09:12 +0000 | [diff] [blame] | 2002 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2003 | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2004 | static inline bool classof(const PHINode *) { return true; } |
| 2005 | static inline bool classof(const Instruction *I) { |
Misha Brukman | 9769ab2 | 2005-04-21 20:19:05 +0000 | [diff] [blame] | 2006 | return I->getOpcode() == Instruction::PHI; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2007 | } |
| 2008 | static inline bool classof(const Value *V) { |
| 2009 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2010 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2011 | private: |
| 2012 | void resizeOperands(unsigned NumOperands); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2013 | }; |
| 2014 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2015 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 2016 | struct OperandTraits<PHINode> : public HungoffOperandTraits<2> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2017 | }; |
| 2018 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2019 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2020 | |
| 2021 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2022 | //===----------------------------------------------------------------------===// |
| 2023 | // ReturnInst Class |
| 2024 | //===----------------------------------------------------------------------===// |
| 2025 | |
| 2026 | //===--------------------------------------------------------------------------- |
| 2027 | /// ReturnInst - Return a value (possibly void), from a function. Execution |
| 2028 | /// does not continue in this function any longer. |
| 2029 | /// |
| 2030 | class ReturnInst : public TerminatorInst { |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2031 | ReturnInst(const ReturnInst &RI); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2032 | |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2033 | private: |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2034 | // ReturnInst constructors: |
| 2035 | // ReturnInst() - 'ret void' instruction |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 2036 | // ReturnInst( null) - 'ret void' instruction |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2037 | // ReturnInst(Value* X) - 'ret X' instruction |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2038 | // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2039 | // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2040 | // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B |
| 2041 | // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B |
Alkis Evlogimenos | 859804f | 2004-11-17 21:02:25 +0000 | [diff] [blame] | 2042 | // |
| 2043 | // NOTE: If the Value* passed is of type void then the constructor behaves as |
| 2044 | // if it was passed NULL. |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2045 | explicit ReturnInst(LLVMContext &C, Value *retVal = 0, |
| 2046 | Instruction *InsertBefore = 0); |
| 2047 | ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); |
| 2048 | explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2049 | public: |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2050 | static ReturnInst* Create(LLVMContext &C, Value *retVal = 0, |
| 2051 | Instruction *InsertBefore = 0) { |
| 2052 | return new(!!retVal) ReturnInst(C, retVal, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2053 | } |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2054 | static ReturnInst* Create(LLVMContext &C, Value *retVal, |
| 2055 | BasicBlock *InsertAtEnd) { |
| 2056 | return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2057 | } |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2058 | static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { |
| 2059 | return new(0) ReturnInst(C, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2060 | } |
Devang Patel | 57ef4f4 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 2061 | virtual ~ReturnInst(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2062 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2063 | virtual ReturnInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2064 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2065 | /// Provide fast operand accessors |
| 2066 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Devang Patel | 64d4e61 | 2008-02-26 17:56:20 +0000 | [diff] [blame] | 2067 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2068 | /// Convenience accessor |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2069 | Value *getReturnValue(unsigned n = 0) const { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2070 | return n < getNumOperands() |
| 2071 | ? getOperand(n) |
| 2072 | : 0; |
Devang Patel | 1eafa06 | 2008-03-11 17:35:03 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2075 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2076 | |
| 2077 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2078 | static inline bool classof(const ReturnInst *) { return true; } |
| 2079 | static inline bool classof(const Instruction *I) { |
| 2080 | return (I->getOpcode() == Instruction::Ret); |
| 2081 | } |
| 2082 | static inline bool classof(const Value *V) { |
| 2083 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2084 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2085 | private: |
| 2086 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2087 | virtual unsigned getNumSuccessorsV() const; |
| 2088 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2089 | }; |
| 2090 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2091 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 2092 | struct OperandTraits<ReturnInst> : public OptionalOperandTraits<> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2093 | }; |
| 2094 | |
| 2095 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2096 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2097 | //===----------------------------------------------------------------------===// |
| 2098 | // BranchInst Class |
| 2099 | //===----------------------------------------------------------------------===// |
| 2100 | |
| 2101 | //===--------------------------------------------------------------------------- |
| 2102 | /// BranchInst - Conditional or Unconditional Branch instruction. |
| 2103 | /// |
| 2104 | class BranchInst : public TerminatorInst { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2105 | /// Ops list - Branches are strange. The operands are ordered: |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2106 | /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because |
| 2107 | /// they don't have to check for cond/uncond branchness. These are mostly |
| 2108 | /// accessed relative from op_end(). |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2109 | BranchInst(const BranchInst &BI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2110 | void AssertOK(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2111 | // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): |
| 2112 | // BranchInst(BB *B) - 'br B' |
| 2113 | // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' |
| 2114 | // BranchInst(BB* B, Inst *I) - 'br B' insert before I |
| 2115 | // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I |
| 2116 | // BranchInst(BB* B, BB *I) - 'br B' insert at end |
| 2117 | // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2118 | explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2119 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2120 | Instruction *InsertBefore = 0); |
| 2121 | BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2122 | BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2123 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2124 | public: |
| 2125 | static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2126 | return new(1, true) BranchInst(IfTrue, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2127 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2128 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2129 | Value *Cond, Instruction *InsertBefore = 0) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2130 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); |
| 2131 | } |
| 2132 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2133 | return new(1, true) BranchInst(IfTrue, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2134 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2135 | static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, |
| 2136 | Value *Cond, BasicBlock *InsertAtEnd) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2137 | return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); |
| 2138 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2139 | |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2140 | ~BranchInst(); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2141 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2142 | /// Transparently provide more efficient getOperand methods. |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2143 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2144 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2145 | virtual BranchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2146 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2147 | bool isUnconditional() const { return getNumOperands() == 1; } |
| 2148 | bool isConditional() const { return getNumOperands() == 3; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2149 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2150 | Value *getCondition() const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2151 | assert(isConditional() && "Cannot get condition of an uncond branch!"); |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2152 | return Op<-3>(); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | void setCondition(Value *V) { |
| 2156 | assert(isConditional() && "Cannot set condition of unconditional branch!"); |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2157 | Op<-3>() = V; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | // setUnconditionalDest - Change the current branch to an unconditional branch |
| 2161 | // targeting the specified block. |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2162 | // FIXME: Eliminate this ugly method. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2163 | void setUnconditionalDest(BasicBlock *Dest) { |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2164 | Op<-1>() = Dest; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2165 | if (isConditional()) { // Convert this to an uncond branch. |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2166 | Op<-2>() = 0; |
| 2167 | Op<-3>() = 0; |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2168 | NumOperands = 1; |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2169 | OperandList = op_begin(); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2170 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2173 | unsigned getNumSuccessors() const { return 1+isConditional(); } |
| 2174 | |
| 2175 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2176 | assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2177 | return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2180 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2181 | assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); |
Gabor Greif | ae5a20a | 2009-03-12 18:34:49 +0000 | [diff] [blame] | 2182 | *(&Op<-1>() - idx) = NewSucc; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2185 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2186 | static inline bool classof(const BranchInst *) { return true; } |
| 2187 | static inline bool classof(const Instruction *I) { |
| 2188 | return (I->getOpcode() == Instruction::Br); |
| 2189 | } |
| 2190 | static inline bool classof(const Value *V) { |
| 2191 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2192 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2193 | private: |
| 2194 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2195 | virtual unsigned getNumSuccessorsV() const; |
| 2196 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2197 | }; |
| 2198 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2199 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 2200 | struct OperandTraits<BranchInst> : public VariadicOperandTraits<1> {}; |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2201 | |
| 2202 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) |
| 2203 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2204 | //===----------------------------------------------------------------------===// |
| 2205 | // SwitchInst Class |
| 2206 | //===----------------------------------------------------------------------===// |
| 2207 | |
| 2208 | //===--------------------------------------------------------------------------- |
| 2209 | /// SwitchInst - Multiway switch |
| 2210 | /// |
| 2211 | class SwitchInst : public TerminatorInst { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2212 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2213 | unsigned ReservedSpace; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2214 | // Operand[0] = Value to switch on |
| 2215 | // Operand[1] = Default basic block destination |
| 2216 | // Operand[2n ] = Value to match |
| 2217 | // Operand[2n+1] = BasicBlock to go to on match |
| 2218 | SwitchInst(const SwitchInst &RI); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2219 | void init(Value *Value, BasicBlock *Default, unsigned NumCases); |
| 2220 | void resizeOperands(unsigned No); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2221 | // allocate space for exactly zero operands |
| 2222 | void *operator new(size_t s) { |
| 2223 | return User::operator new(s, 0); |
| 2224 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2225 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2226 | /// switch on and a default destination. The number of additional cases can |
| 2227 | /// be specified here to make memory allocation more efficient. This |
| 2228 | /// constructor can also autoinsert before another instruction. |
| 2229 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2230 | Instruction *InsertBefore = 0); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2231 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2232 | /// SwitchInst ctor - Create a new switch instruction, specifying a value to |
| 2233 | /// switch on and a default destination. The number of additional cases can |
| 2234 | /// be specified here to make memory allocation more efficient. This |
| 2235 | /// constructor also autoinserts at the end of the specified BasicBlock. |
| 2236 | SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 2237 | BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2238 | public: |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2239 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2240 | unsigned NumCases, Instruction *InsertBefore = 0) { |
| 2241 | return new SwitchInst(Value, Default, NumCases, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2242 | } |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2243 | static SwitchInst *Create(Value *Value, BasicBlock *Default, |
| 2244 | unsigned NumCases, BasicBlock *InsertAtEnd) { |
| 2245 | return new SwitchInst(Value, Default, NumCases, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2246 | } |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 2247 | ~SwitchInst(); |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2248 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2249 | /// Provide fast operand accessors |
| 2250 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
| 2251 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2252 | // Accessor Methods for Switch stmt |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2253 | Value *getCondition() const { return getOperand(0); } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2254 | void setCondition(Value *V) { setOperand(0, V); } |
Chris Lattner | bfaf88a | 2004-12-10 20:35:47 +0000 | [diff] [blame] | 2255 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2256 | BasicBlock *getDefaultDest() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2257 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /// getNumCases - return the number of 'cases' in this switch instruction. |
| 2261 | /// Note that case #0 is always the default case. |
| 2262 | unsigned getNumCases() const { |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2263 | return getNumOperands()/2; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2267 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2268 | ConstantInt *getCaseValue(unsigned i) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2269 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2270 | return getSuccessorValue(i); |
| 2271 | } |
| 2272 | |
| 2273 | /// getCaseValue - Return the specified case value. Note that case #0, the |
| 2274 | /// default destination, does not have a case value. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2275 | const ConstantInt *getCaseValue(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2276 | assert(i && i < getNumCases() && "Illegal case value to get!"); |
| 2277 | return getSuccessorValue(i); |
| 2278 | } |
| 2279 | |
| 2280 | /// findCaseValue - Search all of the case values for the specified constant. |
| 2281 | /// If it is explicitly handled, return the case number of it, otherwise |
| 2282 | /// return 0 to indicate that it is handled by the default handler. |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2283 | unsigned findCaseValue(const ConstantInt *C) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2284 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) |
| 2285 | if (getCaseValue(i) == C) |
| 2286 | return i; |
| 2287 | return 0; |
| 2288 | } |
| 2289 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2290 | /// findCaseDest - Finds the unique case value for a given successor. Returns |
| 2291 | /// null if the successor is not found, not unique, or is the default case. |
| 2292 | ConstantInt *findCaseDest(BasicBlock *BB) { |
Nick Lewycky | d791544 | 2006-09-18 20:44:37 +0000 | [diff] [blame] | 2293 | if (BB == getDefaultDest()) return NULL; |
| 2294 | |
Nick Lewycky | 011f184 | 2006-09-18 19:03:59 +0000 | [diff] [blame] | 2295 | ConstantInt *CI = NULL; |
| 2296 | for (unsigned i = 1, e = getNumCases(); i != e; ++i) { |
| 2297 | if (getSuccessor(i) == BB) { |
| 2298 | if (CI) return NULL; // Multiple cases lead to BB. |
| 2299 | else CI = getCaseValue(i); |
| 2300 | } |
| 2301 | } |
| 2302 | return CI; |
| 2303 | } |
| 2304 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2305 | /// addCase - Add an entry to the switch instruction... |
| 2306 | /// |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2307 | void addCase(ConstantInt *OnVal, BasicBlock *Dest); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2308 | |
| 2309 | /// removeCase - This method removes the specified successor from the switch |
| 2310 | /// instruction. Note that this cannot be used to remove the default |
| 2311 | /// destination (successor #0). |
| 2312 | /// |
| 2313 | void removeCase(unsigned idx); |
| 2314 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2315 | virtual SwitchInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2316 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2317 | unsigned getNumSuccessors() const { return getNumOperands()/2; } |
| 2318 | BasicBlock *getSuccessor(unsigned idx) const { |
| 2319 | assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!"); |
| 2320 | return cast<BasicBlock>(getOperand(idx*2+1)); |
| 2321 | } |
| 2322 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2323 | assert(idx < getNumSuccessors() && "Successor # out of range for switch!"); |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2324 | setOperand(idx*2+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | // getSuccessorValue - Return the value associated with the specified |
| 2328 | // successor. |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2329 | ConstantInt *getSuccessorValue(unsigned idx) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2330 | assert(idx < getNumSuccessors() && "Successor # out of range!"); |
Reid Spencer | edd5d9e | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 2331 | return reinterpret_cast<ConstantInt*>(getOperand(idx*2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2332 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2335 | static inline bool classof(const SwitchInst *) { return true; } |
| 2336 | static inline bool classof(const Instruction *I) { |
Chris Lattner | d1a3260 | 2005-02-24 05:32:09 +0000 | [diff] [blame] | 2337 | return I->getOpcode() == Instruction::Switch; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2338 | } |
| 2339 | static inline bool classof(const Value *V) { |
| 2340 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2341 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2342 | private: |
| 2343 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2344 | virtual unsigned getNumSuccessorsV() const; |
| 2345 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2346 | }; |
| 2347 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2348 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 2349 | struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2350 | }; |
| 2351 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2352 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2353 | |
| 2354 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2355 | //===----------------------------------------------------------------------===// |
| 2356 | // InvokeInst Class |
| 2357 | //===----------------------------------------------------------------------===// |
| 2358 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2359 | /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the |
| 2360 | /// calling convention of the call. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2361 | /// |
| 2362 | class InvokeInst : public TerminatorInst { |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2363 | AttrListPtr AttributeList; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2364 | InvokeInst(const InvokeInst &BI); |
| 2365 | void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException, |
Chris Lattner | d2dd150 | 2007-02-13 01:04:01 +0000 | [diff] [blame] | 2366 | Value* const *Args, unsigned NumArgs); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2367 | |
| 2368 | template<typename InputIterator> |
| 2369 | void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2370 | InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2371 | const Twine &NameStr, |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2372 | // This argument ensures that we have an iterator we can |
| 2373 | // do arithmetic on in constant time |
| 2374 | std::random_access_iterator_tag) { |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2375 | unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2376 | |
Chris Lattner | a5c0d1e | 2007-08-29 16:32:50 +0000 | [diff] [blame] | 2377 | // This requires that the iterator points to contiguous memory. |
| 2378 | init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs); |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2379 | setName(NameStr); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2380 | } |
| 2381 | |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2382 | /// Construct an InvokeInst given a range of arguments. |
| 2383 | /// InputIterator must be a random-access iterator pointing to |
| 2384 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2385 | /// made for random-accessness but not for contiguous storage as |
| 2386 | /// that would incur runtime overhead. |
| 2387 | /// |
| 2388 | /// @brief Construct an InvokeInst from a range of arguments |
| 2389 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2390 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2391 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2392 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2393 | const Twine &NameStr, Instruction *InsertBefore); |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2394 | |
| 2395 | /// Construct an InvokeInst given a range of arguments. |
| 2396 | /// InputIterator must be a random-access iterator pointing to |
| 2397 | /// contiguous storage (e.g. a std::vector<>::iterator). Checks are |
| 2398 | /// made for random-accessness but not for contiguous storage as |
| 2399 | /// that would incur runtime overhead. |
| 2400 | /// |
| 2401 | /// @brief Construct an InvokeInst from a range of arguments |
| 2402 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2403 | inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, |
| 2404 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2405 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2406 | const Twine &NameStr, BasicBlock *InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2407 | public: |
| 2408 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2409 | static InvokeInst *Create(Value *Func, |
| 2410 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2411 | InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2412 | const Twine &NameStr = "", |
Evan Cheng | d69bb1a | 2008-05-05 17:41:03 +0000 | [diff] [blame] | 2413 | Instruction *InsertBefore = 0) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2414 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2415 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2416 | Values, NameStr, InsertBefore); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2417 | } |
| 2418 | template<typename InputIterator> |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2419 | static InvokeInst *Create(Value *Func, |
| 2420 | BasicBlock *IfNormal, BasicBlock *IfException, |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2421 | InputIterator ArgBegin, InputIterator ArgEnd, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2422 | const Twine &NameStr, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2423 | BasicBlock *InsertAtEnd) { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2424 | unsigned Values(ArgEnd - ArgBegin + 3); |
| 2425 | return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2426 | Values, NameStr, InsertAtEnd); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2427 | } |
David Greene | f1355a5 | 2007-08-27 19:04:21 +0000 | [diff] [blame] | 2428 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2429 | virtual InvokeInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2430 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2431 | /// Provide fast operand accessors |
| 2432 | DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2433 | |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2434 | /// getCallingConv/setCallingConv - Get or set the calling convention of this |
| 2435 | /// function call. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2436 | CallingConv::ID getCallingConv() const { |
| 2437 | return static_cast<CallingConv::ID>(SubclassData); |
| 2438 | } |
| 2439 | void setCallingConv(CallingConv::ID CC) { |
| 2440 | SubclassData = static_cast<unsigned>(CC); |
Chris Lattner | 3340ffe | 2005-05-06 20:26:26 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2443 | /// getAttributes - Return the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2444 | /// |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2445 | const AttrListPtr &getAttributes() const { return AttributeList; } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2446 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2447 | /// setAttributes - Set the parameter attributes for this invoke. |
Chris Lattner | 58d7491 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 2448 | /// |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2449 | void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; } |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 2450 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2451 | /// addAttribute - adds the attribute to the list of attributes. |
| 2452 | void addAttribute(unsigned i, Attributes attr); |
Duncan Sands | afa3b6d | 2007-11-28 17:07:01 +0000 | [diff] [blame] | 2453 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2454 | /// removeAttribute - removes the attribute from the list of attributes. |
| 2455 | void removeAttribute(unsigned i, Attributes attr); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 2456 | |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 2457 | /// @brief Determine whether the call or the callee has the given attribute. |
| 2458 | bool paramHasAttr(unsigned i, Attributes attr) const; |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2459 | |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2460 | /// @brief Extract the alignment for a call or parameter (0=unknown). |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2461 | unsigned getParamAlignment(unsigned i) const { |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2462 | return AttributeList.getParamAlignment(i); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2463 | } |
Dale Johannesen | 08e78b1 | 2008-02-22 17:49:45 +0000 | [diff] [blame] | 2464 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2465 | /// @brief Determine if the call does not access memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2466 | bool doesNotAccessMemory() const { |
Dan Gohman | a62b5ed | 2009-07-17 16:12:36 +0000 | [diff] [blame] | 2467 | return paramHasAttr(~0, Attribute::ReadNone); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2468 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2469 | void setDoesNotAccessMemory(bool NotAccessMemory = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2470 | if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone); |
| 2471 | else removeAttribute(~0, Attribute::ReadNone); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 2472 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2473 | |
| 2474 | /// @brief Determine if the call does not access or only reads memory. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2475 | bool onlyReadsMemory() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2476 | return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2477 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2478 | void setOnlyReadsMemory(bool OnlyReadsMemory = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2479 | if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly); |
| 2480 | else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 2481 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2482 | |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2483 | /// @brief Determine if the call cannot return. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2484 | bool doesNotReturn() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2485 | return paramHasAttr(~0, Attribute::NoReturn); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2486 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2487 | void setDoesNotReturn(bool DoesNotReturn = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2488 | if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn); |
| 2489 | else removeAttribute(~0, Attribute::NoReturn); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 2490 | } |
Duncan Sands | cbb8bad | 2007-12-10 19:09:40 +0000 | [diff] [blame] | 2491 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2492 | /// @brief Determine if the call cannot unwind. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2493 | bool doesNotThrow() const { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2494 | return paramHasAttr(~0, Attribute::NoUnwind); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2495 | } |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2496 | void setDoesNotThrow(bool DoesNotThrow = true) { |
Devang Patel | 19c8746 | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 2497 | if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind); |
| 2498 | else removeAttribute(~0, Attribute::NoUnwind); |
Duncan Sands | 2e033f3 | 2008-07-08 08:38:44 +0000 | [diff] [blame] | 2499 | } |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 2500 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2501 | /// @brief Determine if the call returns a structure through first |
Devang Patel | 41e2397 | 2008-03-03 21:46:28 +0000 | [diff] [blame] | 2502 | /// pointer argument. |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2503 | bool hasStructRetAttr() const { |
| 2504 | // Be friendly and also check the callee. |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 2505 | return paramHasAttr(1, Attribute::StructRet); |
Chris Lattner | d5d94df | 2008-03-13 05:00:21 +0000 | [diff] [blame] | 2506 | } |
Reid Spencer | fa3e912 | 2007-04-09 18:00:57 +0000 | [diff] [blame] | 2507 | |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 2508 | /// @brief Determine if any call argument is an aggregate passed by value. |
| 2509 | bool hasByValArgument() const { |
| 2510 | return AttributeList.hasAttrSomewhere(Attribute::ByVal); |
| 2511 | } |
| 2512 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2513 | /// getCalledFunction - Return the function called, or null if this is an |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2514 | /// indirect function invocation. |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2515 | /// |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2516 | Function *getCalledFunction() const { |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2517 | return dyn_cast<Function>(getOperand(0)); |
Chris Lattner | 721aef6 | 2004-11-18 17:46:57 +0000 | [diff] [blame] | 2518 | } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2519 | |
Mikhail Glushenkov | ed2c453 | 2009-02-09 17:11:05 +0000 | [diff] [blame] | 2520 | /// getCalledValue - Get a pointer to the function that is invoked by this |
Dan Gohman | f275250 | 2008-09-26 21:38:45 +0000 | [diff] [blame] | 2521 | /// instruction |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2522 | const Value *getCalledValue() const { return getOperand(0); } |
| 2523 | Value *getCalledValue() { return getOperand(0); } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2524 | |
| 2525 | // get*Dest - Return the destination basic blocks... |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2526 | BasicBlock *getNormalDest() const { |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2527 | return cast<BasicBlock>(getOperand(1)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2528 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2529 | BasicBlock *getUnwindDest() const { |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2530 | return cast<BasicBlock>(getOperand(2)); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2531 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2532 | void setNormalDest(BasicBlock *B) { |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2533 | setOperand(1, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2534 | } |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2535 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2536 | void setUnwindDest(BasicBlock *B) { |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2537 | setOperand(2, B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Devang Patel | 4d4a5e0 | 2008-02-23 01:11:02 +0000 | [diff] [blame] | 2540 | BasicBlock *getSuccessor(unsigned i) const { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2541 | assert(i < 2 && "Successor # out of range for invoke!"); |
| 2542 | return i == 0 ? getNormalDest() : getUnwindDest(); |
| 2543 | } |
| 2544 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2545 | void setSuccessor(unsigned idx, BasicBlock *NewSucc) { |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2546 | assert(idx < 2 && "Successor # out of range for invoke!"); |
Gabor Greif | 03a5f13 | 2009-09-03 02:02:59 +0000 | [diff] [blame] | 2547 | setOperand(idx+1, NewSucc); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2550 | unsigned getNumSuccessors() const { return 2; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2551 | |
| 2552 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2553 | static inline bool classof(const InvokeInst *) { return true; } |
| 2554 | static inline bool classof(const Instruction *I) { |
| 2555 | return (I->getOpcode() == Instruction::Invoke); |
| 2556 | } |
| 2557 | static inline bool classof(const Value *V) { |
| 2558 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2559 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2560 | private: |
| 2561 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2562 | virtual unsigned getNumSuccessorsV() const; |
| 2563 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2564 | }; |
| 2565 | |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2566 | template <> |
Duncan Sands | 59bf4fc | 2009-09-06 08:55:57 +0000 | [diff] [blame] | 2567 | struct OperandTraits<InvokeInst> : public VariadicOperandTraits<3> { |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2568 | }; |
| 2569 | |
| 2570 | template<typename InputIterator> |
| 2571 | InvokeInst::InvokeInst(Value *Func, |
| 2572 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2573 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2574 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2575 | const Twine &NameStr, Instruction *InsertBefore) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2576 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2577 | ->getElementType())->getReturnType(), |
| 2578 | Instruction::Invoke, |
| 2579 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2580 | Values, InsertBefore) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2581 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2582 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2583 | } |
| 2584 | template<typename InputIterator> |
| 2585 | InvokeInst::InvokeInst(Value *Func, |
| 2586 | BasicBlock *IfNormal, BasicBlock *IfException, |
| 2587 | InputIterator ArgBegin, InputIterator ArgEnd, |
| 2588 | unsigned Values, |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2589 | const Twine &NameStr, BasicBlock *InsertAtEnd) |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2590 | : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType()) |
| 2591 | ->getElementType())->getReturnType(), |
| 2592 | Instruction::Invoke, |
| 2593 | OperandTraits<InvokeInst>::op_end(this) - Values, |
| 2594 | Values, InsertAtEnd) { |
Evan Cheng | 1bf9a18 | 2008-07-24 00:08:56 +0000 | [diff] [blame] | 2595 | init(Func, IfNormal, IfException, ArgBegin, ArgEnd, NameStr, |
Gabor Greif | efe6536 | 2008-05-10 08:32:32 +0000 | [diff] [blame] | 2596 | typename std::iterator_traits<InputIterator>::iterator_category()); |
| 2597 | } |
| 2598 | |
| 2599 | DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value) |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2600 | |
| 2601 | //===----------------------------------------------------------------------===// |
| 2602 | // UnwindInst Class |
| 2603 | //===----------------------------------------------------------------------===// |
| 2604 | |
| 2605 | //===--------------------------------------------------------------------------- |
| 2606 | /// UnwindInst - Immediately exit the current function, unwinding the stack |
| 2607 | /// until an invoke instruction is found. |
| 2608 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2609 | class UnwindInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2610 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2611 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2612 | // allocate space for exactly zero operands |
| 2613 | void *operator new(size_t s) { |
| 2614 | return User::operator new(s, 0); |
| 2615 | } |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2616 | explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0); |
| 2617 | explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2618 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2619 | virtual UnwindInst *clone() const; |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2620 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2621 | unsigned getNumSuccessors() const { return 0; } |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2622 | |
| 2623 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2624 | static inline bool classof(const UnwindInst *) { return true; } |
| 2625 | static inline bool classof(const Instruction *I) { |
| 2626 | return I->getOpcode() == Instruction::Unwind; |
| 2627 | } |
| 2628 | static inline bool classof(const Value *V) { |
| 2629 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2630 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2631 | private: |
| 2632 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2633 | virtual unsigned getNumSuccessorsV() const; |
| 2634 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 2635 | }; |
| 2636 | |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2637 | //===----------------------------------------------------------------------===// |
| 2638 | // UnreachableInst Class |
| 2639 | //===----------------------------------------------------------------------===// |
| 2640 | |
| 2641 | //===--------------------------------------------------------------------------- |
| 2642 | /// UnreachableInst - This function has undefined behavior. In particular, the |
| 2643 | /// presence of this instruction indicates some higher level knowledge that the |
| 2644 | /// end of the block cannot be reached. |
| 2645 | /// |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2646 | class UnreachableInst : public TerminatorInst { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2647 | void *operator new(size_t, unsigned); // DO NOT IMPLEMENT |
Chris Lattner | 1fca5ff | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 2648 | public: |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 2649 | // allocate space for exactly zero operands |
| 2650 | void *operator new(size_t s) { |
| 2651 | return User::operator new(s, 0); |
| 2652 | } |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2653 | explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0); |
| 2654 | explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2655 | |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2656 | virtual UnreachableInst *clone() const; |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2657 | |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2658 | unsigned getNumSuccessors() const { return 0; } |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2659 | |
| 2660 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2661 | static inline bool classof(const UnreachableInst *) { return true; } |
| 2662 | static inline bool classof(const Instruction *I) { |
| 2663 | return I->getOpcode() == Instruction::Unreachable; |
| 2664 | } |
| 2665 | static inline bool classof(const Value *V) { |
| 2666 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2667 | } |
Chris Lattner | 454928e | 2005-01-29 00:31:36 +0000 | [diff] [blame] | 2668 | private: |
| 2669 | virtual BasicBlock *getSuccessorV(unsigned idx) const; |
| 2670 | virtual unsigned getNumSuccessorsV() const; |
| 2671 | virtual void setSuccessorV(unsigned idx, BasicBlock *B); |
Chris Lattner | 076b3f1 | 2004-10-16 18:05:54 +0000 | [diff] [blame] | 2672 | }; |
| 2673 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2674 | //===----------------------------------------------------------------------===// |
| 2675 | // TruncInst Class |
| 2676 | //===----------------------------------------------------------------------===// |
| 2677 | |
| 2678 | /// @brief This class represents a truncation of integer types. |
| 2679 | class TruncInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2680 | public: |
| 2681 | /// @brief Constructor with insert-before-instruction semantics |
| 2682 | TruncInst( |
| 2683 | Value *S, ///< The value to be truncated |
| 2684 | const Type *Ty, ///< The (smaller) type to truncate to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2685 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2686 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2687 | ); |
| 2688 | |
| 2689 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2690 | TruncInst( |
| 2691 | Value *S, ///< The value to be truncated |
| 2692 | const Type *Ty, ///< The (smaller) type to truncate to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2693 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2694 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2695 | ); |
| 2696 | |
| 2697 | /// @brief Clone an identical TruncInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2698 | virtual TruncInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2699 | |
| 2700 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2701 | static inline bool classof(const TruncInst *) { return true; } |
| 2702 | static inline bool classof(const Instruction *I) { |
| 2703 | return I->getOpcode() == Trunc; |
| 2704 | } |
| 2705 | static inline bool classof(const Value *V) { |
| 2706 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2707 | } |
| 2708 | }; |
| 2709 | |
| 2710 | //===----------------------------------------------------------------------===// |
| 2711 | // ZExtInst Class |
| 2712 | //===----------------------------------------------------------------------===// |
| 2713 | |
| 2714 | /// @brief This class represents zero extension of integer types. |
| 2715 | class ZExtInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2716 | public: |
| 2717 | /// @brief Constructor with insert-before-instruction semantics |
| 2718 | ZExtInst( |
| 2719 | Value *S, ///< The value to be zero extended |
| 2720 | const Type *Ty, ///< The type to zero extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2721 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2722 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2723 | ); |
| 2724 | |
| 2725 | /// @brief Constructor with insert-at-end semantics. |
| 2726 | ZExtInst( |
| 2727 | Value *S, ///< The value to be zero extended |
| 2728 | const Type *Ty, ///< The type to zero extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2729 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2730 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2731 | ); |
| 2732 | |
| 2733 | /// @brief Clone an identical ZExtInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2734 | virtual ZExtInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2735 | |
| 2736 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2737 | static inline bool classof(const ZExtInst *) { return true; } |
| 2738 | static inline bool classof(const Instruction *I) { |
| 2739 | return I->getOpcode() == ZExt; |
| 2740 | } |
| 2741 | static inline bool classof(const Value *V) { |
| 2742 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2743 | } |
| 2744 | }; |
| 2745 | |
| 2746 | //===----------------------------------------------------------------------===// |
| 2747 | // SExtInst Class |
| 2748 | //===----------------------------------------------------------------------===// |
| 2749 | |
| 2750 | /// @brief This class represents a sign extension of integer types. |
| 2751 | class SExtInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2752 | public: |
| 2753 | /// @brief Constructor with insert-before-instruction semantics |
| 2754 | SExtInst( |
| 2755 | Value *S, ///< The value to be sign extended |
| 2756 | const Type *Ty, ///< The type to sign extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2757 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2758 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2759 | ); |
| 2760 | |
| 2761 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2762 | SExtInst( |
| 2763 | Value *S, ///< The value to be sign extended |
| 2764 | const Type *Ty, ///< The type to sign extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2765 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2766 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2767 | ); |
| 2768 | |
| 2769 | /// @brief Clone an identical SExtInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2770 | virtual SExtInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2771 | |
| 2772 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2773 | static inline bool classof(const SExtInst *) { return true; } |
| 2774 | static inline bool classof(const Instruction *I) { |
| 2775 | return I->getOpcode() == SExt; |
| 2776 | } |
| 2777 | static inline bool classof(const Value *V) { |
| 2778 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2779 | } |
| 2780 | }; |
| 2781 | |
| 2782 | //===----------------------------------------------------------------------===// |
| 2783 | // FPTruncInst Class |
| 2784 | //===----------------------------------------------------------------------===// |
| 2785 | |
| 2786 | /// @brief This class represents a truncation of floating point types. |
| 2787 | class FPTruncInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2788 | public: |
| 2789 | /// @brief Constructor with insert-before-instruction semantics |
| 2790 | FPTruncInst( |
| 2791 | Value *S, ///< The value to be truncated |
| 2792 | const Type *Ty, ///< The type to truncate to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2793 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2794 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2795 | ); |
| 2796 | |
| 2797 | /// @brief Constructor with insert-before-instruction semantics |
| 2798 | FPTruncInst( |
| 2799 | Value *S, ///< The value to be truncated |
| 2800 | const Type *Ty, ///< The type to truncate to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2801 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2802 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2803 | ); |
| 2804 | |
| 2805 | /// @brief Clone an identical FPTruncInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2806 | virtual FPTruncInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2807 | |
| 2808 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2809 | static inline bool classof(const FPTruncInst *) { return true; } |
| 2810 | static inline bool classof(const Instruction *I) { |
| 2811 | return I->getOpcode() == FPTrunc; |
| 2812 | } |
| 2813 | static inline bool classof(const Value *V) { |
| 2814 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2815 | } |
| 2816 | }; |
| 2817 | |
| 2818 | //===----------------------------------------------------------------------===// |
| 2819 | // FPExtInst Class |
| 2820 | //===----------------------------------------------------------------------===// |
| 2821 | |
| 2822 | /// @brief This class represents an extension of floating point types. |
| 2823 | class FPExtInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2824 | public: |
| 2825 | /// @brief Constructor with insert-before-instruction semantics |
| 2826 | FPExtInst( |
| 2827 | Value *S, ///< The value to be extended |
| 2828 | const Type *Ty, ///< The type to extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2829 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2830 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2831 | ); |
| 2832 | |
| 2833 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2834 | FPExtInst( |
| 2835 | Value *S, ///< The value to be extended |
| 2836 | const Type *Ty, ///< The type to extend to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2837 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2838 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2839 | ); |
| 2840 | |
| 2841 | /// @brief Clone an identical FPExtInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2842 | virtual FPExtInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2843 | |
| 2844 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2845 | static inline bool classof(const FPExtInst *) { return true; } |
| 2846 | static inline bool classof(const Instruction *I) { |
| 2847 | return I->getOpcode() == FPExt; |
| 2848 | } |
| 2849 | static inline bool classof(const Value *V) { |
| 2850 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2851 | } |
| 2852 | }; |
| 2853 | |
| 2854 | //===----------------------------------------------------------------------===// |
| 2855 | // UIToFPInst Class |
| 2856 | //===----------------------------------------------------------------------===// |
| 2857 | |
| 2858 | /// @brief This class represents a cast unsigned integer to floating point. |
| 2859 | class UIToFPInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2860 | public: |
| 2861 | /// @brief Constructor with insert-before-instruction semantics |
| 2862 | UIToFPInst( |
| 2863 | Value *S, ///< The value to be converted |
| 2864 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2865 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2866 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2867 | ); |
| 2868 | |
| 2869 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2870 | UIToFPInst( |
| 2871 | Value *S, ///< The value to be converted |
| 2872 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2873 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2874 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2875 | ); |
| 2876 | |
| 2877 | /// @brief Clone an identical UIToFPInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2878 | virtual UIToFPInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2879 | |
| 2880 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2881 | static inline bool classof(const UIToFPInst *) { return true; } |
| 2882 | static inline bool classof(const Instruction *I) { |
| 2883 | return I->getOpcode() == UIToFP; |
| 2884 | } |
| 2885 | static inline bool classof(const Value *V) { |
| 2886 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2887 | } |
| 2888 | }; |
| 2889 | |
| 2890 | //===----------------------------------------------------------------------===// |
| 2891 | // SIToFPInst Class |
| 2892 | //===----------------------------------------------------------------------===// |
| 2893 | |
| 2894 | /// @brief This class represents a cast from signed integer to floating point. |
| 2895 | class SIToFPInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2896 | public: |
| 2897 | /// @brief Constructor with insert-before-instruction semantics |
| 2898 | SIToFPInst( |
| 2899 | Value *S, ///< The value to be converted |
| 2900 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2901 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2902 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2903 | ); |
| 2904 | |
| 2905 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2906 | SIToFPInst( |
| 2907 | Value *S, ///< The value to be converted |
| 2908 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2909 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2910 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2911 | ); |
| 2912 | |
| 2913 | /// @brief Clone an identical SIToFPInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2914 | virtual SIToFPInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2915 | |
| 2916 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2917 | static inline bool classof(const SIToFPInst *) { return true; } |
| 2918 | static inline bool classof(const Instruction *I) { |
| 2919 | return I->getOpcode() == SIToFP; |
| 2920 | } |
| 2921 | static inline bool classof(const Value *V) { |
| 2922 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2923 | } |
| 2924 | }; |
| 2925 | |
| 2926 | //===----------------------------------------------------------------------===// |
| 2927 | // FPToUIInst Class |
| 2928 | //===----------------------------------------------------------------------===// |
| 2929 | |
| 2930 | /// @brief This class represents a cast from floating point to unsigned integer |
| 2931 | class FPToUIInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2932 | public: |
| 2933 | /// @brief Constructor with insert-before-instruction semantics |
| 2934 | FPToUIInst( |
| 2935 | Value *S, ///< The value to be converted |
| 2936 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2937 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2938 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2939 | ); |
| 2940 | |
| 2941 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2942 | FPToUIInst( |
| 2943 | Value *S, ///< The value to be converted |
| 2944 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2945 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2946 | BasicBlock *InsertAtEnd ///< Where to insert the new instruction |
| 2947 | ); |
| 2948 | |
| 2949 | /// @brief Clone an identical FPToUIInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2950 | virtual FPToUIInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2951 | |
| 2952 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2953 | static inline bool classof(const FPToUIInst *) { return true; } |
| 2954 | static inline bool classof(const Instruction *I) { |
| 2955 | return I->getOpcode() == FPToUI; |
| 2956 | } |
| 2957 | static inline bool classof(const Value *V) { |
| 2958 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2959 | } |
| 2960 | }; |
| 2961 | |
| 2962 | //===----------------------------------------------------------------------===// |
| 2963 | // FPToSIInst Class |
| 2964 | //===----------------------------------------------------------------------===// |
| 2965 | |
| 2966 | /// @brief This class represents a cast from floating point to signed integer. |
| 2967 | class FPToSIInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2968 | public: |
| 2969 | /// @brief Constructor with insert-before-instruction semantics |
| 2970 | FPToSIInst( |
| 2971 | Value *S, ///< The value to be converted |
| 2972 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2973 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2974 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 2975 | ); |
| 2976 | |
| 2977 | /// @brief Constructor with insert-at-end-of-block semantics |
| 2978 | FPToSIInst( |
| 2979 | Value *S, ///< The value to be converted |
| 2980 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 2981 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2982 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 2983 | ); |
| 2984 | |
| 2985 | /// @brief Clone an identical FPToSIInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 2986 | virtual FPToSIInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 2987 | |
| 2988 | /// @brief Methods for support type inquiry through isa, cast, and dyn_cast: |
| 2989 | static inline bool classof(const FPToSIInst *) { return true; } |
| 2990 | static inline bool classof(const Instruction *I) { |
| 2991 | return I->getOpcode() == FPToSI; |
| 2992 | } |
| 2993 | static inline bool classof(const Value *V) { |
| 2994 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 2995 | } |
| 2996 | }; |
| 2997 | |
| 2998 | //===----------------------------------------------------------------------===// |
| 2999 | // IntToPtrInst Class |
| 3000 | //===----------------------------------------------------------------------===// |
| 3001 | |
| 3002 | /// @brief This class represents a cast from an integer to a pointer. |
| 3003 | class IntToPtrInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3004 | public: |
| 3005 | /// @brief Constructor with insert-before-instruction semantics |
| 3006 | IntToPtrInst( |
| 3007 | Value *S, ///< The value to be converted |
| 3008 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3009 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3010 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3011 | ); |
| 3012 | |
| 3013 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3014 | IntToPtrInst( |
| 3015 | Value *S, ///< The value to be converted |
| 3016 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3017 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3018 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3019 | ); |
| 3020 | |
| 3021 | /// @brief Clone an identical IntToPtrInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 3022 | virtual IntToPtrInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3023 | |
| 3024 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3025 | static inline bool classof(const IntToPtrInst *) { return true; } |
| 3026 | static inline bool classof(const Instruction *I) { |
| 3027 | return I->getOpcode() == IntToPtr; |
| 3028 | } |
| 3029 | static inline bool classof(const Value *V) { |
| 3030 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3031 | } |
| 3032 | }; |
| 3033 | |
| 3034 | //===----------------------------------------------------------------------===// |
| 3035 | // PtrToIntInst Class |
| 3036 | //===----------------------------------------------------------------------===// |
| 3037 | |
| 3038 | /// @brief This class represents a cast from a pointer to an integer |
| 3039 | class PtrToIntInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3040 | public: |
| 3041 | /// @brief Constructor with insert-before-instruction semantics |
| 3042 | PtrToIntInst( |
| 3043 | Value *S, ///< The value to be converted |
| 3044 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3045 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3046 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3047 | ); |
| 3048 | |
| 3049 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3050 | PtrToIntInst( |
| 3051 | Value *S, ///< The value to be converted |
| 3052 | const Type *Ty, ///< The type to convert to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3053 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3054 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3055 | ); |
| 3056 | |
| 3057 | /// @brief Clone an identical PtrToIntInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 3058 | virtual PtrToIntInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3059 | |
| 3060 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3061 | static inline bool classof(const PtrToIntInst *) { return true; } |
| 3062 | static inline bool classof(const Instruction *I) { |
| 3063 | return I->getOpcode() == PtrToInt; |
| 3064 | } |
| 3065 | static inline bool classof(const Value *V) { |
| 3066 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3067 | } |
| 3068 | }; |
| 3069 | |
| 3070 | //===----------------------------------------------------------------------===// |
| 3071 | // BitCastInst Class |
| 3072 | //===----------------------------------------------------------------------===// |
| 3073 | |
| 3074 | /// @brief This class represents a no-op cast from one type to another. |
| 3075 | class BitCastInst : public CastInst { |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3076 | public: |
| 3077 | /// @brief Constructor with insert-before-instruction semantics |
| 3078 | BitCastInst( |
| 3079 | Value *S, ///< The value to be casted |
| 3080 | const Type *Ty, ///< The type to casted to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3081 | const Twine &NameStr = "", ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3082 | Instruction *InsertBefore = 0 ///< Where to insert the new instruction |
| 3083 | ); |
| 3084 | |
| 3085 | /// @brief Constructor with insert-at-end-of-block semantics |
| 3086 | BitCastInst( |
| 3087 | Value *S, ///< The value to be casted |
| 3088 | const Type *Ty, ///< The type to casted to |
Daniel Dunbar | 6e0d1cb | 2009-07-25 04:41:11 +0000 | [diff] [blame] | 3089 | const Twine &NameStr, ///< A name for the new instruction |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3090 | BasicBlock *InsertAtEnd ///< The block to insert the instruction into |
| 3091 | ); |
| 3092 | |
| 3093 | /// @brief Clone an identical BitCastInst |
Nick Lewycky | 6776064 | 2009-09-27 07:38:41 +0000 | [diff] [blame] | 3094 | virtual BitCastInst *clone() const; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 3095 | |
| 3096 | // Methods for support type inquiry through isa, cast, and dyn_cast: |
| 3097 | static inline bool classof(const BitCastInst *) { return true; } |
| 3098 | static inline bool classof(const Instruction *I) { |
| 3099 | return I->getOpcode() == BitCast; |
| 3100 | } |
| 3101 | static inline bool classof(const Value *V) { |
| 3102 | return isa<Instruction>(V) && classof(cast<Instruction>(V)); |
| 3103 | } |
| 3104 | }; |
| 3105 | |
Alkis Evlogimenos | eb62bc7 | 2004-07-29 12:17:34 +0000 | [diff] [blame] | 3106 | } // End llvm namespace |
Chris Lattner | a892a3a | 2003-01-27 22:08:52 +0000 | [diff] [blame] | 3107 | |
| 3108 | #endif |