LLVM  3.7.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 ValueSubClass, typename ItemParentClass>
26 
27 /// \brief LLVM Argument representation
28 ///
29 /// This class represents an incoming formal argument to a Function. A formal
30 /// argument, since it is ``formal'', does not contain an actual value but
31 /// instead represents the type, argument number, and attributes of an argument
32 /// for a specific function. When used in the body of said function, the
33 /// argument of course represents the value of the actual argument that the
34 /// function was called with.
35 class Argument : public Value, public ilist_node<Argument> {
36  virtual void anchor();
37  Function *Parent;
38 
40  void setParent(Function *parent);
41 
42 public:
43  /// \brief Constructor.
44  ///
45  /// If \p F is specified, the argument is inserted at the end of the argument
46  /// list for \p F.
47  explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
48 
49  inline const Function *getParent() const { return Parent; }
50  inline Function *getParent() { return Parent; }
51 
52  /// \brief Return the index of this formal argument in its containing
53  /// function.
54  ///
55  /// For example in "void foo(int a, float b)" a is 0 and b is 1.
56  unsigned getArgNo() const;
57 
58  /// \brief Return true if this argument has the nonnull attribute on it in
59  /// its containing function. Also returns true if at least one byte is known
60  /// to be dereferenceable and the pointer is in addrspace(0).
61  bool hasNonNullAttr() const;
62 
63  /// \brief If this argument has the dereferenceable attribute on it in its
64  /// containing function, return the number of bytes known to be
65  /// dereferenceable. Otherwise, zero is returned.
66  uint64_t getDereferenceableBytes() const;
67 
68  /// \brief If this argument has the dereferenceable_or_null attribute on
69  /// it in its containing function, return the number of bytes known to be
70  /// dereferenceable. Otherwise, zero is returned.
71  uint64_t getDereferenceableOrNullBytes() const;
72 
73  /// \brief Return true if this argument has the byval attribute on it in its
74  /// containing function.
75  bool hasByValAttr() const;
76 
77  /// \brief Return true if this argument has the byval attribute or inalloca
78  /// attribute on it in its containing function. These attributes both
79  /// represent arguments being passed by value.
80  bool hasByValOrInAllocaAttr() const;
81 
82  /// \brief If this is a byval or inalloca argument, return its alignment.
83  unsigned getParamAlignment() const;
84 
85  /// \brief Return true if this argument has the nest attribute on it in its
86  /// containing function.
87  bool hasNestAttr() const;
88 
89  /// \brief Return true if this argument has the noalias attribute on it in its
90  /// containing function.
91  bool hasNoAliasAttr() const;
92 
93  /// \brief Return true if this argument has the nocapture attribute on it in
94  /// its containing function.
95  bool hasNoCaptureAttr() const;
96 
97  /// \brief Return true if this argument has the sret attribute on it in its
98  /// containing function.
99  bool hasStructRetAttr() const;
100 
101  /// \brief Return true if this argument has the returned attribute on it in
102  /// its containing function.
103  bool hasReturnedAttr() const;
104 
105  /// \brief Return true if this argument has the readonly or readnone attribute
106  /// on it in its containing function.
107  bool onlyReadsMemory() const;
108 
109  /// \brief Return true if this argument has the inalloca attribute on it in
110  /// its containing function.
111  bool hasInAllocaAttr() const;
112 
113  /// \brief Return true if this argument has the zext attribute on it in its
114  /// containing function.
115  bool hasZExtAttr() const;
116 
117  /// \brief Return true if this argument has the sext attribute on it in its
118  /// containing function.
119  bool hasSExtAttr() const;
120 
121  /// \brief Add a Attribute to an argument.
122  void addAttr(AttributeSet AS);
123 
124  /// \brief Remove a Attribute from an argument.
125  void removeAttr(AttributeSet AS);
126 
127  /// \brief Method for support type inquiry through isa, cast, and
128  /// dyn_cast.
129  static inline bool classof(const Value *V) {
130  return V->getValueID() == ArgumentVal;
131  }
132 };
133 
134 } // End llvm namespace
135 
136 #endif
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute on it in its containing function.
Definition: Function.cpp:147
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute on it in its containing function.
Definition: Function.cpp:139
LLVM Argument representation.
Definition: Argument.h:35
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute on it in its containing function...
Definition: Function.cpp:184
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute on it in its containing fu...
Definition: Function.cpp:104
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:129
F(f)
Function * getParent()
Definition: Argument.h:50
void addAttr(AttributeSet AS)
Add a Attribute to an argument.
Definition: Function.cpp:192
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
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:123
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:117
void removeAttr(AttributeSet AS)
Remove a Attribute from an argument.
Definition: Function.cpp:202
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:131
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:49
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute on it in its containing function.
Definition: Function.cpp:98
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:111
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:362
bool hasSExtAttr() const
Return true if this argument has the sext attribute on it in its containing function.
Definition: Function.cpp:177
bool hasByValAttr() const
Return true if this argument has the byval attribute on it in its containing function.
Definition: Function.cpp:90
bool hasZExtAttr() const
Return true if this argument has the zext attribute on it in its containing function.
Definition: Function.cpp:170
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr)
Constructor.
Definition: Function.cpp:47
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute on it in its containing function.
Definition: Function.cpp:77
ilist_node - Base class that provides next/prev services for nodes that use ilist_nextprev_traits or ...
Definition: ilist_node.h:43
LLVM Value Representation.
Definition: Value.h:69
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Function.cpp:62
bool hasReturnedAttr() const
Return true if this argument has the returned attribute on it in its containing function.
Definition: Function.cpp:163