LLVM 20.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"
37#include <cassert>
38#include <cstdint>
39#include <optional>
40
41namespace llvm {
42
43class Metadata;
44
45/// A wrapper class for inspecting calls to intrinsic functions.
46/// This allows the standard isa/dyncast/cast functionality to work with calls
47/// to intrinsic functions.
48class IntrinsicInst : public CallInst {
49public:
50 IntrinsicInst() = delete;
51 IntrinsicInst(const IntrinsicInst &) = delete;
53
54 /// Return the intrinsic ID of this intrinsic.
57 }
58
59 bool isAssociative() const {
60 switch (getIntrinsicID()) {
61 case Intrinsic::smax:
62 case Intrinsic::smin:
63 case Intrinsic::umax:
64 case Intrinsic::umin:
65 return true;
66 default:
67 return false;
68 }
69 }
70
71 /// Return true if swapping the first two arguments to the intrinsic produces
72 /// the same result.
73 bool isCommutative() const {
74 switch (getIntrinsicID()) {
75 case Intrinsic::maxnum:
76 case Intrinsic::minnum:
77 case Intrinsic::maximum:
78 case Intrinsic::minimum:
79 case Intrinsic::maximumnum:
80 case Intrinsic::minimumnum:
81 case Intrinsic::smax:
82 case Intrinsic::smin:
83 case Intrinsic::umax:
84 case Intrinsic::umin:
85 case Intrinsic::sadd_sat:
86 case Intrinsic::uadd_sat:
87 case Intrinsic::sadd_with_overflow:
88 case Intrinsic::uadd_with_overflow:
89 case Intrinsic::smul_with_overflow:
90 case Intrinsic::umul_with_overflow:
91 case Intrinsic::smul_fix:
92 case Intrinsic::umul_fix:
93 case Intrinsic::smul_fix_sat:
94 case Intrinsic::umul_fix_sat:
95 case Intrinsic::fma:
96 case Intrinsic::fmuladd:
97 return true;
98 default:
99 return false;
100 }
101 }
102
103 /// Checks if the intrinsic is an annotation.
105 switch (getIntrinsicID()) {
106 default: break;
107 case Intrinsic::assume:
108 case Intrinsic::sideeffect:
109 case Intrinsic::pseudoprobe:
110 case Intrinsic::dbg_assign:
111 case Intrinsic::dbg_declare:
112 case Intrinsic::dbg_value:
113 case Intrinsic::dbg_label:
114 case Intrinsic::invariant_start:
115 case Intrinsic::invariant_end:
116 case Intrinsic::lifetime_start:
117 case Intrinsic::lifetime_end:
118 case Intrinsic::experimental_noalias_scope_decl:
119 case Intrinsic::objectsize:
120 case Intrinsic::ptr_annotation:
121 case Intrinsic::var_annotation:
122 return true;
123 }
124 return false;
125 }
126
127 /// Check if the intrinsic might lower into a regular function call in the
128 /// course of IR transformations
129 static bool mayLowerToFunctionCall(Intrinsic::ID IID);
130
131 /// Methods for support type inquiry through isa, cast, and dyn_cast:
132 static bool classof(const CallInst *I) {
133 if (const Function *CF = I->getCalledFunction())
134 return CF->isIntrinsic();
135 return false;
136 }
137 static bool classof(const Value *V) {
138 return isa<CallInst>(V) && classof(cast<CallInst>(V));
139 }
140};
141
142/// Check if \p ID corresponds to a lifetime intrinsic.
144 switch (ID) {
145 case Intrinsic::lifetime_start:
146 case Intrinsic::lifetime_end:
147 return true;
148 default:
149 return false;
150 }
151}
152
153/// This is the common base class for lifetime intrinsics.
155public:
156 /// \name Casting methods
157 /// @{
158 static bool classof(const IntrinsicInst *I) {
159 return isLifetimeIntrinsic(I->getIntrinsicID());
160 }
161 static bool classof(const Value *V) {
162 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
163 }
164 /// @}
165};
166
167/// Check if \p ID corresponds to a debug info intrinsic.
169 switch (ID) {
170 case Intrinsic::dbg_declare:
171 case Intrinsic::dbg_value:
172 case Intrinsic::dbg_label:
173 case Intrinsic::dbg_assign:
174 return true;
175 default:
176 return false;
177 }
178}
179
180/// This is the common base class for debug info intrinsics.
182public:
183 /// \name Casting methods
184 /// @{
185 static bool classof(const IntrinsicInst *I) {
186 return isDbgInfoIntrinsic(I->getIntrinsicID());
187 }
188 static bool classof(const Value *V) {
189 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
190 }
191 /// @}
192};
193
194// Iterator for ValueAsMetadata that internally uses direct pointer iteration
195// over either a ValueAsMetadata* or a ValueAsMetadata**, dereferencing to the
196// ValueAsMetadata .
198 : public iterator_facade_base<location_op_iterator,
199 std::bidirectional_iterator_tag, Value *> {
201
202public:
203 location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {}
204 location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {}
205
208 I = R.I;
209 return *this;
210 }
211 bool operator==(const location_op_iterator &RHS) const { return I == RHS.I; }
212 const Value *operator*() const {
213 ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
214 ? cast<ValueAsMetadata *>(I)
215 : *cast<ValueAsMetadata **>(I);
216 return VAM->getValue();
217 };
219 ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
220 ? cast<ValueAsMetadata *>(I)
221 : *cast<ValueAsMetadata **>(I);
222 return VAM->getValue();
223 }
225 if (isa<ValueAsMetadata *>(I))
226 I = cast<ValueAsMetadata *>(I) + 1;
227 else
228 I = cast<ValueAsMetadata **>(I) + 1;
229 return *this;
230 }
232 if (isa<ValueAsMetadata *>(I))
233 I = cast<ValueAsMetadata *>(I) - 1;
234 else
235 I = cast<ValueAsMetadata **>(I) - 1;
236 return *this;
237 }
238};
239
240/// Lightweight class that wraps the location operand metadata of a debug
241/// intrinsic. The raw location may be a ValueAsMetadata, an empty MDTuple,
242/// or a DIArgList.
244 Metadata *RawLocation = nullptr;
245
246public:
248 explicit RawLocationWrapper(Metadata *RawLocation)
249 : RawLocation(RawLocation) {
250 // Allow ValueAsMetadata, empty MDTuple, DIArgList.
251 assert(RawLocation && "unexpected null RawLocation");
252 assert(isa<ValueAsMetadata>(RawLocation) || isa<DIArgList>(RawLocation) ||
253 (isa<MDNode>(RawLocation) &&
254 !cast<MDNode>(RawLocation)->getNumOperands()));
255 }
256 Metadata *getRawLocation() const { return RawLocation; }
257 /// Get the locations corresponding to the variable referenced by the debug
258 /// info intrinsic. Depending on the intrinsic, this could be the
259 /// variable's value or its address.
261 Value *getVariableLocationOp(unsigned OpIdx) const;
262 unsigned getNumVariableLocationOps() const {
263 if (hasArgList())
264 return cast<DIArgList>(getRawLocation())->getArgs().size();
265 return 1;
266 }
267 bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
269 // Check for "kill" sentinel values.
270 // Non-variadic: empty metadata.
271 if (!hasArgList() && isa<MDNode>(getRawLocation()))
272 return true;
273 // Variadic: empty DIArgList with empty expression.
274 if (getNumVariableLocationOps() == 0 && !Expression->isComplex())
275 return true;
276 // Variadic and non-variadic: Interpret expressions using undef or poison
277 // values as kills.
278 return any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
279 }
280
281 friend bool operator==(const RawLocationWrapper &A,
282 const RawLocationWrapper &B) {
283 return A.RawLocation == B.RawLocation;
284 }
285 friend bool operator!=(const RawLocationWrapper &A,
286 const RawLocationWrapper &B) {
287 return !(A == B);
288 }
289 friend bool operator>(const RawLocationWrapper &A,
290 const RawLocationWrapper &B) {
291 return A.RawLocation > B.RawLocation;
292 }
293 friend bool operator>=(const RawLocationWrapper &A,
294 const RawLocationWrapper &B) {
295 return A.RawLocation >= B.RawLocation;
296 }
297 friend bool operator<(const RawLocationWrapper &A,
298 const RawLocationWrapper &B) {
299 return A.RawLocation < B.RawLocation;
300 }
301 friend bool operator<=(const RawLocationWrapper &A,
302 const RawLocationWrapper &B) {
303 return A.RawLocation <= B.RawLocation;
304 }
305};
306
307/// This is the common base class for debug info intrinsics for variables.
309public:
310 /// Get the locations corresponding to the variable referenced by the debug
311 /// info intrinsic. Depending on the intrinsic, this could be the
312 /// variable's value or its address.
314
315 Value *getVariableLocationOp(unsigned OpIdx) const;
316
317 void replaceVariableLocationOp(Value *OldValue, Value *NewValue,
318 bool AllowEmpty = false);
319 void replaceVariableLocationOp(unsigned OpIdx, Value *NewValue);
320 /// Adding a new location operand will always result in this intrinsic using
321 /// an ArgList, and must always be accompanied by a new expression that uses
322 /// the new operand.
325
327 setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar));
328 }
329
332 }
333
334 unsigned getNumVariableLocationOps() const {
336 }
337
338 bool hasArgList() const { return getWrappedLocation().hasArgList(); }
339
340 /// Does this describe the address of a local variable. True for dbg.declare,
341 /// but not dbg.value, which describes its value, or dbg.assign, which
342 /// describes a combination of the variable's value and address.
343 bool isAddressOfVariable() const {
344 return getIntrinsicID() == Intrinsic::dbg_declare;
345 }
346
348 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
349 // this set anymore.
350 SmallPtrSet<Value *, 4> RemovedValues;
351 for (Value *OldValue : location_ops()) {
352 if (!RemovedValues.insert(OldValue).second)
353 continue;
354 Value *Poison = PoisonValue::get(OldValue->getType());
356 }
357 }
358
359 bool isKillLocation() const {
361 }
362
364 return cast<DILocalVariable>(getRawVariable());
365 }
366
368 return cast<DIExpression>(getRawExpression());
369 }
370
372 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
373 }
374
377 }
378
380 return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
381 }
382
384 return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
385 }
386
387 /// Use of this should generally be avoided; instead,
388 /// replaceVariableLocationOp and addVariableLocationOps should be used where
389 /// possible to avoid creating invalid state.
390 void setRawLocation(Metadata *Location) {
391 return setArgOperand(0, MetadataAsValue::get(getContext(), Location));
392 }
393
394 /// Get the size (in bits) of the variable, or fragment of the variable that
395 /// is described.
396 std::optional<uint64_t> getFragmentSizeInBits() const;
397
398 /// Get the FragmentInfo for the variable.
399 std::optional<DIExpression::FragmentInfo> getFragment() const {
400 return getExpression()->getFragmentInfo();
401 }
402
403 /// Get the FragmentInfo for the variable if it exists, otherwise return a
404 /// FragmentInfo that covers the entire variable if the variable size is
405 /// known, otherwise return a zero-sized fragment.
407 DIExpression::FragmentInfo VariableSlice(0, 0);
408 // Get the fragment or variable size, or zero.
409 if (auto Sz = getFragmentSizeInBits())
410 VariableSlice.SizeInBits = *Sz;
411 if (auto Frag = getExpression()->getFragmentInfo())
412 VariableSlice.OffsetInBits = Frag->OffsetInBits;
413 return VariableSlice;
414 }
415
416 /// \name Casting methods
417 /// @{
418 static bool classof(const IntrinsicInst *I) {
419 switch (I->getIntrinsicID()) {
420 case Intrinsic::dbg_declare:
421 case Intrinsic::dbg_value:
422 case Intrinsic::dbg_assign:
423 return true;
424 default:
425 return false;
426 }
427 }
428 static bool classof(const Value *V) {
429 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
430 }
431 /// @}
432protected:
433 void setArgOperand(unsigned i, Value *v) {
435 }
436 void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); }
437};
438
439/// This represents the llvm.dbg.declare instruction.
441public:
442 Value *getAddress() const {
444 "dbg.declare must have exactly 1 location operand.");
445 return getVariableLocationOp(0);
446 }
447
448 /// \name Casting methods
449 /// @{
450 static bool classof(const IntrinsicInst *I) {
451 return I->getIntrinsicID() == Intrinsic::dbg_declare;
452 }
453 static bool classof(const Value *V) {
454 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
455 }
456 /// @}
457};
458
459/// This represents the llvm.dbg.value instruction.
461public:
462 // The default argument should only be used in ISel, and the default option
463 // should be removed once ISel support for multiple location ops is complete.
464 Value *getValue(unsigned OpIdx = 0) const {
465 return getVariableLocationOp(OpIdx);
466 }
468 return location_ops();
469 }
470
471 /// \name Casting methods
472 /// @{
473 static bool classof(const IntrinsicInst *I) {
474 return I->getIntrinsicID() == Intrinsic::dbg_value ||
475 I->getIntrinsicID() == Intrinsic::dbg_assign;
476 }
477 static bool classof(const Value *V) {
478 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
479 }
480 /// @}
481};
482
483/// This represents the llvm.dbg.assign instruction.
485 enum Operands {
486 OpValue,
487 OpVar,
488 OpExpr,
489 OpAssignID,
490 OpAddress,
491 OpAddressExpr,
492 };
493
494public:
495 Value *getAddress() const;
497 return cast<MetadataAsValue>(getArgOperand(OpAddress))->getMetadata();
498 }
500 return cast<MetadataAsValue>(getArgOperand(OpAssignID))->getMetadata();
501 }
502 DIAssignID *getAssignID() const { return cast<DIAssignID>(getRawAssignID()); }
504 return cast<MetadataAsValue>(getArgOperand(OpAddressExpr))->getMetadata();
505 }
507 return cast<DIExpression>(getRawAddressExpression());
508 }
510 setArgOperand(OpAddressExpr,
511 MetadataAsValue::get(NewExpr->getContext(), NewExpr));
512 }
513 void setAssignId(DIAssignID *New);
514 void setAddress(Value *V);
515 /// Kill the address component.
516 void setKillAddress();
517 /// Check whether this kills the address component. This doesn't take into
518 /// account the position of the intrinsic, therefore a returned value of false
519 /// does not guarentee the address is a valid location for the variable at the
520 /// intrinsic's position in IR.
521 bool isKillAddress() const;
522 void setValue(Value *V);
523 /// \name Casting methods
524 /// @{
525 static bool classof(const IntrinsicInst *I) {
526 return I->getIntrinsicID() == Intrinsic::dbg_assign;
527 }
528 static bool classof(const Value *V) {
529 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
530 }
531 /// @}
532};
533
534/// This represents the llvm.dbg.label instruction.
536public:
537 DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); }
538 void setLabel(DILabel *NewLabel) {
540 }
541
543 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
544 }
545
546 /// Methods for support type inquiry through isa, cast, and dyn_cast:
547 /// @{
548 static bool classof(const IntrinsicInst *I) {
549 return I->getIntrinsicID() == Intrinsic::dbg_label;
550 }
551 static bool classof(const Value *V) {
552 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
553 }
554 /// @}
555};
556
557/// This is the common base class for vector predication intrinsics.
559public:
560 /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
561 /// \p Params. Additionally, the load and gather intrinsics require
562 /// \p ReturnType to be specified.
564 Type *ReturnType,
565 ArrayRef<Value *> Params);
566
567 static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
568 static std::optional<unsigned> getVectorLengthParamPos(
569 Intrinsic::ID IntrinsicID);
570
571 /// The llvm.vp.* intrinsics for this instruction Opcode
572 static Intrinsic::ID getForOpcode(unsigned OC);
573
574 /// The llvm.vp.* intrinsics for this intrinsic ID \p Id. Return \p Id if it
575 /// is already a VP intrinsic.
577
578 // Whether \p ID is a VP intrinsic ID.
579 static bool isVPIntrinsic(Intrinsic::ID);
580
581 /// \return The mask parameter or nullptr.
582 Value *getMaskParam() const;
583 void setMaskParam(Value *);
584
585 /// \return The vector length parameter or nullptr.
588
589 /// \return Whether the vector length param can be ignored.
590 bool canIgnoreVectorLengthParam() const;
591
592 /// \return The static element count (vector number of elements) the vector
593 /// length parameter applies to.
595
596 /// \return The alignment of the pointer used by this load/store/gather or
597 /// scatter.
599 // MaybeAlign setPointerAlignment(Align NewAlign); // TODO
600
601 /// \return The pointer operand of this load,store, gather or scatter.
603 static std::optional<unsigned> getMemoryPointerParamPos(Intrinsic::ID);
604
605 /// \return The data (payload) operand of this store or scatter.
606 Value *getMemoryDataParam() const;
607 static std::optional<unsigned> getMemoryDataParamPos(Intrinsic::ID);
608
609 // Methods for support type inquiry through isa, cast, and dyn_cast:
610 static bool classof(const IntrinsicInst *I) {
611 return isVPIntrinsic(I->getIntrinsicID());
612 }
613 static bool classof(const Value *V) {
614 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
615 }
616
617 // Equivalent non-predicated opcode
618 std::optional<unsigned> getFunctionalOpcode() const {
620 }
621
622 // Equivalent non-predicated intrinsic ID
623 std::optional<unsigned> getFunctionalIntrinsicID() const {
625 }
626
627 // Equivalent non-predicated constrained ID
628 std::optional<unsigned> getConstrainedIntrinsicID() const {
630 }
631
632 // Equivalent non-predicated opcode
633 static std::optional<unsigned> getFunctionalOpcodeForVP(Intrinsic::ID ID);
634
635 // Equivalent non-predicated intrinsic ID
636 static std::optional<Intrinsic::ID>
638
639 // Equivalent non-predicated constrained ID
640 static std::optional<Intrinsic::ID>
642};
643
644/// This represents vector predication reduction intrinsics.
646public:
647 static bool isVPReduction(Intrinsic::ID ID);
648
649 unsigned getStartParamPos() const;
650 unsigned getVectorParamPos() const;
651
652 static std::optional<unsigned> getStartParamPos(Intrinsic::ID ID);
653 static std::optional<unsigned> getVectorParamPos(Intrinsic::ID ID);
654
655 /// Methods for support type inquiry through isa, cast, and dyn_cast:
656 /// @{
657 static bool classof(const IntrinsicInst *I) {
658 return VPReductionIntrinsic::isVPReduction(I->getIntrinsicID());
659 }
660 static bool classof(const Value *V) {
661 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
662 }
663 /// @}
664};
665
667public:
668 static bool isVPCast(Intrinsic::ID ID);
669
670 /// Methods for support type inquiry through isa, cast, and dyn_cast:
671 /// @{
672 static bool classof(const IntrinsicInst *I) {
673 return VPCastIntrinsic::isVPCast(I->getIntrinsicID());
674 }
675 static bool classof(const Value *V) {
676 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
677 }
678 /// @}
679};
680
682public:
683 static bool isVPCmp(Intrinsic::ID ID);
684
686
687 /// Methods for support type inquiry through isa, cast, and dyn_cast:
688 /// @{
689 static bool classof(const IntrinsicInst *I) {
690 return VPCmpIntrinsic::isVPCmp(I->getIntrinsicID());
691 }
692 static bool classof(const Value *V) {
693 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
694 }
695 /// @}
696};
697
699public:
700 static bool isVPBinOp(Intrinsic::ID ID);
701
702 /// Methods for support type inquiry through isa, cast, and dyn_cast:
703 /// @{
704 static bool classof(const IntrinsicInst *I) {
705 return VPBinOpIntrinsic::isVPBinOp(I->getIntrinsicID());
706 }
707 static bool classof(const Value *V) {
708 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
709 }
710 /// @}
711};
712
713
714/// This is the common base class for constrained floating point intrinsics.
716public:
717 unsigned getNonMetadataArgCount() const;
718 std::optional<RoundingMode> getRoundingMode() const;
719 std::optional<fp::ExceptionBehavior> getExceptionBehavior() const;
720 bool isDefaultFPEnvironment() const;
721
722 // Methods for support type inquiry through isa, cast, and dyn_cast:
723 static bool classof(const IntrinsicInst *I);
724 static bool classof(const Value *V) {
725 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
726 }
727};
728
729/// Constrained floating point compare intrinsics.
731public:
733 bool isSignaling() const {
734 return getIntrinsicID() == Intrinsic::experimental_constrained_fcmps;
735 }
736
737 // Methods for support type inquiry through isa, cast, and dyn_cast:
738 static bool classof(const IntrinsicInst *I) {
739 switch (I->getIntrinsicID()) {
740 case Intrinsic::experimental_constrained_fcmp:
741 case Intrinsic::experimental_constrained_fcmps:
742 return true;
743 default:
744 return false;
745 }
746 }
747 static bool classof(const Value *V) {
748 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
749 }
750};
751
752/// This class represents min/max intrinsics.
754public:
755 static bool classof(const IntrinsicInst *I) {
756 switch (I->getIntrinsicID()) {
757 case Intrinsic::umin:
758 case Intrinsic::umax:
759 case Intrinsic::smin:
760 case Intrinsic::smax:
761 return true;
762 default:
763 return false;
764 }
765 }
766 static bool classof(const Value *V) {
767 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
768 }
769
770 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
771 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
772
773 /// Returns the comparison predicate underlying the intrinsic.
775 switch (ID) {
776 case Intrinsic::umin:
778 case Intrinsic::umax:
780 case Intrinsic::smin:
782 case Intrinsic::smax:
784 default:
785 llvm_unreachable("Invalid intrinsic");
786 }
787 }
788
789 /// Returns the comparison predicate underlying the intrinsic.
792 }
793
794 /// Whether the intrinsic is signed or unsigned.
795 static bool isSigned(Intrinsic::ID ID) {
797 };
798
799 /// Whether the intrinsic is signed or unsigned.
800 bool isSigned() const { return isSigned(getIntrinsicID()); };
801
802 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
803 /// so there is a certain threshold value, upon reaching which,
804 /// their value can no longer change. Return said threshold.
805 static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits) {
806 switch (ID) {
807 case Intrinsic::umin:
808 return APInt::getMinValue(numBits);
809 case Intrinsic::umax:
810 return APInt::getMaxValue(numBits);
811 case Intrinsic::smin:
812 return APInt::getSignedMinValue(numBits);
813 case Intrinsic::smax:
814 return APInt::getSignedMaxValue(numBits);
815 default:
816 llvm_unreachable("Invalid intrinsic");
817 }
818 }
819
820 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
821 /// so there is a certain threshold value, upon reaching which,
822 /// their value can no longer change. Return said threshold.
823 APInt getSaturationPoint(unsigned numBits) const {
824 return getSaturationPoint(getIntrinsicID(), numBits);
825 }
826
827 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
828 /// so there is a certain threshold value, upon reaching which,
829 /// their value can no longer change. Return said threshold.
833 }
834
835 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
836 /// so there is a certain threshold value, upon reaching which,
837 /// their value can no longer change. Return said threshold.
840 }
841};
842
843/// This class represents a ucmp/scmp intrinsic
845public:
846 static bool classof(const IntrinsicInst *I) {
847 switch (I->getIntrinsicID()) {
848 case Intrinsic::scmp:
849 case Intrinsic::ucmp:
850 return true;
851 default:
852 return false;
853 }
854 }
855 static bool classof(const Value *V) {
856 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
857 }
858
859 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
860 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
861
862 static bool isSigned(Intrinsic::ID ID) { return ID == Intrinsic::scmp; }
863 bool isSigned() const { return isSigned(getIntrinsicID()); }
864
867 }
870 }
871
874 }
877 }
878};
879
880/// This class represents an intrinsic that is based on a binary operation.
881/// This includes op.with.overflow and saturating add/sub intrinsics.
883public:
884 static bool classof(const IntrinsicInst *I) {
885 switch (I->getIntrinsicID()) {
886 case Intrinsic::uadd_with_overflow:
887 case Intrinsic::sadd_with_overflow:
888 case Intrinsic::usub_with_overflow:
889 case Intrinsic::ssub_with_overflow:
890 case Intrinsic::umul_with_overflow:
891 case Intrinsic::smul_with_overflow:
892 case Intrinsic::uadd_sat:
893 case Intrinsic::sadd_sat:
894 case Intrinsic::usub_sat:
895 case Intrinsic::ssub_sat:
896 return true;
897 default:
898 return false;
899 }
900 }
901 static bool classof(const Value *V) {
902 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
903 }
904
905 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
906 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
907
908 /// Returns the binary operation underlying the intrinsic.
910
911 /// Whether the intrinsic is signed or unsigned.
912 bool isSigned() const;
913
914 /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
915 unsigned getNoWrapKind() const;
916};
917
918/// Represents an op.with.overflow intrinsic.
920public:
921 static bool classof(const IntrinsicInst *I) {
922 switch (I->getIntrinsicID()) {
923 case Intrinsic::uadd_with_overflow:
924 case Intrinsic::sadd_with_overflow:
925 case Intrinsic::usub_with_overflow:
926 case Intrinsic::ssub_with_overflow:
927 case Intrinsic::umul_with_overflow:
928 case Intrinsic::smul_with_overflow:
929 return true;
930 default:
931 return false;
932 }
933 }
934 static bool classof(const Value *V) {
935 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
936 }
937};
938
939/// Represents a saturating add/sub intrinsic.
941public:
942 static bool classof(const IntrinsicInst *I) {
943 switch (I->getIntrinsicID()) {
944 case Intrinsic::uadd_sat:
945 case Intrinsic::sadd_sat:
946 case Intrinsic::usub_sat:
947 case Intrinsic::ssub_sat:
948 return true;
949 default:
950 return false;
951 }
952 }
953 static bool classof(const Value *V) {
954 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
955 }
956};
957
958/// Common base class for all memory intrinsics. Simply provides
959/// common methods.
960/// Written as CRTP to avoid a common base class amongst the
961/// three atomicity hierarchies.
962template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
963private:
964 enum { ARG_DEST = 0, ARG_LENGTH = 2 };
965
966public:
967 Value *getRawDest() const {
968 return const_cast<Value *>(getArgOperand(ARG_DEST));
969 }
970 const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
971 Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
972
973 Value *getLength() const {
974 return const_cast<Value *>(getArgOperand(ARG_LENGTH));
975 }
976 const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
977 Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
978
979 /// This is just like getRawDest, but it strips off any cast
980 /// instructions (including addrspacecast) that feed it, giving the
981 /// original input. The returned value is guaranteed to be a pointer.
982 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
983
984 unsigned getDestAddressSpace() const {
985 return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
986 }
987
988 /// FIXME: Remove this function once transition to Align is over.
989 /// Use getDestAlign() instead.
990 LLVM_DEPRECATED("Use getDestAlign() instead", "getDestAlign")
992 if (auto MA = getParamAlign(ARG_DEST))
993 return MA->value();
994 return 0;
995 }
996 MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
997
998 /// Set the specified arguments of the instruction.
1000 assert(getRawDest()->getType() == Ptr->getType() &&
1001 "setDest called with pointer of wrong type!");
1002 setArgOperand(ARG_DEST, Ptr);
1003 }
1004
1006 removeParamAttr(ARG_DEST, Attribute::Alignment);
1007 if (Alignment)
1008 addParamAttr(ARG_DEST,
1010 }
1011 void setDestAlignment(Align Alignment) {
1012 removeParamAttr(ARG_DEST, Attribute::Alignment);
1013 addParamAttr(ARG_DEST,
1015 }
1016
1017 void setLength(Value *L) {
1018 assert(getLength()->getType() == L->getType() &&
1019 "setLength called with value of wrong type!");
1020 setArgOperand(ARG_LENGTH, L);
1021 }
1022};
1023
1024/// Common base class for all memory transfer intrinsics. Simply provides
1025/// common methods.
1026template <class BaseCL> class MemTransferBase : public BaseCL {
1027private:
1028 enum { ARG_SOURCE = 1 };
1029
1030public:
1031 /// Return the arguments to the instruction.
1033 return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
1034 }
1035 const Use &getRawSourceUse() const {
1036 return BaseCL::getArgOperandUse(ARG_SOURCE);
1037 }
1038 Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
1039
1040 /// This is just like getRawSource, but it strips off any cast
1041 /// instructions that feed it, giving the original input. The returned
1042 /// value is guaranteed to be a pointer.
1044
1045 unsigned getSourceAddressSpace() const {
1046 return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
1047 }
1048
1049 /// FIXME: Remove this function once transition to Align is over.
1050 /// Use getSourceAlign() instead.
1051 LLVM_DEPRECATED("Use getSourceAlign() instead", "getSourceAlign")
1053 if (auto MA = BaseCL::getParamAlign(ARG_SOURCE))
1054 return MA->value();
1055 return 0;
1056 }
1057
1059 return BaseCL::getParamAlign(ARG_SOURCE);
1060 }
1061
1063 assert(getRawSource()->getType() == Ptr->getType() &&
1064 "setSource called with pointer of wrong type!");
1065 BaseCL::setArgOperand(ARG_SOURCE, Ptr);
1066 }
1067
1069 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
1070 if (Alignment)
1071 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
1072 BaseCL::getContext(), *Alignment));
1073 }
1074
1075 void setSourceAlignment(Align Alignment) {
1076 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
1077 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
1078 BaseCL::getContext(), Alignment));
1079 }
1080};
1081
1082/// Common base class for all memset intrinsics. Simply provides
1083/// common methods.
1084template <class BaseCL> class MemSetBase : public BaseCL {
1085private:
1086 enum { ARG_VALUE = 1 };
1087
1088public:
1089 Value *getValue() const {
1090 return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
1091 }
1092 const Use &getValueUse() const { return BaseCL::getArgOperandUse(ARG_VALUE); }
1093 Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
1094
1095 void setValue(Value *Val) {
1096 assert(getValue()->getType() == Val->getType() &&
1097 "setValue called with value of wrong type!");
1098 BaseCL::setArgOperand(ARG_VALUE, Val);
1099 }
1100};
1101
1102// The common base class for the atomic memset/memmove/memcpy intrinsics
1103// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
1104class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
1105private:
1106 enum { ARG_ELEMENTSIZE = 3 };
1107
1108public:
1110 return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
1111 }
1112
1114 return cast<ConstantInt>(getRawElementSizeInBytes());
1115 }
1116
1119 }
1120
1122 assert(V->getType() == Type::getInt8Ty(getContext()) &&
1123 "setElementSizeInBytes called with value of wrong type!");
1124 setArgOperand(ARG_ELEMENTSIZE, V);
1125 }
1126
1127 static bool classof(const IntrinsicInst *I) {
1128 switch (I->getIntrinsicID()) {
1129 case Intrinsic::memcpy_element_unordered_atomic:
1130 case Intrinsic::memmove_element_unordered_atomic:
1131 case Intrinsic::memset_element_unordered_atomic:
1132 return true;
1133 default:
1134 return false;
1135 }
1136 }
1137 static bool classof(const Value *V) {
1138 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1139 }
1140};
1141
1142/// This class represents atomic memset intrinsic
1143// i.e. llvm.element.unordered.atomic.memset
1144class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
1145public:
1146 static bool classof(const IntrinsicInst *I) {
1147 return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
1148 }
1149 static bool classof(const Value *V) {
1150 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1151 }
1152};
1153
1154// This class wraps the atomic memcpy/memmove intrinsics
1155// i.e. llvm.element.unordered.atomic.memcpy/memmove
1156class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
1157public:
1158 static bool classof(const IntrinsicInst *I) {
1159 switch (I->getIntrinsicID()) {
1160 case Intrinsic::memcpy_element_unordered_atomic:
1161 case Intrinsic::memmove_element_unordered_atomic:
1162 return true;
1163 default:
1164 return false;
1165 }
1166 }
1167 static bool classof(const Value *V) {
1168 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1169 }
1170};
1171
1172/// This class represents the atomic memcpy intrinsic
1173/// i.e. llvm.element.unordered.atomic.memcpy
1175public:
1176 static bool classof(const IntrinsicInst *I) {
1177 return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
1178 }
1179 static bool classof(const Value *V) {
1180 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1181 }
1182};
1183
1184/// This class represents the atomic memmove intrinsic
1185/// i.e. llvm.element.unordered.atomic.memmove
1187public:
1188 static bool classof(const IntrinsicInst *I) {
1189 return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
1190 }
1191 static bool classof(const Value *V) {
1192 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1193 }
1194};
1195
1196/// This is the common base class for memset/memcpy/memmove.
1197class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1198private:
1199 enum { ARG_VOLATILE = 3 };
1200
1201public:
1203 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1204 }
1205
1206 bool isVolatile() const { return !getVolatileCst()->isZero(); }
1207
1208 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
1209
1210 // Methods for support type inquiry through isa, cast, and dyn_cast:
1211 static bool classof(const IntrinsicInst *I) {
1212 switch (I->getIntrinsicID()) {
1213 case Intrinsic::memcpy:
1214 case Intrinsic::memmove:
1215 case Intrinsic::memset:
1216 case Intrinsic::memset_inline:
1217 case Intrinsic::memcpy_inline:
1218 return true;
1219 default:
1220 return false;
1221 }
1222 }
1223 static bool classof(const Value *V) {
1224 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1225 }
1226};
1227
1228/// This class wraps the llvm.memset and llvm.memset.inline intrinsics.
1229class MemSetInst : public MemSetBase<MemIntrinsic> {
1230public:
1231 // Methods for support type inquiry through isa, cast, and dyn_cast:
1232 static bool classof(const IntrinsicInst *I) {
1233 switch (I->getIntrinsicID()) {
1234 case Intrinsic::memset:
1235 case Intrinsic::memset_inline:
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 wraps the llvm.memset.inline intrinsic.
1248public:
1249 // Methods for support type inquiry through isa, cast, and dyn_cast:
1250 static bool classof(const IntrinsicInst *I) {
1251 return I->getIntrinsicID() == Intrinsic::memset_inline;
1252 }
1253 static bool classof(const Value *V) {
1254 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1255 }
1256};
1257
1258/// This class wraps the llvm.memcpy/memmove intrinsics.
1259class MemTransferInst : public MemTransferBase<MemIntrinsic> {
1260public:
1261 // Methods for support type inquiry through isa, cast, and dyn_cast:
1262 static bool classof(const IntrinsicInst *I) {
1263 switch (I->getIntrinsicID()) {
1264 case Intrinsic::memcpy:
1265 case Intrinsic::memmove:
1266 case Intrinsic::memcpy_inline:
1267 return true;
1268 default:
1269 return false;
1270 }
1271 }
1272 static bool classof(const Value *V) {
1273 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1274 }
1275};
1276
1277/// This class wraps the llvm.memcpy intrinsic.
1279public:
1280 // Methods for support type inquiry through isa, cast, and dyn_cast:
1281 static bool classof(const IntrinsicInst *I) {
1282 return I->getIntrinsicID() == Intrinsic::memcpy ||
1283 I->getIntrinsicID() == Intrinsic::memcpy_inline;
1284 }
1285 static bool classof(const Value *V) {
1286 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1287 }
1288};
1289
1290/// This class wraps the llvm.memmove intrinsic.
1292public:
1293 // Methods for support type inquiry through isa, cast, and dyn_cast:
1294 static bool classof(const IntrinsicInst *I) {
1295 return I->getIntrinsicID() == Intrinsic::memmove;
1296 }
1297 static bool classof(const Value *V) {
1298 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1299 }
1300};
1301
1302/// This class wraps the llvm.memcpy.inline intrinsic.
1304public:
1305 // Methods for support type inquiry through isa, cast, and dyn_cast:
1306 static bool classof(const IntrinsicInst *I) {
1307 return I->getIntrinsicID() == Intrinsic::memcpy_inline;
1308 }
1309 static bool classof(const Value *V) {
1310 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1311 }
1312};
1313
1314// The common base class for any memset/memmove/memcpy intrinsics;
1315// whether they be atomic or non-atomic.
1316// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
1317// and llvm.memset/memcpy/memmove
1318class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
1319public:
1320 bool isVolatile() const {
1321 // Only the non-atomic intrinsics can be volatile
1322 if (auto *MI = dyn_cast<MemIntrinsic>(this))
1323 return MI->isVolatile();
1324 return false;
1325 }
1326
1327 static bool classof(const IntrinsicInst *I) {
1328 switch (I->getIntrinsicID()) {
1329 case Intrinsic::memcpy:
1330 case Intrinsic::memcpy_inline:
1331 case Intrinsic::memmove:
1332 case Intrinsic::memset:
1333 case Intrinsic::memset_inline:
1334 case Intrinsic::memcpy_element_unordered_atomic:
1335 case Intrinsic::memmove_element_unordered_atomic:
1336 case Intrinsic::memset_element_unordered_atomic:
1337 return true;
1338 default:
1339 return false;
1340 }
1341 }
1342 static bool classof(const Value *V) {
1343 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1344 }
1345};
1346
1347/// This class represents any memset intrinsic
1348// i.e. llvm.element.unordered.atomic.memset
1349// and llvm.memset
1350class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
1351public:
1352 static bool classof(const IntrinsicInst *I) {
1353 switch (I->getIntrinsicID()) {
1354 case Intrinsic::memset:
1355 case Intrinsic::memset_inline:
1356 case Intrinsic::memset_element_unordered_atomic:
1357 return true;
1358 default:
1359 return false;
1360 }
1361 }
1362 static bool classof(const Value *V) {
1363 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1364 }
1365};
1366
1367// This class wraps any memcpy/memmove intrinsics
1368// i.e. llvm.element.unordered.atomic.memcpy/memmove
1369// and llvm.memcpy/memmove
1370class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
1371public:
1372 static bool classof(const IntrinsicInst *I) {
1373 switch (I->getIntrinsicID()) {
1374 case Intrinsic::memcpy:
1375 case Intrinsic::memcpy_inline:
1376 case Intrinsic::memmove:
1377 case Intrinsic::memcpy_element_unordered_atomic:
1378 case Intrinsic::memmove_element_unordered_atomic:
1379 return true;
1380 default:
1381 return false;
1382 }
1383 }
1384 static bool classof(const Value *V) {
1385 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1386 }
1387};
1388
1389/// This class represents any memcpy intrinsic
1390/// i.e. llvm.element.unordered.atomic.memcpy
1391/// and llvm.memcpy
1393public:
1394 static bool classof(const IntrinsicInst *I) {
1395 switch (I->getIntrinsicID()) {
1396 case Intrinsic::memcpy:
1397 case Intrinsic::memcpy_inline:
1398 case Intrinsic::memcpy_element_unordered_atomic:
1399 return true;
1400 default:
1401 return false;
1402 }
1403 }
1404 static bool classof(const Value *V) {
1405 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1406 }
1407};
1408
1409/// This class represents any memmove intrinsic
1410/// i.e. llvm.element.unordered.atomic.memmove
1411/// and llvm.memmove
1413public:
1414 static bool classof(const IntrinsicInst *I) {
1415 switch (I->getIntrinsicID()) {
1416 case Intrinsic::memmove:
1417 case Intrinsic::memmove_element_unordered_atomic:
1418 return true;
1419 default:
1420 return false;
1421 }
1422 }
1423 static bool classof(const Value *V) {
1424 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1425 }
1426};
1427
1428/// This represents the llvm.va_start intrinsic.
1430public:
1431 static bool classof(const IntrinsicInst *I) {
1432 return I->getIntrinsicID() == Intrinsic::vastart;
1433 }
1434 static bool classof(const Value *V) {
1435 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1436 }
1437
1438 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1439};
1440
1441/// This represents the llvm.va_end intrinsic.
1442class VAEndInst : public IntrinsicInst {
1443public:
1444 static bool classof(const IntrinsicInst *I) {
1445 return I->getIntrinsicID() == Intrinsic::vaend;
1446 }
1447 static bool classof(const Value *V) {
1448 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1449 }
1450
1451 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1452};
1453
1454/// This represents the llvm.va_copy intrinsic.
1456public:
1457 static bool classof(const IntrinsicInst *I) {
1458 return I->getIntrinsicID() == Intrinsic::vacopy;
1459 }
1460 static bool classof(const Value *V) {
1461 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1462 }
1463
1464 Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); }
1465 Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); }
1466};
1467
1468/// A base class for all instrprof intrinsics.
1470protected:
1471 static bool isCounterBase(const IntrinsicInst &I) {
1472 switch (I.getIntrinsicID()) {
1473 case Intrinsic::instrprof_cover:
1474 case Intrinsic::instrprof_increment:
1475 case Intrinsic::instrprof_increment_step:
1476 case Intrinsic::instrprof_callsite:
1477 case Intrinsic::instrprof_timestamp:
1478 case Intrinsic::instrprof_value_profile:
1479 return true;
1480 }
1481 return false;
1482 }
1483 static bool isMCDCBitmapBase(const IntrinsicInst &I) {
1484 switch (I.getIntrinsicID()) {
1485 case Intrinsic::instrprof_mcdc_parameters:
1486 case Intrinsic::instrprof_mcdc_tvbitmap_update:
1487 return true;
1488 }
1489 return false;
1490 }
1491
1492public:
1493 static bool classof(const Value *V) {
1494 if (const auto *Instr = dyn_cast<IntrinsicInst>(V))
1495 return isCounterBase(*Instr) || isMCDCBitmapBase(*Instr);
1496 return false;
1497 }
1498 // The name of the instrumented function.
1500 return cast<GlobalVariable>(
1501 const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
1502 }
1503 // The hash of the CFG for the instrumented function.
1505 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1506 }
1507};
1508
1509/// A base class for all instrprof counter intrinsics.
1511public:
1512 static bool classof(const Value *V) {
1513 if (const auto *Instr = dyn_cast<IntrinsicInst>(V))
1514 return InstrProfInstBase::isCounterBase(*Instr);
1515 return false;
1516 }
1517
1518 // The number of counters for the instrumented function.
1519 ConstantInt *getNumCounters() const;
1520 // The index of the counter that this instruction acts on.
1521 ConstantInt *getIndex() const;
1522};
1523
1524/// This represents the llvm.instrprof.cover intrinsic.
1526public:
1527 static bool classof(const IntrinsicInst *I) {
1528 return I->getIntrinsicID() == Intrinsic::instrprof_cover;
1529 }
1530 static bool classof(const Value *V) {
1531 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1532 }
1533};
1534
1535/// This represents the llvm.instrprof.increment intrinsic.
1537public:
1538 static bool classof(const IntrinsicInst *I) {
1539 return I->getIntrinsicID() == Intrinsic::instrprof_increment ||
1540 I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1541 }
1542 static bool classof(const Value *V) {
1543 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1544 }
1545 Value *getStep() const;
1546};
1547
1548/// This represents the llvm.instrprof.increment.step intrinsic.
1550public:
1551 static bool classof(const IntrinsicInst *I) {
1552 return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1553 }
1554 static bool classof(const Value *V) {
1555 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1556 }
1557};
1558
1559/// This represents the llvm.instrprof.callsite intrinsic.
1560/// It is structurally like the increment or step counters, hence the
1561/// inheritance relationship, albeit somewhat tenuous (it's not 'counting' per
1562/// se)
1564public:
1565 static bool classof(const IntrinsicInst *I) {
1566 return I->getIntrinsicID() == Intrinsic::instrprof_callsite;
1567 }
1568 static bool classof(const Value *V) {
1569 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1570 }
1571 Value *getCallee() const;
1572};
1573
1574/// This represents the llvm.instrprof.timestamp intrinsic.
1576public:
1577 static bool classof(const IntrinsicInst *I) {
1578 return I->getIntrinsicID() == Intrinsic::instrprof_timestamp;
1579 }
1580 static bool classof(const Value *V) {
1581 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1582 }
1583};
1584
1585/// This represents the llvm.instrprof.value.profile intrinsic.
1587public:
1588 static bool classof(const IntrinsicInst *I) {
1589 return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
1590 }
1591 static bool classof(const Value *V) {
1592 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1593 }
1594
1596 return cast<Value>(const_cast<Value *>(getArgOperand(2)));
1597 }
1598
1600 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1601 }
1602
1603 // Returns the value site index.
1605 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
1606 }
1607};
1608
1609/// A base class for instrprof mcdc intrinsics that require global bitmap bytes.
1611public:
1612 static bool classof(const IntrinsicInst *I) {
1614 }
1615 static bool classof(const Value *V) {
1616 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1617 }
1618
1619 /// \return The number of bits used for the MCDC bitmaps for the instrumented
1620 /// function.
1622 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1623 }
1624
1625 /// \return The number of bytes used for the MCDC bitmaps for the instrumented
1626 /// function.
1627 auto getNumBitmapBytes() const {
1628 return alignTo(getNumBitmapBits()->getZExtValue(), CHAR_BIT) / CHAR_BIT;
1629 }
1630};
1631
1632/// This represents the llvm.instrprof.mcdc.parameters intrinsic.
1634public:
1635 static bool classof(const IntrinsicInst *I) {
1636 return I->getIntrinsicID() == Intrinsic::instrprof_mcdc_parameters;
1637 }
1638 static bool classof(const Value *V) {
1639 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1640 }
1641};
1642
1643/// This represents the llvm.instrprof.mcdc.tvbitmap.update intrinsic.
1645public:
1646 static bool classof(const IntrinsicInst *I) {
1647 return I->getIntrinsicID() == Intrinsic::instrprof_mcdc_tvbitmap_update;
1648 }
1649 static bool classof(const Value *V) {
1650 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1651 }
1652
1653 /// \return The index of the TestVector Bitmap upon which this intrinsic
1654 /// acts.
1656 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1657 }
1658
1659 /// \return The address of the corresponding condition bitmap containing
1660 /// the index of the TestVector to update within the TestVector Bitmap.
1662 return cast<Value>(const_cast<Value *>(getArgOperand(3)));
1663 }
1664};
1665
1667public:
1668 static bool classof(const IntrinsicInst *I) {
1669 return I->getIntrinsicID() == Intrinsic::pseudoprobe;
1670 }
1671
1672 static bool classof(const Value *V) {
1673 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1674 }
1675
1677 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
1678 }
1679
1681 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1682 }
1683
1685 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1686 }
1687
1689 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1690 }
1691};
1692
1694public:
1695 static bool classof(const IntrinsicInst *I) {
1696 return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
1697 }
1698
1699 static bool classof(const Value *V) {
1700 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1701 }
1702
1704 auto *MV =
1705 cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
1706 return cast<MDNode>(MV->getMetadata());
1707 }
1708
1709 void setScopeList(MDNode *ScopeList) {
1711 MetadataAsValue::get(getContext(), ScopeList));
1712 }
1713};
1714
1715/// Common base class for representing values projected from a statepoint.
1716/// Currently, the only projections available are gc.result and gc.relocate.
1718public:
1719 static bool classof(const IntrinsicInst *I) {
1720 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate ||
1721 I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1722 }
1723
1724 static bool classof(const Value *V) {
1725 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1726 }
1727
1728 /// Return true if this relocate is tied to the invoke statepoint.
1729 /// This includes relocates which are on the unwinding path.
1730 bool isTiedToInvoke() const {
1731 const Value *Token = getArgOperand(0);
1732
1733 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
1734 }
1735
1736 /// The statepoint with which this gc.relocate is associated.
1737 const Value *getStatepoint() const;
1738};
1739
1740/// Represents calls to the gc.relocate intrinsic.
1742public:
1743 static bool classof(const IntrinsicInst *I) {
1744 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate;
1745 }
1746
1747 static bool classof(const Value *V) {
1748 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1749 }
1750
1751 /// The index into the associate statepoint's argument list
1752 /// which contains the base pointer of the pointer whose
1753 /// relocation this gc.relocate describes.
1754 unsigned getBasePtrIndex() const {
1755 return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
1756 }
1757
1758 /// The index into the associate statepoint's argument list which
1759 /// contains the pointer whose relocation this gc.relocate describes.
1760 unsigned getDerivedPtrIndex() const {
1761 return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
1762 }
1763
1764 Value *getBasePtr() const;
1765 Value *getDerivedPtr() const;
1766};
1767
1768/// Represents calls to the gc.result intrinsic.
1770public:
1771 static bool classof(const IntrinsicInst *I) {
1772 return I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1773 }
1774
1775 static bool classof(const Value *V) {
1776 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1777 }
1778};
1779
1780
1781/// This represents the llvm.assume intrinsic.
1783public:
1784 static bool classof(const IntrinsicInst *I) {
1785 return I->getIntrinsicID() == Intrinsic::assume;
1786 }
1787 static bool classof(const Value *V) {
1788 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1789 }
1790};
1791
1792/// Check if \p ID corresponds to a convergence control intrinsic.
1793static inline bool isConvergenceControlIntrinsic(unsigned IntrinsicID) {
1794 switch (IntrinsicID) {
1795 default:
1796 return false;
1797 case Intrinsic::experimental_convergence_anchor:
1798 case Intrinsic::experimental_convergence_entry:
1799 case Intrinsic::experimental_convergence_loop:
1800 return true;
1801 }
1802}
1803
1804/// Represents calls to the llvm.experimintal.convergence.* intrinsics.
1806public:
1807 static bool classof(const IntrinsicInst *I) {
1808 return isConvergenceControlIntrinsic(I->getIntrinsicID());
1809 }
1810
1811 static bool classof(const Value *V) {
1812 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1813 }
1814
1815 bool isAnchor() {
1816 return getIntrinsicID() == Intrinsic::experimental_convergence_anchor;
1817 }
1818 bool isEntry() {
1819 return getIntrinsicID() == Intrinsic::experimental_convergence_entry;
1820 }
1821 bool isLoop() {
1822 return getIntrinsicID() == Intrinsic::experimental_convergence_loop;
1823 }
1824};
1825
1826} // end namespace llvm
1827
1828#endif // LLVM_IR_INTRINSICINST_H
@ Poison
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DEPRECATED(MSG, FIX)
Definition: Compiler.h:153
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate DXIL Translate Metadata
This file contains the declarations of entities that describe floating point environment and related ...
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:40
Value * RHS
Class for arbitrary precision integers.
Definition: APInt.h:78
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:184
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:187
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:194
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:197
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:233
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:1641
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1465
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:1838
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1421
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1410
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1415
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1594
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:757
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:786
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:780
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:784
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:782
bool isSigned() const
Definition: InstrTypes.h:1007
This class represents a ucmp/scmp intrinsic.
static CmpInst::Predicate getGTPredicate(Intrinsic::ID ID)
Value * getRHS() const
CmpInst::Predicate getLTPredicate() const
static CmpInst::Predicate getLTPredicate(Intrinsic::ID ID)
static bool classof(const IntrinsicInst *I)
static bool isSigned(Intrinsic::ID ID)
bool isSigned() const
CmpInst::Predicate getGTPredicate() const
Value * getLHS() const
static bool classof(const Value *V)
This is the shared class of boolean and integer constants.
Definition: Constants.h:81
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:206
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:155
This is an important base class in LLVM.
Definition: Constant.h:42
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:400
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
unsigned getNonMetadataArgCount() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
Represents calls to the llvm.experimintal.convergence.* intrinsics.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
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.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)
void setLabel(DILabel *NewLabel)
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
This is the common base class for debug info intrinsics for variables.
DIExpression::FragmentInfo getFragmentOrEntireVariable() const
Get the FragmentInfo for the variable if it exists, otherwise return a FragmentInfo that covers the e...
void setVariable(DILocalVariable *NewVar)
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
void addVariableLocationOps(ArrayRef< Value * > NewValues, DIExpression *NewExpr)
Adding a new location operand will always result in this intrinsic using an ArgList,...
void setRawLocation(Metadata *Location)
Use of this should generally be avoided; instead, replaceVariableLocationOp and addVariableLocationOp...
void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
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.
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
RawLocationWrapper getWrappedLocation() const
Class representing an expression and its matching format.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:249
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.callsite intrinsic.
Value * getCallee() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
A base class for all instrprof counter intrinsics.
static bool classof(const Value *V)
ConstantInt * getIndex() const
ConstantInt * getNumCounters() const
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.
static bool classof(const Value *V)
GlobalVariable * getName() const
ConstantInt * getHash() const
static bool isCounterBase(const IntrinsicInst &I)
static bool isMCDCBitmapBase(const IntrinsicInst &I)
A base class for instrprof mcdc intrinsics that require global bitmap bytes.
ConstantInt * getNumBitmapBits() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This represents the llvm.instrprof.mcdc.parameters intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This represents the llvm.instrprof.mcdc.tvbitmap.update intrinsic.
ConstantInt * getBitmapIndex() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This represents the llvm.instrprof.timestamp intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
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:48
bool isAssumeLikeIntrinsic() const
Checks if the intrinsic is an annotation.
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:55
bool isCommutative() const
Return true if swapping the first two arguments to the intrinsic produces the same result.
Definition: IntrinsicInst.h:73
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:
bool isAssociative() const
Definition: IntrinsicInst.h:59
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:1069
LLVMContext & getContext() const
Definition: Metadata.h:1233
This class wraps the llvm.memcpy.inline intrinsic.
static bool classof(const IntrinsicInst *I)
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)
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:103
Root of the metadata hierarchy.
Definition: Metadata.h:62
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:1852
ConstantInt * getAttributes() const
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
ConstantInt * getFactor() const
ConstantInt * getFuncGuid() const
Lightweight class that wraps the location operand metadata of a debug intrinsic.
friend bool operator<=(const RawLocationWrapper &A, const RawLocationWrapper &B)
Metadata * getRawLocation() const
friend bool operator>(const RawLocationWrapper &A, const RawLocationWrapper &B)
RawLocationWrapper(Metadata *RawLocation)
friend bool operator<(const RawLocationWrapper &A, const RawLocationWrapper &B)
friend bool operator==(const RawLocationWrapper &A, const RawLocationWrapper &B)
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
Value * getVariableLocationOp(unsigned OpIdx) const
bool isKillLocation(const DIExpression *Expression) const
friend bool operator!=(const RawLocationWrapper &A, const RawLocationWrapper &B)
unsigned getNumVariableLocationOps() const
friend bool operator>=(const RawLocationWrapper &A, const RawLocationWrapper &B)
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:367
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:502
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 isVPBinOp(Intrinsic::ID ID)
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 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.
std::optional< unsigned > getFunctionalIntrinsicID() const
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)
static std::optional< Intrinsic::ID > getFunctionalIntrinsicIDForVP(Intrinsic::ID ID)
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
static Intrinsic::ID getForIntrinsic(Intrinsic::ID Id)
The llvm.vp.
Value * getMemoryPointerParam() const
std::optional< unsigned > getConstrainedIntrinsicID() const
MaybeAlign getPointerAlignment() const
Value * getMaskParam() const
ElementCount getStaticVectorLength() const
static std::optional< Intrinsic::ID > getConstrainedIntrinsicIDForVP(Intrinsic::ID ID)
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:450
Value * getValue() const
Definition: Metadata.h:490
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:694
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1075
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.
bool operator==(const location_op_iterator &RHS) const
location_op_iterator & operator=(const location_op_iterator &R)
location_op_iterator(ValueAsMetadata **MultiIter)
location_op_iterator(const location_op_iterator &R)
location_op_iterator & operator++()
location_op_iterator(ValueAsMetadata *SingleIter)
location_op_iterator & operator--()
const Value * operator*() const
#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:1729
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.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
static bool isConvergenceControlIntrinsic(unsigned IntrinsicID)
Check if ID corresponds to a convergence control 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