]> git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/IR/IntrinsicInst.h
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / include / llvm / IR / IntrinsicInst.h
1 //===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes that make it really easy to deal with intrinsic
11 // functions with the isa/dyncast family of functions. In particular, this
12 // allows you to do things like:
13 //
14 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
15 // ... MCI->getDest() ... MCI->getSource() ...
16 //
17 // All intrinsic function calls are instances of the call instruction, so these
18 // are all subclasses of the CallInst class. Note that none of these classes
19 // has state or virtual methods, which is an important part of this gross/neat
20 // hack working.
21 //
22 //===----------------------------------------------------------------------===//
23
24 #ifndef LLVM_IR_INTRINSICINST_H
25 #define LLVM_IR_INTRINSICINST_H
26
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Intrinsics.h"
31 #include "llvm/IR/Metadata.h"
32
33 namespace llvm {
34 /// IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic
35 /// functions. This allows the standard isa/dyncast/cast functionality to
36 /// work with calls to intrinsic functions.
37 class IntrinsicInst : public CallInst {
38 IntrinsicInst() LLVM_DELETED_FUNCTION;
39 IntrinsicInst(const IntrinsicInst&) LLVM_DELETED_FUNCTION;
40 void operator=(const IntrinsicInst&) LLVM_DELETED_FUNCTION;
41 public:
42 /// getIntrinsicID - Return the intrinsic ID of this intrinsic.
43 ///
44 Intrinsic::ID getIntrinsicID() const {
45 return (Intrinsic::ID)getCalledFunction()->getIntrinsicID();
46 }
47
48 // Methods for support type inquiry through isa, cast, and dyn_cast:
49 static inline bool classof(const CallInst *I) {
50 if (const Function *CF = I->getCalledFunction())
51 return CF->isIntrinsic();
52 return false;
53 }
54 static inline bool classof(const Value *V) {
55 return isa<CallInst>(V) && classof(cast<CallInst>(V));
56 }
57 };
58
59 /// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
60 ///
61 class DbgInfoIntrinsic : public IntrinsicInst {
62 public:
63
64 // Methods for support type inquiry through isa, cast, and dyn_cast:
65 static inline bool classof(const IntrinsicInst *I) {
66 switch (I->getIntrinsicID()) {
67 case Intrinsic::dbg_declare:
68 case Intrinsic::dbg_value:
69 return true;
70 default: return false;
71 }
72 }
73 static inline bool classof(const Value *V) {
74 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
75 }
76
77 static Value *StripCast(Value *C);
78 };
79
80 /// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
81 ///
82 class DbgDeclareInst : public DbgInfoIntrinsic {
83 public:
84 Value *getAddress() const;
85 MDNode *getVariable() const {
86 return cast<MDNode>(
87 cast<MetadataAsValue>(getArgOperand(1))->getMetadata());
88 }
89 MDNode *getExpression() const {
90 return cast<MDNode>(
91 cast<MetadataAsValue>(getArgOperand(2))->getMetadata());
92 }
93
94 // Methods for support type inquiry through isa, cast, and dyn_cast:
95 static inline bool classof(const IntrinsicInst *I) {
96 return I->getIntrinsicID() == Intrinsic::dbg_declare;
97 }
98 static inline bool classof(const Value *V) {
99 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
100 }
101 };
102
103 /// DbgValueInst - This represents the llvm.dbg.value instruction.
104 ///
105 class DbgValueInst : public DbgInfoIntrinsic {
106 public:
107 const Value *getValue() const;
108 Value *getValue();
109 uint64_t getOffset() const {
110 return cast<ConstantInt>(
111 const_cast<Value*>(getArgOperand(1)))->getZExtValue();
112 }
113 MDNode *getVariable() const {
114 return cast<MDNode>(
115 cast<MetadataAsValue>(getArgOperand(2))->getMetadata());
116 }
117 MDNode *getExpression() const {
118 return cast<MDNode>(
119 cast<MetadataAsValue>(getArgOperand(3))->getMetadata());
120 }
121
122 // Methods for support type inquiry through isa, cast, and dyn_cast:
123 static inline bool classof(const IntrinsicInst *I) {
124 return I->getIntrinsicID() == Intrinsic::dbg_value;
125 }
126 static inline bool classof(const Value *V) {
127 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
128 }
129 };
130
131 /// MemIntrinsic - This is the common base class for memset/memcpy/memmove.
132 ///
133 class MemIntrinsic : public IntrinsicInst {
134 public:
135 Value *getRawDest() const { return const_cast<Value*>(getArgOperand(0)); }
136 const Use &getRawDestUse() const { return getArgOperandUse(0); }
137 Use &getRawDestUse() { return getArgOperandUse(0); }
138
139 Value *getLength() const { return const_cast<Value*>(getArgOperand(2)); }
140 const Use &getLengthUse() const { return getArgOperandUse(2); }
141 Use &getLengthUse() { return getArgOperandUse(2); }
142
143 ConstantInt *getAlignmentCst() const {
144 return cast<ConstantInt>(const_cast<Value*>(getArgOperand(3)));
145 }
146
147 unsigned getAlignment() const {
148 return getAlignmentCst()->getZExtValue();
149 }
150
151 ConstantInt *getVolatileCst() const {
152 return cast<ConstantInt>(const_cast<Value*>(getArgOperand(4)));
153 }
154 bool isVolatile() const {
155 return !getVolatileCst()->isZero();
156 }
157
158 unsigned getDestAddressSpace() const {
159 return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
160 }
161
162 /// getDest - This is just like getRawDest, but it strips off any cast
163 /// instructions that feed it, giving the original input. The returned
164 /// value is guaranteed to be a pointer.
165 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
166
167 /// set* - Set the specified arguments of the instruction.
168 ///
169 void setDest(Value *Ptr) {
170 assert(getRawDest()->getType() == Ptr->getType() &&
171 "setDest called with pointer of wrong type!");
172 setArgOperand(0, Ptr);
173 }
174
175 void setLength(Value *L) {
176 assert(getLength()->getType() == L->getType() &&
177 "setLength called with value of wrong type!");
178 setArgOperand(2, L);
179 }
180
181 void setAlignment(Constant* A) {
182 setArgOperand(3, A);
183 }
184
185 void setVolatile(Constant* V) {
186 setArgOperand(4, V);
187 }
188
189 Type *getAlignmentType() const {
190 return getArgOperand(3)->getType();
191 }
192
193 // Methods for support type inquiry through isa, cast, and dyn_cast:
194 static inline bool classof(const IntrinsicInst *I) {
195 switch (I->getIntrinsicID()) {
196 case Intrinsic::memcpy:
197 case Intrinsic::memmove:
198 case Intrinsic::memset:
199 return true;
200 default: return false;
201 }
202 }
203 static inline bool classof(const Value *V) {
204 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
205 }
206 };
207
208 /// MemSetInst - This class wraps the llvm.memset intrinsic.
209 ///
210 class MemSetInst : public MemIntrinsic {
211 public:
212 /// get* - Return the arguments to the instruction.
213 ///
214 Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
215 const Use &getValueUse() const { return getArgOperandUse(1); }
216 Use &getValueUse() { return getArgOperandUse(1); }
217
218 void setValue(Value *Val) {
219 assert(getValue()->getType() == Val->getType() &&
220 "setValue called with value of wrong type!");
221 setArgOperand(1, Val);
222 }
223
224 // Methods for support type inquiry through isa, cast, and dyn_cast:
225 static inline bool classof(const IntrinsicInst *I) {
226 return I->getIntrinsicID() == Intrinsic::memset;
227 }
228 static inline bool classof(const Value *V) {
229 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
230 }
231 };
232
233 /// MemTransferInst - This class wraps the llvm.memcpy/memmove intrinsics.
234 ///
235 class MemTransferInst : public MemIntrinsic {
236 public:
237 /// get* - Return the arguments to the instruction.
238 ///
239 Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); }
240 const Use &getRawSourceUse() const { return getArgOperandUse(1); }
241 Use &getRawSourceUse() { return getArgOperandUse(1); }
242
243 /// getSource - This is just like getRawSource, but it strips off any cast
244 /// instructions that feed it, giving the original input. The returned
245 /// value is guaranteed to be a pointer.
246 Value *getSource() const { return getRawSource()->stripPointerCasts(); }
247
248 unsigned getSourceAddressSpace() const {
249 return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
250 }
251
252 void setSource(Value *Ptr) {
253 assert(getRawSource()->getType() == Ptr->getType() &&
254 "setSource called with pointer of wrong type!");
255 setArgOperand(1, Ptr);
256 }
257
258 // Methods for support type inquiry through isa, cast, and dyn_cast:
259 static inline bool classof(const IntrinsicInst *I) {
260 return I->getIntrinsicID() == Intrinsic::memcpy ||
261 I->getIntrinsicID() == Intrinsic::memmove;
262 }
263 static inline bool classof(const Value *V) {
264 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
265 }
266 };
267
268
269 /// MemCpyInst - This class wraps the llvm.memcpy intrinsic.
270 ///
271 class MemCpyInst : public MemTransferInst {
272 public:
273 // Methods for support type inquiry through isa, cast, and dyn_cast:
274 static inline bool classof(const IntrinsicInst *I) {
275 return I->getIntrinsicID() == Intrinsic::memcpy;
276 }
277 static inline bool classof(const Value *V) {
278 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
279 }
280 };
281
282 /// MemMoveInst - This class wraps the llvm.memmove intrinsic.
283 ///
284 class MemMoveInst : public MemTransferInst {
285 public:
286 // Methods for support type inquiry through isa, cast, and dyn_cast:
287 static inline bool classof(const IntrinsicInst *I) {
288 return I->getIntrinsicID() == Intrinsic::memmove;
289 }
290 static inline bool classof(const Value *V) {
291 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
292 }
293 };
294
295 /// VAStartInst - This represents the llvm.va_start intrinsic.
296 ///
297 class VAStartInst : public IntrinsicInst {
298 public:
299 static inline bool classof(const IntrinsicInst *I) {
300 return I->getIntrinsicID() == Intrinsic::vastart;
301 }
302 static inline bool classof(const Value *V) {
303 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
304 }
305
306 Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
307 };
308
309 /// VAEndInst - This represents the llvm.va_end intrinsic.
310 ///
311 class VAEndInst : public IntrinsicInst {
312 public:
313 static inline bool classof(const IntrinsicInst *I) {
314 return I->getIntrinsicID() == Intrinsic::vaend;
315 }
316 static inline bool classof(const Value *V) {
317 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
318 }
319
320 Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
321 };
322
323 /// VACopyInst - This represents the llvm.va_copy intrinsic.
324 ///
325 class VACopyInst : public IntrinsicInst {
326 public:
327 static inline bool classof(const IntrinsicInst *I) {
328 return I->getIntrinsicID() == Intrinsic::vacopy;
329 }
330 static inline bool classof(const Value *V) {
331 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
332 }
333
334 Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
335 Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
336 };
337
338 /// This represents the llvm.instrprof_increment intrinsic.
339 class InstrProfIncrementInst : public IntrinsicInst {
340 public:
341 static inline bool classof(const IntrinsicInst *I) {
342 return I->getIntrinsicID() == Intrinsic::instrprof_increment;
343 }
344 static inline bool classof(const Value *V) {
345 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
346 }
347
348 GlobalVariable *getName() const {
349 return cast<GlobalVariable>(
350 const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
351 }
352
353 ConstantInt *getHash() const {
354 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
355 }
356
357 ConstantInt *getNumCounters() const {
358 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
359 }
360
361 ConstantInt *getIndex() const {
362 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
363 }
364 };
365 }
366
367 #endif