1 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the Argument class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_ARGUMENT_H
15 #define LLVM_IR_ARGUMENT_H
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"
24 template<typename ValueSubClass, typename ItemParentClass>
25 class SymbolTableListTraits;
27 /// \brief LLVM Argument representation
29 /// This class represents an incoming formal argument to a Function. A formal
30 /// argument, since it is ``formal'', does not contain an actual value but
31 /// instead represents the type, argument number, and attributes of an argument
32 /// for a specific function. When used in the body of said function, the
33 /// argument of course represents the value of the actual argument that the
34 /// function was called with.
35 class Argument : public Value, public ilist_node<Argument> {
36 virtual void anchor();
39 friend class SymbolTableListTraits<Argument, Function>;
40 void setParent(Function *parent);
43 /// \brief Constructor.
45 /// If \p F is specified, the argument is inserted at the end of the argument
47 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
49 inline const Function *getParent() const { return Parent; }
50 inline Function *getParent() { return Parent; }
52 /// \brief Return the index of this formal argument in its containing
55 /// For example in "void foo(int a, float b)" a is 0 and b is 1.
56 unsigned getArgNo() const;
58 /// \brief Return true if this argument has the nonnull attribute on it in
59 /// its containing function. Also returns true if at least one byte is known
60 /// to be dereferenceable and the pointer is in addrspace(0).
61 bool hasNonNullAttr() const;
63 /// \brief If this argument has the dereferenceable attribute on it in its
64 /// containing function, return the number of bytes known to be
65 /// dereferenceable. Otherwise, zero is returned.
66 uint64_t getDereferenceableBytes() const;
68 /// \brief Return true if this argument has the byval attribute on it in its
69 /// containing function.
70 bool hasByValAttr() const;
72 /// \brief Return true if this argument has the byval attribute or inalloca
73 /// attribute on it in its containing function. These attributes both
74 /// represent arguments being passed by value.
75 bool hasByValOrInAllocaAttr() const;
77 /// \brief If this is a byval or inalloca argument, return its alignment.
78 unsigned getParamAlignment() const;
80 /// \brief Return true if this argument has the nest attribute on it in its
81 /// containing function.
82 bool hasNestAttr() const;
84 /// \brief Return true if this argument has the noalias attribute on it in its
85 /// containing function.
86 bool hasNoAliasAttr() const;
88 /// \brief Return true if this argument has the nocapture attribute on it in
89 /// its containing function.
90 bool hasNoCaptureAttr() const;
92 /// \brief Return true if this argument has the sret attribute on it in its
93 /// containing function.
94 bool hasStructRetAttr() const;
96 /// \brief Return true if this argument has the returned attribute on it in
97 /// its containing function.
98 bool hasReturnedAttr() const;
100 /// \brief Return true if this argument has the readonly or readnone attribute
101 /// on it in its containing function.
102 bool onlyReadsMemory() const;
104 /// \brief Return true if this argument has the inalloca attribute on it in
105 /// its containing function.
106 bool hasInAllocaAttr() const;
108 /// \brief Return true if this argument has the zext attribute on it in its
109 /// containing function.
110 bool hasZExtAttr() const;
112 /// \brief Return true if this argument has the sext attribute on it in its
113 /// containing function.
114 bool hasSExtAttr() const;
116 /// \brief Add a Attribute to an argument.
117 void addAttr(AttributeSet AS);
119 /// \brief Remove a Attribute from an argument.
120 void removeAttr(AttributeSet AS);
122 /// \brief Method for support type inquiry through isa, cast, and
124 static inline bool classof(const Value *V) {
125 return V->getValueID() == ArgumentVal;
129 } // End llvm namespace