Several performance enhancements and cleanups from Chris.
[oota-llvm.git] / include / llvm / iOther.h
1 //===-- llvm/iOther.h - "Other" instruction node definitions ----*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declarations for instructions that fall into the 
11 // grandiose 'other' catagory...
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IOTHER_H
16 #define LLVM_IOTHER_H
17
18 #include "llvm/InstrTypes.h"
19
20 namespace llvm {
21
22 //===----------------------------------------------------------------------===//
23 //                                 CastInst Class
24 //===----------------------------------------------------------------------===//
25
26 /// CastInst - This class represents a cast from Operand[0] to the type of
27 /// the instruction (i->getType()).
28 ///
29 class CastInst : public Instruction {
30   CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
31     Operands.reserve(1);
32     Operands.push_back(Use(CI.Operands[0], this));
33   }
34 public:
35   CastInst(Value *S, const Type *Ty, const std::string &Name = "",
36            Instruction *InsertBefore = 0)
37     : Instruction(Ty, Cast, Name, InsertBefore) {
38     Operands.reserve(1);
39     Operands.push_back(Use(S, this));
40   }
41
42   virtual Instruction *clone() const { return new CastInst(*this); }
43
44   // Methods for support type inquiry through isa, cast, and dyn_cast:
45   static inline bool classof(const CastInst *) { return true; }
46   static inline bool classof(const Instruction *I) {
47     return I->getOpcode() == Cast;
48   }
49   static inline bool classof(const Value *V) {
50     return isa<Instruction>(V) && classof(cast<Instruction>(V));
51   }
52 };
53
54
55 //===----------------------------------------------------------------------===//
56 //                                 CallInst Class
57 //===----------------------------------------------------------------------===//
58
59 class CallInst : public Instruction {
60   CallInst(const CallInst &CI);
61 public:
62   CallInst(Value *F, const std::vector<Value*> &Par,
63            const std::string &Name = "", Instruction *InsertBefore = 0);
64
65   // Alternate CallInst ctors w/ no actuals & one actual, respectively.
66   CallInst(Value *F, const std::string &Name = "",
67            Instruction  *InsertBefore = 0);
68   CallInst(Value *F, Value *Actual, const std::string& Name = "",
69            Instruction* InsertBefore = 0);
70
71   virtual Instruction *clone() const { return new CallInst(*this); }
72   bool mayWriteToMemory() const { return true; }
73
74   // FIXME: These methods should be inline once we eliminate
75   // ConstantPointerRefs!
76   const Function *getCalledFunction() const;
77   Function *getCalledFunction();
78
79   // getCalledValue - Get a pointer to a method that is invoked by this inst.
80   inline const Value *getCalledValue() const { return Operands[0]; }
81   inline       Value *getCalledValue()       { return Operands[0]; }
82
83   // Methods for support type inquiry through isa, cast, and dyn_cast:
84   static inline bool classof(const CallInst *) { return true; }
85   static inline bool classof(const Instruction *I) {
86     return I->getOpcode() == Instruction::Call; 
87   }
88   static inline bool classof(const Value *V) {
89     return isa<Instruction>(V) && classof(cast<Instruction>(V));
90   }
91 };
92
93
94 //===----------------------------------------------------------------------===//
95 //                                 ShiftInst Class
96 //===----------------------------------------------------------------------===//
97
98 // ShiftInst - This class represents left and right shift instructions.
99 //
100 class ShiftInst : public Instruction {
101   ShiftInst(const ShiftInst &SI) : Instruction(SI.getType(), SI.getOpcode()) {
102     Operands.reserve(2);
103     Operands.push_back(Use(SI.Operands[0], this));
104     Operands.push_back(Use(SI.Operands[1], this));
105   }
106 public:
107   ShiftInst(OtherOps Opcode, Value *S, Value *SA, const std::string &Name = "",
108             Instruction *InsertBefore = 0)
109     : Instruction(S->getType(), Opcode, Name, InsertBefore) {
110     assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
111     Operands.reserve(2);
112     Operands.push_back(Use(S, this));
113     Operands.push_back(Use(SA, this));
114   }
115
116   OtherOps getOpcode() const {
117     return static_cast<OtherOps>(Instruction::getOpcode());
118   }
119
120   virtual Instruction *clone() const { return new ShiftInst(*this); }
121
122   // Methods for support type inquiry through isa, cast, and dyn_cast:
123   static inline bool classof(const ShiftInst *) { return true; }
124   static inline bool classof(const Instruction *I) {
125     return (I->getOpcode() == Instruction::Shr) | 
126            (I->getOpcode() == Instruction::Shl);
127   }
128   static inline bool classof(const Value *V) {
129     return isa<Instruction>(V) && classof(cast<Instruction>(V));
130   }
131 };
132
133
134 //===----------------------------------------------------------------------===//
135 //                                VANextInst Class
136 //===----------------------------------------------------------------------===//
137
138 /// VANextInst - This class represents the va_next llvm instruction, which
139 /// advances a vararg list passed an argument of the specified type, returning
140 /// the resultant list.
141 ///
142 class VANextInst : public Instruction {
143   PATypeHolder ArgTy;
144   VANextInst(const VANextInst &VAN)
145     : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
146     Operands.reserve(1);
147     Operands.push_back(Use(VAN.Operands[0], this));
148   }
149 public:
150   VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
151              Instruction *InsertBefore = 0)
152     : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
153     Operands.reserve(1);
154     Operands.push_back(Use(List, this));
155   }
156
157   const Type *getArgType() const { return ArgTy; }
158
159   virtual Instruction *clone() const { return new VANextInst(*this); }
160
161   // Methods for support type inquiry through isa, cast, and dyn_cast:
162   static inline bool classof(const VANextInst *) { return true; }
163   static inline bool classof(const Instruction *I) {
164     return I->getOpcode() == VANext;
165   }
166   static inline bool classof(const Value *V) {
167     return isa<Instruction>(V) && classof(cast<Instruction>(V));
168   }
169 };
170
171 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
172 /// an argument of the specified type given a va_list.
173 ///
174 class VAArgInst : public Instruction {
175   VAArgInst(const VAArgInst &VAA)
176     : Instruction(VAA.getType(), VAArg) {
177     Operands.reserve(1);
178     Operands.push_back(Use(VAA.Operands[0], this));
179   }
180 public:
181   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
182              Instruction *InsertBefore = 0)
183     : Instruction(Ty, VAArg, Name, InsertBefore) {
184     Operands.reserve(1);
185     Operands.push_back(Use(List, this));
186   }
187
188   virtual Instruction *clone() const { return new VAArgInst(*this); }
189
190   // Methods for support type inquiry through isa, cast, and dyn_cast:
191   static inline bool classof(const VAArgInst *) { return true; }
192   static inline bool classof(const Instruction *I) {
193     return I->getOpcode() == VAArg;
194   }
195   static inline bool classof(const Value *V) {
196     return isa<Instruction>(V) && classof(cast<Instruction>(V));
197   }
198 };
199
200 } // End llvm namespace
201
202 #endif