blob: c78426a239f09cfeefe7fa9494e9e0fc2cc3ad91 [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;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000027
28//===----------------------------------------------------------------------===//
29// AllocationInst Class
30//===----------------------------------------------------------------------===//
31
32/// AllocationInst - This class is the common base class of MallocInst and
33/// AllocaInst.
34///
Chris Lattner454928e2005-01-29 00:31:36 +000035class AllocationInst : public UnaryInstruction {
Nate Begeman14b05292005-11-05 09:21:28 +000036 unsigned Alignment;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000037protected:
Nate Begeman14b05292005-11-05 09:21:28 +000038 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000039 const std::string &Name = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000040 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000041 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000042public:
Chris Lattner70aa33e2006-06-21 16:53:47 +000043 // Out of line virtual method, so the vtable, etc has a home.
44 virtual ~AllocationInst();
Chris Lattnerf56a8db2006-10-03 17:09:12 +000045
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000046 /// isArrayAllocation - Return true if there is an allocation size parameter
47 /// to the allocation instruction that is not 1.
48 ///
49 bool isArrayAllocation() const;
50
51 /// getArraySize - Get the number of element allocated, for a simple
52 /// allocation of a single element, this will return a constant 1 value.
53 ///
Chris Lattner454928e2005-01-29 00:31:36 +000054 inline const Value *getArraySize() const { return getOperand(0); }
55 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000056
57 /// getType - Overload to return most specific pointer type
58 ///
59 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000060 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000061 }
62
63 /// getAllocatedType - Return the type that is being allocated by the
64 /// instruction.
65 ///
66 const Type *getAllocatedType() const;
67
Nate Begeman14b05292005-11-05 09:21:28 +000068 /// getAlignment - Return the alignment of the memory that is being allocated
69 /// by the instruction.
70 ///
71 unsigned getAlignment() const { return Alignment; }
Chris Lattner8ae779d2005-11-05 21:58:30 +000072 void setAlignment(unsigned Align) {
73 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
74 Alignment = Align;
75 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +000076
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000077 virtual Instruction *clone() const = 0;
78
79 // Methods for support type inquiry through isa, cast, and dyn_cast:
80 static inline bool classof(const AllocationInst *) { return true; }
81 static inline bool classof(const Instruction *I) {
82 return I->getOpcode() == Instruction::Alloca ||
83 I->getOpcode() == Instruction::Malloc;
84 }
85 static inline bool classof(const Value *V) {
86 return isa<Instruction>(V) && classof(cast<Instruction>(V));
87 }
88};
89
90
91//===----------------------------------------------------------------------===//
92// MallocInst Class
93//===----------------------------------------------------------------------===//
94
95/// MallocInst - an instruction to allocated memory on the heap
96///
97class MallocInst : public AllocationInst {
98 MallocInst(const MallocInst &MI);
99public:
100 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
101 const std::string &Name = "",
102 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000103 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000104 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
105 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000107
108 MallocInst(const Type *Ty, const std::string &Name,
109 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000110 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
111 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000113
114 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000115 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000116 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
117 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000118 const std::string &Name = "",
119 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000120 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000121
Chris Lattnerf319e832004-10-15 23:52:05 +0000122 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000123
124 // Methods for support type inquiry through isa, cast, and dyn_cast:
125 static inline bool classof(const MallocInst *) { return true; }
126 static inline bool classof(const Instruction *I) {
127 return (I->getOpcode() == Instruction::Malloc);
128 }
129 static inline bool classof(const Value *V) {
130 return isa<Instruction>(V) && classof(cast<Instruction>(V));
131 }
132};
133
134
135//===----------------------------------------------------------------------===//
136// AllocaInst Class
137//===----------------------------------------------------------------------===//
138
139/// AllocaInst - an instruction to allocate memory on the stack
140///
141class AllocaInst : public AllocationInst {
142 AllocaInst(const AllocaInst &);
143public:
144 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
145 const std::string &Name = "",
146 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000147 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000148 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
149 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000150 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerb77780e2006-05-10 04:38:35 +0000151
152 AllocaInst(const Type *Ty, const std::string &Name,
153 Instruction *InsertBefore = 0)
154 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
155 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000157
Chris Lattnerb77780e2006-05-10 04:38:35 +0000158 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
159 const std::string &Name = "", Instruction *InsertBefore = 0)
160 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
Nate Begeman14b05292005-11-05 09:21:28 +0000161 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
162 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000163 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000164
Chris Lattnerf319e832004-10-15 23:52:05 +0000165 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000166
167 // Methods for support type inquiry through isa, cast, and dyn_cast:
168 static inline bool classof(const AllocaInst *) { return true; }
169 static inline bool classof(const Instruction *I) {
170 return (I->getOpcode() == Instruction::Alloca);
171 }
172 static inline bool classof(const Value *V) {
173 return isa<Instruction>(V) && classof(cast<Instruction>(V));
174 }
175};
176
177
178//===----------------------------------------------------------------------===//
179// FreeInst Class
180//===----------------------------------------------------------------------===//
181
182/// FreeInst - an instruction to deallocate memory
183///
Chris Lattner454928e2005-01-29 00:31:36 +0000184class FreeInst : public UnaryInstruction {
185 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000186public:
187 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
188 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
189
Chris Lattnerf319e832004-10-15 23:52:05 +0000190 virtual FreeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000191
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000192 // Methods for support type inquiry through isa, cast, and dyn_cast:
193 static inline bool classof(const FreeInst *) { return true; }
194 static inline bool classof(const Instruction *I) {
195 return (I->getOpcode() == Instruction::Free);
196 }
197 static inline bool classof(const Value *V) {
198 return isa<Instruction>(V) && classof(cast<Instruction>(V));
199 }
200};
201
202
203//===----------------------------------------------------------------------===//
204// LoadInst Class
205//===----------------------------------------------------------------------===//
206
Chris Lattner88fe29a2005-02-05 01:44:18 +0000207/// LoadInst - an instruction for reading from memory. This uses the
208/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000209///
Chris Lattner454928e2005-01-29 00:31:36 +0000210class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000211 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000212 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
213 setVolatile(LI.isVolatile());
Misha Brukman9769ab22005-04-21 20:19:05 +0000214
Chris Lattner454928e2005-01-29 00:31:36 +0000215#ifndef NDEBUG
216 AssertOK();
217#endif
218 }
219 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000220public:
221 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
222 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf00042a2007-02-13 07:54:42 +0000223 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
224 Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000225 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
226 BasicBlock *InsertAtEnd);
227
Chris Lattnerf00042a2007-02-13 07:54:42 +0000228 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
229 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
230 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
231 Instruction *InsertBefore = 0);
232 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
233 BasicBlock *InsertAtEnd);
234
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000235 /// isVolatile - Return true if this is a load from a volatile memory
236 /// location.
237 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000238 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000239
240 /// setVolatile - Specify whether this is a volatile load or not.
241 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000242 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000243
Chris Lattnerf319e832004-10-15 23:52:05 +0000244 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000245
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000246 Value *getPointerOperand() { return getOperand(0); }
247 const Value *getPointerOperand() const { return getOperand(0); }
248 static unsigned getPointerOperandIndex() { return 0U; }
249
250 // Methods for support type inquiry through isa, cast, and dyn_cast:
251 static inline bool classof(const LoadInst *) { return true; }
252 static inline bool classof(const Instruction *I) {
253 return I->getOpcode() == Instruction::Load;
254 }
255 static inline bool classof(const Value *V) {
256 return isa<Instruction>(V) && classof(cast<Instruction>(V));
257 }
258};
259
260
261//===----------------------------------------------------------------------===//
262// StoreInst Class
263//===----------------------------------------------------------------------===//
264
Misha Brukman9769ab22005-04-21 20:19:05 +0000265/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000266///
267class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000268 Use Ops[2];
Chris Lattner88fe29a2005-02-05 01:44:18 +0000269 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000270 Ops[0].init(SI.Ops[0], this);
271 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000272 setVolatile(SI.isVolatile());
Chris Lattner454928e2005-01-29 00:31:36 +0000273#ifndef NDEBUG
274 AssertOK();
275#endif
276 }
277 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000278public:
279 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
280 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
281 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
282 Instruction *InsertBefore = 0);
283 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
284
285
286 /// isVolatile - Return true if this is a load from a volatile memory
287 /// location.
288 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000289 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000290
291 /// setVolatile - Specify whether this is a volatile load or not.
292 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000293 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000294
Chris Lattner454928e2005-01-29 00:31:36 +0000295 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000296 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000297 assert(i < 2 && "getOperand() out of range!");
298 return Ops[i];
299 }
300 void setOperand(unsigned i, Value *Val) {
301 assert(i < 2 && "setOperand() out of range!");
302 Ops[i] = Val;
303 }
304 unsigned getNumOperands() const { return 2; }
305
306
Chris Lattnerf319e832004-10-15 23:52:05 +0000307 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000308
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000309 Value *getPointerOperand() { return getOperand(1); }
310 const Value *getPointerOperand() const { return getOperand(1); }
311 static unsigned getPointerOperandIndex() { return 1U; }
312
313 // Methods for support type inquiry through isa, cast, and dyn_cast:
314 static inline bool classof(const StoreInst *) { return true; }
315 static inline bool classof(const Instruction *I) {
316 return I->getOpcode() == Instruction::Store;
317 }
318 static inline bool classof(const Value *V) {
319 return isa<Instruction>(V) && classof(cast<Instruction>(V));
320 }
321};
322
323
324//===----------------------------------------------------------------------===//
325// GetElementPtrInst Class
326//===----------------------------------------------------------------------===//
327
328/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
329/// access elements of arrays and structs
330///
331class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000332 GetElementPtrInst(const GetElementPtrInst &GEPI)
333 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
334 0, GEPI.getNumOperands()) {
335 Use *OL = OperandList = new Use[NumOperands];
336 Use *GEPIOL = GEPI.OperandList;
337 for (unsigned i = 0, E = NumOperands; i != E; ++i)
338 OL[i].init(GEPIOL[i], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000339 }
Chris Lattner6ffbe172007-01-31 19:47:18 +0000340 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000341 void init(Value *Ptr, Value *Idx0, Value *Idx1);
Chris Lattner38bacf22005-05-03 05:43:30 +0000342 void init(Value *Ptr, Value *Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000343public:
344 /// Constructors - Create a getelementptr instruction with a base pointer an
345 /// list of indices. The first ctor can optionally insert before an existing
346 /// instruction, the second appends the new instruction to the specified
347 /// BasicBlock.
Chris Lattnerfb110532007-01-31 04:39:29 +0000348 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
349 const std::string &Name = "", Instruction *InsertBefore =0);
350 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
351 const std::string &Name, BasicBlock *InsertAtEnd);
352
Chris Lattner38bacf22005-05-03 05:43:30 +0000353 /// Constructors - These two constructors are convenience methods because one
354 /// and two index getelementptr instructions are so common.
355 GetElementPtrInst(Value *Ptr, Value *Idx,
356 const std::string &Name = "", Instruction *InsertBefore =0);
357 GetElementPtrInst(Value *Ptr, Value *Idx,
358 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000359 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000360 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000361 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000362 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000363 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000364
Chris Lattnerf319e832004-10-15 23:52:05 +0000365 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000366
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000367 // getType - Overload to return most specific pointer type...
368 inline const PointerType *getType() const {
369 return reinterpret_cast<const PointerType*>(Instruction::getType());
370 }
371
372 /// getIndexedType - Returns the type of the element that would be loaded with
373 /// a load instruction with the specified parameters.
374 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000375 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000376 /// pointer type.
377 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000378 static const Type *getIndexedType(const Type *Ptr,
Chris Lattnerfb110532007-01-31 04:39:29 +0000379 Value* const *Idx, unsigned NumIdx,
Misha Brukman91102862005-03-16 03:46:55 +0000380 bool AllowStructLeaf = false);
Chris Lattnerfb110532007-01-31 04:39:29 +0000381
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000382 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000383 bool AllowStructLeaf = false);
Chris Lattner38bacf22005-05-03 05:43:30 +0000384 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000385
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000386 inline op_iterator idx_begin() { return op_begin()+1; }
387 inline const_op_iterator idx_begin() const { return op_begin()+1; }
388 inline op_iterator idx_end() { return op_end(); }
389 inline const_op_iterator idx_end() const { return op_end(); }
390
391 Value *getPointerOperand() {
392 return getOperand(0);
393 }
394 const Value *getPointerOperand() const {
395 return getOperand(0);
396 }
397 static unsigned getPointerOperandIndex() {
398 return 0U; // get index for modifying correct operand
399 }
400
401 inline unsigned getNumIndices() const { // Note: always non-negative
402 return getNumOperands() - 1;
403 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000404
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000405 inline bool hasIndices() const {
406 return getNumOperands() > 1;
407 }
408
409 // Methods for support type inquiry through isa, cast, and dyn_cast:
410 static inline bool classof(const GetElementPtrInst *) { return true; }
411 static inline bool classof(const Instruction *I) {
412 return (I->getOpcode() == Instruction::GetElementPtr);
413 }
414 static inline bool classof(const Value *V) {
415 return isa<Instruction>(V) && classof(cast<Instruction>(V));
416 }
417};
418
419//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000420// ICmpInst Class
421//===----------------------------------------------------------------------===//
422
423/// This instruction compares its operands according to the predicate given
424/// to the constructor. It only operates on integers, pointers, or packed
425/// vectors of integrals. The two operands must be the same type.
426/// @brief Represent an integer comparison operator.
427class ICmpInst: public CmpInst {
428public:
429 /// This enumeration lists the possible predicates for the ICmpInst. The
430 /// values in the range 0-31 are reserved for FCmpInst while values in the
431 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
432 /// predicate values are not overlapping between the classes.
433 enum Predicate {
434 ICMP_EQ = 32, ///< equal
435 ICMP_NE = 33, ///< not equal
436 ICMP_UGT = 34, ///< unsigned greater than
437 ICMP_UGE = 35, ///< unsigned greater or equal
438 ICMP_ULT = 36, ///< unsigned less than
439 ICMP_ULE = 37, ///< unsigned less or equal
440 ICMP_SGT = 38, ///< signed greater than
441 ICMP_SGE = 39, ///< signed greater or equal
442 ICMP_SLT = 40, ///< signed less than
443 ICMP_SLE = 41, ///< signed less or equal
444 FIRST_ICMP_PREDICATE = ICMP_EQ,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000445 LAST_ICMP_PREDICATE = ICMP_SLE,
446 BAD_ICMP_PREDICATE = ICMP_SLE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000447 };
448
449 /// @brief Constructor with insert-before-instruction semantics.
450 ICmpInst(
451 Predicate pred, ///< The predicate to use for the comparison
452 Value *LHS, ///< The left-hand-side of the expression
453 Value *RHS, ///< The right-hand-side of the expression
454 const std::string &Name = "", ///< Name of the instruction
455 Instruction *InsertBefore = 0 ///< Where to insert
456 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
457 }
458
459 /// @brief Constructor with insert-at-block-end semantics.
460 ICmpInst(
461 Predicate pred, ///< The predicate to use for the comparison
462 Value *LHS, ///< The left-hand-side of the expression
463 Value *RHS, ///< The right-hand-side of the expression
464 const std::string &Name, ///< Name of the instruction
465 BasicBlock *InsertAtEnd ///< Block to insert into.
466 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
467 }
468
469 /// @brief Return the predicate for this instruction.
470 Predicate getPredicate() const { return Predicate(SubclassData); }
471
Chris Lattnerb769d562007-01-14 19:41:24 +0000472 /// @brief Set the predicate for this instruction to the specified value.
473 void setPredicate(Predicate P) { SubclassData = P; }
474
Reid Spencer45fb3f32006-11-20 01:22:35 +0000475 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
476 /// @returns the inverse predicate for the instruction's current predicate.
477 /// @brief Return the inverse of the instruction's predicate.
478 Predicate getInversePredicate() const {
479 return getInversePredicate(getPredicate());
480 }
481
482 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
483 /// @returns the inverse predicate for predicate provided in \p pred.
484 /// @brief Return the inverse of a given predicate
485 static Predicate getInversePredicate(Predicate pred);
486
487 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
488 /// @returns the predicate that would be the result of exchanging the two
489 /// operands of the ICmpInst instruction without changing the result
490 /// produced.
491 /// @brief Return the predicate as if the operands were swapped
492 Predicate getSwappedPredicate() const {
493 return getSwappedPredicate(getPredicate());
494 }
495
496 /// This is a static version that you can use without an instruction
497 /// available.
498 /// @brief Return the predicate as if the operands were swapped.
Reid Spencere4d87aa2006-12-23 06:05:41 +0000499 static Predicate getSwappedPredicate(Predicate pred);
500
501 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
502 /// @returns the predicate that would be the result if the operand were
503 /// regarded as signed.
504 /// @brief Return the signed version of the predicate
505 Predicate getSignedPredicate() const {
506 return getSignedPredicate(getPredicate());
507 }
508
509 /// This is a static version that you can use without an instruction.
510 /// @brief Return the signed version of the predicate.
511 static Predicate getSignedPredicate(Predicate pred);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000512
513 /// This also tests for commutativity. If isEquality() returns true then
Reid Spencere4d87aa2006-12-23 06:05:41 +0000514 /// the predicate is also commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000515 /// @returns true if the predicate of this instruction is EQ or NE.
516 /// @brief Determine if this is an equality predicate.
517 bool isEquality() const {
518 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
519 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000520
521 /// @returns true if the predicate of this ICmpInst is commutative
522 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000523 bool isCommutative() const { return isEquality(); }
524
525 /// @returns true if the predicate is relational (not EQ or NE).
526 /// @brief Determine if this a relational predicate.
527 bool isRelational() const {
528 return !isEquality();
529 }
530
Reid Spencere4d87aa2006-12-23 06:05:41 +0000531 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
532 /// @brief Determine if this instruction's predicate is signed.
533 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
534
535 /// @returns true if the predicate provided is signed, false otherwise
536 /// @brief Determine if the predicate is signed.
537 static bool isSignedPredicate(Predicate pred);
538
Reid Spencer45fb3f32006-11-20 01:22:35 +0000539 /// Exchange the two operands to this instruction in such a way that it does
540 /// not modify the semantics of the instruction. The predicate value may be
541 /// changed to retain the same result if the predicate is order dependent
542 /// (e.g. ult).
543 /// @brief Swap operands and adjust predicate.
544 void swapOperands() {
545 SubclassData = getSwappedPredicate();
546 std::swap(Ops[0], Ops[1]);
547 }
548
549 // Methods for support type inquiry through isa, cast, and dyn_cast:
550 static inline bool classof(const ICmpInst *) { return true; }
551 static inline bool classof(const Instruction *I) {
552 return I->getOpcode() == Instruction::ICmp;
553 }
554 static inline bool classof(const Value *V) {
555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
556 }
557};
558
559//===----------------------------------------------------------------------===//
560// FCmpInst Class
561//===----------------------------------------------------------------------===//
562
563/// This instruction compares its operands according to the predicate given
564/// to the constructor. It only operates on floating point values or packed
565/// vectors of floating point values. The operands must be identical types.
566/// @brief Represents a floating point comparison operator.
567class FCmpInst: public CmpInst {
568public:
569 /// This enumeration lists the possible predicates for the FCmpInst. Values
570 /// in the range 0-31 are reserved for FCmpInst.
571 enum Predicate {
572 // Opcode U L G E Intuitive operation
573 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
574 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
575 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
576 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
577 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
578 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
579 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
580 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
581 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
582 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
583 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
584 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
585 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
586 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
587 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
588 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
589 FIRST_FCMP_PREDICATE = FCMP_FALSE,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000590 LAST_FCMP_PREDICATE = FCMP_TRUE,
591 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000592 };
593
594 /// @brief Constructor with insert-before-instruction semantics.
595 FCmpInst(
596 Predicate pred, ///< The predicate to use for the comparison
597 Value *LHS, ///< The left-hand-side of the expression
598 Value *RHS, ///< The right-hand-side of the expression
599 const std::string &Name = "", ///< Name of the instruction
600 Instruction *InsertBefore = 0 ///< Where to insert
601 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
602 }
603
604 /// @brief Constructor with insert-at-block-end semantics.
605 FCmpInst(
606 Predicate pred, ///< The predicate to use for the comparison
607 Value *LHS, ///< The left-hand-side of the expression
608 Value *RHS, ///< The right-hand-side of the expression
609 const std::string &Name, ///< Name of the instruction
610 BasicBlock *InsertAtEnd ///< Block to insert into.
611 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
612 }
613
614 /// @brief Return the predicate for this instruction.
615 Predicate getPredicate() const { return Predicate(SubclassData); }
616
Chris Lattnerb769d562007-01-14 19:41:24 +0000617 /// @brief Set the predicate for this instruction to the specified value.
618 void setPredicate(Predicate P) { SubclassData = P; }
619
Reid Spencer45fb3f32006-11-20 01:22:35 +0000620 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
621 /// @returns the inverse predicate for the instructions current predicate.
622 /// @brief Return the inverse of the predicate
623 Predicate getInversePredicate() const {
624 return getInversePredicate(getPredicate());
625 }
626
627 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
628 /// @returns the inverse predicate for \p pred.
629 /// @brief Return the inverse of a given predicate
630 static Predicate getInversePredicate(Predicate pred);
631
632 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
633 /// @returns the predicate that would be the result of exchanging the two
634 /// operands of the ICmpInst instruction without changing the result
635 /// produced.
636 /// @brief Return the predicate as if the operands were swapped
637 Predicate getSwappedPredicate() const {
638 return getSwappedPredicate(getPredicate());
639 }
640
641 /// This is a static version that you can use without an instruction
642 /// available.
643 /// @brief Return the predicate as if the operands were swapped.
644 static Predicate getSwappedPredicate(Predicate Opcode);
645
646 /// This also tests for commutativity. If isEquality() returns true then
647 /// the predicate is also commutative. Only the equality predicates are
648 /// commutative.
649 /// @returns true if the predicate of this instruction is EQ or NE.
650 /// @brief Determine if this is an equality predicate.
651 bool isEquality() const {
652 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
653 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
654 }
655 bool isCommutative() const { return isEquality(); }
656
657 /// @returns true if the predicate is relational (not EQ or NE).
658 /// @brief Determine if this a relational predicate.
659 bool isRelational() const { return !isEquality(); }
660
661 /// Exchange the two operands to this instruction in such a way that it does
662 /// not modify the semantics of the instruction. The predicate value may be
663 /// changed to retain the same result if the predicate is order dependent
664 /// (e.g. ult).
665 /// @brief Swap operands and adjust predicate.
666 void swapOperands() {
667 SubclassData = getSwappedPredicate();
668 std::swap(Ops[0], Ops[1]);
669 }
670
671 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
672 static inline bool classof(const FCmpInst *) { return true; }
673 static inline bool classof(const Instruction *I) {
674 return I->getOpcode() == Instruction::FCmp;
675 }
676 static inline bool classof(const Value *V) {
677 return isa<Instruction>(V) && classof(cast<Instruction>(V));
678 }
679};
680
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000681//===----------------------------------------------------------------------===//
682// CallInst Class
683//===----------------------------------------------------------------------===//
684
685/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000686/// machine's calling convention. This class uses low bit of the SubClassData
687/// field to indicate whether or not this is a tail call. The rest of the bits
688/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000689///
690class CallInst : public Instruction {
691 CallInst(const CallInst &CI);
Chris Lattnerd54f4322007-02-13 00:58:44 +0000692 void init(Value *Func, Value* const *Params, unsigned NumParams);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000693 void init(Value *Func, Value *Actual1, Value *Actual2);
694 void init(Value *Func, Value *Actual);
695 void init(Value *Func);
696
697public:
Chris Lattnerd2dd1502007-02-13 01:04:01 +0000698 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
699 const std::string &Name = "", Instruction *InsertBefore = 0);
700 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
701 const std::string &Name, BasicBlock *InsertAtEnd);
702
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000703 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
704 // actuals, respectively.
705 CallInst(Value *F, Value *Actual1, Value *Actual2,
706 const std::string& Name = "", Instruction *InsertBefore = 0);
707 CallInst(Value *F, Value *Actual1, Value *Actual2,
708 const std::string& Name, BasicBlock *InsertAtEnd);
709 CallInst(Value *F, Value *Actual, const std::string& Name = "",
710 Instruction *InsertBefore = 0);
711 CallInst(Value *F, Value *Actual, const std::string& Name,
712 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000713 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000714 Instruction *InsertBefore = 0);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000715 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000716 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000717
Chris Lattnerf319e832004-10-15 23:52:05 +0000718 virtual CallInst *clone() const;
Chris Lattnerbb5493d2007-02-15 23:15:00 +0000719
Chris Lattner3340ffe2005-05-06 20:26:26 +0000720 bool isTailCall() const { return SubclassData & 1; }
721 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000722 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000723 }
724
725 /// getCallingConv/setCallingConv - Get or set the calling convention of this
726 /// function call.
727 unsigned getCallingConv() const { return SubclassData >> 1; }
728 void setCallingConv(unsigned CC) {
729 SubclassData = (SubclassData & 1) | (CC << 1);
730 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000731
Chris Lattner721aef62004-11-18 17:46:57 +0000732 /// getCalledFunction - Return the function being called by this instruction
733 /// if it is a direct call. If it is a call through a function pointer,
734 /// return null.
735 Function *getCalledFunction() const {
Reid Spenceredd5d9e2005-05-15 16:13:11 +0000736 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
Chris Lattner721aef62004-11-18 17:46:57 +0000737 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000738
Reid Spencerc25ec252006-12-29 04:10:59 +0000739 /// getCalledValue - Get a pointer to the function that is invoked by this
740 /// instruction
Chris Lattner454928e2005-01-29 00:31:36 +0000741 inline const Value *getCalledValue() const { return getOperand(0); }
742 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000743
744 // Methods for support type inquiry through isa, cast, and dyn_cast:
745 static inline bool classof(const CallInst *) { return true; }
746 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000747 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000748 }
749 static inline bool classof(const Value *V) {
750 return isa<Instruction>(V) && classof(cast<Instruction>(V));
751 }
752};
753
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000754//===----------------------------------------------------------------------===//
755// SelectInst Class
756//===----------------------------------------------------------------------===//
757
758/// SelectInst - This class represents the LLVM 'select' instruction.
759///
760class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000761 Use Ops[3];
762
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000763 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000764 Ops[0].init(C, this);
765 Ops[1].init(S1, this);
766 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000767 }
768
Chris Lattner454928e2005-01-29 00:31:36 +0000769 SelectInst(const SelectInst &SI)
770 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
771 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
772 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000773public:
774 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
775 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000776 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000777 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +0000778 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000779 }
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
781 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000782 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000783 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +0000784 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000785 }
786
Chris Lattner454928e2005-01-29 00:31:36 +0000787 Value *getCondition() const { return Ops[0]; }
788 Value *getTrueValue() const { return Ops[1]; }
789 Value *getFalseValue() const { return Ops[2]; }
790
791 /// Transparently provide more efficient getOperand methods.
792 Value *getOperand(unsigned i) const {
793 assert(i < 3 && "getOperand() out of range!");
794 return Ops[i];
795 }
796 void setOperand(unsigned i, Value *Val) {
797 assert(i < 3 && "setOperand() out of range!");
798 Ops[i] = Val;
799 }
800 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000801
802 OtherOps getOpcode() const {
803 return static_cast<OtherOps>(Instruction::getOpcode());
804 }
805
Chris Lattnerf319e832004-10-15 23:52:05 +0000806 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000807
808 // Methods for support type inquiry through isa, cast, and dyn_cast:
809 static inline bool classof(const SelectInst *) { return true; }
810 static inline bool classof(const Instruction *I) {
811 return I->getOpcode() == Instruction::Select;
812 }
813 static inline bool classof(const Value *V) {
814 return isa<Instruction>(V) && classof(cast<Instruction>(V));
815 }
816};
817
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000818//===----------------------------------------------------------------------===//
819// VAArgInst Class
820//===----------------------------------------------------------------------===//
821
822/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +0000823/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000824///
Chris Lattner454928e2005-01-29 00:31:36 +0000825class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000826 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +0000827 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000828public:
829 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
830 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000831 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000832 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000833 }
834 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
835 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000836 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000837 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000838 }
839
Chris Lattnerf319e832004-10-15 23:52:05 +0000840 virtual VAArgInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000841
842 // Methods for support type inquiry through isa, cast, and dyn_cast:
843 static inline bool classof(const VAArgInst *) { return true; }
844 static inline bool classof(const Instruction *I) {
845 return I->getOpcode() == VAArg;
846 }
847 static inline bool classof(const Value *V) {
848 return isa<Instruction>(V) && classof(cast<Instruction>(V));
849 }
850};
851
852//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +0000853// ExtractElementInst Class
854//===----------------------------------------------------------------------===//
855
856/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000857/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +0000858///
859class ExtractElementInst : public Instruction {
860 Use Ops[2];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000861 ExtractElementInst(const ExtractElementInst &EE) :
Robert Bocchinof9993442006-01-17 20:05:59 +0000862 Instruction(EE.getType(), ExtractElement, Ops, 2) {
863 Ops[0].init(EE.Ops[0], this);
864 Ops[1].init(EE.Ops[1], this);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000865 }
866
867public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000868 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
869 Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000870 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
871 Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000872 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
873 BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000874 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
875 BasicBlock *InsertAtEnd);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000876
Chris Lattnerfa495842006-04-08 04:04:54 +0000877 /// isValidOperands - Return true if an extractelement instruction can be
878 /// formed with the specified operands.
879 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000880
Robert Bocchino49b78a52006-01-10 19:04:13 +0000881 virtual ExtractElementInst *clone() const;
882
Robert Bocchino49b78a52006-01-10 19:04:13 +0000883 /// Transparently provide more efficient getOperand methods.
884 Value *getOperand(unsigned i) const {
885 assert(i < 2 && "getOperand() out of range!");
886 return Ops[i];
887 }
888 void setOperand(unsigned i, Value *Val) {
889 assert(i < 2 && "setOperand() out of range!");
890 Ops[i] = Val;
891 }
892 unsigned getNumOperands() const { return 2; }
893
894 // Methods for support type inquiry through isa, cast, and dyn_cast:
895 static inline bool classof(const ExtractElementInst *) { return true; }
896 static inline bool classof(const Instruction *I) {
897 return I->getOpcode() == Instruction::ExtractElement;
898 }
899 static inline bool classof(const Value *V) {
900 return isa<Instruction>(V) && classof(cast<Instruction>(V));
901 }
902};
903
904//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +0000905// InsertElementInst Class
906//===----------------------------------------------------------------------===//
907
908/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000909/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +0000910///
911class InsertElementInst : public Instruction {
912 Use Ops[3];
Chris Lattner6a56ed42006-04-14 22:20:07 +0000913 InsertElementInst(const InsertElementInst &IE);
Robert Bocchinof9993442006-01-17 20:05:59 +0000914public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000915 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
916 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000917 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
918 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000919 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Robert Bocchinof9993442006-01-17 20:05:59 +0000920 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000921 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
922 const std::string &Name, BasicBlock *InsertAtEnd);
Robert Bocchinof9993442006-01-17 20:05:59 +0000923
Chris Lattnerfa495842006-04-08 04:04:54 +0000924 /// isValidOperands - Return true if an insertelement instruction can be
925 /// formed with the specified operands.
926 static bool isValidOperands(const Value *Vec, const Value *NewElt,
927 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000928
Robert Bocchinof9993442006-01-17 20:05:59 +0000929 virtual InsertElementInst *clone() const;
930
Reid Spencerac9dcb92007-02-15 03:39:18 +0000931 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +0000932 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +0000933 inline const VectorType *getType() const {
934 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +0000935 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000936
Robert Bocchinof9993442006-01-17 20:05:59 +0000937 /// Transparently provide more efficient getOperand methods.
938 Value *getOperand(unsigned i) const {
939 assert(i < 3 && "getOperand() out of range!");
940 return Ops[i];
941 }
942 void setOperand(unsigned i, Value *Val) {
943 assert(i < 3 && "setOperand() out of range!");
944 Ops[i] = Val;
945 }
946 unsigned getNumOperands() const { return 3; }
947
948 // Methods for support type inquiry through isa, cast, and dyn_cast:
949 static inline bool classof(const InsertElementInst *) { return true; }
950 static inline bool classof(const Instruction *I) {
951 return I->getOpcode() == Instruction::InsertElement;
952 }
953 static inline bool classof(const Value *V) {
954 return isa<Instruction>(V) && classof(cast<Instruction>(V));
955 }
956};
957
958//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +0000959// ShuffleVectorInst Class
960//===----------------------------------------------------------------------===//
961
962/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
963/// input vectors.
964///
965class ShuffleVectorInst : public Instruction {
966 Use Ops[3];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000967 ShuffleVectorInst(const ShuffleVectorInst &IE);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000968public:
969 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
970 const std::string &Name = "", Instruction *InsertBefor = 0);
971 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
972 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000973
Chris Lattnerfa495842006-04-08 04:04:54 +0000974 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +0000975 /// formed with the specified operands.
976 static bool isValidOperands(const Value *V1, const Value *V2,
977 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000978
Chris Lattner9fc18d22006-04-08 01:15:18 +0000979 virtual ShuffleVectorInst *clone() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000980
Reid Spencerac9dcb92007-02-15 03:39:18 +0000981 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +0000982 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +0000983 inline const VectorType *getType() const {
984 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +0000985 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000986
Chris Lattner9fc18d22006-04-08 01:15:18 +0000987 /// Transparently provide more efficient getOperand methods.
988 Value *getOperand(unsigned i) const {
989 assert(i < 3 && "getOperand() out of range!");
990 return Ops[i];
991 }
992 void setOperand(unsigned i, Value *Val) {
993 assert(i < 3 && "setOperand() out of range!");
994 Ops[i] = Val;
995 }
996 unsigned getNumOperands() const { return 3; }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000997
Chris Lattner9fc18d22006-04-08 01:15:18 +0000998 // Methods for support type inquiry through isa, cast, and dyn_cast:
999 static inline bool classof(const ShuffleVectorInst *) { return true; }
1000 static inline bool classof(const Instruction *I) {
1001 return I->getOpcode() == Instruction::ShuffleVector;
1002 }
1003 static inline bool classof(const Value *V) {
1004 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1005 }
1006};
1007
1008
1009//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001010// PHINode Class
1011//===----------------------------------------------------------------------===//
1012
1013// PHINode - The PHINode class is used to represent the magical mystical PHI
1014// node, that can not exist in nature, but can be synthesized in a computer
1015// scientist's overactive imagination.
1016//
1017class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +00001018 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1019 /// the number actually in use.
1020 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001021 PHINode(const PHINode &PN);
1022public:
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001023 explicit PHINode(const Type *Ty, const std::string &Name = "",
1024 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001025 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Chris Lattner454928e2005-01-29 00:31:36 +00001026 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001027 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001028 }
1029
1030 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001031 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Chris Lattner454928e2005-01-29 00:31:36 +00001032 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001033 setName(Name);
Chris Lattner454928e2005-01-29 00:31:36 +00001034 }
1035
1036 ~PHINode();
1037
1038 /// reserveOperandSpace - This method can be used to avoid repeated
1039 /// reallocation of PHI operand lists by reserving space for the correct
1040 /// number of operands before adding them. Unlike normal vector reserves,
1041 /// this method can also be used to trim the operand space.
1042 void reserveOperandSpace(unsigned NumValues) {
1043 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001044 }
1045
Chris Lattnerf319e832004-10-15 23:52:05 +00001046 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001047
1048 /// getNumIncomingValues - Return the number of incoming edges
1049 ///
Chris Lattner454928e2005-01-29 00:31:36 +00001050 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001051
Reid Spencerc773de62006-05-19 19:07:54 +00001052 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001053 ///
1054 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001055 assert(i*2 < getNumOperands() && "Invalid value number!");
1056 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001057 }
1058 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +00001059 assert(i*2 < getNumOperands() && "Invalid value number!");
1060 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001061 }
Chris Lattner454928e2005-01-29 00:31:36 +00001062 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001063 return i*2;
1064 }
1065
Reid Spencerc773de62006-05-19 19:07:54 +00001066 /// getIncomingBlock - Return incoming basic block number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001067 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00001068 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001069 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001070 }
1071 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +00001072 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001073 }
1074 unsigned getOperandNumForIncomingBlock(unsigned i) {
1075 return i*2+1;
1076 }
1077
1078 /// addIncoming - Add an incoming value to the end of the PHI list
1079 ///
1080 void addIncoming(Value *V, BasicBlock *BB) {
1081 assert(getType() == V->getType() &&
1082 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +00001083 unsigned OpNo = NumOperands;
1084 if (OpNo+2 > ReservedSpace)
1085 resizeOperands(0); // Get more space!
1086 // Initialize some new operands.
1087 NumOperands = OpNo+2;
1088 OperandList[OpNo].init(V, this);
1089 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001090 }
Misha Brukman9769ab22005-04-21 20:19:05 +00001091
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001092 /// removeIncomingValue - Remove an incoming value. This is useful if a
1093 /// predecessor basic block is deleted. The value removed is returned.
1094 ///
1095 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1096 /// is true), the PHI node is destroyed and any uses of it are replaced with
1097 /// dummy values. The only time there should be zero incoming values to a PHI
1098 /// node is when the block is dead, so this strategy is sound.
1099 ///
1100 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1101
1102 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1103 int Idx = getBasicBlockIndex(BB);
1104 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1105 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1106 }
1107
Misha Brukman9769ab22005-04-21 20:19:05 +00001108 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001109 /// block in the value list for this PHI. Returns -1 if no instance.
1110 ///
1111 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001112 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +00001113 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +00001114 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001115 return -1;
1116 }
1117
1118 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1119 return getIncomingValue(getBasicBlockIndex(BB));
1120 }
1121
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001122 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00001123 /// same value, return the value, otherwise return null.
1124 ///
Chris Lattner9acbd612005-08-05 00:49:06 +00001125 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001126
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001127 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1128 static inline bool classof(const PHINode *) { return true; }
1129 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001130 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001131 }
1132 static inline bool classof(const Value *V) {
1133 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1134 }
Chris Lattner454928e2005-01-29 00:31:36 +00001135 private:
1136 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001137};
1138
1139//===----------------------------------------------------------------------===//
1140// ReturnInst Class
1141//===----------------------------------------------------------------------===//
1142
1143//===---------------------------------------------------------------------------
1144/// ReturnInst - Return a value (possibly void), from a function. Execution
1145/// does not continue in this function any longer.
1146///
1147class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00001148 Use RetVal; // Return Value: null if 'void'.
1149 ReturnInst(const ReturnInst &RI);
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001150 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001151
1152public:
1153 // ReturnInst constructors:
1154 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001155 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001156 // ReturnInst(Value* X) - 'ret X' instruction
1157 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1158 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1159 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1160 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001161 //
1162 // NOTE: If the Value* passed is of type void then the constructor behaves as
1163 // if it was passed NULL.
Chris Lattner910c80a2007-02-24 00:55:48 +00001164 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1165 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1166 explicit ReturnInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001167
Chris Lattnerf319e832004-10-15 23:52:05 +00001168 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001169
Chris Lattner454928e2005-01-29 00:31:36 +00001170 // Transparently provide more efficient getOperand methods.
1171 Value *getOperand(unsigned i) const {
1172 assert(i < getNumOperands() && "getOperand() out of range!");
1173 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001174 }
Chris Lattner454928e2005-01-29 00:31:36 +00001175 void setOperand(unsigned i, Value *Val) {
1176 assert(i < getNumOperands() && "setOperand() out of range!");
1177 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001178 }
1179
Chris Lattner454928e2005-01-29 00:31:36 +00001180 Value *getReturnValue() const { return RetVal; }
1181
1182 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001183
1184 // Methods for support type inquiry through isa, cast, and dyn_cast:
1185 static inline bool classof(const ReturnInst *) { return true; }
1186 static inline bool classof(const Instruction *I) {
1187 return (I->getOpcode() == Instruction::Ret);
1188 }
1189 static inline bool classof(const Value *V) {
1190 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1191 }
Chris Lattner454928e2005-01-29 00:31:36 +00001192 private:
1193 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1194 virtual unsigned getNumSuccessorsV() const;
1195 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001196};
1197
1198//===----------------------------------------------------------------------===//
1199// BranchInst Class
1200//===----------------------------------------------------------------------===//
1201
1202//===---------------------------------------------------------------------------
1203/// BranchInst - Conditional or Unconditional Branch instruction.
1204///
1205class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001206 /// Ops list - Branches are strange. The operands are ordered:
1207 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1208 /// they don't have to check for cond/uncond branchness.
1209 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001210 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00001211 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001212public:
1213 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1214 // BranchInst(BB *B) - 'br B'
1215 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1216 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1217 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1218 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1219 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00001220 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001221 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001222 Instruction *InsertBefore = 0);
1223 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001224 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001225 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001226
1227 /// Transparently provide more efficient getOperand methods.
1228 Value *getOperand(unsigned i) const {
1229 assert(i < getNumOperands() && "getOperand() out of range!");
1230 return Ops[i];
1231 }
1232 void setOperand(unsigned i, Value *Val) {
1233 assert(i < getNumOperands() && "setOperand() out of range!");
1234 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001235 }
1236
Chris Lattnerf319e832004-10-15 23:52:05 +00001237 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001238
Chris Lattner454928e2005-01-29 00:31:36 +00001239 inline bool isUnconditional() const { return getNumOperands() == 1; }
1240 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001241
1242 inline Value *getCondition() const {
1243 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001244 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001245 }
1246
1247 void setCondition(Value *V) {
1248 assert(isConditional() && "Cannot set condition of unconditional branch!");
1249 setOperand(2, V);
1250 }
1251
1252 // setUnconditionalDest - Change the current branch to an unconditional branch
1253 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +00001254 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001255 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +00001256 if (isConditional()) { // Convert this to an uncond branch.
1257 NumOperands = 1;
1258 Ops[1].set(0);
1259 Ops[2].set(0);
1260 }
1261 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001262 }
1263
Chris Lattner454928e2005-01-29 00:31:36 +00001264 unsigned getNumSuccessors() const { return 1+isConditional(); }
1265
1266 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001267 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Misha Brukman9769ab22005-04-21 20:19:05 +00001268 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
Chris Lattner454928e2005-01-29 00:31:36 +00001269 cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001270 }
1271
Chris Lattner454928e2005-01-29 00:31:36 +00001272 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001273 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001274 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001275 }
1276
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001277 // Methods for support type inquiry through isa, cast, and dyn_cast:
1278 static inline bool classof(const BranchInst *) { return true; }
1279 static inline bool classof(const Instruction *I) {
1280 return (I->getOpcode() == Instruction::Br);
1281 }
1282 static inline bool classof(const Value *V) {
1283 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1284 }
Chris Lattner454928e2005-01-29 00:31:36 +00001285private:
1286 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1287 virtual unsigned getNumSuccessorsV() const;
1288 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001289};
1290
1291//===----------------------------------------------------------------------===//
1292// SwitchInst Class
1293//===----------------------------------------------------------------------===//
1294
1295//===---------------------------------------------------------------------------
1296/// SwitchInst - Multiway switch
1297///
1298class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001299 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001300 // Operand[0] = Value to switch on
1301 // Operand[1] = Default basic block destination
1302 // Operand[2n ] = Value to match
1303 // Operand[2n+1] = BasicBlock to go to on match
1304 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001305 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1306 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001307public:
Chris Lattner454928e2005-01-29 00:31:36 +00001308 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1309 /// switch on and a default destination. The number of additional cases can
1310 /// be specified here to make memory allocation more efficient. This
1311 /// constructor can also autoinsert before another instruction.
1312 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001313 Instruction *InsertBefore = 0);
1314
Chris Lattner454928e2005-01-29 00:31:36 +00001315 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1316 /// switch on and a default destination. The number of additional cases can
1317 /// be specified here to make memory allocation more efficient. This
1318 /// constructor also autoinserts at the end of the specified BasicBlock.
1319 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001320 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001321 ~SwitchInst();
1322
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001323
1324 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001325 inline Value *getCondition() const { return getOperand(0); }
1326 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001327
Chris Lattner454928e2005-01-29 00:31:36 +00001328 inline BasicBlock *getDefaultDest() const {
1329 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001330 }
1331
1332 /// getNumCases - return the number of 'cases' in this switch instruction.
1333 /// Note that case #0 is always the default case.
1334 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001335 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001336 }
1337
1338 /// getCaseValue - Return the specified case value. Note that case #0, the
1339 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001340 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001341 assert(i && i < getNumCases() && "Illegal case value to get!");
1342 return getSuccessorValue(i);
1343 }
1344
1345 /// getCaseValue - Return the specified case value. Note that case #0, the
1346 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001347 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001348 assert(i && i < getNumCases() && "Illegal case value to get!");
1349 return getSuccessorValue(i);
1350 }
1351
1352 /// findCaseValue - Search all of the case values for the specified constant.
1353 /// If it is explicitly handled, return the case number of it, otherwise
1354 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001355 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001356 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1357 if (getCaseValue(i) == C)
1358 return i;
1359 return 0;
1360 }
1361
Nick Lewycky011f1842006-09-18 19:03:59 +00001362 /// findCaseDest - Finds the unique case value for a given successor. Returns
1363 /// null if the successor is not found, not unique, or is the default case.
1364 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00001365 if (BB == getDefaultDest()) return NULL;
1366
Nick Lewycky011f1842006-09-18 19:03:59 +00001367 ConstantInt *CI = NULL;
1368 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1369 if (getSuccessor(i) == BB) {
1370 if (CI) return NULL; // Multiple cases lead to BB.
1371 else CI = getCaseValue(i);
1372 }
1373 }
1374 return CI;
1375 }
1376
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001377 /// addCase - Add an entry to the switch instruction...
1378 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001379 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001380
1381 /// removeCase - This method removes the specified successor from the switch
1382 /// instruction. Note that this cannot be used to remove the default
1383 /// destination (successor #0).
1384 ///
1385 void removeCase(unsigned idx);
1386
Chris Lattner454928e2005-01-29 00:31:36 +00001387 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001388
Chris Lattner454928e2005-01-29 00:31:36 +00001389 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1390 BasicBlock *getSuccessor(unsigned idx) const {
1391 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1392 return cast<BasicBlock>(getOperand(idx*2+1));
1393 }
1394 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001395 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001396 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001397 }
1398
1399 // getSuccessorValue - Return the value associated with the specified
1400 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001401 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001402 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001403 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001404 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001405
1406 // Methods for support type inquiry through isa, cast, and dyn_cast:
1407 static inline bool classof(const SwitchInst *) { return true; }
1408 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001409 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001410 }
1411 static inline bool classof(const Value *V) {
1412 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1413 }
Chris Lattner454928e2005-01-29 00:31:36 +00001414private:
1415 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1416 virtual unsigned getNumSuccessorsV() const;
1417 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001418};
1419
1420//===----------------------------------------------------------------------===//
1421// InvokeInst Class
1422//===----------------------------------------------------------------------===//
1423
1424//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001425
1426/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1427/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001428///
1429class InvokeInst : public TerminatorInst {
1430 InvokeInst(const InvokeInst &BI);
1431 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001432 Value* const *Args, unsigned NumArgs);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001433public:
1434 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001435 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1436 Instruction *InsertBefore = 0);
1437 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1438 Value* const* Args, unsigned NumArgs, const std::string &Name,
1439 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001440 ~InvokeInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001441
Chris Lattnerf319e832004-10-15 23:52:05 +00001442 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001443
Chris Lattner3340ffe2005-05-06 20:26:26 +00001444 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1445 /// function call.
1446 unsigned getCallingConv() const { return SubclassData; }
1447 void setCallingConv(unsigned CC) {
1448 SubclassData = CC;
1449 }
1450
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001451 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001452 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001453 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001454 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001455 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001456 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001457
1458 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001459 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001460
1461 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001462 BasicBlock *getNormalDest() const {
1463 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001464 }
Chris Lattner454928e2005-01-29 00:31:36 +00001465 BasicBlock *getUnwindDest() const {
1466 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001467 }
Chris Lattner454928e2005-01-29 00:31:36 +00001468 void setNormalDest(BasicBlock *B) {
1469 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001470 }
1471
Chris Lattner454928e2005-01-29 00:31:36 +00001472 void setUnwindDest(BasicBlock *B) {
1473 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001474 }
1475
Chris Lattner454928e2005-01-29 00:31:36 +00001476 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001477 assert(i < 2 && "Successor # out of range for invoke!");
1478 return i == 0 ? getNormalDest() : getUnwindDest();
1479 }
1480
Chris Lattner454928e2005-01-29 00:31:36 +00001481 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001482 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001483 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001484 }
1485
Chris Lattner454928e2005-01-29 00:31:36 +00001486 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001487
1488 // Methods for support type inquiry through isa, cast, and dyn_cast:
1489 static inline bool classof(const InvokeInst *) { return true; }
1490 static inline bool classof(const Instruction *I) {
1491 return (I->getOpcode() == Instruction::Invoke);
1492 }
1493 static inline bool classof(const Value *V) {
1494 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1495 }
Chris Lattner454928e2005-01-29 00:31:36 +00001496private:
1497 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1498 virtual unsigned getNumSuccessorsV() const;
1499 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001500};
1501
1502
1503//===----------------------------------------------------------------------===//
1504// UnwindInst Class
1505//===----------------------------------------------------------------------===//
1506
1507//===---------------------------------------------------------------------------
1508/// UnwindInst - Immediately exit the current function, unwinding the stack
1509/// until an invoke instruction is found.
1510///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001511class UnwindInst : public TerminatorInst {
1512public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001513 explicit UnwindInst(Instruction *InsertBefore = 0);
1514 explicit UnwindInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001515
Chris Lattnerf319e832004-10-15 23:52:05 +00001516 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001517
Chris Lattner454928e2005-01-29 00:31:36 +00001518 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001519
1520 // Methods for support type inquiry through isa, cast, and dyn_cast:
1521 static inline bool classof(const UnwindInst *) { return true; }
1522 static inline bool classof(const Instruction *I) {
1523 return I->getOpcode() == Instruction::Unwind;
1524 }
1525 static inline bool classof(const Value *V) {
1526 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1527 }
Chris Lattner454928e2005-01-29 00:31:36 +00001528private:
1529 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1530 virtual unsigned getNumSuccessorsV() const;
1531 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001532};
1533
Chris Lattner076b3f12004-10-16 18:05:54 +00001534//===----------------------------------------------------------------------===//
1535// UnreachableInst Class
1536//===----------------------------------------------------------------------===//
1537
1538//===---------------------------------------------------------------------------
1539/// UnreachableInst - This function has undefined behavior. In particular, the
1540/// presence of this instruction indicates some higher level knowledge that the
1541/// end of the block cannot be reached.
1542///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001543class UnreachableInst : public TerminatorInst {
1544public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001545 explicit UnreachableInst(Instruction *InsertBefore = 0);
1546 explicit UnreachableInst(BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00001547
1548 virtual UnreachableInst *clone() const;
1549
Chris Lattner454928e2005-01-29 00:31:36 +00001550 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001551
1552 // Methods for support type inquiry through isa, cast, and dyn_cast:
1553 static inline bool classof(const UnreachableInst *) { return true; }
1554 static inline bool classof(const Instruction *I) {
1555 return I->getOpcode() == Instruction::Unreachable;
1556 }
1557 static inline bool classof(const Value *V) {
1558 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1559 }
Chris Lattner454928e2005-01-29 00:31:36 +00001560private:
1561 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1562 virtual unsigned getNumSuccessorsV() const;
1563 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001564};
1565
Reid Spencer3da59db2006-11-27 01:05:10 +00001566//===----------------------------------------------------------------------===//
1567// TruncInst Class
1568//===----------------------------------------------------------------------===//
1569
1570/// @brief This class represents a truncation of integer types.
1571class TruncInst : public CastInst {
1572 /// Private copy constructor
1573 TruncInst(const TruncInst &CI)
1574 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1575 }
1576public:
1577 /// @brief Constructor with insert-before-instruction semantics
1578 TruncInst(
1579 Value *S, ///< The value to be truncated
1580 const Type *Ty, ///< The (smaller) type to truncate to
1581 const std::string &Name = "", ///< A name for the new instruction
1582 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1583 );
1584
1585 /// @brief Constructor with insert-at-end-of-block semantics
1586 TruncInst(
1587 Value *S, ///< The value to be truncated
1588 const Type *Ty, ///< The (smaller) type to truncate to
1589 const std::string &Name, ///< A name for the new instruction
1590 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1591 );
1592
1593 /// @brief Clone an identical TruncInst
1594 virtual CastInst *clone() const;
1595
1596 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1597 static inline bool classof(const TruncInst *) { return true; }
1598 static inline bool classof(const Instruction *I) {
1599 return I->getOpcode() == Trunc;
1600 }
1601 static inline bool classof(const Value *V) {
1602 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1603 }
1604};
1605
1606//===----------------------------------------------------------------------===//
1607// ZExtInst Class
1608//===----------------------------------------------------------------------===//
1609
1610/// @brief This class represents zero extension of integer types.
1611class ZExtInst : public CastInst {
1612 /// @brief Private copy constructor
1613 ZExtInst(const ZExtInst &CI)
1614 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1615 }
1616public:
1617 /// @brief Constructor with insert-before-instruction semantics
1618 ZExtInst(
1619 Value *S, ///< The value to be zero extended
1620 const Type *Ty, ///< The type to zero extend to
1621 const std::string &Name = "", ///< A name for the new instruction
1622 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1623 );
1624
1625 /// @brief Constructor with insert-at-end semantics.
1626 ZExtInst(
1627 Value *S, ///< The value to be zero extended
1628 const Type *Ty, ///< The type to zero extend to
1629 const std::string &Name, ///< A name for the new instruction
1630 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1631 );
1632
1633 /// @brief Clone an identical ZExtInst
1634 virtual CastInst *clone() const;
1635
1636 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1637 static inline bool classof(const ZExtInst *) { return true; }
1638 static inline bool classof(const Instruction *I) {
1639 return I->getOpcode() == ZExt;
1640 }
1641 static inline bool classof(const Value *V) {
1642 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1643 }
1644};
1645
1646//===----------------------------------------------------------------------===//
1647// SExtInst Class
1648//===----------------------------------------------------------------------===//
1649
1650/// @brief This class represents a sign extension of integer types.
1651class SExtInst : public CastInst {
1652 /// @brief Private copy constructor
1653 SExtInst(const SExtInst &CI)
1654 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1655 }
1656public:
1657 /// @brief Constructor with insert-before-instruction semantics
1658 SExtInst(
1659 Value *S, ///< The value to be sign extended
1660 const Type *Ty, ///< The type to sign extend to
1661 const std::string &Name = "", ///< A name for the new instruction
1662 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1663 );
1664
1665 /// @brief Constructor with insert-at-end-of-block semantics
1666 SExtInst(
1667 Value *S, ///< The value to be sign extended
1668 const Type *Ty, ///< The type to sign extend to
1669 const std::string &Name, ///< A name for the new instruction
1670 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1671 );
1672
1673 /// @brief Clone an identical SExtInst
1674 virtual CastInst *clone() const;
1675
1676 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1677 static inline bool classof(const SExtInst *) { return true; }
1678 static inline bool classof(const Instruction *I) {
1679 return I->getOpcode() == SExt;
1680 }
1681 static inline bool classof(const Value *V) {
1682 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1683 }
1684};
1685
1686//===----------------------------------------------------------------------===//
1687// FPTruncInst Class
1688//===----------------------------------------------------------------------===//
1689
1690/// @brief This class represents a truncation of floating point types.
1691class FPTruncInst : public CastInst {
1692 FPTruncInst(const FPTruncInst &CI)
1693 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1694 }
1695public:
1696 /// @brief Constructor with insert-before-instruction semantics
1697 FPTruncInst(
1698 Value *S, ///< The value to be truncated
1699 const Type *Ty, ///< The type to truncate to
1700 const std::string &Name = "", ///< A name for the new instruction
1701 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1702 );
1703
1704 /// @brief Constructor with insert-before-instruction semantics
1705 FPTruncInst(
1706 Value *S, ///< The value to be truncated
1707 const Type *Ty, ///< The type to truncate to
1708 const std::string &Name, ///< A name for the new instruction
1709 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1710 );
1711
1712 /// @brief Clone an identical FPTruncInst
1713 virtual CastInst *clone() const;
1714
1715 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1716 static inline bool classof(const FPTruncInst *) { return true; }
1717 static inline bool classof(const Instruction *I) {
1718 return I->getOpcode() == FPTrunc;
1719 }
1720 static inline bool classof(const Value *V) {
1721 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1722 }
1723};
1724
1725//===----------------------------------------------------------------------===//
1726// FPExtInst Class
1727//===----------------------------------------------------------------------===//
1728
1729/// @brief This class represents an extension of floating point types.
1730class FPExtInst : public CastInst {
1731 FPExtInst(const FPExtInst &CI)
1732 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1733 }
1734public:
1735 /// @brief Constructor with insert-before-instruction semantics
1736 FPExtInst(
1737 Value *S, ///< The value to be extended
1738 const Type *Ty, ///< The type to extend to
1739 const std::string &Name = "", ///< A name for the new instruction
1740 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1741 );
1742
1743 /// @brief Constructor with insert-at-end-of-block semantics
1744 FPExtInst(
1745 Value *S, ///< The value to be extended
1746 const Type *Ty, ///< The type to extend to
1747 const std::string &Name, ///< A name for the new instruction
1748 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1749 );
1750
1751 /// @brief Clone an identical FPExtInst
1752 virtual CastInst *clone() const;
1753
1754 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1755 static inline bool classof(const FPExtInst *) { return true; }
1756 static inline bool classof(const Instruction *I) {
1757 return I->getOpcode() == FPExt;
1758 }
1759 static inline bool classof(const Value *V) {
1760 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1761 }
1762};
1763
1764//===----------------------------------------------------------------------===//
1765// UIToFPInst Class
1766//===----------------------------------------------------------------------===//
1767
1768/// @brief This class represents a cast unsigned integer to floating point.
1769class UIToFPInst : public CastInst {
1770 UIToFPInst(const UIToFPInst &CI)
1771 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1772 }
1773public:
1774 /// @brief Constructor with insert-before-instruction semantics
1775 UIToFPInst(
1776 Value *S, ///< The value to be converted
1777 const Type *Ty, ///< The type to convert to
1778 const std::string &Name = "", ///< A name for the new instruction
1779 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1780 );
1781
1782 /// @brief Constructor with insert-at-end-of-block semantics
1783 UIToFPInst(
1784 Value *S, ///< The value to be converted
1785 const Type *Ty, ///< The type to convert to
1786 const std::string &Name, ///< A name for the new instruction
1787 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1788 );
1789
1790 /// @brief Clone an identical UIToFPInst
1791 virtual CastInst *clone() const;
1792
1793 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1794 static inline bool classof(const UIToFPInst *) { return true; }
1795 static inline bool classof(const Instruction *I) {
1796 return I->getOpcode() == UIToFP;
1797 }
1798 static inline bool classof(const Value *V) {
1799 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1800 }
1801};
1802
1803//===----------------------------------------------------------------------===//
1804// SIToFPInst Class
1805//===----------------------------------------------------------------------===//
1806
1807/// @brief This class represents a cast from signed integer to floating point.
1808class SIToFPInst : public CastInst {
1809 SIToFPInst(const SIToFPInst &CI)
1810 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1811 }
1812public:
1813 /// @brief Constructor with insert-before-instruction semantics
1814 SIToFPInst(
1815 Value *S, ///< The value to be converted
1816 const Type *Ty, ///< The type to convert to
1817 const std::string &Name = "", ///< A name for the new instruction
1818 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1819 );
1820
1821 /// @brief Constructor with insert-at-end-of-block semantics
1822 SIToFPInst(
1823 Value *S, ///< The value to be converted
1824 const Type *Ty, ///< The type to convert to
1825 const std::string &Name, ///< A name for the new instruction
1826 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1827 );
1828
1829 /// @brief Clone an identical SIToFPInst
1830 virtual CastInst *clone() const;
1831
1832 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1833 static inline bool classof(const SIToFPInst *) { return true; }
1834 static inline bool classof(const Instruction *I) {
1835 return I->getOpcode() == SIToFP;
1836 }
1837 static inline bool classof(const Value *V) {
1838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1839 }
1840};
1841
1842//===----------------------------------------------------------------------===//
1843// FPToUIInst Class
1844//===----------------------------------------------------------------------===//
1845
1846/// @brief This class represents a cast from floating point to unsigned integer
1847class FPToUIInst : public CastInst {
1848 FPToUIInst(const FPToUIInst &CI)
1849 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1850 }
1851public:
1852 /// @brief Constructor with insert-before-instruction semantics
1853 FPToUIInst(
1854 Value *S, ///< The value to be converted
1855 const Type *Ty, ///< The type to convert to
1856 const std::string &Name = "", ///< A name for the new instruction
1857 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1858 );
1859
1860 /// @brief Constructor with insert-at-end-of-block semantics
1861 FPToUIInst(
1862 Value *S, ///< The value to be converted
1863 const Type *Ty, ///< The type to convert to
1864 const std::string &Name, ///< A name for the new instruction
1865 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1866 );
1867
1868 /// @brief Clone an identical FPToUIInst
1869 virtual CastInst *clone() const;
1870
1871 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1872 static inline bool classof(const FPToUIInst *) { return true; }
1873 static inline bool classof(const Instruction *I) {
1874 return I->getOpcode() == FPToUI;
1875 }
1876 static inline bool classof(const Value *V) {
1877 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1878 }
1879};
1880
1881//===----------------------------------------------------------------------===//
1882// FPToSIInst Class
1883//===----------------------------------------------------------------------===//
1884
1885/// @brief This class represents a cast from floating point to signed integer.
1886class FPToSIInst : public CastInst {
1887 FPToSIInst(const FPToSIInst &CI)
1888 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1889 }
1890public:
1891 /// @brief Constructor with insert-before-instruction semantics
1892 FPToSIInst(
1893 Value *S, ///< The value to be converted
1894 const Type *Ty, ///< The type to convert to
1895 const std::string &Name = "", ///< A name for the new instruction
1896 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1897 );
1898
1899 /// @brief Constructor with insert-at-end-of-block semantics
1900 FPToSIInst(
1901 Value *S, ///< The value to be converted
1902 const Type *Ty, ///< The type to convert to
1903 const std::string &Name, ///< A name for the new instruction
1904 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1905 );
1906
1907 /// @brief Clone an identical FPToSIInst
1908 virtual CastInst *clone() const;
1909
1910 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1911 static inline bool classof(const FPToSIInst *) { return true; }
1912 static inline bool classof(const Instruction *I) {
1913 return I->getOpcode() == FPToSI;
1914 }
1915 static inline bool classof(const Value *V) {
1916 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1917 }
1918};
1919
1920//===----------------------------------------------------------------------===//
1921// IntToPtrInst Class
1922//===----------------------------------------------------------------------===//
1923
1924/// @brief This class represents a cast from an integer to a pointer.
1925class IntToPtrInst : public CastInst {
1926 IntToPtrInst(const IntToPtrInst &CI)
1927 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1928 }
1929public:
1930 /// @brief Constructor with insert-before-instruction semantics
1931 IntToPtrInst(
1932 Value *S, ///< The value to be converted
1933 const Type *Ty, ///< The type to convert to
1934 const std::string &Name = "", ///< A name for the new instruction
1935 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1936 );
1937
1938 /// @brief Constructor with insert-at-end-of-block semantics
1939 IntToPtrInst(
1940 Value *S, ///< The value to be converted
1941 const Type *Ty, ///< The type to convert to
1942 const std::string &Name, ///< A name for the new instruction
1943 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1944 );
1945
1946 /// @brief Clone an identical IntToPtrInst
1947 virtual CastInst *clone() const;
1948
1949 // Methods for support type inquiry through isa, cast, and dyn_cast:
1950 static inline bool classof(const IntToPtrInst *) { return true; }
1951 static inline bool classof(const Instruction *I) {
1952 return I->getOpcode() == IntToPtr;
1953 }
1954 static inline bool classof(const Value *V) {
1955 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1956 }
1957};
1958
1959//===----------------------------------------------------------------------===//
1960// PtrToIntInst Class
1961//===----------------------------------------------------------------------===//
1962
1963/// @brief This class represents a cast from a pointer to an integer
1964class PtrToIntInst : public CastInst {
1965 PtrToIntInst(const PtrToIntInst &CI)
1966 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
1967 }
1968public:
1969 /// @brief Constructor with insert-before-instruction semantics
1970 PtrToIntInst(
1971 Value *S, ///< The value to be converted
1972 const Type *Ty, ///< The type to convert to
1973 const std::string &Name = "", ///< A name for the new instruction
1974 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1975 );
1976
1977 /// @brief Constructor with insert-at-end-of-block semantics
1978 PtrToIntInst(
1979 Value *S, ///< The value to be converted
1980 const Type *Ty, ///< The type to convert to
1981 const std::string &Name, ///< A name for the new instruction
1982 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1983 );
1984
1985 /// @brief Clone an identical PtrToIntInst
1986 virtual CastInst *clone() const;
1987
1988 // Methods for support type inquiry through isa, cast, and dyn_cast:
1989 static inline bool classof(const PtrToIntInst *) { return true; }
1990 static inline bool classof(const Instruction *I) {
1991 return I->getOpcode() == PtrToInt;
1992 }
1993 static inline bool classof(const Value *V) {
1994 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1995 }
1996};
1997
1998//===----------------------------------------------------------------------===//
1999// BitCastInst Class
2000//===----------------------------------------------------------------------===//
2001
2002/// @brief This class represents a no-op cast from one type to another.
2003class BitCastInst : public CastInst {
2004 BitCastInst(const BitCastInst &CI)
2005 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2006 }
2007public:
2008 /// @brief Constructor with insert-before-instruction semantics
2009 BitCastInst(
2010 Value *S, ///< The value to be casted
2011 const Type *Ty, ///< The type to casted to
2012 const std::string &Name = "", ///< A name for the new instruction
2013 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2014 );
2015
2016 /// @brief Constructor with insert-at-end-of-block semantics
2017 BitCastInst(
2018 Value *S, ///< The value to be casted
2019 const Type *Ty, ///< The type to casted to
2020 const std::string &Name, ///< A name for the new instruction
2021 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2022 );
2023
2024 /// @brief Clone an identical BitCastInst
2025 virtual CastInst *clone() const;
2026
2027 // Methods for support type inquiry through isa, cast, and dyn_cast:
2028 static inline bool classof(const BitCastInst *) { return true; }
2029 static inline bool classof(const Instruction *I) {
2030 return I->getOpcode() == BitCast;
2031 }
2032 static inline bool classof(const Value *V) {
2033 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2034 }
2035};
2036
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002037} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00002038
2039#endif