1 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file declares the Argument class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_IR_ARGUMENT_H 14 #define LLVM_IR_ARGUMENT_H 15 16 #include "llvm/ADT/Twine.h" 17 #include "llvm/ADT/ilist_node.h" 18 #include "llvm/IR/Attributes.h" 19 #include "llvm/IR/Value.h" 20 21 namespace llvm { 22 23 /// This class represents an incoming formal argument to a Function. A formal 24 /// argument, since it is ``formal'', does not contain an actual value but 25 /// instead represents the type, argument number, and attributes of an argument 26 /// for a specific function. When used in the body of said function, the 27 /// argument of course represents the value of the actual argument that the 28 /// function was called with. 29 class Argument final : public Value { 30 Function *Parent; 31 unsigned ArgNo; 32 33 friend class Function; 34 void setParent(Function *parent); 35 36 public: 37 /// Argument constructor. 38 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr, 39 unsigned ArgNo = 0); 40 41 inline const Function *getParent() const { return Parent; } 42 inline Function *getParent() { return Parent; } 43 44 /// Return the index of this formal argument in its containing function. 45 /// 46 /// For example in "void foo(int a, float b)" a is 0 and b is 1. 47 unsigned getArgNo() const { 48 assert(Parent && "can't get number of unparented arg"); 49 return ArgNo; 50 } 51 52 /// Return true if this argument has the nonnull attribute. Also returns true 53 /// if at least one byte is known to be dereferenceable and the pointer is in 54 /// addrspace(0). 55 bool hasNonNullAttr() const; 56 57 /// If this argument has the dereferenceable attribute, return the number of 58 /// bytes known to be dereferenceable. Otherwise, zero is returned. 59 uint64_t getDereferenceableBytes() const; 60 61 /// If this argument has the dereferenceable_or_null attribute, return the 62 /// number of bytes known to be dereferenceable. Otherwise, zero is returned. 63 uint64_t getDereferenceableOrNullBytes() const; 64 65 /// Return true if this argument has the byval attribute. 66 bool hasByValAttr() const; 67 68 /// Return true if this argument has the swiftself attribute. 69 bool hasSwiftSelfAttr() const; 70 71 /// Return true if this argument has the swifterror attribute. 72 bool hasSwiftErrorAttr() const; 73 74 /// Return true if this argument has the byval attribute or inalloca 75 /// attribute. These attributes represent arguments being passed by value. 76 bool hasByValOrInAllocaAttr() const; 77 78 /// If this is a byval or inalloca argument, return its alignment. 79 /// FIXME: Remove this function once transition to Align is over. 80 /// Use getParamAlign() instead. 81 unsigned getParamAlignment() const; 82 83 /// If this is a byval or inalloca argument, return its alignment. 84 MaybeAlign getParamAlign() const; 85 86 /// If this is a byval argument, return its type. 87 Type *getParamByValType() const; 88 89 /// Return true if this argument has the nest attribute. 90 bool hasNestAttr() const; 91 92 /// Return true if this argument has the noalias attribute. 93 bool hasNoAliasAttr() const; 94 95 /// Return true if this argument has the nocapture attribute. 96 bool hasNoCaptureAttr() const; 97 98 /// Return true if this argument has the sret attribute. 99 bool hasStructRetAttr() const; 100 101 /// Return true if this argument has the inreg attribute. 102 bool hasInRegAttr() const; 103 104 /// Return true if this argument has the returned attribute. 105 bool hasReturnedAttr() const; 106 107 /// Return true if this argument has the readonly or readnone attribute. 108 bool onlyReadsMemory() const; 109 110 /// Return true if this argument has the inalloca attribute. 111 bool hasInAllocaAttr() const; 112 113 /// Return true if this argument has the zext attribute. 114 bool hasZExtAttr() const; 115 116 /// Return true if this argument has the sext attribute. 117 bool hasSExtAttr() const; 118 119 /// Add attributes to an argument. 120 void addAttrs(AttrBuilder &B); 121 122 void addAttr(Attribute::AttrKind Kind); 123 124 void addAttr(Attribute Attr); 125 126 /// Remove attributes from an argument. 127 void removeAttr(Attribute::AttrKind Kind); 128 129 /// Check if an argument has a given attribute. 130 bool hasAttribute(Attribute::AttrKind Kind) const; 131 132 Attribute getAttribute(Attribute::AttrKind Kind) const; 133 134 /// Method for support type inquiry through isa, cast, and dyn_cast. 135 static bool classof(const Value *V) { 136 return V->getValueID() == ArgumentVal; 137 } 138 }; 139 140 } // End llvm namespace 141 142 #endif 143