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