LLVM  10.0.0svn
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"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/GlobalVariable.h"
30 #include "llvm/IR/Instructions.h"
31 #include "llvm/IR/Intrinsics.h"
32 #include "llvm/IR/Metadata.h"
33 #include "llvm/IR/Value.h"
34 #include "llvm/Support/Casting.h"
35 #include <cassert>
36 #include <cstdint>
37 
38 namespace llvm {
39 
40  /// A wrapper class for inspecting calls to intrinsic functions.
41  /// This allows the standard isa/dyncast/cast functionality to work with calls
42  /// to intrinsic functions.
43  class IntrinsicInst : public CallInst {
44  public:
45  IntrinsicInst() = delete;
46  IntrinsicInst(const IntrinsicInst &) = delete;
47  IntrinsicInst &operator=(const IntrinsicInst &) = delete;
48 
49  /// Return the intrinsic ID of this intrinsic.
52  }
53 
54  // Methods for support type inquiry through isa, cast, and dyn_cast:
55  static bool classof(const CallInst *I) {
56  if (const Function *CF = I->getCalledFunction())
57  return CF->isIntrinsic();
58  return false;
59  }
60  static bool classof(const Value *V) {
61  return isa<CallInst>(V) && classof(cast<CallInst>(V));
62  }
63  };
64 
65  /// This is the common base class for debug info intrinsics.
67  public:
68  /// \name Casting methods
69  /// @{
70  static bool classof(const IntrinsicInst *I) {
71  switch (I->getIntrinsicID()) {
72  case Intrinsic::dbg_declare:
73  case Intrinsic::dbg_value:
74  case Intrinsic::dbg_addr:
75  case Intrinsic::dbg_label:
76  return true;
77  default: return false;
78  }
79  }
80  static bool classof(const Value *V) {
81  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
82  }
83  /// @}
84  };
85 
86  /// This is the common base class for debug info intrinsics for variables.
88  public:
89  /// Get the location corresponding to the variable referenced by the debug
90  /// info intrinsic. Depending on the intrinsic, this could be the
91  /// variable's value or its address.
92  Value *getVariableLocation(bool AllowNullOp = true) const;
93 
94  /// Does this describe the address of a local variable. True for dbg.addr
95  /// and dbg.declare, but not dbg.value, which describes its value.
96  bool isAddressOfVariable() const {
97  return getIntrinsicID() != Intrinsic::dbg_value;
98  }
99 
101  return cast<DILocalVariable>(getRawVariable());
102  }
103 
105  return cast<DIExpression>(getRawExpression());
106  }
107 
109  return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
110  }
111 
113  return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
114  }
115 
116  /// Get the size (in bits) of the variable, or fragment of the variable that
117  /// is described.
118  Optional<uint64_t> getFragmentSizeInBits() const;
119 
120  /// \name Casting methods
121  /// @{
122  static bool classof(const IntrinsicInst *I) {
123  switch (I->getIntrinsicID()) {
124  case Intrinsic::dbg_declare:
125  case Intrinsic::dbg_value:
126  case Intrinsic::dbg_addr:
127  return true;
128  default: return false;
129  }
130  }
131  static bool classof(const Value *V) {
132  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
133  }
134  /// @}
135  };
136 
137  /// This represents the llvm.dbg.declare instruction.
139  public:
140  Value *getAddress() const { return getVariableLocation(); }
141 
142  /// \name Casting methods
143  /// @{
144  static bool classof(const IntrinsicInst *I) {
145  return I->getIntrinsicID() == Intrinsic::dbg_declare;
146  }
147  static bool classof(const Value *V) {
148  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
149  }
150  /// @}
151  };
152 
153  /// This represents the llvm.dbg.addr instruction.
155  public:
156  Value *getAddress() const { return getVariableLocation(); }
157 
158  /// \name Casting methods
159  /// @{
160  static bool classof(const IntrinsicInst *I) {
161  return I->getIntrinsicID() == Intrinsic::dbg_addr;
162  }
163  static bool classof(const Value *V) {
164  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
165  }
166  };
167 
168  /// This represents the llvm.dbg.value instruction.
170  public:
171  Value *getValue() const {
172  return getVariableLocation(/* AllowNullOp = */ false);
173  }
174 
175  /// \name Casting methods
176  /// @{
177  static bool classof(const IntrinsicInst *I) {
178  return I->getIntrinsicID() == Intrinsic::dbg_value;
179  }
180  static bool classof(const Value *V) {
181  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
182  }
183  /// @}
184  };
185 
186  /// This represents the llvm.dbg.label instruction.
188  public:
189  DILabel *getLabel() const {
190  return cast<DILabel>(getRawLabel());
191  }
192 
194  return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
195  }
196 
197  /// Methods for support type inquiry through isa, cast, and dyn_cast:
198  /// @{
199  static bool classof(const IntrinsicInst *I) {
200  return I->getIntrinsicID() == Intrinsic::dbg_label;
201  }
202  static bool classof(const Value *V) {
203  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
204  }
205  /// @}
206  };
207 
208  /// This is the common base class for constrained floating point intrinsics.
210  public:
211  /// Specifies the rounding mode to be assumed. This is only used when
212  /// when constrained floating point is enabled. See the LLVM Language
213  /// Reference Manual for details.
214  enum RoundingMode : uint8_t {
215  rmDynamic, ///< This corresponds to "fpround.dynamic".
216  rmToNearest, ///< This corresponds to "fpround.tonearest".
217  rmDownward, ///< This corresponds to "fpround.downward".
218  rmUpward, ///< This corresponds to "fpround.upward".
219  rmTowardZero ///< This corresponds to "fpround.tozero".
220  };
221 
222  /// Specifies the required exception behavior. This is only used when
223  /// when constrained floating point is used. See the LLVM Language
224  /// Reference Manual for details.
225  enum ExceptionBehavior : uint8_t {
226  ebIgnore, ///< This corresponds to "fpexcept.ignore".
227  ebMayTrap, ///< This corresponds to "fpexcept.maytrap".
228  ebStrict ///< This corresponds to "fpexcept.strict".
229  };
230 
231  bool isUnaryOp() const;
232  bool isTernaryOp() const;
233  Optional<RoundingMode> getRoundingMode() const;
234  Optional<ExceptionBehavior> getExceptionBehavior() const;
235 
236  /// Returns a valid RoundingMode enumerator when given a string
237  /// that is valid as input in constrained intrinsic rounding mode
238  /// metadata.
239  static Optional<RoundingMode> StrToRoundingMode(StringRef);
240 
241  /// For any RoundingMode enumerator, returns a string valid as input in
242  /// constrained intrinsic rounding mode metadata.
243  static Optional<StringRef> RoundingModeToStr(RoundingMode);
244 
245  /// Returns a valid ExceptionBehavior enumerator when given a string
246  /// valid as input in constrained intrinsic exception behavior metadata.
247  static Optional<ExceptionBehavior> StrToExceptionBehavior(StringRef);
248 
249  /// For any ExceptionBehavior enumerator, returns a string valid as
250  /// input in constrained intrinsic exception behavior metadata.
251  static Optional<StringRef> ExceptionBehaviorToStr(ExceptionBehavior);
252 
253  // Methods for support type inquiry through isa, cast, and dyn_cast:
254  static bool classof(const IntrinsicInst *I) {
255  switch (I->getIntrinsicID()) {
256  case Intrinsic::experimental_constrained_fadd:
257  case Intrinsic::experimental_constrained_fsub:
258  case Intrinsic::experimental_constrained_fmul:
259  case Intrinsic::experimental_constrained_fdiv:
260  case Intrinsic::experimental_constrained_frem:
261  case Intrinsic::experimental_constrained_fma:
262  case Intrinsic::experimental_constrained_fptosi:
263  case Intrinsic::experimental_constrained_fptoui:
264  case Intrinsic::experimental_constrained_fptrunc:
265  case Intrinsic::experimental_constrained_fpext:
266  case Intrinsic::experimental_constrained_sqrt:
267  case Intrinsic::experimental_constrained_pow:
268  case Intrinsic::experimental_constrained_powi:
269  case Intrinsic::experimental_constrained_sin:
270  case Intrinsic::experimental_constrained_cos:
271  case Intrinsic::experimental_constrained_exp:
272  case Intrinsic::experimental_constrained_exp2:
273  case Intrinsic::experimental_constrained_log:
274  case Intrinsic::experimental_constrained_log10:
275  case Intrinsic::experimental_constrained_log2:
276  case Intrinsic::experimental_constrained_rint:
277  case Intrinsic::experimental_constrained_nearbyint:
278  case Intrinsic::experimental_constrained_maxnum:
279  case Intrinsic::experimental_constrained_minnum:
280  case Intrinsic::experimental_constrained_ceil:
281  case Intrinsic::experimental_constrained_floor:
282  case Intrinsic::experimental_constrained_round:
283  case Intrinsic::experimental_constrained_trunc:
284  return true;
285  default: return false;
286  }
287  }
288  static bool classof(const Value *V) {
289  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
290  }
291  };
292 
293  /// This class represents an intrinsic that is based on a binary operation.
294  /// This includes op.with.overflow and saturating add/sub intrinsics.
296  public:
297  static bool classof(const IntrinsicInst *I) {
298  switch (I->getIntrinsicID()) {
299  case Intrinsic::uadd_with_overflow:
300  case Intrinsic::sadd_with_overflow:
301  case Intrinsic::usub_with_overflow:
302  case Intrinsic::ssub_with_overflow:
303  case Intrinsic::umul_with_overflow:
304  case Intrinsic::smul_with_overflow:
305  case Intrinsic::uadd_sat:
306  case Intrinsic::sadd_sat:
307  case Intrinsic::usub_sat:
308  case Intrinsic::ssub_sat:
309  return true;
310  default:
311  return false;
312  }
313  }
314  static bool classof(const Value *V) {
315  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
316  }
317 
318  Value *getLHS() const { return const_cast<Value*>(getArgOperand(0)); }
319  Value *getRHS() const { return const_cast<Value*>(getArgOperand(1)); }
320 
321  /// Returns the binary operation underlying the intrinsic.
322  Instruction::BinaryOps getBinaryOp() const;
323 
324  /// Whether the intrinsic is signed or unsigned.
325  bool isSigned() const;
326 
327  /// Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
328  unsigned getNoWrapKind() const;
329  };
330 
331  /// Represents an op.with.overflow intrinsic.
333  public:
334  static bool classof(const IntrinsicInst *I) {
335  switch (I->getIntrinsicID()) {
336  case Intrinsic::uadd_with_overflow:
337  case Intrinsic::sadd_with_overflow:
338  case Intrinsic::usub_with_overflow:
339  case Intrinsic::ssub_with_overflow:
340  case Intrinsic::umul_with_overflow:
341  case Intrinsic::smul_with_overflow:
342  return true;
343  default:
344  return false;
345  }
346  }
347  static bool classof(const Value *V) {
348  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
349  }
350  };
351 
352  /// Represents a saturating add/sub intrinsic.
354  public:
355  static bool classof(const IntrinsicInst *I) {
356  switch (I->getIntrinsicID()) {
357  case Intrinsic::uadd_sat:
358  case Intrinsic::sadd_sat:
359  case Intrinsic::usub_sat:
360  case Intrinsic::ssub_sat:
361  return true;
362  default:
363  return false;
364  }
365  }
366  static bool classof(const Value *V) {
367  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
368  }
369  };
370 
371  /// Common base class for all memory intrinsics. Simply provides
372  /// common methods.
373  /// Written as CRTP to avoid a common base class amongst the
374  /// three atomicity hierarchies.
375  template <typename Derived> class MemIntrinsicBase : public IntrinsicInst {
376  private:
377  enum { ARG_DEST = 0, ARG_LENGTH = 2 };
378 
379  public:
380  Value *getRawDest() const {
381  return const_cast<Value *>(getArgOperand(ARG_DEST));
382  }
383  const Use &getRawDestUse() const { return getArgOperandUse(ARG_DEST); }
384  Use &getRawDestUse() { return getArgOperandUse(ARG_DEST); }
385 
386  Value *getLength() const {
387  return const_cast<Value *>(getArgOperand(ARG_LENGTH));
388  }
389  const Use &getLengthUse() const { return getArgOperandUse(ARG_LENGTH); }
390  Use &getLengthUse() { return getArgOperandUse(ARG_LENGTH); }
391 
392  /// This is just like getRawDest, but it strips off any cast
393  /// instructions (including addrspacecast) that feed it, giving the
394  /// original input. The returned value is guaranteed to be a pointer.
395  Value *getDest() const { return getRawDest()->stripPointerCasts(); }
396 
397  unsigned getDestAddressSpace() const {
398  return cast<PointerType>(getRawDest()->getType())->getAddressSpace();
399  }
400 
401  unsigned getDestAlignment() const { return getParamAlignment(ARG_DEST); }
402 
403  /// Set the specified arguments of the instruction.
404  void setDest(Value *Ptr) {
405  assert(getRawDest()->getType() == Ptr->getType() &&
406  "setDest called with pointer of wrong type!");
407  setArgOperand(ARG_DEST, Ptr);
408  }
409 
410  void setDestAlignment(unsigned Align) {
411  removeParamAttr(ARG_DEST, Attribute::Alignment);
412  if (Align > 0)
413  addParamAttr(ARG_DEST,
415  }
416 
417  void setLength(Value *L) {
418  assert(getLength()->getType() == L->getType() &&
419  "setLength called with value of wrong type!");
420  setArgOperand(ARG_LENGTH, L);
421  }
422  };
423 
424  /// Common base class for all memory transfer intrinsics. Simply provides
425  /// common methods.
426  template <class BaseCL> class MemTransferBase : public BaseCL {
427  private:
428  enum { ARG_SOURCE = 1 };
429 
430  public:
431  /// Return the arguments to the instruction.
432  Value *getRawSource() const {
433  return const_cast<Value *>(BaseCL::getArgOperand(ARG_SOURCE));
434  }
435  const Use &getRawSourceUse() const {
436  return BaseCL::getArgOperandUse(ARG_SOURCE);
437  }
438  Use &getRawSourceUse() { return BaseCL::getArgOperandUse(ARG_SOURCE); }
439 
440  /// This is just like getRawSource, but it strips off any cast
441  /// instructions that feed it, giving the original input. The returned
442  /// value is guaranteed to be a pointer.
443  Value *getSource() const { return getRawSource()->stripPointerCasts(); }
444 
445  unsigned getSourceAddressSpace() const {
446  return cast<PointerType>(getRawSource()->getType())->getAddressSpace();
447  }
448 
449  unsigned getSourceAlignment() const {
450  return BaseCL::getParamAlignment(ARG_SOURCE);
451  }
452 
453  void setSource(Value *Ptr) {
454  assert(getRawSource()->getType() == Ptr->getType() &&
455  "setSource called with pointer of wrong type!");
456  BaseCL::setArgOperand(ARG_SOURCE, Ptr);
457  }
458 
459  void setSourceAlignment(unsigned Align) {
460  BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
461  if (Align > 0)
462  BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
463  BaseCL::getContext(), Align));
464  }
465  };
466 
467  /// Common base class for all memset intrinsics. Simply provides
468  /// common methods.
469  template <class BaseCL> class MemSetBase : public BaseCL {
470  private:
471  enum { ARG_VALUE = 1 };
472 
473  public:
474  Value *getValue() const {
475  return const_cast<Value *>(BaseCL::getArgOperand(ARG_VALUE));
476  }
477  const Use &getValueUse() const {
478  return BaseCL::getArgOperandUse(ARG_VALUE);
479  }
480  Use &getValueUse() { return BaseCL::getArgOperandUse(ARG_VALUE); }
481 
482  void setValue(Value *Val) {
483  assert(getValue()->getType() == Val->getType() &&
484  "setValue called with value of wrong type!");
485  BaseCL::setArgOperand(ARG_VALUE, Val);
486  }
487  };
488 
489  // The common base class for the atomic memset/memmove/memcpy intrinsics
490  // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
491  class AtomicMemIntrinsic : public MemIntrinsicBase<AtomicMemIntrinsic> {
492  private:
493  enum { ARG_ELEMENTSIZE = 3 };
494 
495  public:
497  return const_cast<Value *>(getArgOperand(ARG_ELEMENTSIZE));
498  }
499 
501  return cast<ConstantInt>(getRawElementSizeInBytes());
502  }
503 
505  return getElementSizeInBytesCst()->getZExtValue();
506  }
507 
510  "setElementSizeInBytes called with value of wrong type!");
511  setArgOperand(ARG_ELEMENTSIZE, V);
512  }
513 
514  static bool classof(const IntrinsicInst *I) {
515  switch (I->getIntrinsicID()) {
516  case Intrinsic::memcpy_element_unordered_atomic:
517  case Intrinsic::memmove_element_unordered_atomic:
518  case Intrinsic::memset_element_unordered_atomic:
519  return true;
520  default:
521  return false;
522  }
523  }
524  static bool classof(const Value *V) {
525  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
526  }
527  };
528 
529  /// This class represents atomic memset intrinsic
530  // i.e. llvm.element.unordered.atomic.memset
531  class AtomicMemSetInst : public MemSetBase<AtomicMemIntrinsic> {
532  public:
533  static bool classof(const IntrinsicInst *I) {
534  return I->getIntrinsicID() == Intrinsic::memset_element_unordered_atomic;
535  }
536  static bool classof(const Value *V) {
537  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
538  }
539  };
540 
541  // This class wraps the atomic memcpy/memmove intrinsics
542  // i.e. llvm.element.unordered.atomic.memcpy/memmove
543  class AtomicMemTransferInst : public MemTransferBase<AtomicMemIntrinsic> {
544  public:
545  static bool classof(const IntrinsicInst *I) {
546  switch (I->getIntrinsicID()) {
547  case Intrinsic::memcpy_element_unordered_atomic:
548  case Intrinsic::memmove_element_unordered_atomic:
549  return true;
550  default:
551  return false;
552  }
553  }
554  static bool classof(const Value *V) {
555  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
556  }
557  };
558 
559  /// This class represents the atomic memcpy intrinsic
560  /// i.e. llvm.element.unordered.atomic.memcpy
562  public:
563  static bool classof(const IntrinsicInst *I) {
564  return I->getIntrinsicID() == Intrinsic::memcpy_element_unordered_atomic;
565  }
566  static bool classof(const Value *V) {
567  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
568  }
569  };
570 
571  /// This class represents the atomic memmove intrinsic
572  /// i.e. llvm.element.unordered.atomic.memmove
574  public:
575  static bool classof(const IntrinsicInst *I) {
576  return I->getIntrinsicID() == Intrinsic::memmove_element_unordered_atomic;
577  }
578  static bool classof(const Value *V) {
579  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
580  }
581  };
582 
583  /// This is the common base class for memset/memcpy/memmove.
584  class MemIntrinsic : public MemIntrinsicBase<MemIntrinsic> {
585  private:
586  enum { ARG_VOLATILE = 3 };
587 
588  public:
590  return cast<ConstantInt>(
591  const_cast<Value *>(getArgOperand(ARG_VOLATILE)));
592  }
593 
594  bool isVolatile() const {
595  return !getVolatileCst()->isZero();
596  }
597 
598  void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }
599 
600  // Methods for support type inquiry through isa, cast, and dyn_cast:
601  static bool classof(const IntrinsicInst *I) {
602  switch (I->getIntrinsicID()) {
603  case Intrinsic::memcpy:
604  case Intrinsic::memmove:
605  case Intrinsic::memset:
606  return true;
607  default: return false;
608  }
609  }
610  static bool classof(const Value *V) {
611  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
612  }
613  };
614 
615  /// This class wraps the llvm.memset intrinsic.
616  class MemSetInst : public MemSetBase<MemIntrinsic> {
617  public:
618  // Methods for support type inquiry through isa, cast, and dyn_cast:
619  static bool classof(const IntrinsicInst *I) {
620  return I->getIntrinsicID() == Intrinsic::memset;
621  }
622  static bool classof(const Value *V) {
623  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
624  }
625  };
626 
627  /// This class wraps the llvm.memcpy/memmove intrinsics.
628  class MemTransferInst : public MemTransferBase<MemIntrinsic> {
629  public:
630  // Methods for support type inquiry through isa, cast, and dyn_cast:
631  static bool classof(const IntrinsicInst *I) {
632  return I->getIntrinsicID() == Intrinsic::memcpy ||
633  I->getIntrinsicID() == Intrinsic::memmove;
634  }
635  static bool classof(const Value *V) {
636  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
637  }
638  };
639 
640  /// This class wraps the llvm.memcpy intrinsic.
641  class MemCpyInst : public MemTransferInst {
642  public:
643  // Methods for support type inquiry through isa, cast, and dyn_cast:
644  static bool classof(const IntrinsicInst *I) {
645  return I->getIntrinsicID() == Intrinsic::memcpy;
646  }
647  static bool classof(const Value *V) {
648  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
649  }
650  };
651 
652  /// This class wraps the llvm.memmove intrinsic.
653  class MemMoveInst : public MemTransferInst {
654  public:
655  // Methods for support type inquiry through isa, cast, and dyn_cast:
656  static bool classof(const IntrinsicInst *I) {
657  return I->getIntrinsicID() == Intrinsic::memmove;
658  }
659  static bool classof(const Value *V) {
660  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
661  }
662  };
663 
664  // The common base class for any memset/memmove/memcpy intrinsics;
665  // whether they be atomic or non-atomic.
666  // i.e. llvm.element.unordered.atomic.memset/memcpy/memmove
667  // and llvm.memset/memcpy/memmove
668  class AnyMemIntrinsic : public MemIntrinsicBase<AnyMemIntrinsic> {
669  public:
670  bool isVolatile() const {
671  // Only the non-atomic intrinsics can be volatile
672  if (auto *MI = dyn_cast<MemIntrinsic>(this))
673  return MI->isVolatile();
674  return false;
675  }
676 
677  static bool classof(const IntrinsicInst *I) {
678  switch (I->getIntrinsicID()) {
679  case Intrinsic::memcpy:
680  case Intrinsic::memmove:
681  case Intrinsic::memset:
682  case Intrinsic::memcpy_element_unordered_atomic:
683  case Intrinsic::memmove_element_unordered_atomic:
684  case Intrinsic::memset_element_unordered_atomic:
685  return true;
686  default:
687  return false;
688  }
689  }
690  static bool classof(const Value *V) {
691  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
692  }
693  };
694 
695  /// This class represents any memset intrinsic
696  // i.e. llvm.element.unordered.atomic.memset
697  // and llvm.memset
698  class AnyMemSetInst : public MemSetBase<AnyMemIntrinsic> {
699  public:
700  static bool classof(const IntrinsicInst *I) {
701  switch (I->getIntrinsicID()) {
702  case Intrinsic::memset:
703  case Intrinsic::memset_element_unordered_atomic:
704  return true;
705  default:
706  return false;
707  }
708  }
709  static bool classof(const Value *V) {
710  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
711  }
712  };
713 
714  // This class wraps any memcpy/memmove intrinsics
715  // i.e. llvm.element.unordered.atomic.memcpy/memmove
716  // and llvm.memcpy/memmove
717  class AnyMemTransferInst : public MemTransferBase<AnyMemIntrinsic> {
718  public:
719  static bool classof(const IntrinsicInst *I) {
720  switch (I->getIntrinsicID()) {
721  case Intrinsic::memcpy:
722  case Intrinsic::memmove:
723  case Intrinsic::memcpy_element_unordered_atomic:
724  case Intrinsic::memmove_element_unordered_atomic:
725  return true;
726  default:
727  return false;
728  }
729  }
730  static bool classof(const Value *V) {
731  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
732  }
733  };
734 
735  /// This class represents any memcpy intrinsic
736  /// i.e. llvm.element.unordered.atomic.memcpy
737  /// and llvm.memcpy
739  public:
740  static bool classof(const IntrinsicInst *I) {
741  switch (I->getIntrinsicID()) {
742  case Intrinsic::memcpy:
743  case Intrinsic::memcpy_element_unordered_atomic:
744  return true;
745  default:
746  return false;
747  }
748  }
749  static bool classof(const Value *V) {
750  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
751  }
752  };
753 
754  /// This class represents any memmove intrinsic
755  /// i.e. llvm.element.unordered.atomic.memmove
756  /// and llvm.memmove
758  public:
759  static bool classof(const IntrinsicInst *I) {
760  switch (I->getIntrinsicID()) {
761  case Intrinsic::memmove:
762  case Intrinsic::memmove_element_unordered_atomic:
763  return true;
764  default:
765  return false;
766  }
767  }
768  static bool classof(const Value *V) {
769  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
770  }
771  };
772 
773  /// This represents the llvm.va_start intrinsic.
774  class VAStartInst : public IntrinsicInst {
775  public:
776  static bool classof(const IntrinsicInst *I) {
777  return I->getIntrinsicID() == Intrinsic::vastart;
778  }
779  static bool classof(const Value *V) {
780  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
781  }
782 
783  Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
784  };
785 
786  /// This represents the llvm.va_end intrinsic.
787  class VAEndInst : public IntrinsicInst {
788  public:
789  static bool classof(const IntrinsicInst *I) {
790  return I->getIntrinsicID() == Intrinsic::vaend;
791  }
792  static bool classof(const Value *V) {
793  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
794  }
795 
796  Value *getArgList() const { return const_cast<Value*>(getArgOperand(0)); }
797  };
798 
799  /// This represents the llvm.va_copy intrinsic.
800  class VACopyInst : public IntrinsicInst {
801  public:
802  static bool classof(const IntrinsicInst *I) {
803  return I->getIntrinsicID() == Intrinsic::vacopy;
804  }
805  static bool classof(const Value *V) {
806  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
807  }
808 
809  Value *getDest() const { return const_cast<Value*>(getArgOperand(0)); }
810  Value *getSrc() const { return const_cast<Value*>(getArgOperand(1)); }
811  };
812 
813  /// This represents the llvm.instrprof_increment intrinsic.
815  public:
816  static bool classof(const IntrinsicInst *I) {
817  return I->getIntrinsicID() == Intrinsic::instrprof_increment;
818  }
819  static bool classof(const Value *V) {
820  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
821  }
822 
824  return cast<GlobalVariable>(
825  const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
826  }
827 
828  ConstantInt *getHash() const {
829  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
830  }
831 
833  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(2)));
834  }
835 
837  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
838  }
839 
840  Value *getStep() const;
841  };
842 
844  public:
845  static bool classof(const IntrinsicInst *I) {
846  return I->getIntrinsicID() == Intrinsic::instrprof_increment_step;
847  }
848  static bool classof(const Value *V) {
849  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
850  }
851  };
852 
853  /// This represents the llvm.instrprof_value_profile intrinsic.
855  public:
856  static bool classof(const IntrinsicInst *I) {
857  return I->getIntrinsicID() == Intrinsic::instrprof_value_profile;
858  }
859  static bool classof(const Value *V) {
860  return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
861  }
862 
864  return cast<GlobalVariable>(
865  const_cast<Value *>(getArgOperand(0))->stripPointerCasts());
866  }
867 
868  ConstantInt *getHash() const {
869  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
870  }
871 
873  return cast<Value>(const_cast<Value *>(getArgOperand(2)));
874  }
875 
877  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
878  }
879 
880  // Returns the value site index.
882  return cast<ConstantInt>(const_cast<Value *>(getArgOperand(4)));
883  }
884  };
885 
886 } // end namespace llvm
887 
888 #endif // LLVM_IR_INTRINSICINST_H
ExceptionBehavior
Specifies the required exception behavior.
static bool classof(const Value *V)
static bool classof(const Value *V)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
IntrinsicInst & operator=(const IntrinsicInst &)=delete
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
This represents the llvm.dbg.label instruction.
Value * getSrc() const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents the llvm.va_end intrinsic.
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:145
Represents an op.with.overflow intrinsic.
Value * getRawElementSizeInBytes() const
This corresponds to "fpround.upward".
This corresponds to "fpround.downward".
This class represents a function call, abstracting a target machine&#39;s calling convention.
This file contains the declarations for metadata subclasses.
static bool classof(const CallInst *I)
Definition: IntrinsicInst.h:55
This corresponds to "fpexcept.maytrap".
unsigned getSourceAlignment() const
static bool classof(const IntrinsicInst *I)
Value * getValue() const
This class represents the atomic memcpy intrinsic i.e.
unsigned getSourceAddressSpace() const
static bool classof(const Value *V)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:733
void setSource(Value *Ptr)
void setDest(Value *Ptr)
Set the specified arguments of the instruction.
This class wraps the llvm.memset intrinsic.
void setVolatile(Constant *V)
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1246
static bool classof(const IntrinsicInst *I)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V)
This is the common base class for constrained floating point intrinsics.
This corresponds to "fpexcept.ignore".
Value * getLength() const
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: InstrTypes.h:1573
Value * getArgList() const
static bool classof(const IntrinsicInst *I)
Definition: IntrinsicInst.h:70
This corresponds to "fpround.dynamic".
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1241
static bool classof(const Value *V)
This class wraps the llvm.memmove intrinsic.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
DILabel * getLabel() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
unsigned getDestAlignment() const
This class represents atomic memset intrinsic.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
This represents the llvm.va_start intrinsic.
const Use & getRawSourceUse() const
void setLength(Value *L)
static bool classof(const Value *V)
This is the common base class for debug info intrinsics for variables.
Definition: IntrinsicInst.h:87
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:244
static bool classof(const Value *V)
Value * getRHS() const
GlobalVariable * getName() const
ConstantInt * getNumCounters() const
static bool classof(const Value *V)
static bool classof(const Value *V)
static bool classof(const Value *V)
static bool classof(const Value *V)
const Use & getValueUse() const
ConstantInt * getHash() const
static bool classof(const Value *V)
This class represents the atomic memmove intrinsic i.e.
Metadata * getRawExpression() const
static bool classof(const Value *V)
static bool classof(const Value *V)
ConstantInt * getIndex() const
static bool classof(const IntrinsicInst *I)
Value * getAddress() const
This is an important base class in LLVM.
Definition: Constant.h:41
Value * getValue() const
static bool classof(const IntrinsicInst *I)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool classof(const Value *V)
DIExpression * getExpression() const
Metadata * getRawLabel() const
static bool classof(const IntrinsicInst *I)
This class represents any memset intrinsic.
static bool classof(const Value *V)
Definition: IntrinsicInst.h:80
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
bool isVolatile() const
static bool classof(const Value *V)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:525
This represents the llvm.dbg.addr instruction.
uint32_t getElementSizeInBytes() const
static bool classof(const IntrinsicInst *I)
Common base class for all memset intrinsics.
bool isVolatile() const
static bool classof(const IntrinsicInst *I)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
ConstantInt * getVolatileCst() const
ConstantInt * getElementSizeInBytesCst() const
static bool classof(const IntrinsicInst *I)
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:50
static bool classof(const Value *V)
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
Definition: InstrTypes.h:1397
This is the common base class for memset/memcpy/memmove.
const Use & getLengthUse() const
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
Value * getArgList() const
void setValue(Value *Val)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Metadata * getRawVariable() const
Represents a saturating add/sub intrinsic.
This is the common base class for debug info intrinsics.
Definition: IntrinsicInst.h:66
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
This class wraps the llvm.memcpy intrinsic.
Value * getRawSource() const
Return the arguments to the instruction.
static bool classof(const Value *V)
Common base class for all memory transfer intrinsics.
DWARF expression.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:193
static bool classof(const Value *V)
Value * getDest() const
This represents the llvm.instrprof_increment intrinsic.
void setElementSizeInBytes(Constant *V)
This class wraps the llvm.memcpy/memmove intrinsics.
unsigned getDestAddressSpace() const
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
This represents the llvm.dbg.value instruction.
bool isAddressOfVariable() const
Does this describe the address of a local variable.
Definition: IntrinsicInst.h:96
ConstantInt * getHash() const
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1287
#define I(x, y, z)
Definition: MD5.cpp:58
static bool classof(const Value *V)
static bool classof(const Value *V)
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1252
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Definition: InstrTypes.h:1427
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
Common base class for all memory intrinsics.
DILocalVariable * getVariable() const
This class represents an intrinsic that is based on a binary operation.
static bool classof(const Value *V)
Definition: IntrinsicInst.h:60
static bool classof(const IntrinsicInst *I)
This represents the llvm.va_copy intrinsic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool classof(const Value *V)
LLVM Value Representation.
Definition: Value.h:73
static bool classof(const IntrinsicInst *I)
This class represents any memmove intrinsic i.e.
GlobalVariable * getName() const
ConstantInt * getValueKind() const
Value * getSource() const
This is just like getRawSource, but it strips off any cast instructions that feed it...
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void setSourceAlignment(unsigned Align)
This corresponds to "fpround.tonearest".
This class represents any memcpy intrinsic i.e.
This represents the llvm.instrprof_value_profile intrinsic.
This represents the llvm.dbg.declare instruction.
RoundingMode
Specifies the rounding mode to be assumed.
static bool classof(const IntrinsicInst *I)
Root of the metadata hierarchy.
Definition: Metadata.h:57
static bool classof(const IntrinsicInst *I)
Value * getLHS() const
bool isUnaryOp() const
Definition: Instruction.h:129
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:173
Value * getRawDest() const
static bool classof(const IntrinsicInst *I)
const Use & getRawDestUse() const
void setDestAlignment(unsigned Align)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:43
Value * getAddress() const