LLVM  4.0.0
Argument.h
Go to the documentation of this file.
1 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Argument class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_ARGUMENT_H
15 #define LLVM_IR_ARGUMENT_H
16 
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/Value.h"
21 
22 namespace llvm {
23 
24 template <typename NodeTy> class SymbolTableListTraits;
25 
26 /// \brief LLVM Argument representation
27 ///
28 /// This class represents an incoming formal argument to a Function. A formal
29 /// argument, since it is ``formal'', does not contain an actual value but
30 /// instead represents the type, argument number, and attributes of an argument
31 /// for a specific function. When used in the body of said function, the
32 /// argument of course represents the value of the actual argument that the
33 /// function was called with.
34 class Argument : public Value, public ilist_node<Argument> {
35  virtual void anchor();
36  Function *Parent;
37 
39  void setParent(Function *parent);
40 
41 public:
42  /// \brief Constructor.
43  ///
44  /// If \p F is specified, the argument is inserted at the end of the argument
45  /// list for \p F.
46  explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
47 
48  inline const Function *getParent() const { return Parent; }
49  inline Function *getParent() { return Parent; }
50 
51  /// \brief Return the index of this formal argument in its containing
52  /// function.
53  ///
54  /// For example in "void foo(int a, float b)" a is 0 and b is 1.
55  unsigned getArgNo() const;
56 
57  /// \brief Return true if this argument has the nonnull attribute on it in
58  /// its containing function. Also returns true if at least one byte is known
59  /// to be dereferenceable and the pointer is in addrspace(0).
60  bool hasNonNullAttr() const;
61 
62  /// \brief If this argument has the dereferenceable attribute on it in its
63  /// containing function, return the number of bytes known to be
64  /// dereferenceable. Otherwise, zero is returned.
65  uint64_t getDereferenceableBytes() const;
66 
67  /// \brief If this argument has the dereferenceable_or_null attribute on
68  /// it in its containing function, return the number of bytes known to be
69  /// dereferenceable. Otherwise, zero is returned.
70  uint64_t getDereferenceableOrNullBytes() const;
71 
72  /// \brief Return true if this argument has the byval attribute on it in its
73  /// containing function.
74  bool hasByValAttr() const;
75 
76  /// \brief Return true if this argument has the swiftself attribute.
77  bool hasSwiftSelfAttr() const;
78 
79  /// \brief Return true if this argument has the swifterror attribute.
80  bool hasSwiftErrorAttr() const;
81 
82  /// \brief Return true if this argument has the byval attribute or inalloca
83  /// attribute on it in its containing function. These attributes both
84  /// represent arguments being passed by value.
85  bool hasByValOrInAllocaAttr() const;
86 
87  /// \brief If this is a byval or inalloca argument, return its alignment.
88  unsigned getParamAlignment() const;
89 
90  /// \brief Return true if this argument has the nest attribute on it in its
91  /// containing function.
92  bool hasNestAttr() const;
93 
94  /// \brief Return true if this argument has the noalias attribute on it in its
95  /// containing function.
96  bool hasNoAliasAttr() const;
97 
98  /// \brief Return true if this argument has the nocapture attribute on it in
99  /// its containing function.
100  bool hasNoCaptureAttr() const;
101 
102  /// \brief Return true if this argument has the sret attribute on it in its
103  /// containing function.
104  bool hasStructRetAttr() const;
105 
106  /// \brief Return true if this argument has the returned attribute on it in
107  /// its containing function.
108  bool hasReturnedAttr() const;
109 
110  /// \brief Return true if this argument has the readonly or readnone attribute
111  /// on it in its containing function.
112  bool onlyReadsMemory() const;
113 
114  /// \brief Return true if this argument has the inalloca attribute on it in
115  /// its containing function.
116  bool hasInAllocaAttr() const;
117 
118  /// \brief Return true if this argument has the zext attribute on it in its
119  /// containing function.
120  bool hasZExtAttr() const;
121 
122  /// \brief Return true if this argument has the sext attribute on it in its
123  /// containing function.
124  bool hasSExtAttr() const;
125 
126  /// \brief Add a Attribute to an argument.
127  void addAttr(AttributeSet AS);
128 
130  addAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind));
131  }
132 
133  /// \brief Remove a Attribute from an argument.
134  void removeAttr(AttributeSet AS);
135 
137  removeAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind));
138  }
139 
140  /// \brief Checks if an argument has a given attribute.
142 
143  /// \brief Method for support type inquiry through isa, cast, and
144  /// dyn_cast.
145  static inline bool classof(const Value *V) {
146  return V->getValueID() == ArgumentVal;
147  }
148 };
149 
150 } // End llvm namespace
151 
152 #endif
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute on it in its containing function.
Definition: Function.cpp:148
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute on it in its containing function.
Definition: Function.cpp:141
LLVM Argument representation.
Definition: Argument.h:34
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute on it in its containing function...
Definition: Function.cpp:180
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute on it in its containing fu...
Definition: Function.cpp:107
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:145
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:90
Function * getParent()
Definition: Argument.h:49
void addAttr(AttributeSet AS)
Add a Attribute to an argument.
Definition: Function.cpp:188
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:95
This file contains the simple types necessary to represent the attributes associated with functions a...
uint64_t getDereferenceableOrNullBytes() const
If this argument has the dereferenceable_or_null attribute on it in its containing function...
Definition: Function.cpp:126
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute on it in its containing function, return the number of bytes known to be dereferenceable.
Definition: Function.cpp:120
void removeAttr(AttributeSet AS)
Remove a Attribute from an argument.
Definition: Function.cpp:198
#define F(x, y, z)
Definition: MD5.cpp:51
bool hasStructRetAttr() const
Return true if this argument has the sret attribute on it in its containing function.
Definition: Function.cpp:155
bool hasNestAttr() const
Return true if this argument has the nest attribute on it in its containing function.
Definition: Function.cpp:134
void addAttr(Attribute::AttrKind Kind)
Definition: Argument.h:129
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
const Function * getParent() const
Definition: Argument.h:48
bool hasAttribute(Attribute::AttrKind Kind) const
Checks if an argument has a given attribute.
Definition: Function.cpp:208
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute on it in its containing function.
Definition: Function.cpp:102
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:114
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:434
bool hasSExtAttr() const
Return true if this argument has the sext attribute on it in its containing function.
Definition: Function.cpp:174
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
void removeAttr(Attribute::AttrKind Kind)
Definition: Argument.h:136
bool hasByValAttr() const
Return true if this argument has the byval attribute on it in its containing function.
Definition: Function.cpp:85
bool hasZExtAttr() const
Return true if this argument has the zext attribute on it in its containing function.
Definition: Function.cpp:168
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr)
Constructor.
Definition: Function.cpp:42
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute on it in its containing function.
Definition: Function.cpp:72
const unsigned Kind
LLVM Value Representation.
Definition: Value.h:71
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Function.cpp:57
bool hasReturnedAttr() const
Return true if this argument has the returned attribute on it in its containing function.
Definition: Function.cpp:162
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67