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