blob: 4103362dd865b22f35db9c76252297da03f7d68c [file] [log] [blame]
Chris Lattnera892a3a2003-01-27 22:08:52 +00001//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
Misha Brukman9769ab22005-04-21 20:19:05 +00002//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner7ed47a12007-12-29 19:59:42 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman9769ab22005-04-21 20:19:05 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnera892a3a2003-01-27 22:08:52 +00009//
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 Evlogimenoseb62bc72004-07-29 12:17:34 +000019#include "llvm/InstrTypes.h"
David Greene52eec542007-08-01 03:43:44 +000020#include "llvm/DerivedTypes.h"
Devang Pateleaf42ab2008-09-23 23:03:40 +000021#include "llvm/Attributes.h"
Sandeep Patel65c3c8f2009-09-02 08:44:58 +000022#include "llvm/CallingConv.h"
Jay Foadfc6d3a42011-07-13 10:26:04 +000023#include "llvm/ADT/ArrayRef.h"
Dan Gohman81a0c0b2008-05-31 00:58:22 +000024#include "llvm/ADT/SmallVector.h"
Eli Friedman47f35132011-07-25 23:16:38 +000025#include "llvm/Support/ErrorHandling.h"
Dan Gohmand68a0762009-01-05 17:59:02 +000026#include <iterator>
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000027
28namespace llvm {
29
Chris Lattnerd1a32602005-02-24 05:32:09 +000030class ConstantInt;
Reid Spencer3da43842007-02-28 22:00:54 +000031class ConstantRange;
32class APInt;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000033class LLVMContext;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000034
Eli Friedman47f35132011-07-25 23:16:38 +000035enum AtomicOrdering {
36 NotAtomic = 0,
37 Unordered = 1,
38 Monotonic = 2,
39 // Consume = 3, // Not specified yet.
40 Acquire = 4,
41 Release = 5,
42 AcquireRelease = 6,
43 SequentiallyConsistent = 7
44};
45
46enum SynchronizationScope {
47 SingleThread = 0,
48 CrossThread = 1
49};
50
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000051//===----------------------------------------------------------------------===//
Victor Hernandez7b929da2009-10-23 21:09:37 +000052// AllocaInst Class
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000053//===----------------------------------------------------------------------===//
54
Victor Hernandez7b929da2009-10-23 21:09:37 +000055/// AllocaInst - an instruction to allocate memory on the stack
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000056///
Victor Hernandez7b929da2009-10-23 21:09:37 +000057class AllocaInst : public UnaryInstruction {
Devang Patel50b6e332009-10-27 22:16:29 +000058protected:
59 virtual AllocaInst *clone_impl() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000060public:
Chris Lattnerdb125cf2011-07-18 04:54:35 +000061 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
Victor Hernandez7b929da2009-10-23 21:09:37 +000062 const Twine &Name = "", Instruction *InsertBefore = 0);
Chris Lattnerdb125cf2011-07-18 04:54:35 +000063 AllocaInst(Type *Ty, Value *ArraySize,
Victor Hernandez7b929da2009-10-23 21:09:37 +000064 const Twine &Name, BasicBlock *InsertAtEnd);
65
Chris Lattnerdb125cf2011-07-18 04:54:35 +000066 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
67 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
Victor Hernandez7b929da2009-10-23 21:09:37 +000068
Chris Lattnerdb125cf2011-07-18 04:54:35 +000069 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
Victor Hernandez7b929da2009-10-23 21:09:37 +000070 const Twine &Name = "", Instruction *InsertBefore = 0);
Chris Lattnerdb125cf2011-07-18 04:54:35 +000071 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
Victor Hernandez7b929da2009-10-23 21:09:37 +000072 const Twine &Name, BasicBlock *InsertAtEnd);
73
Gabor Greif051a9502008-04-06 20:25:17 +000074 // Out of line virtual method, so the vtable, etc. has a home.
Victor Hernandez7b929da2009-10-23 21:09:37 +000075 virtual ~AllocaInst();
Gordon Henriksenafba8fe2007-12-10 02:14:30 +000076
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000077 /// isArrayAllocation - Return true if there is an allocation size parameter
78 /// to the allocation instruction that is not 1.
79 ///
80 bool isArrayAllocation() const;
81
Dan Gohman18476ee2009-07-07 20:47:48 +000082 /// getArraySize - Get the number of elements allocated. For a simple
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000083 /// allocation of a single element, this will return a constant 1 value.
84 ///
Devang Patel4d4a5e02008-02-23 01:11:02 +000085 const Value *getArraySize() const { return getOperand(0); }
86 Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000087
88 /// getType - Overload to return most specific pointer type
89 ///
Chris Lattnerdb125cf2011-07-18 04:54:35 +000090 PointerType *getType() const {
91 return reinterpret_cast<PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000092 }
93
94 /// getAllocatedType - Return the type that is being allocated by the
95 /// instruction.
96 ///
Chris Lattner1afcace2011-07-09 17:41:24 +000097 Type *getAllocatedType() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000098
Nate Begeman14b05292005-11-05 09:21:28 +000099 /// getAlignment - Return the alignment of the memory that is being allocated
100 /// by the instruction.
101 ///
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000102 unsigned getAlignment() const {
Chris Lattnerb2406d92009-12-29 02:46:09 +0000103 return (1u << getSubclassDataFromInstruction()) >> 1;
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000104 }
Dan Gohman52837072008-03-24 16:55:58 +0000105 void setAlignment(unsigned Align);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000106
Chris Lattnerc5dd22a2008-11-26 02:54:17 +0000107 /// isStaticAlloca - Return true if this alloca is in the entry block of the
108 /// function and is a constant size. If so, the code generator will fold it
109 /// into the prolog/epilog code, so it is basically free.
110 bool isStaticAlloca() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000111
112 // Methods for support type inquiry through isa, cast, and dyn_cast:
113 static inline bool classof(const AllocaInst *) { return true; }
114 static inline bool classof(const Instruction *I) {
115 return (I->getOpcode() == Instruction::Alloca);
116 }
117 static inline bool classof(const Value *V) {
118 return isa<Instruction>(V) && classof(cast<Instruction>(V));
119 }
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000120private:
Chris Lattnerb2406d92009-12-29 02:46:09 +0000121 // Shadow Instruction::setInstructionSubclassData with a private forwarding
122 // method so that subclasses cannot accidentally use it.
123 void setInstructionSubclassData(unsigned short D) {
124 Instruction::setInstructionSubclassData(D);
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000125 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000126};
127
128
129//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000130// LoadInst Class
131//===----------------------------------------------------------------------===//
132
Chris Lattner88fe29a2005-02-05 01:44:18 +0000133/// LoadInst - an instruction for reading from memory. This uses the
134/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000135///
Chris Lattner454928e2005-01-29 00:31:36 +0000136class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000137 void AssertOK();
Devang Patel50b6e332009-10-27 22:16:29 +0000138protected:
139 virtual LoadInst *clone_impl() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000140public:
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000141 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
142 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
Daniel Dunbar3603d7a2009-08-11 18:11:15 +0000143 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
Christopher Lamb43c7f372007-04-22 19:24:39 +0000144 Instruction *InsertBefore = 0);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000145 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000146 BasicBlock *InsertAtEnd);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000147 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
Eli Friedman21006d42011-08-09 23:02:53 +0000148 unsigned Align, Instruction *InsertBefore = 0);
149 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
Evan Cheng1bf9a182008-07-24 00:08:56 +0000150 unsigned Align, BasicBlock *InsertAtEnd);
Eli Friedman21006d42011-08-09 23:02:53 +0000151 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
152 unsigned Align, AtomicOrdering Order,
153 SynchronizationScope SynchScope = CrossThread,
154 Instruction *InsertBefore = 0);
155 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
156 unsigned Align, AtomicOrdering Order,
157 SynchronizationScope SynchScope,
158 BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000159
Daniel Dunbar3603d7a2009-08-11 18:11:15 +0000160 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
161 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
162 explicit LoadInst(Value *Ptr, const char *NameStr = 0,
163 bool isVolatile = false, Instruction *InsertBefore = 0);
164 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
165 BasicBlock *InsertAtEnd);
166
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000167 /// isVolatile - Return true if this is a load from a volatile memory
168 /// location.
169 ///
Chris Lattnerb2406d92009-12-29 02:46:09 +0000170 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000171
172 /// setVolatile - Specify whether this is a volatile load or not.
173 ///
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000174 void setVolatile(bool V) {
Chris Lattnerb2406d92009-12-29 02:46:09 +0000175 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
176 (V ? 1 : 0));
Christopher Lamb43c7f372007-04-22 19:24:39 +0000177 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000178
Christopher Lamb43c7f372007-04-22 19:24:39 +0000179 /// getAlignment - Return the alignment of the access that is being performed
180 ///
181 unsigned getAlignment() const {
Eli Friedman21006d42011-08-09 23:02:53 +0000182 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000183 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000184
Christopher Lamb43c7f372007-04-22 19:24:39 +0000185 void setAlignment(unsigned Align);
186
Eli Friedman21006d42011-08-09 23:02:53 +0000187 /// Returns the ordering effect of this fence.
188 AtomicOrdering getOrdering() const {
189 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
190 }
191
192 /// Set the ordering constraint on this load. May not be Release or
193 /// AcquireRelease.
194 void setOrdering(AtomicOrdering Ordering) {
195 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
196 (Ordering << 7));
197 }
198
199 SynchronizationScope getSynchScope() const {
200 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
201 }
202
203 /// Specify whether this load is ordered with respect to all
204 /// concurrently executing threads, or only with respect to signal handlers
205 /// executing in the same thread.
206 void setSynchScope(SynchronizationScope xthread) {
207 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
208 (xthread << 6));
209 }
210
211 bool isAtomic() const { return getOrdering() != NotAtomic; }
212 void setAtomic(AtomicOrdering Ordering,
213 SynchronizationScope SynchScope = CrossThread) {
214 setOrdering(Ordering);
215 setSynchScope(SynchScope);
216 }
217
218 bool isSimple() const { return !isAtomic() && !isVolatile(); }
219 bool isUnordered() const {
220 return getOrdering() <= Unordered && !isVolatile();
221 }
222
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000223 Value *getPointerOperand() { return getOperand(0); }
224 const Value *getPointerOperand() const { return getOperand(0); }
225 static unsigned getPointerOperandIndex() { return 0U; }
226
Chris Lattnera07ae6b2009-08-30 19:45:21 +0000227 unsigned getPointerAddressSpace() const {
228 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
229 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +0000230
231
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000232 // Methods for support type inquiry through isa, cast, and dyn_cast:
233 static inline bool classof(const LoadInst *) { return true; }
234 static inline bool classof(const Instruction *I) {
235 return I->getOpcode() == Instruction::Load;
236 }
237 static inline bool classof(const Value *V) {
238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
239 }
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000240private:
Chris Lattnerb2406d92009-12-29 02:46:09 +0000241 // Shadow Instruction::setInstructionSubclassData with a private forwarding
242 // method so that subclasses cannot accidentally use it.
243 void setInstructionSubclassData(unsigned short D) {
244 Instruction::setInstructionSubclassData(D);
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000245 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000246};
247
248
249//===----------------------------------------------------------------------===//
250// StoreInst Class
251//===----------------------------------------------------------------------===//
252
Misha Brukman9769ab22005-04-21 20:19:05 +0000253/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000254///
255class StoreInst : public Instruction {
Gabor Greif051a9502008-04-06 20:25:17 +0000256 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner454928e2005-01-29 00:31:36 +0000257 void AssertOK();
Devang Patel50b6e332009-10-27 22:16:29 +0000258protected:
259 virtual StoreInst *clone_impl() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000260public:
Gabor Greif051a9502008-04-06 20:25:17 +0000261 // allocate space for exactly two operands
262 void *operator new(size_t s) {
263 return User::operator new(s, 2);
264 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000265 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
266 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
267 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
268 Instruction *InsertBefore = 0);
269 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
Dan Gohman6ab2d182007-07-18 20:51:11 +0000270 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
Eli Friedman21006d42011-08-09 23:02:53 +0000271 unsigned Align, Instruction *InsertBefore = 0);
272 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
Dan Gohman6ab2d182007-07-18 20:51:11 +0000273 unsigned Align, BasicBlock *InsertAtEnd);
Eli Friedman21006d42011-08-09 23:02:53 +0000274 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
275 unsigned Align, AtomicOrdering Order,
276 SynchronizationScope SynchScope = CrossThread,
277 Instruction *InsertBefore = 0);
278 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
279 unsigned Align, AtomicOrdering Order,
280 SynchronizationScope SynchScope,
281 BasicBlock *InsertAtEnd);
282
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000283
Eli Friedman21006d42011-08-09 23:02:53 +0000284 /// isVolatile - Return true if this is a store to a volatile memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000285 /// location.
286 ///
Chris Lattnerb2406d92009-12-29 02:46:09 +0000287 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000288
Eli Friedman21006d42011-08-09 23:02:53 +0000289 /// setVolatile - Specify whether this is a volatile store or not.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000290 ///
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000291 void setVolatile(bool V) {
Chris Lattnerb2406d92009-12-29 02:46:09 +0000292 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
293 (V ? 1 : 0));
Christopher Lamb43c7f372007-04-22 19:24:39 +0000294 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000295
Chris Lattner454928e2005-01-29 00:31:36 +0000296 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +0000297 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Chris Lattner454928e2005-01-29 00:31:36 +0000298
Christopher Lamb43c7f372007-04-22 19:24:39 +0000299 /// getAlignment - Return the alignment of the access that is being performed
300 ///
301 unsigned getAlignment() const {
Eli Friedman21006d42011-08-09 23:02:53 +0000302 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000303 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000304
Christopher Lamb43c7f372007-04-22 19:24:39 +0000305 void setAlignment(unsigned Align);
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000306
Eli Friedman21006d42011-08-09 23:02:53 +0000307 /// Returns the ordering effect of this store.
308 AtomicOrdering getOrdering() const {
309 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
310 }
311
312 /// Set the ordering constraint on this store. May not be Acquire or
313 /// AcquireRelease.
314 void setOrdering(AtomicOrdering Ordering) {
315 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
316 (Ordering << 7));
317 }
318
319 SynchronizationScope getSynchScope() const {
320 return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
321 }
322
323 /// Specify whether this store instruction is ordered with respect to all
324 /// concurrently executing threads, or only with respect to signal handlers
325 /// executing in the same thread.
326 void setSynchScope(SynchronizationScope xthread) {
327 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
328 (xthread << 6));
329 }
330
331 bool isAtomic() const { return getOrdering() != NotAtomic; }
332 void setAtomic(AtomicOrdering Ordering,
333 SynchronizationScope SynchScope = CrossThread) {
334 setOrdering(Ordering);
335 setSynchScope(SynchScope);
336 }
337
338 bool isSimple() const { return !isAtomic() && !isVolatile(); }
339 bool isUnordered() const {
340 return getOrdering() <= Unordered && !isVolatile();
341 }
342
Chris Lattner41c9c0e2010-06-26 23:26:37 +0000343 Value *getValueOperand() { return getOperand(0); }
344 const Value *getValueOperand() const { return getOperand(0); }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +0000345
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000346 Value *getPointerOperand() { return getOperand(1); }
347 const Value *getPointerOperand() const { return getOperand(1); }
348 static unsigned getPointerOperandIndex() { return 1U; }
349
Chris Lattnera07ae6b2009-08-30 19:45:21 +0000350 unsigned getPointerAddressSpace() const {
351 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
352 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +0000353
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000354 // Methods for support type inquiry through isa, cast, and dyn_cast:
355 static inline bool classof(const StoreInst *) { return true; }
356 static inline bool classof(const Instruction *I) {
357 return I->getOpcode() == Instruction::Store;
358 }
359 static inline bool classof(const Value *V) {
360 return isa<Instruction>(V) && classof(cast<Instruction>(V));
361 }
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000362private:
Chris Lattnerb2406d92009-12-29 02:46:09 +0000363 // Shadow Instruction::setInstructionSubclassData with a private forwarding
364 // method so that subclasses cannot accidentally use it.
365 void setInstructionSubclassData(unsigned short D) {
366 Instruction::setInstructionSubclassData(D);
Chris Lattnercafe9bb2009-12-29 02:14:09 +0000367 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000368};
369
Gabor Greifefe65362008-05-10 08:32:32 +0000370template <>
Jay Foad67c619b2011-01-11 15:07:38 +0000371struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
Gabor Greifefe65362008-05-10 08:32:32 +0000372};
373
374DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000375
376//===----------------------------------------------------------------------===//
Eli Friedman47f35132011-07-25 23:16:38 +0000377// FenceInst Class
378//===----------------------------------------------------------------------===//
379
380/// FenceInst - an instruction for ordering other memory operations
381///
382class FenceInst : public Instruction {
383 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
384 void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
385protected:
386 virtual FenceInst *clone_impl() const;
387public:
388 // allocate space for exactly zero operands
389 void *operator new(size_t s) {
390 return User::operator new(s, 0);
391 }
392
393 // Ordering may only be Acquire, Release, AcquireRelease, or
394 // SequentiallyConsistent.
395 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
396 SynchronizationScope SynchScope = CrossThread,
397 Instruction *InsertBefore = 0);
398 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
399 SynchronizationScope SynchScope,
400 BasicBlock *InsertAtEnd);
401
402 /// Returns the ordering effect of this fence.
403 AtomicOrdering getOrdering() const {
404 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
405 }
406
407 /// Set the ordering constraint on this fence. May only be Acquire, Release,
408 /// AcquireRelease, or SequentiallyConsistent.
409 void setOrdering(AtomicOrdering Ordering) {
Eli Friedman21006d42011-08-09 23:02:53 +0000410 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
411 (Ordering << 1));
Eli Friedman47f35132011-07-25 23:16:38 +0000412 }
413
414 SynchronizationScope getSynchScope() const {
415 return SynchronizationScope(getSubclassDataFromInstruction() & 1);
416 }
417
418 /// Specify whether this fence orders other operations with respect to all
419 /// concurrently executing threads, or only with respect to signal handlers
420 /// executing in the same thread.
421 void setSynchScope(SynchronizationScope xthread) {
422 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
423 xthread);
424 }
425
426 // Methods for support type inquiry through isa, cast, and dyn_cast:
427 static inline bool classof(const FenceInst *) { return true; }
428 static inline bool classof(const Instruction *I) {
429 return I->getOpcode() == Instruction::Fence;
430 }
431 static inline bool classof(const Value *V) {
432 return isa<Instruction>(V) && classof(cast<Instruction>(V));
433 }
434private:
435 // Shadow Instruction::setInstructionSubclassData with a private forwarding
436 // method so that subclasses cannot accidentally use it.
437 void setInstructionSubclassData(unsigned short D) {
438 Instruction::setInstructionSubclassData(D);
439 }
440};
441
442//===----------------------------------------------------------------------===//
Eli Friedmanff030482011-07-28 21:48:00 +0000443// AtomicCmpXchgInst Class
444//===----------------------------------------------------------------------===//
445
446/// AtomicCmpXchgInst - an instruction that atomically checks whether a
447/// specified value is in a memory location, and, if it is, stores a new value
448/// there. Returns the value that was loaded.
449///
450class AtomicCmpXchgInst : public Instruction {
451 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
452 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
453 AtomicOrdering Ordering, SynchronizationScope SynchScope);
454protected:
455 virtual AtomicCmpXchgInst *clone_impl() const;
456public:
457 // allocate space for exactly three operands
458 void *operator new(size_t s) {
459 return User::operator new(s, 3);
460 }
461 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
462 AtomicOrdering Ordering, SynchronizationScope SynchScope,
463 Instruction *InsertBefore = 0);
464 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
465 AtomicOrdering Ordering, SynchronizationScope SynchScope,
466 BasicBlock *InsertAtEnd);
467
468 /// isVolatile - Return true if this is a cmpxchg from a volatile memory
469 /// location.
470 ///
471 bool isVolatile() const {
472 return getSubclassDataFromInstruction() & 1;
473 }
474
475 /// setVolatile - Specify whether this is a volatile cmpxchg.
476 ///
477 void setVolatile(bool V) {
478 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
479 (unsigned)V);
480 }
481
482 /// Transparently provide more efficient getOperand methods.
483 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
484
485 /// Set the ordering constraint on this cmpxchg.
486 void setOrdering(AtomicOrdering Ordering) {
487 assert(Ordering != NotAtomic &&
488 "CmpXchg instructions can only be atomic.");
489 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
490 (Ordering << 2));
491 }
492
493 /// Specify whether this cmpxchg is atomic and orders other operations with
494 /// respect to all concurrently executing threads, or only with respect to
495 /// signal handlers executing in the same thread.
496 void setSynchScope(SynchronizationScope SynchScope) {
497 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
498 (SynchScope << 1));
499 }
500
501 /// Returns the ordering constraint on this cmpxchg.
502 AtomicOrdering getOrdering() const {
503 return AtomicOrdering(getSubclassDataFromInstruction() >> 2);
504 }
505
506 /// Returns whether this cmpxchg is atomic between threads or only within a
507 /// single thread.
508 SynchronizationScope getSynchScope() const {
509 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
510 }
511
512 Value *getPointerOperand() { return getOperand(0); }
513 const Value *getPointerOperand() const { return getOperand(0); }
514 static unsigned getPointerOperandIndex() { return 0U; }
515
516 Value *getCompareOperand() { return getOperand(1); }
517 const Value *getCompareOperand() const { return getOperand(1); }
518
519 Value *getNewValOperand() { return getOperand(2); }
520 const Value *getNewValOperand() const { return getOperand(2); }
521
522 unsigned getPointerAddressSpace() const {
523 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
524 }
525
526 // Methods for support type inquiry through isa, cast, and dyn_cast:
527 static inline bool classof(const AtomicCmpXchgInst *) { return true; }
528 static inline bool classof(const Instruction *I) {
529 return I->getOpcode() == Instruction::AtomicCmpXchg;
530 }
531 static inline bool classof(const Value *V) {
532 return isa<Instruction>(V) && classof(cast<Instruction>(V));
533 }
534private:
535 // Shadow Instruction::setInstructionSubclassData with a private forwarding
536 // method so that subclasses cannot accidentally use it.
537 void setInstructionSubclassData(unsigned short D) {
538 Instruction::setInstructionSubclassData(D);
539 }
540};
541
542template <>
543struct OperandTraits<AtomicCmpXchgInst> :
544 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
545};
546
547DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
548
549//===----------------------------------------------------------------------===//
550// AtomicRMWInst Class
551//===----------------------------------------------------------------------===//
552
553/// AtomicRMWInst - an instruction that atomically reads a memory location,
554/// combines it with another value, and then stores the result back. Returns
555/// the old value.
556///
557class AtomicRMWInst : public Instruction {
558 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
559protected:
560 virtual AtomicRMWInst *clone_impl() const;
561public:
562 /// This enumeration lists the possible modifications atomicrmw can make. In
563 /// the descriptions, 'p' is the pointer to the instruction's memory location,
564 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
565 /// instruction. These instructions always return 'old'.
566 enum BinOp {
567 /// *p = v
568 Xchg,
569 /// *p = old + v
570 Add,
571 /// *p = old - v
572 Sub,
573 /// *p = old & v
574 And,
575 /// *p = ~old & v
576 Nand,
577 /// *p = old | v
578 Or,
579 /// *p = old ^ v
580 Xor,
581 /// *p = old >signed v ? old : v
582 Max,
583 /// *p = old <signed v ? old : v
584 Min,
585 /// *p = old >unsigned v ? old : v
586 UMax,
587 /// *p = old <unsigned v ? old : v
588 UMin,
589
590 FIRST_BINOP = Xchg,
591 LAST_BINOP = UMin,
592 BAD_BINOP
593 };
594
595 // allocate space for exactly two operands
596 void *operator new(size_t s) {
597 return User::operator new(s, 2);
598 }
599 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
600 AtomicOrdering Ordering, SynchronizationScope SynchScope,
601 Instruction *InsertBefore = 0);
602 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
603 AtomicOrdering Ordering, SynchronizationScope SynchScope,
604 BasicBlock *InsertAtEnd);
605
606 BinOp getOperation() const {
607 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
608 }
609
610 void setOperation(BinOp Operation) {
611 unsigned short SubclassData = getSubclassDataFromInstruction();
612 setInstructionSubclassData((SubclassData & 31) |
613 (Operation << 5));
614 }
615
616 /// isVolatile - Return true if this is a RMW on a volatile memory location.
617 ///
618 bool isVolatile() const {
619 return getSubclassDataFromInstruction() & 1;
620 }
621
622 /// setVolatile - Specify whether this is a volatile RMW or not.
623 ///
624 void setVolatile(bool V) {
625 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
626 (unsigned)V);
627 }
628
629 /// Transparently provide more efficient getOperand methods.
630 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
631
632 /// Set the ordering constraint on this RMW.
633 void setOrdering(AtomicOrdering Ordering) {
634 assert(Ordering != NotAtomic &&
635 "atomicrmw instructions can only be atomic.");
Eli Friedman21006d42011-08-09 23:02:53 +0000636 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
Eli Friedmanff030482011-07-28 21:48:00 +0000637 (Ordering << 2));
638 }
639
640 /// Specify whether this RMW orders other operations with respect to all
641 /// concurrently executing threads, or only with respect to signal handlers
642 /// executing in the same thread.
643 void setSynchScope(SynchronizationScope SynchScope) {
644 setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
645 (SynchScope << 1));
646 }
647
648 /// Returns the ordering constraint on this RMW.
649 AtomicOrdering getOrdering() const {
Eli Friedman21006d42011-08-09 23:02:53 +0000650 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
Eli Friedmanff030482011-07-28 21:48:00 +0000651 }
652
653 /// Returns whether this RMW is atomic between threads or only within a
654 /// single thread.
655 SynchronizationScope getSynchScope() const {
656 return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
657 }
658
659 Value *getPointerOperand() { return getOperand(0); }
660 const Value *getPointerOperand() const { return getOperand(0); }
661 static unsigned getPointerOperandIndex() { return 0U; }
662
663 Value *getValOperand() { return getOperand(1); }
664 const Value *getValOperand() const { return getOperand(1); }
665
666 unsigned getPointerAddressSpace() const {
667 return cast<PointerType>(getPointerOperand()->getType())->getAddressSpace();
668 }
669
670 // Methods for support type inquiry through isa, cast, and dyn_cast:
671 static inline bool classof(const AtomicRMWInst *) { return true; }
672 static inline bool classof(const Instruction *I) {
673 return I->getOpcode() == Instruction::AtomicRMW;
674 }
675 static inline bool classof(const Value *V) {
676 return isa<Instruction>(V) && classof(cast<Instruction>(V));
677 }
678private:
679 void Init(BinOp Operation, Value *Ptr, Value *Val,
680 AtomicOrdering Ordering, SynchronizationScope SynchScope);
681 // Shadow Instruction::setInstructionSubclassData with a private forwarding
682 // method so that subclasses cannot accidentally use it.
683 void setInstructionSubclassData(unsigned short D) {
684 Instruction::setInstructionSubclassData(D);
685 }
686};
687
688template <>
689struct OperandTraits<AtomicRMWInst>
690 : public FixedNumOperandTraits<AtomicRMWInst,2> {
691};
692
693DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
694
695//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000696// GetElementPtrInst Class
697//===----------------------------------------------------------------------===//
698
Chris Lattner1afcace2011-07-09 17:41:24 +0000699// checkGEPType - Simple wrapper function to give a better assertion failure
David Greeneb8f74792007-09-04 15:46:09 +0000700// message on bad indexes for a gep instruction.
701//
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000702static inline Type *checkGEPType(Type *Ty) {
David Greeneb8f74792007-09-04 15:46:09 +0000703 assert(Ty && "Invalid GetElementPtrInst indices for type!");
704 return Ty;
705}
706
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000707/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
708/// access elements of arrays and structs
709///
710class GetElementPtrInst : public Instruction {
Gabor Greifefe65362008-05-10 08:32:32 +0000711 GetElementPtrInst(const GetElementPtrInst &GEPI);
Jay Foada9203102011-07-25 09:48:08 +0000712 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
David Greeneb8f74792007-09-04 15:46:09 +0000713
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000714 /// Constructors - Create a getelementptr instruction with a base pointer an
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +0000715 /// list of indices. The first ctor can optionally insert before an existing
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000716 /// instruction, the second appends the new instruction to the specified
717 /// BasicBlock.
Jay Foada9203102011-07-25 09:48:08 +0000718 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
719 unsigned Values, const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +0000720 Instruction *InsertBefore);
Jay Foada9203102011-07-25 09:48:08 +0000721 inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
722 unsigned Values, const Twine &NameStr,
723 BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +0000724protected:
725 virtual GetElementPtrInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +0000726public:
Jay Foada9203102011-07-25 09:48:08 +0000727 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000728 const Twine &NameStr = "",
Gabor Greif051a9502008-04-06 20:25:17 +0000729 Instruction *InsertBefore = 0) {
Jay Foada9203102011-07-25 09:48:08 +0000730 unsigned Values = 1 + unsigned(IdxList.size());
Gabor Greifefe65362008-05-10 08:32:32 +0000731 return new(Values)
Jay Foada9203102011-07-25 09:48:08 +0000732 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +0000733 }
Jay Foada9203102011-07-25 09:48:08 +0000734 static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000735 const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +0000736 BasicBlock *InsertAtEnd) {
Jay Foada9203102011-07-25 09:48:08 +0000737 unsigned Values = 1 + unsigned(IdxList.size());
Gabor Greifefe65362008-05-10 08:32:32 +0000738 return new(Values)
Jay Foada9203102011-07-25 09:48:08 +0000739 GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +0000740 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000741
Dan Gohmane2574d32009-08-11 17:57:01 +0000742 /// Create an "inbounds" getelementptr. See the documentation for the
743 /// "inbounds" flag in LangRef.html for details.
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +0000744 static GetElementPtrInst *CreateInBounds(Value *Ptr,
Jay Foada9203102011-07-25 09:48:08 +0000745 ArrayRef<Value *> IdxList,
Dan Gohmane2574d32009-08-11 17:57:01 +0000746 const Twine &NameStr = "",
747 Instruction *InsertBefore = 0) {
Jay Foada9203102011-07-25 09:48:08 +0000748 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
Dan Gohmanf8dbee72009-09-07 23:54:19 +0000749 GEP->setIsInBounds(true);
Dan Gohmane2574d32009-08-11 17:57:01 +0000750 return GEP;
751 }
Dan Gohmane2574d32009-08-11 17:57:01 +0000752 static GetElementPtrInst *CreateInBounds(Value *Ptr,
Jay Foada9203102011-07-25 09:48:08 +0000753 ArrayRef<Value *> IdxList,
Dan Gohmane2574d32009-08-11 17:57:01 +0000754 const Twine &NameStr,
755 BasicBlock *InsertAtEnd) {
Jay Foada9203102011-07-25 09:48:08 +0000756 GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
Dan Gohmanf8dbee72009-09-07 23:54:19 +0000757 GEP->setIsInBounds(true);
Dan Gohmane2574d32009-08-11 17:57:01 +0000758 return GEP;
759 }
760
Gabor Greifefe65362008-05-10 08:32:32 +0000761 /// Transparently provide more efficient getOperand methods.
762 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
763
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000764 // getType - Overload to return most specific pointer type...
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000765 PointerType *getType() const {
766 return reinterpret_cast<PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000767 }
768
769 /// getIndexedType - Returns the type of the element that would be loaded with
770 /// a load instruction with the specified parameters.
771 ///
Dan Gohmane2d896f2008-05-15 23:35:32 +0000772 /// Null is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000773 /// pointer type.
774 ///
Jay Foada9203102011-07-25 09:48:08 +0000775 static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
776 static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
777 static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
Misha Brukman9769ab22005-04-21 20:19:05 +0000778
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000779 inline op_iterator idx_begin() { return op_begin()+1; }
780 inline const_op_iterator idx_begin() const { return op_begin()+1; }
781 inline op_iterator idx_end() { return op_end(); }
782 inline const_op_iterator idx_end() const { return op_end(); }
783
784 Value *getPointerOperand() {
785 return getOperand(0);
786 }
787 const Value *getPointerOperand() const {
788 return getOperand(0);
789 }
790 static unsigned getPointerOperandIndex() {
791 return 0U; // get index for modifying correct operand
792 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +0000793
Chris Lattner8a67ac52009-08-30 20:06:40 +0000794 unsigned getPointerAddressSpace() const {
795 return cast<PointerType>(getType())->getAddressSpace();
796 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000797
Chris Lattner3bc6ced2009-01-09 05:27:40 +0000798 /// getPointerOperandType - Method to return the pointer operand as a
799 /// PointerType.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000800 PointerType *getPointerOperandType() const {
801 return reinterpret_cast<PointerType*>(getPointerOperand()->getType());
Chris Lattner3bc6ced2009-01-09 05:27:40 +0000802 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000803
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000804
Devang Patel4d4a5e02008-02-23 01:11:02 +0000805 unsigned getNumIndices() const { // Note: always non-negative
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000806 return getNumOperands() - 1;
807 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000808
Devang Patel4d4a5e02008-02-23 01:11:02 +0000809 bool hasIndices() const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000810 return getNumOperands() > 1;
811 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000812
Chris Lattner6f771d42007-04-14 00:12:57 +0000813 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
814 /// zeros. If so, the result pointer and the first operand have the same
815 /// value, just potentially different types.
816 bool hasAllZeroIndices() const;
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000817
Chris Lattner6b0974c2007-04-27 20:35:56 +0000818 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
819 /// constant integers. If so, the result pointer and the first operand have
820 /// a constant offset between them.
821 bool hasAllConstantIndices() const;
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000822
Dan Gohmanf8dbee72009-09-07 23:54:19 +0000823 /// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
824 /// See LangRef.html for the meaning of inbounds on a getelementptr.
Nick Lewyckyae05e7d2009-09-27 21:33:04 +0000825 void setIsInBounds(bool b = true);
826
827 /// isInBounds - Determine whether the GEP has the inbounds flag.
828 bool isInBounds() const;
Dan Gohmanf8dbee72009-09-07 23:54:19 +0000829
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000830 // Methods for support type inquiry through isa, cast, and dyn_cast:
831 static inline bool classof(const GetElementPtrInst *) { return true; }
832 static inline bool classof(const Instruction *I) {
833 return (I->getOpcode() == Instruction::GetElementPtr);
834 }
835 static inline bool classof(const Value *V) {
836 return isa<Instruction>(V) && classof(cast<Instruction>(V));
837 }
838};
839
Gabor Greifefe65362008-05-10 08:32:32 +0000840template <>
Jay Foad67c619b2011-01-11 15:07:38 +0000841struct OperandTraits<GetElementPtrInst> :
842 public VariadicOperandTraits<GetElementPtrInst, 1> {
Gabor Greifefe65362008-05-10 08:32:32 +0000843};
844
Gabor Greifefe65362008-05-10 08:32:32 +0000845GetElementPtrInst::GetElementPtrInst(Value *Ptr,
Jay Foada9203102011-07-25 09:48:08 +0000846 ArrayRef<Value *> IdxList,
Gabor Greifefe65362008-05-10 08:32:32 +0000847 unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000848 const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +0000849 Instruction *InsertBefore)
Chris Lattner1afcace2011-07-09 17:41:24 +0000850 : Instruction(PointerType::get(checkGEPType(
Jay Foada9203102011-07-25 09:48:08 +0000851 getIndexedType(Ptr->getType(), IdxList)),
Gabor Greifefe65362008-05-10 08:32:32 +0000852 cast<PointerType>(Ptr->getType())
853 ->getAddressSpace()),
854 GetElementPtr,
855 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
856 Values, InsertBefore) {
Jay Foada9203102011-07-25 09:48:08 +0000857 init(Ptr, IdxList, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +0000858}
Gabor Greifefe65362008-05-10 08:32:32 +0000859GetElementPtrInst::GetElementPtrInst(Value *Ptr,
Jay Foada9203102011-07-25 09:48:08 +0000860 ArrayRef<Value *> IdxList,
Gabor Greifefe65362008-05-10 08:32:32 +0000861 unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000862 const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +0000863 BasicBlock *InsertAtEnd)
Chris Lattner1afcace2011-07-09 17:41:24 +0000864 : Instruction(PointerType::get(checkGEPType(
Jay Foada9203102011-07-25 09:48:08 +0000865 getIndexedType(Ptr->getType(), IdxList)),
Gabor Greifefe65362008-05-10 08:32:32 +0000866 cast<PointerType>(Ptr->getType())
867 ->getAddressSpace()),
868 GetElementPtr,
869 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
870 Values, InsertAtEnd) {
Jay Foada9203102011-07-25 09:48:08 +0000871 init(Ptr, IdxList, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +0000872}
873
874
875DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
876
877
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000878//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000879// ICmpInst Class
880//===----------------------------------------------------------------------===//
881
882/// This instruction compares its operands according to the predicate given
Nate Begemanac80ade2008-05-12 19:01:56 +0000883/// to the constructor. It only operates on integers or pointers. The operands
884/// must be identical types.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000885/// @brief Represent an integer comparison operator.
886class ICmpInst: public CmpInst {
Devang Patel50b6e332009-10-27 22:16:29 +0000887protected:
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000888 /// @brief Clone an identical ICmpInst
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +0000889 virtual ICmpInst *clone_impl() const;
Reid Spencer45fb3f32006-11-20 01:22:35 +0000890public:
Reid Spencer45fb3f32006-11-20 01:22:35 +0000891 /// @brief Constructor with insert-before-instruction semantics.
892 ICmpInst(
Owen Anderson333c4002009-07-09 23:48:35 +0000893 Instruction *InsertBefore, ///< Where to insert
Reid Spencer45fb3f32006-11-20 01:22:35 +0000894 Predicate pred, ///< The predicate to use for the comparison
895 Value *LHS, ///< The left-hand-side of the expression
896 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000897 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +0000898 ) : CmpInst(makeCmpResultType(LHS->getType()),
Dan Gohmanf72fb672008-09-09 01:02:47 +0000899 Instruction::ICmp, pred, LHS, RHS, NameStr,
Nate Begemanac80ade2008-05-12 19:01:56 +0000900 InsertBefore) {
901 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
902 pred <= CmpInst::LAST_ICMP_PREDICATE &&
903 "Invalid ICmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000904 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000905 "Both operands to ICmp instruction are not of the same type!");
906 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +0000907 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
Duncan Sands1df98592010-02-16 11:11:14 +0000908 getOperand(0)->getType()->isPointerTy()) &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000909 "Invalid operand types for ICmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000910 }
911
Owen Anderson333c4002009-07-09 23:48:35 +0000912 /// @brief Constructor with insert-at-end semantics.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000913 ICmpInst(
Owen Anderson333c4002009-07-09 23:48:35 +0000914 BasicBlock &InsertAtEnd, ///< Block to insert into.
915 Predicate pred, ///< The predicate to use for the comparison
916 Value *LHS, ///< The left-hand-side of the expression
917 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000918 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +0000919 ) : CmpInst(makeCmpResultType(LHS->getType()),
Owen Anderson333c4002009-07-09 23:48:35 +0000920 Instruction::ICmp, pred, LHS, RHS, NameStr,
921 &InsertAtEnd) {
922 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
923 pred <= CmpInst::LAST_ICMP_PREDICATE &&
924 "Invalid ICmp predicate value");
925 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
926 "Both operands to ICmp instruction are not of the same type!");
927 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +0000928 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
Duncan Sands1df98592010-02-16 11:11:14 +0000929 getOperand(0)->getType()->isPointerTy()) &&
Owen Anderson333c4002009-07-09 23:48:35 +0000930 "Invalid operand types for ICmp instruction");
931 }
932
933 /// @brief Constructor with no-insertion semantics
934 ICmpInst(
Reid Spencer45fb3f32006-11-20 01:22:35 +0000935 Predicate pred, ///< The predicate to use for the comparison
936 Value *LHS, ///< The left-hand-side of the expression
937 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +0000938 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +0000939 ) : CmpInst(makeCmpResultType(LHS->getType()),
Owen Anderson333c4002009-07-09 23:48:35 +0000940 Instruction::ICmp, pred, LHS, RHS, NameStr) {
Nate Begemanac80ade2008-05-12 19:01:56 +0000941 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
942 pred <= CmpInst::LAST_ICMP_PREDICATE &&
943 "Invalid ICmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000944 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000945 "Both operands to ICmp instruction are not of the same type!");
946 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +0000947 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
Duncan Sands1df98592010-02-16 11:11:14 +0000948 getOperand(0)->getType()->isPointerTy()) &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000949 "Invalid operand types for ICmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000950 }
951
Reid Spencere4d87aa2006-12-23 06:05:41 +0000952 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
953 /// @returns the predicate that would be the result if the operand were
954 /// regarded as signed.
955 /// @brief Return the signed version of the predicate
956 Predicate getSignedPredicate() const {
957 return getSignedPredicate(getPredicate());
958 }
959
960 /// This is a static version that you can use without an instruction.
961 /// @brief Return the signed version of the predicate.
962 static Predicate getSignedPredicate(Predicate pred);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000963
Nick Lewycky4189a532008-01-28 03:48:02 +0000964 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
965 /// @returns the predicate that would be the result if the operand were
966 /// regarded as unsigned.
967 /// @brief Return the unsigned version of the predicate
968 Predicate getUnsignedPredicate() const {
969 return getUnsignedPredicate(getPredicate());
970 }
971
972 /// This is a static version that you can use without an instruction.
973 /// @brief Return the unsigned version of the predicate.
974 static Predicate getUnsignedPredicate(Predicate pred);
975
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000976 /// isEquality - Return true if this predicate is either EQ or NE. This also
977 /// tests for commutativity.
978 static bool isEquality(Predicate P) {
979 return P == ICMP_EQ || P == ICMP_NE;
980 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000981
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000982 /// isEquality - Return true if this predicate is either EQ or NE. This also
983 /// tests for commutativity.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000984 bool isEquality() const {
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000985 return isEquality(getPredicate());
Reid Spencer45fb3f32006-11-20 01:22:35 +0000986 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000987
988 /// @returns true if the predicate of this ICmpInst is commutative
989 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000990 bool isCommutative() const { return isEquality(); }
991
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000992 /// isRelational - Return true if the predicate is relational (not EQ or NE).
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000993 ///
Reid Spencer45fb3f32006-11-20 01:22:35 +0000994 bool isRelational() const {
995 return !isEquality();
996 }
997
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +0000998 /// isRelational - Return true if the predicate is relational (not EQ or NE).
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000999 ///
1000 static bool isRelational(Predicate P) {
1001 return !isEquality(P);
1002 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001003
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001004 /// Initialize a set of values that all satisfy the predicate with C.
Reid Spencer3da43842007-02-28 22:00:54 +00001005 /// @brief Make a ConstantRange for a relation with a constant value.
1006 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
1007
Reid Spencer45fb3f32006-11-20 01:22:35 +00001008 /// Exchange the two operands to this instruction in such a way that it does
1009 /// not modify the semantics of the instruction. The predicate value may be
1010 /// changed to retain the same result if the predicate is order dependent
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001011 /// (e.g. ult).
Reid Spencer45fb3f32006-11-20 01:22:35 +00001012 /// @brief Swap operands and adjust predicate.
1013 void swapOperands() {
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001014 setPredicate(getSwappedPredicate());
Gabor Greif94fb68b2008-05-13 22:51:52 +00001015 Op<0>().swap(Op<1>());
Reid Spencer45fb3f32006-11-20 01:22:35 +00001016 }
1017
1018 // Methods for support type inquiry through isa, cast, and dyn_cast:
1019 static inline bool classof(const ICmpInst *) { return true; }
1020 static inline bool classof(const Instruction *I) {
1021 return I->getOpcode() == Instruction::ICmp;
1022 }
1023 static inline bool classof(const Value *V) {
1024 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1025 }
Dan Gohmanf72fb672008-09-09 01:02:47 +00001026
Reid Spencer45fb3f32006-11-20 01:22:35 +00001027};
1028
1029//===----------------------------------------------------------------------===//
1030// FCmpInst Class
1031//===----------------------------------------------------------------------===//
1032
1033/// This instruction compares its operands according to the predicate given
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001034/// to the constructor. It only operates on floating point values or packed
Reid Spencer45fb3f32006-11-20 01:22:35 +00001035/// vectors of floating point values. The operands must be identical types.
1036/// @brief Represents a floating point comparison operator.
1037class FCmpInst: public CmpInst {
Devang Patel50b6e332009-10-27 22:16:29 +00001038protected:
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001039 /// @brief Clone an identical FCmpInst
Devang Patel50b6e332009-10-27 22:16:29 +00001040 virtual FCmpInst *clone_impl() const;
Reid Spencer45fb3f32006-11-20 01:22:35 +00001041public:
Reid Spencer45fb3f32006-11-20 01:22:35 +00001042 /// @brief Constructor with insert-before-instruction semantics.
1043 FCmpInst(
Owen Anderson333c4002009-07-09 23:48:35 +00001044 Instruction *InsertBefore, ///< Where to insert
Reid Spencer45fb3f32006-11-20 01:22:35 +00001045 Predicate pred, ///< The predicate to use for the comparison
1046 Value *LHS, ///< The left-hand-side of the expression
1047 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001048 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +00001049 ) : CmpInst(makeCmpResultType(LHS->getType()),
Dan Gohmanf72fb672008-09-09 01:02:47 +00001050 Instruction::FCmp, pred, LHS, RHS, NameStr,
Nate Begemanac80ade2008-05-12 19:01:56 +00001051 InsertBefore) {
1052 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1053 "Invalid FCmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +00001054 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +00001055 "Both operands to FCmp instruction are not of the same type!");
1056 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +00001057 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
Nate Begemanac80ade2008-05-12 19:01:56 +00001058 "Invalid operand types for FCmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +00001059 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001060
Owen Anderson333c4002009-07-09 23:48:35 +00001061 /// @brief Constructor with insert-at-end semantics.
Reid Spencer45fb3f32006-11-20 01:22:35 +00001062 FCmpInst(
Owen Anderson333c4002009-07-09 23:48:35 +00001063 BasicBlock &InsertAtEnd, ///< Block to insert into.
1064 Predicate pred, ///< The predicate to use for the comparison
1065 Value *LHS, ///< The left-hand-side of the expression
1066 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001067 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +00001068 ) : CmpInst(makeCmpResultType(LHS->getType()),
Owen Anderson333c4002009-07-09 23:48:35 +00001069 Instruction::FCmp, pred, LHS, RHS, NameStr,
1070 &InsertAtEnd) {
1071 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1072 "Invalid FCmp predicate value");
1073 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
1074 "Both operands to FCmp instruction are not of the same type!");
1075 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +00001076 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
Owen Anderson333c4002009-07-09 23:48:35 +00001077 "Invalid operand types for FCmp instruction");
1078 }
1079
1080 /// @brief Constructor with no-insertion semantics
1081 FCmpInst(
Reid Spencer45fb3f32006-11-20 01:22:35 +00001082 Predicate pred, ///< The predicate to use for the comparison
1083 Value *LHS, ///< The left-hand-side of the expression
1084 Value *RHS, ///< The right-hand-side of the expression
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001085 const Twine &NameStr = "" ///< Name of the instruction
Owen Andersondebcb012009-07-29 22:17:13 +00001086 ) : CmpInst(makeCmpResultType(LHS->getType()),
Owen Anderson333c4002009-07-09 23:48:35 +00001087 Instruction::FCmp, pred, LHS, RHS, NameStr) {
Nate Begemanac80ade2008-05-12 19:01:56 +00001088 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
1089 "Invalid FCmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +00001090 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +00001091 "Both operands to FCmp instruction are not of the same type!");
1092 // Check that the operands are the right type
Duncan Sandsb0bc6c32010-02-15 16:12:20 +00001093 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
Nate Begemanac80ade2008-05-12 19:01:56 +00001094 "Invalid operand types for FCmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +00001095 }
1096
Reid Spencer45fb3f32006-11-20 01:22:35 +00001097 /// @returns true if the predicate of this instruction is EQ or NE.
1098 /// @brief Determine if this is an equality predicate.
1099 bool isEquality() const {
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001100 return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
1101 getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
Reid Spencer45fb3f32006-11-20 01:22:35 +00001102 }
Dan Gohman793df072008-09-16 16:44:00 +00001103
1104 /// @returns true if the predicate of this instruction is commutative.
1105 /// @brief Determine if this is a commutative predicate.
1106 bool isCommutative() const {
1107 return isEquality() ||
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001108 getPredicate() == FCMP_FALSE ||
1109 getPredicate() == FCMP_TRUE ||
1110 getPredicate() == FCMP_ORD ||
1111 getPredicate() == FCMP_UNO;
Dan Gohman793df072008-09-16 16:44:00 +00001112 }
Reid Spencer45fb3f32006-11-20 01:22:35 +00001113
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001114 /// @returns true if the predicate is relational (not EQ or NE).
Reid Spencer45fb3f32006-11-20 01:22:35 +00001115 /// @brief Determine if this a relational predicate.
1116 bool isRelational() const { return !isEquality(); }
1117
1118 /// Exchange the two operands to this instruction in such a way that it does
1119 /// not modify the semantics of the instruction. The predicate value may be
1120 /// changed to retain the same result if the predicate is order dependent
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001121 /// (e.g. ult).
Reid Spencer45fb3f32006-11-20 01:22:35 +00001122 /// @brief Swap operands and adjust predicate.
1123 void swapOperands() {
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001124 setPredicate(getSwappedPredicate());
Gabor Greif94fb68b2008-05-13 22:51:52 +00001125 Op<0>().swap(Op<1>());
Reid Spencer45fb3f32006-11-20 01:22:35 +00001126 }
1127
1128 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1129 static inline bool classof(const FCmpInst *) { return true; }
1130 static inline bool classof(const Instruction *I) {
1131 return I->getOpcode() == Instruction::FCmp;
1132 }
1133 static inline bool classof(const Value *V) {
1134 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1135 }
1136};
1137
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001138//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001139/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +00001140/// machine's calling convention. This class uses low bit of the SubClassData
1141/// field to indicate whether or not this is a tail call. The rest of the bits
1142/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001143///
1144class CallInst : public Instruction {
Devang Patel05988662008-09-25 21:00:45 +00001145 AttrListPtr AttributeList; ///< parameter attributes for call
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001146 CallInst(const CallInst &CI);
Jay Foada3efbb12011-07-15 08:37:34 +00001147 void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
1148 void init(Value *Func, const Twine &NameStr);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001149
Jay Foada3efbb12011-07-15 08:37:34 +00001150 /// Construct a CallInst given a range of arguments.
David Greene52eec542007-08-01 03:43:44 +00001151 /// @brief Construct a CallInst from a range of arguments
Jay Foada3efbb12011-07-15 08:37:34 +00001152 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1153 const Twine &NameStr, Instruction *InsertBefore);
David Greene52eec542007-08-01 03:43:44 +00001154
Jay Foada3efbb12011-07-15 08:37:34 +00001155 /// Construct a CallInst given a range of arguments.
David Greene52eec542007-08-01 03:43:44 +00001156 /// @brief Construct a CallInst from a range of arguments
Jay Foada3efbb12011-07-15 08:37:34 +00001157 inline CallInst(Value *Func, ArrayRef<Value *> Args,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001158 const Twine &NameStr, BasicBlock *InsertAtEnd);
David Greene52eec542007-08-01 03:43:44 +00001159
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001160 CallInst(Value *F, Value *Actual, const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +00001161 Instruction *InsertBefore);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001162 CallInst(Value *F, Value *Actual, const Twine &NameStr,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001163 BasicBlock *InsertAtEnd);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001164 explicit CallInst(Value *F, const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +00001165 Instruction *InsertBefore);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001166 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00001167protected:
1168 virtual CallInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00001169public:
Gabor Greifefe65362008-05-10 08:32:32 +00001170 static CallInst *Create(Value *Func,
Jay Foada3efbb12011-07-15 08:37:34 +00001171 ArrayRef<Value *> Args,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001172 const Twine &NameStr = "",
Evan Chengd69bb1a2008-05-05 17:41:03 +00001173 Instruction *InsertBefore = 0) {
Jay Foada3efbb12011-07-15 08:37:34 +00001174 return new(unsigned(Args.size() + 1))
1175 CallInst(Func, Args, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001176 }
Gabor Greifefe65362008-05-10 08:32:32 +00001177 static CallInst *Create(Value *Func,
Jay Foada3efbb12011-07-15 08:37:34 +00001178 ArrayRef<Value *> Args,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001179 const Twine &NameStr, BasicBlock *InsertAtEnd) {
Jay Foada3efbb12011-07-15 08:37:34 +00001180 return new(unsigned(Args.size() + 1))
1181 CallInst(Func, Args, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001182 }
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001183 static CallInst *Create(Value *F, const Twine &NameStr = "",
Gabor Greif051a9502008-04-06 20:25:17 +00001184 Instruction *InsertBefore = 0) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001185 return new(1) CallInst(F, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001186 }
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001187 static CallInst *Create(Value *F, const Twine &NameStr,
Evan Cheng34cd4a42008-05-05 18:30:58 +00001188 BasicBlock *InsertAtEnd) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001189 return new(1) CallInst(F, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001190 }
Evan Chengfabcb912009-09-10 04:36:43 +00001191 /// CreateMalloc - Generate the IR for a call to malloc:
1192 /// 1. Compute the malloc call's argument as the specified type's size,
1193 /// possibly multiplied by the array size if the array size is not
1194 /// constant 1.
1195 /// 2. Call malloc with that argument.
1196 /// 3. Bitcast the result of the malloc call to the specified type.
Nick Lewycky3fc35c52009-10-17 23:52:26 +00001197 static Instruction *CreateMalloc(Instruction *InsertBefore,
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001198 Type *IntPtrTy, Type *AllocTy,
Victor Hernandez9d0b7042009-11-07 00:16:28 +00001199 Value *AllocSize, Value *ArraySize = 0,
Chris Lattner5a30a852010-07-12 00:57:28 +00001200 Function* MallocF = 0,
Nick Lewycky3fc35c52009-10-17 23:52:26 +00001201 const Twine &Name = "");
1202 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001203 Type *IntPtrTy, Type *AllocTy,
Victor Hernandez9d0b7042009-11-07 00:16:28 +00001204 Value *AllocSize, Value *ArraySize = 0,
1205 Function* MallocF = 0,
Nick Lewycky3fc35c52009-10-17 23:52:26 +00001206 const Twine &Name = "");
Victor Hernandez66284e02009-10-24 04:23:03 +00001207 /// CreateFree - Generate the IR for a call to the builtin free function.
Chris Lattner5a30a852010-07-12 00:57:28 +00001208 static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
Victor Hernandez66284e02009-10-24 04:23:03 +00001209 static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001210
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001211 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001212
Chris Lattnerb2406d92009-12-29 02:46:09 +00001213 bool isTailCall() const { return getSubclassDataFromInstruction() & 1; }
Evan Cheng1bf9a182008-07-24 00:08:56 +00001214 void setTailCall(bool isTC = true) {
Chris Lattnerb2406d92009-12-29 02:46:09 +00001215 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
1216 unsigned(isTC));
Chris Lattner3340ffe2005-05-06 20:26:26 +00001217 }
1218
Dan Gohmanf2752502008-09-26 21:38:45 +00001219 /// Provide fast operand accessors
1220 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001221
Gabor Greif0114b992010-07-31 08:35:21 +00001222 /// getNumArgOperands - Return the number of call arguments.
1223 ///
Bill Wendling22a5b292010-06-07 19:05:06 +00001224 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
Gabor Greif0114b992010-07-31 08:35:21 +00001225
1226 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1227 ///
Gabor Greifa6aac4c2010-07-16 09:38:02 +00001228 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1229 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
Bill Wendling22a5b292010-06-07 19:05:06 +00001230
Chris Lattner3340ffe2005-05-06 20:26:26 +00001231 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1232 /// function call.
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001233 CallingConv::ID getCallingConv() const {
Chris Lattnerb2406d92009-12-29 02:46:09 +00001234 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 1);
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00001235 }
1236 void setCallingConv(CallingConv::ID CC) {
Chris Lattnerb2406d92009-12-29 02:46:09 +00001237 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
1238 (static_cast<unsigned>(CC) << 1));
Chris Lattner3340ffe2005-05-06 20:26:26 +00001239 }
Chris Lattnerddb6db42005-05-06 05:51:46 +00001240
Devang Patel05988662008-09-25 21:00:45 +00001241 /// getAttributes - Return the parameter attributes for this call.
Chris Lattner041221c2008-03-13 04:33:03 +00001242 ///
Devang Patel05988662008-09-25 21:00:45 +00001243 const AttrListPtr &getAttributes() const { return AttributeList; }
Reid Spencer4746ecf2007-04-09 15:01:12 +00001244
Dan Gohmanf2752502008-09-26 21:38:45 +00001245 /// setAttributes - Set the parameter attributes for this call.
1246 ///
Devang Patel05988662008-09-25 21:00:45 +00001247 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001248
Devang Patel05988662008-09-25 21:00:45 +00001249 /// addAttribute - adds the attribute to the list of attributes.
1250 void addAttribute(unsigned i, Attributes attr);
Duncan Sandsdc024672007-11-27 13:23:08 +00001251
Devang Patel05988662008-09-25 21:00:45 +00001252 /// removeAttribute - removes the attribute from the list of attributes.
1253 void removeAttribute(unsigned i, Attributes attr);
Duncan Sands2e033f32008-07-08 08:38:44 +00001254
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001255 /// @brief Determine whether the call or the callee has the given attribute.
Dan Gohmanf2752502008-09-26 21:38:45 +00001256 bool paramHasAttr(unsigned i, Attributes attr) const;
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001257
Dale Johannesen08e78b12008-02-22 17:49:45 +00001258 /// @brief Extract the alignment for a call or parameter (0=unknown).
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001259 unsigned getParamAlignment(unsigned i) const {
Devang Patel05988662008-09-25 21:00:45 +00001260 return AttributeList.getParamAlignment(i);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001261 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001262
Eric Christopherf27e6082010-03-25 04:49:10 +00001263 /// @brief Return true if the call should not be inlined.
1264 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
Nick Lewyckyb9933b82010-07-06 03:53:22 +00001265 void setIsNoInline(bool Value = true) {
Eric Christopherf27e6082010-03-25 04:49:10 +00001266 if (Value) addAttribute(~0, Attribute::NoInline);
1267 else removeAttribute(~0, Attribute::NoInline);
1268 }
Dale Johannesen08e78b12008-02-22 17:49:45 +00001269
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001270 /// @brief Determine if the call does not access memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001271 bool doesNotAccessMemory() const {
Devang Patel19c87462008-09-26 22:53:05 +00001272 return paramHasAttr(~0, Attribute::ReadNone);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001273 }
Evan Cheng1bf9a182008-07-24 00:08:56 +00001274 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
Devang Patel19c87462008-09-26 22:53:05 +00001275 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
1276 else removeAttribute(~0, Attribute::ReadNone);
Duncan Sands2e033f32008-07-08 08:38:44 +00001277 }
1278
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001279 /// @brief Determine if the call does not access or only reads memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001280 bool onlyReadsMemory() const {
Devang Patel19c87462008-09-26 22:53:05 +00001281 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001282 }
Evan Cheng1bf9a182008-07-24 00:08:56 +00001283 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
Devang Patel19c87462008-09-26 22:53:05 +00001284 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
1285 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
Duncan Sands2e033f32008-07-08 08:38:44 +00001286 }
1287
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001288 /// @brief Determine if the call cannot return.
Nick Lewyckyb9933b82010-07-06 03:53:22 +00001289 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
Evan Cheng1bf9a182008-07-24 00:08:56 +00001290 void setDoesNotReturn(bool DoesNotReturn = true) {
Devang Patel19c87462008-09-26 22:53:05 +00001291 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
1292 else removeAttribute(~0, Attribute::NoReturn);
Duncan Sands2e033f32008-07-08 08:38:44 +00001293 }
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001294
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001295 /// @brief Determine if the call cannot unwind.
Nick Lewyckyb9933b82010-07-06 03:53:22 +00001296 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
Evan Cheng1bf9a182008-07-24 00:08:56 +00001297 void setDoesNotThrow(bool DoesNotThrow = true) {
Devang Patel19c87462008-09-26 22:53:05 +00001298 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
1299 else removeAttribute(~0, Attribute::NoUnwind);
Duncan Sands2e033f32008-07-08 08:38:44 +00001300 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001301
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001302 /// @brief Determine if the call returns a structure through first
Devang Patel41e23972008-03-03 21:46:28 +00001303 /// pointer argument.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001304 bool hasStructRetAttr() const {
1305 // Be friendly and also check the callee.
Devang Patel05988662008-09-25 21:00:45 +00001306 return paramHasAttr(1, Attribute::StructRet);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001307 }
Reid Spencer4746ecf2007-04-09 15:01:12 +00001308
Evan Chengf4a54982008-01-12 18:57:32 +00001309 /// @brief Determine if any call argument is an aggregate passed by value.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001310 bool hasByValArgument() const {
Devang Patel05988662008-09-25 21:00:45 +00001311 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001312 }
Evan Chengf4a54982008-01-12 18:57:32 +00001313
Dan Gohmanf2752502008-09-26 21:38:45 +00001314 /// getCalledFunction - Return the function called, or null if this is an
1315 /// indirect function invocation.
1316 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001317 Function *getCalledFunction() const {
Gabor Greifa6aac4c2010-07-16 09:38:02 +00001318 return dyn_cast<Function>(Op<-1>());
Chris Lattner721aef62004-11-18 17:46:57 +00001319 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001320
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001321 /// getCalledValue - Get a pointer to the function that is invoked by this
Chris Lattner14d80382009-10-18 05:08:07 +00001322 /// instruction.
Gabor Greifa6aac4c2010-07-16 09:38:02 +00001323 const Value *getCalledValue() const { return Op<-1>(); }
1324 Value *getCalledValue() { return Op<-1>(); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001325
Chris Lattner14d80382009-10-18 05:08:07 +00001326 /// setCalledFunction - Set the function called.
Victor Hernandez13ad5aa2009-10-17 00:00:19 +00001327 void setCalledFunction(Value* Fn) {
Gabor Greifa6aac4c2010-07-16 09:38:02 +00001328 Op<-1>() = Fn;
Victor Hernandez13ad5aa2009-10-17 00:00:19 +00001329 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001330
Owen Anderson6f615f82010-08-07 00:19:59 +00001331 /// isInlineAsm - Check if this call is an inline asm statement.
1332 bool isInlineAsm() const {
1333 return isa<InlineAsm>(Op<-1>());
1334 }
Victor Hernandez13ad5aa2009-10-17 00:00:19 +00001335
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001336 // Methods for support type inquiry through isa, cast, and dyn_cast:
1337 static inline bool classof(const CallInst *) { return true; }
1338 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001339 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001340 }
1341 static inline bool classof(const Value *V) {
1342 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1343 }
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001344private:
Chris Lattnerb2406d92009-12-29 02:46:09 +00001345 // Shadow Instruction::setInstructionSubclassData with a private forwarding
1346 // method so that subclasses cannot accidentally use it.
1347 void setInstructionSubclassData(unsigned short D) {
1348 Instruction::setInstructionSubclassData(D);
Chris Lattnercafe9bb2009-12-29 02:14:09 +00001349 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001350};
1351
Gabor Greifefe65362008-05-10 08:32:32 +00001352template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001353struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
Gabor Greifefe65362008-05-10 08:32:32 +00001354};
1355
Jay Foada3efbb12011-07-15 08:37:34 +00001356CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001357 const Twine &NameStr, BasicBlock *InsertAtEnd)
Gabor Greifefe65362008-05-10 08:32:32 +00001358 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1359 ->getElementType())->getReturnType(),
1360 Instruction::Call,
Jay Foada3efbb12011-07-15 08:37:34 +00001361 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1362 unsigned(Args.size() + 1), InsertAtEnd) {
1363 init(Func, Args, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +00001364}
1365
Jay Foada3efbb12011-07-15 08:37:34 +00001366CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001367 const Twine &NameStr, Instruction *InsertBefore)
Gabor Greifefe65362008-05-10 08:32:32 +00001368 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1369 ->getElementType())->getReturnType(),
1370 Instruction::Call,
Jay Foada3efbb12011-07-15 08:37:34 +00001371 OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
1372 unsigned(Args.size() + 1), InsertBefore) {
1373 init(Func, Args, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +00001374}
1375
Gabor Greife9e12152010-07-06 15:44:11 +00001376
1377// Note: if you get compile errors about private methods then
1378// please update your code to use the high-level operand
1379// interfaces. See line 943 above.
Gabor Greifefe65362008-05-10 08:32:32 +00001380DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1381
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001382//===----------------------------------------------------------------------===//
1383// SelectInst Class
1384//===----------------------------------------------------------------------===//
1385
1386/// SelectInst - This class represents the LLVM 'select' instruction.
1387///
1388class SelectInst : public Instruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001389 void init(Value *C, Value *S1, Value *S2) {
Chris Lattnerb76ec322008-12-29 00:12:50 +00001390 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
Gabor Greifefe65362008-05-10 08:32:32 +00001391 Op<0>() = C;
1392 Op<1>() = S1;
1393 Op<2>() = S2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001394 }
1395
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001396 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
Gabor Greifefe65362008-05-10 08:32:32 +00001397 Instruction *InsertBefore)
1398 : Instruction(S1->getType(), Instruction::Select,
1399 &Op<0>(), 3, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001400 init(C, S1, S2);
Evan Cheng1bf9a182008-07-24 00:08:56 +00001401 setName(NameStr);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001402 }
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001403 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001404 BasicBlock *InsertAtEnd)
Gabor Greifefe65362008-05-10 08:32:32 +00001405 : Instruction(S1->getType(), Instruction::Select,
1406 &Op<0>(), 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001407 init(C, S1, S2);
Evan Cheng1bf9a182008-07-24 00:08:56 +00001408 setName(NameStr);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001409 }
Devang Patel50b6e332009-10-27 22:16:29 +00001410protected:
1411 virtual SelectInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00001412public:
Evan Chengd69bb1a2008-05-05 17:41:03 +00001413 static SelectInst *Create(Value *C, Value *S1, Value *S2,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001414 const Twine &NameStr = "",
Evan Chengd69bb1a2008-05-05 17:41:03 +00001415 Instruction *InsertBefore = 0) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001416 return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001417 }
Evan Chengd69bb1a2008-05-05 17:41:03 +00001418 static SelectInst *Create(Value *C, Value *S1, Value *S2,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001419 const Twine &NameStr,
Evan Cheng1bf9a182008-07-24 00:08:56 +00001420 BasicBlock *InsertAtEnd) {
1421 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001422 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001423
Chris Lattner97159122009-09-08 03:32:53 +00001424 const Value *getCondition() const { return Op<0>(); }
1425 const Value *getTrueValue() const { return Op<1>(); }
1426 const Value *getFalseValue() const { return Op<2>(); }
1427 Value *getCondition() { return Op<0>(); }
1428 Value *getTrueValue() { return Op<1>(); }
1429 Value *getFalseValue() { return Op<2>(); }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001430
Chris Lattnerb76ec322008-12-29 00:12:50 +00001431 /// areInvalidOperands - Return a string if the specified operands are invalid
1432 /// for a select operation, otherwise return null.
1433 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
Chris Lattner454928e2005-01-29 00:31:36 +00001434
1435 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001436 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001437
1438 OtherOps getOpcode() const {
1439 return static_cast<OtherOps>(Instruction::getOpcode());
1440 }
1441
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001442 // Methods for support type inquiry through isa, cast, and dyn_cast:
1443 static inline bool classof(const SelectInst *) { return true; }
1444 static inline bool classof(const Instruction *I) {
1445 return I->getOpcode() == Instruction::Select;
1446 }
1447 static inline bool classof(const Value *V) {
1448 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1449 }
1450};
1451
Gabor Greifefe65362008-05-10 08:32:32 +00001452template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001453struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
Gabor Greifefe65362008-05-10 08:32:32 +00001454};
1455
1456DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1457
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001458//===----------------------------------------------------------------------===//
1459// VAArgInst Class
1460//===----------------------------------------------------------------------===//
1461
1462/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +00001463/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001464///
Chris Lattner454928e2005-01-29 00:31:36 +00001465class VAArgInst : public UnaryInstruction {
Devang Patel50b6e332009-10-27 22:16:29 +00001466protected:
1467 virtual VAArgInst *clone_impl() const;
1468
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001469public:
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001470 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001471 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001472 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001473 setName(NameStr);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001474 }
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001475 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001476 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001477 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001478 setName(NameStr);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001479 }
1480
Dan Gohmane7445412010-09-09 18:32:40 +00001481 Value *getPointerOperand() { return getOperand(0); }
1482 const Value *getPointerOperand() const { return getOperand(0); }
1483 static unsigned getPointerOperandIndex() { return 0U; }
1484
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001485 // Methods for support type inquiry through isa, cast, and dyn_cast:
1486 static inline bool classof(const VAArgInst *) { return true; }
1487 static inline bool classof(const Instruction *I) {
1488 return I->getOpcode() == VAArg;
1489 }
1490 static inline bool classof(const Value *V) {
1491 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1492 }
1493};
1494
1495//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +00001496// ExtractElementInst Class
1497//===----------------------------------------------------------------------===//
1498
1499/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001500/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +00001501///
1502class ExtractElementInst : public Instruction {
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001503 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
Chris Lattner9fc18d22006-04-08 01:15:18 +00001504 Instruction *InsertBefore = 0);
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001505 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
Chris Lattner9fc18d22006-04-08 01:15:18 +00001506 BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00001507protected:
1508 virtual ExtractElementInst *clone_impl() const;
1509
Eric Christophera3500da2009-07-25 02:28:41 +00001510public:
Eric Christophera3500da2009-07-25 02:28:41 +00001511 static ExtractElementInst *Create(Value *Vec, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001512 const Twine &NameStr = "",
Eric Christophera3500da2009-07-25 02:28:41 +00001513 Instruction *InsertBefore = 0) {
1514 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
1515 }
1516 static ExtractElementInst *Create(Value *Vec, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001517 const Twine &NameStr,
Eric Christophera3500da2009-07-25 02:28:41 +00001518 BasicBlock *InsertAtEnd) {
1519 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
1520 }
Robert Bocchino49b78a52006-01-10 19:04:13 +00001521
Chris Lattnerfa495842006-04-08 04:04:54 +00001522 /// isValidOperands - Return true if an extractelement instruction can be
1523 /// formed with the specified operands.
1524 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001525
Chris Lattner97159122009-09-08 03:32:53 +00001526 Value *getVectorOperand() { return Op<0>(); }
1527 Value *getIndexOperand() { return Op<1>(); }
1528 const Value *getVectorOperand() const { return Op<0>(); }
1529 const Value *getIndexOperand() const { return Op<1>(); }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001530
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001531 VectorType *getVectorOperandType() const {
1532 return reinterpret_cast<VectorType*>(getVectorOperand()->getType());
Chris Lattner97159122009-09-08 03:32:53 +00001533 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00001534
1535
Robert Bocchino49b78a52006-01-10 19:04:13 +00001536 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001537 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Robert Bocchino49b78a52006-01-10 19:04:13 +00001538
1539 // Methods for support type inquiry through isa, cast, and dyn_cast:
1540 static inline bool classof(const ExtractElementInst *) { return true; }
1541 static inline bool classof(const Instruction *I) {
1542 return I->getOpcode() == Instruction::ExtractElement;
1543 }
1544 static inline bool classof(const Value *V) {
1545 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1546 }
1547};
1548
Gabor Greifefe65362008-05-10 08:32:32 +00001549template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001550struct OperandTraits<ExtractElementInst> :
1551 public FixedNumOperandTraits<ExtractElementInst, 2> {
Gabor Greifefe65362008-05-10 08:32:32 +00001552};
1553
1554DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1555
Robert Bocchino49b78a52006-01-10 19:04:13 +00001556//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +00001557// InsertElementInst Class
1558//===----------------------------------------------------------------------===//
1559
1560/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001561/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +00001562///
1563class InsertElementInst : public Instruction {
Gabor Greif051a9502008-04-06 20:25:17 +00001564 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001565 const Twine &NameStr = "",
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001566 Instruction *InsertBefore = 0);
Gabor Greif051a9502008-04-06 20:25:17 +00001567 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001568 const Twine &NameStr, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00001569protected:
1570 virtual InsertElementInst *clone_impl() const;
1571
Robert Bocchinof9993442006-01-17 20:05:59 +00001572public:
Gabor Greif051a9502008-04-06 20:25:17 +00001573 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001574 const Twine &NameStr = "",
Gabor Greifefe65362008-05-10 08:32:32 +00001575 Instruction *InsertBefore = 0) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001576 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001577 }
Gabor Greif051a9502008-04-06 20:25:17 +00001578 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001579 const Twine &NameStr,
Evan Chengd69bb1a2008-05-05 17:41:03 +00001580 BasicBlock *InsertAtEnd) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001581 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001582 }
Robert Bocchinof9993442006-01-17 20:05:59 +00001583
Chris Lattnerfa495842006-04-08 04:04:54 +00001584 /// isValidOperands - Return true if an insertelement instruction can be
1585 /// formed with the specified operands.
1586 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1587 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001588
Reid Spencerac9dcb92007-02-15 03:39:18 +00001589 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001590 ///
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001591 VectorType *getType() const {
1592 return reinterpret_cast<VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001593 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001594
Robert Bocchinof9993442006-01-17 20:05:59 +00001595 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001596 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Robert Bocchinof9993442006-01-17 20:05:59 +00001597
1598 // Methods for support type inquiry through isa, cast, and dyn_cast:
1599 static inline bool classof(const InsertElementInst *) { return true; }
1600 static inline bool classof(const Instruction *I) {
1601 return I->getOpcode() == Instruction::InsertElement;
1602 }
1603 static inline bool classof(const Value *V) {
1604 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1605 }
1606};
1607
Gabor Greifefe65362008-05-10 08:32:32 +00001608template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001609struct OperandTraits<InsertElementInst> :
1610 public FixedNumOperandTraits<InsertElementInst, 3> {
Gabor Greifefe65362008-05-10 08:32:32 +00001611};
1612
1613DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1614
Robert Bocchinof9993442006-01-17 20:05:59 +00001615//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +00001616// ShuffleVectorInst Class
1617//===----------------------------------------------------------------------===//
1618
1619/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1620/// input vectors.
1621///
1622class ShuffleVectorInst : public Instruction {
Devang Patel50b6e332009-10-27 22:16:29 +00001623protected:
1624 virtual ShuffleVectorInst *clone_impl() const;
1625
Chris Lattner9fc18d22006-04-08 01:15:18 +00001626public:
Gabor Greif051a9502008-04-06 20:25:17 +00001627 // allocate space for exactly three operands
1628 void *operator new(size_t s) {
1629 return User::operator new(s, 3);
1630 }
Chris Lattner9fc18d22006-04-08 01:15:18 +00001631 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001632 const Twine &NameStr = "",
Evan Cheng1bf9a182008-07-24 00:08:56 +00001633 Instruction *InsertBefor = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001634 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001635 const Twine &NameStr, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001636
Chris Lattnerfa495842006-04-08 04:04:54 +00001637 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +00001638 /// formed with the specified operands.
1639 static bool isValidOperands(const Value *V1, const Value *V2,
1640 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001641
Reid Spencerac9dcb92007-02-15 03:39:18 +00001642 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001643 ///
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001644 VectorType *getType() const {
1645 return reinterpret_cast<VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001646 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001647
Chris Lattner9fc18d22006-04-08 01:15:18 +00001648 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001649 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001650
Chris Lattner8728f192008-03-02 05:28:33 +00001651 /// getMaskValue - Return the index from the shuffle mask for the specified
1652 /// output result. This is either -1 if the element is undef or a number less
1653 /// than 2*numelements.
1654 int getMaskValue(unsigned i) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001655
Chris Lattner9fc18d22006-04-08 01:15:18 +00001656 // Methods for support type inquiry through isa, cast, and dyn_cast:
1657 static inline bool classof(const ShuffleVectorInst *) { return true; }
1658 static inline bool classof(const Instruction *I) {
1659 return I->getOpcode() == Instruction::ShuffleVector;
1660 }
1661 static inline bool classof(const Value *V) {
1662 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1663 }
1664};
1665
Gabor Greifefe65362008-05-10 08:32:32 +00001666template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001667struct OperandTraits<ShuffleVectorInst> :
1668 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
Gabor Greifefe65362008-05-10 08:32:32 +00001669};
1670
1671DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
Chris Lattner9fc18d22006-04-08 01:15:18 +00001672
1673//===----------------------------------------------------------------------===//
Dan Gohman041e2eb2008-05-15 19:50:34 +00001674// ExtractValueInst Class
1675//===----------------------------------------------------------------------===//
1676
Dan Gohmane2d896f2008-05-15 23:35:32 +00001677/// ExtractValueInst - This instruction extracts a struct member or array
1678/// element value from an aggregate value.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001679///
Gabor Greifd4f268b2008-06-06 20:28:12 +00001680class ExtractValueInst : public UnaryInstruction {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001681 SmallVector<unsigned, 4> Indices;
1682
Dan Gohman041e2eb2008-05-15 19:50:34 +00001683 ExtractValueInst(const ExtractValueInst &EVI);
Jay Foadfc6d3a42011-07-13 10:26:04 +00001684 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001685
Dan Gohmane2d896f2008-05-15 23:35:32 +00001686 /// Constructors - Create a extractvalue instruction with a base aggregate
1687 /// value and a list of indices. The first ctor can optionally insert before
1688 /// an existing instruction, the second appends the new instruction to the
1689 /// specified BasicBlock.
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +00001690 inline ExtractValueInst(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001691 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001692 const Twine &NameStr,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001693 Instruction *InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001694 inline ExtractValueInst(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001695 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001696 const Twine &NameStr, BasicBlock *InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001697
Dan Gohman8e640412008-05-31 19:09:47 +00001698 // allocate space for exactly one operand
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001699 void *operator new(size_t s) {
1700 return User::operator new(s, 1);
1701 }
Devang Patel50b6e332009-10-27 22:16:29 +00001702protected:
1703 virtual ExtractValueInst *clone_impl() const;
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001704
Gabor Greifd4f268b2008-06-06 20:28:12 +00001705public:
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +00001706 static ExtractValueInst *Create(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001707 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001708 const Twine &NameStr = "",
Dan Gohman041e2eb2008-05-15 19:50:34 +00001709 Instruction *InsertBefore = 0) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001710 return new
Jay Foadfc6d3a42011-07-13 10:26:04 +00001711 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001712 }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001713 static ExtractValueInst *Create(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001714 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001715 const Twine &NameStr,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001716 BasicBlock *InsertAtEnd) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001717 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001718 }
1719
Dan Gohman041e2eb2008-05-15 19:50:34 +00001720 /// getIndexedType - Returns the type of the element that would be extracted
1721 /// with an extractvalue instruction with the specified parameters.
1722 ///
Frits van Bommelaf72c622010-12-03 14:54:33 +00001723 /// Null is returned if the indices are invalid for the specified type.
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001724 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001725
Owen Anderson5678d6e2008-06-19 17:15:57 +00001726 typedef const unsigned* idx_iterator;
1727 inline idx_iterator idx_begin() const { return Indices.begin(); }
1728 inline idx_iterator idx_end() const { return Indices.end(); }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001729
1730 Value *getAggregateOperand() {
1731 return getOperand(0);
1732 }
1733 const Value *getAggregateOperand() const {
1734 return getOperand(0);
1735 }
1736 static unsigned getAggregateOperandIndex() {
1737 return 0U; // get index for modifying correct operand
1738 }
1739
Jay Foadfc6d3a42011-07-13 10:26:04 +00001740 ArrayRef<unsigned> getIndices() const {
1741 return Indices;
1742 }
1743
1744 unsigned getNumIndices() const {
Bill Wendling67944fc2008-06-05 07:35:27 +00001745 return (unsigned)Indices.size();
Dan Gohman041e2eb2008-05-15 19:50:34 +00001746 }
1747
1748 bool hasIndices() const {
Dan Gohman35651cd2008-05-31 19:09:08 +00001749 return true;
Dan Gohman041e2eb2008-05-15 19:50:34 +00001750 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001751
Dan Gohman041e2eb2008-05-15 19:50:34 +00001752 // Methods for support type inquiry through isa, cast, and dyn_cast:
1753 static inline bool classof(const ExtractValueInst *) { return true; }
1754 static inline bool classof(const Instruction *I) {
1755 return I->getOpcode() == Instruction::ExtractValue;
1756 }
1757 static inline bool classof(const Value *V) {
1758 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1759 }
1760};
1761
Dan Gohmane4569942008-05-23 00:36:11 +00001762ExtractValueInst::ExtractValueInst(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001763 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001764 const Twine &NameStr,
Dan Gohmane4569942008-05-23 00:36:11 +00001765 Instruction *InsertBefore)
Jay Foadfc6d3a42011-07-13 10:26:04 +00001766 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
Bill Wendling85f40542008-07-22 07:14:12 +00001767 ExtractValue, Agg, InsertBefore) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001768 init(Idxs, NameStr);
Dan Gohmane4569942008-05-23 00:36:11 +00001769}
Dan Gohmane4569942008-05-23 00:36:11 +00001770ExtractValueInst::ExtractValueInst(Value *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001771 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001772 const Twine &NameStr,
Dan Gohmane4569942008-05-23 00:36:11 +00001773 BasicBlock *InsertAtEnd)
Jay Foadfc6d3a42011-07-13 10:26:04 +00001774 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
Bill Wendling85f40542008-07-22 07:14:12 +00001775 ExtractValue, Agg, InsertAtEnd) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001776 init(Idxs, NameStr);
Dan Gohmane4569942008-05-23 00:36:11 +00001777}
1778
Dan Gohmane4569942008-05-23 00:36:11 +00001779
Dan Gohman041e2eb2008-05-15 19:50:34 +00001780//===----------------------------------------------------------------------===//
1781// InsertValueInst Class
1782//===----------------------------------------------------------------------===//
1783
Dan Gohmane2d896f2008-05-15 23:35:32 +00001784/// InsertValueInst - This instruction inserts a struct field of array element
1785/// value into an aggregate value.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001786///
1787class InsertValueInst : public Instruction {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001788 SmallVector<unsigned, 4> Indices;
1789
1790 void *operator new(size_t, unsigned); // Do not implement
Dan Gohman041e2eb2008-05-15 19:50:34 +00001791 InsertValueInst(const InsertValueInst &IVI);
Jay Foadfc6d3a42011-07-13 10:26:04 +00001792 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001793 const Twine &NameStr);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001794
Dan Gohmane2d896f2008-05-15 23:35:32 +00001795 /// Constructors - Create a insertvalue instruction with a base aggregate
1796 /// value, a value to insert, and a list of indices. The first ctor can
1797 /// optionally insert before an existing instruction, the second appends
1798 /// the new instruction to the specified BasicBlock.
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +00001799 inline InsertValueInst(Value *Agg, Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001800 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001801 const Twine &NameStr,
Dan Gohmane2d896f2008-05-15 23:35:32 +00001802 Instruction *InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001803 inline InsertValueInst(Value *Agg, Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001804 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001805 const Twine &NameStr, BasicBlock *InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001806
1807 /// Constructors - These two constructors are convenience methods because one
1808 /// and two index insertvalue instructions are so common.
1809 InsertValueInst(Value *Agg, Value *Val,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001810 unsigned Idx, const Twine &NameStr = "",
Dan Gohman041e2eb2008-05-15 19:50:34 +00001811 Instruction *InsertBefore = 0);
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001812 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001813 const Twine &NameStr, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00001814protected:
1815 virtual InsertValueInst *clone_impl() const;
Dan Gohman041e2eb2008-05-15 19:50:34 +00001816public:
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001817 // allocate space for exactly two operands
1818 void *operator new(size_t s) {
1819 return User::operator new(s, 2);
1820 }
1821
Mikhail Glushenkovd33b77b2010-10-27 07:39:54 +00001822 static InsertValueInst *Create(Value *Agg, Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001823 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001824 const Twine &NameStr = "",
Dan Gohman041e2eb2008-05-15 19:50:34 +00001825 Instruction *InsertBefore = 0) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001826 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001827 }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001828 static InsertValueInst *Create(Value *Agg, Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001829 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001830 const Twine &NameStr,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001831 BasicBlock *InsertAtEnd) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001832 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001833 }
1834
Dan Gohman041e2eb2008-05-15 19:50:34 +00001835 /// Transparently provide more efficient getOperand methods.
1836 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1837
Owen Anderson5678d6e2008-06-19 17:15:57 +00001838 typedef const unsigned* idx_iterator;
1839 inline idx_iterator idx_begin() const { return Indices.begin(); }
1840 inline idx_iterator idx_end() const { return Indices.end(); }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001841
1842 Value *getAggregateOperand() {
1843 return getOperand(0);
1844 }
1845 const Value *getAggregateOperand() const {
1846 return getOperand(0);
1847 }
1848 static unsigned getAggregateOperandIndex() {
1849 return 0U; // get index for modifying correct operand
1850 }
1851
1852 Value *getInsertedValueOperand() {
1853 return getOperand(1);
1854 }
1855 const Value *getInsertedValueOperand() const {
1856 return getOperand(1);
1857 }
1858 static unsigned getInsertedValueOperandIndex() {
1859 return 1U; // get index for modifying correct operand
1860 }
1861
Jay Foadfc6d3a42011-07-13 10:26:04 +00001862 ArrayRef<unsigned> getIndices() const {
1863 return Indices;
1864 }
1865
1866 unsigned getNumIndices() const {
Bill Wendling67944fc2008-06-05 07:35:27 +00001867 return (unsigned)Indices.size();
Dan Gohman041e2eb2008-05-15 19:50:34 +00001868 }
1869
1870 bool hasIndices() const {
Dan Gohman35651cd2008-05-31 19:09:08 +00001871 return true;
Dan Gohman041e2eb2008-05-15 19:50:34 +00001872 }
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00001873
Dan Gohman041e2eb2008-05-15 19:50:34 +00001874 // Methods for support type inquiry through isa, cast, and dyn_cast:
1875 static inline bool classof(const InsertValueInst *) { return true; }
1876 static inline bool classof(const Instruction *I) {
1877 return I->getOpcode() == Instruction::InsertValue;
1878 }
1879 static inline bool classof(const Value *V) {
1880 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1881 }
1882};
1883
1884template <>
Jay Foad67c619b2011-01-11 15:07:38 +00001885struct OperandTraits<InsertValueInst> :
1886 public FixedNumOperandTraits<InsertValueInst, 2> {
Dan Gohman041e2eb2008-05-15 19:50:34 +00001887};
1888
Dan Gohmane4569942008-05-23 00:36:11 +00001889InsertValueInst::InsertValueInst(Value *Agg,
1890 Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001891 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001892 const Twine &NameStr,
Dan Gohmane4569942008-05-23 00:36:11 +00001893 Instruction *InsertBefore)
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001894 : Instruction(Agg->getType(), InsertValue,
1895 OperandTraits<InsertValueInst>::op_begin(this),
1896 2, InsertBefore) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001897 init(Agg, Val, Idxs, NameStr);
Dan Gohmane4569942008-05-23 00:36:11 +00001898}
Dan Gohmane4569942008-05-23 00:36:11 +00001899InsertValueInst::InsertValueInst(Value *Agg,
1900 Value *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +00001901 ArrayRef<unsigned> Idxs,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00001902 const Twine &NameStr,
Dan Gohmane4569942008-05-23 00:36:11 +00001903 BasicBlock *InsertAtEnd)
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001904 : Instruction(Agg->getType(), InsertValue,
1905 OperandTraits<InsertValueInst>::op_begin(this),
1906 2, InsertAtEnd) {
Jay Foadfc6d3a42011-07-13 10:26:04 +00001907 init(Agg, Val, Idxs, NameStr);
Dan Gohmane4569942008-05-23 00:36:11 +00001908}
1909
Dan Gohman041e2eb2008-05-15 19:50:34 +00001910DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1911
1912//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001913// PHINode Class
1914//===----------------------------------------------------------------------===//
1915
1916// PHINode - The PHINode class is used to represent the magical mystical PHI
1917// node, that can not exist in nature, but can be synthesized in a computer
1918// scientist's overactive imagination.
1919//
1920class PHINode : public Instruction {
Gabor Greif051a9502008-04-06 20:25:17 +00001921 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner454928e2005-01-29 00:31:36 +00001922 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1923 /// the number actually in use.
1924 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001925 PHINode(const PHINode &PN);
Gabor Greif051a9502008-04-06 20:25:17 +00001926 // allocate space for exactly zero operands
1927 void *operator new(size_t s) {
1928 return User::operator new(s, 0);
1929 }
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001930 explicit PHINode(Type *Ty, unsigned NumReservedValues,
Jay Foad3ecfc862011-03-30 11:28:46 +00001931 const Twine &NameStr = "", Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001932 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Jay Foad95c3e482011-06-23 09:09:15 +00001933 ReservedSpace(NumReservedValues) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001934 setName(NameStr);
Jay Foad3ecfc862011-03-30 11:28:46 +00001935 OperandList = allocHungoffUses(ReservedSpace);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001936 }
1937
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001938 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
Jay Foad3ecfc862011-03-30 11:28:46 +00001939 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001940 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Jay Foad95c3e482011-06-23 09:09:15 +00001941 ReservedSpace(NumReservedValues) {
Evan Cheng1bf9a182008-07-24 00:08:56 +00001942 setName(NameStr);
Jay Foad3ecfc862011-03-30 11:28:46 +00001943 OperandList = allocHungoffUses(ReservedSpace);
Chris Lattner454928e2005-01-29 00:31:36 +00001944 }
Devang Patel50b6e332009-10-27 22:16:29 +00001945protected:
Jay Foad95c3e482011-06-23 09:09:15 +00001946 // allocHungoffUses - this is more complicated than the generic
1947 // User::allocHungoffUses, because we have to allocate Uses for the incoming
1948 // values and pointers to the incoming blocks, all in one allocation.
1949 Use *allocHungoffUses(unsigned) const;
1950
Devang Patel50b6e332009-10-27 22:16:29 +00001951 virtual PHINode *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00001952public:
Jay Foad44991762011-03-30 13:29:06 +00001953 /// Constructors - NumReservedValues is a hint for the number of incoming
1954 /// edges that this phi node will have (use 0 if you really have no idea).
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001955 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
Jay Foad3ecfc862011-03-30 11:28:46 +00001956 const Twine &NameStr = "",
Gabor Greif051a9502008-04-06 20:25:17 +00001957 Instruction *InsertBefore = 0) {
Jay Foad3ecfc862011-03-30 11:28:46 +00001958 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001959 }
Chris Lattnerdb125cf2011-07-18 04:54:35 +00001960 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
Jay Foad3ecfc862011-03-30 11:28:46 +00001961 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1962 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001963 }
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001964 ~PHINode();
1965
Gabor Greifefe65362008-05-10 08:32:32 +00001966 /// Provide fast operand accessors
1967 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1968
Jay Foad95c3e482011-06-23 09:09:15 +00001969 // Block iterator interface. This provides access to the list of incoming
1970 // basic blocks, which parallels the list of incoming values.
1971
1972 typedef BasicBlock **block_iterator;
1973 typedef BasicBlock * const *const_block_iterator;
1974
1975 block_iterator block_begin() {
1976 Use::UserRef *ref =
1977 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
1978 return reinterpret_cast<block_iterator>(ref + 1);
1979 }
1980
1981 const_block_iterator block_begin() const {
1982 const Use::UserRef *ref =
1983 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
1984 return reinterpret_cast<const_block_iterator>(ref + 1);
1985 }
1986
1987 block_iterator block_end() {
1988 return block_begin() + getNumOperands();
1989 }
1990
1991 const_block_iterator block_end() const {
1992 return block_begin() + getNumOperands();
1993 }
1994
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001995 /// getNumIncomingValues - Return the number of incoming edges
1996 ///
Jay Foad95c3e482011-06-23 09:09:15 +00001997 unsigned getNumIncomingValues() const { return getNumOperands(); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001998
Reid Spencerc773de62006-05-19 19:07:54 +00001999 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002000 ///
2001 Value *getIncomingValue(unsigned i) const {
Jay Foad95c3e482011-06-23 09:09:15 +00002002 return getOperand(i);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002003 }
2004 void setIncomingValue(unsigned i, Value *V) {
Jay Foad95c3e482011-06-23 09:09:15 +00002005 setOperand(i, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002006 }
Dan Gohmanb45088c2009-03-23 15:48:29 +00002007 static unsigned getOperandNumForIncomingValue(unsigned i) {
Jay Foad95c3e482011-06-23 09:09:15 +00002008 return i;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002009 }
Dan Gohmanb45088c2009-03-23 15:48:29 +00002010 static unsigned getIncomingValueNumForOperand(unsigned i) {
Jay Foad95c3e482011-06-23 09:09:15 +00002011 return i;
Dan Gohmanb45088c2009-03-23 15:48:29 +00002012 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002013
Dan Gohmanfb76fe02010-02-22 04:10:52 +00002014 /// getIncomingBlock - Return incoming basic block number @p i.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002015 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00002016 BasicBlock *getIncomingBlock(unsigned i) const {
Jay Foad95c3e482011-06-23 09:09:15 +00002017 return block_begin()[i];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002018 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002019
Chris Lattnerceaa4572009-10-10 07:42:42 +00002020 /// getIncomingBlock - Return incoming basic block corresponding
2021 /// to an operand of the PHI.
2022 ///
2023 BasicBlock *getIncomingBlock(const Use &U) const {
2024 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
Jay Foad95c3e482011-06-23 09:09:15 +00002025 return getIncomingBlock(unsigned(&U - op_begin()));
Chris Lattnerceaa4572009-10-10 07:42:42 +00002026 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002027
Chris Lattnerceaa4572009-10-10 07:42:42 +00002028 /// getIncomingBlock - Return incoming basic block corresponding
2029 /// to value use iterator.
2030 ///
2031 template <typename U>
2032 BasicBlock *getIncomingBlock(value_use_iterator<U> I) const {
2033 return getIncomingBlock(I.getUse());
2034 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002035
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002036 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Jay Foad95c3e482011-06-23 09:09:15 +00002037 block_begin()[i] = BB;
Dan Gohmanb45088c2009-03-23 15:48:29 +00002038 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002039
2040 /// addIncoming - Add an incoming value to the end of the PHI list
2041 ///
2042 void addIncoming(Value *V, BasicBlock *BB) {
Anton Korobeynikov351b0d42008-02-27 22:37:28 +00002043 assert(V && "PHI node got a null value!");
2044 assert(BB && "PHI node got a null basic block!");
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002045 assert(getType() == V->getType() &&
2046 "All operands to PHI node must be the same type as the PHI node!");
Jay Foad95c3e482011-06-23 09:09:15 +00002047 if (NumOperands == ReservedSpace)
Jay Foad8891ed72011-04-01 08:00:58 +00002048 growOperands(); // Get more space!
Chris Lattner454928e2005-01-29 00:31:36 +00002049 // Initialize some new operands.
Jay Foad95c3e482011-06-23 09:09:15 +00002050 ++NumOperands;
2051 setIncomingValue(NumOperands - 1, V);
2052 setIncomingBlock(NumOperands - 1, BB);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002053 }
Misha Brukman9769ab22005-04-21 20:19:05 +00002054
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002055 /// removeIncomingValue - Remove an incoming value. This is useful if a
2056 /// predecessor basic block is deleted. The value removed is returned.
2057 ///
2058 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2059 /// is true), the PHI node is destroyed and any uses of it are replaced with
2060 /// dummy values. The only time there should be zero incoming values to a PHI
2061 /// node is when the block is dead, so this strategy is sound.
2062 ///
2063 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2064
Gabor Greifefe65362008-05-10 08:32:32 +00002065 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002066 int Idx = getBasicBlockIndex(BB);
2067 assert(Idx >= 0 && "Invalid basic block argument to remove!");
2068 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2069 }
2070
Misha Brukman9769ab22005-04-21 20:19:05 +00002071 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002072 /// block in the value list for this PHI. Returns -1 if no instance.
2073 ///
2074 int getBasicBlockIndex(const BasicBlock *BB) const {
Jay Foad95c3e482011-06-23 09:09:15 +00002075 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2076 if (block_begin()[i] == BB)
2077 return i;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002078 return -1;
2079 }
2080
2081 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
Jay Foad95c3e482011-06-23 09:09:15 +00002082 int Idx = getBasicBlockIndex(BB);
2083 assert(Idx >= 0 && "Invalid basic block argument!");
2084 return getIncomingValue(Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002085 }
2086
Chris Lattnerf56a8db2006-10-03 17:09:12 +00002087 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00002088 /// same value, return the value, otherwise return null.
Duncan Sandsff103412010-11-17 04:30:22 +00002089 Value *hasConstantValue() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00002090
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002091 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2092 static inline bool classof(const PHINode *) { return true; }
2093 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00002094 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002095 }
2096 static inline bool classof(const Value *V) {
2097 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2098 }
Chris Lattner454928e2005-01-29 00:31:36 +00002099 private:
Jay Foad8891ed72011-04-01 08:00:58 +00002100 void growOperands();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002101};
2102
Gabor Greifefe65362008-05-10 08:32:32 +00002103template <>
Duncan Sands59bf4fc2009-09-06 08:55:57 +00002104struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
Gabor Greifefe65362008-05-10 08:32:32 +00002105};
2106
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002107DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
Gabor Greifefe65362008-05-10 08:32:32 +00002108
2109
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002110//===----------------------------------------------------------------------===//
2111// ReturnInst Class
2112//===----------------------------------------------------------------------===//
2113
2114//===---------------------------------------------------------------------------
2115/// ReturnInst - Return a value (possibly void), from a function. Execution
2116/// does not continue in this function any longer.
2117///
2118class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00002119 ReturnInst(const ReturnInst &RI);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002120
Gabor Greif051a9502008-04-06 20:25:17 +00002121private:
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002122 // ReturnInst constructors:
2123 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00002124 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002125 // ReturnInst(Value* X) - 'ret X' instruction
Gabor Greifefe65362008-05-10 08:32:32 +00002126 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002127 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
Gabor Greifefe65362008-05-10 08:32:32 +00002128 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2129 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00002130 //
2131 // NOTE: If the Value* passed is of type void then the constructor behaves as
2132 // if it was passed NULL.
Owen Anderson1d0be152009-08-13 21:58:54 +00002133 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2134 Instruction *InsertBefore = 0);
2135 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2136 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00002137protected:
2138 virtual ReturnInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00002139public:
Owen Anderson1d0be152009-08-13 21:58:54 +00002140 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2141 Instruction *InsertBefore = 0) {
2142 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002143 }
Owen Anderson1d0be152009-08-13 21:58:54 +00002144 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2145 BasicBlock *InsertAtEnd) {
2146 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002147 }
Owen Anderson1d0be152009-08-13 21:58:54 +00002148 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2149 return new(0) ReturnInst(C, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002150 }
Devang Patel57ef4f42008-02-23 00:35:18 +00002151 virtual ~ReturnInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002152
Gabor Greifefe65362008-05-10 08:32:32 +00002153 /// Provide fast operand accessors
2154 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Devang Patel64d4e612008-02-26 17:56:20 +00002155
Dan Gohman8faa6af2010-10-06 16:59:24 +00002156 /// Convenience accessor. Returns null if there is no return value.
2157 Value *getReturnValue() const {
2158 return getNumOperands() != 0 ? getOperand(0) : 0;
Devang Patel1eafa062008-03-11 17:35:03 +00002159 }
2160
Chris Lattner454928e2005-01-29 00:31:36 +00002161 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002162
2163 // Methods for support type inquiry through isa, cast, and dyn_cast:
2164 static inline bool classof(const ReturnInst *) { return true; }
2165 static inline bool classof(const Instruction *I) {
2166 return (I->getOpcode() == Instruction::Ret);
2167 }
2168 static inline bool classof(const Value *V) {
2169 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2170 }
Chris Lattner454928e2005-01-29 00:31:36 +00002171 private:
2172 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2173 virtual unsigned getNumSuccessorsV() const;
2174 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002175};
2176
Gabor Greifefe65362008-05-10 08:32:32 +00002177template <>
Jay Foad67c619b2011-01-11 15:07:38 +00002178struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
Gabor Greifefe65362008-05-10 08:32:32 +00002179};
2180
2181DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
Gabor Greifefe65362008-05-10 08:32:32 +00002182
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002183//===----------------------------------------------------------------------===//
2184// BranchInst Class
2185//===----------------------------------------------------------------------===//
2186
2187//===---------------------------------------------------------------------------
2188/// BranchInst - Conditional or Unconditional Branch instruction.
2189///
2190class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00002191 /// Ops list - Branches are strange. The operands are ordered:
Gabor Greifae5a20a2009-03-12 18:34:49 +00002192 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
2193 /// they don't have to check for cond/uncond branchness. These are mostly
2194 /// accessed relative from op_end().
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002195 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00002196 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002197 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2198 // BranchInst(BB *B) - 'br B'
2199 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2200 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2201 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2202 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2203 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00002204 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002205 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00002206 Instruction *InsertBefore = 0);
2207 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002208 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00002209 BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00002210protected:
2211 virtual BranchInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00002212public:
2213 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
Jay Foad8e3914d2011-01-07 20:29:02 +00002214 return new(1) BranchInst(IfTrue, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002215 }
Gabor Greifefe65362008-05-10 08:32:32 +00002216 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2217 Value *Cond, Instruction *InsertBefore = 0) {
Gabor Greif051a9502008-04-06 20:25:17 +00002218 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2219 }
2220 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
Jay Foad8e3914d2011-01-07 20:29:02 +00002221 return new(1) BranchInst(IfTrue, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002222 }
Gabor Greifefe65362008-05-10 08:32:32 +00002223 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2224 Value *Cond, BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00002225 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2226 }
Chris Lattner454928e2005-01-29 00:31:36 +00002227
2228 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00002229 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002230
Devang Patel4d4a5e02008-02-23 01:11:02 +00002231 bool isUnconditional() const { return getNumOperands() == 1; }
2232 bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002233
Devang Patel4d4a5e02008-02-23 01:11:02 +00002234 Value *getCondition() const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002235 assert(isConditional() && "Cannot get condition of an uncond branch!");
Gabor Greifae5a20a2009-03-12 18:34:49 +00002236 return Op<-3>();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002237 }
2238
2239 void setCondition(Value *V) {
2240 assert(isConditional() && "Cannot set condition of unconditional branch!");
Gabor Greifae5a20a2009-03-12 18:34:49 +00002241 Op<-3>() = V;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002242 }
2243
Chris Lattner454928e2005-01-29 00:31:36 +00002244 unsigned getNumSuccessors() const { return 1+isConditional(); }
2245
2246 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002247 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Gabor Greifae5a20a2009-03-12 18:34:49 +00002248 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002249 }
2250
Chris Lattner454928e2005-01-29 00:31:36 +00002251 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002252 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner4b122932009-10-27 16:49:53 +00002253 *(&Op<-1>() - idx) = (Value*)NewSucc;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002254 }
2255
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002256 // Methods for support type inquiry through isa, cast, and dyn_cast:
2257 static inline bool classof(const BranchInst *) { return true; }
2258 static inline bool classof(const Instruction *I) {
2259 return (I->getOpcode() == Instruction::Br);
2260 }
2261 static inline bool classof(const Value *V) {
2262 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2263 }
Chris Lattner454928e2005-01-29 00:31:36 +00002264private:
2265 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2266 virtual unsigned getNumSuccessorsV() const;
2267 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002268};
2269
Gabor Greifefe65362008-05-10 08:32:32 +00002270template <>
Jay Foad67c619b2011-01-11 15:07:38 +00002271struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
2272};
Gabor Greifefe65362008-05-10 08:32:32 +00002273
2274DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2275
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002276//===----------------------------------------------------------------------===//
2277// SwitchInst Class
2278//===----------------------------------------------------------------------===//
2279
2280//===---------------------------------------------------------------------------
2281/// SwitchInst - Multiway switch
2282///
2283class SwitchInst : public TerminatorInst {
Gabor Greifefe65362008-05-10 08:32:32 +00002284 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner454928e2005-01-29 00:31:36 +00002285 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002286 // Operand[0] = Value to switch on
2287 // Operand[1] = Default basic block destination
2288 // Operand[2n ] = Value to match
2289 // Operand[2n+1] = BasicBlock to go to on match
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002290 SwitchInst(const SwitchInst &SI);
Chris Lattneraa6e3502010-11-17 05:41:46 +00002291 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
Jay Foad8891ed72011-04-01 08:00:58 +00002292 void growOperands();
Gabor Greifefe65362008-05-10 08:32:32 +00002293 // allocate space for exactly zero operands
2294 void *operator new(size_t s) {
2295 return User::operator new(s, 0);
2296 }
Chris Lattner454928e2005-01-29 00:31:36 +00002297 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2298 /// switch on and a default destination. The number of additional cases can
2299 /// be specified here to make memory allocation more efficient. This
2300 /// constructor can also autoinsert before another instruction.
2301 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002302 Instruction *InsertBefore);
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002303
Chris Lattner454928e2005-01-29 00:31:36 +00002304 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2305 /// switch on and a default destination. The number of additional cases can
2306 /// be specified here to make memory allocation more efficient. This
2307 /// constructor also autoinserts at the end of the specified BasicBlock.
2308 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00002309 BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00002310protected:
2311 virtual SwitchInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00002312public:
Gabor Greifefe65362008-05-10 08:32:32 +00002313 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2314 unsigned NumCases, Instruction *InsertBefore = 0) {
2315 return new SwitchInst(Value, Default, NumCases, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002316 }
Gabor Greifefe65362008-05-10 08:32:32 +00002317 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2318 unsigned NumCases, BasicBlock *InsertAtEnd) {
2319 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002320 }
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00002321 ~SwitchInst();
Chris Lattner454928e2005-01-29 00:31:36 +00002322
Gabor Greifefe65362008-05-10 08:32:32 +00002323 /// Provide fast operand accessors
2324 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2325
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002326 // Accessor Methods for Switch stmt
Devang Patel4d4a5e02008-02-23 01:11:02 +00002327 Value *getCondition() const { return getOperand(0); }
Chris Lattner454928e2005-01-29 00:31:36 +00002328 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00002329
Devang Patel4d4a5e02008-02-23 01:11:02 +00002330 BasicBlock *getDefaultDest() const {
Chris Lattner454928e2005-01-29 00:31:36 +00002331 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002332 }
2333
2334 /// getNumCases - return the number of 'cases' in this switch instruction.
2335 /// Note that case #0 is always the default case.
2336 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00002337 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002338 }
2339
2340 /// getCaseValue - Return the specified case value. Note that case #0, the
2341 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002342 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002343 assert(i && i < getNumCases() && "Illegal case value to get!");
2344 return getSuccessorValue(i);
2345 }
2346
2347 /// getCaseValue - Return the specified case value. Note that case #0, the
2348 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002349 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002350 assert(i && i < getNumCases() && "Illegal case value to get!");
2351 return getSuccessorValue(i);
2352 }
2353
2354 /// findCaseValue - Search all of the case values for the specified constant.
2355 /// If it is explicitly handled, return the case number of it, otherwise
2356 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002357 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002358 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2359 if (getCaseValue(i) == C)
2360 return i;
2361 return 0;
2362 }
2363
Nick Lewycky011f1842006-09-18 19:03:59 +00002364 /// findCaseDest - Finds the unique case value for a given successor. Returns
2365 /// null if the successor is not found, not unique, or is the default case.
2366 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00002367 if (BB == getDefaultDest()) return NULL;
2368
Nick Lewycky011f1842006-09-18 19:03:59 +00002369 ConstantInt *CI = NULL;
2370 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2371 if (getSuccessor(i) == BB) {
2372 if (CI) return NULL; // Multiple cases lead to BB.
2373 else CI = getCaseValue(i);
2374 }
2375 }
2376 return CI;
2377 }
2378
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002379 /// addCase - Add an entry to the switch instruction...
2380 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00002381 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002382
2383 /// removeCase - This method removes the specified successor from the switch
2384 /// instruction. Note that this cannot be used to remove the default
Jay Foad0faa6092011-02-01 09:22:34 +00002385 /// destination (successor #0). Also note that this operation may reorder the
2386 /// remaining cases at index idx and above.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002387 ///
2388 void removeCase(unsigned idx);
2389
Chris Lattner454928e2005-01-29 00:31:36 +00002390 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2391 BasicBlock *getSuccessor(unsigned idx) const {
2392 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2393 return cast<BasicBlock>(getOperand(idx*2+1));
2394 }
2395 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002396 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner4b122932009-10-27 16:49:53 +00002397 setOperand(idx*2+1, (Value*)NewSucc);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002398 }
2399
2400 // getSuccessorValue - Return the value associated with the specified
2401 // successor.
Devang Patel4d4a5e02008-02-23 01:11:02 +00002402 ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002403 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00002404 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002405 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002406
2407 // Methods for support type inquiry through isa, cast, and dyn_cast:
2408 static inline bool classof(const SwitchInst *) { return true; }
2409 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00002410 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002411 }
2412 static inline bool classof(const Value *V) {
2413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2414 }
Chris Lattner454928e2005-01-29 00:31:36 +00002415private:
2416 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2417 virtual unsigned getNumSuccessorsV() const;
2418 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002419};
2420
Gabor Greifefe65362008-05-10 08:32:32 +00002421template <>
Duncan Sands59bf4fc2009-09-06 08:55:57 +00002422struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
Gabor Greifefe65362008-05-10 08:32:32 +00002423};
2424
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002425DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
Gabor Greifefe65362008-05-10 08:32:32 +00002426
2427
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002428//===----------------------------------------------------------------------===//
Chris Lattnerab21db72009-10-28 00:19:10 +00002429// IndirectBrInst Class
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002430//===----------------------------------------------------------------------===//
2431
2432//===---------------------------------------------------------------------------
Chris Lattnerab21db72009-10-28 00:19:10 +00002433/// IndirectBrInst - Indirect Branch Instruction.
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002434///
Chris Lattnerab21db72009-10-28 00:19:10 +00002435class IndirectBrInst : public TerminatorInst {
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002436 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2437 unsigned ReservedSpace;
2438 // Operand[0] = Value to switch on
2439 // Operand[1] = Default basic block destination
2440 // Operand[2n ] = Value to match
2441 // Operand[2n+1] = BasicBlock to go to on match
Chris Lattnerab21db72009-10-28 00:19:10 +00002442 IndirectBrInst(const IndirectBrInst &IBI);
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002443 void init(Value *Address, unsigned NumDests);
Jay Foad8891ed72011-04-01 08:00:58 +00002444 void growOperands();
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002445 // allocate space for exactly zero operands
2446 void *operator new(size_t s) {
2447 return User::operator new(s, 0);
2448 }
Chris Lattnerab21db72009-10-28 00:19:10 +00002449 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2450 /// Address to jump to. The number of expected destinations can be specified
2451 /// here to make memory allocation more efficient. This constructor can also
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002452 /// autoinsert before another instruction.
Chris Lattnerab21db72009-10-28 00:19:10 +00002453 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002454
Chris Lattnerab21db72009-10-28 00:19:10 +00002455 /// IndirectBrInst ctor - Create a new indirectbr instruction, specifying an
2456 /// Address to jump to. The number of expected destinations can be specified
2457 /// here to make memory allocation more efficient. This constructor also
2458 /// autoinserts at the end of the specified BasicBlock.
2459 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00002460protected:
Chris Lattnerab21db72009-10-28 00:19:10 +00002461 virtual IndirectBrInst *clone_impl() const;
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002462public:
Chris Lattnerab21db72009-10-28 00:19:10 +00002463 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2464 Instruction *InsertBefore = 0) {
2465 return new IndirectBrInst(Address, NumDests, InsertBefore);
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002466 }
Chris Lattnerab21db72009-10-28 00:19:10 +00002467 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
2468 BasicBlock *InsertAtEnd) {
2469 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002470 }
Chris Lattnerab21db72009-10-28 00:19:10 +00002471 ~IndirectBrInst();
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002472
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002473 /// Provide fast operand accessors.
2474 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002475
Chris Lattnerab21db72009-10-28 00:19:10 +00002476 // Accessor Methods for IndirectBrInst instruction.
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002477 Value *getAddress() { return getOperand(0); }
2478 const Value *getAddress() const { return getOperand(0); }
2479 void setAddress(Value *V) { setOperand(0, V); }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002480
2481
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002482 /// getNumDestinations - return the number of possible destinations in this
Chris Lattnerab21db72009-10-28 00:19:10 +00002483 /// indirectbr instruction.
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002484 unsigned getNumDestinations() const { return getNumOperands()-1; }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002485
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002486 /// getDestination - Return the specified destination.
2487 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
2488 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002489
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002490 /// addDestination - Add a destination.
2491 ///
2492 void addDestination(BasicBlock *Dest);
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002493
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002494 /// removeDestination - This method removes the specified successor from the
Chris Lattnerab21db72009-10-28 00:19:10 +00002495 /// indirectbr instruction.
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002496 void removeDestination(unsigned i);
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002497
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002498 unsigned getNumSuccessors() const { return getNumOperands()-1; }
2499 BasicBlock *getSuccessor(unsigned i) const {
2500 return cast<BasicBlock>(getOperand(i+1));
2501 }
2502 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
2503 setOperand(i+1, (Value*)NewSucc);
2504 }
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002505
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002506 // Methods for support type inquiry through isa, cast, and dyn_cast:
Chris Lattnerab21db72009-10-28 00:19:10 +00002507 static inline bool classof(const IndirectBrInst *) { return true; }
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002508 static inline bool classof(const Instruction *I) {
Chris Lattnerab21db72009-10-28 00:19:10 +00002509 return I->getOpcode() == Instruction::IndirectBr;
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002510 }
2511 static inline bool classof(const Value *V) {
2512 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2513 }
2514private:
2515 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2516 virtual unsigned getNumSuccessorsV() const;
2517 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2518};
2519
2520template <>
Chris Lattnerab21db72009-10-28 00:19:10 +00002521struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002522};
2523
Chris Lattnerab21db72009-10-28 00:19:10 +00002524DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
Mikhail Glushenkov0da14f72010-10-27 07:39:48 +00002525
2526
Chris Lattnerf9be95f2009-10-27 19:13:16 +00002527//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002528// InvokeInst Class
2529//===----------------------------------------------------------------------===//
2530
Chris Lattner3340ffe2005-05-06 20:26:26 +00002531/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2532/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002533///
2534class InvokeInst : public TerminatorInst {
Devang Patel05988662008-09-25 21:00:45 +00002535 AttrListPtr AttributeList;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002536 InvokeInst(const InvokeInst &BI);
David Greenef1355a52007-08-27 19:04:21 +00002537 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002538 ArrayRef<Value *> Args, const Twine &NameStr);
David Greenef1355a52007-08-27 19:04:21 +00002539
David Greenef1355a52007-08-27 19:04:21 +00002540 /// Construct an InvokeInst given a range of arguments.
David Greenef1355a52007-08-27 19:04:21 +00002541 ///
2542 /// @brief Construct an InvokeInst from a range of arguments
Gabor Greifefe65362008-05-10 08:32:32 +00002543 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002544 ArrayRef<Value *> Args, unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00002545 const Twine &NameStr, Instruction *InsertBefore);
David Greenef1355a52007-08-27 19:04:21 +00002546
2547 /// Construct an InvokeInst given a range of arguments.
David Greenef1355a52007-08-27 19:04:21 +00002548 ///
2549 /// @brief Construct an InvokeInst from a range of arguments
Gabor Greifefe65362008-05-10 08:32:32 +00002550 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002551 ArrayRef<Value *> Args, unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00002552 const Twine &NameStr, BasicBlock *InsertAtEnd);
Devang Patel50b6e332009-10-27 22:16:29 +00002553protected:
2554 virtual InvokeInst *clone_impl() const;
Gabor Greif051a9502008-04-06 20:25:17 +00002555public:
Gabor Greifefe65362008-05-10 08:32:32 +00002556 static InvokeInst *Create(Value *Func,
2557 BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002558 ArrayRef<Value *> Args, const Twine &NameStr = "",
Evan Chengd69bb1a2008-05-05 17:41:03 +00002559 Instruction *InsertBefore = 0) {
Jay Foada3efbb12011-07-15 08:37:34 +00002560 unsigned Values = unsigned(Args.size()) + 3;
2561 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
Evan Cheng1bf9a182008-07-24 00:08:56 +00002562 Values, NameStr, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002563 }
Gabor Greifefe65362008-05-10 08:32:32 +00002564 static InvokeInst *Create(Value *Func,
2565 BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002566 ArrayRef<Value *> Args, const Twine &NameStr,
Evan Cheng1bf9a182008-07-24 00:08:56 +00002567 BasicBlock *InsertAtEnd) {
Jay Foada3efbb12011-07-15 08:37:34 +00002568 unsigned Values = unsigned(Args.size()) + 3;
2569 return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
Evan Cheng1bf9a182008-07-24 00:08:56 +00002570 Values, NameStr, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002571 }
David Greenef1355a52007-08-27 19:04:21 +00002572
Gabor Greifefe65362008-05-10 08:32:32 +00002573 /// Provide fast operand accessors
2574 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002575
Gabor Greif0114b992010-07-31 08:35:21 +00002576 /// getNumArgOperands - Return the number of invoke arguments.
2577 ///
Bill Wendling22a5b292010-06-07 19:05:06 +00002578 unsigned getNumArgOperands() const { return getNumOperands() - 3; }
Gabor Greif0114b992010-07-31 08:35:21 +00002579
2580 /// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
2581 ///
Bill Wendling22a5b292010-06-07 19:05:06 +00002582 Value *getArgOperand(unsigned i) const { return getOperand(i); }
Gabor Greif710ac072010-06-28 12:23:36 +00002583 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
Bill Wendling22a5b292010-06-07 19:05:06 +00002584
Chris Lattner3340ffe2005-05-06 20:26:26 +00002585 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2586 /// function call.
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00002587 CallingConv::ID getCallingConv() const {
Chris Lattnerb2406d92009-12-29 02:46:09 +00002588 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
Sandeep Patel65c3c8f2009-09-02 08:44:58 +00002589 }
2590 void setCallingConv(CallingConv::ID CC) {
Chris Lattnerb2406d92009-12-29 02:46:09 +00002591 setInstructionSubclassData(static_cast<unsigned>(CC));
Chris Lattner3340ffe2005-05-06 20:26:26 +00002592 }
2593
Devang Patel05988662008-09-25 21:00:45 +00002594 /// getAttributes - Return the parameter attributes for this invoke.
Chris Lattner58d74912008-03-12 17:45:29 +00002595 ///
Devang Patel05988662008-09-25 21:00:45 +00002596 const AttrListPtr &getAttributes() const { return AttributeList; }
Reid Spencerfa3e9122007-04-09 18:00:57 +00002597
Devang Patel05988662008-09-25 21:00:45 +00002598 /// setAttributes - Set the parameter attributes for this invoke.
Chris Lattner58d74912008-03-12 17:45:29 +00002599 ///
Devang Patel05988662008-09-25 21:00:45 +00002600 void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
Duncan Sandsdc024672007-11-27 13:23:08 +00002601
Devang Patel05988662008-09-25 21:00:45 +00002602 /// addAttribute - adds the attribute to the list of attributes.
2603 void addAttribute(unsigned i, Attributes attr);
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00002604
Devang Patel05988662008-09-25 21:00:45 +00002605 /// removeAttribute - removes the attribute from the list of attributes.
2606 void removeAttribute(unsigned i, Attributes attr);
Duncan Sands2e033f32008-07-08 08:38:44 +00002607
Dan Gohmanf2752502008-09-26 21:38:45 +00002608 /// @brief Determine whether the call or the callee has the given attribute.
2609 bool paramHasAttr(unsigned i, Attributes attr) const;
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002610
Dale Johannesen08e78b12008-02-22 17:49:45 +00002611 /// @brief Extract the alignment for a call or parameter (0=unknown).
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002612 unsigned getParamAlignment(unsigned i) const {
Devang Patel05988662008-09-25 21:00:45 +00002613 return AttributeList.getParamAlignment(i);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002614 }
Dale Johannesen08e78b12008-02-22 17:49:45 +00002615
Eric Christopherf27e6082010-03-25 04:49:10 +00002616 /// @brief Return true if the call should not be inlined.
2617 bool isNoInline() const { return paramHasAttr(~0, Attribute::NoInline); }
Nick Lewyckyb9933b82010-07-06 03:53:22 +00002618 void setIsNoInline(bool Value = true) {
Eric Christopherf27e6082010-03-25 04:49:10 +00002619 if (Value) addAttribute(~0, Attribute::NoInline);
2620 else removeAttribute(~0, Attribute::NoInline);
2621 }
Nick Lewyckyb9933b82010-07-06 03:53:22 +00002622
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002623 /// @brief Determine if the call does not access memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002624 bool doesNotAccessMemory() const {
Dan Gohmana62b5ed2009-07-17 16:12:36 +00002625 return paramHasAttr(~0, Attribute::ReadNone);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002626 }
Evan Cheng1bf9a182008-07-24 00:08:56 +00002627 void setDoesNotAccessMemory(bool NotAccessMemory = true) {
Devang Patel19c87462008-09-26 22:53:05 +00002628 if (NotAccessMemory) addAttribute(~0, Attribute::ReadNone);
2629 else removeAttribute(~0, Attribute::ReadNone);
Duncan Sands2e033f32008-07-08 08:38:44 +00002630 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002631
2632 /// @brief Determine if the call does not access or only reads memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002633 bool onlyReadsMemory() const {
Devang Patel19c87462008-09-26 22:53:05 +00002634 return doesNotAccessMemory() || paramHasAttr(~0, Attribute::ReadOnly);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002635 }
Evan Cheng1bf9a182008-07-24 00:08:56 +00002636 void setOnlyReadsMemory(bool OnlyReadsMemory = true) {
Devang Patel19c87462008-09-26 22:53:05 +00002637 if (OnlyReadsMemory) addAttribute(~0, Attribute::ReadOnly);
2638 else removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
Duncan Sands2e033f32008-07-08 08:38:44 +00002639 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002640
Duncan Sandscbb8bad2007-12-10 19:09:40 +00002641 /// @brief Determine if the call cannot return.
Nick Lewyckyb9933b82010-07-06 03:53:22 +00002642 bool doesNotReturn() const { return paramHasAttr(~0, Attribute::NoReturn); }
Evan Cheng1bf9a182008-07-24 00:08:56 +00002643 void setDoesNotReturn(bool DoesNotReturn = true) {
Devang Patel19c87462008-09-26 22:53:05 +00002644 if (DoesNotReturn) addAttribute(~0, Attribute::NoReturn);
2645 else removeAttribute(~0, Attribute::NoReturn);
Duncan Sands2e033f32008-07-08 08:38:44 +00002646 }
Duncan Sandscbb8bad2007-12-10 19:09:40 +00002647
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002648 /// @brief Determine if the call cannot unwind.
Nick Lewyckyb9933b82010-07-06 03:53:22 +00002649 bool doesNotThrow() const { return paramHasAttr(~0, Attribute::NoUnwind); }
Evan Cheng1bf9a182008-07-24 00:08:56 +00002650 void setDoesNotThrow(bool DoesNotThrow = true) {
Devang Patel19c87462008-09-26 22:53:05 +00002651 if (DoesNotThrow) addAttribute(~0, Attribute::NoUnwind);
2652 else removeAttribute(~0, Attribute::NoUnwind);
Duncan Sands2e033f32008-07-08 08:38:44 +00002653 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002654
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002655 /// @brief Determine if the call returns a structure through first
Devang Patel41e23972008-03-03 21:46:28 +00002656 /// pointer argument.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002657 bool hasStructRetAttr() const {
2658 // Be friendly and also check the callee.
Devang Patel05988662008-09-25 21:00:45 +00002659 return paramHasAttr(1, Attribute::StructRet);
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002660 }
Reid Spencerfa3e9122007-04-09 18:00:57 +00002661
Dan Gohmanf2752502008-09-26 21:38:45 +00002662 /// @brief Determine if any call argument is an aggregate passed by value.
2663 bool hasByValArgument() const {
2664 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
2665 }
2666
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002667 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00002668 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002669 ///
Chris Lattner721aef62004-11-18 17:46:57 +00002670 Function *getCalledFunction() const {
Gabor Greifc9f75002010-03-24 13:21:49 +00002671 return dyn_cast<Function>(Op<-3>());
Chris Lattner721aef62004-11-18 17:46:57 +00002672 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002673
Mikhail Glushenkoved2c4532009-02-09 17:11:05 +00002674 /// getCalledValue - Get a pointer to the function that is invoked by this
Dan Gohmanf2752502008-09-26 21:38:45 +00002675 /// instruction
Gabor Greifc9f75002010-03-24 13:21:49 +00002676 const Value *getCalledValue() const { return Op<-3>(); }
2677 Value *getCalledValue() { return Op<-3>(); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002678
Gabor Greif654c06f2010-03-20 21:00:25 +00002679 /// setCalledFunction - Set the function called.
2680 void setCalledFunction(Value* Fn) {
Gabor Greifc9f75002010-03-24 13:21:49 +00002681 Op<-3>() = Fn;
Gabor Greif654c06f2010-03-20 21:00:25 +00002682 }
2683
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002684 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00002685 BasicBlock *getNormalDest() const {
Gabor Greifc9f75002010-03-24 13:21:49 +00002686 return cast<BasicBlock>(Op<-2>());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002687 }
Chris Lattner454928e2005-01-29 00:31:36 +00002688 BasicBlock *getUnwindDest() const {
Gabor Greifc9f75002010-03-24 13:21:49 +00002689 return cast<BasicBlock>(Op<-1>());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002690 }
Chris Lattner454928e2005-01-29 00:31:36 +00002691 void setNormalDest(BasicBlock *B) {
Gabor Greifc9f75002010-03-24 13:21:49 +00002692 Op<-2>() = reinterpret_cast<Value*>(B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002693 }
Chris Lattner454928e2005-01-29 00:31:36 +00002694 void setUnwindDest(BasicBlock *B) {
Gabor Greifc9f75002010-03-24 13:21:49 +00002695 Op<-1>() = reinterpret_cast<Value*>(B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002696 }
2697
Devang Patel4d4a5e02008-02-23 01:11:02 +00002698 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002699 assert(i < 2 && "Successor # out of range for invoke!");
2700 return i == 0 ? getNormalDest() : getUnwindDest();
2701 }
2702
Chris Lattner454928e2005-01-29 00:31:36 +00002703 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002704 assert(idx < 2 && "Successor # out of range for invoke!");
Gabor Greifc9f75002010-03-24 13:21:49 +00002705 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002706 }
2707
Chris Lattner454928e2005-01-29 00:31:36 +00002708 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002709
2710 // Methods for support type inquiry through isa, cast, and dyn_cast:
2711 static inline bool classof(const InvokeInst *) { return true; }
2712 static inline bool classof(const Instruction *I) {
2713 return (I->getOpcode() == Instruction::Invoke);
2714 }
2715 static inline bool classof(const Value *V) {
2716 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2717 }
Gabor Greifc9f75002010-03-24 13:21:49 +00002718
Chris Lattner454928e2005-01-29 00:31:36 +00002719private:
2720 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2721 virtual unsigned getNumSuccessorsV() const;
2722 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattnercafe9bb2009-12-29 02:14:09 +00002723
Chris Lattnerb2406d92009-12-29 02:46:09 +00002724 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2725 // method so that subclasses cannot accidentally use it.
2726 void setInstructionSubclassData(unsigned short D) {
2727 Instruction::setInstructionSubclassData(D);
Chris Lattnercafe9bb2009-12-29 02:14:09 +00002728 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002729};
2730
Gabor Greifefe65362008-05-10 08:32:32 +00002731template <>
Jay Foad67c619b2011-01-11 15:07:38 +00002732struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
Gabor Greifefe65362008-05-10 08:32:32 +00002733};
2734
Gabor Greifefe65362008-05-10 08:32:32 +00002735InvokeInst::InvokeInst(Value *Func,
2736 BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002737 ArrayRef<Value *> Args, unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00002738 const Twine &NameStr, Instruction *InsertBefore)
Gabor Greifefe65362008-05-10 08:32:32 +00002739 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2740 ->getElementType())->getReturnType(),
2741 Instruction::Invoke,
2742 OperandTraits<InvokeInst>::op_end(this) - Values,
2743 Values, InsertBefore) {
Jay Foada3efbb12011-07-15 08:37:34 +00002744 init(Func, IfNormal, IfException, Args, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +00002745}
Gabor Greifefe65362008-05-10 08:32:32 +00002746InvokeInst::InvokeInst(Value *Func,
2747 BasicBlock *IfNormal, BasicBlock *IfException,
Jay Foada3efbb12011-07-15 08:37:34 +00002748 ArrayRef<Value *> Args, unsigned Values,
Daniel Dunbar6e0d1cb2009-07-25 04:41:11 +00002749 const Twine &NameStr, BasicBlock *InsertAtEnd)
Gabor Greifefe65362008-05-10 08:32:32 +00002750 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2751 ->getElementType())->getReturnType(),
2752 Instruction::Invoke,
2753 OperandTraits<InvokeInst>::op_end(this) - Values,
2754 Values, InsertAtEnd) {
Jay Foada3efbb12011-07-15 08:37:34 +00002755 init(Func, IfNormal, IfException, Args, NameStr);
Gabor Greifefe65362008-05-10 08:32:32 +00002756}
2757
2758DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002759
2760//===----------------------------------------------------------------------===//
2761// UnwindInst Class
2762//===----------------------------------------------------------------------===//
2763
2764//===---------------------------------------------------------------------------
2765/// UnwindInst - Immediately exit the current function, unwinding the stack
2766/// until an invoke instruction is found.
2767///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002768class UnwindInst : public TerminatorInst {
Gabor Greif051a9502008-04-06 20:25:17 +00002769 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Devang Patel50b6e332009-10-27 22:16:29 +00002770protected:
2771 virtual UnwindInst *clone_impl() const;
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002772public:
Gabor Greif051a9502008-04-06 20:25:17 +00002773 // allocate space for exactly zero operands
2774 void *operator new(size_t s) {
2775 return User::operator new(s, 0);
2776 }
Owen Anderson1d0be152009-08-13 21:58:54 +00002777 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2778 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002779
Chris Lattner454928e2005-01-29 00:31:36 +00002780 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002781
2782 // Methods for support type inquiry through isa, cast, and dyn_cast:
2783 static inline bool classof(const UnwindInst *) { return true; }
2784 static inline bool classof(const Instruction *I) {
2785 return I->getOpcode() == Instruction::Unwind;
2786 }
2787 static inline bool classof(const Value *V) {
2788 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2789 }
Chris Lattner454928e2005-01-29 00:31:36 +00002790private:
2791 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2792 virtual unsigned getNumSuccessorsV() const;
2793 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002794};
2795
Chris Lattner076b3f12004-10-16 18:05:54 +00002796//===----------------------------------------------------------------------===//
Bill Wendlingdccc03b2011-07-31 06:30:59 +00002797// ResumeInst Class
2798//===----------------------------------------------------------------------===//
2799
2800//===---------------------------------------------------------------------------
2801/// ResumeInst - Resume the propagation of an exception.
2802///
2803class ResumeInst : public TerminatorInst {
2804 ResumeInst(const ResumeInst &RI);
2805
2806 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=0);
2807 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
2808protected:
2809 virtual ResumeInst *clone_impl() const;
2810public:
2811 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = 0) {
2812 return new(1) ResumeInst(Exn, InsertBefore);
2813 }
2814 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
2815 return new(1) ResumeInst(Exn, InsertAtEnd);
2816 }
2817
2818 /// Provide fast operand accessors
2819 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2820
2821 /// Convenience accessor.
2822 Value *getValue() const { return Op<0>(); }
2823
2824 unsigned getNumSuccessors() const { return 0; }
2825
2826 // Methods for support type inquiry through isa, cast, and dyn_cast:
2827 static inline bool classof(const ResumeInst *) { return true; }
2828 static inline bool classof(const Instruction *I) {
2829 return I->getOpcode() == Instruction::Resume;
2830 }
2831 static inline bool classof(const Value *V) {
2832 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2833 }
2834private:
2835 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2836 virtual unsigned getNumSuccessorsV() const;
2837 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
2838};
2839
2840template <>
2841struct OperandTraits<ResumeInst> :
2842 public FixedNumOperandTraits<ResumeInst, 1> {
2843};
2844
2845DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
2846
2847//===----------------------------------------------------------------------===//
Chris Lattner076b3f12004-10-16 18:05:54 +00002848// UnreachableInst Class
2849//===----------------------------------------------------------------------===//
2850
2851//===---------------------------------------------------------------------------
2852/// UnreachableInst - This function has undefined behavior. In particular, the
2853/// presence of this instruction indicates some higher level knowledge that the
2854/// end of the block cannot be reached.
2855///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002856class UnreachableInst : public TerminatorInst {
Gabor Greif051a9502008-04-06 20:25:17 +00002857 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Devang Patel50b6e332009-10-27 22:16:29 +00002858protected:
2859 virtual UnreachableInst *clone_impl() const;
2860
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002861public:
Gabor Greif051a9502008-04-06 20:25:17 +00002862 // allocate space for exactly zero operands
2863 void *operator new(size_t s) {
2864 return User::operator new(s, 0);
2865 }
Owen Anderson1d0be152009-08-13 21:58:54 +00002866 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2867 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00002868
Chris Lattner454928e2005-01-29 00:31:36 +00002869 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00002870
2871 // Methods for support type inquiry through isa, cast, and dyn_cast:
2872 static inline bool classof(const UnreachableInst *) { return true; }
2873 static inline bool classof(const Instruction *I) {
2874 return I->getOpcode() == Instruction::Unreachable;
2875 }
2876 static inline bool classof(const Value *V) {
2877 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2878 }
Chris Lattner454928e2005-01-29 00:31:36 +00002879private:
2880 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2881 virtual unsigned getNumSuccessorsV() const;
2882 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00002883};
2884
Reid Spencer3da59db2006-11-27 01:05:10 +00002885//===----------------------------------------------------------------------===//
2886// TruncInst Class
2887//===----------------------------------------------------------------------===//
2888
2889/// @brief This class represents a truncation of integer types.
2890class TruncInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00002891protected:
2892 /// @brief Clone an identical TruncInst
2893 virtual TruncInst *clone_impl() const;
2894
Reid Spencer3da59db2006-11-27 01:05:10 +00002895public:
2896 /// @brief Constructor with insert-before-instruction semantics
2897 TruncInst(
2898 Value *S, ///< The value to be truncated
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002899 Type *Ty, ///< The (smaller) type to truncate to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002900 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002901 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2902 );
2903
2904 /// @brief Constructor with insert-at-end-of-block semantics
2905 TruncInst(
2906 Value *S, ///< The value to be truncated
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002907 Type *Ty, ///< The (smaller) type to truncate to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002908 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002909 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2910 );
2911
Reid Spencer3da59db2006-11-27 01:05:10 +00002912 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2913 static inline bool classof(const TruncInst *) { return true; }
2914 static inline bool classof(const Instruction *I) {
2915 return I->getOpcode() == Trunc;
2916 }
2917 static inline bool classof(const Value *V) {
2918 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2919 }
2920};
2921
2922//===----------------------------------------------------------------------===//
2923// ZExtInst Class
2924//===----------------------------------------------------------------------===//
2925
2926/// @brief This class represents zero extension of integer types.
2927class ZExtInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00002928protected:
2929 /// @brief Clone an identical ZExtInst
2930 virtual ZExtInst *clone_impl() const;
2931
Reid Spencer3da59db2006-11-27 01:05:10 +00002932public:
2933 /// @brief Constructor with insert-before-instruction semantics
2934 ZExtInst(
2935 Value *S, ///< The value to be zero extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002936 Type *Ty, ///< The type to zero extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002937 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002938 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2939 );
2940
2941 /// @brief Constructor with insert-at-end semantics.
2942 ZExtInst(
2943 Value *S, ///< The value to be zero extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002944 Type *Ty, ///< The type to zero extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002945 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002946 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2947 );
2948
Reid Spencer3da59db2006-11-27 01:05:10 +00002949 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2950 static inline bool classof(const ZExtInst *) { return true; }
2951 static inline bool classof(const Instruction *I) {
2952 return I->getOpcode() == ZExt;
2953 }
2954 static inline bool classof(const Value *V) {
2955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2956 }
2957};
2958
2959//===----------------------------------------------------------------------===//
2960// SExtInst Class
2961//===----------------------------------------------------------------------===//
2962
2963/// @brief This class represents a sign extension of integer types.
2964class SExtInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00002965protected:
2966 /// @brief Clone an identical SExtInst
2967 virtual SExtInst *clone_impl() const;
2968
Reid Spencer3da59db2006-11-27 01:05:10 +00002969public:
2970 /// @brief Constructor with insert-before-instruction semantics
2971 SExtInst(
2972 Value *S, ///< The value to be sign extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002973 Type *Ty, ///< The type to sign extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002974 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002975 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2976 );
2977
2978 /// @brief Constructor with insert-at-end-of-block semantics
2979 SExtInst(
2980 Value *S, ///< The value to be sign extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00002981 Type *Ty, ///< The type to sign extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00002982 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00002983 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2984 );
2985
Reid Spencer3da59db2006-11-27 01:05:10 +00002986 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2987 static inline bool classof(const SExtInst *) { return true; }
2988 static inline bool classof(const Instruction *I) {
2989 return I->getOpcode() == SExt;
2990 }
2991 static inline bool classof(const Value *V) {
2992 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2993 }
2994};
2995
2996//===----------------------------------------------------------------------===//
2997// FPTruncInst Class
2998//===----------------------------------------------------------------------===//
2999
3000/// @brief This class represents a truncation of floating point types.
3001class FPTruncInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003002protected:
3003 /// @brief Clone an identical FPTruncInst
3004 virtual FPTruncInst *clone_impl() const;
3005
Reid Spencer3da59db2006-11-27 01:05:10 +00003006public:
3007 /// @brief Constructor with insert-before-instruction semantics
3008 FPTruncInst(
3009 Value *S, ///< The value to be truncated
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003010 Type *Ty, ///< The type to truncate to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003011 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003012 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3013 );
3014
3015 /// @brief Constructor with insert-before-instruction semantics
3016 FPTruncInst(
3017 Value *S, ///< The value to be truncated
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003018 Type *Ty, ///< The type to truncate to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003019 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003020 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3021 );
3022
Reid Spencer3da59db2006-11-27 01:05:10 +00003023 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3024 static inline bool classof(const FPTruncInst *) { return true; }
3025 static inline bool classof(const Instruction *I) {
3026 return I->getOpcode() == FPTrunc;
3027 }
3028 static inline bool classof(const Value *V) {
3029 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3030 }
3031};
3032
3033//===----------------------------------------------------------------------===//
3034// FPExtInst Class
3035//===----------------------------------------------------------------------===//
3036
3037/// @brief This class represents an extension of floating point types.
3038class FPExtInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003039protected:
3040 /// @brief Clone an identical FPExtInst
3041 virtual FPExtInst *clone_impl() const;
3042
Reid Spencer3da59db2006-11-27 01:05:10 +00003043public:
3044 /// @brief Constructor with insert-before-instruction semantics
3045 FPExtInst(
3046 Value *S, ///< The value to be extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003047 Type *Ty, ///< The type to extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003048 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003049 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3050 );
3051
3052 /// @brief Constructor with insert-at-end-of-block semantics
3053 FPExtInst(
3054 Value *S, ///< The value to be extended
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003055 Type *Ty, ///< The type to extend to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003056 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003057 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3058 );
3059
Reid Spencer3da59db2006-11-27 01:05:10 +00003060 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3061 static inline bool classof(const FPExtInst *) { return true; }
3062 static inline bool classof(const Instruction *I) {
3063 return I->getOpcode() == FPExt;
3064 }
3065 static inline bool classof(const Value *V) {
3066 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3067 }
3068};
3069
3070//===----------------------------------------------------------------------===//
3071// UIToFPInst Class
3072//===----------------------------------------------------------------------===//
3073
3074/// @brief This class represents a cast unsigned integer to floating point.
3075class UIToFPInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003076protected:
3077 /// @brief Clone an identical UIToFPInst
3078 virtual UIToFPInst *clone_impl() const;
3079
Reid Spencer3da59db2006-11-27 01:05:10 +00003080public:
3081 /// @brief Constructor with insert-before-instruction semantics
3082 UIToFPInst(
3083 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003084 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003085 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003086 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3087 );
3088
3089 /// @brief Constructor with insert-at-end-of-block semantics
3090 UIToFPInst(
3091 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003092 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003093 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003094 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3095 );
3096
Reid Spencer3da59db2006-11-27 01:05:10 +00003097 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3098 static inline bool classof(const UIToFPInst *) { return true; }
3099 static inline bool classof(const Instruction *I) {
3100 return I->getOpcode() == UIToFP;
3101 }
3102 static inline bool classof(const Value *V) {
3103 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3104 }
3105};
3106
3107//===----------------------------------------------------------------------===//
3108// SIToFPInst Class
3109//===----------------------------------------------------------------------===//
3110
3111/// @brief This class represents a cast from signed integer to floating point.
3112class SIToFPInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003113protected:
3114 /// @brief Clone an identical SIToFPInst
3115 virtual SIToFPInst *clone_impl() const;
3116
Reid Spencer3da59db2006-11-27 01:05:10 +00003117public:
3118 /// @brief Constructor with insert-before-instruction semantics
3119 SIToFPInst(
3120 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003121 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003122 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003123 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3124 );
3125
3126 /// @brief Constructor with insert-at-end-of-block semantics
3127 SIToFPInst(
3128 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003129 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003130 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003131 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3132 );
3133
Reid Spencer3da59db2006-11-27 01:05:10 +00003134 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3135 static inline bool classof(const SIToFPInst *) { return true; }
3136 static inline bool classof(const Instruction *I) {
3137 return I->getOpcode() == SIToFP;
3138 }
3139 static inline bool classof(const Value *V) {
3140 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3141 }
3142};
3143
3144//===----------------------------------------------------------------------===//
3145// FPToUIInst Class
3146//===----------------------------------------------------------------------===//
3147
3148/// @brief This class represents a cast from floating point to unsigned integer
3149class FPToUIInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003150protected:
3151 /// @brief Clone an identical FPToUIInst
3152 virtual FPToUIInst *clone_impl() const;
3153
Reid Spencer3da59db2006-11-27 01:05:10 +00003154public:
3155 /// @brief Constructor with insert-before-instruction semantics
3156 FPToUIInst(
3157 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003158 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003159 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003160 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3161 );
3162
3163 /// @brief Constructor with insert-at-end-of-block semantics
3164 FPToUIInst(
3165 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003166 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003167 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003168 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
3169 );
3170
Reid Spencer3da59db2006-11-27 01:05:10 +00003171 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3172 static inline bool classof(const FPToUIInst *) { return true; }
3173 static inline bool classof(const Instruction *I) {
3174 return I->getOpcode() == FPToUI;
3175 }
3176 static inline bool classof(const Value *V) {
3177 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3178 }
3179};
3180
3181//===----------------------------------------------------------------------===//
3182// FPToSIInst Class
3183//===----------------------------------------------------------------------===//
3184
3185/// @brief This class represents a cast from floating point to signed integer.
3186class FPToSIInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003187protected:
3188 /// @brief Clone an identical FPToSIInst
3189 virtual FPToSIInst *clone_impl() const;
3190
Reid Spencer3da59db2006-11-27 01:05:10 +00003191public:
3192 /// @brief Constructor with insert-before-instruction semantics
3193 FPToSIInst(
3194 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003195 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003196 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003197 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3198 );
3199
3200 /// @brief Constructor with insert-at-end-of-block semantics
3201 FPToSIInst(
3202 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003203 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003204 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003205 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3206 );
3207
Reid Spencer3da59db2006-11-27 01:05:10 +00003208 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3209 static inline bool classof(const FPToSIInst *) { return true; }
3210 static inline bool classof(const Instruction *I) {
3211 return I->getOpcode() == FPToSI;
3212 }
3213 static inline bool classof(const Value *V) {
3214 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3215 }
3216};
3217
3218//===----------------------------------------------------------------------===//
3219// IntToPtrInst Class
3220//===----------------------------------------------------------------------===//
3221
3222/// @brief This class represents a cast from an integer to a pointer.
3223class IntToPtrInst : public CastInst {
Reid Spencer3da59db2006-11-27 01:05:10 +00003224public:
3225 /// @brief Constructor with insert-before-instruction semantics
3226 IntToPtrInst(
3227 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003228 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003229 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003230 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3231 );
3232
3233 /// @brief Constructor with insert-at-end-of-block semantics
3234 IntToPtrInst(
3235 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003236 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003237 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003238 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3239 );
3240
3241 /// @brief Clone an identical IntToPtrInst
Devang Patel50b6e332009-10-27 22:16:29 +00003242 virtual IntToPtrInst *clone_impl() const;
Reid Spencer3da59db2006-11-27 01:05:10 +00003243
3244 // Methods for support type inquiry through isa, cast, and dyn_cast:
3245 static inline bool classof(const IntToPtrInst *) { return true; }
3246 static inline bool classof(const Instruction *I) {
3247 return I->getOpcode() == IntToPtr;
3248 }
3249 static inline bool classof(const Value *V) {
3250 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3251 }
3252};
3253
3254//===----------------------------------------------------------------------===//
3255// PtrToIntInst Class
3256//===----------------------------------------------------------------------===//
3257
3258/// @brief This class represents a cast from a pointer to an integer
3259class PtrToIntInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003260protected:
3261 /// @brief Clone an identical PtrToIntInst
3262 virtual PtrToIntInst *clone_impl() const;
3263
Reid Spencer3da59db2006-11-27 01:05:10 +00003264public:
3265 /// @brief Constructor with insert-before-instruction semantics
3266 PtrToIntInst(
3267 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003268 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003269 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003270 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3271 );
3272
3273 /// @brief Constructor with insert-at-end-of-block semantics
3274 PtrToIntInst(
3275 Value *S, ///< The value to be converted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003276 Type *Ty, ///< The type to convert to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003277 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003278 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3279 );
3280
Reid Spencer3da59db2006-11-27 01:05:10 +00003281 // Methods for support type inquiry through isa, cast, and dyn_cast:
3282 static inline bool classof(const PtrToIntInst *) { return true; }
3283 static inline bool classof(const Instruction *I) {
3284 return I->getOpcode() == PtrToInt;
3285 }
3286 static inline bool classof(const Value *V) {
3287 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3288 }
3289};
3290
3291//===----------------------------------------------------------------------===//
3292// BitCastInst Class
3293//===----------------------------------------------------------------------===//
3294
3295/// @brief This class represents a no-op cast from one type to another.
3296class BitCastInst : public CastInst {
Devang Patel50b6e332009-10-27 22:16:29 +00003297protected:
3298 /// @brief Clone an identical BitCastInst
3299 virtual BitCastInst *clone_impl() const;
3300
Reid Spencer3da59db2006-11-27 01:05:10 +00003301public:
3302 /// @brief Constructor with insert-before-instruction semantics
3303 BitCastInst(
3304 Value *S, ///< The value to be casted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003305 Type *Ty, ///< The type to casted to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003306 const Twine &NameStr = "", ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003307 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3308 );
3309
3310 /// @brief Constructor with insert-at-end-of-block semantics
3311 BitCastInst(
3312 Value *S, ///< The value to be casted
Chris Lattnerdb125cf2011-07-18 04:54:35 +00003313 Type *Ty, ///< The type to casted to
Gabor Greifc61f6b42010-07-21 08:25:55 +00003314 const Twine &NameStr, ///< A name for the new instruction
Reid Spencer3da59db2006-11-27 01:05:10 +00003315 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3316 );
3317
Reid Spencer3da59db2006-11-27 01:05:10 +00003318 // Methods for support type inquiry through isa, cast, and dyn_cast:
3319 static inline bool classof(const BitCastInst *) { return true; }
3320 static inline bool classof(const Instruction *I) {
3321 return I->getOpcode() == BitCast;
3322 }
3323 static inline bool classof(const Value *V) {
3324 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3325 }
3326};
3327
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00003328} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00003329
3330#endif