Commit more code over to new cast style
[oota-llvm.git] / include / llvm / InstrTypes.h
1 //===-- llvm/InstrTypes.h - Important Instruction subclasses -----*- C++ -*--=//
2 //
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 
5 // i*.h files...
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_INSTRUCTION_TYPES_H
10 #define LLVM_INSTRUCTION_TYPES_H
11
12 #include "llvm/Instruction.h"
13
14 class Method;
15 class SymTabValue;
16
17 //===----------------------------------------------------------------------===//
18 //                            TerminatorInst Class
19 //===----------------------------------------------------------------------===//
20
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.
23 //
24 class TerminatorInst : public Instruction {
25 public:
26   TerminatorInst(unsigned iType);
27   inline ~TerminatorInst() {}
28
29   // Terminators must implement the methods required by Instruction...
30   virtual Instruction *clone() const = 0;
31   virtual const char *getOpcodeName() const = 0;
32
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
35   // returned.
36   //
37   virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
38   virtual unsigned getNumSuccessors() const = 0;
39
40   inline BasicBlock *getSuccessor(unsigned idx) {
41     return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
42   }
43
44   // Methods for support type inquiry through isa, cast, and dyn_cast:
45   static inline bool classof(const TerminatorInst *) { return true; }
46   static inline bool classof(const Instruction *I) {
47     return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps; 
48   }
49   static inline bool classof(const Value *V) {
50     return isa<Instruction>(V) && classof(cast<Instruction>(V));
51   }
52 };
53
54
55 //===----------------------------------------------------------------------===//
56 //                            UnaryOperator Class
57 //===----------------------------------------------------------------------===//
58
59 class UnaryOperator : public Instruction {
60 public:
61
62   // create() - Construct a unary instruction, given the opcode
63   // and its operand.
64   //
65   static UnaryOperator *create(UnaryOps Op, Value *Source);
66
67   UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
68       : Instruction(S->getType(), iType, Name) {
69     Operands.reserve(1);
70     Operands.push_back(Use(S, this));
71   }
72
73   inline UnaryOps getOpcode() const { 
74     return (UnaryOps)Instruction::getOpcode();
75   }
76
77   virtual Instruction *clone() const { 
78     return create(getOpcode(), Operands[0]);
79   }
80
81   virtual const char *getOpcodeName() const = 0;
82
83   // Methods for support type inquiry through isa, cast, and dyn_cast:
84   static inline bool classof(const UnaryOperator *) { return true; }
85   static inline bool classof(const Instruction *I) {
86     return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps; 
87   }
88   static inline bool classof(const Value *V) {
89     return isa<Instruction>(V) && classof(cast<Instruction>(V));
90   }
91 };
92
93
94
95 //===----------------------------------------------------------------------===//
96 //                           BinaryOperator Class
97 //===----------------------------------------------------------------------===//
98
99 class BinaryOperator : public Instruction {
100 public:
101
102   // create() - Construct a binary instruction, given the opcode
103   // and the two operands.
104   //
105   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
106                                 const string &Name = "");
107
108   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
109                  const string &Name = "") 
110     : Instruction(S1->getType(), iType, Name) {
111     Operands.reserve(2);
112     Operands.push_back(Use(S1, this));
113     Operands.push_back(Use(S2, this));
114     assert(Operands[0] && Operands[1] && 
115            Operands[0]->getType() == Operands[1]->getType());
116   }
117
118   inline BinaryOps getOpcode() const { 
119     return (BinaryOps)Instruction::getOpcode();
120   }
121
122   virtual Instruction *clone() const {
123     return create(getOpcode(), Operands[0], Operands[1]);
124   }
125
126   virtual const char *getOpcodeName() const = 0;
127
128   // swapOperands - Exchange the two operands to this instruction
129   void swapOperands() {
130     swap(Operands[0], Operands[1]);
131   }
132
133   // Methods for support type inquiry through isa, cast, and dyn_cast:
134   static inline bool classof(const BinaryOperator *) { return true; }
135   static inline bool classof(const Instruction *I) {
136     return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps; 
137   }
138   static inline bool classof(const Value *V) {
139     return isa<Instruction>(V) && classof(cast<Instruction>(V));
140   }
141 };
142
143 #endif