LLVM 20.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"
19#include <optional>
20
21namespace llvm {
22
23class ConstantRange;
24
25/// This class represents an incoming formal argument to a Function. A formal
26/// argument, since it is ``formal'', does not contain an actual value but
27/// instead represents the type, argument number, and attributes of an argument
28/// for a specific function. When used in the body of said function, the
29/// argument of course represents the value of the actual argument that the
30/// function was called with.
31class Argument final : public Value {
32 Function *Parent;
33 unsigned ArgNo;
34
35 friend class Function;
36 void setParent(Function *parent);
37
38public:
39 /// Argument constructor.
40 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
41 unsigned ArgNo = 0);
42
43 inline const Function *getParent() const { return Parent; }
44 inline Function *getParent() { return Parent; }
45
46 /// Return the index of this formal argument in its containing function.
47 ///
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");
51 return ArgNo;
52 }
53
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
56 /// addrspace(0).
57 /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
58 /// and return true even if the argument can be undef or poison.
59 bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
60
61 /// If this argument has the dereferenceable attribute, return the number of
62 /// bytes known to be dereferenceable. Otherwise, zero is returned.
64
65 /// If this argument has the dereferenceable_or_null attribute, return the
66 /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
68
69 /// If this argument has nofpclass attribute, return the mask representing
70 /// disallowed floating-point values. Otherwise, fcNone is returned.
72
73 /// If this argument has a range attribute, return the value range of the
74 /// argument. Otherwise, std::nullopt is returned.
75 std::optional<ConstantRange> getRange() const;
76
77 /// Return true if this argument has the byval attribute.
78 bool hasByValAttr() const;
79
80 /// Return true if this argument has the byref attribute.
81 bool hasByRefAttr() const;
82
83 /// Return true if this argument has the swiftself attribute.
84 bool hasSwiftSelfAttr() const;
85
86 /// Return true if this argument has the swifterror attribute.
87 bool hasSwiftErrorAttr() const;
88
89 /// Return true if this argument has the byval, inalloca, or preallocated
90 /// attribute. These attributes represent arguments being passed by value,
91 /// with an associated copy between the caller and callee
93
94 /// If this argument satisfies has hasPassPointeeByValueAttr, return the
95 /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
97
98 /// Return true if this argument has the byval, sret, inalloca, preallocated,
99 /// or byref attribute. These attributes represent arguments being passed by
100 /// value (which may or may not involve a stack copy)
101 bool hasPointeeInMemoryValueAttr() const;
102
103 /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
104 /// returned. Otherwise, nullptr.
106
107 /// If this is a byval or inalloca argument, return its alignment.
108 /// FIXME: Remove this function once transition to Align is over.
109 /// Use getParamAlign() instead.
110 LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
112
113 /// If this is a byval or inalloca argument, return its alignment.
115
117
118 /// If this is a byval argument, return its type.
120
121 /// If this is an sret argument, return its type.
123
124 /// If this is a byref argument, return its type.
126
127 /// If this is an inalloca argument, return its type.
129
130 /// Return true if this argument has the nest attribute.
131 bool hasNestAttr() const;
132
133 /// Return true if this argument has the noalias attribute.
134 bool hasNoAliasAttr() const;
135
136 /// Return true if this argument has the nocapture attribute.
137 bool hasNoCaptureAttr() const;
138
139 /// Return true if this argument has the nofree attribute.
140 bool hasNoFreeAttr() const;
141
142 /// Return true if this argument has the sret attribute.
143 bool hasStructRetAttr() const;
144
145 /// Return true if this argument has the inreg attribute.
146 bool hasInRegAttr() const;
147
148 /// Return true if this argument has the returned attribute.
149 bool hasReturnedAttr() const;
150
151 /// Return true if this argument has the readonly or readnone attribute.
152 bool onlyReadsMemory() const;
153
154 /// Return true if this argument has the inalloca attribute.
155 bool hasInAllocaAttr() const;
156
157 /// Return true if this argument has the preallocated attribute.
159
160 /// Return true if this argument has the zext attribute.
161 bool hasZExtAttr() const;
162
163 /// Return true if this argument has the sext attribute.
164 bool hasSExtAttr() const;
165
166 /// Add attributes to an argument.
167 void addAttrs(AttrBuilder &B);
168
169 void addAttr(Attribute::AttrKind Kind);
170
171 void addAttr(Attribute Attr);
172
173 /// Remove attributes from an argument.
174 void removeAttr(Attribute::AttrKind Kind);
175
177
178 /// Check if an argument has a given attribute.
179 bool hasAttribute(Attribute::AttrKind Kind) const;
180
181 Attribute getAttribute(Attribute::AttrKind Kind) const;
182
183 /// Method for support type inquiry through isa, cast, and dyn_cast.
184 static bool classof(const Value *V) {
185 return V->getValueID() == ArgumentVal;
186 }
187};
188
189} // End llvm namespace
190
191#endif
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_DEPRECATED(MSG, FIX)
Definition: Compiler.h:153
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition: Function.cpp:264
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:372
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:302
bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:150
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition: Function.cpp:168
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:280
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:350
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:338
bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition: Function.cpp:201
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:368
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:326
Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition: Function.cpp:259
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:322
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:163
bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition: Function.cpp:187
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:334
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:358
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:231
void removeAttrs(const AttributeMask &AM)
Definition: Function.cpp:362
const Function * getParent() const
Definition: Argument.h:43
Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition: Function.cpp:239
Function * getParent()
Definition: Argument.h:44
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:182
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:178
FPClassTest getNoFPClass() const
If this argument has nofpclass attribute, return the mask representing disallowed floating-point valu...
Definition: Function.cpp:286
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:344
bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition: Function.cpp:312
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:174
Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition: Function.cpp:269
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:330
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:49
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:254
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:297
MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:245
uint64_t getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
std::optional< ConstantRange > getRange() const
If this argument has a range attribute, return the value range of the argument.
Definition: Function.cpp:290
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:184
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:317
bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition: Function.cpp:193
MaybeAlign getParamStackAlign() const
Definition: Function.cpp:250
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:307
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:274
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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:74
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