55 #include <system_error> 61 #define DEBUG_TYPE "function-import" 64 "Number of functions thin link decided to import");
65 STATISTIC(NumImportedHotFunctionsThinLink,
66 "Number of hot functions thin link decided to import");
67 STATISTIC(NumImportedCriticalFunctionsThinLink,
68 "Number of critical functions thin link decided to import");
70 "Number of global variables thin link decided to import");
71 STATISTIC(NumImportedFunctions,
"Number of functions imported in backend");
73 "Number of global variables imported in backend");
74 STATISTIC(NumImportedModules,
"Number of modules imported from");
75 STATISTIC(NumDeadSymbols,
"Number of dead stripped symbols in index");
76 STATISTIC(NumLiveSymbols,
"Number of live symbols in index");
81 cl::desc(
"Only import functions with less than N instructions"));
85 cl::desc(
"Only import first N functions if N>=0 (default -1)"));
90 cl::desc(
"As we import functions, multiply the " 91 "`import-instr-limit` threshold by this factor " 92 "before processing newly imported functions"));
97 cl::desc(
"As we import functions called from hot callsite, multiply the " 98 "`import-instr-limit` threshold by this factor " 99 "before processing newly imported functions"));
103 cl::desc(
"Multiply the `import-instr-limit` threshold for hot callsites"));
109 "Multiply the `import-instr-limit` threshold for critical callsites"));
114 cl::desc(
"Multiply the `import-instr-limit` threshold for cold callsites"));
117 cl::desc(
"Print imported functions"));
121 cl::desc(
"Print information for functions rejected for importing"));
140 cl::desc(
"The summary file to use for function importing."));
146 cl::desc(
"Import all external functions in index."));
149 static std::unique_ptr<Module>
loadFile(
const std::string &FileName,
155 std::unique_ptr<Module> Result =
178 ArrayRef<std::unique_ptr<GlobalValueSummary>> CalleeSummaryList,
185 [&](
const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
186 auto *GVSummary = SummaryPtr.get();
188 Reason = FunctionImporter::ImportFailureReason::NotLive;
210 Reason = FunctionImporter::ImportFailureReason::InterposableLinkage;
215 auto *Summary = cast<FunctionSummary>(GVSummary->getBaseObject());
228 CalleeSummaryList.size() > 1 &&
229 Summary->modulePath() != CallerModulePath) {
231 FunctionImporter::ImportFailureReason::LocalLinkageNotInModule;
235 if ((Summary->instCount() >
Threshold) &&
236 !Summary->fflags().AlwaysInline) {
237 Reason = FunctionImporter::ImportFailureReason::TooLarge;
243 if (Summary->notEligibleToImport()) {
244 Reason = FunctionImporter::ImportFailureReason::NotEligible;
249 if (Summary->fflags().NoInline) {
250 Reason = FunctionImporter::ImportFailureReason::NoInline;
256 if (It == CalleeSummaryList.end())
259 return cast<GlobalValueSummary>(It->get());
289 for (
auto &
VI : Summary.
refs()) {
290 if (DefinedGVSummaries.
count(
VI.getGUID())) {
292 dbgs() <<
"Ref ignored! Target already in destination module.\n");
306 RefSummary->modulePath() != Summary.
modulePath();
311 (*ExportLists)[S->modulePath()].insert(VI);
315 if (isa<GlobalVarSummary>(RefSummary.get()) &&
317 !LocalNotInModule(RefSummary.get())) {
318 auto ILI = ImportList[RefSummary->modulePath()].
insert(VI.
getGUID());
321 NumImportedGlobalVarsThinLink++;
322 MarkExported(VI, RefSummary.get());
327 if (!Index.
isWriteOnly(cast<GlobalVarSummary>(RefSummary.get())))
328 for (
const auto &VI : RefSummary->refs())
330 MarkExported(VI, RefFn.get());
343 case FunctionImporter::ImportFailureReason::NotLive:
345 case FunctionImporter::ImportFailureReason::TooLarge:
347 case FunctionImporter::ImportFailureReason::InterposableLinkage:
348 return "InterposableLinkage";
349 case FunctionImporter::ImportFailureReason::LocalLinkageNotInModule:
350 return "LocalLinkageNotInModule";
351 case FunctionImporter::ImportFailureReason::NotEligible:
352 return "NotEligible";
353 case FunctionImporter::ImportFailureReason::NoInline:
370 ImportList, ExportLists);
371 static int ImportCount = 0;
372 for (
auto &Edge : Summary.
calls()) {
374 LLVM_DEBUG(
dbgs() <<
" edge -> " << VI <<
" Threshold:" << Threshold
388 LLVM_DEBUG(
dbgs() <<
"ignored! Target already in destination module.\n");
402 const auto NewThreshold =
403 Threshold * GetBonusMultiplier(Edge.second.getHotness());
405 auto IT = ImportThresholds.
insert(std::make_pair(
406 VI.
getGUID(), std::make_tuple(NewThreshold,
nullptr,
nullptr)));
407 bool PreviouslyVisited = !IT.second;
408 auto &ProcessedThreshold = std::get<0>(IT.first->second);
409 auto &CalleeSummary = std::get<1>(IT.first->second);
410 auto &FailureInfo = std::get<2>(IT.first->second);
414 bool IsCriticalCallsite =
419 assert(PreviouslyVisited);
424 if (NewThreshold <= ProcessedThreshold) {
426 dbgs() <<
"ignored! Target was already imported with Threshold " 427 << ProcessedThreshold <<
"\n");
431 ProcessedThreshold = NewThreshold;
432 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
436 if (PreviouslyVisited && NewThreshold <= ProcessedThreshold) {
438 dbgs() <<
"ignored! Target was already rejected with Threshold " 439 << ProcessedThreshold <<
"\n");
442 "Expected FailureInfo for previously rejected candidate");
443 FailureInfo->Attempts++;
451 if (!CalleeSummary) {
455 if (PreviouslyVisited) {
456 ProcessedThreshold = NewThreshold;
459 "Expected FailureInfo for previously rejected candidate");
460 FailureInfo->Reason = Reason;
461 FailureInfo->Attempts++;
462 FailureInfo->MaxHotness =
463 std::max(FailureInfo->MaxHotness, Edge.second.getHotness());
467 "Expected no FailureInfo for newly rejected candidate");
468 FailureInfo = std::make_unique<FunctionImporter::ImportFailureInfo>(
469 VI, Edge.second.getHotness(), Reason, 1);
472 dbgs() <<
"ignored! No qualifying callee with summary found.\n");
477 CalleeSummary = CalleeSummary->getBaseObject();
478 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
481 (ResolvedCalleeSummary->
instCount() <= NewThreshold)) &&
482 "selectCallee() didn't honor the threshold");
484 auto ExportModulePath = ResolvedCalleeSummary->
modulePath();
485 auto ILI = ImportList[ExportModulePath].
insert(VI.
getGUID());
488 bool PreviouslyImported = !ILI.second;
489 if (!PreviouslyImported) {
490 NumImportedFunctionsThinLink++;
492 NumImportedHotFunctionsThinLink++;
493 if (IsCriticalCallsite)
494 NumImportedCriticalFunctionsThinLink++;
499 auto &ExportList = (*ExportLists)[ExportModulePath];
500 ExportList.insert(VI);
501 if (!PreviouslyImported) {
508 for (
auto &Edge : ResolvedCalleeSummary->
calls())
509 ExportList.insert(Edge.first);
511 for (
auto &
Ref : ResolvedCalleeSummary->
refs())
512 ExportList.insert(
Ref);
517 auto GetAdjustedThreshold = [](
unsigned Threshold,
bool IsHotCallsite) {
526 const auto AdjThreshold = GetAdjustedThreshold(Threshold, IsHotCallsite);
549 for (
auto &GVSummary : DefinedGVSummaries) {
566 DefinedGVSummaries, Worklist, ImportList,
567 ExportLists, ImportThresholds);
571 while (!Worklist.
empty()) {
573 auto *Summary = std::get<0>(FuncInfo);
577 Worklist, ImportList, ExportLists,
584 dbgs() <<
"Missed imports into module " << ModName <<
"\n";
585 for (
auto &
I : ImportThresholds) {
586 auto &ProcessedThreshold = std::get<0>(
I.second);
587 auto &CalleeSummary = std::get<1>(
I.second);
588 auto &FailureInfo = std::get<2>(
I.second);
593 if (!FailureInfo->VI.getSummaryList().empty())
594 FS = dyn_cast<FunctionSummary>(
595 FailureInfo->VI.getSummaryList()[0]->getBaseObject());
596 dbgs() << FailureInfo->VI
598 <<
", Threshold = " << ProcessedThreshold
599 <<
", Size = " << (FS ? (int)FS->
instCount() : -1)
601 <<
", Attempts = " << FailureInfo->Attempts <<
"\n";
640 for (
auto &ImportPerModule : ImportLists)
641 for (
auto &ExportPerModule : ImportPerModule.second)
642 FlattenedImports.
insert(ExportPerModule.second.begin(),
643 ExportPerModule.second.end());
650 auto *GVS = dyn_cast_or_null<GlobalVarSummary>(
655 for (
auto &ExportPerModule : ExportLists)
656 for (
auto &
VI : ExportPerModule.second)
657 if (!FlattenedImports.
count(
VI.getGUID()) &&
658 IsReadOrWriteOnlyVar(ExportPerModule.first(),
VI))
672 for (
auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
673 auto &ImportList = ImportLists[DefinedGVSummaries.first()];
675 << DefinedGVSummaries.first() <<
"'\n");
677 DefinedGVSummaries.first(), ImportList,
686 for (
auto &ELI : ExportLists) {
687 const auto &DefinedGVSummaries =
688 ModuleToDefinedGVSummaries.lookup(ELI.first());
689 for (
auto EI = ELI.second.begin(); EI != ELI.second.end();) {
690 if (!DefinedGVSummaries.count(EI->getGUID()))
691 ELI.second.erase(EI++);
701 for (
auto &ModuleImports : ImportLists) {
702 auto ModName = ModuleImports.first();
703 auto &Exports = ExportLists[ModName];
706 << Exports.size() - NumGVS <<
" functions and " << NumGVS
707 <<
" vars. Imports from " << ModuleImports.second.size()
709 for (
auto &Src : ModuleImports.second) {
710 auto SrcModName = Src.first();
713 <<
" functions imported from " << SrcModName <<
"\n");
715 <<
" global vars imported from " << SrcModName <<
"\n");
725 LLVM_DEBUG(
dbgs() <<
"* Module " << ModulePath <<
" imports from " 726 << ImportList.
size() <<
" modules.\n");
727 for (
auto &Src : ImportList) {
728 auto SrcModName = Src.first();
731 <<
" functions imported from " << SrcModName <<
"\n");
732 LLVM_DEBUG(
dbgs() <<
" - " << NumGVSPerMod <<
" vars imported from " 733 << SrcModName <<
"\n");
748 LLVM_DEBUG(
dbgs() <<
"Computing import for Module '" << ModulePath <<
"'\n");
761 for (
auto &GlobalList : Index) {
763 if (GlobalList.second.SummaryList.empty())
766 auto GUID = GlobalList.first;
767 assert(GlobalList.second.SummaryList.size() == 1 &&
768 "Expected individual combined index to have one summary per GUID");
769 auto &Summary = GlobalList.second.SummaryList[0];
772 if (Summary->modulePath() == ModulePath)
775 ImportList[Summary->modulePath()].
insert(GUID);
789 if (GUIDPreservedSymbols.
empty())
792 unsigned LiveSymbols = 0;
795 for (
auto GUID : GUIDPreservedSymbols) {
804 for (
const auto &
Entry : Index) {
805 auto VI = Index.getValueInfo(
Entry);
806 for (
auto &S :
Entry.second.SummaryList)
830 [](
const std::unique_ptr<llvm::GlobalValueSummary> &S) {
841 bool KeepAliveLinkage =
false;
842 bool Interposable =
false;
847 KeepAliveLinkage =
true;
853 if (!KeepAliveLinkage)
858 "Interposable and available_externally/linkonce_odr/weak_odr " 869 while (!Worklist.
empty()) {
872 if (
auto *AS = dyn_cast<AliasSummary>(Summary.get())) {
876 visit(AS->getAliaseeVI(),
true);
880 Summary->setLive(
true);
881 for (
auto Ref : Summary->refs())
883 if (
auto *
FS = dyn_cast<FunctionSummary>(Summary.get()))
884 for (
auto Call :
FS->calls())
885 visit(Call.first,
false);
888 Index.setWithGlobalValueDeadStripping();
890 unsigned DeadSymbols = Index.size() - LiveSymbols;
891 LLVM_DEBUG(
dbgs() << LiveSymbols <<
" symbols Live, and " << DeadSymbols
892 <<
" symbols Dead \n");
893 NumDeadSymbols += DeadSymbols;
894 NumLiveSymbols += LiveSymbols;
902 bool ImportEnabled) {
914 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
916 ModuleToSummariesForIndex[ModulePath] =
917 ModuleToDefinedGVSummaries.
lookup(ModulePath);
919 for (
auto &ILI : ImportList) {
920 auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
921 const auto &DefinedGVSummaries =
922 ModuleToDefinedGVSummaries.
lookup(ILI.first());
923 for (
auto &GI : ILI.second) {
924 const auto &
DS = DefinedGVSummaries.find(GI);
925 assert(
DS != DefinedGVSummaries.end() &&
926 "Expected a defined summary for imported global value");
927 SummariesForIndex[GI] =
DS->second;
935 const std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
940 for (
auto &ILI : ModuleToSummariesForIndex)
944 if (ILI.first != ModulePath)
945 ImportsOS << ILI.first <<
"\n";
946 return std::error_code();
952 if (
Function *
F = dyn_cast<Function>(&GV)) {
955 F->setComdat(
nullptr);
957 V->setInitializer(
nullptr);
960 V->setComdat(
nullptr);
987 const auto &
GS = DefinedGlobals.
find(GV.getGUID());
988 if (
GS == DefinedGlobals.
end())
990 auto NewLinkage =
GS->second->linkage();
991 if (NewLinkage == GV.getLinkage())
1020 GS->second->canAutoHide()) {
1021 assert(GV.hasLinkOnceODRLinkage() && GV.hasGlobalUnnamedAddr());
1025 LLVM_DEBUG(
dbgs() <<
"ODR fixing up linkage for `" << GV.getName()
1026 <<
"` from " << GV.getLinkage() <<
" to " << NewLinkage
1028 GV.setLinkage(NewLinkage);
1033 auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
1034 if (GO && GO->isDeclarationForLinker() && GO->hasComdat())
1035 GO->setComdat(
nullptr);
1039 for (
auto &GV : TheModule)
1041 for (
auto &GV : TheModule.globals())
1043 for (
auto &GV : TheModule.aliases())
1052 auto MustPreserveGV = [&](
const GlobalValue &GV) ->
bool {
1054 auto GS = DefinedGlobals.
find(GV.getGUID());
1055 if (
GS == DefinedGlobals.
end()) {
1067 if (GS == DefinedGlobals.
end()) {
1107 if (!GV.isDeclaration() && GV.hasAttribute(
"thinlto-internalize")) {
1119 unsigned ImportedCount = 0, ImportedGVCount = 0;
1123 std::set<StringRef> ModuleNameOrderedList;
1124 for (
auto &FunctionsToImportPerModule : ImportList) {
1125 ModuleNameOrderedList.insert(FunctionsToImportPerModule.first());
1127 for (
auto &
Name : ModuleNameOrderedList) {
1129 const auto &FunctionsToImportPerModule = ImportList.find(
Name);
1130 assert(FunctionsToImportPerModule != ImportList.end());
1132 if (!SrcModuleOrErr)
1133 return SrcModuleOrErr.takeError();
1134 std::unique_ptr<Module> SrcModule = std::move(*SrcModuleOrErr);
1136 "Context mismatch");
1140 if (
Error Err = SrcModule->materializeMetadata())
1141 return std::move(Err);
1143 auto &ImportGUIDs = FunctionsToImportPerModule->second;
1149 auto GUID =
F.getGUID();
1150 auto Import = ImportGUIDs.count(GUID);
1152 << GUID <<
" " <<
F.getName() <<
" from " 1153 << SrcModule->getSourceFileName() <<
"\n");
1155 if (
Error Err =
F.materialize())
1156 return std::move(Err);
1160 "thinlto_src_module",
1163 SrcModule->getSourceFileName())}));
1171 auto GUID = GV.getGUID();
1172 auto Import = ImportGUIDs.count(GUID);
1174 << GUID <<
" " << GV.getName() <<
" from " 1175 << SrcModule->getSourceFileName() <<
"\n");
1177 if (
Error Err = GV.materialize())
1178 return std::move(Err);
1179 ImportedGVCount += GlobalsToImport.
insert(&GV);
1185 auto GUID = GA.getGUID();
1186 auto Import = ImportGUIDs.count(GUID);
1188 << GUID <<
" " << GA.getName() <<
" from " 1189 << SrcModule->getSourceFileName() <<
"\n");
1191 if (
Error Err = GA.materialize())
1192 return std::move(Err);
1196 return std::move(Err);
1199 <<
" " << Base->
getName() <<
" from " 1200 << SrcModule->getSourceFileName() <<
"\n");
1204 "thinlto_src_module",
1207 SrcModule->getSourceFileName())}));
1209 GlobalsToImport.
insert(Fn);
1222 for (
const auto *GV : GlobalsToImport)
1224 <<
" from " << SrcModule->getSourceFileName() <<
"\n";
1232 ImportedCount += GlobalsToImport.
size();
1233 NumImportedModules++;
1238 NumImportedFunctions += (ImportedCount - ImportedGVCount);
1239 NumImportedGlobalVars += ImportedGVCount;
1241 LLVM_DEBUG(
dbgs() <<
"Imported " << ImportedCount - ImportedGVCount
1242 <<
" functions for Module " 1245 <<
" global variables for Module " 1247 return ImportedCount;
1255 if (!IndexPtrOrErr) {
1260 std::unique_ptr<ModuleSummaryIndex> Index = std::move(*IndexPtrOrErr);
1278 for (
auto &
I : *Index) {
1279 for (
auto &S :
I.second.SummaryList) {
1288 errs() <<
"Error renaming module\n";
1293 auto ModuleLoader = [&M](
StringRef Identifier) {
1302 "Error importing module: ");
1312 class FunctionImportLegacyPass :
public ModulePass {
1317 explicit FunctionImportLegacyPass() :
ModulePass(ID) {}
1320 StringRef getPassName()
const override {
return "Function Importing"; }
1322 bool runOnModule(
Module &M)
override {
1342 "Summary Based Function Import",
false,
false)
1347 return new FunctionImportLegacyPass();
void setVisibility(VisibilityTypes V)
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
Pass interface - Implemented by all 'passes'.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
reference emplace_back(ArgTypes &&... Args)
ThreadLocalMode getThreadLocalMode() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void thinLTOResolvePrevailingInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve prevailing symbol linkages in TheModule based on the information recorded in the summaries du...
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
ArrayRef< T > getArrayRef() const
size_type size() const
Determine the number of elements in the SetVector.
static void computeImportForReferencedGlobals(const FunctionSummary &Summary, const ModuleSummaryIndex &Index, const GVSummaryMapTy &DefinedGVSummaries, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists)
A Module instance is used to store all the information related to an LLVM module. ...
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static MDString * get(LLVMContext &Context, StringRef Str)
Implements a dense probed hash-table based set.
Available for inspection, not emission.
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)"))
void push_back(const T &Elt)
std::error_code EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const std::map< std::string, GVSummaryMapTy > &ModuleToSummariesForIndex)
Emit into OutputFilename the files module ModulePath will import from.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
An efficient, type-erasing, non-owning reference to a callable.
Externally visible function.
static void ComputeImportForModule(const GVSummaryMapTy &DefinedGVSummaries, const ModuleSummaryIndex &Index, StringRef ModName, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists=nullptr)
Given the list of globals defined in a module, compute the list of imports as well as the list of "ex...
static StringRef getOriginalNameBeforePromote(StringRef Name)
Helper to obtain the unpromoted name for a global value (or the original name if not promoted)...
STATISTIC(NumFunctions, "Total number of functions")
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
Error takeError()
Take ownership of the stored error.
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
void reserve(size_type N)
static std::unique_ptr< Module > loadFile(const std::string &FileName, LLVMContext &Context)
bool isReadOnly(const GlobalVarSummary *GVS) const
static bool isLocalLinkage(LinkageTypes Linkage)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
GlobalValue::GUID getGUID() const
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 void computeImportForFunction(const FunctionSummary &Summary, const ModuleSummaryIndex &Index, const unsigned Threshold, const GVSummaryMapTy &DefinedGVSummaries, SmallVectorImpl< EdgeInfo > &Worklist, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists, FunctionImporter::ImportThresholdsTy &ImportThresholds)
Compute the list of functions to import for a given caller.
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"))
LLVMContext & getContext() const
Get the global data context.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
The access may reference the value stored in memory.
static cl::opt< bool > PrintImportFailures("print-import-failures", cl::init(false), cl::Hidden, cl::desc("Print information for functions rejected for importing"))
Tagged union holding either a T or a Error.
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
bool insert(const value_type &X)
Insert a new element into the SetVector.
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue *> ValuesToLink, std::function< void(GlobalValue &GV, ValueAdder Add)> AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, ValueInfo VI)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
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"))
const GlobalObject * getBaseObject() const
LinkageTypes getLinkage() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
const std::string & getSourceFileName() const
Get the module's original source file name.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Same, but only replaced by something equivalent.
initializer< Ty > init(const Ty &Val)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
A set of analyses that are preserved following a run of a transformation pass.
VisibilityTypes getVisibility() const
bool renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, SetVector< GlobalValue *> *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
void gatherImportedSummariesForModule(StringRef ModulePath, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, std::map< std::string, GVSummaryMapTy > &ModuleToSummariesForIndex)
Compute the set of summaries needed for a ThinLTO backend compilation of ModulePath.
Import information from summary.
This is an important class for using LLVM in a threaded context.
Pass * createFunctionImportPass()
This pass performs iterative function importing from other modules.
ImportFailureReason
The different reasons selectCallee will chose not to import a candidate.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned instCount() const
Get the instruction count recorded for this function.
std::pair< iterator, bool > insert(const ValueT &V)
PrevailingType
PrevailingType enum used as a return type of callback passed to computeDeadSymbols.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
void ComputeCrossModuleImportForModuleFromIndex(StringRef ModulePath, const ModuleSummaryIndex &Index, FunctionImporter::ImportMapTy &ImportList)
Mark all external summaries in Index for import into the given module.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
unsigned getAddressSpace() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
INITIALIZE_PASS(FunctionImportLegacyPass, "function-import", "Summary Based Function Import", false, false) namespace llvm
Function and variable summary information to aid decisions and implementation of importing.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Error materialize()
Make sure this GlobalValue is fully read.
static unsigned numGlobalVarSummaries(const ModuleSummaryIndex &Index, T &Cont)
static const char * getFailureName(FunctionImporter::ImportFailureReason Reason)
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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Function * replaceAliasWithAliasee(Module *SrcModule, GlobalAlias *GA)
Make alias a clone of its aliasee.
Struct that holds a reference to a particular GUID in a global value summary.
std::unique_ptr< Module > getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given file holds a bitcode image, return a Module for it which does lazy deserialization of fu...
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"))
const char * getHotnessName(CalleeInfo::HotnessType HT)
Align max(MaybeAlign Lhs, Align Rhs)
bool isWriteOnly(const GlobalVarSummary *GVS) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
LLVM_NODISCARD T pop_back_val()
static bool doImportingForModule(Module &M)
static const GlobalValueSummary * selectCallee(const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary >> CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath, FunctionImporter::ImportFailureReason &Reason, GlobalValue::GUID GUID)
Given a list of possible callee implementation for a call site, select one that fits the Threshold...
static ValueInfo updateValueInfoForIndirectCalls(const ModuleSummaryIndex &Index, ValueInfo VI)
void setLinkage(LinkageTypes LT)
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndexForFile(StringRef Path, bool IgnoreEmptyThinLTOIndexFile=false)
Parse the module summary index out of an IR file and return the module summary index object if found...
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
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"))
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
static cl::opt< bool > ComputeDead("compute-dead", cl::init(true), cl::Hidden, cl::desc("Compute dead symbols"))
bool withGlobalValueDeadStripping() const
static void internalizeGVsAfterImport(Module &M)
FFlags fflags() const
Get function summary flags.
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
void propagateAttributes(const DenseSet< GlobalValue::GUID > &PreservedSymbols)
Analyze index and detect unmodified globals.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, StringMap< FunctionImporter::ImportMapTy > &ImportLists, StringMap< FunctionImporter::ExportSetTy > &ExportLists)
Compute all the imports and exports for every module in the Index.
bool isFunctionTy() const
True if this is an instance of FunctionType.
A raw_ostream that writes to a file descriptor.
static cl::opt< bool > PrintImports("print-imports", cl::init(false), cl::Hidden, cl::desc("Print imported functions"))
StringRef modulePath() const
Get the path to the module containing this function.
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"))
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
static bool checkVariableImport(const ModuleSummaryIndex &Index, StringMap< FunctionImporter::ImportMapTy > &ImportLists, StringMap< FunctionImporter::ExportSetTy > &ExportLists)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
Type * getValueType() const
Rename collisions when linking (static functions).
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
Function summary information to aid decisions and implementation of importing.
static void dumpImportListForModule(const ModuleSummaryIndex &Index, StringRef ModulePath, FunctionImporter::ImportMapTy &ImportList)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void ComputeCrossModuleImportForModule(StringRef ModulePath, const ModuleSummaryIndex &Index, FunctionImporter::ImportMapTy &ImportList)
Compute all the imports for the given module using the Index.
void computeDeadSymbolsWithConstProp(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, function_ref< PrevailingType(GlobalValue::GUID)> isPrevailing, bool ImportEnabled)
Compute dead symbols and run constant propagation in combined index after that.
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...
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
Module * getParent()
Get the module that this global value is contained inside of...
The function importer is automatically importing function from other modules based on the provided su...
A vector that has set insertion semantics.
Lightweight error class with error context and mandatory checking.
bool canImportGlobalVar(GlobalValueSummary *S, bool AnalyzeRefs) const
Checks if we can import global variable from another module.
void computeDeadSymbols(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, function_ref< PrevailingType(GlobalValue::GUID)> isPrevailing)
Compute all the symbols that are "dead": i.e these that can't be reached in the graph from any of the...
static cl::opt< bool > EnableImportMetadata("enable-import-metadata", cl::init(true), cl::Hidden, cl::desc("Enable import metadata like 'thinlto_src_module'"))
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
Function Alias Analysis false
bool internalizeModule(Module &TheModule, std::function< bool(const GlobalValue &)> MustPreserveGV, CallGraph *CG=nullptr)
Helper function to internalize functions and variables in a Module.
void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
PointerType * getType() const
Global values are always pointers.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...