LLVM  3.7.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 
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/IR/Argument.h"
24 #include "llvm/IR/Attributes.h"
25 #include "llvm/IR/BasicBlock.h"
26 #include "llvm/IR/CallingConv.h"
27 #include "llvm/IR/GlobalObject.h"
28 #include "llvm/IR/OperandTraits.h"
29 #include "llvm/Support/Compiler.h"
30 
31 namespace llvm {
32 
33 class FunctionType;
34 class LLVMContext;
35 
36 template<> struct ilist_traits<Argument>
37  : public SymbolTableListTraits<Argument, Function> {
38 
40  return static_cast<Argument*>(&Sentinel);
41  }
42  static void destroySentinel(Argument*) {}
43 
45  Argument *ensureHead(Argument*) const { return createSentinel(); }
46  static void noteHead(Argument*, Argument*) {}
47 
48  static ValueSymbolTable *getSymTab(Function *ItemParent);
49 private:
50  mutable ilist_half_node<Argument> Sentinel;
51 };
52 
53 class Function : public GlobalObject, public ilist_node<Function> {
54 public:
57 
58  // BasicBlock iterators...
61 
64 
65 private:
66  // Important things that make up a function!
67  BasicBlockListType BasicBlocks; ///< The basic blocks
68  mutable ArgumentListType ArgumentList; ///< The formal arguments
69  ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
70  AttributeSet AttributeSets; ///< Parameter attributes
71  FunctionType *Ty;
72 
73  /*
74  * Value::SubclassData
75  *
76  * bit 0 : HasLazyArguments
77  * bit 1 : HasPrefixData
78  * bit 2 : HasPrologueData
79  * bit 3-6: CallingConvention
80  */
81 
82  /// Bits from GlobalObject::GlobalObjectSubclassData.
83  enum {
84  /// Whether this function is materializable.
85  IsMaterializableBit = 1 << 0,
86  HasMetadataHashEntryBit = 1 << 1
87  };
88  void setGlobalObjectBit(unsigned Mask, bool Value) {
90  (Value ? Mask : 0u));
91  }
92 
94 
95  void setParent(Module *parent);
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  bool hasLazyArguments() const {
102  return getSubclassDataFromValue() & (1<<0);
103  }
104  void CheckLazyArguments() const {
105  if (hasLazyArguments())
106  BuildLazyArguments();
107  }
108  void BuildLazyArguments() const;
109 
110  Function(const Function&) = delete;
111  void operator=(const Function&) = delete;
112 
113  /// Function ctor - If the (optional) Module argument is specified, the
114  /// function is automatically inserted into the end of the function list for
115  /// the module.
116  ///
117  Function(FunctionType *Ty, LinkageTypes Linkage,
118  const Twine &N = "", Module *M = nullptr);
119 
120 public:
122  const Twine &N = "", Module *M = nullptr) {
123  return new(1) Function(Ty, Linkage, N, M);
124  }
125 
126  ~Function() override;
127 
128  /// \brief Provide fast operand accessors
130 
131  /// \brief Get the personality function associated with this function.
132  bool hasPersonalityFn() const { return getNumOperands() != 0; }
134  assert(hasPersonalityFn());
135  return cast<Constant>(Op<0>());
136  }
137  void setPersonalityFn(Constant *C);
138 
139  Type *getReturnType() const; // Return the type of the ret val
140  FunctionType *getFunctionType() const; // Return the FunctionType for me
141 
142  /// getContext - Return a reference to the LLVMContext associated with this
143  /// function.
144  LLVMContext &getContext() const;
145 
146  /// isVarArg - Return true if this function takes a variable number of
147  /// arguments.
148  bool isVarArg() const;
149 
150  bool isMaterializable() const;
151  void setIsMaterializable(bool V);
152 
153  /// getIntrinsicID - This method returns the ID number of the specified
154  /// function, or Intrinsic::not_intrinsic if the function is not an
155  /// intrinsic, or if the pointer is null. This value is always defined to be
156  /// zero to allow easy checking for whether a function is intrinsic or not.
157  /// The particular intrinsic functions which correspond to this value are
158  /// defined in llvm/Intrinsics.h.
160  bool isIntrinsic() const { return getName().startswith("llvm."); }
161 
162  /// \brief Recalculate the ID for this function if it is an Intrinsic defined
163  /// in llvm/Intrinsics.h. Sets the intrinsic ID to Intrinsic::not_intrinsic
164  /// if the name of this function does not match an intrinsic in that header.
165  /// Note, this method does not need to be called directly, as it is called
166  /// from Value::setName() whenever the name of this function changes.
167  void recalculateIntrinsicID();
168 
169  /// getCallingConv()/setCallingConv(CC) - These method get and set the
170  /// calling convention of this function. The enum values for the known
171  /// calling conventions are defined in CallingConv.h.
173  return static_cast<CallingConv::ID>(getSubclassDataFromValue() >> 3);
174  }
176  setValueSubclassData((getSubclassDataFromValue() & 7) |
177  (static_cast<unsigned>(CC) << 3));
178  }
179 
180  /// @brief Return the attribute list for this Function.
181  AttributeSet getAttributes() const { return AttributeSets; }
182 
183  /// @brief Set the attribute list for this Function.
184  void setAttributes(AttributeSet attrs) { AttributeSets = attrs; }
185 
186  /// @brief Add function attributes to this function.
188  setAttributes(AttributeSets.addAttribute(getContext(),
190  }
191 
192  /// @brief Remove function attributes from this function.
194  setAttributes(AttributeSets.removeAttribute(
196  }
197 
198  /// @brief Add function attributes to this function.
201  AttributeSets.addAttribute(getContext(),
203  }
206  AttributeSets.addAttribute(getContext(),
207  AttributeSet::FunctionIndex, Kind, Value));
208  }
209 
210  /// Set the entry count for this function.
211  void setEntryCount(uint64_t Count);
212 
213  /// Get the entry count for this function.
215 
216  /// @brief Return true if the function has the attribute.
218  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
219  }
221  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
222  }
223 
224  /// @brief Return the attribute for the given attribute kind.
226  return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
227  }
229  return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
230  }
231 
232  /// \brief Return the stack alignment for the function.
233  unsigned getFnStackAlignment() const {
234  return AttributeSets.getStackAlignment(AttributeSet::FunctionIndex);
235  }
236 
237  /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
238  /// to use during code generation.
239  bool hasGC() const;
240  const char *getGC() const;
241  void setGC(const char *Str);
242  void clearGC();
243 
244  /// @brief adds the attribute to the list of attributes.
245  void addAttribute(unsigned i, Attribute::AttrKind attr);
246 
247  /// @brief adds the attributes to the list of attributes.
248  void addAttributes(unsigned i, AttributeSet attrs);
249 
250  /// @brief removes the attributes from the list of attributes.
251  void removeAttributes(unsigned i, AttributeSet attr);
252 
253  /// @brief adds the dereferenceable attribute to the list of attributes.
254  void addDereferenceableAttr(unsigned i, uint64_t Bytes);
255 
256  /// @brief adds the dereferenceable_or_null attribute to the list of
257  /// attributes.
258  void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
259 
260  /// @brief Extract the alignment for a call or parameter (0=unknown).
261  unsigned getParamAlignment(unsigned i) const {
262  return AttributeSets.getParamAlignment(i);
263  }
264 
265  /// @brief Extract the number of dereferenceable bytes for a call or
266  /// parameter (0=unknown).
267  uint64_t getDereferenceableBytes(unsigned i) const {
268  return AttributeSets.getDereferenceableBytes(i);
269  }
270 
271  /// @brief Extract the number of dereferenceable_or_null bytes for a call or
272  /// parameter (0=unknown).
273  uint64_t getDereferenceableOrNullBytes(unsigned i) const {
274  return AttributeSets.getDereferenceableOrNullBytes(i);
275  }
276 
277  /// @brief Determine if the function does not access memory.
278  bool doesNotAccessMemory() const {
279  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
281  }
284  }
285 
286  /// @brief Determine if the function does not access or only reads memory.
287  bool onlyReadsMemory() const {
288  return doesNotAccessMemory() ||
291  }
294  }
295 
296  /// @brief Determine if the call can access memmory only using pointers based
297  /// on its arguments.
298  bool onlyAccessesArgMemory() const {
299  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
301  }
304  }
305 
306  /// @brief Determine if the function cannot return.
307  bool doesNotReturn() const {
308  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
310  }
313  }
314 
315  /// @brief Determine if the function cannot unwind.
316  bool doesNotThrow() const {
317  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
319  }
322  }
323 
324  /// @brief Determine if the call cannot be duplicated.
325  bool cannotDuplicate() const {
326  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
328  }
331  }
332 
333  /// @brief Determine if the call is convergent.
334  bool isConvergent() const {
335  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
337  }
338  void setConvergent() {
340  }
341 
342 
343  /// @brief True if the ABI mandates (or the user requested) that this
344  /// function be in a unwind table.
345  bool hasUWTable() const {
346  return AttributeSets.hasAttribute(AttributeSet::FunctionIndex,
348  }
349  void setHasUWTable() {
351  }
352 
353  /// @brief True if this function needs an unwind table.
354  bool needsUnwindTableEntry() const {
355  return hasUWTable() || !doesNotThrow();
356  }
357 
358  /// @brief Determine if the function returns a structure through first
359  /// pointer argument.
360  bool hasStructRetAttr() const {
361  return AttributeSets.hasAttribute(1, Attribute::StructRet) ||
362  AttributeSets.hasAttribute(2, Attribute::StructRet);
363  }
364 
365  /// @brief Determine if the parameter does not alias other parameters.
366  /// @param n The parameter to check. 1 is the first parameter, 0 is the return
367  bool doesNotAlias(unsigned n) const {
368  return AttributeSets.hasAttribute(n, Attribute::NoAlias);
369  }
370  void setDoesNotAlias(unsigned n) {
372  }
373 
374  /// @brief Determine if the parameter can be captured.
375  /// @param n The parameter to check. 1 is the first parameter, 0 is the return
376  bool doesNotCapture(unsigned n) const {
377  return AttributeSets.hasAttribute(n, Attribute::NoCapture);
378  }
379  void setDoesNotCapture(unsigned n) {
381  }
382 
383  bool doesNotAccessMemory(unsigned n) const {
384  return AttributeSets.hasAttribute(n, Attribute::ReadNone);
385  }
386  void setDoesNotAccessMemory(unsigned n) {
388  }
389 
390  bool onlyReadsMemory(unsigned n) const {
391  return doesNotAccessMemory(n) ||
392  AttributeSets.hasAttribute(n, Attribute::ReadOnly);
393  }
394  void setOnlyReadsMemory(unsigned n) {
396  }
397 
398  /// copyAttributesFrom - copy all additional attributes (those not needed to
399  /// create a Function) from the Function Src to this one.
400  void copyAttributesFrom(const GlobalValue *Src) override;
401 
402  /// deleteBody - This method deletes the body of the function, and converts
403  /// the linkage to external.
404  ///
405  void deleteBody() {
408  }
409 
410  /// removeFromParent - This method unlinks 'this' from the containing module,
411  /// but does not delete it.
412  ///
413  void removeFromParent() override;
414 
415  /// eraseFromParent - This method unlinks 'this' from the containing module
416  /// and deletes it.
417  ///
418  void eraseFromParent() override;
419 
420 
421  /// Get the underlying elements of the Function... the basic block list is
422  /// empty for external functions.
423  ///
425  CheckLazyArguments();
426  return ArgumentList;
427  }
429  CheckLazyArguments();
430  return ArgumentList;
431  }
433  return &Function::ArgumentList;
434  }
435 
436  const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
437  BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
439  return &Function::BasicBlocks;
440  }
441 
442  const BasicBlock &getEntryBlock() const { return front(); }
443  BasicBlock &getEntryBlock() { return front(); }
444 
445  //===--------------------------------------------------------------------===//
446  // Symbol Table Accessing functions...
447 
448  /// getSymbolTable() - Return the symbol table...
449  ///
450  inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
451  inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
452 
453 
454  //===--------------------------------------------------------------------===//
455  // BasicBlock iterator forwarding functions
456  //
457  iterator begin() { return BasicBlocks.begin(); }
458  const_iterator begin() const { return BasicBlocks.begin(); }
459  iterator end () { return BasicBlocks.end(); }
460  const_iterator end () const { return BasicBlocks.end(); }
461 
462  size_t size() const { return BasicBlocks.size(); }
463  bool empty() const { return BasicBlocks.empty(); }
464  const BasicBlock &front() const { return BasicBlocks.front(); }
465  BasicBlock &front() { return BasicBlocks.front(); }
466  const BasicBlock &back() const { return BasicBlocks.back(); }
467  BasicBlock &back() { return BasicBlocks.back(); }
468 
469 /// @name Function Argument Iteration
470 /// @{
471 
473  CheckLazyArguments();
474  return ArgumentList.begin();
475  }
477  CheckLazyArguments();
478  return ArgumentList.begin();
479  }
481  CheckLazyArguments();
482  return ArgumentList.end();
483  }
485  CheckLazyArguments();
486  return ArgumentList.end();
487  }
488 
491  }
492 
495  }
496 
497 /// @}
498 
499  size_t arg_size() const;
500  bool arg_empty() const;
501 
502  bool hasPrefixData() const {
503  return getSubclassDataFromValue() & (1<<1);
504  }
505 
506  Constant *getPrefixData() const;
507  void setPrefixData(Constant *PrefixData);
508 
509  bool hasPrologueData() const {
510  return getSubclassDataFromValue() & (1<<2);
511  }
512 
513  Constant *getPrologueData() const;
514  void setPrologueData(Constant *PrologueData);
515 
516  /// Print the function to an output stream with an optional
517  /// AssemblyAnnotationWriter.
518  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr) const;
519 
520  /// viewCFG - This function is meant for use from the debugger. You can just
521  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
522  /// program, displaying the CFG of the current function with the code for each
523  /// basic block inside. This depends on there being a 'dot' and 'gv' program
524  /// in your path.
525  ///
526  void viewCFG() const;
527 
528  /// viewCFGOnly - This function is meant for use from the debugger. It works
529  /// just like viewCFG, but it does not include the contents of basic blocks
530  /// into the nodes, just the label. If you are only interested in the CFG
531  /// this can make the graph smaller.
532  ///
533  void viewCFGOnly() const;
534 
535  /// Methods for support type inquiry through isa, cast, and dyn_cast:
536  static inline bool classof(const Value *V) {
537  return V->getValueID() == Value::FunctionVal;
538  }
539 
540  /// dropAllReferences() - This method causes all the subinstructions to "let
541  /// go" of all references that they are maintaining. This allows one to
542  /// 'delete' a whole module at a time, even though there may be circular
543  /// references... first all references are dropped, and all use counts go to
544  /// zero. Then everything is deleted for real. Note that no operations are
545  /// valid on an object that has "dropped all references", except operator
546  /// delete.
547  ///
548  /// Since no other object in the module can have references into the body of a
549  /// function, dropping all references deletes the entire body of the function,
550  /// including any contained basic blocks.
551  ///
552  void dropAllReferences();
553 
554  /// hasAddressTaken - returns true if there are any uses of this function
555  /// other than direct calls or invokes to it, or blockaddress expressions.
556  /// Optionally passes back an offending user for diagnostic purposes.
557  ///
558  bool hasAddressTaken(const User** = nullptr) const;
559 
560  /// isDefTriviallyDead - Return true if it is trivially safe to remove
561  /// this function definition from the module (because it isn't externally
562  /// visible, does not have its address taken, and has no callers). To make
563  /// this more accurate, call removeDeadConstantUsers first.
564  bool isDefTriviallyDead() const;
565 
566  /// callsFunctionThatReturnsTwice - Return true if the function has a call to
567  /// setjmp or other function that gcc recognizes as "returning twice".
568  bool callsFunctionThatReturnsTwice() const;
569 
570  /// \brief Check if this has any metadata.
571  bool hasMetadata() const { return hasMetadataHashEntry(); }
572 
573  /// \brief Get the current metadata attachment, if any.
574  ///
575  /// Returns \c nullptr if such an attachment is missing.
576  /// @{
577  MDNode *getMetadata(unsigned KindID) const;
579  /// @}
580 
581  /// \brief Set a particular kind of metadata attachment.
582  ///
583  /// Sets the given attachment to \c MD, erasing it if \c MD is \c nullptr or
584  /// replacing it if it already exists.
585  /// @{
586  void setMetadata(unsigned KindID, MDNode *MD);
587  void setMetadata(StringRef Kind, MDNode *MD);
588  /// @}
589 
590  /// \brief Get all current metadata attachments.
591  void
592  getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const;
593 
594  /// \brief Drop metadata not in the given list.
595  ///
596  /// Drop all metadata from \c this not included in \c KnownIDs.
598 
599 private:
600  // Shadow Value::setValueSubclassData with a private forwarding method so that
601  // subclasses cannot accidentally use it.
602  void setValueSubclassData(unsigned short D) {
604  }
605 
606  bool hasMetadataHashEntry() const {
607  return getGlobalObjectSubClassData() & HasMetadataHashEntryBit;
608  }
609  void setHasMetadataHashEntry(bool HasEntry) {
610  setGlobalObjectBit(HasMetadataHashEntryBit, HasEntry);
611  }
612 
613  void clearMetadata();
614 };
615 
616 inline ValueSymbolTable *
618  return F ? &F->getValueSymbolTable() : nullptr;
619 }
620 
621 inline ValueSymbolTable *
623  return F ? &F->getValueSymbolTable() : nullptr;
624 }
625 
626 template <>
627 struct OperandTraits<Function> : public OptionalOperandTraits<Function> {};
628 
630 
631 } // End llvm namespace
632 
633 #endif
bool isDefTriviallyDead() const
isDefTriviallyDead - Return true if it is trivially safe to remove this function definition from the ...
Definition: Function.cpp:900
void setPersonalityFn(Constant *C)
Definition: Function.cpp:1001
BasicBlockListType::const_iterator const_iterator
Definition: Function.h:60
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
void setConvergent()
Definition: Function.h:338
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:223
LLVM Argument representation.
Definition: Argument.h:35
bool isConvergent() const
Determine if the call is convergent.
Definition: Function.h:334
Constant * getPrologueData() const
Definition: Function.cpp:956
ArgumentListType::iterator arg_iterator
Definition: Function.h:62
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
static void destroySentinel(Argument *)
Definition: Function.h:42
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.h:287
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
bool doesNotAccessMemory(unsigned n) const
Definition: Function.h:383
iterator end()
Definition: Function.h:459
iterator_range< const_arg_iterator > args() const
Definition: Function.h:493
void addDereferenceableAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: Function.cpp:359
unsigned getNumOperands() const
Definition: User.h:138
void clearGC()
Definition: Function.cpp:399
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
const char * getGC() const
Definition: Function.cpp:384
bool isIntrinsic() const
Definition: Function.h:160
Externally visible function.
Definition: GlobalValue.h:40
Type * getReturnType() const
Definition: Function.cpp:233
arg_iterator arg_end()
Definition: Function.h:480
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
Definition: Attributes.cpp:997
bool hasPrologueData() const
Definition: Function.h:509
Metadata node.
Definition: Metadata.h:740
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:225
F(f)
Argument * provideInitialHead() const
Definition: Function.h:44
iterator begin()
Definition: ilist.h:359
const_arg_iterator arg_end() const
Definition: Function.h:484
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:956
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:172
bool doesNotAlias(unsigned n) const
Determine if the parameter does not alias other parameters.
Definition: Function.h:367
bool isMaterializable() const
Definition: Function.cpp:215
size_t arg_size() const
Definition: Function.cpp:301
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: Function.h:267
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
unsigned getGlobalObjectSubClassData() const
Definition: Globals.cpp:87
void setDoesNotThrow()
Definition: Function.h:320
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Remove the specified attribute at the specified index from this attribute list.
Definition: Attributes.cpp:822
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:316
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
This file contains the simple types necessary to represent the attributes associated with functions a...
void setMetadata(unsigned KindID, MDNode *MD)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1191
Function must be in a unwind table.
Definition: Attributes.h:118
bool onlyReadsMemory(unsigned n) const
Definition: Function.h:390
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
const_iterator end() const
Definition: Function.h:460
Function does not access memory.
Definition: Attributes.h:99
Hidden pointer to structure to return.
Definition: Attributes.h:114
Function creates no aliases of pointer.
Definition: Attributes.h:85
void addFnAttr(Attribute::AttrKind N)
Add function attributes to this function.
Definition: Function.h:187
void addFnAttr(StringRef Kind, StringRef Value)
Definition: Function.h:204
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
LinkageTypes Linkage
Definition: GlobalValue.h:79
static void noteHead(Argument *, Argument *)
Definition: Function.h:46
const BasicBlock & back() const
Definition: Function.h:466
bool hasStructRetAttr() const
Determine if the function returns a structure through first pointer argument.
Definition: Function.h:360
void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes.
Definition: Function.cpp:365
const_iterator begin() const
Definition: Function.h:458
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
Definition: Function.cpp:990
void removeAttributes(unsigned i, AttributeSet attr)
removes the attributes from the list of attributes.
Definition: Function.cpp:353
iterator begin()
Definition: Function.h:457
ValueSymbolTable & getValueSymbolTable()
getSymbolTable() - Return the symbol table...
Definition: Function.h:450
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.h:278
Considered to not alias after call.
Definition: Attributes.h:83
void setOnlyAccessesArgMemory()
Definition: Function.h:302
void setDoesNotCapture(unsigned n)
Definition: Function.h:379
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:175
void setOnlyReadsMemory()
Definition: Function.h:292
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachment, if any.
Definition: Metadata.cpp:1179
const ValueSymbolTable & getValueSymbolTable() const
Definition: Function.h:451
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
iplist< BasicBlock > BasicBlockListType
Definition: Function.h:56
const_arg_iterator arg_begin() const
Definition: Function.h:476
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const
Definition: ilist.h:539
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
Definition: Function.h:405
This is an important base class in LLVM.
Definition: Constant.h:41
void dropUnknownMetadata(ArrayRef< unsigned > KnownIDs)
Drop metadata not in the given list.
Definition: Metadata.cpp:1226
BasicBlock & getEntryBlock()
Definition: Function.h:443
BasicBlock & front()
Definition: Function.h:465
void setDoesNotAlias(unsigned n)
Definition: Function.h:370
BasicBlock & back()
Definition: Function.h:467
bool hasPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.h:132
bool hasMetadata() const
Check if this has any metadata.
Definition: Function.h:571
bool doesNotReturn() const
Determine if the function cannot return.
Definition: Function.h:307
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:362
size_t size() const
Definition: Function.h:462
void copyAttributesFrom(const GlobalValue *Src) override
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:416
OptionalOperandTraits - when the number of operands may change at runtime.
Definition: OperandTraits.h:51
void recalculateIntrinsicID()
Recalculate the ID for this function if it is an Intrinsic defined in llvm/Intrinsics.h.
Definition: Function.cpp:453
arg_iterator arg_begin()
Definition: Function.h:472
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
Definition: GlobalValue.h:104
void setHasUWTable()
Definition: Function.h:349
Function doesn't unwind stack.
Definition: Attributes.h:96
BasicBlockListType::iterator iterator
Definition: Function.h:59
Mark the function as not returning.
Definition: Attributes.h:95
void setDoesNotAccessMemory(unsigned n)
Definition: Function.h:386
static iplist< BasicBlock > Function::* getSublistAccess(BasicBlock *)
Definition: Function.h:438
static iplist< Argument > Function::* getSublistAccess(Argument *)
Definition: Function.h:432
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.h:298
Call cannot be duplicated.
Definition: Attributes.h:86
void setCannotDuplicate()
Definition: Function.h:329
BasicBlockListType & getBasicBlockList()
Definition: Function.h:437
void setEntryCount(uint64_t Count)
Set the entry count for this function.
Definition: Function.cpp:985
~Function() override
Definition: Function.cpp:273
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
Definition: Function.h:273
const BasicBlockListType & getBasicBlockList() const
Definition: Function.h:436
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:215
void setDoesNotReturn()
Definition: Function.h:311
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Get all current metadata attachments.
Definition: Metadata.cpp:1216
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Provide fast operand accessors.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: ilist.h:385
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:354
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:320
const BasicBlock & getEntryBlock() const
Definition: Function.h:442
void setValueSubclassData(unsigned short D)
Definition: Value.h:508
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:159
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:284
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:181
ArgumentListType & getArgumentList()
Definition: Function.h:428
A range adaptor for a pair of iterators.
bool arg_empty() const
Definition: Function.cpp:304
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:39
void addAttribute(unsigned i, Attribute::AttrKind attr)
adds the attribute to the list of attributes.
Definition: Function.cpp:341
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Function.h:536
Function only reads from memory.
Definition: Attributes.h:100
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.cpp:379
void setGC(const char *Str)
Definition: Function.cpp:390
bool empty() const
Definition: Function.h:463
void setIsMaterializable(bool V)
Definition: Function.cpp:219
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Definition: Function.cpp:241
reference front()
Definition: ilist.h:390
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
Definition: AsmWriter.cpp:3139
AttributeSet addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:753
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:886
void removeFromParent() override
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
Definition: Function.cpp:237
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:217
unsigned short getSubclassDataFromValue() const
Definition: Value.h:507
ilist_node - Base class that provides next/prev services for nodes that use ilist_nextprev_traits or ...
Definition: ilist_node.h:43
Constant * getPersonalityFn() const
Definition: Function.h:133
void setDoesNotAccessMemory()
Definition: Function.h:282
void removeFnAttr(Attribute::AttrKind N)
Remove function attributes from this function.
Definition: Function.h:193
#define N
FunctionType * getFunctionType() const
Definition: Function.cpp:227
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Definition: Function.cpp:916
void addFnAttr(StringRef Kind)
Add function attributes to this function.
Definition: Function.h:199
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:964
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
Definition: Value.cpp:138
Compile-time customization of User operands.
Definition: User.h:34
bool hasPrefixData() const
Definition: Function.h:502
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table...
Definition: Function.h:345
#define LLVM_READONLY
Definition: Compiler.h:166
Constant * getPrefixData() const
Definition: Function.cpp:927
void setAttributes(AttributeSet attrs)
Set the attribute list for this Function.
Definition: Function.h:184
reference back()
Definition: ilist.h:398
Funciton can access memory only using pointers based on its arguments.
Definition: Attributes.h:101
Argument * createSentinel() const
Definition: Function.h:39
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Definition: Attributes.cpp:985
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
Definition: Function.h:325
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
Definition: ilist.h:78
bool hasFnAttribute(StringRef Kind) const
Definition: Function.h:220
const ARM::ArchExtKind Kind
const BasicBlock & front() const
Definition: Function.h:464
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
Definition: Function.h:261
iterator end()
Definition: ilist.h:367
aarch64 promote const
iplist< Argument > ArgumentListType
Definition: Function.h:55
LLVM Value Representation.
Definition: Value.h:69
void setOnlyReadsMemory(unsigned n)
Definition: Function.h:394
bool doesNotCapture(unsigned n) const
Determine if the parameter can be captured.
Definition: Function.h:376
const ArgumentListType & getArgumentList() const
Get the underlying elements of the Function...
Definition: Function.h:424
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:121
ArgumentListType::const_iterator const_arg_iterator
Definition: Function.h:63
void addAttributes(unsigned i, AttributeSet attrs)
adds the attributes to the list of attributes.
Definition: Function.cpp:347
Argument * ensureHead(Argument *) const
Definition: Function.h:45
Can only be moved to control-equivalent blocks.
Definition: Attributes.h:76
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.cpp:229
void setGlobalObjectSubClassData(unsigned Val)
Definition: Globals.cpp:92
unsigned getFnStackAlignment() const
Return the stack alignment for the function.
Definition: Function.h:233
iterator_range< arg_iterator > args()
Definition: Function.h:489
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:64
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:935
Attribute getFnAttribute(StringRef Kind) const
Definition: Function.h:228