Initial implementation of basic value numbering
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions -----*- C++ -*--=//
2 //
3 // This file contains the declarations for instructions that fall into the 
4 // grandios 'other' catagory...
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_IOTHER_H
9 #define LLVM_IOTHER_H
10
11 #include "llvm/InstrTypes.h"
12
13 //===----------------------------------------------------------------------===//
14 //                                 CastInst Class
15 //===----------------------------------------------------------------------===//
16
17 // CastInst - This class represents a cast from Operand[0] to the type of
18 // the instruction (i->getType()).
19 //
20 class CastInst : public Instruction {
21   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
22     Operands.reserve(1);
23     Operands.push_back(Use(CI.Operands[0], this));
24   }
25 public:
26   CastInst(Value *S, const Type *Ty, const std::string &Name = "")
27     : Instruction(Ty, Cast, Name) {
28     Operands.reserve(1);
29     Operands.push_back(Use(S, this));
30   }
31
32   virtual Instruction *clone() const { return new CastInst(*this); }
33
34   // Methods for support type inquiry through isa, cast, and dyn_cast:
35   static inline bool classof(const CastInst *) { return true; }
36   static inline bool classof(const Instruction *I) {
37     return I->getOpcode() == Cast;
38   }
39   static inline bool classof(const Value *V) {
40     return isa<Instruction>(V) && classof(cast<Instruction>(V));
41   }
42 };
43
44
45 //===----------------------------------------------------------------------===//
46 //             Classes to function calls and method invocations
47 //===----------------------------------------------------------------------===//
48
49 class CallInst : public Instruction {
50   CallInst(const CallInst &CI);
51 public:
52   CallInst(Value *M, const std::vector<Value*> &Par, const std::string & = "");
53
54   virtual Instruction *clone() const { return new CallInst(*this); }
55   bool hasSideEffects() const { return true; }
56
57   const Function *getCalledFunction() const {
58     return dyn_cast<Function>(Operands[0].get());
59   }
60   Function *getCalledFunction() {
61     return dyn_cast<Function>(Operands[0].get());
62   }
63
64   // getCalledValue - Get a pointer to a method that is invoked by this inst.
65   inline const Value *getCalledValue() const { return Operands[0]; }
66   inline       Value *getCalledValue()       { return Operands[0]; }
67
68   // Methods for support type inquiry through isa, cast, and dyn_cast:
69   static inline bool classof(const CallInst *) { return true; }
70   static inline bool classof(const Instruction *I) {
71     return I->getOpcode() == Instruction::Call; 
72   }
73   static inline bool classof(const Value *V) {
74     return isa<Instruction>(V) && classof(cast<Instruction>(V));
75   }
76 };
77
78
79 //===----------------------------------------------------------------------===//
80 //                                 ShiftInst Class
81 //===----------------------------------------------------------------------===//
82
83 // ShiftInst - This class represents left and right shift instructions.
84 //
85 class ShiftInst : public Instruction {
86   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
87     Operands.reserve(2);
88     Operands.push_back(Use(SI.Operands[0], this));
89     Operands.push_back(Use(SI.Operands[1], this));
90   }
91 public:
92   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "")
93     : Instruction(S->getType(), Opcode, Name) {
94     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
95     Operands.reserve(2);
96     Operands.push_back(Use(S, this));
97     Operands.push_back(Use(SA, this));
98   }
99
100   OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
101
102   virtual Instruction *clone() const { return new ShiftInst(*this); }
103
104   // Methods for support type inquiry through isa, cast, and dyn_cast:
105   static inline bool classof(const ShiftInst *) { return true; }
106   static inline bool classof(const Instruction *I) {
107     return (I->getOpcode() == Instruction::Shr) | 
108            (I->getOpcode() == Instruction::Shl);
109   }
110   static inline bool classof(const Value *V) {
111     return isa<Instruction>(V) && classof(cast<Instruction>(V));
112   }
113 };
114
115 #endif