1 //===- llvm/Function.h - Class to represent a single function ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the Function class, which represents a
11 // single function/procedure in LLVM.
13 // A function basically consists of a list of basic blocks, a list of arguments,
14 // and a symbol table.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_IR_FUNCTION_H
19 #define LLVM_IR_FUNCTION_H
21 #include "llvm/ADT/DenseSet.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Twine.h"
24 #include "llvm/ADT/ilist_node.h"
25 #include "llvm/ADT/iterator_range.h"
26 #include "llvm/IR/Argument.h"
27 #include "llvm/IR/Attributes.h"
28 #include "llvm/IR/BasicBlock.h"
29 #include "llvm/IR/CallingConv.h"
30 #include "llvm/IR/DerivedTypes.h"
31 #include "llvm/IR/GlobalObject.h"
32 #include "llvm/IR/GlobalValue.h"
33 #include "llvm/IR/OperandTraits.h"
34 #include "llvm/IR/SymbolTableListTraits.h"
35 #include "llvm/IR/Value.h"
36 #include "llvm/Support/Casting.h"
37 #include "llvm/Support/Compiler.h"
50 class AssemblyAnnotationWriter;
55 template <typename T> class Optional;
60 class Function : public GlobalObject, public ilist_node<Function> {
62 using BasicBlockListType = SymbolTableList<BasicBlock>;
64 // BasicBlock iterators...
65 using iterator = BasicBlockListType::iterator;
66 using const_iterator = BasicBlockListType::const_iterator;
68 using arg_iterator = Argument *;
69 using const_arg_iterator = const Argument *;
72 // Important things that make up a function!
73 BasicBlockListType BasicBlocks; ///< The basic blocks
74 mutable Argument *Arguments = nullptr; ///< The formal arguments
76 std::unique_ptr<ValueSymbolTable>
77 SymTab; ///< Symbol table of args/instructions
78 AttributeList AttributeSets; ///< Parameter attributes
83 * bit 0 : HasLazyArguments
84 * bit 1 : HasPrefixData
85 * bit 2 : HasPrologueData
86 * bit 3 : HasPersonalityFn
87 * bits 4-13 : CallingConvention
89 * bits 15 : [reserved]
92 /// Bits from GlobalObject::GlobalObjectSubclassData.
94 /// Whether this function is materializable.
95 IsMaterializableBit = 0,
98 friend class SymbolTableListTraits<Function>;
100 /// hasLazyArguments/CheckLazyArguments - The argument list of a function is
101 /// built on demand, so that the list isn't allocated until the first client
102 /// needs it. The hasLazyArguments predicate returns true if the arg list
103 /// hasn't been set up yet.
105 bool hasLazyArguments() const {
106 return getSubclassDataFromValue() & (1<<0);
110 void CheckLazyArguments() const {
111 if (hasLazyArguments())
112 BuildLazyArguments();
115 void BuildLazyArguments() const;
117 void clearArguments();
119 /// Function ctor - If the (optional) Module argument is specified, the
120 /// function is automatically inserted into the end of the function list for
123 Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
124 const Twine &N = "", Module *M = nullptr);
127 Function(const Function&) = delete;
128 void operator=(const Function&) = delete;
131 // This is here to help easily convert from FunctionT * (Function * or
132 // MachineFunction *) in BlockFrequencyInfoImpl to Function * by calling
133 // FunctionT->getFunction().
134 const Function &getFunction() const { return *this; }
136 static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
137 unsigned AddrSpace, const Twine &N = "",
138 Module *M = nullptr) {
139 return new Function(Ty, Linkage, AddrSpace, N, M);
142 // TODO: remove this once all users have been updated to pass an AddrSpace
143 static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
144 const Twine &N = "", Module *M = nullptr) {
145 return new Function(Ty, Linkage, static_cast<unsigned>(-1), N, M);
148 /// Creates a new function and attaches it to a module.
150 /// Places the function in the program address space as specified
151 /// by the module's data layout.
152 static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
153 const Twine &N, Module &M);
155 // Provide fast operand accessors.
156 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
158 /// Returns the number of non-debug IR instructions in this function.
159 /// This is equivalent to the sum of the sizes of each basic block contained
160 /// within this function.
161 unsigned getInstructionCount() const;
163 /// Returns the FunctionType for me.
164 FunctionType *getFunctionType() const {
165 return cast<FunctionType>(getValueType());
168 /// Returns the type of the ret val.
169 Type *getReturnType() const { return getFunctionType()->getReturnType(); }
171 /// getContext - Return a reference to the LLVMContext associated with this
173 LLVMContext &getContext() const;
175 /// isVarArg - Return true if this function takes a variable number of
177 bool isVarArg() const { return getFunctionType()->isVarArg(); }
179 bool isMaterializable() const {
180 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
182 void setIsMaterializable(bool V) {
183 unsigned Mask = 1 << IsMaterializableBit;
184 setGlobalObjectSubClassData((~Mask & getGlobalObjectSubClassData()) |
188 /// getIntrinsicID - This method returns the ID number of the specified
189 /// function, or Intrinsic::not_intrinsic if the function is not an
190 /// intrinsic, or if the pointer is null. This value is always defined to be
191 /// zero to allow easy checking for whether a function is intrinsic or not.
192 /// The particular intrinsic functions which correspond to this value are
193 /// defined in llvm/Intrinsics.h.
194 Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; }
196 /// isIntrinsic - Returns true if the function's name starts with "llvm.".
197 /// It's possible for this function to return true while getIntrinsicID()
198 /// returns Intrinsic::not_intrinsic!
199 bool isIntrinsic() const { return HasLLVMReservedName; }
201 static Intrinsic::ID lookupIntrinsicID(StringRef Name);
203 /// Recalculate the ID for this function if it is an Intrinsic defined
204 /// in llvm/Intrinsics.h. Sets the intrinsic ID to Intrinsic::not_intrinsic
205 /// if the name of this function does not match an intrinsic in that header.
206 /// Note, this method does not need to be called directly, as it is called
207 /// from Value::setName() whenever the name of this function changes.
208 void recalculateIntrinsicID();
210 /// getCallingConv()/setCallingConv(CC) - These method get and set the
211 /// calling convention of this function. The enum values for the known
212 /// calling conventions are defined in CallingConv.h.
213 CallingConv::ID getCallingConv() const {
214 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
217 void setCallingConv(CallingConv::ID CC) {
218 auto ID = static_cast<unsigned>(CC);
219 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
220 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
223 /// Return the attribute list for this Function.
224 AttributeList getAttributes() const { return AttributeSets; }
226 /// Set the attribute list for this Function.
227 void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
229 /// Add function attributes to this function.
230 void addFnAttr(Attribute::AttrKind Kind) {
231 addAttribute(AttributeList::FunctionIndex, Kind);
234 /// Add function attributes to this function.
235 void addFnAttr(StringRef Kind, StringRef Val = StringRef()) {
236 addAttribute(AttributeList::FunctionIndex,
237 Attribute::get(getContext(), Kind, Val));
240 /// Add function attributes to this function.
241 void addFnAttr(Attribute Attr) {
242 addAttribute(AttributeList::FunctionIndex, Attr);
245 /// Remove function attributes from this function.
246 void removeFnAttr(Attribute::AttrKind Kind) {
247 removeAttribute(AttributeList::FunctionIndex, Kind);
250 /// Remove function attribute from this function.
251 void removeFnAttr(StringRef Kind) {
252 setAttributes(getAttributes().removeAttribute(
253 getContext(), AttributeList::FunctionIndex, Kind));
256 enum ProfileCountType { PCT_Invalid, PCT_Real, PCT_Synthetic };
258 /// Class to represent profile counts.
260 /// This class represents both real and synthetic profile counts.
264 ProfileCountType PCT;
265 static ProfileCount Invalid;
268 ProfileCount() : Count(-1), PCT(PCT_Invalid) {}
269 ProfileCount(uint64_t Count, ProfileCountType PCT)
270 : Count(Count), PCT(PCT) {}
271 bool hasValue() const { return PCT != PCT_Invalid; }
272 uint64_t getCount() const { return Count; }
273 ProfileCountType getType() const { return PCT; }
274 bool isSynthetic() const { return PCT == PCT_Synthetic; }
275 explicit operator bool() { return hasValue(); }
276 bool operator!() const { return !hasValue(); }
277 // Update the count retaining the same profile count type.
278 ProfileCount &setCount(uint64_t C) {
282 static ProfileCount getInvalid() { return ProfileCount(-1, PCT_Invalid); }
285 /// Set the entry count for this function.
287 /// Entry count is the number of times this function was executed based on
288 /// pgo data. \p Imports points to a set of GUIDs that needs to
289 /// be imported by the function for sample PGO, to enable the same inlines as
290 /// the profiled optimized binary.
291 void setEntryCount(ProfileCount Count,
292 const DenseSet<GlobalValue::GUID> *Imports = nullptr);
294 /// A convenience wrapper for setting entry count
295 void setEntryCount(uint64_t Count, ProfileCountType Type = PCT_Real,
296 const DenseSet<GlobalValue::GUID> *Imports = nullptr);
298 /// Get the entry count for this function.
300 /// Entry count is the number of times the function was executed based on
302 ProfileCount getEntryCount() const;
304 /// Return true if the function is annotated with profile data.
306 /// Presence of entry counts from a profile run implies the function has
307 /// profile annotations.
308 bool hasProfileData() const { return getEntryCount().hasValue(); }
310 /// Returns the set of GUIDs that needs to be imported to the function for
311 /// sample PGO, to enable the same inlines as the profiled optimized binary.
312 DenseSet<GlobalValue::GUID> getImportGUIDs() const;
314 /// Set the section prefix for this function.
315 void setSectionPrefix(StringRef Prefix);
317 /// Get the section prefix for this function.
318 Optional<StringRef> getSectionPrefix() const;
320 /// Return true if the function has the attribute.
321 bool hasFnAttribute(Attribute::AttrKind Kind) const {
322 return AttributeSets.hasFnAttribute(Kind);
325 /// Return true if the function has the attribute.
326 bool hasFnAttribute(StringRef Kind) const {
327 return AttributeSets.hasFnAttribute(Kind);
330 /// Return the attribute for the given attribute kind.
331 Attribute getFnAttribute(Attribute::AttrKind Kind) const {
332 return getAttribute(AttributeList::FunctionIndex, Kind);
335 /// Return the attribute for the given attribute kind.
336 Attribute getFnAttribute(StringRef Kind) const {
337 return getAttribute(AttributeList::FunctionIndex, Kind);
340 /// Return the stack alignment for the function.
341 unsigned getFnStackAlignment() const {
342 if (!hasFnAttribute(Attribute::StackAlignment))
344 return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
347 /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
348 /// to use during code generation.
350 return getSubclassDataFromValue() & (1<<14);
352 const std::string &getGC() const;
353 void setGC(std::string Str);
356 /// adds the attribute to the list of attributes.
357 void addAttribute(unsigned i, Attribute::AttrKind Kind);
359 /// adds the attribute to the list of attributes.
360 void addAttribute(unsigned i, Attribute Attr);
362 /// adds the attributes to the list of attributes.
363 void addAttributes(unsigned i, const AttrBuilder &Attrs);
365 /// adds the attribute to the list of attributes for the given arg.
366 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
368 /// adds the attribute to the list of attributes for the given arg.
369 void addParamAttr(unsigned ArgNo, Attribute Attr);
371 /// adds the attributes to the list of attributes for the given arg.
372 void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
374 /// removes the attribute from the list of attributes.
375 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
377 /// removes the attribute from the list of attributes.
378 void removeAttribute(unsigned i, StringRef Kind);
380 /// removes the attributes from the list of attributes.
381 void removeAttributes(unsigned i, const AttrBuilder &Attrs);
383 /// removes the attribute from the list of attributes.
384 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
386 /// removes the attribute from the list of attributes.
387 void removeParamAttr(unsigned ArgNo, StringRef Kind);
389 /// removes the attribute from the list of attributes.
390 void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
392 /// check if an attributes is in the list of attributes.
393 bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
394 return getAttributes().hasAttribute(i, Kind);
397 /// check if an attributes is in the list of attributes.
398 bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
399 return getAttributes().hasParamAttribute(ArgNo, Kind);
402 /// gets the attribute from the list of attributes.
403 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
404 return AttributeSets.getAttribute(i, Kind);
407 /// gets the attribute from the list of attributes.
408 Attribute getAttribute(unsigned i, StringRef Kind) const {
409 return AttributeSets.getAttribute(i, Kind);
412 /// adds the dereferenceable attribute to the list of attributes.
413 void addDereferenceableAttr(unsigned i, uint64_t Bytes);
415 /// adds the dereferenceable attribute to the list of attributes for
417 void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes);
419 /// adds the dereferenceable_or_null attribute to the list of
421 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes);
423 /// adds the dereferenceable_or_null attribute to the list of
424 /// attributes for the given arg.
425 void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes);
427 /// Extract the alignment for a call or parameter (0=unknown).
428 unsigned getParamAlignment(unsigned ArgNo) const {
429 return AttributeSets.getParamAlignment(ArgNo);
432 /// Extract the number of dereferenceable bytes for a call or
433 /// parameter (0=unknown).
434 /// @param i AttributeList index, referring to a return value or argument.
435 uint64_t getDereferenceableBytes(unsigned i) const {
436 return AttributeSets.getDereferenceableBytes(i);
439 /// Extract the number of dereferenceable bytes for a parameter.
440 /// @param ArgNo Index of an argument, with 0 being the first function arg.
441 uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
442 return AttributeSets.getParamDereferenceableBytes(ArgNo);
445 /// Extract the number of dereferenceable_or_null bytes for a call or
446 /// parameter (0=unknown).
447 /// @param i AttributeList index, referring to a return value or argument.
448 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
449 return AttributeSets.getDereferenceableOrNullBytes(i);
452 /// Extract the number of dereferenceable_or_null bytes for a
454 /// @param ArgNo AttributeList ArgNo, referring to an argument.
455 uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
456 return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
459 /// Determine if the function does not access memory.
460 bool doesNotAccessMemory() const {
461 return hasFnAttribute(Attribute::ReadNone);
463 void setDoesNotAccessMemory() {
464 addFnAttr(Attribute::ReadNone);
467 /// Determine if the function does not access or only reads memory.
468 bool onlyReadsMemory() const {
469 return doesNotAccessMemory() || hasFnAttribute(Attribute::ReadOnly);
471 void setOnlyReadsMemory() {
472 addFnAttr(Attribute::ReadOnly);
475 /// Determine if the function does not access or only writes memory.
476 bool doesNotReadMemory() const {
477 return doesNotAccessMemory() || hasFnAttribute(Attribute::WriteOnly);
479 void setDoesNotReadMemory() {
480 addFnAttr(Attribute::WriteOnly);
483 /// Determine if the call can access memmory only using pointers based
484 /// on its arguments.
485 bool onlyAccessesArgMemory() const {
486 return hasFnAttribute(Attribute::ArgMemOnly);
488 void setOnlyAccessesArgMemory() { addFnAttr(Attribute::ArgMemOnly); }
490 /// Determine if the function may only access memory that is
491 /// inaccessible from the IR.
492 bool onlyAccessesInaccessibleMemory() const {
493 return hasFnAttribute(Attribute::InaccessibleMemOnly);
495 void setOnlyAccessesInaccessibleMemory() {
496 addFnAttr(Attribute::InaccessibleMemOnly);
499 /// Determine if the function may only access memory that is
500 /// either inaccessible from the IR or pointed to by its arguments.
501 bool onlyAccessesInaccessibleMemOrArgMem() const {
502 return hasFnAttribute(Attribute::InaccessibleMemOrArgMemOnly);
504 void setOnlyAccessesInaccessibleMemOrArgMem() {
505 addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
508 /// Determine if the function cannot return.
509 bool doesNotReturn() const {
510 return hasFnAttribute(Attribute::NoReturn);
512 void setDoesNotReturn() {
513 addFnAttr(Attribute::NoReturn);
516 /// Determine if the function should not perform indirect branch tracking.
517 bool doesNoCfCheck() const { return hasFnAttribute(Attribute::NoCfCheck); }
519 /// Determine if the function cannot unwind.
520 bool doesNotThrow() const {
521 return hasFnAttribute(Attribute::NoUnwind);
523 void setDoesNotThrow() {
524 addFnAttr(Attribute::NoUnwind);
527 /// Determine if the call cannot be duplicated.
528 bool cannotDuplicate() const {
529 return hasFnAttribute(Attribute::NoDuplicate);
531 void setCannotDuplicate() {
532 addFnAttr(Attribute::NoDuplicate);
535 /// Determine if the call is convergent.
536 bool isConvergent() const {
537 return hasFnAttribute(Attribute::Convergent);
539 void setConvergent() {
540 addFnAttr(Attribute::Convergent);
542 void setNotConvergent() {
543 removeFnAttr(Attribute::Convergent);
546 /// Determine if the call has sideeffects.
547 bool isSpeculatable() const {
548 return hasFnAttribute(Attribute::Speculatable);
550 void setSpeculatable() {
551 addFnAttr(Attribute::Speculatable);
554 /// Determine if the function is known not to recurse, directly or
556 bool doesNotRecurse() const {
557 return hasFnAttribute(Attribute::NoRecurse);
559 void setDoesNotRecurse() {
560 addFnAttr(Attribute::NoRecurse);
563 /// True if the ABI mandates (or the user requested) that this
564 /// function be in a unwind table.
565 bool hasUWTable() const {
566 return hasFnAttribute(Attribute::UWTable);
568 void setHasUWTable() {
569 addFnAttr(Attribute::UWTable);
572 /// True if this function needs an unwind table.
573 bool needsUnwindTableEntry() const {
574 return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
577 /// Determine if the function returns a structure through first
578 /// or second pointer argument.
579 bool hasStructRetAttr() const {
580 return AttributeSets.hasParamAttribute(0, Attribute::StructRet) ||
581 AttributeSets.hasParamAttribute(1, Attribute::StructRet);
584 /// Determine if the parameter or return value is marked with NoAlias
586 bool returnDoesNotAlias() const {
587 return AttributeSets.hasAttribute(AttributeList::ReturnIndex,
590 void setReturnDoesNotAlias() {
591 addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
594 /// Optimize this function for minimum size (-Oz).
595 bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); }
597 /// Optimize this function for size (-Os) or minimum size (-Oz).
598 bool optForSize() const {
599 return hasFnAttribute(Attribute::OptimizeForSize) || optForMinSize();
602 /// copyAttributesFrom - copy all additional attributes (those not needed to
603 /// create a Function) from the Function Src to this one.
604 void copyAttributesFrom(const Function *Src);
606 /// deleteBody - This method deletes the body of the function, and converts
607 /// the linkage to external.
611 setLinkage(ExternalLinkage);
614 /// removeFromParent - This method unlinks 'this' from the containing module,
615 /// but does not delete it.
617 void removeFromParent();
619 /// eraseFromParent - This method unlinks 'this' from the containing module
622 void eraseFromParent();
624 /// Steal arguments from another function.
626 /// Drop this function's arguments and splice in the ones from \c Src.
627 /// Requires that this has no function body.
628 void stealArgumentListFrom(Function &Src);
630 /// Get the underlying elements of the Function... the basic block list is
631 /// empty for external functions.
633 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
634 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
636 static BasicBlockListType Function::*getSublistAccess(BasicBlock*) {
637 return &Function::BasicBlocks;
640 const BasicBlock &getEntryBlock() const { return front(); }
641 BasicBlock &getEntryBlock() { return front(); }
643 //===--------------------------------------------------------------------===//
644 // Symbol Table Accessing functions...
646 /// getSymbolTable() - Return the symbol table if any, otherwise nullptr.
648 inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); }
649 inline const ValueSymbolTable *getValueSymbolTable() const {
653 //===--------------------------------------------------------------------===//
654 // BasicBlock iterator forwarding functions
656 iterator begin() { return BasicBlocks.begin(); }
657 const_iterator begin() const { return BasicBlocks.begin(); }
658 iterator end () { return BasicBlocks.end(); }
659 const_iterator end () const { return BasicBlocks.end(); }
661 size_t size() const { return BasicBlocks.size(); }
662 bool empty() const { return BasicBlocks.empty(); }
663 const BasicBlock &front() const { return BasicBlocks.front(); }
664 BasicBlock &front() { return BasicBlocks.front(); }
665 const BasicBlock &back() const { return BasicBlocks.back(); }
666 BasicBlock &back() { return BasicBlocks.back(); }
668 /// @name Function Argument Iteration
671 arg_iterator arg_begin() {
672 CheckLazyArguments();
675 const_arg_iterator arg_begin() const {
676 CheckLazyArguments();
680 arg_iterator arg_end() {
681 CheckLazyArguments();
682 return Arguments + NumArgs;
684 const_arg_iterator arg_end() const {
685 CheckLazyArguments();
686 return Arguments + NumArgs;
689 iterator_range<arg_iterator> args() {
690 return make_range(arg_begin(), arg_end());
692 iterator_range<const_arg_iterator> args() const {
693 return make_range(arg_begin(), arg_end());
698 size_t arg_size() const { return NumArgs; }
699 bool arg_empty() const { return arg_size() == 0; }
701 /// Check whether this function has a personality function.
702 bool hasPersonalityFn() const {
703 return getSubclassDataFromValue() & (1<<3);
706 /// Get the personality function associated with this function.
707 Constant *getPersonalityFn() const;
708 void setPersonalityFn(Constant *Fn);
710 /// Check whether this function has prefix data.
711 bool hasPrefixData() const {
712 return getSubclassDataFromValue() & (1<<1);
715 /// Get the prefix data associated with this function.
716 Constant *getPrefixData() const;
717 void setPrefixData(Constant *PrefixData);
719 /// Check whether this function has prologue data.
720 bool hasPrologueData() const {
721 return getSubclassDataFromValue() & (1<<2);
724 /// Get the prologue data associated with this function.
725 Constant *getPrologueData() const;
726 void setPrologueData(Constant *PrologueData);
728 /// Print the function to an output stream with an optional
729 /// AssemblyAnnotationWriter.
730 void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
731 bool ShouldPreserveUseListOrder = false,
732 bool IsForDebug = false) const;
734 /// viewCFG - This function is meant for use from the debugger. You can just
735 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
736 /// program, displaying the CFG of the current function with the code for each
737 /// basic block inside. This depends on there being a 'dot' and 'gv' program
740 void viewCFG() const;
742 /// viewCFGOnly - This function is meant for use from the debugger. It works
743 /// just like viewCFG, but it does not include the contents of basic blocks
744 /// into the nodes, just the label. If you are only interested in the CFG
745 /// this can make the graph smaller.
747 void viewCFGOnly() const;
749 /// Methods for support type inquiry through isa, cast, and dyn_cast:
750 static bool classof(const Value *V) {
751 return V->getValueID() == Value::FunctionVal;
754 /// dropAllReferences() - This method causes all the subinstructions to "let
755 /// go" of all references that they are maintaining. This allows one to
756 /// 'delete' a whole module at a time, even though there may be circular
757 /// references... first all references are dropped, and all use counts go to
758 /// zero. Then everything is deleted for real. Note that no operations are
759 /// valid on an object that has "dropped all references", except operator
762 /// Since no other object in the module can have references into the body of a
763 /// function, dropping all references deletes the entire body of the function,
764 /// including any contained basic blocks.
766 void dropAllReferences();
768 /// hasAddressTaken - returns true if there are any uses of this function
769 /// other than direct calls or invokes to it, or blockaddress expressions.
770 /// Optionally passes back an offending user for diagnostic purposes.
772 bool hasAddressTaken(const User** = nullptr) const;
774 /// isDefTriviallyDead - Return true if it is trivially safe to remove
775 /// this function definition from the module (because it isn't externally
776 /// visible, does not have its address taken, and has no callers). To make
777 /// this more accurate, call removeDeadConstantUsers first.
778 bool isDefTriviallyDead() const;
780 /// callsFunctionThatReturnsTwice - Return true if the function has a call to
781 /// setjmp or other function that gcc recognizes as "returning twice".
782 bool callsFunctionThatReturnsTwice() const;
784 /// Set the attached subprogram.
786 /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
787 void setSubprogram(DISubprogram *SP);
789 /// Get the attached subprogram.
791 /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result
792 /// to \a DISubprogram.
793 DISubprogram *getSubprogram() const;
795 /// Returns true if we should emit debug info for profiling.
796 bool isDebugInfoForProfiling() const;
798 /// Check if null pointer dereferencing is considered undefined behavior for
800 /// Return value: false => null pointer dereference is undefined.
801 /// Return value: true => null pointer dereference is not undefined.
802 bool nullPointerIsDefined() const;
805 void allocHungoffUselist();
806 template<int Idx> void setHungoffOperand(Constant *C);
808 /// Shadow Value::setValueSubclassData with a private forwarding method so
809 /// that subclasses cannot accidentally use it.
810 void setValueSubclassData(unsigned short D) {
811 Value::setValueSubclassData(D);
813 void setValueSubclassDataBit(unsigned Bit, bool On);
816 /// Check whether null pointer dereferencing is considered undefined behavior
817 /// for a given function or an address space.
818 /// Null pointer access in non-zero address space is not considered undefined.
819 /// Return value: false => null pointer dereference is undefined.
820 /// Return value: true => null pointer dereference is not undefined.
821 bool NullPointerIsDefined(const Function *F, unsigned AS = 0);
824 struct OperandTraits<Function> : public HungoffOperandTraits<3> {};
826 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Function, Value)
828 } // end namespace llvm
830 #endif // LLVM_IR_FUNCTION_H