blob: 162601724c667d187944b41d4f8b505b26c7ec14 [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
David Greene52eec542007-08-01 03:43:44 +000019#include <iterator>
20
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000021#include "llvm/InstrTypes.h"
David Greene52eec542007-08-01 03:43:44 +000022#include "llvm/DerivedTypes.h"
Dale Johannesen0d51e7e2008-02-19 21:38:47 +000023#include "llvm/ParameterAttributes.h"
Gabor Greifefe65362008-05-10 08:32:32 +000024#include "llvm/BasicBlock.h"
Dan Gohman81a0c0b2008-05-31 00:58:22 +000025#include "llvm/ADT/SmallVector.h"
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000026
27namespace llvm {
28
Chris Lattnerd1a32602005-02-24 05:32:09 +000029class ConstantInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000030class PointerType;
Reid Spencer9d6565a2007-02-15 02:26:10 +000031class VectorType;
Reid Spencer3da43842007-02-28 22:00:54 +000032class ConstantRange;
33class APInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000034
35//===----------------------------------------------------------------------===//
36// AllocationInst Class
37//===----------------------------------------------------------------------===//
38
39/// AllocationInst - This class is the common base class of MallocInst and
40/// AllocaInst.
41///
Chris Lattner454928e2005-01-29 00:31:36 +000042class AllocationInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000043protected:
Nate Begeman14b05292005-11-05 09:21:28 +000044 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000045 const std::string &Name = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000046 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000047 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000048public:
Gabor Greif051a9502008-04-06 20:25:17 +000049 // Out of line virtual method, so the vtable, etc. has a home.
Gordon Henriksenafba8fe2007-12-10 02:14:30 +000050 virtual ~AllocationInst();
51
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000052 /// isArrayAllocation - Return true if there is an allocation size parameter
53 /// to the allocation instruction that is not 1.
54 ///
55 bool isArrayAllocation() const;
56
57 /// getArraySize - Get the number of element allocated, for a simple
58 /// allocation of a single element, this will return a constant 1 value.
59 ///
Devang Patel4d4a5e02008-02-23 01:11:02 +000060 const Value *getArraySize() const { return getOperand(0); }
61 Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000062
63 /// getType - Overload to return most specific pointer type
64 ///
Devang Patel4d4a5e02008-02-23 01:11:02 +000065 const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000066 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000067 }
68
69 /// getAllocatedType - Return the type that is being allocated by the
70 /// instruction.
71 ///
72 const Type *getAllocatedType() const;
73
Nate Begeman14b05292005-11-05 09:21:28 +000074 /// getAlignment - Return the alignment of the memory that is being allocated
75 /// by the instruction.
76 ///
Dan Gohman52837072008-03-24 16:55:58 +000077 unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
78 void setAlignment(unsigned Align);
Chris Lattnerf56a8db2006-10-03 17:09:12 +000079
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000080 virtual Instruction *clone() const = 0;
81
82 // Methods for support type inquiry through isa, cast, and dyn_cast:
83 static inline bool classof(const AllocationInst *) { return true; }
84 static inline bool classof(const Instruction *I) {
85 return I->getOpcode() == Instruction::Alloca ||
86 I->getOpcode() == Instruction::Malloc;
87 }
88 static inline bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
90 }
91};
92
93
94//===----------------------------------------------------------------------===//
95// MallocInst Class
96//===----------------------------------------------------------------------===//
97
98/// MallocInst - an instruction to allocated memory on the heap
99///
100class MallocInst : public AllocationInst {
101 MallocInst(const MallocInst &MI);
102public:
103 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
104 const std::string &Name = "",
105 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000107 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
108 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000109 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000110
111 MallocInst(const Type *Ty, const std::string &Name,
112 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000113 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
114 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
115 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000116
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000118 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000119 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
120 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000121 const std::string &Name = "",
122 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000123 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000124
Chris Lattnerf319e832004-10-15 23:52:05 +0000125 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000126
127 // Methods for support type inquiry through isa, cast, and dyn_cast:
128 static inline bool classof(const MallocInst *) { return true; }
129 static inline bool classof(const Instruction *I) {
130 return (I->getOpcode() == Instruction::Malloc);
131 }
132 static inline bool classof(const Value *V) {
133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
134 }
135};
136
137
138//===----------------------------------------------------------------------===//
139// AllocaInst Class
140//===----------------------------------------------------------------------===//
141
142/// AllocaInst - an instruction to allocate memory on the stack
143///
144class AllocaInst : public AllocationInst {
145 AllocaInst(const AllocaInst &);
146public:
147 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
148 const std::string &Name = "",
149 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000151 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
152 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000153 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerb77780e2006-05-10 04:38:35 +0000154
155 AllocaInst(const Type *Ty, const std::string &Name,
156 Instruction *InsertBefore = 0)
157 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
158 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
159 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000160
Chris Lattnerb77780e2006-05-10 04:38:35 +0000161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name = "", Instruction *InsertBefore = 0)
163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
Nate Begeman14b05292005-11-05 09:21:28 +0000164 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
165 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000166 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000167
Chris Lattnerf319e832004-10-15 23:52:05 +0000168 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000169
170 // Methods for support type inquiry through isa, cast, and dyn_cast:
171 static inline bool classof(const AllocaInst *) { return true; }
172 static inline bool classof(const Instruction *I) {
173 return (I->getOpcode() == Instruction::Alloca);
174 }
175 static inline bool classof(const Value *V) {
176 return isa<Instruction>(V) && classof(cast<Instruction>(V));
177 }
178};
179
180
181//===----------------------------------------------------------------------===//
182// FreeInst Class
183//===----------------------------------------------------------------------===//
184
185/// FreeInst - an instruction to deallocate memory
186///
Chris Lattner454928e2005-01-29 00:31:36 +0000187class FreeInst : public UnaryInstruction {
188 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000189public:
190 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
191 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
192
Chris Lattnerf319e832004-10-15 23:52:05 +0000193 virtual FreeInst *clone() const;
Owen Andersonc9edf0b2007-07-06 23:13:31 +0000194
195 // Accessor methods for consistency with other memory operations
196 Value *getPointerOperand() { return getOperand(0); }
197 const Value *getPointerOperand() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000198
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000199 // Methods for support type inquiry through isa, cast, and dyn_cast:
200 static inline bool classof(const FreeInst *) { return true; }
201 static inline bool classof(const Instruction *I) {
202 return (I->getOpcode() == Instruction::Free);
203 }
204 static inline bool classof(const Value *V) {
205 return isa<Instruction>(V) && classof(cast<Instruction>(V));
206 }
207};
208
209
210//===----------------------------------------------------------------------===//
211// LoadInst Class
212//===----------------------------------------------------------------------===//
213
Chris Lattner88fe29a2005-02-05 01:44:18 +0000214/// LoadInst - an instruction for reading from memory. This uses the
215/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000216///
Chris Lattner454928e2005-01-29 00:31:36 +0000217class LoadInst : public UnaryInstruction {
Christopher Lamb43c7f372007-04-22 19:24:39 +0000218
Chris Lattner454928e2005-01-29 00:31:36 +0000219 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000220 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
221 setVolatile(LI.isVolatile());
Christopher Lamb43c7f372007-04-22 19:24:39 +0000222 setAlignment(LI.getAlignment());
Misha Brukman9769ab22005-04-21 20:19:05 +0000223
Chris Lattner454928e2005-01-29 00:31:36 +0000224#ifndef NDEBUG
225 AssertOK();
226#endif
227 }
228 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000229public:
230 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
231 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000232 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
233 Instruction *InsertBefore = 0);
234 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
Chris Lattnerf00042a2007-02-13 07:54:42 +0000235 Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000236 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
237 BasicBlock *InsertAtEnd);
Dan Gohman6ab2d182007-07-18 20:51:11 +0000238 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile, unsigned Align,
239 BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000240
Chris Lattnerf00042a2007-02-13 07:54:42 +0000241 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
242 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000243 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
Chris Lattnerf00042a2007-02-13 07:54:42 +0000244 Instruction *InsertBefore = 0);
245 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
246 BasicBlock *InsertAtEnd);
247
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000248 /// isVolatile - Return true if this is a load from a volatile memory
249 /// location.
250 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000251 bool isVolatile() const { return SubclassData & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000252
253 /// setVolatile - Specify whether this is a volatile load or not.
254 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000255 void setVolatile(bool V) {
Hartmut Kaiserefd4a512007-10-17 14:56:40 +0000256 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000257 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000258
Chris Lattnerf319e832004-10-15 23:52:05 +0000259 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000260
Christopher Lamb43c7f372007-04-22 19:24:39 +0000261 /// getAlignment - Return the alignment of the access that is being performed
262 ///
263 unsigned getAlignment() const {
Christopher Lamb032507d2007-04-22 22:22:02 +0000264 return (1 << (SubclassData>>1)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000265 }
266
267 void setAlignment(unsigned Align);
268
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000269 Value *getPointerOperand() { return getOperand(0); }
270 const Value *getPointerOperand() const { return getOperand(0); }
271 static unsigned getPointerOperandIndex() { return 0U; }
272
273 // Methods for support type inquiry through isa, cast, and dyn_cast:
274 static inline bool classof(const LoadInst *) { return true; }
275 static inline bool classof(const Instruction *I) {
276 return I->getOpcode() == Instruction::Load;
277 }
278 static inline bool classof(const Value *V) {
279 return isa<Instruction>(V) && classof(cast<Instruction>(V));
280 }
281};
282
283
284//===----------------------------------------------------------------------===//
285// StoreInst Class
286//===----------------------------------------------------------------------===//
287
Misha Brukman9769ab22005-04-21 20:19:05 +0000288/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000289///
290class StoreInst : public Instruction {
Gabor Greif051a9502008-04-06 20:25:17 +0000291 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Christopher Lamb43c7f372007-04-22 19:24:39 +0000292
Gabor Greifefe65362008-05-10 08:32:32 +0000293 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store,
294 &Op<0>(), 2) {
Gabor Greif6c80c382008-05-26 21:33:52 +0000295 Op<0>() = SI.Op<0>();
296 Op<1>() = SI.Op<1>();
Chris Lattner88fe29a2005-02-05 01:44:18 +0000297 setVolatile(SI.isVolatile());
Christopher Lamb43c7f372007-04-22 19:24:39 +0000298 setAlignment(SI.getAlignment());
299
Chris Lattner454928e2005-01-29 00:31:36 +0000300#ifndef NDEBUG
301 AssertOK();
302#endif
303 }
304 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000305public:
Gabor Greif051a9502008-04-06 20:25:17 +0000306 // allocate space for exactly two operands
307 void *operator new(size_t s) {
308 return User::operator new(s, 2);
309 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000310 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
311 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
312 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
313 Instruction *InsertBefore = 0);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000314 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
315 unsigned Align, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000316 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
Dan Gohman6ab2d182007-07-18 20:51:11 +0000317 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
318 unsigned Align, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000319
320
321 /// isVolatile - Return true if this is a load from a volatile memory
322 /// location.
323 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000324 bool isVolatile() const { return SubclassData & 1; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000325
326 /// setVolatile - Specify whether this is a volatile load or not.
327 ///
Christopher Lamb43c7f372007-04-22 19:24:39 +0000328 void setVolatile(bool V) {
Hartmut Kaiserefd4a512007-10-17 14:56:40 +0000329 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
Christopher Lamb43c7f372007-04-22 19:24:39 +0000330 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000331
Chris Lattner454928e2005-01-29 00:31:36 +0000332 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +0000333 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Chris Lattner454928e2005-01-29 00:31:36 +0000334
Christopher Lamb43c7f372007-04-22 19:24:39 +0000335 /// getAlignment - Return the alignment of the access that is being performed
336 ///
337 unsigned getAlignment() const {
Christopher Lamb032507d2007-04-22 22:22:02 +0000338 return (1 << (SubclassData>>1)) >> 1;
Christopher Lamb43c7f372007-04-22 19:24:39 +0000339 }
340
341 void setAlignment(unsigned Align);
342
Chris Lattnerf319e832004-10-15 23:52:05 +0000343 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000344
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000345 Value *getPointerOperand() { return getOperand(1); }
346 const Value *getPointerOperand() const { return getOperand(1); }
347 static unsigned getPointerOperandIndex() { return 1U; }
348
349 // Methods for support type inquiry through isa, cast, and dyn_cast:
350 static inline bool classof(const StoreInst *) { return true; }
351 static inline bool classof(const Instruction *I) {
352 return I->getOpcode() == Instruction::Store;
353 }
354 static inline bool classof(const Value *V) {
355 return isa<Instruction>(V) && classof(cast<Instruction>(V));
356 }
357};
358
Gabor Greifefe65362008-05-10 08:32:32 +0000359template <>
360struct OperandTraits<StoreInst> : FixedNumOperandTraits<2> {
361};
362
363DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000364
365//===----------------------------------------------------------------------===//
366// GetElementPtrInst Class
367//===----------------------------------------------------------------------===//
368
David Greeneb8f74792007-09-04 15:46:09 +0000369// checkType - Simple wrapper function to give a better assertion failure
370// message on bad indexes for a gep instruction.
371//
372static inline const Type *checkType(const Type *Ty) {
373 assert(Ty && "Invalid GetElementPtrInst indices for type!");
374 return Ty;
375}
376
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000377/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
378/// access elements of arrays and structs
379///
380class GetElementPtrInst : public Instruction {
Gabor Greifefe65362008-05-10 08:32:32 +0000381 GetElementPtrInst(const GetElementPtrInst &GEPI);
Matthijs Kooijmancfd5b7d2008-06-05 07:26:15 +0000382 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx,
383 const std::string &Name);
Matthijs Kooijman338169d2008-06-04 16:14:12 +0000384 void init(Value *Ptr, Value *Idx, const std::string &Name);
David Greeneb8f74792007-09-04 15:46:09 +0000385
386 template<typename InputIterator>
387 void init(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
388 const std::string &Name,
389 // This argument ensures that we have an iterator we can
390 // do arithmetic on in constant time
391 std::random_access_iterator_tag) {
Evan Cheng34cd4a42008-05-05 18:30:58 +0000392 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
David Greeneb8f74792007-09-04 15:46:09 +0000393
394 if (NumIdx > 0) {
Gabor Greifefe65362008-05-10 08:32:32 +0000395 // This requires that the iterator points to contiguous memory.
Matthijs Kooijman338169d2008-06-04 16:14:12 +0000396 init(Ptr, &*IdxBegin, NumIdx, Name); // FIXME: for the general case
Gabor Greifefe65362008-05-10 08:32:32 +0000397 // we have to build an array here
David Greeneb8f74792007-09-04 15:46:09 +0000398 }
399 else {
Matthijs Kooijman338169d2008-06-04 16:14:12 +0000400 init(Ptr, 0, NumIdx, Name);
David Greeneb8f74792007-09-04 15:46:09 +0000401 }
David Greeneb8f74792007-09-04 15:46:09 +0000402 }
403
404 /// getIndexedType - Returns the type of the element that would be loaded with
405 /// a load instruction with the specified parameters.
406 ///
Dan Gohmane2d896f2008-05-15 23:35:32 +0000407 /// Null is returned if the indices are invalid for the specified
David Greeneb8f74792007-09-04 15:46:09 +0000408 /// pointer type.
409 ///
410 static const Type *getIndexedType(const Type *Ptr,
Dan Gohman041e2eb2008-05-15 19:50:34 +0000411 Value* const *Idx, unsigned NumIdx);
David Greeneb8f74792007-09-04 15:46:09 +0000412
413 template<typename InputIterator>
414 static const Type *getIndexedType(const Type *Ptr,
415 InputIterator IdxBegin,
416 InputIterator IdxEnd,
David Greeneb8f74792007-09-04 15:46:09 +0000417 // This argument ensures that we
418 // have an iterator we can do
419 // arithmetic on in constant time
420 std::random_access_iterator_tag) {
Evan Cheng34cd4a42008-05-05 18:30:58 +0000421 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
David Greeneb8f74792007-09-04 15:46:09 +0000422
Dan Gohman041e2eb2008-05-15 19:50:34 +0000423 if (NumIdx > 0)
David Greeneb8f74792007-09-04 15:46:09 +0000424 // This requires that the iterator points to contiguous memory.
Dan Gohman041e2eb2008-05-15 19:50:34 +0000425 return getIndexedType(Ptr, (Value *const *)&*IdxBegin, NumIdx);
426 else
427 return getIndexedType(Ptr, (Value *const*)0, NumIdx);
David Greeneb8f74792007-09-04 15:46:09 +0000428 }
429
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000430 /// Constructors - Create a getelementptr instruction with a base pointer an
431 /// list of indices. The first ctor can optionally insert before an existing
432 /// instruction, the second appends the new instruction to the specified
433 /// BasicBlock.
David Greeneb8f74792007-09-04 15:46:09 +0000434 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +0000435 inline GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
436 InputIterator IdxEnd,
437 unsigned Values,
438 const std::string &Name,
439 Instruction *InsertBefore);
David Greeneb8f74792007-09-04 15:46:09 +0000440 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +0000441 inline GetElementPtrInst(Value *Ptr,
442 InputIterator IdxBegin, InputIterator IdxEnd,
443 unsigned Values,
444 const std::string &Name, BasicBlock *InsertAtEnd);
David Greeneb8f74792007-09-04 15:46:09 +0000445
Chris Lattner38bacf22005-05-03 05:43:30 +0000446 /// Constructors - These two constructors are convenience methods because one
447 /// and two index getelementptr instructions are so common.
Gabor Greifefe65362008-05-10 08:32:32 +0000448 GetElementPtrInst(Value *Ptr, Value *Idx, const std::string &Name = "",
449 Instruction *InsertBefore = 0);
Chris Lattner38bacf22005-05-03 05:43:30 +0000450 GetElementPtrInst(Value *Ptr, Value *Idx,
451 const std::string &Name, BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +0000452public:
453 template<typename InputIterator>
454 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
455 InputIterator IdxEnd,
456 const std::string &Name = "",
457 Instruction *InsertBefore = 0) {
Gabor Greifefe65362008-05-10 08:32:32 +0000458 typename std::iterator_traits<InputIterator>::difference_type Values =
459 1 + std::distance(IdxBegin, IdxEnd);
460 return new(Values)
461 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +0000462 }
463 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +0000464 static GetElementPtrInst *Create(Value *Ptr,
465 InputIterator IdxBegin, InputIterator IdxEnd,
466 const std::string &Name,
467 BasicBlock *InsertAtEnd) {
468 typename std::iterator_traits<InputIterator>::difference_type Values =
469 1 + std::distance(IdxBegin, IdxEnd);
470 return new(Values)
471 GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +0000472 }
473
Gabor Greifefe65362008-05-10 08:32:32 +0000474 /// Constructors - These two creators are convenience methods because one
475 /// index getelementptr instructions are so common.
Gabor Greif051a9502008-04-06 20:25:17 +0000476 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
Gabor Greifefe65362008-05-10 08:32:32 +0000477 const std::string &Name = "",
478 Instruction *InsertBefore = 0) {
479 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +0000480 }
481 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
Gabor Greifefe65362008-05-10 08:32:32 +0000482 const std::string &Name,
483 BasicBlock *InsertAtEnd) {
484 return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +0000485 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000486
Chris Lattnerf319e832004-10-15 23:52:05 +0000487 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000488
Gabor Greifefe65362008-05-10 08:32:32 +0000489 /// Transparently provide more efficient getOperand methods.
490 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
491
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000492 // getType - Overload to return most specific pointer type...
Devang Patel4d4a5e02008-02-23 01:11:02 +0000493 const PointerType *getType() const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000494 return reinterpret_cast<const PointerType*>(Instruction::getType());
495 }
496
497 /// getIndexedType - Returns the type of the element that would be loaded with
498 /// a load instruction with the specified parameters.
499 ///
Dan Gohmane2d896f2008-05-15 23:35:32 +0000500 /// Null is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000501 /// pointer type.
502 ///
David Greeneb8f74792007-09-04 15:46:09 +0000503 template<typename InputIterator>
Misha Brukman9769ab22005-04-21 20:19:05 +0000504 static const Type *getIndexedType(const Type *Ptr,
David Greeneb8f74792007-09-04 15:46:09 +0000505 InputIterator IdxBegin,
Dan Gohman041e2eb2008-05-15 19:50:34 +0000506 InputIterator IdxEnd) {
507 return getIndexedType(Ptr, IdxBegin, IdxEnd,
David Greeneb8f74792007-09-04 15:46:09 +0000508 typename std::iterator_traits<InputIterator>::
Dan Gohman041e2eb2008-05-15 19:50:34 +0000509 iterator_category());
David Greeneb8f74792007-09-04 15:46:09 +0000510 }
Chris Lattner38bacf22005-05-03 05:43:30 +0000511 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000512
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000513 inline op_iterator idx_begin() { return op_begin()+1; }
514 inline const_op_iterator idx_begin() const { return op_begin()+1; }
515 inline op_iterator idx_end() { return op_end(); }
516 inline const_op_iterator idx_end() const { return op_end(); }
517
518 Value *getPointerOperand() {
519 return getOperand(0);
520 }
521 const Value *getPointerOperand() const {
522 return getOperand(0);
523 }
524 static unsigned getPointerOperandIndex() {
525 return 0U; // get index for modifying correct operand
526 }
527
Devang Patel4d4a5e02008-02-23 01:11:02 +0000528 unsigned getNumIndices() const { // Note: always non-negative
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000529 return getNumOperands() - 1;
530 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000531
Devang Patel4d4a5e02008-02-23 01:11:02 +0000532 bool hasIndices() const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000533 return getNumOperands() > 1;
534 }
Chris Lattner6f771d42007-04-14 00:12:57 +0000535
536 /// hasAllZeroIndices - Return true if all of the indices of this GEP are
537 /// zeros. If so, the result pointer and the first operand have the same
538 /// value, just potentially different types.
539 bool hasAllZeroIndices() const;
Chris Lattner6b0974c2007-04-27 20:35:56 +0000540
541 /// hasAllConstantIndices - Return true if all of the indices of this GEP are
542 /// constant integers. If so, the result pointer and the first operand have
543 /// a constant offset between them.
544 bool hasAllConstantIndices() const;
545
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000546
547 // Methods for support type inquiry through isa, cast, and dyn_cast:
548 static inline bool classof(const GetElementPtrInst *) { return true; }
549 static inline bool classof(const Instruction *I) {
550 return (I->getOpcode() == Instruction::GetElementPtr);
551 }
552 static inline bool classof(const Value *V) {
553 return isa<Instruction>(V) && classof(cast<Instruction>(V));
554 }
555};
556
Gabor Greifefe65362008-05-10 08:32:32 +0000557template <>
558struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
559};
560
561template<typename InputIterator>
562GetElementPtrInst::GetElementPtrInst(Value *Ptr,
563 InputIterator IdxBegin,
564 InputIterator IdxEnd,
565 unsigned Values,
566 const std::string &Name,
567 Instruction *InsertBefore)
568 : Instruction(PointerType::get(checkType(
569 getIndexedType(Ptr->getType(),
Dan Gohman041e2eb2008-05-15 19:50:34 +0000570 IdxBegin, IdxEnd)),
Gabor Greifefe65362008-05-10 08:32:32 +0000571 cast<PointerType>(Ptr->getType())
572 ->getAddressSpace()),
573 GetElementPtr,
574 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
575 Values, InsertBefore) {
576 init(Ptr, IdxBegin, IdxEnd, Name,
577 typename std::iterator_traits<InputIterator>::iterator_category());
578}
579template<typename InputIterator>
580GetElementPtrInst::GetElementPtrInst(Value *Ptr,
581 InputIterator IdxBegin,
582 InputIterator IdxEnd,
583 unsigned Values,
584 const std::string &Name,
585 BasicBlock *InsertAtEnd)
586 : Instruction(PointerType::get(checkType(
587 getIndexedType(Ptr->getType(),
Dan Gohman041e2eb2008-05-15 19:50:34 +0000588 IdxBegin, IdxEnd)),
Gabor Greifefe65362008-05-10 08:32:32 +0000589 cast<PointerType>(Ptr->getType())
590 ->getAddressSpace()),
591 GetElementPtr,
592 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
593 Values, InsertAtEnd) {
594 init(Ptr, IdxBegin, IdxEnd, Name,
595 typename std::iterator_traits<InputIterator>::iterator_category());
596}
597
598
599DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
600
601
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000602//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000603// ICmpInst Class
604//===----------------------------------------------------------------------===//
605
606/// This instruction compares its operands according to the predicate given
Nate Begemanac80ade2008-05-12 19:01:56 +0000607/// to the constructor. It only operates on integers or pointers. The operands
608/// must be identical types.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000609/// @brief Represent an integer comparison operator.
610class ICmpInst: public CmpInst {
611public:
Reid Spencer45fb3f32006-11-20 01:22:35 +0000612 /// @brief Constructor with insert-before-instruction semantics.
613 ICmpInst(
614 Predicate pred, ///< The predicate to use for the comparison
615 Value *LHS, ///< The left-hand-side of the expression
616 Value *RHS, ///< The right-hand-side of the expression
617 const std::string &Name = "", ///< Name of the instruction
618 Instruction *InsertBefore = 0 ///< Where to insert
Nate Begemanac80ade2008-05-12 19:01:56 +0000619 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
620 InsertBefore) {
621 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
622 pred <= CmpInst::LAST_ICMP_PREDICATE &&
623 "Invalid ICmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000624 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000625 "Both operands to ICmp instruction are not of the same type!");
626 // Check that the operands are the right type
Nate Begeman31cd33a2008-05-14 20:28:31 +0000627 assert((getOperand(0)->getType()->isInteger() ||
628 isa<PointerType>(getOperand(0)->getType())) &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000629 "Invalid operand types for ICmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000630 }
631
632 /// @brief Constructor with insert-at-block-end semantics.
633 ICmpInst(
634 Predicate pred, ///< The predicate to use for the comparison
635 Value *LHS, ///< The left-hand-side of the expression
636 Value *RHS, ///< The right-hand-side of the expression
637 const std::string &Name, ///< Name of the instruction
638 BasicBlock *InsertAtEnd ///< Block to insert into.
Nate Begemanac80ade2008-05-12 19:01:56 +0000639 ) : CmpInst(Type::Int1Ty, Instruction::ICmp, pred, LHS, RHS, Name,
640 InsertAtEnd) {
641 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
642 pred <= CmpInst::LAST_ICMP_PREDICATE &&
643 "Invalid ICmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000644 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000645 "Both operands to ICmp instruction are not of the same type!");
646 // Check that the operands are the right type
Nate Begeman31cd33a2008-05-14 20:28:31 +0000647 assert((getOperand(0)->getType()->isInteger() ||
648 isa<PointerType>(getOperand(0)->getType())) &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000649 "Invalid operand types for ICmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000650 }
651
Reid Spencere4d87aa2006-12-23 06:05:41 +0000652 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
653 /// @returns the predicate that would be the result if the operand were
654 /// regarded as signed.
655 /// @brief Return the signed version of the predicate
656 Predicate getSignedPredicate() const {
657 return getSignedPredicate(getPredicate());
658 }
659
660 /// This is a static version that you can use without an instruction.
661 /// @brief Return the signed version of the predicate.
662 static Predicate getSignedPredicate(Predicate pred);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000663
Nick Lewycky4189a532008-01-28 03:48:02 +0000664 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
665 /// @returns the predicate that would be the result if the operand were
666 /// regarded as unsigned.
667 /// @brief Return the unsigned version of the predicate
668 Predicate getUnsignedPredicate() const {
669 return getUnsignedPredicate(getPredicate());
670 }
671
672 /// This is a static version that you can use without an instruction.
673 /// @brief Return the unsigned version of the predicate.
674 static Predicate getUnsignedPredicate(Predicate pred);
675
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000676 /// isEquality - Return true if this predicate is either EQ or NE. This also
677 /// tests for commutativity.
678 static bool isEquality(Predicate P) {
679 return P == ICMP_EQ || P == ICMP_NE;
680 }
681
682 /// isEquality - Return true if this predicate is either EQ or NE. This also
683 /// tests for commutativity.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000684 bool isEquality() const {
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000685 return isEquality(getPredicate());
Reid Spencer45fb3f32006-11-20 01:22:35 +0000686 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000687
688 /// @returns true if the predicate of this ICmpInst is commutative
689 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000690 bool isCommutative() const { return isEquality(); }
691
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000692 /// isRelational - Return true if the predicate is relational (not EQ or NE).
693 ///
Reid Spencer45fb3f32006-11-20 01:22:35 +0000694 bool isRelational() const {
695 return !isEquality();
696 }
697
Chris Lattnerc2bfadb2007-11-22 23:43:29 +0000698 /// isRelational - Return true if the predicate is relational (not EQ or NE).
699 ///
700 static bool isRelational(Predicate P) {
701 return !isEquality(P);
702 }
703
Reid Spencere4d87aa2006-12-23 06:05:41 +0000704 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
705 /// @brief Determine if this instruction's predicate is signed.
Chris Lattner5bda9e42007-09-15 06:51:03 +0000706 bool isSignedPredicate() const { return isSignedPredicate(getPredicate()); }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000707
708 /// @returns true if the predicate provided is signed, false otherwise
709 /// @brief Determine if the predicate is signed.
710 static bool isSignedPredicate(Predicate pred);
711
Nick Lewyckyfc1efbb2008-05-17 07:33:39 +0000712 /// @returns true if the specified compare predicate is
713 /// true when both operands are equal...
714 /// @brief Determine if the icmp is true when both operands are equal
715 static bool isTrueWhenEqual(ICmpInst::Predicate pred) {
716 return pred == ICmpInst::ICMP_EQ || pred == ICmpInst::ICMP_UGE ||
717 pred == ICmpInst::ICMP_SGE || pred == ICmpInst::ICMP_ULE ||
718 pred == ICmpInst::ICMP_SLE;
719 }
720
721 /// @returns true if the specified compare instruction is
722 /// true when both operands are equal...
723 /// @brief Determine if the ICmpInst returns true when both operands are equal
724 bool isTrueWhenEqual() {
725 return isTrueWhenEqual(getPredicate());
726 }
727
Reid Spencer3da43842007-02-28 22:00:54 +0000728 /// Initialize a set of values that all satisfy the predicate with C.
729 /// @brief Make a ConstantRange for a relation with a constant value.
730 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
731
Reid Spencer45fb3f32006-11-20 01:22:35 +0000732 /// Exchange the two operands to this instruction in such a way that it does
733 /// not modify the semantics of the instruction. The predicate value may be
734 /// changed to retain the same result if the predicate is order dependent
735 /// (e.g. ult).
736 /// @brief Swap operands and adjust predicate.
737 void swapOperands() {
738 SubclassData = getSwappedPredicate();
Gabor Greif94fb68b2008-05-13 22:51:52 +0000739 Op<0>().swap(Op<1>());
Reid Spencer45fb3f32006-11-20 01:22:35 +0000740 }
741
Chris Lattnercd406fe2007-08-24 20:48:18 +0000742 virtual ICmpInst *clone() const;
743
Reid Spencer45fb3f32006-11-20 01:22:35 +0000744 // Methods for support type inquiry through isa, cast, and dyn_cast:
745 static inline bool classof(const ICmpInst *) { return true; }
746 static inline bool classof(const Instruction *I) {
747 return I->getOpcode() == Instruction::ICmp;
748 }
749 static inline bool classof(const Value *V) {
750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
751 }
752};
753
754//===----------------------------------------------------------------------===//
755// FCmpInst Class
756//===----------------------------------------------------------------------===//
757
758/// This instruction compares its operands according to the predicate given
759/// to the constructor. It only operates on floating point values or packed
760/// vectors of floating point values. The operands must be identical types.
761/// @brief Represents a floating point comparison operator.
762class FCmpInst: public CmpInst {
763public:
Reid Spencer45fb3f32006-11-20 01:22:35 +0000764 /// @brief Constructor with insert-before-instruction semantics.
765 FCmpInst(
766 Predicate pred, ///< The predicate to use for the comparison
767 Value *LHS, ///< The left-hand-side of the expression
768 Value *RHS, ///< The right-hand-side of the expression
769 const std::string &Name = "", ///< Name of the instruction
770 Instruction *InsertBefore = 0 ///< Where to insert
Nate Begemanac80ade2008-05-12 19:01:56 +0000771 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
772 InsertBefore) {
773 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
774 "Invalid FCmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000775 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000776 "Both operands to FCmp instruction are not of the same type!");
777 // Check that the operands are the right type
Nate Begeman31cd33a2008-05-14 20:28:31 +0000778 assert(getOperand(0)->getType()->isFloatingPoint() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000779 "Invalid operand types for FCmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000780 }
781
782 /// @brief Constructor with insert-at-block-end semantics.
783 FCmpInst(
784 Predicate pred, ///< The predicate to use for the comparison
785 Value *LHS, ///< The left-hand-side of the expression
786 Value *RHS, ///< The right-hand-side of the expression
787 const std::string &Name, ///< Name of the instruction
788 BasicBlock *InsertAtEnd ///< Block to insert into.
Nate Begemanac80ade2008-05-12 19:01:56 +0000789 ) : CmpInst(Type::Int1Ty, Instruction::FCmp, pred, LHS, RHS, Name,
790 InsertAtEnd) {
791 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
792 "Invalid FCmp predicate value");
Nate Begeman31cd33a2008-05-14 20:28:31 +0000793 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000794 "Both operands to FCmp instruction are not of the same type!");
795 // Check that the operands are the right type
Nate Begeman31cd33a2008-05-14 20:28:31 +0000796 assert(getOperand(0)->getType()->isFloatingPoint() &&
Nate Begemanac80ade2008-05-12 19:01:56 +0000797 "Invalid operand types for FCmp instruction");
Reid Spencer45fb3f32006-11-20 01:22:35 +0000798 }
799
Reid Spencer45fb3f32006-11-20 01:22:35 +0000800 /// This also tests for commutativity. If isEquality() returns true then
801 /// the predicate is also commutative. Only the equality predicates are
802 /// commutative.
803 /// @returns true if the predicate of this instruction is EQ or NE.
804 /// @brief Determine if this is an equality predicate.
805 bool isEquality() const {
806 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
807 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
808 }
809 bool isCommutative() const { return isEquality(); }
810
811 /// @returns true if the predicate is relational (not EQ or NE).
812 /// @brief Determine if this a relational predicate.
813 bool isRelational() const { return !isEquality(); }
814
815 /// Exchange the two operands to this instruction in such a way that it does
816 /// not modify the semantics of the instruction. The predicate value may be
817 /// changed to retain the same result if the predicate is order dependent
818 /// (e.g. ult).
819 /// @brief Swap operands and adjust predicate.
820 void swapOperands() {
821 SubclassData = getSwappedPredicate();
Gabor Greif94fb68b2008-05-13 22:51:52 +0000822 Op<0>().swap(Op<1>());
Reid Spencer45fb3f32006-11-20 01:22:35 +0000823 }
824
Chris Lattnercd406fe2007-08-24 20:48:18 +0000825 virtual FCmpInst *clone() const;
826
Reid Spencer45fb3f32006-11-20 01:22:35 +0000827 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
828 static inline bool classof(const FCmpInst *) { return true; }
829 static inline bool classof(const Instruction *I) {
830 return I->getOpcode() == Instruction::FCmp;
831 }
832 static inline bool classof(const Value *V) {
833 return isa<Instruction>(V) && classof(cast<Instruction>(V));
834 }
835};
836
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000837//===----------------------------------------------------------------------===//
Nate Begemanac80ade2008-05-12 19:01:56 +0000838// VICmpInst Class
839//===----------------------------------------------------------------------===//
840
841/// This instruction compares its operands according to the predicate given
842/// to the constructor. It only operates on vectors of integers.
843/// The operands must be identical types.
844/// @brief Represents a vector integer comparison operator.
845class VICmpInst: public CmpInst {
846public:
847 /// @brief Constructor with insert-before-instruction semantics.
848 VICmpInst(
849 Predicate pred, ///< The predicate to use for the comparison
850 Value *LHS, ///< The left-hand-side of the expression
851 Value *RHS, ///< The right-hand-side of the expression
852 const std::string &Name = "", ///< Name of the instruction
853 Instruction *InsertBefore = 0 ///< Where to insert
854 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
855 InsertBefore) {
Nate Begeman31cd33a2008-05-14 20:28:31 +0000856 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
857 pred <= CmpInst::LAST_ICMP_PREDICATE &&
858 "Invalid VICmp predicate value");
859 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
860 "Both operands to VICmp instruction are not of the same type!");
Nate Begemanac80ade2008-05-12 19:01:56 +0000861 }
862
863 /// @brief Constructor with insert-at-block-end semantics.
864 VICmpInst(
865 Predicate pred, ///< The predicate to use for the comparison
866 Value *LHS, ///< The left-hand-side of the expression
867 Value *RHS, ///< The right-hand-side of the expression
868 const std::string &Name, ///< Name of the instruction
869 BasicBlock *InsertAtEnd ///< Block to insert into.
870 ) : CmpInst(LHS->getType(), Instruction::VICmp, pred, LHS, RHS, Name,
871 InsertAtEnd) {
Nate Begeman31cd33a2008-05-14 20:28:31 +0000872 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
873 pred <= CmpInst::LAST_ICMP_PREDICATE &&
874 "Invalid VICmp predicate value");
875 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
876 "Both operands to VICmp instruction are not of the same type!");
Nate Begemanac80ade2008-05-12 19:01:56 +0000877 }
878
879 /// @brief Return the predicate for this instruction.
880 Predicate getPredicate() const { return Predicate(SubclassData); }
881
882 virtual VICmpInst *clone() const;
883
884 // Methods for support type inquiry through isa, cast, and dyn_cast:
885 static inline bool classof(const VICmpInst *) { return true; }
886 static inline bool classof(const Instruction *I) {
887 return I->getOpcode() == Instruction::VICmp;
888 }
889 static inline bool classof(const Value *V) {
890 return isa<Instruction>(V) && classof(cast<Instruction>(V));
891 }
892};
893
894//===----------------------------------------------------------------------===//
895// VFCmpInst Class
896//===----------------------------------------------------------------------===//
897
898/// This instruction compares its operands according to the predicate given
899/// to the constructor. It only operates on vectors of floating point values.
900/// The operands must be identical types.
901/// @brief Represents a vector floating point comparison operator.
902class VFCmpInst: public CmpInst {
903public:
904 /// @brief Constructor with insert-before-instruction semantics.
905 VFCmpInst(
906 Predicate pred, ///< The predicate to use for the comparison
907 Value *LHS, ///< The left-hand-side of the expression
908 Value *RHS, ///< The right-hand-side of the expression
909 const std::string &Name = "", ///< Name of the instruction
910 Instruction *InsertBefore = 0 ///< Where to insert
911 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
912 Instruction::VFCmp, pred, LHS, RHS, Name, InsertBefore) {
Nate Begeman31cd33a2008-05-14 20:28:31 +0000913 assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
914 "Invalid VFCmp predicate value");
915 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
916 "Both operands to VFCmp instruction are not of the same type!");
Nate Begemanac80ade2008-05-12 19:01:56 +0000917 }
918
919 /// @brief Constructor with insert-at-block-end semantics.
920 VFCmpInst(
921 Predicate pred, ///< The predicate to use for the comparison
922 Value *LHS, ///< The left-hand-side of the expression
923 Value *RHS, ///< The right-hand-side of the expression
924 const std::string &Name, ///< Name of the instruction
925 BasicBlock *InsertAtEnd ///< Block to insert into.
926 ) : CmpInst(VectorType::getInteger(cast<VectorType>(LHS->getType())),
927 Instruction::VFCmp, pred, LHS, RHS, Name, InsertAtEnd) {
Nate Begeman31cd33a2008-05-14 20:28:31 +0000928 assert(pred <= CmpInst::LAST_FCMP_PREDICATE &&
929 "Invalid VFCmp predicate value");
930 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
931 "Both operands to VFCmp instruction are not of the same type!");
Nate Begemanac80ade2008-05-12 19:01:56 +0000932 }
933
934 /// @brief Return the predicate for this instruction.
935 Predicate getPredicate() const { return Predicate(SubclassData); }
936
937 virtual VFCmpInst *clone() const;
938
939 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
940 static inline bool classof(const VFCmpInst *) { return true; }
941 static inline bool classof(const Instruction *I) {
942 return I->getOpcode() == Instruction::VFCmp;
943 }
944 static inline bool classof(const Value *V) {
945 return isa<Instruction>(V) && classof(cast<Instruction>(V));
946 }
947};
948
949//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000950// CallInst Class
951//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000952/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000953/// machine's calling convention. This class uses low bit of the SubClassData
954/// field to indicate whether or not this is a tail call. The rest of the bits
955/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000956///
David Greene52eec542007-08-01 03:43:44 +0000957
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000958class CallInst : public Instruction {
Chris Lattner58d74912008-03-12 17:45:29 +0000959 PAListPtr ParamAttrs; ///< parameter attributes for call
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000960 CallInst(const CallInst &CI);
Chris Lattnerd54f4322007-02-13 00:58:44 +0000961 void init(Value *Func, Value* const *Params, unsigned NumParams);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000962 void init(Value *Func, Value *Actual1, Value *Actual2);
963 void init(Value *Func, Value *Actual);
964 void init(Value *Func);
965
David Greene52eec542007-08-01 03:43:44 +0000966 template<typename InputIterator>
967 void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
968 const std::string &Name,
969 // This argument ensures that we have an iterator we can
970 // do arithmetic on in constant time
971 std::random_access_iterator_tag) {
Chris Lattnera5c0d1e2007-08-29 16:32:50 +0000972 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greene52eec542007-08-01 03:43:44 +0000973
Chris Lattnera5c0d1e2007-08-29 16:32:50 +0000974 // This requires that the iterator points to contiguous memory.
975 init(Func, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greene52eec542007-08-01 03:43:44 +0000976 setName(Name);
977 }
978
David Greene52eec542007-08-01 03:43:44 +0000979 /// Construct a CallInst given a range of arguments. InputIterator
980 /// must be a random-access iterator pointing to contiguous storage
981 /// (e.g. a std::vector<>::iterator). Checks are made for
982 /// random-accessness but not for contiguous storage as that would
983 /// incur runtime overhead.
984 /// @brief Construct a CallInst from a range of arguments
985 template<typename InputIterator>
986 CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
Gabor Greifefe65362008-05-10 08:32:32 +0000987 const std::string &Name, Instruction *InsertBefore);
David Greene52eec542007-08-01 03:43:44 +0000988
989 /// Construct a CallInst given a range of arguments. InputIterator
990 /// must be a random-access iterator pointing to contiguous storage
991 /// (e.g. a std::vector<>::iterator). Checks are made for
992 /// random-accessness but not for contiguous storage as that would
993 /// incur runtime overhead.
994 /// @brief Construct a CallInst from a range of arguments
995 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +0000996 inline CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
997 const std::string &Name, BasicBlock *InsertAtEnd);
David Greene52eec542007-08-01 03:43:44 +0000998
Gabor Greifefe65362008-05-10 08:32:32 +0000999 CallInst(Value *F, Value *Actual, const std::string& Name,
1000 Instruction *InsertBefore);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001001 CallInst(Value *F, Value *Actual, const std::string& Name,
1002 BasicBlock *InsertAtEnd);
Gabor Greifefe65362008-05-10 08:32:32 +00001003 explicit CallInst(Value *F, const std::string &Name,
1004 Instruction *InsertBefore);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001005 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001006public:
1007 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00001008 static CallInst *Create(Value *Func,
1009 InputIterator ArgBegin, InputIterator ArgEnd,
Evan Chengd69bb1a2008-05-05 17:41:03 +00001010 const std::string &Name = "",
1011 Instruction *InsertBefore = 0) {
Bill Wendlingc2e73532008-05-10 19:59:59 +00001012 return new((unsigned)(ArgEnd - ArgBegin + 1))
Evan Chengd69bb1a2008-05-05 17:41:03 +00001013 CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001014 }
1015 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00001016 static CallInst *Create(Value *Func,
1017 InputIterator ArgBegin, InputIterator ArgEnd,
1018 const std::string &Name, BasicBlock *InsertAtEnd) {
Bill Wendlingc2e73532008-05-10 19:59:59 +00001019 return new((unsigned)(ArgEnd - ArgBegin + 1))
Evan Chengd69bb1a2008-05-05 17:41:03 +00001020 CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001021 }
1022 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
1023 Instruction *InsertBefore = 0) {
1024 return new(2) CallInst(F, Actual, Name, InsertBefore);
1025 }
1026 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
1027 BasicBlock *InsertAtEnd) {
1028 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
1029 }
1030 static CallInst *Create(Value *F, const std::string &Name = "",
1031 Instruction *InsertBefore = 0) {
1032 return new(1) CallInst(F, Name, InsertBefore);
1033 }
Evan Cheng34cd4a42008-05-05 18:30:58 +00001034 static CallInst *Create(Value *F, const std::string &Name,
1035 BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00001036 return new(1) CallInst(F, Name, InsertAtEnd);
1037 }
1038
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001039 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001040
Chris Lattnerf319e832004-10-15 23:52:05 +00001041 virtual CallInst *clone() const;
Gabor Greifefe65362008-05-10 08:32:32 +00001042
1043 /// Provide fast operand accessors
1044 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Chris Lattnerbb5493d2007-02-15 23:15:00 +00001045
Chris Lattner3340ffe2005-05-06 20:26:26 +00001046 bool isTailCall() const { return SubclassData & 1; }
1047 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +00001048 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +00001049 }
1050
1051 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1052 /// function call.
1053 unsigned getCallingConv() const { return SubclassData >> 1; }
1054 void setCallingConv(unsigned CC) {
1055 SubclassData = (SubclassData & 1) | (CC << 1);
1056 }
Chris Lattnerddb6db42005-05-06 05:51:46 +00001057
Chris Lattner041221c2008-03-13 04:33:03 +00001058 /// getParamAttrs - Return the parameter attributes for this call.
1059 ///
Chris Lattner58d74912008-03-12 17:45:29 +00001060 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
Reid Spencer4746ecf2007-04-09 15:01:12 +00001061
Chris Lattner041221c2008-03-13 04:33:03 +00001062 /// setParamAttrs - Sets the parameter attributes for this call.
Chris Lattner58d74912008-03-12 17:45:29 +00001063 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
Eric Christopher0bf7b412008-05-16 20:39:43 +00001064
1065 /// addParamAttr - adds the attribute to the list of attributes.
1066 void addParamAttr(unsigned i, ParameterAttributes attr);
Duncan Sandsdc024672007-11-27 13:23:08 +00001067
Duncan Sands2e033f32008-07-08 08:38:44 +00001068 /// removeParamAttr - removes the attribute from the list of attributes.
1069 void removeParamAttr(unsigned i, ParameterAttributes attr);
1070
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001071 /// @brief Determine whether the call or the callee has the given attribute.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001072 bool paramHasAttr(unsigned i, unsigned attr) const;
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00001073
Dale Johannesen08e78b12008-02-22 17:49:45 +00001074 /// @brief Extract the alignment for a call or parameter (0=unknown).
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001075 unsigned getParamAlignment(unsigned i) const {
1076 return ParamAttrs.getParamAlignment(i);
1077 }
Dale Johannesen08e78b12008-02-22 17:49:45 +00001078
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001079 /// @brief Determine if the call does not access memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001080 bool doesNotAccessMemory() const {
1081 return paramHasAttr(0, ParamAttr::ReadNone);
1082 }
Duncan Sands2e033f32008-07-08 08:38:44 +00001083 void setDoesNotAccessMemory(bool doesNotAccessMemory = true) {
1084 if (doesNotAccessMemory) addParamAttr(0, ParamAttr::ReadNone);
1085 else removeParamAttr(0, ParamAttr::ReadNone);
1086 }
1087
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001088 /// @brief Determine if the call does not access or only reads memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001089 bool onlyReadsMemory() const {
1090 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
1091 }
Duncan Sands2e033f32008-07-08 08:38:44 +00001092 void setOnlyReadsMemory(bool onlyReadsMemory = true) {
1093 if (onlyReadsMemory) addParamAttr(0, ParamAttr::ReadOnly);
1094 else removeParamAttr(0, ParamAttr::ReadOnly | ParamAttr::ReadNone);
1095 }
1096
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001097 /// @brief Determine if the call cannot return.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001098 bool doesNotReturn() const {
1099 return paramHasAttr(0, ParamAttr::NoReturn);
1100 }
Duncan Sands2e033f32008-07-08 08:38:44 +00001101 void setDoesNotReturn(bool doesNotReturn = true) {
1102 if (doesNotReturn) addParamAttr(0, ParamAttr::NoReturn);
1103 else removeParamAttr(0, ParamAttr::NoReturn);
1104 }
Duncan Sandscbb8bad2007-12-10 19:09:40 +00001105
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001106 /// @brief Determine if the call cannot unwind.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001107 bool doesNotThrow() const {
1108 return paramHasAttr(0, ParamAttr::NoUnwind);
1109 }
Duncan Sands2e033f32008-07-08 08:38:44 +00001110 void setDoesNotThrow(bool doesNotThrow = true) {
1111 if (doesNotThrow) addParamAttr(0, ParamAttr::NoUnwind);
1112 else removeParamAttr(0, ParamAttr::NoUnwind);
1113 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00001114
Devang Patel41e23972008-03-03 21:46:28 +00001115 /// @brief Determine if the call returns a structure through first
1116 /// pointer argument.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001117 bool hasStructRetAttr() const {
1118 // Be friendly and also check the callee.
1119 return paramHasAttr(1, ParamAttr::StructRet);
1120 }
Reid Spencer4746ecf2007-04-09 15:01:12 +00001121
Evan Chengf4a54982008-01-12 18:57:32 +00001122 /// @brief Determine if any call argument is an aggregate passed by value.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00001123 bool hasByValArgument() const {
1124 return ParamAttrs.hasAttrSomewhere(ParamAttr::ByVal);
1125 }
Evan Chengf4a54982008-01-12 18:57:32 +00001126
Chris Lattner721aef62004-11-18 17:46:57 +00001127 /// getCalledFunction - Return the function being called by this instruction
1128 /// if it is a direct call. If it is a call through a function pointer,
1129 /// return null.
1130 Function *getCalledFunction() const {
Dan Gohman11a7dbf2007-09-24 15:46:02 +00001131 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001132 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001133
Reid Spencerc25ec252006-12-29 04:10:59 +00001134 /// getCalledValue - Get a pointer to the function that is invoked by this
1135 /// instruction
Devang Patel4d4a5e02008-02-23 01:11:02 +00001136 const Value *getCalledValue() const { return getOperand(0); }
1137 Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001138
1139 // Methods for support type inquiry through isa, cast, and dyn_cast:
1140 static inline bool classof(const CallInst *) { return true; }
1141 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001142 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001143 }
1144 static inline bool classof(const Value *V) {
1145 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1146 }
1147};
1148
Gabor Greifefe65362008-05-10 08:32:32 +00001149template <>
1150struct OperandTraits<CallInst> : VariadicOperandTraits<1> {
1151};
1152
1153template<typename InputIterator>
1154CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1155 const std::string &Name, BasicBlock *InsertAtEnd)
1156 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1157 ->getElementType())->getReturnType(),
1158 Instruction::Call,
1159 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
Bill Wendling1b2f7292008-05-10 11:26:52 +00001160 (unsigned)(ArgEnd - ArgBegin + 1), InsertAtEnd) {
Gabor Greifefe65362008-05-10 08:32:32 +00001161 init(Func, ArgBegin, ArgEnd, Name,
1162 typename std::iterator_traits<InputIterator>::iterator_category());
1163}
1164
1165template<typename InputIterator>
1166CallInst::CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
1167 const std::string &Name, Instruction *InsertBefore)
1168 : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
1169 ->getElementType())->getReturnType(),
1170 Instruction::Call,
1171 OperandTraits<CallInst>::op_end(this) - (ArgEnd - ArgBegin + 1),
Bill Wendling1b2f7292008-05-10 11:26:52 +00001172 (unsigned)(ArgEnd - ArgBegin + 1), InsertBefore) {
Gabor Greifefe65362008-05-10 08:32:32 +00001173 init(Func, ArgBegin, ArgEnd, Name,
1174 typename std::iterator_traits<InputIterator>::iterator_category());
1175}
1176
1177DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
1178
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001179//===----------------------------------------------------------------------===//
1180// SelectInst Class
1181//===----------------------------------------------------------------------===//
1182
1183/// SelectInst - This class represents the LLVM 'select' instruction.
1184///
1185class SelectInst : public Instruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001186 void init(Value *C, Value *S1, Value *S2) {
Gabor Greifefe65362008-05-10 08:32:32 +00001187 Op<0>() = C;
1188 Op<1>() = S1;
1189 Op<2>() = S2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001190 }
1191
Chris Lattner454928e2005-01-29 00:31:36 +00001192 SelectInst(const SelectInst &SI)
Gabor Greifefe65362008-05-10 08:32:32 +00001193 : Instruction(SI.getType(), SI.getOpcode(), &Op<0>(), 3) {
1194 init(SI.Op<0>(), SI.Op<1>(), SI.Op<2>());
Chris Lattner454928e2005-01-29 00:31:36 +00001195 }
Gabor Greifefe65362008-05-10 08:32:32 +00001196 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1197 Instruction *InsertBefore)
1198 : Instruction(S1->getType(), Instruction::Select,
1199 &Op<0>(), 3, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001200 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +00001201 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001202 }
1203 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
1204 BasicBlock *InsertAtEnd)
Gabor Greifefe65362008-05-10 08:32:32 +00001205 : Instruction(S1->getType(), Instruction::Select,
1206 &Op<0>(), 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001207 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +00001208 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001209 }
Gabor Greif051a9502008-04-06 20:25:17 +00001210public:
Evan Chengd69bb1a2008-05-05 17:41:03 +00001211 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1212 const std::string &Name = "",
1213 Instruction *InsertBefore = 0) {
Gabor Greif051a9502008-04-06 20:25:17 +00001214 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1215 }
Evan Chengd69bb1a2008-05-05 17:41:03 +00001216 static SelectInst *Create(Value *C, Value *S1, Value *S2,
1217 const std::string &Name, BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00001218 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
1219 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001220
Gabor Greifefe65362008-05-10 08:32:32 +00001221 Value *getCondition() const { return Op<0>(); }
1222 Value *getTrueValue() const { return Op<1>(); }
1223 Value *getFalseValue() const { return Op<2>(); }
Chris Lattner454928e2005-01-29 00:31:36 +00001224
1225 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001226 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001227
1228 OtherOps getOpcode() const {
1229 return static_cast<OtherOps>(Instruction::getOpcode());
1230 }
1231
Chris Lattnerf319e832004-10-15 23:52:05 +00001232 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001233
1234 // Methods for support type inquiry through isa, cast, and dyn_cast:
1235 static inline bool classof(const SelectInst *) { return true; }
1236 static inline bool classof(const Instruction *I) {
1237 return I->getOpcode() == Instruction::Select;
1238 }
1239 static inline bool classof(const Value *V) {
1240 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1241 }
1242};
1243
Gabor Greifefe65362008-05-10 08:32:32 +00001244template <>
1245struct OperandTraits<SelectInst> : FixedNumOperandTraits<3> {
1246};
1247
1248DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
1249
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001250//===----------------------------------------------------------------------===//
1251// VAArgInst Class
1252//===----------------------------------------------------------------------===//
1253
1254/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +00001255/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001256///
Chris Lattner454928e2005-01-29 00:31:36 +00001257class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001258 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +00001259 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001260public:
1261 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
1262 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001263 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Chris Lattnerf00042a2007-02-13 07:54:42 +00001264 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001265 }
1266 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
1267 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001268 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Chris Lattnerf00042a2007-02-13 07:54:42 +00001269 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001270 }
1271
Chris Lattnerf319e832004-10-15 23:52:05 +00001272 virtual VAArgInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001273
1274 // Methods for support type inquiry through isa, cast, and dyn_cast:
1275 static inline bool classof(const VAArgInst *) { return true; }
1276 static inline bool classof(const Instruction *I) {
1277 return I->getOpcode() == VAArg;
1278 }
1279 static inline bool classof(const Value *V) {
1280 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1281 }
1282};
1283
1284//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +00001285// ExtractElementInst Class
1286//===----------------------------------------------------------------------===//
1287
1288/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001289/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +00001290///
1291class ExtractElementInst : public Instruction {
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001292 ExtractElementInst(const ExtractElementInst &EE) :
Gabor Greifefe65362008-05-10 08:32:32 +00001293 Instruction(EE.getType(), ExtractElement, &Op<0>(), 2) {
Gabor Greif6c80c382008-05-26 21:33:52 +00001294 Op<0>() = EE.Op<0>();
1295 Op<1>() = EE.Op<1>();
Robert Bocchino49b78a52006-01-10 19:04:13 +00001296 }
1297
1298public:
Gabor Greif051a9502008-04-06 20:25:17 +00001299 // allocate space for exactly two operands
1300 void *operator new(size_t s) {
Gabor Greifefe65362008-05-10 08:32:32 +00001301 return User::operator new(s, 2); // FIXME: "unsigned Idx" forms of ctor?
Gabor Greif051a9502008-04-06 20:25:17 +00001302 }
Chris Lattner9fc18d22006-04-08 01:15:18 +00001303 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
1304 Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +00001305 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
1306 Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001307 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
1308 BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +00001309 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
1310 BasicBlock *InsertAtEnd);
Robert Bocchino49b78a52006-01-10 19:04:13 +00001311
Chris Lattnerfa495842006-04-08 04:04:54 +00001312 /// isValidOperands - Return true if an extractelement instruction can be
1313 /// formed with the specified operands.
1314 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001315
Robert Bocchino49b78a52006-01-10 19:04:13 +00001316 virtual ExtractElementInst *clone() const;
1317
Robert Bocchino49b78a52006-01-10 19:04:13 +00001318 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001319 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Robert Bocchino49b78a52006-01-10 19:04:13 +00001320
1321 // Methods for support type inquiry through isa, cast, and dyn_cast:
1322 static inline bool classof(const ExtractElementInst *) { return true; }
1323 static inline bool classof(const Instruction *I) {
1324 return I->getOpcode() == Instruction::ExtractElement;
1325 }
1326 static inline bool classof(const Value *V) {
1327 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1328 }
1329};
1330
Gabor Greifefe65362008-05-10 08:32:32 +00001331template <>
1332struct OperandTraits<ExtractElementInst> : FixedNumOperandTraits<2> {
1333};
1334
1335DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
1336
Robert Bocchino49b78a52006-01-10 19:04:13 +00001337//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +00001338// InsertElementInst Class
1339//===----------------------------------------------------------------------===//
1340
1341/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +00001342/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +00001343///
1344class InsertElementInst : public Instruction {
Chris Lattner6a56ed42006-04-14 22:20:07 +00001345 InsertElementInst(const InsertElementInst &IE);
Gabor Greif051a9502008-04-06 20:25:17 +00001346 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1347 const std::string &Name = "",Instruction *InsertBefore = 0);
1348 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1349 const std::string &Name = "",Instruction *InsertBefore = 0);
1350 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
1351 const std::string &Name, BasicBlock *InsertAtEnd);
1352 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
1353 const std::string &Name, BasicBlock *InsertAtEnd);
Robert Bocchinof9993442006-01-17 20:05:59 +00001354public:
Gabor Greif051a9502008-04-06 20:25:17 +00001355 static InsertElementInst *Create(const InsertElementInst &IE) {
1356 return new(IE.getNumOperands()) InsertElementInst(IE);
1357 }
1358 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
Gabor Greifefe65362008-05-10 08:32:32 +00001359 const std::string &Name = "",
1360 Instruction *InsertBefore = 0) {
Gabor Greif051a9502008-04-06 20:25:17 +00001361 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1362 }
1363 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
Evan Chengd69bb1a2008-05-05 17:41:03 +00001364 const std::string &Name = "",
1365 Instruction *InsertBefore = 0) {
Gabor Greifefe65362008-05-10 08:32:32 +00001366 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00001367 }
1368 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
Evan Chengd69bb1a2008-05-05 17:41:03 +00001369 const std::string &Name,
1370 BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00001371 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1372 }
1373 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
Evan Chengd69bb1a2008-05-05 17:41:03 +00001374 const std::string &Name,
1375 BasicBlock *InsertAtEnd) {
Gabor Greifefe65362008-05-10 08:32:32 +00001376 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00001377 }
Robert Bocchinof9993442006-01-17 20:05:59 +00001378
Chris Lattnerfa495842006-04-08 04:04:54 +00001379 /// isValidOperands - Return true if an insertelement instruction can be
1380 /// formed with the specified operands.
1381 static bool isValidOperands(const Value *Vec, const Value *NewElt,
1382 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001383
Robert Bocchinof9993442006-01-17 20:05:59 +00001384 virtual InsertElementInst *clone() const;
1385
Reid Spencerac9dcb92007-02-15 03:39:18 +00001386 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001387 ///
Devang Patel4d4a5e02008-02-23 01:11:02 +00001388 const VectorType *getType() const {
Reid Spencer9d6565a2007-02-15 02:26:10 +00001389 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001390 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001391
Robert Bocchinof9993442006-01-17 20:05:59 +00001392 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001393 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Robert Bocchinof9993442006-01-17 20:05:59 +00001394
1395 // Methods for support type inquiry through isa, cast, and dyn_cast:
1396 static inline bool classof(const InsertElementInst *) { return true; }
1397 static inline bool classof(const Instruction *I) {
1398 return I->getOpcode() == Instruction::InsertElement;
1399 }
1400 static inline bool classof(const Value *V) {
1401 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1402 }
1403};
1404
Gabor Greifefe65362008-05-10 08:32:32 +00001405template <>
1406struct OperandTraits<InsertElementInst> : FixedNumOperandTraits<3> {
1407};
1408
1409DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
1410
Robert Bocchinof9993442006-01-17 20:05:59 +00001411//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +00001412// ShuffleVectorInst Class
1413//===----------------------------------------------------------------------===//
1414
1415/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
1416/// input vectors.
1417///
1418class ShuffleVectorInst : public Instruction {
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001419 ShuffleVectorInst(const ShuffleVectorInst &IE);
Chris Lattner9fc18d22006-04-08 01:15:18 +00001420public:
Gabor Greif051a9502008-04-06 20:25:17 +00001421 // allocate space for exactly three operands
1422 void *operator new(size_t s) {
1423 return User::operator new(s, 3);
1424 }
Chris Lattner9fc18d22006-04-08 01:15:18 +00001425 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1426 const std::string &Name = "", Instruction *InsertBefor = 0);
1427 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
1428 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001429
Chris Lattnerfa495842006-04-08 04:04:54 +00001430 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +00001431 /// formed with the specified operands.
1432 static bool isValidOperands(const Value *V1, const Value *V2,
1433 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001434
Chris Lattner9fc18d22006-04-08 01:15:18 +00001435 virtual ShuffleVectorInst *clone() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001436
Reid Spencerac9dcb92007-02-15 03:39:18 +00001437 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001438 ///
Devang Patel4d4a5e02008-02-23 01:11:02 +00001439 const VectorType *getType() const {
Reid Spencer9d6565a2007-02-15 02:26:10 +00001440 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001441 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001442
Chris Lattner9fc18d22006-04-08 01:15:18 +00001443 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00001444 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Chris Lattner8728f192008-03-02 05:28:33 +00001445
1446 /// getMaskValue - Return the index from the shuffle mask for the specified
1447 /// output result. This is either -1 if the element is undef or a number less
1448 /// than 2*numelements.
1449 int getMaskValue(unsigned i) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001450
Chris Lattner9fc18d22006-04-08 01:15:18 +00001451 // Methods for support type inquiry through isa, cast, and dyn_cast:
1452 static inline bool classof(const ShuffleVectorInst *) { return true; }
1453 static inline bool classof(const Instruction *I) {
1454 return I->getOpcode() == Instruction::ShuffleVector;
1455 }
1456 static inline bool classof(const Value *V) {
1457 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1458 }
1459};
1460
Gabor Greifefe65362008-05-10 08:32:32 +00001461template <>
1462struct OperandTraits<ShuffleVectorInst> : FixedNumOperandTraits<3> {
1463};
1464
1465DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
Chris Lattner9fc18d22006-04-08 01:15:18 +00001466
1467//===----------------------------------------------------------------------===//
Dan Gohman041e2eb2008-05-15 19:50:34 +00001468// ExtractValueInst Class
1469//===----------------------------------------------------------------------===//
1470
Dan Gohmane2d896f2008-05-15 23:35:32 +00001471/// ExtractValueInst - This instruction extracts a struct member or array
1472/// element value from an aggregate value.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001473///
Gabor Greifd4f268b2008-06-06 20:28:12 +00001474class ExtractValueInst : public UnaryInstruction {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001475 SmallVector<unsigned, 4> Indices;
1476
Dan Gohman041e2eb2008-05-15 19:50:34 +00001477 ExtractValueInst(const ExtractValueInst &EVI);
Gabor Greif76aca6f2008-06-06 21:06:32 +00001478 void init(const unsigned *Idx, unsigned NumIdx,
Matthijs Kooijmancfd5b7d2008-06-05 07:26:15 +00001479 const std::string &Name);
Gabor Greif76aca6f2008-06-06 21:06:32 +00001480 void init(unsigned Idx, const std::string &Name);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001481
1482 template<typename InputIterator>
Gabor Greif76aca6f2008-06-06 21:06:32 +00001483 void init(InputIterator IdxBegin, InputIterator IdxEnd,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001484 const std::string &Name,
1485 // This argument ensures that we have an iterator we can
1486 // do arithmetic on in constant time
1487 std::random_access_iterator_tag) {
1488 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1489
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001490 // There's no fundamental reason why we require at least one index
1491 // (other than weirdness with &*IdxBegin being invalid; see
1492 // getelementptr's init routine for example). But there's no
1493 // present need to support it.
1494 assert(NumIdx > 0 && "ExtractValueInst must have at least one index");
1495
1496 // This requires that the iterator points to contiguous memory.
Gabor Greif76aca6f2008-06-06 21:06:32 +00001497 init(&*IdxBegin, NumIdx, Name); // FIXME: for the general case
Matthijs Kooijman444099f62008-06-04 14:40:55 +00001498 // we have to build an array here
Dan Gohman041e2eb2008-05-15 19:50:34 +00001499 }
1500
1501 /// getIndexedType - Returns the type of the element that would be extracted
1502 /// with an extractvalue instruction with the specified parameters.
1503 ///
Dan Gohmane2d896f2008-05-15 23:35:32 +00001504 /// Null is returned if the indices are invalid for the specified
Dan Gohman041e2eb2008-05-15 19:50:34 +00001505 /// pointer type.
1506 ///
1507 static const Type *getIndexedType(const Type *Agg,
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001508 const unsigned *Idx, unsigned NumIdx);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001509
1510 template<typename InputIterator>
1511 static const Type *getIndexedType(const Type *Ptr,
1512 InputIterator IdxBegin,
1513 InputIterator IdxEnd,
1514 // This argument ensures that we
1515 // have an iterator we can do
1516 // arithmetic on in constant time
1517 std::random_access_iterator_tag) {
1518 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1519
1520 if (NumIdx > 0)
1521 // This requires that the iterator points to contiguous memory.
Dan Gohman19a81632008-06-23 16:38:10 +00001522 return getIndexedType(Ptr, &*IdxBegin, NumIdx);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001523 else
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001524 return getIndexedType(Ptr, (const unsigned *)0, NumIdx);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001525 }
1526
Dan Gohmane2d896f2008-05-15 23:35:32 +00001527 /// Constructors - Create a extractvalue instruction with a base aggregate
1528 /// value and a list of indices. The first ctor can optionally insert before
1529 /// an existing instruction, the second appends the new instruction to the
1530 /// specified BasicBlock.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001531 template<typename InputIterator>
1532 inline ExtractValueInst(Value *Agg, InputIterator IdxBegin,
1533 InputIterator IdxEnd,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001534 const std::string &Name,
1535 Instruction *InsertBefore);
1536 template<typename InputIterator>
1537 inline ExtractValueInst(Value *Agg,
1538 InputIterator IdxBegin, InputIterator IdxEnd,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001539 const std::string &Name, BasicBlock *InsertAtEnd);
1540
Dan Gohman8e640412008-05-31 19:09:47 +00001541 // allocate space for exactly one operand
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001542 void *operator new(size_t s) {
1543 return User::operator new(s, 1);
1544 }
1545
Gabor Greifd4f268b2008-06-06 20:28:12 +00001546public:
Dan Gohman041e2eb2008-05-15 19:50:34 +00001547 template<typename InputIterator>
1548 static ExtractValueInst *Create(Value *Agg, InputIterator IdxBegin,
1549 InputIterator IdxEnd,
1550 const std::string &Name = "",
1551 Instruction *InsertBefore = 0) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001552 return new
1553 ExtractValueInst(Agg, IdxBegin, IdxEnd, Name, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001554 }
1555 template<typename InputIterator>
1556 static ExtractValueInst *Create(Value *Agg,
1557 InputIterator IdxBegin, InputIterator IdxEnd,
1558 const std::string &Name,
1559 BasicBlock *InsertAtEnd) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001560 return new ExtractValueInst(Agg, IdxBegin, IdxEnd, Name, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001561 }
1562
1563 /// Constructors - These two creators are convenience methods because one
1564 /// index extractvalue instructions are much more common than those with
1565 /// more than one.
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001566 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001567 const std::string &Name = "",
1568 Instruction *InsertBefore = 0) {
Dan Gohman2f27e172008-06-23 16:48:17 +00001569 unsigned Idxs[1] = { Idx };
1570 return new ExtractValueInst(Agg, Idxs, Idxs + 1, Name, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001571 }
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001572 static ExtractValueInst *Create(Value *Agg, unsigned Idx,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001573 const std::string &Name,
1574 BasicBlock *InsertAtEnd) {
Dan Gohman2f27e172008-06-23 16:48:17 +00001575 unsigned Idxs[1] = { Idx };
1576 return new ExtractValueInst(Agg, Idxs, Idxs + 1, Name, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001577 }
1578
1579 virtual ExtractValueInst *clone() const;
1580
Dan Gohman041e2eb2008-05-15 19:50:34 +00001581 // getType - Overload to return most specific pointer type...
1582 const PointerType *getType() const {
1583 return reinterpret_cast<const PointerType*>(Instruction::getType());
1584 }
1585
1586 /// getIndexedType - Returns the type of the element that would be extracted
1587 /// with an extractvalue instruction with the specified parameters.
1588 ///
Dan Gohmane2d896f2008-05-15 23:35:32 +00001589 /// Null is returned if the indices are invalid for the specified
Dan Gohman041e2eb2008-05-15 19:50:34 +00001590 /// pointer type.
1591 ///
1592 template<typename InputIterator>
1593 static const Type *getIndexedType(const Type *Ptr,
1594 InputIterator IdxBegin,
1595 InputIterator IdxEnd) {
1596 return getIndexedType(Ptr, IdxBegin, IdxEnd,
1597 typename std::iterator_traits<InputIterator>::
1598 iterator_category());
1599 }
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001600 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001601
Owen Anderson5678d6e2008-06-19 17:15:57 +00001602 typedef const unsigned* idx_iterator;
1603 inline idx_iterator idx_begin() const { return Indices.begin(); }
1604 inline idx_iterator idx_end() const { return Indices.end(); }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001605
1606 Value *getAggregateOperand() {
1607 return getOperand(0);
1608 }
1609 const Value *getAggregateOperand() const {
1610 return getOperand(0);
1611 }
1612 static unsigned getAggregateOperandIndex() {
1613 return 0U; // get index for modifying correct operand
1614 }
1615
1616 unsigned getNumIndices() const { // Note: always non-negative
Bill Wendling67944fc2008-06-05 07:35:27 +00001617 return (unsigned)Indices.size();
Dan Gohman041e2eb2008-05-15 19:50:34 +00001618 }
1619
1620 bool hasIndices() const {
Dan Gohman35651cd2008-05-31 19:09:08 +00001621 return true;
Dan Gohman041e2eb2008-05-15 19:50:34 +00001622 }
1623
1624 // Methods for support type inquiry through isa, cast, and dyn_cast:
1625 static inline bool classof(const ExtractValueInst *) { return true; }
1626 static inline bool classof(const Instruction *I) {
1627 return I->getOpcode() == Instruction::ExtractValue;
1628 }
1629 static inline bool classof(const Value *V) {
1630 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1631 }
1632};
1633
Dan Gohmane4569942008-05-23 00:36:11 +00001634template<typename InputIterator>
1635ExtractValueInst::ExtractValueInst(Value *Agg,
1636 InputIterator IdxBegin,
1637 InputIterator IdxEnd,
Dan Gohmane4569942008-05-23 00:36:11 +00001638 const std::string &Name,
1639 Instruction *InsertBefore)
Gabor Greifd4f268b2008-06-06 20:28:12 +00001640 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1641 IdxBegin, IdxEnd)),
1642 ExtractValue, Agg, InsertBefore) {
Gabor Greif76aca6f2008-06-06 21:06:32 +00001643 init(IdxBegin, IdxEnd, Name,
Dan Gohmane4569942008-05-23 00:36:11 +00001644 typename std::iterator_traits<InputIterator>::iterator_category());
1645}
1646template<typename InputIterator>
1647ExtractValueInst::ExtractValueInst(Value *Agg,
1648 InputIterator IdxBegin,
1649 InputIterator IdxEnd,
Dan Gohmane4569942008-05-23 00:36:11 +00001650 const std::string &Name,
1651 BasicBlock *InsertAtEnd)
Gabor Greifd4f268b2008-06-06 20:28:12 +00001652 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
1653 IdxBegin, IdxEnd)),
1654 ExtractValue, Agg, InsertAtEnd) {
Gabor Greif76aca6f2008-06-06 21:06:32 +00001655 init(IdxBegin, IdxEnd, Name,
Dan Gohmane4569942008-05-23 00:36:11 +00001656 typename std::iterator_traits<InputIterator>::iterator_category());
1657}
1658
Dan Gohmane4569942008-05-23 00:36:11 +00001659
Dan Gohman041e2eb2008-05-15 19:50:34 +00001660//===----------------------------------------------------------------------===//
1661// InsertValueInst Class
1662//===----------------------------------------------------------------------===//
1663
Dan Gohmane2d896f2008-05-15 23:35:32 +00001664/// InsertValueInst - This instruction inserts a struct field of array element
1665/// value into an aggregate value.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001666///
1667class InsertValueInst : public Instruction {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001668 SmallVector<unsigned, 4> Indices;
1669
1670 void *operator new(size_t, unsigned); // Do not implement
Dan Gohman041e2eb2008-05-15 19:50:34 +00001671 InsertValueInst(const InsertValueInst &IVI);
Matthijs Kooijmancfd5b7d2008-06-05 07:26:15 +00001672 void init(Value *Agg, Value *Val, const unsigned *Idx, unsigned NumIdx,
1673 const std::string &Name);
Matthijs Kooijman444099f62008-06-04 14:40:55 +00001674 void init(Value *Agg, Value *Val, unsigned Idx, const std::string &Name);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001675
1676 template<typename InputIterator>
1677 void init(Value *Agg, Value *Val,
1678 InputIterator IdxBegin, InputIterator IdxEnd,
1679 const std::string &Name,
1680 // This argument ensures that we have an iterator we can
1681 // do arithmetic on in constant time
1682 std::random_access_iterator_tag) {
1683 unsigned NumIdx = static_cast<unsigned>(std::distance(IdxBegin, IdxEnd));
1684
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001685 // There's no fundamental reason why we require at least one index
1686 // (other than weirdness with &*IdxBegin being invalid; see
1687 // getelementptr's init routine for example). But there's no
1688 // present need to support it.
1689 assert(NumIdx > 0 && "InsertValueInst must have at least one index");
1690
1691 // This requires that the iterator points to contiguous memory.
Matthijs Kooijman444099f62008-06-04 14:40:55 +00001692 init(Agg, Val, &*IdxBegin, NumIdx, Name); // FIXME: for the general case
1693 // we have to build an array here
Dan Gohman041e2eb2008-05-15 19:50:34 +00001694 }
1695
Dan Gohmane2d896f2008-05-15 23:35:32 +00001696 /// Constructors - Create a insertvalue instruction with a base aggregate
1697 /// value, a value to insert, and a list of indices. The first ctor can
1698 /// optionally insert before an existing instruction, the second appends
1699 /// the new instruction to the specified BasicBlock.
Dan Gohman041e2eb2008-05-15 19:50:34 +00001700 template<typename InputIterator>
1701 inline InsertValueInst(Value *Agg, Value *Val, InputIterator IdxBegin,
Dan Gohmane2d896f2008-05-15 23:35:32 +00001702 InputIterator IdxEnd,
Dan Gohmane2d896f2008-05-15 23:35:32 +00001703 const std::string &Name,
1704 Instruction *InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001705 template<typename InputIterator>
1706 inline InsertValueInst(Value *Agg, Value *Val,
Dan Gohmane2d896f2008-05-15 23:35:32 +00001707 InputIterator IdxBegin, InputIterator IdxEnd,
Dan Gohmane2d896f2008-05-15 23:35:32 +00001708 const std::string &Name, BasicBlock *InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001709
1710 /// Constructors - These two constructors are convenience methods because one
1711 /// and two index insertvalue instructions are so common.
1712 InsertValueInst(Value *Agg, Value *Val,
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001713 unsigned Idx, const std::string &Name = "",
Dan Gohman041e2eb2008-05-15 19:50:34 +00001714 Instruction *InsertBefore = 0);
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001715 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001716 const std::string &Name, BasicBlock *InsertAtEnd);
1717public:
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001718 // allocate space for exactly two operands
1719 void *operator new(size_t s) {
1720 return User::operator new(s, 2);
1721 }
1722
Dan Gohman041e2eb2008-05-15 19:50:34 +00001723 template<typename InputIterator>
Matthijs Kooijmancfd5b7d2008-06-05 07:26:15 +00001724 static InsertValueInst *Create(Value *Agg, Value *Val, InputIterator IdxBegin,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001725 InputIterator IdxEnd,
1726 const std::string &Name = "",
1727 Instruction *InsertBefore = 0) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001728 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1729 Name, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001730 }
1731 template<typename InputIterator>
1732 static InsertValueInst *Create(Value *Agg, Value *Val,
1733 InputIterator IdxBegin, InputIterator IdxEnd,
1734 const std::string &Name,
1735 BasicBlock *InsertAtEnd) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001736 return new InsertValueInst(Agg, Val, IdxBegin, IdxEnd,
1737 Name, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001738 }
1739
1740 /// Constructors - These two creators are convenience methods because one
1741 /// index insertvalue instructions are much more common than those with
1742 /// more than one.
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001743 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001744 const std::string &Name = "",
1745 Instruction *InsertBefore = 0) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001746 return new InsertValueInst(Agg, Val, Idx, Name, InsertBefore);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001747 }
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001748 static InsertValueInst *Create(Value *Agg, Value *Val, unsigned Idx,
Dan Gohman041e2eb2008-05-15 19:50:34 +00001749 const std::string &Name,
1750 BasicBlock *InsertAtEnd) {
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001751 return new InsertValueInst(Agg, Val, Idx, Name, InsertAtEnd);
Dan Gohman041e2eb2008-05-15 19:50:34 +00001752 }
1753
1754 virtual InsertValueInst *clone() const;
1755
1756 /// Transparently provide more efficient getOperand methods.
1757 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1758
1759 // getType - Overload to return most specific pointer type...
1760 const PointerType *getType() const {
1761 return reinterpret_cast<const PointerType*>(Instruction::getType());
1762 }
1763
Owen Anderson5678d6e2008-06-19 17:15:57 +00001764 typedef const unsigned* idx_iterator;
1765 inline idx_iterator idx_begin() const { return Indices.begin(); }
1766 inline idx_iterator idx_end() const { return Indices.end(); }
Dan Gohman041e2eb2008-05-15 19:50:34 +00001767
1768 Value *getAggregateOperand() {
1769 return getOperand(0);
1770 }
1771 const Value *getAggregateOperand() const {
1772 return getOperand(0);
1773 }
1774 static unsigned getAggregateOperandIndex() {
1775 return 0U; // get index for modifying correct operand
1776 }
1777
1778 Value *getInsertedValueOperand() {
1779 return getOperand(1);
1780 }
1781 const Value *getInsertedValueOperand() const {
1782 return getOperand(1);
1783 }
1784 static unsigned getInsertedValueOperandIndex() {
1785 return 1U; // get index for modifying correct operand
1786 }
1787
1788 unsigned getNumIndices() const { // Note: always non-negative
Bill Wendling67944fc2008-06-05 07:35:27 +00001789 return (unsigned)Indices.size();
Dan Gohman041e2eb2008-05-15 19:50:34 +00001790 }
1791
1792 bool hasIndices() const {
Dan Gohman35651cd2008-05-31 19:09:08 +00001793 return true;
Dan Gohman041e2eb2008-05-15 19:50:34 +00001794 }
1795
1796 // Methods for support type inquiry through isa, cast, and dyn_cast:
1797 static inline bool classof(const InsertValueInst *) { return true; }
1798 static inline bool classof(const Instruction *I) {
1799 return I->getOpcode() == Instruction::InsertValue;
1800 }
1801 static inline bool classof(const Value *V) {
1802 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1803 }
1804};
1805
1806template <>
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001807struct OperandTraits<InsertValueInst> : FixedNumOperandTraits<2> {
Dan Gohman041e2eb2008-05-15 19:50:34 +00001808};
1809
Dan Gohmane4569942008-05-23 00:36:11 +00001810template<typename InputIterator>
1811InsertValueInst::InsertValueInst(Value *Agg,
1812 Value *Val,
1813 InputIterator IdxBegin,
1814 InputIterator IdxEnd,
Dan Gohmane4569942008-05-23 00:36:11 +00001815 const std::string &Name,
1816 Instruction *InsertBefore)
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001817 : Instruction(Agg->getType(), InsertValue,
1818 OperandTraits<InsertValueInst>::op_begin(this),
1819 2, InsertBefore) {
Dan Gohmane4569942008-05-23 00:36:11 +00001820 init(Agg, Val, IdxBegin, IdxEnd, Name,
1821 typename std::iterator_traits<InputIterator>::iterator_category());
1822}
1823template<typename InputIterator>
1824InsertValueInst::InsertValueInst(Value *Agg,
1825 Value *Val,
1826 InputIterator IdxBegin,
1827 InputIterator IdxEnd,
Dan Gohmane4569942008-05-23 00:36:11 +00001828 const std::string &Name,
1829 BasicBlock *InsertAtEnd)
Dan Gohman81a0c0b2008-05-31 00:58:22 +00001830 : Instruction(Agg->getType(), InsertValue,
1831 OperandTraits<InsertValueInst>::op_begin(this),
1832 2, InsertAtEnd) {
Dan Gohmane4569942008-05-23 00:36:11 +00001833 init(Agg, Val, IdxBegin, IdxEnd, Name,
1834 typename std::iterator_traits<InputIterator>::iterator_category());
1835}
1836
Dan Gohman041e2eb2008-05-15 19:50:34 +00001837DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
1838
1839//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001840// PHINode Class
1841//===----------------------------------------------------------------------===//
1842
1843// PHINode - The PHINode class is used to represent the magical mystical PHI
1844// node, that can not exist in nature, but can be synthesized in a computer
1845// scientist's overactive imagination.
1846//
1847class PHINode : public Instruction {
Gabor Greif051a9502008-04-06 20:25:17 +00001848 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner454928e2005-01-29 00:31:36 +00001849 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1850 /// the number actually in use.
1851 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001852 PHINode(const PHINode &PN);
Gabor Greif051a9502008-04-06 20:25:17 +00001853 // allocate space for exactly zero operands
1854 void *operator new(size_t s) {
1855 return User::operator new(s, 0);
1856 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001857 explicit PHINode(const Type *Ty, const std::string &Name = "",
1858 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001859 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Chris Lattner454928e2005-01-29 00:31:36 +00001860 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001861 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001862 }
1863
1864 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001865 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Chris Lattner454928e2005-01-29 00:31:36 +00001866 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001867 setName(Name);
Chris Lattner454928e2005-01-29 00:31:36 +00001868 }
Gabor Greif051a9502008-04-06 20:25:17 +00001869public:
1870 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1871 Instruction *InsertBefore = 0) {
1872 return new PHINode(Ty, Name, InsertBefore);
1873 }
Evan Chengd69bb1a2008-05-05 17:41:03 +00001874 static PHINode *Create(const Type *Ty, const std::string &Name,
1875 BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00001876 return new PHINode(Ty, Name, InsertAtEnd);
1877 }
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00001878 ~PHINode();
1879
Chris Lattner454928e2005-01-29 00:31:36 +00001880 /// reserveOperandSpace - This method can be used to avoid repeated
1881 /// reallocation of PHI operand lists by reserving space for the correct
1882 /// number of operands before adding them. Unlike normal vector reserves,
1883 /// this method can also be used to trim the operand space.
1884 void reserveOperandSpace(unsigned NumValues) {
1885 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001886 }
1887
Chris Lattnerf319e832004-10-15 23:52:05 +00001888 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001889
Gabor Greifefe65362008-05-10 08:32:32 +00001890 /// Provide fast operand accessors
1891 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1892
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001893 /// getNumIncomingValues - Return the number of incoming edges
1894 ///
Chris Lattner454928e2005-01-29 00:31:36 +00001895 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001896
Reid Spencerc773de62006-05-19 19:07:54 +00001897 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001898 ///
1899 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001900 assert(i*2 < getNumOperands() && "Invalid value number!");
1901 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001902 }
1903 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +00001904 assert(i*2 < getNumOperands() && "Invalid value number!");
1905 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001906 }
Chris Lattner454928e2005-01-29 00:31:36 +00001907 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001908 return i*2;
1909 }
1910
Reid Spencerc773de62006-05-19 19:07:54 +00001911 /// getIncomingBlock - Return incoming basic block number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001912 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00001913 BasicBlock *getIncomingBlock(unsigned i) const {
Gabor Greifefe65362008-05-10 08:32:32 +00001914 return static_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001915 }
1916 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Gabor Greifefe65362008-05-10 08:32:32 +00001917 setOperand(i*2+1, BB);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001918 }
1919 unsigned getOperandNumForIncomingBlock(unsigned i) {
1920 return i*2+1;
1921 }
1922
1923 /// addIncoming - Add an incoming value to the end of the PHI list
1924 ///
1925 void addIncoming(Value *V, BasicBlock *BB) {
Anton Korobeynikov351b0d42008-02-27 22:37:28 +00001926 assert(V && "PHI node got a null value!");
1927 assert(BB && "PHI node got a null basic block!");
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001928 assert(getType() == V->getType() &&
1929 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +00001930 unsigned OpNo = NumOperands;
1931 if (OpNo+2 > ReservedSpace)
1932 resizeOperands(0); // Get more space!
1933 // Initialize some new operands.
1934 NumOperands = OpNo+2;
Gabor Greif6c80c382008-05-26 21:33:52 +00001935 OperandList[OpNo] = V;
1936 OperandList[OpNo+1] = BB;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001937 }
Misha Brukman9769ab22005-04-21 20:19:05 +00001938
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001939 /// removeIncomingValue - Remove an incoming value. This is useful if a
1940 /// predecessor basic block is deleted. The value removed is returned.
1941 ///
1942 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1943 /// is true), the PHI node is destroyed and any uses of it are replaced with
1944 /// dummy values. The only time there should be zero incoming values to a PHI
1945 /// node is when the block is dead, so this strategy is sound.
1946 ///
1947 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1948
Gabor Greifefe65362008-05-10 08:32:32 +00001949 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001950 int Idx = getBasicBlockIndex(BB);
1951 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1952 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1953 }
1954
Misha Brukman9769ab22005-04-21 20:19:05 +00001955 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001956 /// block in the value list for this PHI. Returns -1 if no instance.
1957 ///
1958 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001959 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +00001960 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Gabor Greifefe65362008-05-10 08:32:32 +00001961 if (OL[i+1].get() == BB) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001962 return -1;
1963 }
1964
1965 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1966 return getIncomingValue(getBasicBlockIndex(BB));
1967 }
1968
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001969 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00001970 /// same value, return the value, otherwise return null.
1971 ///
Chris Lattner9acbd612005-08-05 00:49:06 +00001972 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001973
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001974 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1975 static inline bool classof(const PHINode *) { return true; }
1976 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001977 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001978 }
1979 static inline bool classof(const Value *V) {
1980 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1981 }
Chris Lattner454928e2005-01-29 00:31:36 +00001982 private:
1983 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001984};
1985
Gabor Greifefe65362008-05-10 08:32:32 +00001986template <>
1987struct OperandTraits<PHINode> : HungoffOperandTraits<2> {
1988};
1989
1990DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
1991
1992
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001993//===----------------------------------------------------------------------===//
1994// ReturnInst Class
1995//===----------------------------------------------------------------------===//
1996
1997//===---------------------------------------------------------------------------
1998/// ReturnInst - Return a value (possibly void), from a function. Execution
1999/// does not continue in this function any longer.
2000///
2001class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00002002 ReturnInst(const ReturnInst &RI);
Devang Patelfea98302008-02-26 19:15:26 +00002003 void init(Value * const* retVals, unsigned N);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002004
Gabor Greif051a9502008-04-06 20:25:17 +00002005private:
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002006 // ReturnInst constructors:
2007 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00002008 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002009 // ReturnInst(Value* X) - 'ret X' instruction
Gabor Greifefe65362008-05-10 08:32:32 +00002010 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002011 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
Gabor Greifefe65362008-05-10 08:32:32 +00002012 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
2013 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
Devang Patele6be34a2008-02-27 01:20:54 +00002014 // ReturnInst(Value* X, N) - 'ret X,X+1...X+N-1' instruction
Gabor Greifefe65362008-05-10 08:32:32 +00002015 // ReturnInst(Value* X, N, Inst *I) - 'ret X,X+1...X+N-1', insert before I
2016 // ReturnInst(Value* X, N, BB *B) - 'ret X,X+1...X+N-1', insert @ end of B
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00002017 //
2018 // NOTE: If the Value* passed is of type void then the constructor behaves as
2019 // if it was passed NULL.
Chris Lattner910c80a2007-02-24 00:55:48 +00002020 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
2021 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
Gabor Greifefe65362008-05-10 08:32:32 +00002022 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore = 0);
Devang Patelf4511cd2008-02-26 19:38:17 +00002023 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
Chris Lattner910c80a2007-02-24 00:55:48 +00002024 explicit ReturnInst(BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002025public:
2026 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
2027 return new(!!retVal) ReturnInst(retVal, InsertBefore);
2028 }
2029 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
2030 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
2031 }
Evan Chengd69bb1a2008-05-05 17:41:03 +00002032 static ReturnInst* Create(Value * const* retVals, unsigned N,
Gabor Greifefe65362008-05-10 08:32:32 +00002033 Instruction *InsertBefore = 0) {
Gabor Greif051a9502008-04-06 20:25:17 +00002034 return new(N) ReturnInst(retVals, N, InsertBefore);
2035 }
Evan Chengd69bb1a2008-05-05 17:41:03 +00002036 static ReturnInst* Create(Value * const* retVals, unsigned N,
2037 BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00002038 return new(N) ReturnInst(retVals, N, InsertAtEnd);
2039 }
2040 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
2041 return new(0) ReturnInst(InsertAtEnd);
2042 }
Devang Patel57ef4f42008-02-23 00:35:18 +00002043 virtual ~ReturnInst();
Gabor Greifefe65362008-05-10 08:32:32 +00002044 inline void operator delete(void*);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002045
Chris Lattnerf319e832004-10-15 23:52:05 +00002046 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002047
Gabor Greifefe65362008-05-10 08:32:32 +00002048 /// Provide fast operand accessors
2049 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Devang Patel64d4e612008-02-26 17:56:20 +00002050
Gabor Greifefe65362008-05-10 08:32:32 +00002051 /// Convenience accessor
Devang Patel1eafa062008-03-11 17:35:03 +00002052 Value *getReturnValue(unsigned n = 0) const {
Gabor Greifefe65362008-05-10 08:32:32 +00002053 return n < getNumOperands()
2054 ? getOperand(n)
2055 : 0;
Devang Patel1eafa062008-03-11 17:35:03 +00002056 }
2057
Chris Lattner454928e2005-01-29 00:31:36 +00002058 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002059
2060 // Methods for support type inquiry through isa, cast, and dyn_cast:
2061 static inline bool classof(const ReturnInst *) { return true; }
2062 static inline bool classof(const Instruction *I) {
2063 return (I->getOpcode() == Instruction::Ret);
2064 }
2065 static inline bool classof(const Value *V) {
2066 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2067 }
Chris Lattner454928e2005-01-29 00:31:36 +00002068 private:
2069 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2070 virtual unsigned getNumSuccessorsV() const;
2071 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002072};
2073
Gabor Greifefe65362008-05-10 08:32:32 +00002074template <>
2075struct OperandTraits<ReturnInst> : VariadicOperandTraits<> {
2076};
2077
2078DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
2079void ReturnInst::operator delete(void *it) {
2080 ReturnInst* me(static_cast<ReturnInst*>(it));
2081 Use::zap(OperandTraits<ReturnInst>::op_begin(me),
2082 OperandTraits<ReturnInst>::op_end(me),
2083 true);
2084}
2085
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002086//===----------------------------------------------------------------------===//
2087// BranchInst Class
2088//===----------------------------------------------------------------------===//
2089
2090//===---------------------------------------------------------------------------
2091/// BranchInst - Conditional or Unconditional Branch instruction.
2092///
2093class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00002094 /// Ops list - Branches are strange. The operands are ordered:
2095 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
2096 /// they don't have to check for cond/uncond branchness.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002097 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00002098 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002099 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
2100 // BranchInst(BB *B) - 'br B'
2101 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
2102 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
2103 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
2104 // BranchInst(BB* B, BB *I) - 'br B' insert at end
2105 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00002106 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002107 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00002108 Instruction *InsertBefore = 0);
2109 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002110 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00002111 BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002112public:
2113 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
2114 return new(1) BranchInst(IfTrue, InsertBefore);
2115 }
Gabor Greifefe65362008-05-10 08:32:32 +00002116 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2117 Value *Cond, Instruction *InsertBefore = 0) {
Gabor Greif051a9502008-04-06 20:25:17 +00002118 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
2119 }
2120 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
2121 return new(1) BranchInst(IfTrue, InsertAtEnd);
2122 }
Gabor Greifefe65362008-05-10 08:32:32 +00002123 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
2124 Value *Cond, BasicBlock *InsertAtEnd) {
Gabor Greif051a9502008-04-06 20:25:17 +00002125 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
2126 }
Chris Lattner454928e2005-01-29 00:31:36 +00002127
Bill Wendlingd2a5a2a2008-05-10 10:58:07 +00002128 ~BranchInst() {
Gabor Greifefe65362008-05-10 08:32:32 +00002129 if (NumOperands == 1)
Bill Wendlingc2e73532008-05-10 19:59:59 +00002130 NumOperands = (unsigned)((Use*)this - OperandList);
Gabor Greifefe65362008-05-10 08:32:32 +00002131 }
2132
Chris Lattner454928e2005-01-29 00:31:36 +00002133 /// Transparently provide more efficient getOperand methods.
Gabor Greifefe65362008-05-10 08:32:32 +00002134 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002135
Chris Lattnerf319e832004-10-15 23:52:05 +00002136 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002137
Devang Patel4d4a5e02008-02-23 01:11:02 +00002138 bool isUnconditional() const { return getNumOperands() == 1; }
2139 bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002140
Devang Patel4d4a5e02008-02-23 01:11:02 +00002141 Value *getCondition() const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002142 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00002143 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002144 }
2145
2146 void setCondition(Value *V) {
2147 assert(isConditional() && "Cannot set condition of unconditional branch!");
2148 setOperand(2, V);
2149 }
2150
2151 // setUnconditionalDest - Change the current branch to an unconditional branch
2152 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +00002153 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002154 void setUnconditionalDest(BasicBlock *Dest) {
Gabor Greifefe65362008-05-10 08:32:32 +00002155 Op<0>() = Dest;
Chris Lattner454928e2005-01-29 00:31:36 +00002156 if (isConditional()) { // Convert this to an uncond branch.
Gabor Greifefe65362008-05-10 08:32:32 +00002157 Op<1>().set(0);
2158 Op<2>().set(0);
Chris Lattner454928e2005-01-29 00:31:36 +00002159 NumOperands = 1;
Chris Lattner454928e2005-01-29 00:31:36 +00002160 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002161 }
2162
Chris Lattner454928e2005-01-29 00:31:36 +00002163 unsigned getNumSuccessors() const { return 1+isConditional(); }
2164
2165 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002166 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Dan Gohmanb96039e2007-05-11 20:59:29 +00002167 return cast<BasicBlock>(getOperand(i));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002168 }
2169
Chris Lattner454928e2005-01-29 00:31:36 +00002170 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002171 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Gabor Greifefe65362008-05-10 08:32:32 +00002172 setOperand(idx, NewSucc);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002173 }
2174
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002175 // Methods for support type inquiry through isa, cast, and dyn_cast:
2176 static inline bool classof(const BranchInst *) { return true; }
2177 static inline bool classof(const Instruction *I) {
2178 return (I->getOpcode() == Instruction::Br);
2179 }
2180 static inline bool classof(const Value *V) {
2181 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2182 }
Chris Lattner454928e2005-01-29 00:31:36 +00002183private:
2184 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2185 virtual unsigned getNumSuccessorsV() const;
2186 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002187};
2188
Gabor Greifefe65362008-05-10 08:32:32 +00002189template <>
2190struct OperandTraits<BranchInst> : HungoffOperandTraits<> {
2191 // we need to access operands via OperandList, since
2192 // the NumOperands may change from 3 to 1
2193 static inline void *allocate(unsigned); // FIXME
2194};
2195
2196DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
2197
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002198//===----------------------------------------------------------------------===//
2199// SwitchInst Class
2200//===----------------------------------------------------------------------===//
2201
2202//===---------------------------------------------------------------------------
2203/// SwitchInst - Multiway switch
2204///
2205class SwitchInst : public TerminatorInst {
Gabor Greifefe65362008-05-10 08:32:32 +00002206 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner454928e2005-01-29 00:31:36 +00002207 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002208 // Operand[0] = Value to switch on
2209 // Operand[1] = Default basic block destination
2210 // Operand[2n ] = Value to match
2211 // Operand[2n+1] = BasicBlock to go to on match
2212 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00002213 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
2214 void resizeOperands(unsigned No);
Gabor Greifefe65362008-05-10 08:32:32 +00002215 // allocate space for exactly zero operands
2216 void *operator new(size_t s) {
2217 return User::operator new(s, 0);
2218 }
Chris Lattner454928e2005-01-29 00:31:36 +00002219 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2220 /// switch on and a default destination. The number of additional cases can
2221 /// be specified here to make memory allocation more efficient. This
2222 /// constructor can also autoinsert before another instruction.
2223 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00002224 Instruction *InsertBefore = 0);
2225
Chris Lattner454928e2005-01-29 00:31:36 +00002226 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
2227 /// switch on and a default destination. The number of additional cases can
2228 /// be specified here to make memory allocation more efficient. This
2229 /// constructor also autoinserts at the end of the specified BasicBlock.
2230 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00002231 BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002232public:
Gabor Greifefe65362008-05-10 08:32:32 +00002233 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2234 unsigned NumCases, Instruction *InsertBefore = 0) {
2235 return new SwitchInst(Value, Default, NumCases, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002236 }
Gabor Greifefe65362008-05-10 08:32:32 +00002237 static SwitchInst *Create(Value *Value, BasicBlock *Default,
2238 unsigned NumCases, BasicBlock *InsertAtEnd) {
2239 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002240 }
Gordon Henriksenafba8fe2007-12-10 02:14:30 +00002241 ~SwitchInst();
Chris Lattner454928e2005-01-29 00:31:36 +00002242
Gabor Greifefe65362008-05-10 08:32:32 +00002243 /// Provide fast operand accessors
2244 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2245
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002246 // Accessor Methods for Switch stmt
Devang Patel4d4a5e02008-02-23 01:11:02 +00002247 Value *getCondition() const { return getOperand(0); }
Chris Lattner454928e2005-01-29 00:31:36 +00002248 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00002249
Devang Patel4d4a5e02008-02-23 01:11:02 +00002250 BasicBlock *getDefaultDest() const {
Chris Lattner454928e2005-01-29 00:31:36 +00002251 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002252 }
2253
2254 /// getNumCases - return the number of 'cases' in this switch instruction.
2255 /// Note that case #0 is always the default case.
2256 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00002257 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002258 }
2259
2260 /// getCaseValue - Return the specified case value. Note that case #0, the
2261 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002262 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002263 assert(i && i < getNumCases() && "Illegal case value to get!");
2264 return getSuccessorValue(i);
2265 }
2266
2267 /// getCaseValue - Return the specified case value. Note that case #0, the
2268 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002269 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002270 assert(i && i < getNumCases() && "Illegal case value to get!");
2271 return getSuccessorValue(i);
2272 }
2273
2274 /// findCaseValue - Search all of the case values for the specified constant.
2275 /// If it is explicitly handled, return the case number of it, otherwise
2276 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00002277 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002278 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
2279 if (getCaseValue(i) == C)
2280 return i;
2281 return 0;
2282 }
2283
Nick Lewycky011f1842006-09-18 19:03:59 +00002284 /// findCaseDest - Finds the unique case value for a given successor. Returns
2285 /// null if the successor is not found, not unique, or is the default case.
2286 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00002287 if (BB == getDefaultDest()) return NULL;
2288
Nick Lewycky011f1842006-09-18 19:03:59 +00002289 ConstantInt *CI = NULL;
2290 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
2291 if (getSuccessor(i) == BB) {
2292 if (CI) return NULL; // Multiple cases lead to BB.
2293 else CI = getCaseValue(i);
2294 }
2295 }
2296 return CI;
2297 }
2298
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002299 /// addCase - Add an entry to the switch instruction...
2300 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00002301 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002302
2303 /// removeCase - This method removes the specified successor from the switch
2304 /// instruction. Note that this cannot be used to remove the default
2305 /// destination (successor #0).
2306 ///
2307 void removeCase(unsigned idx);
2308
Chris Lattner454928e2005-01-29 00:31:36 +00002309 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002310
Chris Lattner454928e2005-01-29 00:31:36 +00002311 unsigned getNumSuccessors() const { return getNumOperands()/2; }
2312 BasicBlock *getSuccessor(unsigned idx) const {
2313 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
2314 return cast<BasicBlock>(getOperand(idx*2+1));
2315 }
2316 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002317 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Gabor Greifefe65362008-05-10 08:32:32 +00002318 setOperand(idx*2+1, NewSucc);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002319 }
2320
2321 // getSuccessorValue - Return the value associated with the specified
2322 // successor.
Devang Patel4d4a5e02008-02-23 01:11:02 +00002323 ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002324 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00002325 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002326 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002327
2328 // Methods for support type inquiry through isa, cast, and dyn_cast:
2329 static inline bool classof(const SwitchInst *) { return true; }
2330 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00002331 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002332 }
2333 static inline bool classof(const Value *V) {
2334 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2335 }
Chris Lattner454928e2005-01-29 00:31:36 +00002336private:
2337 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2338 virtual unsigned getNumSuccessorsV() const;
2339 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002340};
2341
Gabor Greifefe65362008-05-10 08:32:32 +00002342template <>
2343struct OperandTraits<SwitchInst> : HungoffOperandTraits<2> {
2344};
2345
2346DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
2347
2348
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002349//===----------------------------------------------------------------------===//
2350// InvokeInst Class
2351//===----------------------------------------------------------------------===//
2352
Chris Lattner3340ffe2005-05-06 20:26:26 +00002353/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
2354/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002355///
2356class InvokeInst : public TerminatorInst {
Chris Lattner58d74912008-03-12 17:45:29 +00002357 PAListPtr ParamAttrs;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002358 InvokeInst(const InvokeInst &BI);
2359 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00002360 Value* const *Args, unsigned NumArgs);
David Greenef1355a52007-08-27 19:04:21 +00002361
2362 template<typename InputIterator>
2363 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2364 InputIterator ArgBegin, InputIterator ArgEnd,
2365 const std::string &Name,
2366 // This argument ensures that we have an iterator we can
2367 // do arithmetic on in constant time
2368 std::random_access_iterator_tag) {
Chris Lattnera5c0d1e2007-08-29 16:32:50 +00002369 unsigned NumArgs = (unsigned)std::distance(ArgBegin, ArgEnd);
David Greenef1355a52007-08-27 19:04:21 +00002370
Chris Lattnera5c0d1e2007-08-29 16:32:50 +00002371 // This requires that the iterator points to contiguous memory.
2372 init(Func, IfNormal, IfException, NumArgs ? &*ArgBegin : 0, NumArgs);
David Greenef1355a52007-08-27 19:04:21 +00002373 setName(Name);
2374 }
2375
David Greenef1355a52007-08-27 19:04:21 +00002376 /// Construct an InvokeInst given a range of arguments.
2377 /// InputIterator must be a random-access iterator pointing to
2378 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2379 /// made for random-accessness but not for contiguous storage as
2380 /// that would incur runtime overhead.
2381 ///
2382 /// @brief Construct an InvokeInst from a range of arguments
2383 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00002384 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2385 InputIterator ArgBegin, InputIterator ArgEnd,
2386 unsigned Values,
2387 const std::string &Name, Instruction *InsertBefore);
David Greenef1355a52007-08-27 19:04:21 +00002388
2389 /// Construct an InvokeInst given a range of arguments.
2390 /// InputIterator must be a random-access iterator pointing to
2391 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
2392 /// made for random-accessness but not for contiguous storage as
2393 /// that would incur runtime overhead.
2394 ///
2395 /// @brief Construct an InvokeInst from a range of arguments
2396 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00002397 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
2398 InputIterator ArgBegin, InputIterator ArgEnd,
2399 unsigned Values,
2400 const std::string &Name, BasicBlock *InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002401public:
2402 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00002403 static InvokeInst *Create(Value *Func,
2404 BasicBlock *IfNormal, BasicBlock *IfException,
Gabor Greif051a9502008-04-06 20:25:17 +00002405 InputIterator ArgBegin, InputIterator ArgEnd,
Evan Chengd69bb1a2008-05-05 17:41:03 +00002406 const std::string &Name = "",
2407 Instruction *InsertBefore = 0) {
Gabor Greifefe65362008-05-10 08:32:32 +00002408 unsigned Values(ArgEnd - ArgBegin + 3);
2409 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2410 Values, Name, InsertBefore);
Gabor Greif051a9502008-04-06 20:25:17 +00002411 }
2412 template<typename InputIterator>
Gabor Greifefe65362008-05-10 08:32:32 +00002413 static InvokeInst *Create(Value *Func,
2414 BasicBlock *IfNormal, BasicBlock *IfException,
Gabor Greif051a9502008-04-06 20:25:17 +00002415 InputIterator ArgBegin, InputIterator ArgEnd,
2416 const std::string &Name, BasicBlock *InsertAtEnd) {
Gabor Greifefe65362008-05-10 08:32:32 +00002417 unsigned Values(ArgEnd - ArgBegin + 3);
2418 return new(Values) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd,
2419 Values, Name, InsertAtEnd);
Gabor Greif051a9502008-04-06 20:25:17 +00002420 }
David Greenef1355a52007-08-27 19:04:21 +00002421
Chris Lattnerf319e832004-10-15 23:52:05 +00002422 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002423
Gabor Greifefe65362008-05-10 08:32:32 +00002424 /// Provide fast operand accessors
2425 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
2426
Chris Lattner3340ffe2005-05-06 20:26:26 +00002427 /// getCallingConv/setCallingConv - Get or set the calling convention of this
2428 /// function call.
2429 unsigned getCallingConv() const { return SubclassData; }
2430 void setCallingConv(unsigned CC) {
2431 SubclassData = CC;
2432 }
2433
Chris Lattner041221c2008-03-13 04:33:03 +00002434 /// getParamAttrs - Return the parameter attributes for this invoke.
Chris Lattner58d74912008-03-12 17:45:29 +00002435 ///
2436 const PAListPtr &getParamAttrs() const { return ParamAttrs; }
Reid Spencerfa3e9122007-04-09 18:00:57 +00002437
Chris Lattner041221c2008-03-13 04:33:03 +00002438 /// setParamAttrs - Set the parameter attributes for this invoke.
Chris Lattner58d74912008-03-12 17:45:29 +00002439 ///
2440 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
Duncan Sandsdc024672007-11-27 13:23:08 +00002441
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00002442 /// @brief Determine whether the call or the callee has the given attribute.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002443 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
Eric Christopher0bf7b412008-05-16 20:39:43 +00002444
2445 /// addParamAttr - adds the attribute to the list of attributes.
2446 void addParamAttr(unsigned i, ParameterAttributes attr);
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00002447
Duncan Sands2e033f32008-07-08 08:38:44 +00002448 /// removeParamAttr - removes the attribute from the list of attributes.
2449 void removeParamAttr(unsigned i, ParameterAttributes attr);
2450
Dale Johannesen08e78b12008-02-22 17:49:45 +00002451 /// @brief Extract the alignment for a call or parameter (0=unknown).
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002452 unsigned getParamAlignment(unsigned i) const {
2453 return ParamAttrs.getParamAlignment(i);
2454 }
Dale Johannesen08e78b12008-02-22 17:49:45 +00002455
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002456 /// @brief Determine if the call does not access memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002457 bool doesNotAccessMemory() const {
2458 return paramHasAttr(0, ParamAttr::ReadNone);
2459 }
Duncan Sands2e033f32008-07-08 08:38:44 +00002460 void setDoesNotAccessMemory(bool doesNotAccessMemory = true) {
2461 if (doesNotAccessMemory) addParamAttr(0, ParamAttr::ReadNone);
2462 else removeParamAttr(0, ParamAttr::ReadNone);
2463 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002464
2465 /// @brief Determine if the call does not access or only reads memory.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002466 bool onlyReadsMemory() const {
2467 return doesNotAccessMemory() || paramHasAttr(0, ParamAttr::ReadOnly);
2468 }
Duncan Sands2e033f32008-07-08 08:38:44 +00002469 void setOnlyReadsMemory(bool onlyReadsMemory = true) {
2470 if (onlyReadsMemory) addParamAttr(0, ParamAttr::ReadOnly);
2471 else removeParamAttr(0, ParamAttr::ReadOnly | ParamAttr::ReadNone);
2472 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002473
Duncan Sandscbb8bad2007-12-10 19:09:40 +00002474 /// @brief Determine if the call cannot return.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002475 bool doesNotReturn() const {
2476 return paramHasAttr(0, ParamAttr::NoReturn);
2477 }
Duncan Sands2e033f32008-07-08 08:38:44 +00002478 void setDoesNotReturn(bool doesNotReturn = true) {
2479 if (doesNotReturn) addParamAttr(0, ParamAttr::NoReturn);
2480 else removeParamAttr(0, ParamAttr::NoReturn);
2481 }
Duncan Sandscbb8bad2007-12-10 19:09:40 +00002482
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002483 /// @brief Determine if the call cannot unwind.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002484 bool doesNotThrow() const {
2485 return paramHasAttr(0, ParamAttr::NoUnwind);
2486 }
Duncan Sands2e033f32008-07-08 08:38:44 +00002487 void setDoesNotThrow(bool doesNotThrow = true) {
2488 if (doesNotThrow) addParamAttr(0, ParamAttr::NoUnwind);
2489 else removeParamAttr(0, ParamAttr::NoUnwind);
2490 }
Duncan Sandsa3355ff2007-12-03 20:06:50 +00002491
Devang Patel41e23972008-03-03 21:46:28 +00002492 /// @brief Determine if the call returns a structure through first
2493 /// pointer argument.
Chris Lattnerd5d94df2008-03-13 05:00:21 +00002494 bool hasStructRetAttr() const {
2495 // Be friendly and also check the callee.
2496 return paramHasAttr(1, ParamAttr::StructRet);
2497 }
Reid Spencerfa3e9122007-04-09 18:00:57 +00002498
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002499 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00002500 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002501 ///
Chris Lattner721aef62004-11-18 17:46:57 +00002502 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00002503 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00002504 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002505
2506 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Devang Patel4d4a5e02008-02-23 01:11:02 +00002507 Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002508
2509 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00002510 BasicBlock *getNormalDest() const {
2511 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002512 }
Chris Lattner454928e2005-01-29 00:31:36 +00002513 BasicBlock *getUnwindDest() const {
2514 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002515 }
Chris Lattner454928e2005-01-29 00:31:36 +00002516 void setNormalDest(BasicBlock *B) {
Gabor Greifefe65362008-05-10 08:32:32 +00002517 setOperand(1, B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002518 }
2519
Chris Lattner454928e2005-01-29 00:31:36 +00002520 void setUnwindDest(BasicBlock *B) {
Gabor Greifefe65362008-05-10 08:32:32 +00002521 setOperand(2, B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002522 }
2523
Devang Patel4d4a5e02008-02-23 01:11:02 +00002524 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002525 assert(i < 2 && "Successor # out of range for invoke!");
2526 return i == 0 ? getNormalDest() : getUnwindDest();
2527 }
2528
Chris Lattner454928e2005-01-29 00:31:36 +00002529 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002530 assert(idx < 2 && "Successor # out of range for invoke!");
Gabor Greifefe65362008-05-10 08:32:32 +00002531 setOperand(idx+1, NewSucc);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002532 }
2533
Chris Lattner454928e2005-01-29 00:31:36 +00002534 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002535
2536 // Methods for support type inquiry through isa, cast, and dyn_cast:
2537 static inline bool classof(const InvokeInst *) { return true; }
2538 static inline bool classof(const Instruction *I) {
2539 return (I->getOpcode() == Instruction::Invoke);
2540 }
2541 static inline bool classof(const Value *V) {
2542 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2543 }
Chris Lattner454928e2005-01-29 00:31:36 +00002544private:
2545 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2546 virtual unsigned getNumSuccessorsV() const;
2547 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002548};
2549
Gabor Greifefe65362008-05-10 08:32:32 +00002550template <>
2551struct OperandTraits<InvokeInst> : VariadicOperandTraits<3> {
2552};
2553
2554template<typename InputIterator>
2555InvokeInst::InvokeInst(Value *Func,
2556 BasicBlock *IfNormal, BasicBlock *IfException,
2557 InputIterator ArgBegin, InputIterator ArgEnd,
2558 unsigned Values,
2559 const std::string &Name, Instruction *InsertBefore)
2560 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2561 ->getElementType())->getReturnType(),
2562 Instruction::Invoke,
2563 OperandTraits<InvokeInst>::op_end(this) - Values,
2564 Values, InsertBefore) {
2565 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2566 typename std::iterator_traits<InputIterator>::iterator_category());
2567}
2568template<typename InputIterator>
2569InvokeInst::InvokeInst(Value *Func,
2570 BasicBlock *IfNormal, BasicBlock *IfException,
2571 InputIterator ArgBegin, InputIterator ArgEnd,
2572 unsigned Values,
2573 const std::string &Name, BasicBlock *InsertAtEnd)
2574 : TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
2575 ->getElementType())->getReturnType(),
2576 Instruction::Invoke,
2577 OperandTraits<InvokeInst>::op_end(this) - Values,
2578 Values, InsertAtEnd) {
2579 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
2580 typename std::iterator_traits<InputIterator>::iterator_category());
2581}
2582
2583DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002584
2585//===----------------------------------------------------------------------===//
2586// UnwindInst Class
2587//===----------------------------------------------------------------------===//
2588
2589//===---------------------------------------------------------------------------
2590/// UnwindInst - Immediately exit the current function, unwinding the stack
2591/// until an invoke instruction is found.
2592///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002593class UnwindInst : public TerminatorInst {
Gabor Greif051a9502008-04-06 20:25:17 +00002594 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002595public:
Gabor Greif051a9502008-04-06 20:25:17 +00002596 // allocate space for exactly zero operands
2597 void *operator new(size_t s) {
2598 return User::operator new(s, 0);
2599 }
Chris Lattner910c80a2007-02-24 00:55:48 +00002600 explicit UnwindInst(Instruction *InsertBefore = 0);
2601 explicit UnwindInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002602
Chris Lattnerf319e832004-10-15 23:52:05 +00002603 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002604
Chris Lattner454928e2005-01-29 00:31:36 +00002605 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002606
2607 // Methods for support type inquiry through isa, cast, and dyn_cast:
2608 static inline bool classof(const UnwindInst *) { return true; }
2609 static inline bool classof(const Instruction *I) {
2610 return I->getOpcode() == Instruction::Unwind;
2611 }
2612 static inline bool classof(const Value *V) {
2613 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2614 }
Chris Lattner454928e2005-01-29 00:31:36 +00002615private:
2616 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2617 virtual unsigned getNumSuccessorsV() const;
2618 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002619};
2620
Chris Lattner076b3f12004-10-16 18:05:54 +00002621//===----------------------------------------------------------------------===//
2622// UnreachableInst Class
2623//===----------------------------------------------------------------------===//
2624
2625//===---------------------------------------------------------------------------
2626/// UnreachableInst - This function has undefined behavior. In particular, the
2627/// presence of this instruction indicates some higher level knowledge that the
2628/// end of the block cannot be reached.
2629///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002630class UnreachableInst : public TerminatorInst {
Gabor Greif051a9502008-04-06 20:25:17 +00002631 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Chris Lattner1fca5ff2004-10-27 16:14:51 +00002632public:
Gabor Greif051a9502008-04-06 20:25:17 +00002633 // allocate space for exactly zero operands
2634 void *operator new(size_t s) {
2635 return User::operator new(s, 0);
2636 }
Chris Lattner910c80a2007-02-24 00:55:48 +00002637 explicit UnreachableInst(Instruction *InsertBefore = 0);
2638 explicit UnreachableInst(BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00002639
2640 virtual UnreachableInst *clone() const;
2641
Chris Lattner454928e2005-01-29 00:31:36 +00002642 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00002643
2644 // Methods for support type inquiry through isa, cast, and dyn_cast:
2645 static inline bool classof(const UnreachableInst *) { return true; }
2646 static inline bool classof(const Instruction *I) {
2647 return I->getOpcode() == Instruction::Unreachable;
2648 }
2649 static inline bool classof(const Value *V) {
2650 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2651 }
Chris Lattner454928e2005-01-29 00:31:36 +00002652private:
2653 virtual BasicBlock *getSuccessorV(unsigned idx) const;
2654 virtual unsigned getNumSuccessorsV() const;
2655 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00002656};
2657
Reid Spencer3da59db2006-11-27 01:05:10 +00002658//===----------------------------------------------------------------------===//
2659// TruncInst Class
2660//===----------------------------------------------------------------------===//
2661
2662/// @brief This class represents a truncation of integer types.
2663class TruncInst : public CastInst {
2664 /// Private copy constructor
2665 TruncInst(const TruncInst &CI)
2666 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
2667 }
2668public:
2669 /// @brief Constructor with insert-before-instruction semantics
2670 TruncInst(
2671 Value *S, ///< The value to be truncated
2672 const Type *Ty, ///< The (smaller) type to truncate to
2673 const std::string &Name = "", ///< A name for the new instruction
2674 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2675 );
2676
2677 /// @brief Constructor with insert-at-end-of-block semantics
2678 TruncInst(
2679 Value *S, ///< The value to be truncated
2680 const Type *Ty, ///< The (smaller) type to truncate to
2681 const std::string &Name, ///< A name for the new instruction
2682 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2683 );
2684
2685 /// @brief Clone an identical TruncInst
2686 virtual CastInst *clone() const;
2687
2688 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2689 static inline bool classof(const TruncInst *) { return true; }
2690 static inline bool classof(const Instruction *I) {
2691 return I->getOpcode() == Trunc;
2692 }
2693 static inline bool classof(const Value *V) {
2694 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2695 }
2696};
2697
2698//===----------------------------------------------------------------------===//
2699// ZExtInst Class
2700//===----------------------------------------------------------------------===//
2701
2702/// @brief This class represents zero extension of integer types.
2703class ZExtInst : public CastInst {
2704 /// @brief Private copy constructor
2705 ZExtInst(const ZExtInst &CI)
2706 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
2707 }
2708public:
2709 /// @brief Constructor with insert-before-instruction semantics
2710 ZExtInst(
2711 Value *S, ///< The value to be zero extended
2712 const Type *Ty, ///< The type to zero extend to
2713 const std::string &Name = "", ///< A name for the new instruction
2714 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2715 );
2716
2717 /// @brief Constructor with insert-at-end semantics.
2718 ZExtInst(
2719 Value *S, ///< The value to be zero extended
2720 const Type *Ty, ///< The type to zero extend to
2721 const std::string &Name, ///< A name for the new instruction
2722 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2723 );
2724
2725 /// @brief Clone an identical ZExtInst
2726 virtual CastInst *clone() const;
2727
2728 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2729 static inline bool classof(const ZExtInst *) { return true; }
2730 static inline bool classof(const Instruction *I) {
2731 return I->getOpcode() == ZExt;
2732 }
2733 static inline bool classof(const Value *V) {
2734 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2735 }
2736};
2737
2738//===----------------------------------------------------------------------===//
2739// SExtInst Class
2740//===----------------------------------------------------------------------===//
2741
2742/// @brief This class represents a sign extension of integer types.
2743class SExtInst : public CastInst {
2744 /// @brief Private copy constructor
2745 SExtInst(const SExtInst &CI)
2746 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
2747 }
2748public:
2749 /// @brief Constructor with insert-before-instruction semantics
2750 SExtInst(
2751 Value *S, ///< The value to be sign extended
2752 const Type *Ty, ///< The type to sign extend to
2753 const std::string &Name = "", ///< A name for the new instruction
2754 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2755 );
2756
2757 /// @brief Constructor with insert-at-end-of-block semantics
2758 SExtInst(
2759 Value *S, ///< The value to be sign extended
2760 const Type *Ty, ///< The type to sign extend to
2761 const std::string &Name, ///< A name for the new instruction
2762 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2763 );
2764
2765 /// @brief Clone an identical SExtInst
2766 virtual CastInst *clone() const;
2767
2768 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2769 static inline bool classof(const SExtInst *) { return true; }
2770 static inline bool classof(const Instruction *I) {
2771 return I->getOpcode() == SExt;
2772 }
2773 static inline bool classof(const Value *V) {
2774 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2775 }
2776};
2777
2778//===----------------------------------------------------------------------===//
2779// FPTruncInst Class
2780//===----------------------------------------------------------------------===//
2781
2782/// @brief This class represents a truncation of floating point types.
2783class FPTruncInst : public CastInst {
2784 FPTruncInst(const FPTruncInst &CI)
2785 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
2786 }
2787public:
2788 /// @brief Constructor with insert-before-instruction semantics
2789 FPTruncInst(
2790 Value *S, ///< The value to be truncated
2791 const Type *Ty, ///< The type to truncate to
2792 const std::string &Name = "", ///< A name for the new instruction
2793 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2794 );
2795
2796 /// @brief Constructor with insert-before-instruction semantics
2797 FPTruncInst(
2798 Value *S, ///< The value to be truncated
2799 const Type *Ty, ///< The type to truncate to
2800 const std::string &Name, ///< A name for the new instruction
2801 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2802 );
2803
2804 /// @brief Clone an identical FPTruncInst
2805 virtual CastInst *clone() const;
2806
2807 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2808 static inline bool classof(const FPTruncInst *) { return true; }
2809 static inline bool classof(const Instruction *I) {
2810 return I->getOpcode() == FPTrunc;
2811 }
2812 static inline bool classof(const Value *V) {
2813 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2814 }
2815};
2816
2817//===----------------------------------------------------------------------===//
2818// FPExtInst Class
2819//===----------------------------------------------------------------------===//
2820
2821/// @brief This class represents an extension of floating point types.
2822class FPExtInst : public CastInst {
2823 FPExtInst(const FPExtInst &CI)
2824 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
2825 }
2826public:
2827 /// @brief Constructor with insert-before-instruction semantics
2828 FPExtInst(
2829 Value *S, ///< The value to be extended
2830 const Type *Ty, ///< The type to extend to
2831 const std::string &Name = "", ///< A name for the new instruction
2832 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2833 );
2834
2835 /// @brief Constructor with insert-at-end-of-block semantics
2836 FPExtInst(
2837 Value *S, ///< The value to be extended
2838 const Type *Ty, ///< The type to extend to
2839 const std::string &Name, ///< A name for the new instruction
2840 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2841 );
2842
2843 /// @brief Clone an identical FPExtInst
2844 virtual CastInst *clone() const;
2845
2846 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2847 static inline bool classof(const FPExtInst *) { return true; }
2848 static inline bool classof(const Instruction *I) {
2849 return I->getOpcode() == FPExt;
2850 }
2851 static inline bool classof(const Value *V) {
2852 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2853 }
2854};
2855
2856//===----------------------------------------------------------------------===//
2857// UIToFPInst Class
2858//===----------------------------------------------------------------------===//
2859
2860/// @brief This class represents a cast unsigned integer to floating point.
2861class UIToFPInst : public CastInst {
2862 UIToFPInst(const UIToFPInst &CI)
2863 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
2864 }
2865public:
2866 /// @brief Constructor with insert-before-instruction semantics
2867 UIToFPInst(
2868 Value *S, ///< The value to be converted
2869 const Type *Ty, ///< The type to convert to
2870 const std::string &Name = "", ///< A name for the new instruction
2871 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2872 );
2873
2874 /// @brief Constructor with insert-at-end-of-block semantics
2875 UIToFPInst(
2876 Value *S, ///< The value to be converted
2877 const Type *Ty, ///< The type to convert to
2878 const std::string &Name, ///< A name for the new instruction
2879 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2880 );
2881
2882 /// @brief Clone an identical UIToFPInst
2883 virtual CastInst *clone() const;
2884
2885 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2886 static inline bool classof(const UIToFPInst *) { return true; }
2887 static inline bool classof(const Instruction *I) {
2888 return I->getOpcode() == UIToFP;
2889 }
2890 static inline bool classof(const Value *V) {
2891 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2892 }
2893};
2894
2895//===----------------------------------------------------------------------===//
2896// SIToFPInst Class
2897//===----------------------------------------------------------------------===//
2898
2899/// @brief This class represents a cast from signed integer to floating point.
2900class SIToFPInst : public CastInst {
2901 SIToFPInst(const SIToFPInst &CI)
2902 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
2903 }
2904public:
2905 /// @brief Constructor with insert-before-instruction semantics
2906 SIToFPInst(
2907 Value *S, ///< The value to be converted
2908 const Type *Ty, ///< The type to convert to
2909 const std::string &Name = "", ///< A name for the new instruction
2910 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2911 );
2912
2913 /// @brief Constructor with insert-at-end-of-block semantics
2914 SIToFPInst(
2915 Value *S, ///< The value to be converted
2916 const Type *Ty, ///< The type to convert to
2917 const std::string &Name, ///< A name for the new instruction
2918 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2919 );
2920
2921 /// @brief Clone an identical SIToFPInst
2922 virtual CastInst *clone() const;
2923
2924 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2925 static inline bool classof(const SIToFPInst *) { return true; }
2926 static inline bool classof(const Instruction *I) {
2927 return I->getOpcode() == SIToFP;
2928 }
2929 static inline bool classof(const Value *V) {
2930 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2931 }
2932};
2933
2934//===----------------------------------------------------------------------===//
2935// FPToUIInst Class
2936//===----------------------------------------------------------------------===//
2937
2938/// @brief This class represents a cast from floating point to unsigned integer
2939class FPToUIInst : public CastInst {
2940 FPToUIInst(const FPToUIInst &CI)
2941 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
2942 }
2943public:
2944 /// @brief Constructor with insert-before-instruction semantics
2945 FPToUIInst(
2946 Value *S, ///< The value to be converted
2947 const Type *Ty, ///< The type to convert to
2948 const std::string &Name = "", ///< A name for the new instruction
2949 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2950 );
2951
2952 /// @brief Constructor with insert-at-end-of-block semantics
2953 FPToUIInst(
2954 Value *S, ///< The value to be converted
2955 const Type *Ty, ///< The type to convert to
2956 const std::string &Name, ///< A name for the new instruction
2957 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
2958 );
2959
2960 /// @brief Clone an identical FPToUIInst
2961 virtual CastInst *clone() const;
2962
2963 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
2964 static inline bool classof(const FPToUIInst *) { return true; }
2965 static inline bool classof(const Instruction *I) {
2966 return I->getOpcode() == FPToUI;
2967 }
2968 static inline bool classof(const Value *V) {
2969 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2970 }
2971};
2972
2973//===----------------------------------------------------------------------===//
2974// FPToSIInst Class
2975//===----------------------------------------------------------------------===//
2976
2977/// @brief This class represents a cast from floating point to signed integer.
2978class FPToSIInst : public CastInst {
2979 FPToSIInst(const FPToSIInst &CI)
2980 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
2981 }
2982public:
2983 /// @brief Constructor with insert-before-instruction semantics
2984 FPToSIInst(
2985 Value *S, ///< The value to be converted
2986 const Type *Ty, ///< The type to convert to
2987 const std::string &Name = "", ///< A name for the new instruction
2988 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2989 );
2990
2991 /// @brief Constructor with insert-at-end-of-block semantics
2992 FPToSIInst(
2993 Value *S, ///< The value to be converted
2994 const Type *Ty, ///< The type to convert to
2995 const std::string &Name, ///< A name for the new instruction
2996 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2997 );
2998
2999 /// @brief Clone an identical FPToSIInst
3000 virtual CastInst *clone() const;
3001
3002 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
3003 static inline bool classof(const FPToSIInst *) { return true; }
3004 static inline bool classof(const Instruction *I) {
3005 return I->getOpcode() == FPToSI;
3006 }
3007 static inline bool classof(const Value *V) {
3008 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3009 }
3010};
3011
3012//===----------------------------------------------------------------------===//
3013// IntToPtrInst Class
3014//===----------------------------------------------------------------------===//
3015
3016/// @brief This class represents a cast from an integer to a pointer.
3017class IntToPtrInst : public CastInst {
3018 IntToPtrInst(const IntToPtrInst &CI)
3019 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
3020 }
3021public:
3022 /// @brief Constructor with insert-before-instruction semantics
3023 IntToPtrInst(
3024 Value *S, ///< The value to be converted
3025 const Type *Ty, ///< The type to convert to
3026 const std::string &Name = "", ///< A name for the new instruction
3027 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3028 );
3029
3030 /// @brief Constructor with insert-at-end-of-block semantics
3031 IntToPtrInst(
3032 Value *S, ///< The value to be converted
3033 const Type *Ty, ///< The type to convert to
3034 const std::string &Name, ///< A name for the new instruction
3035 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3036 );
3037
3038 /// @brief Clone an identical IntToPtrInst
3039 virtual CastInst *clone() const;
3040
3041 // Methods for support type inquiry through isa, cast, and dyn_cast:
3042 static inline bool classof(const IntToPtrInst *) { return true; }
3043 static inline bool classof(const Instruction *I) {
3044 return I->getOpcode() == IntToPtr;
3045 }
3046 static inline bool classof(const Value *V) {
3047 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3048 }
3049};
3050
3051//===----------------------------------------------------------------------===//
3052// PtrToIntInst Class
3053//===----------------------------------------------------------------------===//
3054
3055/// @brief This class represents a cast from a pointer to an integer
3056class PtrToIntInst : public CastInst {
3057 PtrToIntInst(const PtrToIntInst &CI)
3058 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
3059 }
3060public:
3061 /// @brief Constructor with insert-before-instruction semantics
3062 PtrToIntInst(
3063 Value *S, ///< The value to be converted
3064 const Type *Ty, ///< The type to convert to
3065 const std::string &Name = "", ///< A name for the new instruction
3066 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3067 );
3068
3069 /// @brief Constructor with insert-at-end-of-block semantics
3070 PtrToIntInst(
3071 Value *S, ///< The value to be converted
3072 const Type *Ty, ///< The type to convert to
3073 const std::string &Name, ///< A name for the new instruction
3074 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3075 );
3076
3077 /// @brief Clone an identical PtrToIntInst
3078 virtual CastInst *clone() const;
3079
3080 // Methods for support type inquiry through isa, cast, and dyn_cast:
3081 static inline bool classof(const PtrToIntInst *) { return true; }
3082 static inline bool classof(const Instruction *I) {
3083 return I->getOpcode() == PtrToInt;
3084 }
3085 static inline bool classof(const Value *V) {
3086 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3087 }
3088};
3089
3090//===----------------------------------------------------------------------===//
3091// BitCastInst Class
3092//===----------------------------------------------------------------------===//
3093
3094/// @brief This class represents a no-op cast from one type to another.
3095class BitCastInst : public CastInst {
3096 BitCastInst(const BitCastInst &CI)
3097 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
3098 }
3099public:
3100 /// @brief Constructor with insert-before-instruction semantics
3101 BitCastInst(
3102 Value *S, ///< The value to be casted
3103 const Type *Ty, ///< The type to casted to
3104 const std::string &Name = "", ///< A name for the new instruction
3105 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3106 );
3107
3108 /// @brief Constructor with insert-at-end-of-block semantics
3109 BitCastInst(
3110 Value *S, ///< The value to be casted
3111 const Type *Ty, ///< The type to casted to
3112 const std::string &Name, ///< A name for the new instruction
3113 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3114 );
3115
3116 /// @brief Clone an identical BitCastInst
3117 virtual CastInst *clone() const;
3118
3119 // Methods for support type inquiry through isa, cast, and dyn_cast:
3120 static inline bool classof(const BitCastInst *) { return true; }
3121 static inline bool classof(const Instruction *I) {
3122 return I->getOpcode() == BitCast;
3123 }
3124 static inline bool classof(const Value *V) {
3125 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3126 }
3127};
3128
Devang Patel40a04212008-02-19 22:15:16 +00003129//===----------------------------------------------------------------------===//
3130// GetResultInst Class
3131//===----------------------------------------------------------------------===//
3132
3133/// GetResultInst - This instruction extracts individual result value from
3134/// aggregate value, where aggregate value is returned by CallInst.
3135///
Gabor Greifd6a22182008-05-13 07:09:08 +00003136class GetResultInst : public UnaryInstruction {
Devang Patel23755d82008-02-20 19:10:47 +00003137 unsigned Idx;
Devang Patel40a04212008-02-19 22:15:16 +00003138 GetResultInst(const GetResultInst &GRI) :
Gabor Greifd6a22182008-05-13 07:09:08 +00003139 UnaryInstruction(GRI.getType(), Instruction::GetResult, GRI.getOperand(0)),
3140 Idx(GRI.Idx) {
Devang Patel40a04212008-02-19 22:15:16 +00003141 }
3142
3143public:
Gabor Greifefe65362008-05-10 08:32:32 +00003144 GetResultInst(Value *Aggr, unsigned index,
3145 const std::string &Name = "",
3146 Instruction *InsertBefore = 0);
Devang Patel40a04212008-02-19 22:15:16 +00003147
3148 /// isValidOperands - Return true if an getresult instruction can be
3149 /// formed with the specified operands.
Devang Patel23755d82008-02-20 19:10:47 +00003150 static bool isValidOperands(const Value *Aggr, unsigned index);
Devang Patel40a04212008-02-19 22:15:16 +00003151
3152 virtual GetResultInst *clone() const;
3153
Devang Patel4d4a5e02008-02-23 01:11:02 +00003154 Value *getAggregateValue() {
Devang Patel40a04212008-02-19 22:15:16 +00003155 return getOperand(0);
3156 }
Devang Patel2d2ae342008-02-20 18:36:16 +00003157
Devang Patel4d4a5e02008-02-23 01:11:02 +00003158 const Value *getAggregateValue() const {
Devang Patel2d2ae342008-02-20 18:36:16 +00003159 return getOperand(0);
3160 }
3161
Devang Patel4d4a5e02008-02-23 01:11:02 +00003162 unsigned getIndex() const {
Devang Patel23755d82008-02-20 19:10:47 +00003163 return Idx;
Devang Patel40a04212008-02-19 22:15:16 +00003164 }
3165
Devang Patel40a04212008-02-19 22:15:16 +00003166 // Methods for support type inquiry through isa, cast, and dyn_cast:
3167 static inline bool classof(const GetResultInst *) { return true; }
3168 static inline bool classof(const Instruction *I) {
3169 return (I->getOpcode() == Instruction::GetResult);
3170 }
3171 static inline bool classof(const Value *V) {
3172 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3173 }
3174};
3175
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00003176} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00003177
3178#endif