LCOV - code coverage report
Current view: top level - include/llvm/IR - Function.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 111 111 100.0 %
Date: 2017-09-14 15:23:50 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/Function.h - Class to represent a single function ---*- 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 contains the declaration of the Function class, which represents a
      11             : // single function/procedure in LLVM.
      12             : //
      13             : // A function basically consists of a list of basic blocks, a list of arguments,
      14             : // and a symbol table.
      15             : //
      16             : //===----------------------------------------------------------------------===//
      17             : 
      18             : #ifndef LLVM_IR_FUNCTION_H
      19             : #define LLVM_IR_FUNCTION_H
      20             : 
      21             : #include "llvm/ADT/DenseSet.h"
      22             : #include "llvm/ADT/StringRef.h"
      23             : #include "llvm/ADT/Twine.h"
      24             : #include "llvm/ADT/ilist_node.h"
      25             : #include "llvm/ADT/iterator_range.h"
      26             : #include "llvm/IR/Argument.h"
      27             : #include "llvm/IR/Attributes.h"
      28             : #include "llvm/IR/BasicBlock.h"
      29             : #include "llvm/IR/CallingConv.h"
      30             : #include "llvm/IR/DerivedTypes.h"
      31             : #include "llvm/IR/GlobalObject.h"
      32             : #include "llvm/IR/GlobalValue.h"
      33             : #include "llvm/IR/OperandTraits.h"
      34             : #include "llvm/IR/SymbolTableListTraits.h"
      35             : #include "llvm/IR/Value.h"
      36             : #include "llvm/Support/Casting.h"
      37             : #include "llvm/Support/Compiler.h"
      38             : #include <cassert>
      39             : #include <cstddef>
      40             : #include <cstdint>
      41             : #include <memory>
      42             : #include <string>
      43             : 
      44             : namespace llvm {
      45             : 
      46             : namespace Intrinsic {
      47             : enum ID : unsigned;
      48             : }
      49             : 
      50             : class AssemblyAnnotationWriter;
      51             : class Constant;
      52             : class DISubprogram;
      53             : class LLVMContext;
      54             : class Module;
      55             : template <typename T> class Optional;
      56             : class raw_ostream;
      57             : class Type;
      58             : class User;
      59             : 
      60             : class Function : public GlobalObject, public ilist_node<Function> {
      61             : public:
      62             :   using BasicBlockListType = SymbolTableList<BasicBlock>;
      63             : 
      64             :   // BasicBlock iterators...
      65             :   using iterator = BasicBlockListType::iterator;
      66             :   using const_iterator = BasicBlockListType::const_iterator;
      67             : 
      68             :   using arg_iterator = Argument *;
      69             :   using const_arg_iterator = const Argument *;
      70             : 
      71             : private:
      72             :   // Important things that make up a function!
      73             :   BasicBlockListType BasicBlocks;         ///< The basic blocks
      74             :   mutable Argument *Arguments = nullptr;  ///< The formal arguments
      75             :   size_t NumArgs;
      76             :   std::unique_ptr<ValueSymbolTable>
      77             :       SymTab;                             ///< Symbol table of args/instructions
      78             :   AttributeList AttributeSets;            ///< Parameter attributes
      79             : 
      80             :   /*
      81             :    * Value::SubclassData
      82             :    *
      83             :    * bit 0      : HasLazyArguments
      84             :    * bit 1      : HasPrefixData
      85             :    * bit 2      : HasPrologueData
      86             :    * bit 3      : HasPersonalityFn
      87             :    * bits 4-13  : CallingConvention
      88             :    * bits 14    : HasGC
      89             :    * bits 15 : [reserved]
      90             :    */
      91             : 
      92             :   /// Bits from GlobalObject::GlobalObjectSubclassData.
      93             :   enum {
      94             :     /// Whether this function is materializable.
      95             :     IsMaterializableBit = 0,
      96             :   };
      97             : 
      98             :   friend class SymbolTableListTraits<Function>;
      99             : 
     100             :   /// hasLazyArguments/CheckLazyArguments - The argument list of a function is
     101             :   /// built on demand, so that the list isn't allocated until the first client
     102             :   /// needs it.  The hasLazyArguments predicate returns true if the arg list
     103             :   /// hasn't been set up yet.
     104             : public:
     105             :   bool hasLazyArguments() const {
     106     9482233 :     return getSubclassDataFromValue() & (1<<0);
     107             :   }
     108             : 
     109             : private:
     110             :   void CheckLazyArguments() const {
     111     9480034 :     if (hasLazyArguments())
     112      349247 :       BuildLazyArguments();
     113             :   }
     114             : 
     115             :   void BuildLazyArguments() const;
     116             : 
     117             :   void clearArguments();
     118             : 
     119             :   /// Function ctor - If the (optional) Module argument is specified, the
     120             :   /// function is automatically inserted into the end of the function list for
     121             :   /// the module.
     122             :   ///
     123             :   Function(FunctionType *Ty, LinkageTypes Linkage,
     124             :            const Twine &N = "", Module *M = nullptr);
     125             : 
     126             : public:
     127             :   Function(const Function&) = delete;
     128             :   void operator=(const Function&) = delete;
     129             :   ~Function();
     130             : 
     131             :   static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
     132             :                           const Twine &N = "", Module *M = nullptr) {
     133      427411 :     return new Function(Ty, Linkage, N, M);
     134             :   }
     135             : 
     136             :   // Provide fast operand accessors.
     137             :   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
     138             : 
     139             :   /// Returns the FunctionType for me.
     140             :   FunctionType *getFunctionType() const {
     141    17682400 :     return cast<FunctionType>(getValueType());
     142             :   }
     143             : 
     144             :   /// Returns the type of the ret val.
     145     4608646 :   Type *getReturnType() const { return getFunctionType()->getReturnType(); }
     146             : 
     147             :   /// getContext - Return a reference to the LLVMContext associated with this
     148             :   /// function.
     149             :   LLVMContext &getContext() const;
     150             : 
     151             :   /// isVarArg - Return true if this function takes a variable number of
     152             :   /// arguments.
     153     1720706 :   bool isVarArg() const { return getFunctionType()->isVarArg(); }
     154             : 
     155             :   bool isMaterializable() const {
     156    12888618 :     return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
     157             :   }
     158             :   void setIsMaterializable(bool V) {
     159      795022 :     unsigned Mask = 1 << IsMaterializableBit;
     160     2385066 :     setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
     161             :                                 (V ? Mask : 0u));
     162             :   }
     163             : 
     164             :   /// getIntrinsicID - This method returns the ID number of the specified
     165             :   /// function, or Intrinsic::not_intrinsic if the function is not an
     166             :   /// intrinsic, or if the pointer is null.  This value is always defined to be
     167             :   /// zero to allow easy checking for whether a function is intrinsic or not.
     168             :   /// The particular intrinsic functions which correspond to this value are
     169             :   /// defined in llvm/Intrinsics.h.
     170             :   Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; }
     171             : 
     172             :   /// isIntrinsic - Returns true if the function's name starts with "llvm.".
     173             :   /// It's possible for this function to return true while getIntrinsicID()
     174             :   /// returns Intrinsic::not_intrinsic!
     175   113090885 :   bool isIntrinsic() const { return HasLLVMReservedName; }
     176             : 
     177             :   static Intrinsic::ID lookupIntrinsicID(StringRef Name);
     178             : 
     179             :   /// \brief Recalculate the ID for this function if it is an Intrinsic defined
     180             :   /// in llvm/Intrinsics.h.  Sets the intrinsic ID to Intrinsic::not_intrinsic
     181             :   /// if the name of this function does not match an intrinsic in that header.
     182             :   /// Note, this method does not need to be called directly, as it is called
     183             :   /// from Value::setName() whenever the name of this function changes.
     184             :   void recalculateIntrinsicID();
     185             : 
     186             :   /// getCallingConv()/setCallingConv(CC) - These method get and set the
     187             :   /// calling convention of this function.  The enum values for the known
     188             :   /// calling conventions are defined in CallingConv.h.
     189             :   CallingConv::ID getCallingConv() const {
     190     9387667 :     return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
     191     9004666 :                                         CallingConv::MaxID);
     192             :   }
     193             :   void setCallingConv(CallingConv::ID CC) {
     194      394573 :     auto ID = static_cast<unsigned>(CC);
     195             :     assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
     196      789146 :     setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
     197             :   }
     198             : 
     199             :   /// @brief Return the attribute list for this Function.
     200             :   AttributeList getAttributes() const { return AttributeSets; }
     201             : 
     202             :   /// @brief Set the attribute list for this Function.
     203     1355207 :   void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
     204             : 
     205             :   /// @brief Add function attributes to this function.
     206             :   void addFnAttr(Attribute::AttrKind Kind) {
     207       83826 :     addAttribute(AttributeList::FunctionIndex, Kind);
     208             :   }
     209             : 
     210             :   /// @brief Add function attributes to this function.
     211      105990 :   void addFnAttr(StringRef Kind, StringRef Val = StringRef()) {
     212      105990 :     addAttribute(AttributeList::FunctionIndex,
     213             :                  Attribute::get(getContext(), Kind, Val));
     214      105990 :   }
     215             : 
     216             :   void addFnAttr(Attribute Attr) {
     217           4 :     addAttribute(AttributeList::FunctionIndex, Attr);
     218             :   }
     219             : 
     220             :   /// @brief Remove function attributes from this function.
     221             :   void removeFnAttr(Attribute::AttrKind Kind) {
     222       95413 :     removeAttribute(AttributeList::FunctionIndex, Kind);
     223             :   }
     224             : 
     225             :   /// @brief Remove function attribute from this function.
     226          29 :   void removeFnAttr(StringRef Kind) {
     227          58 :     setAttributes(getAttributes().removeAttribute(
     228             :         getContext(), AttributeList::FunctionIndex, Kind));
     229          29 :   }
     230             : 
     231             :   /// \brief Set the entry count for this function.
     232             :   ///
     233             :   /// Entry count is the number of times this function was executed based on
     234             :   /// pgo data. \p Imports points to a set of GUIDs that needs to be imported
     235             :   /// by the function for sample PGO, to enable the same inlines as the
     236             :   /// profiled optimized binary.
     237             :   void setEntryCount(uint64_t Count,
     238             :                      const DenseSet<GlobalValue::GUID> *Imports = nullptr);
     239             : 
     240             :   /// \brief Get the entry count for this function.
     241             :   ///
     242             :   /// Entry count is the number of times the function was executed based on
     243             :   /// pgo data.
     244             :   Optional<uint64_t> getEntryCount() const;
     245             : 
     246             :   /// Returns the set of GUIDs that needs to be imported to the function for
     247             :   /// sample PGO, to enable the same inlines as the profiled optimized binary.
     248             :   DenseSet<GlobalValue::GUID> getImportGUIDs() const;
     249             : 
     250             :   /// Set the section prefix for this function.
     251             :   void setSectionPrefix(StringRef Prefix);
     252             : 
     253             :   /// Get the section prefix for this function.
     254             :   Optional<StringRef> getSectionPrefix() const;
     255             : 
     256             :   /// @brief Return true if the function has the attribute.
     257             :   bool hasFnAttribute(Attribute::AttrKind Kind) const {
     258    78337180 :     return AttributeSets.hasFnAttribute(Kind);
     259             :   }
     260             :   bool hasFnAttribute(StringRef Kind) const {
     261     9315714 :     return AttributeSets.hasFnAttribute(Kind);
     262             :   }
     263             : 
     264             :   /// @brief Return the attribute for the given attribute kind.
     265             :   Attribute getFnAttribute(Attribute::AttrKind Kind) const {
     266     2827552 :     return getAttribute(AttributeList::FunctionIndex, Kind);
     267             :   }
     268             :   Attribute getFnAttribute(StringRef Kind) const {
     269    13864256 :     return getAttribute(AttributeList::FunctionIndex, Kind);
     270             :   }
     271             : 
     272             :   /// \brief Return the stack alignment for the function.
     273          60 :   unsigned getFnStackAlignment() const {
     274          60 :     if (!hasFnAttribute(Attribute::StackAlignment))
     275             :       return 0;
     276          60 :     return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
     277             :   }
     278             : 
     279             :   /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
     280             :   ///                             to use during code generation.
     281             :   bool hasGC() const {
     282     1550673 :     return getSubclassDataFromValue() & (1<<14);
     283             :   }
     284             :   const std::string &getGC() const;
     285             :   void setGC(std::string Str);
     286             :   void clearGC();
     287             : 
     288             :   /// @brief adds the attribute to the list of attributes.
     289             :   void addAttribute(unsigned i, Attribute::AttrKind Kind);
     290             : 
     291             :   /// @brief adds the attribute to the list of attributes.
     292             :   void addAttribute(unsigned i, Attribute Attr);
     293             : 
     294             :   /// @brief adds the attributes to the list of attributes.
     295             :   void addAttributes(unsigned i, const AttrBuilder &Attrs);
     296             : 
     297             :   /// @brief adds the attribute to the list of attributes for the given arg.
     298             :   void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
     299             : 
     300             :   /// @brief adds the attribute to the list of attributes for the given arg.
     301             :   void addParamAttr(unsigned ArgNo, Attribute Attr);
     302             : 
     303             :   /// @brief adds the attributes to the list of attributes for the given arg.
     304             :   void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
     305             : 
     306             :   /// @brief removes the attribute from the list of attributes.
     307             :   void removeAttribute(unsigned i, Attribute::AttrKind Kind);
     308             : 
     309             :   /// @brief removes the attribute from the list of attributes.
     310             :   void removeAttribute(unsigned i, StringRef Kind);
     311             : 
     312             :   /// @brief removes the attributes from the list of attributes.
     313             :   void removeAttributes(unsigned i, const AttrBuilder &Attrs);
     314             : 
     315             :   /// @brief removes the attribute from the list of attributes.
     316             :   void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
     317             : 
     318             :   /// @brief removes the attribute from the list of attributes.
     319             :   void removeParamAttr(unsigned ArgNo, StringRef Kind);
     320             : 
     321             :   /// @brief removes the attribute from the list of attributes.
     322             :   void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
     323             : 
     324             :   /// @brief check if an attributes is in the list of attributes.
     325             :   bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
     326         298 :     return getAttributes().hasAttribute(i, Kind);
     327             :   }
     328             : 
     329             :   /// @brief check if an attributes is in the list of attributes.
     330             :   bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
     331    11283881 :     return getAttributes().hasParamAttribute(ArgNo, Kind);
     332             :   }
     333             : 
     334             :   Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
     335     2830302 :     return AttributeSets.getAttribute(i, Kind);
     336             :   }
     337             : 
     338             :   Attribute getAttribute(unsigned i, StringRef Kind) const {
     339    13864256 :     return AttributeSets.getAttribute(i, Kind);
     340             :   }
     341             : 
     342             :   /// @brief adds the dereferenceable attribute to the list of attributes.
     343             :   void addDereferenceableAttr(unsigned i, uint64_t Bytes);
     344             : 
     345             :   /// @brief adds the dereferenceable attribute to the list of attributes for
     346             :   /// the given arg.
     347             :   void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes);
     348             : 
     349             :   /// @brief adds the dereferenceable_or_null attribute to the list of
     350             :   /// attributes.
     351             :   void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
     352             : 
     353             :   /// @brief adds the dereferenceable_or_null attribute to the list of
     354             :   /// attributes for the given arg.
     355             :   void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes);
     356             : 
     357             :   /// @brief Extract the alignment for a call or parameter (0=unknown).
     358             :   unsigned getParamAlignment(unsigned ArgNo) const {
     359      995785 :     return AttributeSets.getParamAlignment(ArgNo);
     360             :   }
     361             : 
     362             :   /// @brief Extract the number of dereferenceable bytes for a call or
     363             :   /// parameter (0=unknown).
     364             :   /// @param i AttributeList index, referring to a return value or argument.
     365             :   uint64_t getDereferenceableBytes(unsigned i) const {
     366         298 :     return AttributeSets.getDereferenceableBytes(i);
     367             :   }
     368             : 
     369             :   /// @brief Extract the number of dereferenceable bytes for a parameter.
     370             :   /// @param ArgNo Index of an argument, with 0 being the first function arg.
     371             :   uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
     372     2462850 :     return AttributeSets.getParamDereferenceableBytes(ArgNo);
     373             :   }
     374             : 
     375             :   /// @brief Extract the number of dereferenceable_or_null bytes for a call or
     376             :   /// parameter (0=unknown).
     377             :   /// @param i AttributeList index, referring to a return value or argument.
     378             :   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
     379         297 :     return AttributeSets.getDereferenceableOrNullBytes(i);
     380             :   }
     381             : 
     382             :   /// @brief Extract the number of dereferenceable_or_null bytes for a
     383             :   /// parameter.
     384             :   /// @param ArgNo AttributeList ArgNo, referring to an argument.
     385             :   uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
     386       92110 :     return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
     387             :   }
     388             : 
     389             :   /// @brief Determine if the function does not access memory.
     390             :   bool doesNotAccessMemory() const {
     391    24942822 :     return hasFnAttribute(Attribute::ReadNone);
     392             :   }
     393             :   void setDoesNotAccessMemory() {
     394           1 :     addFnAttr(Attribute::ReadNone);
     395             :   }
     396             : 
     397             :   /// @brief Determine if the function does not access or only reads memory.
     398     8329117 :   bool onlyReadsMemory() const {
     399    16652770 :     return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
     400             :   }
     401             :   void setOnlyReadsMemory() {
     402         173 :     addFnAttr(Attribute::ReadOnly);
     403             :   }
     404             : 
     405             :   /// @brief Determine if the function does not access or only writes memory.
     406     8265284 :   bool doesNotReadMemory() const {
     407    16530568 :     return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
     408             :   }
     409             :   void setDoesNotReadMemory() {
     410             :     addFnAttr(Attribute::WriteOnly);
     411             :   }
     412             : 
     413             :   /// @brief Determine if the call can access memmory only using pointers based
     414             :   /// on its arguments.
     415             :   bool onlyAccessesArgMemory() const {
     416     8292087 :     return hasFnAttribute(Attribute::ArgMemOnly);
     417             :   }
     418          86 :   void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); }
     419             : 
     420             :   /// @brief Determine if the function may only access memory that is 
     421             :   ///  inaccessible from the IR.
     422             :   bool onlyAccessesInaccessibleMemory() const {
     423     2037502 :     return hasFnAttribute(Attribute::InaccessibleMemOnly);
     424             :   }
     425             :   void setOnlyAccessesInaccessibleMemory() {
     426             :     addFnAttr(Attribute::InaccessibleMemOnly);
     427             :   }
     428             : 
     429             :   /// @brief Determine if the function may only access memory that is
     430             :   ///  either inaccessible from the IR or pointed to by its arguments.
     431             :   bool onlyAccessesInaccessibleMemOrArgMem() const {
     432     2037347 :     return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
     433             :   }
     434             :   void setOnlyAccessesInaccessibleMemOrArgMem() {
     435             :     addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
     436             :   }
     437             : 
     438             :   /// @brief Determine if the function cannot return.
     439             :   bool doesNotReturn() const {
     440       40350 :     return hasFnAttribute(Attribute::NoReturn);
     441             :   }
     442             :   void setDoesNotReturn() {
     443         158 :     addFnAttr(Attribute::NoReturn);
     444             :   }
     445             : 
     446             :   /// @brief Determine if the function cannot unwind.
     447             :   bool doesNotThrow() const {
     448     3132297 :     return hasFnAttribute(Attribute::NoUnwind);
     449             :   }
     450             :   void setDoesNotThrow() {
     451       53598 :     addFnAttr(Attribute::NoUnwind);
     452             :   }
     453             : 
     454             :   /// @brief Determine if the call cannot be duplicated.
     455             :   bool cannotDuplicate() const {
     456             :     return hasFnAttribute(Attribute::NoDuplicate);
     457             :   }
     458             :   void setCannotDuplicate() {
     459             :     addFnAttr(Attribute::NoDuplicate);
     460             :   }
     461             : 
     462             :   /// @brief Determine if the call is convergent.
     463             :   bool isConvergent() const {
     464       41375 :     return hasFnAttribute(Attribute::Convergent);
     465             :   }
     466             :   void setConvergent() {
     467             :     addFnAttr(Attribute::Convergent);
     468             :   }
     469             :   void setNotConvergent() {
     470           5 :     removeFnAttr(Attribute::Convergent);
     471             :   }
     472             : 
     473             :   /// @brief Determine if the call has sideeffects.
     474             :   bool isSpeculatable() const {
     475       85757 :     return hasFnAttribute(Attribute::Speculatable);
     476             :   }
     477             :   void setSpeculatable() {
     478             :     addFnAttr(Attribute::Speculatable);
     479             :   }
     480             : 
     481             :   /// Determine if the function is known not to recurse, directly or
     482             :   /// indirectly.
     483             :   bool doesNotRecurse() const {
     484       81295 :     return hasFnAttribute(Attribute::NoRecurse);
     485             :   }
     486             :   void setDoesNotRecurse() {
     487       12380 :     addFnAttr(Attribute::NoRecurse);
     488             :   }  
     489             : 
     490             :   /// @brief True if the ABI mandates (or the user requested) that this
     491             :   /// function be in a unwind table.
     492             :   bool hasUWTable() const {
     493      468177 :     return hasFnAttribute(Attribute::UWTable);
     494             :   }
     495             :   void setHasUWTable() {
     496          18 :     addFnAttr(Attribute::UWTable);
     497             :   }
     498             : 
     499             :   /// @brief True if this function needs an unwind table.
     500      468093 :   bool needsUnwindTableEntry() const {
     501      904342 :     return hasUWTable() || !doesNotThrow();
     502             :   }
     503             : 
     504             :   /// @brief Determine if the function returns a structure through first
     505             :   /// or second pointer argument.
     506      865277 :   bool hasStructRetAttr() const {
     507     1727311 :     return AttributeSets.hasParamAttribute(0, Attribute::StructRet) ||
     508     1727311 :            AttributeSets.hasParamAttribute(1, Attribute::StructRet);
     509             :   }
     510             : 
     511             :   /// @brief Determine if the parameter or return value is marked with NoAlias
     512             :   /// attribute.
     513             :   bool returnDoesNotAlias() const {
     514       51687 :     return AttributeSets.hasAttribute(AttributeList::ReturnIndex,
     515       52197 :                                       Attribute::NoAlias);
     516             :   }
     517             :   void setReturnDoesNotAlias() {
     518          38 :     addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
     519             :   }
     520             : 
     521             :   /// Optimize this function for minimum size (-Oz).
     522     3660846 :   bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); }
     523             : 
     524             :   /// Optimize this function for size (-Os) or minimum size (-Oz).
     525     2595204 :   bool optForSize() const {
     526     5174703 :     return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize();
     527             :   }
     528             : 
     529             :   /// copyAttributesFrom - copy all additional attributes (those not needed to
     530             :   /// create a Function) from the Function Src to this one.
     531             :   void copyAttributesFrom(const Function *Src);
     532             : 
     533             :   /// deleteBody - This method deletes the body of the function, and converts
     534             :   /// the linkage to external.
     535             :   ///
     536             :   void deleteBody() {
     537        1243 :     dropAllReferences();
     538        2486 :     setLinkage(ExternalLinkage);
     539             :   }
     540             : 
     541             :   /// removeFromParent - This method unlinks 'this' from the containing module,
     542             :   /// but does not delete it.
     543             :   ///
     544             :   void removeFromParent();
     545             : 
     546             :   /// eraseFromParent - This method unlinks 'this' from the containing module
     547             :   /// and deletes it.
     548             :   ///
     549             :   void eraseFromParent();
     550             : 
     551             :   /// Steal arguments from another function.
     552             :   ///
     553             :   /// Drop this function's arguments and splice in the ones from \c Src.
     554             :   /// Requires that this has no function body.
     555             :   void stealArgumentListFrom(Function &Src);
     556             : 
     557             :   /// Get the underlying elements of the Function... the basic block list is
     558             :   /// empty for external functions.
     559             :   ///
     560      351954 :   const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
     561     1370050 :         BasicBlockListType &getBasicBlockList()       { return BasicBlocks; }
     562             : 
     563             :   static BasicBlockListType Function::*getSublistAccess(BasicBlock*) {
     564             :     return &Function::BasicBlocks;
     565             :   }
     566             : 
     567     2021129 :   const BasicBlock       &getEntryBlock() const   { return front(); }
     568     5722045 :         BasicBlock       &getEntryBlock()         { return front(); }
     569             : 
     570             :   //===--------------------------------------------------------------------===//
     571             :   // Symbol Table Accessing functions...
     572             : 
     573             :   /// getSymbolTable() - Return the symbol table if any, otherwise nullptr.
     574             :   ///
     575    12524946 :   inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); }
     576             :   inline const ValueSymbolTable *getValueSymbolTable() const {
     577       16856 :     return SymTab.get();
     578             :   }
     579             : 
     580             :   //===--------------------------------------------------------------------===//
     581             :   // BasicBlock iterator forwarding functions
     582             :   //
     583    13085926 :   iterator                begin()       { return BasicBlocks.begin(); }
     584     6403946 :   const_iterator          begin() const { return BasicBlocks.begin(); }
     585    19677494 :   iterator                end  ()       { return BasicBlocks.end();   }
     586     6404020 :   const_iterator          end  () const { return BasicBlocks.end();   }
     587             : 
     588     1388152 :   size_t                   size() const { return BasicBlocks.size();  }
     589    35623542 :   bool                    empty() const { return BasicBlocks.empty(); }
     590    10285500 :   const BasicBlock       &front() const { return BasicBlocks.front(); }
     591    13308569 :         BasicBlock       &front()       { return BasicBlocks.front(); }
     592             :   const BasicBlock        &back() const { return BasicBlocks.back();  }
     593          26 :         BasicBlock        &back()       { return BasicBlocks.back();  }
     594             : 
     595             : /// @name Function Argument Iteration
     596             : /// @{
     597             : 
     598             :   arg_iterator arg_begin() {
     599     1308817 :     CheckLazyArguments();
     600     1308816 :     return Arguments;
     601             :   }
     602             :   const_arg_iterator arg_begin() const {
     603     3583251 :     CheckLazyArguments();
     604     3583251 :     return Arguments;
     605             :   }
     606             : 
     607             :   arg_iterator arg_end() {
     608     1064217 :     CheckLazyArguments();
     609     1064217 :     return Arguments + NumArgs;
     610             :   }
     611             :   const_arg_iterator arg_end() const {
     612     3523749 :     CheckLazyArguments();
     613     3523749 :     return Arguments + NumArgs;
     614             :   }
     615             : 
     616      637110 :   iterator_range<arg_iterator> args() {
     617     1911330 :     return make_range(arg_begin(), arg_end());
     618             :   }
     619     2225804 :   iterator_range<const_arg_iterator> args() const {
     620     6677412 :     return make_range(arg_begin(), arg_end());
     621             :   }
     622             : 
     623             : /// @}
     624             : 
     625             :   size_t arg_size() const { return NumArgs; }
     626       16062 :   bool arg_empty() const { return arg_size() == 0; }
     627             : 
     628             :   /// \brief Check whether this function has a personality function.
     629             :   bool hasPersonalityFn() const {
     630     2290563 :     return getSubclassDataFromValue() & (1<<3);
     631             :   }
     632             : 
     633             :   /// \brief Get the personality function associated with this function.
     634             :   Constant *getPersonalityFn() const;
     635             :   void setPersonalityFn(Constant *Fn);
     636             : 
     637             :   /// \brief Check whether this function has prefix data.
     638             :   bool hasPrefixData() const {
     639      311251 :     return getSubclassDataFromValue() & (1<<1);
     640             :   }
     641             : 
     642             :   /// \brief Get the prefix data associated with this function.
     643             :   Constant *getPrefixData() const;
     644             :   void setPrefixData(Constant *PrefixData);
     645             : 
     646             :   /// \brief Check whether this function has prologue data.
     647             :   bool hasPrologueData() const {
     648      311248 :     return getSubclassDataFromValue() & (1<<2);
     649             :   }
     650             : 
     651             :   /// \brief Get the prologue data associated with this function.
     652             :   Constant *getPrologueData() const;
     653             :   void setPrologueData(Constant *PrologueData);
     654             : 
     655             :   /// Print the function to an output stream with an optional
     656             :   /// AssemblyAnnotationWriter.
     657             :   void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
     658             :              bool ShouldPreserveUseListOrder = false,
     659             :              bool IsForDebug = false) const;
     660             : 
     661             :   /// viewCFG - This function is meant for use from the debugger.  You can just
     662             :   /// say 'call F->viewCFG()' and a ghostview window should pop up from the
     663             :   /// program, displaying the CFG of the current function with the code for each
     664             :   /// basic block inside.  This depends on there being a 'dot' and 'gv' program
     665             :   /// in your path.
     666             :   ///
     667             :   void viewCFG() const;
     668             : 
     669             :   /// viewCFGOnly - This function is meant for use from the debugger.  It works
     670             :   /// just like viewCFG, but it does not include the contents of basic blocks
     671             :   /// into the nodes, just the label.  If you are only interested in the CFG
     672             :   /// this can make the graph smaller.
     673             :   ///
     674             :   void viewCFGOnly() const;
     675             : 
     676             :   /// Methods for support type inquiry through isa, cast, and dyn_cast:
     677             :   static bool classof(const Value *V) {
     678    19177285 :     return V->getValueID() == Value::FunctionVal;
     679             :   }
     680             : 
     681             :   /// dropAllReferences() - This method causes all the subinstructions to "let
     682             :   /// go" of all references that they are maintaining.  This allows one to
     683             :   /// 'delete' a whole module at a time, even though there may be circular
     684             :   /// references... first all references are dropped, and all use counts go to
     685             :   /// zero.  Then everything is deleted for real.  Note that no operations are
     686             :   /// valid on an object that has "dropped all references", except operator
     687             :   /// delete.
     688             :   ///
     689             :   /// Since no other object in the module can have references into the body of a
     690             :   /// function, dropping all references deletes the entire body of the function,
     691             :   /// including any contained basic blocks.
     692             :   ///
     693             :   void dropAllReferences();
     694             : 
     695             :   /// hasAddressTaken - returns true if there are any uses of this function
     696             :   /// other than direct calls or invokes to it, or blockaddress expressions.
     697             :   /// Optionally passes back an offending user for diagnostic purposes.
     698             :   ///
     699             :   bool hasAddressTaken(const User** = nullptr) const;
     700             : 
     701             :   /// isDefTriviallyDead - Return true if it is trivially safe to remove
     702             :   /// this function definition from the module (because it isn't externally
     703             :   /// visible, does not have its address taken, and has no callers).  To make
     704             :   /// this more accurate, call removeDeadConstantUsers first.
     705             :   bool isDefTriviallyDead() const;
     706             : 
     707             :   /// callsFunctionThatReturnsTwice - Return true if the function has a call to
     708             :   /// setjmp or other function that gcc recognizes as "returning twice".
     709             :   bool callsFunctionThatReturnsTwice() const;
     710             : 
     711             :   /// \brief Set the attached subprogram.
     712             :   ///
     713             :   /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
     714             :   void setSubprogram(DISubprogram *SP);
     715             : 
     716             :   /// \brief Get the attached subprogram.
     717             :   ///
     718             :   /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result
     719             :   /// to \a DISubprogram.
     720             :   DISubprogram *getSubprogram() const;
     721             : 
     722             :   /// Returns true if we should emit debug info for profiling.
     723             :   bool isDebugInfoForProfiling() const;
     724             : 
     725             : private:
     726             :   void allocHungoffUselist();
     727             :   template<int Idx> void setHungoffOperand(Constant *C);
     728             : 
     729             :   /// Shadow Value::setValueSubclassData with a private forwarding method so
     730             :   /// that subclasses cannot accidentally use it.
     731             :   void setValueSubclassData(unsigned short D) {
     732     3639720 :     Value::setValueSubclassData(D);
     733             :   }
     734             :   void setValueSubclassDataBit(unsigned Bit, bool On);
     735             : };
     736             : 
     737             : template <>
     738             : struct OperandTraits<Function> : public HungoffOperandTraits<3> {};
     739             : 
     740     3468099 : DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value)
     741             : 
     742             : } // end namespace llvm
     743             : 
     744             : #endif // LLVM_IR_FUNCTION_H

Generated by: LCOV version 1.13