1*9880d681SAndroid Build Coastguard Worker //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file declares the Argument class. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_IR_ARGUMENT_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_IR_ARGUMENT_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/Twine.h" 18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/ilist_node.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Attributes.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Value.h" 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker namespace llvm { 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker template <typename NodeTy> class SymbolTableListTraits; 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker /// \brief LLVM Argument representation 27*9880d681SAndroid Build Coastguard Worker /// 28*9880d681SAndroid Build Coastguard Worker /// This class represents an incoming formal argument to a Function. A formal 29*9880d681SAndroid Build Coastguard Worker /// argument, since it is ``formal'', does not contain an actual value but 30*9880d681SAndroid Build Coastguard Worker /// instead represents the type, argument number, and attributes of an argument 31*9880d681SAndroid Build Coastguard Worker /// for a specific function. When used in the body of said function, the 32*9880d681SAndroid Build Coastguard Worker /// argument of course represents the value of the actual argument that the 33*9880d681SAndroid Build Coastguard Worker /// function was called with. 34*9880d681SAndroid Build Coastguard Worker class Argument : public Value, public ilist_node<Argument> { 35*9880d681SAndroid Build Coastguard Worker virtual void anchor(); 36*9880d681SAndroid Build Coastguard Worker Function *Parent; 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker friend class SymbolTableListTraits<Argument>; 39*9880d681SAndroid Build Coastguard Worker void setParent(Function *parent); 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker public: 42*9880d681SAndroid Build Coastguard Worker /// \brief Constructor. 43*9880d681SAndroid Build Coastguard Worker /// 44*9880d681SAndroid Build Coastguard Worker /// If \p F is specified, the argument is inserted at the end of the argument 45*9880d681SAndroid Build Coastguard Worker /// list for \p F. 46*9880d681SAndroid Build Coastguard Worker explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr); 47*9880d681SAndroid Build Coastguard Worker getParent()48*9880d681SAndroid Build Coastguard Worker inline const Function *getParent() const { return Parent; } getParent()49*9880d681SAndroid Build Coastguard Worker inline Function *getParent() { return Parent; } 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker /// \brief Return the index of this formal argument in its containing 52*9880d681SAndroid Build Coastguard Worker /// function. 53*9880d681SAndroid Build Coastguard Worker /// 54*9880d681SAndroid Build Coastguard Worker /// For example in "void foo(int a, float b)" a is 0 and b is 1. 55*9880d681SAndroid Build Coastguard Worker unsigned getArgNo() const; 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the nonnull attribute on it in 58*9880d681SAndroid Build Coastguard Worker /// its containing function. Also returns true if at least one byte is known 59*9880d681SAndroid Build Coastguard Worker /// to be dereferenceable and the pointer is in addrspace(0). 60*9880d681SAndroid Build Coastguard Worker bool hasNonNullAttr() const; 61*9880d681SAndroid Build Coastguard Worker 62*9880d681SAndroid Build Coastguard Worker /// \brief If this argument has the dereferenceable attribute on it in its 63*9880d681SAndroid Build Coastguard Worker /// containing function, return the number of bytes known to be 64*9880d681SAndroid Build Coastguard Worker /// dereferenceable. Otherwise, zero is returned. 65*9880d681SAndroid Build Coastguard Worker uint64_t getDereferenceableBytes() const; 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Worker /// \brief If this argument has the dereferenceable_or_null attribute on 68*9880d681SAndroid Build Coastguard Worker /// it in its containing function, return the number of bytes known to be 69*9880d681SAndroid Build Coastguard Worker /// dereferenceable. Otherwise, zero is returned. 70*9880d681SAndroid Build Coastguard Worker uint64_t getDereferenceableOrNullBytes() const; 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the byval attribute on it in its 73*9880d681SAndroid Build Coastguard Worker /// containing function. 74*9880d681SAndroid Build Coastguard Worker bool hasByValAttr() const; 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the swiftself attribute. 77*9880d681SAndroid Build Coastguard Worker bool hasSwiftSelfAttr() const; 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the swifterror attribute. 80*9880d681SAndroid Build Coastguard Worker bool hasSwiftErrorAttr() const; 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the byval attribute or inalloca 83*9880d681SAndroid Build Coastguard Worker /// attribute on it in its containing function. These attributes both 84*9880d681SAndroid Build Coastguard Worker /// represent arguments being passed by value. 85*9880d681SAndroid Build Coastguard Worker bool hasByValOrInAllocaAttr() const; 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker /// \brief If this is a byval or inalloca argument, return its alignment. 88*9880d681SAndroid Build Coastguard Worker unsigned getParamAlignment() const; 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the nest attribute on it in its 91*9880d681SAndroid Build Coastguard Worker /// containing function. 92*9880d681SAndroid Build Coastguard Worker bool hasNestAttr() const; 93*9880d681SAndroid Build Coastguard Worker 94*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the noalias attribute on it in its 95*9880d681SAndroid Build Coastguard Worker /// containing function. 96*9880d681SAndroid Build Coastguard Worker bool hasNoAliasAttr() const; 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the nocapture attribute on it in 99*9880d681SAndroid Build Coastguard Worker /// its containing function. 100*9880d681SAndroid Build Coastguard Worker bool hasNoCaptureAttr() const; 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the sret attribute on it in its 103*9880d681SAndroid Build Coastguard Worker /// containing function. 104*9880d681SAndroid Build Coastguard Worker bool hasStructRetAttr() const; 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the returned attribute on it in 107*9880d681SAndroid Build Coastguard Worker /// its containing function. 108*9880d681SAndroid Build Coastguard Worker bool hasReturnedAttr() const; 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the readonly or readnone attribute 111*9880d681SAndroid Build Coastguard Worker /// on it in its containing function. 112*9880d681SAndroid Build Coastguard Worker bool onlyReadsMemory() const; 113*9880d681SAndroid Build Coastguard Worker 114*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the inalloca attribute on it in 115*9880d681SAndroid Build Coastguard Worker /// its containing function. 116*9880d681SAndroid Build Coastguard Worker bool hasInAllocaAttr() const; 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the zext attribute on it in its 119*9880d681SAndroid Build Coastguard Worker /// containing function. 120*9880d681SAndroid Build Coastguard Worker bool hasZExtAttr() const; 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker /// \brief Return true if this argument has the sext attribute on it in its 123*9880d681SAndroid Build Coastguard Worker /// containing function. 124*9880d681SAndroid Build Coastguard Worker bool hasSExtAttr() const; 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Worker /// \brief Add a Attribute to an argument. 127*9880d681SAndroid Build Coastguard Worker void addAttr(AttributeSet AS); 128*9880d681SAndroid Build Coastguard Worker addAttr(Attribute::AttrKind Kind)129*9880d681SAndroid Build Coastguard Worker void addAttr(Attribute::AttrKind Kind) { 130*9880d681SAndroid Build Coastguard Worker addAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind)); 131*9880d681SAndroid Build Coastguard Worker } 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard Worker /// \brief Remove a Attribute from an argument. 134*9880d681SAndroid Build Coastguard Worker void removeAttr(AttributeSet AS); 135*9880d681SAndroid Build Coastguard Worker removeAttr(Attribute::AttrKind Kind)136*9880d681SAndroid Build Coastguard Worker void removeAttr(Attribute::AttrKind Kind) { 137*9880d681SAndroid Build Coastguard Worker removeAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind)); 138*9880d681SAndroid Build Coastguard Worker } 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Worker /// \brief Checks if an argument has a given attribute. 141*9880d681SAndroid Build Coastguard Worker bool hasAttribute(Attribute::AttrKind Kind) const; 142*9880d681SAndroid Build Coastguard Worker 143*9880d681SAndroid Build Coastguard Worker /// \brief Method for support type inquiry through isa, cast, and 144*9880d681SAndroid Build Coastguard Worker /// dyn_cast. classof(const Value * V)145*9880d681SAndroid Build Coastguard Worker static inline bool classof(const Value *V) { 146*9880d681SAndroid Build Coastguard Worker return V->getValueID() == ArgumentVal; 147*9880d681SAndroid Build Coastguard Worker } 148*9880d681SAndroid Build Coastguard Worker }; 149*9880d681SAndroid Build Coastguard Worker 150*9880d681SAndroid Build Coastguard Worker } // End llvm namespace 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker #endif 153