LLVM 19.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
20namespace llvm {
21
22/// This class represents an incoming formal argument to a Function. A formal
23/// argument, since it is ``formal'', does not contain an actual value but
24/// instead represents the type, argument number, and attributes of an argument
25/// for a specific function. When used in the body of said function, the
26/// argument of course represents the value of the actual argument that the
27/// function was called with.
28class Argument final : public Value {
29 Function *Parent;
30 unsigned ArgNo;
31
32 friend class Function;
33 void setParent(Function *parent);
34
35public:
36 /// Argument constructor.
37 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
38 unsigned ArgNo = 0);
39
40 inline const Function *getParent() const { return Parent; }
41 inline Function *getParent() { return Parent; }
42
43 /// Return the index of this formal argument in its containing function.
44 ///
45 /// For example in "void foo(int a, float b)" a is 0 and b is 1.
46 unsigned getArgNo() const {
47 assert(Parent && "can't get number of unparented arg");
48 return ArgNo;
49 }
50
51 /// Return true if this argument has the nonnull attribute. Also returns true
52 /// if at least one byte is known to be dereferenceable and the pointer is in
53 /// addrspace(0).
54 /// If AllowUndefOrPoison is true, respect the semantics of nonnull attribute
55 /// and return true even if the argument can be undef or poison.
56 bool hasNonNullAttr(bool AllowUndefOrPoison = true) const;
57
58 /// If this argument has the dereferenceable attribute, return the number of
59 /// bytes known to be dereferenceable. Otherwise, zero is returned.
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.
65
66 /// If this argument has nofpclass attribute, return the mask representing
67 /// disallowed floating-point values. Otherwise, fcNone is returned.
69
70 /// Return true if this argument has the byval attribute.
71 bool hasByValAttr() const;
72
73 /// Return true if this argument has the byref attribute.
74 bool hasByRefAttr() const;
75
76 /// Return true if this argument has the swiftself attribute.
77 bool hasSwiftSelfAttr() const;
78
79 /// Return true if this argument has the swifterror attribute.
80 bool hasSwiftErrorAttr() const;
81
82 /// Return true if this argument has the byval, inalloca, or preallocated
83 /// attribute. These attributes represent arguments being passed by value,
84 /// with an associated copy between the caller and callee
86
87 /// If this argument satisfies has hasPassPointeeByValueAttr, return the
88 /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
90
91 /// Return true if this argument has the byval, sret, inalloca, preallocated,
92 /// or byref attribute. These attributes represent arguments being passed by
93 /// value (which may or may not involve a stack copy)
94 bool hasPointeeInMemoryValueAttr() const;
95
96 /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
97 /// returned. Otherwise, nullptr.
99
100 /// If this is a byval or inalloca argument, return its alignment.
101 /// FIXME: Remove this function once transition to Align is over.
102 /// Use getParamAlign() instead.
103 LLVM_DEPRECATED("Use getParamAlign() instead", "getParamAlign")
105
106 /// If this is a byval or inalloca argument, return its alignment.
108
110
111 /// If this is a byval argument, return its type.
113
114 /// If this is an sret argument, return its type.
116
117 /// If this is a byref argument, return its type.
119
120 /// If this is an inalloca argument, return its type.
122
123 /// Return true if this argument has the nest attribute.
124 bool hasNestAttr() const;
125
126 /// Return true if this argument has the noalias attribute.
127 bool hasNoAliasAttr() const;
128
129 /// Return true if this argument has the nocapture attribute.
130 bool hasNoCaptureAttr() const;
131
132 /// Return true if this argument has the nofree attribute.
133 bool hasNoFreeAttr() const;
134
135 /// Return true if this argument has the sret attribute.
136 bool hasStructRetAttr() const;
137
138 /// Return true if this argument has the inreg attribute.
139 bool hasInRegAttr() const;
140
141 /// Return true if this argument has the returned attribute.
142 bool hasReturnedAttr() const;
143
144 /// Return true if this argument has the readonly or readnone attribute.
145 bool onlyReadsMemory() const;
146
147 /// Return true if this argument has the inalloca attribute.
148 bool hasInAllocaAttr() const;
149
150 /// Return true if this argument has the preallocated attribute.
152
153 /// Return true if this argument has the zext attribute.
154 bool hasZExtAttr() const;
155
156 /// Return true if this argument has the sext attribute.
157 bool hasSExtAttr() const;
158
159 /// Add attributes to an argument.
160 void addAttrs(AttrBuilder &B);
161
162 void addAttr(Attribute::AttrKind Kind);
163
164 void addAttr(Attribute Attr);
165
166 /// Remove attributes from an argument.
167 void removeAttr(Attribute::AttrKind Kind);
168
170
171 /// Check if an argument has a given attribute.
172 bool hasAttribute(Attribute::AttrKind Kind) const;
173
174 Attribute getAttribute(Attribute::AttrKind Kind) const;
175
176 /// Method for support type inquiry through isa, cast, and dyn_cast.
177 static bool classof(const Value *V) {
178 return V->getValueID() == ArgumentVal;
179 }
180};
181
182} // End llvm namespace
183
184#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:157
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:28
Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition: Function.cpp:233
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:334
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:264
bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:119
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition: Function.cpp:137
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:249
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:312
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:300
bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition: Function.cpp:170
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:330
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:288
Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition: Function.cpp:228
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:284
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:132
bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition: Function.cpp:156
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:296
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:320
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:200
void removeAttrs(const AttributeMask &AM)
Definition: Function.cpp:324
const Function * getParent() const
Definition: Argument.h:40
Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition: Function.cpp:208
Function * getParent()
Definition: Argument.h:41
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:151
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:147
FPClassTest getNoFPClass() const
If this argument has nofpclass attribute, return the mask representing disallowed floating-point valu...
Definition: Function.cpp:255
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:306
bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition: Function.cpp:274
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:143
Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition: Function.cpp:238
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:292
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:46
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:223
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:259
MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:214
uint64_t getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:177
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:279
bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition: Function.cpp:162
MaybeAlign getParamStackAlign() const
Definition: Function.cpp:219
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:269
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:243
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
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