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"
19 //===----------------------------------------------------------------------===//
20 // TerminatorInst Class
21 //===----------------------------------------------------------------------===//
23 // TerminatorInst - Subclasses of this class are all able to terminate a basic
24 // block. Thus, these are all the flow control type of operations.
26 class TerminatorInst : public Instruction {
28 TerminatorInst(unsigned iType);
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);
48 //===----------------------------------------------------------------------===//
49 // UnaryOperator Class
50 //===----------------------------------------------------------------------===//
52 class UnaryOperator : public Instruction {
55 // create() - Construct a unary instruction, given the opcode
58 static UnaryOperator *create(UnaryOps Op, Value *Source);
60 UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
61 : Instruction(S->getType(), iType, Name) {
63 Operands.push_back(Use(S, this));
66 inline UnaryOps getOpcode() const {
67 return (UnaryOps)Instruction::getOpcode();
70 virtual Instruction *clone() const {
71 return create(getOpcode(), Operands[0]);
74 virtual const char *getOpcodeName() const = 0;
79 //===----------------------------------------------------------------------===//
80 // BinaryOperator Class
81 //===----------------------------------------------------------------------===//
83 class BinaryOperator : public Instruction {
86 // create() - Construct a binary instruction, given the opcode
87 // and the two operands.
89 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
90 const string &Name = "");
92 BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
93 const string &Name = "")
94 : Instruction(S1->getType(), iType, Name) {
96 Operands.push_back(Use(S1, this));
97 Operands.push_back(Use(S2, this));
98 assert(Operands[0] && Operands[1] &&
99 Operands[0]->getType() == Operands[1]->getType());
102 inline BinaryOps getOpcode() const {
103 return (BinaryOps)Instruction::getOpcode();
106 virtual Instruction *clone() const {
107 return create(getOpcode(), Operands[0], Operands[1]);
110 virtual const char *getOpcodeName() const = 0;