1 //===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines classes that make it really easy to deal with intrinsic
10 // functions with the isa/dyncast family of functions. In particular, this
11 // allows you to do things like:
13 // if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
14 // ... MCI->getDest() ... MCI->getSource() ...
16 // All intrinsic function calls are instances of the call instruction, so these
17 // are all subclasses of the CallInst class. Note that none of these classes
18 // has state or virtual methods, which is an important part of this gross/neat
21 //===----------------------------------------------------------------------===//
23 #ifndef LLVM_IR_INTRINSICINST_H
24 #define LLVM_IR_INTRINSICINST_H
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/FPEnv.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"
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 {
46 IntrinsicInst() = delete;
47 IntrinsicInst(const IntrinsicInst &) = delete;
48 IntrinsicInst &operator=(const IntrinsicInst &) = delete;
50 /// Return the intrinsic ID of this intrinsic.
51 Intrinsic::ID getIntrinsicID() const {
52 return getCalledFunction()->getIntrinsicID();
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();
61 static bool classof(const Value *V) {
62 return isa<CallInst>(V) && classof(cast<CallInst>(V));
66 /// This is the common base class for debug info intrinsics.
67 class DbgInfoIntrinsic : public IntrinsicInst {
69 /// \name Casting methods
71 static bool classof(const IntrinsicInst *I) {
72 switch (I->getIntrinsicID()) {
73 case Intrinsic::dbg_declare:
74 case Intrinsic::dbg_value:
75 case Intrinsic::dbg_addr:
76 case Intrinsic::dbg_label:
78 default: return false;
81 static bool classof(const Value *V) {
82 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
87 /// This is the common base class for debug info intrinsics for variables.
88 class DbgVariableIntrinsic : public DbgInfoIntrinsic {
90 /// Get the location corresponding to the variable referenced by the debug
91 /// info intrinsic. Depending on the intrinsic, this could be the
92 /// variable's value or its address.
93 Value *getVariableLocation(bool AllowNullOp = true) const;
95 /// Does this describe the address of a local variable. True for dbg.addr
96 /// and dbg.declare, but not dbg.value, which describes its value.
97 bool isAddressOfVariable() const {
98 return getIntrinsicID() != Intrinsic::dbg_value;
101 DILocalVariable *getVariable() const {
102 return cast<DILocalVariable>(getRawVariable());
105 DIExpression *getExpression() const {
106 return cast<DIExpression>(getRawExpression());
109 Metadata *getRawVariable() const {
110 return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
113 Metadata *getRawExpression() const {
114 return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
117 /// Get the size (in bits) of the variable, or fragment of the variable that
119 Optional<uint64_t> getFragmentSizeInBits() const;
121 /// \name Casting methods
123 static bool classof(const IntrinsicInst *I) {
124 switch (I->getIntrinsicID()) {
125 case Intrinsic::dbg_declare:
126 case Intrinsic::dbg_value:
127 case Intrinsic::dbg_addr:
129 default: return false;
132 static bool classof(const Value *V) {
133 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
138 /// This represents the llvm.dbg.declare instruction.
139 class DbgDeclareInst : public DbgVariableIntrinsic {
141 Value *getAddress() const { return getVariableLocation(); }
143 /// \name Casting methods
145 static bool classof(const IntrinsicInst *I) {
146 return I->getIntrinsicID() == Intrinsic::dbg_declare;
148 static bool classof(const Value *V) {
149 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
154 /// This represents the llvm.dbg.addr instruction.
155 class DbgAddrIntrinsic : public DbgVariableIntrinsic {
157 Value *getAddress() const { return getVariableLocation(); }
159 /// \name Casting methods
161 static bool classof(const IntrinsicInst *I) {
162 return I->getIntrinsicID() == Intrinsic::dbg_addr;
164 static bool classof(const Value *V) {
165 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
169 /// This represents the llvm.dbg.value instruction.
170 class DbgValueInst : public DbgVariableIntrinsic {
172 Value *getValue() const {
173 return getVariableLocation(/* AllowNullOp = */ false);
176 /// \name Casting methods
178 static bool classof(const IntrinsicInst *I) {
179 return I->getIntrinsicID() == Intrinsic::dbg_value;
181 static bool classof(const Value *V) {
182 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
187 /// This represents the llvm.dbg.label instruction.
188 class DbgLabelInst : public DbgInfoIntrinsic {
190 DILabel *getLabel() const {
191 return cast<DILabel>(getRawLabel());
194 Metadata *getRawLabel() const {
195 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
198 /// Methods for support type inquiry through isa, cast, and dyn_cast:
200 static bool classof(const IntrinsicInst *I) {
201 return I->getIntrinsicID() == Intrinsic::dbg_label;
203 static bool classof(const Value *V) {
204 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
209 /// This is the common base class for constrained floating point intrinsics.
210 class ConstrainedFPIntrinsic : public IntrinsicInst {
212 bool isUnaryOp() const;
213 bool isTernaryOp() const;
214 Optional<fp::RoundingMode> getRoundingMode() const;
215 Optional<fp::ExceptionBehavior> getExceptionBehavior() const;
217 // Methods for support type inquiry through isa, cast, and dyn_cast:
218 static bool classof(const IntrinsicInst *I);
219 static bool classof(const Value *V) {
220 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
224 /// Constrained floating point compare intrinsics.
225 class ConstrainedFPCmpIntrinsic : public ConstrainedFPIntrinsic {
227 FCmpInst::Predicate getPredicate() const;
229 // Methods for support type inquiry through isa, cast, and dyn_cast:
230 static bool classof(const IntrinsicInst *I) {
231 switch (I->getIntrinsicID()) {
232 case Intrinsic::experimental_constrained_fcmp:
233 case Intrinsic::experimental_constrained_fcmps:
235 default: return false;
238 static bool classof(const Value *V) {
239 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
243 /// This class represents an intrinsic that is based on a binary operation.
244 /// This includes op.with.overflow and saturating add/sub intrinsics.
245 class BinaryOpIntrinsic : public IntrinsicInst {
247 static bool classof(const IntrinsicInst *I) {
248 switch (I->getIntrinsicID()) {
249 case Intrinsic::uadd_with_overflow:
250 case Intrinsic::sadd_with_overflow:
251 case Intrinsic::usub_with_overflow:
252 case Intrinsic::ssub_with_overflow:
253 case Intrinsic::umul_with_overflow:
254 case Intrinsic::smul_with_overflow:
255 case Intrinsic::uadd_sat:
256 case Intrinsic::sadd_sat:
257 case Intrinsic::usub_sat:
258 case Intrinsic::ssub_sat:
264 static bool classof(const Value *V) {
265 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
268 Value *getLHS() const { return const_cast<Value*>(getArgOperand(0)); }
269 Value *getRHS() const { return const_cast<Value*>(getArgOperand(1)); }
271 /// Returns the binary operation underlying the intrinsic.
272 Instruction::BinaryOps getBinaryOp() const;
274 /// Whether the intrinsic is signed or unsigned.
275 bool isSigned() const;
277 /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
278 unsigned getNoWrapKind() const;
281 /// Represents an op.with.overflow intrinsic.
282 class WithOverflowInst : public BinaryOpIntrinsic {
284 static bool classof(const IntrinsicInst *I) {
285 switch (I->getIntrinsicID()) {
286 case Intrinsic::uadd_with_overflow:
287 case Intrinsic::sadd_with_overflow:
288 case Intrinsic::usub_with_overflow:
289 case Intrinsic::ssub_with_overflow:
290 case Intrinsic::umul_with_overflow:
291 case Intrinsic::smul_with_overflow:
297 static bool classof(const Value *V) {
298 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
302 /// Represents a saturating add/sub intrinsic.
303 class SaturatingInst : public BinaryOpIntrinsic {
305 static bool classof(const IntrinsicInst *I) {
306 switch (I->getIntrinsicID()) {
307 case Intrinsic::uadd_sat:
308 case Intrinsic::sadd_sat:
309 case Intrinsic::usub_sat:
310 case Intrinsic::ssub_sat:
316 static bool classof(const Value *V) {
317 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
321 /// Common base class for all memory intrinsics. Simply provides
323 /// Written as CRTP to avoid a common base class amongst the
324 /// three atomicity hierarchies.
325 template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
327 enum { ARG_DEST = 0, ARG_LENGTH = 2 };
330 Value *getRawDest() const {
331 return const_cast<Value *>(getArgOperand(ARG_DEST));
333 const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
334 Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
336 Value *getLength() const {
337 return const_cast<Value *>(getArgOperand(ARG_LENGTH));
339 const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
340 Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
342 /// This is just like getRawDest, but it strips off any cast
343 /// instructions (including addrspacecast) that feed it, giving the
344 /// original input. The returned value is guaranteed to be a pointer.
345 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
347 unsigned getDestAddressSpace() const {
348 return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
351 /// FIXME: Remove this function once transition to Align is over.
352 /// Use getDestAlign() instead.
353 unsigned getDestAlignment() const { return getParamAlignment(ARG_DEST); }
354 MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
356 /// Set the specified arguments of the instruction.
357 void setDest(Value *Ptr) {
358 assert(getRawDest()->getType() == Ptr->getType() &&
359 "setDest called with pointer of wrong type!");
360 setArgOperand(ARG_DEST, Ptr);
363 /// FIXME: Remove this function once transition to Align is over.
364 /// Use the version that takes MaybeAlign instead of this one.
365 void setDestAlignment(unsigned Alignment) {
366 setDestAlignment(MaybeAlign(Alignment));
368 void setDestAlignment(MaybeAlign Alignment) {
369 removeParamAttr(ARG_DEST, Attribute::Alignment);
371 addParamAttr(ARG_DEST,
372 Attribute::getWithAlignment(getContext(), *Alignment));
374 void setDestAlignment(Align Alignment) {
375 removeParamAttr(ARG_DEST, Attribute::Alignment);
376 addParamAttr(ARG_DEST,
377 Attribute::getWithAlignment(getContext(), Alignment));
380 void setLength(Value *L) {
381 assert(getLength()->getType() == L->getType() &&
382 "setLength called with value of wrong type!");
383 setArgOperand(ARG_LENGTH, L);
387 /// Common base class for all memory transfer intrinsics. Simply provides
389 template <class BaseCL> class MemTransferBase : public BaseCL {
391 enum { ARG_SOURCE = 1 };
394 /// Return the arguments to the instruction.
395 Value *getRawSource() const {
396 return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
398 const Use &getRawSourceUse() const {
399 return BaseCL::getArgOperandUse(ARG_SOURCE);
401 Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
403 /// This is just like getRawSource, but it strips off any cast
404 /// instructions that feed it, giving the original input. The returned
405 /// value is guaranteed to be a pointer.
406 Value *getSource() const { return getRawSource()->stripPointerCasts(); }
408 unsigned getSourceAddressSpace() const {
409 return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
412 /// FIXME: Remove this function once transition to Align is over.
413 /// Use getSourceAlign() instead.
414 unsigned getSourceAlignment() const {
415 return BaseCL::getParamAlignment(ARG_SOURCE);
418 MaybeAlign getSourceAlign() const {
419 return BaseCL::getParamAlign(ARG_SOURCE);
422 void setSource(Value *Ptr) {
423 assert(getRawSource()->getType() == Ptr->getType() &&
424 "setSource called with pointer of wrong type!");
425 BaseCL::setArgOperand(ARG_SOURCE, Ptr);
428 /// FIXME: Remove this function once transition to Align is over.
429 /// Use the version that takes MaybeAlign instead of this one.
430 void setSourceAlignment(unsigned Alignment) {
431 setSourceAlignment(MaybeAlign(Alignment));
433 void setSourceAlignment(MaybeAlign Alignment) {
434 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
436 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
437 BaseCL::getContext(), *Alignment));
439 void setSourceAlignment(Align Alignment) {
440 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
441 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
442 BaseCL::getContext(), Alignment));
446 /// Common base class for all memset intrinsics. Simply provides
448 template <class BaseCL> class MemSetBase : public BaseCL {
450 enum { ARG_VALUE = 1 };
453 Value *getValue() const {
454 return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
456 const Use &getValueUse() const {
457 return BaseCL::getArgOperandUse(ARG_VALUE);
459 Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
461 void setValue(Value *Val) {
462 assert(getValue()->getType() == Val->getType() &&
463 "setValue called with value of wrong type!");
464 BaseCL::setArgOperand(ARG_VALUE, Val);
468 // The common base class for the atomic memset/memmove/memcpy intrinsics
469 // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
470 class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
472 enum { ARG_ELEMENTSIZE = 3 };
475 Value *getRawElementSizeInBytes() const {
476 return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
479 ConstantInt *getElementSizeInBytesCst() const {
480 return cast<ConstantInt>(getRawElementSizeInBytes());
483 uint32_t getElementSizeInBytes() const {
484 return getElementSizeInBytesCst()->getZExtValue();
487 void setElementSizeInBytes(Constant *V) {
488 assert(V->getType() == Type::getInt8Ty(getContext()) &&
489 "setElementSizeInBytes called with value of wrong type!");
490 setArgOperand(ARG_ELEMENTSIZE, V);
493 static bool classof(const IntrinsicInst *I) {
494 switch (I->getIntrinsicID()) {
495 case Intrinsic::memcpy_element_unordered_atomic:
496 case Intrinsic::memmove_element_unordered_atomic:
497 case Intrinsic::memset_element_unordered_atomic:
503 static bool classof(const Value *V) {
504 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
508 /// This class represents atomic memset intrinsic
509 // i.e. llvm.element.unordered.atomic.memset
510 class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
512 static bool classof(const IntrinsicInst *I) {
513 return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
515 static bool classof(const Value *V) {
516 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
520 // This class wraps the atomic memcpy/memmove intrinsics
521 // i.e. llvm.element.unordered.atomic.memcpy/memmove
522 class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
524 static bool classof(const IntrinsicInst *I) {
525 switch (I->getIntrinsicID()) {
526 case Intrinsic::memcpy_element_unordered_atomic:
527 case Intrinsic::memmove_element_unordered_atomic:
533 static bool classof(const Value *V) {
534 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
538 /// This class represents the atomic memcpy intrinsic
539 /// i.e. llvm.element.unordered.atomic.memcpy
540 class AtomicMemCpyInst : public AtomicMemTransferInst {
542 static bool classof(const IntrinsicInst *I) {
543 return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
545 static bool classof(const Value *V) {
546 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
550 /// This class represents the atomic memmove intrinsic
551 /// i.e. llvm.element.unordered.atomic.memmove
552 class AtomicMemMoveInst : public AtomicMemTransferInst {
554 static bool classof(const IntrinsicInst *I) {
555 return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
557 static bool classof(const Value *V) {
558 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
562 /// This is the common base class for memset/memcpy/memmove.
563 class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
565 enum { ARG_VOLATILE = 3 };
568 ConstantInt *getVolatileCst() const {
569 return cast<ConstantInt>(
570 const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
573 bool isVolatile() const {
574 return !getVolatileCst()->isZero();
577 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
579 // Methods for support type inquiry through isa, cast, and dyn_cast:
580 static bool classof(const IntrinsicInst *I) {
581 switch (I->getIntrinsicID()) {
582 case Intrinsic::memcpy:
583 case Intrinsic::memmove:
584 case Intrinsic::memset:
586 default: return false;
589 static bool classof(const Value *V) {
590 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
594 /// This class wraps the llvm.memset intrinsic.
595 class MemSetInst : public MemSetBase<MemIntrinsic> {
597 // Methods for support type inquiry through isa, cast, and dyn_cast:
598 static bool classof(const IntrinsicInst *I) {
599 return I->getIntrinsicID() == Intrinsic::memset;
601 static bool classof(const Value *V) {
602 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
606 /// This class wraps the llvm.memcpy/memmove intrinsics.
607 class MemTransferInst : public MemTransferBase<MemIntrinsic> {
609 // Methods for support type inquiry through isa, cast, and dyn_cast:
610 static bool classof(const IntrinsicInst *I) {
611 return I->getIntrinsicID() == Intrinsic::memcpy ||
612 I->getIntrinsicID() == Intrinsic::memmove;
614 static bool classof(const Value *V) {
615 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
619 /// This class wraps the llvm.memcpy intrinsic.
620 class MemCpyInst : public MemTransferInst {
622 // Methods for support type inquiry through isa, cast, and dyn_cast:
623 static bool classof(const IntrinsicInst *I) {
624 return I->getIntrinsicID() == Intrinsic::memcpy;
626 static bool classof(const Value *V) {
627 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
631 /// This class wraps the llvm.memmove intrinsic.
632 class MemMoveInst : public MemTransferInst {
634 // Methods for support type inquiry through isa, cast, and dyn_cast:
635 static bool classof(const IntrinsicInst *I) {
636 return I->getIntrinsicID() == Intrinsic::memmove;
638 static bool classof(const Value *V) {
639 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
643 // The common base class for any memset/memmove/memcpy intrinsics;
644 // whether they be atomic or non-atomic.
645 // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
646 // and llvm.memset/memcpy/memmove
647 class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
649 bool isVolatile() const {
650 // Only the non-atomic intrinsics can be volatile
651 if (auto *MI = dyn_cast<MemIntrinsic>(this))
652 return MI->isVolatile();
656 static bool classof(const IntrinsicInst *I) {
657 switch (I->getIntrinsicID()) {
658 case Intrinsic::memcpy:
659 case Intrinsic::memmove:
660 case Intrinsic::memset:
661 case Intrinsic::memcpy_element_unordered_atomic:
662 case Intrinsic::memmove_element_unordered_atomic:
663 case Intrinsic::memset_element_unordered_atomic:
669 static bool classof(const Value *V) {
670 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
674 /// This class represents any memset intrinsic
675 // i.e. llvm.element.unordered.atomic.memset
677 class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
679 static bool classof(const IntrinsicInst *I) {
680 switch (I->getIntrinsicID()) {
681 case Intrinsic::memset:
682 case Intrinsic::memset_element_unordered_atomic:
688 static bool classof(const Value *V) {
689 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
693 // This class wraps any memcpy/memmove intrinsics
694 // i.e. llvm.element.unordered.atomic.memcpy/memmove
695 // and llvm.memcpy/memmove
696 class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
698 static bool classof(const IntrinsicInst *I) {
699 switch (I->getIntrinsicID()) {
700 case Intrinsic::memcpy:
701 case Intrinsic::memmove:
702 case Intrinsic::memcpy_element_unordered_atomic:
703 case Intrinsic::memmove_element_unordered_atomic:
709 static bool classof(const Value *V) {
710 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
714 /// This class represents any memcpy intrinsic
715 /// i.e. llvm.element.unordered.atomic.memcpy
717 class AnyMemCpyInst : public AnyMemTransferInst {
719 static bool classof(const IntrinsicInst *I) {
720 switch (I->getIntrinsicID()) {
721 case Intrinsic::memcpy:
722 case Intrinsic::memcpy_element_unordered_atomic:
728 static bool classof(const Value *V) {
729 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
733 /// This class represents any memmove intrinsic
734 /// i.e. llvm.element.unordered.atomic.memmove
736 class AnyMemMoveInst : public AnyMemTransferInst {
738 static bool classof(const IntrinsicInst *I) {
739 switch (I->getIntrinsicID()) {
740 case Intrinsic::memmove:
741 case Intrinsic::memmove_element_unordered_atomic:
747 static bool classof(const Value *V) {
748 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
752 /// This represents the llvm.va_start intrinsic.
753 class VAStartInst : public IntrinsicInst {
755 static bool classof(const IntrinsicInst *I) {
756 return I->getIntrinsicID() == Intrinsic::vastart;
758 static bool classof(const Value *V) {
759 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
762 Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
765 /// This represents the llvm.va_end intrinsic.
766 class VAEndInst : public IntrinsicInst {
768 static bool classof(const IntrinsicInst *I) {
769 return I->getIntrinsicID() == Intrinsic::vaend;
771 static bool classof(const Value *V) {
772 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
775 Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
778 /// This represents the llvm.va_copy intrinsic.
779 class VACopyInst : public IntrinsicInst {
781 static bool classof(const IntrinsicInst *I) {
782 return I->getIntrinsicID() == Intrinsic::vacopy;
784 static bool classof(const Value *V) {
785 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
788 Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
789 Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
792 /// This represents the llvm.instrprof_increment intrinsic.
793 class InstrProfIncrementInst : public IntrinsicInst {
795 static bool classof(const IntrinsicInst *I) {
796 return I->getIntrinsicID() == Intrinsic::instrprof_increment;
798 static bool classof(const Value *V) {
799 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
802 GlobalVariable *getName() const {
803 return cast<GlobalVariable>(
804 const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
807 ConstantInt *getHash() const {
808 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
811 ConstantInt *getNumCounters() const {
812 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
815 ConstantInt *getIndex() const {
816 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
819 Value *getStep() const;
822 class InstrProfIncrementInstStep : public InstrProfIncrementInst {
824 static bool classof(const IntrinsicInst *I) {
825 return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
827 static bool classof(const Value *V) {
828 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
832 /// This represents the llvm.instrprof_value_profile intrinsic.
833 class InstrProfValueProfileInst : public IntrinsicInst {
835 static bool classof(const IntrinsicInst *I) {
836 return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
838 static bool classof(const Value *V) {
839 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
842 GlobalVariable *getName() const {
843 return cast<GlobalVariable>(
844 const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
847 ConstantInt *getHash() const {
848 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
851 Value *getTargetValue() const {
852 return cast<Value>(const_cast<Value *>(getArgOperand(2)));
855 ConstantInt *getValueKind() const {
856 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
859 // Returns the value site index.
860 ConstantInt *getIndex() const {
861 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
865 } // end namespace llvm
867 #endif // LLVM_IR_INTRINSICINST_H