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 /// 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 {
31 virtual void anchor();
35 friend class Function;
36 void setParent(Function *parent);
39 /// Argument constructor.
40 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
43 inline const Function *getParent() const { return Parent; }
44 inline Function *getParent() { return Parent; }
46 /// Return the index of this formal argument in its containing function.
48 /// For example in "void foo(int a, float b)" a is 0 and b is 1.
49 unsigned getArgNo() const {
50 assert(Parent && "can't get number of unparented arg");
54 /// Return true if this argument has the nonnull attribute. Also returns true
55 /// if at least one byte is known to be dereferenceable and the pointer is in
57 bool hasNonNullAttr() const;
59 /// If this argument has the dereferenceable attribute, return the number of
60 /// bytes known to be dereferenceable. Otherwise, zero is returned.
61 uint64_t getDereferenceableBytes() const;
63 /// If this argument has the dereferenceable_or_null attribute, return the
64 /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
65 uint64_t getDereferenceableOrNullBytes() const;
67 /// Return true if this argument has the byval attribute.
68 bool hasByValAttr() const;
70 /// Return true if this argument has the swiftself attribute.
71 bool hasSwiftSelfAttr() const;
73 /// Return true if this argument has the swifterror attribute.
74 bool hasSwiftErrorAttr() const;
76 /// Return true if this argument has the byval attribute or inalloca
77 /// attribute. These attributes represent arguments being passed by value.
78 bool hasByValOrInAllocaAttr() const;
80 /// If this is a byval or inalloca argument, return its alignment.
81 unsigned getParamAlignment() const;
83 /// Return true if this argument has the nest attribute.
84 bool hasNestAttr() const;
86 /// Return true if this argument has the noalias attribute.
87 bool hasNoAliasAttr() const;
89 /// Return true if this argument has the nocapture attribute.
90 bool hasNoCaptureAttr() const;
92 /// Return true if this argument has the sret attribute.
93 bool hasStructRetAttr() const;
95 /// Return true if this argument has the returned attribute.
96 bool hasReturnedAttr() const;
98 /// Return true if this argument has the readonly or readnone attribute.
99 bool onlyReadsMemory() const;
101 /// Return true if this argument has the inalloca attribute.
102 bool hasInAllocaAttr() const;
104 /// Return true if this argument has the zext attribute.
105 bool hasZExtAttr() const;
107 /// Return true if this argument has the sext attribute.
108 bool hasSExtAttr() const;
110 /// Add attributes to an argument.
111 void addAttrs(AttrBuilder &B);
113 void addAttr(Attribute::AttrKind Kind);
115 void addAttr(Attribute Attr);
117 /// Remove attributes from an argument.
118 void removeAttr(AttributeList AS);
120 void removeAttr(Attribute::AttrKind Kind);
122 /// Check if an argument has a given attribute.
123 bool hasAttribute(Attribute::AttrKind Kind) const;
125 /// Method for support type inquiry through isa, cast, and dyn_cast.
126 static inline bool classof(const Value *V) {
127 return V->getValueID() == ArgumentVal;
131 } // End llvm namespace