Argument.h 6.1 KB

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