29#include "llvm/Config/llvm-config.h"
67#if !defined(_MSC_VER) && !defined(__MINGW32__)
76#define DEBUG_TYPE "thinlto"
107 " to save optimized bitcode\n");
112 ArrayRef<std::unique_ptr<GlobalValueSummary>> GVSummaryList) {
115 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
116 auto Linkage = Summary->linkage();
120 if (StrongDefForLinker != GVSummaryList.end())
121 return StrongDefForLinker->get();
125 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
126 auto Linkage = Summary->linkage();
130 if (FirstDefForLinker == GVSummaryList.end())
132 return FirstDefForLinker->get();
141 auto HasMultipleCopies =
143 return GVSummaryList.size() > 1;
146 for (
auto &
I : Index) {
147 if (HasMultipleCopies(
I.second.getSummaryList()))
148 PrevailingCopy[
I.first] =
156 for (
auto &M : Modules) {
157 LLVM_DEBUG(
dbgs() <<
"Adding module " << M->getName() <<
" to ModuleMap\n");
159 "Expect unique Buffer Identifier");
160 ModuleMap[M->getName()] = M.get();
166 bool ClearDSOLocalOnDeclarations) {
176 : DiagnosticInfo(
DK_Linker, Severity), Msg(DiagMsg) {}
177 void print(DiagnosticPrinter &DP)
const override { DP << Msg; }
183 bool BrokenDebugInfo =
false;
186 if (BrokenDebugInfo) {
188 "Invalid debug info found, debug info will be stripped",
DS_Warning));
197 auto &
Mod =
Input->getSingleBitcodeModule();
199 Lazy ?
Mod.getLazyModule(Context,
201 :
Mod.parseModule(Context);
204 SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
205 SourceMgr::DK_Error, EIB.message());
206 Err.print(
"ThinLTO", errs());
212 return std::move(*ModuleOrErr);
219 bool ClearDSOLocalOnDeclarations) {
220 auto Loader = [&](
StringRef Identifier) {
221 auto &
Input = ModuleMap[Identifier];
230 SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
231 SourceMgr::DK_Error, EIB.message());
232 Err.print(
"ThinLTO", errs());
241 unsigned OptLevel,
bool Freestanding,
243 std::optional<PGOOptions> PGOOpt;
256 !SampleProfileFile.empty()) {
275 std::unique_ptr<TargetLibraryInfoImpl> TLII(
278 TLII->disableAllFunctions();
282 PB.registerModuleAnalyses(
MAM);
283 PB.registerCGSCCAnalyses(
CGAM);
284 PB.registerFunctionAnalyses(
FAM);
285 PB.registerLoopAnalyses(
LAM);
309 MPM.
addPass(
PB.buildThinLTODefaultPipeline(OL, Index));
317 Triple TT(File.getTargetTriple());
321 for (
const auto &Sym : File.symbols())
322 if (Sym.isUsed() || Sym.isLibcall(
TLI, Libcalls))
334 for (
const auto &Sym : File.symbols()) {
335 if (PreservedSymbols.
count(Sym.getName()) && !Sym.getIRName().empty())
345 const Triple &TheTriple) {
348 GUIDPreservedSymbols);
349 return GUIDPreservedSymbols;
363 return std::make_unique<SmallVectorMemoryBuffer>(
369class ModuleCacheEntry {
370 SmallString<128> EntryPath;
377 StringRef CachePath,
const ModuleSummaryIndex &Index, StringRef ModuleID,
378 const FunctionImporter::ImportMapTy &ImportList,
380 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
382 bool Freestanding,
const TargetMachineBuilder &TMBuilder,
383 ArrayRef<std::string> MllvmArgs) {
384 if (CachePath.
empty())
387 if (!
Index.modulePaths().count(ModuleID))
392 [](uint32_t
V) { return V == 0; }))
396 llvm::lto::Config Conf;
407 ResolvedODR, DefinedGVSummaries);
415 StringRef getEntryPath() {
return EntryPath; }
418 ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
419 if (EntryPath.empty())
420 return std::error_code();
421 SmallString<64> ResultPath;
427 *FDOrErr, EntryPath, -1,
false);
433 void write(
const MemoryBuffer &OutputBuffer) {
434 if (EntryPath.empty())
438 EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) ->
llvm::Error {
449static std::unique_ptr<MemoryBuffer>
457 bool DisableCodeGen,
StringRef SaveTempsDir,
458 bool Freestanding,
unsigned OptLevel,
unsigned count,
459 bool DebugPassManager) {
461 bool SingleModule = (ModuleMap.
size() == 1);
465 bool ClearDSOLocalOnDeclarations =
471 promoteModule(TheModule, Index, ClearDSOLocalOnDeclarations);
482 if (!ExportList.
empty() || !GUIDPreservedSymbols.
empty()) {
492 ClearDSOLocalOnDeclarations);
503 optimizeModule(TheModule, TM, OptLevel, Freestanding, DebugPassManager,
508 if (DisableCodeGen) {
517 return std::make_unique<SmallVectorMemoryBuffer>(
531 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
538 const auto &Prevailing = PrevailingCopy.
find(GUID);
540 if (Prevailing == PrevailingCopy.
end())
542 return Prevailing->second == S;
545 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
548 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
554 GUIDPreservedSymbols);
559 const Triple &TheTriple) {
560 if (TMBuilder.
MCpu.empty())
562 TMBuilder.
TheTriple = std::move(TheTriple);
575 toString(InputOrError.takeError()));
577 auto TripleStr = (*InputOrError)->getTargetTriple();
578 Triple TheTriple(TripleStr);
582 else if (TMBuilder.TheTriple != TheTriple) {
583 if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
589 Modules.emplace_back(std::move(*InputOrError));
593 PreservedSymbols.insert(Name);
600 PreservedSymbols.insert(Name);
614 std::string FeatureStr = Features.
getString();
616 std::unique_ptr<TargetMachine> TM(
619 assert(TM &&
"Cannot create target machine");
629 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
630 std::make_unique<ModuleSummaryIndex>(
false);
631 for (
auto &
Mod : Modules) {
632 auto &M =
Mod->getSingleBitcodeModule();
633 if (
Error Err = M.readSummary(*CombinedIndex,
Mod->getName())) {
636 std::move(Err),
errs(),
637 "error: can't create module summary index for buffer: ");
641 return CombinedIndex;
652 : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
655 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
656 return (ExportList != ExportLists.
end() && ExportList->second.
count(VI)) ||
657 GUIDPreservedSymbols.
count(VI.getGUID());
662 const DenseMap<GlobalValue::GUID, const GlobalValueSummary *> &PrevailingCopy;
663 IsPrevailing(
const DenseMap<GlobalValue::GUID, const GlobalValueSummary *>
665 : PrevailingCopy(PrevailingCopy) {}
668 const auto &Prevailing = PrevailingCopy.
find(GUID);
670 if (Prevailing == PrevailingCopy.
end())
672 return Prevailing->second == S;
696 auto ModuleCount = Index.modulePaths().size();
701 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
721 IsPrevailing(PrevailingCopy), ImportLists,
730 ModuleToDefinedGVSummaries[ModuleIdentifier],
736 Index, IsExported(ExportLists, GUIDPreservedSymbols),
737 IsPrevailing(PrevailingCopy));
750 auto ModuleCount = Index.modulePaths().size();
754 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
773 IsPrevailing(PrevailingCopy), ImportLists,
789 auto ModuleCount = Index.modulePaths().size();
794 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
813 IsPrevailing(PrevailingCopy), ImportLists,
817 ModuleIdentifier, ModuleToDefinedGVSummaries,
818 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex, DecSummaries);
827 auto ModuleCount = Index.modulePaths().size();
832 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
851 IsPrevailing(PrevailingCopy), ImportLists,
860 ModuleIdentifier, ModuleToDefinedGVSummaries,
861 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex, DecSummaries);
864 ModuleToSummariesForIndex))
866 " to save imports lists\n");
877 auto ModuleCount = Index.modulePaths().size();
881 auto GUIDPreservedSymbols =
888 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
901 IsPrevailing(PrevailingCopy), ImportLists,
903 auto &ExportList = ExportLists[ModuleIdentifier];
907 if (ExportList.
empty() && GUIDPreservedSymbols.
empty())
918 Index, IsExported(ExportLists, GUIDPreservedSymbols),
919 IsPrevailing(PrevailingCopy));
926 ModuleToDefinedGVSummaries[ModuleIdentifier],
930 ModuleToDefinedGVSummaries[ModuleIdentifier]);
940 optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding,
941 DebugPassManager,
nullptr);
950 auto ArchName = TMBuilder.TheTriple.getArchName();
953 Twine(
count) +
"." + ArchName +
".thinlto.o");
959 if (!CacheEntryPath.
empty()) {
963 return std::string(OutputPath);
967 return std::string(OutputPath);
971 errs() <<
"remark: can't link or copy from cached entry '" << CacheEntryPath
972 <<
"' to '" << OutputPath <<
"'\n";
980 return std::string(OutputPath);
991 assert(ProducedBinaries.empty() &&
"The generator should not be reused");
992 if (SavedObjectsDirectoryPath.empty())
993 ProducedBinaries.resize(Modules.size());
1000 ProducedBinaryFiles.resize(Modules.size());
1007 for (
auto &
Mod : Modules) {
1019 if (SavedObjectsDirectoryPath.empty())
1022 ProducedBinaryFiles[
count] =
1034 if (!SaveTempsDir.empty()) {
1035 auto SaveTempPath = SaveTempsDir +
"index.bc";
1040 " to save optimized bitcode\n");
1047 auto ModuleCount = Modules.size();
1051 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1056 for (
const auto &M : Modules)
1058 GUIDPreservedSymbols);
1061 for (
const auto &M : Modules)
1071 Index->setWithWholeProgramVisibility();
1084 std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
1085 std::set<GlobalValue::GUID> ExportedGUIDs;
1098 IsPrevailing(PrevailingCopy), ImportLists,
1116 IsExported(ExportLists, GUIDPreservedSymbols),
1117 LocalWPDTargetsMap);
1119 *Index, IsExported(ExportLists, GUIDPreservedSymbols),
1120 IsPrevailing(PrevailingCopy));
1127 for (
auto &
Module : Modules) {
1129 ExportLists[ModuleIdentifier];
1130 ImportLists[ModuleIdentifier];
1131 ResolvedODR[ModuleIdentifier];
1132 ModuleToDefinedGVSummaries[ModuleIdentifier];
1135 std::vector<BitcodeModule *> ModulesVec;
1136 ModulesVec.reserve(Modules.size());
1137 for (
auto &
Mod : Modules)
1138 ModulesVec.push_back(&
Mod->getSingleBitcodeModule());
1144 TimeTraceScopeExit.release();
1149 for (
auto IndexCount : ModulesOrdering) {
1150 auto &
Mod = Modules[IndexCount];
1152 auto ModuleIdentifier =
Mod->getName();
1153 auto &ExportList = ExportLists[ModuleIdentifier];
1155 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1158 ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
1159 ImportLists[ModuleIdentifier], ExportList,
1160 ResolvedODR[ModuleIdentifier],
1161 DefinedGVSummaries, OptLevel, Freestanding,
1162 TMBuilder, MllvmArgs);
1163 auto CacheEntryPath = CacheEntry.getEntryPath();
1166 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1168 <<
" '" << CacheEntryPath <<
"' for buffer "
1169 <<
count <<
" " << ModuleIdentifier <<
"\n");
1173 if (SavedObjectsDirectoryPath.empty())
1174 ProducedBinaries[
count] = std::move(ErrOrBuffer.get());
1177 count, CacheEntryPath, *ErrOrBuffer.get());
1185 Context.enableDebugTypeODRUniquing();
1189 if (!DiagFileOrErr) {
1190 errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
1202 auto &ImportList = ImportLists[ModuleIdentifier];
1205 *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
1206 ExportList, GUIDPreservedSymbols,
1207 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1208 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel,
count,
1214 if (SavedObjectsDirectoryPath.empty()) {
1216 if (!CacheEntryPath.empty()) {
1223 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1224 if (
auto EC = ReloadedBufferOrErr.getError()) {
1226 errs() <<
"remark: can't reload cached file '" << CacheEntryPath
1227 <<
"': " << EC.message() <<
"\n";
1242 pruneCache(CacheOptions.Path, CacheOptions.Policy, ProducedBinaries);
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file provides a bitcode writing pass.
#define LLVM_LIFETIME_BOUND
Provides passes for computing function attributes based on interprocedural analyses.
This file implements a simple parser to decode commandline option for remarks hotness threshold that ...
This is the interface to build a ModuleSummaryIndex for a module.
CGSCCAnalysisManager CGAM
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
This header defines classes/functions to handle pass execution timing information with interfaces for...
This file provides the interface for the sampled PGO loader pass.
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
static void crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index, StringMap< lto::InputFile * > &ModuleMap, const FunctionImporter::ImportMapTy &ImportList, bool ClearDSOLocalOnDeclarations)
static void computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
static StringMap< lto::InputFile * > generateModuleMap(std::vector< std::unique_ptr< lto::InputFile > > &Modules)
static void initTMBuilder(TargetMachineBuilder &TMBuilder, const Triple &TheTriple)
static void resolvePrevailingInIndex(ModuleSummaryIndex &Index, StringMap< std::map< GlobalValue::GUID, GlobalValue::LinkageTypes > > &ResolvedODR, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, const DenseMap< GlobalValue::GUID, const GlobalValueSummary * > &PrevailingCopy)
Resolve prevailing symbols.
static const GlobalValueSummary * getFirstDefinitionForLinker(ArrayRef< std::unique_ptr< GlobalValueSummary > > GVSummaryList)
static void computePrevailingCopies(const ModuleSummaryIndex &Index, DenseMap< GlobalValue::GUID, const GlobalValueSummary * > &PrevailingCopy)
static void saveTempBitcode(const Module &TheModule, StringRef TempDir, unsigned count, StringRef Suffix)
static void verifyLoadedModule(Module &TheModule)
Verify the module and strip broken debug info.
static void addUsedSymbolToPreservedGUID(const lto::InputFile &File, DenseSet< GlobalValue::GUID > &PreservedGUID)
static std::unique_ptr< MemoryBuffer > ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, StringMap< lto::InputFile * > &ModuleMap, TargetMachine &TM, const FunctionImporter::ImportMapTy &ImportList, const FunctionImporter::ExportSetTy &ExportList, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, const GVSummaryMapTy &DefinedGlobals, const ThinLTOCodeGenerator::CachingOptions &CacheOptions, bool DisableCodeGen, StringRef SaveTempsDir, bool Freestanding, unsigned OptLevel, unsigned count, bool DebugPassManager)
static cl::opt< int > ThreadCount("threads", cl::init(0))
static std::unique_ptr< MemoryBuffer > codegenModule(Module &TheModule, TargetMachine &TM)
static void optimizeModule(Module &TheModule, TargetMachine &TM, unsigned OptLevel, bool Freestanding, bool DebugPassManager, ModuleSummaryIndex *Index)
static void computeGUIDPreservedSymbols(const lto::InputFile &File, const StringSet<> &PreservedSymbols, const Triple &TheTriple, DenseSet< GlobalValue::GUID > &GUIDs)
static std::unique_ptr< Module > loadModuleFromInput(lto::InputFile *Input, LLVMContext &Context, bool Lazy, bool IsImporting)
static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index, bool ClearDSOLocalOnDeclarations)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
iterator find(const_arg_type_t< KeyT > Val)
Implements a dense probed hash-table based set.
This is the base abstract class for diagnostic reporting in the backend.
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
The map maintains the list of imports.
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.
DenseSet< ValueInfo > ExportSetTy
The set contains an entry for every global value that the module exports.
Function and variable summary information to aid decisions and implementation of importing.
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
static LLVM_ABI std::string getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, StringRef FileName)
Return the modified name for a global value suitable to be used as the key for a global lookup (e....
bool isWeakForLinker() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ ExternalLinkage
Externally visible function.
This is an important class for using LLVM in a threaded context.
LLVM_ABI cl::LibraryOptionsContext & getLibraryOptions() const
The library options this context reads in place of their process-wide values.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
StringRef getBuffer() const
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.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
LLVMContext & getContext() const
Get the global data context.
StringRef getName() const
Get a short "name" for the module.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Tunable parameters for passes in the default pipelines.
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Analysis providing profile information.
static LLVM_ABI StringRef getSampleProfileFile(const LLVMContext &C)
Return -sample-profile-file.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class provides an interface to register all the standard pass instrumentations and manages their...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
bool contains(StringRef Key) const
contains - Return true if the element is in the map, false otherwise.
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
StringSet - A wrapper for StringMap that provides set-like functionality.
Manages the enabling and disabling of subtarget specific features.
LLVM_ABI void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
LLVM_ABI std::string getString() const
Returns features as a string.
Analysis pass providing the TargetLibraryInfo.
Implementation of the target library information.
Provides information about what library functions are available for the current target.
Primary interface to the complete machine description for the target machine.
const Triple & getTargetTriple() const
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
VectorLibrary VecLib
Vector math library to use.
unsigned DataSections
Emit data into separate sections.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
LLVM_ABI void preserveSymbol(StringRef Name)
Adds to a list of all global symbols that must exist in the final generated code.
LLVM_ABI void run()
Process all the modules that were added to the code generator in parallel.
LLVM_ABI void crossReferenceSymbol(StringRef Name)
Adds to a list of all global symbols that are cross-referenced between ThinLTO files.
LLVM_ABI void addModule(StringRef Identifier, StringRef Data)
Add given module to the code generator.
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
Triple - Helper class for working with autoconf configuration names.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void assign(const LibraryOptionsContext &Other)
std::pair< iterator, bool > insert(const ValueT &V)
void insert_range(Range &&R)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
A raw_ostream that writes to a file descriptor.
A raw_ostream that writes to an SmallVector or SmallString.
LLVM_ABI void optimize(Module &Module)
Perform post-importing ThinLTO optimizations.
LLVM_ABI std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
LLVM_ABI void crossModuleImport(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform cross-module importing for the module identified by ModuleIdentifier.
LLVM_ABI void emitImports(Module &Module, StringRef OutputName, ModuleSummaryIndex &Index, const lto::InputFile &File)
Compute and emit the imported files for module at ModulePath.
LLVM_ABI void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
LLVM_ABI void gatherImportedSummariesForModule(Module &Module, ModuleSummaryIndex &Index, ModuleToSummariesForIndexTy &ModuleToSummariesForIndex, GVSummaryPtrSet &DecSummaries, const lto::InputFile &File)
Compute the list of summaries and the subset of declaration summaries needed for importing into modul...
LLVM_ABI void promote(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform promotion and renaming of exported internal functions, and additionally resolve weak and link...
LLVM_ABI std::string writeGeneratedObject(int count, StringRef CacheEntryPath, const MemoryBuffer &OutputBuffer)
Write temporary object file to SavedObjectDirectoryPath, write symlink to Cache directory if needed.
Interfaces for registering analysis passes, producing common pass manager configurations,...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ThinLTOCodeGeneratorImpl - Namespace used for ThinLTOCodeGenerator implementation details.
initializer< Ty > init(const Ty &Val)
LLVM_ABI std::optional< bool > getExplicitDataSections()
LLVM_ABI StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
LLVM_ABI Expected< LLVMRemarkFileHandle > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
LLVM_ABI std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
LLVM_ABI std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
@ OF_UpdateAtime
Force files Atime to be updated on access.
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)
Returns a thread strategy for tasks requiring significant memory or other resources.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
cl::opt< std::string > RemarksFormat("lto-pass-remarks-format", cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml"))
LLVM_ABI void runWholeProgramDevirtOnIndex(ModuleSummaryIndex &Summary, std::set< GlobalValue::GUID > &ExportedGUIDs, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap, DenseSet< StringRef > *ExternallyVisibleSymbolNamesPtr=nullptr)
Perform index-based whole program devirtualization on the Summary index.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
cl::opt< bool > LTODiscardValueNames("lto-discard-value-names", cl::desc("Strip names from Value during LTO (other than GlobalValue)."), cl::init(false), cl::Hidden)
LLVM_ABI void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
cl::opt< std::string > RemarksPasses("lto-pass-remarks-filter", cl::desc("Only record optimization remarks from passes whose " "names match the given regular expression"), cl::value_desc("regex"))
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
@ O1
Optimize quickly without destroying debuggability.
@ O0
Disable as many optimizations as possible.
@ O3
Optimize for fast execution as much as possible.
@ O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
LLVM_ABI bool thinLTOPropagateFunctionAttrs(ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing)
Propagate function attributes for function summaries along the index's callgraph during thinlink.
LLVM_ABI void renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, bool ClearDSOLocalOnDeclarations, SetVector< GlobalValue * > *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback=[](const Function &F) -> const StackSafetyInfo *{ return nullptr;})
Direct function to compute a ModuleSummaryIndex from a given module.
LLVM_ABI void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
LLVM_ABI bool hasWholeProgramVisibility(bool WholeProgramVisibilityEnabledInLTO)
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
LLVM_ABI void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
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.
LLVM_ABI void updateIndexWPDForExports(ModuleSummaryIndex &Summary, function_ref< bool(StringRef, ValueInfo)> isExported, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap, DenseSet< StringRef > *ExternallyVisibleSymbolNamesPtr=nullptr)
Call after cross-module importing to update the recorded single impl devirt target names for any loca...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI Error runCodeGenPipeline(TargetMachine &TM, Module &M, raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify=true, bool DisableSimplifyLibCalls=false, const ModuleSummaryIndex *MSI=nullptr, IntrusiveRefCntPtr< vfs::FileSystem > VFS=vfs::getRealFileSystem())
LLVM_ABI void updatePublicTypeTestCalls(Module &M, bool WholeProgramVisibilityEnabledInLTO)
cl::opt< std::string > LTOCSIRProfile("cs-profile-path", cl::desc("Context sensitive profile file path"))
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
bool timeTraceProfilerEnabled()
Is the time trace profiler enabled, i.e. initialized?
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI Error writeToOutput(StringRef OutputFileName, std::function< Error(raw_ostream &)> Write)
This helper creates an output stream and then passes it to Write.
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
LLVM_ABI void timeTraceProfilerEnd()
Manually end the last time section.
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
LLVM_ABI void thinLTOResolvePrevailingInIndex(const lto::Config &C, ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Resolve linkage for prevailing symbols in the Index.
cl::opt< bool > LTORunCSIRInstr("cs-profile-generate", cl::desc("Perform context sensitive PGO instrumentation"))
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
@ Mod
The access may modify the value stored in memory.
LLVM_ABI void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
LLVM_ABI void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
SingleThreadExecutor DefaultThreadPool
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::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
cl::opt< std::optional< uint64_t >, false, remarks::HotnessThresholdParser > RemarksHotnessThreshold("lto-pass-remarks-hotness-threshold", cl::desc("Minimum profile count required for an " "optimization remark to be output." " Use 'auto' to apply the threshold from profile summary."), cl::value_desc("uint or 'auto'"), cl::init(0), cl::Hidden)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI std::string computeLTOCacheKey(const lto::Config &Conf, const ModuleSummaryIndex &Index, StringRef ModuleID, const FunctionImporter::ImportMapTy &ImportList, const FunctionImporter::ExportSetTy &ExportList, const std::map< GlobalValue::GUID, GlobalValue::LinkageTypes > &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, const DenseSet< GlobalValue::GUID > &CfiFunctionDefs={}, const DenseSet< GlobalValue::GUID > &CfiFunctionDecls={})
Computes a unique hash for the Module considering the current list of export/import and other global ...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
SmallPtrSet< GlobalValueSummary *, 0 > GVSummaryPtrSet
A set of global value summary pointers.
LLVM_ABI Expected< bool > pruneCache(StringRef Path, CachePruningPolicy Policy, const std::vector< std::unique_ptr< MemoryBuffer > > &Files={})
Perform pruning using the supplied policy, returns true if pruning occurred, i.e.
LLVM_ABI std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
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 write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
LLVM_ABI Error EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex)
Emit into OutputFilename the files module ModulePath will import from.
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI TimeTraceProfilerEntry * timeTraceProfilerBegin(StringRef Name, StringRef Detail)
Manually begin a time section, with the given Name and Detail.
LLVM_ABI void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, ValueInfo)> isExported, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, DenseSet< StringRef > *ExternallyVisibleSymbolNamesPtr=nullptr)
Update the linkages in the given Index to mark exported values as external and non-exported values as...
LLVM_ABI void updateVCallVisibilityInIndex(ModuleSummaryIndex &Index, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols, const DenseSet< GlobalValue::GUID > &VisibleToRegularObjSymbols)
If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable def...
LLVM_ABI void thinLTOFinalizeInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals, bool PropagateAttrs)
Based on the information recorded in the summaries during global summary-based analysis:
A struct capturing PGO tunables.
A simple container for information about the supported runtime calls.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Helper to gather options relevant to the target machine creation.
LLVM_ABI std::unique_ptr< TargetMachine > create() const
std::optional< Reloc::Model > RelocModel
CodeGenOptLevel CGOptLevel
Struct that holds a reference to a particular GUID in a global value summary.
std::vector< std::string > MAttrs
std::vector< std::string > MllvmArgs
CodeGenOptLevel CGOptLevel
std::optional< Reloc::Model > RelocModel
bool Freestanding
Flag to indicate that the optimizer should not assume builtins are present on the target.