llvm/llvm/lib/IR/Function.cpp

//===- Function.cpp - Implement the Global object classes -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the Function class for the IR library.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/Function.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/AbstractCallSite.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicsAArch64.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsARM.h"
#include "llvm/IR/IntrinsicsBPF.h"
#include "llvm/IR/IntrinsicsDirectX.h"
#include "llvm/IR/IntrinsicsHexagon.h"
#include "llvm/IR/IntrinsicsLoongArch.h"
#include "llvm/IR/IntrinsicsMips.h"
#include "llvm/IR/IntrinsicsNVPTX.h"
#include "llvm/IR/IntrinsicsPowerPC.h"
#include "llvm/IR/IntrinsicsR600.h"
#include "llvm/IR/IntrinsicsRISCV.h"
#include "llvm/IR/IntrinsicsS390.h"
#include "llvm/IR/IntrinsicsSPIRV.h"
#include "llvm/IR/IntrinsicsVE.h"
#include "llvm/IR/IntrinsicsWebAssembly.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/IntrinsicsXCore.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ModRef.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>

usingnamespacellvm;
ProfileCount;

// Explicit instantiations of SymbolTableListTraits since some of the methods
// are not in the public header file...
template class llvm::SymbolTableListTraits<BasicBlock>;

static cl::opt<int> NonGlobalValueMaxNameSize(
    "non-global-value-max-name-size", cl::Hidden, cl::init(1024),
    cl::desc("Maximum size for the name of non-global values."));

extern cl::opt<bool> UseNewDbgInfoFormat;

void Function::renumberBlocks() {}

void Function::validateBlockNumbers() const {}

void Function::convertToNewDbgValues() {}

void Function::convertFromNewDbgValues() {}

void Function::setIsNewDbgInfoFormat(bool NewFlag) {}
void Function::setNewDbgInfoFormatFlag(bool NewFlag) {}

//===----------------------------------------------------------------------===//
// Argument Implementation
//===----------------------------------------------------------------------===//

Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
    :{}

void Argument::setParent(Function *parent) {}

bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const {}

bool Argument::hasByValAttr() const {}

bool Argument::hasByRefAttr() const {}

bool Argument::hasSwiftSelfAttr() const {}

bool Argument::hasSwiftErrorAttr() const {}

bool Argument::hasInAllocaAttr() const {}

bool Argument::hasPreallocatedAttr() const {}

bool Argument::hasPassPointeeByValueCopyAttr() const {}

bool Argument::hasPointeeInMemoryValueAttr() const {}

/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
/// parameter type.
static Type *getMemoryParamAllocType(AttributeSet ParamAttrs) {}

uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const {}

Type *Argument::getPointeeInMemoryValueType() const {}

MaybeAlign Argument::getParamAlign() const {}

MaybeAlign Argument::getParamStackAlign() const {}

Type *Argument::getParamByValType() const {}

Type *Argument::getParamStructRetType() const {}

Type *Argument::getParamByRefType() const {}

Type *Argument::getParamInAllocaType() const {}

uint64_t Argument::getDereferenceableBytes() const {}

uint64_t Argument::getDereferenceableOrNullBytes() const {}

FPClassTest Argument::getNoFPClass() const {}

std::optional<ConstantRange> Argument::getRange() const {}

bool Argument::hasNestAttr() const {}

bool Argument::hasNoAliasAttr() const {}

bool Argument::hasNoCaptureAttr() const {}

bool Argument::hasNoFreeAttr() const {}

bool Argument::hasStructRetAttr() const {}

bool Argument::hasInRegAttr() const {}

bool Argument::hasReturnedAttr() const {}

bool Argument::hasZExtAttr() const {}

bool Argument::hasSExtAttr() const {}

bool Argument::onlyReadsMemory() const {}

void Argument::addAttrs(AttrBuilder &B) {}

void Argument::addAttr(Attribute::AttrKind Kind) {}

void Argument::addAttr(Attribute Attr) {}

void Argument::removeAttr(Attribute::AttrKind Kind) {}

void Argument::removeAttrs(const AttributeMask &AM) {}

bool Argument::hasAttribute(Attribute::AttrKind Kind) const {}

Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {}

//===----------------------------------------------------------------------===//
// Helper Methods in Function
//===----------------------------------------------------------------------===//

LLVMContext &Function::getContext() const {}

const DataLayout &Function::getDataLayout() const {}

unsigned Function::getInstructionCount() const {}

Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage,
                           const Twine &N, Module &M) {}

Function *Function::createWithDefaultAttr(FunctionType *Ty,
                                          LinkageTypes Linkage,
                                          unsigned AddrSpace, const Twine &N,
                                          Module *M) {}

void Function::removeFromParent() {}

void Function::eraseFromParent() {}

void Function::splice(Function::iterator ToIt, Function *FromF,
                      Function::iterator FromBeginIt,
                      Function::iterator FromEndIt) {}

