[llvm-exegesis] Fix missing std::move.
[llvm-complete.git] / include / llvm / IR / Argument.h
blob497dca44547cdac01cd2f3a3a92dd21fa4be0a38
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_ARGUMENT_H
15 #define LLVM_IR_ARGUMENT_H
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"
22 namespace llvm {
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;
34 friend class Function;
35 void setParent(Function *parent);
37 public:
38 /// Argument constructor.
39 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr,
40 unsigned ArgNo = 0);
42 inline const Function *getParent() const { return Parent; }
43 inline Function *getParent() { return Parent; }
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;
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;
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;
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;
66 /// Return true if this argument has the byval attribute.
67 bool hasByValAttr() const;
69 /// Return true if this argument has the swiftself attribute.
70 bool hasSwiftSelfAttr() const;
72 /// Return true if this argument has the swifterror attribute.
73 bool hasSwiftErrorAttr() const;
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;
79 /// If this is a byval or inalloca argument, return its alignment.
80 unsigned getParamAlignment() const;
82 /// Return true if this argument has the nest attribute.
83 bool hasNestAttr() const;
85 /// Return true if this argument has the noalias attribute.
86 bool hasNoAliasAttr() const;
88 /// Return true if this argument has the nocapture attribute.
89 bool hasNoCaptureAttr() const;
91 /// Return true if this argument has the sret attribute.
92 bool hasStructRetAttr() const;
94 /// Return true if this argument has the returned attribute.
95 bool hasReturnedAttr() const;
97 /// Return true if this argument has the readonly or readnone attribute.
98 bool onlyReadsMemory() const;
100 /// Return true if this argument has the inalloca attribute.
101 bool hasInAllocaAttr() const;
103 /// Return true if this argument has the zext attribute.
104 bool hasZExtAttr() const;
106 /// Return true if this argument has the sext attribute.
107 bool hasSExtAttr() const;
109 /// Add attributes to an argument.
110 void addAttrs(AttrBuilder &B);
112 void addAttr(Attribute::AttrKind Kind);
114 void addAttr(Attribute Attr);
116 /// Remove attributes from an argument.
117 void removeAttr(Attribute::AttrKind Kind);
119 /// Check if an argument has a given attribute.
120 bool hasAttribute(Attribute::AttrKind Kind) const;
122 /// Method for support type inquiry through isa, cast, and dyn_cast.
123 static bool classof(const Value *V) {
124 return V->getValueID() == ArgumentVal;
128 } // End llvm namespace
130 #endif