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 {
59 UnaryOperator(Value *S, unsigned iType, const string &Name = "")
60 : Instruction(S->getType(), iType, Name), Source(S, this) {
62 inline ~UnaryOperator() { dropAllReferences(); }
64 virtual Instruction *clone() const {
65 return Instruction::getUnaryOperator(getInstType(), Source);
68 virtual void dropAllReferences() {
72 virtual string getOpcode() const = 0;
74 virtual unsigned getNumOperands() const { return 1; }
75 virtual const Value *getOperand(unsigned i) const {
76 return (i == 0) ? Source : 0;
78 virtual bool setOperand(unsigned i, Value *Val) {
79 // assert(Val && "operand must not be null!");
88 //===----------------------------------------------------------------------===//
89 // BinaryOperator Class
90 //===----------------------------------------------------------------------===//
92 class BinaryOperator : public Instruction {
95 BinaryOperator(unsigned iType, Value *S1, Value *S2,
96 const string &Name = "")
97 : Instruction(S1->getType(), iType, Name), Source1(S1, this),
99 assert(S1 && S2 && S1->getType() == S2->getType());
101 inline ~BinaryOperator() { dropAllReferences(); }
103 virtual Instruction *clone() const {
104 return Instruction::getBinaryOperator(getInstType(), Source1, Source2);
107 virtual void dropAllReferences() {
108 Source1 = Source2 = 0;
111 virtual string getOpcode() const = 0;
113 virtual unsigned getNumOperands() const { return 2; }
114 virtual const Value *getOperand(unsigned i) const {
115 return (i == 0) ? Source1 : ((i == 1) ? Source2 : 0);
118 virtual bool setOperand(unsigned i, Value *Val) {
119 // assert(Val && "operand must not be null!");
121 Source1 = Val; //assert(Val->getType() == Source2->getType());
123 Source2 = Val; //assert(Val->getType() == Source1->getType());