55 #include <system_error> 61 #define DEBUG_TYPE "function-import" 63 STATISTIC(NumImportedFunctions,
"Number of functions imported");
64 STATISTIC(NumImportedGlobalVars,
"Number of global variables imported");
65 STATISTIC(NumImportedModules,
"Number of modules imported from");
66 STATISTIC(NumDeadSymbols,
"Number of dead stripped symbols in index");
67 STATISTIC(NumLiveSymbols,
"Number of live symbols in index");
72 cl::desc(
"Only import functions with less than N instructions"));
76 cl::desc(
"Only import first N functions if N>=0 (default -1)"));
81 cl::desc(
"As we import functions, multiply the " 82 "`import-instr-limit` threshold by this factor " 83 "before processing newly imported functions"));
88 cl::desc(
"As we import functions called from hot callsite, multiply the " 89 "`import-instr-limit` threshold by this factor " 90 "before processing newly imported functions"));
94 cl::desc(
"Multiply the `import-instr-limit` threshold for hot callsites"));
100 "Multiply the `import-instr-limit` threshold for critical callsites"));
105 cl::desc(
"Multiply the `import-instr-limit` threshold for cold callsites"));
108 cl::desc(
"Print imported functions"));
127 cl::desc(
"The summary file to use for function importing."));
133 cl::desc(
"Import all external functions in index."));
136 static std::unique_ptr<Module>
loadFile(
const std::string &FileName,
142 std::unique_ptr<Module>
Result =
165 ArrayRef<std::unique_ptr<GlobalValueSummary>> CalleeSummaryList,
169 [&](
const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
170 auto *GVSummary = SummaryPtr.get();
193 auto *Summary = cast<FunctionSummary>(GVSummary->getBaseObject());
206 CalleeSummaryList.size() > 1 &&
207 Summary->modulePath() != CallerModulePath)
213 if (Summary->notEligibleToImport())
218 if (It == CalleeSummaryList.end())
221 return cast<GlobalValueSummary>(It->get());
250 for (
auto &
VI : Summary.
refs()) {
251 if (DefinedGVSummaries.
count(
VI.getGUID())) {
253 dbgs() <<
"Ref ignored! Target already in destination module.\n");
259 for (
auto &RefSummary :
VI.getSummaryList())
262 !RefSummary->modulePath().empty() &&
264 RefSummary->refs().empty()) {
265 ImportList[RefSummary->modulePath()].
insert(
VI.getGUID());
267 (*ExportLists)[RefSummary->modulePath()].insert(
VI.getGUID());
285 static int ImportCount = 0;
286 for (
auto &Edge : Summary.
calls()) {
288 LLVM_DEBUG(
dbgs() <<
" edge -> " << VI <<
" Threshold:" << Threshold
302 LLVM_DEBUG(
dbgs() <<
"ignored! Target already in destination module.\n");
316 const auto NewThreshold =
317 Threshold * GetBonusMultiplier(Edge.second.getHotness());
320 std::make_pair(VI.
getGUID(), std::make_pair(NewThreshold,
nullptr)));
321 bool PreviouslyVisited = !IT.second;
322 auto &ProcessedThreshold = IT.first->second.first;
323 auto &CalleeSummary = IT.first->second.second;
327 assert(PreviouslyVisited);
332 if (NewThreshold <= ProcessedThreshold) {
334 dbgs() <<
"ignored! Target was already imported with Threshold " 335 << ProcessedThreshold <<
"\n");
339 ProcessedThreshold = NewThreshold;
340 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
344 if (PreviouslyVisited && NewThreshold <= ProcessedThreshold) {
346 dbgs() <<
"ignored! Target was already rejected with Threshold " 347 << ProcessedThreshold <<
"\n");
353 if (!CalleeSummary) {
356 if (PreviouslyVisited)
357 ProcessedThreshold = NewThreshold;
359 dbgs() <<
"ignored! No qualifying callee with summary found.\n");
364 CalleeSummary = CalleeSummary->getBaseObject();
365 ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
368 "selectCallee() didn't honor the threshold");
370 auto ExportModulePath = ResolvedCalleeSummary->
modulePath();
371 auto ILI = ImportList[ExportModulePath].
insert(VI.
getGUID());
374 bool PreviouslyImported = !ILI.second;
378 auto &ExportList = (*ExportLists)[ExportModulePath];
379 ExportList.insert(VI.
getGUID());
380 if (!PreviouslyImported) {
387 for (
auto &Edge : ResolvedCalleeSummary->
calls()) {
388 auto CalleeGUID = Edge.first.getGUID();
389 ExportList.insert(CalleeGUID);
391 for (
auto &
Ref : ResolvedCalleeSummary->
refs()) {
392 auto GUID =
Ref.getGUID();
393 ExportList.insert(GUID);
399 auto GetAdjustedThreshold = [](
unsigned Threshold,
bool IsHotCallsite) {
410 const auto AdjThreshold = GetAdjustedThreshold(Threshold, IsHotCallsite);
433 for (
auto &GVSummary : DefinedGVSummaries) {
450 DefinedGVSummaries, Worklist, ImportList,
451 ExportLists, ImportThresholds);
455 while (!Worklist.
empty()) {
457 auto *Summary = std::get<0>(FuncInfo);
461 Worklist, ImportList, ExportLists,
470 auto SL =
VI.getSummaryList();
497 for (
auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
498 auto &ImportList = ImportLists[DefinedGVSummaries.first()];
500 << DefinedGVSummaries.first() <<
"'\n");
510 for (
auto &ELI : ExportLists) {
511 const auto &DefinedGVSummaries =
512 ModuleToDefinedGVSummaries.lookup(ELI.first());
513 for (
auto EI = ELI.second.begin(); EI != ELI.second.end();) {
514 if (!DefinedGVSummaries.count(*EI))
515 EI = ELI.second.erase(EI);
524 for (
auto &ModuleImports : ImportLists) {
525 auto ModName = ModuleImports.first();
526 auto &Exports = ExportLists[ModName];
529 << Exports.size() - NumGVS <<
" functions and " << NumGVS
530 <<
" vars. Imports from " << ModuleImports.second.size()
532 for (
auto &Src : ModuleImports.second) {
533 auto SrcModName = Src.first();
536 <<
" functions imported from " << SrcModName <<
"\n");
538 <<
" global vars imported from " << SrcModName <<
"\n");
548 LLVM_DEBUG(
dbgs() <<
"* Module " << ModulePath <<
" imports from " 549 << ImportList.
size() <<
" modules.\n");
550 for (
auto &Src : ImportList) {
551 auto SrcModName = Src.first();
554 <<
" functions imported from " << SrcModName <<
"\n");
555 LLVM_DEBUG(
dbgs() <<
" - " << NumGVSPerMod <<
" vars imported from " 556 << SrcModName <<
"\n");
571 LLVM_DEBUG(
dbgs() <<
"Computing import for Module '" << ModulePath <<
"'\n");
584 for (
auto &GlobalList : Index) {
586 if (GlobalList.second.SummaryList.empty())
589 auto GUID = GlobalList.first;
590 assert(GlobalList.second.SummaryList.size() == 1 &&
591 "Expected individual combined index to have one summary per GUID");
592 auto &Summary = GlobalList.second.SummaryList[0];
595 if (Summary->modulePath() == ModulePath)
598 ImportList[Summary->modulePath()].
insert(GUID);
612 if (GUIDPreservedSymbols.
empty())
615 unsigned LiveSymbols = 0;
618 for (
auto GUID : GUIDPreservedSymbols) {
627 for (
const auto &Entry : Index) {
628 auto VI = Index.getValueInfo(Entry);
629 for (
auto &S : Entry.second.SummaryList)
651 for (
auto &S :
VI.getSummaryList())
660 bool AvailableExternally =
false;
661 bool Interposable =
false;
662 for (
auto &S :
VI.getSummaryList()) {
664 AvailableExternally =
true;
669 if (!AvailableExternally)
676 for (
auto &S :
VI.getSummaryList())
682 while (!Worklist.
empty()) {
684 for (
auto &Summary :
VI.getSummaryList()) {
690 if (
auto *FS = dyn_cast<FunctionSummary>(Base))
691 for (
auto Call : FS->calls())
695 Index.setWithGlobalValueDeadStripping();
697 unsigned DeadSymbols = Index.size() - LiveSymbols;
698 LLVM_DEBUG(
dbgs() << LiveSymbols <<
" symbols Live, and " << DeadSymbols
699 <<
" symbols Dead \n");
700 NumDeadSymbols += DeadSymbols;
701 NumLiveSymbols += LiveSymbols;
710 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
712 ModuleToSummariesForIndex[ModulePath] =
713 ModuleToDefinedGVSummaries.
lookup(ModulePath);
715 for (
auto &ILI : ImportList) {
716 auto &SummariesForIndex = ModuleToSummariesForIndex[ILI.first()];
717 const auto &DefinedGVSummaries =
718 ModuleToDefinedGVSummaries.
lookup(ILI.first());
719 for (
auto &GI : ILI.second) {
720 const auto &
DS = DefinedGVSummaries.find(GI);
721 assert(
DS != DefinedGVSummaries.end() &&
722 "Expected a defined summary for imported global value");
723 SummariesForIndex[GI] =
DS->second;
731 const std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
736 for (
auto &ILI : ModuleToSummariesForIndex)
740 if (ILI.first != ModulePath)
741 ImportsOS << ILI.first <<
"\n";
742 return std::error_code();
748 if (
Function *
F = dyn_cast<Function>(&GV)) {
751 F->setComdat(
nullptr);
753 V->setInitializer(
nullptr);
756 V->setComdat(
nullptr);
782 const auto &GS = DefinedGlobals.
find(GV.getGUID());
783 if (GS == DefinedGlobals.
end())
785 auto NewLinkage = GS->second->linkage();
786 if (NewLinkage == GV.getLinkage())
797 GV.setLinkage(NewLinkage);
819 if (GV.hasLinkOnceODRLinkage() && GV.hasGlobalUnnamedAddr() &&
823 LLVM_DEBUG(
dbgs() <<
"ODR fixing up linkage for `" << GV.getName()
824 <<
"` from " << GV.getLinkage() <<
" to " << NewLinkage
826 GV.setLinkage(NewLinkage);
831 auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
832 if (GO && GO->isDeclarationForLinker() && GO->hasComdat())
833 GO->setComdat(
nullptr);
837 for (
auto &GV : TheModule)
839 for (
auto &GV : TheModule.globals())
841 for (
auto &GV : TheModule.aliases())
850 auto MustPreserveGV = [&](
const GlobalValue &GV) ->
bool {
852 auto GS = DefinedGlobals.
find(GV.getGUID());
853 if (GS == DefinedGlobals.
end()) {
865 if (GS == DefinedGlobals.
end()) {
904 unsigned ImportedCount = 0, ImportedGVCount = 0;
908 std::set<StringRef> ModuleNameOrderedList;
909 for (
auto &FunctionsToImportPerModule : ImportList) {
910 ModuleNameOrderedList.insert(FunctionsToImportPerModule.first());
912 for (
auto &
Name : ModuleNameOrderedList) {
914 const auto &FunctionsToImportPerModule = ImportList.find(
Name);
915 assert(FunctionsToImportPerModule != ImportList.end());
918 return SrcModuleOrErr.takeError();
919 std::unique_ptr<Module> SrcModule = std::move(*SrcModuleOrErr);
925 if (
Error Err = SrcModule->materializeMetadata())
926 return std::move(Err);
928 auto &ImportGUIDs = FunctionsToImportPerModule->second;
934 auto GUID =
F.getGUID();
935 auto Import = ImportGUIDs.count(GUID);
937 << GUID <<
" " <<
F.getName() <<
" from " 938 << SrcModule->getSourceFileName() <<
"\n");
940 if (
Error Err =
F.materialize())
941 return std::move(Err);
945 "thinlto_src_module",
948 SrcModule->getSourceFileName())}));
956 auto GUID = GV.getGUID();
957 auto Import = ImportGUIDs.count(GUID);
959 << GUID <<
" " << GV.getName() <<
" from " 960 << SrcModule->getSourceFileName() <<
"\n");
962 if (
Error Err = GV.materialize())
963 return std::move(Err);
964 ImportedGVCount += GlobalsToImport.
insert(&GV);
970 auto GUID = GA.getGUID();
971 auto Import = ImportGUIDs.count(GUID);
973 << GUID <<
" " << GA.getName() <<
" from " 974 << SrcModule->getSourceFileName() <<
"\n");
976 if (
Error Err = GA.materialize())
977 return std::move(Err);
981 return std::move(Err);
984 <<
" " << Base->
getName() <<
" from " 985 << SrcModule->getSourceFileName() <<
"\n");
989 "thinlto_src_module",
992 SrcModule->getSourceFileName())}));
994 GlobalsToImport.
insert(Fn);
1007 for (
const auto *GV : GlobalsToImport)
1009 <<
" from " << SrcModule->getSourceFileName() <<
"\n";
1017 ImportedCount += GlobalsToImport.
size();
1018 NumImportedModules++;
1021 NumImportedFunctions += (ImportedCount - ImportedGVCount);
1022 NumImportedGlobalVars += ImportedGVCount;
1024 LLVM_DEBUG(
dbgs() <<
"Imported " << ImportedCount - ImportedGVCount
1025 <<
" functions for Module " 1028 <<
" global variables for Module " 1030 return ImportedCount;
1038 if (!IndexPtrOrErr) {
1043 std::unique_ptr<ModuleSummaryIndex> Index = std::move(*IndexPtrOrErr);
1061 for (
auto &
I : *Index) {
1062 for (
auto &S :
I.second.SummaryList) {
1071 errs() <<
"Error renaming module\n";
1085 "Error importing module: ");
1095 class FunctionImportLegacyPass :
public ModulePass {
1100 explicit FunctionImportLegacyPass() :
ModulePass(ID) {}
1103 StringRef getPassName()
const override {
return "Function Importing"; }
1105 bool runOnModule(
Module &M)
override {
1125 "Summary Based Function Import",
false,
false)
1130 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)
void push_back(const T &Elt)
ThreadLocalMode getThreadLocalMode() const
const GlobalObject * getBaseObject() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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.
Compute iterated dominance frontiers using a linear time algorithm.
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. ...
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner)
Log all errors (if any) in E to OS.
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)"))
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)
CloneFunction - 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 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)
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...
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, GlobalValue::GUID G)
The access may reference the value stored in memory.
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.
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)
initializer< Ty > init(const Ty &Val)
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.
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.
bool isWeakForLinker() 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 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.
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"))
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 ComputeImportForModule(const GVSummaryMapTy &DefinedGVSummaries, const ModuleSummaryIndex &Index, 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 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 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...
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).
void thinLTOResolveWeakForLinkerModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve WeakForLinker values in TheModule based on the information recorded in the summaries during g...
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.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
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'"))
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
static const GlobalValueSummary * selectCallee(const ModuleSummaryIndex &Index, ArrayRef< std::unique_ptr< GlobalValueSummary >> CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath)
Given a list of possible callee implementation for a call site, select one that fits the Threshold...
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...