LLVM 22.0.0git
Argument.h
Go to the documentation of this file.
1//===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the Argument class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_ARGUMENT_H
14#define LLVM_IR_ARGUMENT_H
15
16#include "llvm/ADT/Twine.h"
17#include "llvm/IR/Attributes.h"
18#include "llvm/IR/Value.h"
20#include <optional>
21
22namespace llvm {
23
24class ConstantRange;
25
26/// This class represents an incoming formal argument to a Function. A formal
27/// argument, since it is ``formal'', does not contain an actual value but
28/// instead represents the type, argument number, and attributes of an argument
29/// for a specific function. When used in the body of said function, the
30/// argument of course represents the value of the actual argument that the
31/// function was called with.
32class Argument final : public Value {
33 Function *Parent;
34 unsigned ArgNo;
35
36 friend class Function;
37 void setParent(Function *parent);
38
39public:
40 /// Argument constructor.
41 LLVM_ABI explicit Argument(Type *Ty, const Twine &Name = "",
42 Function *F = nullptr, unsigned ArgNo = 0);
43
44 inline const Function *getParent() const { return Parent; }
45 inline Function *getParent() { return Parent; }
46
47 /// Return the index of this formal argument in its containing function.
48 ///
49 /// For example in "void foo(int a, float b)" a is 0 and b is 1.
50 unsigned getArgNo() const {
51 assert(Parent && "can't get number of unparented arg");
52 return ArgNo;
53 }
54
55 /// Return true if this argument has the nonnull attribute. Also returns true
56 /// if at least one byte is known to be dereferenceable and the pointer is in
57 /// addrspace(0).
58 /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
59 /// and return true even if the argument can be undef or poison.
60 LLVM_ABI bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
61
62 /// If this argument has the dereferenceable attribute, return the number of
63 /// bytes known to be dereferenceable. Otherwise, zero is returned.
65
66 /// If this argument has the dereferenceable_or_null attribute, return the
67 /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
69
70 /// If this argument has nofpclass attribute, return the mask representing
71 /// disallowed floating-point values. Otherwise, fcNone is returned.
73
74 /// If this argument has a range attribute, return the value range of the
75 /// argument. Otherwise, std::nullopt is returned.
76 LLVM_ABI std::optional<ConstantRange> getRange() const;
77
78 /// Return true if this argument has the byval attribute.
79 LLVM_ABI bool hasByValAttr() const;
80
81 /// Return true if this argument has the dead_on_return attribute.
82 LLVM_ABI bool hasDeadOnReturnAttr() const;
83
84 /// Return true if this argument has the byref attribute.
85 LLVM_ABI bool hasByRefAttr() const;
86
87 /// Return true if this argument has the swiftself attribute.
88 LLVM_ABI bool hasSwiftSelfAttr() const;
89
90 /// Return true if this argument has the swifterror attribute.
91 LLVM_ABI bool hasSwiftErrorAttr() const;
92
93 /// Return true if this argument has the byval, inalloca, or preallocated
94 /// attribute. These attributes represent arguments being passed by value,
95 /// with an associated copy between the caller and callee
97
98 /// If this argument satisfies has hasPassPointeeByValueAttr, return the
99 /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
101
102 /// Return true if this argument has the byval, sret, inalloca, preallocated,
103 /// or byref attribute. These attributes represent arguments being passed by
104 /// value (which may or may not involve a stack copy)
106
107 /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
108 /// returned. Otherwise, nullptr.
110
111 /// If this is a byval or inalloca argument, return its alignment.
112 /// FIXME: Remove this function once transition to Align is over.
113 /// Use getParamAlign() instead.
114 LLVM_ABI LLVM_DEPRECATED("Use getParamAlign() instead",
115 "getParamAlign") uint64_t getParamAlignment() const;
116
117 /// If this is a byval or inalloca argument, return its alignment.
119
121
122 /// If this is a byval argument, return its type.
124
125 /// If this is an sret argument, return its type.
127
128 /// If this is a byref argument, return its type.
130
131 /// If this is an inalloca argument, return its type.
133
134 /// Return true if this argument has the nest attribute.
136
137 /// Return true if this argument has the noalias attribute.
139
140 /// Return true if this argument has the nocapture attribute.
142
143 /// Return true if this argument has the nofree attribute.
145
146 /// Return true if this argument has the sret attribute.
148
149 /// Return true if this argument has the inreg attribute.
151
152 /// Return true if this argument has the returned attribute.
154
155 /// Return true if this argument has the readonly or readnone attribute.
157
158 /// Return true if this argument has the inalloca attribute.
160
161 /// Return true if this argument has the preallocated attribute.
163
164 /// Return true if this argument has the zext attribute.
166
167 /// Return true if this argument has the sext attribute.
169
170 /// Add attributes to an argument.
172
173 LLVM_ABI void addAttr(Attribute::AttrKind Kind);
174
175 LLVM_ABI void addAttr(Attribute Attr);
176
177 /// Remove attributes from an argument.
178 LLVM_ABI void removeAttr(Attribute::AttrKind Kind);
179
181
182 /// Check if an argument has a given attribute.
183 LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const;
184
186
188
190
191 /// Method for support type inquiry through isa, cast, and dyn_cast.
192 static bool classof(const Value *V) {
193 return V->getValueID() == ArgumentVal;
194 }
195};
196
197} // End llvm namespace
198
199#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
This class represents an incoming formal argument to a Function.
Definition: Argument.h:32
LLVM_ABI Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition: Function.cpp:235
LLVM_ABI LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign") uint64_t getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
LLVM_ABI bool hasDeadOnReturnAttr() const
Return true if this argument has the dead_on_return attribute.
Definition: Function.cpp:133
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:347
LLVM_ABI bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:273
LLVM_ABI bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:115
LLVM_ABI bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition: Function.cpp:139
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const
If this argument has the dereferenceable_or_null attribute, return the number of bytes known to be de...
Definition: Function.cpp:251
LLVM_ABI void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:321
LLVM_ABI bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:309
LLVM_ABI bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition: Function.cpp:172
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:339
LLVM_ABI bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:297
LLVM_ABI Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition: Function.cpp:230
LLVM_ABI bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:293
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:128
LLVM_ABI bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition: Function.cpp:158
LLVM_ABI bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:305
LLVM_ABI void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:329
LLVM_ABI uint64_t getPassPointeeByValueCopySize(const DataLayout &DL) const
If this argument satisfies has hasPassPointeeByValueAttr, return the in-memory ABI size copied to the...
Definition: Function.cpp:202
LLVM_ABI void removeAttrs(const AttributeMask &AM)
Definition: Function.cpp:333
const Function * getParent() const
Definition: Argument.h:44
LLVM_ABI Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition: Function.cpp:210
Function * getParent()
Definition: Argument.h:45
LLVM_ABI bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:153
LLVM_ABI bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:149
LLVM_ABI FPClassTest getNoFPClass() const
If this argument has nofpclass attribute, return the mask representing disallowed floating-point valu...
Definition: Function.cpp:257
LLVM_ABI void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:315
LLVM_ABI bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition: Function.cpp:283
LLVM_ABI bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:145
LLVM_ABI Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition: Function.cpp:240
LLVM_ABI bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:301
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:50
LLVM_ABI Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:225
LLVM_ABI bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:268
LLVM_ABI MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:216
LLVM_ABI std::optional< ConstantRange > getRange() const
If this argument has a range attribute, return the value range of the argument.
Definition: Function.cpp:261
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:192
LLVM_ABI bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:288
LLVM_ABI AttributeSet getAttributes() const
Definition: Function.cpp:351
LLVM_ABI bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition: Function.cpp:164
LLVM_ABI MaybeAlign getParamStackAlign() const
Definition: Function.cpp:221
LLVM_ABI bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:278
LLVM_ABI uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:245
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117