LLVM 18.0.0git
|
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalObject.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Linker/IRMover.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <cassert>
#include <memory>
#include <set>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
Go to the source code of this file.
Classes | |
class | GlobalsImporter |
Import globals referenced by a function or other globals that are being imported, if importing such global is possible. More... | |
class | ModuleImportsManager |
Determine the list of imports and exports for each module. More... | |
Macros | |
#define | DEBUG_TYPE "function-import" |
Functions | |
STATISTIC (NumImportedFunctionsThinLink, "Number of functions thin link decided to import") | |
STATISTIC (NumImportedHotFunctionsThinLink, "Number of hot functions thin link decided to import") | |
STATISTIC (NumImportedCriticalFunctionsThinLink, "Number of critical functions thin link decided to import") | |
STATISTIC (NumImportedGlobalVarsThinLink, "Number of global variables thin link decided to import") | |
STATISTIC (NumImportedFunctions, "Number of functions imported in backend") | |
STATISTIC (NumImportedGlobalVars, "Number of global variables imported in backend") | |
STATISTIC (NumImportedModules, "Number of modules imported from") | |
STATISTIC (NumDeadSymbols, "Number of dead stripped symbols in index") | |
STATISTIC (NumLiveSymbols, "Number of live symbols in index") | |
static std::unique_ptr< Module > | loadFile (const std::string &FileName, LLVMContext &Context) |
static auto | qualifyCalleeCandidates (const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary > > CalleeSummaryList, StringRef CallerModulePath) |
Given a list of possible callee implementation for a call site, qualify the legality of importing each. | |
static const GlobalValueSummary * | selectCallee (const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary > > CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath, FunctionImporter::ImportFailureReason &Reason) |
Given a list of possible callee implementation for a call site, select one that fits the Threshold . | |
static const char * | getFailureName (FunctionImporter::ImportFailureReason Reason) |
static void | computeImportForFunction (const FunctionSummary &Summary, const ModuleSummaryIndex &Index, const unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, SmallVectorImpl< EdgeInfo > &Worklist, GlobalsImporter &GVImporter, FunctionImporter::ImportMapTy &ImportList, DenseMap< StringRef, FunctionImporter::ExportSetTy > *ExportLists, FunctionImporter::ImportThresholdsTy &ImportThresholds) |
Compute the list of functions to import for a given caller. | |
static bool | isGlobalVarSummary (const ModuleSummaryIndex &Index, ValueInfo VI) |
static bool | isGlobalVarSummary (const ModuleSummaryIndex &Index, GlobalValue::GUID G) |
template<class T > | |
static unsigned | numGlobalVarSummaries (const ModuleSummaryIndex &Index, T &Cont) |
static bool | checkVariableImport (const ModuleSummaryIndex &Index, DenseMap< StringRef, FunctionImporter::ImportMapTy > &ImportLists, DenseMap< StringRef, FunctionImporter::ExportSetTy > &ExportLists) |
static void | dumpImportListForModule (const ModuleSummaryIndex &Index, StringRef ModulePath, FunctionImporter::ImportMapTy &ImportList) |
static void | ComputeCrossModuleImportForModuleForTest (StringRef ModulePath, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, const ModuleSummaryIndex &Index, FunctionImporter::ImportMapTy &ImportList) |
Compute all the imports for the given module using the Index. | |
static void | ComputeCrossModuleImportForModuleFromIndexForTest (StringRef ModulePath, const ModuleSummaryIndex &Index, FunctionImporter::ImportMapTy &ImportList) |
Mark all external summaries in Index for import into the given module. | |
void | updateValueInfoForIndirectCalls (ModuleSummaryIndex &Index, FunctionSummary *FS) |
static Function * | replaceAliasWithAliasee (Module *SrcModule, GlobalAlias *GA) |
Make alias a clone of its aliasee. | |
static void | internalizeGVsAfterImport (Module &M) |
static bool | doImportingForModuleForTest (Module &M, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) |
Variables | |
static cl::opt< unsigned > | ImportInstrLimit ("import-instr-limit", cl::init(100), cl::Hidden, cl::value_desc("N"), cl::desc("Only import functions with less than N instructions")) |
Limit on instruction count of imported functions. | |
static cl::opt< int > | ImportCutoff ("import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"), cl::desc("Only import first N functions if N>=0 (default -1)")) |
static cl::opt< bool > | ForceImportAll ("force-import-all", cl::init(false), cl::Hidden, cl::desc("Import functions with noinline attribute")) |
static cl::opt< float > | ImportInstrFactor ("import-instr-evolution-factor", cl::init(0.7), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions")) |
static cl::opt< float > | ImportHotInstrFactor ("import-hot-evolution-factor", cl::init(1.0), cl::Hidden, cl::value_desc("x"), cl::desc("As we import functions called from hot callsite, multiply the " "`import-instr-limit` threshold by this factor " "before processing newly imported functions")) |
static cl::opt< float > | ImportHotMultiplier ("import-hot-multiplier", cl::init(10.0), cl::Hidden, cl::value_desc("x"), cl::desc("Multiply the `import-instr-limit` threshold for hot callsites")) |
static cl::opt< float > | ImportCriticalMultiplier ("import-critical-multiplier", cl::init(100.0), cl::Hidden, cl::value_desc("x"), cl::desc("Multiply the `import-instr-limit` threshold for critical callsites")) |
static cl::opt< float > | ImportColdMultiplier ("import-cold-multiplier", cl::init(0), cl::Hidden, cl::value_desc("N"), cl::desc("Multiply the `import-instr-limit` threshold for cold callsites")) |
static cl::opt< bool > | PrintImports ("print-imports", cl::init(false), cl::Hidden, cl::desc("Print imported functions")) |
static cl::opt< bool > | PrintImportFailures ("print-import-failures", cl::init(false), cl::Hidden, cl::desc("Print information for functions rejected for importing")) |
static cl::opt< bool > | ComputeDead ("compute-dead", cl::init(true), cl::Hidden, cl::desc("Compute dead symbols")) |
static cl::opt< bool > | EnableImportMetadata ("enable-import-metadata", cl::init(false), cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'")) |
static cl::opt< std::string > | SummaryFile ("summary-file", cl::desc("The summary file to use for function importing.")) |
Summary file to use for function importing when using -function-import from the command line. | |
static cl::opt< bool > | ImportAllIndex ("import-all-index", cl::desc("Import all external functions in index.")) |
Used when testing importing from distributed indexes via opt. | |
#define DEBUG_TYPE "function-import" |
Definition at line 56 of file FunctionImport.cpp.
|
static |
Definition at line 689 of file FunctionImport.cpp.
References llvm::GlobalValue::AvailableExternallyLinkage, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::GlobalValue::LinkOnceODRLinkage, and llvm::GlobalValue::WeakODRLinkage.
Referenced by llvm::ComputeCrossModuleImport().
|
static |
Compute all the imports for the given module using the Index.
isPrevailing
is a callback that will be called with a global value's GUID and summary and should return whether the module corresponding to the summary contains the linker-prevailing copy of that value.
ImportList
will be populated with a map that can be passed to FunctionImporter::importFunctions() above (see description there).
Definition at line 845 of file FunctionImport.cpp.
References ModuleImportsManager::computeImportForModule(), llvm::dbgs(), dumpImportListForModule(), and LLVM_DEBUG.
Referenced by doImportingForModuleForTest().
|
static |
Mark all external summaries in Index
for import into the given module.
Used for testing the case of distributed builds using a distributed index.
ImportList
will be populated with a map that can be passed to FunctionImporter::importFunctions() above (see description there).
Definition at line 871 of file FunctionImport.cpp.
References assert(), dumpImportListForModule(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert().
Referenced by doImportingForModuleForTest().
|
static |
Compute the list of functions to import for a given caller.
Mark these imported functions and the symbols they reference in their source module as exported from their source module.
Definition at line 421 of file FunctionImport.cpp.
References llvm::FunctionSummary::FFlags::AlwaysInline, assert(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::dbgs(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::errs(), llvm::FunctionSummary::fflags(), ForceImportAll, getFailureName(), ImportColdMultiplier, ImportCriticalMultiplier, ImportCutoff, ImportHotInstrFactor, ImportHotMultiplier, ImportInstrFactor, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::FunctionSummary::instCount(), IT, LLVM_DEBUG, llvm::logAllUnhandledErrors(), llvm::make_error_code(), llvm::GlobalValueSummary::modulePath(), GlobalsImporter::onImportingSummary(), PrintImportFailures, and selectCallee().
Referenced by ModuleImportsManager::computeImportForModule().
|
static |
Definition at line 1488 of file FunctionImport.cpp.
References ComputeCrossModuleImportForModuleForTest(), ComputeCrossModuleImportForModuleFromIndexForTest(), llvm::errs(), llvm::GlobalValue::ExternalLinkage, llvm::getModuleSummaryIndexForFile(), I, ImportAllIndex, llvm::FunctionImporter::importFunctions(), llvm::GlobalValue::isLocalLinkage(), loadFile(), llvm::logAllUnhandledErrors(), llvm::renameModuleForThinLTO(), llvm::report_fatal_error(), SummaryFile, and llvm::Expected< T >::takeError().
Referenced by llvm::FunctionImportPass::run().
|
static |
Definition at line 821 of file FunctionImport.cpp.
References llvm::dbgs(), LLVM_DEBUG, numGlobalVarSummaries(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::size().
Referenced by ComputeCrossModuleImportForModuleForTest(), and ComputeCrossModuleImportForModuleFromIndexForTest().
|
static |
Definition at line 396 of file FunctionImport.cpp.
References llvm_unreachable.
Referenced by computeImportForFunction(), and ModuleImportsManager::computeImportForModule().
|
static |
Definition at line 1332 of file FunctionImport.cpp.
References llvm::GlobalValue::DefaultVisibility, and llvm::GlobalValue::InternalLinkage.
Referenced by llvm::FunctionImporter::importFunctions().
|
static |
Definition at line 670 of file FunctionImport.cpp.
References G, and isGlobalVarSummary().
|
static |
Definition at line 663 of file FunctionImport.cpp.
References llvm::GlobalValueSummary::GlobalVarKind.
Referenced by isGlobalVarSummary(), and numGlobalVarSummaries().
|
static |
Definition at line 142 of file FunctionImport.cpp.
References Context, llvm::dbgs(), llvm::errs(), llvm::getLazyIRFileModule(), LLVM_DEBUG, and llvm::report_fatal_error().
Referenced by doImportingForModuleForTest().
|
static |
Definition at line 678 of file FunctionImport.cpp.
References isGlobalVarSummary().
Referenced by llvm::ComputeCrossModuleImport(), and dumpImportListForModule().
|
static |
Given a list of possible callee implementation for a call site, qualify the legality of importing each.
The return is a range of pairs. Each pair corresponds to a candidate. The first value is the ImportFailureReason for that candidate, the second is the candidate.
Definition at line 163 of file FunctionImport.cpp.
References if(), llvm::GlobalValue::isInterposableLinkage(), llvm::GlobalValue::isLocalLinkage(), and llvm::map_range().
Referenced by selectCallee().
|
static |
Make alias a clone of its aliasee.
Definition at line 1316 of file FunctionImport.cpp.
References llvm::CloneFunction(), llvm::GlobalAlias::getAliaseeObject(), llvm::GlobalValue::getLinkage(), llvm::GlobalValue::getVisibility(), llvm::Value::replaceAllUsesWith(), llvm::GlobalValue::setLinkage(), llvm::GlobalValue::setVisibility(), and llvm::Value::takeName().
Referenced by llvm::FunctionImporter::importFunctions().
|
static |
Given a list of possible callee implementation for a call site, select one that fits the Threshold
.
If none are found, the Reason will give the last reason for the failure (last, in the order of CalleeSummaryList entries).
FIXME: select "best" instead of first that fits. But what is "best"?
Definition at line 230 of file FunctionImport.cpp.
References ForceImportAll, and qualifyCalleeCandidates().
Referenced by computeImportForFunction().
STATISTIC | ( | NumDeadSymbols | , |
"Number of dead stripped symbols in index" | |||
) |
STATISTIC | ( | NumImportedCriticalFunctionsThinLink | , |
"Number of critical functions thin link decided to import" | |||
) |
STATISTIC | ( | NumImportedFunctions | , |
"Number of functions imported in backend" | |||
) |
STATISTIC | ( | NumImportedFunctionsThinLink | , |
"Number of functions thin link decided to import" | |||
) |
STATISTIC | ( | NumImportedGlobalVars | , |
"Number of global variables imported in backend" | |||
) |
STATISTIC | ( | NumImportedGlobalVarsThinLink | , |
"Number of global variables thin link decided to import" | |||
) |
STATISTIC | ( | NumImportedHotFunctionsThinLink | , |
"Number of hot functions thin link decided to import" | |||
) |
STATISTIC | ( | NumImportedModules | , |
"Number of modules imported from" | |||
) |
STATISTIC | ( | NumLiveSymbols | , |
"Number of live symbols in index" | |||
) |
void updateValueInfoForIndirectCalls | ( | ModuleSummaryIndex & | Index, |
FunctionSummary * | FS | ||
) |
Definition at line 899 of file FunctionImport.cpp.
References llvm::any_of().
Referenced by llvm::computeDeadSymbolsAndUpdateIndirectCalls(), and llvm::updateIndirectCalls().
|
static |
Referenced by llvm::computeDeadSymbolsAndUpdateIndirectCalls().
|
static |
Referenced by llvm::FunctionImporter::importFunctions().
|
static |
Referenced by computeImportForFunction(), and selectCallee().
|
static |
Used when testing importing from distributed indexes via opt.
Referenced by doImportingForModuleForTest().
|
static |
Referenced by computeImportForFunction().
|
static |
Referenced by computeImportForFunction().
|
static |
Referenced by computeImportForFunction().
|
static |
Referenced by computeImportForFunction().
|
static |
Referenced by computeImportForFunction().
|
static |
Referenced by computeImportForFunction().
|
static |
Limit on instruction count of imported functions.
Referenced by ModuleImportsManager::computeImportForModule().
|
static |
Referenced by computeImportForFunction(), and ModuleImportsManager::computeImportForModule().
|
static |
Referenced by llvm::FunctionImporter::importFunctions().
|
static |
Summary file to use for function importing when using -function-import from the command line.
Referenced by doImportingForModuleForTest().