Convert comments to Doxygen 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 //===----------------------------------------------------------------------===//
15 //                            TerminatorInst Class
16 //===----------------------------------------------------------------------===//
17
18 /// TerminatorInst - Subclasses of this class are all able to terminate a basic 
19 /// block.  Thus, these are all the flow control type of operations.
20 ///
21 class TerminatorInst : public Instruction {
22 protected:
23   TerminatorInst(Instruction::TermOps iType);
24   TerminatorInst(const Type *Ty, Instruction::TermOps iType,
25                  const std::string &Name = "");
26 public:
27
28   /// Terminators must implement the methods required by Instruction...
29   virtual Instruction *clone() const = 0;
30
31   /// Additionally, they must provide a method to get at the successors of this
32   /// terminator instruction.  'idx' may not be >= the number of successors
33   /// returned by getNumSuccessors()!
34   ///
35   virtual const BasicBlock *getSuccessor(unsigned idx) const = 0;
36   virtual unsigned getNumSuccessors() const = 0;
37   
38   /// Set a successor at a given index
39   virtual void setSuccessor(unsigned idx, BasicBlock *B) = 0;
40
41   inline BasicBlock *getSuccessor(unsigned idx) {
42     return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
43   }
44
45   // Methods for support type inquiry through isa, cast, and dyn_cast:
46   static inline bool classof(const TerminatorInst *) { return true; }
47   static inline bool classof(const Instruction *I) {
48     return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps; 
49   }
50   static inline bool classof(const Value *V) {
51     return isa<Instruction>(V) && classof(cast<Instruction>(V));
52   }
53 };
54
55
56 //===----------------------------------------------------------------------===//
57 //                           BinaryOperator Class
58 //===----------------------------------------------------------------------===//
59
60 class BinaryOperator : public Instruction {
61 protected:
62   BinaryOperator(BinaryOps iType, Value *S1, Value *S2, 
63                  const std::string &Name = "") 
64     : Instruction(S1->getType(), iType, Name) {
65     Operands.reserve(2);
66     Operands.push_back(Use(S1, this));
67     Operands.push_back(Use(S2, this));
68     assert(Operands[0] && Operands[1] && 
69            Operands[0]->getType() == Operands[1]->getType());
70   }
71
72 public:
73
74   /// create() - Construct a binary instruction, given the opcode
75   /// and the two operands.
76   ///
77   static BinaryOperator *create(BinaryOps Op, Value *S1, Value *S2,
78                                 const std::string &Name = "");
79
80   /// Helper functions to construct and inspect unary operations (NEG and NOT)
81   /// via binary operators SUB and XOR:
82   /// 
83   /// createNeg, createNot - Create the NEG and NOT
84   ///     instructions out of SUB and XOR instructions.
85   ///
86   static BinaryOperator *createNeg(Value *Op, const std::string &Name = "");
87   static BinaryOperator *createNot(Value *Op, const std::string &Name = "");
88
89   /// isNeg, isNot - Check if the given Value is a NEG or NOT instruction.
90   ///
91   static bool            isNeg(const Value *V);
92   static bool            isNot(const Value *V);
93
94   /// getNegArgument, getNotArgument - Helper functions to extract the
95   ///     unary argument of a NEG or NOT operation implemented via Sub or Xor.
96   /// 
97   static const Value*    getNegArgument(const BinaryOperator* Bop);
98   static       Value*    getNegArgument(      BinaryOperator* Bop);
99   static const Value*    getNotArgument(const BinaryOperator* Bop);
100   static       Value*    getNotArgument(      BinaryOperator* Bop);
101
102   BinaryOps getOpcode() const { 
103     return (BinaryOps)Instruction::getOpcode();
104   }
105
106   virtual Instruction *clone() const {
107     return create(getOpcode(), Operands[0], Operands[1]);
108   }
109
110   /// swapOperands - Exchange the two operands to this instruction.
111   /// This instruction is safe to use on any binary instruction and
112   /// does not modify the semantics of the instruction.  If the
113   /// instruction is order dependant (SetLT f.e.) the opcode is
114   /// changed.  If the instruction cannot be reversed (ie, it's a Div),
115   /// then return true.
116   ///
117   bool swapOperands();
118
119   // Methods for support type inquiry through isa, cast, and dyn_cast:
120   static inline bool classof(const BinaryOperator *) { return true; }
121   static inline bool classof(const Instruction *I) {
122     return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps; 
123   }
124   static inline bool classof(const Value *V) {
125     return isa<Instruction>(V) && classof(cast<Instruction>(V));
126   }
127 };
128
129 #endif