1 //===-- llvm/InstrTypes.h - Important Instruction subclasses -----*- C++ -*--=//
3 // This file defines various meta classes of instructions that exist in the VM
4 // representation. Specific concrete subclasses of these may be found in the
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_INSTRUCTION_TYPES_H
10 #define LLVM_INSTRUCTION_TYPES_H
12 #include "llvm/Instruction.h"
14 //===----------------------------------------------------------------------===//
15 // TerminatorInst Class
16 //===----------------------------------------------------------------------===//
18 // TerminatorInst - Subclasses of this class are all able to terminate a basic
19 // block. Thus, these are all the flow control type of operations.
21 class TerminatorInst : public Instruction {
23 TerminatorInst(Instruction::TermOps iType);
24 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
25 const std::string &Name = "");
28 // Terminators must implement the methods required by Instruction...
29 virtual Instruction *clone() const = 0;
31 // Additionally, they must provide a method to get at the successors of this
32 // terminator instruction. 'idx' may not be >= the number of successors
33 // returned by getNumSuccessors()!
35 virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
36 virtual unsigned getNumSuccessors() const = 0;
38 // Set a successor at a given index
39 virtual void setSuccessor(unsigned idx, BasicBlock *B) = 0;
41 inline BasicBlock *getSuccessor(unsigned idx) {
42 return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
45 // Methods for support type inquiry through isa, cast, and dyn_cast:
46 static inline bool classof(const TerminatorInst *) { return true; }
47 static inline bool classof(const Instruction *I) {
48 return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps;
50 static inline bool classof(const Value *V) {
51 return isa<Instruction>(V) && classof(cast<Instruction>(V));
56 //===----------------------------------------------------------------------===//
57 // UnaryOperator Class
58 //===----------------------------------------------------------------------===//
60 class UnaryOperator : public Instruction {
62 UnaryOperator(Value *S, UnaryOps iType, const std::string &Name = "")
63 : Instruction(S->getType(), iType, Name) {
65 Operands.push_back(Use(S, this));
69 // create() - Construct a unary instruction, given the opcode
72 static UnaryOperator *create(UnaryOps Op, Value *Source);
74 inline UnaryOps getOpcode() const {
75 return (UnaryOps)Instruction::getOpcode();
78 virtual Instruction *clone() const {
79 return create(getOpcode(), Operands[0]);
82 // Methods for support type inquiry through isa, cast, and dyn_cast:
83 static inline bool classof(const UnaryOperator *) { return true; }
84 static inline bool classof(const Instruction *I) {
85 return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps;
87 static inline bool classof(const Value *V) {
88 return isa<Instruction>(V) && classof(cast<Instruction>(V));
94 //===----------------------------------------------------------------------===//
95 // BinaryOperator Class
96 //===----------------------------------------------------------------------===//
98 class BinaryOperator : public Instruction {
100 BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
101 const std::string &Name = "")
102 : Instruction(S1->getType(), iType, Name) {
104 Operands.push_back(Use(S1, this));
105 Operands.push_back(Use(S2, this));
106 assert(Operands[0] && Operands[1] &&
107 Operands[0]->getType() == Operands[1]->getType());
112 // create() - Construct a binary instruction, given the opcode
113 // and the two operands.
115 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
116 const std::string &Name = "");
118 inline BinaryOps getOpcode() const {
119 return (BinaryOps)Instruction::getOpcode();
122 virtual Instruction *clone() const {
123 return create(getOpcode(), Operands[0], Operands[1]);
126 // swapOperands - Exchange the two operands to this instruction.
127 // This instruction is safe to use on any binary instruction and
128 // does not modify the semantics of the instruction. If the
129 // instruction is order dependant (SetLT f.e.) the opcode is
130 // changed. If the instruction cannot be reversed (ie, it's a Div),
135 // Methods for support type inquiry through isa, cast, and dyn_cast:
136 static inline bool classof(const BinaryOperator *) { return true; }
137 static inline bool classof(const Instruction *I) {
138 return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps;
140 static inline bool classof(const Value *V) {
141 return isa<Instruction>(V) && classof(cast<Instruction>(V));