xref: /llvm-project/llvm/include/llvm/IR/IntrinsicInst.h (revision 77e6f434ec79db025aa9c7d193179727f1d63714)
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"
27 #include "llvm/IR/DebugInfoMetadata.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/FPEnv.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/GlobalVariable.h"
32 #include "llvm/IR/Instructions.h"
33 #include "llvm/IR/Intrinsics.h"
34 #include "llvm/IR/Value.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/MathExtras.h"
37 #include <cassert>
38 #include <cstdint>
39 #include <optional>
40 
41 namespace llvm {
42 
43 class 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.
48 class IntrinsicInst : public CallInst {
49 public:
50   IntrinsicInst() = delete;
51   IntrinsicInst(const IntrinsicInst &) = delete;
52   IntrinsicInst &operator=(const IntrinsicInst &) = delete;
53 
54   /// Return the intrinsic ID of this intrinsic.
55   Intrinsic::ID getIntrinsicID() const {
56     return getCalledFunction()->getIntrinsicID();
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.
104   bool isAssumeLikeIntrinsic() const {
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.
143 static inline bool isLifetimeIntrinsic(Intrinsic::ID ID) {
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.
154 class LifetimeIntrinsic : public IntrinsicInst {
155 public:
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.
168 static inline bool isDbgInfoIntrinsic(Intrinsic::ID ID) {
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.
181 class DbgInfoIntrinsic : public IntrinsicInst {
182 public:
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 .
197 class location_op_iterator
198     : public iterator_facade_base<location_op_iterator,
199                                   std::bidirectional_iterator_tag, Value *> {
200   PointerUnion<ValueAsMetadata *, ValueAsMetadata **> I;
201 
202 public:
203   location_op_iterator(ValueAsMetadata *SingleIter) : I(SingleIter) {}
204   location_op_iterator(ValueAsMetadata **MultiIter) : I(MultiIter) {}
205 
206   location_op_iterator(const location_op_iterator &R) : I(R.I) {}
207   location_op_iterator &operator=(const location_op_iterator &R) {
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   };
218   Value *operator*() {
219     ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
220                                ? cast<ValueAsMetadata *>(I)
221                                : *cast<ValueAsMetadata **>(I);
222     return VAM->getValue();
223   }
224   location_op_iterator &operator++() {
225     if (isa<ValueAsMetadata *>(I))
226       I = cast<ValueAsMetadata *>(I) + 1;
227     else
228       I = cast<ValueAsMetadata **>(I) + 1;
229     return *this;
230   }
231   location_op_iterator &operator--() {
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.
243 class RawLocationWrapper {
244   Metadata *RawLocation = nullptr;
245 
246 public:
247   RawLocationWrapper() = default;
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.
260   iterator_range<location_op_iterator> location_ops() const;
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()); }
268   bool isKillLocation(const DIExpression *Expression) const {
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.
308 class DbgVariableIntrinsic : public DbgInfoIntrinsic {
309 public:
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.
313   iterator_range<location_op_iterator> location_ops() const;
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.
323   void addVariableLocationOps(ArrayRef<Value *> NewValues,
324                               DIExpression *NewExpr);
325 
326   void setVariable(DILocalVariable *NewVar) {
327     setArgOperand(1, MetadataAsValue::get(NewVar->getContext(), NewVar));
328   }
329 
330   void setExpression(DIExpression *NewExpr) {
331     setArgOperand(2, MetadataAsValue::get(NewExpr->getContext(), NewExpr));
332   }
333 
334   unsigned getNumVariableLocationOps() const {
335     return getWrappedLocation().getNumVariableLocationOps();
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 
355   void setKillLocation() {
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());
363       replaceVariableLocationOp(OldValue, Poison);
364     }
365   }
366 
367   bool isKillLocation() const {
368     return getWrappedLocation().isKillLocation(getExpression());
369   }
370 
371   DILocalVariable *getVariable() const {
372     return cast<DILocalVariable>(getRawVariable());
373   }
374 
375   DIExpression *getExpression() const {
376     return cast<DIExpression>(getRawExpression());
377   }
378 
379   Metadata *getRawLocation() const {
380     return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
381   }
382 
383   RawLocationWrapper getWrappedLocation() const {
384     return RawLocationWrapper(getRawLocation());
385   }
386 
387   Metadata *getRawVariable() const {
388     return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
389   }
390 
391   Metadata *getRawExpression() const {
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.
414   DIExpression::FragmentInfo getFragmentOrEntireVariable() const {
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   /// @}
440 protected:
441   void setArgOperand(unsigned i, Value *v) {
442     DbgInfoIntrinsic::setArgOperand(i, v);
443   }
444   void setOperand(unsigned i, Value *v) { DbgInfoIntrinsic::setOperand(i, v); }
445 };
446 
447 /// This represents the llvm.dbg.declare instruction.
448 class DbgDeclareInst : public DbgVariableIntrinsic {
449 public:
450   Value *getAddress() const {
451     assert(getNumVariableLocationOps() == 1 &&
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.
468 class DbgValueInst : public DbgVariableIntrinsic {
469 public:
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   }
475   iterator_range<location_op_iterator> getValues() const {
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.
492 class DbgAssignIntrinsic : public DbgValueInst {
493   enum Operands {
494     OpValue,
495     OpVar,
496     OpExpr,
497     OpAssignID,
498     OpAddress,
499     OpAddressExpr,
500   };
501 
502 public:
503   Value *getAddress() const;
504   Metadata *getRawAddress() const {
505     return cast<MetadataAsValue>(getArgOperand(OpAddress))->getMetadata();
506   }
507   Metadata *getRawAssignID() const {
508     return cast<MetadataAsValue>(getArgOperand(OpAssignID))->getMetadata();
509   }
510   DIAssignID *getAssignID() const { return cast<DIAssignID>(getRawAssignID()); }
511   Metadata *getRawAddressExpression() const {
512     return cast<MetadataAsValue>(getArgOperand(OpAddressExpr))->getMetadata();
513   }
514   DIExpression *getAddressExpression() const {
515     return cast<DIExpression>(getRawAddressExpression());
516   }
517   void setAddressExpression(DIExpression *NewExpr) {
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.
543 class DbgLabelInst : public DbgInfoIntrinsic {
544 public:
545   DILabel *getLabel() const { return cast<DILabel>(getRawLabel()); }
546   void setLabel(DILabel *NewLabel) {
547     setArgOperand(0, MetadataAsValue::get(getContext(), NewLabel));
548   }
549 
550   Metadata *getRawLabel() const {
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.
566 class VPIntrinsic : public IntrinsicInst {
567 public:
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.
571   static Function *getOrInsertDeclarationForParams(Module *M, Intrinsic::ID,
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.
584   static Intrinsic::ID getForIntrinsic(Intrinsic::ID Id);
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.
594   Value *getVectorLengthParam() const;
595   void setVectorLengthParam(Value *);
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.
602   ElementCount getStaticVectorLength() const;
603 
604   /// \return The alignment of the pointer used by this load/store/gather or
605   /// scatter.
606   MaybeAlign getPointerAlignment() const;
607   // MaybeAlign setPointerAlignment(Align NewAlign); // TODO
608 
609   /// \return The pointer operand of this load,store, gather or scatter.
610   Value *getMemoryPointerParam() const;
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 {
627     return getFunctionalOpcodeForVP(getIntrinsicID());
628   }
629 
630   // Equivalent non-predicated intrinsic ID
631   std::optional<unsigned> getFunctionalIntrinsicID() const {
632     return getFunctionalIntrinsicIDForVP(getIntrinsicID());
633   }
634 
635   // Equivalent non-predicated constrained ID
636   std::optional<unsigned> getConstrainedIntrinsicID() const {
637     return getConstrainedIntrinsicIDForVP(getIntrinsicID());
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>
645   getFunctionalIntrinsicIDForVP(Intrinsic::ID ID);
646 
647   // Equivalent non-predicated constrained ID
648   static std::optional<Intrinsic::ID>
649   getConstrainedIntrinsicIDForVP(Intrinsic::ID ID);
650 };
651 
652 /// This represents vector predication reduction intrinsics.
653 class VPReductionIntrinsic : public VPIntrinsic {
654 public:
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 
674 class VPCastIntrinsic : public VPIntrinsic {
675 public:
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 
689 class VPCmpIntrinsic : public VPIntrinsic {
690 public:
691   static bool isVPCmp(Intrinsic::ID ID);
692 
693   CmpInst::Predicate getPredicate() const;
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 
706 class VPBinOpIntrinsic : public VPIntrinsic {
707 public:
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.
723 class ConstrainedFPIntrinsic : public IntrinsicInst {
724 public:
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.
738 class ConstrainedFPCmpIntrinsic : public ConstrainedFPIntrinsic {
739 public:
740   FCmpInst::Predicate getPredicate() const;
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.
761 class MinMaxIntrinsic : public IntrinsicInst {
762 public:
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.
782   static ICmpInst::Predicate getPredicate(Intrinsic::ID ID) {
783     switch (ID) {
784     case Intrinsic::umin:
785       return ICmpInst::Predicate::ICMP_ULT;
786     case Intrinsic::umax:
787       return ICmpInst::Predicate::ICMP_UGT;
788     case Intrinsic::smin:
789       return ICmpInst::Predicate::ICMP_SLT;
790     case Intrinsic::smax:
791       return ICmpInst::Predicate::ICMP_SGT;
792     default:
793       llvm_unreachable("Invalid intrinsic");
794     }
795   }
796 
797   /// Returns the comparison predicate underlying the intrinsic.
798   ICmpInst::Predicate getPredicate() const {
799     return getPredicate(getIntrinsicID());
800   }
801 
802   /// Whether the intrinsic is signed or unsigned.
803   static bool isSigned(Intrinsic::ID ID) {
804     return ICmpInst::isSigned(getPredicate(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.
838   static Constant *getSaturationPoint(Intrinsic::ID ID, Type *Ty) {
839     return Constant::getIntegerValue(
840         Ty, getSaturationPoint(ID, Ty->getScalarSizeInBits()));
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.
846   Constant *getSaturationPoint(Type *Ty) const {
847     return getSaturationPoint(getIntrinsicID(), Ty);
848   }
849 };
850 
851 /// This class represents a ucmp/scmp intrinsic
852 class CmpIntrinsic : public IntrinsicInst {
853 public:
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 
873   static CmpInst::Predicate getGTPredicate(Intrinsic::ID ID) {
874     return isSigned(ID) ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
875   }
876   CmpInst::Predicate getGTPredicate() const {
877     return getGTPredicate(getIntrinsicID());
878   }
879 
880   static CmpInst::Predicate getLTPredicate(Intrinsic::ID ID) {
881     return isSigned(ID) ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
882   }
883   CmpInst::Predicate getLTPredicate() const {
884     return getLTPredicate(getIntrinsicID());
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.
890 class BinaryOpIntrinsic : public IntrinsicInst {
891 public:
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.
917   Instruction::BinaryOps getBinaryOp() const;
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.
927 class WithOverflowInst : public BinaryOpIntrinsic {
928 public:
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.
948 class SaturatingInst : public BinaryOpIntrinsic {
949 public:
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.
970 template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
971 private:
972   enum { ARG_DEST = 0, ARG_LENGTH = 2 };
973 
974 public:
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")
999   unsigned getDestAlignment() const {
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.
1007   void setDest(Value *Ptr) {
1008     assert(getRawDest()->getType() == Ptr->getType() &&
1009            "setDest called with pointer of wrong type!");
1010     setArgOperand(ARG_DEST, Ptr);
1011   }
1012 
1013   void setDestAlignment(MaybeAlign Alignment) {
1014     removeParamAttr(ARG_DEST, Attribute::Alignment);
1015     if (Alignment)
1016       addParamAttr(ARG_DEST,
1017                    Attribute::getWithAlignment(getContext(), *Alignment));
1018   }
1019   void setDestAlignment(Align Alignment) {
1020     removeParamAttr(ARG_DEST, Attribute::Alignment);
1021     addParamAttr(ARG_DEST,
1022                  Attribute::getWithAlignment(getContext(), Alignment));
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.
1034 template <class BaseCL> class MemTransferBase : public BaseCL {
1035 private:
1036   enum { ARG_SOURCE = 1 };
1037 
1038 public:
1039   /// Return the arguments to the instruction.
1040   Value *getRawSource() const {
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.
1051   Value *getSource() const { return getRawSource()->stripPointerCasts(); }
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")
1060   unsigned getSourceAlignment() const {
1061     if (auto MA = BaseCL::getParamAlign(ARG_SOURCE))
1062       return MA->value();
1063     return 0;
1064   }
1065 
1066   MaybeAlign getSourceAlign() const {
1067     return BaseCL::getParamAlign(ARG_SOURCE);
1068   }
1069 
1070   void setSource(Value *Ptr) {
1071     assert(getRawSource()->getType() == Ptr->getType() &&
1072            "setSource called with pointer of wrong type!");
1073     BaseCL::setArgOperand(ARG_SOURCE, Ptr);
1074   }
1075 
1076   void setSourceAlignment(MaybeAlign Alignment) {
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.
1092 template <class BaseCL> class MemSetBase : public BaseCL {
1093 private:
1094   enum { ARG_VALUE = 1 };
1095 
1096 public:
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
1112 class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
1113 private:
1114   enum { ARG_ELEMENTSIZE = 3 };
1115 
1116 public:
1117   Value *getRawElementSizeInBytes() const {
1118     return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
1119   }
1120 
1121   ConstantInt *getElementSizeInBytesCst() const {
1122     return cast<ConstantInt>(getRawElementSizeInBytes());
1123   }
1124 
1125   uint32_t getElementSizeInBytes() const {
1126     return getElementSizeInBytesCst()->getZExtValue();
1127   }
1128 
1129   void setElementSizeInBytes(Constant *V) {
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
1152 class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
1153 public:
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
1164 class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
1165 public:
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
1182 class AtomicMemCpyInst : public AtomicMemTransferInst {
1183 public:
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
1194 class AtomicMemMoveInst : public AtomicMemTransferInst {
1195 public:
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.
1205 class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1206 private:
1207   enum { ARG_VOLATILE = 3 };
1208 
1209 public:
1210   ConstantInt *getVolatileCst() const {
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.
1237 class MemSetInst : public MemSetBase<MemIntrinsic> {
1238 public:
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.
1255 class MemSetInlineInst : public MemSetInst {
1256 public:
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
1267 class MemSetPatternIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
1268 private:
1269   enum { ARG_VOLATILE = 3 };
1270 
1271 public:
1272   ConstantInt *getVolatileCst() const {
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.
1290 class MemSetPatternInst : public MemSetBase<MemSetPatternIntrinsic> {
1291 public:
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.
1302 class MemTransferInst : public MemTransferBase<MemIntrinsic> {
1303 public:
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.
1321 class MemCpyInst : public MemTransferInst {
1322 public:
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.
1334 class MemMoveInst : public MemTransferInst {
1335 public:
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.
1346 class MemCpyInlineInst : public MemCpyInst {
1347 public:
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
1361 class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
1362 public:
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
1393 class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
1394 public:
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
1413 class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
1414 public:
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
1435 class AnyMemCpyInst : public AnyMemTransferInst {
1436 public:
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
1455 class AnyMemMoveInst : public AnyMemTransferInst {
1456 public:
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.
1472 class VAStartInst : public IntrinsicInst {
1473 public:
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.
1485 class VAEndInst : public IntrinsicInst {
1486 public:
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.
1498 class VACopyInst : public IntrinsicInst {
1499 public:
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.
1512 class InstrProfInstBase : public IntrinsicInst {
1513 protected:
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 
1535 public:
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.
1543   GlobalVariable *getName() const {
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.
1550   Value *getNameValue() const {
1551     return const_cast<Value *>(getArgOperand(0))->stripPointerCasts();
1552   }
1553 
1554   void setNameValue(Value *V) { setArgOperand(0, V); }
1555 
1556   // The hash of the CFG for the instrumented function.
1557   ConstantInt *getHash() const {
1558     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1559   }
1560 };
1561 
1562 /// A base class for all instrprof counter intrinsics.
1563 class InstrProfCntrInstBase : public InstrProfInstBase {
1564 public:
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.
1579 class InstrProfCoverInst : public InstrProfCntrInstBase {
1580 public:
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.
1590 class InstrProfIncrementInst : public InstrProfCntrInstBase {
1591 public:
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.
1603 class InstrProfIncrementInstStep : public InstrProfIncrementInst {
1604 public:
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)
1617 class InstrProfCallsite : public InstrProfCntrInstBase {
1618 public:
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() ||
1629             (CB.getCalledFunction() && !CB.getCalledFunction()->isIntrinsic()));
1630   }
1631   Value *getCallee() const;
1632   void setCallee(Value *Callee);
1633 };
1634 
1635 /// This represents the llvm.instrprof.timestamp intrinsic.
1636 class InstrProfTimestampInst : public InstrProfCntrInstBase {
1637 public:
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.
1647 class InstrProfValueProfileInst : public InstrProfCntrInstBase {
1648 public:
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 
1656   Value *getTargetValue() const {
1657     return cast<Value>(const_cast<Value *>(getArgOperand(2)));
1658   }
1659 
1660   ConstantInt *getValueKind() const {
1661     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1662   }
1663 
1664   // Returns the value site index.
1665   ConstantInt *getIndex() const {
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.
1671 class InstrProfMCDCBitmapInstBase : public InstrProfInstBase {
1672 public:
1673   static bool classof(const IntrinsicInst *I) {
1674     return InstrProfInstBase::isMCDCBitmapBase(*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.
1682   ConstantInt *getNumBitmapBits() const {
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.
1694 class InstrProfMCDCBitmapParameters : public InstrProfMCDCBitmapInstBase {
1695 public:
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.
1705 class InstrProfMCDCTVBitmapUpdate : public InstrProfMCDCBitmapInstBase {
1706 public:
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.
1716   ConstantInt *getBitmapIndex() const {
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.
1722   Value *getMCDCCondBitmapAddr() const {
1723     return cast<Value>(const_cast<Value *>(getArgOperand(3)));
1724   }
1725 };
1726 
1727 class PseudoProbeInst : public IntrinsicInst {
1728 public:
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 
1737   ConstantInt *getFuncGuid() const {
1738     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(0)));
1739   }
1740 
1741   ConstantInt *getIndex() const {
1742     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
1743   }
1744 
1745   ConstantInt *getAttributes() const {
1746     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
1747   }
1748 
1749   ConstantInt *getFactor() const {
1750     return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
1751   }
1752 };
1753 
1754 class NoAliasScopeDeclInst : public IntrinsicInst {
1755 public:
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 
1764   MDNode *getScopeList() const {
1765     auto *MV =
1766         cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
1767     return cast<MDNode>(MV->getMetadata());
1768   }
1769 
1770   void setScopeList(MDNode *ScopeList) {
1771     setOperand(Intrinsic::NoAliasScopeDeclScopeArg,
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.
1778 class GCProjectionInst : public IntrinsicInst {
1779 public:
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.
1802 class GCRelocateInst : public GCProjectionInst {
1803 public:
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.
1830 class GCResultInst : public GCProjectionInst {
1831 public:
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.
1843 class AssumeInst : public IntrinsicInst {
1844 public:
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.
1854 static 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.
1866 class ConvergenceControlInst : public IntrinsicInst {
1867 public:
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() const {
1877     return getIntrinsicID() == Intrinsic::experimental_convergence_anchor;
1878   }
1879   bool isEntry() const {
1880     return getIntrinsicID() == Intrinsic::experimental_convergence_entry;
1881   }
1882   bool isLoop() const {
1883     return getIntrinsicID() == Intrinsic::experimental_convergence_loop;
1884   }
1885 };
1886 
1887 } // end namespace llvm
1888 
1889 #endif // LLVM_IR_INTRINSICINST_H
1890