Argument.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares the Argument class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_IR_ARGUMENT_H
  14. #define LLVM_IR_ARGUMENT_H
  15. #include "llvm/ADT/Twine.h"
  16. #include "llvm/ADT/ilist_node.h"
  17. #include "llvm/IR/Attributes.h"
  18. #include "llvm/IR/Value.h"
  19. namespace llvm {
  20. template<typename ValueSubClass, typename ItemParentClass>
  21. class SymbolTableListTraits;
  22. /// \brief LLVM Argument representation
  23. ///
  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 : public Value, public ilist_node<Argument> {
  31. virtual void anchor();
  32. Function *Parent;
  33. friend class SymbolTableListTraits<Argument, Function>;
  34. void setParent(Function *parent);
  35. public:
  36. /// \brief Constructor.
  37. ///
  38. /// If \p F is specified, the argument is inserted at the end of the argument
  39. /// list for \p F.
  40. explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
  41. inline const Function *getParent() const { return Parent; }
  42. inline Function *getParent() { return Parent; }
  43. /// \brief Return the index of this formal argument in its containing
  44. /// function.
  45. ///
  46. /// For example in "void foo(int a, float b)" a is 0 and b is 1.
  47. unsigned getArgNo() const;
  48. /// \brief Return true if this argument has the nonnull attribute on it in
  49. /// its containing function. Also returns true if at least one byte is known
  50. /// to be dereferenceable and the pointer is in addrspace(0).
  51. bool hasNonNullAttr() const;
  52. /// \brief If this argument has the dereferenceable attribute on it in its
  53. /// containing function, return the number of bytes known to be
  54. /// dereferenceable. Otherwise, zero is returned.
  55. uint64_t getDereferenceableBytes() const;
  56. /// \brief If this argument has the dereferenceable_or_null attribute on
  57. /// it in its containing function, return the number of bytes known to be
  58. /// dereferenceable. Otherwise, zero is returned.
  59. uint64_t getDereferenceableOrNullBytes() const;
  60. /// \brief Return true if this argument has the byval attribute on it in its
  61. /// containing function.
  62. bool hasByValAttr() const;
  63. /// \brief Return true if this argument has the byval attribute or inalloca
  64. /// attribute on it in its containing function. These attributes both
  65. /// represent arguments being passed by value.
  66. bool hasByValOrInAllocaAttr() const;
  67. /// \brief If this is a byval or inalloca argument, return its alignment.
  68. unsigned getParamAlignment() const;
  69. /// \brief Return true if this argument has the nest attribute on it in its
  70. /// containing function.
  71. bool hasNestAttr() const;
  72. /// \brief Return true if this argument has the noalias attribute on it in its
  73. /// containing function.
  74. bool hasNoAliasAttr() const;
  75. /// \brief Return true if this argument has the nocapture attribute on it in
  76. /// its containing function.
  77. bool hasNoCaptureAttr() const;
  78. /// \brief Return true if this argument has the sret attribute on it in its
  79. /// containing function.
  80. bool hasStructRetAttr() const;
  81. /// \brief Return true if this argument has the returned attribute on it in
  82. /// its containing function.
  83. bool hasReturnedAttr() const;
  84. /// \brief Return true if this argument has the readonly or readnone attribute
  85. /// on it in its containing function.
  86. bool onlyReadsMemory() const;
  87. /// \brief Return true if this argument has the inalloca attribute on it in
  88. /// its containing function.
  89. bool hasInAllocaAttr() const;
  90. /// \brief Return true if this argument has the zext attribute on it in its
  91. /// containing function.
  92. bool hasZExtAttr() const;
  93. /// \brief Return true if this argument has the sext attribute on it in its
  94. /// containing function.
  95. bool hasSExtAttr() const;
  96. /// \brief Add a Attribute to an argument.
  97. void addAttr(AttributeSet AS);
  98. /// \brief Remove a Attribute from an argument.
  99. void removeAttr(AttributeSet AS);
  100. /// \brief Method for support type inquiry through isa, cast, and
  101. /// dyn_cast.
  102. static inline bool classof(const Value *V) {
  103. return V->getValueID() == ArgumentVal;
  104. }
  105. };
  106. } // End llvm namespace
  107. #endif