llvm/llvm/lib/IR/Module.cpp

//===- Module.cpp - Implement the Module class ----------------------------===//
//
// 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 Module class for the IR library.
//
//===----------------------------------------------------------------------===//

#include "llvm/IR/Module.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GVMaterializer.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalIFunc.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/SymbolTableListTraits.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/RandomNumberGenerator.h"
#include "llvm/Support/VersionTuple.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
#include <optional>
#include <utility>
#include <vector>

usingnamespacellvm;

extern cl::opt<bool> UseNewDbgInfoFormat;

//===----------------------------------------------------------------------===//
// Methods to implement the globals and functions lists.
//

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

//===----------------------------------------------------------------------===//
// Primitive Module methods.
//

Module::Module(StringRef MID, LLVMContext &C)
    :{}

Module::~Module() {}

void Module::removeDebugIntrinsicDeclarations() {}

std::unique_ptr<RandomNumberGenerator>
Module::createRNG(const StringRef Name) const {}

/// getNamedValue - Return the first global value in the module with
/// the specified name, of arbitrary type.  This method returns null
/// if a global with the specified name is not found.
GlobalValue *Module::getNamedValue(StringRef Name) const {}

unsigned Module::getNumNamedValues() const {}

/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
/// This ID is uniqued across modules in the current LLVMContext.
unsigned Module::getMDKindID(StringRef Name) const {}

/// getMDKindNames - Populate client supplied SmallVector with the name for
/// custom metadata IDs registered in this LLVMContext.   ID #0 is not used,
/// so it is filled in as an empty string.
void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {}

void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const {}

//===----------------------------------------------------------------------===//
// Methods for easy access to the functions in the module.
//

// getOrInsertFunction - Look up the specified function in the module symbol
// table.  If it does not exist, add a prototype for the function and return
// it.  This is nice because it allows most passes to get away with not handling
// the symbol table directly for this common task.
//
FunctionCallee Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
                                           AttributeList AttributeList) {}

FunctionCallee Module::getOrInsertFunction(StringRef Name, FunctionType *Ty) {}

// getFunction - Look up the specified function in the module symbol table.
// If it does not exist, return null.
//
Function *Module::getFunction(StringRef Name) const {}

//===----------------------------------------------------------------------===//
// Methods for easy access to the global variables in the module.
//

/// getGlobalVariable - Look up the specified global variable in the module
/// symbol table.  If it does not exist, return null.  The type argument
/// should be the underlying type of the global, i.e., it should not have
/// the top-level PointerType, which represents the address of the global.
/// If AllowLocal is set to true, this function will return types that
/// have an local. By default, these types are not returned.
///
GlobalVariable *Module::getGlobalVariable(StringRef Name,
                                          bool AllowLocal) const {}

/// getOrInsertGlobal - Look up the specified global in the module symbol table.
///   1. If it does not exist, add a declaration of the global and return it.
///   2. Else, the global exists but has the wrong type: return the function
///      with a constantexpr cast to the right type.
///   3. Finally, if the existing global is the correct declaration, return the
///      existing global.
Constant *Module::getOrInsertGlobal(
    StringRef Name, Type *Ty,
    function_ref<GlobalVariable *()> CreateGlobalCallback) {}

// Overload to construct a global variable using its constructor's defaults.
Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {}

//===----------------------------------------------------------------------===//
// Methods for easy access to the global variables in the module.
//

// getNamedAlias - Look up the specified global in the module symbol table.
// If it does not exist, return null.
//
GlobalAlias *Module::getNamedAlias(StringRef Name) const {}

GlobalIFunc *Module::getNamedIFunc(StringRef Name) const {}

/// getNamedMetadata - Return the first NamedMDNode in the module with the
/// specified name. This method returns null if a NamedMDNode with the
/// specified name is not found.
NamedMDNode *Module::getNamedMetadata(StringRef Name) const {}

/// getOrInsertNamedMetadata - Return the first named MDNode in the module
/// with the specified name. This method returns a new NamedMDNode if a
/// NamedMDNode with the specified name is not found.
NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {}

/// eraseNamedMetadata - Remove the given NamedMDNode from this module and
/// delete it.
void Module::eraseNamedMetadata(NamedMDNode *NMD) {}

bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {}

/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
void Module::
getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {}

/// Return the corresponding value if Key appears in module flags, otherwise
/// return null.
Metadata *Module::getModuleFlag(StringRef Key) const {}

/// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
/// represents module-level flags. If module-level flags aren't found, it
/// creates the named metadata that contains them.
NamedMDNode *Module::getOrInsertModuleFlagsMetadata() {}

/// addModuleFlag - Add a module-level flag to the module-level flags
/// metadata. It will create the module-level flags named metadata if it doesn't
/// already exist.
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           Metadata *Val) {}
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           Constant *Val) {}
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           uint32_t Val) {}
void Module::addModuleFlag(MDNode *Node) {}

