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
347 /// Determine if this describes the value of a local variable. It is true for
348 /// dbg.value, but false for dbg.declare, which describes its address, and
349 /// false for dbg.assign, which describes a combination of the variable's
350 /// value and address.
351 bool isValueOfVariable() const {
352 return getIntrinsicID() == Intrinsic::dbg_value;
353 }
354
356 // TODO: When/if we remove duplicate values from DIArgLists, we don't need
357 // this set anymore.
358 SmallPtrSet<Value *, 4> RemovedValues;
359 for (Value *OldValue : location_ops()) {
360 if (!RemovedValues.insert(OldValue).second)
361 continue;
362 Value *Poison = PoisonValue::get(OldValue->getType());
364 }
365 }
366
367 bool isKillLocation() const {
369 }
370
372 return cast<DILocalVariable>(getRawVariable());
373 }
374
376 return cast<DIExpression>(getRawExpression());
377 }
378
380 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
381 }
382
385 }
386
388 return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
389 }
390
392 return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
393 }
394
395 /// Use of this should generally be avoided; instead,
396 /// replaceVariableLocationOp and addVariableLocationOps should be used where
397 /// possible to avoid creating invalid state.
398 void setRawLocation(Metadata *Location) {
399 return setArgOperand(0, MetadataAsValue::get(getContext(), Location));
400 }
401
402 /// Get the size (in bits) of the variable, or fragment of the variable that
403 /// is described.
404 std::optional<uint64_t> getFragmentSizeInBits() const;
405
406 /// Get the FragmentInfo for the variable.
407 std::optional<DIExpression::FragmentInfo> getFragment() const {
408 return getExpression()->getFragmentInfo();
409 }
410
411 /// Get the FragmentInfo for the variable if it exists, otherwise return a
412 /// FragmentInfo that covers the entire variable if the variable size is
413 /// known, otherwise return a zero-sized fragment.
415 DIExpression::FragmentInfo VariableSlice(0, 0);
416 // Get the fragment or variable size, or zero.
417 if (auto Sz = getFragmentSizeInBits())
418 VariableSlice.SizeInBits = *Sz;
419 if (auto Frag = getExpression()->getFragmentInfo())
420 VariableSlice.OffsetInBits = Frag->OffsetInBits;
421 return VariableSlice;
422 }
423
424 /// \name Casting methods
425 /// @{
426 static bool classof(const IntrinsicInst *I) {
427 switch (I->getIntrinsicID()) {
428 case Intrinsic::dbg_declare:
429 case Intrinsic::dbg_value:
430 case Intrinsic::dbg_assign:
431 return true;
432 default:
433 return false;
434 }
435 }
436 static bool classof(const Value *V) {
437 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
438 }
439 /// @}
440protected:
441 void setArgOperand(unsigned i, Value *v) {
443 }
444 void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); }
445};
446
447/// This represents the llvm.dbg.declare instruction.
449public:
450 Value *getAddress() const {
452 "dbg.declare must have exactly 1 location operand.");
453 return getVariableLocationOp(0);
454 }
455
456 /// \name Casting methods
457 /// @{
458 static bool classof(const IntrinsicInst *I) {
459 return I->getIntrinsicID() == Intrinsic::dbg_declare;
460 }
461 static bool classof(const Value *V) {
462 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
463 }
464 /// @}
465};
466
467/// This represents the llvm.dbg.value instruction.
469public:
470 // The default argument should only be used in ISel, and the default option
471 // should be removed once ISel support for multiple location ops is complete.
472 Value *getValue(unsigned OpIdx = 0) const {
473 return getVariableLocationOp(OpIdx);
474 }
476 return location_ops();
477 }
478
479 /// \name Casting methods
480 /// @{
481 static bool classof(const IntrinsicInst *I) {
482 return I->getIntrinsicID() == Intrinsic::dbg_value ||
483 I->getIntrinsicID() == Intrinsic::dbg_assign;
484 }
485 static bool classof(const Value *V) {
486 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
487 }
488 /// @}
489};
490
491/// This represents the llvm.dbg.assign instruction.
493 enum Operands {
494 OpValue,
495 OpVar,
496 OpExpr,
497 OpAssignID,
498 OpAddress,
499 OpAddressExpr,
500 };
501
502public:
503 Value *getAddress() const;
505 return cast<MetadataAsValue>(getArgOperand(OpAddress))->getMetadata();
506 }
508 return cast<MetadataAsValue>(getArgOperand(OpAssignID))->getMetadata();
509 }
510 DIAssignID *getAssignID() const { return cast<DIAssignID>(getRawAssignID()); }
512 return cast<MetadataAsValue>(getArgOperand(OpAddressExpr))->getMetadata();
513 }
515 return cast<DIExpression>(getRawAddressExpression());
516 }
518 setArgOperand(OpAddressExpr,
519 MetadataAsValue::get(NewExpr->getContext(), NewExpr));
520 }
521 void setAssignId(DIAssignID *New);
522 void setAddress(Value *V);
523 /// Kill the address component.
524 void setKillAddress();
525 /// Check whether this kills the address component. This doesn't take into
526 /// account the position of the intrinsic, therefore a returned value of false
527 /// does not guarentee the address is a valid location for the variable at the
528 /// intrinsic's position in IR.
529 bool isKillAddress() const;
530 void setValue(Value *V);
531 /// \name Casting methods
532 /// @{
533 static bool classof(const IntrinsicInst *I) {
534 return I->getIntrinsicID() == Intrinsic::dbg_assign;
535 }
536 static bool classof(const Value *V) {
537 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
538 }
539 /// @}
540};
541
542/// This represents the llvm.dbg.label instruction.
544public:
545 DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); }
546 void setLabel(DILabel *NewLabel) {
548 }
549
551 return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
552 }
553
554 /// Methods for support type inquiry through isa, cast, and dyn_cast:
555 /// @{
556 static bool classof(const IntrinsicInst *I) {
557 return I->getIntrinsicID() == Intrinsic::dbg_label;
558 }
559 static bool classof(const Value *V) {
560 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
561 }
562 /// @}
563};
564
565/// This is the common base class for vector predication intrinsics.
567public:
568 /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
569 /// \p Params. Additionally, the load and gather intrinsics require
570 /// \p ReturnType to be specified.
572 Type *ReturnType,
573 ArrayRef<Value *> Params);
574
575 static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
576 static std::optional<unsigned> getVectorLengthParamPos(
577 Intrinsic::ID IntrinsicID);
578
579 /// The llvm.vp.* intrinsics for this instruction Opcode
580 static Intrinsic::ID getForOpcode(unsigned OC);
581
582 /// The llvm.vp.* intrinsics for this intrinsic ID \p Id. Return \p Id if it
583 /// is already a VP intrinsic.
585
586 // Whether \p ID is a VP intrinsic ID.
587 static bool isVPIntrinsic(Intrinsic::ID);
588
589 /// \return The mask parameter or nullptr.
590 Value *getMaskParam() const;
591 void setMaskParam(Value *);
592
593 /// \return The vector length parameter or nullptr.
596
597 /// \return Whether the vector length param can be ignored.
598 bool canIgnoreVectorLengthParam() const;
599
600 /// \return The static element count (vector number of elements) the vector
601 /// length parameter applies to.
603
604 /// \return The alignment of the pointer used by this load/store/gather or
605 /// scatter.
607 // MaybeAlign setPointerAlignment(Align NewAlign); // TODO
608
609 /// \return The pointer operand of this load,store, gather or scatter.
611 static std::optional<unsigned> getMemoryPointerParamPos(Intrinsic::ID);
612
613 /// \return The data (payload) operand of this store or scatter.
614 Value *getMemoryDataParam() const;
615 static std::optional<unsigned> getMemoryDataParamPos(Intrinsic::ID);
616
617 // Methods for support type inquiry through isa, cast, and dyn_cast:
618 static bool classof(const IntrinsicInst *I) {
619 return isVPIntrinsic(I->getIntrinsicID());
620 }
621 static bool classof(const Value *V) {
622 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
623 }
624
625 // Equivalent non-predicated opcode
626 std::optional<unsigned> getFunctionalOpcode() const {
628 }
629
630 // Equivalent non-predicated intrinsic ID
631 std::optional<unsigned> getFunctionalIntrinsicID() const {
633 }
634
635 // Equivalent non-predicated constrained ID
636 std::optional<unsigned> getConstrainedIntrinsicID() const {
638 }
639
640 // Equivalent non-predicated opcode
641 static std::optional<unsigned> getFunctionalOpcodeForVP(Intrinsic::ID ID);
642
643 // Equivalent non-predicated intrinsic ID
644 static std::optional<Intrinsic::ID>
646
647 // Equivalent non-predicated constrained ID
648 static std::optional<Intrinsic::ID>
650};
651
652/// This represents vector predication reduction intrinsics.
654public:
655 static bool isVPReduction(Intrinsic::ID ID);
656
657 unsigned getStartParamPos() const;
658 unsigned getVectorParamPos() const;
659
660 static std::optional<unsigned> getStartParamPos(Intrinsic::ID ID);
661 static std::optional<unsigned> getVectorParamPos(Intrinsic::ID ID);
662
663 /// Methods for support type inquiry through isa, cast, and dyn_cast:
664 /// @{
665 static bool classof(const IntrinsicInst *I) {
666 return VPReductionIntrinsic::isVPReduction(I->getIntrinsicID());
667 }
668 static bool classof(const Value *V) {
669 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
670 }
671 /// @}
672};
673
675public:
676 static bool isVPCast(Intrinsic::ID ID);
677
678 /// Methods for support type inquiry through isa, cast, and dyn_cast:
679 /// @{
680 static bool classof(const IntrinsicInst *I) {
681 return VPCastIntrinsic::isVPCast(I->getIntrinsicID());
682 }
683 static bool classof(const Value *V) {
684 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
685 }
686 /// @}
687};
688
690public:
691 static bool isVPCmp(Intrinsic::ID ID);
692
694
695 /// Methods for support type inquiry through isa, cast, and dyn_cast:
696 /// @{
697 static bool classof(const IntrinsicInst *I) {
698 return VPCmpIntrinsic::isVPCmp(I->getIntrinsicID());
699 }
700 static bool classof(const Value *V) {
701 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
702 }
703 /// @}
704};
705
707public:
708 static bool isVPBinOp(Intrinsic::ID ID);
709
710 /// Methods for support type inquiry through isa, cast, and dyn_cast:
711 /// @{
712 static bool classof(const IntrinsicInst *I) {
713 return VPBinOpIntrinsic::isVPBinOp(I->getIntrinsicID());
714 }
715 static bool classof(const Value *V) {
716 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
717 }
718 /// @}
719};
720
721
722/// This is the common base class for constrained floating point intrinsics.
724public:
725 unsigned getNonMetadataArgCount() const;
726 std::optional<RoundingMode> getRoundingMode() const;
727 std::optional<fp::ExceptionBehavior> getExceptionBehavior() const;
728 bool isDefaultFPEnvironment() const;
729
730 // Methods for support type inquiry through isa, cast, and dyn_cast:
731 static bool classof(const IntrinsicInst *I);
732 static bool classof(const Value *V) {
733 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
734 }
735};
736
737/// Constrained floating point compare intrinsics.
739public:
741 bool isSignaling() const {
742 return getIntrinsicID() == Intrinsic::experimental_constrained_fcmps;
743 }
744
745 // Methods for support type inquiry through isa, cast, and dyn_cast:
746 static bool classof(const IntrinsicInst *I) {
747 switch (I->getIntrinsicID()) {
748 case Intrinsic::experimental_constrained_fcmp:
749 case Intrinsic::experimental_constrained_fcmps:
750 return true;
751 default:
752 return false;
753 }
754 }
755 static bool classof(const Value *V) {
756 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
757 }
758};
759
760/// This class represents min/max intrinsics.
762public:
763 static bool classof(const IntrinsicInst *I) {
764 switch (I->getIntrinsicID()) {
765 case Intrinsic::umin:
766 case Intrinsic::umax:
767 case Intrinsic::smin:
768 case Intrinsic::smax:
769 return true;
770 default:
771 return false;
772 }
773 }
774 static bool classof(const Value *V) {
775 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
776 }
777
778 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
779 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
780
781 /// Returns the comparison predicate underlying the intrinsic.
783 switch (ID) {
784 case Intrinsic::umin:
786 case Intrinsic::umax:
788 case Intrinsic::smin:
790 case Intrinsic::smax:
792 default:
793 llvm_unreachable("Invalid intrinsic");
794 }
795 }
796
797 /// Returns the comparison predicate underlying the intrinsic.
800 }
801
802 /// Whether the intrinsic is signed or unsigned.
803 static bool isSigned(Intrinsic::ID ID) {
805 };
806
807 /// Whether the intrinsic is signed or unsigned.
808 bool isSigned() const { return isSigned(getIntrinsicID()); };
809
810 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
811 /// so there is a certain threshold value, upon reaching which,
812 /// their value can no longer change. Return said threshold.
813 static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits) {
814 switch (ID) {
815 case Intrinsic::umin:
816 return APInt::getMinValue(numBits);
817 case Intrinsic::umax:
818 return APInt::getMaxValue(numBits);
819 case Intrinsic::smin:
820 return APInt::getSignedMinValue(numBits);
821 case Intrinsic::smax:
822 return APInt::getSignedMaxValue(numBits);
823 default:
824 llvm_unreachable("Invalid intrinsic");
825 }
826 }
827
828 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
829 /// so there is a certain threshold value, upon reaching which,
830 /// their value can no longer change. Return said threshold.
831 APInt getSaturationPoint(unsigned numBits) const {
832 return getSaturationPoint(getIntrinsicID(), numBits);
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.
841 }
842
843 /// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
844 /// so there is a certain threshold value, upon reaching which,
845 /// their value can no longer change. Return said threshold.
848 }
849};
850
851/// This class represents a ucmp/scmp intrinsic
853public:
854 static bool classof(const IntrinsicInst *I) {
855 switch (I->getIntrinsicID()) {
856 case Intrinsic::scmp:
857 case Intrinsic::ucmp:
858 return true;
859 default:
860 return false;
861 }
862 }
863 static bool classof(const Value *V) {
864 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
865 }
866
867 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
868 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
869
870 static bool isSigned(Intrinsic::ID ID) { return ID == Intrinsic::scmp; }
871 bool isSigned() const { return isSigned(getIntrinsicID()); }
872
875 }
878 }
879
882 }
885 }
886};
887
888/// This class represents an intrinsic that is based on a binary operation.
889/// This includes op.with.overflow and saturating add/sub intrinsics.
891public:
892 static bool classof(const IntrinsicInst *I) {
893 switch (I->getIntrinsicID()) {
894 case Intrinsic::uadd_with_overflow:
895 case Intrinsic::sadd_with_overflow:
896 case Intrinsic::usub_with_overflow:
897 case Intrinsic::ssub_with_overflow:
898 case Intrinsic::umul_with_overflow:
899 case Intrinsic::smul_with_overflow:
900 case Intrinsic::uadd_sat:
901 case Intrinsic::sadd_sat:
902 case Intrinsic::usub_sat:
903 case Intrinsic::ssub_sat:
904 return true;
905 default:
906 return false;
907 }
908 }
909 static bool classof(const Value *V) {
910 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
911 }
912
913 Value *getLHS() const { return const_cast<Value *>(getArgOperand(0)); }
914 Value *getRHS() const { return const_cast<Value *>(getArgOperand(1)); }
915
916 /// Returns the binary operation underlying the intrinsic.
918
919 /// Whether the intrinsic is signed or unsigned.
920 bool isSigned() const;
921
922 /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
923 unsigned getNoWrapKind() const;
924};
925
926/// Represents an op.with.overflow intrinsic.
928public:
929 static bool classof(const IntrinsicInst *I) {
930 switch (I->getIntrinsicID()) {
931 case Intrinsic::uadd_with_overflow:
932 case Intrinsic::sadd_with_overflow:
933 case Intrinsic::usub_with_overflow:
934 case Intrinsic::ssub_with_overflow:
935 case Intrinsic::umul_with_overflow:
936 case Intrinsic::smul_with_overflow:
937 return true;
938 default:
939 return false;
940 }
941 }
942 static bool classof(const Value *V) {
943 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
944 }
945};
946
947/// Represents a saturating add/sub intrinsic.
949public:
950 static bool classof(const IntrinsicInst *I) {
951 switch (I->getIntrinsicID()) {
952 case Intrinsic::uadd_sat:
953 case Intrinsic::sadd_sat:
954 case Intrinsic::usub_sat:
955 case Intrinsic::ssub_sat:
956 return true;
957 default:
958 return false;
959 }
960 }
961 static bool classof(const Value *V) {
962 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
963 }
964};
965
966/// Common base class for all memory intrinsics. Simply provides
967/// common methods.
968/// Written as CRTP to avoid a common base class amongst the
969/// three atomicity hierarchies.
970template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
971private:
972 enum { ARG_DEST = 0, ARG_LENGTH = 2 };
973
974public:
975 Value *getRawDest() const {
976 return const_cast<Value *>(getArgOperand(ARG_DEST));
977 }
978 const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
979 Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
980
981 Value *getLength() const {
982 return const_cast<Value *>(getArgOperand(ARG_LENGTH));
983 }
984 const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
985 Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
986
987 /// This is just like getRawDest, but it strips off any cast
988 /// instructions (including addrspacecast) that feed it, giving the
989 /// original input. The returned value is guaranteed to be a pointer.
990 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
991
992 unsigned getDestAddressSpace() const {
993 return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
994 }
995
996 /// FIXME: Remove this function once transition to Align is over.
997 /// Use getDestAlign() instead.
998 LLVM_DEPRECATED("Use getDestAlign() instead", "getDestAlign")
1000 if (auto MA = getParamAlign(ARG_DEST))
1001 return MA->value();
1002 return 0;
1003 }
1004 MaybeAlign getDestAlign() const { return getParamAlign(ARG_DEST); }
1005
1006 /// Set the specified arguments of the instruction.
1008 assert(getRawDest()->getType() == Ptr->getType() &&
1009 "setDest called with pointer of wrong type!");
1010 setArgOperand(ARG_DEST, Ptr);
1011 }
1012
1014 removeParamAttr(ARG_DEST, Attribute::Alignment);
1015 if (Alignment)
1016 addParamAttr(ARG_DEST,
1018 }
1019 void setDestAlignment(Align Alignment) {
1020 removeParamAttr(ARG_DEST, Attribute::Alignment);
1021 addParamAttr(ARG_DEST,
1023 }
1024
1025 void setLength(Value *L) {
1026 assert(getLength()->getType() == L->getType() &&
1027 "setLength called with value of wrong type!");
1028 setArgOperand(ARG_LENGTH, L);
1029 }
1030};
1031
1032/// Common base class for all memory transfer intrinsics. Simply provides
1033/// common methods.
1034template <class BaseCL> class MemTransferBase : public BaseCL {
1035private:
1036 enum { ARG_SOURCE = 1 };
1037
1038public:
1039 /// Return the arguments to the instruction.
1041 return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
1042 }
1043 const Use &getRawSourceUse() const {
1044 return BaseCL::getArgOperandUse(ARG_SOURCE);
1045 }
1046 Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
1047
1048 /// This is just like getRawSource, but it strips off any cast
1049 /// instructions that feed it, giving the original input. The returned
1050 /// value is guaranteed to be a pointer.
1052
1053 unsigned getSourceAddressSpace() const {
1054 return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
1055 }
1056
1057 /// FIXME: Remove this function once transition to Align is over.
1058 /// Use getSourceAlign() instead.
1059 LLVM_DEPRECATED("Use getSourceAlign() instead", "getSourceAlign")
1061 if (auto MA = BaseCL::getParamAlign(ARG_SOURCE))
1062 return MA->value();
1063 return 0;
1064 }
1065
1067 return BaseCL::getParamAlign(ARG_SOURCE);
1068 }
1069
1071 assert(getRawSource()->getType() == Ptr->getType() &&
1072 "setSource called with pointer of wrong type!");
1073 BaseCL::setArgOperand(ARG_SOURCE, Ptr);
1074 }
1075
1077 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
1078 if (Alignment)
1079 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
1080 BaseCL::getContext(), *Alignment));
1081 }
1082
1083 void setSourceAlignment(Align Alignment) {
1084 BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
1085 BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
1086 BaseCL::getContext(), Alignment));
1087 }
1088};
1089
1090/// Common base class for all memset intrinsics. Simply provides
1091/// common methods.
1092template <class BaseCL> class MemSetBase : public BaseCL {
1093private:
1094 enum { ARG_VALUE = 1 };
1095
1096public:
1097 Value *getValue() const {
1098 return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
1099 }
1100 const Use &getValueUse() const { return BaseCL::getArgOperandUse(ARG_VALUE); }
1101 Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
1102
1103 void setValue(Value *Val) {
1104 assert(getValue()->getType() == Val->getType() &&
1105 "setValue called with value of wrong type!");
1106 BaseCL::setArgOperand(ARG_VALUE, Val);
1107 }
1108};
1109
1110// The common base class for the atomic memset/memmove/memcpy intrinsics
1111// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
1112class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
1113private:
1114 enum { ARG_ELEMENTSIZE = 3 };
1115
1116public:
1118 return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
1119 }
1120
1122 return cast<ConstantInt>(getRawElementSizeInBytes());
1123 }
1124
1127 }
1128
1130 assert(V->getType() == Type::getInt8Ty(getContext()) &&
1131 "setElementSizeInBytes called with value of wrong type!");
1132 setArgOperand(ARG_ELEMENTSIZE, V);
1133 }
1134
1135 static bool classof(const IntrinsicInst *I) {
1136 switch (I->getIntrinsicID()) {
1137 case Intrinsic::memcpy_element_unordered_atomic:
1138 case Intrinsic::memmove_element_unordered_atomic:
1139 case Intrinsic::memset_element_unordered_atomic:
1140 return true;
1141 default:
1142 return false;
1143 }
1144 }
1145 static bool classof(const Value *V) {
1146 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1147 }
1148};
1149
1150/// This class represents atomic memset intrinsic
1151// i.e. llvm.element.unordered.atomic.memset
1152class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
1153public:
1154 static bool classof(const IntrinsicInst *I) {
1155 return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
1156 }
1157 static bool classof(const Value *V) {
1158 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1159 }
1160};
1161
1162// This class wraps the atomic memcpy/memmove intrinsics
1163// i.e. llvm.element.unordered.atomic.memcpy/memmove
1164class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
1165public:
1166 static bool classof(const IntrinsicInst *I) {
1167 switch (I->getIntrinsicID()) {
1168 case Intrinsic::memcpy_element_unordered_atomic:
1169 case Intrinsic::memmove_element_unordered_atomic:
1170 return true;
1171 default:
1172 return false;
1173 }
1174 }
1175 static bool classof(const Value *V) {
1176 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1177 }
1178};
1179
1180/// This class represents the atomic memcpy intrinsic
1181/// i.e. llvm.element.unordered.atomic.memcpy
1183public:
1184 static bool classof(const IntrinsicInst *I) {
1185 return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
1186 }
1187 static bool classof(const Value *V) {
1188 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1189 }
1190};
1191
1192/// This class represents the atomic memmove intrinsic
1193/// i.e. llvm.element.unordered.atomic.memmove
1195public:
1196 static bool classof(const IntrinsicInst *I) {
1197 return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
1198 }
1199 static bool classof(const Value *V) {
1200 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1201 }
1202};
1203
1204/// This is the common base class for memset/memcpy/memmove.
1205class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1206private:
1207 enum { ARG_VOLATILE = 3 };
1208
1209public:
1211 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1212 }
1213
1214 bool isVolatile() const { return !getVolatileCst()->isZero(); }
1215
1216 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
1217
1218 // Methods for support type inquiry through isa, cast, and dyn_cast:
1219 static bool classof(const IntrinsicInst *I) {
1220 switch (I->getIntrinsicID()) {
1221 case Intrinsic::memcpy:
1222 case Intrinsic::memmove:
1223 case Intrinsic::memset:
1224 case Intrinsic::memset_inline:
1225 case Intrinsic::memcpy_inline:
1226 return true;
1227 default:
1228 return false;
1229 }
1230 }
1231 static bool classof(const Value *V) {
1232 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1233 }
1234};
1235
1236/// This class wraps the llvm.memset and llvm.memset.inline intrinsics.
1237class MemSetInst : public MemSetBase<MemIntrinsic> {
1238public:
1239 // Methods for support type inquiry through isa, cast, and dyn_cast:
1240 static bool classof(const IntrinsicInst *I) {
1241 switch (I->getIntrinsicID()) {
1242 case Intrinsic::memset:
1243 case Intrinsic::memset_inline:
1244 return true;
1245 default:
1246 return false;
1247 }
1248 }
1249 static bool classof(const Value *V) {
1250 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1251 }
1252};
1253
1254/// This class wraps the llvm.memset.inline intrinsic.
1256public:
1257 // Methods for support type inquiry through isa, cast, and dyn_cast:
1258 static bool classof(const IntrinsicInst *I) {
1259 return I->getIntrinsicID() == Intrinsic::memset_inline;
1260 }
1261 static bool classof(const Value *V) {
1262 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1263 }
1264};
1265
1266/// This is the base class for llvm.experimental.memset.pattern
1267class MemSetPatternIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1268private:
1269 enum { ARG_VOLATILE = 3 };
1270
1271public:
1273 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
1274 }
1275
1276 bool isVolatile() const { return !getVolatileCst()->isZero(); }
1277
1278 void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
1279
1280 // Methods for support of type inquiry through isa, cast, and dyn_cast:
1281 static bool classof(const IntrinsicInst *I) {
1282 return I->getIntrinsicID() == Intrinsic::experimental_memset_pattern;
1283 }
1284 static bool classof(const Value *V) {
1285 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1286 }
1287};
1288
1289/// This class wraps the llvm.experimental.memset.pattern intrinsic.
1290class MemSetPatternInst : public MemSetBase<MemSetPatternIntrinsic> {
1291public:
1292 // Methods for support type inquiry through isa, cast, and dyn_cast:
1293 static bool classof(const IntrinsicInst *I) {
1294 return I->getIntrinsicID() == Intrinsic::experimental_memset_pattern;
1295 }
1296 static bool classof(const Value *V) {
1297 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1298 }
1299};
1300
1301/// This class wraps the llvm.memcpy/memmove intrinsics.
1302class MemTransferInst : public MemTransferBase<MemIntrinsic> {
1303public:
1304 // Methods for support type inquiry through isa, cast, and dyn_cast:
1305 static bool classof(const IntrinsicInst *I) {
1306 switch (I->getIntrinsicID()) {
1307 case Intrinsic::memcpy:
1308 case Intrinsic::memmove:
1309 case Intrinsic::memcpy_inline:
1310 return true;
1311 default:
1312 return false;
1313 }
1314 }
1315 static bool classof(const Value *V) {
1316 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1317 }
1318};
1319
1320/// This class wraps the llvm.memcpy intrinsic.
1322public:
1323 // Methods for support type inquiry through isa, cast, and dyn_cast:
1324 static bool classof(const IntrinsicInst *I) {
1325 return I->getIntrinsicID() == Intrinsic::memcpy ||
1326 I->getIntrinsicID() == Intrinsic::memcpy_inline;
1327 }
1328 static bool classof(const Value *V) {
1329 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1330 }
1331};
1332
1333/// This class wraps the llvm.memmove intrinsic.
1335public:
1336 // Methods for support type inquiry through isa, cast, and dyn_cast:
1337 static bool classof(const IntrinsicInst *I) {
1338 return I->getIntrinsicID() == Intrinsic::memmove;
1339 }
1340 static bool classof(const Value *V) {
1341 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1342 }
1343};
1344
1345/// This class wraps the llvm.memcpy.inline intrinsic.
1347public:
1348 // Methods for support type inquiry through isa, cast, and dyn_cast:
1349 static bool classof(const IntrinsicInst *I) {
1350 return I->getIntrinsicID() == Intrinsic::memcpy_inline;
1351 }
1352 static bool classof(const Value *V) {
1353 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1354 }
1355};
1356
1357// The common base class for any memset/memmove/memcpy intrinsics;
1358// whether they be atomic or non-atomic.
1359// i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
1360// and llvm.memset/memcpy/memmove
1361class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
1362public:
1363 bool isVolatile() const {
1364 // Only the non-atomic intrinsics can be volatile
1365 if (auto *MI = dyn_cast<MemIntrinsic>(this))
1366 return MI->isVolatile();
1367 return false;
1368 }
1369
1370 static bool classof(const IntrinsicInst *I) {
1371 switch (I->getIntrinsicID()) {
1372 case Intrinsic::memcpy:
1373 case Intrinsic::memcpy_inline:
1374 case Intrinsic::memmove:
1375 case Intrinsic::memset:
1376 case Intrinsic::memset_inline:
1377 case Intrinsic::memcpy_element_unordered_atomic:
1378 case Intrinsic::memmove_element_unordered_atomic:
1379 case Intrinsic::memset_element_unordered_atomic:
1380 return true;
1381 default:
1382 return false;
1383 }
1384 }
1385 static bool classof(const Value *V) {
1386 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1387 }
1388};
1389
1390/// This class represents any memset intrinsic
1391// i.e. llvm.element.unordered.atomic.memset
1392// and llvm.memset
1393class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
1394public:
1395 static bool classof(const IntrinsicInst *I) {
1396 switch (I->getIntrinsicID()) {
1397 case Intrinsic::memset:
1398 case Intrinsic::memset_inline:
1399 case Intrinsic::memset_element_unordered_atomic:
1400 return true;
1401 default:
1402 return false;
1403 }
1404 }
1405 static bool classof(const Value *V) {
1406 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1407 }
1408};
1409
1410// This class wraps any memcpy/memmove intrinsics
1411// i.e. llvm.element.unordered.atomic.memcpy/memmove
1412// and llvm.memcpy/memmove
1413class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
1414public:
1415 static bool classof(const IntrinsicInst *I) {
1416 switch (I->getIntrinsicID()) {
1417 case Intrinsic::memcpy:
1418 case Intrinsic::memcpy_inline:
1419 case Intrinsic::memmove:
1420 case Intrinsic::memcpy_element_unordered_atomic:
1421 case Intrinsic::memmove_element_unordered_atomic:
1422 return true;
1423 default:
1424 return false;
1425 }
1426 }
1427 static bool classof(const Value *V) {
1428 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1429 }
1430};
1431
1432/// This class represents any memcpy intrinsic
1433/// i.e. llvm.element.unordered.atomic.memcpy
1434/// and llvm.memcpy
1436public:
1437 static bool classof(const IntrinsicInst *I) {
1438 switch (I->getIntrinsicID()) {
1439 case Intrinsic::memcpy:
1440 case Intrinsic::memcpy_inline:
1441 case Intrinsic::memcpy_element_unordered_atomic:
1442 return true;
1443 default:
1444 return false;
1445 }
1446 }
1447 static bool classof(const Value *V) {
1448 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1449 }
1450};
1451
1452/// This class represents any memmove intrinsic
1453/// i.e. llvm.element.unordered.atomic.memmove
1454/// and llvm.memmove
1456public:
1457 static bool classof(const IntrinsicInst *I) {
1458 switch (I->getIntrinsicID()) {
1459 case Intrinsic::memmove:
1460 case Intrinsic::memmove_element_unordered_atomic:
1461 return true;
1462 default:
1463 return false;
1464 }
1465 }
1466 static bool classof(const Value *V) {
1467 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1468 }
1469};
1470
1471/// This represents the llvm.va_start intrinsic.
1473public:
1474 static bool classof(const IntrinsicInst *I) {
1475 return I->getIntrinsicID() == Intrinsic::vastart;
1476 }
1477 static bool classof(const Value *V) {
1478 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1479 }
1480
1481 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1482};
1483
1484/// This represents the llvm.va_end intrinsic.
1485class VAEndInst : public IntrinsicInst {
1486public:
1487 static bool classof(const IntrinsicInst *I) {
1488 return I->getIntrinsicID() == Intrinsic::vaend;
1489 }
1490 static bool classof(const Value *V) {
1491 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1492 }
1493
1494 Value *getArgList() const { return const_cast<Value *>(getArgOperand(0)); }
1495};
1496
1497/// This represents the llvm.va_copy intrinsic.
1499public:
1500 static bool classof(const IntrinsicInst *I) {
1501 return I->getIntrinsicID() == Intrinsic::vacopy;
1502 }
1503 static bool classof(const Value *V) {
1504 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1505 }
1506
1507 Value *getDest() const { return const_cast<Value *>(getArgOperand(0)); }
1508 Value *getSrc() const { return const_cast<Value *>(getArgOperand(1)); }
1509};
1510
1511/// A base class for all instrprof intrinsics.
1513protected:
1514 static bool isCounterBase(const IntrinsicInst &I) {
1515 switch (I.getIntrinsicID()) {
1516 case Intrinsic::instrprof_cover:
1517 case Intrinsic::instrprof_increment:
1518 case Intrinsic::instrprof_increment_step:
1519 case Intrinsic::instrprof_callsite:
1520 case Intrinsic::instrprof_timestamp:
1521 case Intrinsic::instrprof_value_profile:
1522 return true;
1523 }
1524 return false;
1525 }
1526 static bool isMCDCBitmapBase(const IntrinsicInst &I) {
1527 switch (I.getIntrinsicID()) {
1528 case Intrinsic::instrprof_mcdc_parameters:
1529 case Intrinsic::instrprof_mcdc_tvbitmap_update:
1530 return true;
1531 }
1532 return false;
1533 }
1534
1535public:
1536 static bool classof(const Value *V) {
1537 if (const auto *Instr = dyn_cast<IntrinsicInst>(V))
1538 return isCounterBase(*Instr) || isMCDCBitmapBase(*Instr);
1539 return false;
1540 }
1541
1542 // The name of the instrumented function, assuming it is a global variable.
1544 return cast<GlobalVariable>(getNameValue());
1545 }
1546
1547 // The "name" operand of the profile instrumentation instruction - this is the
1548 // operand that can be used to relate the instruction to the function it
1549 // belonged to at instrumentation time.
1551 return const_cast<Value *>(getArgOperand(0))->stripPointerCasts();
1552 }
1553
1555
1556 // The hash of the CFG for the instrumented function.
1558 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1559 }
1560};
1561
1562/// A base class for all instrprof counter intrinsics.
1564public:
1565 static bool classof(const Value *V) {
1566 if (const auto *Instr = dyn_cast<IntrinsicInst>(V))
1567 return InstrProfInstBase::isCounterBase(*Instr);
1568 return false;
1569 }
1570
1571 // The number of counters for the instrumented function.
1572 ConstantInt *getNumCounters() const;
1573 // The index of the counter that this instruction acts on.
1574 ConstantInt *getIndex() const;
1575 void setIndex(uint32_t Idx);
1576};
1577
1578/// This represents the llvm.instrprof.cover intrinsic.
1580public:
1581 static bool classof(const IntrinsicInst *I) {
1582 return I->getIntrinsicID() == Intrinsic::instrprof_cover;
1583 }
1584 static bool classof(const Value *V) {
1585 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1586 }
1587};
1588
1589/// This represents the llvm.instrprof.increment intrinsic.
1591public:
1592 static bool classof(const IntrinsicInst *I) {
1593 return I->getIntrinsicID() == Intrinsic::instrprof_increment ||
1594 I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1595 }
1596 static bool classof(const Value *V) {
1597 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1598 }
1599 Value *getStep() const;
1600};
1601
1602/// This represents the llvm.instrprof.increment.step intrinsic.
1604public:
1605 static bool classof(const IntrinsicInst *I) {
1606 return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
1607 }
1608 static bool classof(const Value *V) {
1609 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1610 }
1611};
1612
1613/// This represents the llvm.instrprof.callsite intrinsic.
1614/// It is structurally like the increment or step counters, hence the
1615/// inheritance relationship, albeit somewhat tenuous (it's not 'counting' per
1616/// se)
1618public:
1619 static bool classof(const IntrinsicInst *I) {
1620 return I->getIntrinsicID() == Intrinsic::instrprof_callsite;
1621 }
1622 static bool classof(const Value *V) {
1623 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1624 }
1625 // We instrument direct calls (but not to intrinsics), or indirect calls.
1626 static bool canInstrumentCallsite(const CallBase &CB) {
1627 return !CB.isInlineAsm() &&
1628 (CB.isIndirectCall() ||
1630 }
1631 Value *getCallee() const;
1632 void setCallee(Value *Callee);
1633};
1634
1635/// This represents the llvm.instrprof.timestamp intrinsic.
1637public:
1638 static bool classof(const IntrinsicInst *I) {
1639 return I->getIntrinsicID() == Intrinsic::instrprof_timestamp;
1640 }
1641 static bool classof(const Value *V) {
1642 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1643 }
1644};
1645
1646/// This represents the llvm.instrprof.value.profile intrinsic.
1648public:
1649 static bool classof(const IntrinsicInst *I) {
1650 return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
1651 }
1652 static bool classof(const Value *V) {
1653 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1654 }
1655
1657 return cast<Value>(const_cast<Value *>(getArgOperand(2)));
1658 }
1659
1661 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1662 }
1663
1664 // Returns the value site index.
1666 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
1667 }
1668};
1669
1670/// A base class for instrprof mcdc intrinsics that require global bitmap bytes.
1672public:
1673 static bool classof(const IntrinsicInst *I) {
1675 }
1676 static bool classof(const Value *V) {
1677 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1678 }
1679
1680 /// \return The number of bits used for the MCDC bitmaps for the instrumented
1681 /// function.
1683 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1684 }
1685
1686 /// \return The number of bytes used for the MCDC bitmaps for the instrumented
1687 /// function.
1688 auto getNumBitmapBytes() const {
1689 return alignTo(getNumBitmapBits()->getZExtValue(), CHAR_BIT) / CHAR_BIT;
1690 }
1691};
1692
1693/// This represents the llvm.instrprof.mcdc.parameters intrinsic.
1695public:
1696 static bool classof(const IntrinsicInst *I) {
1697 return I->getIntrinsicID() == Intrinsic::instrprof_mcdc_parameters;
1698 }
1699 static bool classof(const Value *V) {
1700 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1701 }
1702};
1703
1704/// This represents the llvm.instrprof.mcdc.tvbitmap.update intrinsic.
1706public:
1707 static bool classof(const IntrinsicInst *I) {
1708 return I->getIntrinsicID() == Intrinsic::instrprof_mcdc_tvbitmap_update;
1709 }
1710 static bool classof(const Value *V) {
1711 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1712 }
1713
1714 /// \return The index of the TestVector Bitmap upon which this intrinsic
1715 /// acts.
1717 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1718 }
1719
1720 /// \return The address of the corresponding condition bitmap containing
1721 /// the index of the TestVector to update within the TestVector Bitmap.
1723 return cast<Value>(const_cast<Value *>(getArgOperand(3)));
1724 }
1725};
1726
1728public:
1729 static bool classof(const IntrinsicInst *I) {
1730 return I->getIntrinsicID() == Intrinsic::pseudoprobe;
1731 }
1732
1733 static bool classof(const Value *V) {
1734 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1735 }
1736
1738 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
1739 }
1740
1742 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1743 }
1744
1746 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1747 }
1748
1750 return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1751 }
1752};
1753
1755public:
1756 static bool classof(const IntrinsicInst *I) {
1757 return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
1758 }
1759
1760 static bool classof(const Value *V) {
1761 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1762 }
1763
1765 auto *MV =
1766 cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
1767 return cast<MDNode>(MV->getMetadata());
1768 }
1769
1770 void setScopeList(MDNode *ScopeList) {
1772 MetadataAsValue::get(getContext(), ScopeList));
1773 }
1774};
1775
1776/// Common base class for representing values projected from a statepoint.
1777/// Currently, the only projections available are gc.result and gc.relocate.
1779public:
1780 static bool classof(const IntrinsicInst *I) {
1781 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate ||
1782 I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1783 }
1784
1785 static bool classof(const Value *V) {
1786 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1787 }
1788
1789 /// Return true if this relocate is tied to the invoke statepoint.
1790 /// This includes relocates which are on the unwinding path.
1791 bool isTiedToInvoke() const {
1792 const Value *Token = getArgOperand(0);
1793
1794 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
1795 }
1796
1797 /// The statepoint with which this gc.relocate is associated.
1798 const Value *getStatepoint() const;
1799};
1800
1801/// Represents calls to the gc.relocate intrinsic.
1803public:
1804 static bool classof(const IntrinsicInst *I) {
1805 return I->getIntrinsicID() == Intrinsic::experimental_gc_relocate;
1806 }
1807
1808 static bool classof(const Value *V) {
1809 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1810 }
1811
1812 /// The index into the associate statepoint's argument list
1813 /// which contains the base pointer of the pointer whose
1814 /// relocation this gc.relocate describes.
1815 unsigned getBasePtrIndex() const {
1816 return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
1817 }
1818
1819 /// The index into the associate statepoint's argument list which
1820 /// contains the pointer whose relocation this gc.relocate describes.
1821 unsigned getDerivedPtrIndex() const {
1822 return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
1823 }
1824
1825 Value *getBasePtr() const;
1826 Value *getDerivedPtr() const;
1827};
1828
1829/// Represents calls to the gc.result intrinsic.
1831public:
1832 static bool classof(const IntrinsicInst *I) {
1833 return I->getIntrinsicID() == Intrinsic::experimental_gc_result;
1834 }
1835
1836 static bool classof(const Value *V) {
1837 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1838 }
1839};
1840
1841
1842/// This represents the llvm.assume intrinsic.
1844public:
1845 static bool classof(const IntrinsicInst *I) {
1846 return I->getIntrinsicID() == Intrinsic::assume;
1847 }
1848 static bool classof(const Value *V) {
1849 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1850 }
1851};
1852
1853/// Check if \p ID corresponds to a convergence control intrinsic.
1854static inline bool isConvergenceControlIntrinsic(unsigned IntrinsicID) {
1855 switch (IntrinsicID) {
1856 default:
1857 return false;
1858 case Intrinsic::experimental_convergence_anchor:
1859 case Intrinsic::experimental_convergence_entry:
1860 case Intrinsic::experimental_convergence_loop:
1861 return true;
1862 }
1863}
1864
1865/// Represents calls to the llvm.experimintal.convergence.* intrinsics.
1867public:
1868 static bool classof(const IntrinsicInst *I) {
1869 return isConvergenceControlIntrinsic(I->getIntrinsicID());
1870 }
1871
1872 static bool classof(const Value *V) {
1873 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
1874 }
1875
1876 bool isAnchor() {
1877 return getIntrinsicID() == Intrinsic::experimental_convergence_anchor;
1878 }
1879 bool isEntry() {
1880 return getIntrinsicID() == Intrinsic::experimental_convergence_entry;
1881 }
1882 bool isLoop() {
1883 return getIntrinsicID() == Intrinsic::experimental_convergence_loop;
1884 }
1885};
1886
1887} // end namespace llvm
1888
1889#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:236
This file contains the declarations for the subclasses of Constant, which represent the different fla...
dxil translate DXIL Translate Metadata
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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:39
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:206
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:209
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
Definition: APInt.h:216
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Definition: APInt.h:219
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:234
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
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
bool isInlineAsm() const
Check if this call is an inline asm statement.
Definition: InstrTypes.h:1416
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1549
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1349
bool isIndirectCall() const
Return true if the callsite is an indirect call.
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:1746
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1305
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1294
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1299
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1502
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:673
@ ICMP_SLT
signed less than
Definition: InstrTypes.h:702
@ ICMP_UGT
unsigned greater than
Definition: InstrTypes.h:696
@ ICMP_SGT
signed greater than
Definition: InstrTypes.h:700
@ ICMP_ULT
unsigned less than
Definition: InstrTypes.h:698
bool isSigned() const
Definition: InstrTypes.h:928
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:83
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:208
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:157
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:403
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,...
bool isValueOfVariable() const
Determine if this describes the value of a local variable.
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:251
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:256
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.
void setCallee(Value *Callee)
Value * getCallee() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool canInstrumentCallsite(const CallBase &CB)
A base class for all instrprof counter intrinsics.
static bool classof(const Value *V)
ConstantInt * getIndex() const
void setIndex(uint32_t Idx)
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)
void setNameValue(Value *V)
GlobalVariable * getName() const
ConstantInt * getHash() const
Value * getNameValue() 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)
This class wraps the llvm.experimental.memset.pattern intrinsic.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
This is the base class for llvm.experimental.memset.pattern.
void setVolatile(Constant *V)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
ConstantInt * getVolatileCst() const
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:1878
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:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
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:233
Value * getOperand(unsigned i) const
Definition: User.h:228
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 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 Function * getOrInsertDeclarationForParams(Module *M, Intrinsic::ID, Type *ReturnType, ArrayRef< Value * > Params)
Declares a llvm.vp.
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:1746
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