Added LLVM copyright header (for lack of a better term).
[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   const Function *getCalledFunction() const {
73     return dyn_cast<Function>(Operands[0].get());
74   }
75   Function *getCalledFunction() {
76     return dyn_cast<Function>(Operands[0].get());
77   }
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 { return (OtherOps)Instruction::getOpcode(); }
117
118   virtual Instruction *clone() const { return new ShiftInst(*this); }
119
120   // Methods for support type inquiry through isa, cast, and dyn_cast:
121   static inline bool classof(const ShiftInst *) { return true; }
122   static inline bool classof(const Instruction *I) {
123     return (I->getOpcode() == Instruction::Shr) | 
124            (I->getOpcode() == Instruction::Shl);
125   }
126   static inline bool classof(const Value *V) {
127     return isa<Instruction>(V) && classof(cast<Instruction>(V));
128   }
129 };
130
131
132 //===----------------------------------------------------------------------===//
133 //                                VANextInst Class
134 //===----------------------------------------------------------------------===//
135
136 /// VANextInst - This class represents the va_next llvm instruction, which
137 /// advances a vararg list passed an argument of the specified type, returning
138 /// the resultant list.
139 ///
140 class VANextInst : public Instruction {
141   PATypeHolder ArgTy;
142   VANextInst(const VANextInst &VAN)
143     : Instruction(VAN.getType(), VANext), ArgTy(VAN.getArgType()) {
144     Operands.reserve(1);
145     Operands.push_back(Use(VAN.Operands[0], this));
146   }
147 public:
148   VANextInst(Value *List, const Type *Ty, const std::string &Name = "",
149              Instruction *InsertBefore = 0)
150     : Instruction(List->getType(), VANext, Name, InsertBefore), ArgTy(Ty) {
151     Operands.reserve(1);
152     Operands.push_back(Use(List, this));
153   }
154
155   const Type *getArgType() const { return ArgTy; }
156
157   virtual Instruction *clone() const { return new VANextInst(*this); }
158
159   // Methods for support type inquiry through isa, cast, and dyn_cast:
160   static inline bool classof(const VANextInst *) { return true; }
161   static inline bool classof(const Instruction *I) {
162     return I->getOpcode() == VANext;
163   }
164   static inline bool classof(const Value *V) {
165     return isa<Instruction>(V) && classof(cast<Instruction>(V));
166   }
167 };
168
169 /// VAArgInst - This class represents the va_arg llvm instruction, which returns
170 /// an argument of the specified type given a va_list.
171 ///
172 class VAArgInst : public Instruction {
173   VAArgInst(const VAArgInst &VAA)
174     : Instruction(VAA.getType(), VAArg) {
175     Operands.reserve(1);
176     Operands.push_back(Use(VAA.Operands[0], this));
177   }
178 public:
179   VAArgInst(Value *List, const Type *Ty, const std::string &Name = "",
180              Instruction *InsertBefore = 0)
181     : Instruction(Ty, VAArg, Name, InsertBefore) {
182     Operands.reserve(1);
183     Operands.push_back(Use(List, this));
184   }
185
186   virtual Instruction *clone() const { return new VAArgInst(*this); }
187
188   bool mayWriteToMemory() const { return true; }
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 #endif