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