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(unsigned iType);
27 inline ~TerminatorInst() {}
29 // Terminators must implement the methods required by Instruction...
30 virtual Instruction *clone() const = 0;
31 virtual const char *getOpcodeName() const = 0;
33 // Additionally, they must provide a method to get at the successors of this
34 // terminator instruction. If 'idx' is out of range, a null pointer shall be
37 virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
38 virtual unsigned getNumSuccessors() const = 0;
40 inline BasicBlock *getSuccessor(unsigned idx) {
41 return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
44 // Methods for support type inquiry through isa, cast, and dyn_cast:
45 static inline bool classof(const TerminatorInst *) { return true; }
46 static inline bool classof(const Instruction *I) {
47 return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps;
49 static inline bool classof(const Value *V) {
50 return isa<Instruction>(V) && classof(cast<Instruction>(V));
55 //===----------------------------------------------------------------------===//
56 // UnaryOperator Class
57 //===----------------------------------------------------------------------===//
59 class UnaryOperator : public Instruction {
62 // create() - Construct a unary instruction, given the opcode
65 static UnaryOperator *create(UnaryOps Op, Value *Source);
67 UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
68 : Instruction(S->getType(), iType, Name) {
70 Operands.push_back(Use(S, this));
73 inline UnaryOps getOpcode() const {
74 return (UnaryOps)Instruction::getOpcode();
77 virtual Instruction *clone() const {
78 return create(getOpcode(), Operands[0]);
81 virtual const char *getOpcodeName() const = 0;
83 // Methods for support type inquiry through isa, cast, and dyn_cast:
84 static inline bool classof(const UnaryOperator *) { return true; }
85 static inline bool classof(const Instruction *I) {
86 return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps;
88 static inline bool classof(const Value *V) {
89 return isa<Instruction>(V) && classof(cast<Instruction>(V));
95 //===----------------------------------------------------------------------===//
96 // BinaryOperator Class
97 //===----------------------------------------------------------------------===//
99 class BinaryOperator : public Instruction {
102 // create() - Construct a binary instruction, given the opcode
103 // and the two operands.
105 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
106 const string &Name = "");
108 BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
109 const string &Name = "")
110 : Instruction(S1->getType(), iType, Name) {
112 Operands.push_back(Use(S1, this));
113 Operands.push_back(Use(S2, this));
114 assert(Operands[0] && Operands[1] &&
115 Operands[0]->getType() == Operands[1]->getType());
118 inline BinaryOps getOpcode() const {
119 return (BinaryOps)Instruction::getOpcode();
122 virtual Instruction *clone() const {
123 return create(getOpcode(), Operands[0], Operands[1]);
126 virtual const char *getOpcodeName() const = 0;
128 // swapOperands - Exchange the two operands to this instruction
129 void swapOperands() {
130 swap(Operands[0], Operands[1]);
133 // Methods for support type inquiry through isa, cast, and dyn_cast:
134 static inline bool classof(const BinaryOperator *) { return true; }
135 static inline bool classof(const Instruction *I) {
136 return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps;
138 static inline bool classof(const Value *V) {
139 return isa<Instruction>(V) && classof(cast<Instruction>(V));