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;
38 inline Value *getOperand(unsigned i) {
39 return (Value*)((const Instruction *)this)->getOperand(i);
42 // Additionally, they must provide a method to get at the successors of this
43 // terminator instruction. If 'idx' is out of range, a null pointer shall be
46 virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
47 virtual unsigned getNumSuccessors() const = 0;
49 inline BasicBlock *getSuccessor(unsigned idx) {
50 return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
55 //===----------------------------------------------------------------------===//
56 // UnaryOperator Class
57 //===----------------------------------------------------------------------===//
59 class UnaryOperator : public Instruction {
63 // getUnaryOperator() - Construct a unary instruction, given the opcode
66 static UnaryOperator *getUnaryOperator(unsigned Op, Value *Source);
68 UnaryOperator(Value *S, unsigned iType, const string &Name = "")
69 : Instruction(S->getType(), iType, Name), Source(S, this) {
71 inline ~UnaryOperator() { dropAllReferences(); }
73 virtual Instruction *clone() const {
74 return getUnaryOperator(getInstType(), Source);
77 virtual void dropAllReferences() {
81 virtual string getOpcode() const = 0;
83 virtual unsigned getNumOperands() const { return 1; }
84 inline Value *getOperand(unsigned i) {
85 return (i == 0) ? Source : 0;
87 virtual const Value *getOperand(unsigned i) const {
88 return (i == 0) ? Source : 0;
90 virtual bool setOperand(unsigned i, Value *Val) {
91 // assert(Val && "operand must not be null!");
100 //===----------------------------------------------------------------------===//
101 // BinaryOperator Class
102 //===----------------------------------------------------------------------===//
104 class BinaryOperator : public Instruction {
105 Use Source1, Source2;
108 // getBinaryOperator() - Construct a binary instruction, given the opcode
109 // and the two operands.
111 static BinaryOperator *getBinaryOperator(unsigned Op, Value *S1, Value *S2);
113 BinaryOperator(unsigned iType, Value *S1, Value *S2,
114 const string &Name = "")
115 : Instruction(S1->getType(), iType, Name), Source1(S1, this),
117 assert(S1 && S2 && S1->getType() == S2->getType());
119 inline ~BinaryOperator() { dropAllReferences(); }
121 virtual Instruction *clone() const {
122 return getBinaryOperator(getInstType(), Source1, Source2);
125 virtual void dropAllReferences() {
126 Source1 = Source2 = 0;
129 virtual string getOpcode() const = 0;
131 virtual unsigned getNumOperands() const { return 2; }
132 virtual const Value *getOperand(unsigned i) const {
133 return (i == 0) ? Source1 : ((i == 1) ? Source2 : 0);
135 inline Value *getOperand(unsigned i) {
136 return (i == 0) ? Source1 : ((i == 1) ? Source2 : 0);
139 virtual bool setOperand(unsigned i, Value *Val) {
140 // assert(Val && "operand must not be null!");
142 Source1 = Val; //assert(Val->getType() == Source2->getType());
144 Source2 = Val; //assert(Val->getType() == Source1->getType());