]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/Argument.h
Merge ^/head r317216 through r317280.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / Argument.h
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 : public Value {
31   virtual void anchor();
32   Function *Parent;
33   unsigned ArgNo;
34
35   friend class Function;
36   void setParent(Function *parent);
37
38 public:
39   /// Argument constructor.
40   explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
41                     unsigned ArgNo = 0);
42
43   inline const Function *getParent() const { return Parent; }
44   inline       Function *getParent()       { return Parent; }
45
46   /// Return the index of this formal argument in its containing function.
47   ///
48   /// For example in "void foo(int a, float b)" a is 0 and b is 1.
49   unsigned getArgNo() const {
50     assert(Parent && "can't get number of unparented arg");
51     return ArgNo;
52   }
53
54   /// Return true if this argument has the nonnull attribute. Also returns true
55   /// if at least one byte is known to be dereferenceable and the pointer is in
56   /// addrspace(0).
57   bool hasNonNullAttr() const;
58
59   /// If this argument has the dereferenceable attribute, return the number of
60   /// bytes known to be dereferenceable. Otherwise, zero is returned.
61   uint64_t getDereferenceableBytes() const;
62
63   /// If this argument has the dereferenceable_or_null attribute, return the
64   /// number of bytes known to be dereferenceable. Otherwise, zero is returned.
65   uint64_t getDereferenceableOrNullBytes() const;
66
67   /// Return true if this argument has the byval attribute.
68   bool hasByValAttr() const;
69
70   /// Return true if this argument has the swiftself attribute.
71   bool hasSwiftSelfAttr() const;
72
73   /// Return true if this argument has the swifterror attribute.
74   bool hasSwiftErrorAttr() const;
75
76   /// Return true if this argument has the byval attribute or inalloca
77   /// attribute. These attributes represent arguments being passed by value.
78   bool hasByValOrInAllocaAttr() const;
79
80   /// If this is a byval or inalloca argument, return its alignment.
81   unsigned getParamAlignment() const;
82
83   /// Return true if this argument has the nest attribute.
84   bool hasNestAttr() const;
85
86   /// Return true if this argument has the noalias attribute.
87   bool hasNoAliasAttr() const;
88
89   /// Return true if this argument has the nocapture attribute.
90   bool hasNoCaptureAttr() const;
91
92   /// Return true if this argument has the sret attribute.
93   bool hasStructRetAttr() const;
94
95   /// Return true if this argument has the returned attribute.
96   bool hasReturnedAttr() const;
97
98   /// Return true if this argument has the readonly or readnone attribute.
99   bool onlyReadsMemory() const;
100
101   /// Return true if this argument has the inalloca attribute.
102   bool hasInAllocaAttr() const;
103
104   /// Return true if this argument has the zext attribute.
105   bool hasZExtAttr() const;
106
107   /// Return true if this argument has the sext attribute.
108   bool hasSExtAttr() const;
109
110   /// Add attributes to an argument.
111   void addAttrs(AttrBuilder &B);
112
113   void addAttr(Attribute::AttrKind Kind);
114
115   void addAttr(Attribute Attr);
116
117   /// Remove attributes from an argument.
118   void removeAttr(AttributeList AS);
119
120   void removeAttr(Attribute::AttrKind Kind);
121
122   /// Check if an argument has a given attribute.
123   bool hasAttribute(Attribute::AttrKind Kind) const;
124
125   /// Method for support type inquiry through isa, cast, and dyn_cast.
126   static inline bool classof(const Value *V) {
127     return V->getValueID() == ArgumentVal;
128   }
129 };
130
131 } // End llvm namespace
132
133 #endif