LLVM  6.0.0svn
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 /// This class represents an incoming formal argument to a Function. A formal
25 /// argument, since it is ``formal'', does not contain an actual value but
26 /// instead represents the type, argument number, and attributes of an argument
27 /// for a specific function. When used in the body of said function, the
28 /// argument of course represents the value of the actual argument that the
29 /// function was called with.
30 class Argument final : public Value {
31  Function *Parent;
32  unsigned ArgNo;
33 
34  friend class Function;
35  void setParent(Function *parent);
36 
37 public:
38  /// Argument constructor.
39  explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
40  unsigned ArgNo = 0);
41 
42  inline const Function *getParent() const { return Parent; }
43  inline Function *getParent() { return Parent; }
44 
45  /// Return the index of this formal argument in its containing function.
46  ///
47  /// For example in "void foo(int a, float b)" a is 0 and b is 1.
48  unsigned getArgNo() const {
49  assert(Parent && "can't get number of unparented arg");
50  return ArgNo;
51  }
52 
53  /// Return true if this argument has the nonnull attribute. Also returns true
54  /// if at least one byte is known to be dereferenceable and the pointer is in
55  /// addrspace(0).
56  bool hasNonNullAttr() const;
57 
58  /// If this argument has the dereferenceable attribute, return the number of
59  /// bytes known to be dereferenceable. Otherwise, zero is returned.
60  uint64_t getDereferenceableBytes() const;
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.
64  uint64_t getDereferenceableOrNullBytes() const;
65 
66  /// Return true if this argument has the byval attribute.
67  bool hasByValAttr() const;
68 
69  /// Return true if this argument has the swiftself attribute.
70  bool hasSwiftSelfAttr() const;
71 
72  /// Return true if this argument has the swifterror attribute.
73  bool hasSwiftErrorAttr() const;
74 
75  /// Return true if this argument has the byval attribute or inalloca
76  /// attribute. These attributes represent arguments being passed by value.
77  bool hasByValOrInAllocaAttr() const;
78 
79  /// If this is a byval or inalloca argument, return its alignment.
80  unsigned getParamAlignment() const;
81 
82  /// Return true if this argument has the nest attribute.
83  bool hasNestAttr() const;
84 
85  /// Return true if this argument has the noalias attribute.
86  bool hasNoAliasAttr() const;
87 
88  /// Return true if this argument has the nocapture attribute.
89  bool hasNoCaptureAttr() const;
90 
91  /// Return true if this argument has the sret attribute.
92  bool hasStructRetAttr() const;
93 
94  /// Return true if this argument has the returned attribute.
95  bool hasReturnedAttr() const;
96 
97  /// Return true if this argument has the readonly or readnone attribute.
98  bool onlyReadsMemory() const;
99 
100  /// Return true if this argument has the inalloca attribute.
101  bool hasInAllocaAttr() const;
102 
103  /// Return true if this argument has the zext attribute.
104  bool hasZExtAttr() const;
105 
106  /// Return true if this argument has the sext attribute.
107  bool hasSExtAttr() const;
108 
109  /// Add attributes to an argument.
110  void addAttrs(AttrBuilder &B);
111 
113 
114  void addAttr(Attribute Attr);
115 
116  /// Remove attributes from an argument.
117  void removeAttr(Attribute::AttrKind Kind);
118 
119  /// Check if an argument has a given attribute.
120  bool hasAttribute(Attribute::AttrKind Kind) const;
121 
122  /// Method for support type inquiry through isa, cast, and dyn_cast.
123  static bool classof(const Value *V) {
124  return V->getValueID() == ArgumentVal;
125  }
126 };
127 
128 } // End llvm namespace
129 
130 #endif
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:130
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:186
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:459
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:124
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:182
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition: Function.cpp:69
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute.
Definition: Function.cpp:106
static bool classof(const Value *V)
Method for support type inquiry through isa, cast, and dyn_cast.
Definition: Argument.h:123
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:168
Function * getParent()
Definition: Argument.h:43
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:88
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This file contains the simple types necessary to represent the attributes associated with functions a...
#define F(x, y, z)
Definition: MD5.cpp:55
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:162
const char * Name
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:135
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:174
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:78
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:145
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:158
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:150
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:101
#define B
Definition: LargeTest.cpp:24
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:113
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:93
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:48
const Function * getParent() const
Definition: Argument.h:42
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:97
const unsigned Kind
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:154
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:140
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:118
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70