blob: a25dd128ef2ec56084dd6e1307673f366c892293 [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//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman9769ab22005-04-21 20:19:05 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnera892a3a2003-01-27 22:08:52 +00009//
10// This file exposes the class definitions of all of the subclasses of the
11// Instruction class. This is meant to be an easy way to get access to all
12// instruction subclasses.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_INSTRUCTIONS_H
17#define LLVM_INSTRUCTIONS_H
18
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000019#include "llvm/InstrTypes.h"
20
21namespace llvm {
22
Chris Lattner1fca5ff2004-10-27 16:14:51 +000023class BasicBlock;
Chris Lattnerd1a32602005-02-24 05:32:09 +000024class ConstantInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000025class PointerType;
Reid Spencer9d6565a2007-02-15 02:26:10 +000026class VectorType;
Reid Spencer3da43842007-02-28 22:00:54 +000027class ConstantRange;
28class APInt;
Reid Spencer4746ecf2007-04-09 15:01:12 +000029class ParamAttrsList;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000030
31//===----------------------------------------------------------------------===//
32// AllocationInst Class
33//===----------------------------------------------------------------------===//
34
35/// AllocationInst - This class is the common base class of MallocInst and
36/// AllocaInst.
37///
Chris Lattner454928e2005-01-29 00:31:36 +000038class AllocationInst : public UnaryInstruction {
Nate Begeman14b05292005-11-05 09:21:28 +000039 unsigned Alignment;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000040protected:
Nate Begeman14b05292005-11-05 09:21:28 +000041 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000042 const std::string &Name = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000043 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000044 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000045public:
Chris Lattner70aa33e2006-06-21 16:53:47 +000046 // Out of line virtual method, so the vtable, etc has a home.
47 virtual ~AllocationInst();
Chris Lattnerf56a8db2006-10-03 17:09:12 +000048
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000049 /// isArrayAllocation - Return true if there is an allocation size parameter
50 /// to the allocation instruction that is not 1.
51 ///
52 bool isArrayAllocation() const;
53
54 /// getArraySize - Get the number of element allocated, for a simple
55 /// allocation of a single element, this will return a constant 1 value.
56 ///
Chris Lattner454928e2005-01-29 00:31:36 +000057 inline const Value *getArraySize() const { return getOperand(0); }
58 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000059
60 /// getType - Overload to return most specific pointer type
61 ///
62 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000063 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000064 }
65
66 /// getAllocatedType - Return the type that is being allocated by the
67 /// instruction.
68 ///
69 const Type *getAllocatedType() const;
70
Nate Begeman14b05292005-11-05 09:21:28 +000071 /// getAlignment - Return the alignment of the memory that is being allocated
72 /// by the instruction.
73 ///
74 unsigned getAlignment() const { return Alignment; }
Chris Lattner8ae779d2005-11-05 21:58:30 +000075 void setAlignment(unsigned Align) {
76 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
77 Alignment = Align;
78 }
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;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000194
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000195 // Methods for support type inquiry through isa, cast, and dyn_cast:
196 static inline bool classof(const FreeInst *) { return true; }
197 static inline bool classof(const Instruction *I) {
198 return (I->getOpcode() == Instruction::Free);
199 }
200 static inline bool classof(const Value *V) {
201 return isa<Instruction>(V) && classof(cast<Instruction>(V));
202 }
203};
204
205
206//===----------------------------------------------------------------------===//
207// LoadInst Class
208//===----------------------------------------------------------------------===//
209
Chris Lattner88fe29a2005-02-05 01:44:18 +0000210/// LoadInst - an instruction for reading from memory. This uses the
211/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000212///
Chris Lattner454928e2005-01-29 00:31:36 +0000213class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000214 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000215 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
216 setVolatile(LI.isVolatile());
Misha Brukman9769ab22005-04-21 20:19:05 +0000217
Chris Lattner454928e2005-01-29 00:31:36 +0000218#ifndef NDEBUG
219 AssertOK();
220#endif
221 }
222 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000223public:
224 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
225 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf00042a2007-02-13 07:54:42 +0000226 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
227 Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000228 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
229 BasicBlock *InsertAtEnd);
230
Chris Lattnerf00042a2007-02-13 07:54:42 +0000231 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
232 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
233 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
234 Instruction *InsertBefore = 0);
235 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
236 BasicBlock *InsertAtEnd);
237
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000238 /// isVolatile - Return true if this is a load from a volatile memory
239 /// location.
240 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000241 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000242
243 /// setVolatile - Specify whether this is a volatile load or not.
244 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000245 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000246
Chris Lattnerf319e832004-10-15 23:52:05 +0000247 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000248
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000249 Value *getPointerOperand() { return getOperand(0); }
250 const Value *getPointerOperand() const { return getOperand(0); }
251 static unsigned getPointerOperandIndex() { return 0U; }
252
253 // Methods for support type inquiry through isa, cast, and dyn_cast:
254 static inline bool classof(const LoadInst *) { return true; }
255 static inline bool classof(const Instruction *I) {
256 return I->getOpcode() == Instruction::Load;
257 }
258 static inline bool classof(const Value *V) {
259 return isa<Instruction>(V) && classof(cast<Instruction>(V));
260 }
261};
262
263
264//===----------------------------------------------------------------------===//
265// StoreInst Class
266//===----------------------------------------------------------------------===//
267
Misha Brukman9769ab22005-04-21 20:19:05 +0000268/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000269///
270class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000271 Use Ops[2];
Chris Lattner88fe29a2005-02-05 01:44:18 +0000272 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000273 Ops[0].init(SI.Ops[0], this);
274 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000275 setVolatile(SI.isVolatile());
Chris Lattner454928e2005-01-29 00:31:36 +0000276#ifndef NDEBUG
277 AssertOK();
278#endif
279 }
280 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000281public:
282 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
283 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
284 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
285 Instruction *InsertBefore = 0);
286 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
287
288
289 /// isVolatile - Return true if this is a load from a volatile memory
290 /// location.
291 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000292 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000293
294 /// setVolatile - Specify whether this is a volatile load or not.
295 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000296 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000297
Chris Lattner454928e2005-01-29 00:31:36 +0000298 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000299 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000300 assert(i < 2 && "getOperand() out of range!");
301 return Ops[i];
302 }
303 void setOperand(unsigned i, Value *Val) {
304 assert(i < 2 && "setOperand() out of range!");
305 Ops[i] = Val;
306 }
307 unsigned getNumOperands() const { return 2; }
308
309
Chris Lattnerf319e832004-10-15 23:52:05 +0000310 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000311
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000312 Value *getPointerOperand() { return getOperand(1); }
313 const Value *getPointerOperand() const { return getOperand(1); }
314 static unsigned getPointerOperandIndex() { return 1U; }
315
316 // Methods for support type inquiry through isa, cast, and dyn_cast:
317 static inline bool classof(const StoreInst *) { return true; }
318 static inline bool classof(const Instruction *I) {
319 return I->getOpcode() == Instruction::Store;
320 }
321 static inline bool classof(const Value *V) {
322 return isa<Instruction>(V) && classof(cast<Instruction>(V));
323 }
324};
325
326
327//===----------------------------------------------------------------------===//
328// GetElementPtrInst Class
329//===----------------------------------------------------------------------===//
330
331/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
332/// access elements of arrays and structs
333///
334class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000335 GetElementPtrInst(const GetElementPtrInst &GEPI)
336 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
337 0, GEPI.getNumOperands()) {
338 Use *OL = OperandList = new Use[NumOperands];
339 Use *GEPIOL = GEPI.OperandList;
340 for (unsigned i = 0, E = NumOperands; i != E; ++i)
341 OL[i].init(GEPIOL[i], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000342 }
Chris Lattner6ffbe172007-01-31 19:47:18 +0000343 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000344 void init(Value *Ptr, Value *Idx0, Value *Idx1);
Chris Lattner38bacf22005-05-03 05:43:30 +0000345 void init(Value *Ptr, Value *Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000346public:
347 /// Constructors - Create a getelementptr instruction with a base pointer an
348 /// list of indices. The first ctor can optionally insert before an existing
349 /// instruction, the second appends the new instruction to the specified
350 /// BasicBlock.
Chris Lattnerfb110532007-01-31 04:39:29 +0000351 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
352 const std::string &Name = "", Instruction *InsertBefore =0);
353 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
354 const std::string &Name, BasicBlock *InsertAtEnd);
355
Chris Lattner38bacf22005-05-03 05:43:30 +0000356 /// Constructors - These two constructors are convenience methods because one
357 /// and two index getelementptr instructions are so common.
358 GetElementPtrInst(Value *Ptr, Value *Idx,
359 const std::string &Name = "", Instruction *InsertBefore =0);
360 GetElementPtrInst(Value *Ptr, Value *Idx,
361 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000362 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000363 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000364 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000365 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000366 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000367
Chris Lattnerf319e832004-10-15 23:52:05 +0000368 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000369
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000370 // getType - Overload to return most specific pointer type...
371 inline const PointerType *getType() const {
372 return reinterpret_cast<const PointerType*>(Instruction::getType());
373 }
374
375 /// getIndexedType - Returns the type of the element that would be loaded with
376 /// a load instruction with the specified parameters.
377 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000378 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000379 /// pointer type.
380 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000381 static const Type *getIndexedType(const Type *Ptr,
Chris Lattnerfb110532007-01-31 04:39:29 +0000382 Value* const *Idx, unsigned NumIdx,
Misha Brukman91102862005-03-16 03:46:55 +0000383 bool AllowStructLeaf = false);
Chris Lattnerfb110532007-01-31 04:39:29 +0000384
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000385 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000386 bool AllowStructLeaf = false);
Chris Lattner38bacf22005-05-03 05:43:30 +0000387 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000388
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000389 inline op_iterator idx_begin() { return op_begin()+1; }
390 inline const_op_iterator idx_begin() const { return op_begin()+1; }
391 inline op_iterator idx_end() { return op_end(); }
392 inline const_op_iterator idx_end() const { return op_end(); }
393
394 Value *getPointerOperand() {
395 return getOperand(0);
396 }
397 const Value *getPointerOperand() const {
398 return getOperand(0);
399 }
400 static unsigned getPointerOperandIndex() {
401 return 0U; // get index for modifying correct operand
402 }
403
404 inline unsigned getNumIndices() const { // Note: always non-negative
405 return getNumOperands() - 1;
406 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000407
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000408 inline bool hasIndices() const {
409 return getNumOperands() > 1;
410 }
411
412 // Methods for support type inquiry through isa, cast, and dyn_cast:
413 static inline bool classof(const GetElementPtrInst *) { return true; }
414 static inline bool classof(const Instruction *I) {
415 return (I->getOpcode() == Instruction::GetElementPtr);
416 }
417 static inline bool classof(const Value *V) {
418 return isa<Instruction>(V) && classof(cast<Instruction>(V));
419 }
420};
421
422//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000423// ICmpInst Class
424//===----------------------------------------------------------------------===//
425
426/// This instruction compares its operands according to the predicate given
427/// to the constructor. It only operates on integers, pointers, or packed
428/// vectors of integrals. The two operands must be the same type.
429/// @brief Represent an integer comparison operator.
430class ICmpInst: public CmpInst {
431public:
432 /// This enumeration lists the possible predicates for the ICmpInst. The
433 /// values in the range 0-31 are reserved for FCmpInst while values in the
434 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
435 /// predicate values are not overlapping between the classes.
436 enum Predicate {
437 ICMP_EQ = 32, ///< equal
438 ICMP_NE = 33, ///< not equal
439 ICMP_UGT = 34, ///< unsigned greater than
440 ICMP_UGE = 35, ///< unsigned greater or equal
441 ICMP_ULT = 36, ///< unsigned less than
442 ICMP_ULE = 37, ///< unsigned less or equal
443 ICMP_SGT = 38, ///< signed greater than
444 ICMP_SGE = 39, ///< signed greater or equal
445 ICMP_SLT = 40, ///< signed less than
446 ICMP_SLE = 41, ///< signed less or equal
447 FIRST_ICMP_PREDICATE = ICMP_EQ,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000448 LAST_ICMP_PREDICATE = ICMP_SLE,
449 BAD_ICMP_PREDICATE = ICMP_SLE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000450 };
451
452 /// @brief Constructor with insert-before-instruction semantics.
453 ICmpInst(
454 Predicate pred, ///< The predicate to use for the comparison
455 Value *LHS, ///< The left-hand-side of the expression
456 Value *RHS, ///< The right-hand-side of the expression
457 const std::string &Name = "", ///< Name of the instruction
458 Instruction *InsertBefore = 0 ///< Where to insert
459 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
460 }
461
462 /// @brief Constructor with insert-at-block-end semantics.
463 ICmpInst(
464 Predicate pred, ///< The predicate to use for the comparison
465 Value *LHS, ///< The left-hand-side of the expression
466 Value *RHS, ///< The right-hand-side of the expression
467 const std::string &Name, ///< Name of the instruction
468 BasicBlock *InsertAtEnd ///< Block to insert into.
469 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
470 }
471
472 /// @brief Return the predicate for this instruction.
473 Predicate getPredicate() const { return Predicate(SubclassData); }
474
Chris Lattnerb769d562007-01-14 19:41:24 +0000475 /// @brief Set the predicate for this instruction to the specified value.
476 void setPredicate(Predicate P) { SubclassData = P; }
477
Reid Spencer45fb3f32006-11-20 01:22:35 +0000478 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
479 /// @returns the inverse predicate for the instruction's current predicate.
480 /// @brief Return the inverse of the instruction's predicate.
481 Predicate getInversePredicate() const {
482 return getInversePredicate(getPredicate());
483 }
484
485 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
486 /// @returns the inverse predicate for predicate provided in \p pred.
487 /// @brief Return the inverse of a given predicate
488 static Predicate getInversePredicate(Predicate pred);
489
490 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
491 /// @returns the predicate that would be the result of exchanging the two
492 /// operands of the ICmpInst instruction without changing the result
493 /// produced.
494 /// @brief Return the predicate as if the operands were swapped
495 Predicate getSwappedPredicate() const {
496 return getSwappedPredicate(getPredicate());
497 }
498
499 /// This is a static version that you can use without an instruction
500 /// available.
501 /// @brief Return the predicate as if the operands were swapped.
Reid Spencere4d87aa2006-12-23 06:05:41 +0000502 static Predicate getSwappedPredicate(Predicate pred);
503
504 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
505 /// @returns the predicate that would be the result if the operand were
506 /// regarded as signed.
507 /// @brief Return the signed version of the predicate
508 Predicate getSignedPredicate() const {
509 return getSignedPredicate(getPredicate());
510 }
511
512 /// This is a static version that you can use without an instruction.
513 /// @brief Return the signed version of the predicate.
514 static Predicate getSignedPredicate(Predicate pred);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000515
516 /// This also tests for commutativity. If isEquality() returns true then
Reid Spencere4d87aa2006-12-23 06:05:41 +0000517 /// the predicate is also commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000518 /// @returns true if the predicate of this instruction is EQ or NE.
519 /// @brief Determine if this is an equality predicate.
520 bool isEquality() const {
521 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
522 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000523
524 /// @returns true if the predicate of this ICmpInst is commutative
525 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000526 bool isCommutative() const { return isEquality(); }
527
528 /// @returns true if the predicate is relational (not EQ or NE).
529 /// @brief Determine if this a relational predicate.
530 bool isRelational() const {
531 return !isEquality();
532 }
533
Reid Spencere4d87aa2006-12-23 06:05:41 +0000534 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
535 /// @brief Determine if this instruction's predicate is signed.
536 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
537
538 /// @returns true if the predicate provided is signed, false otherwise
539 /// @brief Determine if the predicate is signed.
540 static bool isSignedPredicate(Predicate pred);
541
Reid Spencer3da43842007-02-28 22:00:54 +0000542 /// Initialize a set of values that all satisfy the predicate with C.
543 /// @brief Make a ConstantRange for a relation with a constant value.
544 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
545
Reid Spencer45fb3f32006-11-20 01:22:35 +0000546 /// Exchange the two operands to this instruction in such a way that it does
547 /// not modify the semantics of the instruction. The predicate value may be
548 /// changed to retain the same result if the predicate is order dependent
549 /// (e.g. ult).
550 /// @brief Swap operands and adjust predicate.
551 void swapOperands() {
552 SubclassData = getSwappedPredicate();
553 std::swap(Ops[0], Ops[1]);
554 }
555
556 // Methods for support type inquiry through isa, cast, and dyn_cast:
557 static inline bool classof(const ICmpInst *) { return true; }
558 static inline bool classof(const Instruction *I) {
559 return I->getOpcode() == Instruction::ICmp;
560 }
561 static inline bool classof(const Value *V) {
562 return isa<Instruction>(V) && classof(cast<Instruction>(V));
563 }
564};
565
566//===----------------------------------------------------------------------===//
567// FCmpInst Class
568//===----------------------------------------------------------------------===//
569
570/// This instruction compares its operands according to the predicate given
571/// to the constructor. It only operates on floating point values or packed
572/// vectors of floating point values. The operands must be identical types.
573/// @brief Represents a floating point comparison operator.
574class FCmpInst: public CmpInst {
575public:
576 /// This enumeration lists the possible predicates for the FCmpInst. Values
577 /// in the range 0-31 are reserved for FCmpInst.
578 enum Predicate {
579 // Opcode U L G E Intuitive operation
580 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
581 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
582 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
583 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
584 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
585 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
586 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
587 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
588 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
589 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
590 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
591 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
592 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
593 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
594 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
595 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
596 FIRST_FCMP_PREDICATE = FCMP_FALSE,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000597 LAST_FCMP_PREDICATE = FCMP_TRUE,
598 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000599 };
600
601 /// @brief Constructor with insert-before-instruction semantics.
602 FCmpInst(
603 Predicate pred, ///< The predicate to use for the comparison
604 Value *LHS, ///< The left-hand-side of the expression
605 Value *RHS, ///< The right-hand-side of the expression
606 const std::string &Name = "", ///< Name of the instruction
607 Instruction *InsertBefore = 0 ///< Where to insert
608 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
609 }
610
611 /// @brief Constructor with insert-at-block-end semantics.
612 FCmpInst(
613 Predicate pred, ///< The predicate to use for the comparison
614 Value *LHS, ///< The left-hand-side of the expression
615 Value *RHS, ///< The right-hand-side of the expression
616 const std::string &Name, ///< Name of the instruction
617 BasicBlock *InsertAtEnd ///< Block to insert into.
618 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
619 }
620
621 /// @brief Return the predicate for this instruction.
622 Predicate getPredicate() const { return Predicate(SubclassData); }
623
Chris Lattnerb769d562007-01-14 19:41:24 +0000624 /// @brief Set the predicate for this instruction to the specified value.
625 void setPredicate(Predicate P) { SubclassData = P; }
626
Reid Spencer45fb3f32006-11-20 01:22:35 +0000627 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
628 /// @returns the inverse predicate for the instructions current predicate.
629 /// @brief Return the inverse of the predicate
630 Predicate getInversePredicate() const {
631 return getInversePredicate(getPredicate());
632 }
633
634 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
635 /// @returns the inverse predicate for \p pred.
636 /// @brief Return the inverse of a given predicate
637 static Predicate getInversePredicate(Predicate pred);
638
639 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
640 /// @returns the predicate that would be the result of exchanging the two
641 /// operands of the ICmpInst instruction without changing the result
642 /// produced.
643 /// @brief Return the predicate as if the operands were swapped
644 Predicate getSwappedPredicate() const {
645 return getSwappedPredicate(getPredicate());
646 }
647
648 /// This is a static version that you can use without an instruction
649 /// available.
650 /// @brief Return the predicate as if the operands were swapped.
651 static Predicate getSwappedPredicate(Predicate Opcode);
652
653 /// This also tests for commutativity. If isEquality() returns true then
654 /// the predicate is also commutative. Only the equality predicates are
655 /// commutative.
656 /// @returns true if the predicate of this instruction is EQ or NE.
657 /// @brief Determine if this is an equality predicate.
658 bool isEquality() const {
659 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
660 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
661 }
662 bool isCommutative() const { return isEquality(); }
663
664 /// @returns true if the predicate is relational (not EQ or NE).
665 /// @brief Determine if this a relational predicate.
666 bool isRelational() const { return !isEquality(); }
667
668 /// Exchange the two operands to this instruction in such a way that it does
669 /// not modify the semantics of the instruction. The predicate value may be
670 /// changed to retain the same result if the predicate is order dependent
671 /// (e.g. ult).
672 /// @brief Swap operands and adjust predicate.
673 void swapOperands() {
674 SubclassData = getSwappedPredicate();
675 std::swap(Ops[0], Ops[1]);
676 }
677
678 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
679 static inline bool classof(const FCmpInst *) { return true; }
680 static inline bool classof(const Instruction *I) {
681 return I->getOpcode() == Instruction::FCmp;
682 }
683 static inline bool classof(const Value *V) {
684 return isa<Instruction>(V) && classof(cast<Instruction>(V));
685 }
686};
687
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000688//===----------------------------------------------------------------------===//
689// CallInst Class
690//===----------------------------------------------------------------------===//
691
692/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000693/// machine's calling convention. This class uses low bit of the SubClassData
694/// field to indicate whether or not this is a tail call. The rest of the bits
695/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000696///
697class CallInst : public Instruction {
Reid Spencer4746ecf2007-04-09 15:01:12 +0000698 ParamAttrsList *ParamAttrs; ///< parameter attributes for call
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000699 CallInst(const CallInst &CI);
Chris Lattnerd54f4322007-02-13 00:58:44 +0000700 void init(Value *Func, Value* const *Params, unsigned NumParams);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000701 void init(Value *Func, Value *Actual1, Value *Actual2);
702 void init(Value *Func, Value *Actual);
703 void init(Value *Func);
704
705public:
Chris Lattnerd2dd1502007-02-13 01:04:01 +0000706 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
707 const std::string &Name = "", Instruction *InsertBefore = 0);
708 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
709 const std::string &Name, BasicBlock *InsertAtEnd);
710
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000711 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
712 // actuals, respectively.
713 CallInst(Value *F, Value *Actual1, Value *Actual2,
714 const std::string& Name = "", Instruction *InsertBefore = 0);
715 CallInst(Value *F, Value *Actual1, Value *Actual2,
716 const std::string& Name, BasicBlock *InsertAtEnd);
717 CallInst(Value *F, Value *Actual, const std::string& Name = "",
718 Instruction *InsertBefore = 0);
719 CallInst(Value *F, Value *Actual, const std::string& Name,
720 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000721 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000722 Instruction *InsertBefore = 0);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000723 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000724 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000725
Chris Lattnerf319e832004-10-15 23:52:05 +0000726 virtual CallInst *clone() const;
Chris Lattnerbb5493d2007-02-15 23:15:00 +0000727
Chris Lattner3340ffe2005-05-06 20:26:26 +0000728 bool isTailCall() const { return SubclassData & 1; }
729 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000730 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000731 }
732
733 /// getCallingConv/setCallingConv - Get or set the calling convention of this
734 /// function call.
735 unsigned getCallingConv() const { return SubclassData >> 1; }
736 void setCallingConv(unsigned CC) {
737 SubclassData = (SubclassData & 1) | (CC << 1);
738 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000739
Reid Spencer4746ecf2007-04-09 15:01:12 +0000740 /// Obtains a constant pointer to the ParamAttrsList object which holds the
741 /// parameter attributes information, if any.
742 /// @brief Get the parameter attributes.
743 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
744
745 /// Sets the parameter attributes for this CallInst. To construct a
746 /// ParamAttrsList, see ParameterAttributes.h
747 /// @brief Set the parameter attributes.
748 void setParamAttrs(ParamAttrsList *attrs) { ParamAttrs = attrs; }
749
Chris Lattner721aef62004-11-18 17:46:57 +0000750 /// getCalledFunction - Return the function being called by this instruction
751 /// if it is a direct call. If it is a call through a function pointer,
752 /// return null.
753 Function *getCalledFunction() const {
Reid Spenceredd5d9e2005-05-15 16:13:11 +0000754 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
Chris Lattner721aef62004-11-18 17:46:57 +0000755 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000756
Reid Spencerc25ec252006-12-29 04:10:59 +0000757 /// getCalledValue - Get a pointer to the function that is invoked by this
758 /// instruction
Chris Lattner454928e2005-01-29 00:31:36 +0000759 inline const Value *getCalledValue() const { return getOperand(0); }
760 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000761
762 // Methods for support type inquiry through isa, cast, and dyn_cast:
763 static inline bool classof(const CallInst *) { return true; }
764 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000765 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000766 }
767 static inline bool classof(const Value *V) {
768 return isa<Instruction>(V) && classof(cast<Instruction>(V));
769 }
770};
771
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000772//===----------------------------------------------------------------------===//
773// SelectInst Class
774//===----------------------------------------------------------------------===//
775
776/// SelectInst - This class represents the LLVM 'select' instruction.
777///
778class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000779 Use Ops[3];
780
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000781 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000782 Ops[0].init(C, this);
783 Ops[1].init(S1, this);
784 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000785 }
786
Chris Lattner454928e2005-01-29 00:31:36 +0000787 SelectInst(const SelectInst &SI)
788 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
789 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
790 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000791public:
792 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
793 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000794 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000795 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +0000796 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000797 }
798 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
799 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000800 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000801 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +0000802 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000803 }
804
Chris Lattner454928e2005-01-29 00:31:36 +0000805 Value *getCondition() const { return Ops[0]; }
806 Value *getTrueValue() const { return Ops[1]; }
807 Value *getFalseValue() const { return Ops[2]; }
808
809 /// Transparently provide more efficient getOperand methods.
810 Value *getOperand(unsigned i) const {
811 assert(i < 3 && "getOperand() out of range!");
812 return Ops[i];
813 }
814 void setOperand(unsigned i, Value *Val) {
815 assert(i < 3 && "setOperand() out of range!");
816 Ops[i] = Val;
817 }
818 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000819
820 OtherOps getOpcode() const {
821 return static_cast<OtherOps>(Instruction::getOpcode());
822 }
823
Chris Lattnerf319e832004-10-15 23:52:05 +0000824 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000825
826 // Methods for support type inquiry through isa, cast, and dyn_cast:
827 static inline bool classof(const SelectInst *) { return true; }
828 static inline bool classof(const Instruction *I) {
829 return I->getOpcode() == Instruction::Select;
830 }
831 static inline bool classof(const Value *V) {
832 return isa<Instruction>(V) && classof(cast<Instruction>(V));
833 }
834};
835
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000836//===----------------------------------------------------------------------===//
837// VAArgInst Class
838//===----------------------------------------------------------------------===//
839
840/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +0000841/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000842///
Chris Lattner454928e2005-01-29 00:31:36 +0000843class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000844 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +0000845 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000846public:
847 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
848 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000849 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000850 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000851 }
852 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
853 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000854 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000855 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000856 }
857
Chris Lattnerf319e832004-10-15 23:52:05 +0000858 virtual VAArgInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000859
860 // Methods for support type inquiry through isa, cast, and dyn_cast:
861 static inline bool classof(const VAArgInst *) { return true; }
862 static inline bool classof(const Instruction *I) {
863 return I->getOpcode() == VAArg;
864 }
865 static inline bool classof(const Value *V) {
866 return isa<Instruction>(V) && classof(cast<Instruction>(V));
867 }
868};
869
870//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +0000871// ExtractElementInst Class
872//===----------------------------------------------------------------------===//
873
874/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000875/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +0000876///
877class ExtractElementInst : public Instruction {
878 Use Ops[2];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000879 ExtractElementInst(const ExtractElementInst &EE) :
Robert Bocchinof9993442006-01-17 20:05:59 +0000880 Instruction(EE.getType(), ExtractElement, Ops, 2) {
881 Ops[0].init(EE.Ops[0], this);
882 Ops[1].init(EE.Ops[1], this);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000883 }
884
885public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000886 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
887 Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000888 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
889 Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000890 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
891 BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000892 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
893 BasicBlock *InsertAtEnd);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000894
Chris Lattnerfa495842006-04-08 04:04:54 +0000895 /// isValidOperands - Return true if an extractelement instruction can be
896 /// formed with the specified operands.
897 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000898
Robert Bocchino49b78a52006-01-10 19:04:13 +0000899 virtual ExtractElementInst *clone() const;
900
Robert Bocchino49b78a52006-01-10 19:04:13 +0000901 /// Transparently provide more efficient getOperand methods.
902 Value *getOperand(unsigned i) const {
903 assert(i < 2 && "getOperand() out of range!");
904 return Ops[i];
905 }
906 void setOperand(unsigned i, Value *Val) {
907 assert(i < 2 && "setOperand() out of range!");
908 Ops[i] = Val;
909 }
910 unsigned getNumOperands() const { return 2; }
911
912 // Methods for support type inquiry through isa, cast, and dyn_cast:
913 static inline bool classof(const ExtractElementInst *) { return true; }
914 static inline bool classof(const Instruction *I) {
915 return I->getOpcode() == Instruction::ExtractElement;
916 }
917 static inline bool classof(const Value *V) {
918 return isa<Instruction>(V) && classof(cast<Instruction>(V));
919 }
920};
921
922//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +0000923// InsertElementInst Class
924//===----------------------------------------------------------------------===//
925
926/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000927/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +0000928///
929class InsertElementInst : public Instruction {
930 Use Ops[3];
Chris Lattner6a56ed42006-04-14 22:20:07 +0000931 InsertElementInst(const InsertElementInst &IE);
Robert Bocchinof9993442006-01-17 20:05:59 +0000932public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000933 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
934 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000935 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
936 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000937 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Robert Bocchinof9993442006-01-17 20:05:59 +0000938 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000939 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
940 const std::string &Name, BasicBlock *InsertAtEnd);
Robert Bocchinof9993442006-01-17 20:05:59 +0000941
Chris Lattnerfa495842006-04-08 04:04:54 +0000942 /// isValidOperands - Return true if an insertelement instruction can be
943 /// formed with the specified operands.
944 static bool isValidOperands(const Value *Vec, const Value *NewElt,
945 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000946
Robert Bocchinof9993442006-01-17 20:05:59 +0000947 virtual InsertElementInst *clone() const;
948
Reid Spencerac9dcb92007-02-15 03:39:18 +0000949 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +0000950 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +0000951 inline const VectorType *getType() const {
952 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +0000953 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000954
Robert Bocchinof9993442006-01-17 20:05:59 +0000955 /// Transparently provide more efficient getOperand methods.
956 Value *getOperand(unsigned i) const {
957 assert(i < 3 && "getOperand() out of range!");
958 return Ops[i];
959 }
960 void setOperand(unsigned i, Value *Val) {
961 assert(i < 3 && "setOperand() out of range!");
962 Ops[i] = Val;
963 }
964 unsigned getNumOperands() const { return 3; }
965
966 // Methods for support type inquiry through isa, cast, and dyn_cast:
967 static inline bool classof(const InsertElementInst *) { return true; }
968 static inline bool classof(const Instruction *I) {
969 return I->getOpcode() == Instruction::InsertElement;
970 }
971 static inline bool classof(const Value *V) {
972 return isa<Instruction>(V) && classof(cast<Instruction>(V));
973 }
974};
975
976//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +0000977// ShuffleVectorInst Class
978//===----------------------------------------------------------------------===//
979
980/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
981/// input vectors.
982///
983class ShuffleVectorInst : public Instruction {
984 Use Ops[3];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000985 ShuffleVectorInst(const ShuffleVectorInst &IE);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000986public:
987 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
988 const std::string &Name = "", Instruction *InsertBefor = 0);
989 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
990 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000991
Chris Lattnerfa495842006-04-08 04:04:54 +0000992 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +0000993 /// formed with the specified operands.
994 static bool isValidOperands(const Value *V1, const Value *V2,
995 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000996
Chris Lattner9fc18d22006-04-08 01:15:18 +0000997 virtual ShuffleVectorInst *clone() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000998
Reid Spencerac9dcb92007-02-15 03:39:18 +0000999 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +00001000 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +00001001 inline const VectorType *getType() const {
1002 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +00001003 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001004
Chris Lattner9fc18d22006-04-08 01:15:18 +00001005 /// Transparently provide more efficient getOperand methods.
1006 Value *getOperand(unsigned i) const {
1007 assert(i < 3 && "getOperand() out of range!");
1008 return Ops[i];
1009 }
1010 void setOperand(unsigned i, Value *Val) {
1011 assert(i < 3 && "setOperand() out of range!");
1012 Ops[i] = Val;
1013 }
1014 unsigned getNumOperands() const { return 3; }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001015
Chris Lattner9fc18d22006-04-08 01:15:18 +00001016 // Methods for support type inquiry through isa, cast, and dyn_cast:
1017 static inline bool classof(const ShuffleVectorInst *) { return true; }
1018 static inline bool classof(const Instruction *I) {
1019 return I->getOpcode() == Instruction::ShuffleVector;
1020 }
1021 static inline bool classof(const Value *V) {
1022 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1023 }
1024};
1025
1026
1027//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001028// PHINode Class
1029//===----------------------------------------------------------------------===//
1030
1031// PHINode - The PHINode class is used to represent the magical mystical PHI
1032// node, that can not exist in nature, but can be synthesized in a computer
1033// scientist's overactive imagination.
1034//
1035class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +00001036 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1037 /// the number actually in use.
1038 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001039 PHINode(const PHINode &PN);
1040public:
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001041 explicit PHINode(const Type *Ty, const std::string &Name = "",
1042 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001043 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Chris Lattner454928e2005-01-29 00:31:36 +00001044 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001045 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001046 }
1047
1048 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001049 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Chris Lattner454928e2005-01-29 00:31:36 +00001050 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001051 setName(Name);
Chris Lattner454928e2005-01-29 00:31:36 +00001052 }
1053
1054 ~PHINode();
1055
1056 /// reserveOperandSpace - This method can be used to avoid repeated
1057 /// reallocation of PHI operand lists by reserving space for the correct
1058 /// number of operands before adding them. Unlike normal vector reserves,
1059 /// this method can also be used to trim the operand space.
1060 void reserveOperandSpace(unsigned NumValues) {
1061 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001062 }
1063
Chris Lattnerf319e832004-10-15 23:52:05 +00001064 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001065
1066 /// getNumIncomingValues - Return the number of incoming edges
1067 ///
Chris Lattner454928e2005-01-29 00:31:36 +00001068 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001069
Reid Spencerc773de62006-05-19 19:07:54 +00001070 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001071 ///
1072 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001073 assert(i*2 < getNumOperands() && "Invalid value number!");
1074 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001075 }
1076 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +00001077 assert(i*2 < getNumOperands() && "Invalid value number!");
1078 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001079 }
Chris Lattner454928e2005-01-29 00:31:36 +00001080 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001081 return i*2;
1082 }
1083
Reid Spencerc773de62006-05-19 19:07:54 +00001084 /// getIncomingBlock - Return incoming basic block number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001085 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00001086 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001087 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001088 }
1089 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +00001090 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001091 }
1092 unsigned getOperandNumForIncomingBlock(unsigned i) {
1093 return i*2+1;
1094 }
1095
1096 /// addIncoming - Add an incoming value to the end of the PHI list
1097 ///
1098 void addIncoming(Value *V, BasicBlock *BB) {
1099 assert(getType() == V->getType() &&
1100 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +00001101 unsigned OpNo = NumOperands;
1102 if (OpNo+2 > ReservedSpace)
1103 resizeOperands(0); // Get more space!
1104 // Initialize some new operands.
1105 NumOperands = OpNo+2;
1106 OperandList[OpNo].init(V, this);
1107 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001108 }
Misha Brukman9769ab22005-04-21 20:19:05 +00001109
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001110 /// removeIncomingValue - Remove an incoming value. This is useful if a
1111 /// predecessor basic block is deleted. The value removed is returned.
1112 ///
1113 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1114 /// is true), the PHI node is destroyed and any uses of it are replaced with
1115 /// dummy values. The only time there should be zero incoming values to a PHI
1116 /// node is when the block is dead, so this strategy is sound.
1117 ///
1118 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1119
1120 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1121 int Idx = getBasicBlockIndex(BB);
1122 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1123 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1124 }
1125
Misha Brukman9769ab22005-04-21 20:19:05 +00001126 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001127 /// block in the value list for this PHI. Returns -1 if no instance.
1128 ///
1129 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001130 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +00001131 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +00001132 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001133 return -1;
1134 }
1135
1136 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1137 return getIncomingValue(getBasicBlockIndex(BB));
1138 }
1139
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001140 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00001141 /// same value, return the value, otherwise return null.
1142 ///
Chris Lattner9acbd612005-08-05 00:49:06 +00001143 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001144
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001145 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1146 static inline bool classof(const PHINode *) { return true; }
1147 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001148 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001149 }
1150 static inline bool classof(const Value *V) {
1151 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1152 }
Chris Lattner454928e2005-01-29 00:31:36 +00001153 private:
1154 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001155};
1156
1157//===----------------------------------------------------------------------===//
1158// ReturnInst Class
1159//===----------------------------------------------------------------------===//
1160
1161//===---------------------------------------------------------------------------
1162/// ReturnInst - Return a value (possibly void), from a function. Execution
1163/// does not continue in this function any longer.
1164///
1165class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00001166 Use RetVal; // Return Value: null if 'void'.
1167 ReturnInst(const ReturnInst &RI);
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001168 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001169
1170public:
1171 // ReturnInst constructors:
1172 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001173 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001174 // ReturnInst(Value* X) - 'ret X' instruction
1175 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1176 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1177 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1178 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001179 //
1180 // NOTE: If the Value* passed is of type void then the constructor behaves as
1181 // if it was passed NULL.
Chris Lattner910c80a2007-02-24 00:55:48 +00001182 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1183 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1184 explicit ReturnInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001185
Chris Lattnerf319e832004-10-15 23:52:05 +00001186 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001187
Chris Lattner454928e2005-01-29 00:31:36 +00001188 // Transparently provide more efficient getOperand methods.
1189 Value *getOperand(unsigned i) const {
1190 assert(i < getNumOperands() && "getOperand() out of range!");
1191 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001192 }
Chris Lattner454928e2005-01-29 00:31:36 +00001193 void setOperand(unsigned i, Value *Val) {
1194 assert(i < getNumOperands() && "setOperand() out of range!");
1195 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001196 }
1197
Chris Lattner454928e2005-01-29 00:31:36 +00001198 Value *getReturnValue() const { return RetVal; }
1199
1200 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001201
1202 // Methods for support type inquiry through isa, cast, and dyn_cast:
1203 static inline bool classof(const ReturnInst *) { return true; }
1204 static inline bool classof(const Instruction *I) {
1205 return (I->getOpcode() == Instruction::Ret);
1206 }
1207 static inline bool classof(const Value *V) {
1208 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1209 }
Chris Lattner454928e2005-01-29 00:31:36 +00001210 private:
1211 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1212 virtual unsigned getNumSuccessorsV() const;
1213 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001214};
1215
1216//===----------------------------------------------------------------------===//
1217// BranchInst Class
1218//===----------------------------------------------------------------------===//
1219
1220//===---------------------------------------------------------------------------
1221/// BranchInst - Conditional or Unconditional Branch instruction.
1222///
1223class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001224 /// Ops list - Branches are strange. The operands are ordered:
1225 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1226 /// they don't have to check for cond/uncond branchness.
1227 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001228 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00001229 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001230public:
1231 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1232 // BranchInst(BB *B) - 'br B'
1233 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1234 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1235 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1236 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1237 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00001238 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001239 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001240 Instruction *InsertBefore = 0);
1241 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001242 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001243 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001244
1245 /// Transparently provide more efficient getOperand methods.
1246 Value *getOperand(unsigned i) const {
1247 assert(i < getNumOperands() && "getOperand() out of range!");
1248 return Ops[i];
1249 }
1250 void setOperand(unsigned i, Value *Val) {
1251 assert(i < getNumOperands() && "setOperand() out of range!");
1252 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001253 }
1254
Chris Lattnerf319e832004-10-15 23:52:05 +00001255 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001256
Chris Lattner454928e2005-01-29 00:31:36 +00001257 inline bool isUnconditional() const { return getNumOperands() == 1; }
1258 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001259
1260 inline Value *getCondition() const {
1261 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001262 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001263 }
1264
1265 void setCondition(Value *V) {
1266 assert(isConditional() && "Cannot set condition of unconditional branch!");
1267 setOperand(2, V);
1268 }
1269
1270 // setUnconditionalDest - Change the current branch to an unconditional branch
1271 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +00001272 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001273 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +00001274 if (isConditional()) { // Convert this to an uncond branch.
1275 NumOperands = 1;
1276 Ops[1].set(0);
1277 Ops[2].set(0);
1278 }
1279 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001280 }
1281
Chris Lattner454928e2005-01-29 00:31:36 +00001282 unsigned getNumSuccessors() const { return 1+isConditional(); }
1283
1284 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001285 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Misha Brukman9769ab22005-04-21 20:19:05 +00001286 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
Chris Lattner454928e2005-01-29 00:31:36 +00001287 cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001288 }
1289
Chris Lattner454928e2005-01-29 00:31:36 +00001290 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001291 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001292 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001293 }
1294
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001295 // Methods for support type inquiry through isa, cast, and dyn_cast:
1296 static inline bool classof(const BranchInst *) { return true; }
1297 static inline bool classof(const Instruction *I) {
1298 return (I->getOpcode() == Instruction::Br);
1299 }
1300 static inline bool classof(const Value *V) {
1301 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1302 }
Chris Lattner454928e2005-01-29 00:31:36 +00001303private:
1304 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1305 virtual unsigned getNumSuccessorsV() const;
1306 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001307};
1308
1309//===----------------------------------------------------------------------===//
1310// SwitchInst Class
1311//===----------------------------------------------------------------------===//
1312
1313//===---------------------------------------------------------------------------
1314/// SwitchInst - Multiway switch
1315///
1316class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001317 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001318 // Operand[0] = Value to switch on
1319 // Operand[1] = Default basic block destination
1320 // Operand[2n ] = Value to match
1321 // Operand[2n+1] = BasicBlock to go to on match
1322 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001323 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1324 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001325public:
Chris Lattner454928e2005-01-29 00:31:36 +00001326 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1327 /// switch on and a default destination. The number of additional cases can
1328 /// be specified here to make memory allocation more efficient. This
1329 /// constructor can also autoinsert before another instruction.
1330 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001331 Instruction *InsertBefore = 0);
1332
Chris Lattner454928e2005-01-29 00:31:36 +00001333 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1334 /// switch on and a default destination. The number of additional cases can
1335 /// be specified here to make memory allocation more efficient. This
1336 /// constructor also autoinserts at the end of the specified BasicBlock.
1337 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001338 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001339 ~SwitchInst();
1340
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001341
1342 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001343 inline Value *getCondition() const { return getOperand(0); }
1344 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001345
Chris Lattner454928e2005-01-29 00:31:36 +00001346 inline BasicBlock *getDefaultDest() const {
1347 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001348 }
1349
1350 /// getNumCases - return the number of 'cases' in this switch instruction.
1351 /// Note that case #0 is always the default case.
1352 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001353 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001354 }
1355
1356 /// getCaseValue - Return the specified case value. Note that case #0, the
1357 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001358 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001359 assert(i && i < getNumCases() && "Illegal case value to get!");
1360 return getSuccessorValue(i);
1361 }
1362
1363 /// getCaseValue - Return the specified case value. Note that case #0, the
1364 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001365 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001366 assert(i && i < getNumCases() && "Illegal case value to get!");
1367 return getSuccessorValue(i);
1368 }
1369
1370 /// findCaseValue - Search all of the case values for the specified constant.
1371 /// If it is explicitly handled, return the case number of it, otherwise
1372 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001373 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001374 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1375 if (getCaseValue(i) == C)
1376 return i;
1377 return 0;
1378 }
1379
Nick Lewycky011f1842006-09-18 19:03:59 +00001380 /// findCaseDest - Finds the unique case value for a given successor. Returns
1381 /// null if the successor is not found, not unique, or is the default case.
1382 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00001383 if (BB == getDefaultDest()) return NULL;
1384
Nick Lewycky011f1842006-09-18 19:03:59 +00001385 ConstantInt *CI = NULL;
1386 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1387 if (getSuccessor(i) == BB) {
1388 if (CI) return NULL; // Multiple cases lead to BB.
1389 else CI = getCaseValue(i);
1390 }
1391 }
1392 return CI;
1393 }
1394
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001395 /// addCase - Add an entry to the switch instruction...
1396 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001397 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001398
1399 /// removeCase - This method removes the specified successor from the switch
1400 /// instruction. Note that this cannot be used to remove the default
1401 /// destination (successor #0).
1402 ///
1403 void removeCase(unsigned idx);
1404
Chris Lattner454928e2005-01-29 00:31:36 +00001405 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001406
Chris Lattner454928e2005-01-29 00:31:36 +00001407 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1408 BasicBlock *getSuccessor(unsigned idx) const {
1409 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1410 return cast<BasicBlock>(getOperand(idx*2+1));
1411 }
1412 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001413 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001414 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001415 }
1416
1417 // getSuccessorValue - Return the value associated with the specified
1418 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001419 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001420 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001421 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001422 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001423
1424 // Methods for support type inquiry through isa, cast, and dyn_cast:
1425 static inline bool classof(const SwitchInst *) { return true; }
1426 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001427 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001428 }
1429 static inline bool classof(const Value *V) {
1430 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1431 }
Chris Lattner454928e2005-01-29 00:31:36 +00001432private:
1433 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1434 virtual unsigned getNumSuccessorsV() const;
1435 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001436};
1437
1438//===----------------------------------------------------------------------===//
1439// InvokeInst Class
1440//===----------------------------------------------------------------------===//
1441
1442//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001443
1444/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1445/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001446///
1447class InvokeInst : public TerminatorInst {
1448 InvokeInst(const InvokeInst &BI);
1449 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001450 Value* const *Args, unsigned NumArgs);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001451public:
1452 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001453 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1454 Instruction *InsertBefore = 0);
1455 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1456 Value* const* Args, unsigned NumArgs, const std::string &Name,
1457 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001458 ~InvokeInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001459
Chris Lattnerf319e832004-10-15 23:52:05 +00001460 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001461
Chris Lattner3340ffe2005-05-06 20:26:26 +00001462 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1463 /// function call.
1464 unsigned getCallingConv() const { return SubclassData; }
1465 void setCallingConv(unsigned CC) {
1466 SubclassData = CC;
1467 }
1468
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001469 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001470 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001471 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001472 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001473 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001474 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001475
1476 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001477 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001478
1479 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001480 BasicBlock *getNormalDest() const {
1481 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001482 }
Chris Lattner454928e2005-01-29 00:31:36 +00001483 BasicBlock *getUnwindDest() const {
1484 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001485 }
Chris Lattner454928e2005-01-29 00:31:36 +00001486 void setNormalDest(BasicBlock *B) {
1487 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001488 }
1489
Chris Lattner454928e2005-01-29 00:31:36 +00001490 void setUnwindDest(BasicBlock *B) {
1491 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001492 }
1493
Chris Lattner454928e2005-01-29 00:31:36 +00001494 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001495 assert(i < 2 && "Successor # out of range for invoke!");
1496 return i == 0 ? getNormalDest() : getUnwindDest();
1497 }
1498
Chris Lattner454928e2005-01-29 00:31:36 +00001499 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001500 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001501 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001502 }
1503
Chris Lattner454928e2005-01-29 00:31:36 +00001504 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001505
1506 // Methods for support type inquiry through isa, cast, and dyn_cast:
1507 static inline bool classof(const InvokeInst *) { return true; }
1508 static inline bool classof(const Instruction *I) {
1509 return (I->getOpcode() == Instruction::Invoke);
1510 }
1511 static inline bool classof(const Value *V) {
1512 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1513 }
Chris Lattner454928e2005-01-29 00:31:36 +00001514private:
1515 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1516 virtual unsigned getNumSuccessorsV() const;
1517 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001518};
1519
1520
1521//===----------------------------------------------------------------------===//
1522// UnwindInst Class
1523//===----------------------------------------------------------------------===//
1524
1525//===---------------------------------------------------------------------------
1526/// UnwindInst - Immediately exit the current function, unwinding the stack
1527/// until an invoke instruction is found.
1528///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001529class UnwindInst : public TerminatorInst {
1530public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001531 explicit UnwindInst(Instruction *InsertBefore = 0);
1532 explicit UnwindInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001533
Chris Lattnerf319e832004-10-15 23:52:05 +00001534 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001535
Chris Lattner454928e2005-01-29 00:31:36 +00001536 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001537
1538 // Methods for support type inquiry through isa, cast, and dyn_cast:
1539 static inline bool classof(const UnwindInst *) { return true; }
1540 static inline bool classof(const Instruction *I) {
1541 return I->getOpcode() == Instruction::Unwind;
1542 }
1543 static inline bool classof(const Value *V) {
1544 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1545 }
Chris Lattner454928e2005-01-29 00:31:36 +00001546private:
1547 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1548 virtual unsigned getNumSuccessorsV() const;
1549 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001550};
1551
Chris Lattner076b3f12004-10-16 18:05:54 +00001552//===----------------------------------------------------------------------===//
1553// UnreachableInst Class
1554//===----------------------------------------------------------------------===//
1555
1556//===---------------------------------------------------------------------------
1557/// UnreachableInst - This function has undefined behavior. In particular, the
1558/// presence of this instruction indicates some higher level knowledge that the
1559/// end of the block cannot be reached.
1560///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001561class UnreachableInst : public TerminatorInst {
1562public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001563 explicit UnreachableInst(Instruction *InsertBefore = 0);
1564 explicit UnreachableInst(BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00001565
1566 virtual UnreachableInst *clone() const;
1567
Chris Lattner454928e2005-01-29 00:31:36 +00001568 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001569
1570 // Methods for support type inquiry through isa, cast, and dyn_cast:
1571 static inline bool classof(const UnreachableInst *) { return true; }
1572 static inline bool classof(const Instruction *I) {
1573 return I->getOpcode() == Instruction::Unreachable;
1574 }
1575 static inline bool classof(const Value *V) {
1576 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1577 }
Chris Lattner454928e2005-01-29 00:31:36 +00001578private:
1579 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1580 virtual unsigned getNumSuccessorsV() const;
1581 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001582};
1583
Reid Spencer3da59db2006-11-27 01:05:10 +00001584//===----------------------------------------------------------------------===//
1585// TruncInst Class
1586//===----------------------------------------------------------------------===//
1587
1588/// @brief This class represents a truncation of integer types.
1589class TruncInst : public CastInst {
1590 /// Private copy constructor
1591 TruncInst(const TruncInst &CI)
1592 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1593 }
1594public:
1595 /// @brief Constructor with insert-before-instruction semantics
1596 TruncInst(
1597 Value *S, ///< The value to be truncated
1598 const Type *Ty, ///< The (smaller) type to truncate to
1599 const std::string &Name = "", ///< A name for the new instruction
1600 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1601 );
1602
1603 /// @brief Constructor with insert-at-end-of-block semantics
1604 TruncInst(
1605 Value *S, ///< The value to be truncated
1606 const Type *Ty, ///< The (smaller) type to truncate to
1607 const std::string &Name, ///< A name for the new instruction
1608 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1609 );
1610
1611 /// @brief Clone an identical TruncInst
1612 virtual CastInst *clone() const;
1613
1614 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1615 static inline bool classof(const TruncInst *) { return true; }
1616 static inline bool classof(const Instruction *I) {
1617 return I->getOpcode() == Trunc;
1618 }
1619 static inline bool classof(const Value *V) {
1620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1621 }
1622};
1623
1624//===----------------------------------------------------------------------===//
1625// ZExtInst Class
1626//===----------------------------------------------------------------------===//
1627
1628/// @brief This class represents zero extension of integer types.
1629class ZExtInst : public CastInst {
1630 /// @brief Private copy constructor
1631 ZExtInst(const ZExtInst &CI)
1632 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1633 }
1634public:
1635 /// @brief Constructor with insert-before-instruction semantics
1636 ZExtInst(
1637 Value *S, ///< The value to be zero extended
1638 const Type *Ty, ///< The type to zero extend to
1639 const std::string &Name = "", ///< A name for the new instruction
1640 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1641 );
1642
1643 /// @brief Constructor with insert-at-end semantics.
1644 ZExtInst(
1645 Value *S, ///< The value to be zero extended
1646 const Type *Ty, ///< The type to zero extend to
1647 const std::string &Name, ///< A name for the new instruction
1648 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1649 );
1650
1651 /// @brief Clone an identical ZExtInst
1652 virtual CastInst *clone() const;
1653
1654 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1655 static inline bool classof(const ZExtInst *) { return true; }
1656 static inline bool classof(const Instruction *I) {
1657 return I->getOpcode() == ZExt;
1658 }
1659 static inline bool classof(const Value *V) {
1660 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1661 }
1662};
1663
1664//===----------------------------------------------------------------------===//
1665// SExtInst Class
1666//===----------------------------------------------------------------------===//
1667
1668/// @brief This class represents a sign extension of integer types.
1669class SExtInst : public CastInst {
1670 /// @brief Private copy constructor
1671 SExtInst(const SExtInst &CI)
1672 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1673 }
1674public:
1675 /// @brief Constructor with insert-before-instruction semantics
1676 SExtInst(
1677 Value *S, ///< The value to be sign extended
1678 const Type *Ty, ///< The type to sign extend to
1679 const std::string &Name = "", ///< A name for the new instruction
1680 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1681 );
1682
1683 /// @brief Constructor with insert-at-end-of-block semantics
1684 SExtInst(
1685 Value *S, ///< The value to be sign extended
1686 const Type *Ty, ///< The type to sign extend to
1687 const std::string &Name, ///< A name for the new instruction
1688 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1689 );
1690
1691 /// @brief Clone an identical SExtInst
1692 virtual CastInst *clone() const;
1693
1694 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1695 static inline bool classof(const SExtInst *) { return true; }
1696 static inline bool classof(const Instruction *I) {
1697 return I->getOpcode() == SExt;
1698 }
1699 static inline bool classof(const Value *V) {
1700 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1701 }
1702};
1703
1704//===----------------------------------------------------------------------===//
1705// FPTruncInst Class
1706//===----------------------------------------------------------------------===//
1707
1708/// @brief This class represents a truncation of floating point types.
1709class FPTruncInst : public CastInst {
1710 FPTruncInst(const FPTruncInst &CI)
1711 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1712 }
1713public:
1714 /// @brief Constructor with insert-before-instruction semantics
1715 FPTruncInst(
1716 Value *S, ///< The value to be truncated
1717 const Type *Ty, ///< The type to truncate to
1718 const std::string &Name = "", ///< A name for the new instruction
1719 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1720 );
1721
1722 /// @brief Constructor with insert-before-instruction semantics
1723 FPTruncInst(
1724 Value *S, ///< The value to be truncated
1725 const Type *Ty, ///< The type to truncate to
1726 const std::string &Name, ///< A name for the new instruction
1727 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1728 );
1729
1730 /// @brief Clone an identical FPTruncInst
1731 virtual CastInst *clone() const;
1732
1733 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1734 static inline bool classof(const FPTruncInst *) { return true; }
1735 static inline bool classof(const Instruction *I) {
1736 return I->getOpcode() == FPTrunc;
1737 }
1738 static inline bool classof(const Value *V) {
1739 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1740 }
1741};
1742
1743//===----------------------------------------------------------------------===//
1744// FPExtInst Class
1745//===----------------------------------------------------------------------===//
1746
1747/// @brief This class represents an extension of floating point types.
1748class FPExtInst : public CastInst {
1749 FPExtInst(const FPExtInst &CI)
1750 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1751 }
1752public:
1753 /// @brief Constructor with insert-before-instruction semantics
1754 FPExtInst(
1755 Value *S, ///< The value to be extended
1756 const Type *Ty, ///< The type to extend to
1757 const std::string &Name = "", ///< A name for the new instruction
1758 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1759 );
1760
1761 /// @brief Constructor with insert-at-end-of-block semantics
1762 FPExtInst(
1763 Value *S, ///< The value to be extended
1764 const Type *Ty, ///< The type to extend to
1765 const std::string &Name, ///< A name for the new instruction
1766 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1767 );
1768
1769 /// @brief Clone an identical FPExtInst
1770 virtual CastInst *clone() const;
1771
1772 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1773 static inline bool classof(const FPExtInst *) { return true; }
1774 static inline bool classof(const Instruction *I) {
1775 return I->getOpcode() == FPExt;
1776 }
1777 static inline bool classof(const Value *V) {
1778 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1779 }
1780};
1781
1782//===----------------------------------------------------------------------===//
1783// UIToFPInst Class
1784//===----------------------------------------------------------------------===//
1785
1786/// @brief This class represents a cast unsigned integer to floating point.
1787class UIToFPInst : public CastInst {
1788 UIToFPInst(const UIToFPInst &CI)
1789 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1790 }
1791public:
1792 /// @brief Constructor with insert-before-instruction semantics
1793 UIToFPInst(
1794 Value *S, ///< The value to be converted
1795 const Type *Ty, ///< The type to convert to
1796 const std::string &Name = "", ///< A name for the new instruction
1797 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1798 );
1799
1800 /// @brief Constructor with insert-at-end-of-block semantics
1801 UIToFPInst(
1802 Value *S, ///< The value to be converted
1803 const Type *Ty, ///< The type to convert to
1804 const std::string &Name, ///< A name for the new instruction
1805 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1806 );
1807
1808 /// @brief Clone an identical UIToFPInst
1809 virtual CastInst *clone() const;
1810
1811 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1812 static inline bool classof(const UIToFPInst *) { return true; }
1813 static inline bool classof(const Instruction *I) {
1814 return I->getOpcode() == UIToFP;
1815 }
1816 static inline bool classof(const Value *V) {
1817 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1818 }
1819};
1820
1821//===----------------------------------------------------------------------===//
1822// SIToFPInst Class
1823//===----------------------------------------------------------------------===//
1824
1825/// @brief This class represents a cast from signed integer to floating point.
1826class SIToFPInst : public CastInst {
1827 SIToFPInst(const SIToFPInst &CI)
1828 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1829 }
1830public:
1831 /// @brief Constructor with insert-before-instruction semantics
1832 SIToFPInst(
1833 Value *S, ///< The value to be converted
1834 const Type *Ty, ///< The type to convert to
1835 const std::string &Name = "", ///< A name for the new instruction
1836 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1837 );
1838
1839 /// @brief Constructor with insert-at-end-of-block semantics
1840 SIToFPInst(
1841 Value *S, ///< The value to be converted
1842 const Type *Ty, ///< The type to convert to
1843 const std::string &Name, ///< A name for the new instruction
1844 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1845 );
1846
1847 /// @brief Clone an identical SIToFPInst
1848 virtual CastInst *clone() const;
1849
1850 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1851 static inline bool classof(const SIToFPInst *) { return true; }
1852 static inline bool classof(const Instruction *I) {
1853 return I->getOpcode() == SIToFP;
1854 }
1855 static inline bool classof(const Value *V) {
1856 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1857 }
1858};
1859
1860//===----------------------------------------------------------------------===//
1861// FPToUIInst Class
1862//===----------------------------------------------------------------------===//
1863
1864/// @brief This class represents a cast from floating point to unsigned integer
1865class FPToUIInst : public CastInst {
1866 FPToUIInst(const FPToUIInst &CI)
1867 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1868 }
1869public:
1870 /// @brief Constructor with insert-before-instruction semantics
1871 FPToUIInst(
1872 Value *S, ///< The value to be converted
1873 const Type *Ty, ///< The type to convert to
1874 const std::string &Name = "", ///< A name for the new instruction
1875 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1876 );
1877
1878 /// @brief Constructor with insert-at-end-of-block semantics
1879 FPToUIInst(
1880 Value *S, ///< The value to be converted
1881 const Type *Ty, ///< The type to convert to
1882 const std::string &Name, ///< A name for the new instruction
1883 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1884 );
1885
1886 /// @brief Clone an identical FPToUIInst
1887 virtual CastInst *clone() const;
1888
1889 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1890 static inline bool classof(const FPToUIInst *) { return true; }
1891 static inline bool classof(const Instruction *I) {
1892 return I->getOpcode() == FPToUI;
1893 }
1894 static inline bool classof(const Value *V) {
1895 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1896 }
1897};
1898
1899//===----------------------------------------------------------------------===//
1900// FPToSIInst Class
1901//===----------------------------------------------------------------------===//
1902
1903/// @brief This class represents a cast from floating point to signed integer.
1904class FPToSIInst : public CastInst {
1905 FPToSIInst(const FPToSIInst &CI)
1906 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1907 }
1908public:
1909 /// @brief Constructor with insert-before-instruction semantics
1910 FPToSIInst(
1911 Value *S, ///< The value to be converted
1912 const Type *Ty, ///< The type to convert to
1913 const std::string &Name = "", ///< A name for the new instruction
1914 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1915 );
1916
1917 /// @brief Constructor with insert-at-end-of-block semantics
1918 FPToSIInst(
1919 Value *S, ///< The value to be converted
1920 const Type *Ty, ///< The type to convert to
1921 const std::string &Name, ///< A name for the new instruction
1922 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1923 );
1924
1925 /// @brief Clone an identical FPToSIInst
1926 virtual CastInst *clone() const;
1927
1928 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1929 static inline bool classof(const FPToSIInst *) { return true; }
1930 static inline bool classof(const Instruction *I) {
1931 return I->getOpcode() == FPToSI;
1932 }
1933 static inline bool classof(const Value *V) {
1934 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1935 }
1936};
1937
1938//===----------------------------------------------------------------------===//
1939// IntToPtrInst Class
1940//===----------------------------------------------------------------------===//
1941
1942/// @brief This class represents a cast from an integer to a pointer.
1943class IntToPtrInst : public CastInst {
1944 IntToPtrInst(const IntToPtrInst &CI)
1945 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1946 }
1947public:
1948 /// @brief Constructor with insert-before-instruction semantics
1949 IntToPtrInst(
1950 Value *S, ///< The value to be converted
1951 const Type *Ty, ///< The type to convert to
1952 const std::string &Name = "", ///< A name for the new instruction
1953 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1954 );
1955
1956 /// @brief Constructor with insert-at-end-of-block semantics
1957 IntToPtrInst(
1958 Value *S, ///< The value to be converted
1959 const Type *Ty, ///< The type to convert to
1960 const std::string &Name, ///< A name for the new instruction
1961 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1962 );
1963
1964 /// @brief Clone an identical IntToPtrInst
1965 virtual CastInst *clone() const;
1966
1967 // Methods for support type inquiry through isa, cast, and dyn_cast:
1968 static inline bool classof(const IntToPtrInst *) { return true; }
1969 static inline bool classof(const Instruction *I) {
1970 return I->getOpcode() == IntToPtr;
1971 }
1972 static inline bool classof(const Value *V) {
1973 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1974 }
1975};
1976
1977//===----------------------------------------------------------------------===//
1978// PtrToIntInst Class
1979//===----------------------------------------------------------------------===//
1980
1981/// @brief This class represents a cast from a pointer to an integer
1982class PtrToIntInst : public CastInst {
1983 PtrToIntInst(const PtrToIntInst &CI)
1984 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
1985 }
1986public:
1987 /// @brief Constructor with insert-before-instruction semantics
1988 PtrToIntInst(
1989 Value *S, ///< The value to be converted
1990 const Type *Ty, ///< The type to convert to
1991 const std::string &Name = "", ///< A name for the new instruction
1992 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1993 );
1994
1995 /// @brief Constructor with insert-at-end-of-block semantics
1996 PtrToIntInst(
1997 Value *S, ///< The value to be converted
1998 const Type *Ty, ///< The type to convert to
1999 const std::string &Name, ///< A name for the new instruction
2000 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2001 );
2002
2003 /// @brief Clone an identical PtrToIntInst
2004 virtual CastInst *clone() const;
2005
2006 // Methods for support type inquiry through isa, cast, and dyn_cast:
2007 static inline bool classof(const PtrToIntInst *) { return true; }
2008 static inline bool classof(const Instruction *I) {
2009 return I->getOpcode() == PtrToInt;
2010 }
2011 static inline bool classof(const Value *V) {
2012 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2013 }
2014};
2015
2016//===----------------------------------------------------------------------===//
2017// BitCastInst Class
2018//===----------------------------------------------------------------------===//
2019
2020/// @brief This class represents a no-op cast from one type to another.
2021class BitCastInst : public CastInst {
2022 BitCastInst(const BitCastInst &CI)
2023 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2024 }
2025public:
2026 /// @brief Constructor with insert-before-instruction semantics
2027 BitCastInst(
2028 Value *S, ///< The value to be casted
2029 const Type *Ty, ///< The type to casted to
2030 const std::string &Name = "", ///< A name for the new instruction
2031 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2032 );
2033
2034 /// @brief Constructor with insert-at-end-of-block semantics
2035 BitCastInst(
2036 Value *S, ///< The value to be casted
2037 const Type *Ty, ///< The type to casted to
2038 const std::string &Name, ///< A name for the new instruction
2039 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2040 );
2041
2042 /// @brief Clone an identical BitCastInst
2043 virtual CastInst *clone() const;
2044
2045 // Methods for support type inquiry through isa, cast, and dyn_cast:
2046 static inline bool classof(const BitCastInst *) { return true; }
2047 static inline bool classof(const Instruction *I) {
2048 return I->getOpcode() == BitCast;
2049 }
2050 static inline bool classof(const Value *V) {
2051 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2052 }
2053};
2054
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002055} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00002056
2057#endif