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