9#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
10#define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
22#include <system_error>
87 std::unique_ptr<ImportFailureInfo>>>;
126 auto Key = std::make_pair(FromModule, GUID);
127 auto InsertResult = TheTable.try_emplace(Key, TheTable.size());
128 return makeIDPair(InsertResult.first->second);
133 std::optional<std::pair<ImportIDTy, ImportIDTy>>
135 auto Key = std::make_pair(FromModule, GUID);
136 auto It = TheTable.find(Key);
137 if (It != TheTable.end())
138 return makeIDPair(It->second);
144 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>
149 auto It = TheTable.begin() + (ImportID >> 1);
152 return std::make_tuple(FromModule, GUID, Kind);
156 std::tuple<StringRef, GlobalValue::GUID, GlobalValueSummary::ImportKind>
163 static std::pair<ImportIDTy, ImportIDTy> makeIDPair(
ImportIDTy Index) {
166 return std::make_pair(Def, Decl);
173 class SortedImportList;
224 LLVM_ABI std::optional<GlobalValueSummary::ImportKind>
246 bool(
const std::pair<StringRef, GlobalValue::GUID> &,
247 const std::pair<StringRef, GlobalValue::GUID> &)>
249 : IDs(ImportMap.IDs), Imports(
iterator_range(ImportMap.Imports)) {
253 -> std::pair<StringRef, GlobalValue::GUID> {
254 auto Tuple = IDs.
lookup(Id);
255 return std::make_pair(std::get<0>(Tuple), std::get<1>(Tuple));
277 : ImportIDs(), EmptyList(ImportIDs), ListsImpl(
Size) {}
280 return ListsImpl.try_emplace(DestMod, ImportIDs).first->second;
284 auto It = ListsImpl.find(DestMod);
285 if (It != ListsImpl.end())
290 size_t size()
const {
return ListsImpl.size(); }
309 std::function<Expected<std::unique_ptr<Module>>(
StringRef Identifier)>;
313 bool ClearDSOLocalOnDeclarations)
314 : Index(Index), ModuleLoader(
std::
move(ModuleLoader)),
315 ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {}
319 const ImportMapTy &ImportList);
330 bool ClearDSOLocalOnDeclarations;
387 ModuleSummaryIndex &
Index,
388 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
394 ModuleSummaryIndex &
Index,
395 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
417 StringRef ModulePath,
418 const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
419 const FunctionImporter::ImportMapTy &ImportList,
430 StringRef ModulePath,
432 function_ref<
void(
const std::string &)>
F);
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.
LLVM_ABI 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.
LLVM_ABI AddDefinitionStatus addDefinition(StringRef FromModule, GlobalValue::GUID GUID)
ImportMapTy(ImportIDTable &IDs)
void addGUID(StringRef FromModule, GlobalValue::GUID GUID, GlobalValueSummary::ImportKind ImportKind)
LLVM_ABI SmallVector< StringRef, 0 > getSourceModules() const
LLVM_ABI std::optional< GlobalValueSummary::ImportKind > getImportType(StringRef FromModule, GlobalValue::GUID GUID) const
LLVM_ABI 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...
LLVM_ABI 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)
LLVM_ABI bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
LLVM_ABI 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)
LLVM_ABI 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...
LLVM_ABI void updateIndirectCalls(ModuleSummaryIndex &Index)
Update call edges for indirect calls to local functions added from SamplePGO when needed.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI void processImportsFiles(StringRef ModulePath, const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex, function_ref< void(const std::string &)> F)
Call F passing each of the files module ModulePath will import from.
PrevailingType
PrevailingType enum used as a return type of callback passed to computeDeadSymbolsAndUpdateIndirectCa...
LLVM_ABI 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.
LLVM_ABI 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,...
LLVM_ABI 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.