Chris seems fond of #include <vector>. Fix these. Also convert use list in
[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
45
46 //===----------------------------------------------------------------------===//
47 //                            UnaryOperator Class
48 //===----------------------------------------------------------------------===//
49
50 class UnaryOperator : public Instruction {
51 public:
52
53   // create() - Construct a unary instruction, given the opcode
54   // and its operand.
55   //
56   static UnaryOperator *create(UnaryOps Op, Value *Source);
57
58   UnaryOperator(Value *S, UnaryOps iType, const string &Name = "")
59       : Instruction(S->getType(), iType, Name) {
60     Operands.reserve(1);
61     Operands.push_back(Use(S, this));
62   }
63
64   inline UnaryOps getOpcode() const { 
65     return (UnaryOps)Instruction::getOpcode();
66   }
67
68   virtual Instruction *clone() const { 
69     return create(getOpcode(), Operands[0]);
70   }
71
72   virtual const char *getOpcodeName() const = 0;
73 };
74
75
76
77 //===----------------------------------------------------------------------===//
78 //                           BinaryOperator Class
79 //===----------------------------------------------------------------------===//
80
81 class BinaryOperator : public Instruction {
82 public:
83
84   // create() - Construct a binary instruction, given the opcode
85   // and the two operands.
86   //
87   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
88                                 const string &Name = "");
89
90   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
91                  const string &Name = "") 
92     : Instruction(S1->getType(), iType, Name) {
93     Operands.reserve(2);
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());
98   }
99
100   inline BinaryOps getOpcode() const { 
101     return (BinaryOps)Instruction::getOpcode();
102   }
103
104   virtual Instruction *clone() const {
105     return create(getOpcode(), Operands[0], Operands[1]);
106   }
107
108   virtual const char *getOpcodeName() const = 0;
109
110   // swapOperands - Exchange the two operands to this instruction
111   void swapOperands() {
112     swap(Operands[0], Operands[1]);
113   }
114 };
115
116 #endif