|
LLVM 24.0.0git
|
#include "llvm/Transforms/IPO/FunctionImport.h"#include "IPOOptions.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/DenseMap.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/LLVMContext.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/ProfileData/PGOCtxProfReader.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/JSON.h"#include "llvm/Support/Path.h"#include "llvm/Support/SourceMgr.h"#include "llvm/Support/TimeProfiler.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/ModuleUtils.h"#include "llvm/Transforms/Utils/ValueMapper.h"#include <cassert>#include <memory>#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... | |
| class | WorkloadImportsManager |
| A ModuleImportsManager that operates based on a workload definition (see -thinlto-workload-def). More... | |
| struct | ImportStatistics |
Namespaces | |
| namespace | llvm |
| This is an optimization pass for GlobalISel generic memory operations. | |
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 (NumRequiredDeclsThinLink, "Number of function declarations thin link decided to import because " "the callee is required in the caller's module (e.g. for MemProf " "ICP)") | |
| STATISTIC (NumImportedFunctionDecls, "Number of function declarations 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 bool | shouldSkipLocalInAnotherModule (const GlobalValueSummary *RefSummary, size_t NumDefs, StringRef ImporterModule) |
| 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 IPOOptions &Opts, const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary > > CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath, const GlobalValueSummary *&TooLargeOrNoInlineSummary, FunctionImporter::ImportFailureReason &Reason) |
Given a list of possible callee implementation for a call site, select one that fits the Threshold for function definition import. | |
| static const char * | getFailureName (FunctionImporter::ImportFailureReason Reason) |
| static bool | isGlobalVarSummary (const ModuleSummaryIndex &Index, ValueInfo VI) |
| static bool | isGlobalVarSummary (const ModuleSummaryIndex &Index, GlobalValue::GUID G) |
| static unsigned | numGlobalVarSummaries (const ModuleSummaryIndex &Index, FunctionImporter::ExportSetTy &ExportSet) |
| static DenseMap< StringRef, ImportStatistics > | collectImportStatistics (const ModuleSummaryIndex &Index, const FunctionImporter::ImportMapTy &ImportList) |
| static bool | checkVariableImport (const ModuleSummaryIndex &Index, FunctionImporter::ImportListsTy &ImportLists, DenseMap< StringRef, FunctionImporter::ExportSetTy > &ExportLists) |
| static void | dumpImportListForModule (const ModuleSummaryIndex &Index, StringRef ModulePath, FunctionImporter::ImportMapTy &ImportList) |
| static void | ComputeCrossModuleImportForModuleForTest (const IPOOptions &Opts, 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 void | protectImplicitRefGlobals (Module &M) |
| When a function carrying !implicit.ref is imported via ThinLTO, the referenced global arrives as available_externally. | |
| static bool | doImportingForModuleForTest (Module &M, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) |
Variables | |
| cl::list< GlobalValue::GUID > | llvm::MoveSymbolGUID |
| #define DEBUG_TYPE "function-import" |
Definition at line 63 of file FunctionImport.cpp.
|
static |
Definition at line 1217 of file FunctionImport.cpp.
References llvm::GlobalValue::AvailableExternallyLinkage, llvm::detail::DenseSetImpl< ValueT, MapTy >::count(), llvm::dyn_cast_or_null(), llvm::detail::DenseSetImpl< ValueT, MapTy >::insert(), llvm::GlobalValue::LinkOnceODRLinkage, and llvm::GlobalValue::WeakODRLinkage.
Referenced by llvm::ComputeCrossModuleImport().
|
static |
Definition at line 1200 of file FunctionImport.cpp.
References llvm::GlobalValueSummary::Definition, and isGlobalVarSummary().
Referenced by llvm::ComputeCrossModuleImport(), and dumpImportListForModule().
|
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 1380 of file FunctionImport.cpp.
References ModuleImportsManager::create(), 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 1406 of file FunctionImport.cpp.
References llvm::FunctionImporter::ImportMapTy::addGUID(), assert(), and dumpImportListForModule().
Referenced by doImportingForModuleForTest().
|
static |
Definition at line 2317 of file FunctionImport.cpp.
References ComputeCrossModuleImportForModuleForTest(), ComputeCrossModuleImportForModuleFromIndexForTest(), llvm::errs(), llvm::getIPOOptions(), llvm::getModuleSummaryIndexForFile(), I, llvm::FunctionImporter::importFunctions(), llvm::GlobalValue::isLocalLinkage(), loadFile(), llvm::logAllUnhandledErrors(), llvm::renameModuleForThinLTO(), llvm::report_fatal_error(), and llvm::Expected< T >::takeError().
Referenced by llvm::FunctionImportPass::run().
|
static |
Definition at line 1353 of file FunctionImport.cpp.
References collectImportStatistics(), llvm::dbgs(), LLVM_DEBUG, llvm::DenseMapBase< StorageT, KeyT, ValueT, KeyInfoT, BucketT >::size(), and Stats.
Referenced by ComputeCrossModuleImportForModuleForTest(), and ComputeCrossModuleImportForModuleFromIndexForTest().
|
static |
Definition at line 806 of file FunctionImport.cpp.
References llvm::FunctionImporter::GlobalVar, llvm::FunctionImporter::InterposableLinkage, llvm_unreachable, llvm::FunctionImporter::LocalLinkageNotInModule, llvm::FunctionImporter::NoInline, llvm::FunctionImporter::None, llvm::FunctionImporter::NotEligible, llvm::FunctionImporter::NotLive, and llvm::FunctionImporter::TooLarge.
Referenced by ModuleImportsManager::computeImportForModule().
|
static |
Definition at line 1968 of file FunctionImport.cpp.
References llvm::GlobalValue::DefaultVisibility, and llvm::GlobalValue::InternalLinkage.
Referenced by llvm::FunctionImporter::importFunctions().
|
static |
Definition at line 1174 of file FunctionImport.cpp.
References G, and isGlobalVarSummary().
|
static |
Definition at line 1167 of file FunctionImport.cpp.
References llvm::GlobalValueSummary::GlobalVarKind.
Referenced by collectImportStatistics(), isGlobalVarSummary(), and numGlobalVarSummaries().
|
static |
Definition at line 95 of file FunctionImport.cpp.
References llvm::dbgs(), llvm::errs(), llvm::getLazyIRFileModule(), LLVM_DEBUG, and llvm::report_fatal_error().
Referenced by doImportingForModuleForTest().
|
static |
Definition at line 1183 of file FunctionImport.cpp.
References isGlobalVarSummary().
Referenced by llvm::ComputeCrossModuleImport().
|
static |
When a function carrying !implicit.ref is imported via ThinLTO, the referenced global arrives as available_externally.
This string can be dead code eliminated since it has no IR uses – only metadata references. Adding it to llvm.compiler.used prevents elimination.
Definition at line 1982 of file FunctionImport.cpp.
References llvm::appendToCompilerUsed(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), F, llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by llvm::FunctionImporter::importFunctions().
|
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 132 of file FunctionImport.cpp.
References llvm::dyn_cast(), llvm::FunctionImporter::GlobalVar, llvm::FunctionImporter::InterposableLinkage, llvm::GlobalValue::isInterposableLinkage(), llvm::FunctionImporter::LocalLinkageNotInModule, llvm::map_range(), llvm::FunctionImporter::None, llvm::FunctionImporter::NotEligible, llvm::FunctionImporter::NotLive, and shouldSkipLocalInAnotherModule().
Referenced by ModuleImportsManager::importRequiredDeclaration(), and selectCallee().
|
static |
Make alias a clone of its aliasee.
Definition at line 1952 of file FunctionImport.cpp.
References llvm::cast(), 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 for function definition import.
If none are found, the Reason will give the last reason for the failure (last, in the order of CalleeSummaryList entries). While looking for a callee definition, sets TooLargeOrNoInlineSummary to the last seen too-large or noinline candidate; other modules may want to know the function summary or declaration even if a definition is not needed.
FIXME: select "best" instead of first that fits. But what is "best"?
Definition at line 204 of file FunctionImport.cpp.
References llvm::cast(), llvm::FunctionImporter::NoInline, llvm::FunctionImporter::None, qualifyCalleeCandidates(), and llvm::FunctionImporter::TooLarge.
|
static |
Definition at line 112 of file FunctionImport.cpp.
References llvm::GlobalValue::isLocalLinkage(), llvm::GlobalValueSummary::linkage(), and llvm::GlobalValueSummary::modulePath().
Referenced by qualifyCalleeCandidates().
| STATISTIC | ( | NumDeadSymbols | , |
| "Number of dead stripped symbols in index" | ) |
| STATISTIC | ( | NumImportedCriticalFunctionsThinLink | , |
| "Number of critical functions thin link decided to import" | ) |
| STATISTIC | ( | NumImportedFunctionDecls | , |
| "Number of function declarations imported in backend" | ) |
| 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" | ) |
References llvm::AlwaysRenamePromotedLocals, llvm::MoveSymbolGUID, and llvm::UseCtxProfile.
| STATISTIC | ( | NumRequiredDeclsThinLink | , |
| "Number of function declarations thin link decided to import because " "the callee is required in the caller's module (e.g. for MemProf " "ICP)" | ) |
| void updateValueInfoForIndirectCalls | ( | ModuleSummaryIndex & | Index, |
| FunctionSummary * | FS ) |
Definition at line 1434 of file FunctionImport.cpp.
References llvm::any_of().
Referenced by llvm::computeDeadSymbolsAndUpdateIndirectCalls(), and llvm::updateIndirectCalls().