LLVM  mainline
Argument.h
Go to the documentation of this file.
00001 //===-- llvm/Argument.h - Definition of the Argument class ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the Argument class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_IR_ARGUMENT_H
00015 #define LLVM_IR_ARGUMENT_H
00016 
00017 #include "llvm/ADT/Twine.h"
00018 #include "llvm/ADT/ilist_node.h"
00019 #include "llvm/IR/Attributes.h"
00020 #include "llvm/IR/Value.h"
00021 
00022 namespace llvm {
00023 
00024 template <typename NodeTy> class SymbolTableListTraits;
00025 
00026 /// \brief LLVM Argument representation
00027 ///
00028 /// This class represents an incoming formal argument to a Function. A formal
00029 /// argument, since it is ``formal'', does not contain an actual value but
00030 /// instead represents the type, argument number, and attributes of an argument
00031 /// for a specific function. When used in the body of said function, the
00032 /// argument of course represents the value of the actual argument that the
00033 /// function was called with.
00034 class Argument : public Value, public ilist_node<Argument> {
00035   virtual void anchor();
00036   Function *Parent;
00037 
00038   friend class SymbolTableListTraits<Argument>;
00039   void setParent(Function *parent);
00040 
00041 public:
00042   /// \brief Constructor.
00043   ///
00044   /// If \p F is specified, the argument is inserted at the end of the argument
00045   /// list for \p F.
00046   explicit Argument(Type *Ty, const Twine &Name = "", Function *F = nullptr);
00047 
00048   inline const Function *getParent() const { return Parent; }
00049   inline       Function *getParent()       { return Parent; }
00050 
00051   /// \brief Return the index of this formal argument in its containing
00052   /// function.
00053   ///
00054   /// For example in "void foo(int a, float b)" a is 0 and b is 1.
00055   unsigned getArgNo() const;
00056 
00057   /// \brief Return true if this argument has the nonnull attribute on it in
00058   /// its containing function. Also returns true if at least one byte is known
00059   /// to be dereferenceable and the pointer is in addrspace(0).
00060   bool hasNonNullAttr() const;
00061 
00062   /// \brief If this argument has the dereferenceable attribute on it in its
00063   /// containing function, return the number of bytes known to be
00064   /// dereferenceable. Otherwise, zero is returned.
00065   uint64_t getDereferenceableBytes() const;
00066 
00067   /// \brief If this argument has the dereferenceable_or_null attribute on
00068   /// it in its containing function, return the number of bytes known to be
00069   /// dereferenceable. Otherwise, zero is returned.
00070   uint64_t getDereferenceableOrNullBytes() const;
00071 
00072   /// \brief Return true if this argument has the byval attribute on it in its
00073   /// containing function.
00074   bool hasByValAttr() const;
00075 
00076   /// \brief Return true if this argument has the byval attribute or inalloca
00077   /// attribute on it in its containing function.  These attributes both
00078   /// represent arguments being passed by value.
00079   bool hasByValOrInAllocaAttr() const;
00080 
00081   /// \brief If this is a byval or inalloca argument, return its alignment.
00082   unsigned getParamAlignment() const;
00083 
00084   /// \brief Return true if this argument has the nest attribute on it in its
00085   /// containing function.
00086   bool hasNestAttr() const;
00087 
00088   /// \brief Return true if this argument has the noalias attribute on it in its
00089   /// containing function.
00090   bool hasNoAliasAttr() const;
00091 
00092   /// \brief Return true if this argument has the nocapture attribute on it in
00093   /// its containing function.
00094   bool hasNoCaptureAttr() const;
00095 
00096   /// \brief Return true if this argument has the sret attribute on it in its
00097   /// containing function.
00098   bool hasStructRetAttr() const;
00099 
00100   /// \brief Return true if this argument has the returned attribute on it in
00101   /// its containing function.
00102   bool hasReturnedAttr() const;
00103 
00104   /// \brief Return true if this argument has the readonly or readnone attribute
00105   /// on it in its containing function.
00106   bool onlyReadsMemory() const;
00107 
00108   /// \brief Return true if this argument has the inalloca attribute on it in
00109   /// its containing function.
00110   bool hasInAllocaAttr() const;
00111 
00112   /// \brief Return true if this argument has the zext attribute on it in its
00113   /// containing function.
00114   bool hasZExtAttr() const;
00115 
00116   /// \brief Return true if this argument has the sext attribute on it in its
00117   /// containing function.
00118   bool hasSExtAttr() const;
00119 
00120   /// \brief Add a Attribute to an argument.
00121   void addAttr(AttributeSet AS);
00122 
00123   /// \brief Remove a Attribute from an argument.
00124   void removeAttr(AttributeSet AS);
00125 
00126   /// \brief Method for support type inquiry through isa, cast, and
00127   /// dyn_cast.
00128   static inline bool classof(const Value *V) {
00129     return V->getValueID() == ArgumentVal;
00130   }
00131 };
00132 
00133 } // End llvm namespace
00134 
00135 #endif