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