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 14 #ifndef LLVM_IR_ARGUMENT_H 15 #define LLVM_IR_ARGUMENT_H 16 17 #include "llvm/ADT/Twine.h" 18 #include "llvm/ADT/ilist_node.h" 19 #include "llvm/IR/Attributes.h" 20 #include "llvm/IR/Value.h" 21 22 namespace llvm { 23 24 template <typename NodeTy> class SymbolTableListTraits; 25 26 /// \brief LLVM Argument representation 27 /// 28 /// This class represents an incoming formal argument to a Function. A formal 29 /// argument, since it is ``formal'', does not contain an actual value but 30 /// instead represents the type, argument number, and attributes of an argument 31 /// for a specific function. When used in the body of said function, the 32 /// argument of course represents the value of the actual argument that the 33 /// function was called with. 34 class Argument : public Value, public ilist_node<Argument> { 35 virtual void anchor(); 36 Function *Parent; 37 38 friend class SymbolTableListTraits<Argument>; 39 void setParent(Function *parent); 40 41 public: 42 /// \brief Constructor. 43 /// 44 /// If \p F is specified, the argument is inserted at the end of the argument 45 /// list for \p F. 46 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr); 47 getParent()48 inline const Function *getParent() const { return Parent; } getParent()49 inline Function *getParent() { return Parent; } 50 51 /// \brief Return the index of this formal argument in its containing 52 /// function. 53 /// 54 /// For example in "void foo(int a, float b)" a is 0 and b is 1. 55 unsigned getArgNo() const; 56 57 /// \brief Return true if this argument has the nonnull attribute on it in 58 /// its containing function. Also returns true if at least one byte is known 59 /// to be dereferenceable and the pointer is in addrspace(0). 60 bool hasNonNullAttr() const; 61 62 /// \brief If this argument has the dereferenceable attribute on it in its 63 /// containing function, return the number of bytes known to be 64 /// dereferenceable. Otherwise, zero is returned. 65 uint64_t getDereferenceableBytes() const; 66 67 /// \brief If this argument has the dereferenceable_or_null attribute on 68 /// it in its containing function, return the number of bytes known to be 69 /// dereferenceable. Otherwise, zero is returned. 70 uint64_t getDereferenceableOrNullBytes() const; 71 72 /// \brief Return true if this argument has the byval attribute on it in its 73 /// containing function. 74 bool hasByValAttr() const; 75 76 /// \brief Return true if this argument has the byval attribute or inalloca 77 /// attribute on it in its containing function. These attributes both 78 /// represent arguments being passed by value. 79 bool hasByValOrInAllocaAttr() const; 80 81 /// \brief If this is a byval or inalloca argument, return its alignment. 82 unsigned getParamAlignment() const; 83 84 /// \brief Return true if this argument has the nest attribute on it in its 85 /// containing function. 86 bool hasNestAttr() const; 87 88 /// \brief Return true if this argument has the noalias attribute on it in its 89 /// containing function. 90 bool hasNoAliasAttr() const; 91 92 /// \brief Return true if this argument has the nocapture attribute on it in 93 /// its containing function. 94 bool hasNoCaptureAttr() const; 95 96 /// \brief Return true if this argument has the sret attribute on it in its 97 /// containing function. 98 bool hasStructRetAttr() const; 99 100 /// \brief Return true if this argument has the returned attribute on it in 101 /// its containing function. 102 bool hasReturnedAttr() const; 103 104 /// \brief Return true if this argument has the readonly or readnone attribute 105 /// on it in its containing function. 106 bool onlyReadsMemory() const; 107 108 /// \brief Return true if this argument has the inalloca attribute on it in 109 /// its containing function. 110 bool hasInAllocaAttr() const; 111 112 /// \brief Return true if this argument has the zext attribute on it in its 113 /// containing function. 114 bool hasZExtAttr() const; 115 116 /// \brief Return true if this argument has the sext attribute on it in its 117 /// containing function. 118 bool hasSExtAttr() const; 119 120 /// \brief Add a Attribute to an argument. 121 void addAttr(AttributeSet AS); 122 123 /// \brief Remove a Attribute from an argument. 124 void removeAttr(AttributeSet AS); 125 126 /// \brief Method for support type inquiry through isa, cast, and 127 /// dyn_cast. classof(const Value * V)128 static inline bool classof(const Value *V) { 129 return V->getValueID() == ArgumentVal; 130 } 131 }; 132 133 } // End llvm namespace 134 135 #endif 136