46 #include "llvm/Support/VCSRevision.h"
59 #define DEBUG_TYPE "thinlto"
80 std::string SaveTempPath = (TempDir +
llvm::utostr(count) + Suffix).str();
85 " to save optimized bitcode\n");
93 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
94 auto Linkage = Summary->linkage();
98 if (StrongDefForLinker != GVSummaryList.end())
99 return StrongDefForLinker->get();
103 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
104 auto Linkage = Summary->linkage();
108 if (FirstDefForLinker == GVSummaryList.end())
110 return FirstDefForLinker->get();
116 static void computePrevailingCopies(
120 return GVSummaryList.size() > 1;
123 for (
auto &
I : Index) {
124 if (HasMultipleCopies(
I.second.SummaryList))
125 PrevailingCopy[
I.first] =
126 getFirstDefinitionForLinker(
I.second.SummaryList);
131 generateModuleMap(
const std::vector<ThinLTOBuffer> &Modules) {
133 for (
auto &ModuleBuffer : Modules) {
134 assert(ModuleMap.
find(ModuleBuffer.getBufferIdentifier()) ==
136 "Expect unique Buffer Identifier");
137 ModuleMap[ModuleBuffer.getBufferIdentifier()] = ModuleBuffer.getMemBuffer();
151 ThinLTODiagnosticInfo(
const Twine &DiagMsg,
159 static void verifyLoadedModule(
Module &TheModule) {
160 bool BrokenDebugInfo =
false;
164 if (BrokenDebugInfo) {
166 "Invalid debug info found, debug info will be stripped",
DS_Warning));
171 static std::unique_ptr<Module>
173 bool Lazy,
bool IsImporting) {
189 verifyLoadedModule(*ModuleOrErr.
get());
190 return std::move(ModuleOrErr.
get());
203 Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
213 verifyLoadedModule(TheModule);
217 unsigned OptLevel,
bool Freestanding) {
246 computeGUIDPreservedSymbols(
const StringSet<> &PreservedSymbols,
247 const Triple &TheTriple) {
249 for (
auto &Entry : PreservedSymbols) {
255 return GUIDPreservedSymbols;
258 std::unique_ptr<MemoryBuffer> codegenModule(
Module &TheModule,
279 return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer));
283 class ModuleCacheEntry {
294 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
298 if (CachePath.
empty())
324 auto AddUnsigned = [&](
unsigned I) {
334 Hasher.
update(LLVM_VERSION_STRING);
336 Hasher.
update(LLVM_REVISION);
340 AddString(TMBuilder.
MCpu);
349 AddString(TMBuilder.
MAttr);
353 AddUnsigned(OptLevel);
354 AddUnsigned(Freestanding);
357 for (
auto F : ExportList)
362 for (
auto &Entry : ImportList) {
368 for (
auto &Entry : ResolvedODR) {
376 for (
auto &Entry : PreservedSymbols) {
377 if (DefinedFunctions.
count(Entry))
389 StringRef getEntryPath() {
return EntryPath; }
393 if (EntryPath.empty())
394 return std::error_code();
400 if (EntryPath.empty())
409 errs() <<
"Error: " << EC.message() <<
"\n";
423 " to save cached entry\n");
429 static std::unique_ptr<MemoryBuffer>
437 bool DisableCodeGen,
StringRef SaveTempsDir,
438 bool Freestanding,
unsigned OptLevel,
unsigned count) {
441 bool SingleModule = (ModuleMap.
size() == 1);
444 promoteModule(TheModule, Index);
450 saveTempBitcode(TheModule, SaveTempsDir, count,
".1.promoted.bc");
455 if (!ExportList.empty() || !GUIDPreservedSymbols.
empty()) {
461 saveTempBitcode(TheModule, SaveTempsDir, count,
".2.internalized.bc");
464 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
467 saveTempBitcode(TheModule, SaveTempsDir, count,
".3.imported.bc");
470 optimizeModule(TheModule, TM, OptLevel, Freestanding);
472 saveTempBitcode(TheModule, SaveTempsDir, count,
".4.opt.bc");
474 if (DisableCodeGen) {
483 return make_unique<ObjectMemoryBuffer>(std::move(OutputBuffer));
486 return codegenModule(TheModule, TM);
494 static void resolveWeakForLinkerInIndex(
496 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
500 computePrevailingCopies(Index, PrevailingCopy);
503 const auto &Prevailing = PrevailingCopy.
find(GUID);
505 if (Prevailing == PrevailingCopy.
end())
507 return Prevailing->second == S;
510 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
513 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
521 const Triple &TheTriple) {
526 TMBuilder.
MCpu =
"core2";
528 TMBuilder.
MCpu =
"yonah";
530 TMBuilder.
MCpu =
"cyclone";
532 TMBuilder.
TheTriple = std::move(TheTriple);
545 TripleStr = *TripleOrErr;
547 Triple TheTriple(TripleStr);
550 initTMBuilder(TMBuilder,
Triple(TheTriple));
551 else if (TMBuilder.
TheTriple != TheTriple) {
558 Modules.push_back(Buffer);
562 PreservedSymbols.insert(Name);
569 PreservedSymbols.insert(Name);
584 std::string FeatureStr = Features.
getString();
596 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
597 llvm::make_unique<ModuleSummaryIndex>();
598 uint64_t NextModuleId = 0;
599 for (
auto &ModuleBuffer : Modules) {
601 *CombinedIndex, NextModuleId++)) {
604 std::move(Err),
errs(),
605 "error: can't create module summary index for buffer: ");
609 return CombinedIndex;
626 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
640 resolveWeakForLinkerInIndex(Index, ResolvedODR);
643 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
648 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
649 return (ExportList != ExportLists.
end() &&
650 ExportList->second.count(GUID)) ||
651 GUIDPreservedSymbols.
count(GUID);
655 promoteModule(TheModule, Index);
663 auto ModuleMap = generateModuleMap(Modules);
671 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
684 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
692 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
706 ImportLists[ModulePath],
707 ModuleToSummariesForIndex);
729 if ((EC =
EmitImportsFiles(ModulePath, OutputName, ImportLists[ModulePath])))
731 " to save imports lists\n");
744 auto GUIDPreservedSymbols =
745 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.
TheTriple);
759 auto &ExportList = ExportLists[ModuleIdentifier];
763 if (ExportList.empty() && GUIDPreservedSymbols.
empty())
768 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
769 return (ExportList != ExportLists.
end() &&
770 ExportList->second.count(GUID)) ||
771 GUIDPreservedSymbols.
count(GUID);
775 ModuleToDefinedGVSummaries[ModuleIdentifier]);
785 optimizeModule(TheModule, *TMBuilder.
create(), OptLevel, Freestanding);
793 return codegenModule(TheModule, *TMBuilder.
create());
809 if (!CacheEntryPath.
empty()) {
813 return OutputPath.
str();
817 return OutputPath.
str();
821 errs() <<
"error: can't link or copy from cached entry '" << CacheEntryPath
822 <<
"' to '" << OutputPath <<
"'\n";
830 return OutputPath.
str();
836 assert(ProducedBinaries.empty() &&
"The generator should not be reused");
837 if (SavedObjectsDirectoryPath.empty())
838 ProducedBinaries.resize(Modules.size());
845 ProducedBinaryFiles.resize(Modules.size());
852 for (
auto &ModuleBuffer : Modules) {
853 Pool.
async([&](
int count) {
859 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(),
Context,
false,
863 auto OutputBuffer =
codegen(*TheModule);
864 if (SavedObjectsDirectoryPath.empty())
865 ProducedBinaries[count] = std::move(OutputBuffer);
868 count,
"", SavedObjectsDirectoryPath, *OutputBuffer);
879 if (!SaveTempsDir.
empty()) {
880 auto SaveTempPath = SaveTempsDir +
"index.bc";
885 " to save optimized bitcode\n");
891 auto ModuleMap = generateModuleMap(Modules);
892 auto ModuleCount = Modules.size();
900 auto GUIDPreservedSymbols =
901 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.
TheTriple);
921 resolveWeakForLinkerInIndex(*Index, ResolvedODR);
924 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
925 return (ExportList != ExportLists.
end() &&
926 ExportList->second.count(GUID)) ||
927 GUIDPreservedSymbols.
count(GUID);
937 for (
auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
938 ExportLists[DefinedGVSummaries.first()];
939 ResolvedODR[DefinedGVSummaries.first()];
945 std::vector<int> ModulesOrdering;
946 ModulesOrdering.resize(Modules.size());
947 std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
948 std::sort(ModulesOrdering.begin(), ModulesOrdering.end(),
949 [&](
int LeftIndex,
int RightIndex) {
950 auto LSize = Modules[LeftIndex].getBuffer().size();
951 auto RSize = Modules[RightIndex].getBuffer().size();
952 return LSize > RSize;
958 for (
auto IndexCount : ModulesOrdering) {
959 auto &ModuleBuffer = Modules[IndexCount];
960 Pool.
async([&](
int count) {
961 auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier();
962 auto &ExportList = ExportLists[ModuleIdentifier];
964 auto &DefinedFunctions = ModuleToDefinedGVSummaries[ModuleIdentifier];
967 ModuleCacheEntry CacheEntry(CacheOptions.
Path, *Index, ModuleIdentifier,
968 ImportLists[ModuleIdentifier], ExportList,
969 ResolvedODR[ModuleIdentifier],
970 DefinedFunctions, GUIDPreservedSymbols,
971 OptLevel, Freestanding, TMBuilder);
972 auto CacheEntryPath = CacheEntry.getEntryPath();
975 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
976 DEBUG(
dbgs() <<
"Cache " << (ErrOrBuffer ?
"hit" :
"miss") <<
" '"
977 << CacheEntryPath <<
"' for buffer " << count <<
" "
978 << ModuleIdentifier <<
"\n");
982 if (SavedObjectsDirectoryPath.empty())
983 ProducedBinaries[count] = std::move(ErrOrBuffer.get());
986 count, CacheEntryPath, SavedObjectsDirectoryPath,
997 if (!DiagFileOrErr) {
998 errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
1005 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(),
Context,
false,
1009 saveTempBitcode(*TheModule, SaveTempsDir, count,
".0.original.bc");
1011 auto &ImportList = ImportLists[ModuleIdentifier];
1013 auto OutputBuffer = ProcessThinLTOModule(
1014 *TheModule, *Index, ModuleMap, *TMBuilder.
create(), ImportList,
1015 ExportList, GUIDPreservedSymbols,
1016 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1017 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel,
count);
1020 CacheEntry.write(*OutputBuffer);
1022 if (SavedObjectsDirectoryPath.empty()) {
1024 if (!CacheEntryPath.empty()) {
1030 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1031 if (
auto EC = ReloadedBufferOrErr.getError()) {
1034 errs() <<
"error: can't reload cached file '" << CacheEntryPath
1035 <<
"': " << EC.message() <<
"\n";
1037 OutputBuffer = std::move(*ReloadedBufferOrErr);
1040 ProducedBinaries[
count] = std::move(OutputBuffer);
1044 count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
void computeDeadSymbols(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Compute all the symbols that are "dead": i.e these that can't be reached in the graph from any of t...
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.
Represents either an error or a value T.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
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.
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
CodeGenOpt::Level CGOptLevel
void promote(Module &Module, ModuleSummaryIndex &Index)
Perform promotion and renaming of exported internal functions, and additionally resolve weak and link...
cl::opt< std::string > LTORemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
unsigned heavyweight_hardware_concurrency()
Get the amount of currency to use for tasks requiring significant memory or other resources...
A Module instance is used to store all the information related to an LLVM module. ...
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner)
Log all errors (if any) in E to OS.
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)
unsigned DataSections
Emit data into separate sections.
std::unique_ptr< TargetMachine > create() const
Analysis providing profile information.
void enableDebugTypeODRUniquing()
void disableAllFunctions()
Disables all builtins.
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
iterator find(StringRef Key)
StringRef getBuffer() const
A raw_ostream that writes to an SmallVector or SmallString.
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...
const std::string & str() const
A class that wrap the SHA1 algorithm.
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.
void addModule(StringRef Identifier, StringRef Data)
Add given module to the code generator.
Base class for error info classes.
void reportAndResetTimings()
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Pass * Inliner
Inliner - Specifies the inliner to use.
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
Wrapper around MemoryBufferRef, owning the identifier.
std::shared_future< void > async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
const Triple & getTargetTriple() const
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
std::unordered_set< GlobalValue::GUID > ExportSetTy
The set contains an entry for every global value the module exports.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
void add(Pass *P) override
Add a pass to the queue of passes to run.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
std::unique_ptr< MemoryBuffer > codegen(Module &Module)
Perform ThinLTO CodeGen.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
cl::opt< bool > LTOStripInvalidDebugInfo("lto-strip-invalid-debug-info", cl::desc("Strip invalid debug info metadata during LTO instead of aborting."), cl::init(false), cl::Hidden)
MemoryBufferRef getMemBuffer() const
Tagged union holding either a T or a Error.
Interface for custom diagnostic printing.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
StringRef result()
Return a reference to the current raw 160-bits SHA1 for the digested data since the last call to init...
std::vector< std::unique_ptr< GlobalValueSummary >> GlobalValueSummaryList
void run()
Process all the modules that were added to the code generator in parallel.
cl::opt< bool > LTOPassRemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
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.
const StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths() const
Table of modules, containing module hash and id.
unsigned FunctionSections
Emit functions into separate sections.
static std::string utostr(uint64_t X, bool isNeg=false)
A ThreadPool for asynchronous parallel execution on a defined number of threads.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
void update(ArrayRef< uint8_t > Data)
Digest more data.
bool isWeakForLinker() const
iterator find(const_arg_type_t< KeyT > Val)
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, CodeGenFileType, bool=true, AnalysisID=nullptr, AnalysisID=nullptr, AnalysisID=nullptr, AnalysisID=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
PassManager manages ModulePassManagers.
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
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.
DebuggerKind DebuggerTuning
Which debugger to tune for.
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.
This is an important class for using LLVM in a threaded context.
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Helper to gather options relevant to the target machine creation.
virtual TargetIRAnalysis getTargetIRAnalysis()
Get a TargetIRAnalysis appropriate for the target.
Expected< std::unique_ptr< tool_output_file > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex, uint64_t ModuleId)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
void handleAllErrors(Error E, HandlerTs &&...Handlers)
Behaves the same as handleErrors, except that it requires that all errors be handled by the given han...
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)
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
bool pruneCache(StringRef Path, CachePruningPolicy Policy)
Peform pruning using the supplied policy, returns true if pruning occured, i.e.
std::string getString() const
Returns features as a string.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
bool is_directory(file_status status)
Does status represent a directory?
Triple - Helper class for working with autoconf configuration names.
static std::string writeGeneratedObject(int count, StringRef CacheEntryPath, StringRef SavedObjectsDirectoryPath, const MemoryBuffer &OutputBuffer)
Write out the generated object file, either from CacheEntryPath or from OutputBuffer, preferring hard-link when possible.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, CodeModel::Model CM=CodeModel::Default, CodeGenOpt::Level OL=CodeGenOpt::Default) const
createTargetMachine - Create a target specific machine implementation for the specified Triple...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
reference get()
Returns a reference to the stored T value.
std::error_code EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const FunctionImporter::ImportMapTy &ModuleImports)
Emit into OutputFilename the files module ModulePath will import from.
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.
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.
StringRef str() const
Explicit conversion to StringRef.
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 collectDefinedGVSummariesPerModule(StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
std::string toHex(StringRef Input)
Convert buffer Input to its hexadecimal representation.
std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
unsigned RelaxELFRelocations
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
static void gatherImportedSummariesForModule(StringRef ModulePath, ModuleSummaryIndex &Index, std::map< std::string, GVSummaryMapTy > &ModuleToSummariesForIndex)
Compute the list of summaries needed for importing into module.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
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)
ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)
A raw_ostream that writes to a file descriptor.
void thinLTOResolveWeakForLinkerInIndex(ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage)
Resolve Weak and LinkOnce values in the Index.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
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.
void thinLTOResolveWeakForLinkerModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve WeakForLinker values in TheModule based on the information recorded in the summaries during g...
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index)
Perform cross-module importing for the module identified by ModuleIdentifier.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
Optional< Reloc::Model > RelocModel
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef getBufferIdentifier() const
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
void internalize(Module &Module, ModuleSummaryIndex &Index)
Perform internalization.
bool renameModuleForThinLTO(Module &M, const ModuleSummaryIndex &Index, SetVector< GlobalValue * > *GlobalsToImport=nullptr)
Perform in-place global value handling on the given Module for exported local functions renamed and p...
The function importer is automatically importing function from other modules based on the provided su...
Lightweight error class with error context and mandatory checking.
const FeatureBitset Features
StringSet - A wrapper for StringMap that provides set-like functionality.
CachePruningPolicy Policy
Primary interface to the complete machine description for the target machine.
static void emitImports(StringRef ModulePath, StringRef OutputName, ModuleSummaryIndex &Index)
Compute and emit the imported files for module at ModulePath.
StringRef - Represent a constant reference to a string, i.e.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
bool exists(file_status status)
Does file exist?
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
std::string merge(const Triple &Other) const
Merge target triples.
bool AreStatisticsEnabled()
Check if statistics are enabled.
void thinLTOInternalizeAndPromoteInIndex(ModuleSummaryIndex &Index, function_ref< bool(StringRef, GlobalValue::GUID)> isExported)
Update the linkages in the given Index to mark exported values as external and non-exported values as...
LLVMContext & getContext() const
Get the global data context.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...