blob: 337ae2a463b78b07fb58c52a302935b114db8699 [file] [log] [blame]
Chris Lattnera892a3a2003-01-27 22:08:52 +00001//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
Misha Brukman9769ab22005-04-21 20:19:05 +00002//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman9769ab22005-04-21 20:19:05 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattnera892a3a2003-01-27 22:08:52 +00009//
10// This file exposes the class definitions of all of the subclasses of the
11// Instruction class. This is meant to be an easy way to get access to all
12// instruction subclasses.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_INSTRUCTIONS_H
17#define LLVM_INSTRUCTIONS_H
18
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000019#include "llvm/InstrTypes.h"
20
21namespace llvm {
22
Chris Lattner1fca5ff2004-10-27 16:14:51 +000023class BasicBlock;
Chris Lattnerd1a32602005-02-24 05:32:09 +000024class ConstantInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000025class PointerType;
Reid Spencer9d6565a2007-02-15 02:26:10 +000026class VectorType;
Reid Spencer3da43842007-02-28 22:00:54 +000027class ConstantRange;
28class APInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000029
30//===----------------------------------------------------------------------===//
31// AllocationInst Class
32//===----------------------------------------------------------------------===//
33
34/// AllocationInst - This class is the common base class of MallocInst and
35/// AllocaInst.
36///
Chris Lattner454928e2005-01-29 00:31:36 +000037class AllocationInst : public UnaryInstruction {
Nate Begeman14b05292005-11-05 09:21:28 +000038 unsigned Alignment;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000039protected:
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 = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000042 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000043 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000044public:
Chris Lattner70aa33e2006-06-21 16:53:47 +000045 // Out of line virtual method, so the vtable, etc has a home.
46 virtual ~AllocationInst();
Chris Lattnerf56a8db2006-10-03 17:09:12 +000047
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000048 /// isArrayAllocation - Return true if there is an allocation size parameter
49 /// to the allocation instruction that is not 1.
50 ///
51 bool isArrayAllocation() const;
52
53 /// getArraySize - Get the number of element allocated, for a simple
54 /// allocation of a single element, this will return a constant 1 value.
55 ///
Chris Lattner454928e2005-01-29 00:31:36 +000056 inline const Value *getArraySize() const { return getOperand(0); }
57 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000058
59 /// getType - Overload to return most specific pointer type
60 ///
61 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000062 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000063 }
64
65 /// getAllocatedType - Return the type that is being allocated by the
66 /// instruction.
67 ///
68 const Type *getAllocatedType() const;
69
Nate Begeman14b05292005-11-05 09:21:28 +000070 /// getAlignment - Return the alignment of the memory that is being allocated
71 /// by the instruction.
72 ///
73 unsigned getAlignment() const { return Alignment; }
Chris Lattner8ae779d2005-11-05 21:58:30 +000074 void setAlignment(unsigned Align) {
75 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
76 Alignment = Align;
77 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +000078
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000079 virtual Instruction *clone() const = 0;
80
81 // Methods for support type inquiry through isa, cast, and dyn_cast:
82 static inline bool classof(const AllocationInst *) { return true; }
83 static inline bool classof(const Instruction *I) {
84 return I->getOpcode() == Instruction::Alloca ||
85 I->getOpcode() == Instruction::Malloc;
86 }
87 static inline bool classof(const Value *V) {
88 return isa<Instruction>(V) && classof(cast<Instruction>(V));
89 }
90};
91
92
93//===----------------------------------------------------------------------===//
94// MallocInst Class
95//===----------------------------------------------------------------------===//
96
97/// MallocInst - an instruction to allocated memory on the heap
98///
99class MallocInst : public AllocationInst {
100 MallocInst(const MallocInst &MI);
101public:
102 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
103 const std::string &Name = "",
104 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000105 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000106 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
107 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000108 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000109
110 MallocInst(const Type *Ty, const std::string &Name,
111 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000112 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertBefore) {}
113 MallocInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
114 : AllocationInst(Ty, 0, Malloc, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000115
116 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000117 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000118 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
119 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
Nate Begeman14b05292005-11-05 09:21:28 +0000120 const std::string &Name = "",
121 Instruction *InsertBefore = 0)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000122 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000123
Chris Lattnerf319e832004-10-15 23:52:05 +0000124 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000125
126 // Methods for support type inquiry through isa, cast, and dyn_cast:
127 static inline bool classof(const MallocInst *) { return true; }
128 static inline bool classof(const Instruction *I) {
129 return (I->getOpcode() == Instruction::Malloc);
130 }
131 static inline bool classof(const Value *V) {
132 return isa<Instruction>(V) && classof(cast<Instruction>(V));
133 }
134};
135
136
137//===----------------------------------------------------------------------===//
138// AllocaInst Class
139//===----------------------------------------------------------------------===//
140
141/// AllocaInst - an instruction to allocate memory on the stack
142///
143class AllocaInst : public AllocationInst {
144 AllocaInst(const AllocaInst &);
145public:
146 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
147 const std::string &Name = "",
148 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000149 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000150 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
151 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000152 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerb77780e2006-05-10 04:38:35 +0000153
154 AllocaInst(const Type *Ty, const std::string &Name,
155 Instruction *InsertBefore = 0)
156 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertBefore) {}
157 AllocaInst(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
158 : AllocationInst(Ty, 0, Alloca, 0, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000159
Chris Lattnerb77780e2006-05-10 04:38:35 +0000160 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
161 const std::string &Name = "", Instruction *InsertBefore = 0)
162 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
Nate Begeman14b05292005-11-05 09:21:28 +0000163 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
164 const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattnerb77780e2006-05-10 04:38:35 +0000165 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000166
Chris Lattnerf319e832004-10-15 23:52:05 +0000167 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000168
169 // Methods for support type inquiry through isa, cast, and dyn_cast:
170 static inline bool classof(const AllocaInst *) { return true; }
171 static inline bool classof(const Instruction *I) {
172 return (I->getOpcode() == Instruction::Alloca);
173 }
174 static inline bool classof(const Value *V) {
175 return isa<Instruction>(V) && classof(cast<Instruction>(V));
176 }
177};
178
179
180//===----------------------------------------------------------------------===//
181// FreeInst Class
182//===----------------------------------------------------------------------===//
183
184/// FreeInst - an instruction to deallocate memory
185///
Chris Lattner454928e2005-01-29 00:31:36 +0000186class FreeInst : public UnaryInstruction {
187 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000188public:
189 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
190 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
191
Chris Lattnerf319e832004-10-15 23:52:05 +0000192 virtual FreeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000193
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000194 // Methods for support type inquiry through isa, cast, and dyn_cast:
195 static inline bool classof(const FreeInst *) { return true; }
196 static inline bool classof(const Instruction *I) {
197 return (I->getOpcode() == Instruction::Free);
198 }
199 static inline bool classof(const Value *V) {
200 return isa<Instruction>(V) && classof(cast<Instruction>(V));
201 }
202};
203
204
205//===----------------------------------------------------------------------===//
206// LoadInst Class
207//===----------------------------------------------------------------------===//
208
Chris Lattner88fe29a2005-02-05 01:44:18 +0000209/// LoadInst - an instruction for reading from memory. This uses the
210/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000211///
Chris Lattner454928e2005-01-29 00:31:36 +0000212class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000213 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000214 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
215 setVolatile(LI.isVolatile());
Misha Brukman9769ab22005-04-21 20:19:05 +0000216
Chris Lattner454928e2005-01-29 00:31:36 +0000217#ifndef NDEBUG
218 AssertOK();
219#endif
220 }
221 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000222public:
223 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
224 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf00042a2007-02-13 07:54:42 +0000225 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile = false,
226 Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000227 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
228 BasicBlock *InsertAtEnd);
229
Chris Lattnerf00042a2007-02-13 07:54:42 +0000230 LoadInst(Value *Ptr, const char *Name, Instruction *InsertBefore);
231 LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAtEnd);
232 explicit LoadInst(Value *Ptr, const char *Name = 0, bool isVolatile = false,
233 Instruction *InsertBefore = 0);
234 LoadInst(Value *Ptr, const char *Name, bool isVolatile,
235 BasicBlock *InsertAtEnd);
236
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000237 /// isVolatile - Return true if this is a load from a volatile memory
238 /// location.
239 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000240 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000241
242 /// setVolatile - Specify whether this is a volatile load or not.
243 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000244 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000245
Chris Lattnerf319e832004-10-15 23:52:05 +0000246 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000247
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000248 Value *getPointerOperand() { return getOperand(0); }
249 const Value *getPointerOperand() const { return getOperand(0); }
250 static unsigned getPointerOperandIndex() { return 0U; }
251
252 // Methods for support type inquiry through isa, cast, and dyn_cast:
253 static inline bool classof(const LoadInst *) { return true; }
254 static inline bool classof(const Instruction *I) {
255 return I->getOpcode() == Instruction::Load;
256 }
257 static inline bool classof(const Value *V) {
258 return isa<Instruction>(V) && classof(cast<Instruction>(V));
259 }
260};
261
262
263//===----------------------------------------------------------------------===//
264// StoreInst Class
265//===----------------------------------------------------------------------===//
266
Misha Brukman9769ab22005-04-21 20:19:05 +0000267/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000268///
269class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000270 Use Ops[2];
Chris Lattner88fe29a2005-02-05 01:44:18 +0000271 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000272 Ops[0].init(SI.Ops[0], this);
273 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000274 setVolatile(SI.isVolatile());
Chris Lattner454928e2005-01-29 00:31:36 +0000275#ifndef NDEBUG
276 AssertOK();
277#endif
278 }
279 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000280public:
281 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
282 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
283 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
284 Instruction *InsertBefore = 0);
285 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
286
287
288 /// isVolatile - Return true if this is a load from a volatile memory
289 /// location.
290 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000291 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000292
293 /// setVolatile - Specify whether this is a volatile load or not.
294 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000295 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000296
Chris Lattner454928e2005-01-29 00:31:36 +0000297 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000298 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000299 assert(i < 2 && "getOperand() out of range!");
300 return Ops[i];
301 }
302 void setOperand(unsigned i, Value *Val) {
303 assert(i < 2 && "setOperand() out of range!");
304 Ops[i] = Val;
305 }
306 unsigned getNumOperands() const { return 2; }
307
308
Chris Lattnerf319e832004-10-15 23:52:05 +0000309 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000310
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000311 Value *getPointerOperand() { return getOperand(1); }
312 const Value *getPointerOperand() const { return getOperand(1); }
313 static unsigned getPointerOperandIndex() { return 1U; }
314
315 // Methods for support type inquiry through isa, cast, and dyn_cast:
316 static inline bool classof(const StoreInst *) { return true; }
317 static inline bool classof(const Instruction *I) {
318 return I->getOpcode() == Instruction::Store;
319 }
320 static inline bool classof(const Value *V) {
321 return isa<Instruction>(V) && classof(cast<Instruction>(V));
322 }
323};
324
325
326//===----------------------------------------------------------------------===//
327// GetElementPtrInst Class
328//===----------------------------------------------------------------------===//
329
330/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
331/// access elements of arrays and structs
332///
333class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000334 GetElementPtrInst(const GetElementPtrInst &GEPI)
335 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
336 0, GEPI.getNumOperands()) {
337 Use *OL = OperandList = new Use[NumOperands];
338 Use *GEPIOL = GEPI.OperandList;
339 for (unsigned i = 0, E = NumOperands; i != E; ++i)
340 OL[i].init(GEPIOL[i], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000341 }
Chris Lattner6ffbe172007-01-31 19:47:18 +0000342 void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000343 void init(Value *Ptr, Value *Idx0, Value *Idx1);
Chris Lattner38bacf22005-05-03 05:43:30 +0000344 void init(Value *Ptr, Value *Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000345public:
346 /// Constructors - Create a getelementptr instruction with a base pointer an
347 /// list of indices. The first ctor can optionally insert before an existing
348 /// instruction, the second appends the new instruction to the specified
349 /// BasicBlock.
Chris Lattnerfb110532007-01-31 04:39:29 +0000350 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
351 const std::string &Name = "", Instruction *InsertBefore =0);
352 GetElementPtrInst(Value *Ptr, Value* const *Idx, unsigned NumIdx,
353 const std::string &Name, BasicBlock *InsertAtEnd);
354
Chris Lattner38bacf22005-05-03 05:43:30 +0000355 /// Constructors - These two constructors are convenience methods because one
356 /// and two index getelementptr instructions are so common.
357 GetElementPtrInst(Value *Ptr, Value *Idx,
358 const std::string &Name = "", Instruction *InsertBefore =0);
359 GetElementPtrInst(Value *Ptr, Value *Idx,
360 const std::string &Name, BasicBlock *InsertAtEnd);
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 = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000363 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000364 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000365 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000366
Chris Lattnerf319e832004-10-15 23:52:05 +0000367 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000368
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000369 // getType - Overload to return most specific pointer type...
370 inline const PointerType *getType() const {
371 return reinterpret_cast<const PointerType*>(Instruction::getType());
372 }
373
374 /// getIndexedType - Returns the type of the element that would be loaded with
375 /// a load instruction with the specified parameters.
376 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000377 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000378 /// pointer type.
379 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000380 static const Type *getIndexedType(const Type *Ptr,
Chris Lattnerfb110532007-01-31 04:39:29 +0000381 Value* const *Idx, unsigned NumIdx,
Misha Brukman91102862005-03-16 03:46:55 +0000382 bool AllowStructLeaf = false);
Chris Lattnerfb110532007-01-31 04:39:29 +0000383
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000384 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000385 bool AllowStructLeaf = false);
Chris Lattner38bacf22005-05-03 05:43:30 +0000386 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000387
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000388 inline op_iterator idx_begin() { return op_begin()+1; }
389 inline const_op_iterator idx_begin() const { return op_begin()+1; }
390 inline op_iterator idx_end() { return op_end(); }
391 inline const_op_iterator idx_end() const { return op_end(); }
392
393 Value *getPointerOperand() {
394 return getOperand(0);
395 }
396 const Value *getPointerOperand() const {
397 return getOperand(0);
398 }
399 static unsigned getPointerOperandIndex() {
400 return 0U; // get index for modifying correct operand
401 }
402
403 inline unsigned getNumIndices() const { // Note: always non-negative
404 return getNumOperands() - 1;
405 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000406
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000407 inline bool hasIndices() const {
408 return getNumOperands() > 1;
409 }
410
411 // Methods for support type inquiry through isa, cast, and dyn_cast:
412 static inline bool classof(const GetElementPtrInst *) { return true; }
413 static inline bool classof(const Instruction *I) {
414 return (I->getOpcode() == Instruction::GetElementPtr);
415 }
416 static inline bool classof(const Value *V) {
417 return isa<Instruction>(V) && classof(cast<Instruction>(V));
418 }
419};
420
421//===----------------------------------------------------------------------===//
Reid Spencer45fb3f32006-11-20 01:22:35 +0000422// ICmpInst Class
423//===----------------------------------------------------------------------===//
424
425/// This instruction compares its operands according to the predicate given
426/// to the constructor. It only operates on integers, pointers, or packed
427/// vectors of integrals. The two operands must be the same type.
428/// @brief Represent an integer comparison operator.
429class ICmpInst: public CmpInst {
430public:
431 /// This enumeration lists the possible predicates for the ICmpInst. The
432 /// values in the range 0-31 are reserved for FCmpInst while values in the
433 /// range 32-64 are reserved for ICmpInst. This is necessary to ensure the
434 /// predicate values are not overlapping between the classes.
435 enum Predicate {
436 ICMP_EQ = 32, ///< equal
437 ICMP_NE = 33, ///< not equal
438 ICMP_UGT = 34, ///< unsigned greater than
439 ICMP_UGE = 35, ///< unsigned greater or equal
440 ICMP_ULT = 36, ///< unsigned less than
441 ICMP_ULE = 37, ///< unsigned less or equal
442 ICMP_SGT = 38, ///< signed greater than
443 ICMP_SGE = 39, ///< signed greater or equal
444 ICMP_SLT = 40, ///< signed less than
445 ICMP_SLE = 41, ///< signed less or equal
446 FIRST_ICMP_PREDICATE = ICMP_EQ,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000447 LAST_ICMP_PREDICATE = ICMP_SLE,
448 BAD_ICMP_PREDICATE = ICMP_SLE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000449 };
450
451 /// @brief Constructor with insert-before-instruction semantics.
452 ICmpInst(
453 Predicate pred, ///< The predicate to use for the comparison
454 Value *LHS, ///< The left-hand-side of the expression
455 Value *RHS, ///< The right-hand-side of the expression
456 const std::string &Name = "", ///< Name of the instruction
457 Instruction *InsertBefore = 0 ///< Where to insert
458 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertBefore) {
459 }
460
461 /// @brief Constructor with insert-at-block-end semantics.
462 ICmpInst(
463 Predicate pred, ///< The predicate to use for the comparison
464 Value *LHS, ///< The left-hand-side of the expression
465 Value *RHS, ///< The right-hand-side of the expression
466 const std::string &Name, ///< Name of the instruction
467 BasicBlock *InsertAtEnd ///< Block to insert into.
468 ) : CmpInst(Instruction::ICmp, pred, LHS, RHS, Name, InsertAtEnd) {
469 }
470
471 /// @brief Return the predicate for this instruction.
472 Predicate getPredicate() const { return Predicate(SubclassData); }
473
Chris Lattnerb769d562007-01-14 19:41:24 +0000474 /// @brief Set the predicate for this instruction to the specified value.
475 void setPredicate(Predicate P) { SubclassData = P; }
476
Reid Spencer45fb3f32006-11-20 01:22:35 +0000477 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
478 /// @returns the inverse predicate for the instruction's current predicate.
479 /// @brief Return the inverse of the instruction's predicate.
480 Predicate getInversePredicate() const {
481 return getInversePredicate(getPredicate());
482 }
483
484 /// For example, EQ -> NE, UGT -> ULE, SLT -> SGE, etc.
485 /// @returns the inverse predicate for predicate provided in \p pred.
486 /// @brief Return the inverse of a given predicate
487 static Predicate getInversePredicate(Predicate pred);
488
489 /// For example, EQ->EQ, SLE->SGE, ULT->UGT, etc.
490 /// @returns the predicate that would be the result of exchanging the two
491 /// operands of the ICmpInst instruction without changing the result
492 /// produced.
493 /// @brief Return the predicate as if the operands were swapped
494 Predicate getSwappedPredicate() const {
495 return getSwappedPredicate(getPredicate());
496 }
497
498 /// This is a static version that you can use without an instruction
499 /// available.
500 /// @brief Return the predicate as if the operands were swapped.
Reid Spencere4d87aa2006-12-23 06:05:41 +0000501 static Predicate getSwappedPredicate(Predicate pred);
502
503 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
504 /// @returns the predicate that would be the result if the operand were
505 /// regarded as signed.
506 /// @brief Return the signed version of the predicate
507 Predicate getSignedPredicate() const {
508 return getSignedPredicate(getPredicate());
509 }
510
511 /// This is a static version that you can use without an instruction.
512 /// @brief Return the signed version of the predicate.
513 static Predicate getSignedPredicate(Predicate pred);
Reid Spencer45fb3f32006-11-20 01:22:35 +0000514
515 /// This also tests for commutativity. If isEquality() returns true then
Reid Spencere4d87aa2006-12-23 06:05:41 +0000516 /// the predicate is also commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000517 /// @returns true if the predicate of this instruction is EQ or NE.
518 /// @brief Determine if this is an equality predicate.
519 bool isEquality() const {
520 return SubclassData == ICMP_EQ || SubclassData == ICMP_NE;
521 }
Reid Spencere4d87aa2006-12-23 06:05:41 +0000522
523 /// @returns true if the predicate of this ICmpInst is commutative
524 /// @brief Determine if this relation is commutative.
Reid Spencer45fb3f32006-11-20 01:22:35 +0000525 bool isCommutative() const { return isEquality(); }
526
527 /// @returns true if the predicate is relational (not EQ or NE).
528 /// @brief Determine if this a relational predicate.
529 bool isRelational() const {
530 return !isEquality();
531 }
532
Reid Spencere4d87aa2006-12-23 06:05:41 +0000533 /// @returns true if the predicate of this ICmpInst is signed, false otherwise
534 /// @brief Determine if this instruction's predicate is signed.
535 bool isSignedPredicate() { return isSignedPredicate(getPredicate()); }
536
537 /// @returns true if the predicate provided is signed, false otherwise
538 /// @brief Determine if the predicate is signed.
539 static bool isSignedPredicate(Predicate pred);
540
Reid Spencer3da43842007-02-28 22:00:54 +0000541 /// Initialize a set of values that all satisfy the predicate with C.
542 /// @brief Make a ConstantRange for a relation with a constant value.
543 static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
544
Reid Spencer45fb3f32006-11-20 01:22:35 +0000545 /// Exchange the two operands to this instruction in such a way that it does
546 /// not modify the semantics of the instruction. The predicate value may be
547 /// changed to retain the same result if the predicate is order dependent
548 /// (e.g. ult).
549 /// @brief Swap operands and adjust predicate.
550 void swapOperands() {
551 SubclassData = getSwappedPredicate();
552 std::swap(Ops[0], Ops[1]);
553 }
554
555 // Methods for support type inquiry through isa, cast, and dyn_cast:
556 static inline bool classof(const ICmpInst *) { return true; }
557 static inline bool classof(const Instruction *I) {
558 return I->getOpcode() == Instruction::ICmp;
559 }
560 static inline bool classof(const Value *V) {
561 return isa<Instruction>(V) && classof(cast<Instruction>(V));
562 }
563};
564
565//===----------------------------------------------------------------------===//
566// FCmpInst Class
567//===----------------------------------------------------------------------===//
568
569/// This instruction compares its operands according to the predicate given
570/// to the constructor. It only operates on floating point values or packed
571/// vectors of floating point values. The operands must be identical types.
572/// @brief Represents a floating point comparison operator.
573class FCmpInst: public CmpInst {
574public:
575 /// This enumeration lists the possible predicates for the FCmpInst. Values
576 /// in the range 0-31 are reserved for FCmpInst.
577 enum Predicate {
578 // Opcode U L G E Intuitive operation
579 FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
580 FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
581 FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
582 FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
583 FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
584 FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
585 FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
586 FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
587 FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
588 FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
589 FCMP_UGT =10, ///< 1 0 1 0 True if unordered or greater than
590 FCMP_UGE =11, ///< 1 0 1 1 True if unordered, greater than, or equal
591 FCMP_ULT =12, ///< 1 1 0 0 True if unordered or less than
592 FCMP_ULE =13, ///< 1 1 0 1 True if unordered, less than, or equal
593 FCMP_UNE =14, ///< 1 1 1 0 True if unordered or not equal
594 FCMP_TRUE =15, ///< 1 1 1 1 Always true (always folded)
595 FIRST_FCMP_PREDICATE = FCMP_FALSE,
Reid Spencere4d87aa2006-12-23 06:05:41 +0000596 LAST_FCMP_PREDICATE = FCMP_TRUE,
597 BAD_FCMP_PREDICATE = FCMP_TRUE + 1
Reid Spencer45fb3f32006-11-20 01:22:35 +0000598 };
599
600 /// @brief Constructor with insert-before-instruction semantics.
601 FCmpInst(
602 Predicate pred, ///< The predicate to use for the comparison
603 Value *LHS, ///< The left-hand-side of the expression
604 Value *RHS, ///< The right-hand-side of the expression
605 const std::string &Name = "", ///< Name of the instruction
606 Instruction *InsertBefore = 0 ///< Where to insert
607 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertBefore) {
608 }
609
610 /// @brief Constructor with insert-at-block-end semantics.
611 FCmpInst(
612 Predicate pred, ///< The predicate to use for the comparison
613 Value *LHS, ///< The left-hand-side of the expression
614 Value *RHS, ///< The right-hand-side of the expression
615 const std::string &Name, ///< Name of the instruction
616 BasicBlock *InsertAtEnd ///< Block to insert into.
617 ) : CmpInst(Instruction::FCmp, pred, LHS, RHS, Name, InsertAtEnd) {
618 }
619
620 /// @brief Return the predicate for this instruction.
621 Predicate getPredicate() const { return Predicate(SubclassData); }
622
Chris Lattnerb769d562007-01-14 19:41:24 +0000623 /// @brief Set the predicate for this instruction to the specified value.
624 void setPredicate(Predicate P) { SubclassData = P; }
625
Reid Spencer45fb3f32006-11-20 01:22:35 +0000626 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
627 /// @returns the inverse predicate for the instructions current predicate.
628 /// @brief Return the inverse of the predicate
629 Predicate getInversePredicate() const {
630 return getInversePredicate(getPredicate());
631 }
632
633 /// For example, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
634 /// @returns the inverse predicate for \p pred.
635 /// @brief Return the inverse of a given predicate
636 static Predicate getInversePredicate(Predicate pred);
637
638 /// For example, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
639 /// @returns the predicate that would be the result of exchanging the two
640 /// operands of the ICmpInst instruction without changing the result
641 /// produced.
642 /// @brief Return the predicate as if the operands were swapped
643 Predicate getSwappedPredicate() const {
644 return getSwappedPredicate(getPredicate());
645 }
646
647 /// This is a static version that you can use without an instruction
648 /// available.
649 /// @brief Return the predicate as if the operands were swapped.
650 static Predicate getSwappedPredicate(Predicate Opcode);
651
652 /// This also tests for commutativity. If isEquality() returns true then
653 /// the predicate is also commutative. Only the equality predicates are
654 /// commutative.
655 /// @returns true if the predicate of this instruction is EQ or NE.
656 /// @brief Determine if this is an equality predicate.
657 bool isEquality() const {
658 return SubclassData == FCMP_OEQ || SubclassData == FCMP_ONE ||
659 SubclassData == FCMP_UEQ || SubclassData == FCMP_UNE;
660 }
661 bool isCommutative() const { return isEquality(); }
662
663 /// @returns true if the predicate is relational (not EQ or NE).
664 /// @brief Determine if this a relational predicate.
665 bool isRelational() const { return !isEquality(); }
666
667 /// Exchange the two operands to this instruction in such a way that it does
668 /// not modify the semantics of the instruction. The predicate value may be
669 /// changed to retain the same result if the predicate is order dependent
670 /// (e.g. ult).
671 /// @brief Swap operands and adjust predicate.
672 void swapOperands() {
673 SubclassData = getSwappedPredicate();
674 std::swap(Ops[0], Ops[1]);
675 }
676
677 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
678 static inline bool classof(const FCmpInst *) { return true; }
679 static inline bool classof(const Instruction *I) {
680 return I->getOpcode() == Instruction::FCmp;
681 }
682 static inline bool classof(const Value *V) {
683 return isa<Instruction>(V) && classof(cast<Instruction>(V));
684 }
685};
686
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000687//===----------------------------------------------------------------------===//
688// CallInst Class
689//===----------------------------------------------------------------------===//
690
691/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000692/// machine's calling convention. This class uses low bit of the SubClassData
693/// field to indicate whether or not this is a tail call. The rest of the bits
694/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000695///
696class CallInst : public Instruction {
697 CallInst(const CallInst &CI);
Chris Lattnerd54f4322007-02-13 00:58:44 +0000698 void init(Value *Func, Value* const *Params, unsigned NumParams);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000699 void init(Value *Func, Value *Actual1, Value *Actual2);
700 void init(Value *Func, Value *Actual);
701 void init(Value *Func);
702
703public:
Chris Lattnerd2dd1502007-02-13 01:04:01 +0000704 CallInst(Value *F, Value* const *Args, unsigned NumArgs,
705 const std::string &Name = "", Instruction *InsertBefore = 0);
706 CallInst(Value *F, Value *const *Args, unsigned NumArgs,
707 const std::string &Name, BasicBlock *InsertAtEnd);
708
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000709 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
710 // actuals, respectively.
711 CallInst(Value *F, Value *Actual1, Value *Actual2,
712 const std::string& Name = "", Instruction *InsertBefore = 0);
713 CallInst(Value *F, Value *Actual1, Value *Actual2,
714 const std::string& Name, BasicBlock *InsertAtEnd);
715 CallInst(Value *F, Value *Actual, const std::string& Name = "",
716 Instruction *InsertBefore = 0);
717 CallInst(Value *F, Value *Actual, const std::string& Name,
718 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000719 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000720 Instruction *InsertBefore = 0);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000721 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000722 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000723
Chris Lattnerf319e832004-10-15 23:52:05 +0000724 virtual CallInst *clone() const;
Chris Lattnerbb5493d2007-02-15 23:15:00 +0000725
Chris Lattner3340ffe2005-05-06 20:26:26 +0000726 bool isTailCall() const { return SubclassData & 1; }
727 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000728 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000729 }
730
731 /// getCallingConv/setCallingConv - Get or set the calling convention of this
732 /// function call.
733 unsigned getCallingConv() const { return SubclassData >> 1; }
734 void setCallingConv(unsigned CC) {
735 SubclassData = (SubclassData & 1) | (CC << 1);
736 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000737
Chris Lattner721aef62004-11-18 17:46:57 +0000738 /// getCalledFunction - Return the function being called by this instruction
739 /// if it is a direct call. If it is a call through a function pointer,
740 /// return null.
741 Function *getCalledFunction() const {
Reid Spenceredd5d9e2005-05-15 16:13:11 +0000742 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
Chris Lattner721aef62004-11-18 17:46:57 +0000743 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000744
Reid Spencerc25ec252006-12-29 04:10:59 +0000745 /// getCalledValue - Get a pointer to the function that is invoked by this
746 /// instruction
Chris Lattner454928e2005-01-29 00:31:36 +0000747 inline const Value *getCalledValue() const { return getOperand(0); }
748 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000749
750 // Methods for support type inquiry through isa, cast, and dyn_cast:
751 static inline bool classof(const CallInst *) { return true; }
752 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000753 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000754 }
755 static inline bool classof(const Value *V) {
756 return isa<Instruction>(V) && classof(cast<Instruction>(V));
757 }
758};
759
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000760//===----------------------------------------------------------------------===//
761// SelectInst Class
762//===----------------------------------------------------------------------===//
763
764/// SelectInst - This class represents the LLVM 'select' instruction.
765///
766class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000767 Use Ops[3];
768
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000769 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000770 Ops[0].init(C, this);
771 Ops[1].init(S1, this);
772 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000773 }
774
Chris Lattner454928e2005-01-29 00:31:36 +0000775 SelectInst(const SelectInst &SI)
776 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
777 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
778 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000779public:
780 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
781 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000782 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
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 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
787 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000788 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000789 init(C, S1, S2);
Chris Lattner910c80a2007-02-24 00:55:48 +0000790 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000791 }
792
Chris Lattner454928e2005-01-29 00:31:36 +0000793 Value *getCondition() const { return Ops[0]; }
794 Value *getTrueValue() const { return Ops[1]; }
795 Value *getFalseValue() const { return Ops[2]; }
796
797 /// Transparently provide more efficient getOperand methods.
798 Value *getOperand(unsigned i) const {
799 assert(i < 3 && "getOperand() out of range!");
800 return Ops[i];
801 }
802 void setOperand(unsigned i, Value *Val) {
803 assert(i < 3 && "setOperand() out of range!");
804 Ops[i] = Val;
805 }
806 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000807
808 OtherOps getOpcode() const {
809 return static_cast<OtherOps>(Instruction::getOpcode());
810 }
811
Chris Lattnerf319e832004-10-15 23:52:05 +0000812 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000813
814 // Methods for support type inquiry through isa, cast, and dyn_cast:
815 static inline bool classof(const SelectInst *) { return true; }
816 static inline bool classof(const Instruction *I) {
817 return I->getOpcode() == Instruction::Select;
818 }
819 static inline bool classof(const Value *V) {
820 return isa<Instruction>(V) && classof(cast<Instruction>(V));
821 }
822};
823
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000824//===----------------------------------------------------------------------===//
825// VAArgInst Class
826//===----------------------------------------------------------------------===//
827
828/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +0000829/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000830///
Chris Lattner454928e2005-01-29 00:31:36 +0000831class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000832 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +0000833 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000834public:
835 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
836 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +0000837 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000838 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000839 }
840 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
841 BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +0000842 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
Chris Lattnerf00042a2007-02-13 07:54:42 +0000843 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000844 }
845
Chris Lattnerf319e832004-10-15 23:52:05 +0000846 virtual VAArgInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000847
848 // Methods for support type inquiry through isa, cast, and dyn_cast:
849 static inline bool classof(const VAArgInst *) { return true; }
850 static inline bool classof(const Instruction *I) {
851 return I->getOpcode() == VAArg;
852 }
853 static inline bool classof(const Value *V) {
854 return isa<Instruction>(V) && classof(cast<Instruction>(V));
855 }
856};
857
858//===----------------------------------------------------------------------===//
Robert Bocchino49b78a52006-01-10 19:04:13 +0000859// ExtractElementInst Class
860//===----------------------------------------------------------------------===//
861
862/// ExtractElementInst - This instruction extracts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000863/// element from a VectorType value
Robert Bocchino49b78a52006-01-10 19:04:13 +0000864///
865class ExtractElementInst : public Instruction {
866 Use Ops[2];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000867 ExtractElementInst(const ExtractElementInst &EE) :
Robert Bocchinof9993442006-01-17 20:05:59 +0000868 Instruction(EE.getType(), ExtractElement, Ops, 2) {
869 Ops[0].init(EE.Ops[0], this);
870 Ops[1].init(EE.Ops[1], this);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000871 }
872
873public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000874 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
875 Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000876 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
877 Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000878 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
879 BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000880 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name,
881 BasicBlock *InsertAtEnd);
Robert Bocchino49b78a52006-01-10 19:04:13 +0000882
Chris Lattnerfa495842006-04-08 04:04:54 +0000883 /// isValidOperands - Return true if an extractelement instruction can be
884 /// formed with the specified operands.
885 static bool isValidOperands(const Value *Vec, const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000886
Robert Bocchino49b78a52006-01-10 19:04:13 +0000887 virtual ExtractElementInst *clone() const;
888
Robert Bocchino49b78a52006-01-10 19:04:13 +0000889 /// Transparently provide more efficient getOperand methods.
890 Value *getOperand(unsigned i) const {
891 assert(i < 2 && "getOperand() out of range!");
892 return Ops[i];
893 }
894 void setOperand(unsigned i, Value *Val) {
895 assert(i < 2 && "setOperand() out of range!");
896 Ops[i] = Val;
897 }
898 unsigned getNumOperands() const { return 2; }
899
900 // Methods for support type inquiry through isa, cast, and dyn_cast:
901 static inline bool classof(const ExtractElementInst *) { return true; }
902 static inline bool classof(const Instruction *I) {
903 return I->getOpcode() == Instruction::ExtractElement;
904 }
905 static inline bool classof(const Value *V) {
906 return isa<Instruction>(V) && classof(cast<Instruction>(V));
907 }
908};
909
910//===----------------------------------------------------------------------===//
Robert Bocchinof9993442006-01-17 20:05:59 +0000911// InsertElementInst Class
912//===----------------------------------------------------------------------===//
913
914/// InsertElementInst - This instruction inserts a single (scalar)
Reid Spencer9d6565a2007-02-15 02:26:10 +0000915/// element into a VectorType value
Robert Bocchinof9993442006-01-17 20:05:59 +0000916///
917class InsertElementInst : public Instruction {
918 Use Ops[3];
Chris Lattner6a56ed42006-04-14 22:20:07 +0000919 InsertElementInst(const InsertElementInst &IE);
Robert Bocchinof9993442006-01-17 20:05:59 +0000920public:
Chris Lattner9fc18d22006-04-08 01:15:18 +0000921 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
922 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner06a248c22006-10-05 06:24:58 +0000923 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
924 const std::string &Name = "",Instruction *InsertBefore = 0);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000925 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
Robert Bocchinof9993442006-01-17 20:05:59 +0000926 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner06a248c22006-10-05 06:24:58 +0000927 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
928 const std::string &Name, BasicBlock *InsertAtEnd);
Robert Bocchinof9993442006-01-17 20:05:59 +0000929
Chris Lattnerfa495842006-04-08 04:04:54 +0000930 /// isValidOperands - Return true if an insertelement instruction can be
931 /// formed with the specified operands.
932 static bool isValidOperands(const Value *Vec, const Value *NewElt,
933 const Value *Idx);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000934
Robert Bocchinof9993442006-01-17 20:05:59 +0000935 virtual InsertElementInst *clone() const;
936
Reid Spencerac9dcb92007-02-15 03:39:18 +0000937 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +0000938 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +0000939 inline const VectorType *getType() const {
940 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +0000941 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000942
Robert Bocchinof9993442006-01-17 20:05:59 +0000943 /// Transparently provide more efficient getOperand methods.
944 Value *getOperand(unsigned i) const {
945 assert(i < 3 && "getOperand() out of range!");
946 return Ops[i];
947 }
948 void setOperand(unsigned i, Value *Val) {
949 assert(i < 3 && "setOperand() out of range!");
950 Ops[i] = Val;
951 }
952 unsigned getNumOperands() const { return 3; }
953
954 // Methods for support type inquiry through isa, cast, and dyn_cast:
955 static inline bool classof(const InsertElementInst *) { return true; }
956 static inline bool classof(const Instruction *I) {
957 return I->getOpcode() == Instruction::InsertElement;
958 }
959 static inline bool classof(const Value *V) {
960 return isa<Instruction>(V) && classof(cast<Instruction>(V));
961 }
962};
963
964//===----------------------------------------------------------------------===//
Chris Lattner9fc18d22006-04-08 01:15:18 +0000965// ShuffleVectorInst Class
966//===----------------------------------------------------------------------===//
967
968/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
969/// input vectors.
970///
971class ShuffleVectorInst : public Instruction {
972 Use Ops[3];
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000973 ShuffleVectorInst(const ShuffleVectorInst &IE);
Chris Lattner9fc18d22006-04-08 01:15:18 +0000974public:
975 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
976 const std::string &Name = "", Instruction *InsertBefor = 0);
977 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
978 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000979
Chris Lattnerfa495842006-04-08 04:04:54 +0000980 /// isValidOperands - Return true if a shufflevector instruction can be
Chris Lattner9fc18d22006-04-08 01:15:18 +0000981 /// formed with the specified operands.
982 static bool isValidOperands(const Value *V1, const Value *V2,
983 const Value *Mask);
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000984
Chris Lattner9fc18d22006-04-08 01:15:18 +0000985 virtual ShuffleVectorInst *clone() const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000986
Reid Spencerac9dcb92007-02-15 03:39:18 +0000987 /// getType - Overload to return most specific vector type.
Chris Lattner6a56ed42006-04-14 22:20:07 +0000988 ///
Reid Spencer9d6565a2007-02-15 02:26:10 +0000989 inline const VectorType *getType() const {
990 return reinterpret_cast<const VectorType*>(Instruction::getType());
Chris Lattner6a56ed42006-04-14 22:20:07 +0000991 }
Chris Lattnerf56a8db2006-10-03 17:09:12 +0000992
Chris Lattner9fc18d22006-04-08 01:15:18 +0000993 /// Transparently provide more efficient getOperand methods.
994 Value *getOperand(unsigned i) const {
995 assert(i < 3 && "getOperand() out of range!");
996 return Ops[i];
997 }
998 void setOperand(unsigned i, Value *Val) {
999 assert(i < 3 && "setOperand() out of range!");
1000 Ops[i] = Val;
1001 }
1002 unsigned getNumOperands() const { return 3; }
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001003
Chris Lattner9fc18d22006-04-08 01:15:18 +00001004 // Methods for support type inquiry through isa, cast, and dyn_cast:
1005 static inline bool classof(const ShuffleVectorInst *) { return true; }
1006 static inline bool classof(const Instruction *I) {
1007 return I->getOpcode() == Instruction::ShuffleVector;
1008 }
1009 static inline bool classof(const Value *V) {
1010 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1011 }
1012};
1013
1014
1015//===----------------------------------------------------------------------===//
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001016// PHINode Class
1017//===----------------------------------------------------------------------===//
1018
1019// PHINode - The PHINode class is used to represent the magical mystical PHI
1020// node, that can not exist in nature, but can be synthesized in a computer
1021// scientist's overactive imagination.
1022//
1023class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +00001024 /// ReservedSpace - The number of operands actually allocated. NumOperands is
1025 /// the number actually in use.
1026 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001027 PHINode(const PHINode &PN);
1028public:
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001029 explicit PHINode(const Type *Ty, const std::string &Name = "",
1030 Instruction *InsertBefore = 0)
Chris Lattner910c80a2007-02-24 00:55:48 +00001031 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
Chris Lattner454928e2005-01-29 00:31:36 +00001032 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001033 setName(Name);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001034 }
1035
1036 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner910c80a2007-02-24 00:55:48 +00001037 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
Chris Lattner454928e2005-01-29 00:31:36 +00001038 ReservedSpace(0) {
Chris Lattner910c80a2007-02-24 00:55:48 +00001039 setName(Name);
Chris Lattner454928e2005-01-29 00:31:36 +00001040 }
1041
1042 ~PHINode();
1043
1044 /// reserveOperandSpace - This method can be used to avoid repeated
1045 /// reallocation of PHI operand lists by reserving space for the correct
1046 /// number of operands before adding them. Unlike normal vector reserves,
1047 /// this method can also be used to trim the operand space.
1048 void reserveOperandSpace(unsigned NumValues) {
1049 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001050 }
1051
Chris Lattnerf319e832004-10-15 23:52:05 +00001052 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001053
1054 /// getNumIncomingValues - Return the number of incoming edges
1055 ///
Chris Lattner454928e2005-01-29 00:31:36 +00001056 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001057
Reid Spencerc773de62006-05-19 19:07:54 +00001058 /// getIncomingValue - Return incoming value number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001059 ///
1060 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001061 assert(i*2 < getNumOperands() && "Invalid value number!");
1062 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001063 }
1064 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +00001065 assert(i*2 < getNumOperands() && "Invalid value number!");
1066 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001067 }
Chris Lattner454928e2005-01-29 00:31:36 +00001068 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001069 return i*2;
1070 }
1071
Reid Spencerc773de62006-05-19 19:07:54 +00001072 /// getIncomingBlock - Return incoming basic block number x
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001073 ///
Misha Brukman9769ab22005-04-21 20:19:05 +00001074 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001075 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001076 }
1077 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +00001078 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001079 }
1080 unsigned getOperandNumForIncomingBlock(unsigned i) {
1081 return i*2+1;
1082 }
1083
1084 /// addIncoming - Add an incoming value to the end of the PHI list
1085 ///
1086 void addIncoming(Value *V, BasicBlock *BB) {
1087 assert(getType() == V->getType() &&
1088 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +00001089 unsigned OpNo = NumOperands;
1090 if (OpNo+2 > ReservedSpace)
1091 resizeOperands(0); // Get more space!
1092 // Initialize some new operands.
1093 NumOperands = OpNo+2;
1094 OperandList[OpNo].init(V, this);
1095 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001096 }
Misha Brukman9769ab22005-04-21 20:19:05 +00001097
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001098 /// removeIncomingValue - Remove an incoming value. This is useful if a
1099 /// predecessor basic block is deleted. The value removed is returned.
1100 ///
1101 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
1102 /// is true), the PHI node is destroyed and any uses of it are replaced with
1103 /// dummy values. The only time there should be zero incoming values to a PHI
1104 /// node is when the block is dead, so this strategy is sound.
1105 ///
1106 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
1107
1108 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
1109 int Idx = getBasicBlockIndex(BB);
1110 assert(Idx >= 0 && "Invalid basic block argument to remove!");
1111 return removeIncomingValue(Idx, DeletePHIIfEmpty);
1112 }
1113
Misha Brukman9769ab22005-04-21 20:19:05 +00001114 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001115 /// block in the value list for this PHI. Returns -1 if no instance.
1116 ///
1117 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +00001118 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +00001119 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +00001120 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001121 return -1;
1122 }
1123
1124 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
1125 return getIncomingValue(getBasicBlockIndex(BB));
1126 }
1127
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001128 /// hasConstantValue - If the specified PHI node always merges together the
Nate Begemana83ba0f2005-08-04 23:24:19 +00001129 /// same value, return the value, otherwise return null.
1130 ///
Chris Lattner9acbd612005-08-05 00:49:06 +00001131 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Chris Lattnerf56a8db2006-10-03 17:09:12 +00001132
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001133 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1134 static inline bool classof(const PHINode *) { return true; }
1135 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +00001136 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001137 }
1138 static inline bool classof(const Value *V) {
1139 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1140 }
Chris Lattner454928e2005-01-29 00:31:36 +00001141 private:
1142 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001143};
1144
1145//===----------------------------------------------------------------------===//
1146// ReturnInst Class
1147//===----------------------------------------------------------------------===//
1148
1149//===---------------------------------------------------------------------------
1150/// ReturnInst - Return a value (possibly void), from a function. Execution
1151/// does not continue in this function any longer.
1152///
1153class ReturnInst : public TerminatorInst {
Chris Lattner910c80a2007-02-24 00:55:48 +00001154 Use RetVal; // Return Value: null if 'void'.
1155 ReturnInst(const ReturnInst &RI);
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001156 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001157
1158public:
1159 // ReturnInst constructors:
1160 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001161 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001162 // ReturnInst(Value* X) - 'ret X' instruction
1163 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1164 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1165 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1166 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +00001167 //
1168 // NOTE: If the Value* passed is of type void then the constructor behaves as
1169 // if it was passed NULL.
Chris Lattner910c80a2007-02-24 00:55:48 +00001170 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
1171 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
1172 explicit ReturnInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001173
Chris Lattnerf319e832004-10-15 23:52:05 +00001174 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001175
Chris Lattner454928e2005-01-29 00:31:36 +00001176 // Transparently provide more efficient getOperand methods.
1177 Value *getOperand(unsigned i) const {
1178 assert(i < getNumOperands() && "getOperand() out of range!");
1179 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001180 }
Chris Lattner454928e2005-01-29 00:31:36 +00001181 void setOperand(unsigned i, Value *Val) {
1182 assert(i < getNumOperands() && "setOperand() out of range!");
1183 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001184 }
1185
Chris Lattner454928e2005-01-29 00:31:36 +00001186 Value *getReturnValue() const { return RetVal; }
1187
1188 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001189
1190 // Methods for support type inquiry through isa, cast, and dyn_cast:
1191 static inline bool classof(const ReturnInst *) { return true; }
1192 static inline bool classof(const Instruction *I) {
1193 return (I->getOpcode() == Instruction::Ret);
1194 }
1195 static inline bool classof(const Value *V) {
1196 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1197 }
Chris Lattner454928e2005-01-29 00:31:36 +00001198 private:
1199 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1200 virtual unsigned getNumSuccessorsV() const;
1201 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001202};
1203
1204//===----------------------------------------------------------------------===//
1205// BranchInst Class
1206//===----------------------------------------------------------------------===//
1207
1208//===---------------------------------------------------------------------------
1209/// BranchInst - Conditional or Unconditional Branch instruction.
1210///
1211class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001212 /// Ops list - Branches are strange. The operands are ordered:
1213 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1214 /// they don't have to check for cond/uncond branchness.
1215 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001216 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +00001217 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001218public:
1219 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1220 // BranchInst(BB *B) - 'br B'
1221 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1222 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1223 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1224 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1225 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
Chris Lattner910c80a2007-02-24 00:55:48 +00001226 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001227 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001228 Instruction *InsertBefore = 0);
1229 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001230 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
Chris Lattner910c80a2007-02-24 00:55:48 +00001231 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001232
1233 /// Transparently provide more efficient getOperand methods.
1234 Value *getOperand(unsigned i) const {
1235 assert(i < getNumOperands() && "getOperand() out of range!");
1236 return Ops[i];
1237 }
1238 void setOperand(unsigned i, Value *Val) {
1239 assert(i < getNumOperands() && "setOperand() out of range!");
1240 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001241 }
1242
Chris Lattnerf319e832004-10-15 23:52:05 +00001243 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001244
Chris Lattner454928e2005-01-29 00:31:36 +00001245 inline bool isUnconditional() const { return getNumOperands() == 1; }
1246 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001247
1248 inline Value *getCondition() const {
1249 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001250 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001251 }
1252
1253 void setCondition(Value *V) {
1254 assert(isConditional() && "Cannot set condition of unconditional branch!");
1255 setOperand(2, V);
1256 }
1257
1258 // setUnconditionalDest - Change the current branch to an unconditional branch
1259 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +00001260 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001261 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +00001262 if (isConditional()) { // Convert this to an uncond branch.
1263 NumOperands = 1;
1264 Ops[1].set(0);
1265 Ops[2].set(0);
1266 }
1267 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001268 }
1269
Chris Lattner454928e2005-01-29 00:31:36 +00001270 unsigned getNumSuccessors() const { return 1+isConditional(); }
1271
1272 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001273 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Misha Brukman9769ab22005-04-21 20:19:05 +00001274 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
Chris Lattner454928e2005-01-29 00:31:36 +00001275 cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001276 }
1277
Chris Lattner454928e2005-01-29 00:31:36 +00001278 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001279 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001280 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001281 }
1282
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001283 // Methods for support type inquiry through isa, cast, and dyn_cast:
1284 static inline bool classof(const BranchInst *) { return true; }
1285 static inline bool classof(const Instruction *I) {
1286 return (I->getOpcode() == Instruction::Br);
1287 }
1288 static inline bool classof(const Value *V) {
1289 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1290 }
Chris Lattner454928e2005-01-29 00:31:36 +00001291private:
1292 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1293 virtual unsigned getNumSuccessorsV() const;
1294 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001295};
1296
1297//===----------------------------------------------------------------------===//
1298// SwitchInst Class
1299//===----------------------------------------------------------------------===//
1300
1301//===---------------------------------------------------------------------------
1302/// SwitchInst - Multiway switch
1303///
1304class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001305 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001306 // Operand[0] = Value to switch on
1307 // Operand[1] = Default basic block destination
1308 // Operand[2n ] = Value to match
1309 // Operand[2n+1] = BasicBlock to go to on match
1310 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001311 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1312 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001313public:
Chris Lattner454928e2005-01-29 00:31:36 +00001314 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1315 /// switch on and a default destination. The number of additional cases can
1316 /// be specified here to make memory allocation more efficient. This
1317 /// constructor can also autoinsert before another instruction.
1318 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001319 Instruction *InsertBefore = 0);
1320
Chris Lattner454928e2005-01-29 00:31:36 +00001321 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1322 /// switch on and a default destination. The number of additional cases can
1323 /// be specified here to make memory allocation more efficient. This
1324 /// constructor also autoinserts at the end of the specified BasicBlock.
1325 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Chris Lattner910c80a2007-02-24 00:55:48 +00001326 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001327 ~SwitchInst();
1328
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001329
1330 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001331 inline Value *getCondition() const { return getOperand(0); }
1332 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001333
Chris Lattner454928e2005-01-29 00:31:36 +00001334 inline BasicBlock *getDefaultDest() const {
1335 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001336 }
1337
1338 /// getNumCases - return the number of 'cases' in this switch instruction.
1339 /// Note that case #0 is always the default case.
1340 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001341 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001342 }
1343
1344 /// getCaseValue - Return the specified case value. Note that case #0, the
1345 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001346 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001347 assert(i && i < getNumCases() && "Illegal case value to get!");
1348 return getSuccessorValue(i);
1349 }
1350
1351 /// getCaseValue - Return the specified case value. Note that case #0, the
1352 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001353 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001354 assert(i && i < getNumCases() && "Illegal case value to get!");
1355 return getSuccessorValue(i);
1356 }
1357
1358 /// findCaseValue - Search all of the case values for the specified constant.
1359 /// If it is explicitly handled, return the case number of it, otherwise
1360 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001361 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001362 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1363 if (getCaseValue(i) == C)
1364 return i;
1365 return 0;
1366 }
1367
Nick Lewycky011f1842006-09-18 19:03:59 +00001368 /// findCaseDest - Finds the unique case value for a given successor. Returns
1369 /// null if the successor is not found, not unique, or is the default case.
1370 ConstantInt *findCaseDest(BasicBlock *BB) {
Nick Lewyckyd7915442006-09-18 20:44:37 +00001371 if (BB == getDefaultDest()) return NULL;
1372
Nick Lewycky011f1842006-09-18 19:03:59 +00001373 ConstantInt *CI = NULL;
1374 for (unsigned i = 1, e = getNumCases(); i != e; ++i) {
1375 if (getSuccessor(i) == BB) {
1376 if (CI) return NULL; // Multiple cases lead to BB.
1377 else CI = getCaseValue(i);
1378 }
1379 }
1380 return CI;
1381 }
1382
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001383 /// addCase - Add an entry to the switch instruction...
1384 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001385 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001386
1387 /// removeCase - This method removes the specified successor from the switch
1388 /// instruction. Note that this cannot be used to remove the default
1389 /// destination (successor #0).
1390 ///
1391 void removeCase(unsigned idx);
1392
Chris Lattner454928e2005-01-29 00:31:36 +00001393 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001394
Chris Lattner454928e2005-01-29 00:31:36 +00001395 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1396 BasicBlock *getSuccessor(unsigned idx) const {
1397 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1398 return cast<BasicBlock>(getOperand(idx*2+1));
1399 }
1400 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001401 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001402 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001403 }
1404
1405 // getSuccessorValue - Return the value associated with the specified
1406 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001407 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001408 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001409 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001410 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001411
1412 // Methods for support type inquiry through isa, cast, and dyn_cast:
1413 static inline bool classof(const SwitchInst *) { return true; }
1414 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001415 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001416 }
1417 static inline bool classof(const Value *V) {
1418 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1419 }
Chris Lattner454928e2005-01-29 00:31:36 +00001420private:
1421 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1422 virtual unsigned getNumSuccessorsV() const;
1423 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001424};
1425
1426//===----------------------------------------------------------------------===//
1427// InvokeInst Class
1428//===----------------------------------------------------------------------===//
1429
1430//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001431
1432/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1433/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001434///
1435class InvokeInst : public TerminatorInst {
1436 InvokeInst(const InvokeInst &BI);
1437 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001438 Value* const *Args, unsigned NumArgs);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001439public:
1440 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Chris Lattnerd2dd1502007-02-13 01:04:01 +00001441 Value* const* Args, unsigned NumArgs, const std::string &Name = "",
1442 Instruction *InsertBefore = 0);
1443 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1444 Value* const* Args, unsigned NumArgs, const std::string &Name,
1445 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001446 ~InvokeInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001447
Chris Lattnerf319e832004-10-15 23:52:05 +00001448 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001449
Chris Lattner3340ffe2005-05-06 20:26:26 +00001450 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1451 /// function call.
1452 unsigned getCallingConv() const { return SubclassData; }
1453 void setCallingConv(unsigned CC) {
1454 SubclassData = CC;
1455 }
1456
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001457 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001458 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001459 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001460 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001461 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001462 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001463
1464 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001465 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001466
1467 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001468 BasicBlock *getNormalDest() const {
1469 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001470 }
Chris Lattner454928e2005-01-29 00:31:36 +00001471 BasicBlock *getUnwindDest() const {
1472 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001473 }
Chris Lattner454928e2005-01-29 00:31:36 +00001474 void setNormalDest(BasicBlock *B) {
1475 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001476 }
1477
Chris Lattner454928e2005-01-29 00:31:36 +00001478 void setUnwindDest(BasicBlock *B) {
1479 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001480 }
1481
Chris Lattner454928e2005-01-29 00:31:36 +00001482 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001483 assert(i < 2 && "Successor # out of range for invoke!");
1484 return i == 0 ? getNormalDest() : getUnwindDest();
1485 }
1486
Chris Lattner454928e2005-01-29 00:31:36 +00001487 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001488 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001489 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001490 }
1491
Chris Lattner454928e2005-01-29 00:31:36 +00001492 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001493
1494 // Methods for support type inquiry through isa, cast, and dyn_cast:
1495 static inline bool classof(const InvokeInst *) { return true; }
1496 static inline bool classof(const Instruction *I) {
1497 return (I->getOpcode() == Instruction::Invoke);
1498 }
1499 static inline bool classof(const Value *V) {
1500 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1501 }
Chris Lattner454928e2005-01-29 00:31:36 +00001502private:
1503 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1504 virtual unsigned getNumSuccessorsV() const;
1505 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001506};
1507
1508
1509//===----------------------------------------------------------------------===//
1510// UnwindInst Class
1511//===----------------------------------------------------------------------===//
1512
1513//===---------------------------------------------------------------------------
1514/// UnwindInst - Immediately exit the current function, unwinding the stack
1515/// until an invoke instruction is found.
1516///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001517class UnwindInst : public TerminatorInst {
1518public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001519 explicit UnwindInst(Instruction *InsertBefore = 0);
1520 explicit UnwindInst(BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001521
Chris Lattnerf319e832004-10-15 23:52:05 +00001522 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001523
Chris Lattner454928e2005-01-29 00:31:36 +00001524 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001525
1526 // Methods for support type inquiry through isa, cast, and dyn_cast:
1527 static inline bool classof(const UnwindInst *) { return true; }
1528 static inline bool classof(const Instruction *I) {
1529 return I->getOpcode() == Instruction::Unwind;
1530 }
1531 static inline bool classof(const Value *V) {
1532 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1533 }
Chris Lattner454928e2005-01-29 00:31:36 +00001534private:
1535 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1536 virtual unsigned getNumSuccessorsV() const;
1537 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001538};
1539
Chris Lattner076b3f12004-10-16 18:05:54 +00001540//===----------------------------------------------------------------------===//
1541// UnreachableInst Class
1542//===----------------------------------------------------------------------===//
1543
1544//===---------------------------------------------------------------------------
1545/// UnreachableInst - This function has undefined behavior. In particular, the
1546/// presence of this instruction indicates some higher level knowledge that the
1547/// end of the block cannot be reached.
1548///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001549class UnreachableInst : public TerminatorInst {
1550public:
Chris Lattner910c80a2007-02-24 00:55:48 +00001551 explicit UnreachableInst(Instruction *InsertBefore = 0);
1552 explicit UnreachableInst(BasicBlock *InsertAtEnd);
Chris Lattner076b3f12004-10-16 18:05:54 +00001553
1554 virtual UnreachableInst *clone() const;
1555
Chris Lattner454928e2005-01-29 00:31:36 +00001556 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001557
1558 // Methods for support type inquiry through isa, cast, and dyn_cast:
1559 static inline bool classof(const UnreachableInst *) { return true; }
1560 static inline bool classof(const Instruction *I) {
1561 return I->getOpcode() == Instruction::Unreachable;
1562 }
1563 static inline bool classof(const Value *V) {
1564 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1565 }
Chris Lattner454928e2005-01-29 00:31:36 +00001566private:
1567 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1568 virtual unsigned getNumSuccessorsV() const;
1569 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001570};
1571
Reid Spencer3da59db2006-11-27 01:05:10 +00001572//===----------------------------------------------------------------------===//
1573// TruncInst Class
1574//===----------------------------------------------------------------------===//
1575
1576/// @brief This class represents a truncation of integer types.
1577class TruncInst : public CastInst {
1578 /// Private copy constructor
1579 TruncInst(const TruncInst &CI)
1580 : CastInst(CI.getType(), Trunc, CI.getOperand(0)) {
1581 }
1582public:
1583 /// @brief Constructor with insert-before-instruction semantics
1584 TruncInst(
1585 Value *S, ///< The value to be truncated
1586 const Type *Ty, ///< The (smaller) type to truncate to
1587 const std::string &Name = "", ///< A name for the new instruction
1588 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1589 );
1590
1591 /// @brief Constructor with insert-at-end-of-block semantics
1592 TruncInst(
1593 Value *S, ///< The value to be truncated
1594 const Type *Ty, ///< The (smaller) type to truncate to
1595 const std::string &Name, ///< A name for the new instruction
1596 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1597 );
1598
1599 /// @brief Clone an identical TruncInst
1600 virtual CastInst *clone() const;
1601
1602 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1603 static inline bool classof(const TruncInst *) { return true; }
1604 static inline bool classof(const Instruction *I) {
1605 return I->getOpcode() == Trunc;
1606 }
1607 static inline bool classof(const Value *V) {
1608 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1609 }
1610};
1611
1612//===----------------------------------------------------------------------===//
1613// ZExtInst Class
1614//===----------------------------------------------------------------------===//
1615
1616/// @brief This class represents zero extension of integer types.
1617class ZExtInst : public CastInst {
1618 /// @brief Private copy constructor
1619 ZExtInst(const ZExtInst &CI)
1620 : CastInst(CI.getType(), ZExt, CI.getOperand(0)) {
1621 }
1622public:
1623 /// @brief Constructor with insert-before-instruction semantics
1624 ZExtInst(
1625 Value *S, ///< The value to be zero extended
1626 const Type *Ty, ///< The type to zero extend to
1627 const std::string &Name = "", ///< A name for the new instruction
1628 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1629 );
1630
1631 /// @brief Constructor with insert-at-end semantics.
1632 ZExtInst(
1633 Value *S, ///< The value to be zero extended
1634 const Type *Ty, ///< The type to zero extend to
1635 const std::string &Name, ///< A name for the new instruction
1636 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1637 );
1638
1639 /// @brief Clone an identical ZExtInst
1640 virtual CastInst *clone() const;
1641
1642 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1643 static inline bool classof(const ZExtInst *) { return true; }
1644 static inline bool classof(const Instruction *I) {
1645 return I->getOpcode() == ZExt;
1646 }
1647 static inline bool classof(const Value *V) {
1648 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1649 }
1650};
1651
1652//===----------------------------------------------------------------------===//
1653// SExtInst Class
1654//===----------------------------------------------------------------------===//
1655
1656/// @brief This class represents a sign extension of integer types.
1657class SExtInst : public CastInst {
1658 /// @brief Private copy constructor
1659 SExtInst(const SExtInst &CI)
1660 : CastInst(CI.getType(), SExt, CI.getOperand(0)) {
1661 }
1662public:
1663 /// @brief Constructor with insert-before-instruction semantics
1664 SExtInst(
1665 Value *S, ///< The value to be sign extended
1666 const Type *Ty, ///< The type to sign extend to
1667 const std::string &Name = "", ///< A name for the new instruction
1668 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1669 );
1670
1671 /// @brief Constructor with insert-at-end-of-block semantics
1672 SExtInst(
1673 Value *S, ///< The value to be sign extended
1674 const Type *Ty, ///< The type to sign extend to
1675 const std::string &Name, ///< A name for the new instruction
1676 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1677 );
1678
1679 /// @brief Clone an identical SExtInst
1680 virtual CastInst *clone() const;
1681
1682 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1683 static inline bool classof(const SExtInst *) { return true; }
1684 static inline bool classof(const Instruction *I) {
1685 return I->getOpcode() == SExt;
1686 }
1687 static inline bool classof(const Value *V) {
1688 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1689 }
1690};
1691
1692//===----------------------------------------------------------------------===//
1693// FPTruncInst Class
1694//===----------------------------------------------------------------------===//
1695
1696/// @brief This class represents a truncation of floating point types.
1697class FPTruncInst : public CastInst {
1698 FPTruncInst(const FPTruncInst &CI)
1699 : CastInst(CI.getType(), FPTrunc, CI.getOperand(0)) {
1700 }
1701public:
1702 /// @brief Constructor with insert-before-instruction semantics
1703 FPTruncInst(
1704 Value *S, ///< The value to be truncated
1705 const Type *Ty, ///< The type to truncate to
1706 const std::string &Name = "", ///< A name for the new instruction
1707 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1708 );
1709
1710 /// @brief Constructor with insert-before-instruction semantics
1711 FPTruncInst(
1712 Value *S, ///< The value to be truncated
1713 const Type *Ty, ///< The type to truncate to
1714 const std::string &Name, ///< A name for the new instruction
1715 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1716 );
1717
1718 /// @brief Clone an identical FPTruncInst
1719 virtual CastInst *clone() const;
1720
1721 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1722 static inline bool classof(const FPTruncInst *) { return true; }
1723 static inline bool classof(const Instruction *I) {
1724 return I->getOpcode() == FPTrunc;
1725 }
1726 static inline bool classof(const Value *V) {
1727 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1728 }
1729};
1730
1731//===----------------------------------------------------------------------===//
1732// FPExtInst Class
1733//===----------------------------------------------------------------------===//
1734
1735/// @brief This class represents an extension of floating point types.
1736class FPExtInst : public CastInst {
1737 FPExtInst(const FPExtInst &CI)
1738 : CastInst(CI.getType(), FPExt, CI.getOperand(0)) {
1739 }
1740public:
1741 /// @brief Constructor with insert-before-instruction semantics
1742 FPExtInst(
1743 Value *S, ///< The value to be extended
1744 const Type *Ty, ///< The type to extend to
1745 const std::string &Name = "", ///< A name for the new instruction
1746 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1747 );
1748
1749 /// @brief Constructor with insert-at-end-of-block semantics
1750 FPExtInst(
1751 Value *S, ///< The value to be extended
1752 const Type *Ty, ///< The type to extend to
1753 const std::string &Name, ///< A name for the new instruction
1754 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1755 );
1756
1757 /// @brief Clone an identical FPExtInst
1758 virtual CastInst *clone() const;
1759
1760 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1761 static inline bool classof(const FPExtInst *) { return true; }
1762 static inline bool classof(const Instruction *I) {
1763 return I->getOpcode() == FPExt;
1764 }
1765 static inline bool classof(const Value *V) {
1766 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1767 }
1768};
1769
1770//===----------------------------------------------------------------------===//
1771// UIToFPInst Class
1772//===----------------------------------------------------------------------===//
1773
1774/// @brief This class represents a cast unsigned integer to floating point.
1775class UIToFPInst : public CastInst {
1776 UIToFPInst(const UIToFPInst &CI)
1777 : CastInst(CI.getType(), UIToFP, CI.getOperand(0)) {
1778 }
1779public:
1780 /// @brief Constructor with insert-before-instruction semantics
1781 UIToFPInst(
1782 Value *S, ///< The value to be converted
1783 const Type *Ty, ///< The type to convert to
1784 const std::string &Name = "", ///< A name for the new instruction
1785 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1786 );
1787
1788 /// @brief Constructor with insert-at-end-of-block semantics
1789 UIToFPInst(
1790 Value *S, ///< The value to be converted
1791 const Type *Ty, ///< The type to convert to
1792 const std::string &Name, ///< A name for the new instruction
1793 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1794 );
1795
1796 /// @brief Clone an identical UIToFPInst
1797 virtual CastInst *clone() const;
1798
1799 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1800 static inline bool classof(const UIToFPInst *) { return true; }
1801 static inline bool classof(const Instruction *I) {
1802 return I->getOpcode() == UIToFP;
1803 }
1804 static inline bool classof(const Value *V) {
1805 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1806 }
1807};
1808
1809//===----------------------------------------------------------------------===//
1810// SIToFPInst Class
1811//===----------------------------------------------------------------------===//
1812
1813/// @brief This class represents a cast from signed integer to floating point.
1814class SIToFPInst : public CastInst {
1815 SIToFPInst(const SIToFPInst &CI)
1816 : CastInst(CI.getType(), SIToFP, CI.getOperand(0)) {
1817 }
1818public:
1819 /// @brief Constructor with insert-before-instruction semantics
1820 SIToFPInst(
1821 Value *S, ///< The value to be converted
1822 const Type *Ty, ///< The type to convert to
1823 const std::string &Name = "", ///< A name for the new instruction
1824 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1825 );
1826
1827 /// @brief Constructor with insert-at-end-of-block semantics
1828 SIToFPInst(
1829 Value *S, ///< The value to be converted
1830 const Type *Ty, ///< The type to convert to
1831 const std::string &Name, ///< A name for the new instruction
1832 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1833 );
1834
1835 /// @brief Clone an identical SIToFPInst
1836 virtual CastInst *clone() const;
1837
1838 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1839 static inline bool classof(const SIToFPInst *) { return true; }
1840 static inline bool classof(const Instruction *I) {
1841 return I->getOpcode() == SIToFP;
1842 }
1843 static inline bool classof(const Value *V) {
1844 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1845 }
1846};
1847
1848//===----------------------------------------------------------------------===//
1849// FPToUIInst Class
1850//===----------------------------------------------------------------------===//
1851
1852/// @brief This class represents a cast from floating point to unsigned integer
1853class FPToUIInst : public CastInst {
1854 FPToUIInst(const FPToUIInst &CI)
1855 : CastInst(CI.getType(), FPToUI, CI.getOperand(0)) {
1856 }
1857public:
1858 /// @brief Constructor with insert-before-instruction semantics
1859 FPToUIInst(
1860 Value *S, ///< The value to be converted
1861 const Type *Ty, ///< The type to convert to
1862 const std::string &Name = "", ///< A name for the new instruction
1863 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1864 );
1865
1866 /// @brief Constructor with insert-at-end-of-block semantics
1867 FPToUIInst(
1868 Value *S, ///< The value to be converted
1869 const Type *Ty, ///< The type to convert to
1870 const std::string &Name, ///< A name for the new instruction
1871 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
1872 );
1873
1874 /// @brief Clone an identical FPToUIInst
1875 virtual CastInst *clone() const;
1876
1877 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1878 static inline bool classof(const FPToUIInst *) { return true; }
1879 static inline bool classof(const Instruction *I) {
1880 return I->getOpcode() == FPToUI;
1881 }
1882 static inline bool classof(const Value *V) {
1883 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1884 }
1885};
1886
1887//===----------------------------------------------------------------------===//
1888// FPToSIInst Class
1889//===----------------------------------------------------------------------===//
1890
1891/// @brief This class represents a cast from floating point to signed integer.
1892class FPToSIInst : public CastInst {
1893 FPToSIInst(const FPToSIInst &CI)
1894 : CastInst(CI.getType(), FPToSI, CI.getOperand(0)) {
1895 }
1896public:
1897 /// @brief Constructor with insert-before-instruction semantics
1898 FPToSIInst(
1899 Value *S, ///< The value to be converted
1900 const Type *Ty, ///< The type to convert to
1901 const std::string &Name = "", ///< A name for the new instruction
1902 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1903 );
1904
1905 /// @brief Constructor with insert-at-end-of-block semantics
1906 FPToSIInst(
1907 Value *S, ///< The value to be converted
1908 const Type *Ty, ///< The type to convert to
1909 const std::string &Name, ///< A name for the new instruction
1910 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1911 );
1912
1913 /// @brief Clone an identical FPToSIInst
1914 virtual CastInst *clone() const;
1915
1916 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
1917 static inline bool classof(const FPToSIInst *) { return true; }
1918 static inline bool classof(const Instruction *I) {
1919 return I->getOpcode() == FPToSI;
1920 }
1921 static inline bool classof(const Value *V) {
1922 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1923 }
1924};
1925
1926//===----------------------------------------------------------------------===//
1927// IntToPtrInst Class
1928//===----------------------------------------------------------------------===//
1929
1930/// @brief This class represents a cast from an integer to a pointer.
1931class IntToPtrInst : public CastInst {
1932 IntToPtrInst(const IntToPtrInst &CI)
1933 : CastInst(CI.getType(), IntToPtr, CI.getOperand(0)) {
1934 }
1935public:
1936 /// @brief Constructor with insert-before-instruction semantics
1937 IntToPtrInst(
1938 Value *S, ///< The value to be converted
1939 const Type *Ty, ///< The type to convert to
1940 const std::string &Name = "", ///< A name for the new instruction
1941 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1942 );
1943
1944 /// @brief Constructor with insert-at-end-of-block semantics
1945 IntToPtrInst(
1946 Value *S, ///< The value to be converted
1947 const Type *Ty, ///< The type to convert to
1948 const std::string &Name, ///< A name for the new instruction
1949 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1950 );
1951
1952 /// @brief Clone an identical IntToPtrInst
1953 virtual CastInst *clone() const;
1954
1955 // Methods for support type inquiry through isa, cast, and dyn_cast:
1956 static inline bool classof(const IntToPtrInst *) { return true; }
1957 static inline bool classof(const Instruction *I) {
1958 return I->getOpcode() == IntToPtr;
1959 }
1960 static inline bool classof(const Value *V) {
1961 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1962 }
1963};
1964
1965//===----------------------------------------------------------------------===//
1966// PtrToIntInst Class
1967//===----------------------------------------------------------------------===//
1968
1969/// @brief This class represents a cast from a pointer to an integer
1970class PtrToIntInst : public CastInst {
1971 PtrToIntInst(const PtrToIntInst &CI)
1972 : CastInst(CI.getType(), PtrToInt, CI.getOperand(0)) {
1973 }
1974public:
1975 /// @brief Constructor with insert-before-instruction semantics
1976 PtrToIntInst(
1977 Value *S, ///< The value to be converted
1978 const Type *Ty, ///< The type to convert to
1979 const std::string &Name = "", ///< A name for the new instruction
1980 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
1981 );
1982
1983 /// @brief Constructor with insert-at-end-of-block semantics
1984 PtrToIntInst(
1985 Value *S, ///< The value to be converted
1986 const Type *Ty, ///< The type to convert to
1987 const std::string &Name, ///< A name for the new instruction
1988 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
1989 );
1990
1991 /// @brief Clone an identical PtrToIntInst
1992 virtual CastInst *clone() const;
1993
1994 // Methods for support type inquiry through isa, cast, and dyn_cast:
1995 static inline bool classof(const PtrToIntInst *) { return true; }
1996 static inline bool classof(const Instruction *I) {
1997 return I->getOpcode() == PtrToInt;
1998 }
1999 static inline bool classof(const Value *V) {
2000 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2001 }
2002};
2003
2004//===----------------------------------------------------------------------===//
2005// BitCastInst Class
2006//===----------------------------------------------------------------------===//
2007
2008/// @brief This class represents a no-op cast from one type to another.
2009class BitCastInst : public CastInst {
2010 BitCastInst(const BitCastInst &CI)
2011 : CastInst(CI.getType(), BitCast, CI.getOperand(0)) {
2012 }
2013public:
2014 /// @brief Constructor with insert-before-instruction semantics
2015 BitCastInst(
2016 Value *S, ///< The value to be casted
2017 const Type *Ty, ///< The type to casted to
2018 const std::string &Name = "", ///< A name for the new instruction
2019 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
2020 );
2021
2022 /// @brief Constructor with insert-at-end-of-block semantics
2023 BitCastInst(
2024 Value *S, ///< The value to be casted
2025 const Type *Ty, ///< The type to casted to
2026 const std::string &Name, ///< A name for the new instruction
2027 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
2028 );
2029
2030 /// @brief Clone an identical BitCastInst
2031 virtual CastInst *clone() const;
2032
2033 // Methods for support type inquiry through isa, cast, and dyn_cast:
2034 static inline bool classof(const BitCastInst *) { return true; }
2035 static inline bool classof(const Instruction *I) {
2036 return I->getOpcode() == BitCast;
2037 }
2038 static inline bool classof(const Value *V) {
2039 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2040 }
2041};
2042
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00002043} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00002044
2045#endif