Function::iterator Function::erase(Function::iterator FromIt,
                                   Function::iterator ToIt) {}

//===----------------------------------------------------------------------===//
// Function Implementation
//===----------------------------------------------------------------------===//

static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {}

Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
                   const Twine &name, Module *ParentModule)
    :{}

Function::~Function() {}

void Function::BuildLazyArguments() const {}

static MutableArrayRef<Argument> makeArgArray(Argument *Args, size_t Count) {}

bool Function::isConstrainedFPIntrinsic() const {}

void Function::clearArguments() {}

void Function::stealArgumentListFrom(Function &Src) {}

void Function::deleteBodyImpl(bool ShouldDrop) {}

void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {}

void Function::addFnAttr(Attribute::AttrKind Kind) {}

void Function::addFnAttr(StringRef Kind, StringRef Val) {}

void Function::addFnAttr(Attribute Attr) {}

void Function::addFnAttrs(const AttrBuilder &Attrs) {}

void Function::addRetAttr(Attribute::AttrKind Kind) {}

void Function::addRetAttr(Attribute Attr) {}

void Function::addRetAttrs(const AttrBuilder &Attrs) {}

void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {}

void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {}

void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {}

void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {}

void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) {}

void Function::removeFnAttr(Attribute::AttrKind Kind) {}

void Function::removeFnAttr(StringRef Kind) {}

void Function::removeFnAttrs(const AttributeMask &AM) {}

void Function::removeRetAttr(Attribute::AttrKind Kind) {}

void Function::removeRetAttr(StringRef Kind) {}

void Function::removeRetAttrs(const AttributeMask &Attrs) {}

void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {}

void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {}

void Function::removeParamAttrs(unsigned ArgNo, const AttributeMask &Attrs) {}

void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {}

bool Function::hasFnAttribute(Attribute::AttrKind Kind) const {}

bool Function::hasFnAttribute(StringRef Kind) const {}

bool Function::hasRetAttribute(Attribute::AttrKind Kind) const {}

bool Function::hasParamAttribute(unsigned ArgNo,
                                 Attribute::AttrKind Kind) const {}

Attribute Function::getAttributeAtIndex(unsigned i,
                                        Attribute::AttrKind Kind) const {}

Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const {}

Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const {}

Attribute Function::getFnAttribute(StringRef Kind) const {}

Attribute Function::getRetAttribute(Attribute::AttrKind Kind) const {}

uint64_t Function::getFnAttributeAsParsedInteger(StringRef Name,
                                                 uint64_t Default) const {}

/// gets the specified attribute from the list of attributes.
Attribute Function::getParamAttribute(unsigned ArgNo,
                                      Attribute::AttrKind Kind) const {}

void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo,
                                                 uint64_t Bytes) {}

void Function::addRangeRetAttr(const ConstantRange &CR) {}

DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const {}

DenormalMode Function::getDenormalModeRaw() const {}

DenormalMode Function::getDenormalModeF32Raw() const {}

const std::string &Function::getGC() const {}

void Function::setGC(std::string Str) {}

void Function::clearGC() {}

bool Function::hasStackProtectorFnAttr() const {}

/// Copy all additional attributes (those not needed to create a Function) from
/// the Function Src to this one.
void Function::copyAttributesFrom(const Function *Src) {}

MemoryEffects Function::getMemoryEffects() const {}
void Function::setMemoryEffects(MemoryEffects ME) {}

/// Determine if the function does not access memory.
bool Function::doesNotAccessMemory() const {}
void Function::setDoesNotAccessMemory() {}

/// Determine if the function does not access or only reads memory.
bool Function::onlyReadsMemory() const {}
void Function::setOnlyReadsMemory() {}

/// Determine if the function does not access or only writes memory.
bool Function::onlyWritesMemory() const {}
void Function::setOnlyWritesMemory() {}

/// Determine if the call can access memmory only using pointers based
/// on its arguments.
bool Function::onlyAccessesArgMemory() const {}
void Function::setOnlyAccessesArgMemory() {}

/// Determine if the function may only access memory that is
///  inaccessible from the IR.
bool Function::onlyAccessesInaccessibleMemory() const {}
void Function::setOnlyAccessesInaccessibleMemory() {}

/// Determine if the function may only access memory that is
///  either inaccessible from the IR or pointed to by its arguments.
bool Function::onlyAccessesInaccessibleMemOrArgMem() const {}
void Function::setOnlyAccessesInaccessibleMemOrArgMem() {}

/// Table of string intrinsic names indexed by enum value.
static const char * const IntrinsicNameTable[] =;

/// Table of per-target intrinsic name tables.
#define GET_INTRINSIC_TARGET_DATA
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_TARGET_DATA

bool Function::isTargetIntrinsic(Intrinsic::ID IID) {}

bool Function::isTargetIntrinsic() const {}

/// Find the segment of \c IntrinsicNameTable for intrinsics with the same
/// target as \c Name, or the generic table if \c Name is not target specific.
///
/// Returns the relevant slice of \c IntrinsicNameTable
static ArrayRef<const char *> findTargetSubtable(StringRef Name) {}

