26 #include "llvm/Config/llvm-config.h" 63 #if !defined(_MSC_VER) && !defined(__MINGW32__) 71 #define DEBUG_TYPE "thinlto" 102 " to save optimized bitcode\n");
110 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
111 auto Linkage = Summary->linkage();
115 if (StrongDefForLinker != GVSummaryList.end())
116 return StrongDefForLinker->get();
120 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
121 auto Linkage = Summary->linkage();
125 if (FirstDefForLinker == GVSummaryList.end())
127 return FirstDefForLinker->get();
133 static void computePrevailingCopies(
137 return GVSummaryList.size() > 1;
141 if (HasMultipleCopies(
I.second.SummaryList))
142 PrevailingCopy[
I.first] =
143 getFirstDefinitionForLinker(
I.second.SummaryList);
148 generateModuleMap(
std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
150 for (
auto &M : Modules) {
152 "Expect unique Buffer Identifier");
153 ModuleMap[
M->getName()] =
M.get();
159 bool ClearDSOLocalOnDeclarations) {
168 ThinLTODiagnosticInfo(
const Twine &DiagMsg,
176 static void verifyLoadedModule(
Module &TheModule) {
177 bool BrokenDebugInfo =
false;
180 if (BrokenDebugInfo) {
182 "Invalid debug info found, debug info will be stripped",
DS_Warning));
187 static std::unique_ptr<Module> loadModuleFromInput(
lto::InputFile *Input,
201 Err.print(
"ThinLTO",
errs());
206 verifyLoadedModule(*ModuleOrErr.
get());
214 bool ClearDSOLocalOnDeclarations) {
217 return loadModuleFromInput(Input, TheModule.
getContext(),
227 Err.print(
"ThinLTO",
errs());
232 verifyLoadedModule(TheModule);
236 unsigned OptLevel,
bool Freestanding,
268 for (
const auto &Sym :
File.symbols()) {
281 for (
const auto &Sym :
File.symbols()) {
282 if (PreservedSymbols.
count(Sym.getName()) && !Sym.getIRName().empty())
291 const Triple &TheTriple) {
293 computeGUIDPreservedSymbols(
File, PreservedSymbols, TheTriple,
294 GUIDPreservedSymbols);
295 return GUIDPreservedSymbols;
298 std::unique_ptr<MemoryBuffer> codegenModule(
Module &TheModule,
319 return std::make_unique<SmallVectorMemoryBuffer>(
std::move(OutputBuffer));
323 class ModuleCacheEntry {
334 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
337 if (CachePath.
empty())
340 if (!
Index.modulePaths().count(ModuleID))
359 ResolvedODR, DefinedGVSummaries);
367 StringRef getEntryPath() {
return EntryPath; }
371 if (EntryPath.
empty())
372 return std::error_code();
379 *FDOrErr, EntryPath, -1,
false);
386 if (EntryPath.
empty())
399 std::string ErrorMsgBuffer;
405 errs() <<
"Error: " << ErrorMsgBuffer <<
"\n";
415 static std::unique_ptr<MemoryBuffer>
423 bool DisableCodeGen,
StringRef SaveTempsDir,
424 bool Freestanding,
unsigned OptLevel,
unsigned count) {
427 bool SingleModule = (ModuleMap.
size() == 1);
431 bool ClearDSOLocalOnDeclarations =
432 TM.getTargetTriple().isOSBinFormatELF() &&
437 promoteModule(TheModule,
Index, ClearDSOLocalOnDeclarations);
443 saveTempBitcode(TheModule, SaveTempsDir,
count,
".1.promoted.bc");
448 if (!ExportList.
empty() || !GUIDPreservedSymbols.
empty()) {
454 saveTempBitcode(TheModule, SaveTempsDir,
count,
".2.internalized.bc");
457 crossImportIntoModule(TheModule,
Index, ModuleMap, ImportList,
458 ClearDSOLocalOnDeclarations);
461 saveTempBitcode(TheModule, SaveTempsDir,
count,
".3.imported.bc");
464 optimizeModule(TheModule,
TM, OptLevel, Freestanding, &
Index);
466 saveTempBitcode(TheModule, SaveTempsDir,
count,
".4.opt.bc");
468 if (DisableCodeGen) {
477 return std::make_unique<SmallVectorMemoryBuffer>(
std::move(OutputBuffer));
480 return codegenModule(TheModule,
TM);
488 static void resolvePrevailingInIndex(
490 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
497 const auto &Prevailing = PrevailingCopy.
find(GUID);
499 if (Prevailing == PrevailingCopy.
end())
501 return Prevailing->second == S;
504 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
507 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
511 GUIDPreservedSymbols);
516 const Triple &TheTriple) {
521 TMBuilder.
MCpu =
"core2";
523 TMBuilder.
MCpu =
"yonah";
526 TMBuilder.
MCpu =
"cyclone";
539 toString(InputOrError.takeError()));
541 auto TripleStr = (*InputOrError)->getTargetTriple();
542 Triple TheTriple(TripleStr);
545 initTMBuilder(TMBuilder,
Triple(TheTriple));
546 else if (TMBuilder.
TheTriple != TheTriple) {
553 Modules.emplace_back(
std::move(*InputOrError));
579 std::string FeatureStr = Features.
getString();
581 std::unique_ptr<TargetMachine>
TM(
584 assert(
TM &&
"Cannot create target machine");
594 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
595 std::make_unique<ModuleSummaryIndex>(
false);
596 uint64_t NextModuleId = 0;
597 for (
auto &
Mod : Modules) {
598 auto &M =
Mod->getSingleBitcodeModule();
600 M.readSummary(*CombinedIndex,
Mod->getName(), NextModuleId++)) {
604 "error: can't create module summary index for buffer: ");
608 return CombinedIndex;
618 : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
621 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
622 return (ExportList != ExportLists.
end() && ExportList->second.
count(
VI)) ||
623 GUIDPreservedSymbols.
count(
VI.getGUID());
627 struct IsPrevailing {
631 : PrevailingCopy(PrevailingCopy) {}
634 const auto &Prevailing = PrevailingCopy.
find(GUID);
636 if (Prevailing == PrevailingCopy.
end())
638 return Prevailing->second == S;
662 auto ModuleCount =
Index.modulePaths().size();
667 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
670 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
674 addUsedSymbolToPreservedGUID(
File, GUIDPreservedSymbols);
686 computePrevailingCopies(
Index, PrevailingCopy);
690 resolvePrevailingInIndex(
Index, ResolvedODR, GUIDPreservedSymbols,
694 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
699 Index, IsExported(ExportLists, GUIDPreservedSymbols),
700 IsPrevailing(PrevailingCopy));
703 promoteModule(TheModule,
Index,
false);
712 auto ModuleMap = generateModuleMap(Modules);
713 auto ModuleCount =
Index.modulePaths().size();
717 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
720 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
723 addUsedSymbolToPreservedGUID(
File, GUIDPreservedSymbols);
736 crossImportIntoModule(TheModule,
Index, ModuleMap, ImportList,
745 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
747 auto ModuleCount =
Index.modulePaths().size();
752 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
755 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
758 addUsedSymbolToPreservedGUID(
File, GUIDPreservedSymbols);
770 ModuleIdentifier, ModuleToDefinedGVSummaries,
771 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
780 auto ModuleCount =
Index.modulePaths().size();
785 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
788 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
791 addUsedSymbolToPreservedGUID(
File, GUIDPreservedSymbols);
802 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
804 ModuleIdentifier, ModuleToDefinedGVSummaries,
805 ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
809 ModuleToSummariesForIndex)))
811 " to save imports lists\n");
822 auto ModuleCount =
Index.modulePaths().size();
826 auto GUIDPreservedSymbols =
827 computeGUIDPreservedSymbols(
File, PreservedSymbols, TMBuilder.
TheTriple);
829 addUsedSymbolToPreservedGUID(
File, GUIDPreservedSymbols);
833 Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
843 auto &ExportList = ExportLists[ModuleIdentifier];
847 if (ExportList.
empty() && GUIDPreservedSymbols.
empty())
851 computePrevailingCopies(
Index, PrevailingCopy);
855 resolvePrevailingInIndex(
Index, ResolvedODR, GUIDPreservedSymbols,
861 Index, IsExported(ExportLists, GUIDPreservedSymbols),
862 IsPrevailing(PrevailingCopy));
865 promoteModule(TheModule,
Index,
false);
869 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
872 ModuleToDefinedGVSummaries[ModuleIdentifier]);
882 optimizeModule(TheModule, *TMBuilder.
create(), OptLevel, Freestanding,
895 Twine(
count) +
"." + ArchName +
".thinlto.o");
901 if (!CacheEntryPath.
empty()) {
905 return std::string(OutputPath.
str());
909 return std::string(OutputPath.
str());
913 errs() <<
"remark: can't link or copy from cached entry '" << CacheEntryPath
914 <<
"' to '" << OutputPath <<
"'\n";
922 return std::string(OutputPath.
str());
928 assert(ProducedBinaries.empty() &&
"The generator should not be reused");
929 if (SavedObjectsDirectoryPath.empty())
930 ProducedBinaries.resize(Modules.size());
937 ProducedBinaryFiles.resize(Modules.size());
944 for (
auto &
Mod : Modules) {
950 auto TheModule = loadModuleFromInput(
Mod.get(),
Context,
false,
954 auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.
create());
955 if (SavedObjectsDirectoryPath.empty())
958 ProducedBinaryFiles[
count] =
970 if (!SaveTempsDir.
empty()) {
971 auto SaveTempPath = SaveTempsDir +
"index.bc";
976 " to save optimized bitcode\n");
982 auto ModuleMap = generateModuleMap(Modules);
983 auto ModuleCount = Modules.size();
987 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
992 for (
const auto &M : Modules)
993 computeGUIDPreservedSymbols(*M, PreservedSymbols, TMBuilder.
TheTriple,
994 GUIDPreservedSymbols);
997 for (
const auto &M : Modules)
998 addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
1015 std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
1016 std::set<GlobalValue::GUID> ExportedGUIDs;
1018 for (
auto GUID : ExportedGUIDs)
1019 GUIDPreservedSymbols.
insert(GUID);
1035 computePrevailingCopies(*
Index, PrevailingCopy);
1039 resolvePrevailingInIndex(*
Index, ResolvedODR, GUIDPreservedSymbols,
1046 IsExported(ExportLists, GUIDPreservedSymbols),
1047 LocalWPDTargetsMap);
1049 *
Index, IsExported(ExportLists, GUIDPreservedSymbols),
1050 IsPrevailing(PrevailingCopy));
1055 for (
auto &
Module : Modules) {
1057 ExportLists[ModuleIdentifier];
1058 ImportLists[ModuleIdentifier];
1059 ResolvedODR[ModuleIdentifier];
1060 ModuleToDefinedGVSummaries[ModuleIdentifier];
1063 std::vector<BitcodeModule *> ModulesVec;
1064 ModulesVec.reserve(Modules.
size());
1065 for (
auto &
Mod : Modules)
1066 ModulesVec.push_back(&
Mod->getSingleBitcodeModule());
1072 for (
auto IndexCount : ModulesOrdering) {
1073 auto &
Mod = Modules[IndexCount];
1075 auto ModuleIdentifier =
Mod->getName();
1076 auto &ExportList = ExportLists[ModuleIdentifier];
1078 auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1081 ModuleCacheEntry CacheEntry(CacheOptions.
Path, *
Index, ModuleIdentifier,
1082 ImportLists[ModuleIdentifier], ExportList,
1083 ResolvedODR[ModuleIdentifier],
1084 DefinedGVSummaries, OptLevel, Freestanding,
1086 auto CacheEntryPath = CacheEntry.getEntryPath();
1089 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1091 <<
" '" << CacheEntryPath <<
"' for buffer " 1092 <<
count <<
" " << ModuleIdentifier <<
"\n");
1096 if (SavedObjectsDirectoryPath.empty())
1100 count, CacheEntryPath, *ErrOrBuffer.get());
1111 if (!DiagFileOrErr) {
1112 errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
1118 auto TheModule = loadModuleFromInput(
Mod.get(),
Context,
false,
1122 saveTempBitcode(*TheModule, SaveTempsDir,
count,
".0.original.bc");
1124 auto &ImportList = ImportLists[ModuleIdentifier];
1126 auto OutputBuffer = ProcessThinLTOModule(
1127 *TheModule, *
Index, ModuleMap, *TMBuilder.
create(), ImportList,
1128 ExportList, GUIDPreservedSymbols,
1129 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1130 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel,
count);
1133 CacheEntry.write(*OutputBuffer);
1135 if (SavedObjectsDirectoryPath.empty()) {
1137 if (!CacheEntryPath.empty()) {
1144 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1145 if (
auto EC = ReloadedBufferOrErr.getError()) {
1147 errs() <<
"remark: can't reload cached file '" << CacheEntryPath
1148 <<
"': " << EC.message() <<
"\n";
1150 OutputBuffer =
std::move(*ReloadedBufferOrErr);
1157 count, CacheEntryPath, *OutputBuffer);
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
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.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Represents either an error or a value T.
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
void thinLTOResolvePrevailingInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve prevailing symbol linkages in TheModule based on the information recorded in the summaries du...
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 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...
CodeGenOpt::Level CGOptLevel
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
StringRef getBuffer() const
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
CodeGenOpt::Level CGOptLevel
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
A Module instance is used to store all the information related to an LLVM module.
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM=None, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
LLVM_NODISCARD bool empty() const
This is the interface to build a ModuleSummaryIndex for a module.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
This file provides a bitcode writing pass.
Implements a dense probed hash-table based set.
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
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.
Analysis providing profile information.
void enableDebugTypeODRUniquing()
void disableAllFunctions()
Disables all builtins.
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
std::string getString() const
Returns features as a string.
iterator find(StringRef Key)
Externally visible function.
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
A raw_ostream that writes to an SmallVector or SmallString.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Implementation of the target library information.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
StringRef getName() const
Get a short "name" for the module.
Error takeError()
Take ownership of the stored error.
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
void addModule(StringRef Identifier, StringRef Data)
Add given module to the code generator.
Base class for error info classes.
std::shared_future< void > async(Function &&F, Args &&... ArgList)
Asynchronous submission of a task to the pool.
Pass * Inliner
Inliner - Specifies the inliner to use.
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform cross-module importing for the module identified by ModuleIdentifier.
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 append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::vector< std::string > MAttrs
LLVMContext & getContext() const
Get the global data context.
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...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
void emitImports(Module &Module, StringRef OutputName, ModuleSummaryIndex &Index, const lto::InputFile &File)
Compute and emit the imported files for module at ModulePath.
Tagged union holding either a T or a Error.
Interface for custom diagnostic printing.
This header defines classes/functions to handle pass execution timing information with interfaces for...
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
std::string writeGeneratedObject(int count, StringRef CacheEntryPath, const MemoryBuffer &OutputBuffer)
Write temporary object file to SavedObjectDirectoryPath, write symlink to Cache directory if needed.
StringRef str() const
Explicit conversion to StringRef.
void run()
Process all the modules that were added to the code generator in parallel.
void updateVCallVisibilityInIndex(ModuleSummaryIndex &Index, bool WholeProgramVisibilityEnabledInLTO)
If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable def...
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Pass * createObjCARCContractPass()
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
const std::string & str() const
iterator find(const_arg_type_t< KeyT > Val)
PassManager manages ModulePassManagers.
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
void crossReferenceSymbol(StringRef Name)
Adds to a list of all global symbols that are cross-referenced between ThinLTO files.
initializer< Ty > init(const Ty &Val)
This is the base abstract class for diagnostic reporting in the backend.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
parseOptionalThreadLocal := /*empty
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.
void optimize(Module &Module)
Perform post-importing ThinLTO optimizations.
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
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.
This is an important class for using LLVM in a threaded context.
Instrumentation for Order File
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Helper to gather options relevant to the target machine creation.
void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
std::pair< iterator, bool > insert(const ValueT &V)
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
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< 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)
bool isWeakForLinker() const
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...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
void thinLTOResolvePrevailingInIndex(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.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
Function and variable summary information to aid decisions and implementation of importing.
static void write(bool isBE, void *P, T V)
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 consumeError(Error Err)
Consume a Error without doing anything.
bool pruneCache(StringRef Path, CachePruningPolicy Policy)
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Force files Atime to be updated on access. Only makes a difference on windows.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Triple - Helper class for working with autoconf configuration names.
Struct that holds a reference to a particular GUID in a global value summary.
void computeSyntheticCounts(ModuleSummaryIndex &Index)
Compute synthetic function entry counts.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
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 ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Optional< Reloc::Model > RelocModel
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.
reference get()
Returns a reference to the stored T value.
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, Optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
std::error_code closeFile(file_t &F)
Close the file object.
std::string merge(const Triple &Other) const
Merge target triples.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Target - Wrapper for Target specific information.
Manages the enabling and disabling of subtarget specific features.
void promote(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform promotion and renaming of exported internal functions, and additionally resolve weak and link...
LinkageTypes
An enumeration for the kinds of linkage for global values.
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 add(Pass *P) override
Add a pass to the queue of passes to run.
std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
static void computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
std::unique_ptr< TargetMachine > create() const
void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, StringMap< FunctionImporter::ImportMapTy > &ImportLists, StringMap< FunctionImporter::ExportSetTy > &ExportLists)
Compute all the imports and exports for every module in the Index.
cl::opt< bool > LTODiscardValueNames("lto-discard-value-names", cl::desc("Strip names from Value during LTO (other than GlobalValue)."), cl::init(false), cl::Hidden)
A raw_ostream that writes to a file descriptor.
Linkage
Describes symbol linkage.
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
void preserveSymbol(StringRef Name)
Adds to a list of all global symbols that must exist in the final generated code.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
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...
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.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
Optional< Reloc::Model > RelocModel
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
A raw_ostream that writes to an std::string.
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"))
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
The function importer is automatically importing function from other modules based on the provided su...
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Lightweight error class with error context and mandatory checking.
StringSet - A wrapper for StringMap that provides set-like functionality.
CachePruningPolicy Policy
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Primary interface to the complete machine description for the target machine.
This file implements a simple parser to decode commandline option for remarks hotness threshold that ...
ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)
Returns a thread strategy for tasks requiring significant memory or other resources.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
StringRef - Represent a constant reference to a string, i.e.
bool Freestanding
Flag to indicate that the optimizer should not assume builtins are present on the target.
bool exists(const basic_file_status &status)
Does file exist?
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool AreStatisticsEnabled()
Check if statistics are enabled.
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...