blob: e6c3ca9fe917f36c6f0817f0c01ef6742f4effc5 [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 {
Nate Begeman14b05292005-11-05 09:21:28 +000036 unsigned Alignment;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000037protected:
Nate Begeman14b05292005-11-05 09:21:28 +000038 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000039 const std::string &Name = "", Instruction *InsertBefore = 0);
Nate Begeman14b05292005-11-05 09:21:28 +000040 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
Misha Brukman91102862005-03-16 03:46:55 +000041 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000042
43public:
44
45 /// isArrayAllocation - Return true if there is an allocation size parameter
46 /// to the allocation instruction that is not 1.
47 ///
48 bool isArrayAllocation() const;
49
50 /// getArraySize - Get the number of element allocated, for a simple
51 /// allocation of a single element, this will return a constant 1 value.
52 ///
Chris Lattner454928e2005-01-29 00:31:36 +000053 inline const Value *getArraySize() const { return getOperand(0); }
54 inline Value *getArraySize() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000055
56 /// getType - Overload to return most specific pointer type
57 ///
58 inline const PointerType *getType() const {
Misha Brukman9769ab22005-04-21 20:19:05 +000059 return reinterpret_cast<const PointerType*>(Instruction::getType());
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000060 }
61
62 /// getAllocatedType - Return the type that is being allocated by the
63 /// instruction.
64 ///
65 const Type *getAllocatedType() const;
66
Nate Begeman14b05292005-11-05 09:21:28 +000067 /// getAlignment - Return the alignment of the memory that is being allocated
68 /// by the instruction.
69 ///
70 unsigned getAlignment() const { return Alignment; }
71
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000072 virtual Instruction *clone() const = 0;
73
74 // Methods for support type inquiry through isa, cast, and dyn_cast:
75 static inline bool classof(const AllocationInst *) { return true; }
76 static inline bool classof(const Instruction *I) {
77 return I->getOpcode() == Instruction::Alloca ||
78 I->getOpcode() == Instruction::Malloc;
79 }
80 static inline bool classof(const Value *V) {
81 return isa<Instruction>(V) && classof(cast<Instruction>(V));
82 }
83};
84
85
86//===----------------------------------------------------------------------===//
87// MallocInst Class
88//===----------------------------------------------------------------------===//
89
90/// MallocInst - an instruction to allocated memory on the heap
91///
92class MallocInst : public AllocationInst {
93 MallocInst(const MallocInst &MI);
94public:
95 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
96 const std::string &Name = "",
97 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +000098 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +000099 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
100 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000101 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
102 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
103 const std::string &Name, BasicBlock *InsertAtEnd)
104 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
105 explicit MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
106 const std::string &Name = "",
107 Instruction *InsertBefore = 0)
108 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
109
Chris Lattnerf319e832004-10-15 23:52:05 +0000110 virtual MallocInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000111
112 // Methods for support type inquiry through isa, cast, and dyn_cast:
113 static inline bool classof(const MallocInst *) { return true; }
114 static inline bool classof(const Instruction *I) {
115 return (I->getOpcode() == Instruction::Malloc);
116 }
117 static inline bool classof(const Value *V) {
118 return isa<Instruction>(V) && classof(cast<Instruction>(V));
119 }
120};
121
122
123//===----------------------------------------------------------------------===//
124// AllocaInst Class
125//===----------------------------------------------------------------------===//
126
127/// AllocaInst - an instruction to allocate memory on the stack
128///
129class AllocaInst : public AllocationInst {
130 AllocaInst(const AllocaInst &);
131public:
132 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
133 const std::string &Name = "",
134 Instruction *InsertBefore = 0)
Nate Begeman14b05292005-11-05 09:21:28 +0000135 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000136 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
137 BasicBlock *InsertAtEnd)
Nate Begeman14b05292005-11-05 09:21:28 +0000138 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
139 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
140 const std::string &Name, BasicBlock *InsertAtEnd)
141 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
142 explicit AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
143 const std::string &Name = "",
144 Instruction *InsertBefore = 0)
145 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
146
Chris Lattnerf319e832004-10-15 23:52:05 +0000147 virtual AllocaInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000148
149 // Methods for support type inquiry through isa, cast, and dyn_cast:
150 static inline bool classof(const AllocaInst *) { return true; }
151 static inline bool classof(const Instruction *I) {
152 return (I->getOpcode() == Instruction::Alloca);
153 }
154 static inline bool classof(const Value *V) {
155 return isa<Instruction>(V) && classof(cast<Instruction>(V));
156 }
157};
158
159
160//===----------------------------------------------------------------------===//
161// FreeInst Class
162//===----------------------------------------------------------------------===//
163
164/// FreeInst - an instruction to deallocate memory
165///
Chris Lattner454928e2005-01-29 00:31:36 +0000166class FreeInst : public UnaryInstruction {
167 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000168public:
169 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
170 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
171
Chris Lattnerf319e832004-10-15 23:52:05 +0000172 virtual FreeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000173
174 virtual bool mayWriteToMemory() const { return true; }
175
176 // Methods for support type inquiry through isa, cast, and dyn_cast:
177 static inline bool classof(const FreeInst *) { return true; }
178 static inline bool classof(const Instruction *I) {
179 return (I->getOpcode() == Instruction::Free);
180 }
181 static inline bool classof(const Value *V) {
182 return isa<Instruction>(V) && classof(cast<Instruction>(V));
183 }
184};
185
186
187//===----------------------------------------------------------------------===//
188// LoadInst Class
189//===----------------------------------------------------------------------===//
190
Chris Lattner88fe29a2005-02-05 01:44:18 +0000191/// LoadInst - an instruction for reading from memory. This uses the
192/// SubclassData field in Value to store whether or not the load is volatile.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000193///
Chris Lattner454928e2005-01-29 00:31:36 +0000194class LoadInst : public UnaryInstruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000195 LoadInst(const LoadInst &LI)
Chris Lattner88fe29a2005-02-05 01:44:18 +0000196 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
197 setVolatile(LI.isVolatile());
Misha Brukman9769ab22005-04-21 20:19:05 +0000198
Chris Lattner454928e2005-01-29 00:31:36 +0000199#ifndef NDEBUG
200 AssertOK();
201#endif
202 }
203 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000204public:
205 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
206 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
207 LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
208 Instruction *InsertBefore = 0);
209 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
210 BasicBlock *InsertAtEnd);
211
212 /// isVolatile - Return true if this is a load from a volatile memory
213 /// location.
214 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000215 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000216
217 /// setVolatile - Specify whether this is a volatile load or not.
218 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000219 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000220
Chris Lattnerf319e832004-10-15 23:52:05 +0000221 virtual LoadInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000222
223 virtual bool mayWriteToMemory() const { return isVolatile(); }
224
225 Value *getPointerOperand() { return getOperand(0); }
226 const Value *getPointerOperand() const { return getOperand(0); }
227 static unsigned getPointerOperandIndex() { return 0U; }
228
229 // Methods for support type inquiry through isa, cast, and dyn_cast:
230 static inline bool classof(const LoadInst *) { return true; }
231 static inline bool classof(const Instruction *I) {
232 return I->getOpcode() == Instruction::Load;
233 }
234 static inline bool classof(const Value *V) {
235 return isa<Instruction>(V) && classof(cast<Instruction>(V));
236 }
237};
238
239
240//===----------------------------------------------------------------------===//
241// StoreInst Class
242//===----------------------------------------------------------------------===//
243
Misha Brukman9769ab22005-04-21 20:19:05 +0000244/// StoreInst - an instruction for storing to memory
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000245///
246class StoreInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000247 Use Ops[2];
Chris Lattner88fe29a2005-02-05 01:44:18 +0000248 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000249 Ops[0].init(SI.Ops[0], this);
250 Ops[1].init(SI.Ops[1], this);
Chris Lattner88fe29a2005-02-05 01:44:18 +0000251 setVolatile(SI.isVolatile());
Chris Lattner454928e2005-01-29 00:31:36 +0000252#ifndef NDEBUG
253 AssertOK();
254#endif
255 }
256 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000257public:
258 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
259 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
260 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
261 Instruction *InsertBefore = 0);
262 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
263
264
265 /// isVolatile - Return true if this is a load from a volatile memory
266 /// location.
267 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000268 bool isVolatile() const { return SubclassData; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000269
270 /// setVolatile - Specify whether this is a volatile load or not.
271 ///
Chris Lattner88fe29a2005-02-05 01:44:18 +0000272 void setVolatile(bool V) { SubclassData = V; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000273
Chris Lattner454928e2005-01-29 00:31:36 +0000274 /// Transparently provide more efficient getOperand methods.
Misha Brukman9769ab22005-04-21 20:19:05 +0000275 Value *getOperand(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000276 assert(i < 2 && "getOperand() out of range!");
277 return Ops[i];
278 }
279 void setOperand(unsigned i, Value *Val) {
280 assert(i < 2 && "setOperand() out of range!");
281 Ops[i] = Val;
282 }
283 unsigned getNumOperands() const { return 2; }
284
285
Chris Lattnerf319e832004-10-15 23:52:05 +0000286 virtual StoreInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000287
288 virtual bool mayWriteToMemory() const { return true; }
289
290 Value *getPointerOperand() { return getOperand(1); }
291 const Value *getPointerOperand() const { return getOperand(1); }
292 static unsigned getPointerOperandIndex() { return 1U; }
293
294 // Methods for support type inquiry through isa, cast, and dyn_cast:
295 static inline bool classof(const StoreInst *) { return true; }
296 static inline bool classof(const Instruction *I) {
297 return I->getOpcode() == Instruction::Store;
298 }
299 static inline bool classof(const Value *V) {
300 return isa<Instruction>(V) && classof(cast<Instruction>(V));
301 }
302};
303
304
305//===----------------------------------------------------------------------===//
306// GetElementPtrInst Class
307//===----------------------------------------------------------------------===//
308
309/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
310/// access elements of arrays and structs
311///
312class GetElementPtrInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000313 GetElementPtrInst(const GetElementPtrInst &GEPI)
314 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
315 0, GEPI.getNumOperands()) {
316 Use *OL = OperandList = new Use[NumOperands];
317 Use *GEPIOL = GEPI.OperandList;
318 for (unsigned i = 0, E = NumOperands; i != E; ++i)
319 OL[i].init(GEPIOL[i], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000320 }
321 void init(Value *Ptr, const std::vector<Value*> &Idx);
322 void init(Value *Ptr, Value *Idx0, Value *Idx1);
Chris Lattner38bacf22005-05-03 05:43:30 +0000323 void init(Value *Ptr, Value *Idx);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000324public:
325 /// Constructors - Create a getelementptr instruction with a base pointer an
326 /// list of indices. The first ctor can optionally insert before an existing
327 /// instruction, the second appends the new instruction to the specified
328 /// BasicBlock.
329 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
Misha Brukman91102862005-03-16 03:46:55 +0000330 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000331 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
Misha Brukman91102862005-03-16 03:46:55 +0000332 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000333
Chris Lattner38bacf22005-05-03 05:43:30 +0000334 /// Constructors - These two constructors are convenience methods because one
335 /// and two index getelementptr instructions are so common.
336 GetElementPtrInst(Value *Ptr, Value *Idx,
337 const std::string &Name = "", Instruction *InsertBefore =0);
338 GetElementPtrInst(Value *Ptr, Value *Idx,
339 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000340 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000341 const std::string &Name = "", Instruction *InsertBefore =0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000342 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000343 const std::string &Name, BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000344 ~GetElementPtrInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000345
Chris Lattnerf319e832004-10-15 23:52:05 +0000346 virtual GetElementPtrInst *clone() const;
Misha Brukman9769ab22005-04-21 20:19:05 +0000347
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000348 // getType - Overload to return most specific pointer type...
349 inline const PointerType *getType() const {
350 return reinterpret_cast<const PointerType*>(Instruction::getType());
351 }
352
353 /// getIndexedType - Returns the type of the element that would be loaded with
354 /// a load instruction with the specified parameters.
355 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000356 /// A null type is returned if the indices are invalid for the specified
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000357 /// pointer type.
358 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000359 static const Type *getIndexedType(const Type *Ptr,
Misha Brukman91102862005-03-16 03:46:55 +0000360 const std::vector<Value*> &Indices,
361 bool AllowStructLeaf = false);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000362 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
Misha Brukman91102862005-03-16 03:46:55 +0000363 bool AllowStructLeaf = false);
Chris Lattner38bacf22005-05-03 05:43:30 +0000364 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
Misha Brukman9769ab22005-04-21 20:19:05 +0000365
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000366 inline op_iterator idx_begin() { return op_begin()+1; }
367 inline const_op_iterator idx_begin() const { return op_begin()+1; }
368 inline op_iterator idx_end() { return op_end(); }
369 inline const_op_iterator idx_end() const { return op_end(); }
370
371 Value *getPointerOperand() {
372 return getOperand(0);
373 }
374 const Value *getPointerOperand() const {
375 return getOperand(0);
376 }
377 static unsigned getPointerOperandIndex() {
378 return 0U; // get index for modifying correct operand
379 }
380
381 inline unsigned getNumIndices() const { // Note: always non-negative
382 return getNumOperands() - 1;
383 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000384
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000385 inline bool hasIndices() const {
386 return getNumOperands() > 1;
387 }
388
389 // Methods for support type inquiry through isa, cast, and dyn_cast:
390 static inline bool classof(const GetElementPtrInst *) { return true; }
391 static inline bool classof(const Instruction *I) {
392 return (I->getOpcode() == Instruction::GetElementPtr);
393 }
394 static inline bool classof(const Value *V) {
395 return isa<Instruction>(V) && classof(cast<Instruction>(V));
396 }
397};
398
399//===----------------------------------------------------------------------===//
400// SetCondInst Class
401//===----------------------------------------------------------------------===//
402
403/// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
404/// le, or ge.
405///
406class SetCondInst : public BinaryOperator {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000407public:
408 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
Misha Brukman91102862005-03-16 03:46:55 +0000409 const std::string &Name = "", Instruction *InsertBefore = 0);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000410 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
Misha Brukman91102862005-03-16 03:46:55 +0000411 const std::string &Name, BasicBlock *InsertAtEnd);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000412
413 /// getInverseCondition - Return the inverse of the current condition opcode.
414 /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
415 ///
416 BinaryOps getInverseCondition() const {
417 return getInverseCondition(getOpcode());
418 }
419
420 /// getInverseCondition - Static version that you can use without an
421 /// instruction available.
422 ///
423 static BinaryOps getInverseCondition(BinaryOps Opcode);
424
425 /// getSwappedCondition - Return the condition opcode that would be the result
426 /// of exchanging the two operands of the setcc instruction without changing
427 /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
428 ///
429 BinaryOps getSwappedCondition() const {
430 return getSwappedCondition(getOpcode());
431 }
432
433 /// getSwappedCondition - Static version that you can use without an
434 /// instruction available.
435 ///
436 static BinaryOps getSwappedCondition(BinaryOps Opcode);
437
438
439 // Methods for support type inquiry through isa, cast, and dyn_cast:
440 static inline bool classof(const SetCondInst *) { return true; }
441 static inline bool classof(const Instruction *I) {
442 return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
443 I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
444 I->getOpcode() == SetLT || I->getOpcode() == SetGT;
445 }
446 static inline bool classof(const Value *V) {
447 return isa<Instruction>(V) && classof(cast<Instruction>(V));
448 }
449};
450
451//===----------------------------------------------------------------------===//
452// CastInst Class
453//===----------------------------------------------------------------------===//
454
455/// CastInst - This class represents a cast from Operand[0] to the type of
456/// the instruction (i->getType()).
457///
Chris Lattner454928e2005-01-29 00:31:36 +0000458class CastInst : public UnaryInstruction {
Misha Brukman9769ab22005-04-21 20:19:05 +0000459 CastInst(const CastInst &CI)
Chris Lattner454928e2005-01-29 00:31:36 +0000460 : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000461 }
462public:
463 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
464 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000465 : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000466 }
467 CastInst(Value *S, const Type *Ty, const std::string &Name,
468 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000469 : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000470 }
471
Chris Lattnerf319e832004-10-15 23:52:05 +0000472 virtual CastInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000473
474 // Methods for support type inquiry through isa, cast, and dyn_cast:
475 static inline bool classof(const CastInst *) { return true; }
476 static inline bool classof(const Instruction *I) {
477 return I->getOpcode() == Cast;
478 }
479 static inline bool classof(const Value *V) {
480 return isa<Instruction>(V) && classof(cast<Instruction>(V));
481 }
482};
483
484
485//===----------------------------------------------------------------------===//
486// CallInst Class
487//===----------------------------------------------------------------------===//
488
489/// CallInst - This class represents a function call, abstracting a target
Chris Lattner3340ffe2005-05-06 20:26:26 +0000490/// machine's calling convention. This class uses low bit of the SubClassData
491/// field to indicate whether or not this is a tail call. The rest of the bits
492/// hold the calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000493///
494class CallInst : public Instruction {
495 CallInst(const CallInst &CI);
496 void init(Value *Func, const std::vector<Value*> &Params);
497 void init(Value *Func, Value *Actual1, Value *Actual2);
498 void init(Value *Func, Value *Actual);
499 void init(Value *Func);
500
501public:
502 CallInst(Value *F, const std::vector<Value*> &Par,
503 const std::string &Name = "", Instruction *InsertBefore = 0);
504 CallInst(Value *F, const std::vector<Value*> &Par,
505 const std::string &Name, BasicBlock *InsertAtEnd);
506
507 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
508 // actuals, respectively.
509 CallInst(Value *F, Value *Actual1, Value *Actual2,
510 const std::string& Name = "", Instruction *InsertBefore = 0);
511 CallInst(Value *F, Value *Actual1, Value *Actual2,
512 const std::string& Name, BasicBlock *InsertAtEnd);
513 CallInst(Value *F, Value *Actual, const std::string& Name = "",
514 Instruction *InsertBefore = 0);
515 CallInst(Value *F, Value *Actual, const std::string& Name,
516 BasicBlock *InsertAtEnd);
Misha Brukman9769ab22005-04-21 20:19:05 +0000517 explicit CallInst(Value *F, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000518 Instruction *InsertBefore = 0);
Misha Brukman9769ab22005-04-21 20:19:05 +0000519 explicit CallInst(Value *F, const std::string &Name,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000520 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +0000521 ~CallInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000522
Chris Lattnerf319e832004-10-15 23:52:05 +0000523 virtual CallInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000524 bool mayWriteToMemory() const { return true; }
525
Chris Lattner3340ffe2005-05-06 20:26:26 +0000526 bool isTailCall() const { return SubclassData & 1; }
527 void setTailCall(bool isTailCall = true) {
Jeff Cohen39cef602005-05-07 02:44:04 +0000528 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
Chris Lattner3340ffe2005-05-06 20:26:26 +0000529 }
530
531 /// getCallingConv/setCallingConv - Get or set the calling convention of this
532 /// function call.
533 unsigned getCallingConv() const { return SubclassData >> 1; }
534 void setCallingConv(unsigned CC) {
535 SubclassData = (SubclassData & 1) | (CC << 1);
536 }
Chris Lattnerddb6db42005-05-06 05:51:46 +0000537
Chris Lattner721aef62004-11-18 17:46:57 +0000538 /// getCalledFunction - Return the function being called by this instruction
539 /// if it is a direct call. If it is a call through a function pointer,
540 /// return null.
541 Function *getCalledFunction() const {
Reid Spenceredd5d9e2005-05-15 16:13:11 +0000542 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
Chris Lattner721aef62004-11-18 17:46:57 +0000543 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000544
545 // getCalledValue - Get a pointer to a method that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +0000546 inline const Value *getCalledValue() const { return getOperand(0); }
547 inline Value *getCalledValue() { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000548
549 // Methods for support type inquiry through isa, cast, and dyn_cast:
550 static inline bool classof(const CallInst *) { return true; }
551 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000552 return I->getOpcode() == Instruction::Call;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000553 }
554 static inline bool classof(const Value *V) {
555 return isa<Instruction>(V) && classof(cast<Instruction>(V));
556 }
557};
558
559
560//===----------------------------------------------------------------------===//
561// ShiftInst Class
562//===----------------------------------------------------------------------===//
563
564/// ShiftInst - This class represents left and right shift instructions.
565///
566class ShiftInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000567 Use Ops[2];
568 ShiftInst(const ShiftInst &SI)
569 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
570 Ops[0].init(SI.Ops[0], this);
571 Ops[1].init(SI.Ops[1], this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000572 }
573 void init(OtherOps Opcode, Value *S, Value *SA) {
574 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
Chris Lattner454928e2005-01-29 00:31:36 +0000575 Ops[0].init(S, this);
576 Ops[1].init(SA, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000577 }
578
579public:
580 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
581 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000582 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000583 init(Opcode, S, SA);
584 }
585 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
586 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000587 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000588 init(Opcode, S, SA);
589 }
590
591 OtherOps getOpcode() const {
592 return static_cast<OtherOps>(Instruction::getOpcode());
593 }
594
Chris Lattner454928e2005-01-29 00:31:36 +0000595 /// Transparently provide more efficient getOperand methods.
596 Value *getOperand(unsigned i) const {
597 assert(i < 2 && "getOperand() out of range!");
598 return Ops[i];
599 }
600 void setOperand(unsigned i, Value *Val) {
601 assert(i < 2 && "setOperand() out of range!");
602 Ops[i] = Val;
603 }
604 unsigned getNumOperands() const { return 2; }
605
Chris Lattnerf319e832004-10-15 23:52:05 +0000606 virtual ShiftInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000607
608 // Methods for support type inquiry through isa, cast, and dyn_cast:
609 static inline bool classof(const ShiftInst *) { return true; }
610 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000611 return (I->getOpcode() == Instruction::Shr) |
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000612 (I->getOpcode() == Instruction::Shl);
613 }
614 static inline bool classof(const Value *V) {
615 return isa<Instruction>(V) && classof(cast<Instruction>(V));
616 }
617};
618
619//===----------------------------------------------------------------------===//
620// SelectInst Class
621//===----------------------------------------------------------------------===//
622
623/// SelectInst - This class represents the LLVM 'select' instruction.
624///
625class SelectInst : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000626 Use Ops[3];
627
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000628 void init(Value *C, Value *S1, Value *S2) {
Chris Lattner454928e2005-01-29 00:31:36 +0000629 Ops[0].init(C, this);
630 Ops[1].init(S1, this);
631 Ops[2].init(S2, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000632 }
633
Chris Lattner454928e2005-01-29 00:31:36 +0000634 SelectInst(const SelectInst &SI)
635 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
636 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
637 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000638public:
639 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
640 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000641 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
642 Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000643 init(C, S1, S2);
644 }
645 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
646 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000647 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
648 Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000649 init(C, S1, S2);
650 }
651
Chris Lattner454928e2005-01-29 00:31:36 +0000652 Value *getCondition() const { return Ops[0]; }
653 Value *getTrueValue() const { return Ops[1]; }
654 Value *getFalseValue() const { return Ops[2]; }
655
656 /// Transparently provide more efficient getOperand methods.
657 Value *getOperand(unsigned i) const {
658 assert(i < 3 && "getOperand() out of range!");
659 return Ops[i];
660 }
661 void setOperand(unsigned i, Value *Val) {
662 assert(i < 3 && "setOperand() out of range!");
663 Ops[i] = Val;
664 }
665 unsigned getNumOperands() const { return 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000666
667 OtherOps getOpcode() const {
668 return static_cast<OtherOps>(Instruction::getOpcode());
669 }
670
Chris Lattnerf319e832004-10-15 23:52:05 +0000671 virtual SelectInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000672
673 // Methods for support type inquiry through isa, cast, and dyn_cast:
674 static inline bool classof(const SelectInst *) { return true; }
675 static inline bool classof(const Instruction *I) {
676 return I->getOpcode() == Instruction::Select;
677 }
678 static inline bool classof(const Value *V) {
679 return isa<Instruction>(V) && classof(cast<Instruction>(V));
680 }
681};
682
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000683//===----------------------------------------------------------------------===//
684// VAArgInst Class
685//===----------------------------------------------------------------------===//
686
687/// VAArgInst - This class represents the va_arg llvm instruction, which returns
Andrew Lenharthf5428212005-06-18 18:31:30 +0000688/// an argument of the specified type given a va_list and increments that list
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000689///
Chris Lattner454928e2005-01-29 00:31:36 +0000690class VAArgInst : public UnaryInstruction {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000691 VAArgInst(const VAArgInst &VAA)
Chris Lattner454928e2005-01-29 00:31:36 +0000692 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000693public:
694 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
695 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000696 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000697 }
698 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
699 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000700 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000701 }
702
Chris Lattnerf319e832004-10-15 23:52:05 +0000703 virtual VAArgInst *clone() const;
Andrew Lenharthc64b64a2005-06-19 14:46:20 +0000704 bool mayWriteToMemory() const { return true; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000705
706 // Methods for support type inquiry through isa, cast, and dyn_cast:
707 static inline bool classof(const VAArgInst *) { return true; }
708 static inline bool classof(const Instruction *I) {
709 return I->getOpcode() == VAArg;
710 }
711 static inline bool classof(const Value *V) {
712 return isa<Instruction>(V) && classof(cast<Instruction>(V));
713 }
714};
715
716//===----------------------------------------------------------------------===//
717// PHINode Class
718//===----------------------------------------------------------------------===//
719
720// PHINode - The PHINode class is used to represent the magical mystical PHI
721// node, that can not exist in nature, but can be synthesized in a computer
722// scientist's overactive imagination.
723//
724class PHINode : public Instruction {
Chris Lattner454928e2005-01-29 00:31:36 +0000725 /// ReservedSpace - The number of operands actually allocated. NumOperands is
726 /// the number actually in use.
727 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000728 PHINode(const PHINode &PN);
729public:
730 PHINode(const Type *Ty, const std::string &Name = "",
731 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000732 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
733 ReservedSpace(0) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000734 }
735
736 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000737 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
738 ReservedSpace(0) {
739 }
740
741 ~PHINode();
742
743 /// reserveOperandSpace - This method can be used to avoid repeated
744 /// reallocation of PHI operand lists by reserving space for the correct
745 /// number of operands before adding them. Unlike normal vector reserves,
746 /// this method can also be used to trim the operand space.
747 void reserveOperandSpace(unsigned NumValues) {
748 resizeOperands(NumValues*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000749 }
750
Chris Lattnerf319e832004-10-15 23:52:05 +0000751 virtual PHINode *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000752
753 /// getNumIncomingValues - Return the number of incoming edges
754 ///
Chris Lattner454928e2005-01-29 00:31:36 +0000755 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000756
757 /// getIncomingValue - Return incoming value #x
758 ///
759 Value *getIncomingValue(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000760 assert(i*2 < getNumOperands() && "Invalid value number!");
761 return getOperand(i*2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000762 }
763 void setIncomingValue(unsigned i, Value *V) {
Chris Lattner454928e2005-01-29 00:31:36 +0000764 assert(i*2 < getNumOperands() && "Invalid value number!");
765 setOperand(i*2, V);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000766 }
Chris Lattner454928e2005-01-29 00:31:36 +0000767 unsigned getOperandNumForIncomingValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000768 return i*2;
769 }
770
771 /// getIncomingBlock - Return incoming basic block #x
772 ///
Misha Brukman9769ab22005-04-21 20:19:05 +0000773 BasicBlock *getIncomingBlock(unsigned i) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000774 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000775 }
776 void setIncomingBlock(unsigned i, BasicBlock *BB) {
Chris Lattner454928e2005-01-29 00:31:36 +0000777 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000778 }
779 unsigned getOperandNumForIncomingBlock(unsigned i) {
780 return i*2+1;
781 }
782
783 /// addIncoming - Add an incoming value to the end of the PHI list
784 ///
785 void addIncoming(Value *V, BasicBlock *BB) {
786 assert(getType() == V->getType() &&
787 "All operands to PHI node must be the same type as the PHI node!");
Chris Lattner454928e2005-01-29 00:31:36 +0000788 unsigned OpNo = NumOperands;
789 if (OpNo+2 > ReservedSpace)
790 resizeOperands(0); // Get more space!
791 // Initialize some new operands.
792 NumOperands = OpNo+2;
793 OperandList[OpNo].init(V, this);
794 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000795 }
Misha Brukman9769ab22005-04-21 20:19:05 +0000796
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000797 /// removeIncomingValue - Remove an incoming value. This is useful if a
798 /// predecessor basic block is deleted. The value removed is returned.
799 ///
800 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
801 /// is true), the PHI node is destroyed and any uses of it are replaced with
802 /// dummy values. The only time there should be zero incoming values to a PHI
803 /// node is when the block is dead, so this strategy is sound.
804 ///
805 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
806
807 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
808 int Idx = getBasicBlockIndex(BB);
809 assert(Idx >= 0 && "Invalid basic block argument to remove!");
810 return removeIncomingValue(Idx, DeletePHIIfEmpty);
811 }
812
Misha Brukman9769ab22005-04-21 20:19:05 +0000813 /// getBasicBlockIndex - Return the first index of the specified basic
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000814 /// block in the value list for this PHI. Returns -1 if no instance.
815 ///
816 int getBasicBlockIndex(const BasicBlock *BB) const {
Chris Lattner454928e2005-01-29 00:31:36 +0000817 Use *OL = OperandList;
Misha Brukman9769ab22005-04-21 20:19:05 +0000818 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
Chris Lattner454928e2005-01-29 00:31:36 +0000819 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000820 return -1;
821 }
822
823 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
824 return getIncomingValue(getBasicBlockIndex(BB));
825 }
826
Nate Begemana83ba0f2005-08-04 23:24:19 +0000827 /// hasConstantValue - If the specified PHI node always merges together the
828 /// same value, return the value, otherwise return null.
829 ///
Chris Lattner9acbd612005-08-05 00:49:06 +0000830 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
Nate Begemana83ba0f2005-08-04 23:24:19 +0000831
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000832 /// Methods for support type inquiry through isa, cast, and dyn_cast:
833 static inline bool classof(const PHINode *) { return true; }
834 static inline bool classof(const Instruction *I) {
Misha Brukman9769ab22005-04-21 20:19:05 +0000835 return I->getOpcode() == Instruction::PHI;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000836 }
837 static inline bool classof(const Value *V) {
838 return isa<Instruction>(V) && classof(cast<Instruction>(V));
839 }
Chris Lattner454928e2005-01-29 00:31:36 +0000840 private:
841 void resizeOperands(unsigned NumOperands);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000842};
843
844//===----------------------------------------------------------------------===//
845// ReturnInst Class
846//===----------------------------------------------------------------------===//
847
848//===---------------------------------------------------------------------------
849/// ReturnInst - Return a value (possibly void), from a function. Execution
850/// does not continue in this function any longer.
851///
852class ReturnInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +0000853 Use RetVal; // Possibly null retval.
854 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
855 RI.getNumOperands()) {
856 if (RI.getNumOperands())
857 RetVal.init(RI.RetVal, this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000858 }
859
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000860 void init(Value *RetVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000861
862public:
863 // ReturnInst constructors:
864 // ReturnInst() - 'ret void' instruction
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000865 // ReturnInst( null) - 'ret void' instruction
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000866 // ReturnInst(Value* X) - 'ret X' instruction
867 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
868 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
869 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
870 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
Alkis Evlogimenos859804f2004-11-17 21:02:25 +0000871 //
872 // NOTE: If the Value* passed is of type void then the constructor behaves as
873 // if it was passed NULL.
Chris Lattner454928e2005-01-29 00:31:36 +0000874 ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
875 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
876 init(retVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000877 }
Chris Lattner454928e2005-01-29 00:31:36 +0000878 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
879 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
880 init(retVal);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000881 }
882 ReturnInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000883 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000884 }
885
Chris Lattnerf319e832004-10-15 23:52:05 +0000886 virtual ReturnInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000887
Chris Lattner454928e2005-01-29 00:31:36 +0000888 // Transparently provide more efficient getOperand methods.
889 Value *getOperand(unsigned i) const {
890 assert(i < getNumOperands() && "getOperand() out of range!");
891 return RetVal;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000892 }
Chris Lattner454928e2005-01-29 00:31:36 +0000893 void setOperand(unsigned i, Value *Val) {
894 assert(i < getNumOperands() && "setOperand() out of range!");
895 RetVal = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000896 }
897
Chris Lattner454928e2005-01-29 00:31:36 +0000898 Value *getReturnValue() const { return RetVal; }
899
900 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000901
902 // Methods for support type inquiry through isa, cast, and dyn_cast:
903 static inline bool classof(const ReturnInst *) { return true; }
904 static inline bool classof(const Instruction *I) {
905 return (I->getOpcode() == Instruction::Ret);
906 }
907 static inline bool classof(const Value *V) {
908 return isa<Instruction>(V) && classof(cast<Instruction>(V));
909 }
Chris Lattner454928e2005-01-29 00:31:36 +0000910 private:
911 virtual BasicBlock *getSuccessorV(unsigned idx) const;
912 virtual unsigned getNumSuccessorsV() const;
913 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000914};
915
916//===----------------------------------------------------------------------===//
917// BranchInst Class
918//===----------------------------------------------------------------------===//
919
920//===---------------------------------------------------------------------------
921/// BranchInst - Conditional or Unconditional Branch instruction.
922///
923class BranchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +0000924 /// Ops list - Branches are strange. The operands are ordered:
925 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
926 /// they don't have to check for cond/uncond branchness.
927 Use Ops[3];
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000928 BranchInst(const BranchInst &BI);
Chris Lattner454928e2005-01-29 00:31:36 +0000929 void AssertOK();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000930public:
931 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
932 // BranchInst(BB *B) - 'br B'
933 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
934 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
935 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
936 // BranchInst(BB* B, BB *I) - 'br B' insert at end
937 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
938 BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000939 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
940 assert(IfTrue != 0 && "Branch destination may not be null!");
941 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000942 }
943 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
944 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +0000945 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
946 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
947 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
948 Ops[2].init(Cond, this);
949#ifndef NDEBUG
950 AssertOK();
951#endif
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000952 }
953
954 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000955 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
956 assert(IfTrue != 0 && "Branch destination may not be null!");
957 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000958 }
959
960 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
961 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +0000962 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
963 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
964 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
965 Ops[2].init(Cond, this);
966#ifndef NDEBUG
967 AssertOK();
968#endif
969 }
970
971
972 /// Transparently provide more efficient getOperand methods.
973 Value *getOperand(unsigned i) const {
974 assert(i < getNumOperands() && "getOperand() out of range!");
975 return Ops[i];
976 }
977 void setOperand(unsigned i, Value *Val) {
978 assert(i < getNumOperands() && "setOperand() out of range!");
979 Ops[i] = Val;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000980 }
981
Chris Lattnerf319e832004-10-15 23:52:05 +0000982 virtual BranchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000983
Chris Lattner454928e2005-01-29 00:31:36 +0000984 inline bool isUnconditional() const { return getNumOperands() == 1; }
985 inline bool isConditional() const { return getNumOperands() == 3; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000986
987 inline Value *getCondition() const {
988 assert(isConditional() && "Cannot get condition of an uncond branch!");
Chris Lattner454928e2005-01-29 00:31:36 +0000989 return getOperand(2);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +0000990 }
991
992 void setCondition(Value *V) {
993 assert(isConditional() && "Cannot set condition of unconditional branch!");
994 setOperand(2, V);
995 }
996
997 // setUnconditionalDest - Change the current branch to an unconditional branch
998 // targeting the specified block.
Chris Lattner454928e2005-01-29 00:31:36 +0000999 // FIXME: Eliminate this ugly method.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001000 void setUnconditionalDest(BasicBlock *Dest) {
Chris Lattner454928e2005-01-29 00:31:36 +00001001 if (isConditional()) { // Convert this to an uncond branch.
1002 NumOperands = 1;
1003 Ops[1].set(0);
1004 Ops[2].set(0);
1005 }
1006 setOperand(0, reinterpret_cast<Value*>(Dest));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001007 }
1008
Chris Lattner454928e2005-01-29 00:31:36 +00001009 unsigned getNumSuccessors() const { return 1+isConditional(); }
1010
1011 BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001012 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
Misha Brukman9769ab22005-04-21 20:19:05 +00001013 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
Chris Lattner454928e2005-01-29 00:31:36 +00001014 cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001015 }
1016
Chris Lattner454928e2005-01-29 00:31:36 +00001017 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001018 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001019 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001020 }
1021
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001022 // Methods for support type inquiry through isa, cast, and dyn_cast:
1023 static inline bool classof(const BranchInst *) { return true; }
1024 static inline bool classof(const Instruction *I) {
1025 return (I->getOpcode() == Instruction::Br);
1026 }
1027 static inline bool classof(const Value *V) {
1028 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1029 }
Chris Lattner454928e2005-01-29 00:31:36 +00001030private:
1031 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1032 virtual unsigned getNumSuccessorsV() const;
1033 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001034};
1035
1036//===----------------------------------------------------------------------===//
1037// SwitchInst Class
1038//===----------------------------------------------------------------------===//
1039
1040//===---------------------------------------------------------------------------
1041/// SwitchInst - Multiway switch
1042///
1043class SwitchInst : public TerminatorInst {
Chris Lattner454928e2005-01-29 00:31:36 +00001044 unsigned ReservedSpace;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001045 // Operand[0] = Value to switch on
1046 // Operand[1] = Default basic block destination
1047 // Operand[2n ] = Value to match
1048 // Operand[2n+1] = BasicBlock to go to on match
1049 SwitchInst(const SwitchInst &RI);
Chris Lattner454928e2005-01-29 00:31:36 +00001050 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1051 void resizeOperands(unsigned No);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001052public:
Chris Lattner454928e2005-01-29 00:31:36 +00001053 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1054 /// switch on and a default destination. The number of additional cases can
1055 /// be specified here to make memory allocation more efficient. This
1056 /// constructor can also autoinsert before another instruction.
1057 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Misha Brukman9769ab22005-04-21 20:19:05 +00001058 Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001059 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1060 init(Value, Default, NumCases);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001061 }
1062
Chris Lattner454928e2005-01-29 00:31:36 +00001063 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1064 /// switch on and a default destination. The number of additional cases can
1065 /// be specified here to make memory allocation more efficient. This
1066 /// constructor also autoinserts at the end of the specified BasicBlock.
1067 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
Misha Brukman9769ab22005-04-21 20:19:05 +00001068 BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001069 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1070 init(Value, Default, NumCases);
1071 }
1072 ~SwitchInst();
1073
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001074
1075 // Accessor Methods for Switch stmt
Chris Lattner454928e2005-01-29 00:31:36 +00001076 inline Value *getCondition() const { return getOperand(0); }
1077 void setCondition(Value *V) { setOperand(0, V); }
Chris Lattnerbfaf88a2004-12-10 20:35:47 +00001078
Chris Lattner454928e2005-01-29 00:31:36 +00001079 inline BasicBlock *getDefaultDest() const {
1080 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001081 }
1082
1083 /// getNumCases - return the number of 'cases' in this switch instruction.
1084 /// Note that case #0 is always the default case.
1085 unsigned getNumCases() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001086 return getNumOperands()/2;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001087 }
1088
1089 /// getCaseValue - Return the specified case value. Note that case #0, the
1090 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001091 ConstantInt *getCaseValue(unsigned i) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001092 assert(i && i < getNumCases() && "Illegal case value to get!");
1093 return getSuccessorValue(i);
1094 }
1095
1096 /// getCaseValue - Return the specified case value. Note that case #0, the
1097 /// default destination, does not have a case value.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001098 const ConstantInt *getCaseValue(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001099 assert(i && i < getNumCases() && "Illegal case value to get!");
1100 return getSuccessorValue(i);
1101 }
1102
1103 /// findCaseValue - Search all of the case values for the specified constant.
1104 /// If it is explicitly handled, return the case number of it, otherwise
1105 /// return 0 to indicate that it is handled by the default handler.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001106 unsigned findCaseValue(const ConstantInt *C) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001107 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1108 if (getCaseValue(i) == C)
1109 return i;
1110 return 0;
1111 }
1112
1113 /// addCase - Add an entry to the switch instruction...
1114 ///
Chris Lattnerd1a32602005-02-24 05:32:09 +00001115 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001116
1117 /// removeCase - This method removes the specified successor from the switch
1118 /// instruction. Note that this cannot be used to remove the default
1119 /// destination (successor #0).
1120 ///
1121 void removeCase(unsigned idx);
1122
Chris Lattner454928e2005-01-29 00:31:36 +00001123 virtual SwitchInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001124
Chris Lattner454928e2005-01-29 00:31:36 +00001125 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1126 BasicBlock *getSuccessor(unsigned idx) const {
1127 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1128 return cast<BasicBlock>(getOperand(idx*2+1));
1129 }
1130 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001131 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
Chris Lattner454928e2005-01-29 00:31:36 +00001132 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001133 }
1134
1135 // getSuccessorValue - Return the value associated with the specified
1136 // successor.
Chris Lattnerd1a32602005-02-24 05:32:09 +00001137 inline ConstantInt *getSuccessorValue(unsigned idx) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001138 assert(idx < getNumSuccessors() && "Successor # out of range!");
Reid Spenceredd5d9e2005-05-15 16:13:11 +00001139 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001140 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001141
1142 // Methods for support type inquiry through isa, cast, and dyn_cast:
1143 static inline bool classof(const SwitchInst *) { return true; }
1144 static inline bool classof(const Instruction *I) {
Chris Lattnerd1a32602005-02-24 05:32:09 +00001145 return I->getOpcode() == Instruction::Switch;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001146 }
1147 static inline bool classof(const Value *V) {
1148 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1149 }
Chris Lattner454928e2005-01-29 00:31:36 +00001150private:
1151 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1152 virtual unsigned getNumSuccessorsV() const;
1153 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001154};
1155
1156//===----------------------------------------------------------------------===//
1157// InvokeInst Class
1158//===----------------------------------------------------------------------===//
1159
1160//===---------------------------------------------------------------------------
Chris Lattner3340ffe2005-05-06 20:26:26 +00001161
1162/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1163/// calling convention of the call.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001164///
1165class InvokeInst : public TerminatorInst {
1166 InvokeInst(const InvokeInst &BI);
1167 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1168 const std::vector<Value*> &Params);
1169public:
1170 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Misha Brukman91102862005-03-16 03:46:55 +00001171 const std::vector<Value*> &Params, const std::string &Name = "",
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001172 Instruction *InsertBefore = 0);
1173 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
Misha Brukman91102862005-03-16 03:46:55 +00001174 const std::vector<Value*> &Params, const std::string &Name,
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001175 BasicBlock *InsertAtEnd);
Chris Lattner454928e2005-01-29 00:31:36 +00001176 ~InvokeInst();
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001177
Chris Lattnerf319e832004-10-15 23:52:05 +00001178 virtual InvokeInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001179
1180 bool mayWriteToMemory() const { return true; }
1181
Chris Lattner3340ffe2005-05-06 20:26:26 +00001182 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1183 /// function call.
1184 unsigned getCallingConv() const { return SubclassData; }
1185 void setCallingConv(unsigned CC) {
1186 SubclassData = CC;
1187 }
1188
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001189 /// getCalledFunction - Return the function called, or null if this is an
Chris Lattner721aef62004-11-18 17:46:57 +00001190 /// indirect function invocation.
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001191 ///
Chris Lattner721aef62004-11-18 17:46:57 +00001192 Function *getCalledFunction() const {
Chris Lattner454928e2005-01-29 00:31:36 +00001193 return dyn_cast<Function>(getOperand(0));
Chris Lattner721aef62004-11-18 17:46:57 +00001194 }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001195
1196 // getCalledValue - Get a pointer to a function that is invoked by this inst.
Chris Lattner454928e2005-01-29 00:31:36 +00001197 inline Value *getCalledValue() const { return getOperand(0); }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001198
1199 // get*Dest - Return the destination basic blocks...
Chris Lattner454928e2005-01-29 00:31:36 +00001200 BasicBlock *getNormalDest() const {
1201 return cast<BasicBlock>(getOperand(1));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001202 }
Chris Lattner454928e2005-01-29 00:31:36 +00001203 BasicBlock *getUnwindDest() const {
1204 return cast<BasicBlock>(getOperand(2));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001205 }
Chris Lattner454928e2005-01-29 00:31:36 +00001206 void setNormalDest(BasicBlock *B) {
1207 setOperand(1, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001208 }
1209
Chris Lattner454928e2005-01-29 00:31:36 +00001210 void setUnwindDest(BasicBlock *B) {
1211 setOperand(2, reinterpret_cast<Value*>(B));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001212 }
1213
Chris Lattner454928e2005-01-29 00:31:36 +00001214 inline BasicBlock *getSuccessor(unsigned i) const {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001215 assert(i < 2 && "Successor # out of range for invoke!");
1216 return i == 0 ? getNormalDest() : getUnwindDest();
1217 }
1218
Chris Lattner454928e2005-01-29 00:31:36 +00001219 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001220 assert(idx < 2 && "Successor # out of range for invoke!");
Chris Lattner454928e2005-01-29 00:31:36 +00001221 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001222 }
1223
Chris Lattner454928e2005-01-29 00:31:36 +00001224 unsigned getNumSuccessors() const { return 2; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001225
1226 // Methods for support type inquiry through isa, cast, and dyn_cast:
1227 static inline bool classof(const InvokeInst *) { return true; }
1228 static inline bool classof(const Instruction *I) {
1229 return (I->getOpcode() == Instruction::Invoke);
1230 }
1231 static inline bool classof(const Value *V) {
1232 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1233 }
Chris Lattner454928e2005-01-29 00:31:36 +00001234private:
1235 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1236 virtual unsigned getNumSuccessorsV() const;
1237 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001238};
1239
1240
1241//===----------------------------------------------------------------------===//
1242// UnwindInst Class
1243//===----------------------------------------------------------------------===//
1244
1245//===---------------------------------------------------------------------------
1246/// UnwindInst - Immediately exit the current function, unwinding the stack
1247/// until an invoke instruction is found.
1248///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001249class UnwindInst : public TerminatorInst {
1250public:
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001251 UnwindInst(Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001252 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001253 }
1254 UnwindInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001255 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001256 }
1257
Chris Lattnerf319e832004-10-15 23:52:05 +00001258 virtual UnwindInst *clone() const;
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001259
Chris Lattner454928e2005-01-29 00:31:36 +00001260 unsigned getNumSuccessors() const { return 0; }
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001261
1262 // Methods for support type inquiry through isa, cast, and dyn_cast:
1263 static inline bool classof(const UnwindInst *) { return true; }
1264 static inline bool classof(const Instruction *I) {
1265 return I->getOpcode() == Instruction::Unwind;
1266 }
1267 static inline bool classof(const Value *V) {
1268 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1269 }
Chris Lattner454928e2005-01-29 00:31:36 +00001270private:
1271 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1272 virtual unsigned getNumSuccessorsV() const;
1273 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001274};
1275
Chris Lattner076b3f12004-10-16 18:05:54 +00001276//===----------------------------------------------------------------------===//
1277// UnreachableInst Class
1278//===----------------------------------------------------------------------===//
1279
1280//===---------------------------------------------------------------------------
1281/// UnreachableInst - This function has undefined behavior. In particular, the
1282/// presence of this instruction indicates some higher level knowledge that the
1283/// end of the block cannot be reached.
1284///
Chris Lattner1fca5ff2004-10-27 16:14:51 +00001285class UnreachableInst : public TerminatorInst {
1286public:
Chris Lattner076b3f12004-10-16 18:05:54 +00001287 UnreachableInst(Instruction *InsertBefore = 0)
Chris Lattner454928e2005-01-29 00:31:36 +00001288 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
Chris Lattner076b3f12004-10-16 18:05:54 +00001289 }
1290 UnreachableInst(BasicBlock *InsertAtEnd)
Chris Lattner454928e2005-01-29 00:31:36 +00001291 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
Chris Lattner076b3f12004-10-16 18:05:54 +00001292 }
1293
1294 virtual UnreachableInst *clone() const;
1295
Chris Lattner454928e2005-01-29 00:31:36 +00001296 unsigned getNumSuccessors() const { return 0; }
Chris Lattner076b3f12004-10-16 18:05:54 +00001297
1298 // Methods for support type inquiry through isa, cast, and dyn_cast:
1299 static inline bool classof(const UnreachableInst *) { return true; }
1300 static inline bool classof(const Instruction *I) {
1301 return I->getOpcode() == Instruction::Unreachable;
1302 }
1303 static inline bool classof(const Value *V) {
1304 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1305 }
Chris Lattner454928e2005-01-29 00:31:36 +00001306private:
1307 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1308 virtual unsigned getNumSuccessorsV() const;
1309 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
Chris Lattner076b3f12004-10-16 18:05:54 +00001310};
1311
Alkis Evlogimenoseb62bc72004-07-29 12:17:34 +00001312} // End llvm namespace
Chris Lattnera892a3a2003-01-27 22:08:52 +00001313
1314#endif