/// This does the actual lookup of an intrinsic ID which
/// matches the given function name.
Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) {}

void Function::updateAfterNameChange() {}

/// Returns a stable mangling for the type specified for use in the name
/// mangling scheme used by 'any' types in intrinsic signatures.  The mangling
/// of named types is simply their name.  Manglings for unnamed types consist
/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
/// combined with the mangling of their component types.  A vararg function
/// type will have a suffix of 'vararg'.  Since function types can contain
/// other function types, we close a function type mangling with suffix 'f'
/// which can't be confused with it's prefix.  This ensures we don't have
/// collisions between two unrelated function types. Otherwise, you might
/// parse ffXX as f(fXX) or f(fX)X.  (X is a placeholder for any other type.)
/// The HasUnnamedType boolean is set if an unnamed type was encountered,
/// indicating that extra care must be taken to ensure a unique name.
static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {}

StringRef Intrinsic::getBaseName(ID id) {}

StringRef Intrinsic::getName(ID id) {}

static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
                                        Module *M, FunctionType *FT,
                                        bool EarlyModuleCheck) {}

std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys, Module *M,
                               FunctionType *FT) {}

std::string Intrinsic::getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys) {}

/// IIT_Info - These are enumerators that describe the entries returned by the
/// getIntrinsicInfoTableEntries function.
///
/// Defined in Intrinsics.td.
enum IIT_Info {};

static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
                      IIT_Info LastInfo,
                      SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {}

#define GET_INTRINSIC_GENERATOR_GLOBAL
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_GENERATOR_GLOBAL

void Intrinsic::getIntrinsicInfoTableEntries(ID id,
                                             SmallVectorImpl<IITDescriptor> &T){}

static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
                             ArrayRef<Type*> Tys, LLVMContext &Context) {}

FunctionType *Intrinsic::getType(LLVMContext &Context,
                                 ID id, ArrayRef<Type*> Tys) {}

bool Intrinsic::isOverloaded(ID id) {}

/// This defines the "Intrinsic::getAttributes(ID id)" method.
#define GET_INTRINSIC_ATTRIBUTES
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_ATTRIBUTES

Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) {}

// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN

// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN

bool Intrinsic::isConstrainedFPIntrinsic(ID QID) {}

bool Intrinsic::hasConstrainedFPRoundingModeOperand(Intrinsic::ID QID) {}

DeferredIntrinsicMatchPair;

static bool matchIntrinsicType(
    Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
    SmallVectorImpl<Type *> &ArgTys,
    SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
    bool IsDeferredCheck) {}

Intrinsic::MatchIntrinsicTypesResult
Intrinsic::matchIntrinsicSignature(FunctionType *FTy,
                                   ArrayRef<Intrinsic::IITDescriptor> &Infos,
                                   SmallVectorImpl<Type *> &ArgTys) {}

bool
Intrinsic::matchIntrinsicVarArg(bool isVarArg,
                                ArrayRef<Intrinsic::IITDescriptor> &Infos) {}

bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
                                      SmallVectorImpl<Type *> &ArgTys) {}

bool Intrinsic::getIntrinsicSignature(Function *F,
                                      SmallVectorImpl<Type *> &ArgTys) {}

std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {}

/// hasAddressTaken - returns true if there are any uses of this function
/// other than direct calls or invokes to it. Optionally ignores callback
/// uses, assume like pointer annotation calls, and references in llvm.used
/// and llvm.compiler.used variables.
bool Function::hasAddressTaken(const User **PutOffender,
                               bool IgnoreCallbackUses,
                               bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed,
                               bool IgnoreARCAttachedCall,
                               bool IgnoreCastedDirectCall) const {}

bool Function::isDefTriviallyDead() const {}

/// callsFunctionThatReturnsTwice - Return true if the function has a call to
/// setjmp or other function that gcc recognizes as "returning twice".
bool Function::callsFunctionThatReturnsTwice() const {}

Constant *Function::getPersonalityFn() const {}

void Function::setPersonalityFn(Constant *Fn) {}

Constant *Function::getPrefixData() const {}

void Function::setPrefixData(Constant *PrefixData) {}

Constant *Function::getPrologueData() const {}

void Function::setPrologueData(Constant *PrologueData) {}

void Function::allocHungoffUselist() {}

template <int Idx>
void Function::setHungoffOperand(Constant *C) {}

void Function::setValueSubclassDataBit(unsigned Bit, bool On) {}

void Function::setEntryCount(ProfileCount Count,
                             const DenseSet<GlobalValue::GUID> *S) {}

void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type,
                             const DenseSet<GlobalValue::GUID> *Imports) {}

std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {}

DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const {}

void Function::setSectionPrefix(StringRef Prefix) {}

std::optional<StringRef> Function::getSectionPrefix() const {}

bool Function::nullPointerIsDefined() const {}

bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {}