Neg instruction removed. Cast instruction implemented.
[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 #include <list>
14 #include <vector>
15
16 class Method;
17 class SymTabValue;
18
19 //===----------------------------------------------------------------------===//
20 //                            TerminatorInst Class
21 //===----------------------------------------------------------------------===//
22
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.
25 //
26 class TerminatorInst : public Instruction {
27 public:
28   TerminatorInst(unsigned iType);
29   inline ~TerminatorInst() {}
30
31   // Terminators must implement the methods required by Instruction...
32   virtual Instruction *clone() const = 0;
33   virtual const char *getOpcodeName() const = 0;
34
35   // Additionally, they must provide a method to get at the successors of this
36   // terminator instruction.  If 'idx' is out of range, a null pointer shall be
37   // returned.
38   //
39   virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
40   virtual unsigned getNumSuccessors() const = 0;
41
42   inline BasicBlock *getSuccessor(unsigned idx) {
43     return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
44   }
45 };
46
47
48 //===----------------------------------------------------------------------===//
49 //                            UnaryOperator Class
50 //===----------------------------------------------------------------------===//
51
52 class UnaryOperator : public Instruction {
53 public:
54
55   // create() - Construct a unary instruction, given the opcode
56   // and its operand.
57   //
58   static UnaryOperator *create(UnaryOps Op, Value *Source,
59                                const Type *DestTy = 0);
60
61   UnaryOperator(Value *S, UnaryOps iType, const Type *ResultType,
62                 const string &Name = "")
63       : Instruction(ResultType, iType, Name) {
64     Operands.reserve(1);
65     Operands.push_back(Use(S, this));
66   }
67
68   inline UnaryOps getOpcode() const { 
69     return (UnaryOps)Instruction::getOpcode();
70   }
71
72   virtual Instruction *clone() const { 
73     return create(getOpcode(), Operands[0]);
74   }
75
76   virtual const char *getOpcodeName() const = 0;
77 };
78
79
80
81 //===----------------------------------------------------------------------===//
82 //                           BinaryOperator Class
83 //===----------------------------------------------------------------------===//
84
85 class BinaryOperator : public Instruction {
86 public:
87
88   // create() - Construct a binary instruction, given the opcode
89   // and the two operands.
90   //
91   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
92                                 const string &Name = "");
93
94   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
95                  const string &Name = "") 
96     : Instruction(S1->getType(), iType, Name) {
97     Operands.reserve(2);
98     Operands.push_back(Use(S1, this));
99     Operands.push_back(Use(S2, this));
100     assert(Operands[0] && Operands[1] && 
101            Operands[0]->getType() == Operands[1]->getType());
102   }
103
104   inline BinaryOps getOpcode() const { 
105     return (BinaryOps)Instruction::getOpcode();
106   }
107
108   virtual Instruction *clone() const {
109     return create(getOpcode(), Operands[0], Operands[1]);
110   }
111
112   virtual const char *getOpcodeName() const = 0;
113 };
114
115 #endif