LLVM  15.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 
20 namespace 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.
28 class Argument final : public Value {
29  Function *Parent;
30  unsigned ArgNo;
31 
32  friend class Function;
33  void setParent(Function *parent);
34 
35 public:
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  /// Return true if this argument has the byval attribute.
67  bool hasByValAttr() const;
68 
69  /// Return true if this argument has the byref attribute.
70  bool hasByRefAttr() const;
71 
72  /// Return true if this argument has the swiftself attribute.
73  bool hasSwiftSelfAttr() const;
74 
75  /// Return true if this argument has the swifterror attribute.
76  bool hasSwiftErrorAttr() const;
77 
78  /// Return true if this argument has the byval, inalloca, or preallocated
79  /// attribute. These attributes represent arguments being passed by value,
80  /// with an associated copy between the caller and callee
81  bool hasPassPointeeByValueCopyAttr() const;
82 
83  /// If this argument satisfies has hasPassPointeeByValueAttr, return the
84  /// in-memory ABI size copied to the stack for the call. Otherwise, return 0.
86 
87  /// Return true if this argument has the byval, sret, inalloca, preallocated,
88  /// or byref attribute. These attributes represent arguments being passed by
89  /// value (which may or may not involve a stack copy)
90  bool hasPointeeInMemoryValueAttr() const;
91 
92  /// If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is
93  /// returned. Otherwise, nullptr.
95 
96  /// If this is a byval or inalloca argument, return its alignment.
97  /// FIXME: Remove this function once transition to Align is over.
98  /// Use getParamAlign() instead.
100 
101  /// If this is a byval or inalloca argument, return its alignment.
102  MaybeAlign getParamAlign() const;
103 
105 
106  /// If this is a byval argument, return its type.
107  Type *getParamByValType() const;
108 
109  /// If this is an sret argument, return its type.
110  Type *getParamStructRetType() const;
111 
112  /// If this is a byref argument, return its type.
113  Type *getParamByRefType() const;
114 
115  /// If this is an inalloca argument, return its type.
116  Type *getParamInAllocaType() const;
117 
118  /// Return true if this argument has the nest attribute.
119  bool hasNestAttr() const;
120 
121  /// Return true if this argument has the noalias attribute.
122  bool hasNoAliasAttr() const;
123 
124  /// Return true if this argument has the nocapture attribute.
125  bool hasNoCaptureAttr() const;
126 
127  /// Return true if this argument has the nofree attribute.
128  bool hasNoFreeAttr() const;
129 
130  /// Return true if this argument has the sret attribute.
131  bool hasStructRetAttr() const;
132 
133  /// Return true if this argument has the inreg attribute.
134  bool hasInRegAttr() const;
135 
136  /// Return true if this argument has the returned attribute.
137  bool hasReturnedAttr() const;
138 
139  /// Return true if this argument has the readonly or readnone attribute.
140  bool onlyReadsMemory() const;
141 
142  /// Return true if this argument has the inalloca attribute.
143  bool hasInAllocaAttr() const;
144 
145  /// Return true if this argument has the preallocated attribute.
146  bool hasPreallocatedAttr() const;
147 
148  /// Return true if this argument has the zext attribute.
149  bool hasZExtAttr() const;
150 
151  /// Return true if this argument has the sext attribute.
152  bool hasSExtAttr() const;
153 
154  /// Add attributes to an argument.
155  void addAttrs(AttrBuilder &B);
156 
158 
159  void addAttr(Attribute Attr);
160 
161  /// Remove attributes from an argument.
163 
164  void removeAttrs(const AttributeMask &AM);
165 
166  /// Check if an argument has a given attribute.
168 
170 
171  /// Method for support type inquiry through isa, cast, and dyn_cast.
172  static bool classof(const Value *V) {
173  return V->getValueID() == ArgumentVal;
174  }
175 };
176 
177 } // End llvm namespace
178 
179 #endif
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
llvm::Argument::hasStructRetAttr
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:257
llvm::Argument::hasInAllocaAttr
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:128
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Argument::hasPassPointeeByValueCopyAttr
bool hasPassPointeeByValueCopyAttr() const
Return true if this argument has the byval, inalloca, or preallocated attribute.
Definition: Function.cpp:139
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::Argument::removeAttrs
void removeAttrs(const AttributeMask &AM)
Definition: Function.cpp:302
llvm::Function
Definition: Function.h:60
llvm::Attribute
Definition: Attributes.h:65
llvm::Argument::hasPointeeInMemoryValueAttr
bool hasPointeeInMemoryValueAttr() const
Return true if this argument has the byval, sret, inalloca, preallocated, or byref attribute.
Definition: Function.cpp:147
llvm::Argument::getParamInAllocaType
Type * getParamInAllocaType() const
If this is an inalloca argument, return its type.
Definition: Function.cpp:220
llvm::Argument::getParamAlignment
uint64_t getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:191
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AttributeMask
Definition: Attributes.h:963
llvm::Argument::getArgNo
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:46
llvm::Argument::hasInRegAttr
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:262
llvm::Argument::getParent
const Function * getParent() const
Definition: Argument.h:40
llvm::Argument::hasSwiftSelfAttr
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:120
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Argument::hasZExtAttr
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:270
llvm::Argument::getParamStackAlign
MaybeAlign getParamStackAlign() const
Definition: Function.cpp:201
Twine.h
llvm::Argument::hasSwiftErrorAttr
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:124
llvm::Argument::hasNoCaptureAttr
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:247
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Value::getValueID
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
llvm::Argument::getDereferenceableBytes
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:225
llvm::Argument::getAttribute
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:312
llvm::Argument::hasNestAttr
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:237
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::Argument::hasByRefAttr
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Definition: Function.cpp:114
llvm::Argument::getDereferenceableOrNullBytes
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:231
llvm::Argument::getParamStructRetType
Type * getParamStructRetType() const
If this is an sret argument, return its type.
Definition: Function.cpp:210
llvm::Argument::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:308
uint64_t
llvm::AttrBuilder
Definition: Attributes.h:1024
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
llvm::Argument::hasNoFreeAttr
bool hasNoFreeAttr() const
Return true if this argument has the nofree attribute.
Definition: Function.cpp:252
llvm::Argument::hasPreallocatedAttr
bool hasPreallocatedAttr() const
Return true if this argument has the preallocated attribute.
Definition: Function.cpp:133
llvm::Argument::removeAttr
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:298
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Argument::classof
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:172
llvm::Argument::Argument
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition: Function.cpp:87
llvm::Argument::getParent
Function * getParent()
Definition: Argument.h:41
llvm::Argument::getParamByRefType
Type * getParamByRefType() const
If this is a byref argument, return its type.
Definition: Function.cpp:215
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Argument::getPassPointeeByValueCopySize
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:177
llvm::Argument::addAttrs
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:284
Attributes.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::Argument::hasNonNullAttr
bool hasNonNullAttr(bool AllowUndefOrPoison=true) const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:96
llvm::Argument::hasByValAttr
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:109
llvm::Argument::getParamByValType
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:205
llvm::Argument::getPointeeInMemoryValueType
Type * getPointeeInMemoryValueType() const
If hasPointeeInMemoryValueAttr returns true, the in-memory ABI type is returned.
Definition: Function.cpp:185
llvm::Argument::hasNoAliasAttr
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:242
llvm::Argument::getParamAlign
MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:196
llvm::Argument::onlyReadsMemory
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:278
Value.h
llvm::Argument::hasSExtAttr
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:274
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::Argument::hasReturnedAttr
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:266
llvm::Argument::addAttr
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:290