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