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