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;
236 Reason = FunctionImporter::ImportFailureReason::TooLarge;
242 if (Summary->notEligibleToImport()) {
243 Reason = FunctionImporter::ImportFailureReason::NotEligible;
248 if (Summary->fflags().NoInline) {
249 Reason = FunctionImporter::ImportFailureReason::NoInline;
255 if (It == CalleeSummaryList.end())
258 return cast<GlobalValueSummary>(It->get());
287 for (
auto &
VI : Summary.
refs()) {
288 if (DefinedGVSummaries.
count(
VI.getGUID())) {
290 dbgs() <<
"Ref ignored! Target already in destination module.\n");
304 RefSummary->modulePath() != Summary.
modulePath();
307 for (
auto &RefSummary :
VI.getSummaryList())
308 if (isa<GlobalVarSummary>(RefSummary.get()) &&
310 !LocalNotInModule(RefSummary.get())) {
311 auto ILI = ImportList[RefSummary->modulePath()].
insert(
VI.getGUID());
314 NumImportedGlobalVarsThinLink++;
316 (*ExportLists)[RefSummary->modulePath()].insert(
VI.getGUID());
329 case FunctionImporter::ImportFailureReason::NotLive:
331 case FunctionImporter::ImportFailureReason::TooLarge:
333 case FunctionImporter::ImportFailureReason::InterposableLinkage:
334 return "InterposableLinkage";
335 case FunctionImporter::ImportFailureReason::LocalLinkageNotInModule:
336 return "LocalLinkageNotInModule";
337 case FunctionImporter::ImportFailureReason::NotEligible:
338 return "NotEligible";
339 case FunctionImporter::ImportFailureReason::NoInline:
357 static int ImportCount = 0;
358 for (
auto &Edge : Summary.
calls()) {
360 LLVM_DEBUG(
dbgs() <<
" edge -> " << VI <<
" Threshold:" << Threshold
374 LLVM_DEBUG(
dbgs() <<
"ignored! Target already in destination module.\n");
388 const auto NewThreshold =
389 Threshold * GetBonusMultiplier(Edge.second.getHotness());
391 auto IT = ImportThresholds.
insert(std::make_pair(
392 VI.
getGUID(), std::make_tuple(NewThreshold,
nullptr,
nullptr)));
393 bool PreviouslyVisited = !IT.second;
394 auto &ProcessedThreshold = std::get<0>(IT.first->second);
395 auto &CalleeSummary = std::get<1>(IT.first->second);
396 auto &FailureInfo = std::get<2>(IT.first->second);
400 bool IsCriticalCallsite =
405 assert(PreviouslyVisited);
410 if (NewThreshold <= ProcessedThreshold) {
412 dbgs() <<
"ignored! Target was already imported with Threshold " 413 << ProcessedThreshold <<
"\n");
417 ProcessedThreshold = NewThreshold;
418 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
422 if (PreviouslyVisited && NewThreshold <= ProcessedThreshold) {
424 dbgs() <<
"ignored! Target was already rejected with Threshold " 425 << ProcessedThreshold <<
"\n");
428 "Expected FailureInfo for previously rejected candidate");
429 FailureInfo->Attempts++;
437 if (!CalleeSummary) {
441 if (PreviouslyVisited) {
442 ProcessedThreshold = NewThreshold;
445 "Expected FailureInfo for previously rejected candidate");
446 FailureInfo->Reason = Reason;
447 FailureInfo->Attempts++;
448 FailureInfo->MaxHotness =
449 std::max(FailureInfo->MaxHotness, Edge.second.getHotness());
453 "Expected no FailureInfo for newly rejected candidate");
454 FailureInfo = llvm::make_unique<FunctionImporter::ImportFailureInfo>(
455 VI, Edge.second.getHotness(), Reason, 1);
458 dbgs() <<
"ignored! No qualifying callee with summary found.\n");
463 CalleeSummary = CalleeSummary->getBaseObject();
464 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
467 "selectCallee() didn't honor the threshold");
469 auto ExportModulePath = ResolvedCalleeSummary->
modulePath();
470 auto ILI = ImportList[ExportModulePath].
insert(VI.
getGUID());
473 bool PreviouslyImported = !ILI.second;
474 if (!PreviouslyImported) {
475 NumImportedFunctionsThinLink++;
477 NumImportedHotFunctionsThinLink++;
478 if (IsCriticalCallsite)
479 NumImportedCriticalFunctionsThinLink++;
484 auto &ExportList = (*ExportLists)[ExportModulePath];
485 ExportList.insert(VI.
getGUID());
486 if (!PreviouslyImported) {
493 for (
auto &Edge : ResolvedCalleeSummary->
calls()) {
494 auto CalleeGUID = Edge.first.getGUID();
495 ExportList.insert(CalleeGUID);
497 for (
auto &
Ref : ResolvedCalleeSummary->
refs()) {
498 auto GUID =
Ref.getGUID();
499 ExportList.insert(GUID);
505 auto GetAdjustedThreshold = [](
unsigned Threshold,
bool IsHotCallsite) {
514 const auto AdjThreshold = GetAdjustedThreshold(Threshold, IsHotCallsite);
537 for (
auto &GVSummary : DefinedGVSummaries) {
554 DefinedGVSummaries, Worklist, ImportList,
555 ExportLists, ImportThresholds);
559 while (!Worklist.
empty()) {
561 auto *Summary = std::get<0>(FuncInfo);
565 Worklist, ImportList, ExportLists,
572 dbgs() <<
"Missed imports into module " << ModName <<
"\n";
573 for (
auto &
I : ImportThresholds) {
574 auto &ProcessedThreshold = std::get<0>(
I.second);
575 auto &CalleeSummary = std::get<1>(
I.second);
576 auto &FailureInfo = std::get<2>(
I.second);
581 if (!FailureInfo->VI.getSummaryList().empty())
582 FS = dyn_cast<FunctionSummary>(
583 FailureInfo->VI.getSummaryList()[0]->getBaseObject());
584 dbgs() << FailureInfo->VI
586 <<
", Threshold = " << ProcessedThreshold
587 <<
", Size = " << (FS ? (int)FS->
instCount() : -1)
589 <<
", Attempts = " << FailureInfo->Attempts <<
"\n";
598 auto SL =
VI.getSummaryList();
625 for (
auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
626 auto &ImportList = ImportLists[DefinedGVSummaries.first()];
628 << DefinedGVSummaries.first() <<
"'\n");
630 DefinedGVSummaries.first(), ImportList,
639 for (
auto &ELI : ExportLists) {
640 const auto &DefinedGVSummaries =
641 ModuleToDefinedGVSummaries.lookup(ELI.first());
642 for (
auto EI = ELI.second.begin(); EI != ELI.second.end();) {
643 if (!DefinedGVSummaries.count(*EI))
644 EI = ELI.second.erase(EI);
653 for (
auto &ModuleImports : ImportLists) {
654 auto ModName = ModuleImports.first();
655 auto &Exports = ExportLists[ModName];
658 << Exports.size() - NumGVS <<
" functions and " << NumGVS
659 <<
" vars. Imports from " << ModuleImports.second.size()
661 for (
auto &Src : ModuleImports.second) {
662 auto SrcModName = Src.first();
665 <<
" functions imported from " << SrcModName <<
"\n");
667 <<
" global vars imported from " << SrcModName <<
"\n");
677 LLVM_DEBUG(
dbgs() <<
"* Module " << ModulePath <<
" imports from " 678 << ImportList.
size() <<
" modules.\n");
679 for (
auto &Src : ImportList) {
680 auto SrcModName = Src.first();
683 <<
" functions imported from " << SrcModName <<
"\n");
684 LLVM_DEBUG(
dbgs() <<
" - " << NumGVSPerMod <<
" vars imported from " 685 << SrcModName <<
"\n");
700 LLVM_DEBUG(
dbgs() <<
"Computing import for Module '" << ModulePath <<
"'\n");
713 for (
auto &GlobalList : Index) {
715 if (GlobalList.second.SummaryList.empty())
718 auto GUID = GlobalList.first;
719 assert(GlobalList.second.SummaryList.size() == 1 &&
720 "Expected individual combined index to have one summary per GUID");
721 auto &Summary = GlobalList.second.SummaryList[0];
724 if (Summary->modulePath() == ModulePath)
727 ImportList[Summary->modulePath()].
insert(GUID);
741 if (GUIDPreservedSymbols.
empty())
744 unsigned LiveSymbols = 0;
747 for (
auto GUID : GUIDPreservedSymbols) {
756 for (
const auto &Entry : Index) {
757 auto VI = Index.getValueInfo(Entry);
758 for (
auto &S : Entry.second.SummaryList)
784 [](
const std::unique_ptr<llvm::GlobalValueSummary> &S) {
795 bool KeepAliveLinkage =
false;
796 bool Interposable =
false;
797 for (
auto &S :
VI.getSummaryList()) {
801 KeepAliveLinkage =
true;
806 if (!KeepAliveLinkage)
811 "Interposable and available_externally/linkonce_odr/weak_odr symbol");
814 for (
auto &S :
VI.getSummaryList())
820 while (!Worklist.
empty()) {
822 for (
auto &Summary :
VI.getSummaryList()) {
828 if (
auto *FS = dyn_cast<FunctionSummary>(Base))
829 for (
auto Call : FS->calls())
833 Index.setWithGlobalValueDeadStripping();
835 unsigned DeadSymbols = Index.size() - LiveSymbols;
836 LLVM_DEBUG(
dbgs() << LiveSymbols <<
" symbols Live, and " << DeadSymbols
837 <<
" symbols Dead \n");
838 NumDeadSymbols += DeadSymbols;
839 NumLiveSymbols += LiveSymbols;
847 bool ImportEnabled) {
854 for (
auto &
P : Index)
855 for (
auto &S :
P.second.SummaryList)
856 if (
auto *GVS = dyn_cast<GlobalVarSummary>(S.get()))
857 GVS->setReadOnly(
false);
867 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
869 ModuleToSummariesForIndex[ModulePath] =
870 ModuleToDefinedGVSummaries.
lookup(ModulePath);
872 for (
auto &ILI : ImportList) {
873 auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
874 const auto &DefinedGVSummaries =
875 ModuleToDefinedGVSummaries.
lookup(ILI.first());
876 for (
auto &GI : ILI.second) {
877 const auto &
DS = DefinedGVSummaries.find(GI);
878 assert(
DS != DefinedGVSummaries.end() &&
879 "Expected a defined summary for imported global value");
880 SummariesForIndex[GI] =
DS->second;
888 const std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
893 for (
auto &ILI : ModuleToSummariesForIndex)
897 if (ILI.first != ModulePath)
898 ImportsOS << ILI.first <<
"\n";
899 return std::error_code();
905 if (
Function *
F = dyn_cast<Function>(&GV)) {
908 F->setComdat(
nullptr);
910 V->setInitializer(
nullptr);
913 V->setComdat(
nullptr);
940 const auto &GS = DefinedGlobals.
find(GV.getGUID());
941 if (GS == DefinedGlobals.
end())
943 auto NewLinkage = GS->second->linkage();
944 if (NewLinkage == GV.getLinkage())
955 GV.setLinkage(NewLinkage);
979 if (GV.hasLinkOnceODRLinkage() && GV.hasGlobalUnnamedAddr() &&
983 LLVM_DEBUG(
dbgs() <<
"ODR fixing up linkage for `" << GV.getName()
984 <<
"` from " << GV.getLinkage() <<
" to " << NewLinkage
986 GV.setLinkage(NewLinkage);
991 auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
992 if (GO && GO->isDeclarationForLinker() && GO->hasComdat())
993 GO->setComdat(
nullptr);
997 for (
auto &GV : TheModule)
999 for (
auto &GV : TheModule.globals())
1001 for (
auto &GV : TheModule.aliases())
1010 auto MustPreserveGV = [&](
const GlobalValue &GV) ->
bool {
1012 auto GS = DefinedGlobals.
find(GV.getGUID());
1013 if (GS == DefinedGlobals.
end()) {
1025 if (GS == DefinedGlobals.
end()) {
1064 if (!GV.isDeclaration() && GV.hasAttribute(
"thinlto-internalize")) {
1076 unsigned ImportedCount = 0, ImportedGVCount = 0;
1080 std::set<StringRef> ModuleNameOrderedList;
1081 for (
auto &FunctionsToImportPerModule : ImportList) {
1082 ModuleNameOrderedList.insert(FunctionsToImportPerModule.first());
1084 for (
auto &
Name : ModuleNameOrderedList) {
1086 const auto &FunctionsToImportPerModule = ImportList.find(
Name);
1087 assert(FunctionsToImportPerModule != ImportList.end());
1089 if (!SrcModuleOrErr)
1090 return SrcModuleOrErr.takeError();
1091 std::unique_ptr<Module> SrcModule = std::move(*SrcModuleOrErr);
1093 "Context mismatch");
1097 if (
Error Err = SrcModule->materializeMetadata())
1098 return std::move(Err);
1100 auto &ImportGUIDs = FunctionsToImportPerModule->second;
1106 auto GUID =
F.getGUID();
1107 auto Import = ImportGUIDs.count(GUID);
1109 << GUID <<
" " <<
F.getName() <<
" from " 1110 << SrcModule->getSourceFileName() <<
"\n");
1112 if (
Error Err =
F.materialize())
1113 return std::move(Err);
1117 "thinlto_src_module",
1120 SrcModule->getSourceFileName())}));
1128 auto GUID = GV.getGUID();
1129 auto Import = ImportGUIDs.count(GUID);
1131 << GUID <<
" " << GV.getName() <<
" from " 1132 << SrcModule->getSourceFileName() <<
"\n");
1134 if (
Error Err = GV.materialize())
1135 return std::move(Err);
1136 ImportedGVCount += GlobalsToImport.
insert(&GV);
1142 auto GUID = GA.getGUID();
1143 auto Import = ImportGUIDs.count(GUID);
1145 << GUID <<
" " << GA.getName() <<
" from " 1146 << SrcModule->getSourceFileName() <<
"\n");
1148 if (
Error Err = GA.materialize())
1149 return std::move(Err);
1153 return std::move(Err);
1156 <<
" " << Base->
getName() <<
" from " 1157 << SrcModule->getSourceFileName() <<
"\n");
1161 "thinlto_src_module",
1164 SrcModule->getSourceFileName())}));
1166 GlobalsToImport.
insert(Fn);
1179 for (
const auto *GV : GlobalsToImport)
1181 <<
" from " << SrcModule->getSourceFileName() <<
"\n";
1189 ImportedCount += GlobalsToImport.
size();
1190 NumImportedModules++;
1195 NumImportedFunctions += (ImportedCount - ImportedGVCount);
1196 NumImportedGlobalVars += ImportedGVCount;
1198 LLVM_DEBUG(
dbgs() <<
"Imported " << ImportedCount - ImportedGVCount
1199 <<
" functions for Module " 1202 <<
" global variables for Module " 1204 return ImportedCount;
1212 if (!IndexPtrOrErr) {
1217 std::unique_ptr<ModuleSummaryIndex> Index = std::move(*IndexPtrOrErr);
1235 for (
auto &
I : *Index) {
1236 for (
auto &S :
I.second.SummaryList) {
1245 errs() <<
"Error renaming module\n";
1250 auto ModuleLoader = [&M](
StringRef Identifier) {
1259 "Error importing module: ");
1269 class FunctionImportLegacyPass :
public ModulePass {
1274 explicit FunctionImportLegacyPass() :
ModulePass(ID) {}
1277 StringRef getPassName()
const override {
return "Function Importing"; }
1279 bool runOnModule(
Module &M)
override {
1299 "Summary Based Function Import",
false,
false)
1304 return new FunctionImportLegacyPass();
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)
ThreadLocalMode getThreadLocalMode() const
const GlobalObject * getBaseObject() 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...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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.
A Module instance is used to store all the information related to an LLVM module. ...
Same, but only replaced by something equivalent.
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)...
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
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)
static bool isLocalLinkage(LinkageTypes Linkage)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
GlobalValue::GUID getGUID() const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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...
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, GlobalValue::GUID G)
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"))
static bool canImportGlobalVar(GlobalValueSummary *S)
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.
void propagateConstants(const DenseSet< GlobalValue::GUID > &PreservedSymbols)
Analyze index and detect unmodified globals.
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"))
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.
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.
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.
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)
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 void computeImportForReferencedGlobals(const FunctionSummary &Summary, const GVSummaryMapTy &DefinedGVSummaries, FunctionImporter::ImportMapTy &ImportList, StringMap< FunctionImporter::ExportSetTy > *ExportLists)
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
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
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.
void emplace_back(ArgTypes &&... Args)
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.
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
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
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.
static GlobalValue::GUID getGUID(GlobalValue::GUID G)
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.
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.
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.
static void internalizeImmutableGVs(Module &M)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...