]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/IntrinsicInst.h
Update bmake to version 20180919
[FreeBSD/FreeBSD.git] / contrib / 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/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GlobalVariable.h"
31 #include "llvm/IR/Instructions.h"
32 #include "llvm/IR/Intrinsics.h"
33 #include "llvm/IR/Metadata.h"
34 #include "llvm/IR/Value.h"
35 #include "llvm/Support/Casting.h"
36 #include <cassert>
37 #include <cstdint>
38
39 namespace llvm {
40
41   /// A wrapper class for inspecting calls to intrinsic functions.
42   /// This allows the standard isa/dyncast/cast functionality to work with calls
43   /// to intrinsic functions.
44   class IntrinsicInst : public CallInst {
45   public:
46     IntrinsicInst() = delete;
47     IntrinsicInst(const IntrinsicInst &) = delete;
48     IntrinsicInst &operator=(const IntrinsicInst &) = delete;
49
50     /// Return the intrinsic ID of this intrinsic.
51     Intrinsic::ID getIntrinsicID() const {
52       return getCalledFunction()->getIntrinsicID();
53     }
54
55     // Methods for support type inquiry through isa, cast, and dyn_cast:
56     static bool classof(const CallInst *I) {
57       if (const Function *CF = I->getCalledFunction())
58         return CF->isIntrinsic();
59       return false;
60     }
61     static bool classof(const Value *V) {
62       return isa<CallInst>(V) && classof(cast<CallInst>(V));
63     }
64   };
65
66   /// This is the common base class for debug info intrinsics.
67   class DbgInfoIntrinsic : public IntrinsicInst {
68   public:
69     /// Get the location corresponding to the variable referenced by the debug
70     /// info intrinsic.  Depending on the intrinsic, this could be the
71     /// variable's value or its address.
72     Value *getVariableLocation(bool AllowNullOp = true) const;
73
74     /// Does this describe the address of a local variable. True for dbg.addr
75     /// and dbg.declare, but not dbg.value, which describes its value.
76     bool isAddressOfVariable() const {
77       return getIntrinsicID() != Intrinsic::dbg_value;
78     }
79
80     DILocalVariable *getVariable() const {
81       return cast<DILocalVariable>(getRawVariable());
82     }
83
84     DIExpression *getExpression() const {
85       return cast<DIExpression>(getRawExpression());
86     }
87
88     Metadata *getRawVariable() const {
89       return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
90     }
91
92     Metadata *getRawExpression() const {
93       return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
94     }
95
96     /// \name Casting methods
97     /// @{
98     static bool classof(const IntrinsicInst *I) {
99       switch (I->getIntrinsicID()) {
100       case Intrinsic::dbg_declare:
101       case Intrinsic::dbg_value:
102       case Intrinsic::dbg_addr:
103         return true;
104       default: return false;
105       }
106     }
107     static bool classof(const Value *V) {
108       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
109     }
110     /// @}
111   };
112
113   /// This represents the llvm.dbg.declare instruction.
114   class DbgDeclareInst : public DbgInfoIntrinsic {
115   public:
116     Value *getAddress() const { return getVariableLocation(); }
117
118     /// \name Casting methods
119     /// @{
120     static bool classof(const IntrinsicInst *I) {
121       return I->getIntrinsicID() == Intrinsic::dbg_declare;
122     }
123     static bool classof(const Value *V) {
124       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
125     }
126     /// @}
127   };
128
129   /// This represents the llvm.dbg.addr instruction.
130   class DbgAddrIntrinsic : public DbgInfoIntrinsic {
131   public:
132     Value *getAddress() const { return getVariableLocation(); }
133
134     /// \name Casting methods
135     /// @{
136     static bool classof(const IntrinsicInst *I) {
137       return I->getIntrinsicID() == Intrinsic::dbg_addr;
138     }
139     static bool classof(const Value *V) {
140       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
141     }
142   };
143
144   /// This represents the llvm.dbg.value instruction.
145   class DbgValueInst : public DbgInfoIntrinsic {
146   public:
147     Value *getValue() const {
148       return getVariableLocation(/* AllowNullOp = */ false);
149     }
150
151     /// \name Casting methods
152     /// @{
153     static bool classof(const IntrinsicInst *I) {
154       return I->getIntrinsicID() == Intrinsic::dbg_value;
155     }
156     static bool classof(const Value *V) {
157       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
158     }
159     /// @}
160   };
161
162   /// This is the common base class for constrained floating point intrinsics.
163   class ConstrainedFPIntrinsic : public IntrinsicInst {
164   public:
165     enum RoundingMode {
166       rmInvalid,
167       rmDynamic,
168       rmToNearest,
169       rmDownward,
170       rmUpward,
171       rmTowardZero
172     };
173
174     enum ExceptionBehavior {
175       ebInvalid,
176       ebIgnore,
177       ebMayTrap,
178       ebStrict
179     };
180
181     bool isUnaryOp() const;
182     bool isTernaryOp() const;
183     RoundingMode getRoundingMode() const;
184     ExceptionBehavior getExceptionBehavior() const;
185
186     // Methods for support type inquiry through isa, cast, and dyn_cast:
187     static bool classof(const IntrinsicInst *I) {
188       switch (I->getIntrinsicID()) {
189       case Intrinsic::experimental_constrained_fadd:
190       case Intrinsic::experimental_constrained_fsub:
191       case Intrinsic::experimental_constrained_fmul:
192       case Intrinsic::experimental_constrained_fdiv:
193       case Intrinsic::experimental_constrained_frem:
194       case Intrinsic::experimental_constrained_fma:
195       case Intrinsic::experimental_constrained_sqrt:
196       case Intrinsic::experimental_constrained_pow:
197       case Intrinsic::experimental_constrained_powi:
198       case Intrinsic::experimental_constrained_sin:
199       case Intrinsic::experimental_constrained_cos:
200       case Intrinsic::experimental_constrained_exp:
201       case Intrinsic::experimental_constrained_exp2:
202       case Intrinsic::experimental_constrained_log:
203       case Intrinsic::experimental_constrained_log10:
204       case Intrinsic::experimental_constrained_log2:
205       case Intrinsic::experimental_constrained_rint:
206       case Intrinsic::experimental_constrained_nearbyint:
207         return true;
208       default: return false;
209       }
210     }
211     static bool classof(const Value *V) {
212       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
213     }
214   };
215
216   /// Common base class for all memory intrinsics. Simply provides
217   /// common methods.
218   /// Written as CRTP to avoid a common base class amongst the
219   /// three atomicity hierarchies.
220   template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
221   private:
222     enum { ARG_DEST = 0, ARG_LENGTH = 2 };
223
224   public:
225     Value *getRawDest() const {
226       return const_cast<Value *>(getArgOperand(ARG_DEST));
227     }
228     const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
229     Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
230
231     Value *getLength() const {
232       return const_cast<Value *>(getArgOperand(ARG_LENGTH));
233     }
234     const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
235     Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
236
237     /// This is just like getRawDest, but it strips off any cast
238     /// instructions (including addrspacecast) that feed it, giving the
239     /// original input.  The returned value is guaranteed to be a pointer.
240     Value *getDest() const { return getRawDest()->stripPointerCasts(); }
241
242     unsigned getDestAddressSpace() const {
243       return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
244     }
245
246     /// Set the specified arguments of the instruction.
247     void setDest(Value *Ptr) {
248       assert(getRawDest()->getType() == Ptr->getType() &&
249              "setDest called with pointer of wrong type!");
250       setArgOperand(ARG_DEST, Ptr);
251     }
252
253     void setLength(Value *L) {
254       assert(getLength()->getType() == L->getType() &&
255              "setLength called with value of wrong type!");
256       setArgOperand(ARG_LENGTH, L);
257     }
258   };
259
260   // The common base class for the atomic memset/memmove/memcpy intrinsics
261   // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
262   class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
263   private:
264     enum { ARG_ELEMENTSIZE = 3 };
265
266   public:
267     Value *getRawElementSizeInBytes() const {
268       return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
269     }
270
271     ConstantInt *getElementSizeInBytesCst() const {
272       return cast<ConstantInt>(getRawElementSizeInBytes());
273     }
274
275     uint32_t getElementSizeInBytes() const {
276       return getElementSizeInBytesCst()->getZExtValue();
277     }
278
279     void setElementSizeInBytes(Constant *V) {
280       assert(V->getType() == Type::getInt8Ty(getContext()) &&
281              "setElementSizeInBytes called with value of wrong type!");
282       setArgOperand(ARG_ELEMENTSIZE, V);
283     }
284
285     static bool classof(const IntrinsicInst *I) {
286       switch (I->getIntrinsicID()) {
287       case Intrinsic::memcpy_element_unordered_atomic:
288       case Intrinsic::memmove_element_unordered_atomic:
289       case Intrinsic::memset_element_unordered_atomic:
290         return true;
291       default:
292         return false;
293       }
294     }
295     static bool classof(const Value *V) {
296       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
297     }
298   };
299
300   /// This class represents atomic memset intrinsic
301   // i.e. llvm.element.unordered.atomic.memset
302   class AtomicMemSetInst : public AtomicMemIntrinsic {
303   private:
304     enum { ARG_VALUE = 1 };
305
306   public:
307     Value *getValue() const {
308       return const_cast<Value *>(getArgOperand(ARG_VALUE));
309     }
310     const Use &getValueUse() const { return getArgOperandUse(ARG_VALUE); }
311     Use &getValueUse() { return getArgOperandUse(ARG_VALUE); }
312
313     void setValue(Value *Val) {
314       assert(getValue()->getType() == Val->getType() &&
315              "setValue called with value of wrong type!");
316       setArgOperand(ARG_VALUE, Val);
317     }
318
319     static bool classof(const IntrinsicInst *I) {
320       return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
321     }
322     static bool classof(const Value *V) {
323       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
324     }
325   };
326
327   // This class wraps the atomic memcpy/memmove intrinsics
328   // i.e. llvm.element.unordered.atomic.memcpy/memmove
329   class AtomicMemTransferInst : public AtomicMemIntrinsic {
330   private:
331     enum { ARG_SOURCE = 1 };
332
333   public:
334     /// Return the arguments to the instruction.
335     Value *getRawSource() const {
336       return const_cast<Value *>(getArgOperand(ARG_SOURCE));
337     }
338     const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
339     Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
340
341     /// This is just like getRawSource, but it strips off any cast
342     /// instructions that feed it, giving the original input.  The returned
343     /// value is guaranteed to be a pointer.
344     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
345
346     unsigned getSourceAddressSpace() const {
347       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
348     }
349
350     void setSource(Value *Ptr) {
351       assert(getRawSource()->getType() == Ptr->getType() &&
352              "setSource called with pointer of wrong type!");
353       setArgOperand(ARG_SOURCE, Ptr);
354     }
355
356     static bool classof(const IntrinsicInst *I) {
357       switch (I->getIntrinsicID()) {
358       case Intrinsic::memcpy_element_unordered_atomic:
359       case Intrinsic::memmove_element_unordered_atomic:
360         return true;
361       default:
362         return false;
363       }
364     }
365     static bool classof(const Value *V) {
366       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
367     }
368   };
369
370   /// This class represents the atomic memcpy intrinsic
371   /// i.e. llvm.element.unordered.atomic.memcpy
372   class AtomicMemCpyInst : public AtomicMemTransferInst {
373   public:
374     static bool classof(const IntrinsicInst *I) {
375       return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
376     }
377     static bool classof(const Value *V) {
378       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
379     }
380   };
381
382   /// This class represents the atomic memmove intrinsic
383   /// i.e. llvm.element.unordered.atomic.memmove
384   class AtomicMemMoveInst : public AtomicMemTransferInst {
385   public:
386     static bool classof(const IntrinsicInst *I) {
387       return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
388     }
389     static bool classof(const Value *V) {
390       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
391     }
392   };
393
394   /// This is the common base class for memset/memcpy/memmove.
395   class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
396   private:
397     enum { ARG_ALIGN = 3, ARG_VOLATILE = 4 };
398
399   public:
400     ConstantInt *getAlignmentCst() const {
401       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_ALIGN)));
402     }
403
404     unsigned getAlignment() const {
405       return getAlignmentCst()->getZExtValue();
406     }
407
408     ConstantInt *getVolatileCst() const {
409       return cast<ConstantInt>(
410           const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
411     }
412
413     bool isVolatile() const {
414       return !getVolatileCst()->isZero();
415     }
416
417     void setAlignment(Constant *A) { setArgOperand(ARG_ALIGN, A); }
418
419     void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
420
421     Type *getAlignmentType() const {
422       return getArgOperand(ARG_ALIGN)->getType();
423     }
424
425     // Methods for support type inquiry through isa, cast, and dyn_cast:
426     static bool classof(const IntrinsicInst *I) {
427       switch (I->getIntrinsicID()) {
428       case Intrinsic::memcpy:
429       case Intrinsic::memmove:
430       case Intrinsic::memset:
431         return true;
432       default: return false;
433       }
434     }
435     static bool classof(const Value *V) {
436       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
437     }
438   };
439
440   /// This class wraps the llvm.memset intrinsic.
441   class MemSetInst : public MemIntrinsic {
442   public:
443     /// Return the arguments to the instruction.
444     Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); }
445     const Use &getValueUse() const { return getArgOperandUse(1); }
446     Use &getValueUse() { return getArgOperandUse(1); }
447
448     void setValue(Value *Val) {
449       assert(getValue()->getType() == Val->getType() &&
450              "setValue called with value of wrong type!");
451       setArgOperand(1, Val);
452     }
453
454     // Methods for support type inquiry through isa, cast, and dyn_cast:
455     static bool classof(const IntrinsicInst *I) {
456       return I->getIntrinsicID() == Intrinsic::memset;
457     }
458     static bool classof(const Value *V) {
459       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
460     }
461   };
462
463   /// This class wraps the llvm.memcpy/memmove intrinsics.
464   class MemTransferInst : public MemIntrinsic {
465   public:
466     /// Return the arguments to the instruction.
467     Value *getRawSource() const { return const_cast<Value*>(getArgOperand(1)); }
468     const Use &getRawSourceUse() const { return getArgOperandUse(1); }
469     Use &getRawSourceUse() { return getArgOperandUse(1); }
470
471     /// This is just like getRawSource, but it strips off any cast
472     /// instructions that feed it, giving the original input.  The returned
473     /// value is guaranteed to be a pointer.
474     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
475
476     unsigned getSourceAddressSpace() const {
477       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
478     }
479
480     void setSource(Value *Ptr) {
481       assert(getRawSource()->getType() == Ptr->getType() &&
482              "setSource called with pointer of wrong type!");
483       setArgOperand(1, Ptr);
484     }
485
486     // Methods for support type inquiry through isa, cast, and dyn_cast:
487     static bool classof(const IntrinsicInst *I) {
488       return I->getIntrinsicID() == Intrinsic::memcpy ||
489              I->getIntrinsicID() == Intrinsic::memmove;
490     }
491     static bool classof(const Value *V) {
492       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
493     }
494   };
495
496   /// This class wraps the llvm.memcpy intrinsic.
497   class MemCpyInst : public MemTransferInst {
498   public:
499     // Methods for support type inquiry through isa, cast, and dyn_cast:
500     static bool classof(const IntrinsicInst *I) {
501       return I->getIntrinsicID() == Intrinsic::memcpy;
502     }
503     static bool classof(const Value *V) {
504       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
505     }
506   };
507
508   /// This class wraps the llvm.memmove intrinsic.
509   class MemMoveInst : public MemTransferInst {
510   public:
511     // Methods for support type inquiry through isa, cast, and dyn_cast:
512     static bool classof(const IntrinsicInst *I) {
513       return I->getIntrinsicID() == Intrinsic::memmove;
514     }
515     static bool classof(const Value *V) {
516       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
517     }
518   };
519
520   // The common base class for any memset/memmove/memcpy intrinsics;
521   // whether they be atomic or non-atomic.
522   // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
523   //  and llvm.memset/memcpy/memmove
524   class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
525   public:
526     bool isVolatile() const {
527       // Only the non-atomic intrinsics can be volatile
528       if (auto *MI = dyn_cast<MemIntrinsic>(this))
529         return MI->isVolatile();
530       return false;
531     }
532
533     static bool classof(const IntrinsicInst *I) {
534       switch (I->getIntrinsicID()) {
535       case Intrinsic::memcpy:
536       case Intrinsic::memmove:
537       case Intrinsic::memset:
538       case Intrinsic::memcpy_element_unordered_atomic:
539       case Intrinsic::memmove_element_unordered_atomic:
540       case Intrinsic::memset_element_unordered_atomic:
541         return true;
542       default:
543         return false;
544       }
545     }
546     static bool classof(const Value *V) {
547       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
548     }
549   };
550
551   /// This class represents any memset intrinsic
552   // i.e. llvm.element.unordered.atomic.memset
553   // and  llvm.memset
554   class AnyMemSetInst : public AnyMemIntrinsic {
555   private:
556     enum { ARG_VALUE = 1 };
557
558   public:
559     Value *getValue() const {
560       return const_cast<Value *>(getArgOperand(ARG_VALUE));
561     }
562     const Use &getValueUse() const { return getArgOperandUse(ARG_VALUE); }
563     Use &getValueUse() { return getArgOperandUse(ARG_VALUE); }
564
565     void setValue(Value *Val) {
566       assert(getValue()->getType() == Val->getType() &&
567              "setValue called with value of wrong type!");
568       setArgOperand(ARG_VALUE, Val);
569     }
570
571     static bool classof(const IntrinsicInst *I) {
572       switch (I->getIntrinsicID()) {
573       case Intrinsic::memset:
574       case Intrinsic::memset_element_unordered_atomic:
575         return true;
576       default:
577         return false;
578       }
579     }
580     static bool classof(const Value *V) {
581       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
582     }
583   };
584
585   // This class wraps any memcpy/memmove intrinsics
586   // i.e. llvm.element.unordered.atomic.memcpy/memmove
587   // and  llvm.memcpy/memmove
588   class AnyMemTransferInst : public AnyMemIntrinsic {
589   private:
590     enum { ARG_SOURCE = 1 };
591
592   public:
593     /// Return the arguments to the instruction.
594     Value *getRawSource() const {
595       return const_cast<Value *>(getArgOperand(ARG_SOURCE));
596     }
597     const Use &getRawSourceUse() const { return getArgOperandUse(ARG_SOURCE); }
598     Use &getRawSourceUse() { return getArgOperandUse(ARG_SOURCE); }
599
600     /// This is just like getRawSource, but it strips off any cast
601     /// instructions that feed it, giving the original input.  The returned
602     /// value is guaranteed to be a pointer.
603     Value *getSource() const { return getRawSource()->stripPointerCasts(); }
604
605     unsigned getSourceAddressSpace() const {
606       return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
607     }
608
609     void setSource(Value *Ptr) {
610       assert(getRawSource()->getType() == Ptr->getType() &&
611              "setSource called with pointer of wrong type!");
612       setArgOperand(ARG_SOURCE, Ptr);
613     }
614
615     static bool classof(const IntrinsicInst *I) {
616       switch (I->getIntrinsicID()) {
617       case Intrinsic::memcpy:
618       case Intrinsic::memmove:
619       case Intrinsic::memcpy_element_unordered_atomic:
620       case Intrinsic::memmove_element_unordered_atomic:
621         return true;
622       default:
623         return false;
624       }
625     }
626     static bool classof(const Value *V) {
627       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
628     }
629   };
630
631   /// This class represents any memcpy intrinsic
632   /// i.e. llvm.element.unordered.atomic.memcpy
633   ///  and llvm.memcpy
634   class AnyMemCpyInst : public AnyMemTransferInst {
635   public:
636     static bool classof(const IntrinsicInst *I) {
637       switch (I->getIntrinsicID()) {
638       case Intrinsic::memcpy:
639       case Intrinsic::memcpy_element_unordered_atomic:
640         return true;
641       default:
642         return false;
643       }
644     }
645     static bool classof(const Value *V) {
646       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
647     }
648   };
649
650   /// This class represents any memmove intrinsic
651   /// i.e. llvm.element.unordered.atomic.memmove
652   ///  and llvm.memmove
653   class AnyMemMoveInst : public AnyMemTransferInst {
654   public:
655     static bool classof(const IntrinsicInst *I) {
656       switch (I->getIntrinsicID()) {
657       case Intrinsic::memmove:
658       case Intrinsic::memmove_element_unordered_atomic:
659         return true;
660       default:
661         return false;
662       }
663     }
664     static bool classof(const Value *V) {
665       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
666     }
667   };
668
669   /// This represents the llvm.va_start intrinsic.
670   class VAStartInst : public IntrinsicInst {
671   public:
672     static bool classof(const IntrinsicInst *I) {
673       return I->getIntrinsicID() == Intrinsic::vastart;
674     }
675     static bool classof(const Value *V) {
676       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
677     }
678
679     Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
680   };
681
682   /// This represents the llvm.va_end intrinsic.
683   class VAEndInst : public IntrinsicInst {
684   public:
685     static bool classof(const IntrinsicInst *I) {
686       return I->getIntrinsicID() == Intrinsic::vaend;
687     }
688     static bool classof(const Value *V) {
689       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
690     }
691
692     Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
693   };
694
695   /// This represents the llvm.va_copy intrinsic.
696   class VACopyInst : public IntrinsicInst {
697   public:
698     static bool classof(const IntrinsicInst *I) {
699       return I->getIntrinsicID() == Intrinsic::vacopy;
700     }
701     static bool classof(const Value *V) {
702       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
703     }
704
705     Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
706     Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
707   };
708
709   /// This represents the llvm.instrprof_increment intrinsic.
710   class InstrProfIncrementInst : public IntrinsicInst {
711   public:
712     static bool classof(const IntrinsicInst *I) {
713       return I->getIntrinsicID() == Intrinsic::instrprof_increment;
714     }
715     static bool classof(const Value *V) {
716       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
717     }
718
719     GlobalVariable *getName() const {
720       return cast<GlobalVariable>(
721           const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
722     }
723
724     ConstantInt *getHash() const {
725       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
726     }
727
728     ConstantInt *getNumCounters() const {
729       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
730     }
731
732     ConstantInt *getIndex() const {
733       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
734     }
735
736     Value *getStep() const;
737   };
738
739   class InstrProfIncrementInstStep : public InstrProfIncrementInst {
740   public:
741     static bool classof(const IntrinsicInst *I) {
742       return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
743     }
744     static bool classof(const Value *V) {
745       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
746     }
747   };
748
749   /// This represents the llvm.instrprof_value_profile intrinsic.
750   class InstrProfValueProfileInst : public IntrinsicInst {
751   public:
752     static bool classof(const IntrinsicInst *I) {
753       return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
754     }
755     static bool classof(const Value *V) {
756       return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
757     }
758
759     GlobalVariable *getName() const {
760       return cast<GlobalVariable>(
761           const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
762     }
763
764     ConstantInt *getHash() const {
765       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
766     }
767
768     Value *getTargetValue() const {
769       return cast<Value>(const_cast<Value *>(getArgOperand(2)));
770     }
771
772     ConstantInt *getValueKind() const {
773       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
774     }
775
776     // Returns the value site index.
777     ConstantInt *getIndex() const {
778       return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
779     }
780   };
781
782 } // end namespace llvm
783
784 #endif // LLVM_IR_INTRINSICINST_H