Argument.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the Argument class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_IR_ARGUMENT_H
  18. #define LLVM_IR_ARGUMENT_H
  19. #include "llvm/ADT/Twine.h"
  20. #include "llvm/IR/Attributes.h"
  21. #include "llvm/IR/Value.h"
  22. namespace llvm {
  23. /// This class represents an incoming formal argument to a Function. A formal
  24. /// argument, since it is ``formal'', does not contain an actual value but
  25. /// instead represents the type, argument number, and attributes of an argument
  26. /// for a specific function. When used in the body of said function, the
  27. /// argument of course represents the value of the actual argument that the
  28. /// function was called with.
  29. class Argument final : public Value {
  30. Function *Parent;
  31. unsigned ArgNo;
  32. friend class Function;
  33. void setParent(Function *parent);
  34. public:
  35. /// Argument constructor.
  36. explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
  37. unsigned ArgNo = 0);
  38. inline const Function *getParent() const { return Parent; }
  39. inline Function *getParent() { return Parent; }
  40. /// Return the index of this formal argument in its containing function.
  41. ///
  42. /// For example in "void foo(int a, float b)" a is 0 and b is 1.
  43. unsigned getArgNo() const {
  44. assert(Parent && "can't get number of unparented arg");
  45. return ArgNo;
  46. }
  47. /// Return true if this argument has the nonnull attribute. Also returns true
  48. /// if at least one byte is known to be dereferenceable and the pointer is in
  49. /// addrspace(0).
  50. /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
  51. /// and return true even if the argument can be undef or poison.
  52. bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
  53. /// If this argument has the dereferenceable attribute, return the number of
  54. /// bytes known to be dereferenceable. Otherwise, zero is returned.
  55. uint64_t getDereferenceableBytes() const;
  56. /// If this argument has the dereferenceable_or_null attribute, return the
  57. /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
  58. uint64_t getDereferenceableOrNullBytes() const;
  59. /// Return true if this argument has the byval attribute.
  60. bool hasByValAttr() const;
  61. /// Return true if this argument has the byref attribute.
  62. bool hasByRefAttr() const;
  63. /// Return true if this argument has the swiftself attribute.
  64. bool hasSwiftSelfAttr() const;
  65. /// Return true if this argument has the swifterror attribute.
  66. bool hasSwiftErrorAttr() const;
  67. /// Return true if this argument has the byval, inalloca, or preallocated
  68. /// attribute. These attributes represent arguments being passed by value,
  69. /// with an associated copy between the caller and callee
  70. bool hasPassPointeeByValueCopyAttr() const;
  71. /// If this argument satisfies has hasPassPointeeByValueAttr, return the
  72. /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
  73. uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const;
  74. /// Return true if this argument has the byval, sret, inalloca, preallocated,
  75. /// or byref attribute. These attributes represent arguments being passed by
  76. /// value (which may or may not involve a stack copy)
  77. bool hasPointeeInMemoryValueAttr() const;
  78. /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
  79. /// returned. Otherwise, nullptr.
  80. Type *getPointeeInMemoryValueType() const;
  81. /// If this is a byval or inalloca argument, return its alignment.
  82. /// FIXME: Remove this function once transition to Align is over.
  83. /// Use getParamAlign() instead.
  84. LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
  85. uint64_t getParamAlignment() const;
  86. /// If this is a byval or inalloca argument, return its alignment.
  87. MaybeAlign getParamAlign() const;
  88. MaybeAlign getParamStackAlign() const;
  89. /// If this is a byval argument, return its type.
  90. Type *getParamByValType() const;
  91. /// If this is an sret argument, return its type.
  92. Type *getParamStructRetType() const;
  93. /// If this is a byref argument, return its type.
  94. Type *getParamByRefType() const;
  95. /// If this is an inalloca argument, return its type.
  96. Type *getParamInAllocaType() const;
  97. /// Return true if this argument has the nest attribute.
  98. bool hasNestAttr() const;
  99. /// Return true if this argument has the noalias attribute.
  100. bool hasNoAliasAttr() const;
  101. /// Return true if this argument has the nocapture attribute.
  102. bool hasNoCaptureAttr() const;
  103. /// Return true if this argument has the nofree attribute.
  104. bool hasNoFreeAttr() const;
  105. /// Return true if this argument has the sret attribute.
  106. bool hasStructRetAttr() const;
  107. /// Return true if this argument has the inreg attribute.
  108. bool hasInRegAttr() const;
  109. /// Return true if this argument has the returned attribute.
  110. bool hasReturnedAttr() const;
  111. /// Return true if this argument has the readonly or readnone attribute.
  112. bool onlyReadsMemory() const;
  113. /// Return true if this argument has the inalloca attribute.
  114. bool hasInAllocaAttr() const;
  115. /// Return true if this argument has the preallocated attribute.
  116. bool hasPreallocatedAttr() const;
  117. /// Return true if this argument has the zext attribute.
  118. bool hasZExtAttr() const;
  119. /// Return true if this argument has the sext attribute.
  120. bool hasSExtAttr() const;
  121. /// Add attributes to an argument.
  122. void addAttrs(AttrBuilder &B);
  123. void addAttr(Attribute::AttrKind Kind);
  124. void addAttr(Attribute Attr);
  125. /// Remove attributes from an argument.
  126. void removeAttr(Attribute::AttrKind Kind);
  127. void removeAttrs(const AttributeMask &AM);
  128. /// Check if an argument has a given attribute.
  129. bool hasAttribute(Attribute::AttrKind Kind) const;
  130. Attribute getAttribute(Attribute::AttrKind Kind) const;
  131. /// Method for support type inquiry through isa, cast, and dyn_cast.
  132. static bool classof(const Value *V) {
  133. return V->getValueID() == ArgumentVal;
  134. }
  135. };
  136. } // End llvm namespace
  137. #endif
  138. #ifdef __GNUC__
  139. #pragma GCC diagnostic pop
  140. #endif