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"
29 //===----------------------------------------------------------------------===//
30 // AllocationInst Class
31 //===----------------------------------------------------------------------===//
33 /// AllocationInst - This class is the common base class of MallocInst and
36 class AllocationInst : public UnaryInstruction {
39 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
40 const std::string &Name = "", Instruction *InsertBefore = 0);
41 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
42 const std::string &Name, BasicBlock *InsertAtEnd);
46 /// isArrayAllocation - Return true if there is an allocation size parameter
47 /// to the allocation instruction that is not 1.
49 bool isArrayAllocation() const;
51 /// getArraySize - Get the number of element allocated, for a simple
52 /// allocation of a single element, this will return a constant 1 value.
54 inline const Value *getArraySize() const { return getOperand(0); }
55 inline Value *getArraySize() { return getOperand(0); }
57 /// getType - Overload to return most specific pointer type
59 inline const PointerType *getType() const {
60 return reinterpret_cast<const PointerType*>(Instruction::getType());
63 /// getAllocatedType - Return the type that is being allocated by the
66 const Type *getAllocatedType() const;
68 /// getAlignment - Return the alignment of the memory that is being allocated
69 /// by the instruction.
71 unsigned getAlignment() const { return Alignment; }
72 void setAlignment(unsigned Align) {
73 assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
77 virtual Instruction *clone() const = 0;
79 // Methods for support type inquiry through isa, cast, and dyn_cast:
80 static inline bool classof(const AllocationInst *) { return true; }
81 static inline bool classof(const Instruction *I) {
82 return I->getOpcode() == Instruction::Alloca ||
83 I->getOpcode() == Instruction::Malloc;
85 static inline bool classof(const Value *V) {
86 return isa<Instruction>(V) && classof(cast<Instruction>(V));
91 //===----------------------------------------------------------------------===//
93 //===----------------------------------------------------------------------===//
95 /// MallocInst - an instruction to allocated memory on the heap
97 class MallocInst : public AllocationInst {
98 MallocInst(const MallocInst &MI);
100 explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
101 const std::string &Name = "",
102 Instruction *InsertBefore = 0)
103 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertBefore) {}
104 MallocInst(const Type *Ty, Value *ArraySize, const std::string &Name,
105 BasicBlock *InsertAtEnd)
106 : AllocationInst(Ty, ArraySize, Malloc, 0, Name, InsertAtEnd) {}
107 MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
108 const std::string &Name, BasicBlock *InsertAtEnd)
109 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertAtEnd) {}
110 explicit MallocInst(const Type *Ty, Value *ArraySize, unsigned Align,
111 const std::string &Name = "",
112 Instruction *InsertBefore = 0)
113 : AllocationInst(Ty, ArraySize, Malloc, Align, Name, InsertBefore) {}
115 virtual MallocInst *clone() const;
117 // Methods for support type inquiry through isa, cast, and dyn_cast:
118 static inline bool classof(const MallocInst *) { return true; }
119 static inline bool classof(const Instruction *I) {
120 return (I->getOpcode() == Instruction::Malloc);
122 static inline bool classof(const Value *V) {
123 return isa<Instruction>(V) && classof(cast<Instruction>(V));
128 //===----------------------------------------------------------------------===//
130 //===----------------------------------------------------------------------===//
132 /// AllocaInst - an instruction to allocate memory on the stack
134 class AllocaInst : public AllocationInst {
135 AllocaInst(const AllocaInst &);
137 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
138 const std::string &Name = "",
139 Instruction *InsertBefore = 0)
140 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertBefore) {}
141 AllocaInst(const Type *Ty, Value *ArraySize, const std::string &Name,
142 BasicBlock *InsertAtEnd)
143 : AllocationInst(Ty, ArraySize, Alloca, 0, Name, InsertAtEnd) {}
144 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
145 const std::string &Name, BasicBlock *InsertAtEnd)
146 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertAtEnd) {}
147 explicit AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
148 const std::string &Name = "",
149 Instruction *InsertBefore = 0)
150 : AllocationInst(Ty, ArraySize, Alloca, Align, Name, InsertBefore) {}
152 virtual AllocaInst *clone() const;
154 // Methods for support type inquiry through isa, cast, and dyn_cast:
155 static inline bool classof(const AllocaInst *) { return true; }
156 static inline bool classof(const Instruction *I) {
157 return (I->getOpcode() == Instruction::Alloca);
159 static inline bool classof(const Value *V) {
160 return isa<Instruction>(V) && classof(cast<Instruction>(V));
165 //===----------------------------------------------------------------------===//
167 //===----------------------------------------------------------------------===//
169 /// FreeInst - an instruction to deallocate memory
171 class FreeInst : public UnaryInstruction {
174 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
175 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
177 virtual FreeInst *clone() const;
179 virtual bool mayWriteToMemory() const { return true; }
181 // Methods for support type inquiry through isa, cast, and dyn_cast:
182 static inline bool classof(const FreeInst *) { return true; }
183 static inline bool classof(const Instruction *I) {
184 return (I->getOpcode() == Instruction::Free);
186 static inline bool classof(const Value *V) {
187 return isa<Instruction>(V) && classof(cast<Instruction>(V));
192 //===----------------------------------------------------------------------===//
194 //===----------------------------------------------------------------------===//
196 /// LoadInst - an instruction for reading from memory. This uses the
197 /// SubclassData field in Value to store whether or not the load is volatile.
199 class LoadInst : public UnaryInstruction {
200 LoadInst(const LoadInst &LI)
201 : UnaryInstruction(LI.getType(), Load, LI.getOperand(0)) {
202 setVolatile(LI.isVolatile());
210 LoadInst(Value *Ptr, const std::string &Name, Instruction *InsertBefore);
211 LoadInst(Value *Ptr, const std::string &Name, BasicBlock *InsertAtEnd);
212 LoadInst(Value *Ptr, const std::string &Name = "", bool isVolatile = false,
213 Instruction *InsertBefore = 0);
214 LoadInst(Value *Ptr, const std::string &Name, bool isVolatile,
215 BasicBlock *InsertAtEnd);
217 /// isVolatile - Return true if this is a load from a volatile memory
220 bool isVolatile() const { return SubclassData; }
222 /// setVolatile - Specify whether this is a volatile load or not.
224 void setVolatile(bool V) { SubclassData = V; }
226 virtual LoadInst *clone() const;
228 virtual bool mayWriteToMemory() const { return isVolatile(); }
230 Value *getPointerOperand() { return getOperand(0); }
231 const Value *getPointerOperand() const { return getOperand(0); }
232 static unsigned getPointerOperandIndex() { return 0U; }
234 // Methods for support type inquiry through isa, cast, and dyn_cast:
235 static inline bool classof(const LoadInst *) { return true; }
236 static inline bool classof(const Instruction *I) {
237 return I->getOpcode() == Instruction::Load;
239 static inline bool classof(const Value *V) {
240 return isa<Instruction>(V) && classof(cast<Instruction>(V));
245 //===----------------------------------------------------------------------===//
247 //===----------------------------------------------------------------------===//
249 /// StoreInst - an instruction for storing to memory
251 class StoreInst : public Instruction {
253 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
254 Ops[0].init(SI.Ops[0], this);
255 Ops[1].init(SI.Ops[1], this);
256 setVolatile(SI.isVolatile());
263 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
264 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
265 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
266 Instruction *InsertBefore = 0);
267 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
270 /// isVolatile - Return true if this is a load from a volatile memory
273 bool isVolatile() const { return SubclassData; }
275 /// setVolatile - Specify whether this is a volatile load or not.
277 void setVolatile(bool V) { SubclassData = V; }
279 /// Transparently provide more efficient getOperand methods.
280 Value *getOperand(unsigned i) const {
281 assert(i < 2 && "getOperand() out of range!");
284 void setOperand(unsigned i, Value *Val) {
285 assert(i < 2 && "setOperand() out of range!");
288 unsigned getNumOperands() const { return 2; }
291 virtual StoreInst *clone() const;
293 virtual bool mayWriteToMemory() const { return true; }
295 Value *getPointerOperand() { return getOperand(1); }
296 const Value *getPointerOperand() const { return getOperand(1); }
297 static unsigned getPointerOperandIndex() { return 1U; }
299 // Methods for support type inquiry through isa, cast, and dyn_cast:
300 static inline bool classof(const StoreInst *) { return true; }
301 static inline bool classof(const Instruction *I) {
302 return I->getOpcode() == Instruction::Store;
304 static inline bool classof(const Value *V) {
305 return isa<Instruction>(V) && classof(cast<Instruction>(V));
310 //===----------------------------------------------------------------------===//
311 // GetElementPtrInst Class
312 //===----------------------------------------------------------------------===//
314 /// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
315 /// access elements of arrays and structs
317 class GetElementPtrInst : public Instruction {
318 GetElementPtrInst(const GetElementPtrInst &GEPI)
319 : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
320 0, GEPI.getNumOperands()) {
321 Use *OL = OperandList = new Use[NumOperands];
322 Use *GEPIOL = GEPI.OperandList;
323 for (unsigned i = 0, E = NumOperands; i != E; ++i)
324 OL[i].init(GEPIOL[i], this);
326 void init(Value *Ptr, const std::vector<Value*> &Idx);
327 void init(Value *Ptr, Value *Idx0, Value *Idx1);
328 void init(Value *Ptr, Value *Idx);
330 /// Constructors - Create a getelementptr instruction with a base pointer an
331 /// list of indices. The first ctor can optionally insert before an existing
332 /// instruction, the second appends the new instruction to the specified
334 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
335 const std::string &Name = "", Instruction *InsertBefore =0);
336 GetElementPtrInst(Value *Ptr, const std::vector<Value*> &Idx,
337 const std::string &Name, BasicBlock *InsertAtEnd);
339 /// Constructors - These two constructors are convenience methods because one
340 /// and two index getelementptr instructions are so common.
341 GetElementPtrInst(Value *Ptr, Value *Idx,
342 const std::string &Name = "", Instruction *InsertBefore =0);
343 GetElementPtrInst(Value *Ptr, Value *Idx,
344 const std::string &Name, BasicBlock *InsertAtEnd);
345 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
346 const std::string &Name = "", Instruction *InsertBefore =0);
347 GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
348 const std::string &Name, BasicBlock *InsertAtEnd);
349 ~GetElementPtrInst();
351 virtual GetElementPtrInst *clone() const;
353 // getType - Overload to return most specific pointer type...
354 inline const PointerType *getType() const {
355 return reinterpret_cast<const PointerType*>(Instruction::getType());
358 /// getIndexedType - Returns the type of the element that would be loaded with
359 /// a load instruction with the specified parameters.
361 /// A null type is returned if the indices are invalid for the specified
364 static const Type *getIndexedType(const Type *Ptr,
365 const std::vector<Value*> &Indices,
366 bool AllowStructLeaf = false);
367 static const Type *getIndexedType(const Type *Ptr, Value *Idx0, Value *Idx1,
368 bool AllowStructLeaf = false);
369 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
371 inline op_iterator idx_begin() { return op_begin()+1; }
372 inline const_op_iterator idx_begin() const { return op_begin()+1; }
373 inline op_iterator idx_end() { return op_end(); }
374 inline const_op_iterator idx_end() const { return op_end(); }
376 Value *getPointerOperand() {
377 return getOperand(0);
379 const Value *getPointerOperand() const {
380 return getOperand(0);
382 static unsigned getPointerOperandIndex() {
383 return 0U; // get index for modifying correct operand
386 inline unsigned getNumIndices() const { // Note: always non-negative
387 return getNumOperands() - 1;
390 inline bool hasIndices() const {
391 return getNumOperands() > 1;
394 // Methods for support type inquiry through isa, cast, and dyn_cast:
395 static inline bool classof(const GetElementPtrInst *) { return true; }
396 static inline bool classof(const Instruction *I) {
397 return (I->getOpcode() == Instruction::GetElementPtr);
399 static inline bool classof(const Value *V) {
400 return isa<Instruction>(V) && classof(cast<Instruction>(V));
404 //===----------------------------------------------------------------------===//
406 //===----------------------------------------------------------------------===//
408 /// SetCondInst class - Represent a setCC operator, where CC is eq, ne, lt, gt,
411 class SetCondInst : public BinaryOperator {
413 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
414 const std::string &Name = "", Instruction *InsertBefore = 0);
415 SetCondInst(BinaryOps Opcode, Value *LHS, Value *RHS,
416 const std::string &Name, BasicBlock *InsertAtEnd);
418 /// getInverseCondition - Return the inverse of the current condition opcode.
419 /// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
421 BinaryOps getInverseCondition() const {
422 return getInverseCondition(getOpcode());
425 /// getInverseCondition - Static version that you can use without an
426 /// instruction available.
428 static BinaryOps getInverseCondition(BinaryOps Opcode);
430 /// getSwappedCondition - Return the condition opcode that would be the result
431 /// of exchanging the two operands of the setcc instruction without changing
432 /// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
434 BinaryOps getSwappedCondition() const {
435 return getSwappedCondition(getOpcode());
438 /// getSwappedCondition - Static version that you can use without an
439 /// instruction available.
441 static BinaryOps getSwappedCondition(BinaryOps Opcode);
444 // Methods for support type inquiry through isa, cast, and dyn_cast:
445 static inline bool classof(const SetCondInst *) { return true; }
446 static inline bool classof(const Instruction *I) {
447 return I->getOpcode() == SetEQ || I->getOpcode() == SetNE ||
448 I->getOpcode() == SetLE || I->getOpcode() == SetGE ||
449 I->getOpcode() == SetLT || I->getOpcode() == SetGT;
451 static inline bool classof(const Value *V) {
452 return isa<Instruction>(V) && classof(cast<Instruction>(V));
456 //===----------------------------------------------------------------------===//
458 //===----------------------------------------------------------------------===//
460 /// CastInst - This class represents a cast from Operand[0] to the type of
461 /// the instruction (i->getType()).
463 class CastInst : public UnaryInstruction {
464 CastInst(const CastInst &CI)
465 : UnaryInstruction(CI.getType(), Cast, CI.getOperand(0)) {
468 CastInst(Value *S, const Type *Ty, const std::string &Name = "",
469 Instruction *InsertBefore = 0)
470 : UnaryInstruction(Ty, Cast, S, Name, InsertBefore) {
472 CastInst(Value *S, const Type *Ty, const std::string &Name,
473 BasicBlock *InsertAtEnd)
474 : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) {
477 virtual CastInst *clone() const;
479 // Methods for support type inquiry through isa, cast, and dyn_cast:
480 static inline bool classof(const CastInst *) { return true; }
481 static inline bool classof(const Instruction *I) {
482 return I->getOpcode() == Cast;
484 static inline bool classof(const Value *V) {
485 return isa<Instruction>(V) && classof(cast<Instruction>(V));
490 //===----------------------------------------------------------------------===//
492 //===----------------------------------------------------------------------===//
494 /// CallInst - This class represents a function call, abstracting a target
495 /// machine's calling convention. This class uses low bit of the SubClassData
496 /// field to indicate whether or not this is a tail call. The rest of the bits
497 /// hold the calling convention of the call.
499 class CallInst : public Instruction {
500 CallInst(const CallInst &CI);
501 void init(Value *Func, const std::vector<Value*> &Params);
502 void init(Value *Func, Value *Actual1, Value *Actual2);
503 void init(Value *Func, Value *Actual);
504 void init(Value *Func);
507 CallInst(Value *F, const std::vector<Value*> &Par,
508 const std::string &Name = "", Instruction *InsertBefore = 0);
509 CallInst(Value *F, const std::vector<Value*> &Par,
510 const std::string &Name, BasicBlock *InsertAtEnd);
512 // Alternate CallInst ctors w/ two actuals, w/ one actual and no
513 // actuals, respectively.
514 CallInst(Value *F, Value *Actual1, Value *Actual2,
515 const std::string& Name = "", Instruction *InsertBefore = 0);
516 CallInst(Value *F, Value *Actual1, Value *Actual2,
517 const std::string& Name, BasicBlock *InsertAtEnd);
518 CallInst(Value *F, Value *Actual, const std::string& Name = "",
519 Instruction *InsertBefore = 0);
520 CallInst(Value *F, Value *Actual, const std::string& Name,
521 BasicBlock *InsertAtEnd);
522 explicit CallInst(Value *F, const std::string &Name = "",
523 Instruction *InsertBefore = 0);
524 explicit CallInst(Value *F, const std::string &Name,
525 BasicBlock *InsertAtEnd);
528 virtual CallInst *clone() const;
529 bool mayWriteToMemory() const { return true; }
531 bool isTailCall() const { return SubclassData & 1; }
532 void setTailCall(bool isTailCall = true) {
533 SubclassData = (SubclassData & ~1) | unsigned(isTailCall);
536 /// getCallingConv/setCallingConv - Get or set the calling convention of this
538 unsigned getCallingConv() const { return SubclassData >> 1; }
539 void setCallingConv(unsigned CC) {
540 SubclassData = (SubclassData & 1) | (CC << 1);
543 /// getCalledFunction - Return the function being called by this instruction
544 /// if it is a direct call. If it is a call through a function pointer,
546 Function *getCalledFunction() const {
547 return static_cast<Function*>(dyn_cast<Function>(getOperand(0)));
550 // getCalledValue - Get a pointer to a method that is invoked by this inst.
551 inline const Value *getCalledValue() const { return getOperand(0); }
552 inline Value *getCalledValue() { return getOperand(0); }
554 // Methods for support type inquiry through isa, cast, and dyn_cast:
555 static inline bool classof(const CallInst *) { return true; }
556 static inline bool classof(const Instruction *I) {
557 return I->getOpcode() == Instruction::Call;
559 static inline bool classof(const Value *V) {
560 return isa<Instruction>(V) && classof(cast<Instruction>(V));
565 //===----------------------------------------------------------------------===//
567 //===----------------------------------------------------------------------===//
569 /// ShiftInst - This class represents left and right shift instructions.
571 class ShiftInst : public Instruction {
573 ShiftInst(const ShiftInst &SI)
574 : Instruction(SI.getType(), SI.getOpcode(), Ops, 2) {
575 Ops[0].init(SI.Ops[0], this);
576 Ops[1].init(SI.Ops[1], this);
578 void init(OtherOps Opcode, Value *S, Value *SA) {
579 assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
580 Ops[0].init(S, this);
581 Ops[1].init(SA, this);
585 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
586 Instruction *InsertBefore = 0)
587 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertBefore) {
590 ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name,
591 BasicBlock *InsertAtEnd)
592 : Instruction(S->getType(), Opcode, Ops, 2, Name, InsertAtEnd) {
596 OtherOps getOpcode() const {
597 return static_cast<OtherOps>(Instruction::getOpcode());
600 /// Transparently provide more efficient getOperand methods.
601 Value *getOperand(unsigned i) const {
602 assert(i < 2 && "getOperand() out of range!");
605 void setOperand(unsigned i, Value *Val) {
606 assert(i < 2 && "setOperand() out of range!");
609 unsigned getNumOperands() const { return 2; }
611 virtual ShiftInst *clone() const;
613 // Methods for support type inquiry through isa, cast, and dyn_cast:
614 static inline bool classof(const ShiftInst *) { return true; }
615 static inline bool classof(const Instruction *I) {
616 return (I->getOpcode() == Instruction::Shr) |
617 (I->getOpcode() == Instruction::Shl);
619 static inline bool classof(const Value *V) {
620 return isa<Instruction>(V) && classof(cast<Instruction>(V));
624 //===----------------------------------------------------------------------===//
626 //===----------------------------------------------------------------------===//
628 /// SelectInst - This class represents the LLVM 'select' instruction.
630 class SelectInst : public Instruction {
633 void init(Value *C, Value *S1, Value *S2) {
634 Ops[0].init(C, this);
635 Ops[1].init(S1, this);
636 Ops[2].init(S2, this);
639 SelectInst(const SelectInst &SI)
640 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
641 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
644 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
645 Instruction *InsertBefore = 0)
646 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
647 Name, InsertBefore) {
650 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name,
651 BasicBlock *InsertAtEnd)
652 : Instruction(S1->getType(), Instruction::Select, Ops, 3,
657 Value *getCondition() const { return Ops[0]; }
658 Value *getTrueValue() const { return Ops[1]; }
659 Value *getFalseValue() const { return Ops[2]; }
661 /// Transparently provide more efficient getOperand methods.
662 Value *getOperand(unsigned i) const {
663 assert(i < 3 && "getOperand() out of range!");
666 void setOperand(unsigned i, Value *Val) {
667 assert(i < 3 && "setOperand() out of range!");
670 unsigned getNumOperands() const { return 3; }
672 OtherOps getOpcode() const {
673 return static_cast<OtherOps>(Instruction::getOpcode());
676 virtual SelectInst *clone() const;
678 // Methods for support type inquiry through isa, cast, and dyn_cast:
679 static inline bool classof(const SelectInst *) { return true; }
680 static inline bool classof(const Instruction *I) {
681 return I->getOpcode() == Instruction::Select;
683 static inline bool classof(const Value *V) {
684 return isa<Instruction>(V) && classof(cast<Instruction>(V));
688 //===----------------------------------------------------------------------===//
690 //===----------------------------------------------------------------------===//
692 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
693 /// an argument of the specified type given a va_list and increments that list
695 class VAArgInst : public UnaryInstruction {
696 VAArgInst(const VAArgInst &VAA)
697 : UnaryInstruction(VAA.getType(), VAArg, VAA.getOperand(0)) {}
699 VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
700 Instruction *InsertBefore = 0)
701 : UnaryInstruction(Ty, VAArg, List, Name, InsertBefore) {
703 VAArgInst(Value *List, const Type *Ty, const std::string &Name,
704 BasicBlock *InsertAtEnd)
705 : UnaryInstruction(Ty, VAArg, List, Name, InsertAtEnd) {
708 virtual VAArgInst *clone() const;
709 bool mayWriteToMemory() const { return true; }
711 // Methods for support type inquiry through isa, cast, and dyn_cast:
712 static inline bool classof(const VAArgInst *) { return true; }
713 static inline bool classof(const Instruction *I) {
714 return I->getOpcode() == VAArg;
716 static inline bool classof(const Value *V) {
717 return isa<Instruction>(V) && classof(cast<Instruction>(V));
721 //===----------------------------------------------------------------------===//
722 // ExtractElementInst Class
723 //===----------------------------------------------------------------------===//
725 /// ExtractElementInst - This instruction extracts a single (scalar)
726 /// element from a PackedType value
728 class ExtractElementInst : public Instruction {
730 ExtractElementInst(const ExtractElementInst &EE) :
731 Instruction(EE.getType(), ExtractElement, Ops, 2) {
732 Ops[0].init(EE.Ops[0], this);
733 Ops[1].init(EE.Ops[1], this);
737 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
738 Instruction *InsertBefore = 0);
739 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name,
740 BasicBlock *InsertAtEnd);
742 /// isValidOperands - Return true if an extractelement instruction can be
743 /// formed with the specified operands.
744 static bool isValidOperands(const Value *Vec, const Value *Idx);
746 virtual ExtractElementInst *clone() const;
748 virtual bool mayWriteToMemory() const { return false; }
750 /// Transparently provide more efficient getOperand methods.
751 Value *getOperand(unsigned i) const {
752 assert(i < 2 && "getOperand() out of range!");
755 void setOperand(unsigned i, Value *Val) {
756 assert(i < 2 && "setOperand() out of range!");
759 unsigned getNumOperands() const { return 2; }
761 // Methods for support type inquiry through isa, cast, and dyn_cast:
762 static inline bool classof(const ExtractElementInst *) { return true; }
763 static inline bool classof(const Instruction *I) {
764 return I->getOpcode() == Instruction::ExtractElement;
766 static inline bool classof(const Value *V) {
767 return isa<Instruction>(V) && classof(cast<Instruction>(V));
771 //===----------------------------------------------------------------------===//
772 // InsertElementInst Class
773 //===----------------------------------------------------------------------===//
775 /// InsertElementInst - This instruction inserts a single (scalar)
776 /// element into a PackedType value
778 class InsertElementInst : public Instruction {
780 InsertElementInst(const InsertElementInst &IE);
782 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
783 const std::string &Name = "",Instruction *InsertBefore = 0);
784 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
785 const std::string &Name, BasicBlock *InsertAtEnd);
787 /// isValidOperands - Return true if an insertelement instruction can be
788 /// formed with the specified operands.
789 static bool isValidOperands(const Value *Vec, const Value *NewElt,
792 virtual InsertElementInst *clone() const;
794 virtual bool mayWriteToMemory() const { return false; }
796 /// getType - Overload to return most specific packed type.
798 inline const PackedType *getType() const {
799 return reinterpret_cast<const PackedType*>(Instruction::getType());
802 /// Transparently provide more efficient getOperand methods.
803 Value *getOperand(unsigned i) const {
804 assert(i < 3 && "getOperand() out of range!");
807 void setOperand(unsigned i, Value *Val) {
808 assert(i < 3 && "setOperand() out of range!");
811 unsigned getNumOperands() const { return 3; }
813 // Methods for support type inquiry through isa, cast, and dyn_cast:
814 static inline bool classof(const InsertElementInst *) { return true; }
815 static inline bool classof(const Instruction *I) {
816 return I->getOpcode() == Instruction::InsertElement;
818 static inline bool classof(const Value *V) {
819 return isa<Instruction>(V) && classof(cast<Instruction>(V));
823 //===----------------------------------------------------------------------===//
824 // ShuffleVectorInst Class
825 //===----------------------------------------------------------------------===//
827 /// ShuffleVectorInst - This instruction constructs a fixed permutation of two
830 class ShuffleVectorInst : public Instruction {
832 ShuffleVectorInst(const ShuffleVectorInst &IE);
834 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
835 const std::string &Name = "", Instruction *InsertBefor = 0);
836 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
837 const std::string &Name, BasicBlock *InsertAtEnd);
839 /// isValidOperands - Return true if a shufflevector instruction can be
840 /// formed with the specified operands.
841 static bool isValidOperands(const Value *V1, const Value *V2,
844 virtual ShuffleVectorInst *clone() const;
846 virtual bool mayWriteToMemory() const { return false; }
848 /// getType - Overload to return most specific packed type.
850 inline const PackedType *getType() const {
851 return reinterpret_cast<const PackedType*>(Instruction::getType());
854 /// Transparently provide more efficient getOperand methods.
855 Value *getOperand(unsigned i) const {
856 assert(i < 3 && "getOperand() out of range!");
859 void setOperand(unsigned i, Value *Val) {
860 assert(i < 3 && "setOperand() out of range!");
863 unsigned getNumOperands() const { return 3; }
865 // Methods for support type inquiry through isa, cast, and dyn_cast:
866 static inline bool classof(const ShuffleVectorInst *) { return true; }
867 static inline bool classof(const Instruction *I) {
868 return I->getOpcode() == Instruction::ShuffleVector;
870 static inline bool classof(const Value *V) {
871 return isa<Instruction>(V) && classof(cast<Instruction>(V));
876 //===----------------------------------------------------------------------===//
878 //===----------------------------------------------------------------------===//
880 // PHINode - The PHINode class is used to represent the magical mystical PHI
881 // node, that can not exist in nature, but can be synthesized in a computer
882 // scientist's overactive imagination.
884 class PHINode : public Instruction {
885 /// ReservedSpace - The number of operands actually allocated. NumOperands is
886 /// the number actually in use.
887 unsigned ReservedSpace;
888 PHINode(const PHINode &PN);
890 PHINode(const Type *Ty, const std::string &Name = "",
891 Instruction *InsertBefore = 0)
892 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertBefore),
896 PHINode(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd)
897 : Instruction(Ty, Instruction::PHI, 0, 0, Name, InsertAtEnd),
903 /// reserveOperandSpace - This method can be used to avoid repeated
904 /// reallocation of PHI operand lists by reserving space for the correct
905 /// number of operands before adding them. Unlike normal vector reserves,
906 /// this method can also be used to trim the operand space.
907 void reserveOperandSpace(unsigned NumValues) {
908 resizeOperands(NumValues*2);
911 virtual PHINode *clone() const;
913 /// getNumIncomingValues - Return the number of incoming edges
915 unsigned getNumIncomingValues() const { return getNumOperands()/2; }
917 /// getIncomingValue - Return incoming value #x
919 Value *getIncomingValue(unsigned i) const {
920 assert(i*2 < getNumOperands() && "Invalid value number!");
921 return getOperand(i*2);
923 void setIncomingValue(unsigned i, Value *V) {
924 assert(i*2 < getNumOperands() && "Invalid value number!");
927 unsigned getOperandNumForIncomingValue(unsigned i) {
931 /// getIncomingBlock - Return incoming basic block #x
933 BasicBlock *getIncomingBlock(unsigned i) const {
934 return reinterpret_cast<BasicBlock*>(getOperand(i*2+1));
936 void setIncomingBlock(unsigned i, BasicBlock *BB) {
937 setOperand(i*2+1, reinterpret_cast<Value*>(BB));
939 unsigned getOperandNumForIncomingBlock(unsigned i) {
943 /// addIncoming - Add an incoming value to the end of the PHI list
945 void addIncoming(Value *V, BasicBlock *BB) {
946 assert(getType() == V->getType() &&
947 "All operands to PHI node must be the same type as the PHI node!");
948 unsigned OpNo = NumOperands;
949 if (OpNo+2 > ReservedSpace)
950 resizeOperands(0); // Get more space!
951 // Initialize some new operands.
952 NumOperands = OpNo+2;
953 OperandList[OpNo].init(V, this);
954 OperandList[OpNo+1].init(reinterpret_cast<Value*>(BB), this);
957 /// removeIncomingValue - Remove an incoming value. This is useful if a
958 /// predecessor basic block is deleted. The value removed is returned.
960 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
961 /// is true), the PHI node is destroyed and any uses of it are replaced with
962 /// dummy values. The only time there should be zero incoming values to a PHI
963 /// node is when the block is dead, so this strategy is sound.
965 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
967 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){
968 int Idx = getBasicBlockIndex(BB);
969 assert(Idx >= 0 && "Invalid basic block argument to remove!");
970 return removeIncomingValue(Idx, DeletePHIIfEmpty);
973 /// getBasicBlockIndex - Return the first index of the specified basic
974 /// block in the value list for this PHI. Returns -1 if no instance.
976 int getBasicBlockIndex(const BasicBlock *BB) const {
977 Use *OL = OperandList;
978 for (unsigned i = 0, e = getNumOperands(); i != e; i += 2)
979 if (OL[i+1] == reinterpret_cast<const Value*>(BB)) return i/2;
983 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
984 return getIncomingValue(getBasicBlockIndex(BB));
987 /// hasConstantValue - If the specified PHI node always merges together the
988 /// same value, return the value, otherwise return null.
990 Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const;
992 /// Methods for support type inquiry through isa, cast, and dyn_cast:
993 static inline bool classof(const PHINode *) { return true; }
994 static inline bool classof(const Instruction *I) {
995 return I->getOpcode() == Instruction::PHI;
997 static inline bool classof(const Value *V) {
998 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1001 void resizeOperands(unsigned NumOperands);
1004 //===----------------------------------------------------------------------===//
1006 //===----------------------------------------------------------------------===//
1008 //===---------------------------------------------------------------------------
1009 /// ReturnInst - Return a value (possibly void), from a function. Execution
1010 /// does not continue in this function any longer.
1012 class ReturnInst : public TerminatorInst {
1013 Use RetVal; // Possibly null retval.
1014 ReturnInst(const ReturnInst &RI) : TerminatorInst(Instruction::Ret, &RetVal,
1015 RI.getNumOperands()) {
1016 if (RI.getNumOperands())
1017 RetVal.init(RI.RetVal, this);
1020 void init(Value *RetVal);
1023 // ReturnInst constructors:
1024 // ReturnInst() - 'ret void' instruction
1025 // ReturnInst( null) - 'ret void' instruction
1026 // ReturnInst(Value* X) - 'ret X' instruction
1027 // ReturnInst( null, Inst *) - 'ret void' instruction, insert before I
1028 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
1029 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of BB
1030 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of BB
1032 // NOTE: If the Value* passed is of type void then the constructor behaves as
1033 // if it was passed NULL.
1034 ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0)
1035 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertBefore) {
1038 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd)
1039 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1042 ReturnInst(BasicBlock *InsertAtEnd)
1043 : TerminatorInst(Instruction::Ret, &RetVal, 0, InsertAtEnd) {
1046 virtual ReturnInst *clone() const;
1048 // Transparently provide more efficient getOperand methods.
1049 Value *getOperand(unsigned i) const {
1050 assert(i < getNumOperands() && "getOperand() out of range!");
1053 void setOperand(unsigned i, Value *Val) {
1054 assert(i < getNumOperands() && "setOperand() out of range!");
1058 Value *getReturnValue() const { return RetVal; }
1060 unsigned getNumSuccessors() const { return 0; }
1062 // Methods for support type inquiry through isa, cast, and dyn_cast:
1063 static inline bool classof(const ReturnInst *) { return true; }
1064 static inline bool classof(const Instruction *I) {
1065 return (I->getOpcode() == Instruction::Ret);
1067 static inline bool classof(const Value *V) {
1068 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1071 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1072 virtual unsigned getNumSuccessorsV() const;
1073 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1076 //===----------------------------------------------------------------------===//
1078 //===----------------------------------------------------------------------===//
1080 //===---------------------------------------------------------------------------
1081 /// BranchInst - Conditional or Unconditional Branch instruction.
1083 class BranchInst : public TerminatorInst {
1084 /// Ops list - Branches are strange. The operands are ordered:
1085 /// TrueDest, FalseDest, Cond. This makes some accessors faster because
1086 /// they don't have to check for cond/uncond branchness.
1088 BranchInst(const BranchInst &BI);
1091 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
1092 // BranchInst(BB *B) - 'br B'
1093 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
1094 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
1095 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
1096 // BranchInst(BB* B, BB *I) - 'br B' insert at end
1097 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
1098 BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = 0)
1099 : TerminatorInst(Instruction::Br, Ops, 1, InsertBefore) {
1100 assert(IfTrue != 0 && "Branch destination may not be null!");
1101 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1103 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1104 Instruction *InsertBefore = 0)
1105 : TerminatorInst(Instruction::Br, Ops, 3, InsertBefore) {
1106 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1107 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1108 Ops[2].init(Cond, this);
1114 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
1115 : TerminatorInst(Instruction::Br, Ops, 1, InsertAtEnd) {
1116 assert(IfTrue != 0 && "Branch destination may not be null!");
1117 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1120 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1121 BasicBlock *InsertAtEnd)
1122 : TerminatorInst(Instruction::Br, Ops, 3, InsertAtEnd) {
1123 Ops[0].init(reinterpret_cast<Value*>(IfTrue), this);
1124 Ops[1].init(reinterpret_cast<Value*>(IfFalse), this);
1125 Ops[2].init(Cond, this);
1132 /// Transparently provide more efficient getOperand methods.
1133 Value *getOperand(unsigned i) const {
1134 assert(i < getNumOperands() && "getOperand() out of range!");
1137 void setOperand(unsigned i, Value *Val) {
1138 assert(i < getNumOperands() && "setOperand() out of range!");
1142 virtual BranchInst *clone() const;
1144 inline bool isUnconditional() const { return getNumOperands() == 1; }
1145 inline bool isConditional() const { return getNumOperands() == 3; }
1147 inline Value *getCondition() const {
1148 assert(isConditional() && "Cannot get condition of an uncond branch!");
1149 return getOperand(2);
1152 void setCondition(Value *V) {
1153 assert(isConditional() && "Cannot set condition of unconditional branch!");
1157 // setUnconditionalDest - Change the current branch to an unconditional branch
1158 // targeting the specified block.
1159 // FIXME: Eliminate this ugly method.
1160 void setUnconditionalDest(BasicBlock *Dest) {
1161 if (isConditional()) { // Convert this to an uncond branch.
1166 setOperand(0, reinterpret_cast<Value*>(Dest));
1169 unsigned getNumSuccessors() const { return 1+isConditional(); }
1171 BasicBlock *getSuccessor(unsigned i) const {
1172 assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
1173 return (i == 0) ? cast<BasicBlock>(getOperand(0)) :
1174 cast<BasicBlock>(getOperand(1));
1177 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1178 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
1179 setOperand(idx, reinterpret_cast<Value*>(NewSucc));
1182 // Methods for support type inquiry through isa, cast, and dyn_cast:
1183 static inline bool classof(const BranchInst *) { return true; }
1184 static inline bool classof(const Instruction *I) {
1185 return (I->getOpcode() == Instruction::Br);
1187 static inline bool classof(const Value *V) {
1188 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1191 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1192 virtual unsigned getNumSuccessorsV() const;
1193 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1196 //===----------------------------------------------------------------------===//
1198 //===----------------------------------------------------------------------===//
1200 //===---------------------------------------------------------------------------
1201 /// SwitchInst - Multiway switch
1203 class SwitchInst : public TerminatorInst {
1204 unsigned ReservedSpace;
1205 // Operand[0] = Value to switch on
1206 // Operand[1] = Default basic block destination
1207 // Operand[2n ] = Value to match
1208 // Operand[2n+1] = BasicBlock to go to on match
1209 SwitchInst(const SwitchInst &RI);
1210 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
1211 void resizeOperands(unsigned No);
1213 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1214 /// switch on and a default destination. The number of additional cases can
1215 /// be specified here to make memory allocation more efficient. This
1216 /// constructor can also autoinsert before another instruction.
1217 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1218 Instruction *InsertBefore = 0)
1219 : TerminatorInst(Instruction::Switch, 0, 0, InsertBefore) {
1220 init(Value, Default, NumCases);
1223 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
1224 /// switch on and a default destination. The number of additional cases can
1225 /// be specified here to make memory allocation more efficient. This
1226 /// constructor also autoinserts at the end of the specified BasicBlock.
1227 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
1228 BasicBlock *InsertAtEnd)
1229 : TerminatorInst(Instruction::Switch, 0, 0, InsertAtEnd) {
1230 init(Value, Default, NumCases);
1235 // Accessor Methods for Switch stmt
1236 inline Value *getCondition() const { return getOperand(0); }
1237 void setCondition(Value *V) { setOperand(0, V); }
1239 inline BasicBlock *getDefaultDest() const {
1240 return cast<BasicBlock>(getOperand(1));
1243 /// getNumCases - return the number of 'cases' in this switch instruction.
1244 /// Note that case #0 is always the default case.
1245 unsigned getNumCases() const {
1246 return getNumOperands()/2;
1249 /// getCaseValue - Return the specified case value. Note that case #0, the
1250 /// default destination, does not have a case value.
1251 ConstantInt *getCaseValue(unsigned i) {
1252 assert(i && i < getNumCases() && "Illegal case value to get!");
1253 return getSuccessorValue(i);
1256 /// getCaseValue - Return the specified case value. Note that case #0, the
1257 /// default destination, does not have a case value.
1258 const ConstantInt *getCaseValue(unsigned i) const {
1259 assert(i && i < getNumCases() && "Illegal case value to get!");
1260 return getSuccessorValue(i);
1263 /// findCaseValue - Search all of the case values for the specified constant.
1264 /// If it is explicitly handled, return the case number of it, otherwise
1265 /// return 0 to indicate that it is handled by the default handler.
1266 unsigned findCaseValue(const ConstantInt *C) const {
1267 for (unsigned i = 1, e = getNumCases(); i != e; ++i)
1268 if (getCaseValue(i) == C)
1273 /// addCase - Add an entry to the switch instruction...
1275 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
1277 /// removeCase - This method removes the specified successor from the switch
1278 /// instruction. Note that this cannot be used to remove the default
1279 /// destination (successor #0).
1281 void removeCase(unsigned idx);
1283 virtual SwitchInst *clone() const;
1285 unsigned getNumSuccessors() const { return getNumOperands()/2; }
1286 BasicBlock *getSuccessor(unsigned idx) const {
1287 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
1288 return cast<BasicBlock>(getOperand(idx*2+1));
1290 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1291 assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
1292 setOperand(idx*2+1, reinterpret_cast<Value*>(NewSucc));
1295 // getSuccessorValue - Return the value associated with the specified
1297 inline ConstantInt *getSuccessorValue(unsigned idx) const {
1298 assert(idx < getNumSuccessors() && "Successor # out of range!");
1299 return reinterpret_cast<ConstantInt*>(getOperand(idx*2));
1302 // Methods for support type inquiry through isa, cast, and dyn_cast:
1303 static inline bool classof(const SwitchInst *) { return true; }
1304 static inline bool classof(const Instruction *I) {
1305 return I->getOpcode() == Instruction::Switch;
1307 static inline bool classof(const Value *V) {
1308 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1311 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1312 virtual unsigned getNumSuccessorsV() const;
1313 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1316 //===----------------------------------------------------------------------===//
1318 //===----------------------------------------------------------------------===//
1320 //===---------------------------------------------------------------------------
1322 /// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
1323 /// calling convention of the call.
1325 class InvokeInst : public TerminatorInst {
1326 InvokeInst(const InvokeInst &BI);
1327 void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1328 const std::vector<Value*> &Params);
1330 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1331 const std::vector<Value*> &Params, const std::string &Name = "",
1332 Instruction *InsertBefore = 0);
1333 InvokeInst(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
1334 const std::vector<Value*> &Params, const std::string &Name,
1335 BasicBlock *InsertAtEnd);
1338 virtual InvokeInst *clone() const;
1340 bool mayWriteToMemory() const { return true; }
1342 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1344 unsigned getCallingConv() const { return SubclassData; }
1345 void setCallingConv(unsigned CC) {
1349 /// getCalledFunction - Return the function called, or null if this is an
1350 /// indirect function invocation.
1352 Function *getCalledFunction() const {
1353 return dyn_cast<Function>(getOperand(0));
1356 // getCalledValue - Get a pointer to a function that is invoked by this inst.
1357 inline Value *getCalledValue() const { return getOperand(0); }
1359 // get*Dest - Return the destination basic blocks...
1360 BasicBlock *getNormalDest() const {
1361 return cast<BasicBlock>(getOperand(1));
1363 BasicBlock *getUnwindDest() const {
1364 return cast<BasicBlock>(getOperand(2));
1366 void setNormalDest(BasicBlock *B) {
1367 setOperand(1, reinterpret_cast<Value*>(B));
1370 void setUnwindDest(BasicBlock *B) {
1371 setOperand(2, reinterpret_cast<Value*>(B));
1374 inline BasicBlock *getSuccessor(unsigned i) const {
1375 assert(i < 2 && "Successor # out of range for invoke!");
1376 return i == 0 ? getNormalDest() : getUnwindDest();
1379 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
1380 assert(idx < 2 && "Successor # out of range for invoke!");
1381 setOperand(idx+1, reinterpret_cast<Value*>(NewSucc));
1384 unsigned getNumSuccessors() const { return 2; }
1386 // Methods for support type inquiry through isa, cast, and dyn_cast:
1387 static inline bool classof(const InvokeInst *) { return true; }
1388 static inline bool classof(const Instruction *I) {
1389 return (I->getOpcode() == Instruction::Invoke);
1391 static inline bool classof(const Value *V) {
1392 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1395 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1396 virtual unsigned getNumSuccessorsV() const;
1397 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1401 //===----------------------------------------------------------------------===//
1403 //===----------------------------------------------------------------------===//
1405 //===---------------------------------------------------------------------------
1406 /// UnwindInst - Immediately exit the current function, unwinding the stack
1407 /// until an invoke instruction is found.
1409 class UnwindInst : public TerminatorInst {
1411 UnwindInst(Instruction *InsertBefore = 0)
1412 : TerminatorInst(Instruction::Unwind, 0, 0, InsertBefore) {
1414 UnwindInst(BasicBlock *InsertAtEnd)
1415 : TerminatorInst(Instruction::Unwind, 0, 0, InsertAtEnd) {
1418 virtual UnwindInst *clone() const;
1420 unsigned getNumSuccessors() const { return 0; }
1422 // Methods for support type inquiry through isa, cast, and dyn_cast:
1423 static inline bool classof(const UnwindInst *) { return true; }
1424 static inline bool classof(const Instruction *I) {
1425 return I->getOpcode() == Instruction::Unwind;
1427 static inline bool classof(const Value *V) {
1428 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1431 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1432 virtual unsigned getNumSuccessorsV() const;
1433 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1436 //===----------------------------------------------------------------------===//
1437 // UnreachableInst Class
1438 //===----------------------------------------------------------------------===//
1440 //===---------------------------------------------------------------------------
1441 /// UnreachableInst - This function has undefined behavior. In particular, the
1442 /// presence of this instruction indicates some higher level knowledge that the
1443 /// end of the block cannot be reached.
1445 class UnreachableInst : public TerminatorInst {
1447 UnreachableInst(Instruction *InsertBefore = 0)
1448 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertBefore) {
1450 UnreachableInst(BasicBlock *InsertAtEnd)
1451 : TerminatorInst(Instruction::Unreachable, 0, 0, InsertAtEnd) {
1454 virtual UnreachableInst *clone() const;
1456 unsigned getNumSuccessors() const { return 0; }
1458 // Methods for support type inquiry through isa, cast, and dyn_cast:
1459 static inline bool classof(const UnreachableInst *) { return true; }
1460 static inline bool classof(const Instruction *I) {
1461 return I->getOpcode() == Instruction::Unreachable;
1463 static inline bool classof(const Value *V) {
1464 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1467 virtual BasicBlock *getSuccessorV(unsigned idx) const;
1468 virtual unsigned getNumSuccessorsV() const;
1469 virtual void setSuccessorV(unsigned idx, BasicBlock *B);
1472 } // End llvm namespace