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