LLVM  10.0.0svn
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/ADT/ilist_node.h"
18 #include "llvm/IR/Attributes.h"
19 #include "llvm/IR/Value.h"
20 
21 namespace llvm {
22 
23 /// This class represents an incoming formal argument to a Function. A formal
24 /// argument, since it is ``formal'', does not contain an actual value but
25 /// instead represents the type, argument number, and attributes of an argument
26 /// for a specific function. When used in the body of said function, the
27 /// argument of course represents the value of the actual argument that the
28 /// function was called with.
29 class Argument final : public Value {
30  Function *Parent;
31  unsigned ArgNo;
32 
33  friend class Function;
34  void setParent(Function *parent);
35 
36 public:
37  /// Argument constructor.
38  explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
39  unsigned ArgNo = 0);
40 
41  inline const Function *getParent() const { return Parent; }
42  inline Function *getParent() { return Parent; }
43 
44  /// Return the index of this formal argument in its containing function.
45  ///
46  /// For example in "void foo(int a, float b)" a is 0 and b is 1.
47  unsigned getArgNo() const {
48  assert(Parent && "can't get number of unparented arg");
49  return ArgNo;
50  }
51 
52  /// Return true if this argument has the nonnull attribute. Also returns true
53  /// if at least one byte is known to be dereferenceable and the pointer is in
54  /// addrspace(0).
55  bool hasNonNullAttr() const;
56 
57  /// If this argument has the dereferenceable attribute, return the number of
58  /// bytes known to be dereferenceable. Otherwise, zero is returned.
59  uint64_t getDereferenceableBytes() const;
60 
61  /// If this argument has the dereferenceable_or_null attribute, return the
62  /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
63  uint64_t getDereferenceableOrNullBytes() const;
64 
65  /// Return true if this argument has the byval attribute.
66  bool hasByValAttr() const;
67 
68  /// Return true if this argument has the swiftself attribute.
69  bool hasSwiftSelfAttr() const;
70 
71  /// Return true if this argument has the swifterror attribute.
72  bool hasSwiftErrorAttr() const;
73 
74  /// Return true if this argument has the byval attribute or inalloca
75  /// attribute. These attributes represent arguments being passed by value.
76  bool hasByValOrInAllocaAttr() const;
77 
78  /// If this is a byval or inalloca argument, return its alignment.
79  unsigned getParamAlignment() const;
80 
81  /// If this is a byval argument, return its type.
82  Type *getParamByValType() const;
83 
84  /// Return true if this argument has the nest attribute.
85  bool hasNestAttr() const;
86 
87  /// Return true if this argument has the noalias attribute.
88  bool hasNoAliasAttr() const;
89 
90  /// Return true if this argument has the nocapture attribute.
91  bool hasNoCaptureAttr() const;
92 
93  /// Return true if this argument has the sret attribute.
94  bool hasStructRetAttr() const;
95 
96  /// Return true if this argument has the inreg attribute.
97  bool hasInRegAttr() const;
98 
99  /// Return true if this argument has the returned attribute.
100  bool hasReturnedAttr() const;
101 
102  /// Return true if this argument has the readonly or readnone attribute.
103  bool onlyReadsMemory() const;
104 
105  /// Return true if this argument has the inalloca attribute.
106  bool hasInAllocaAttr() const;
107 
108  /// Return true if this argument has the zext attribute.
109  bool hasZExtAttr() const;
110 
111  /// Return true if this argument has the sext attribute.
112  bool hasSExtAttr() const;
113 
114  /// Add attributes to an argument.
115  void addAttrs(AttrBuilder &B);
116 
118 
119  void addAttr(Attribute Attr);
120 
121  /// Remove attributes from an argument.
122  void removeAttr(Attribute::AttrKind Kind);
123 
124  /// Check if an argument has a given attribute.
125  bool hasAttribute(Attribute::AttrKind Kind) const;
126 
128 
129  /// Method for support type inquiry through isa, cast, and dyn_cast.
130  static bool classof(const Value *V) {
131  return V->getValueID() == ArgumentVal;
132  }
133 };
134 
135 } // End llvm namespace
136 
137 #endif
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:133
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:193
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:483
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:127
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:189
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition: Function.cpp:66
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute.
Definition: Function.cpp:104
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:130
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:175
F(f)
Function * getParent()
Definition: Argument.h:42
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:86
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:116
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
This file contains the simple types necessary to represent the attributes associated with functions a...
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:169
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:138
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:181
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:75
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:148
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:165
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:157
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:99
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:111
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:91
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:47
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:153
const Function * getParent() const
Definition: Argument.h:41
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:95
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:161
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:143
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:197
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:121
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70