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