1 //===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_INSTRUCTIONS_H
17 #define LLVM_INSTRUCTIONS_H
19 #include "llvm/Instruction.h"
20 #include "llvm/InstrTypes.h"
28 //===----------------------------------------------------------------------===//
29 // AllocationInst Class
30 //===----------------------------------------------------------------------===//
32 /// AllocationInst - This class is the common base class of MallocInst and
35 class AllocationInst : public UnaryInstruction {
38 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
39 const std::string &Name = "", Instruction *InsertBefore = 0);
40 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
41 const std::string &Name, BasicBlock *InsertAtEnd);
45 /// isArrayAllocation - Return true if there is an allocation size parameter
46 /// to the allocation instruction that is not 1.
48 bool isArrayAllocation() const;
50 /// getArraySize - Get the number of element allocated, for a simple
51 /// allocation of a single element, this will return a constant 1 value.
53 inline const Value *getArraySize() const { return getOperand(0); }
54 inline Value *getArraySize() { return getOperand(0); }
56 /// getType - Overload to return most specific pointer type
58 inline const PointerType *getType() const {
59 return reinterpret_cast<const PointerType*>(Instruction::getType());
62 /// getAllocatedType - Return the type that is being allocated by the
65 const Type *getAllocatedType() const;
67 /// getAlignment - Return the alignment of the memory that is being allocated
68 /// by the instruction.
70 unsigned getAlignment() const { return Alignment; }
71 void setAlignment(unsigned Align) {
72 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
76 virtual Instruction *clone() const = 0;
78 // Methods for support type inquiry through isa, cast, and dyn_cast:
79 static inline bool classof(const AllocationInst *) { return true; }
80 static inline bool classof(const Instruction *I) {
81 return I->getOpcode() == Instruction::Alloca ||
82 I->getOpcode() == Instruction::Malloc;
84 static inline bool classof(const Value *V) {
85 return isa<Instruction>(V) && classof(cast<Instruction>(V));
90 //===----------------------------------------------------------------------===//
92 //===----------------------------------------------------------------------===//
94 /// MallocInst - an instruction to allocated memory on the heap
96 class MallocInst : public AllocationInst {
97 MallocInst(const MallocInst &MI);
99 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
100 const std::string &Name = "",
101 Instruction *InsertBefore = 0)
102 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
103 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
104 BasicBlock *InsertAtEnd)
105 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
106 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
107 const std::string &Name, BasicBlock *InsertAtEnd)
108 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
109 explicit MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
110 const std::string &Name = "",
111 Instruction *InsertBefore = 0)
112 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
114 virtual MallocInst *clone() const;
116 // Methods for support type inquiry through isa, cast, and dyn_cast:
117 static inline bool classof(const MallocInst *) { return true; }
118 static inline bool classof(const Instruction *I) {
119 return (I->getOpcode() == Instruction::Malloc);
121 static inline bool classof(const Value *V) {
122 return isa<Instruction>(V) && classof(cast<Instruction>(V));
127 //===----------------------------------------------------------------------===//
129 //===----------------------------------------------------------------------===//
131 /// AllocaInst - an instruction to allocate memory on the stack
133 class AllocaInst : public AllocationInst {
134 AllocaInst(const AllocaInst &);
136 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
137 const std::string &Name = "",
138 Instruction *InsertBefore = 0)
139 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
140 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
141 BasicBlock *InsertAtEnd)
142 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
143 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
144 const std::string &Name, BasicBlock *InsertAtEnd)
145 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
146 explicit AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
147 const std::string &Name = "",
148 Instruction *InsertBefore = 0)
149 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
151 virtual AllocaInst *clone() const;
153 // Methods for support type inquiry through isa, cast, and dyn_cast:
154 static inline bool classof(const AllocaInst *) { return true; }
155 static inline bool classof(const Instruction *I) {
156 return (I->getOpcode() == Instruction::Alloca);
158 static inline bool classof(const Value *V) {
159 return isa<Instruction>(V) && classof(cast<Instruction>(V));
164 //===----------------------------------------------------------------------===//
166 //===----------------------------------------------------------------------===//
168 /// FreeInst - an instruction to deallocate memory
170 class FreeInst : public UnaryInstruction {
173 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
174 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
176 virtual FreeInst *clone() const;
178 virtual bool mayWriteToMemory() const { return true; }
180 // Methods for support type inquiry through isa, cast, and dyn_cast:
181 static inline bool classof(const FreeInst *) { return true; }
182 static inline bool classof(const Instruction *I) {
183 return (I->getOpcode() == Instruction::Free);
185 static inline bool classof(const Value *V) {
186 return isa<Instruction>(V) && classof(cast<Instruction>(V));
191 //===----------------------------------------------------------------------===//
193 //===----------------------------------------------------------------------===//
195 /// LoadInst - an instruction for reading from memory. This uses the
196 /// SubclassData field in Value to store whether or not the load is volatile.
198 class LoadInst : public UnaryInstruction {
199 LoadInst(const LoadInst &LI)
200 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
201 setVolatile(LI.isVolatile());
209 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
210 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
211 LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
212 Instruction *InsertBefore = 0);
213 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
214 BasicBlock *InsertAtEnd);
216 /// isVolatile - Return true if this is a load from a volatile memory
219 bool isVolatile() const { return SubclassData; }
221 /// setVolatile - Specify whether this is a volatile load or not.
223 void setVolatile(bool V) { SubclassData = V; }
225 virtual LoadInst *clone() const;
227 virtual bool mayWriteToMemory() const { return isVolatile(); }
229 Value *getPointerOperand() { return getOperand(0); }
230 const Value *getPointerOperand() const { return getOperand(0); }
231 static unsigned getPointerOperandIndex() { return 0U; }
233 // Methods for support type inquiry through isa, cast, and dyn_cast:
234 static inline bool classof(const LoadInst *) { return true; }
235 static inline bool classof(const Instruction *I) {
236 return I->getOpcode() == Instruction::Load;
238 static inline bool classof(const Value *V) {
239 return isa<Instruction>(V) && classof(cast<Instruction>(V));
244 //===----------------------------------------------------------------------===//
246 //===----------------------------------------------------------------------===//
248 /// StoreInst - an instruction for storing to memory
250 class StoreInst : public Instruction {
252 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
253 Ops[0].init(SI.Ops[0], this);
254 Ops[1].init(SI.Ops[1], this);
255 setVolatile(SI.isVolatile());
262 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
263 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
264 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
265 Instruction *InsertBefore = 0);
266 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
269 /// isVolatile - Return true if this is a load from a volatile memory
272 bool isVolatile() const { return SubclassData; }
274 /// setVolatile - Specify whether this is a volatile load or not.
276 void setVolatile(bool V) { SubclassData = V; }
278 /// Transparently provide more efficient getOperand methods.
279 Value *getOperand(unsigned i) const {
280 assert(i < 2 && "getOperand() out of range!");
283 void setOperand(unsigned i, Value *Val) {
284 assert(i < 2 && "setOperand() out of range!");
287 unsigned getNumOperands() const { return 2; }
290 virtual StoreInst *clone() const;
292 virtual bool mayWriteToMemory() const { return true; }
294 Value *getPointerOperand() { return getOperand(1); }
295 const Value *getPointerOperand() const { return getOperand(1); }
296 static unsigned getPointerOperandIndex() { return 1U; }
298 // Methods for support type inquiry through isa, cast, and dyn_cast:
299 static inline bool classof(const StoreInst *) { return true; }
300 static inline bool classof(const Instruction *I) {
301 return I->getOpcode() == Instruction::Store;
303 static inline bool classof(const Value *V) {
304 return isa<Instruction>(V) && classof(cast<Instruction>(V));
309 //===----------------------------------------------------------------------===//
310 // GetElementPtrInst Class
311 //===----------------------------------------------------------------------===//
313 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
314 /// access elements of arrays and structs
316 class GetElementPtrInst : public Instruction {
317 GetElementPtrInst(const GetElementPtrInst &GEPI)
318 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
319 0, GEPI.getNumOperands()) {
320 Use *OL = OperandList = new Use[NumOperands];
321 Use *GEPIOL = GEPI.OperandList;
322 for (unsigned i = 0, E = NumOperands; i != E; ++i)
323 OL[i].init(GEPIOL[i], this);
325 void init(Value *Ptr, const std::vector<Value*> &Idx);
326 void init(Value *Ptr, Value *Idx0, Value *Idx1);
327 void init(Value *Ptr, Value *Idx);
329 /// Constructors - Create a getelementptr instruction with a base pointer an
330 /// list of indices. The first ctor can optionally insert before an existing
331 /// instruction, the second appends the new instruction to the specified
333 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
334 const std::string &Name = "", Instruction *InsertBefore =0);
335 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
336 const std::string &Name, BasicBlock *InsertAtEnd);
338 /// Constructors - These two constructors are convenience methods because one
339 /// and two index getelementptr instructions are so common.
340 GetElementPtrInst(Value *Ptr, Value *Idx,
341 const std::string &Name = "", Instruction *InsertBefore =0);
342 GetElementPtrInst(Value *Ptr, Value *Idx,
343 const std::string &Name, BasicBlock *InsertAtEnd);
344 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
345 const std::string &Name = "", Instruction *InsertBefore =0);
346 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
347 const std::string &Name, BasicBlock *InsertAtEnd);
348 ~GetElementPtrInst();
350 virtual GetElementPtrInst *clone() const;
352 // getType - Overload to return most specific pointer type...
353 inline const PointerType *getType() const {
354 return reinterpret_cast<const PointerType*>(Instruction::getType());
357 /// getIndexedType - Returns the type of the element that would be loaded with
358 /// a load instruction with the specified parameters.
360 /// A null type is returned if the indices are invalid for the specified
363 static const Type *getIndexedType(const Type *Ptr,
364 const std::vector<Value*> &Indices,
365 bool AllowStructLeaf = false);
366 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
367 bool AllowStructLeaf = false);
368 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
370 inline op_iterator idx_begin() { return op_begin()+1; }
371 inline const_op_iterator idx_begin() const { return op_begin()+1; }
372 inline op_iterator idx_end() { return op_end(); }
373 inline const_op_iterator idx_end() const { return op_end(); }
375 Value *getPointerOperand() {
376 return getOperand(0);
378 const Value *getPointerOperand() const {
379 return getOperand(0);
381 static unsigned getPointerOperandIndex() {
382 return 0U; // get index for modifying correct operand
385 inline unsigned getNumIndices() const { // Note: always non-negative
386 return getNumOperands() - 1;
389 inline bool hasIndices() const {
390 return getNumOperands() > 1;
393 // Methods for support type inquiry through isa, cast, and dyn_cast:
394 static inline bool classof(const GetElementPtrInst *) { return true; }
395 static inline bool classof(const Instruction *I) {
396 return (I->getOpcode() == Instruction::GetElementPtr);
398 static inline bool classof(const Value *V) {
399 return isa<Instruction>(V) && classof(cast<Instruction>(V));
403 //===----------------------------------------------------------------------===//
405 //===----------------------------------------------------------------------===//
407 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
410 class SetCondInst : public BinaryOperator {
412 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
413 const std::string &Name = "", Instruction *InsertBefore = 0);
414 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
415 const std::string &Name, BasicBlock *InsertAtEnd);
417 /// getInverseCondition - Return the inverse of the current condition opcode.
418 /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
420 BinaryOps getInverseCondition() const {
421 return getInverseCondition(getOpcode());
424 /// getInverseCondition - Static version that you can use without an
425 /// instruction available.
427 static BinaryOps getInverseCondition(BinaryOps Opcode);
429 /// getSwappedCondition - Return the condition opcode that would be the result
430 /// of exchanging the two operands of the setcc instruction without changing
431 /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
433 BinaryOps getSwappedCondition() const {
434 return getSwappedCondition(getOpcode());
437 /// getSwappedCondition - Static version that you can use without an
438 /// instruction available.
440 static BinaryOps getSwappedCondition(BinaryOps Opcode);
443 // Methods for support type inquiry through isa, cast, and dyn_cast:
444 static inline bool classof(const SetCondInst *) { return true; }
445 static inline bool classof(const Instruction *I) {
446 return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
447 I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
448 I->getOpcode() == SetLT || I->getOpcode() == SetGT;
450 static inline bool classof(const Value *V) {
451 return isa<Instruction>(V) && classof(cast<Instruction>(V));
455 //===----------------------------------------------------------------------===//
457 //===----------------------------------------------------------------------===//
459 /// CastInst - This class represents a cast from Operand[0] to the type of
460 /// the instruction (i->getType()).
462 class CastInst : public UnaryInstruction {
463 CastInst(const CastInst &CI)
464 : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) {
467 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
468 Instruction *InsertBefore = 0)
469 : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) {
471 CastInst(Value *S, const Type *Ty, const std::string &Name,
472 BasicBlock *InsertAtEnd)
473 : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) {
476 virtual CastInst *clone() const;
478 // Methods for support type inquiry through isa, cast, and dyn_cast:
479 static inline bool classof(const CastInst *) { return true; }
480 static inline bool classof(const Instruction *I) {
481 return I->getOpcode() == Cast;
483 static inline bool classof(const Value *V) {
484 return isa<Instruction>(V) && classof(cast<Instruction>(V));
489 //===----------------------------------------------------------------------===//
491 //===----------------------------------------------------------------------===//
493 /// CallInst - This class represents a function call, abstracting a target
494 /// machine's calling convention. This class uses low bit of the SubClassData
495 /// field to indicate whether or not this is a tail call. The rest of the bits
496 /// hold the calling convention of the call.
498 class CallInst : public Instruction {
499 CallInst(const CallInst &CI);
500 void init(Value *Func, const std::vector<Value*> &Params);
501 void init(Value *Func, Value *Actual1, Value *Actual2);
502 void init(Value *Func, Value *Actual);
503 void init(Value *Func);
506 CallInst(Value *F, const std::vector<Value*> &Par,
507 const std::string &Name = "", Instruction *InsertBefore = 0);
508 CallInst(Value *F, const std::vector<Value*> &Par,
509 const std::string &Name, BasicBlock *InsertAtEnd);
511 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
512 // actuals, respectively.
513 CallInst(Value *F, Value *Actual1, Value *Actual2,
514 const std::string& Name = "", Instruction *InsertBefore = 0);
515 CallInst(Value *F, Value *Actual1, Value *Actual2,
516 const std::string& Name, BasicBlock *InsertAtEnd);
517 CallInst(Value *F, Value *Actual, const std::string& Name = "",
518 Instruction *InsertBefore = 0);
519 CallInst(Value *F, Value *Actual, const std::string& Name,
520 BasicBlock *InsertAtEnd);
521 explicit CallInst(Value *F, const std::string &Name = "",
522 Instruction *InsertBefore = 0);
523 explicit CallInst(Value *F, const std::string &Name,
524 BasicBlock *InsertAtEnd);
527 virtual CallInst *clone() const;
528 bool mayWriteToMemory() const { return true; }
530 bool isTailCall() const { return SubclassData & 1; }
531 void setTailCall(bool isTailCall = true) {
532 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
535 /// getCallingConv/setCallingConv - Get or set the calling convention of this
537 unsigned getCallingConv() const { return SubclassData >> 1; }
538 void setCallingConv(unsigned CC) {
539 SubclassData = (SubclassData & 1) | (CC << 1);
542 /// getCalledFunction - Return the function being called by this instruction
543 /// if it is a direct call. If it is a call through a function pointer,
545 Function *getCalledFunction() const {
546 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
549 // getCalledValue - Get a pointer to a method that is invoked by this inst.
550 inline const Value *getCalledValue() const { return getOperand(0); }
551 inline Value *getCalledValue() { return getOperand(0); }
553 // Methods for support type inquiry through isa, cast, and dyn_cast:
554 static inline bool classof(const CallInst *) { return true; }
555 static inline bool classof(const Instruction *I) {
556 return I->getOpcode() == Instruction::Call;
558 static inline bool classof(const Value *V) {
559 return isa<Instruction>(V) && classof(cast<Instruction>(V));
564 //===----------------------------------------------------------------------===//
566 //===----------------------------------------------------------------------===//
568 /// ShiftInst - This class represents left and right shift instructions.
570 class ShiftInst : public Instruction {
572 ShiftInst(const ShiftInst &SI)
573 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
574 Ops[0].init(SI.Ops[0], this);
575 Ops[1].init(SI.Ops[1], this);
577 void init(OtherOps Opcode, Value *S, Value *SA) {
578 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
579 Ops[0].init(S, this);
580 Ops[1].init(SA, this);
584 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
585 Instruction *InsertBefore = 0)
586 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
589 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
590 BasicBlock *InsertAtEnd)
591 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
595 OtherOps getOpcode() const {
596 return static_cast<OtherOps>(Instruction::getOpcode());
599 /// Transparently provide more efficient getOperand methods.
600 Value *getOperand(unsigned i) const {
601 assert(i < 2 && "getOperand() out of range!");
604 void setOperand(unsigned i, Value *Val) {
605 assert(i < 2 && "setOperand() out of range!");
608 unsigned getNumOperands() const { return 2; }
610 virtual ShiftInst *clone() const;
612 // Methods for support type inquiry through isa, cast, and dyn_cast:
613 static inline bool classof(const ShiftInst *) { return true; }
614 static inline bool classof(const Instruction *I) {
615 return (I->getOpcode() == Instruction::Shr) |
616 (I->getOpcode() == Instruction::Shl);
618 static inline bool classof(const Value *V) {
619 return isa<Instruction>(V) && classof(cast<Instruction>(V));
623 //===----------------------------------------------------------------------===//
625 //===----------------------------------------------------------------------===//
627 /// SelectInst - This class represents the LLVM 'select' instruction.
629 class SelectInst : public Instruction {
632 void init(Value *C, Value *S1, Value *S2) {
633 Ops[0].init(C, this);
634 Ops[1].init(S1, this);
635 Ops[2].init(S2, this);
638 SelectInst(const SelectInst &SI)
639 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
640 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
643 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
644 Instruction *InsertBefore = 0)
645 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
646 Name, InsertBefore) {
649 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
650 BasicBlock *InsertAtEnd)
651 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
656 Value *getCondition() const { return Ops[0]; }
657 Value *getTrueValue() const { return Ops[1]; }
658 Value *getFalseValue() const { return Ops[2]; }
660 /// Transparently provide more efficient getOperand methods.
661 Value *getOperand(unsigned i) const {
662 assert(i < 3 && "getOperand() out of range!");
665 void setOperand(unsigned i, Value *Val) {
666 assert(i < 3 && "setOperand() out of range!");
669 unsigned getNumOperands() const { return 3; }
671 OtherOps getOpcode() const {
672 return static_cast<OtherOps>(Instruction::getOpcode());
675 virtual SelectInst *clone() const;
677 // Methods for support type inquiry through isa, cast, and dyn_cast:
678 static inline bool classof(const SelectInst *) { return true; }
679 static inline bool classof(const Instruction *I) {
680 return I->getOpcode() == Instruction::Select;
682 static inline bool classof(const Value *V) {
683 return isa<Instruction>(V) && classof(cast<Instruction>(V));
687 //===----------------------------------------------------------------------===//
689 //===----------------------------------------------------------------------===//
691 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
692 /// an argument of the specified type given a va_list and increments that list
694 class VAArgInst : public UnaryInstruction {
695 VAArgInst(const VAArgInst &VAA)
696 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
698 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
699 Instruction *InsertBefore = 0)
700 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
702 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
703 BasicBlock *InsertAtEnd)
704 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
707 virtual VAArgInst *clone() const;
708 bool mayWriteToMemory() const { return true; }
710 // Methods for support type inquiry through isa, cast, and dyn_cast:
711 static inline bool classof(const VAArgInst *) { return true; }
712 static inline bool classof(const Instruction *I) {
713 return I->getOpcode() == VAArg;
715 static inline bool classof(const Value *V) {
716 return isa<Instruction>(V) && classof(cast<Instruction>(V));
720 //===----------------------------------------------------------------------===//
721 // ExtractElementInst Class
722 //===----------------------------------------------------------------------===//
724 /// ExtractElementInst - This instruction extracts a single (scalar)
725 /// element from a PackedType value
727 class ExtractElementInst : public Instruction {
729 ExtractElementInst(const ExtractElementInst &EE) :
730 Instruction(EE.getType(), ExtractElement, Ops, 2) {
731 Ops[0].init(EE.Ops[0], this);
732 Ops[1].init(EE.Ops[1], this);
736 ExtractElementInst(Value *Val, Value *Index,
737 const std::string &Name = "", Instruction *InsertBefore = 0);
738 ExtractElementInst(Value *Val, Value *Index,
739 const std::string &Name, BasicBlock *InsertAtEnd);
741 virtual ExtractElementInst *clone() const;
743 virtual bool mayWriteToMemory() const { return false; }
745 /// Transparently provide more efficient getOperand methods.
746 Value *getOperand(unsigned i) const {
747 assert(i < 2 && "getOperand() out of range!");
750 void setOperand(unsigned i, Value *Val) {
751 assert(i < 2 && "setOperand() out of range!");
754 unsigned getNumOperands() const { return 2; }
756 // Methods for support type inquiry through isa, cast, and dyn_cast:
757 static inline bool classof(const ExtractElementInst *) { return true; }
758 static inline bool classof(const Instruction *I) {
759 return I->getOpcode() == Instruction::ExtractElement;
761 static inline bool classof(const Value *V) {
762 return isa<Instruction>(V) && classof(cast<Instruction>(V));
766 //===----------------------------------------------------------------------===//
767 // InsertElementInst Class
768 //===----------------------------------------------------------------------===//
770 /// InsertElementInst - This instruction inserts a single (scalar)
771 /// element into a PackedType value
773 class InsertElementInst : public Instruction {
775 InsertElementInst(const InsertElementInst &IE) :
776 Instruction(IE.getType(), InsertElement, Ops, 3) {
777 Ops[0].init(IE.Ops[0], this);
778 Ops[1].init(IE.Ops[1], this);
779 Ops[2].init(IE.Ops[2], this);
783 InsertElementInst(Value *Val, Value *Elt, Value *Index,
784 const std::string &Name = "", Instruction *InsertBefore = 0);
785 InsertElementInst(Value *Val, Value *Elt, Value *Index,
786 const std::string &Name, BasicBlock *InsertAtEnd);
788 virtual InsertElementInst *clone() const;
790 virtual bool mayWriteToMemory() const { return false; }
792 /// Transparently provide more efficient getOperand methods.
793 Value *getOperand(unsigned i) const {
794 assert(i < 3 && "getOperand() out of range!");
797 void setOperand(unsigned i, Value *Val) {
798 assert(i < 3 && "setOperand() out of range!");
801 unsigned getNumOperands() const { return 3; }
803 // Methods for support type inquiry through isa, cast, and dyn_cast:
804 static inline bool classof(const InsertElementInst *) { return true; }
805 static inline bool classof(const Instruction *I) {
806 return I->getOpcode() == Instruction::InsertElement;
808 static inline bool classof(const Value *V) {
809 return isa<Instruction>(V) && classof(cast<Instruction>(V));
813 //===----------------------------------------------------------------------===//
815 //===----------------------------------------------------------------------===//
817 // PHINode - The PHINode class is used to represent the magical mystical PHI
818 // node, that can not exist in nature, but can be synthesized in a computer
819 // scientist's overactive imagination.
821 class PHINode : public Instruction {
822 /// ReservedSpace - The number of operands actually allocated. NumOperands is
823 /// the number actually in use.
824 unsigned ReservedSpace;
825 PHINode(const PHINode &PN);
827 PHINode(const Type *Ty, const std::string &Name = "",
828 Instruction *InsertBefore = 0)
829 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
833 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
834 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
840 /// reserveOperandSpace - This method can be used to avoid repeated
841 /// reallocation of PHI operand lists by reserving space for the correct
842 /// number of operands before adding them. Unlike normal vector reserves,
843 /// this method can also be used to trim the operand space.
844 void reserveOperandSpace(unsigned NumValues) {
845 resizeOperands(NumValues*2);
848 virtual PHINode *clone() const;
850 /// getNumIncomingValues - Return the number of incoming edges
852 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
854 /// getIncomingValue - Return incoming value #x
856 Value *getIncomingValue(unsigned i) const {
857 assert(i*2 < getNumOperands() && "Invalid value number!");
858 return getOperand(i*2);
860 void setIncomingValue(unsigned i, Value *V) {
861 assert(i*2 < getNumOperands() && "Invalid value number!");
864 unsigned getOperandNumForIncomingValue(unsigned i) {
868 /// getIncomingBlock - Return incoming basic block #x
870 BasicBlock *getIncomingBlock(unsigned i) const {
871 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
873 void setIncomingBlock(unsigned i, BasicBlock *BB) {
874 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
876 unsigned getOperandNumForIncomingBlock(unsigned i) {
880 /// addIncoming - Add an incoming value to the end of the PHI list
882 void addIncoming(Value *V, BasicBlock *BB) {
883 assert(getType() == V->getType() &&
884 "All operands to PHI node must be the same type as the PHI node!");
885 unsigned OpNo = NumOperands;
886 if (OpNo+2 > ReservedSpace)
887 resizeOperands(0); // Get more space!
888 // Initialize some new operands.
889 NumOperands = OpNo+2;
890 OperandList[OpNo].init(V, this);
891 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
894 /// removeIncomingValue - Remove an incoming value. This is useful if a
895 /// predecessor basic block is deleted. The value removed is returned.
897 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
898 /// is true), the PHI node is destroyed and any uses of it are replaced with
899 /// dummy values. The only time there should be zero incoming values to a PHI
900 /// node is when the block is dead, so this strategy is sound.
902 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
904 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
905 int Idx = getBasicBlockIndex(BB);
906 assert(Idx >= 0 && "Invalid basic block argument to remove!");
907 return removeIncomingValue(Idx, DeletePHIIfEmpty);
910 /// getBasicBlockIndex - Return the first index of the specified basic
911 /// block in the value list for this PHI. Returns -1 if no instance.
913 int getBasicBlockIndex(const BasicBlock *BB) const {
914 Use *OL = OperandList;
915 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
916 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
920 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
921 return getIncomingValue(getBasicBlockIndex(BB));
924 /// hasConstantValue - If the specified PHI node always merges together the
925 /// same value, return the value, otherwise return null.
927 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
929 /// Methods for support type inquiry through isa, cast, and dyn_cast:
930 static inline bool classof(const PHINode *) { return true; }
931 static inline bool classof(const Instruction *I) {
932 return I->getOpcode() == Instruction::PHI;
934 static inline bool classof(const Value *V) {
935 return isa<Instruction>(V) && classof(cast<Instruction>(V));
938 void resizeOperands(unsigned NumOperands);
941 //===----------------------------------------------------------------------===//
943 //===----------------------------------------------------------------------===//
945 //===---------------------------------------------------------------------------
946 /// ReturnInst - Return a value (possibly void), from a function. Execution
947 /// does not continue in this function any longer.
949 class ReturnInst : public TerminatorInst {
950 Use RetVal; // Possibly null retval.
951 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
952 RI.getNumOperands()) {
953 if (RI.getNumOperands())
954 RetVal.init(RI.RetVal, this);
957 void init(Value *RetVal);
960 // ReturnInst constructors:
961 // ReturnInst() - 'ret void' instruction
962 // ReturnInst( null) - 'ret void' instruction
963 // ReturnInst(Value* X) - 'ret X' instruction
964 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
965 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
966 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
967 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
969 // NOTE: If the Value* passed is of type void then the constructor behaves as
970 // if it was passed NULL.
971 ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
972 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
975 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
976 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
979 ReturnInst(BasicBlock *InsertAtEnd)
980 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
983 virtual ReturnInst *clone() const;
985 // Transparently provide more efficient getOperand methods.
986 Value *getOperand(unsigned i) const {
987 assert(i < getNumOperands() && "getOperand() out of range!");
990 void setOperand(unsigned i, Value *Val) {
991 assert(i < getNumOperands() && "setOperand() out of range!");
995 Value *getReturnValue() const { return RetVal; }
997 unsigned getNumSuccessors() const { return 0; }
999 // Methods for support type inquiry through isa, cast, and dyn_cast:
1000 static inline bool classof(const ReturnInst *) { return true; }
1001 static inline bool classof(const Instruction *I) {
1002 return (I->getOpcode() == Instruction::Ret);
1004 static inline bool classof(const Value *V) {
1005 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1008 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1009 virtual unsigned getNumSuccessorsV() const;
1010 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1013 //===----------------------------------------------------------------------===//
1015 //===----------------------------------------------------------------------===//
1017 //===---------------------------------------------------------------------------
1018 /// BranchInst - Conditional or Unconditional Branch instruction.
1020 class BranchInst : public TerminatorInst {
1021 /// Ops list - Branches are strange. The operands are ordered:
1022 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1023 /// they don't have to check for cond/uncond branchness.
1025 BranchInst(const BranchInst &BI);
1028 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1029 // BranchInst(BB *B) - 'br B'
1030 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1031 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1032 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1033 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1034 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1035 BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1036 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1037 assert(IfTrue != 0 && "Branch destination may not be null!");
1038 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1040 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1041 Instruction *InsertBefore = 0)
1042 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1043 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1044 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1045 Ops[2].init(Cond, this);
1051 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1052 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1053 assert(IfTrue != 0 && "Branch destination may not be null!");
1054 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1057 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1058 BasicBlock *InsertAtEnd)
1059 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1060 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1061 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1062 Ops[2].init(Cond, this);
1069 /// Transparently provide more efficient getOperand methods.
1070 Value *getOperand(unsigned i) const {
1071 assert(i < getNumOperands() && "getOperand() out of range!");
1074 void setOperand(unsigned i, Value *Val) {
1075 assert(i < getNumOperands() && "setOperand() out of range!");
1079 virtual BranchInst *clone() const;
1081 inline bool isUnconditional() const { return getNumOperands() == 1; }
1082 inline bool isConditional() const { return getNumOperands() == 3; }
1084 inline Value *getCondition() const {
1085 assert(isConditional() && "Cannot get condition of an uncond branch!");
1086 return getOperand(2);
1089 void setCondition(Value *V) {
1090 assert(isConditional() && "Cannot set condition of unconditional branch!");
1094 // setUnconditionalDest - Change the current branch to an unconditional branch
1095 // targeting the specified block.
1096 // FIXME: Eliminate this ugly method.
1097 void setUnconditionalDest(BasicBlock *Dest) {
1098 if (isConditional()) { // Convert this to an uncond branch.
1103 setOperand(0, reinterpret_cast<Value*>(Dest));
1106 unsigned getNumSuccessors() const { return 1+isConditional(); }
1108 BasicBlock *getSuccessor(unsigned i) const {
1109 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1110 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1111 cast<BasicBlock>(getOperand(1));
1114 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1115 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1116 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1119 // Methods for support type inquiry through isa, cast, and dyn_cast:
1120 static inline bool classof(const BranchInst *) { return true; }
1121 static inline bool classof(const Instruction *I) {
1122 return (I->getOpcode() == Instruction::Br);
1124 static inline bool classof(const Value *V) {
1125 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1128 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1129 virtual unsigned getNumSuccessorsV() const;
1130 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1133 //===----------------------------------------------------------------------===//
1135 //===----------------------------------------------------------------------===//
1137 //===---------------------------------------------------------------------------
1138 /// SwitchInst - Multiway switch
1140 class SwitchInst : public TerminatorInst {
1141 unsigned ReservedSpace;
1142 // Operand[0] = Value to switch on
1143 // Operand[1] = Default basic block destination
1144 // Operand[2n ] = Value to match
1145 // Operand[2n+1] = BasicBlock to go to on match
1146 SwitchInst(const SwitchInst &RI);
1147 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1148 void resizeOperands(unsigned No);
1150 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1151 /// switch on and a default destination. The number of additional cases can
1152 /// be specified here to make memory allocation more efficient. This
1153 /// constructor can also autoinsert before another instruction.
1154 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1155 Instruction *InsertBefore = 0)
1156 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1157 init(Value, Default, NumCases);
1160 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1161 /// switch on and a default destination. The number of additional cases can
1162 /// be specified here to make memory allocation more efficient. This
1163 /// constructor also autoinserts at the end of the specified BasicBlock.
1164 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1165 BasicBlock *InsertAtEnd)
1166 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1167 init(Value, Default, NumCases);
1172 // Accessor Methods for Switch stmt
1173 inline Value *getCondition() const { return getOperand(0); }
1174 void setCondition(Value *V) { setOperand(0, V); }
1176 inline BasicBlock *getDefaultDest() const {
1177 return cast<BasicBlock>(getOperand(1));
1180 /// getNumCases - return the number of 'cases' in this switch instruction.
1181 /// Note that case #0 is always the default case.
1182 unsigned getNumCases() const {
1183 return getNumOperands()/2;
1186 /// getCaseValue - Return the specified case value. Note that case #0, the
1187 /// default destination, does not have a case value.
1188 ConstantInt *getCaseValue(unsigned i) {
1189 assert(i && i < getNumCases() && "Illegal case value to get!");
1190 return getSuccessorValue(i);
1193 /// getCaseValue - Return the specified case value. Note that case #0, the
1194 /// default destination, does not have a case value.
1195 const ConstantInt *getCaseValue(unsigned i) const {
1196 assert(i && i < getNumCases() && "Illegal case value to get!");
1197 return getSuccessorValue(i);
1200 /// findCaseValue - Search all of the case values for the specified constant.
1201 /// If it is explicitly handled, return the case number of it, otherwise
1202 /// return 0 to indicate that it is handled by the default handler.
1203 unsigned findCaseValue(const ConstantInt *C) const {
1204 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1205 if (getCaseValue(i) == C)
1210 /// addCase - Add an entry to the switch instruction...
1212 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1214 /// removeCase - This method removes the specified successor from the switch
1215 /// instruction. Note that this cannot be used to remove the default
1216 /// destination (successor #0).
1218 void removeCase(unsigned idx);
1220 virtual SwitchInst *clone() const;
1222 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1223 BasicBlock *getSuccessor(unsigned idx) const {
1224 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1225 return cast<BasicBlock>(getOperand(idx*2+1));
1227 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1228 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1229 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1232 // getSuccessorValue - Return the value associated with the specified
1234 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1235 assert(idx < getNumSuccessors() && "Successor # out of range!");
1236 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1239 // Methods for support type inquiry through isa, cast, and dyn_cast:
1240 static inline bool classof(const SwitchInst *) { return true; }
1241 static inline bool classof(const Instruction *I) {
1242 return I->getOpcode() == Instruction::Switch;
1244 static inline bool classof(const Value *V) {
1245 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1248 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1249 virtual unsigned getNumSuccessorsV() const;
1250 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1253 //===----------------------------------------------------------------------===//
1255 //===----------------------------------------------------------------------===//
1257 //===---------------------------------------------------------------------------
1259 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1260 /// calling convention of the call.
1262 class InvokeInst : public TerminatorInst {
1263 InvokeInst(const InvokeInst &BI);
1264 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1265 const std::vector<Value*> &Params);
1267 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1268 const std::vector<Value*> &Params, const std::string &Name = "",
1269 Instruction *InsertBefore = 0);
1270 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1271 const std::vector<Value*> &Params, const std::string &Name,
1272 BasicBlock *InsertAtEnd);
1275 virtual InvokeInst *clone() const;
1277 bool mayWriteToMemory() const { return true; }
1279 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1281 unsigned getCallingConv() const { return SubclassData; }
1282 void setCallingConv(unsigned CC) {
1286 /// getCalledFunction - Return the function called, or null if this is an
1287 /// indirect function invocation.
1289 Function *getCalledFunction() const {
1290 return dyn_cast<Function>(getOperand(0));
1293 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1294 inline Value *getCalledValue() const { return getOperand(0); }
1296 // get*Dest - Return the destination basic blocks...
1297 BasicBlock *getNormalDest() const {
1298 return cast<BasicBlock>(getOperand(1));
1300 BasicBlock *getUnwindDest() const {
1301 return cast<BasicBlock>(getOperand(2));
1303 void setNormalDest(BasicBlock *B) {
1304 setOperand(1, reinterpret_cast<Value*>(B));
1307 void setUnwindDest(BasicBlock *B) {
1308 setOperand(2, reinterpret_cast<Value*>(B));
1311 inline BasicBlock *getSuccessor(unsigned i) const {
1312 assert(i < 2 && "Successor # out of range for invoke!");
1313 return i == 0 ? getNormalDest() : getUnwindDest();
1316 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1317 assert(idx < 2 && "Successor # out of range for invoke!");
1318 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1321 unsigned getNumSuccessors() const { return 2; }
1323 // Methods for support type inquiry through isa, cast, and dyn_cast:
1324 static inline bool classof(const InvokeInst *) { return true; }
1325 static inline bool classof(const Instruction *I) {
1326 return (I->getOpcode() == Instruction::Invoke);
1328 static inline bool classof(const Value *V) {
1329 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1332 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1333 virtual unsigned getNumSuccessorsV() const;
1334 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1338 //===----------------------------------------------------------------------===//
1340 //===----------------------------------------------------------------------===//
1342 //===---------------------------------------------------------------------------
1343 /// UnwindInst - Immediately exit the current function, unwinding the stack
1344 /// until an invoke instruction is found.
1346 class UnwindInst : public TerminatorInst {
1348 UnwindInst(Instruction *InsertBefore = 0)
1349 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1351 UnwindInst(BasicBlock *InsertAtEnd)
1352 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1355 virtual UnwindInst *clone() const;
1357 unsigned getNumSuccessors() const { return 0; }
1359 // Methods for support type inquiry through isa, cast, and dyn_cast:
1360 static inline bool classof(const UnwindInst *) { return true; }
1361 static inline bool classof(const Instruction *I) {
1362 return I->getOpcode() == Instruction::Unwind;
1364 static inline bool classof(const Value *V) {
1365 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1368 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1369 virtual unsigned getNumSuccessorsV() const;
1370 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1373 //===----------------------------------------------------------------------===//
1374 // UnreachableInst Class
1375 //===----------------------------------------------------------------------===//
1377 //===---------------------------------------------------------------------------
1378 /// UnreachableInst - This function has undefined behavior. In particular, the
1379 /// presence of this instruction indicates some higher level knowledge that the
1380 /// end of the block cannot be reached.
1382 class UnreachableInst : public TerminatorInst {
1384 UnreachableInst(Instruction *InsertBefore = 0)
1385 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1387 UnreachableInst(BasicBlock *InsertAtEnd)
1388 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1391 virtual UnreachableInst *clone() const;
1393 unsigned getNumSuccessors() const { return 0; }
1395 // Methods for support type inquiry through isa, cast, and dyn_cast:
1396 static inline bool classof(const UnreachableInst *) { return true; }
1397 static inline bool classof(const Instruction *I) {
1398 return I->getOpcode() == Instruction::Unreachable;
1400 static inline bool classof(const Value *V) {
1401 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1404 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1405 virtual unsigned getNumSuccessorsV() const;
1406 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1409 } // End llvm namespace