27#include "llvm/Config/llvm-config.h"
65#if !defined(_MSC_VER) && !defined(__MINGW32__)
73#define DEBUG_TYPE "thinlto"
104 " to save optimized bitcode\n");
112 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
117 if (StrongDefForLinker != GVSummaryList.end())
118 return StrongDefForLinker->get();
122 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
127 if (FirstDefForLinker == GVSummaryList.end())
129 return FirstDefForLinker->get();
135static void computePrevailingCopies(
139 return GVSummaryList.size() > 1;
143 if (HasMultipleCopies(
I.second.SummaryList))
144 PrevailingCopy[
I.first] =
145 getFirstDefinitionForLinker(
I.second.SummaryList);
150generateModuleMap(std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
152 for (
auto &M : Modules) {
154 "Expect unique Buffer Identifier");
155 ModuleMap[
M->getName()] =
M.get();
161 bool ClearDSOLocalOnDeclarations) {
170 ThinLTODiagnosticInfo(
const Twine &DiagMsg,
178static void verifyLoadedModule(
Module &TheModule) {
179 bool BrokenDebugInfo =
false;
182 if (BrokenDebugInfo) {
184 "Invalid debug info found, debug info will be stripped",
DS_Warning));
189static std::unique_ptr<Module> loadModuleFromInput(
lto::InputFile *Input,
196 Lazy ?
Mod.getLazyModule(Context,
198 :
Mod.parseModule(Context);
201 SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
202 SourceMgr::DK_Error, EIB.message());
203 Err.print(
"ThinLTO", errs());
208 verifyLoadedModule(*ModuleOrErr.
get());
209 return std::move(*ModuleOrErr);
216 bool ClearDSOLocalOnDeclarations) {
219 return loadModuleFromInput(Input, TheModule.
getContext(),
227 SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
228 SourceMgr::DK_Error, EIB.message());
229 Err.print(
"ThinLTO", errs());
234 verifyLoadedModule(TheModule);
238 unsigned OptLevel,
bool Freestanding,
240 std::optional<PGOOptions> PGOOpt;
254 std::unique_ptr<TargetLibraryInfoImpl> TLII(
257 TLII->disableAllFunctions();
296 for (
const auto &
Sym :
File.symbols()) {
303static void computeGUIDPreservedSymbols(
const lto::InputFile &File,
309 for (
const auto &
Sym :
File.symbols()) {
319 const Triple &TheTriple) {
322 GUIDPreservedSymbols);
323 return GUIDPreservedSymbols;
326std::unique_ptr<MemoryBuffer> codegenModule(
Module &TheModule,
347 return std::make_unique<SmallVectorMemoryBuffer>(
352class ModuleCacheEntry {
363 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
366 if (CachePath.
empty())
369 if (!
Index.modulePaths().count(ModuleID))
388 ResolvedODR, DefinedGVSummaries);
396 StringRef getEntryPath() {
return EntryPath; }
400 if (EntryPath.
empty())
401 return std::error_code();
408 *FDOrErr, EntryPath, -1,
false);
415 if (EntryPath.
empty())
428 std::string ErrorMsgBuffer;
429 llvm::raw_string_ostream S(ErrorMsgBuffer);
433 llvm::atomic_write_error::failed_to_create_uniq_file) {
434 errs() <<
"Error: " << ErrorMsgBuffer <<
"\n";
435 report_fatal_error(
"ThinLTO: Can't get a temporary file");
444static std::unique_ptr<MemoryBuffer>
452 bool DisableCodeGen,
StringRef SaveTempsDir,
453 bool Freestanding,
unsigned OptLevel,
unsigned count,
454 bool DebugPassManager) {
456 bool SingleModule = (ModuleMap.
size() == 1);
460 bool ClearDSOLocalOnDeclarations =
461 TM.getTargetTriple().isOSBinFormatELF() &&
466 promoteModule(TheModule,
Index, ClearDSOLocalOnDeclarations);
472 saveTempBitcode(TheModule, SaveTempsDir,
count,
".1.promoted.bc");
477 if (!ExportList.
empty() || !GUIDPreservedSymbols.
empty()) {
483 saveTempBitcode(TheModule, SaveTempsDir,
count,
".2.internalized.bc");
486 crossImportIntoModule(TheModule,
Index, ModuleMap, ImportList,
487 ClearDSOLocalOnDeclarations);
496 saveTempBitcode(TheModule, SaveTempsDir,
count,
".3.imported.bc");
498 optimizeModule(TheModule,
TM, OptLevel, Freestanding, DebugPassManager,
501 saveTempBitcode(TheModule, SaveTempsDir,
count,
".4.opt.bc");
503 if (DisableCodeGen) {
512 return std::make_unique<SmallVectorMemoryBuffer>(
516 return codegenModule(TheModule,
TM);
524static void resolvePrevailingInIndex(
526 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
533 const auto &Prevailing = PrevailingCopy.
find(GUID);
535 if (Prevailing == PrevailingCopy.
end())
537 return Prevailing->second == S;
540 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
543 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
549 GUIDPreservedSymbols);
554 const Triple &TheTriple) {
559 TMBuilder.
MCpu =
"core2";
561 TMBuilder.
MCpu =
"yonah";
564 TMBuilder.
MCpu =
"cyclone";
566 TMBuilder.
TheTriple = std::move(TheTriple);
577 toString(InputOrError.takeError()));
579 auto TripleStr = (*InputOrError)->getTargetTriple();
580 Triple TheTriple(TripleStr);
583 initTMBuilder(TMBuilder,
Triple(TheTriple));
584 else if (TMBuilder.
TheTriple != TheTriple) {
591 Modules.emplace_back(std::move(*InputOrError));
617 std::string FeatureStr = Features.
getString();
619 std::unique_ptr<TargetMachine>
TM(
622 assert(
TM &&
"Cannot create target machine");
632 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
633 std::make_unique<ModuleSummaryIndex>(
false);
635 for (
auto &
Mod : Modules) {
636 auto &M =
Mod->getSingleBitcodeModule();
638 M.readSummary(*CombinedIndex,
Mod->getName(), NextModuleId++)) {
641 std::move(Err),
errs(),
642 "error: can't create module summary index for buffer: ");
646 return CombinedIndex;
656 : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
659 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
660 return (ExportList != ExportLists.
end() && ExportList->second.
count(
VI)) ||
661 GUIDPreservedSymbols.
count(
VI.getGUID());
669 : PrevailingCopy(PrevailingCopy) {}
672 const auto &Prevailing = PrevailingCopy.
find(GUID);
674 if (Prevailing == PrevailingCopy.
end())
676 return Prevailing->second == S;
700 auto ModuleCount =
Index.modulePaths().size();
705 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
708 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
712 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
719 computePrevailingCopies(
Index, PrevailingCopy);
725 IsPrevailing(PrevailingCopy), ImportLists,
730 resolvePrevailingInIndex(
Index, ResolvedODR, GUIDPreservedSymbols,
734 ModuleToDefinedGVSummaries[ModuleIdentifier],
740 Index, IsExported(ExportLists, GUIDPreservedSymbols),
741 IsPrevailing(PrevailingCopy));
744 promoteModule(TheModule,
Index,
false);
753 auto ModuleMap = generateModuleMap(Modules);
754 auto ModuleCount =
Index.modulePaths().size();
758 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
761 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
764 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
771 computePrevailingCopies(
Index, PrevailingCopy);
777 IsPrevailing(PrevailingCopy), ImportLists,
782 crossImportIntoModule(TheModule,
Index, ModuleMap, ImportList,
791 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
793 auto ModuleCount =
Index.modulePaths().size();
798 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
801 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
804 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
811 computePrevailingCopies(
Index, PrevailingCopy);
817 IsPrevailing(PrevailingCopy), ImportLists,
821 ModuleIdentifier, ModuleToDefinedGVSummaries,
822 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
831 auto ModuleCount =
Index.modulePaths().size();
836 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
839 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
842 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
849 computePrevailingCopies(
Index, PrevailingCopy);
855 IsPrevailing(PrevailingCopy), ImportLists,
858 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
860 ModuleIdentifier, ModuleToDefinedGVSummaries,
861 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
865 ModuleToSummariesForIndex)))
867 " to save imports lists\n");
878 auto ModuleCount =
Index.modulePaths().size();
882 auto GUIDPreservedSymbols =
883 computeGUIDPreservedSymbols(File, PreservedSymbols, TMBuilder.
TheTriple);
885 addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
889 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
896 computePrevailingCopies(
Index, PrevailingCopy);
902 IsPrevailing(PrevailingCopy), ImportLists,
904 auto &ExportList = ExportLists[ModuleIdentifier];
908 if (ExportList.
empty() && GUIDPreservedSymbols.
empty())
913 resolvePrevailingInIndex(
Index, ResolvedODR, GUIDPreservedSymbols,
919 Index, IsExported(ExportLists, GUIDPreservedSymbols),
920 IsPrevailing(PrevailingCopy));
923 promoteModule(TheModule,
Index,
false);
927 ModuleToDefinedGVSummaries[ModuleIdentifier],
931 ModuleToDefinedGVSummaries[ModuleIdentifier]);
941 optimizeModule(TheModule, *TMBuilder.
create(), OptLevel, Freestanding,
942 DebugPassManager,
nullptr);
954 Twine(
count) +
"." + ArchName +
".thinlto.o");
960 if (!CacheEntryPath.
empty()) {
964 return std::string(OutputPath.
str());
968 return std::string(OutputPath.
str());
972 errs() <<
"remark: can't link or copy from cached entry '" << CacheEntryPath
973 <<
"' to '" << OutputPath <<
"'\n";
981 return std::string(OutputPath.
str());
992 assert(ProducedBinaries.empty() &&
"The generator should not be reused");
993 if (SavedObjectsDirectoryPath.empty())
994 ProducedBinaries.resize(Modules.size());
1001 ProducedBinaryFiles.resize(Modules.size());
1008 for (
auto &
Mod : Modules) {
1014 auto TheModule = loadModuleFromInput(
Mod.get(),
Context,
false,
1018 auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.
create());
1019 if (SavedObjectsDirectoryPath.empty())
1020 ProducedBinaries[
count] = std::move(OutputBuffer);
1022 ProducedBinaryFiles[
count] =
1034 if (!SaveTempsDir.
empty()) {
1035 auto SaveTempPath = SaveTempsDir +
"index.bc";
1040 " to save optimized bitcode\n");
1046 auto ModuleMap = generateModuleMap(Modules);
1047 auto ModuleCount = Modules.size();
1051 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1056 for (
const auto &M : Modules)
1057 computeGUIDPreservedSymbols(*M, PreservedSymbols, TMBuilder.
TheTriple,
1058 GUIDPreservedSymbols);
1061 for (
const auto &M : Modules)
1062 addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
1074 Index->setWithWholeProgramVisibility();
1084 std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
1085 std::set<GlobalValue::GUID> ExportedGUIDs;
1087 for (
auto GUID : ExportedGUIDs)
1088 GUIDPreservedSymbols.
insert(GUID);
1092 computePrevailingCopies(*
Index, PrevailingCopy);
1099 IsPrevailing(PrevailingCopy), ImportLists,
1110 resolvePrevailingInIndex(*
Index, ResolvedODR, GUIDPreservedSymbols,
1117 IsExported(ExportLists, GUIDPreservedSymbols),
1118 LocalWPDTargetsMap);
1120 *
Index, IsExported(ExportLists, GUIDPreservedSymbols),
1121 IsPrevailing(PrevailingCopy));
1128 for (
auto &
Module : Modules) {
1130 ExportLists[ModuleIdentifier];
1131 ImportLists[ModuleIdentifier];
1132 ResolvedODR[ModuleIdentifier];
1133 ModuleToDefinedGVSummaries[ModuleIdentifier];
1136 std::vector<BitcodeModule *> ModulesVec;
1137 ModulesVec.reserve(Modules.size());
1138 for (
auto &
Mod : Modules)
1139 ModulesVec.push_back(&
Mod->getSingleBitcodeModule());
1145 TimeTraceScopeExit.release();
1150 for (
auto IndexCount : ModulesOrdering) {
1151 auto &
Mod = Modules[IndexCount];
1153 auto ModuleIdentifier =
Mod->getName();
1154 auto &ExportList = ExportLists[ModuleIdentifier];
1156 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1159 ModuleCacheEntry CacheEntry(CacheOptions.
Path, *
Index, ModuleIdentifier,
1160 ImportLists[ModuleIdentifier], ExportList,
1161 ResolvedODR[ModuleIdentifier],
1162 DefinedGVSummaries, OptLevel, Freestanding,
1164 auto CacheEntryPath = CacheEntry.getEntryPath();
1167 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1169 <<
" '" << CacheEntryPath <<
"' for buffer "
1170 <<
count <<
" " << ModuleIdentifier <<
"\n");
1174 if (SavedObjectsDirectoryPath.empty())
1175 ProducedBinaries[
count] = std::move(ErrOrBuffer.get());
1178 count, CacheEntryPath, *ErrOrBuffer.get());
1189 if (!DiagFileOrErr) {
1190 errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
1196 auto TheModule = loadModuleFromInput(
Mod.get(),
Context,
false,
1200 saveTempBitcode(*TheModule, SaveTempsDir,
count,
".0.original.bc");
1202 auto &ImportList = ImportLists[ModuleIdentifier];
1204 auto OutputBuffer = ProcessThinLTOModule(
1205 *TheModule, *
Index, ModuleMap, *TMBuilder.
create(), ImportList,
1206 ExportList, GUIDPreservedSymbols,
1207 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1208 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel,
count,
1212 CacheEntry.write(*OutputBuffer);
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";
1229 OutputBuffer = std::move(*ReloadedBufferOrErr);
1232 ProducedBinaries[
count] = std::move(OutputBuffer);
1236 count, CacheEntryPath, *OutputBuffer);
This file provides a bitcode writing pass.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 ...
static const char * PreservedSymbols[]
This is the interface to build a ModuleSummaryIndex for a module.
CGSCCAnalysisManager CGAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
const char LLVMTargetMachineRef TM
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
This header defines classes/functions to handle pass execution timing information with interfaces for...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
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 computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
A container for analyses that lazily runs them and caches their results.
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
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.
virtual void print(DiagnosticPrinter &DP) const =0
Print using the given DP a user-friendly message.
Interface for custom diagnostic printing.
Base class for error info classes.
Represents either an error or a value T.
Lightweight error class with error context and mandatory checking.
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 function importer is automatically importing function from other modules based on the provided su...
Function and variable summary information to aid decisions and implementation of importing.
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
bool isWeakForLinker() const
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
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.
void enableDebugTypeODRUniquing()
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
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.
LLVMContext & getContext() const
Get the global data context.
StringRef getName() const
Get a short "name" for the module.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
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)
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
static const OptimizationLevel O0
Disable as many optimizations as possible.
static const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
This class provides access to building LLVM's passes.
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis 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< PassT, PassManager >::value > 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.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
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",...
iterator find(StringRef Key)
bool contains(StringRef Key) const
contains - Return true if the element is in the map, false otherwise.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
StringSet - A wrapper for StringMap that provides set-like functionality.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Manages the enabling and disabling of subtarget specific features.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
std::string getString() const
Returns features as a string.
Analysis pass providing the TargetLibraryInfo.
Implementation of the target library information.
Primary interface to the complete machine description for the target machine.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
void preserveSymbol(StringRef Name)
Adds to a list of all global symbols that must exist in the final generated code.
void run()
Process all the modules that were added to the code generator in parallel.
void crossReferenceSymbol(StringRef Name)
Adds to a list of all global symbols that are cross-referenced between ThinLTO files.
void addModule(StringRef Identifier, StringRef Data)
Add given module to the code generator.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
const std::string & str() const
std::string merge(const Triple &Other) const
Merge target triples.
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit).
StringRef getArchName() const
Get the architecture (first) component of the triple.
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
PassManager manages ModulePassManagers.
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
A raw_ostream that writes to a file descriptor.
A raw_ostream that writes to an SmallVector or SmallString.
void optimize(Module &Module)
Perform post-importing ThinLTO optimizations.
std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform cross-module importing for the module identified by ModuleIdentifier.
void emitImports(Module &Module, StringRef OutputName, ModuleSummaryIndex &Index, const lto::InputFile &File)
Compute and emit the imported files for module at ModulePath.
void gatherImportedSummariesForModule(Module &Module, ModuleSummaryIndex &Index, std::map< std::string, GVSummaryMapTy > &ModuleToSummariesForIndex, const lto::InputFile &File)
Compute the list of summaries needed for importing into module.
void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
void promote(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform promotion and renaming of exported internal functions, and additionally resolve weak and link...
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.
const CustomOperand< const MCSubtargetInfo & > Msg[]
initializer< Ty > init(const Ty &Val)
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
std::error_code closeFile(file_t &F)
Close the file object.
bool exists(const basic_file_status &status)
Does file exist?
@ OF_UpdateAtime
Force files Atime to be updated on access.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
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.
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
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.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
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.
llvm::Error writeFileAtomically(StringRef TempPathModel, StringRef FinalPath, StringRef Buffer)
Creates a unique file with name according to the given TempPathModel, writes content of Buffer to the...
ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)
Returns a thread strategy for tasks requiring significant memory or other resources.
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"))
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
cl::opt< bool > LTODiscardValueNames("lto-discard-value-names", cl::desc("Strip names from Value during LTO (other than GlobalValue)."), cl::init(false), cl::Hidden)
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.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
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...
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
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.
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
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.
void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, StringMap< FunctionImporter::ImportMapTy > &ImportLists, StringMap< FunctionImporter::ExportSetTy > &ExportLists)
Compute all the imports and exports for every module in the Index.
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.
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.
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
bool hasWholeProgramVisibility(bool WholeProgramVisibilityEnabledInLTO)
bool 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...
void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, ValueInfo)> isExported, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing)
Update the linkages in the given Index to mark exported values as external and non-exported values as...
void computeLTOCacheKey(SmallString< 40 > &Key, 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 std::set< GlobalValue::GUID > &CfiFunctionDefs={}, const std::set< GlobalValue::GUID > &CfiFunctionDecls={})
Computes a unique hash for the Module considering the current list of export/import and other global ...
void timeTraceProfilerBegin(StringRef Name, StringRef Detail)
Manually begin a time section, with the given Name and Detail.
void updatePublicTypeTestCalls(Module &M, bool WholeProgramVisibilityEnabledInLTO)
bool timeTraceProfilerEnabled()
Is the time trace profiler enabled, i.e. initialized?
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool AreStatisticsEnabled()
Check if statistics are enabled.
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
void computeSyntheticCounts(ModuleSummaryIndex &Index)
Compute synthetic function entry counts.
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"))
void updateIndexWPDForExports(ModuleSummaryIndex &Summary, function_ref< bool(StringRef, ValueInfo)> isExported, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap)
Call after cross-module importing to update the recorded single impl devirt target names for any loca...
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.
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
@ Mod
The access may modify the value stored in memory.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
void updateVCallVisibilityInIndex(ModuleSummaryIndex &Index, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols)
If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable def...
void runWholeProgramDevirtOnIndex(ModuleSummaryIndex &Summary, std::set< GlobalValue::GUID > &ExportedGUIDs, std::map< ValueInfo, std::vector< VTableSlotSummary > > &LocalWPDTargetsMap)
Perform index-based whole program devirtualization on the Summary index.
bool pruneCache(StringRef Path, CachePruningPolicy Policy, const std::vector< std::unique_ptr< MemoryBuffer > > &Files={})
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
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...
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.
Pass * createObjCARCContractPass()
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
void consumeError(Error Err)
Consume a Error without doing anything.
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.
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
void thinLTOFinalizeInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals, bool PropagateAttrs)
Based on the information recorded in the summaries during global summary-based analysis:
Helper to gather options relevant to the target machine creation.
std::unique_ptr< TargetMachine > create() const
std::optional< Reloc::Model > RelocModel
CodeGenOpt::Level CGOptLevel
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
CachePruningPolicy Policy
Struct that holds a reference to a particular GUID in a global value summary.
std::vector< std::string > MAttrs
CodeGenOpt::Level CGOptLevel
std::optional< Reloc::Model > RelocModel
bool Freestanding
Flag to indicate that the optimizer should not assume builtins are present on the target.