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