blob: 538c31ed1f42002df13b171bcc5611f9a097937f [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/Instruction.h"
20#include "llvm/InstrTypes.h"
21
22namespace llvm {
23
Chris Lattner1fca5ff2004-10-27 16:14:51 +000024class BasicBlock;
Chris Lattnerd1a32602005-02-24 05:32:09 +000025class ConstantInt;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000026class PointerType;
27
28//===----------------------------------------------------------------------===//
29// AllocationInst Class
30//===----------------------------------------------------------------------===//
31
32/// AllocationInst - This class is the common base class of MallocInst and
33/// AllocaInst.
34///
Chris Lattner454928e2005-01-29 00:31:36 +000035class AllocationInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000036protected:
Misha Brukman9769ab22005-04-21 20:19:05 +000037 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
Misha Brukman91102862005-03-16 03:46:55 +000038 const std::string &Name = "", Instruction *InsertBefore = 0);
Misha Brukman9769ab22005-04-21 20:19:05 +000039 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
Misha Brukman91102862005-03-16 03:46:55 +000040 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000041
42public:
43
44 /// isArrayAllocation - Return true if there is an allocation size parameter
45 /// to the allocation instruction that is not 1.
46 ///
47 bool isArrayAllocation() const;
48
49 /// getArraySize - Get the number of element allocated, for a simple
50 /// allocation of a single element, this will return a constant 1 value.
51 ///
Chris Lattner454928e2005-01-29 00:31:36 +000052 inline const Value *getArraySize() const { return getOperand(0); }
53 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000054
55 /// getType - Overload to return most specific pointer type
56 ///
57 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000058 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000059 }
60
61 /// getAllocatedType - Return the type that is being allocated by the
62 /// instruction.
63 ///
64 const Type *getAllocatedType() const;
65
66 virtual Instruction *clone() const = 0;
67
68 // Methods for support type inquiry through isa, cast, and dyn_cast:
69 static inline bool classof(const AllocationInst *) { return true; }
70 static inline bool classof(const Instruction *I) {
71 return I->getOpcode() == Instruction::Alloca ||
72 I->getOpcode() == Instruction::Malloc;
73 }
74 static inline bool classof(const Value *V) {
75 return isa<Instruction>(V) && classof(cast<Instruction>(V));
76 }
77};
78
79
80//===----------------------------------------------------------------------===//
81// MallocInst Class
82//===----------------------------------------------------------------------===//
83
84/// MallocInst - an instruction to allocated memory on the heap
85///
86class MallocInst : public AllocationInst {
87 MallocInst(const MallocInst &MI);
88public:
89 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
90 const std::string &Name = "",
91 Instruction *InsertBefore = 0)
92 : AllocationInst(Ty, ArraySize, Malloc, Name, InsertBefore) {}
93 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
94 BasicBlock *InsertAtEnd)
95 : AllocationInst(Ty, ArraySize, Malloc, Name, InsertAtEnd) {}
96
Chris Lattnerf319e832004-10-15 23:52:05 +000097 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000098
99 // Methods for support type inquiry through isa, cast, and dyn_cast:
100 static inline bool classof(const MallocInst *) { return true; }
101 static inline bool classof(const Instruction *I) {
102 return (I->getOpcode() == Instruction::Malloc);
103 }
104 static inline bool classof(const Value *V) {
105 return isa<Instruction>(V) && classof(cast<Instruction>(V));
106 }
107};
108
109
110//===----------------------------------------------------------------------===//
111// AllocaInst Class
112//===----------------------------------------------------------------------===//
113
114/// AllocaInst - an instruction to allocate memory on the stack
115///
116class AllocaInst : public AllocationInst {
117 AllocaInst(const AllocaInst &);
118public:
119 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
120 const std::string &Name = "",
121 Instruction *InsertBefore = 0)
122 : AllocationInst(Ty, ArraySize, Alloca, Name, InsertBefore) {}
123 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
124 BasicBlock *InsertAtEnd)
125 : AllocationInst(Ty, ArraySize, Alloca, Name, InsertAtEnd) {}
126
Chris Lattnerf319e832004-10-15 23:52:05 +0000127 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000128
129 // Methods for support type inquiry through isa, cast, and dyn_cast:
130 static inline bool classof(const AllocaInst *) { return true; }
131 static inline bool classof(const Instruction *I) {
132 return (I->getOpcode() == Instruction::Alloca);
133 }
134 static inline bool classof(const Value *V) {
135 return isa<Instruction>(V) && classof(cast<Instruction>(V));
136 }
137};
138
139
140//===----------------------------------------------------------------------===//
141// FreeInst Class
142//===----------------------------------------------------------------------===//
143
144/// FreeInst - an instruction to deallocate memory
145///
Chris Lattner454928e2005-01-29 00:31:36 +0000146class FreeInst : public UnaryInstruction {
147 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000148public:
149 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
150 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
151
Chris Lattnerf319e832004-10-15 23:52:05 +0000152 virtual FreeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000153
154 virtual bool mayWriteToMemory() const { return true; }
155
156 // Methods for support type inquiry through isa, cast, and dyn_cast:
157 static inline bool classof(const FreeInst *) { return true; }
158 static inline bool classof(const Instruction *I) {
159 return (I->getOpcode() == Instruction::Free);
160 }
161 static inline bool classof(const Value *V) {
162 return isa<Instruction>(V) && classof(cast<Instruction>(V));
163 }
164};
165
166
167//===----------------------------------------------------------------------===//
168// LoadInst Class
169//===----------------------------------------------------------------------===//
170
Chris Lattner88fe29a2005-02-05 01:44:18 +0000171/// LoadInst - an instruction for reading from memory. This uses the
172/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000173///
Chris Lattner454928e2005-01-29 00:31:36 +0000174class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000175 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000176 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
177 setVolatile(LI.isVolatile());
Misha Brukman9769ab22005-04-21 20:19:05 +0000178
Chris Lattner454928e2005-01-29 00:31:36 +0000179#ifndef NDEBUG
180 AssertOK();
181#endif
182 }
183 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000184public:
185 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
186 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
187 LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
188 Instruction *InsertBefore = 0);
189 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
190 BasicBlock *InsertAtEnd);
191
192 /// isVolatile - Return true if this is a load from a volatile memory
193 /// location.
194 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000195 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000196
197 /// setVolatile - Specify whether this is a volatile load or not.
198 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000199 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000200
Chris Lattnerf319e832004-10-15 23:52:05 +0000201 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000202
203 virtual bool mayWriteToMemory() const { return isVolatile(); }
204
205 Value *getPointerOperand() { return getOperand(0); }
206 const Value *getPointerOperand() const { return getOperand(0); }
207 static unsigned getPointerOperandIndex() { return 0U; }
208
209 // Methods for support type inquiry through isa, cast, and dyn_cast:
210 static inline bool classof(const LoadInst *) { return true; }
211 static inline bool classof(const Instruction *I) {
212 return I->getOpcode() == Instruction::Load;
213 }
214 static inline bool classof(const Value *V) {
215 return isa<Instruction>(V) && classof(cast<Instruction>(V));
216 }
217};
218
219
220//===----------------------------------------------------------------------===//
221// StoreInst Class
222//===----------------------------------------------------------------------===//
223
Misha Brukman9769ab22005-04-21 20:19:05 +0000224/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000225///
226class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000227 Use Ops[2];
Chris Lattner88fe29a2005-02-05 01:44:18 +0000228 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000229 Ops[0].init(SI.Ops[0], this);
230 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000231 setVolatile(SI.isVolatile());
Chris Lattner454928e2005-01-29 00:31:36 +0000232#ifndef NDEBUG
233 AssertOK();
234#endif
235 }
236 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000237public:
238 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
239 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
240 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
241 Instruction *InsertBefore = 0);
242 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
243
244
245 /// isVolatile - Return true if this is a load from a volatile memory
246 /// location.
247 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000248 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000249
250 /// setVolatile - Specify whether this is a volatile load or not.
251 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000252 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000253
Chris Lattner454928e2005-01-29 00:31:36 +0000254 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000255 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000256 assert(i < 2 && "getOperand() out of range!");
257 return Ops[i];
258 }
259 void setOperand(unsigned i, Value *Val) {
260 assert(i < 2 && "setOperand() out of range!");
261 Ops[i] = Val;
262 }
263 unsigned getNumOperands() const { return 2; }
264
265
Chris Lattnerf319e832004-10-15 23:52:05 +0000266 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000267
268 virtual bool mayWriteToMemory() const { return true; }
269
270 Value *getPointerOperand() { return getOperand(1); }
271 const Value *getPointerOperand() const { return getOperand(1); }
272 static unsigned getPointerOperandIndex() { return 1U; }
273
274 // Methods for support type inquiry through isa, cast, and dyn_cast:
275 static inline bool classof(const StoreInst *) { return true; }
276 static inline bool classof(const Instruction *I) {
277 return I->getOpcode() == Instruction::Store;
278 }
279 static inline bool classof(const Value *V) {
280 return isa<Instruction>(V) && classof(cast<Instruction>(V));
281 }
282};
283
284
285//===----------------------------------------------------------------------===//
286// GetElementPtrInst Class
287//===----------------------------------------------------------------------===//
288
289/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
290/// access elements of arrays and structs
291///
292class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000293 GetElementPtrInst(const GetElementPtrInst &GEPI)
294 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
295 0, GEPI.getNumOperands()) {
296 Use *OL = OperandList = new Use[NumOperands];
297 Use *GEPIOL = GEPI.OperandList;
298 for (unsigned i = 0, E = NumOperands; i != E; ++i)
299 OL[i].init(GEPIOL[i], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000300 }
301 void init(Value *Ptr, const std::vector<Value*> &Idx);
302 void init(Value *Ptr, Value *Idx0, Value *Idx1);
Chris Lattner38bacf22005-05-03 05:43:30 +0000303 void init(Value *Ptr, Value *Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000304public:
305 /// Constructors - Create a getelementptr instruction with a base pointer an
306 /// list of indices. The first ctor can optionally insert before an existing
307 /// instruction, the second appends the new instruction to the specified
308 /// BasicBlock.
309 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
Misha Brukman91102862005-03-16 03:46:55 +0000310 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000311 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
Misha Brukman91102862005-03-16 03:46:55 +0000312 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000313
Chris Lattner38bacf22005-05-03 05:43:30 +0000314 /// Constructors - These two constructors are convenience methods because one
315 /// and two index getelementptr instructions are so common.
316 GetElementPtrInst(Value *Ptr, Value *Idx,
317 const std::string &Name = "", Instruction *InsertBefore =0);
318 GetElementPtrInst(Value *Ptr, Value *Idx,
319 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000320 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000321 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000322 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000323 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000324 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000325
Chris Lattnerf319e832004-10-15 23:52:05 +0000326 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000327
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000328 // getType - Overload to return most specific pointer type...
329 inline const PointerType *getType() const {
330 return reinterpret_cast<const PointerType*>(Instruction::getType());
331 }
332
333 /// getIndexedType - Returns the type of the element that would be loaded with
334 /// a load instruction with the specified parameters.
335 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000336 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000337 /// pointer type.
338 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000339 static const Type *getIndexedType(const Type *Ptr,
Misha Brukman91102862005-03-16 03:46:55 +0000340 const std::vector<Value*> &Indices,
341 bool AllowStructLeaf = false);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000342 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000343 bool AllowStructLeaf = false);
Chris Lattner38bacf22005-05-03 05:43:30 +0000344 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000345
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000346 inline op_iterator idx_begin() { return op_begin()+1; }
347 inline const_op_iterator idx_begin() const { return op_begin()+1; }
348 inline op_iterator idx_end() { return op_end(); }
349 inline const_op_iterator idx_end() const { return op_end(); }
350
351 Value *getPointerOperand() {
352 return getOperand(0);
353 }
354 const Value *getPointerOperand() const {
355 return getOperand(0);
356 }
357 static unsigned getPointerOperandIndex() {
358 return 0U; // get index for modifying correct operand
359 }
360
361 inline unsigned getNumIndices() const { // Note: always non-negative
362 return getNumOperands() - 1;
363 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000364
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000365 inline bool hasIndices() const {
366 return getNumOperands() > 1;
367 }
368
369 // Methods for support type inquiry through isa, cast, and dyn_cast:
370 static inline bool classof(const GetElementPtrInst *) { return true; }
371 static inline bool classof(const Instruction *I) {
372 return (I->getOpcode() == Instruction::GetElementPtr);
373 }
374 static inline bool classof(const Value *V) {
375 return isa<Instruction>(V) && classof(cast<Instruction>(V));
376 }
377};
378
379//===----------------------------------------------------------------------===//
380// SetCondInst Class
381//===----------------------------------------------------------------------===//
382
383/// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
384/// le, or ge.
385///
386class SetCondInst : public BinaryOperator {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000387public:
388 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
Misha Brukman91102862005-03-16 03:46:55 +0000389 const std::string &Name = "", Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000390 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
Misha Brukman91102862005-03-16 03:46:55 +0000391 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000392
393 /// getInverseCondition - Return the inverse of the current condition opcode.
394 /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
395 ///
396 BinaryOps getInverseCondition() const {
397 return getInverseCondition(getOpcode());
398 }
399
400 /// getInverseCondition - Static version that you can use without an
401 /// instruction available.
402 ///
403 static BinaryOps getInverseCondition(BinaryOps Opcode);
404
405 /// getSwappedCondition - Return the condition opcode that would be the result
406 /// of exchanging the two operands of the setcc instruction without changing
407 /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
408 ///
409 BinaryOps getSwappedCondition() const {
410 return getSwappedCondition(getOpcode());
411 }
412
413 /// getSwappedCondition - Static version that you can use without an
414 /// instruction available.
415 ///
416 static BinaryOps getSwappedCondition(BinaryOps Opcode);
417
418
419 // Methods for support type inquiry through isa, cast, and dyn_cast:
420 static inline bool classof(const SetCondInst *) { return true; }
421 static inline bool classof(const Instruction *I) {
422 return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
423 I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
424 I->getOpcode() == SetLT || I->getOpcode() == SetGT;
425 }
426 static inline bool classof(const Value *V) {
427 return isa<Instruction>(V) && classof(cast<Instruction>(V));
428 }
429};
430
431//===----------------------------------------------------------------------===//
432// CastInst Class
433//===----------------------------------------------------------------------===//
434
435/// CastInst - This class represents a cast from Operand[0] to the type of
436/// the instruction (i->getType()).
437///
Chris Lattner454928e2005-01-29 00:31:36 +0000438class CastInst : public UnaryInstruction {
Misha Brukman9769ab22005-04-21 20:19:05 +0000439 CastInst(const CastInst &CI)
Chris Lattner454928e2005-01-29 00:31:36 +0000440 : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000441 }
442public:
443 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
444 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000445 : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000446 }
447 CastInst(Value *S, const Type *Ty, const std::string &Name,
448 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000449 : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000450 }
451
Chris Lattnerf319e832004-10-15 23:52:05 +0000452 virtual CastInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000453
454 // Methods for support type inquiry through isa, cast, and dyn_cast:
455 static inline bool classof(const CastInst *) { return true; }
456 static inline bool classof(const Instruction *I) {
457 return I->getOpcode() == Cast;
458 }
459 static inline bool classof(const Value *V) {
460 return isa<Instruction>(V) && classof(cast<Instruction>(V));
461 }
462};
463
464
465//===----------------------------------------------------------------------===//
466// CallInst Class
467//===----------------------------------------------------------------------===//
468
469/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000470/// machine's calling convention. This class uses low bit of the SubClassData
471/// field to indicate whether or not this is a tail call. The rest of the bits
472/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000473///
474class CallInst : public Instruction {
475 CallInst(const CallInst &CI);
476 void init(Value *Func, const std::vector<Value*> &Params);
477 void init(Value *Func, Value *Actual1, Value *Actual2);
478 void init(Value *Func, Value *Actual);
479 void init(Value *Func);
480
481public:
482 CallInst(Value *F, const std::vector<Value*> &Par,
483 const std::string &Name = "", Instruction *InsertBefore = 0);
484 CallInst(Value *F, const std::vector<Value*> &Par,
485 const std::string &Name, BasicBlock *InsertAtEnd);
486
487 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
488 // actuals, respectively.
489 CallInst(Value *F, Value *Actual1, Value *Actual2,
490 const std::string& Name = "", Instruction *InsertBefore = 0);
491 CallInst(Value *F, Value *Actual1, Value *Actual2,
492 const std::string& Name, BasicBlock *InsertAtEnd);
493 CallInst(Value *F, Value *Actual, const std::string& Name = "",
494 Instruction *InsertBefore = 0);
495 CallInst(Value *F, Value *Actual, const std::string& Name,
496 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000497 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000498 Instruction *InsertBefore = 0);
Misha Brukman9769ab22005-04-21 20:19:05 +0000499 explicit CallInst(Value *F, const std::string &Name,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000500 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000501 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000502
Chris Lattnerf319e832004-10-15 23:52:05 +0000503 virtual CallInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000504 bool mayWriteToMemory() const { return true; }
505
Chris Lattner3340ffe2005-05-06 20:26:26 +0000506 bool isTailCall() const { return SubclassData & 1; }
507 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000508 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000509 }
510
511 /// getCallingConv/setCallingConv - Get or set the calling convention of this
512 /// function call.
513 unsigned getCallingConv() const { return SubclassData >> 1; }
514 void setCallingConv(unsigned CC) {
515 SubclassData = (SubclassData & 1) | (CC << 1);
516 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000517
Chris Lattner721aef62004-11-18 17:46:57 +0000518 /// getCalledFunction - Return the function being called by this instruction
519 /// if it is a direct call. If it is a call through a function pointer,
520 /// return null.
521 Function *getCalledFunction() const {
Reid Spenceredd5d9e2005-05-15 16:13:11 +0000522 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
Chris Lattner721aef62004-11-18 17:46:57 +0000523 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000524
525 // getCalledValue - Get a pointer to a method that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +0000526 inline const Value *getCalledValue() const { return getOperand(0); }
527 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000528
529 // Methods for support type inquiry through isa, cast, and dyn_cast:
530 static inline bool classof(const CallInst *) { return true; }
531 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000532 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000533 }
534 static inline bool classof(const Value *V) {
535 return isa<Instruction>(V) && classof(cast<Instruction>(V));
536 }
537};
538
539
540//===----------------------------------------------------------------------===//
541// ShiftInst Class
542//===----------------------------------------------------------------------===//
543
544/// ShiftInst - This class represents left and right shift instructions.
545///
546class ShiftInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000547 Use Ops[2];
548 ShiftInst(const ShiftInst &SI)
549 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
550 Ops[0].init(SI.Ops[0], this);
551 Ops[1].init(SI.Ops[1], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000552 }
553 void init(OtherOps Opcode, Value *S, Value *SA) {
554 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
Chris Lattner454928e2005-01-29 00:31:36 +0000555 Ops[0].init(S, this);
556 Ops[1].init(SA, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000557 }
558
559public:
560 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
561 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000562 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000563 init(Opcode, S, SA);
564 }
565 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
566 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000567 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000568 init(Opcode, S, SA);
569 }
570
571 OtherOps getOpcode() const {
572 return static_cast<OtherOps>(Instruction::getOpcode());
573 }
574
Chris Lattner454928e2005-01-29 00:31:36 +0000575 /// Transparently provide more efficient getOperand methods.
576 Value *getOperand(unsigned i) const {
577 assert(i < 2 && "getOperand() out of range!");
578 return Ops[i];
579 }
580 void setOperand(unsigned i, Value *Val) {
581 assert(i < 2 && "setOperand() out of range!");
582 Ops[i] = Val;
583 }
584 unsigned getNumOperands() const { return 2; }
585
Chris Lattnerf319e832004-10-15 23:52:05 +0000586 virtual ShiftInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000587
588 // Methods for support type inquiry through isa, cast, and dyn_cast:
589 static inline bool classof(const ShiftInst *) { return true; }
590 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000591 return (I->getOpcode() == Instruction::Shr) |
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000592 (I->getOpcode() == Instruction::Shl);
593 }
594 static inline bool classof(const Value *V) {
595 return isa<Instruction>(V) && classof(cast<Instruction>(V));
596 }
597};
598
599//===----------------------------------------------------------------------===//
600// SelectInst Class
601//===----------------------------------------------------------------------===//
602
603/// SelectInst - This class represents the LLVM 'select' instruction.
604///
605class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000606 Use Ops[3];
607
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000608 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000609 Ops[0].init(C, this);
610 Ops[1].init(S1, this);
611 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000612 }
613
Chris Lattner454928e2005-01-29 00:31:36 +0000614 SelectInst(const SelectInst &SI)
615 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
616 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
617 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000618public:
619 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
620 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000621 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
622 Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000623 init(C, S1, S2);
624 }
625 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
626 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000627 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
628 Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000629 init(C, S1, S2);
630 }
631
Chris Lattner454928e2005-01-29 00:31:36 +0000632 Value *getCondition() const { return Ops[0]; }
633 Value *getTrueValue() const { return Ops[1]; }
634 Value *getFalseValue() const { return Ops[2]; }
635
636 /// Transparently provide more efficient getOperand methods.
637 Value *getOperand(unsigned i) const {
638 assert(i < 3 && "getOperand() out of range!");
639 return Ops[i];
640 }
641 void setOperand(unsigned i, Value *Val) {
642 assert(i < 3 && "setOperand() out of range!");
643 Ops[i] = Val;
644 }
645 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000646
647 OtherOps getOpcode() const {
648 return static_cast<OtherOps>(Instruction::getOpcode());
649 }
650
Chris Lattnerf319e832004-10-15 23:52:05 +0000651 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000652
653 // Methods for support type inquiry through isa, cast, and dyn_cast:
654 static inline bool classof(const SelectInst *) { return true; }
655 static inline bool classof(const Instruction *I) {
656 return I->getOpcode() == Instruction::Select;
657 }
658 static inline bool classof(const Value *V) {
659 return isa<Instruction>(V) && classof(cast<Instruction>(V));
660 }
661};
662
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000663//===----------------------------------------------------------------------===//
664// VAArgInst Class
665//===----------------------------------------------------------------------===//
666
667/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +0000668/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000669///
Chris Lattner454928e2005-01-29 00:31:36 +0000670class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000671 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +0000672 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000673public:
674 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
675 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000676 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000677 }
678 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
679 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000680 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000681 }
682
Chris Lattnerf319e832004-10-15 23:52:05 +0000683 virtual VAArgInst *clone() const;
Andrew Lenharthc64b64a2005-06-19 14:46:20 +0000684 bool mayWriteToMemory() const { return true; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000685
686 // Methods for support type inquiry through isa, cast, and dyn_cast:
687 static inline bool classof(const VAArgInst *) { return true; }
688 static inline bool classof(const Instruction *I) {
689 return I->getOpcode() == VAArg;
690 }
691 static inline bool classof(const Value *V) {
692 return isa<Instruction>(V) && classof(cast<Instruction>(V));
693 }
694};
695
696//===----------------------------------------------------------------------===//
697// PHINode Class
698//===----------------------------------------------------------------------===//
699
700// PHINode - The PHINode class is used to represent the magical mystical PHI
701// node, that can not exist in nature, but can be synthesized in a computer
702// scientist's overactive imagination.
703//
704class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000705 /// ReservedSpace - The number of operands actually allocated. NumOperands is
706 /// the number actually in use.
707 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000708 PHINode(const PHINode &PN);
709public:
710 PHINode(const Type *Ty, const std::string &Name = "",
711 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000712 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
713 ReservedSpace(0) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000714 }
715
716 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000717 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
718 ReservedSpace(0) {
719 }
720
721 ~PHINode();
722
723 /// reserveOperandSpace - This method can be used to avoid repeated
724 /// reallocation of PHI operand lists by reserving space for the correct
725 /// number of operands before adding them. Unlike normal vector reserves,
726 /// this method can also be used to trim the operand space.
727 void reserveOperandSpace(unsigned NumValues) {
728 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000729 }
730
Chris Lattnerf319e832004-10-15 23:52:05 +0000731 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000732
733 /// getNumIncomingValues - Return the number of incoming edges
734 ///
Chris Lattner454928e2005-01-29 00:31:36 +0000735 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000736
737 /// getIncomingValue - Return incoming value #x
738 ///
739 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000740 assert(i*2 < getNumOperands() && "Invalid value number!");
741 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000742 }
743 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +0000744 assert(i*2 < getNumOperands() && "Invalid value number!");
745 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000746 }
Chris Lattner454928e2005-01-29 00:31:36 +0000747 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000748 return i*2;
749 }
750
751 /// getIncomingBlock - Return incoming basic block #x
752 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000753 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000754 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000755 }
756 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +0000757 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000758 }
759 unsigned getOperandNumForIncomingBlock(unsigned i) {
760 return i*2+1;
761 }
762
763 /// addIncoming - Add an incoming value to the end of the PHI list
764 ///
765 void addIncoming(Value *V, BasicBlock *BB) {
766 assert(getType() == V->getType() &&
767 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +0000768 unsigned OpNo = NumOperands;
769 if (OpNo+2 > ReservedSpace)
770 resizeOperands(0); // Get more space!
771 // Initialize some new operands.
772 NumOperands = OpNo+2;
773 OperandList[OpNo].init(V, this);
774 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000775 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000776
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000777 /// removeIncomingValue - Remove an incoming value. This is useful if a
778 /// predecessor basic block is deleted. The value removed is returned.
779 ///
780 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
781 /// is true), the PHI node is destroyed and any uses of it are replaced with
782 /// dummy values. The only time there should be zero incoming values to a PHI
783 /// node is when the block is dead, so this strategy is sound.
784 ///
785 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
786
787 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
788 int Idx = getBasicBlockIndex(BB);
789 assert(Idx >= 0 && "Invalid basic block argument to remove!");
790 return removeIncomingValue(Idx, DeletePHIIfEmpty);
791 }
792
Misha Brukman9769ab22005-04-21 20:19:05 +0000793 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000794 /// block in the value list for this PHI. Returns -1 if no instance.
795 ///
796 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000797 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +0000798 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +0000799 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000800 return -1;
801 }
802
803 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
804 return getIncomingValue(getBasicBlockIndex(BB));
805 }
806
Nate Begemana83ba0f2005-08-04 23:24:19 +0000807 /// hasConstantValue - If the specified PHI node always merges together the
808 /// same value, return the value, otherwise return null.
809 ///
Chris Lattner9acbd612005-08-05 00:49:06 +0000810 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Nate Begemana83ba0f2005-08-04 23:24:19 +0000811
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000812 /// Methods for support type inquiry through isa, cast, and dyn_cast:
813 static inline bool classof(const PHINode *) { return true; }
814 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000815 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000816 }
817 static inline bool classof(const Value *V) {
818 return isa<Instruction>(V) && classof(cast<Instruction>(V));
819 }
Chris Lattner454928e2005-01-29 00:31:36 +0000820 private:
821 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000822};
823
824//===----------------------------------------------------------------------===//
825// ReturnInst Class
826//===----------------------------------------------------------------------===//
827
828//===---------------------------------------------------------------------------
829/// ReturnInst - Return a value (possibly void), from a function. Execution
830/// does not continue in this function any longer.
831///
832class ReturnInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +0000833 Use RetVal; // Possibly null retval.
834 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
835 RI.getNumOperands()) {
836 if (RI.getNumOperands())
837 RetVal.init(RI.RetVal, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000838 }
839
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000840 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000841
842public:
843 // ReturnInst constructors:
844 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000845 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000846 // ReturnInst(Value* X) - 'ret X' instruction
847 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
848 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
849 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
850 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000851 //
852 // NOTE: If the Value* passed is of type void then the constructor behaves as
853 // if it was passed NULL.
Chris Lattner454928e2005-01-29 00:31:36 +0000854 ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
855 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
856 init(retVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000857 }
Chris Lattner454928e2005-01-29 00:31:36 +0000858 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
859 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
860 init(retVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000861 }
862 ReturnInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000863 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000864 }
865
Chris Lattnerf319e832004-10-15 23:52:05 +0000866 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000867
Chris Lattner454928e2005-01-29 00:31:36 +0000868 // Transparently provide more efficient getOperand methods.
869 Value *getOperand(unsigned i) const {
870 assert(i < getNumOperands() && "getOperand() out of range!");
871 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000872 }
Chris Lattner454928e2005-01-29 00:31:36 +0000873 void setOperand(unsigned i, Value *Val) {
874 assert(i < getNumOperands() && "setOperand() out of range!");
875 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000876 }
877
Chris Lattner454928e2005-01-29 00:31:36 +0000878 Value *getReturnValue() const { return RetVal; }
879
880 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000881
882 // Methods for support type inquiry through isa, cast, and dyn_cast:
883 static inline bool classof(const ReturnInst *) { return true; }
884 static inline bool classof(const Instruction *I) {
885 return (I->getOpcode() == Instruction::Ret);
886 }
887 static inline bool classof(const Value *V) {
888 return isa<Instruction>(V) && classof(cast<Instruction>(V));
889 }
Chris Lattner454928e2005-01-29 00:31:36 +0000890 private:
891 virtual BasicBlock *getSuccessorV(unsigned idx) const;
892 virtual unsigned getNumSuccessorsV() const;
893 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000894};
895
896//===----------------------------------------------------------------------===//
897// BranchInst Class
898//===----------------------------------------------------------------------===//
899
900//===---------------------------------------------------------------------------
901/// BranchInst - Conditional or Unconditional Branch instruction.
902///
903class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +0000904 /// Ops list - Branches are strange. The operands are ordered:
905 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
906 /// they don't have to check for cond/uncond branchness.
907 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000908 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +0000909 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000910public:
911 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
912 // BranchInst(BB *B) - 'br B'
913 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
914 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
915 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
916 // BranchInst(BB* B, BB *I) - 'br B' insert at end
917 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
918 BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000919 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
920 assert(IfTrue != 0 && "Branch destination may not be null!");
921 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000922 }
923 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
924 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000925 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
926 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
927 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
928 Ops[2].init(Cond, this);
929#ifndef NDEBUG
930 AssertOK();
931#endif
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000932 }
933
934 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000935 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
936 assert(IfTrue != 0 && "Branch destination may not be null!");
937 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000938 }
939
940 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
941 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000942 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
943 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
944 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
945 Ops[2].init(Cond, this);
946#ifndef NDEBUG
947 AssertOK();
948#endif
949 }
950
951
952 /// Transparently provide more efficient getOperand methods.
953 Value *getOperand(unsigned i) const {
954 assert(i < getNumOperands() && "getOperand() out of range!");
955 return Ops[i];
956 }
957 void setOperand(unsigned i, Value *Val) {
958 assert(i < getNumOperands() && "setOperand() out of range!");
959 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000960 }
961
Chris Lattnerf319e832004-10-15 23:52:05 +0000962 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000963
Chris Lattner454928e2005-01-29 00:31:36 +0000964 inline bool isUnconditional() const { return getNumOperands() == 1; }
965 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000966
967 inline Value *getCondition() const {
968 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +0000969 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000970 }
971
972 void setCondition(Value *V) {
973 assert(isConditional() && "Cannot set condition of unconditional branch!");
974 setOperand(2, V);
975 }
976
977 // setUnconditionalDest - Change the current branch to an unconditional branch
978 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +0000979 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000980 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +0000981 if (isConditional()) { // Convert this to an uncond branch.
982 NumOperands = 1;
983 Ops[1].set(0);
984 Ops[2].set(0);
985 }
986 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000987 }
988
Chris Lattner454928e2005-01-29 00:31:36 +0000989 unsigned getNumSuccessors() const { return 1+isConditional(); }
990
991 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000992 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Misha Brukman9769ab22005-04-21 20:19:05 +0000993 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
Chris Lattner454928e2005-01-29 00:31:36 +0000994 cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000995 }
996
Chris Lattner454928e2005-01-29 00:31:36 +0000997 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000998 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +0000999 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001000 }
1001
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001002 // Methods for support type inquiry through isa, cast, and dyn_cast:
1003 static inline bool classof(const BranchInst *) { return true; }
1004 static inline bool classof(const Instruction *I) {
1005 return (I->getOpcode() == Instruction::Br);
1006 }
1007 static inline bool classof(const Value *V) {
1008 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1009 }
Chris Lattner454928e2005-01-29 00:31:36 +00001010private:
1011 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1012 virtual unsigned getNumSuccessorsV() const;
1013 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001014};
1015
1016//===----------------------------------------------------------------------===//
1017// SwitchInst Class
1018//===----------------------------------------------------------------------===//
1019
1020//===---------------------------------------------------------------------------
1021/// SwitchInst - Multiway switch
1022///
1023class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001024 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001025 // Operand[0] = Value to switch on
1026 // Operand[1] = Default basic block destination
1027 // Operand[2n ] = Value to match
1028 // Operand[2n+1] = BasicBlock to go to on match
1029 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001030 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1031 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001032public:
Chris Lattner454928e2005-01-29 00:31:36 +00001033 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1034 /// switch on and a default destination. The number of additional cases can
1035 /// be specified here to make memory allocation more efficient. This
1036 /// constructor can also autoinsert before another instruction.
1037 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Misha Brukman9769ab22005-04-21 20:19:05 +00001038 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001039 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1040 init(Value, Default, NumCases);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001041 }
1042
Chris Lattner454928e2005-01-29 00:31:36 +00001043 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1044 /// switch on and a default destination. The number of additional cases can
1045 /// be specified here to make memory allocation more efficient. This
1046 /// constructor also autoinserts at the end of the specified BasicBlock.
1047 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Misha Brukman9769ab22005-04-21 20:19:05 +00001048 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001049 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1050 init(Value, Default, NumCases);
1051 }
1052 ~SwitchInst();
1053
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001054
1055 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001056 inline Value *getCondition() const { return getOperand(0); }
1057 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001058
Chris Lattner454928e2005-01-29 00:31:36 +00001059 inline BasicBlock *getDefaultDest() const {
1060 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001061 }
1062
1063 /// getNumCases - return the number of 'cases' in this switch instruction.
1064 /// Note that case #0 is always the default case.
1065 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001066 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001067 }
1068
1069 /// getCaseValue - Return the specified case value. Note that case #0, the
1070 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001071 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001072 assert(i && i < getNumCases() && "Illegal case value to get!");
1073 return getSuccessorValue(i);
1074 }
1075
1076 /// getCaseValue - Return the specified case value. Note that case #0, the
1077 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001078 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001079 assert(i && i < getNumCases() && "Illegal case value to get!");
1080 return getSuccessorValue(i);
1081 }
1082
1083 /// findCaseValue - Search all of the case values for the specified constant.
1084 /// If it is explicitly handled, return the case number of it, otherwise
1085 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001086 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001087 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1088 if (getCaseValue(i) == C)
1089 return i;
1090 return 0;
1091 }
1092
1093 /// addCase - Add an entry to the switch instruction...
1094 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001095 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001096
1097 /// removeCase - This method removes the specified successor from the switch
1098 /// instruction. Note that this cannot be used to remove the default
1099 /// destination (successor #0).
1100 ///
1101 void removeCase(unsigned idx);
1102
Chris Lattner454928e2005-01-29 00:31:36 +00001103 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001104
Chris Lattner454928e2005-01-29 00:31:36 +00001105 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1106 BasicBlock *getSuccessor(unsigned idx) const {
1107 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1108 return cast<BasicBlock>(getOperand(idx*2+1));
1109 }
1110 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001111 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001112 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001113 }
1114
1115 // getSuccessorValue - Return the value associated with the specified
1116 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001117 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001118 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001119 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001120 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001121
1122 // Methods for support type inquiry through isa, cast, and dyn_cast:
1123 static inline bool classof(const SwitchInst *) { return true; }
1124 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001125 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001126 }
1127 static inline bool classof(const Value *V) {
1128 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1129 }
Chris Lattner454928e2005-01-29 00:31:36 +00001130private:
1131 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1132 virtual unsigned getNumSuccessorsV() const;
1133 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001134};
1135
1136//===----------------------------------------------------------------------===//
1137// InvokeInst Class
1138//===----------------------------------------------------------------------===//
1139
1140//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001141
1142/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1143/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001144///
1145class InvokeInst : public TerminatorInst {
1146 InvokeInst(const InvokeInst &BI);
1147 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1148 const std::vector<Value*> &Params);
1149public:
1150 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Misha Brukman91102862005-03-16 03:46:55 +00001151 const std::vector<Value*> &Params, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001152 Instruction *InsertBefore = 0);
1153 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Misha Brukman91102862005-03-16 03:46:55 +00001154 const std::vector<Value*> &Params, const std::string &Name,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001155 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001156 ~InvokeInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001157
Chris Lattnerf319e832004-10-15 23:52:05 +00001158 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001159
1160 bool mayWriteToMemory() const { return true; }
1161
Chris Lattner3340ffe2005-05-06 20:26:26 +00001162 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1163 /// function call.
1164 unsigned getCallingConv() const { return SubclassData; }
1165 void setCallingConv(unsigned CC) {
1166 SubclassData = CC;
1167 }
1168
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001169 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001170 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001171 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001172 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001173 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001174 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001175
1176 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001177 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001178
1179 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001180 BasicBlock *getNormalDest() const {
1181 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001182 }
Chris Lattner454928e2005-01-29 00:31:36 +00001183 BasicBlock *getUnwindDest() const {
1184 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001185 }
Chris Lattner454928e2005-01-29 00:31:36 +00001186 void setNormalDest(BasicBlock *B) {
1187 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001188 }
1189
Chris Lattner454928e2005-01-29 00:31:36 +00001190 void setUnwindDest(BasicBlock *B) {
1191 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001192 }
1193
Chris Lattner454928e2005-01-29 00:31:36 +00001194 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001195 assert(i < 2 && "Successor # out of range for invoke!");
1196 return i == 0 ? getNormalDest() : getUnwindDest();
1197 }
1198
Chris Lattner454928e2005-01-29 00:31:36 +00001199 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001200 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001201 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001202 }
1203
Chris Lattner454928e2005-01-29 00:31:36 +00001204 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001205
1206 // Methods for support type inquiry through isa, cast, and dyn_cast:
1207 static inline bool classof(const InvokeInst *) { return true; }
1208 static inline bool classof(const Instruction *I) {
1209 return (I->getOpcode() == Instruction::Invoke);
1210 }
1211 static inline bool classof(const Value *V) {
1212 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1213 }
Chris Lattner454928e2005-01-29 00:31:36 +00001214private:
1215 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1216 virtual unsigned getNumSuccessorsV() const;
1217 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001218};
1219
1220
1221//===----------------------------------------------------------------------===//
1222// UnwindInst Class
1223//===----------------------------------------------------------------------===//
1224
1225//===---------------------------------------------------------------------------
1226/// UnwindInst - Immediately exit the current function, unwinding the stack
1227/// until an invoke instruction is found.
1228///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001229class UnwindInst : public TerminatorInst {
1230public:
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001231 UnwindInst(Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001232 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001233 }
1234 UnwindInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001235 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001236 }
1237
Chris Lattnerf319e832004-10-15 23:52:05 +00001238 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001239
Chris Lattner454928e2005-01-29 00:31:36 +00001240 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001241
1242 // Methods for support type inquiry through isa, cast, and dyn_cast:
1243 static inline bool classof(const UnwindInst *) { return true; }
1244 static inline bool classof(const Instruction *I) {
1245 return I->getOpcode() == Instruction::Unwind;
1246 }
1247 static inline bool classof(const Value *V) {
1248 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1249 }
Chris Lattner454928e2005-01-29 00:31:36 +00001250private:
1251 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1252 virtual unsigned getNumSuccessorsV() const;
1253 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001254};
1255
Chris Lattner076b3f12004-10-16 18:05:54 +00001256//===----------------------------------------------------------------------===//
1257// UnreachableInst Class
1258//===----------------------------------------------------------------------===//
1259
1260//===---------------------------------------------------------------------------
1261/// UnreachableInst - This function has undefined behavior. In particular, the
1262/// presence of this instruction indicates some higher level knowledge that the
1263/// end of the block cannot be reached.
1264///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001265class UnreachableInst : public TerminatorInst {
1266public:
Chris Lattner076b3f12004-10-16 18:05:54 +00001267 UnreachableInst(Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001268 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
Chris Lattner076b3f12004-10-16 18:05:54 +00001269 }
1270 UnreachableInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001271 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
Chris Lattner076b3f12004-10-16 18:05:54 +00001272 }
1273
1274 virtual UnreachableInst *clone() const;
1275
Chris Lattner454928e2005-01-29 00:31:36 +00001276 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001277
1278 // Methods for support type inquiry through isa, cast, and dyn_cast:
1279 static inline bool classof(const UnreachableInst *) { return true; }
1280 static inline bool classof(const Instruction *I) {
1281 return I->getOpcode() == Instruction::Unreachable;
1282 }
1283 static inline bool classof(const Value *V) {
1284 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1285 }
Chris Lattner454928e2005-01-29 00:31:36 +00001286private:
1287 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1288 virtual unsigned getNumSuccessorsV() const;
1289 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001290};
1291
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001292} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00001293
1294#endif