LLVM 17.0.0git
IntrinsicInst.h
Go to the documentation of this file.
1//===-- llvm/IntrinsicInst.h - Intrinsic Instruction Wrappers ---*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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:
12//
13// if (MemCpyInst *MCI = dyn_cast<MemCpyInst>(Inst))
14// ... MCI->getDest() ... MCI->getSource() ...
15//
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
19// hack working.
20//
21//===----------------------------------------------------------------------===//
22
23#ifndef LLVM_IR_INTRINSICINST_H
24#define LLVM_IR_INTRINSICINST_H
25
26#include "llvm/IR/Constants.h"
29#include "llvm/IR/FPEnv.h"
30#include "llvm/IR/Function.h"
33#include "llvm/IR/Intrinsics.h"
34#include "llvm/IR/Value.h"
36#include <cassert>
37#include <cstdint>
38#include <optional>
39
40namespace llvm {
41
42class Metadata;
43
44/// A wrapper class for inspecting calls to intrinsic functions.
45/// This allows the standard isa/dyncast/cast functionality to work with calls
46/// to intrinsic functions.
47class IntrinsicInst : public CallInst {
48public:
49 IntrinsicInst() = delete;
50 IntrinsicInst(const IntrinsicInst &) = delete;
52
53 /// Return the intrinsic ID of this intrinsic.
56 }
57
58 /// Return true if swapping the first two arguments to the intrinsic produces
59 /// the same result.
60 bool isCommutative() const {
61 switch (getIntrinsicID()) {
62 case Intrinsic::maxnum:
63 case Intrinsic::minnum:
64 case Intrinsic::maximum:
65 case Intrinsic::minimum:
66 case Intrinsic::smax:
67 case Intrinsic::smin:
68 case Intrinsic::umax:
69 case Intrinsic::umin:
70 case Intrinsic::sadd_sat:
71 case Intrinsic::uadd_sat:
72 case Intrinsic::sadd_with_overflow:
73 case Intrinsic::uadd_with_overflow:
74 case Intrinsic::smul_with_overflow:
75 case Intrinsic::umul_with_overflow:
76 case Intrinsic::smul_fix:
77 case Intrinsic::umul_fix:
78 case Intrinsic::smul_fix_sat:
79 case Intrinsic::umul_fix_sat:
80 case Intrinsic::fma:
81 case Intrinsic::fmuladd:
82 return true;
83 default:
84 return false;
85 }
86 }
87
88 /// Checks if the intrinsic is an annotation.
89 bool isAssumeLikeIntrinsic() const {
90 switch (getIntrinsicID()) {
91 default: break;
92 case Intrinsic::assume:
93 case Intrinsic::sideeffect:
94 case Intrinsic::pseudoprobe:
95 case Intrinsic::dbg_assign:
96 case Intrinsic::dbg_declare:
97 case Intrinsic::dbg_value:
98 case Intrinsic::dbg_label:
99 case Intrinsic::invariant_start:
100 case Intrinsic::invariant_end:
101 case Intrinsic::lifetime_start:
102 case Intrinsic::lifetime_end:
103 case Intrinsic::experimental_noalias_scope_decl:
104 case Intrinsic::objectsize:
105 case Intrinsic::ptr_annotation:
106 case Intrinsic::var_annotation:
107 return true;
108 }
109 return false;
110 }
111
112 /// Check if the intrinsic might lower into a regular function call in the
113 /// course of IR transformations
114 static bool mayLowerToFunctionCall(Intrinsic::ID IID);
115
116 /// Methods for support type inquiry through isa, cast, and dyn_cast:
117 static bool classof(const CallInst *I) {
118 if (const Function *CF = I->getCalledFunction())
119 return CF->isIntrinsic();
120 return false;
121 }
122 static bool classof(const Value *V) {
123 return isa<CallInst>(V) && classof(cast<CallInst>(V));
124 }
125};
126
127/// Check if \p ID corresponds to a lifetime intrinsic.
129 switch (ID) {
130 case Intrinsic::lifetime_start:
131 case Intrinsic::lifetime_end:
132 return true;
133 default:
134 return false;
135 }
136}
137
138/// This is the common base class for lifetime intrinsics.
140public:
141 /// \name Casting methods
142 /// @{
143 static bool classof(const IntrinsicInst *I) {
144 return isLifetimeIntrinsic(I->getIntrinsicID());
145 }
146 static bool classof(const Value *V) {
147 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
148 }
149 /// @}
150};
151
152/// Check if \p ID corresponds to a debug info intrinsic.
154 switch (ID) {
155 case Intrinsic::dbg_declare:
156 case Intrinsic::dbg_value:
157 case Intrinsic::dbg_addr:
158 case Intrinsic::dbg_label:
159 case Intrinsic::dbg_assign:
160 return true;
161 default:
162 return false;
163 }
164}
165
166/// This is the common base class for debug info intrinsics.
168public:
169 /// \name Casting methods
170 /// @{
171 static bool classof(const IntrinsicInst *I) {
172 return isDbgInfoIntrinsic(I->getIntrinsicID());
173 }
174 static bool classof(const Value *V) {
175 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
176 }
177 /// @}
178};
179
180/// This is the common base class for debug info intrinsics for variables.
182public:
183 // Iterator for ValueAsMetadata that internally uses direct pointer iteration
184 // over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
185 // ValueAsMetadata .
187 : public iterator_facade_base<location_op_iterator,
188 std::bidirectional_iterator_tag, Value *> {
190
191 public:
192 location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {}
193 location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {}
194
197 I = R.I;
198 return *this;
199 }
201 return I == RHS.I;
202 }
203 const Value *operator*() const {
204 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
205 ? I.get<ValueAsMetadata *>()
206 : *I.get<ValueAsMetadata **>();
207 return VAM->getValue();
208 };
210 ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
211 ? I.get<ValueAsMetadata *>()
212 : *I.get<ValueAsMetadata **>();
213 return VAM->getValue();
214 }
216 if (I.is<ValueAsMetadata *>())
217 I = I.get<ValueAsMetadata *>() + 1;
218 else
219 I = I.get<ValueAsMetadata **>() + 1;
220 return *this;
221 }
223 if (I.is<ValueAsMetadata *>())
224 I = I.get<ValueAsMetadata *>() - 1;
225 else
226 I = I.get<ValueAsMetadata **>() - 1;
227 return *this;
228 }
229 };
230
231 /// Get the locations corresponding to the variable referenced by the debug
232 /// info intrinsic. Depending on the intrinsic, this could be the
233 /// variable's value or its address.
235
236 Value *getVariableLocationOp(unsigned OpIdx) const;
237
238 void replaceVariableLocationOp(Value *OldValue, Value *NewValue);
239 void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue);
240 /// Adding a new location operand will always result in this intrinsic using
241 /// an ArgList, and must always be accompanied by a new expression that uses
242 /// the new operand.
245
247 setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar));
248 }
249
252 }
253
254 unsigned getNumVariableLocationOps() const {
255 if (hasArgList())
256 return cast<DIArgList>(getRawLocation())->getArgs().size();
257 return 1;
258 }
259
260 bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
261
262 /// Does this describe the address of a local variable. True for dbg.addr and
263 /// dbg.declare, but not dbg.value, which describes its value, or dbg.assign,
264 /// which describes a combination of the variable's value and address.
265 bool isAddressOfVariable() const {
266 return getIntrinsicID() != Intrinsic::dbg_value &&
267 getIntrinsicID() != Intrinsic::dbg_assign;
268 }
269
271 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
272 // this set anymore.
273 SmallPtrSet<Value *, 4> RemovedValues;
274 for (Value *OldValue : location_ops()) {
275 if (!RemovedValues.insert(OldValue).second)
276 continue;
277 Value *Poison = PoisonValue::get(OldValue->getType());
278 replaceVariableLocationOp(OldValue, Poison);
279 }
280 }
281
282 bool isKillLocation() const {
283 return (getNumVariableLocationOps() == 0 &&
284 !getExpression()->isComplex()) ||
285 any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
286 }
287
289 return cast<DILocalVariable>(getRawVariable());
290 }
291
293 return cast<DIExpression>(getRawExpression());
294 }
295
297 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
298 }
299
301 return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
302 }
303
305 return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
306 }
307
308 /// Use of this should generally be avoided; instead,
309 /// replaceVariableLocationOp and addVariableLocationOps should be used where
310 /// possible to avoid creating invalid state.
311 void setRawLocation(Metadata *Location) {
312 return setArgOperand(0, MetadataAsValue::get(getContext(), Location));
313 }
314
315 /// Get the size (in bits) of the variable, or fragment of the variable that
316 /// is described.
317 std::optional<uint64_t> getFragmentSizeInBits() const;
318
319 /// Get the FragmentInfo for the variable.
320 std::optional<DIExpression::FragmentInfo> getFragment() const {
321 return getExpression()->getFragmentInfo();
322 }
323
324 /// \name Casting methods
325 /// @{
326 static bool classof(const IntrinsicInst *I) {
327 switch (I->getIntrinsicID()) {
328 case Intrinsic::dbg_declare:
329 case Intrinsic::dbg_value:
330 case Intrinsic::dbg_addr:
331 case Intrinsic::dbg_assign:
332 return true;
333 default:
334 return false;
335 }
336 }
337 static bool classof(const Value *V) {
338 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
339 }
340 /// @}
341protected:
342 void setArgOperand(unsigned i, Value *v) {
344 }
345 void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); }
346};
347
348/// This represents the llvm.dbg.declare instruction.
350public:
351 Value *getAddress() const {
353 "dbg.declare must have exactly 1 location operand.");
354 return getVariableLocationOp(0);
355 }
356
357 /// \name Casting methods
358 /// @{
359 static bool classof(const IntrinsicInst *I) {
360 return I->getIntrinsicID() == Intrinsic::dbg_declare;
361 }
362 static bool classof(const Value *V) {
363 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
364 }
365 /// @}
366};
367
368/// This represents the llvm.dbg.addr instruction.
370public:
371 Value *getAddress() const {
373 "dbg.addr must have exactly 1 location operand.");
374 return getVariableLocationOp(0);
375 }
376
377 /// \name Casting methods
378 /// @{
379 static bool classof(const IntrinsicInst *I) {
380 return I->getIntrinsicID() == Intrinsic::dbg_addr;
381 }
382 static bool classof(const Value *V) {
383 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
384 }
385};
386
387/// This represents the llvm.dbg.value instruction.
389public:
390 // The default argument should only be used in ISel, and the default option
391 // should be removed once ISel support for multiple location ops is complete.
392 Value *getValue(unsigned OpIdx = 0) const {
393 return getVariableLocationOp(OpIdx);
394 }
396 return location_ops();
397 }
398
399 /// \name Casting methods
400 /// @{
401 static bool classof(const IntrinsicInst *I) {
402 return I->getIntrinsicID() == Intrinsic::dbg_value ||
403 I->getIntrinsicID() == Intrinsic::dbg_assign;
404 }
405 static bool classof(const Value *V) {
406 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
407 }
408 /// @}
409};
410
411/// This represents the llvm.dbg.assign instruction.
413 enum Operands {
414 OpValue,
415 OpVar,
416 OpExpr,
417 OpAssignID,
418 OpAddress,
419 OpAddressExpr,
420 };
421
422public:
423 Value *getAddress() const;
425 return cast<MetadataAsValue>(getArgOperand(OpAddress))->getMetadata();
426 }
428 return cast<MetadataAsValue>(getArgOperand(OpAssignID))->getMetadata();
429 }
430 DIAssignID *getAssignID() const { return cast<DIAssignID>(getRawAssignID()); }
432 return cast<MetadataAsValue>(getArgOperand(OpAddressExpr))->getMetadata();
433 }
435 return cast<DIExpression>(getRawAddressExpression());
436 }
438 setArgOperand(OpAddressExpr,
439 MetadataAsValue::get(NewExpr->getContext(), NewExpr));
440 }
441 void setAssignId(DIAssignID *New);
442 void setAddress(Value *V);
443 /// Kill the address component.
444 void setKillAddress();
445 /// Check whether this kills the address component. This doesn't take into
446 /// account the position of the intrinsic, therefore a returned value of false
447 /// does not guarentee the address is a valid location for the variable at the
448 /// intrinsic's position in IR.
449 bool isKillAddress() const;
450 void setValue(Value *V);
451 /// \name Casting methods
452 /// @{
453 static bool classof(const IntrinsicInst *I) {
454 return I->getIntrinsicID() == Intrinsic::dbg_assign;
455 }
456 static bool classof(const Value *V) {
457 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
458 }
459 /// @}
460};
461
462/// This represents the llvm.dbg.label instruction.
464public:
465 DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); }
466
468 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
469 }
470
471 /// Methods for support type inquiry through isa, cast, and dyn_cast:
472 /// @{
473 static bool classof(const IntrinsicInst *I) {
474 return I->getIntrinsicID() == Intrinsic::dbg_label;
475 }
476 static bool classof(const Value *V) {
477 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
478 }
479 /// @}
480};
481
482/// This is the common base class for vector predication intrinsics.
484public:
485 /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
486 /// \p Params. Additionally, the load and gather intrinsics require
487 /// \p ReturnType to be specified.
489 Type *ReturnType,
490 ArrayRef<Value *> Params);
491
492 static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
493 static std::optional<unsigned> getVectorLengthParamPos(
494 Intrinsic::ID IntrinsicID);
495
496 /// The llvm.vp.* intrinsics for this instruction Opcode
497 static Intrinsic::ID getForOpcode(unsigned OC);
498
499 // Whether \p ID is a VP intrinsic ID.
500 static bool isVPIntrinsic(Intrinsic::ID);
501
502 /// \return The mask parameter or nullptr.
503 Value *getMaskParam() const;
504 void setMaskParam(Value *);
505
506 /// \return The vector length parameter or nullptr.
509
510 /// \return Whether the vector length param can be ignored.
511 bool canIgnoreVectorLengthParam() const;
512
513 /// \return The static element count (vector number of elements) the vector
514 /// length parameter applies to.
516
517 /// \return The alignment of the pointer used by this load/store/gather or
518 /// scatter.
520 // MaybeAlign setPointerAlignment(Align NewAlign); // TODO
521
522 /// \return The pointer operand of this load,store, gather or scatter.
524 static std::optional<unsigned> getMemoryPointerParamPos(Intrinsic::ID);
525
526 /// \return The data (payload) operand of this store or scatter.
527 Value *getMemoryDataParam() const;
528 static std::optional<unsigned> getMemoryDataParamPos(Intrinsic::ID);
529
530 // Methods for support type inquiry through isa, cast, and dyn_cast:
531 static bool classof(const IntrinsicInst *I) {
532 return isVPIntrinsic(I->getIntrinsicID());
533 }
534 static bool classof(const Value *V) {
535 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
536 }
537
538 // Equivalent non-predicated opcode
539 std::optional<unsigned> getFunctionalOpcode() const {
541 }
542
543 // Equivalent non-predicated opcode
544 static std::optional<unsigned> getFunctionalOpcodeForVP(Intrinsic::ID ID);
545};
546
547/// This represents vector predication reduction intrinsics.
549public:
550 static bool isVPReduction(Intrinsic::ID ID);
551
552 unsigned getStartParamPos() const;
553 unsigned getVectorParamPos() const;
554
555 static std::optional<unsigned> getStartParamPos(Intrinsic::ID ID);
556 static std::optional<unsigned> getVectorParamPos(Intrinsic::ID ID);
557
558 /// Methods for support type inquiry through isa, cast, and dyn_cast:
559 /// @{
560 static bool classof(const IntrinsicInst *I) {
561 return VPReductionIntrinsic::isVPReduction(I->getIntrinsicID());
562 }
563 static bool classof(const Value *V) {
564 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
565 }
566 /// @}
567};
568
570public:
571 static bool isVPCast(Intrinsic::ID ID);
572
573 /// Methods for support type inquiry through isa, cast, and dyn_cast:
574 /// @{
575 static bool classof(const IntrinsicInst *I) {
576 return VPCastIntrinsic::isVPCast(I->getIntrinsicID());
577 }
578 static bool classof(const Value *V) {
579 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
580 }
581 /// @}
582};
583
585public:
586 static bool isVPCmp(Intrinsic::ID ID);
587
589
590 /// Methods for support type inquiry through isa, cast, and dyn_cast:
591 /// @{
592 static bool classof(const IntrinsicInst *I) {
593 return VPCmpIntrinsic::isVPCmp(I->getIntrinsicID());
594 }
595 static bool classof(const Value *V) {
596 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
597 }
598 /// @}
599};
600
601/// This is the common base class for constrained floating point intrinsics.
603public:
604 bool isUnaryOp() const;
605 bool isTernaryOp() const;
606 std::optional<RoundingMode> getRoundingMode() const;
607 std::optional<fp::ExceptionBehavior> getExceptionBehavior() const;
608 bool isDefaultFPEnvironment() const;
609
610 // Methods for support type inquiry through isa, cast, and dyn_cast:
611 static bool classof(const IntrinsicInst *I);
612 static bool classof(const Value *V) {
613 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
614 }
615};
616
617/// Constrained floating point compare intrinsics.
619public:
621 bool isSignaling() const {
622 return getIntrinsicID() == Intrinsic::experimental_constrained_fcmps;
623 }
624
625 // Methods for support type inquiry through isa, cast, and dyn_cast:
626 static bool classof(const IntrinsicInst *I) {
627 switch (I->getIntrinsicID()) {
628 case Intrinsic::experimental_constrained_fcmp:
629 case Intrinsic::experimental_constrained_fcmps:
630 return true;
631 default:
632 return false;
633 }
634 }
635 static bool classof(const Value *V) {
636 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
637 }
638};
639
640/// This class represents min/max intrinsics.
642public:
643 static bool classof(const IntrinsicInst *I) {
644 switch (I->getIntrinsicID()) {
645 case Intrinsic::umin:
646 case Intrinsic::umax:
647 case Intrinsic::smin:
648 case Intrinsic::smax:
649 return true;
650 default:
651 return false;
652 }
653 }
654 static bool classof(const Value *V) {
655 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
656 }
657
658 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
659 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
660
661 /// Returns the comparison predicate underlying the intrinsic.
663 switch (ID) {
664 case Intrinsic::umin:
666 case Intrinsic::umax:
668 case Intrinsic::smin:
670 case Intrinsic::smax:
672 default:
673 llvm_unreachable("Invalid intrinsic");
674 }
675 }
676
677 /// Returns the comparison predicate underlying the intrinsic.
680 }
681
682 /// Whether the intrinsic is signed or unsigned.
683 static bool isSigned(Intrinsic::ID ID) {
685 };
686
687 /// Whether the intrinsic is signed or unsigned.
688 bool isSigned() const { return isSigned(getIntrinsicID()); };
689
690 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
691 /// so there is a certain threshold value, upon reaching which,
692 /// their value can no longer change. Return said threshold.
693 static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits) {
694 switch (ID) {
695 case Intrinsic::umin:
696 return APInt::getMinValue(numBits);
697 case Intrinsic::umax:
698 return APInt::getMaxValue(numBits);
699 case Intrinsic::smin:
700 return APInt::getSignedMinValue(numBits);
701 case Intrinsic::smax:
702 return APInt::getSignedMaxValue(numBits);
703 default:
704 llvm_unreachable("Invalid intrinsic");
705 }
706 }
707
708 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
709 /// so there is a certain threshold value, upon reaching which,
710 /// their value can no longer change. Return said threshold.
711 APInt getSaturationPoint(unsigned numBits) const {
712 return getSaturationPoint(getIntrinsicID(), numBits);
713 }
714
715 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
716 /// so there is a certain threshold value, upon reaching which,
717 /// their value can no longer change. Return said threshold.
721 }
722
723 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
724 /// so there is a certain threshold value, upon reaching which,
725 /// their value can no longer change. Return said threshold.
728 }
729};
730
731/// This class represents an intrinsic that is based on a binary operation.
732/// This includes op.with.overflow and saturating add/sub intrinsics.
734public:
735 static bool classof(const IntrinsicInst *I) {
736 switch (I->getIntrinsicID()) {
737 case Intrinsic::uadd_with_overflow:
738 case Intrinsic::sadd_with_overflow:
739 case Intrinsic::usub_with_overflow:
740 case Intrinsic::ssub_with_overflow:
741 case Intrinsic::umul_with_overflow:
742 case Intrinsic::smul_with_overflow:
743 case Intrinsic::uadd_sat:
744 case Intrinsic::sadd_sat:
745 case Intrinsic::usub_sat:
746 case Intrinsic::ssub_sat:
747 return true;
748 default:
749 return false;
750 }
751 }
752 static bool classof(const Value *V) {
753 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
754 }
755
756 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
757 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
758
759 /// Returns the binary operation underlying the intrinsic.
761
762 /// Whether the intrinsic is signed or unsigned.
763 bool isSigned() const;
764
765 /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
766 unsigned getNoWrapKind() const;
767};
768
769/// Represents an op.with.overflow intrinsic.
771public:
772 static bool classof(const IntrinsicInst *I) {
773 switch (I->getIntrinsicID()) {
774 case Intrinsic::uadd_with_overflow:
775 case Intrinsic::sadd_with_overflow:
776 case Intrinsic::usub_with_overflow:
777 case Intrinsic::ssub_with_overflow:
778 case Intrinsic::umul_with_overflow:
779 case Intrinsic::smul_with_overflow:
780 return true;
781 default:
782 return false;
783 }
784 }
785 static bool classof(const Value *V) {
786 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
787 }
788};
789
790/// Represents a saturating add/sub intrinsic.
792public:
793 static bool classof(const IntrinsicInst *I) {
794 switch (I->getIntrinsicID()) {
795 case Intrinsic::uadd_sat:
796 case Intrinsic::sadd_sat:
797 case Intrinsic::usub_sat:
798 case Intrinsic::ssub_sat:
799 return true;
800 default:
801 return false;
802 }
803 }
804 static bool classof(const Value *V) {
805 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
806 }
807};
808
809/// Common base class for all memory intrinsics. Simply provides
810/// common methods.
811/// Written as CRTP to avoid a common base class amongst the
812/// three atomicity hierarchies.
813template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
814private:
815 enum { ARG_DEST = 0, ARG_LENGTH = 2 };
816
817public:
818 Value *getRawDest() const {
819 return const_cast<Value *>(getArgOperand(ARG_DEST));
820 }
821 const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
822 Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
823
824 Value *getLength() const {
825 return const_cast<Value *>(getArgOperand(ARG_LENGTH));
826 }
827 const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
828 Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
829
830 /// This is just like getRawDest, but it strips off any cast
831 /// instructions (including addrspacecast) that feed it, giving the
832 /// original input. The returned value is guaranteed to be a pointer.
833 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
834
835 unsigned getDestAddressSpace() const {
836 return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
837 }
838
839 /// FIXME: Remove this function once transition to Align is over.
840 /// Use getDestAlign() instead.
841 LLVM_DEPRECATED("Use getDestAlign() instead", "getDestAlign")
843 if (auto MA = getParamAlign(ARG_DEST))
844 return MA->value();
845 return 0;
846 }
847 MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
848
849 /// Set the specified arguments of the instruction.
851 assert(getRawDest()->getType() == Ptr->getType() &&
852 "setDest called with pointer of wrong type!");
853 setArgOperand(ARG_DEST, Ptr);
854 }
855
856 void setDestAlignment(MaybeAlign Alignment) {
857 removeParamAttr(ARG_DEST, Attribute::Alignment);
858 if (Alignment)
859 addParamAttr(ARG_DEST,
861 }
862 void setDestAlignment(Align Alignment) {
863 removeParamAttr(ARG_DEST, Attribute::Alignment);
864 addParamAttr(ARG_DEST,
866 }
867
868 void setLength(Value *L) {
869 assert(getLength()->getType() == L->getType() &&
870 "setLength called with value of wrong type!");
871 setArgOperand(ARG_LENGTH, L);
872 }
873};
874
875/// Common base class for all memory transfer intrinsics. Simply provides
876/// common methods.
877template <class BaseCL> class MemTransferBase : public BaseCL {
878private:
879 enum { ARG_SOURCE = 1 };
880
881public:
882 /// Return the arguments to the instruction.
884 return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
885 }
886 const Use &getRawSourceUse() const {
887 return BaseCL::getArgOperandUse(ARG_SOURCE);
888 }
889 Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
890
891 /// This is just like getRawSource, but it strips off any cast
892 /// instructions that feed it, giving the original input. The returned
893 /// value is guaranteed to be a pointer.
895
896 unsigned getSourceAddressSpace() const {
897 return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
898 }
899
900 /// FIXME: Remove this function once transition to Align is over.
901 /// Use getSourceAlign() instead.
902 LLVM_DEPRECATED("Use getSourceAlign() instead", "getSourceAlign")
904 if (auto MA = BaseCL::getParamAlign(ARG_SOURCE))
905 return MA->value();
906 return 0;
907 }
908
910 return BaseCL::getParamAlign(ARG_SOURCE);
911 }
912
914 assert(getRawSource()->getType() == Ptr->getType() &&
915 "setSource called with pointer of wrong type!");
916 BaseCL::setArgOperand(ARG_SOURCE, Ptr);
917 }
918
920 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
921 if (Alignment)
922 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
923 BaseCL::getContext(), *Alignment));
924 }
925
926 void setSourceAlignment(Align Alignment) {
927 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
928 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
929 BaseCL::getContext(), Alignment));
930 }
931};
932
933/// Common base class for all memset intrinsics. Simply provides
934/// common methods.
935template <class BaseCL> class MemSetBase : public BaseCL {
936private:
937 enum { ARG_VALUE = 1 };
938
939public:
940 Value *getValue() const {
941 return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
942 }
943 const Use &getValueUse() const { return BaseCL::getArgOperandUse(ARG_VALUE); }
944 Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
945
946 void setValue(Value *Val) {
947 assert(getValue()->getType() == Val->getType() &&
948 "setValue called with value of wrong type!");
949 BaseCL::setArgOperand(ARG_VALUE, Val);
950 }
951};
952
953// The common base class for the atomic memset/memmove/memcpy intrinsics
954// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
955class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
956private:
957 enum { ARG_ELEMENTSIZE = 3 };
958
959public:
961 return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
962 }
963
965 return cast<ConstantInt>(getRawElementSizeInBytes());
966 }
967
970 }
971
974 "setElementSizeInBytes called with value of wrong type!");
975 setArgOperand(ARG_ELEMENTSIZE, V);
976 }
977
978 static bool classof(const IntrinsicInst *I) {
979 switch (I->getIntrinsicID()) {
980 case Intrinsic::memcpy_element_unordered_atomic:
981 case Intrinsic::memmove_element_unordered_atomic:
982 case Intrinsic::memset_element_unordered_atomic:
983 return true;
984 default:
985 return false;
986 }
987 }
988 static bool classof(const Value *V) {
989 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
990 }
991};
992
993/// This class represents atomic memset intrinsic
994// i.e. llvm.element.unordered.atomic.memset
995class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
996public:
997 static bool classof(const IntrinsicInst *I) {
998 return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
999 }
1000 static bool classof(const Value *V) {
1001 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1002 }
1003};
1004
1005// This class wraps the atomic memcpy/memmove intrinsics
1006// i.e. llvm.element.unordered.atomic.memcpy/memmove
1007class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
1008public:
1009 static bool classof(const IntrinsicInst *I) {
1010 switch (I->getIntrinsicID()) {
1011 case Intrinsic::memcpy_element_unordered_atomic:
1012 case Intrinsic::memmove_element_unordered_atomic:
1013 return true;
1014 default:
1015 return false;
1016 }
1017 }
1018 static bool classof(const Value *V) {
1019 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1020 }
1021};
1022
1023/// This class represents the atomic memcpy intrinsic
1024/// i.e. llvm.element.unordered.atomic.memcpy
1026public:
1027 static bool classof(const IntrinsicInst *I) {
1028 return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
1029 }
1030 static bool classof(const Value *V) {
1031 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1032 }
1033};
1034
1035/// This class represents the atomic memmove intrinsic
1036/// i.e. llvm.element.unordered.atomic.memmove
1038public:
1039 static bool classof(const IntrinsicInst *I) {
1040 return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
1041 }
1042 static bool classof(const Value *V) {
1043 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1044 }
1045};
1046
1047/// This is the common base class for memset/memcpy/memmove.
1048class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1049private:
1050 enum { ARG_VOLATILE = 3 };
1051
1052public:
1054 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1055 }
1056
1057 bool isVolatile() const { return !getVolatileCst()->isZero(); }
1058
1059 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
1060
1061 // Methods for support type inquiry through isa, cast, and dyn_cast:
1062 static bool classof(const IntrinsicInst *I) {
1063 switch (I->getIntrinsicID()) {
1064 case Intrinsic::memcpy:
1065 case Intrinsic::memmove:
1066 case Intrinsic::memset:
1067 case Intrinsic::memset_inline:
1068 case Intrinsic::memcpy_inline:
1069 return true;
1070 default:
1071 return false;
1072 }
1073 }
1074 static bool classof(const Value *V) {
1075 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1076 }
1077};
1078
1079/// This class wraps the llvm.memset and llvm.memset.inline intrinsics.
1080class MemSetInst : public MemSetBase<MemIntrinsic> {
1081public:
1082 // Methods for support type inquiry through isa, cast, and dyn_cast:
1083 static bool classof(const IntrinsicInst *I) {
1084 switch (I->getIntrinsicID()) {
1085 case Intrinsic::memset:
1086 case Intrinsic::memset_inline:
1087 return true;
1088 default:
1089 return false;
1090 }
1091 }
1092 static bool classof(const Value *V) {
1093 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1094 }
1095};
1096
1097/// This class wraps the llvm.memset.inline intrinsic.
1099public:
1101 return cast<ConstantInt>(MemSetInst::getLength());
1102 }
1103 // Methods for support type inquiry through isa, cast, and dyn_cast:
1104 static bool classof(const IntrinsicInst *I) {
1105 return I->getIntrinsicID() == Intrinsic::memset_inline;
1106 }
1107 static bool classof(const Value *V) {
1108 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1109 }
1110};
1111
1112/// This class wraps the llvm.memcpy/memmove intrinsics.
1113class MemTransferInst : public MemTransferBase<MemIntrinsic> {
1114public:
1115 // Methods for support type inquiry through isa, cast, and dyn_cast:
1116 static bool classof(const IntrinsicInst *I) {
1117 switch (I->getIntrinsicID()) {
1118 case Intrinsic::memcpy:
1119 case Intrinsic::memmove:
1120 case Intrinsic::memcpy_inline:
1121 return true;
1122 default:
1123 return false;
1124 }
1125 }
1126 static bool classof(const Value *V) {
1127 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1128 }
1129};
1130
1131/// This class wraps the llvm.memcpy intrinsic.
1133public:
1134 // Methods for support type inquiry through isa, cast, and dyn_cast:
1135 static bool classof(const IntrinsicInst *I) {
1136 return I->getIntrinsicID() == Intrinsic::memcpy ||
1137 I->getIntrinsicID() == Intrinsic::memcpy_inline;
1138 }
1139 static bool classof(const Value *V) {
1140 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1141 }
1142};
1143
1144/// This class wraps the llvm.memmove intrinsic.
1146public:
1147 // Methods for support type inquiry through isa, cast, and dyn_cast:
1148 static bool classof(const IntrinsicInst *I) {
1149 return I->getIntrinsicID() == Intrinsic::memmove;
1150 }
1151 static bool classof(const Value *V) {
1152 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1153 }
1154};
1155
1156/// This class wraps the llvm.memcpy.inline intrinsic.
1158public:
1160 return cast<ConstantInt>(MemCpyInst::getLength());
1161 }
1162 // Methods for support type inquiry through isa, cast, and dyn_cast:
1163 static bool classof(const IntrinsicInst *I) {
1164 return I->getIntrinsicID() == Intrinsic::memcpy_inline;
1165 }
1166 static bool classof(const Value *V) {
1167 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1168 }
1169};
1170
1171// The common base class for any memset/memmove/memcpy intrinsics;
1172// whether they be atomic or non-atomic.
1173// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
1174// and llvm.memset/memcpy/memmove
1175class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
1176public:
1177 bool isVolatile() const {
1178 // Only the non-atomic intrinsics can be volatile
1179 if (auto *MI = dyn_cast<MemIntrinsic>(this))
1180 return MI->isVolatile();
1181 return false;
1182 }
1183
1184 static bool classof(const IntrinsicInst *I) {
1185 switch (I->getIntrinsicID()) {
1186 case Intrinsic::memcpy:
1187 case Intrinsic::memcpy_inline:
1188 case Intrinsic::memmove:
1189 case Intrinsic::memset:
1190 case Intrinsic::memset_inline:
1191 case Intrinsic::memcpy_element_unordered_atomic:
1192 case Intrinsic::memmove_element_unordered_atomic:
1193 case Intrinsic::memset_element_unordered_atomic:
1194 return true;
1195 default:
1196 return false;
1197 }
1198 }
1199 static bool classof(const Value *V) {
1200 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1201 }
1202};
1203
1204/// This class represents any memset intrinsic
1205// i.e. llvm.element.unordered.atomic.memset
1206// and llvm.memset
1207class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
1208public:
1209 static bool classof(const IntrinsicInst *I) {
1210 switch (I->getIntrinsicID()) {
1211 case Intrinsic::memset:
1212 case Intrinsic::memset_inline:
1213 case Intrinsic::memset_element_unordered_atomic:
1214 return true;
1215 default:
1216 return false;
1217 }
1218 }
1219 static bool classof(const Value *V) {
1220 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1221 }
1222};
1223
1224// This class wraps any memcpy/memmove intrinsics
1225// i.e. llvm.element.unordered.atomic.memcpy/memmove
1226// and llvm.memcpy/memmove
1227class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
1228public:
1229 static bool classof(const IntrinsicInst *I) {
1230 switch (I->getIntrinsicID()) {
1231 case Intrinsic::memcpy:
1232 case Intrinsic::memcpy_inline:
1233 case Intrinsic::memmove:
1234 case Intrinsic::memcpy_element_unordered_atomic:
1235 case Intrinsic::memmove_element_unordered_atomic:
1236 return true;
1237 default:
1238 return false;
1239 }
1240 }
1241 static bool classof(const Value *V) {
1242 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1243 }
1244};
1245
1246/// This class represents any memcpy intrinsic
1247/// i.e. llvm.element.unordered.atomic.memcpy
1248/// and llvm.memcpy
1250public:
1251 static bool classof(const IntrinsicInst *I) {
1252 switch (I->getIntrinsicID()) {
1253 case Intrinsic::memcpy:
1254 case Intrinsic::memcpy_inline:
1255 case Intrinsic::memcpy_element_unordered_atomic:
1256 return true;
1257 default:
1258 return false;
1259 }
1260 }
1261 static bool classof(const Value *V) {
1262 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1263 }
1264};
1265
1266/// This class represents any memmove intrinsic
1267/// i.e. llvm.element.unordered.atomic.memmove
1268/// and llvm.memmove
1270public:
1271 static bool classof(const IntrinsicInst *I) {
1272 switch (I->getIntrinsicID()) {
1273 case Intrinsic::memmove:
1274 case Intrinsic::memmove_element_unordered_atomic:
1275 return true;
1276 default:
1277 return false;
1278 }
1279 }
1280 static bool classof(const Value *V) {
1281 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1282 }
1283};
1284
1285/// This represents the llvm.va_start intrinsic.
1287public:
1288 static bool classof(const IntrinsicInst *I) {
1289 return I->getIntrinsicID() == Intrinsic::vastart;
1290 }
1291 static bool classof(const Value *V) {
1292 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1293 }
1294
1295 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1296};
1297
1298/// This represents the llvm.va_end intrinsic.
1299class VAEndInst : public IntrinsicInst {
1300public:
1301 static bool classof(const IntrinsicInst *I) {
1302 return I->getIntrinsicID() == Intrinsic::vaend;
1303 }
1304 static bool classof(const Value *V) {
1305 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1306 }
1307
1308 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1309};
1310
1311/// This represents the llvm.va_copy intrinsic.
1313public:
1314 static bool classof(const IntrinsicInst *I) {
1315 return I->getIntrinsicID() == Intrinsic::vacopy;
1316 }
1317 static bool classof(const Value *V) {
1318 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1319 }
1320
1321 Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); }
1322 Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); }
1323};
1324
1325/// A base class for all instrprof intrinsics.
1327public:
1328 // The name of the instrumented function.
1330 return cast<GlobalVariable>(
1331 const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
1332 }
1333 // The hash of the CFG for the instrumented function.
1335 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1336 }
1337 // The number of counters for the instrumented function.
1338 ConstantInt *getNumCounters() const;
1339 // The index of the counter that this instruction acts on.
1340 ConstantInt *getIndex() const;
1341};
1342
1343/// This represents the llvm.instrprof.cover intrinsic.
1345public:
1346 static bool classof(const IntrinsicInst *I) {
1347 return I->getIntrinsicID() == Intrinsic::instrprof_cover;
1348 }
1349 static bool classof(const Value *V) {
1350 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1351 }
1352};
1353
1354/// This represents the llvm.instrprof.increment intrinsic.
1356public:
1357 static bool classof(const IntrinsicInst *I) {
1358 return I->getIntrinsicID() == Intrinsic::instrprof_increment ||
1359 I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1360 }
1361 static bool classof(const Value *V) {
1362 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1363 }
1364 Value *getStep() const;
1365};
1366
1367/// This represents the llvm.instrprof.increment.step intrinsic.
1369public:
1370 static bool classof(const IntrinsicInst *I) {
1371 return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1372 }
1373 static bool classof(const Value *V) {
1374 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1375 }
1376};
1377
1378/// This represents the llvm.instrprof.value.profile intrinsic.
1380public:
1381 static bool classof(const IntrinsicInst *I) {
1382 return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
1383 }
1384 static bool classof(const Value *V) {
1385 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1386 }
1387
1389 return cast<Value>(const_cast<Value *>(getArgOperand(2)));
1390 }
1391
1393 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1394 }
1395
1396 // Returns the value site index.
1398 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
1399 }
1400};
1401
1403public:
1404 static bool classof(const IntrinsicInst *I) {
1405 return I->getIntrinsicID() == Intrinsic::pseudoprobe;
1406 }
1407
1408 static bool classof(const Value *V) {
1409 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1410 }
1411
1413 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
1414 }
1415
1417 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1418 }
1419
1421 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1422 }
1423
1425 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1426 }
1427};
1428
1430public:
1431 static bool classof(const IntrinsicInst *I) {
1432 return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
1433 }
1434
1435 static bool classof(const Value *V) {
1436 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1437 }
1438
1440 auto *MV =
1441 cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
1442 return cast<MDNode>(MV->getMetadata());
1443 }
1444
1445 void setScopeList(MDNode *ScopeList) {
1447 MetadataAsValue::get(getContext(), ScopeList));
1448 }
1449};
1450
1451/// Common base class for representing values projected from a statepoint.
1452/// Currently, the only projections available are gc.result and gc.relocate.
1454public:
1455 static bool classof(const IntrinsicInst *I) {
1456 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate ||
1457 I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1458 }
1459
1460 static bool classof(const Value *V) {
1461 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1462 }
1463
1464 /// Return true if this relocate is tied to the invoke statepoint.
1465 /// This includes relocates which are on the unwinding path.
1466 bool isTiedToInvoke() const {
1467 const Value *Token = getArgOperand(0);
1468
1469 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
1470 }
1471
1472 /// The statepoint with which this gc.relocate is associated.
1473 const Value *getStatepoint() const;
1474};
1475
1476/// Represents calls to the gc.relocate intrinsic.
1478public:
1479 static bool classof(const IntrinsicInst *I) {
1480 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate;
1481 }
1482
1483 static bool classof(const Value *V) {
1484 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1485 }
1486
1487 /// The index into the associate statepoint's argument list
1488 /// which contains the base pointer of the pointer whose
1489 /// relocation this gc.relocate describes.
1490 unsigned getBasePtrIndex() const {
1491 return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
1492 }
1493
1494 /// The index into the associate statepoint's argument list which
1495 /// contains the pointer whose relocation this gc.relocate describes.
1496 unsigned getDerivedPtrIndex() const {
1497 return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
1498 }
1499
1500 Value *getBasePtr() const;
1501 Value *getDerivedPtr() const;
1502};
1503
1504/// Represents calls to the gc.result intrinsic.
1506public:
1507 static bool classof(const IntrinsicInst *I) {
1508 return I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1509 }
1510
1511 static bool classof(const Value *V) {
1512 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1513 }
1514};
1515
1516/// This represents intrinsics that guard a condition
1518public:
1519 static bool classof(const IntrinsicInst *I) {
1520 return I->getIntrinsicID() == Intrinsic::assume ||
1521 I->getIntrinsicID() == Intrinsic::experimental_guard;
1522 }
1523 static bool classof(const Value *V) {
1524 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1525 }
1526};
1527
1528/// This represents the llvm.assume intrinsic.
1530public:
1531 static bool classof(const IntrinsicInst *I) {
1532 return I->getIntrinsicID() == Intrinsic::assume;
1533 }
1534 static bool classof(const Value *V) {
1535 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1536 }
1537};
1538
1539} // end namespace llvm
1540
1541#endif // LLVM_IR_INTRINSICINST_H
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:145
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains the declarations of entities that describe floating point environment and related ...
IRTranslator LLVM IR MI
static M68kRelType getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel)
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Class for arbitrary precision integers.
Definition: APInt.h:75
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:186
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:189
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:196
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:199
This class represents any memcpy intrinsic i.e.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This class represents any memmove intrinsic i.e.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This class represents any memset intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This represents the llvm.assume intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This class represents the atomic memcpy intrinsic i.e.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
ConstantInt * getElementSizeInBytesCst() const
static bool classof(const IntrinsicInst *I)
Value * getRawElementSizeInBytes() const
static bool classof(const Value *V)
void setElementSizeInBytes(Constant *V)
uint32_t getElementSizeInBytes() const
This class represents the atomic memmove intrinsic i.e.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This class represents atomic memset intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:167
This class represents an intrinsic that is based on a binary operation.
Value * getRHS() const
static bool classof(const Value *V)
unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
bool isSigned() const
Whether the intrinsic is signed or unsigned.
static bool classof(const IntrinsicInst *I)
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
Value * getLHS() const
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1578
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1406
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:1752
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1362
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1351
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1356
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1536
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:718
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:747
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:741
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:745
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:743
bool isSigned() const
Definition: InstrTypes.h:957
This represents intrinsics that guard a condition.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:193
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:141
This is an important base class in LLVM.
Definition: Constant.h:41
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
Definition: Constants.cpp:386
Constrained floating point compare intrinsics.
FCmpInst::Predicate getPredicate() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This is the common base class for constrained floating point intrinsics.
std::optional< fp::ExceptionBehavior > getExceptionBehavior() const
std::optional< RoundingMode > getRoundingMode() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Assignment ID.
DWARF expression.
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
This represents the llvm.dbg.addr instruction.
static bool classof(const IntrinsicInst *I)
Value * getAddress() const
static bool classof(const Value *V)
This represents the llvm.dbg.assign instruction.
DIAssignID * getAssignID() const
static bool classof(const Value *V)
void setAssignId(DIAssignID *New)
void setKillAddress()
Kill the address component.
bool isKillAddress() const
Check whether this kills the address component.
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
Value * getAddress() const
static bool classof(const IntrinsicInst *I)
Metadata * getRawAddressExpression() const
Metadata * getRawAssignID() const
void setAddressExpression(DIExpression *NewExpr)
This represents the llvm.dbg.declare instruction.
static bool classof(const Value *V)
Value * getAddress() const
static bool classof(const IntrinsicInst *I)
This is the common base class for debug info intrinsics.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This represents the llvm.dbg.label instruction.
Metadata * getRawLabel() const
static bool classof(const IntrinsicInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
DILabel * getLabel() const
static bool classof(const Value *V)
This represents the llvm.dbg.value instruction.
iterator_range< location_op_iterator > getValues() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Value * getValue(unsigned OpIdx=0) const
location_op_iterator & operator=(const location_op_iterator &R)
bool operator==(const location_op_iterator &RHS) const
location_op_iterator(ValueAsMetadata *SingleIter)
location_op_iterator(ValueAsMetadata **MultiIter)
location_op_iterator(const location_op_iterator &R)
This is the common base class for debug info intrinsics for variables.
void setVariable(DILocalVariable *NewVar)
void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
void replaceVariableLocationOp(Value *OldValue, Value *NewValue)
void setRawLocation(Metadata *Location)
Use of this should generally be avoided; instead, replaceVariableLocationOp and addVariableLocationOp...
Value * getVariableLocationOp(unsigned OpIdx) const
std::optional< DIExpression::FragmentInfo > getFragment() const
Get the FragmentInfo for the variable.
static bool classof(const Value *V)
void setExpression(DIExpression *NewExpr)
Metadata * getRawLocation() const
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
bool isAddressOfVariable() const
Does this describe the address of a local variable.
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
void setOperand(unsigned i, Value *v)
Metadata * getRawVariable() const
static bool classof(const IntrinsicInst *I)
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
DIExpression * getExpression() const
void setArgOperand(unsigned i, Value *v)
Metadata * getRawExpression() const
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:204
Common base class for representing values projected from a statepoint.
const Value * getStatepoint() const
The statepoint with which this gc.relocate is associated.
bool isTiedToInvoke() const
Return true if this relocate is tied to the invoke statepoint.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Represents calls to the gc.relocate intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Value * getBasePtr() const
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
Value * getDerivedPtr() const
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
Represents calls to the gc.result intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This represents the llvm.instrprof.cover intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This represents the llvm.instrprof.increment.step intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This represents the llvm.instrprof.increment intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
A base class for all instrprof intrinsics.
ConstantInt * getNumCounters() const
GlobalVariable * getName() const
ConstantInt * getHash() const
ConstantInt * getIndex() const
This represents the llvm.instrprof.value.profile intrinsic.
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
ConstantInt * getValueKind() const
static bool classof(const Value *V)
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:47
bool isAssumeLikeIntrinsic() const
Checks if the intrinsic is an annotation.
Definition: IntrinsicInst.h:89
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
IntrinsicInst(const IntrinsicInst &)=delete
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:54
bool isCommutative() const
Return true if swapping the first two arguments to the intrinsic produces the same result.
Definition: IntrinsicInst.h:60
static bool classof(const Value *V)
IntrinsicInst & operator=(const IntrinsicInst &)=delete
static bool classof(const CallInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
This is the common base class for lifetime intrinsics.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Metadata node.
Definition: Metadata.h:943
LLVMContext & getContext() const
Definition: Metadata.h:1107
This class wraps the llvm.memcpy.inline intrinsic.
static bool classof(const IntrinsicInst *I)
ConstantInt * getLength() const
static bool classof(const Value *V)
This class wraps the llvm.memcpy intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Common base class for all memory intrinsics.
const Use & getRawDestUse() const
Value * getLength() const
Value * getRawDest() const
void setDestAlignment(Align Alignment)
void setLength(Value *L)
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
void setDestAlignment(MaybeAlign Alignment)
void setDest(Value *Ptr)
Set the specified arguments of the instruction.
unsigned getDestAlignment() const
FIXME: Remove this function once transition to Align is over.
MaybeAlign getDestAlign() const
const Use & getLengthUse() const
unsigned getDestAddressSpace() const
This is the common base class for memset/memcpy/memmove.
ConstantInt * getVolatileCst() const
void setVolatile(Constant *V)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
bool isVolatile() const
This class wraps the llvm.memmove intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Common base class for all memset intrinsics.
void setValue(Value *Val)
const Use & getValueUse() const
Value * getValue() const
This class wraps the llvm.memset.inline intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
ConstantInt * getLength() const
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Common base class for all memory transfer intrinsics.
unsigned getSourceAlignment() const
FIXME: Remove this function once transition to Align is over.
void setSource(Value *Ptr)
Value * getRawSource() const
Return the arguments to the instruction.
unsigned getSourceAddressSpace() const
MaybeAlign getSourceAlign() const
Value * getSource() const
This is just like getRawSource, but it strips off any cast instructions that feed it,...
void setSourceAlignment(MaybeAlign Alignment)
void setSourceAlignment(Align Alignment)
const Use & getRawSourceUse() const
This class wraps the llvm.memcpy/memmove intrinsics.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
Root of the metadata hierarchy.
Definition: Metadata.h:61
This class represents min/max intrinsics.
static bool classof(const Value *V)
static Constant * getSaturationPoint(Intrinsic::ID ID, Type *Ty)
Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values, so there is a certain thre...
APInt getSaturationPoint(unsigned numBits) const
Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values, so there is a certain thre...
static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits)
Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values, so there is a certain thre...
Value * getLHS() const
Value * getRHS() const
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID)
Returns the comparison predicate underlying the intrinsic.
ICmpInst::Predicate getPredicate() const
Returns the comparison predicate underlying the intrinsic.
static bool isSigned(Intrinsic::ID ID)
Whether the intrinsic is signed or unsigned.
static bool classof(const IntrinsicInst *I)
bool isSigned() const
Whether the intrinsic is signed or unsigned.
Constant * getSaturationPoint(Type *Ty) const
Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values, so there is a certain thre...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static bool classof(const IntrinsicInst *I)
void setScopeList(MDNode *ScopeList)
static bool classof(const Value *V)
MDNode * getScopeList() const
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1759
ConstantInt * getAttributes() const
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
ConstantInt * getFactor() const
ConstantInt * getFuncGuid() const
Represents a saturating add/sub intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static IntegerType * getInt8Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
Value * getOperand(unsigned i) const
Definition: User.h:169
This represents the llvm.va_copy intrinsic.
Value * getSrc() const
static bool classof(const Value *V)
Value * getDest() const
static bool classof(const IntrinsicInst *I)
This represents the llvm.va_end intrinsic.
Value * getArgList() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This represents the llvm.va_start intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Value * getArgList() const
static bool isVPCast(Intrinsic::ID ID)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const IntrinsicInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
static bool isVPCmp(Intrinsic::ID ID)
CmpInst::Predicate getPredicate() const
This is the common base class for vector predication intrinsics.
static bool classof(const Value *V)
static Function * getDeclarationForParams(Module *M, Intrinsic::ID, Type *ReturnType, ArrayRef< Value * > Params)
Declares a llvm.vp.
static std::optional< unsigned > getMaskParamPos(Intrinsic::ID IntrinsicID)
bool canIgnoreVectorLengthParam() const
void setMaskParam(Value *)
static std::optional< unsigned > getFunctionalOpcodeForVP(Intrinsic::ID ID)
static std::optional< unsigned > getMemoryDataParamPos(Intrinsic::ID)
Value * getVectorLengthParam() const
static bool classof(const IntrinsicInst *I)
void setVectorLengthParam(Value *)
static std::optional< unsigned > getVectorLengthParamPos(Intrinsic::ID IntrinsicID)
static Intrinsic::ID getForOpcode(unsigned OC)
The llvm.vp.* intrinsics for this instruction Opcode.
static std::optional< unsigned > getMemoryPointerParamPos(Intrinsic::ID)
static bool isVPIntrinsic(Intrinsic::ID)
Value * getMemoryDataParam() const
Value * getMemoryPointerParam() const
MaybeAlign getPointerAlignment() const
Value * getMaskParam() const
ElementCount getStaticVectorLength() const
std::optional< unsigned > getFunctionalOpcode() const
This represents vector predication reduction intrinsics.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool isVPReduction(Intrinsic::ID ID)
unsigned getStartParamPos() const
unsigned getVectorParamPos() const
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
Value * getValue() const
Definition: Metadata.h:384
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:685
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
Represents an op.with.overflow intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const int NoAliasScopeDeclScopeArg
Definition: Intrinsics.h:37
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1742
static bool isLifetimeIntrinsic(Intrinsic::ID ID)
Check if ID corresponds to a lifetime intrinsic.
static bool isDbgInfoIntrinsic(Intrinsic::ID ID)
Check if ID corresponds to a debug info intrinsic.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117