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