LLVM  mainline
Function.h
Go to the documentation of this file.
00001 //===-- llvm/Function.h - Class to represent a single function --*- 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 contains the declaration of the Function class, which represents a
00011 // single function/procedure in LLVM.
00012 //
00013 // A function basically consists of a list of basic blocks, a list of arguments,
00014 // and a symbol table.
00015 //
00016 //===----------------------------------------------------------------------===//
00017 
00018 #ifndef LLVM_IR_FUNCTION_H
00019 #define LLVM_IR_FUNCTION_H
00020 
00021 #include "llvm/ADT/iterator_range.h"
00022 #include "llvm/ADT/Optional.h"
00023 #include "llvm/IR/Argument.h"
00024 #include "llvm/IR/Attributes.h"
00025 #include "llvm/IR/BasicBlock.h"
00026 #include "llvm/IR/CallingConv.h"
00027 #include "llvm/IR/GlobalObject.h"
00028 #include "llvm/IR/OperandTraits.h"
00029 #include "llvm/Support/Compiler.h"
00030 
00031 namespace llvm {
00032 
00033 class FunctionType;
00034 class LLVMContext;
00035 class DISubprogram;
00036 
00037 template <>
00038 struct SymbolTableListSentinelTraits<Argument>
00039     : public ilist_half_embedded_sentinel_traits<Argument> {};
00040 
00041 class Function : public GlobalObject, public ilist_node<Function> {
00042 public:
00043   typedef SymbolTableList<Argument> ArgumentListType;
00044   typedef SymbolTableList<BasicBlock> BasicBlockListType;
00045 
00046   // BasicBlock iterators...
00047   typedef BasicBlockListType::iterator iterator;
00048   typedef BasicBlockListType::const_iterator const_iterator;
00049 
00050   typedef ArgumentListType::iterator arg_iterator;
00051   typedef ArgumentListType::const_iterator const_arg_iterator;
00052 
00053 private:
00054   // Important things that make up a function!
00055   BasicBlockListType  BasicBlocks;        ///< The basic blocks
00056   mutable ArgumentListType ArgumentList;  ///< The formal arguments
00057   ValueSymbolTable *SymTab;               ///< Symbol table of args/instructions
00058   AttributeSet AttributeSets;             ///< Parameter attributes
00059 
00060   /*
00061    * Value::SubclassData
00062    *
00063    * bit 0      : HasLazyArguments
00064    * bit 1      : HasPrefixData
00065    * bit 2      : HasPrologueData
00066    * bit 3      : HasPersonalityFn
00067    * bits 4-13  : CallingConvention
00068    * bits 14    : HasGC
00069    * bits 15 : [reserved]
00070    */
00071 
00072   /// Bits from GlobalObject::GlobalObjectSubclassData.
00073   enum {
00074     /// Whether this function is materializable.
00075     IsMaterializableBit = 1 << 0,
00076     HasMetadataHashEntryBit = 1 << 1
00077   };
00078   void setGlobalObjectBit(unsigned Mask, bool Value) {
00079     setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
00080                                 (Value ? Mask : 0u));
00081   }
00082 
00083   friend class SymbolTableListTraits<Function>;
00084 
00085   void setParent(Module *parent);
00086 
00087   /// hasLazyArguments/CheckLazyArguments - The argument list of a function is
00088   /// built on demand, so that the list isn't allocated until the first client
00089   /// needs it.  The hasLazyArguments predicate returns true if the arg list
00090   /// hasn't been set up yet.
00091   bool hasLazyArguments() const {
00092     return getSubclassDataFromValue() & (1<<0);
00093   }
00094   void CheckLazyArguments() const {
00095     if (hasLazyArguments())
00096       BuildLazyArguments();
00097   }
00098   void BuildLazyArguments() const;
00099 
00100   Function(const Function&) = delete;
00101   void operator=(const Function&) = delete;
00102 
00103   /// Function ctor - If the (optional) Module argument is specified, the
00104   /// function is automatically inserted into the end of the function list for
00105   /// the module.
00106   ///
00107   Function(FunctionType *Ty, LinkageTypes Linkage,
00108            const Twine &N = "", Module *M = nullptr);
00109 
00110 public:
00111   static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
00112                           const Twine &N = "", Module *M = nullptr) {
00113     return new Function(Ty, Linkage, N, M);
00114   }
00115 
00116   ~Function() override;
00117 
00118   /// \brief Provide fast operand accessors
00119   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00120 
00121   Type *getReturnType() const;           // Return the type of the ret val
00122   FunctionType *getFunctionType() const; // Return the FunctionType for me
00123 
00124   /// getContext - Return a reference to the LLVMContext associated with this
00125   /// function.
00126   LLVMContext &getContext() const;
00127 
00128   /// isVarArg - Return true if this function takes a variable number of
00129   /// arguments.
00130   bool isVarArg() const;
00131 
00132   bool isMaterializable() const;
00133   void setIsMaterializable(bool V);
00134 
00135   /// getIntrinsicID - This method returns the ID number of the specified
00136   /// function, or Intrinsic::not_intrinsic if the function is not an
00137   /// intrinsic, or if the pointer is null.  This value is always defined to be
00138   /// zero to allow easy checking for whether a function is intrinsic or not.
00139   /// The particular intrinsic functions which correspond to this value are
00140   /// defined in llvm/Intrinsics.h.
00141   Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; }
00142   bool isIntrinsic() const { return getName().startswith("llvm."); }
00143 
00144   /// \brief Recalculate the ID for this function if it is an Intrinsic defined
00145   /// in llvm/Intrinsics.h.  Sets the intrinsic ID to Intrinsic::not_intrinsic
00146   /// if the name of this function does not match an intrinsic in that header.
00147   /// Note, this method does not need to be called directly, as it is called
00148   /// from Value::setName() whenever the name of this function changes.
00149   void recalculateIntrinsicID();
00150 
00151   /// getCallingConv()/setCallingConv(CC) - These method get and set the
00152   /// calling convention of this function.  The enum values for the known
00153   /// calling conventions are defined in CallingConv.h.
00154   CallingConv::ID getCallingConv() const {
00155     return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
00156                                         CallingConv::MaxID);
00157   }
00158   void setCallingConv(CallingConv::ID CC) {
00159     auto ID = static_cast<unsigned>(CC);
00160     assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
00161     setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
00162   }
00163 
00164   /// @brief Return the attribute list for this Function.
00165   AttributeSet getAttributes() const { return AttributeSets; }
00166 
00167   /// @brief Set the attribute list for this Function.
00168   void setAttributes(AttributeSet attrs) { AttributeSets = attrs; }
00169 
00170   /// @brief Add function attributes to this function.
00171   void addFnAttr(Attribute::AttrKind N) {
00172     setAttributes(AttributeSets.addAttribute(getContext(),
00173                                              AttributeSet::FunctionIndex, N));
00174   }
00175 
00176   /// @brief Remove function attributes from this function.
00177   void removeFnAttr(Attribute::AttrKind N) {
00178     setAttributes(AttributeSets.removeAttribute(
00179         getContext(), AttributeSet::FunctionIndex, N));
00180   }
00181 
00182   /// @brief Add function attributes to this function.
00183   void addFnAttr(StringRef Kind) {
00184     setAttributes(
00185       AttributeSets.addAttribute(getContext(),
00186                                  AttributeSet::FunctionIndex, Kind));
00187   }
00188   void addFnAttr(StringRef Kind, StringRef Value) {
00189     setAttributes(
00190       AttributeSets.addAttribute(getContext(),
00191                                  AttributeSet::FunctionIndex, Kind, Value));
00192   }
00193 
00194   /// Set the entry count for this function.
00195   void setEntryCount(uint64_t Count);
00196 
00197   /// Get the entry count for this function.
00198   Optional<uint64_t> getEntryCount() const;
00199 
00200   /// @brief Return true if the function has the attribute.
00201   bool hasFnAttribute(Attribute::AttrKind Kind) const {
00202     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
00203   }
00204   bool hasFnAttribute(StringRef Kind) const {
00205     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
00206   }
00207 
00208   /// @brief Return the attribute for the given attribute kind.
00209   Attribute getFnAttribute(Attribute::AttrKind Kind) const {
00210     return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
00211   }
00212   Attribute getFnAttribute(StringRef Kind) const {
00213     return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
00214   }
00215 
00216   /// \brief Return the stack alignment for the function.
00217   unsigned getFnStackAlignment() const {
00218     return AttributeSets.getStackAlignment(AttributeSet::FunctionIndex);
00219   }
00220 
00221   /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
00222   ///                             to use during code generation.
00223   bool hasGC() const {
00224     return getSubclassDataFromValue() & (1<<14);
00225   }
00226   const std::string &getGC() const;
00227   void setGC(const std::string Str);
00228   void clearGC();
00229 
00230   /// @brief adds the attribute to the list of attributes.
00231   void addAttribute(unsigned i, Attribute::AttrKind attr);
00232 
00233   /// @brief adds the attributes to the list of attributes.
00234   void addAttributes(unsigned i, AttributeSet attrs);
00235 
00236   /// @brief removes the attributes from the list of attributes.
00237   void removeAttributes(unsigned i, AttributeSet attr);
00238 
00239   /// @brief adds the dereferenceable attribute to the list of attributes.
00240   void addDereferenceableAttr(unsigned i, uint64_t Bytes);
00241 
00242   /// @brief adds the dereferenceable_or_null attribute to the list of
00243   /// attributes.
00244   void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
00245 
00246   /// @brief Extract the alignment for a call or parameter (0=unknown).
00247   unsigned getParamAlignment(unsigned i) const {
00248     return AttributeSets.getParamAlignment(i);
00249   }
00250 
00251   /// @brief Extract the number of dereferenceable bytes for a call or
00252   /// parameter (0=unknown).
00253   uint64_t getDereferenceableBytes(unsigned i) const {
00254     return AttributeSets.getDereferenceableBytes(i);
00255   }
00256 
00257   /// @brief Extract the number of dereferenceable_or_null bytes for a call or
00258   /// parameter (0=unknown).
00259   uint64_t getDereferenceableOrNullBytes(unsigned i) const {
00260     return AttributeSets.getDereferenceableOrNullBytes(i);
00261   }
00262 
00263   /// @brief Determine if the function does not access memory.
00264   bool doesNotAccessMemory() const {
00265     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00266                                       Attribute::ReadNone);
00267   }
00268   void setDoesNotAccessMemory() {
00269     addFnAttr(Attribute::ReadNone);
00270   }
00271 
00272   /// @brief Determine if the function does not access or only reads memory.
00273   bool onlyReadsMemory() const {
00274     return doesNotAccessMemory() ||
00275       AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00276                                  Attribute::ReadOnly);
00277   }
00278   void setOnlyReadsMemory() {
00279     addFnAttr(Attribute::ReadOnly);
00280   }
00281 
00282   /// @brief Determine if the call can access memmory only using pointers based
00283   /// on its arguments.
00284   bool onlyAccessesArgMemory() const {
00285     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00286                                       Attribute::ArgMemOnly);
00287   }
00288   void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); }
00289 
00290   /// @brief Determine if the function may only access memory that is 
00291   ///  inaccessible from the IR.
00292   bool onlyAccessesInaccessibleMemory() const {
00293     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00294                                       Attribute::InaccessibleMemOnly);
00295   }
00296   void setOnlyAccessesInaccessibleMemory() {
00297     addFnAttr(Attribute::InaccessibleMemOnly);
00298   }
00299 
00300   /// @brief Determine if the function may only access memory that is
00301   //  either inaccessible from the IR or pointed to by its arguments.
00302   bool onlyAccessesInaccessibleMemOrArgMem() const {
00303     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00304                                       Attribute::InaccessibleMemOrArgMemOnly);
00305   }
00306   void setOnlyAccessesInaccessibleMemOrArgMem() {
00307     addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
00308   }
00309 
00310   /// @brief Determine if the function cannot return.
00311   bool doesNotReturn() const {
00312     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00313                                       Attribute::NoReturn);
00314   }
00315   void setDoesNotReturn() {
00316     addFnAttr(Attribute::NoReturn);
00317   }
00318 
00319   /// @brief Determine if the function cannot unwind.
00320   bool doesNotThrow() const {
00321     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00322                                       Attribute::NoUnwind);
00323   }
00324   void setDoesNotThrow() {
00325     addFnAttr(Attribute::NoUnwind);
00326   }
00327 
00328   /// @brief Determine if the call cannot be duplicated.
00329   bool cannotDuplicate() const {
00330     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00331                                       Attribute::NoDuplicate);
00332   }
00333   void setCannotDuplicate() {
00334     addFnAttr(Attribute::NoDuplicate);
00335   }
00336 
00337   /// @brief Determine if the call is convergent.
00338   bool isConvergent() const {
00339     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00340                                       Attribute::Convergent);
00341   }
00342   void setConvergent() {
00343     addFnAttr(Attribute::Convergent);
00344   }
00345 
00346   /// Determine if the function is known not to recurse, directly or
00347   /// indirectly.
00348   bool doesNotRecurse() const {
00349     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00350                                       Attribute::NoRecurse);
00351   }
00352   void setDoesNotRecurse() {
00353     addFnAttr(Attribute::NoRecurse);
00354   }  
00355 
00356   /// @brief True if the ABI mandates (or the user requested) that this
00357   /// function be in a unwind table.
00358   bool hasUWTable() const {
00359     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
00360                                       Attribute::UWTable);
00361   }
00362   void setHasUWTable() {
00363     addFnAttr(Attribute::UWTable);
00364   }
00365 
00366   /// @brief True if this function needs an unwind table.
00367   bool needsUnwindTableEntry() const {
00368     return hasUWTable() || !doesNotThrow();
00369   }
00370 
00371   /// @brief Determine if the function returns a structure through first
00372   /// pointer argument.
00373   bool hasStructRetAttr() const {
00374     return AttributeSets.hasAttribute(1, Attribute::StructRet) ||
00375            AttributeSets.hasAttribute(2, Attribute::StructRet);
00376   }
00377 
00378   /// @brief Determine if the parameter or return value is marked with NoAlias
00379   /// attribute.
00380   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
00381   bool doesNotAlias(unsigned n) const {
00382     return AttributeSets.hasAttribute(n, Attribute::NoAlias);
00383   }
00384   void setDoesNotAlias(unsigned n) {
00385     addAttribute(n, Attribute::NoAlias);
00386   }
00387 
00388   /// @brief Determine if the parameter can be captured.
00389   /// @param n The parameter to check. 1 is the first parameter, 0 is the return
00390   bool doesNotCapture(unsigned n) const {
00391     return AttributeSets.hasAttribute(n, Attribute::NoCapture);
00392   }
00393   void setDoesNotCapture(unsigned n) {
00394     addAttribute(n, Attribute::NoCapture);
00395   }
00396 
00397   bool doesNotAccessMemory(unsigned n) const {
00398     return AttributeSets.hasAttribute(n, Attribute::ReadNone);
00399   }
00400   void setDoesNotAccessMemory(unsigned n) {
00401     addAttribute(n, Attribute::ReadNone);
00402   }
00403 
00404   bool onlyReadsMemory(unsigned n) const {
00405     return doesNotAccessMemory(n) ||
00406       AttributeSets.hasAttribute(n, Attribute::ReadOnly);
00407   }
00408   void setOnlyReadsMemory(unsigned n) {
00409     addAttribute(n, Attribute::ReadOnly);
00410   }
00411 
00412   /// Optimize this function for minimum size (-Oz).
00413   bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); };
00414 
00415   /// Optimize this function for size (-Os) or minimum size (-Oz).
00416   bool optForSize() const {
00417     return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize();
00418   }
00419 
00420   /// copyAttributesFrom - copy all additional attributes (those not needed to
00421   /// create a Function) from the Function Src to this one.
00422   void copyAttributesFrom(const GlobalValue *Src) override;
00423 
00424   /// deleteBody - This method deletes the body of the function, and converts
00425   /// the linkage to external.
00426   ///
00427   void deleteBody() {
00428     dropAllReferences();
00429     setLinkage(ExternalLinkage);
00430   }
00431 
00432   /// removeFromParent - This method unlinks 'this' from the containing module,
00433   /// but does not delete it.
00434   ///
00435   void removeFromParent() override;
00436 
00437   /// eraseFromParent - This method unlinks 'this' from the containing module
00438   /// and deletes it.
00439   ///
00440   void eraseFromParent() override;
00441 
00442   /// Get the underlying elements of the Function... the basic block list is
00443   /// empty for external functions.
00444   ///
00445   const ArgumentListType &getArgumentList() const {
00446     CheckLazyArguments();
00447     return ArgumentList;
00448   }
00449   ArgumentListType &getArgumentList() {
00450     CheckLazyArguments();
00451     return ArgumentList;
00452   }
00453   static ArgumentListType Function::*getSublistAccess(Argument*) {
00454     return &Function::ArgumentList;
00455   }
00456 
00457   const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
00458         BasicBlockListType &getBasicBlockList()       { return BasicBlocks; }
00459   static BasicBlockListType Function::*getSublistAccess(BasicBlock*) {
00460     return &Function::BasicBlocks;
00461   }
00462 
00463   const BasicBlock       &getEntryBlock() const   { return front(); }
00464         BasicBlock       &getEntryBlock()         { return front(); }
00465 
00466   //===--------------------------------------------------------------------===//
00467   // Symbol Table Accessing functions...
00468 
00469   /// getSymbolTable() - Return the symbol table...
00470   ///
00471   inline       ValueSymbolTable &getValueSymbolTable()       { return *SymTab; }
00472   inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
00473 
00474   //===--------------------------------------------------------------------===//
00475   // BasicBlock iterator forwarding functions
00476   //
00477   iterator                begin()       { return BasicBlocks.begin(); }
00478   const_iterator          begin() const { return BasicBlocks.begin(); }
00479   iterator                end  ()       { return BasicBlocks.end();   }
00480   const_iterator          end  () const { return BasicBlocks.end();   }
00481 
00482   size_t                   size() const { return BasicBlocks.size();  }
00483   bool                    empty() const { return BasicBlocks.empty(); }
00484   const BasicBlock       &front() const { return BasicBlocks.front(); }
00485         BasicBlock       &front()       { return BasicBlocks.front(); }
00486   const BasicBlock        &back() const { return BasicBlocks.back();  }
00487         BasicBlock        &back()       { return BasicBlocks.back();  }
00488 
00489 /// @name Function Argument Iteration
00490 /// @{
00491 
00492   arg_iterator arg_begin() {
00493     CheckLazyArguments();
00494     return ArgumentList.begin();
00495   }
00496   const_arg_iterator arg_begin() const {
00497     CheckLazyArguments();
00498     return ArgumentList.begin();
00499   }
00500   arg_iterator arg_end() {
00501     CheckLazyArguments();
00502     return ArgumentList.end();
00503   }
00504   const_arg_iterator arg_end() const {
00505     CheckLazyArguments();
00506     return ArgumentList.end();
00507   }
00508 
00509   iterator_range<arg_iterator> args() {
00510     return make_range(arg_begin(), arg_end());
00511   }
00512 
00513   iterator_range<const_arg_iterator> args() const {
00514     return make_range(arg_begin(), arg_end());
00515   }
00516 
00517 /// @}
00518 
00519   size_t arg_size() const;
00520   bool arg_empty() const;
00521 
00522   /// \brief Check whether this function has a personality function.
00523   bool hasPersonalityFn() const {
00524     return getSubclassDataFromValue() & (1<<3);
00525   }
00526 
00527   /// \brief Get the personality function associated with this function.
00528   Constant *getPersonalityFn() const;
00529   void setPersonalityFn(Constant *Fn);
00530 
00531   /// \brief Check whether this function has prefix data.
00532   bool hasPrefixData() const {
00533     return getSubclassDataFromValue() & (1<<1);
00534   }
00535 
00536   /// \brief Get the prefix data associated with this function.
00537   Constant *getPrefixData() const;
00538   void setPrefixData(Constant *PrefixData);
00539 
00540   /// \brief Check whether this function has prologue data.
00541   bool hasPrologueData() const {
00542     return getSubclassDataFromValue() & (1<<2);
00543   }
00544 
00545   /// \brief Get the prologue data associated with this function.
00546   Constant *getPrologueData() const;
00547   void setPrologueData(Constant *PrologueData);
00548 
00549   /// viewCFG - This function is meant for use from the debugger.  You can just
00550   /// say 'call F->viewCFG()' and a ghostview window should pop up from the
00551   /// program, displaying the CFG of the current function with the code for each
00552   /// basic block inside.  This depends on there being a 'dot' and 'gv' program
00553   /// in your path.
00554   ///
00555   void viewCFG() const;
00556 
00557   /// viewCFGOnly - This function is meant for use from the debugger.  It works
00558   /// just like viewCFG, but it does not include the contents of basic blocks
00559   /// into the nodes, just the label.  If you are only interested in the CFG
00560   /// this can make the graph smaller.
00561   ///
00562   void viewCFGOnly() const;
00563 
00564   /// Methods for support type inquiry through isa, cast, and dyn_cast:
00565   static inline bool classof(const Value *V) {
00566     return V->getValueID() == Value::FunctionVal;
00567   }
00568 
00569   /// dropAllReferences() - This method causes all the subinstructions to "let
00570   /// go" of all references that they are maintaining.  This allows one to
00571   /// 'delete' a whole module at a time, even though there may be circular
00572   /// references... first all references are dropped, and all use counts go to
00573   /// zero.  Then everything is deleted for real.  Note that no operations are
00574   /// valid on an object that has "dropped all references", except operator
00575   /// delete.
00576   ///
00577   /// Since no other object in the module can have references into the body of a
00578   /// function, dropping all references deletes the entire body of the function,
00579   /// including any contained basic blocks.
00580   ///
00581   void dropAllReferences();
00582 
00583   /// hasAddressTaken - returns true if there are any uses of this function
00584   /// other than direct calls or invokes to it, or blockaddress expressions.
00585   /// Optionally passes back an offending user for diagnostic purposes.
00586   ///
00587   bool hasAddressTaken(const User** = nullptr) const;
00588 
00589   /// isDefTriviallyDead - Return true if it is trivially safe to remove
00590   /// this function definition from the module (because it isn't externally
00591   /// visible, does not have its address taken, and has no callers).  To make
00592   /// this more accurate, call removeDeadConstantUsers first.
00593   bool isDefTriviallyDead() const;
00594 
00595   /// callsFunctionThatReturnsTwice - Return true if the function has a call to
00596   /// setjmp or other function that gcc recognizes as "returning twice".
00597   bool callsFunctionThatReturnsTwice() const;
00598 
00599   /// \brief Check if this has any metadata.
00600   bool hasMetadata() const { return hasMetadataHashEntry(); }
00601 
00602   /// \brief Get the current metadata attachment, if any.
00603   ///
00604   /// Returns \c nullptr if such an attachment is missing.
00605   /// @{
00606   MDNode *getMetadata(unsigned KindID) const;
00607   MDNode *getMetadata(StringRef Kind) const;
00608   /// @}
00609 
00610   /// \brief Set a particular kind of metadata attachment.
00611   ///
00612   /// Sets the given attachment to \c MD, erasing it if \c MD is \c nullptr or
00613   /// replacing it if it already exists.
00614   /// @{
00615   void setMetadata(unsigned KindID, MDNode *MD);
00616   void setMetadata(StringRef Kind, MDNode *MD);
00617   /// @}
00618 
00619   /// \brief Get all current metadata attachments.
00620   void
00621   getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const;
00622 
00623   /// \brief Drop metadata not in the given list.
00624   ///
00625   /// Drop all metadata from \c this not included in \c KnownIDs.
00626   void dropUnknownMetadata(ArrayRef<unsigned> KnownIDs);
00627 
00628   /// \brief Set the attached subprogram.
00629   ///
00630   /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
00631   void setSubprogram(DISubprogram *SP);
00632 
00633   /// \brief Get the attached subprogram.
00634   ///
00635   /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result
00636   /// to \a DISubprogram.
00637   DISubprogram *getSubprogram() const;
00638 
00639 private:
00640   void allocHungoffUselist();
00641   template<int Idx> void setHungoffOperand(Constant *C);
00642 
00643   // Shadow Value::setValueSubclassData with a private forwarding method so that
00644   // subclasses cannot accidentally use it.
00645   void setValueSubclassData(unsigned short D) {
00646     Value::setValueSubclassData(D);
00647   }
00648   void setValueSubclassDataBit(unsigned Bit, bool On);
00649 
00650   bool hasMetadataHashEntry() const {
00651     return getGlobalObjectSubClassData() & HasMetadataHashEntryBit;
00652   }
00653   void setHasMetadataHashEntry(bool HasEntry) {
00654     setGlobalObjectBit(HasMetadataHashEntryBit, HasEntry);
00655   }
00656 
00657   void clearMetadata();
00658 };
00659 
00660 template <>
00661 struct OperandTraits<Function> : public HungoffOperandTraits<3> {};
00662 
00663 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value)
00664 
00665 } // End llvm namespace
00666 
00667 #endif