37 #include "llvm/Support/VCSRevision.h"
49 using namespace object;
51 #define DEBUG_TYPE "lto"
66 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
76 Hasher.
update(LLVM_VERSION_STRING);
78 Hasher.
update(LLVM_REVISION);
86 auto AddUnsigned = [&](
unsigned I) {
94 auto AddUint64 = [&](uint64_t
I) {
134 for (
auto F : ExportList)
141 for (
auto &Entry : ImportList) {
145 AddUint64(Entry.second.size());
146 for (
auto &Fn : Entry.second)
151 for (
auto &Entry : ResolvedODR) {
158 std::set<GlobalValue::GUID> UsedTypeIds;
161 auto *FS = dyn_cast_or_null<FunctionSummary>(GS);
164 for (
auto &TT : FS->type_tests())
165 UsedTypeIds.insert(TT);
166 for (
auto &TT : FS->type_test_assume_vcalls())
167 UsedTypeIds.insert(TT.GUID);
168 for (
auto &TT : FS->type_checked_load_vcalls())
169 UsedTypeIds.insert(TT.GUID);
170 for (
auto &TT : FS->type_test_assume_const_vcalls())
171 UsedTypeIds.insert(TT.VFunc.GUID);
172 for (
auto &TT : FS->type_checked_load_const_vcalls())
173 UsedTypeIds.insert(TT.VFunc.GUID);
178 for (
auto &GS : DefinedGlobals) {
182 AddUsedTypeIds(GS.second);
187 for (
auto &ImpM : ImportList)
188 for (
auto &ImpF : ImpM.second)
194 AddUnsigned(S.TTRes.TheKind);
195 AddUnsigned(S.TTRes.SizeM1BitWidth);
197 AddUint64(S.WPDRes.size());
198 for (
auto &WPD : S.WPDRes) {
199 AddUnsigned(WPD.first);
200 AddUnsigned(WPD.second.TheKind);
201 AddString(WPD.second.SingleImplName);
203 AddUint64(WPD.second.ResByArg.size());
204 for (
auto &ByArg : WPD.second.ResByArg) {
205 AddUint64(ByArg.first.size());
206 for (uint64_t Arg : ByArg.first)
208 AddUnsigned(ByArg.second.TheKind);
209 AddUint64(ByArg.second.Info);
216 auto SummariesI = TypeIdSummariesByGuid.
find(TId);
217 if (SummariesI != TypeIdSummariesByGuid.
end())
218 for (
auto *Summary : SummariesI->second)
219 AddTypeIdSummary(Summary->first, Summary->second);
225 Hasher.
update(FileOrErr.get()->getBuffer());
238 for (
auto &S : GVSummaryList) {
250 if (isPrevailing(GUID, S.get())) {
256 else if (!isa<AliasSummary>(S.get()) &&
257 !GlobalInvolvedWithAlias.
count(S.get()))
259 if (S->linkage() != OriginalLinkage)
260 recordNewLinkage(S->modulePath(), GUID, S->linkage());
280 for (
auto &
I : Index)
281 for (
auto &S :
I.second.SummaryList)
282 if (
auto AS = dyn_cast<AliasSummary>(S.get()))
283 GlobalInvolvedWithAlias.
insert(&AS->getAliasee());
285 for (
auto &
I : Index)
287 GlobalInvolvedWithAlias, isPrevailing,
294 for (
auto &S : GVSummaryList) {
295 if (isExported(S->modulePath(), GUID)) {
308 for (
auto &
I : Index)
322 File->TargetTriple = FOrErr->TheReader.getTargetTriple();
323 File->SourceFileName = FOrErr->TheReader.getSourceFileName();
324 File->COFFLinkerOpts = FOrErr->TheReader.getCOFFLinkerOpts();
325 File->ComdatTable = FOrErr->TheReader.getComdatTable();
327 for (
unsigned I = 0;
I != FOrErr->Mods.size(); ++
I) {
328 size_t Begin = File->Symbols.size();
330 FOrErr->TheReader.module_symbols(
I))
333 if (Sym.isGlobal() && !Sym.isFormatSpecific())
334 File->Symbols.push_back(Sym);
335 File->ModuleSymIndices.push_back({Begin, File->Symbols.size()});
338 File->Mods = FOrErr->Mods;
339 File->Strtab = std::move(FOrErr->Strtab);
340 return std::move(File);
344 return Mods[0].getModuleIdentifier();
347 LTO::RegularLTOState::RegularLTOState(
unsigned ParallelCodeGenParallelismLevel,
349 : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
352 LTO::ThinLTOState::ThinLTOState(
ThinBackend Backend) : Backend(Backend) {
359 unsigned ParallelCodeGenParallelismLevel)
360 : Conf(std::move(Conf)),
361 RegularLTO(ParallelCodeGenParallelismLevel, this->Conf),
362 ThinLTO(std::move(Backend)) {}
371 unsigned Partition,
bool InSummary) {
372 auto *ResI = Res.
begin();
373 auto *ResE = Res.
end();
379 auto &GlobalRes = GlobalResolutions[Sym.getName()];
380 GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
382 GlobalRes.IRName = Sym.getIRName();
390 GlobalRes.Partition != Partition)) {
391 GlobalRes.Partition = GlobalResolution::External;
394 GlobalRes.Partition = Partition;
398 GlobalRes.VisibleOutsideSummary |=
407 auto ResI = Res.
begin();
412 OS <<
"-r=" << Path <<
',' << Sym.getName() <<
',';
415 if (Res.FinalDefinitionInLinkageUnit)
417 if (Res.VisibleToRegularObj)
419 if (Res.LinkerRedefined)
429 assert(!CalledGetMaxTasks);
435 for (
unsigned I = 0;
I != Input->Mods.size(); ++
I)
436 if (
Error Err = addModule(*Input,
I, ResI, Res.
end()))
451 auto ModSyms = Input.module_symbols(ModI);
452 addModuleToGlobalRes(ModSyms, {ResI, ResE},
453 LTOInfo->IsThinLTO ? ThinLTO.ModuleMap.size() + 1 : 0,
454 LTOInfo->HasSummary);
456 if (LTOInfo->IsThinLTO)
457 return addThinLTO(BM, ModSyms, ResI, ResE);
460 addRegularLTO(BM, ModSyms, ResI, ResE);
464 if (!LTOInfo->HasSummary)
465 return linkRegularLTO(std::move(*ModOrErr),
false);
471 RegularLTO.ModsWithSummaries.push_back(std::move(*ModOrErr));
487 std::set<const Comdat *> &NonPrevailingComdats) {
492 if (!NonPrevailingComdats.count(C))
501 if (
auto GO = dyn_cast<GlobalObject>(&GV))
502 GO->setComdat(
nullptr);
512 RegularLTOState::AddedModule Mod;
519 Mod.M = std::move(*MOrErr);
522 return std::move(Err);
529 if (GV.hasAppendingLinkage())
530 Mod.Keep.push_back(&GV);
535 AliasedGlobals.
insert(GO);
544 auto MsymI = SymTab.
symbols().begin(), MsymE = SymTab.
symbols().end();
546 while (MsymI != MsymE) {
556 std::set<const Comdat *> NonPrevailingComdats;
567 if (Sym.isUndefined())
569 Mod.Keep.push_back(GV);
580 }
else if (isa<GlobalObject>(GV) &&
581 (GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage() ||
582 GV->hasAvailableExternallyLinkage()) &&
583 !AliasedGlobals.
count(cast<GlobalObject>(GV))) {
589 Mod.Keep.push_back(GV);
592 NonPrevailingComdats.insert(GV->getComdat());
593 cast<GlobalObject>(GV)->setComdat(
nullptr);
599 if (Sym.isCommon()) {
602 auto &CommonRes = RegularLTO.Commons[Sym.getIRName()];
603 CommonRes.Size =
std::max(CommonRes.Size, Sym.getCommonSize());
604 CommonRes.Align =
std::max(CommonRes.Align, Sym.getCommonAlignment());
614 return std::move(Mod);
617 Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
618 bool LivenessFromIndex) {
619 if (!RegularLTO.CombinedModule) {
620 RegularLTO.CombinedModule =
621 llvm::make_unique<Module>(
"ld-temp.o", RegularLTO.Ctx);
622 RegularLTO.Mover = llvm::make_unique<IRMover>(*RegularLTO.CombinedModule);
625 std::vector<GlobalValue *> Keep;
627 if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->
getGUID()))
638 RegularLTO.CombinedModule->getNamedValue(GV->
getName());
645 return RegularLTO.Mover->move(std::move(Mod.M), Keep,
656 ThinLTO.ModuleMap.
size()))
664 if (!Sym.getIRName().empty()) {
674 if (
auto S = ThinLTO.CombinedIndex.findSummaryInModule(
682 return make_error<StringError>(
683 "Expected at most one ThinLTO module per bitcode file",
689 unsigned LTO::getMaxTasks()
const {
690 CalledGetMaxTasks =
true;
691 return RegularLTO.ParallelCodeGenParallelismLevel + ThinLTO.ModuleMap.size();
697 for (
auto &Res : GlobalResolutions) {
698 if (Res.second.VisibleOutsideSummary &&
701 !Res.second.IRName.empty())
711 bool HasRegularLTO = RegularLTO.CombinedModule !=
nullptr ||
712 !RegularLTO.ModsWithSummaries.empty();
715 if (
auto E = runRegularLTO(AddStream))
717 return runThinLTO(AddStream, Cache, HasRegularLTO);
721 for (
auto &M : RegularLTO.ModsWithSummaries)
722 if (
Error Err = linkRegularLTO(std::move(M),
728 const DataLayout &
DL = RegularLTO.CombinedModule->getDataLayout();
729 for (
auto &
I : RegularLTO.Commons) {
730 if (!
I.second.Prevailing)
733 GlobalVariable *OldGV = RegularLTO.CombinedModule->getNamedGlobal(
I.first);
742 auto *GV =
new GlobalVariable(*RegularLTO.CombinedModule, Ty,
false,
745 GV->setAlignment(
I.second.Align);
760 for (
const auto &R : GlobalResolutions) {
761 if (R.second.IRName.empty())
763 if (R.second.Partition != 0 &&
764 R.second.Partition != GlobalResolution::External)
768 RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
774 if (R.second.Partition == 0)
782 return backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
783 std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex);
796 : Conf(Conf), CombinedIndex(CombinedIndex),
797 ModuleToDefinedGVSummaries(ModuleToDefinedGVSummaries) {}
804 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
806 virtual Error wait() = 0;
820 InProcessThinBackend(
822 unsigned ThinLTOParallelismLevel,
826 BackendThreadPool(ThinLTOParallelismLevel),
827 AddStream(std::move(AddStream)), Cache(std::move(Cache)) {
832 for (
auto &TId : CombinedIndex.
typeIds())
836 Error runThinLTOBackendThread(
841 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
851 return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
852 ImportList, DefinedGlobals, ModuleMap);
857 if (!Cache || !CombinedIndex.
modulePaths().count(ModuleID) ||
862 return RunThinBackend(AddStream);
866 computeCacheKey(Key, Conf, CombinedIndex, ModuleID, ImportList, ExportList,
867 ResolvedODR, DefinedGlobals, TypeIdSummariesByGuid);
869 return RunThinBackend(CacheAddStream);
878 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
881 assert(ModuleToDefinedGVSummaries.
count(ModulePath));
883 ModuleToDefinedGVSummaries.
find(ModulePath)->second;
884 BackendThreadPool.async(
888 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>
893 Error E = runThinLTOBackendThread(
894 AddStream, Cache, Task, BM, CombinedIndex, ImportList, ExportList,
895 ResolvedODR, DefinedGlobals, ModuleMap, TypeIdSummariesByGuid);
897 std::unique_lock<std::mutex>
L(ErrMu);
899 Err =
joinErrors(std::move(*Err), std::move(E));
904 BM, std::ref(CombinedIndex), std::ref(ImportList), std::ref(ExportList),
905 std::ref(ResolvedODR), std::ref(DefinedGlobals), std::ref(ModuleMap),
906 std::ref(TypeIdSummariesByGuid));
910 Error wait()
override {
911 BackendThreadPool.wait();
913 return std::move(*Err);
924 return llvm::make_unique<InProcessThinBackend>(
925 Conf, CombinedIndex, ParallelismLevel, ModuleToDefinedGVSummaries,
934 const std::string &OldPrefix,
935 const std::string &NewPrefix) {
936 if (OldPrefix.empty() && NewPrefix.empty())
941 if (!ParentPath.
empty()) {
944 llvm::errs() <<
"warning: could not create directory '" << ParentPath
945 <<
"': " << EC.message() <<
'\n';
947 return NewPath.
str();
952 std::string OldPrefix, NewPrefix;
953 bool ShouldEmitImportsFiles;
955 std::string LinkedObjectsFileName;
956 std::unique_ptr<llvm::raw_fd_ostream> LinkedObjectsFile;
959 WriteIndexesThinBackend(
962 std::string OldPrefix, std::string NewPrefix,
bool ShouldEmitImportsFiles,
963 std::string LinkedObjectsFileName)
965 OldPrefix(OldPrefix), NewPrefix(NewPrefix),
966 ShouldEmitImportsFiles(ShouldEmitImportsFiles),
967 LinkedObjectsFileName(LinkedObjectsFileName) {}
973 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
976 std::string NewModulePath =
980 if (!LinkedObjectsFileName.empty()) {
981 if (!LinkedObjectsFile) {
982 LinkedObjectsFile = llvm::make_unique<raw_fd_ostream>(
987 *LinkedObjectsFile << NewModulePath <<
'\n';
990 std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
992 ImportList, ModuleToSummariesForIndex);
1000 if (ShouldEmitImportsFiles)
1011 std::string NewPrefix,
1012 bool ShouldEmitImportsFiles,
1013 std::string LinkedObjectsFile) {
1017 return llvm::make_unique<WriteIndexesThinBackend>(
1018 Conf, CombinedIndex, ModuleToDefinedGVSummaries, OldPrefix, NewPrefix,
1019 ShouldEmitImportsFiles, LinkedObjectsFile);
1024 bool HasRegularLTO) {
1025 if (ThinLTO.ModuleMap.empty())
1034 ModuleToDefinedGVSummaries(ThinLTO.ModuleMap.size());
1035 ThinLTO.CombinedIndex.collectDefinedGVSummariesPerModule(
1036 ModuleToDefinedGVSummaries);
1044 for (
auto &Mod : ThinLTO.ModuleMap)
1045 if (!ModuleToDefinedGVSummaries.
count(Mod.first))
1046 ModuleToDefinedGVSummaries.
try_emplace(Mod.first);
1049 ThinLTO.ModuleMap.size());
1051 ThinLTO.ModuleMap.size());
1056 ImportLists, ExportLists);
1058 std::set<GlobalValue::GUID> ExportedGUIDs;
1059 for (
auto &Res : GlobalResolutions) {
1061 if (Res.second.Partition != GlobalResolution::External)
1066 if (Res.second.IRName.empty())
1071 if (ThinLTO.CombinedIndex.isGUIDLive(GUID))
1072 ExportedGUIDs.insert(GUID);
1076 const auto &ExportList = ExportLists.find(ModuleIdentifier);
1077 return (ExportList != ExportLists.end() &&
1078 ExportList->second.count(GUID)) ||
1079 ExportedGUIDs.count(GUID);
1086 return ThinLTO.PrevailingModuleForGUID[GUID] == S->modulePath();
1088 auto recordNewLinkage = [&](
StringRef ModuleIdentifier,
1091 ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
1096 std::unique_ptr<ThinBackendProc> BackendProc =
1097 ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
1104 HasRegularLTO ? RegularLTO.ParallelCodeGenParallelismLevel : 0;
1105 for (
auto &Mod : ThinLTO.ModuleMap) {
1106 if (
Error E = BackendProc->start(Task, Mod.second, ImportLists[Mod.first],
1107 ExportLists[Mod.first],
1108 ResolvedODR[Mod.first], ThinLTO.ModuleMap))
1113 return BackendProc->wait();
1120 if (LTORemarksFilename.
empty())
1128 auto DiagnosticFile =
1133 llvm::make_unique<yaml::Output>(DiagnosticFile->os()));
1134 if (LTOPassRemarksWithHotness)
1136 DiagnosticFile->keep();
1137 return std::move(DiagnosticFile);
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.
A parsed version of the target data layout string in and methods for querying it. ...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class defines the interface to the ThinLTO backend.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned Prevailing
The linker has chosen this definition of the symbol.
CodeGenOpt::Level CGOptLevel
void replace_path_prefix(SmallVectorImpl< char > &Path, const StringRef &OldPrefix, const StringRef &NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
void setDiagnosticsOutputFile(std::unique_ptr< yaml::Output > F)
Set the diagnostics output file used for optimization diagnostics.
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. ...
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Implements a dense probed hash-table based set.
std::string OverrideTriple
Setting this field will replace target triples in input files with this triple.
Available for inspection, not emission.
unsigned DataSections
Emit data into separate sections.
static ConstantAggregateZero * get(Type *Ty)
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
bool CodeGenOnly
Disable entirely the optimizer, including importing for ThinLTO.
Type * getValueType() const
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, uint64_t ModuleId)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
unsigned LinkerRedefined
Linker redefined version of the symbol which appeared in -wrap or -defsym linker option.
std::unique_ptr< raw_ostream > ResolutionFile
If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 comman...
An efficient, type-erasing, non-owning reference to a callable.
static void computeCacheKey(SmallString< 40 > &Key, const 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 TypeIdSummariesByGuidTy &TypeIdSummariesByGuid)
iterator find(StringRef Key)
Externally visible function.
bool hasAvailableExternallyLinkage() const
The resolution for a symbol.
This class implements a map that also provides access to all stored values in a deterministic order...
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 StringMap< GVSummaryMapTy > & ModuleToDefinedGVSummaries
A class that wrap the SHA1 algorithm.
Error takeError()
Take ownership of the stored error.
void setAlignment(unsigned Align)
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
const Comdat * getComdat() const
static bool isLocalLinkage(LinkageTypes Linkage)
static bool isLinkOnceLinkage(LinkageTypes Linkage)
CombinedIndexHookFn CombinedIndexHook
StringRef getName() const
Return a constant reference to the value's name.
std::function< std::unique_ptr< NativeObjectStream >unsigned Task)> AddStreamFn
This type defines the callback to add a native object that is generated on the fly.
std::unordered_set< GlobalValue::GUID > ExportSetTy
The set contains an entry for every global value the module exports.
Represents a module in a bitcode file.
std::vector< std::string > MAttrs
ModuleSummaryIndex & CombinedIndex
const GlobalObject * getBaseObject() const
void setName(const Twine &Name)
Change the name of the value.
Tagged union holding either a T or a Error.
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef result()
Return a reference to the current raw 160-bits SHA1 for the digested data since the last call to init...
void addModule(Module *M)
std::vector< std::unique_ptr< GlobalValueSummary >> GlobalValueSummaryList
static bool isLinkOnceODRLinkage(LinkageTypes Linkage)
cl::opt< bool > LTOPassRemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
void setDiagnosticsHotnessRequested(bool Requested)
Set if a code hotness metric should be included in optimization diagnostics.
Class to represent array types.
std::string SampleProfile
Sample PGO profile path.
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)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
A ThreadPool for asynchronous parallel execution on a defined number of threads.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
void takeName(Value *V)
Transfer the name from V to this value.
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)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Ephemeral symbols produced by Reader::symbols() and Reader::module_symbols().
Error add(std::unique_ptr< InputFile > Obj, ArrayRef< SymbolResolution > Res)
Add an input file to the LTO link, using the provided symbol resolutions.
DebuggerKind DebuggerTuning
Which debugger to tune for.
ModuleHookFn PreOptModuleHook
This module hook is called after linking (regular LTO) or loading (ThinLTO) the module, before modifying it.
std::function< AddStreamFn(unsigned Task, StringRef Key)> NativeObjectCache
This is the type of a native object cache.
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.
This is an important class for using LLVM in a threaded context.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
ThinBackend createWriteIndexesThinBackend(std::string OldPrefix, std::string NewPrefix, bool ShouldEmitImportsFiles, std::string LinkedObjectsFile)
This ThinBackend writes individual module indexes to files, instead of running the individual backend...
std::pair< iterator, bool > insert(const ValueT &V)
bool UseNewPM
Use the new pass manager.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
ThinBackendProc(Config &Conf, ModuleSummaryIndex &CombinedIndex, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Expected< std::unique_ptr< tool_output_file > > setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename, bool LTOPassRemarksWithHotness, int Count=-1)
Setup optimization remarks.
DenseMap< GlobalValue::GUID, TinyPtrVector< const std::pair< const std::string, TypeIdSummary > * > > TypeIdSummariesByGuidTy
std::string DefaultTriple
Setting this field will replace unspecified target triples in input files with this triple...
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Function and variable summary information to aid decisions and implementation of importing.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
ModuleHookFn PostInternalizeModuleHook
This hook is called after internalizing the module.
TargetMachine::CodeGenFileType CGFileType
static LinkageTypes getWeakLinkage(bool ODR)
static void writeToResolutionFile(raw_ostream &OS, InputFile *Input, ArrayRef< SymbolResolution > Res)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map...
static ErrorSuccess success()
Create a success value.
std::function< std::unique_ptr< ThinBackendProc > Config &C, ModuleSummaryIndex &CombinedIndex, StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, AddStreamFn AddStream, NativeObjectCache Cache)> ThinBackend
A ThinBackend defines what happens after the thin-link phase during ThinLTO.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static void thinLTOInternalizeAndPromoteGUID(GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID, function_ref< bool(StringRef, GlobalValue::GUID)> isExported)
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
virtual ~ThinBackendProc()
Optional< Reloc::Model > RelocModel
std::error_code EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const FunctionImporter::ImportMapTy &ModuleImports)
Emit into OutputFilename the files module ModulePath will import from.
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
static void thinLTOResolveWeakForLinkerGUID(GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID, DenseSet< GlobalValueSummary * > &GlobalInvolvedWithAlias, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage)
void setLinkage(LinkageTypes LT)
StringRef getModuleIdentifier() const
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1', drop it.
StringRef str() const
Explicit conversion to StringRef.
LinkageTypes
An enumeration for the kinds of linkage for global values.
std::string OptPipeline
If this field is set, the set of passes run in the middle-end optimizer will be the one specified by ...
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.
uint32_t getSymbolFlags(Symbol S) const
unsigned RelaxELFRelocations
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ThinBackend createInProcessThinBackend(unsigned ParallelismLevel)
This ThinBackend runs the individual backend jobs in-process.
static std::vector< std::string > Flags
Error thinBackend(Config &C, unsigned Task, AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector< StringRef, BitcodeModule > &ModuleMap)
Runs a ThinLTO backend.
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.
PointerType * getType() const
Global values are always pointers.
A raw_ostream that writes to a file descriptor.
LTO(Config Conf, ThinBackend Backend=nullptr, unsigned ParallelCodeGenParallelismLevel=1)
Create an LTO object.
void setUnnamedAddr(UnnamedAddr Val)
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.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Error joinErrors(Error E1, Error E2)
Concatenate errors.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
ArrayRef< Symbol > symbols() const
Error run(AddStreamFn AddStream, NativeObjectCache Cache=nullptr)
Runs the LTO pipeline.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
CodeModel::Model CodeModel
unsigned VisibleToRegularObj
The definition of this symbol is visible outside of the LTO unit.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool hasLocalLinkage() const
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.
Error backend(Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, std::unique_ptr< Module > M, ModuleSummaryIndex &CombinedIndex)
Runs a regular LTO backend.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting)
Read the bitcode module and prepare for lazy deserialization of function bodies.
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context)
Read the entire bitcode module and return it.
iterator_range< global_iterator > globals()
A derived class of LLVMContext that initializes itself according to a given Config object...
StringRef - Represent a constant reference to a string, i.e.
Expected< IRSymtabFile > readIRSymtab(MemoryBufferRef MBRef)
Reads a bitcode file, creating its irsymtab if necessary.
static void handleNonPrevailingComdat(GlobalValue &GV, std::set< const Comdat * > &NonPrevailingComdats)
iterator_range< global_value_iterator > global_values()
const std::map< std::string, TypeIdSummary > & typeIds() const
llvm::Error materializeMetadata()
static IntegerType * getInt8Ty(LLVMContext &C)
std::string getThinLTOOutputFile(const std::string &Path, const std::string &OldPrefix, const std::string &NewPrefix)
Given the original Path to an output file, replace any path prefix matching OldPrefix with NewPrefix...
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...
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
iterator_range< alias_iterator > aliases()