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