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);
46 //===----------------------------------------------------------------------===//
47 // UnaryOperator Class
48 //===----------------------------------------------------------------------===//
50 class UnaryOperator : public Instruction {
53 // create() - Construct a unary instruction, given the opcode
56 static UnaryOperator *create(UnaryOps Op, Value *Source);
58 UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
59 : Instruction(S->getType(), iType, Name) {
61 Operands.push_back(Use(S, this));
64 inline UnaryOps getOpcode() const {
65 return (UnaryOps)Instruction::getOpcode();
68 virtual Instruction *clone() const {
69 return create(getOpcode(), Operands[0]);
72 virtual const char *getOpcodeName() const = 0;
77 //===----------------------------------------------------------------------===//
78 // BinaryOperator Class
79 //===----------------------------------------------------------------------===//
81 class BinaryOperator : public Instruction {
84 // create() - Construct a binary instruction, given the opcode
85 // and the two operands.
87 static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
88 const string &Name = "");
90 BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
91 const string &Name = "")
92 : Instruction(S1->getType(), iType, Name) {
94 Operands.push_back(Use(S1, this));
95 Operands.push_back(Use(S2, this));
96 assert(Operands[0] && Operands[1] &&
97 Operands[0]->getType() == Operands[1]->getType());
100 inline BinaryOps getOpcode() const {
101 return (BinaryOps)Instruction::getOpcode();
104 virtual Instruction *clone() const {
105 return create(getOpcode(), Operands[0], Operands[1]);
108 virtual const char *getOpcodeName() const = 0;
110 // swapOperands - Exchange the two operands to this instruction
111 void swapOperands() {
112 swap(Operands[0], Operands[1]);