LLVM 23.0.0git
Function.h
Go to the documentation of this file.
1//===- llvm/Function.h - Class to represent a single function ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the declaration of the Function class, which represents a
10// single function/procedure in LLVM.
11//
12// A function basically consists of a list of basic blocks, a list of arguments,
13// and a symbol table.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_IR_FUNCTION_H
18#define LLVM_IR_FUNCTION_H
19
20#include "llvm/ADT/DenseSet.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/Twine.h"
23#include "llvm/ADT/ilist_node.h"
25#include "llvm/IR/Argument.h"
26#include "llvm/IR/Attributes.h"
27#include "llvm/IR/BasicBlock.h"
28#include "llvm/IR/CallingConv.h"
31#include "llvm/IR/GlobalValue.h"
34#include "llvm/IR/Value.h"
36#include <cassert>
37#include <cstddef>
38#include <cstdint>
39#include <memory>
40#include <string>
41
42namespace llvm {
43
44namespace Intrinsic {
45typedef unsigned ID;
46}
47
49class Constant;
50class ConstantRange;
51class DataLayout;
52struct DenormalFPEnv;
53struct DenormalMode;
54class DISubprogram;
55enum LibFunc : unsigned;
56class LLVMContext;
57class Module;
58class raw_ostream;
60class Type;
61class User;
64
65class LLVM_ABI Function : public GlobalObject, public ilist_node<Function> {
66public:
68
69 // BasicBlock iterators...
72
75
76private:
77 constexpr static HungOffOperandsAllocMarker AllocMarker{};
78
79 // Important things that make up a function!
80 BasicBlockListType BasicBlocks; ///< The basic blocks
81
82 // Basic blocks need to get their number when added to a function.
83 friend void BasicBlock::setParent(Function *);
84 unsigned NextBlockNum = 0;
85 /// Epoch of block numbers. (Could be shrinked to uint8_t if required.)
86 unsigned BlockNumEpoch = 0;
87
88 mutable Argument *Arguments = nullptr; ///< The formal arguments
89 uint32_t NumArgs;
90 MaybeAlign PreferredAlign;
91 std::unique_ptr<ValueSymbolTable>
92 SymTab; ///< Symbol table of args/instructions
93 AttributeList AttributeSets; ///< Parameter attributes
94
95 /*
96 * Value::SubclassData
97 *
98 * bit 0 : HasLazyArguments
99 * bit 1 : HasPrefixData
100 * bit 2 : HasPrologueData
101 * bit 3 : HasPersonalityFn
102 * bits 4-13 : CallingConvention
103 * bits 14 : HasGC
104 * bits 15 : [reserved]
105 */
106
107 /// Bits from GlobalObject::GlobalObjectSubclassData.
108 enum {
109 /// Whether this function is materializable.
110 IsMaterializableBit = 0,
111 };
112
113 friend class SymbolTableListTraits<Function>;
114
115public:
116 /// hasLazyArguments/CheckLazyArguments - The argument list of a function is
117 /// built on demand, so that the list isn't allocated until the first client
118 /// needs it. The hasLazyArguments predicate returns true if the arg list
119 /// hasn't been set up yet.
120 bool hasLazyArguments() const {
121 return getSubclassDataFromValue() & (1<<0);
122 }
123
124 /// \see BasicBlock::convertToNewDbgValues.
125 void convertToNewDbgValues();
126
127 /// \see BasicBlock::convertFromNewDbgValues.
128 void convertFromNewDbgValues();
129
130private:
132
133 static constexpr LibFunc UnknownLibFunc = LibFunc(-1);
134
135 /// Cache for TLI::getLibFunc() result without prototype validation.
136 /// UnknownLibFunc if uninitialized. NotLibFunc if definitely not lib func.
137 /// Otherwise may be libfunc if prototype validation passes.
138 mutable LibFunc LibFuncCache = UnknownLibFunc;
139
140 void CheckLazyArguments() const {
141 if (hasLazyArguments())
142 BuildLazyArguments();
143 }
144
145 void BuildLazyArguments() const;
146
147 void clearArguments();
148
149 void deleteBodyImpl(bool ShouldDrop);
150
151 /// Function ctor - If the (optional) Module argument is specified, the
152 /// function is automatically inserted into the end of the function list for
153 /// the module.
154 ///
155 Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
156 const Twine &N = "", Module *M = nullptr);
157
158public:
159 Function(const Function&) = delete;
160 void operator=(const Function&) = delete;
161 ~Function();
162
163 // This is here to help easily convert from FunctionT * (Function * or
164 // MachineFunction *) in BlockFrequencyInfoImpl to Function * by calling
165 // FunctionT->getFunction().
166 const Function &getFunction() const { return *this; }
167
169 unsigned AddrSpace, const Twine &N = "",
170 Module *M = nullptr) {
171 return new (AllocMarker) Function(Ty, Linkage, AddrSpace, N, M);
172 }
173
174 // TODO: remove this once all users have been updated to pass an AddrSpace
176 const Twine &N = "", Module *M = nullptr) {
177 return new (AllocMarker)
178 Function(Ty, Linkage, static_cast<unsigned>(-1), N, M);
179 }
180
181 /// Creates a new function and attaches it to a module.
182 ///
183 /// Places the function in the program address space as specified
184 /// by the module's data layout.
185 static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
186 const Twine &N, Module &M);
187
188 /// Creates a function with some attributes recorded in llvm.module.flags
189 /// and the LLVMContext applied.
190 ///
191 /// Use this when synthesizing new functions that need attributes that would
192 /// have been set by command line options.
193 ///
194 /// This function should not be called from backends or the LTO pipeline. If
195 /// it is called from one of those places, some default attributes will not be
196 /// applied to the function.
197 static Function *createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage,
198 unsigned AddrSpace,
199 const Twine &N = "",
200 Module *M = nullptr);
201
202 // Provide fast operand accessors.
204
205 /// Returns the number of non-debug IR instructions in this function.
206 /// This is equivalent to the sum of the sizes of each basic block contained
207 /// within this function.
208 unsigned getInstructionCount() const;
209
210 /// Returns the FunctionType for me.
214
215 /// Returns the type of the ret val.
216 Type *getReturnType() const { return getFunctionType()->getReturnType(); }
217
218 /// getContext - Return a reference to the LLVMContext associated with this
219 /// function.
220 LLVMContext &getContext() const;
221
222 /// Get the data layout of the module this function belongs to.
223 ///
224 /// Requires the function to have a parent module.
225 const DataLayout &getDataLayout() const;
226
227 /// isVarArg - Return true if this function takes a variable number of
228 /// arguments.
229 bool isVarArg() const { return getFunctionType()->isVarArg(); }
230
231 bool isMaterializable() const {
232 return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
233 }
234 void setIsMaterializable(bool V) {
235 unsigned Mask = 1 << IsMaterializableBit;
237 (V ? Mask : 0u));
238 }
239
240 /// getIntrinsicID - This method returns the ID number of the specified
241 /// function, or Intrinsic::not_intrinsic if the function is not an
242 /// intrinsic, or if the pointer is null. This value is always defined to be
243 /// zero to allow easy checking for whether a function is intrinsic or not.
244 /// The particular intrinsic functions which correspond to this value are
245 /// defined in llvm/Intrinsics.h.
247
248 /// isIntrinsic - Returns true if the function's name starts with "llvm.".
249 /// It's possible for this function to return true while getIntrinsicID()
250 /// returns Intrinsic::not_intrinsic!
251 bool isIntrinsic() const { return HasLLVMReservedName; }
252
253 /// isTargetIntrinsic - Returns true if this function is an intrinsic and the
254 /// intrinsic is specific to a certain target. If this is not an intrinsic
255 /// or a generic intrinsic, false is returned.
256 bool isTargetIntrinsic() const;
257
258 /// Returns true if the function is one of the "Constrained Floating-Point
259 /// Intrinsics". Returns false if not, and returns false when
260 /// getIntrinsicID() returns Intrinsic::not_intrinsic.
261 bool isConstrainedFPIntrinsic() const;
262
263 /// Update internal caches that depend on the function name (such as the
264 /// intrinsic ID and libcall cache).
265 /// Note, this method does not need to be called directly, as it is called
266 /// from Value::setName() whenever the name of this function changes.
267 void updateAfterNameChange();
268
269 /// getCallingConv()/setCallingConv(CC) - These method get and set the
270 /// calling convention of this function. The enum values for the known
271 /// calling conventions are defined in CallingConv.h.
273 return static_cast<CallingConv::ID>((getSubclassDataFromValue() >> 4) &
275 }
277 auto ID = static_cast<unsigned>(CC);
278 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention");
279 setValueSubclassData((getSubclassDataFromValue() & 0xc00f) | (ID << 4));
280 }
281
282 /// Does it have a kernel calling convention?
283 bool hasKernelCallingConv() const {
284 switch (getCallingConv()) {
285 default:
286 return false;
290 return true;
291 }
292 }
293
295
296 /// Class to represent profile counts.
297 ///
298 /// This class represents both real and synthetic profile counts.
300 private:
301 uint64_t Count = 0;
303
304 public:
306 : Count(Count), PCT(PCT) {}
307 uint64_t getCount() const { return Count; }
308 ProfileCountType getType() const { return PCT; }
309 bool isSynthetic() const { return PCT == PCT_Synthetic; }
310 };
311
312 /// Set the entry count for this function.
313 ///
314 /// Entry count is the number of times this function was executed based on
315 /// pgo data. \p Imports points to a set of GUIDs that needs to
316 /// be imported by the function for sample PGO, to enable the same inlines as
317 /// the profiled optimized binary.
318 void setEntryCount(ProfileCount Count,
319 const DenseSet<GlobalValue::GUID> *Imports = nullptr);
320
321 /// A convenience wrapper for setting entry count
322 void setEntryCount(uint64_t Count, ProfileCountType Type = PCT_Real,
323 const DenseSet<GlobalValue::GUID> *Imports = nullptr);
324
325 /// Get the entry count for this function.
326 ///
327 /// Entry count is the number of times the function was executed.
328 /// When AllowSynthetic is false, only pgo_data will be returned.
329 std::optional<ProfileCount> getEntryCount(bool AllowSynthetic = false) const;
330
331 /// Return true if the function is annotated with profile data.
332 ///
333 /// Presence of entry counts from a profile run implies the function has
334 /// profile annotations. If IncludeSynthetic is false, only return true
335 /// when the profile data is real.
336 bool hasProfileData(bool IncludeSynthetic = false) const {
337 return getEntryCount(IncludeSynthetic).has_value();
338 }
339
340 /// Returns the set of GUIDs that needs to be imported to the function for
341 /// sample PGO, to enable the same inlines as the profiled optimized binary.
342 DenseSet<GlobalValue::GUID> getImportGUIDs() const;
343
344 /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
345 /// to use during code generation.
346 bool hasGC() const {
347 return getSubclassDataFromValue() & (1<<14);
348 }
349 const std::string &getGC() const;
350 void setGC(std::string Str);
351 void clearGC();
352
353 /// Return the attribute list for this Function.
354 AttributeList getAttributes() const { return AttributeSets; }
355
356 /// Set the attribute list for this Function.
357 void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
358
359 // TODO: remove non-AtIndex versions of these methods.
360 /// adds the attribute to the list of attributes.
361 void addAttributeAtIndex(unsigned i, Attribute Attr);
362
363 /// Add function attributes to this function.
364 void addFnAttr(Attribute::AttrKind Kind);
365
366 /// Add function attributes to this function.
367 void addFnAttr(StringRef Kind, StringRef Val = StringRef());
368
369 /// Add function attributes to this function.
370 void addFnAttr(Attribute Attr);
371
372 /// Add function attributes to this function.
373 void addFnAttrs(const AttrBuilder &Attrs);
374
375 /// Add return value attributes to this function.
376 void addRetAttr(Attribute::AttrKind Kind);
377
378 /// Add return value attributes to this function.
379 void addRetAttr(Attribute Attr);
380
381 /// Add return value attributes to this function.
382 void addRetAttrs(const AttrBuilder &Attrs);
383
384 /// adds the attribute to the list of attributes for the given arg.
385 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
386
387 /// adds the attribute to the list of attributes for the given arg.
388 void addParamAttr(unsigned ArgNo, Attribute Attr);
389
390 /// adds the attributes to the list of attributes for the given arg.
391 void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs);
392
393 /// removes the attribute from the list of attributes.
394 void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind);
395
396 /// removes the attribute from the list of attributes.
397 void removeAttributeAtIndex(unsigned i, StringRef Kind);
398
399 /// Remove function attributes from this function.
400 void removeFnAttr(Attribute::AttrKind Kind);
401
402 /// Remove function attribute from this function.
403 void removeFnAttr(StringRef Kind);
404
405 void removeFnAttrs(const AttributeMask &Attrs);
406
407 /// removes the attribute from the return value list of attributes.
408 void removeRetAttr(Attribute::AttrKind Kind);
409
410 /// removes the attribute from the return value list of attributes.
411 void removeRetAttr(StringRef Kind);
412
413 /// removes the attributes from the return value list of attributes.
414 void removeRetAttrs(const AttributeMask &Attrs);
415
416 /// removes the attribute from the list of attributes.
417 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind);
418
419 /// removes the attribute from the list of attributes.
420 void removeParamAttr(unsigned ArgNo, StringRef Kind);
421
422 /// removes the attribute from the list of attributes.
423 void removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs);
424
425 /// Return true if the function has the attribute.
426 bool hasFnAttribute(Attribute::AttrKind Kind) const;
427
428 /// Return true if the function has the attribute.
429 bool hasFnAttribute(StringRef Kind) const;
430
431 /// check if an attribute is in the list of attributes for the return value.
432 bool hasRetAttribute(Attribute::AttrKind Kind) const;
433
434 /// check if an attributes is in the list of attributes.
435 bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
436
437 /// Check if an attribute is in the list of attributes.
438 bool hasParamAttribute(unsigned ArgNo, StringRef Kind) const;
439
440 /// gets the attribute from the list of attributes.
441 Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const;
442
443 /// gets the attribute from the list of attributes.
444 Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const;
445
446 /// Check if attribute of the given kind is set at the given index.
447 bool hasAttributeAtIndex(unsigned Idx, Attribute::AttrKind Kind) const;
448
449 /// Return the attribute for the given attribute kind.
450 Attribute getFnAttribute(Attribute::AttrKind Kind) const;
451
452 /// Return the attribute for the given attribute kind.
453 Attribute getFnAttribute(StringRef Kind) const;
454
455 /// Return the attribute for the given attribute kind for the return value.
456 Attribute getRetAttribute(Attribute::AttrKind Kind) const;
457
458 /// For a string attribute \p Kind, parse attribute as an integer.
459 ///
460 /// \returns \p Default if attribute is not present.
461 ///
462 /// \returns \p Default if there is an error parsing the attribute integer,
463 /// and error is emitted to the LLVMContext
464 uint64_t getFnAttributeAsParsedInteger(StringRef Kind,
465 uint64_t Default = 0) const;
466
467 /// gets the specified attribute from the list of attributes.
468 Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
469
470 /// Return the stack alignment for the function.
472 return AttributeSets.getFnStackAlignment();
473 }
474
475 /// Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
476 bool hasStackProtectorFnAttr() const;
477
478 /// adds the dereferenceable attribute to the list of attributes for
479 /// the given arg.
480 void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes);
481
482 /// adds the dereferenceable_or_null attribute to the list of
483 /// attributes for the given arg.
484 void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes);
485
486 /// adds the range attribute to the list of attributes for the return value.
487 void addRangeRetAttr(const ConstantRange &CR);
488
489 MaybeAlign getParamAlign(unsigned ArgNo) const {
490 return AttributeSets.getParamAlignment(ArgNo);
491 }
492
493 MaybeAlign getParamStackAlign(unsigned ArgNo) const {
494 return AttributeSets.getParamStackAlignment(ArgNo);
495 }
496
497 /// Extract the byval type for a parameter.
498 Type *getParamByValType(unsigned ArgNo) const {
499 return AttributeSets.getParamByValType(ArgNo);
500 }
501
502 /// Extract the sret type for a parameter.
503 Type *getParamStructRetType(unsigned ArgNo) const {
504 return AttributeSets.getParamStructRetType(ArgNo);
505 }
506
507 /// Extract the inalloca type for a parameter.
508 Type *getParamInAllocaType(unsigned ArgNo) const {
509 return AttributeSets.getParamInAllocaType(ArgNo);
510 }
511
512 /// Extract the byref type for a parameter.
513 Type *getParamByRefType(unsigned ArgNo) const {
514 return AttributeSets.getParamByRefType(ArgNo);
515 }
516
517 /// Extract the preallocated type for a parameter.
518 Type *getParamPreallocatedType(unsigned ArgNo) const {
519 return AttributeSets.getParamPreallocatedType(ArgNo);
520 }
521
522 /// Extract the number of dereferenceable bytes for a parameter.
523 /// @param ArgNo Index of an argument, with 0 being the first function arg.
525 return AttributeSets.getParamDereferenceableBytes(ArgNo);
526 }
527
528 /// Extract the number of dead_on_return bytes for a parameter.
529 /// @param ArgNo Index of an argument, with 0 being the first function arg.
530 DeadOnReturnInfo getDeadOnReturnInfo(unsigned ArgNo) const {
531 return AttributeSets.getDeadOnReturnInfo(ArgNo);
532 }
533
534 /// Extract the number of dereferenceable_or_null bytes for a
535 /// parameter.
536 /// @param ArgNo AttributeList ArgNo, referring to an argument.
538 return AttributeSets.getParamDereferenceableOrNullBytes(ArgNo);
539 }
540
541 /// Extract the nofpclass attribute for a parameter.
542 FPClassTest getParamNoFPClass(unsigned ArgNo) const {
543 return AttributeSets.getParamNoFPClass(ArgNo);
544 }
545
546 /// Determine if the function is presplit coroutine.
547 bool isPresplitCoroutine() const {
548 return hasFnAttribute(Attribute::PresplitCoroutine);
549 }
550 void setPresplitCoroutine() { addFnAttr(Attribute::PresplitCoroutine); }
551 void setSplittedCoroutine() { removeFnAttr(Attribute::PresplitCoroutine); }
552
554 return hasFnAttribute(Attribute::CoroDestroyOnlyWhenComplete);
555 }
557 addFnAttr(Attribute::CoroDestroyOnlyWhenComplete);
558 }
559
560 MemoryEffects getMemoryEffects() const;
562
563 /// Determine if the function does not access memory.
564 bool doesNotAccessMemory() const;
566
567 /// Determine if the function does not access or only reads memory.
568 bool onlyReadsMemory() const;
569 void setOnlyReadsMemory();
570
571 /// Determine if the function does not access or only writes memory.
572 bool onlyWritesMemory() const;
573 void setOnlyWritesMemory();
574
575 /// Determine if the call can access memory only using pointers based
576 /// on its arguments.
577 bool onlyAccessesArgMemory() const;
579
580 /// Determine if the function may only access memory that is
581 /// inaccessible from the IR.
582 bool onlyAccessesInaccessibleMemory() const;
584
585 /// Determine if the function may only access memory that is
586 /// either inaccessible from the IR or pointed to by its arguments.
587 bool onlyAccessesInaccessibleMemOrArgMem() const;
589
590 /// Determine if the function cannot return.
591 bool doesNotReturn() const {
592 return hasFnAttribute(Attribute::NoReturn);
593 }
595 addFnAttr(Attribute::NoReturn);
596 }
597
598 /// Determine if the function should not perform indirect branch tracking.
599 bool doesNoCfCheck() const { return hasFnAttribute(Attribute::NoCfCheck); }
600
601 /// Determine if the function cannot unwind.
602 bool doesNotThrow() const {
603 return hasFnAttribute(Attribute::NoUnwind);
604 }
606 addFnAttr(Attribute::NoUnwind);
607 }
608
609 /// Determine if the call cannot be duplicated.
610 bool cannotDuplicate() const {
611 return hasFnAttribute(Attribute::NoDuplicate);
612 }
614 addFnAttr(Attribute::NoDuplicate);
615 }
616
617 /// Determine if the call is convergent.
618 bool isConvergent() const {
619 return hasFnAttribute(Attribute::Convergent);
620 }
622 addFnAttr(Attribute::Convergent);
623 }
625 removeFnAttr(Attribute::Convergent);
626 }
627
628 /// Determine if the call has sideeffects.
629 bool isSpeculatable() const {
630 return hasFnAttribute(Attribute::Speculatable);
631 }
633 addFnAttr(Attribute::Speculatable);
634 }
635
636 /// Determine if the call might deallocate memory.
637 bool doesNotFreeMemory() const {
638 return onlyReadsMemory() || hasFnAttribute(Attribute::NoFree);
639 }
641 addFnAttr(Attribute::NoFree);
642 }
643
644 /// Determine if the call can synchroize with other threads
645 bool hasNoSync() const {
646 return hasFnAttribute(Attribute::NoSync);
647 }
648 void setNoSync() {
649 addFnAttr(Attribute::NoSync);
650 }
651
652 /// Determine if the function is known not to recurse, directly or
653 /// indirectly.
654 bool doesNotRecurse() const {
655 return hasFnAttribute(Attribute::NoRecurse);
656 }
658 addFnAttr(Attribute::NoRecurse);
659 }
660
661 /// Determine if the function is required to make forward progress.
662 bool mustProgress() const {
663 return hasFnAttribute(Attribute::MustProgress) ||
664 hasFnAttribute(Attribute::WillReturn);
665 }
666 void setMustProgress() { addFnAttr(Attribute::MustProgress); }
667
668 /// Determine if the function will return.
669 bool willReturn() const { return hasFnAttribute(Attribute::WillReturn); }
670 void setWillReturn() { addFnAttr(Attribute::WillReturn); }
671
672 /// Get what kind of unwind table entry to generate for this function.
674 return AttributeSets.getUWTableKind();
675 }
676
677 /// True if the ABI mandates (or the user requested) that this
678 /// function be in a unwind table.
679 bool hasUWTable() const {
681 }
683 if (K == UWTableKind::None)
684 removeFnAttr(Attribute::UWTable);
685 else
687 }
688 /// True if this function needs an unwind table.
690 return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
691 }
692
693 /// Determine if the function returns a structure through first
694 /// or second pointer argument.
695 bool hasStructRetAttr() const {
696 return AttributeSets.hasParamAttr(0, Attribute::StructRet) ||
697 AttributeSets.hasParamAttr(1, Attribute::StructRet);
698 }
699
700 /// Determine if the parameter or return value is marked with NoAlias
701 /// attribute.
702 bool returnDoesNotAlias() const {
703 return AttributeSets.hasRetAttr(Attribute::NoAlias);
704 }
705 void setReturnDoesNotAlias() { addRetAttr(Attribute::NoAlias); }
706
707 /// Do not optimize this function (-O0).
708 bool hasOptNone() const { return hasFnAttribute(Attribute::OptimizeNone); }
709
710 /// Optimize this function for minimum size (-Oz).
711 bool hasMinSize() const { return hasFnAttribute(Attribute::MinSize); }
712
713 /// Optimize this function for size (-Os) or minimum size (-Oz).
714 bool hasOptSize() const {
715 return hasFnAttribute(Attribute::OptimizeForSize) || hasMinSize();
716 }
717
718 /// Returns the denormal handling type for the default rounding mode of the
719 /// function.
720 DenormalMode getDenormalMode(const fltSemantics &FPType) const;
721
722 /// Return the representational value of the denormal_fpenv attribute.
723 DenormalFPEnv getDenormalFPEnv() const;
724
725 /// copyAttributesFrom - copy all additional attributes (those not needed to
726 /// create a Function) from the Function Src to this one.
727 void copyAttributesFrom(const Function *Src);
728
729 /// deleteBody - This method deletes the body of the function, and converts
730 /// the linkage to external.
731 ///
732 void deleteBody() {
733 deleteBodyImpl(/*ShouldDrop=*/false);
735 }
736
737 /// removeFromParent - This method unlinks 'this' from the containing module,
738 /// but does not delete it.
739 ///
740 void removeFromParent();
741
742 /// eraseFromParent - This method unlinks 'this' from the containing module
743 /// and deletes it.
744 ///
745 void eraseFromParent();
746
747 /// Steal arguments from another function.
748 ///
749 /// Drop this function's arguments and splice in the ones from \c Src.
750 /// Requires that this has no function body.
751 void stealArgumentListFrom(Function &Src);
752
753 /// Insert \p BB in the basic block list at \p Position. \Returns an iterator
754 /// to the newly inserted BB.
756 Function::iterator FIt = BasicBlocks.insert(Position, BB);
757 return FIt;
758 }
759
760 /// Transfer all blocks from \p FromF to this function at \p ToIt.
761 void splice(Function::iterator ToIt, Function *FromF) {
762 splice(ToIt, FromF, FromF->begin(), FromF->end());
763 }
764
765 /// Transfer one BasicBlock from \p FromF at \p FromIt to this function
766 /// at \p ToIt.
767 void splice(Function::iterator ToIt, Function *FromF,
768 Function::iterator FromIt) {
769 auto FromItNext = std::next(FromIt);
770 // Single-element splice is a noop if destination == source.
771 if (ToIt == FromIt || ToIt == FromItNext)
772 return;
773 splice(ToIt, FromF, FromIt, FromItNext);
774 }
775
776 /// Transfer a range of basic blocks that belong to \p FromF from \p
777 /// FromBeginIt to \p FromEndIt, to this function at \p ToIt.
778 void splice(Function::iterator ToIt, Function *FromF,
779 Function::iterator FromBeginIt,
780 Function::iterator FromEndIt);
781
782 /// Erases a range of BasicBlocks from \p FromIt to (not including) \p ToIt.
783 /// \Returns \p ToIt.
785
786private:
787 // These need access to the underlying BB list.
790 template <class BB_t, class BB_i_t, class BI_t, class II_t>
791 friend class InstIterator;
793 friend class llvm::ilist_node_with_parent<llvm::BasicBlock, llvm::Function>;
794
795 /// Get the underlying elements of the Function... the basic block list is
796 /// empty for external functions.
797 ///
798 /// This is deliberately private because we have implemented an adequate set
799 /// of functions to modify the list, including Function::splice(),
800 /// Function::erase(), Function::insert() etc.
801 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
802 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
803
804 static BasicBlockListType Function::*getSublistAccess(BasicBlock*) {
805 return &Function::BasicBlocks;
806 }
807
808public:
809 const BasicBlock &getEntryBlock() const { return front(); }
811
812 //===--------------------------------------------------------------------===//
813 // Symbol Table Accessing functions...
814
815 /// getSymbolTable() - Return the symbol table if any, otherwise nullptr.
816 ///
817 inline ValueSymbolTable *getValueSymbolTable() { return SymTab.get(); }
818 inline const ValueSymbolTable *getValueSymbolTable() const {
819 return SymTab.get();
820 }
821
822 //===--------------------------------------------------------------------===//
823 // Block number functions
824
825 /// Return a value larger than the largest block number. Intended to allocate
826 /// a vector that is sufficiently large to hold all blocks indexed by their
827 /// number.
828 unsigned getMaxBlockNumber() const { return NextBlockNum; }
829
830 /// Renumber basic blocks into a dense value range starting from 0. Be aware
831 /// that other data structures and analyses (e.g., DominatorTree) may depend
832 /// on the value numbers and need to be updated or invalidated.
833 void renumberBlocks();
834
835 /// Return the "epoch" of current block numbers. This will return a different
836 /// value after every renumbering. The intention is: if something (e.g., an
837 /// analysis) uses block numbers, it also stores the number epoch and then
838 /// can assert later on that the epoch didn't change (indicating that the
839 /// numbering is still valid). If the epoch changed, blocks might have been
840 /// assigned new numbers and previous uses of the numbers needs to be
841 /// invalidated. This is solely intended as a debugging feature.
842 unsigned getBlockNumberEpoch() const { return BlockNumEpoch; }
843
844private:
845 /// Assert that all blocks have unique numbers within 0..NextBlockNum. This
846 /// has O(n) runtime complexity.
847 void validateBlockNumbers() const;
848
849public:
850 //===--------------------------------------------------------------------===//
851 // BasicBlock iterator forwarding functions
852 //
853 iterator begin() { return BasicBlocks.begin(); }
854 const_iterator begin() const { return BasicBlocks.begin(); }
855 iterator end () { return BasicBlocks.end(); }
856 const_iterator end () const { return BasicBlocks.end(); }
857
858 size_t size() const { return BasicBlocks.size(); }
859 bool empty() const { return BasicBlocks.empty(); }
860 const BasicBlock &front() const { return BasicBlocks.front(); }
861 BasicBlock &front() { return BasicBlocks.front(); }
862 const BasicBlock &back() const { return BasicBlocks.back(); }
863 BasicBlock &back() { return BasicBlocks.back(); }
864
865/// @name Function Argument Iteration
866/// @{
867
869 CheckLazyArguments();
870 return Arguments;
871 }
873 CheckLazyArguments();
874 return Arguments;
875 }
876
878 CheckLazyArguments();
879 return Arguments + NumArgs;
880 }
882 CheckLazyArguments();
883 return Arguments + NumArgs;
884 }
885
886 Argument* getArg(unsigned i) const {
887 assert (i < NumArgs && "getArg() out of range!");
888 CheckLazyArguments();
889 return Arguments + i;
890 }
891
898
899/// @}
900
901 size_t arg_size() const { return NumArgs; }
902 bool arg_empty() const { return arg_size() == 0; }
903
904 /// Check whether this function has a personality function.
905 bool hasPersonalityFn() const {
906 return getSubclassDataFromValue() & (1<<3);
907 }
908
909 /// Get the personality function associated with this function.
910 Constant *getPersonalityFn() const;
911 void setPersonalityFn(Constant *Fn);
912
913 /// Check whether this function has prefix data.
914 bool hasPrefixData() const {
915 return getSubclassDataFromValue() & (1<<1);
916 }
917
918 /// Get the prefix data associated with this function.
919 Constant *getPrefixData() const;
920 void setPrefixData(Constant *PrefixData);
921
922 /// Check whether this function has prologue data.
923 bool hasPrologueData() const {
924 return getSubclassDataFromValue() & (1<<2);
925 }
926
927 /// Get the prologue data associated with this function.
928 Constant *getPrologueData() const;
929 void setPrologueData(Constant *PrologueData);
930
931 /// Print the function to an output stream with an optional
932 /// AssemblyAnnotationWriter.
933 void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW = nullptr,
934 bool ShouldPreserveUseListOrder = false,
935 bool IsForDebug = false) const;
936
937 /// viewCFG - This function is meant for use from the debugger. You can just
938 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
939 /// program, displaying the CFG of the current function with the code for each
940 /// basic block inside. This depends on there being a 'dot' and 'gv' program
941 /// in your path.
942 ///
943 void viewCFG() const;
944
945 /// viewCFG - This function is meant for use from the debugger. It works just
946 /// like viewCFG(), but generates the dot file with the given file name.
947 void viewCFG(const char *OutputFileName) const;
948
949 /// Extended form to print edge weights.
950 void viewCFG(bool ViewCFGOnly, const BlockFrequencyInfo *BFI,
951 const BranchProbabilityInfo *BPI,
952 const char *OutputFileName = nullptr) const;
953
954 /// viewCFGOnly - This function is meant for use from the debugger. It works
955 /// just like viewCFG, but it does not include the contents of basic blocks
956 /// into the nodes, just the label. If you are only interested in the CFG
957 /// this can make the graph smaller.
958 ///
959 void viewCFGOnly() const;
960
961 /// viewCFG - This function is meant for use from the debugger. It works just
962 /// like viewCFGOnly(), but generates the dot file with the given file name.
963 void viewCFGOnly(const char *OutputFileName) const;
964
965 /// Extended form to print edge weights.
966 void viewCFGOnly(const BlockFrequencyInfo *BFI,
967 const BranchProbabilityInfo *BPI) const;
968
969 /// Methods for support type inquiry through isa, cast, and dyn_cast:
970 static bool classof(const Value *V) {
971 return V->getValueID() == Value::FunctionVal;
972 }
973
974 /// dropAllReferences() - This method causes all the subinstructions to "let
975 /// go" of all references that they are maintaining. This allows one to
976 /// 'delete' a whole module at a time, even though there may be circular
977 /// references... first all references are dropped, and all use counts go to
978 /// zero. Then everything is deleted for real. Note that no operations are
979 /// valid on an object that has "dropped all references", except operator
980 /// delete.
981 ///
982 /// Since no other object in the module can have references into the body of a
983 /// function, dropping all references deletes the entire body of the function,
984 /// including any contained basic blocks.
985 ///
987 deleteBodyImpl(/*ShouldDrop=*/true);
988 }
989
990 /// hasAddressTaken - returns true if there are any uses of this function
991 /// other than direct calls or invokes to it, or blockaddress expressions.
992 /// Optionally passes back an offending user for diagnostic purposes,
993 /// ignores callback uses, assume like pointer annotation calls, references in
994 /// llvm.used and llvm.compiler.used variables, operand bundle
995 /// "clang.arc.attachedcall", and direct calls with a different call site
996 /// signature (the function is implicitly casted).
997 bool hasAddressTaken(const User ** = nullptr, bool IgnoreCallbackUses = false,
998 bool IgnoreAssumeLikeCalls = true,
999 bool IngoreLLVMUsed = false,
1000 bool IgnoreARCAttachedCall = false,
1001 bool IgnoreCastedDirectCall = false) const;
1002
1003 /// isDefTriviallyDead - Return true if it is trivially safe to remove
1004 /// this function definition from the module (because it isn't externally
1005 /// visible, does not have its address taken, and has no callers). To make
1006 /// this more accurate, call removeDeadConstantUsers first.
1007 bool isDefTriviallyDead() const;
1008
1009 /// callsFunctionThatReturnsTwice - Return true if the function has a call to
1010 /// setjmp or other function that gcc recognizes as "returning twice".
1011 bool callsFunctionThatReturnsTwice() const;
1012
1013 /// Set the attached subprogram.
1014 ///
1015 /// Calls \a setMetadata() with \a LLVMContext::MD_dbg.
1016 void setSubprogram(DISubprogram *SP);
1017
1018 /// Get the attached subprogram.
1019 ///
1020 /// Calls \a getMetadata() with \a LLVMContext::MD_dbg and casts the result
1021 /// to \a DISubprogram.
1022 DISubprogram *getSubprogram() const;
1023
1024 /// Returns true if we should emit debug info for profiling.
1025 bool shouldEmitDebugInfoForProfiling() const;
1026
1027 /// Check if null pointer dereferencing is considered undefined behavior for
1028 /// the function.
1029 /// Return value: false => null pointer dereference is undefined.
1030 /// Return value: true => null pointer dereference is not undefined.
1031 bool nullPointerIsDefined() const;
1032
1033 /// Returns the alignment of the given function.
1034 ///
1035 /// Note that this is the alignment of the code, not the alignment of a
1036 /// function pointer.
1038
1039 /// Sets the alignment attribute of the Function.
1041
1042 /// Sets the alignment attribute of the Function.
1043 ///
1044 /// This method will be deprecated as the alignment property should always be
1045 /// defined.
1047
1048 /// Returns the prefalign of the given function.
1049 MaybeAlign getPreferredAlignment() const { return PreferredAlign; }
1050
1051 /// Sets the prefalign attribute of the Function.
1052 void setPreferredAlignment(MaybeAlign Align) { PreferredAlign = Align; }
1053
1054 /// Return the value for vscale based on the vscale_range attribute or 0 when
1055 /// unknown.
1056 unsigned getVScaleValue() const;
1057
1058private:
1059 void allocHungoffUselist();
1060 template<int Idx> void setHungoffOperand(Constant *C);
1061
1062 /// Shadow Value::setValueSubclassData with a private forwarding method so
1063 /// that subclasses cannot accidentally use it.
1064 void setValueSubclassData(unsigned short D) {
1066 }
1067 void setValueSubclassDataBit(unsigned Bit, bool On);
1068};
1069
1070namespace CallingConv {
1071
1072// TODO: Need similar function for support of argument in position. General
1073// version on FunctionType + Attributes + CallingConv::ID?
1075} // namespace CallingConv
1076
1077/// Check whether null pointer dereferencing is considered undefined behavior
1078/// for a given function or an address space.
1079/// Null pointer access in non-zero address space is not considered undefined.
1080/// Return value: false => null pointer dereference is undefined.
1081/// Return value: true => null pointer dereference is not undefined.
1082LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS = 0);
1083
1084template <> struct OperandTraits<Function> : public HungoffOperandTraits {};
1085
1087
1088} // end namespace llvm
1089
1090#endif // LLVM_IR_FUNCTION_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
static bool setDoesNotAccessMemory(Function &F)
static bool setMemoryEffects(Function &F, MemoryEffects ME)
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
static bool setOnlyAccessesInaccessibleMemory(Function &F)
static bool setOnlyAccessesArgMemory(Function &F)
static bool setOnlyWritesMemory(Function &F)
static bool setOnlyReadsMemory(Function &F)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void viewCFG(Function &F, const BlockFrequencyInfo *BFI, const BranchProbabilityInfo *BPI, uint64_t MaxFreq, bool CFGOnly=false)
#define LLVM_READNONE
Definition Compiler.h:315
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_READONLY
Definition Compiler.h:322
SmallVector< BasicBlock *, 8 > BasicBlockListType
Definition DDG.cpp:184
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
DXIL Finalize Linkage
This file defines the DenseSet and SmallDenseSet classes.
#define F(x, y, z)
Definition MD5.cpp:54
II addRangeRetAttr(Range)
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
static Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
static LLVM_ABI Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
LLVM Basic Block Representation.
Definition BasicBlock.h:62
const Instruction & back() const
Definition BasicBlock.h:495
friend void Instruction::removeFromParent()
friend BasicBlock::iterator Instruction::eraseFromParent()
const Instruction & front() const
Definition BasicBlock.h:493
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
This class represents a range of values.
This is an important base class in LLVM.
Definition Constant.h:43
Subprogram description. Uses SubclassData1.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Class to represent function types.
uint64_t getCount() const
Definition Function.h:307
ProfileCount(uint64_t Count, ProfileCountType PCT)
Definition Function.h:305
ProfileCountType getType() const
Definition Function.h:308
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external.
Definition Function.h:732
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition Function.cpp:639
const ValueSymbolTable * getValueSymbolTable() const
Definition Function.h:818
bool isConvergent() const
Determine if the call is convergent.
Definition Function.h:618
void setCoroDestroyOnlyWhenComplete()
Definition Function.h:556
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:168
BasicBlock & getEntryBlock()
Definition Function.h:810
SymbolTableList< BasicBlock > BasicBlockListType
Definition Function.h:67
void setAlignment(MaybeAlign Align)
Sets the alignment attribute of the Function.
Definition Function.h:1046
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition Function.h:761
const BasicBlock & getEntryBlock() const
Definition Function.h:809
BasicBlockListType::iterator iterator
Definition Function.h:70
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition Function.h:714
Argument * arg_iterator
Definition Function.h:73
void splice(Function::iterator ToIt, Function *FromF, Function::iterator FromIt)
Transfer one BasicBlock from FromF at FromIt to this function at ToIt.
Definition Function.h:767
bool empty() const
Definition Function.h:859
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:211
bool isMaterializable() const
Definition Function.h:231
MaybeAlign getAlign() const
Returns the alignment of the given function.
Definition Function.h:1037
MaybeAlign getFnStackAlign() const
Return the stack alignment for the function.
Definition Function.h:471
iterator_range< const_arg_iterator > args() const
Definition Function.h:895
bool arg_empty() const
Definition Function.h:902
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition Function.h:970
const BasicBlock & front() const
Definition Function.h:860
const_arg_iterator arg_end() const
Definition Function.h:881
const_arg_iterator arg_begin() const
Definition Function.h:872
bool mustProgress() const
Determine if the function is required to make forward progress.
Definition Function.h:662
bool returnDoesNotAlias() const
Determine if the parameter or return value is marked with NoAlias attribute.
Definition Function.h:702
bool cannotDuplicate() const
Determine if the call cannot be duplicated.
Definition Function.h:610
const BasicBlock & back() const
Definition Function.h:862
unsigned getMaxBlockNumber() const
Return a value larger than the largest block number.
Definition Function.h:828
void setWillReturn()
Definition Function.h:670
bool willReturn() const
Determine if the function will return.
Definition Function.h:669
iterator_range< arg_iterator > args()
Definition Function.h:892
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition Function.h:246
friend class TargetLibraryInfoImpl
Definition Function.h:131
bool doesNotRecurse() const
Determine if the function is known not to recurse, directly or indirectly.
Definition Function.h:654
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
Definition Function.h:711
void setDoesNotReturn()
Definition Function.h:594
bool doesNoCfCheck() const
Determine if the function should not perform indirect branch tracking.
Definition Function.h:599
void setIsMaterializable(bool V)
Definition Function.h:234
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Definition Function.h:524
bool isSpeculatable() const
Determine if the call has sideeffects.
Definition Function.h:629
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition Function.h:346
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:272
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
Definition Function.h:498
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Extract the nofpclass attribute for a parameter.
Definition Function.h:542
bool hasPrefixData() const
Check whether this function has prefix data.
Definition Function.h:914
void setReturnDoesNotAlias()
Definition Function.h:705
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition Function.h:905
void addRetAttr(Attribute::AttrKind Kind)
Add return value attributes to this function.
Definition Function.cpp:655
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition Function.h:175
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition Function.h:354
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "letgo" of all references that th...
Definition Function.h:986
unsigned getBlockNumberEpoch() const
Return the "epoch" of current block numbers.
Definition Function.h:842
void setUWTableKind(UWTableKind K)
Definition Function.h:682
BasicBlockListType::const_iterator const_iterator
Definition Function.h:71
UWTableKind getUWTableKind() const
Get what kind of unwind table entry to generate for this function.
Definition Function.h:673
Type * getParamByRefType(unsigned ArgNo) const
Extract the byref type for a parameter.
Definition Function.h:513
bool hasNoSync() const
Determine if the call can synchroize with other threads.
Definition Function.h:645
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition Function.h:602
arg_iterator arg_end()
Definition Function.h:877
const Function & getFunction() const
Definition Function.h:166
iterator begin()
Definition Function.h:853
const_iterator end() const
Definition Function.h:856
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
Definition Function.h:537
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition Function.cpp:687
arg_iterator arg_begin()
Definition Function.h:868
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition Function.h:251
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
Definition Function.h:336
const_iterator begin() const
Definition Function.h:854
void setConvergent()
Definition Function.h:621
void setPresplitCoroutine()
Definition Function.h:550
size_t size() const
Definition Function.h:858
void setAlignment(Align Align)
Sets the alignment attribute of the Function.
Definition Function.h:1040
MaybeAlign getParamAlign(unsigned ArgNo) const
Definition Function.h:489
void setSpeculatable()
Definition Function.h:632
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition Function.h:817
bool hasOptNone() const
Do not optimize this function (-O0).
Definition Function.h:708
void setCannotDuplicate()
Definition Function.h:613
Type * getParamPreallocatedType(unsigned ArgNo) const
Extract the preallocated type for a parameter.
Definition Function.h:518
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition Function.h:357
bool isPresplitCoroutine() const
Determine if the function is presplit coroutine.
Definition Function.h:547
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:358
BasicBlock & back()
Definition Function.h:863
bool hasKernelCallingConv() const
Does it have a kernel calling convention?
Definition Function.h:283
void setPreferredAlignment(MaybeAlign Align)
Sets the prefalign attribute of the Function.
Definition Function.h:1052
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition Function.h:695
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition Function.h:755
void setNotConvergent()
Definition Function.h:624
bool doesNotFreeMemory() const
Determine if the call might deallocate memory.
Definition Function.h:637
Type * getParamInAllocaType(unsigned ArgNo) const
Extract the inalloca type for a parameter.
Definition Function.h:508
bool doesNotReturn() const
Determine if the function cannot return.
Definition Function.h:591
friend class InstIterator
Definition Function.h:791
BasicBlock & front()
Definition Function.h:861
bool isCoroOnlyDestroyWhenComplete() const
Definition Function.h:553
std::optional< ProfileCount > getEntryCount(bool AllowSynthetic=false) const
Get the entry count for this function.
void setSplittedCoroutine()
Definition Function.h:551
MaybeAlign getParamStackAlign(unsigned ArgNo) const
Definition Function.h:493
size_t arg_size() const
Definition Function.h:901
void setNoSync()
Definition Function.h:648
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table.
Definition Function.h:679
void operator=(const Function &)=delete
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:216
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition Function.h:689
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand,...
Definition Function.h:120
MaybeAlign getPreferredAlignment() const
Returns the prefalign of the given function.
Definition Function.h:1049
iterator end()
Definition Function.h:855
void setCallingConv(CallingConv::ID CC)
Definition Function.h:276
Function(const Function &)=delete
bool hasPrologueData() const
Check whether this function has prologue data.
Definition Function.h:923
const Argument * const_arg_iterator
Definition Function.h:74
DeadOnReturnInfo getDeadOnReturnInfo(unsigned ArgNo) const
Extract the number of dead_on_return bytes for a parameter.
Definition Function.h:530
Type * getParamStructRetType(unsigned ArgNo) const
Extract the sret type for a parameter.
Definition Function.h:503
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
void setDoesNotRecurse()
Definition Function.h:657
Argument * getArg(unsigned i) const
Definition Function.h:886
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition Function.h:229
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
Definition Function.cpp:366
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition Function.cpp:876
void setMustProgress()
Definition Function.h:666
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:729
void setDoesNotFreeMemory()
Definition Function.h:640
void setDoesNotThrow()
Definition Function.h:605
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
LLVM_ABI void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition Globals.cpp:146
GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace=0)
void setGlobalObjectSubClassData(unsigned Val)
unsigned getGlobalObjectSubClassData() const
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
void setLinkage(LinkageTypes LT)
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
List that automatically updates parent links and symbol tables.
Implementation of the target library information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Definition Value.h:75
unsigned short getSubclassDataFromValue() const
Definition Value.h:891
void setValueSubclassData(unsigned short D)
Definition Value.h:892
An ilist node that can access its parent list.
Definition ilist_node.h:316
typename base_list_type::iterator iterator
Definition ilist.h:121
typename base_list_type::const_iterator const_iterator
Definition ilist.h:122
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
CallingConv Namespace - This namespace contains an enum with a value for the well-known calling conve...
Definition CallingConv.h:21
LLVM_ABI LLVM_READNONE bool supportsNonVoidReturnType(CallingConv::ID CC)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ MaxID
The highest possible ID. Must be some 2^k - 1.
@ SPIR_KERNEL
Used for SPIR kernel functions.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:313
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition STLExtras.h:2200
UWTableKind
Definition CodeGen.h:154
@ None
No unwind table requested.
Definition CodeGen.h:155
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
Function::ProfileCount ProfileCount
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Represents the full denormal controls for a function, including the default mode and the f32 specific...
Represent subnormal handling kind for floating point instruction inputs and outputs.
HungoffOperandTraits - determine the allocation regime of the Use array when it is not a prefix to th...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
Compile-time customization of User operands.
Definition User.h:42
Indicates this User has operands "hung off" in another allocation.
Definition User.h:57