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