9#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
10#define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
21#include <system_error>
86 std::unique_ptr<ImportFailureInfo>>>;
125 auto Key = std::make_pair(FromModule, GUID);
126 auto InsertResult = TheTable.try_emplace(Key, TheTable.size());
127 return makeIDPair(InsertResult.first->second);
132 std::optional<std::pair<ImportIDTy, ImportIDTy>>
134 auto Key = std::make_pair(FromModule, GUID);
135 auto It = TheTable.find(Key);
136 if (It != TheTable.end())
137 return makeIDPair(It->second);
143 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>
148 auto It = TheTable.begin() + (ImportID >> 1);
151 return std::make_tuple(FromModule, GUID, Kind);
155 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>
162 static std::pair<ImportIDTy, ImportIDTy> makeIDPair(
ImportIDTy Index) {
165 return std::make_pair(Def, Decl);
172 class SortedImportList;
222 std::optional<GlobalValueSummary::ImportKind>
244 bool(
const std::pair<StringRef, GlobalValue::GUID> &,
245 const std::pair<StringRef, GlobalValue::GUID> &)>
247 : IDs(ImportMap.IDs), Imports(
iterator_range(ImportMap.Imports)) {
251 -> std::pair<StringRef, GlobalValue::GUID> {
252 auto Tuple = IDs.
lookup(Id);
253 return std::make_pair(std::get<0>(Tuple), std::get<1>(Tuple));
277 return ListsImpl.try_emplace(DestMod, ImportIDs).first->second;
281 auto It = ListsImpl.find(DestMod);
282 if (It != ListsImpl.end())
287 size_t size()
const {
return ListsImpl.size(); }
306 std::function<Expected<std::unique_ptr<Module>>(
StringRef Identifier)>;
310 bool ClearDSOLocalOnDeclarations)
311 : Index(Index), ModuleLoader(
std::
move(ModuleLoader)),
312 ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {}
326 bool ClearDSOLocalOnDeclarations;
383 ModuleSummaryIndex &
Index,
384 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
390 ModuleSummaryIndex &
Index,
391 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
413 StringRef ModulePath,
414 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
415 const FunctionImporter::ImportMapTy &ImportList,
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
This file implements a map that provides insertion order iteration.
static cl::opt< bool > PropagateAttrs("propagate-attrs", cl::init(true), cl::Hidden, cl::desc("Propagate attributes in index"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
A container for analyses that lazily runs them and caches their results.
Implements a dense probed hash-table based set.
Tagged union holding either a T or a Error.
The function importing pass.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
std::pair< ImportIDTy, ImportIDTy > createImportIDs(StringRef FromModule, GlobalValue::GUID GUID)
ImportIDTable(const ImportIDTable &)=delete
ImportIDTable & operator=(const ImportIDTable &)=delete
std::tuple< StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind > lookup(ImportIDTy ImportID) const
std::optional< std::pair< ImportIDTy, ImportIDTy > > getImportIDs(StringRef FromModule, GlobalValue::GUID GUID)
std::tuple< StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind > operator()(ImportIDTable::ImportIDTy ImportID) const
const_iterator begin() const
const ImportMapTy & lookup(StringRef DestMod) const
const_iterator end() const
ImportMapTy & operator[](StringRef DestMod)
ImportListsTy(size_t Size)
The map maintains the list of imports.
AddDefinitionStatus addDefinition(StringRef FromModule, GlobalValue::GUID GUID)
ImportMapTy(ImportIDTable &IDs)
void addGUID(StringRef FromModule, GlobalValue::GUID GUID, GlobalValueSummary::ImportKind ImportKind)
SmallVector< StringRef, 0 > getSourceModules() const
std::optional< GlobalValueSummary::ImportKind > getImportType(StringRef FromModule, GlobalValue::GUID GUID) const
void maybeAddDeclaration(StringRef FromModule, GlobalValue::GUID GUID)
SortedImportList(const ImportMapTy &ImportMap, llvm::function_ref< bool(const std::pair< StringRef, GlobalValue::GUID > &, const std::pair< StringRef, GlobalValue::GUID > &)> Comp)
The function importer is automatically importing function from other modules based on the provided su...
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader, bool ClearDSOLocalOnDeclarations)
Create a Function Importer.
ImportFailureReason
The different reasons selectCallee will chose not to import a candidate.
@ LocalLinkageNotInModule
std::function< Expected< std::unique_ptr< Module > >(StringRef Identifier)> ModuleLoaderTy
A function of this type is used to load modules referenced by the index.
Function and variable summary information to aid decisions and implementation of importing.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class implements a map that also provides access to all stored values in a deterministic order.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This is an optimization pass for GlobalISel generic memory operations.
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, FunctionImporter::ImportListsTy &ImportLists, DenseMap< StringRef, FunctionImporter::ExportSetTy > &ExportLists)
Compute all the imports and exports for every module in the Index.
void sort(IteratorTy Start, IteratorTy End)
void computeDeadSymbolsAndUpdateIndirectCalls(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...
void updateIndirectCalls(ModuleSummaryIndex &Index)
Update call edges for indirect calls to local functions added from SamplePGO when needed.
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
void gatherImportedSummariesForModule(StringRef ModulePath, const DenseMap< StringRef, GVSummaryMapTy > &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, ModuleToSummariesForIndexTy &ModuleToSummariesForIndex, GVSummaryPtrSet &DecSummaries)
Compute the set of summaries needed for a ThinLTO backend compilation of ModulePath.
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
PrevailingType
PrevailingType enum used as a return type of callback passed to computeDeadSymbolsAndUpdateIndirectCa...
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.
Error EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex)
Emit into OutputFilename the files module ModulePath will import from.
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
void thinLTOFinalizeInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals, bool PropagateAttrs)
Based on the information recorded in the summaries during global summary-based analysis:
Implement std::hash so that hash_code can be used in STL containers.
Information optionally tracked for candidates the importer decided not to import.
ImportFailureInfo(ValueInfo VI, CalleeInfo::HotnessType MaxHotness, ImportFailureReason Reason, unsigned Attempts)
CalleeInfo::HotnessType MaxHotness
ImportFailureReason Reason
A CRTP mix-in to automatically provide informational APIs needed for passes.
Struct that holds a reference to a particular GUID in a global value summary.