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