LLVM  14.0.0git
ThinLTOCodeGenerator.cpp
Go to the documentation of this file.
1 //===-ThinLTOCodeGenerator.cpp - LLVM Link Time Optimizer -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Thin Link Time Optimization library. This library is
10 // intended to be used by linker to optimize code at link time.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 
17 #include "llvm/ADT/ScopeExit.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/ADT/StringExtras.h"
28 #include "llvm/Config/llvm-config.h"
29 #include "llvm/IR/DebugInfo.h"
31 #include "llvm/IR/LLVMContext.h"
34 #include "llvm/IR/Mangler.h"
35 #include "llvm/IR/PassTimingInfo.h"
36 #include "llvm/IR/Verifier.h"
37 #include "llvm/IRReader/IRReader.h"
38 #include "llvm/LTO/LTO.h"
41 #include "llvm/MC/TargetRegistry.h"
47 #include "llvm/Support/Debug.h"
48 #include "llvm/Support/Error.h"
50 #include "llvm/Support/Path.h"
51 #include "llvm/Support/SHA1.h"
54 #include "llvm/Support/Threading.h"
57 #include "llvm/Transforms/IPO.h"
65 
66 #include <numeric>
67 
68 #if !defined(_MSC_VER) && !defined(__MINGW32__)
69 #include <unistd.h>
70 #else
71 #include <io.h>
72 #endif
73 
74 using namespace llvm;
75 
76 #define DEBUG_TYPE "thinlto"
77 
78 namespace llvm {
79 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
87 }
88 
89 namespace {
90 
91 // Default to using all available threads in the system, but using only one
92 // thred per core, as indicated by the usage of
93 // heavyweight_hardware_concurrency() below.
94 static cl::opt<int> ThreadCount("threads", cl::init(0));
95 
96 // Simple helper to save temporary files for debug.
97 static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
98  unsigned count, StringRef Suffix) {
99  if (TempDir.empty())
100  return;
101  // User asked to save temps, let dump the bitcode file after import.
102  std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str();
103  std::error_code EC;
104  raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
105  if (EC)
106  report_fatal_error(Twine("Failed to open ") + SaveTempPath +
107  " to save optimized bitcode\n");
108  WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
109 }
110 
111 static const GlobalValueSummary *
112 getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
113  // If there is any strong definition anywhere, get it.
114  auto StrongDefForLinker = llvm::find_if(
115  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
116  auto Linkage = Summary->linkage();
119  });
120  if (StrongDefForLinker != GVSummaryList.end())
121  return StrongDefForLinker->get();
122  // Get the first *linker visible* definition for this global in the summary
123  // list.
124  auto FirstDefForLinker = llvm::find_if(
125  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
126  auto Linkage = Summary->linkage();
128  });
129  // Extern templates can be emitted as available_externally.
130  if (FirstDefForLinker == GVSummaryList.end())
131  return nullptr;
132  return FirstDefForLinker->get();
133 }
134 
135 // Populate map of GUID to the prevailing copy for any multiply defined
136 // symbols. Currently assume first copy is prevailing, or any strong
137 // definition. Can be refined with Linker information in the future.
138 static void computePrevailingCopies(
139  const ModuleSummaryIndex &Index,
141  auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
142  return GVSummaryList.size() > 1;
143  };
144 
145  for (auto &I : Index) {
146  if (HasMultipleCopies(I.second.SummaryList))
147  PrevailingCopy[I.first] =
148  getFirstDefinitionForLinker(I.second.SummaryList);
149  }
150 }
151 
153 generateModuleMap(std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
154  StringMap<lto::InputFile *> ModuleMap;
155  for (auto &M : Modules) {
156  assert(ModuleMap.find(M->getName()) == ModuleMap.end() &&
157  "Expect unique Buffer Identifier");
158  ModuleMap[M->getName()] = M.get();
159  }
160  return ModuleMap;
161 }
162 
163 static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index,
164  bool ClearDSOLocalOnDeclarations) {
165  if (renameModuleForThinLTO(TheModule, Index, ClearDSOLocalOnDeclarations))
166  report_fatal_error("renameModuleForThinLTO failed");
167 }
168 
169 namespace {
170 class ThinLTODiagnosticInfo : public DiagnosticInfo {
171  const Twine &Msg;
172 public:
173  ThinLTODiagnosticInfo(const Twine &DiagMsg,
174  DiagnosticSeverity Severity = DS_Error)
175  : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
176  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
177 };
178 }
179 
180 /// Verify the module and strip broken debug info.
181 static void verifyLoadedModule(Module &TheModule) {
182  bool BrokenDebugInfo = false;
183  if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
184  report_fatal_error("Broken module found, compilation aborted!");
185  if (BrokenDebugInfo) {
186  TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
187  "Invalid debug info found, debug info will be stripped", DS_Warning));
188  StripDebugInfo(TheModule);
189  }
190 }
191 
192 static std::unique_ptr<Module> loadModuleFromInput(lto::InputFile *Input,
194  bool Lazy,
195  bool IsImporting) {
196  auto &Mod = Input->getSingleBitcodeModule();
197  SMDiagnostic Err;
198  Expected<std::unique_ptr<Module>> ModuleOrErr =
199  Lazy ? Mod.getLazyModule(Context,
200  /* ShouldLazyLoadMetadata */ true, IsImporting)
201  : Mod.parseModule(Context);
202  if (!ModuleOrErr) {
203  handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
204  SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
205  SourceMgr::DK_Error, EIB.message());
206  Err.print("ThinLTO", errs());
207  });
208  report_fatal_error("Can't load module, abort.");
209  }
210  if (!Lazy)
211  verifyLoadedModule(*ModuleOrErr.get());
212  return std::move(*ModuleOrErr);
213 }
214 
215 static void
216 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
217  StringMap<lto::InputFile *> &ModuleMap,
218  const FunctionImporter::ImportMapTy &ImportList,
219  bool ClearDSOLocalOnDeclarations) {
220  auto Loader = [&](StringRef Identifier) {
221  auto &Input = ModuleMap[Identifier];
222  return loadModuleFromInput(Input, TheModule.getContext(),
223  /*Lazy=*/true, /*IsImporting*/ true);
224  };
225 
226  FunctionImporter Importer(Index, Loader, ClearDSOLocalOnDeclarations);
227  Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
228  if (!Result) {
229  handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) {
230  SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
231  SourceMgr::DK_Error, EIB.message());
232  Err.print("ThinLTO", errs());
233  });
234  report_fatal_error("importFunctions failed");
235  }
236  // Verify again after cross-importing.
237  verifyLoadedModule(TheModule);
238 }
239 
240 static void optimizeModule(Module &TheModule, TargetMachine &TM,
241  unsigned OptLevel, bool Freestanding,
243  // Populate the PassManager
244  PassManagerBuilder PMB;
245  PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());
246  if (Freestanding)
249  // FIXME: should get it from the bitcode?
250  PMB.OptLevel = OptLevel;
251  PMB.LoopVectorize = true;
252  PMB.SLPVectorize = true;
253  // Already did this in verifyLoadedModule().
254  PMB.VerifyInput = false;
255  PMB.VerifyOutput = false;
256  PMB.ImportSummary = Index;
257 
259 
260  // Add the TTI (required to inform the vectorizer about register size for
261  // instance)
262  PM.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
263 
264  // Add optimizations
266 
267  PM.run(TheModule);
268 }
269 
270 static void optimizeModuleNewPM(Module &TheModule, TargetMachine &TM,
271  unsigned OptLevel, bool Freestanding,
272  bool DebugPassManager,
274  Optional<PGOOptions> PGOOpt;
279 
281  StandardInstrumentations SI(DebugPassManager);
284  PTO.LoopVectorization = true;
285  PTO.SLPVectorization = true;
286  PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
287 
288  std::unique_ptr<TargetLibraryInfoImpl> TLII(
289  new TargetLibraryInfoImpl(Triple(TM.getTargetTriple())));
290  if (Freestanding)
291  TLII->disableAllFunctions();
292  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
293 
294  // Register all the basic analyses with the managers.
300 
302 
304 
305  switch (OptLevel) {
306  default:
307  llvm_unreachable("Invalid optimization level");
308  case 0:
310  break;
311  case 1:
313  break;
314  case 2:
316  break;
317  case 3:
319  break;
320  }
321 
323 
324  MPM.run(TheModule, MAM);
325 }
326 
327 static void
328 addUsedSymbolToPreservedGUID(const lto::InputFile &File,
329  DenseSet<GlobalValue::GUID> &PreservedGUID) {
330  for (const auto &Sym : File.symbols()) {
331  if (Sym.isUsed())
332  PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
333  }
334 }
335 
336 // Convert the PreservedSymbols map from "Name" based to "GUID" based.
337 static void computeGUIDPreservedSymbols(const lto::InputFile &File,
339  const Triple &TheTriple,
341  // Iterate the symbols in the input file and if the input has preserved symbol
342  // compute the GUID for the symbol.
343  for (const auto &Sym : File.symbols()) {
344  if (PreservedSymbols.count(Sym.getName()) && !Sym.getIRName().empty())
346  Sym.getIRName(), GlobalValue::ExternalLinkage, "")));
347  }
348 }
349 
351 computeGUIDPreservedSymbols(const lto::InputFile &File,
353  const Triple &TheTriple) {
354  DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
355  computeGUIDPreservedSymbols(File, PreservedSymbols, TheTriple,
356  GUIDPreservedSymbols);
357  return GUIDPreservedSymbols;
358 }
359 
360 std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
361  TargetMachine &TM) {
362  SmallVector<char, 128> OutputBuffer;
363 
364  // CodeGen
365  {
366  raw_svector_ostream OS(OutputBuffer);
368 
369  // If the bitcode files contain ARC code and were compiled with optimization,
370  // the ObjCARCContractPass must be run, so do it unconditionally here.
372 
373  // Setup the codegen now.
374  if (TM.addPassesToEmitFile(PM, OS, nullptr, CGFT_ObjectFile,
375  /* DisableVerify */ true))
376  report_fatal_error("Failed to setup codegen");
377 
378  // Run codegen now. resulting binary is in OutputBuffer.
379  PM.run(TheModule);
380  }
381  return std::make_unique<SmallVectorMemoryBuffer>(
382  std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
383 }
384 
385 /// Manage caching for a single Module.
386 class ModuleCacheEntry {
387  SmallString<128> EntryPath;
388 
389 public:
390  // Create a cache entry. This compute a unique hash for the Module considering
391  // the current list of export/import, and offer an interface to query to
392  // access the content in the cache.
393  ModuleCacheEntry(
394  StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID,
395  const FunctionImporter::ImportMapTy &ImportList,
396  const FunctionImporter::ExportSetTy &ExportList,
397  const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
398  const GVSummaryMapTy &DefinedGVSummaries, unsigned OptLevel,
399  bool Freestanding, const TargetMachineBuilder &TMBuilder) {
400  if (CachePath.empty())
401  return;
402 
403  if (!Index.modulePaths().count(ModuleID))
404  // The module does not have an entry, it can't have a hash at all
405  return;
406 
407  if (all_of(Index.getModuleHash(ModuleID),
408  [](uint32_t V) { return V == 0; }))
409  // No hash entry, no caching!
410  return;
411 
412  llvm::lto::Config Conf;
413  Conf.OptLevel = OptLevel;
414  Conf.Options = TMBuilder.Options;
415  Conf.CPU = TMBuilder.MCpu;
416  Conf.MAttrs.push_back(TMBuilder.MAttr);
417  Conf.RelocModel = TMBuilder.RelocModel;
418  Conf.CGOptLevel = TMBuilder.CGOptLevel;
419  Conf.Freestanding = Freestanding;
421  computeLTOCacheKey(Key, Conf, Index, ModuleID, ImportList, ExportList,
422  ResolvedODR, DefinedGVSummaries);
423 
424  // This choice of file name allows the cache to be pruned (see pruneCache()
425  // in include/llvm/Support/CachePruning.h).
426  sys::path::append(EntryPath, CachePath, "llvmcache-" + Key);
427  }
428 
429  // Access the path to this entry in the cache.
430  StringRef getEntryPath() { return EntryPath; }
431 
432  // Try loading the buffer for this cache entry.
433  ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
434  if (EntryPath.empty())
435  return std::error_code();
436  SmallString<64> ResultPath;
438  Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
439  if (!FDOrErr)
440  return errorToErrorCode(FDOrErr.takeError());
442  *FDOrErr, EntryPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
443  sys::fs::closeFile(*FDOrErr);
444  return MBOrErr;
445  }
446 
447  // Cache the Produced object file
448  void write(const MemoryBuffer &OutputBuffer) {
449  if (EntryPath.empty())
450  return;
451 
452  // Write to a temporary to avoid race condition
453  SmallString<128> TempFilename;
454  SmallString<128> CachePath(EntryPath);
456  sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
457 
458  if (auto Err = handleErrors(
459  llvm::writeFileAtomically(TempFilename, EntryPath,
460  OutputBuffer.getBuffer()),
461  [](const llvm::AtomicFileWriteError &E) {
462  std::string ErrorMsgBuffer;
463  llvm::raw_string_ostream S(ErrorMsgBuffer);
464  E.log(S);
465 
466  if (E.Error ==
467  llvm::atomic_write_error::failed_to_create_uniq_file) {
468  errs() << "Error: " << ErrorMsgBuffer << "\n";
469  report_fatal_error("ThinLTO: Can't get a temporary file");
470  }
471  })) {
472  // FIXME
473  consumeError(std::move(Err));
474  }
475  }
476 };
477 
478 static std::unique_ptr<MemoryBuffer>
479 ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
481  const FunctionImporter::ImportMapTy &ImportList,
482  const FunctionImporter::ExportSetTy &ExportList,
483  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
484  const GVSummaryMapTy &DefinedGlobals,
485  const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
486  bool DisableCodeGen, StringRef SaveTempsDir,
487  bool Freestanding, unsigned OptLevel, unsigned count,
488  bool UseNewPM, bool DebugPassManager) {
489 
490  // "Benchmark"-like optimization: single-source case
491  bool SingleModule = (ModuleMap.size() == 1);
492 
493  // When linking an ELF shared object, dso_local should be dropped. We
494  // conservatively do this for -fpic.
495  bool ClearDSOLocalOnDeclarations =
496  TM.getTargetTriple().isOSBinFormatELF() &&
497  TM.getRelocationModel() != Reloc::Static &&
498  TheModule.getPIELevel() == PIELevel::Default;
499 
500  if (!SingleModule) {
501  promoteModule(TheModule, Index, ClearDSOLocalOnDeclarations);
502 
503  // Apply summary-based prevailing-symbol resolution decisions.
504  thinLTOFinalizeInModule(TheModule, DefinedGlobals, /*PropagateAttrs=*/true);
505 
506  // Save temps: after promotion.
507  saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc");
508  }
509 
510  // Be friendly and don't nuke totally the module when the client didn't
511  // supply anything to preserve.
512  if (!ExportList.empty() || !GUIDPreservedSymbols.empty()) {
513  // Apply summary-based internalization decisions.
514  thinLTOInternalizeModule(TheModule, DefinedGlobals);
515  }
516 
517  // Save internalized bitcode
518  saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc");
519 
520  if (!SingleModule) {
521  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
522  ClearDSOLocalOnDeclarations);
523 
524  // Save temps: after cross-module import.
525  saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
526  }
527 
528  if (UseNewPM)
529  optimizeModuleNewPM(TheModule, TM, OptLevel, Freestanding, DebugPassManager,
530  &Index);
531  else
532  optimizeModule(TheModule, TM, OptLevel, Freestanding, &Index);
533 
534  saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
535 
536  if (DisableCodeGen) {
537  // Configured to stop before CodeGen, serialize the bitcode and return.
538  SmallVector<char, 128> OutputBuffer;
539  {
540  raw_svector_ostream OS(OutputBuffer);
541  ProfileSummaryInfo PSI(TheModule);
542  auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
543  WriteBitcodeToFile(TheModule, OS, true, &Index);
544  }
545  return std::make_unique<SmallVectorMemoryBuffer>(
546  std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
547  }
548 
549  return codegenModule(TheModule, TM);
550 }
551 
552 /// Resolve prevailing symbols. Record resolutions in the \p ResolvedODR map
553 /// for caching, and in the \p Index for application during the ThinLTO
554 /// backends. This is needed for correctness for exported symbols (ensure
555 /// at least one copy kept) and a compile-time optimization (to drop duplicate
556 /// copies when possible).
557 static void resolvePrevailingInIndex(
559  StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
560  &ResolvedODR,
561  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
563  &PrevailingCopy) {
564 
565  auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
566  const auto &Prevailing = PrevailingCopy.find(GUID);
567  // Not in map means that there was only one copy, which must be prevailing.
568  if (Prevailing == PrevailingCopy.end())
569  return true;
570  return Prevailing->second == S;
571  };
572 
573  auto recordNewLinkage = [&](StringRef ModuleIdentifier,
574  GlobalValue::GUID GUID,
575  GlobalValue::LinkageTypes NewLinkage) {
576  ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
577  };
578 
579  // TODO Conf.VisibilityScheme can be lto::Config::ELF for ELF.
580  lto::Config Conf;
581  thinLTOResolvePrevailingInIndex(Conf, Index, isPrevailing, recordNewLinkage,
582  GUIDPreservedSymbols);
583 }
584 
585 // Initialize the TargetMachine builder for a given Triple
586 static void initTMBuilder(TargetMachineBuilder &TMBuilder,
587  const Triple &TheTriple) {
588  // Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
589  // FIXME this looks pretty terrible...
590  if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
591  if (TheTriple.getArch() == llvm::Triple::x86_64)
592  TMBuilder.MCpu = "core2";
593  else if (TheTriple.getArch() == llvm::Triple::x86)
594  TMBuilder.MCpu = "yonah";
595  else if (TheTriple.getArch() == llvm::Triple::aarch64 ||
596  TheTriple.getArch() == llvm::Triple::aarch64_32)
597  TMBuilder.MCpu = "cyclone";
598  }
599  TMBuilder.TheTriple = std::move(TheTriple);
600 }
601 
602 } // end anonymous namespace
603 
604 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
605  MemoryBufferRef Buffer(Data, Identifier);
606 
607  auto InputOrError = lto::InputFile::create(Buffer);
608  if (!InputOrError)
609  report_fatal_error(Twine("ThinLTO cannot create input file: ") +
610  toString(InputOrError.takeError()));
611 
612  auto TripleStr = (*InputOrError)->getTargetTriple();
613  Triple TheTriple(TripleStr);
614 
615  if (Modules.empty())
616  initTMBuilder(TMBuilder, Triple(TheTriple));
617  else if (TMBuilder.TheTriple != TheTriple) {
618  if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
619  report_fatal_error("ThinLTO modules with incompatible triples not "
620  "supported");
621  initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
622  }
623 
624  Modules.emplace_back(std::move(*InputOrError));
625 }
626 
628  PreservedSymbols.insert(Name);
629 }
630 
632  // FIXME: At the moment, we don't take advantage of this extra information,
633  // we're conservatively considering cross-references as preserved.
634  // CrossReferencedSymbols.insert(Name);
635  PreservedSymbols.insert(Name);
636 }
637 
638 // TargetMachine factory
639 std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
640  std::string ErrMsg;
641  const Target *TheTarget =
643  if (!TheTarget) {
644  report_fatal_error(Twine("Can't load target for this Triple: ") + ErrMsg);
645  }
646 
647  // Use MAttr as the default set of features.
648  SubtargetFeatures Features(MAttr);
650  std::string FeatureStr = Features.getString();
651 
652  std::unique_ptr<TargetMachine> TM(
653  TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
655  assert(TM && "Cannot create target machine");
656 
657  return TM;
658 }
659 
660 /**
661  * Produce the combined summary index from all the bitcode files:
662  * "thin-link".
663  */
664 std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
665  std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
666  std::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
667  uint64_t NextModuleId = 0;
668  for (auto &Mod : Modules) {
669  auto &M = Mod->getSingleBitcodeModule();
670  if (Error Err =
671  M.readSummary(*CombinedIndex, Mod->getName(), NextModuleId++)) {
672  // FIXME diagnose
674  std::move(Err), errs(),
675  "error: can't create module summary index for buffer: ");
676  return nullptr;
677  }
678  }
679  return CombinedIndex;
680 }
681 
682 namespace {
683 struct IsExported {
684  const StringMap<FunctionImporter::ExportSetTy> &ExportLists;
685  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols;
686 
687  IsExported(const StringMap<FunctionImporter::ExportSetTy> &ExportLists,
688  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols)
689  : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
690 
691  bool operator()(StringRef ModuleIdentifier, ValueInfo VI) const {
692  const auto &ExportList = ExportLists.find(ModuleIdentifier);
693  return (ExportList != ExportLists.end() && ExportList->second.count(VI)) ||
694  GUIDPreservedSymbols.count(VI.getGUID());
695  }
696 };
697 
698 struct IsPrevailing {
701  &PrevailingCopy)
702  : PrevailingCopy(PrevailingCopy) {}
703 
704  bool operator()(GlobalValue::GUID GUID, const GlobalValueSummary *S) const {
705  const auto &Prevailing = PrevailingCopy.find(GUID);
706  // Not in map means that there was only one copy, which must be prevailing.
707  if (Prevailing == PrevailingCopy.end())
708  return true;
709  return Prevailing->second == S;
710  };
711 };
712 } // namespace
713 
716  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
717  // We have no symbols resolution available. And can't do any better now in the
718  // case where the prevailing symbol is in a native object. It can be refined
719  // with linker information in the future.
720  auto isPrevailing = [&](GlobalValue::GUID G) {
722  };
723  computeDeadSymbolsWithConstProp(Index, GUIDPreservedSymbols, isPrevailing,
724  /* ImportEnabled = */ true);
725 }
726 
727 /**
728  * Perform promotion and renaming of exported internal functions.
729  * Index is updated to reflect linkage changes from weak resolution.
730  */
732  const lto::InputFile &File) {
733  auto ModuleCount = Index.modulePaths().size();
734  auto ModuleIdentifier = TheModule.getModuleIdentifier();
735 
736  // Collect for each module the list of function it defines (GUID -> Summary).
737  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
738  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
739 
740  // Convert the preserved symbols set from string to GUID
741  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
742  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
743 
744  // Add used symbol to the preserved symbols.
745  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
746 
747  // Compute "dead" symbols, we don't want to import/export these!
748  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
749 
750  // Generate import/export list
751  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
752  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
753  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
754  ExportLists);
755 
757  computePrevailingCopies(Index, PrevailingCopy);
758 
759  // Resolve prevailing symbols
761  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
762  PrevailingCopy);
763 
764  thinLTOFinalizeInModule(TheModule,
765  ModuleToDefinedGVSummaries[ModuleIdentifier],
766  /*PropagateAttrs=*/false);
767 
768  // Promote the exported values in the index, so that they are promoted
769  // in the module.
771  Index, IsExported(ExportLists, GUIDPreservedSymbols),
772  IsPrevailing(PrevailingCopy));
773 
774  // FIXME Set ClearDSOLocalOnDeclarations.
775  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
776 }
777 
778 /**
779  * Perform cross-module importing for the module identified by ModuleIdentifier.
780  */
783  const lto::InputFile &File) {
784  auto ModuleMap = generateModuleMap(Modules);
785  auto ModuleCount = Index.modulePaths().size();
786 
787  // Collect for each module the list of function it defines (GUID -> Summary).
788  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
789  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
790 
791  // Convert the preserved symbols set from string to GUID
792  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
793  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
794 
795  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
796 
797  // Compute "dead" symbols, we don't want to import/export these!
798  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
799 
800  // Generate import/export list
801  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
802  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
803  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
804  ExportLists);
805  auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
806 
807  // FIXME Set ClearDSOLocalOnDeclarations.
808  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
809  /*ClearDSOLocalOnDeclarations=*/false);
810 }
811 
812 /**
813  * Compute the list of summaries needed for importing into module.
814  */
816  Module &TheModule, ModuleSummaryIndex &Index,
817  std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
818  const lto::InputFile &File) {
819  auto ModuleCount = Index.modulePaths().size();
820  auto ModuleIdentifier = TheModule.getModuleIdentifier();
821 
822  // Collect for each module the list of function it defines (GUID -> Summary).
823  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
824  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
825 
826  // Convert the preserved symbols set from string to GUID
827  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
828  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
829 
830  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
831 
832  // Compute "dead" symbols, we don't want to import/export these!
833  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
834 
835  // Generate import/export list
836  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
837  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
838  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
839  ExportLists);
840 
842  ModuleIdentifier, ModuleToDefinedGVSummaries,
843  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
844 }
845 
846 /**
847  * Emit the list of files needed for importing into module.
848  */
851  const lto::InputFile &File) {
852  auto ModuleCount = Index.modulePaths().size();
853  auto ModuleIdentifier = TheModule.getModuleIdentifier();
854 
855  // Collect for each module the list of function it defines (GUID -> Summary).
856  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
857  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
858 
859  // Convert the preserved symbols set from string to GUID
860  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
861  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
862 
863  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
864 
865  // Compute "dead" symbols, we don't want to import/export these!
866  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
867 
868  // Generate import/export list
869  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
870  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
871  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
872  ExportLists);
873 
874  std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
876  ModuleIdentifier, ModuleToDefinedGVSummaries,
877  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
878 
879  std::error_code EC;
880  if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,
881  ModuleToSummariesForIndex)))
882  report_fatal_error(Twine("Failed to open ") + OutputName +
883  " to save imports lists\n");
884 }
885 
886 /**
887  * Perform internalization. Runs promote and internalization together.
888  * Index is updated to reflect linkage changes.
889  */
892  const lto::InputFile &File) {
893  initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
894  auto ModuleCount = Index.modulePaths().size();
895  auto ModuleIdentifier = TheModule.getModuleIdentifier();
896 
897  // Convert the preserved symbols set from string to GUID
898  auto GUIDPreservedSymbols =
899  computeGUIDPreservedSymbols(File, PreservedSymbols, TMBuilder.TheTriple);
900 
901  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
902 
903  // Collect for each module the list of function it defines (GUID -> Summary).
904  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
905  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
906 
907  // Compute "dead" symbols, we don't want to import/export these!
908  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
909 
910  // Generate import/export list
911  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
912  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
913  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
914  ExportLists);
915  auto &ExportList = ExportLists[ModuleIdentifier];
916 
917  // Be friendly and don't nuke totally the module when the client didn't
918  // supply anything to preserve.
919  if (ExportList.empty() && GUIDPreservedSymbols.empty())
920  return;
921 
923  computePrevailingCopies(Index, PrevailingCopy);
924 
925  // Resolve prevailing symbols
927  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
928  PrevailingCopy);
929 
930  // Promote the exported values in the index, so that they are promoted
931  // in the module.
933  Index, IsExported(ExportLists, GUIDPreservedSymbols),
934  IsPrevailing(PrevailingCopy));
935 
936  // FIXME Set ClearDSOLocalOnDeclarations.
937  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
938 
939  // Internalization
940  thinLTOFinalizeInModule(TheModule,
941  ModuleToDefinedGVSummaries[ModuleIdentifier],
942  /*PropagateAttrs=*/false);
943 
944  thinLTOInternalizeModule(TheModule,
945  ModuleToDefinedGVSummaries[ModuleIdentifier]);
946 }
947 
948 /**
949  * Perform post-importing ThinLTO optimizations.
950  */
952  initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
953 
954  // Optimize now
955  optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding,
956  nullptr);
957 }
958 
959 /// Write out the generated object file, either from CacheEntryPath or from
960 /// OutputBuffer, preferring hard-link when possible.
961 /// Returns the path to the generated file in SavedObjectsDirectoryPath.
962 std::string
964  const MemoryBuffer &OutputBuffer) {
965  auto ArchName = TMBuilder.TheTriple.getArchName();
966  SmallString<128> OutputPath(SavedObjectsDirectoryPath);
967  llvm::sys::path::append(OutputPath,
968  Twine(count) + "." + ArchName + ".thinlto.o");
969  OutputPath.c_str(); // Ensure the string is null terminated.
970  if (sys::fs::exists(OutputPath))
971  sys::fs::remove(OutputPath);
972 
973  // We don't return a memory buffer to the linker, just a list of files.
974  if (!CacheEntryPath.empty()) {
975  // Cache is enabled, hard-link the entry (or copy if hard-link fails).
976  auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
977  if (!Err)
978  return std::string(OutputPath.str());
979  // Hard linking failed, try to copy.
980  Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
981  if (!Err)
982  return std::string(OutputPath.str());
983  // Copy failed (could be because the CacheEntry was removed from the cache
984  // in the meantime by another process), fall back and try to write down the
985  // buffer to the output.
986  errs() << "remark: can't link or copy from cached entry '" << CacheEntryPath
987  << "' to '" << OutputPath << "'\n";
988  }
989  // No cache entry, just write out the buffer.
990  std::error_code Err;
991  raw_fd_ostream OS(OutputPath, Err, sys::fs::OF_None);
992  if (Err)
993  report_fatal_error(Twine("Can't open output '") + OutputPath + "'\n");
994  OS << OutputBuffer.getBuffer();
995  return std::string(OutputPath.str());
996 }
997 
998 // Main entry point for the ThinLTO processing
1000  timeTraceProfilerBegin("ThinLink", StringRef(""));
1001  auto TimeTraceScopeExit = llvm::make_scope_exit([]() {
1004  });
1005  // Prepare the resulting object vector
1006  assert(ProducedBinaries.empty() && "The generator should not be reused");
1007  if (SavedObjectsDirectoryPath.empty())
1008  ProducedBinaries.resize(Modules.size());
1009  else {
1010  sys::fs::create_directories(SavedObjectsDirectoryPath);
1011  bool IsDir;
1012  sys::fs::is_directory(SavedObjectsDirectoryPath, IsDir);
1013  if (!IsDir)
1014  report_fatal_error(Twine("Unexistent dir: '") + SavedObjectsDirectoryPath + "'");
1015  ProducedBinaryFiles.resize(Modules.size());
1016  }
1017 
1018  if (CodeGenOnly) {
1019  // Perform only parallel codegen and return.
1020  ThreadPool Pool;
1021  int count = 0;
1022  for (auto &Mod : Modules) {
1023  Pool.async([&](int count) {
1025  Context.setDiscardValueNames(LTODiscardValueNames);
1026 
1027  // Parse module now
1028  auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
1029  /*IsImporting*/ false);
1030 
1031  // CodeGen
1032  auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create());
1033  if (SavedObjectsDirectoryPath.empty())
1034  ProducedBinaries[count] = std::move(OutputBuffer);
1035  else
1036  ProducedBinaryFiles[count] =
1037  writeGeneratedObject(count, "", *OutputBuffer);
1038  }, count++);
1039  }
1040 
1041  return;
1042  }
1043 
1044  // Sequential linking phase
1045  auto Index = linkCombinedIndex();
1046 
1047  // Save temps: index.
1048  if (!SaveTempsDir.empty()) {
1049  auto SaveTempPath = SaveTempsDir + "index.bc";
1050  std::error_code EC;
1051  raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
1052  if (EC)
1053  report_fatal_error(Twine("Failed to open ") + SaveTempPath +
1054  " to save optimized bitcode\n");
1055  WriteIndexToFile(*Index, OS);
1056  }
1057 
1058 
1059  // Prepare the module map.
1060  auto ModuleMap = generateModuleMap(Modules);
1061  auto ModuleCount = Modules.size();
1062 
1063  // Collect for each module the list of function it defines (GUID -> Summary).
1064  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1065  Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1066 
1067  // Convert the preserved symbols set from string to GUID, this is needed for
1068  // computing the caching hash and the internalization.
1069  DenseSet<GlobalValue::GUID> GUIDPreservedSymbols;
1070  for (const auto &M : Modules)
1071  computeGUIDPreservedSymbols(*M, PreservedSymbols, TMBuilder.TheTriple,
1072  GUIDPreservedSymbols);
1073 
1074  // Add used symbol from inputs to the preserved symbols.
1075  for (const auto &M : Modules)
1076  addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
1077 
1078  // Compute "dead" symbols, we don't want to import/export these!
1079  computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
1080 
1081  // Synthesize entry counts for functions in the combined index.
1083 
1084  // Currently there is no support for enabling whole program visibility via a
1085  // linker option in the old LTO API, but this call allows it to be specified
1086  // via the internal option. Must be done before WPD below.
1088  /* WholeProgramVisibilityEnabledInLTO */ false,
1089  // FIXME: This needs linker information via a
1090  // TBD new interface.
1091  /* DynamicExportSymbols */ {});
1092 
1093  // Perform index-based WPD. This will return immediately if there are
1094  // no index entries in the typeIdMetadata map (e.g. if we are instead
1095  // performing IR-based WPD in hybrid regular/thin LTO mode).
1096  std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
1097  std::set<GlobalValue::GUID> ExportedGUIDs;
1098  runWholeProgramDevirtOnIndex(*Index, ExportedGUIDs, LocalWPDTargetsMap);
1099  for (auto GUID : ExportedGUIDs)
1100  GUIDPreservedSymbols.insert(GUID);
1101 
1102  // Collect the import/export lists for all modules from the call-graph in the
1103  // combined index.
1104  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1105  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1106  ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists,
1107  ExportLists);
1108 
1109  // We use a std::map here to be able to have a defined ordering when
1110  // producing a hash for the cache entry.
1111  // FIXME: we should be able to compute the caching hash for the entry based
1112  // on the index, and nuke this map.
1114 
1116  computePrevailingCopies(*Index, PrevailingCopy);
1117 
1118  // Resolve prevailing symbols, this has to be computed early because it
1119  // impacts the caching.
1120  resolvePrevailingInIndex(*Index, ResolvedODR, GUIDPreservedSymbols,
1121  PrevailingCopy);
1122 
1123  // Use global summary-based analysis to identify symbols that can be
1124  // internalized (because they aren't exported or preserved as per callback).
1125  // Changes are made in the index, consumed in the ThinLTO backends.
1127  IsExported(ExportLists, GUIDPreservedSymbols),
1128  LocalWPDTargetsMap);
1130  *Index, IsExported(ExportLists, GUIDPreservedSymbols),
1131  IsPrevailing(PrevailingCopy));
1132 
1133  thinLTOPropagateFunctionAttrs(*Index, IsPrevailing(PrevailingCopy));
1134 
1135  // Make sure that every module has an entry in the ExportLists, ImportList,
1136  // GVSummary and ResolvedODR maps to enable threaded access to these maps
1137  // below.
1138  for (auto &Module : Modules) {
1139  auto ModuleIdentifier = Module->getName();
1140  ExportLists[ModuleIdentifier];
1141  ImportLists[ModuleIdentifier];
1142  ResolvedODR[ModuleIdentifier];
1143  ModuleToDefinedGVSummaries[ModuleIdentifier];
1144  }
1145 
1146  std::vector<BitcodeModule *> ModulesVec;
1147  ModulesVec.reserve(Modules.size());
1148  for (auto &Mod : Modules)
1149  ModulesVec.push_back(&Mod->getSingleBitcodeModule());
1150  std::vector<int> ModulesOrdering = lto::generateModulesOrdering(ModulesVec);
1151 
1154 
1155  TimeTraceScopeExit.release();
1156 
1157  // Parallel optimizer + codegen
1158  {
1159  ThreadPool Pool(heavyweight_hardware_concurrency(ThreadCount));
1160  for (auto IndexCount : ModulesOrdering) {
1161  auto &Mod = Modules[IndexCount];
1162  Pool.async([&](int count) {
1163  auto ModuleIdentifier = Mod->getName();
1164  auto &ExportList = ExportLists[ModuleIdentifier];
1165 
1166  auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1167 
1168  // The module may be cached, this helps handling it.
1169  ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
1170  ImportLists[ModuleIdentifier], ExportList,
1171  ResolvedODR[ModuleIdentifier],
1172  DefinedGVSummaries, OptLevel, Freestanding,
1173  TMBuilder);
1174  auto CacheEntryPath = CacheEntry.getEntryPath();
1175 
1176  {
1177  auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1178  LLVM_DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss")
1179  << " '" << CacheEntryPath << "' for buffer "
1180  << count << " " << ModuleIdentifier << "\n");
1181 
1182  if (ErrOrBuffer) {
1183  // Cache Hit!
1184  if (SavedObjectsDirectoryPath.empty())
1185  ProducedBinaries[count] = std::move(ErrOrBuffer.get());
1186  else
1187  ProducedBinaryFiles[count] = writeGeneratedObject(
1188  count, CacheEntryPath, *ErrOrBuffer.get());
1189  return;
1190  }
1191  }
1192 
1194  Context.setDiscardValueNames(LTODiscardValueNames);
1195  Context.enableDebugTypeODRUniquing();
1196  auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(
1199  if (!DiagFileOrErr) {
1200  errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
1201  report_fatal_error("ThinLTO: Can't get an output file for the "
1202  "remarks");
1203  }
1204 
1205  // Parse module now
1206  auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
1207  /*IsImporting*/ false);
1208 
1209  // Save temps: original file.
1210  saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
1211 
1212  auto &ImportList = ImportLists[ModuleIdentifier];
1213  // Run the main process now, and generates a binary
1214  auto OutputBuffer = ProcessThinLTOModule(
1215  *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
1216  ExportList, GUIDPreservedSymbols,
1217  ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1218  DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
1219  UseNewPM, DebugPassManager);
1220 
1221  // Commit to the cache (if enabled)
1222  CacheEntry.write(*OutputBuffer);
1223 
1224  if (SavedObjectsDirectoryPath.empty()) {
1225  // We need to generated a memory buffer for the linker.
1226  if (!CacheEntryPath.empty()) {
1227  // When cache is enabled, reload from the cache if possible.
1228  // Releasing the buffer from the heap and reloading it from the
1229  // cache file with mmap helps us to lower memory pressure.
1230  // The freed memory can be used for the next input file.
1231  // The final binary link will read from the VFS cache (hopefully!)
1232  // or from disk (if the memory pressure was too high).
1233  auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1234  if (auto EC = ReloadedBufferOrErr.getError()) {
1235  // On error, keep the preexisting buffer and print a diagnostic.
1236  errs() << "remark: can't reload cached file '" << CacheEntryPath
1237  << "': " << EC.message() << "\n";
1238  } else {
1239  OutputBuffer = std::move(*ReloadedBufferOrErr);
1240  }
1241  }
1242  ProducedBinaries[count] = std::move(OutputBuffer);
1243  return;
1244  }
1245  ProducedBinaryFiles[count] = writeGeneratedObject(
1246  count, CacheEntryPath, *OutputBuffer);
1247  }, IndexCount);
1248  }
1249  }
1250 
1251  pruneCache(CacheOptions.Path, CacheOptions.Policy);
1252 
1253  // If statistics were requested, print them out now.
1257 }
llvm::RemarksPasses
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"))
Definition: ThinLTOCodeGenerator.cpp:82
llvm::ThinLTOCodeGenerator::CachingOptions
Definition: ThinLTOCodeGenerator.h:125
llvm::ThinLTOCodeGenerator::promote
void promote(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform promotion and renaming of exported internal functions, and additionally resolve weak and link...
Definition: ThinLTOCodeGenerator.cpp:731
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:475
llvm::TargetMachineBuilder::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: ThinLTOCodeGenerator.h:41
FunctionImportUtils.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
PassBuilder.h
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:945
llvm::reportAndResetTimings
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
Definition: PassTimingInfo.cpp:162
llvm::ThinLTOCodeGenerator::run
void run()
Process all the modules that were added to the code generator in parallel.
Definition: ThinLTOCodeGenerator.cpp:999
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::TargetMachineBuilder::MAttr
std::string MAttr
Definition: ThinLTOCodeGenerator.h:38
llvm::OptimizationLevel::O1
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
Definition: OptimizationLevel.h:57
llvm::ThinLTOCodeGenerator::crossReferenceSymbol
void crossReferenceSymbol(StringRef Name)
Adds to a list of all global symbols that are cross-referenced between ThinLTO files.
Definition: ThinLTOCodeGenerator.cpp:631
llvm::thinLTOInternalizeModule
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
Definition: FunctionImport.cpp:1147
llvm::MemoryBuffer::getOpenFile
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.
Definition: MemoryBuffer.cpp:494
llvm::sys::fs::OF_None
@ OF_None
Definition: FileSystem.h:757
llvm::GlobalValue::getGlobalIdentifier
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
Definition: Globals.cpp:164
llvm::ThinLTOCodeGenerator::writeGeneratedObject
std::string writeGeneratedObject(int count, StringRef CacheEntryPath, const MemoryBuffer &OutputBuffer)
Write temporary object file to SavedObjectDirectoryPath, write symlink to Cache directory if needed.
Definition: ThinLTOCodeGenerator.cpp:963
print
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Definition: ArchiveWriter.cpp:148
llvm::CGFT_ObjectFile
@ CGFT_ObjectFile
Definition: CodeGen.h:65
llvm::ThreadPool
A ThreadPool for asynchronous parallel execution on a defined number of threads.
Definition: ThreadPool.h:37
llvm::computeLTOCacheKey
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 ...
Definition: LTO.cpp:79
llvm::lto::Config::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: Config.h:55
llvm::PassManagerBuilder::VerifyOutput
bool VerifyOutput
Definition: PassManagerBuilder.h:166
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:553
llvm::renameModuleForThinLTO
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...
Definition: FunctionImportUtils.cpp:330
llvm::OptimizationLevel::O2
static const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: OptimizationLevel.h:74
llvm::Triple::x86
@ x86
Definition: Triple.h:82
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
Definition: DWP.cpp:535
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1030
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1177
Statistic.h
Path.h
FunctionImport.h
llvm::runWholeProgramDevirtOnIndex
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.
Definition: WholeProgramDevirt.cpp:882
llvm::RemarksFilename
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Definition: ThinLTOCodeGenerator.cpp:81
llvm::StandardInstrumentations::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM=nullptr)
Definition: StandardInstrumentations.cpp:2120
SmallVectorMemoryBuffer.h
llvm::lto::InputFile::getSingleBitcodeModule
BitcodeModule & getSingleBitcodeModule()
Definition: LTO.cpp:505
llvm::PassManagerBuilder::LoopVectorize
bool LoopVectorize
Definition: PassManagerBuilder.h:159
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:38
llvm::TargetMachineBuilder
Helper to gather options relevant to the target machine creation.
Definition: ThinLTOCodeGenerator.h:35
Error.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::ThinLTOCodeGenerator::CachingOptions::Policy
CachePruningPolicy Policy
Definition: ThinLTOCodeGenerator.h:127
llvm::heavyweight_hardware_concurrency
ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)
Returns a thread strategy for tasks requiring significant memory or other resources.
Definition: Threading.h:165
llvm::ThinLTOCodeGenerator::crossModuleImport
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform cross-module importing for the module identified by ModuleIdentifier.
Definition: ThinLTOCodeGenerator.cpp:781
llvm::DK_Linker
@ DK_Linker
Definition: DiagnosticInfo.h:60
llvm::PassManagerBuilder::ImportSummary
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
Definition: PassManagerBuilder.h:154
llvm::StringMap::end
iterator end()
Definition: StringMap.h:203
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:83
llvm::RemarksHotnessThreshold
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)
Definition: ThinLTOCodeGenerator.cpp:85
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
llvm::ThinLTOCodeGenerator::emitImports
void emitImports(Module &Module, StringRef OutputName, ModuleSummaryIndex &Index, const lto::InputFile &File)
Compute and emit the imported files for module at ModulePath.
Definition: ThinLTOCodeGenerator.cpp:849
llvm::lto::Config
LTO configuration.
Definition: Config.h:40
llvm::Optional
Definition: APInt.h:33
llvm::lto::Config::Freestanding
bool Freestanding
Flag to indicate that the optimizer should not assume builtins are present on the target.
Definition: Config.h:65
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:48
llvm::RemarksWithHotness
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:83
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:894
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:33
llvm::FunctionImporter
The function importer is automatically importing function from other modules based on the provided su...
Definition: FunctionImport.h:33
llvm::lto::setupLLVMOptimizationRemarks
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.
Definition: LTO.cpp:1578
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::Triple::merge
std::string merge(const Triple &Other) const
Merge target triples.
Definition: Triple.cpp:1676
llvm::thinLTOResolvePrevailingInIndex
void thinLTOResolvePrevailingInIndex(const lto::Config &C, ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing, function_ref< void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)> recordNewLinkage, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Resolve linkage for prevailing symbols in the Index.
Definition: LTO.cpp:399
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
ModuleSummaryAnalysis.h
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:216
llvm::gatherImportedSummariesForModule
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.
Definition: FunctionImport.cpp:979
llvm::Triple::aarch64_32
@ aarch64_32
Definition: Triple.h:53
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::OptimizationLevel::O0
static const OptimizationLevel O0
Disable as many optimizations as possible.
Definition: OptimizationLevel.h:41
llvm::TargetRegistry::lookupTarget
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Definition: TargetRegistry.cpp:62
LegacyPassManager.h
llvm::detail::DenseSetImpl::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
PassManagerBuilder.h
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
BitcodeWriterPass.h
Internalize.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::EmitImportsFiles
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.
Definition: FunctionImport.cpp:1003
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::TargetMachineBuilder::Options
TargetOptions Options
Definition: ThinLTOCodeGenerator.h:39
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
AliasAnalysis.h
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:457
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
PassTimingInfo.h
llvm::Triple::isCompatibleWith
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
Definition: Triple.cpp:1652
CommandLine.h
llvm::GlobalValueSummary
Function and variable summary information to aid decisions and implementation of importing.
Definition: ModuleSummaryIndex.h:290
CachePruning.h
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1649
llvm::AreStatisticsEnabled
bool AreStatisticsEnabled()
Check if statistics are enabled.
Definition: Statistic.cpp:138
SubtargetFeature.h
llvm::writeFileAtomically
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...
Definition: FileUtilities.cpp:289
TargetMachine.h
llvm::PassManagerBuilder::LibraryInfo
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Definition: PassManagerBuilder.h:140
llvm::Triple::str
const std::string & str() const
Definition: Triple.h:367
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::Triple::isOSDarwin
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
Definition: Triple.h:468
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:47
BitcodeWriter.h
llvm::ThinLTOCodeGenerator::internalize
void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
Definition: ThinLTOCodeGenerator.cpp:890
llvm::timeTraceProfilerBegin
void timeTraceProfilerBegin(StringRef Name, StringRef Detail)
Manually begin a time section, with the given Name and Detail.
Definition: TimeProfiler.cpp:315
llvm::LTODiscardValueNames
cl::opt< bool > LTODiscardValueNames("lto-discard-value-names", cl::desc("Strip names from Value during LTO (other than GlobalValue)."), cl::init(false), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:80
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::lto::Config::Options
TargetOptions Options
Definition: Config.h:48
llvm::PassBuilder
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:94
llvm::SMDiagnostic
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:251
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:183
HotnessThresholdParser.h
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
TargetLibraryInfo.h
llvm::computeSyntheticCounts
void computeSyntheticCounts(ModuleSummaryIndex &Index)
Compute synthetic function entry counts.
Definition: SummaryBasedOptimizations.cpp:47
llvm::thinLTOInternalizeAndPromoteInIndex
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...
Definition: LTO.cpp:459
llvm::make_scope_exit
LLVM_NODISCARD detail::scope_exit< typename std::decay< Callable >::type > make_scope_exit(Callable &&F)
Definition: ScopeExit.h:58
llvm::sys::fs::create_directories
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.
Definition: Path.cpp:964
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: DiagnosticInfo.h:45
llvm::WriteIndexToFile
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 ...
Definition: BitcodeWriter.cpp:4671
llvm::thinLTOFinalizeInModule
void thinLTOFinalizeInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals, bool PropagateAttrs)
Based on the information recorded in the summaries during global summary-based analysis:
Definition: FunctionImport.cpp:1054
llvm::lto::InputFile::create
static Expected< std::unique_ptr< InputFile > > create(MemoryBufferRef Object)
Create an InputFile.
Definition: LTO.cpp:472
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::PassManagerBuilder::Inliner
Pass * Inliner
Inliner - Specifies the inliner to use.
Definition: PassManagerBuilder.h:144
llvm::sys::fs::openNativeFileForRead
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.
llvm::Triple::getArchName
StringRef getArchName() const
Get the architecture (first) component of the triple.
Definition: Triple.cpp:1047
llvm::MemoryBuffer::getBuffer
StringRef getBuffer() const
Definition: MemoryBuffer.h:69
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition: DiagnosticInfo.h:103
llvm::DiagnosticPrinter
Interface for custom diagnostic printing.
Definition: DiagnosticPrinter.h:31
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:311
llvm::SubtargetFeatures::getDefaultSubtargetFeatures
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
Definition: SubtargetFeature.cpp:70
llvm::AtomicFileWriteError
Definition: FileUtilities.h:85
llvm::None
const NoneType None
Definition: None.h:23
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:48
llvm::sys::fs::create_hard_link
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
llvm::ThinLTOCodeGenerator::preserveSymbol
void preserveSymbol(StringRef Name)
Adds to a list of all global symbols that must exist in the final generated code.
Definition: ThinLTOCodeGenerator.cpp:627
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition: ModuleSummaryIndex.h:168
llvm::SmallString< 128 >
llvm::RemarksFormat
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"))
Definition: ThinLTOCodeGenerator.cpp:86
computeDeadSymbolsInIndex
static void computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Definition: ThinLTOCodeGenerator.cpp:714
llvm::createFunctionInliningPass
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Definition: InlineSimple.cpp:97
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::PassManagerBuilder
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
Definition: PassManagerBuilder.h:58
llvm::lto::Config::OptLevel
unsigned OptLevel
Definition: Config.h:57
llvm::createTargetTransformInfoWrapperPass
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
Definition: TargetTransformInfo.cpp:1204
llvm::updateVCallVisibilityInIndex
void updateVCallVisibilityInIndex(ModuleSummaryIndex &Index, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols)
If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable def...
Definition: WholeProgramDevirt.cpp:863
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::GlobalValue::isWeakForLinker
bool isWeakForLinker() const
Definition: GlobalValue.h:473
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::SubtargetFeatures::getString
std::string getString() const
Returns features as a string.
Definition: SubtargetFeature.cpp:54
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
ThreadPool.h
llvm::cl::opt< bool >
llvm::SmallString::c_str
const char * c_str()
Definition: SmallString.h:262
IRObjectFile.h
llvm::Module::getName
StringRef getName() const
Get a short "name" for the module.
Definition: Module.h:242
VI
@ VI
Definition: SIInstrInfo.cpp:7658
Threading.h
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:430
llvm::StandardInstrumentations
This class provides an interface to register all the standard pass instrumentations and manages their...
Definition: StandardInstrumentations.h:496
llvm::sys::fs::exists
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1074
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
llvm::count
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...
Definition: STLExtras.h:1732
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
ProfileSummaryInfo.h
llvm::computeDeadSymbolsWithConstProp
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.
Definition: FunctionImport.cpp:966
llvm::remarks::HotnessThresholdParser
Definition: HotnessThresholdParser.h:45
IPO.h
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:412
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:58
StringExtras.h
llvm::detail::DenseSetImpl::empty
bool empty() const
Definition: DenseSet.h:80
llvm::PassBuilder::buildThinLTODefaultPipeline
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1355
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
llvm::PassManagerBuilder::OptLevel
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Definition: PassManagerBuilder.h:131
ToolOutputFile.h
llvm::ThinLTOCodeGenerator::gatherImportedSummariesForModule
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.
Definition: ThinLTOCodeGenerator.cpp:815
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:80
llvm::PipelineTuningOptions::SLPVectorization
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:53
SI
StandardInstrumentations SI(Debug, VerifyEach)
PreservedSymbols
static const char * PreservedSymbols[]
Definition: IRSymtab.cpp:44
llvm::sys::fs::closeFile
std::error_code closeFile(file_t &F)
Close the file object.
llvm::Module::getModuleIdentifier
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:225
llvm::PassManagerBuilder::VerifyInput
bool VerifyInput
Definition: PassManagerBuilder.h:165
llvm::updateIndexWPDForExports
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...
Definition: WholeProgramDevirt.cpp:888
llvm::lto::Config::MAttrs
std::vector< std::string > MAttrs
Definition: Config.h:49
llvm::GlobalValue::isAvailableExternallyLinkage
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:302
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::StringMapImpl::size
unsigned size() const
Definition: StringMap.h:93
llvm::PrevailingType::Unknown
@ Unknown
llvm::PrintStatistics
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
Definition: Statistic.cpp:228
Mangler.h
llvm::WriteBitcodeToFile
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.
Definition: BitcodeWriter.cpp:4626
llvm::sys::fs::remove
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:22
llvm::lto::Config::RelocModel
Optional< Reloc::Model > RelocModel
Definition: Config.h:53
FileUtilities.h
llvm::PassManagerBuilder::SLPVectorize
bool SLPVectorize
Definition: PassManagerBuilder.h:158
llvm::PIELevel::Default
@ Default
Definition: CodeGen.h:37
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::ThreadPool::async
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
Definition: ThreadPool.h:51
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:569
llvm::ThinLTOCodeGenerator::linkCombinedIndex
std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
Definition: ThinLTOCodeGenerator.cpp:664
uint32_t
llvm::OptimizationLevel::O3
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
Definition: OptimizationLevel.h:89
llvm::PipelineTuningOptions::LoopVectorization
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:49
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:443
LAM
LoopAnalysisManager LAM
Definition: PassBuilderBindings.cpp:58
llvm::sys::fs::OF_UpdateAtime
@ OF_UpdateAtime
Force files Atime to be updated on access.
Definition: FileSystem.h:785
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1676
llvm::PassManager< Module >
llvm::logAllUnhandledErrors
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition: Error.cpp:61
llvm::GlobalValueSummaryList
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
Definition: ModuleSummaryIndex.h:124
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:444
ThinLTOCodeGenerator.h
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:228
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
Verifier.h
llvm::TargetLibraryInfoImpl::disableAllFunctions
void disableAllFunctions()
Disables all builtins.
Definition: TargetLibraryInfo.cpp:1818
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
LLVMRemarkStreamer.h
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end
iterator end()
Definition: DenseMap.h:83
llvm::ThinLTOCodeGenerator::optimize
void optimize(Module &Module)
Perform post-importing ThinLTO optimizations.
Definition: ThinLTOCodeGenerator.cpp:951
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::legacy::PassManager
PassManager manages ModulePassManagers.
Definition: LegacyPassManager.h:52
llvm::thinLTOPropagateFunctionAttrs
bool thinLTOPropagateFunctionAttrs(ModuleSummaryIndex &Index, function_ref< bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing)
Propagate function attributes for function summaries along the index's callgraph during thinlink.
Definition: FunctionAttrs.cpp:437
llvm::timeTraceProfilerEnabled
bool timeTraceProfilerEnabled()
Is the time trace profiler enabled, i.e. initialized?
Definition: TimeProfiler.h:33
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:259
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:517
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:421
llvm::TargetMachineBuilder::MCpu
std::string MCpu
Definition: ThinLTOCodeGenerator.h:37
llvm::OptimizationLevel
Definition: OptimizationLevel.h:22
llvm::TargetMachineBuilder::create
std::unique_ptr< TargetMachine > create() const
Definition: ThinLTOCodeGenerator.cpp:639
llvm::object::Identifier
@ Identifier
Definition: COFFModuleDefinition.cpp:36
DP
So we should use XX3Form_Rcr to implement instrinsic Convert DP outs ins xscvdpsp No builtin are required Round &Convert QP DP(dword[1] is set to zero) No builtin are required Round to Quad Precision because you need to assign rounding mode in instruction Provide builtin(set f128:$vT,(int_ppc_vsx_xsrqpi f128:$vB))(set f128 yields< n x< ty > >< result > yields< ty >< result > No builtin are required Load Store load store see def memrix16 in PPCInstrInfo td Load Store Vector load store outs ins lxsdx set load store with conversion from to DP
Definition: README_P9.txt:520
llvm::buildModuleSummaryIndex
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.
Definition: ModuleSummaryAnalysis.cpp:679
llvm::sys::fs::is_directory
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition: Path.cpp:1089
llvm::legacy::PassManager::add
void add(Pass *P) override
Add a pass to the queue of passes to run.
Definition: LegacyPassManager.cpp:1670
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:845
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:259
llvm::Module::getPIELevel
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition: Module.cpp:605
WholeProgramDevirt.h
llvm::PassManager::run
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Definition: PassManager.h:501
SHA1.h
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::errorToErrorCode
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Definition: Error.cpp:96
llvm::TargetMachineBuilder::RelocModel
Optional< Reloc::Model > RelocModel
Definition: ThinLTOCodeGenerator.h:40
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:599
llvm::lto::generateModulesOrdering
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Definition: LTO.cpp:1622
ObjCARC.h
LTO.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1088
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
llvm::Module::getTargetTriple
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:255
llvm::PassBuilder::crossRegisterProxies
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Definition: PassBuilder.cpp:1565
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::TargetMachineBuilder::TheTriple
Triple TheTriple
Definition: ThinLTOCodeGenerator.h:36
IRReader.h
TargetTransformInfo.h
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:661
llvm::sys::path::remove_filename
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition: Path.cpp:475
ScopeExit.h
llvm::legacy::PassManager::run
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition: LegacyPassManager.cpp:1676
llvm::ComputeCrossModuleImport
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.
Definition: FunctionImport.cpp:656
llvm::timeTraceProfilerEnd
void timeTraceProfilerEnd()
Manually end the last time section.
Definition: TimeProfiler.cpp:327
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::pruneCache
bool pruneCache(StringRef Path, CachePruningPolicy Policy)
Peform pruning using the supplied policy, returns true if pruning occurred, i.e.
Definition: CachePruning.cpp:144
llvm::PassManagerBuilder::populateThinLTOPassManager
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
Definition: PassManagerBuilder.cpp:1178
llvm::lto::Config::CPU
std::string CPU
Definition: Config.h:47
LLVMContext.h
llvm::createObjCARCContractPass
Pass * createObjCARCContractPass()
Definition: ObjCARCContract.cpp:739
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
BitcodeReader.h
SummaryBasedOptimizations.h
DiagnosticPrinter.h
TargetRegistry.h
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:968
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
FunctionAttrs.h
llvm::DS_Error
@ DS_Error
Definition: DiagnosticInfo.h:46
Debug.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:440
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:51
llvm::sys::fs::copy_file
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
Definition: Path.cpp:1013
llvm::verifyModule
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:5929
llvm::ThinLTOCodeGenerator::CachingOptions::Path
std::string Path
Definition: ThinLTOCodeGenerator.h:126
StandardInstrumentations.h
llvm::lto::InputFile
An input file.
Definition: LTO.h:105
llvm::Target::createTargetMachine
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.
Definition: TargetRegistry.h:449
llvm::Module::size
size_t size() const
Definition: Module.h:628