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"
17 //===----------------------------------------------------------------------===//
18 // TerminatorInst Class
19 //===----------------------------------------------------------------------===//
21 // TerminatorInst - Subclasses of this class are all able to terminate a basic
22 // block. Thus, these are all the flow control type of operations.
24 class TerminatorInst : public Instruction {
26 TerminatorInst(Instruction::TermOps iType);
27 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
28 const string &Name = "");
29 inline ~TerminatorInst() {}
31 // Terminators must implement the methods required by Instruction...
32 virtual Instruction *clone() const = 0;
33 virtual const char *getOpcodeName() const = 0;
35 // Additionally, they must provide a method to get at the successors of this
36 // terminator instruction. If 'idx' is out of range, a null pointer shall be
39 virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
40 virtual unsigned getNumSuccessors() const = 0;
42 inline BasicBlock *getSuccessor(unsigned idx) {
43 return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
46 // Methods for support type inquiry through isa, cast, and dyn_cast:
47 static inline bool classof(const TerminatorInst *) { return true; }
48 static inline bool classof(const Instruction *I) {
49 return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps;
51 static inline bool classof(const Value *V) {
52 return isa<Instruction>(V) && classof(cast<Instruction>(V));
57 //===----------------------------------------------------------------------===//
58 // UnaryOperator Class
59 //===----------------------------------------------------------------------===//
61 class UnaryOperator : public Instruction {
64 // create() - Construct a unary instruction, given the opcode
67 static UnaryOperator *create(UnaryOps Op, Value *Source);
69 UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
70 : Instruction(S->getType(), iType, Name) {
72 Operands.push_back(Use(S, this));
75 inline UnaryOps getOpcode() const {
76 return (UnaryOps)Instruction::getOpcode();
79 virtual Instruction *clone() const {
80 return create(getOpcode(), Operands[0]);
83 virtual const char *getOpcodeName() const = 0;
85 // Methods for support type inquiry through isa, cast, and dyn_cast:
86 static inline bool classof(const UnaryOperator *) { return true; }
87 static inline bool classof(const Instruction *I) {
88 return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps;
90 static inline bool classof(const Value *V) {
91 return isa<Instruction>(V) && classof(cast<Instruction>(V));
97 //===----------------------------------------------------------------------===//
98 // BinaryOperator Class
99 //===----------------------------------------------------------------------===//
101 class BinaryOperator : public Instruction {
104 // create() - Construct a binary instruction, given the opcode
105 // and the two operands.
107 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
108 const string &Name = "");
110 BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
111 const string &Name = "")
112 : Instruction(S1->getType(), iType, Name) {
114 Operands.push_back(Use(S1, this));
115 Operands.push_back(Use(S2, this));
116 assert(Operands[0] && Operands[1] &&
117 Operands[0]->getType() == Operands[1]->getType());
120 inline BinaryOps getOpcode() const {
121 return (BinaryOps)Instruction::getOpcode();
124 virtual Instruction *clone() const {
125 return create(getOpcode(), Operands[0], Operands[1]);
128 virtual const char *getOpcodeName() const = 0;
130 // swapOperands - Exchange the two operands to this instruction
131 void swapOperands() {
132 swap(Operands[0], Operands[1]);
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));