void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           Metadata *Val) {}
void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           Constant *Val) {}
void Module::setModuleFlag(ModFlagBehavior Behavior, StringRef Key,
                           uint32_t Val) {}

void Module::setDataLayout(StringRef Desc) {}

void Module::setDataLayout(const DataLayout &Other) {}

DICompileUnit *Module::debug_compile_units_iterator::operator*() const {}
DICompileUnit *Module::debug_compile_units_iterator::operator->() const {}

void Module::debug_compile_units_iterator::SkipNoDebugCUs() {}

iterator_range<Module::global_object_iterator> Module::global_objects() {}
iterator_range<Module::const_global_object_iterator>
Module::global_objects() const {}

iterator_range<Module::global_value_iterator> Module::global_values() {}
iterator_range<Module::const_global_value_iterator>
Module::global_values() const {}

//===----------------------------------------------------------------------===//
// Methods to control the materialization of GlobalValues in the Module.
//
void Module::setMaterializer(GVMaterializer *GVM) {}

Error Module::materialize(GlobalValue *GV) {}

Error Module::materializeAll() {}

Error Module::materializeMetadata() {}

//===----------------------------------------------------------------------===//
// Other module related stuff.
//

std::vector<StructType *> Module::getIdentifiedStructTypes() const {}

std::string Module::getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id,
                                           const FunctionType *Proto) {}

// dropAllReferences() - This function causes all the subelements to "let go"
// of all references that they are maintaining.  This allows one to 'delete' a
// whole module at a time, even though there may be circular references... first
// all references are dropped, and all use counts go to zero.  Then everything
// is deleted for real.  Note that no operations are valid on an object that
// has "dropped all references", except operator delete.
//
void Module::dropAllReferences() {}

unsigned Module::getNumberRegisterParameters() const {}

unsigned Module::getDwarfVersion() const {}

bool Module::isDwarf64() const {}

unsigned Module::getCodeViewFlag() const {}

unsigned Module::getInstructionCount() const {}

Comdat *Module::getOrInsertComdat(StringRef Name) {}

PICLevel::Level Module::getPICLevel() const {}

void Module::setPICLevel(PICLevel::Level PL) {}

PIELevel::Level Module::getPIELevel() const {}

void Module::setPIELevel(PIELevel::Level PL) {}

std::optional<CodeModel::Model> Module::getCodeModel() const {}

void Module::setCodeModel(CodeModel::Model CL) {}

std::optional<uint64_t> Module::getLargeDataThreshold() const {}

void Module::setLargeDataThreshold(uint64_t Threshold) {}

void Module::setProfileSummary(Metadata *M, ProfileSummary::Kind Kind) {}

Metadata *Module::getProfileSummary(bool IsCS) const {}

bool Module::getSemanticInterposition() const {}

void Module::setSemanticInterposition(bool SI) {}

void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {}

bool Module::getRtLibUseGOT() const {}

void Module::setRtLibUseGOT() {}

bool Module::getDirectAccessExternalData() const {}

void Module::setDirectAccessExternalData(bool Value) {}

UWTableKind Module::getUwtable() const {}

void Module::setUwtable(UWTableKind Kind) {}

FramePointerKind Module::getFramePointer() const {}

void Module::setFramePointer(FramePointerKind Kind) {}

StringRef Module::getStackProtectorGuard() const {}

void Module::setStackProtectorGuard(StringRef Kind) {}

StringRef Module::getStackProtectorGuardReg() const {}

void Module::setStackProtectorGuardReg(StringRef Reg) {}

StringRef Module::getStackProtectorGuardSymbol() const {}

void Module::setStackProtectorGuardSymbol(StringRef Symbol) {}

int Module::getStackProtectorGuardOffset() const {}

void Module::setStackProtectorGuardOffset(int Offset) {}

unsigned Module::getOverrideStackAlignment() const {}

unsigned Module::getMaxTLSAlignment() const {}

void Module::setOverrideStackAlignment(unsigned Align) {}

static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name) {}

void Module::setSDKVersion(const VersionTuple &V) {}

static VersionTuple getSDKVersionMD(Metadata *MD) {}

VersionTuple Module::getSDKVersion() const {}

GlobalVariable *llvm::collectUsedGlobalVariables(
    const Module &M, SmallVectorImpl<GlobalValue *> &Vec, bool CompilerUsed) {}

void Module::setPartialSampleProfileRatio(const ModuleSummaryIndex &Index) {}

StringRef Module::getDarwinTargetVariantTriple() const {}

void Module::setDarwinTargetVariantTriple(StringRef T) {}

VersionTuple Module::getDarwinTargetVariantSDKVersion() const {}

void Module::setDarwinTargetVariantSDKVersion(VersionTuple Version) {}