LLVM  7.0.0svn
Function.h
Go to the documentation of this file.
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"
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"
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:
63 
64  // BasicBlock iterators...
67 
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 
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.
143 
144  /// Returns the FunctionType for me.
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.
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.
195  return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
197  }
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.
212  addAttribute(AttributeList::FunctionIndex, Kind);
213  }
214 
215  /// @brief Add function attributes to this function.
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.
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  enum ProfileCountType { PCT_Invalid, PCT_Real, PCT_Synthetic };
238 
239  /// Class to represent profile counts.
240  ///
241  /// This class represents both real and synthetic profile counts.
242  class ProfileCount {
243  private:
244  uint64_t Count;
245  ProfileCountType PCT;
246  static ProfileCount Invalid;
247 
248  public:
249  ProfileCount() : Count(-1), PCT(PCT_Invalid) {}
250  ProfileCount(uint64_t Count, ProfileCountType PCT)
251  : Count(Count), PCT(PCT) {}
252  bool hasValue() const { return PCT != PCT_Invalid; }
253  uint64_t getCount() const { return Count; }
254  ProfileCountType getType() const { return PCT; }
255  bool isSynthetic() const { return PCT == PCT_Synthetic; }
256  explicit operator bool() { return hasValue(); }
257  bool operator!() const { return !hasValue(); }
258  // Update the count retaining the same profile count type.
259  ProfileCount &setCount(uint64_t C) {
260  Count = C;
261  return *this;
262  }
263  static ProfileCount getInvalid() { return ProfileCount(-1, PCT_Invalid); }
264  };
265 
266  /// \brief Set the entry count for this function.
267  ///
268  /// Entry count is the number of times this function was executed based on
269  /// pgo data. \p Imports points to a set of GUIDs that needs to
270  /// be imported by the function for sample PGO, to enable the same inlines as
271  /// the profiled optimized binary.
272  void setEntryCount(ProfileCount Count,
273  const DenseSet<GlobalValue::GUID> *Imports = nullptr);
274 
275  /// A convenience wrapper for setting entry count
276  void setEntryCount(uint64_t Count, ProfileCountType Type = PCT_Real,
277  const DenseSet<GlobalValue::GUID> *Imports = nullptr);
278 
279  /// \brief Get the entry count for this function.
280  ///
281  /// Entry count is the number of times the function was executed based on
282  /// pgo data.
283  ProfileCount getEntryCount() const;
284 
285  /// Return true if the function is annotated with profile data.
286  ///
287  /// Presence of entry counts from a profile run implies the function has
288  /// profile annotations.
289  bool hasProfileData() const { return getEntryCount().hasValue(); }
290 
291  /// Returns the set of GUIDs that needs to be imported to the function for
292  /// sample PGO, to enable the same inlines as the profiled optimized binary.
293  DenseSet<GlobalValue::GUID> getImportGUIDs() const;
294 
295  /// Set the section prefix for this function.
296  void setSectionPrefix(StringRef Prefix);
297 
298  /// Get the section prefix for this function.
299  Optional<StringRef> getSectionPrefix() const;
300 
301  /// @brief Return true if the function has the attribute.
303  return AttributeSets.hasFnAttribute(Kind);
304  }
305 
306  /// @brief Return true if the function has the attribute.
307  bool hasFnAttribute(StringRef Kind) const {
308  return AttributeSets.hasFnAttribute(Kind);
309  }
310 
311  /// @brief Return the attribute for the given attribute kind.
313  return getAttribute(AttributeList::FunctionIndex, Kind);
314  }
315 
316  /// @brief Return the attribute for the given attribute kind.
318  return getAttribute(AttributeList::FunctionIndex, Kind);
319  }
320 
321  /// \brief Return the stack alignment for the function.
322  unsigned getFnStackAlignment() const {
323  if (!hasFnAttribute(Attribute::StackAlignment))
324  return 0;
325  return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
326  }
327 
328  /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
329  /// to use during code generation.
330  bool hasGC() const {
331  return getSubclassDataFromValue() & (1<<14);
332  }
333  const std::string &getGC() const;
334  void setGC(std::string Str);
335  void clearGC();
336 
337  /// @brief adds the attribute to the list of attributes.
338  void addAttribute(unsigned i, Attribute::AttrKind Kind);
339 
340  /// @brief adds the attribute to the list of attributes.
341  void addAttribute(unsigned i, Attribute Attr);
342 
343  /// @brief adds the attributes to the list of attributes.
344  void addAttributes(unsigned i, const AttrBuilder &Attrs);
345 
346  /// @brief adds the attribute to the list of attributes for the given arg.
347  void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
348 
349  /// @brief adds the attribute to the list of attributes for the given arg.
350  void addParamAttr(unsigned ArgNo, Attribute Attr);
351 
352  /// @brief adds the attributes to the list of attributes for the given arg.
353  void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
354 
355  /// @brief removes the attribute from the list of attributes.
356  void removeAttribute(unsigned i, Attribute::AttrKind Kind);
357 
358  /// @brief removes the attribute from the list of attributes.
359  void removeAttribute(unsigned i, StringRef Kind);
360 
361  /// @brief removes the attributes from the list of attributes.
362  void removeAttributes(unsigned i, const AttrBuilder &Attrs);
363 
364  /// @brief removes the attribute from the list of attributes.
365  void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
366 
367  /// @brief removes the attribute from the list of attributes.
368  void removeParamAttr(unsigned ArgNo, StringRef Kind);
369 
370  /// @brief removes the attribute from the list of attributes.
371  void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
372 
373  /// @brief check if an attributes is in the list of attributes.
374  bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
375  return getAttributes().hasAttribute(i, Kind);
376  }
377 
378  /// @brief check if an attributes is in the list of attributes.
379  bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
380  return getAttributes().hasParamAttribute(ArgNo, Kind);
381  }
382 
383  /// @brief gets the attribute from the list of attributes.
384  Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
385  return AttributeSets.getAttribute(i, Kind);
386  }
387 
388  /// @brief gets the attribute from the list of attributes.
389  Attribute getAttribute(unsigned i, StringRef Kind) const {
390  return AttributeSets.getAttribute(i, Kind);
391  }
392 
393  /// @brief adds the dereferenceable attribute to the list of attributes.
394  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
395 
396  /// @brief adds the dereferenceable attribute to the list of attributes for
397  /// the given arg.
398  void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes);
399 
400  /// @brief adds the dereferenceable_or_null attribute to the list of
401  /// attributes.
402  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
403 
404  /// @brief adds the dereferenceable_or_null attribute to the list of
405  /// attributes for the given arg.
406  void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes);
407 
408  /// @brief Extract the alignment for a call or parameter (0=unknown).
409  unsigned getParamAlignment(unsigned ArgNo) const {
410  return AttributeSets.getParamAlignment(ArgNo);
411  }
412 
413  /// @brief Extract the number of dereferenceable bytes for a call or
414  /// parameter (0=unknown).
415  /// @param i AttributeList index, referring to a return value or argument.
416  uint64_t getDereferenceableBytes(unsigned i) const {
417  return AttributeSets.getDereferenceableBytes(i);
418  }
419 
420  /// @brief Extract the number of dereferenceable bytes for a parameter.
421  /// @param ArgNo Index of an argument, with 0 being the first function arg.
422  uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
423  return AttributeSets.getParamDereferenceableBytes(ArgNo);
424  }
425 
426  /// @brief Extract the number of dereferenceable_or_null bytes for a call or
427  /// parameter (0=unknown).
428  /// @param i AttributeList index, referring to a return value or argument.
429  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
430  return AttributeSets.getDereferenceableOrNullBytes(i);
431  }
432 
433  /// @brief Extract the number of dereferenceable_or_null bytes for a
434  /// parameter.
435  /// @param ArgNo AttributeList ArgNo, referring to an argument.
436  uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
437  return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
438  }
439 
440  /// @brief Determine if the function does not access memory.
441  bool doesNotAccessMemory() const {
442  return hasFnAttribute(Attribute::ReadNone);
443  }
445  addFnAttr(Attribute::ReadNone);
446  }
447 
448  /// @brief Determine if the function does not access or only reads memory.
449  bool onlyReadsMemory() const {
450  return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
451  }
453  addFnAttr(Attribute::ReadOnly);
454  }
455 
456  /// @brief Determine if the function does not access or only writes memory.
457  bool doesNotReadMemory() const {
458  return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
459  }
461  addFnAttr(Attribute::WriteOnly);
462  }
463 
464  /// @brief Determine if the call can access memmory only using pointers based
465  /// on its arguments.
466  bool onlyAccessesArgMemory() const {
467  return hasFnAttribute(Attribute::ArgMemOnly);
468  }
469  void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); }
470 
471  /// @brief Determine if the function may only access memory that is
472  /// inaccessible from the IR.
474  return hasFnAttribute(Attribute::InaccessibleMemOnly);
475  }
477  addFnAttr(Attribute::InaccessibleMemOnly);
478  }
479 
480  /// @brief Determine if the function may only access memory that is
481  /// either inaccessible from the IR or pointed to by its arguments.
483  return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
484  }
486  addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
487  }
488 
489  /// @brief Determine if the function cannot return.
490  bool doesNotReturn() const {
491  return hasFnAttribute(Attribute::NoReturn);
492  }
494  addFnAttr(Attribute::NoReturn);
495  }
496 
497  /// @brief Determine if the function cannot unwind.
498  bool doesNotThrow() const {
499  return hasFnAttribute(Attribute::NoUnwind);
500  }
502  addFnAttr(Attribute::NoUnwind);
503  }
504 
505  /// @brief Determine if the call cannot be duplicated.
506  bool cannotDuplicate() const {
507  return hasFnAttribute(Attribute::NoDuplicate);
508  }
510  addFnAttr(Attribute::NoDuplicate);
511  }
512 
513  /// @brief Determine if the call is convergent.
514  bool isConvergent() const {
515  return hasFnAttribute(Attribute::Convergent);
516  }
517  void setConvergent() {
518  addFnAttr(Attribute::Convergent);
519  }
521  removeFnAttr(Attribute::Convergent);
522  }
523 
524  /// @brief Determine if the call has sideeffects.
525  bool isSpeculatable() const {
526  return hasFnAttribute(Attribute::Speculatable);
527  }
529  addFnAttr(Attribute::Speculatable);
530  }
531 
532  /// Determine if the function is known not to recurse, directly or
533  /// indirectly.
534  bool doesNotRecurse() const {
535  return hasFnAttribute(Attribute::NoRecurse);
536  }
538  addFnAttr(Attribute::NoRecurse);
539  }
540 
541  /// @brief True if the ABI mandates (or the user requested) that this
542  /// function be in a unwind table.
543  bool hasUWTable() const {
544  return hasFnAttribute(Attribute::UWTable);
545  }
546  void setHasUWTable() {
547  addFnAttr(Attribute::UWTable);
548  }
549 
550  /// @brief True if this function needs an unwind table.
551  bool needsUnwindTableEntry() const {
552  return hasUWTable() || !doesNotThrow();
553  }
554 
555  /// @brief Determine if the function returns a structure through first
556  /// or second pointer argument.
557  bool hasStructRetAttr() const {
558  return AttributeSets.hasParamAttribute(0, Attribute::StructRet) ||
559  AttributeSets.hasParamAttribute(1, Attribute::StructRet);
560  }
561 
562  /// @brief Determine if the parameter or return value is marked with NoAlias
563  /// attribute.
564  bool returnDoesNotAlias() const {
565  return AttributeSets.hasAttribute(AttributeList::ReturnIndex,
567  }
570  }
571 
572  /// Optimize this function for minimum size (-Oz).
573  bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); }
574 
575  /// Optimize this function for size (-Os) or minimum size (-Oz).
576  bool optForSize() const {
577  return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize();
578  }
579 
580  /// copyAttributesFrom - copy all additional attributes (those not needed to
581  /// create a Function) from the Function Src to this one.
582  void copyAttributesFrom(const Function *Src);
583 
584  /// deleteBody - This method deletes the body of the function, and converts
585  /// the linkage to external.
586  ///
587  void deleteBody() {
588  dropAllReferences();
589  setLinkage(ExternalLinkage);
590  }
591 
592  /// removeFromParent - This method unlinks 'this' from the containing module,
593  /// but does not delete it.
594  ///
595  void removeFromParent();
596 
597  /// eraseFromParent - This method unlinks 'this' from the containing module
598  /// and deletes it.
599  ///
600  void eraseFromParent();
601 
602  /// Steal arguments from another function.
603  ///
604  /// Drop this function's arguments and splice in the ones from \c Src.
605  /// Requires that this has no function body.
606  void stealArgumentListFrom(Function &Src);
607 
608  /// Get the underlying elements of the Function... the basic block list is
609  /// empty for external functions.
610  ///
611  const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
612  BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
613 
615  return &Function::BasicBlocks;
616  }
617 
618  const BasicBlock &getEntryBlock() const { return front(); }
619  BasicBlock &getEntryBlock() { return front(); }
620 
621  //===--------------------------------------------------------------------===//
622  // Symbol Table Accessing functions...
623 
624  /// getSymbolTable() - Return the symbol table if any, otherwise nullptr.
625  ///
626  inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); }
627  inline const ValueSymbolTable *getValueSymbolTable() const {
628  return SymTab.get();
629  }
630 
631  //===--------------------------------------------------------------------===//
632  // BasicBlock iterator forwarding functions
633  //
634  iterator begin() { return BasicBlocks.begin(); }
635  const_iterator begin() const { return BasicBlocks.begin(); }
636  iterator end () { return BasicBlocks.end(); }
637  const_iterator end () const { return BasicBlocks.end(); }
638 
639  size_t size() const { return BasicBlocks.size(); }
640  bool empty() const { return BasicBlocks.empty(); }
641  const BasicBlock &front() const { return BasicBlocks.front(); }
642  BasicBlock &front() { return BasicBlocks.front(); }
643  const BasicBlock &back() const { return BasicBlocks.back(); }
644  BasicBlock &back() { return BasicBlocks.back(); }
645 
646 /// @name Function Argument Iteration
647 /// @{
648 
650  CheckLazyArguments();
651  return Arguments;
652  }
654  CheckLazyArguments();
655  return Arguments;
656  }
657 
659  CheckLazyArguments();
660  return Arguments + NumArgs;
661  }
663  CheckLazyArguments();
664  return Arguments + NumArgs;
665  }
666 
668  return make_range(arg_begin(), arg_end());
669  }
671  return make_range(arg_begin(), arg_end());
672  }
673 
674 /// @}
675 
676  size_t arg_size() const { return NumArgs; }
677  bool arg_empty() const { return arg_size() == 0; }
678 
679  /// \brief Check whether this function has a personality function.
680  bool hasPersonalityFn() const {
681  return getSubclassDataFromValue() & (1<<3);
682  }
683 
684  /// \brief Get the personality function associated with this function.
685  Constant *getPersonalityFn() const;
686  void setPersonalityFn(Constant *Fn);
687 
688  /// \brief Check whether this function has prefix data.
689  bool hasPrefixData() const {
690  return getSubclassDataFromValue() & (1<<1);
691  }
692 
693  /// \brief Get the prefix data associated with this function.
694  Constant *getPrefixData() const;
695  void setPrefixData(Constant *PrefixData);
696 
697  /// \brief Check whether this function has prologue data.
698  bool hasPrologueData() const {
699  return getSubclassDataFromValue() & (1<<2);
700  }
701 
702  /// \brief Get the prologue data associated with this function.
703  Constant *getPrologueData() const;
704  void setPrologueData(Constant *PrologueData);
705 
706  /// Print the function to an output stream with an optional
707  /// AssemblyAnnotationWriter.
708  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
709  bool ShouldPreserveUseListOrder = false,
710  bool IsForDebug = false) const;
711 
712  /// viewCFG - This function is meant for use from the debugger. You can just
713  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
714  /// program, displaying the CFG of the current function with the code for each
715  /// basic block inside. This depends on there being a 'dot' and 'gv' program
716  /// in your path.
717  ///
718  void viewCFG() const;
719 
720  /// viewCFGOnly - This function is meant for use from the debugger. It works
721  /// just like viewCFG, but it does not include the contents of basic blocks
722  /// into the nodes, just the label. If you are only interested in the CFG
723  /// this can make the graph smaller.
724  ///
725  void viewCFGOnly() const;
726 
727  /// Methods for support type inquiry through isa, cast, and dyn_cast:
728  static bool classof(const Value *V) {
729  return V->getValueID() == Value::FunctionVal;
730  }
731 
732  /// dropAllReferences() - This method causes all the subinstructions to "let
733  /// go" of all references that they are maintaining. This allows one to
734  /// 'delete' a whole module at a time, even though there may be circular
735  /// references... first all references are dropped, and all use counts go to
736  /// zero. Then everything is deleted for real. Note that no operations are
737  /// valid on an object that has "dropped all references", except operator
738  /// delete.
739  ///
740  /// Since no other object in the module can have references into the body of a
741  /// function, dropping all references deletes the entire body of the function,
742  /// including any contained basic blocks.
743  ///
744  void dropAllReferences();
745 
746  /// hasAddressTaken - returns true if there are any uses of this function
747  /// other than direct calls or invokes to it, or blockaddress expressions.
748  /// Optionally passes back an offending user for diagnostic purposes.
749  ///
750  bool hasAddressTaken(const User** = nullptr) const;
751 
752  /// isDefTriviallyDead - Return true if it is trivially safe to remove
753  /// this function definition from the module (because it isn't externally
754  /// visible, does not have its address taken, and has no callers). To make
755  /// this more accurate, call removeDeadConstantUsers first.
756  bool isDefTriviallyDead() const;
757 
758  /// callsFunctionThatReturnsTwice - Return true if the function has a call to
759  /// setjmp or other function that gcc recognizes as "returning twice".
760  bool callsFunctionThatReturnsTwice() const;
761 
762  /// \brief Set the attached subprogram.
763  ///
764  /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
765  void setSubprogram(DISubprogram *SP);
766 
767  /// \brief Get the attached subprogram.
768  ///
769  /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result
770  /// to \a DISubprogram.
771  DISubprogram *getSubprogram() const;
772 
773  /// Returns true if we should emit debug info for profiling.
774  bool isDebugInfoForProfiling() const;
775 
776 private:
777  void allocHungoffUselist();
778  template<int Idx> void setHungoffOperand(Constant *C);
779 
780  /// Shadow Value::setValueSubclassData with a private forwarding method so
781  /// that subclasses cannot accidentally use it.
782  void setValueSubclassData(unsigned short D) {
784  }
785  void setValueSubclassDataBit(unsigned Bit, bool On);
786 };
787 
788 template <>
790 
792 
793 } // end namespace llvm
794 
795 #endif // LLVM_IR_FUNCTION_H
size_t size() const
Definition: Function.h:639
const Function & getFunction() const
Definition: Function.h:134
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:158
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.h:449
uint64_t CallInst * C
bool isIntrinsic() const
isIntrinsic - Returns true if the function&#39;s name starts with "llvm.".
Definition: Function.h:180
void setConvergent()
Definition: Function.h:517
This class provides a symbol table of name/value pairs.
bool empty() const
Definition: Function.h:640
unsigned getFnStackAlignment() const
Return the stack alignment for the function.
Definition: Function.h:322
const_iterator begin() const
Definition: Function.h:635
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:469
bool isSpeculatable() const
Determine if the call has sideeffects.
Definition: Function.h:525
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Definition: Function.h:422
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
iterator end()
Definition: Function.h:636
AMDGPU Rewrite Out Arguments
Implements a dense probed hash-table based set.
Definition: DenseSet.h:221
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: Function.h:409
bool hasFnAttribute(StringRef Kind) const
Return true if the function has the attribute.
Definition: Function.h:307
const BasicBlock & back() const
Definition: Function.h:643
void setDoesNotRecurse()
Definition: Function.h:537
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:698
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:302
The highest possible calling convention ID. Must be some 2^k - 1.
Definition: CallingConv.h:224
arg_iterator arg_end()
Definition: Function.h:658
The two locations do not alias at all.
Definition: AliasAnalysis.h:85
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
void setDoesNotReadMemory()
Definition: Function.h:460
void setDoesNotThrow()
Definition: Function.h:501
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:557
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:689
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: Function.h:416
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table...
Definition: Function.h:543
This file contains the simple types necessary to represent the attributes associated with functions a...
Attribute getAttribute(unsigned i, StringRef Kind) const
gets the attribute from the list of attributes.
Definition: Function.h:389
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:379
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
Definition: Function.h:473
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
Subprogram description.
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Class to represent function types.
Definition: DerivedTypes.h:103
static BasicBlockListType Function::* getSublistAccess(BasicBlock *)
Definition: Function.h:614
bool arg_empty() const
Definition: Function.h:677
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:374
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:205
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:680
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
iterator begin()
Definition: Function.h:634
void setSpeculatable()
Definition: Function.h:528
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
Definition: Function.h:436
void setIsMaterializable(bool V)
Definition: Function.h:163
void setOnlyAccessesArgMemory()
Definition: Function.h:469
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.h:441
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
Definition: Function.h:429
const BasicBlock & getEntryBlock() const
Definition: Function.h:618
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
Definition: Function.h:506
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:198
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:150
void setOnlyReadsMemory()
Definition: Function.h:452
uint64_t getCount() const
Definition: Function.h:253
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
Definition: Function.h:587
This is an important base class in LLVM.
Definition: Constant.h:42
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
Definition: Function.h:564
BasicBlock & getEntryBlock()
Definition: Function.h:619
BasicBlock & front()
Definition: Function.h:642
void addFnAttr(StringRef Kind, StringRef Val=StringRef())
Add function attributes to this function.
Definition: Function.h:216
BasicBlock & back()
Definition: Function.h:644
bool doesNotReturn() const
Determine if the function cannot return.
Definition: Function.h:490
iterator_range< const_arg_iterator > args() const
Definition: Function.h:670
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition: Function.h:576
size_t arg_size() const
Definition: Function.h:676
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
arg_iterator arg_begin()
Definition: Function.h:649
void setHasUWTable()
Definition: Function.h:546
bool isMaterializable() const
Definition: Function.h:160
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&... Args)
Definition: DIBuilder.cpp:711
Class to represent profile counts.
Definition: Function.h:242
void setCannotDuplicate()
Definition: Function.h:509
void addFnAttr(Attribute Attr)
Add function attributes to this function.
Definition: Function.h:222
BasicBlockListType & getBasicBlockList()
Definition: Function.h:612
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
Definition: Function.h:534
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:498
ProfileCount & setCount(uint64_t C)
Definition: Function.h:259
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
void setDoesNotReturn()
Definition: Function.h:493
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:194
void setOnlyAccessesInaccessibleMemOrArgMem()
Definition: Function.h:485
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static ProfileCount getInvalid()
Definition: Function.h:263
void setNotConvergent()
Definition: Function.h:520
ProfileCount(uint64_t Count, ProfileCountType PCT)
Definition: Function.h:250
void setOnlyAccessesInaccessibleMemory()
Definition: Function.h:476
void setValueSubclassData(unsigned short D)
Definition: Value.h:660
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:208
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:175
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition: Function.h:626
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:551
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:145
A range adaptor for a pair of iterators.
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:48
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Function.h:728
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
Definition: Attributes.h:600
const_arg_iterator arg_end() const
Definition: Function.h:662
could "use" a pointer
Function::ProfileCount ProfileCount
Definition: Function.cpp:59
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:330
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
Definition: Attributes.h:610
void setDoesNotAccessMemory()
Definition: Function.h:444
#define N
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
Definition: Function.h:573
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.h:466
bool doesNotReadMemory() const
Determine if the function does not access or only writes memory.
Definition: Function.h:457
Compile-time customization of User operands.
Definition: User.h:43
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
Definition: Function.h:482
const_arg_iterator arg_begin() const
Definition: Function.h:653
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:611
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:81
#define LLVM_READONLY
Definition: Compiler.h:168
const ValueSymbolTable * getValueSymbolTable() const
Definition: Function.h:627
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition: Function.h:227
const unsigned Kind
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const BasicBlock & front() const
Definition: Function.h:641
aarch64 promote const
LLVM Value Representation.
Definition: Value.h:73
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
Definition: OperandTraits.h:96
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
ProfileCountType getType() const
Definition: Function.h:254
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:312
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:211
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition: Function.h:384
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
Attribute getFnAttribute(StringRef Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:317
const_iterator end() const
Definition: Function.h:637
bool isConvergent() const
Determine if the call is convergent.
Definition: Function.h:514
bool hasProfileData() const
Return true if the function is annotated with profile data.
Definition: Function.h:289
void removeFnAttr(StringRef Kind)
Remove function attribute from this function.
Definition: Function.h:232
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand...
Definition: Function.h:105
iterator_range< arg_iterator > args()
Definition: Function.h:667
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70
void setReturnDoesNotAlias()
Definition: Function.h:568