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