26 #include "llvm/Config/llvm-config.h" 47 #include "llvm/Support/VCSRevision.h" 58 #if !defined(_MSC_VER) && !defined(__MINGW32__) 66 #define DEBUG_TYPE "thinlto" 86 std::string SaveTempPath = (TempDir +
llvm::Twine(count) + Suffix).str();
91 " to save optimized bitcode\n");
99 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
100 auto Linkage = Summary->linkage();
104 if (StrongDefForLinker != GVSummaryList.end())
105 return StrongDefForLinker->get();
109 GVSummaryList, [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
110 auto Linkage = Summary->linkage();
114 if (FirstDefForLinker == GVSummaryList.end())
116 return FirstDefForLinker->get();
122 static void computePrevailingCopies(
126 return GVSummaryList.size() > 1;
129 for (
auto &
I : Index) {
130 if (HasMultipleCopies(
I.second.SummaryList))
131 PrevailingCopy[
I.first] =
132 getFirstDefinitionForLinker(
I.second.SummaryList);
137 generateModuleMap(
const std::vector<ThinLTOBuffer> &Modules) {
139 for (
auto &ModuleBuffer : Modules) {
140 assert(ModuleMap.
find(ModuleBuffer.getBufferIdentifier()) ==
142 "Expect unique Buffer Identifier");
143 ModuleMap[ModuleBuffer.getBufferIdentifier()] = ModuleBuffer.getMemBuffer();
157 ThinLTODiagnosticInfo(
const Twine &DiagMsg,
165 static void verifyLoadedModule(
Module &TheModule) {
166 bool BrokenDebugInfo =
false;
169 if (BrokenDebugInfo) {
171 "Invalid debug info found, debug info will be stripped",
DS_Warning));
176 static std::unique_ptr<Module>
178 bool Lazy,
bool IsImporting) {
194 verifyLoadedModule(*ModuleOrErr.
get());
195 return std::move(ModuleOrErr.
get());
218 verifyLoadedModule(TheModule);
222 unsigned OptLevel,
bool Freestanding) {
251 computeGUIDPreservedSymbols(
const StringSet<> &PreservedSymbols,
252 const Triple &TheTriple) {
254 for (
auto &Entry : PreservedSymbols) {
260 return GUIDPreservedSymbols;
263 std::unique_ptr<MemoryBuffer> codegenModule(
Module &TheModule,
284 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
288 class ModuleCacheEntry {
299 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
303 if (CachePath.
empty())
329 auto AddUnsigned = [&](
unsigned I) {
339 Hasher.
update(LLVM_VERSION_STRING);
341 Hasher.
update(LLVM_REVISION);
345 AddString(TMBuilder.
MCpu);
354 AddString(TMBuilder.
MAttr);
358 AddUnsigned(OptLevel);
359 AddUnsigned(Freestanding);
362 for (
auto F : ExportList)
367 for (
auto &Entry : ImportList) {
373 for (
auto &Entry : ResolvedODR) {
381 for (
auto &Entry : PreservedSymbols) {
382 if (DefinedFunctions.
count(Entry))
394 StringRef getEntryPath() {
return EntryPath; }
398 if (EntryPath.empty())
399 return std::error_code();
416 if (EntryPath.empty())
428 errs() <<
"Error: " << EC.message() <<
"\n";
442 static std::unique_ptr<MemoryBuffer>
450 bool DisableCodeGen,
StringRef SaveTempsDir,
451 bool Freestanding,
unsigned OptLevel,
unsigned count) {
454 bool SingleModule = (ModuleMap.
size() == 1);
457 promoteModule(TheModule, Index);
463 saveTempBitcode(TheModule, SaveTempsDir, count,
".1.promoted.bc");
468 if (!ExportList.empty() || !GUIDPreservedSymbols.
empty()) {
474 saveTempBitcode(TheModule, SaveTempsDir, count,
".2.internalized.bc");
477 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
480 saveTempBitcode(TheModule, SaveTempsDir, count,
".3.imported.bc");
483 optimizeModule(TheModule, TM, OptLevel, Freestanding);
485 saveTempBitcode(TheModule, SaveTempsDir, count,
".4.opt.bc");
487 if (DisableCodeGen) {
496 return make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
499 return codegenModule(TheModule, TM);
507 static void resolveWeakForLinkerInIndex(
509 StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
513 computePrevailingCopies(Index, PrevailingCopy);
516 const auto &Prevailing = PrevailingCopy.
find(GUID);
518 if (Prevailing == PrevailingCopy.
end())
520 return Prevailing->second == S;
523 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
526 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
534 const Triple &TheTriple) {
539 TMBuilder.
MCpu =
"core2";
541 TMBuilder.
MCpu =
"yonah";
543 TMBuilder.
MCpu =
"cyclone";
545 TMBuilder.
TheTriple = std::move(TheTriple);
558 TripleStr = *TripleOrErr;
560 Triple TheTriple(TripleStr);
563 initTMBuilder(TMBuilder,
Triple(TheTriple));
564 else if (TMBuilder.TheTriple != TheTriple) {
565 if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
568 initTMBuilder(TMBuilder,
Triple(TMBuilder.TheTriple.merge(TheTriple)));
571 Modules.push_back(Buffer);
575 PreservedSymbols.insert(Name);
582 PreservedSymbols.insert(Name);
597 std::string FeatureStr = Features.
getString();
599 return std::unique_ptr<TargetMachine>(
601 RelocModel,
None, CGOptLevel));
609 std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
610 llvm::make_unique<ModuleSummaryIndex>(
false);
611 uint64_t NextModuleId = 0;
612 for (
auto &ModuleBuffer : Modules) {
614 *CombinedIndex, NextModuleId++)) {
617 std::move(Err),
errs(),
618 "error: can't create module summary index for buffer: ");
622 return CombinedIndex;
630 const auto &ExportList = ExportLists.
find(ModuleIdentifier);
631 return (ExportList != ExportLists.
end() &&
632 ExportList->second.count(GUID)) ||
633 GUIDPreservedSymbols.
count(GUID);
665 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
679 resolveWeakForLinkerInIndex(Index, ResolvedODR);
682 TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
688 promoteModule(TheModule, Index);
696 auto ModuleMap = generateModuleMap(Modules);
704 auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
717 crossImportIntoModule(TheModule, Index, ModuleMap, ImportList);
725 std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
739 ImportLists[ModulePath],
740 ModuleToSummariesForIndex);
761 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
763 ImportLists[ModulePath],
764 ModuleToSummariesForIndex);
770 " to save imports lists\n");
783 auto GUIDPreservedSymbols =
784 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
798 auto &ExportList = ExportLists[ModuleIdentifier];
802 if (ExportList.empty() && GUIDPreservedSymbols.empty())
808 ModuleToDefinedGVSummaries[ModuleIdentifier]);
818 optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding);
826 return codegenModule(TheModule, *TMBuilder.create());
842 if (!CacheEntryPath.
empty()) {
846 return OutputPath.
str();
850 return OutputPath.
str();
854 errs() <<
"error: can't link or copy from cached entry '" << CacheEntryPath
855 <<
"' to '" << OutputPath <<
"'\n";
863 return OutputPath.
str();
869 assert(ProducedBinaries.empty() &&
"The generator should not be reused");
870 if (SavedObjectsDirectoryPath.empty())
871 ProducedBinaries.resize(Modules.size());
878 ProducedBinaryFiles.resize(Modules.size());
885 for (
auto &ModuleBuffer : Modules) {
886 Pool.
async([&](
int count) {
892 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(),
Context,
false,
896 auto OutputBuffer =
codegen(*TheModule);
897 if (SavedObjectsDirectoryPath.empty())
898 ProducedBinaries[count] = std::move(OutputBuffer);
901 count,
"", SavedObjectsDirectoryPath, *OutputBuffer);
909 auto Index = linkCombinedIndex();
912 if (!SaveTempsDir.empty()) {
913 auto SaveTempPath = SaveTempsDir +
"index.bc";
918 " to save optimized bitcode\n");
924 auto ModuleMap = generateModuleMap(Modules);
925 auto ModuleCount = Modules.size();
929 Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
933 auto GUIDPreservedSymbols =
934 computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
954 resolveWeakForLinkerInIndex(*
Index, ResolvedODR);
963 for (
auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
964 ExportLists[DefinedGVSummaries.first()];
965 ResolvedODR[DefinedGVSummaries.first()];
971 std::vector<int> ModulesOrdering;
972 ModulesOrdering.resize(Modules.size());
973 std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
974 llvm::sort(ModulesOrdering.begin(), ModulesOrdering.end(),
975 [&](
int LeftIndex,
int RightIndex) {
976 auto LSize = Modules[LeftIndex].getBuffer().size();
977 auto RSize = Modules[RightIndex].getBuffer().size();
978 return LSize > RSize;
984 for (
auto IndexCount : ModulesOrdering) {
985 auto &ModuleBuffer = Modules[IndexCount];
987 auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier();
988 auto &ExportList = ExportLists[ModuleIdentifier];
990 auto &DefinedFunctions = ModuleToDefinedGVSummaries[ModuleIdentifier];
993 ModuleCacheEntry CacheEntry(CacheOptions.Path, *
Index, ModuleIdentifier,
994 ImportLists[ModuleIdentifier], ExportList,
995 ResolvedODR[ModuleIdentifier],
996 DefinedFunctions, GUIDPreservedSymbols,
997 OptLevel, Freestanding, TMBuilder);
998 auto CacheEntryPath = CacheEntry.getEntryPath();
1001 auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1003 <<
" '" << CacheEntryPath <<
"' for buffer " 1004 << count <<
" " << ModuleIdentifier <<
"\n");
1008 if (SavedObjectsDirectoryPath.empty())
1009 ProducedBinaries[count] = std::move(ErrOrBuffer.get());
1012 count, CacheEntryPath, SavedObjectsDirectoryPath,
1013 *ErrOrBuffer.get());
1023 if (!DiagFileOrErr) {
1024 errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
1031 loadModuleFromBuffer(ModuleBuffer.getMemBuffer(),
Context,
false,
1035 saveTempBitcode(*TheModule, SaveTempsDir, count,
".0.original.bc");
1037 auto &ImportList = ImportLists[ModuleIdentifier];
1039 auto OutputBuffer = ProcessThinLTOModule(
1040 *TheModule, *
Index, ModuleMap, *TMBuilder.create(), ImportList,
1041 ExportList, GUIDPreservedSymbols,
1042 ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1043 DisableCodeGen, SaveTempsDir, Freestanding, OptLevel,
count);
1046 CacheEntry.write(*OutputBuffer);
1048 if (SavedObjectsDirectoryPath.empty()) {
1050 if (!CacheEntryPath.empty()) {
1057 auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1058 if (
auto EC = ReloadedBufferOrErr.getError()) {
1060 errs() <<
"error: can't reload cached file '" << CacheEntryPath
1061 <<
"': " << EC.message() <<
"\n";
1063 OutputBuffer = std::move(*ReloadedBufferOrErr);
1066 ProducedBinaries[
count] = std::move(OutputBuffer);
1070 count, CacheEntryPath, SavedObjectsDirectoryPath, *OutputBuffer);
1075 pruneCache(CacheOptions.Path, CacheOptions.Policy);
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, TargetMachine::CodeGenFileType FileType)
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, 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.
void collectDefinedGVSummariesPerModule(StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
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.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Expected< std::unique_ptr< ToolOutputFile > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
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.
Compute iterated dominance frontiers using a linear time algorithm.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
CodeGenOpt::Level CGOptLevel
std::error_code openFileForRead(const Twine &Name, int &ResultFD, 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.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
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...
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...
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner)
Log all errors (if any) in E to OS.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
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::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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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)
const StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths() const
Table of modules, containing module hash and id.
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...
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.
std::shared_future< void > async(Function &&F, Args &&... ArgList)
Asynchronous submission of a task to the pool.
void reportAndResetTimings()
If -time-passes has been specified, report the timings immediately and then reset the timers to zero...
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.
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, raw_pwrite_stream *, CodeGenFileType, bool=true, MachineModuleInfo *MMI=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
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.
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...
LLVMContext & getContext() const
Get the global data context.
std::unordered_set< GlobalValue::GUID > ExportSetTy
The set contains an entry for every global value the module exports.
Tagged union holding either a T or a Error.
Interface for custom diagnostic printing.
StringRef result()
Return a reference to the current raw 160-bits SHA1 for the digested data since the last call to init...
StringRef str() const
Explicit conversion to StringRef.
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)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Pass * createObjCARCContractPass()
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
unsigned FunctionSections
Emit functions into separate sections.
A ThreadPool for asynchronous parallel execution on a defined number of threads.
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.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
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.
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.
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...
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.
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
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.
TargetIRAnalysis getTargetIRAnalysis()
Get a TargetIRAnalysis appropriate for the target.
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.
bool isWeakForLinker() const
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
const Triple & getTargetTriple() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex, uint64_t ModuleId)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Function and variable summary information to aid decisions and implementation of importing.
static void internalizeAndPromoteInIndex(const StringMap< FunctionImporter::ExportSetTy > &ExportLists, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, ModuleSummaryIndex &Index)
static void write(bool isBE, void *P, T V)
bool pruneCache(StringRef Path, CachePruningPolicy Policy)
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
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.
Triple - Helper class for working with autoconf configuration names.
void sort(IteratorTy Start, IteratorTy End)
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.
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 handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
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.
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.
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 ...
std::string toHex(StringRef Input)
Convert buffer Input to its hexadecimal representation.
StringRef getBufferIdentifier() const
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.
unsigned RelaxELFRelocations
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.
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.
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
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)
ErrorOr< T > expectedToErrorOrAndEmitErrors(LLVMContext &Ctx, Expected< T > Val)
MemoryBufferRef getMemBuffer() const
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.
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.
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< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index)
Perform cross-module importing for the module identified by ModuleIdentifier.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
Optional< Reloc::Model > RelocModel
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
void internalize(Module &Module, ModuleSummaryIndex &Index)
Perform internalization.
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.
void computeDeadSymbols(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols, function_ref< PrevailingType(GlobalValue::GUID)> isPrevailing)
Compute all the symbols that are "dead": i.e these that can't be reached in the graph from any of the...
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.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(int 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.
bool exists(const basic_file_status &status)
Does file exist?
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...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...