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 void dropAllReferences() = 0;
34 virtual string getOpcode() const = 0;
36 virtual bool setOperand(unsigned i, Value *Val) = 0;
37 virtual const Value *getOperand(unsigned i) const = 0;
39 // Additionally, they must provide a method to get at the successors of this
40 // terminator instruction. If 'idx' is out of range, a null pointer shall be
43 virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
44 virtual unsigned getNumSuccessors() const = 0;
46 inline BasicBlock *getSuccessor(unsigned idx) {
47 return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
52 //===----------------------------------------------------------------------===//
53 // UnaryOperator Class
54 //===----------------------------------------------------------------------===//
56 class UnaryOperator : public Instruction {
60 // getUnaryOperator() - Construct a unary instruction, given the opcode
63 static UnaryOperator *getUnaryOperator(unsigned Op, Value *Source);
65 UnaryOperator(Value *S, unsigned iType, const string &Name = "")
66 : Instruction(S->getType(), iType, Name), Source(S, this) {
68 inline ~UnaryOperator() { dropAllReferences(); }
70 virtual Instruction *clone() const {
71 return getUnaryOperator(getInstType(), Source);
74 virtual void dropAllReferences() {
78 virtual string getOpcode() const = 0;
80 virtual unsigned getNumOperands() const { return 1; }
81 virtual const Value *getOperand(unsigned i) const {
82 return (i == 0) ? Source : 0;
84 virtual bool setOperand(unsigned i, Value *Val) {
85 // assert(Val && "operand must not be null!");
94 //===----------------------------------------------------------------------===//
95 // BinaryOperator Class
96 //===----------------------------------------------------------------------===//
98 class BinaryOperator : public Instruction {
102 // getBinaryOperator() - Construct a binary instruction, given the opcode
103 // and the two operands.
105 static BinaryOperator *getBinaryOperator(unsigned Op, Value *S1, Value *S2);
107 BinaryOperator(unsigned iType, Value *S1, Value *S2,
108 const string &Name = "")
109 : Instruction(S1->getType(), iType, Name), Source1(S1, this),
111 assert(S1 && S2 && S1->getType() == S2->getType());
113 inline ~BinaryOperator() { dropAllReferences(); }
115 virtual Instruction *clone() const {
116 return getBinaryOperator(getInstType(), Source1, Source2);
119 virtual void dropAllReferences() {
120 Source1 = Source2 = 0;
123 virtual string getOpcode() const = 0;
125 virtual unsigned getNumOperands() const { return 2; }
126 virtual const Value *getOperand(unsigned i) const {
127 return (i == 0) ? Source1 : ((i == 1) ? Source2 : 0);
130 virtual bool setOperand(unsigned i, Value *Val) {
131 // assert(Val && "operand must not be null!");
133 Source1 = Val; //assert(Val->getType() == Source2->getType());
135 Source2 = Val; //assert(Val->getType() == Source1->getType());