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"
46 #include "llvm/Support/Debug.h"
47 #include "llvm/Support/Error.h"
49 #include "llvm/Support/Path.h"
50 #include "llvm/Support/SHA1.h"
54 #include "llvm/Support/Threading.h"
57 #include "llvm/Transforms/IPO.h"
64 
65 #include <numeric>
66 
67 #if !defined(_MSC_VER) && !defined(__MINGW32__)
68 #include <unistd.h>
69 #else
70 #include <io.h>
71 #endif
72 
73 using namespace llvm;
74 
75 #define DEBUG_TYPE "thinlto"
76 
77 namespace llvm {
78 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
86 }
87 
88 namespace {
89 
90 // Default to using all available threads in the system, but using only one
91 // thred per core, as indicated by the usage of
92 // heavyweight_hardware_concurrency() below.
93 static cl::opt<int> ThreadCount("threads", cl::init(0));
94 
95 // Simple helper to save temporary files for debug.
96 static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
97  unsigned count, StringRef Suffix) {
98  if (TempDir.empty())
99  return;
100  // User asked to save temps, let dump the bitcode file after import.
101  std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str();
102  std::error_code EC;
103  raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
104  if (EC)
105  report_fatal_error(Twine("Failed to open ") + SaveTempPath +
106  " to save optimized bitcode\n");
107  WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
108 }
109 
110 static const GlobalValueSummary *
111 getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
112  // If there is any strong definition anywhere, get it.
113  auto StrongDefForLinker = llvm::find_if(
114  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
115  auto Linkage = Summary->linkage();
118  });
119  if (StrongDefForLinker != GVSummaryList.end())
120  return StrongDefForLinker->get();
121  // Get the first *linker visible* definition for this global in the summary
122  // list.
123  auto FirstDefForLinker = llvm::find_if(
124  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
125  auto Linkage = Summary->linkage();
127  });
128  // Extern templates can be emitted as available_externally.
129  if (FirstDefForLinker == GVSummaryList.end())
130  return nullptr;
131  return FirstDefForLinker->get();
132 }
133 
134 // Populate map of GUID to the prevailing copy for any multiply defined
135 // symbols. Currently assume first copy is prevailing, or any strong
136 // definition. Can be refined with Linker information in the future.
137 static void computePrevailingCopies(
138  const ModuleSummaryIndex &Index,
140  auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
141  return GVSummaryList.size() > 1;
142  };
143 
144  for (auto &I : Index) {
145  if (HasMultipleCopies(I.second.SummaryList))
146  PrevailingCopy[I.first] =
147  getFirstDefinitionForLinker(I.second.SummaryList);
148  }
149 }
150 
152 generateModuleMap(std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
153  StringMap<lto::InputFile *> ModuleMap;
154  for (auto &M : Modules) {
155  assert(ModuleMap.find(M->getName()) == ModuleMap.end() &&
156  "Expect unique Buffer Identifier");
157  ModuleMap[M->getName()] = M.get();
158  }
159  return ModuleMap;
160 }
161 
162 static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index,
163  bool ClearDSOLocalOnDeclarations) {
164  if (renameModuleForThinLTO(TheModule, Index, ClearDSOLocalOnDeclarations))
165  report_fatal_error("renameModuleForThinLTO failed");
166 }
167 
168 namespace {
169 class ThinLTODiagnosticInfo : public DiagnosticInfo {
170  const Twine &Msg;
171 public:
172  ThinLTODiagnosticInfo(const Twine &DiagMsg,
173  DiagnosticSeverity Severity = DS_Error)
174  : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
175  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
176 };
177 }
178 
179 /// Verify the module and strip broken debug info.
180 static void verifyLoadedModule(Module &TheModule) {
181  bool BrokenDebugInfo = false;
182  if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
183  report_fatal_error("Broken module found, compilation aborted!");
184  if (BrokenDebugInfo) {
185  TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
186  "Invalid debug info found, debug info will be stripped", DS_Warning));
187  StripDebugInfo(TheModule);
188  }
189 }
190 
191 static std::unique_ptr<Module> loadModuleFromInput(lto::InputFile *Input,
193  bool Lazy,
194  bool IsImporting) {
195  auto &Mod = Input->getSingleBitcodeModule();
196  SMDiagnostic Err;
197  Expected<std::unique_ptr<Module>> ModuleOrErr =
198  Lazy ? Mod.getLazyModule(Context,
199  /* ShouldLazyLoadMetadata */ true, IsImporting)
200  : Mod.parseModule(Context);
201  if (!ModuleOrErr) {
202  handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
203  SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
204  SourceMgr::DK_Error, EIB.message());
205  Err.print("ThinLTO", errs());
206  });
207  report_fatal_error("Can't load module, abort.");
208  }
209  if (!Lazy)
210  verifyLoadedModule(*ModuleOrErr.get());
211  return std::move(*ModuleOrErr);
212 }
213 
214 static void
215 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
216  StringMap<lto::InputFile *> &ModuleMap,
217  const FunctionImporter::ImportMapTy &ImportList,
218  bool ClearDSOLocalOnDeclarations) {
219  auto Loader = [&](StringRef Identifier) {
220  auto &Input = ModuleMap[Identifier];
221  return loadModuleFromInput(Input, TheModule.getContext(),
222  /*Lazy=*/true, /*IsImporting*/ true);
223  };
224 
225  FunctionImporter Importer(Index, Loader, ClearDSOLocalOnDeclarations);
226  Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
227  if (!Result) {
228  handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) {
229  SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
230  SourceMgr::DK_Error, EIB.message());
231  Err.print("ThinLTO", errs());
232  });
233  report_fatal_error("importFunctions failed");
234  }
235  // Verify again after cross-importing.
236  verifyLoadedModule(TheModule);
237 }
238 
239 static void optimizeModule(Module &TheModule, TargetMachine &TM,
240  unsigned OptLevel, bool Freestanding,
242  // Populate the PassManager
243  PassManagerBuilder PMB;
244  PMB.LibraryInfo = new TargetLibraryInfoImpl(TM.getTargetTriple());
245  if (Freestanding)
248  // FIXME: should get it from the bitcode?
249  PMB.OptLevel = OptLevel;
250  PMB.LoopVectorize = true;
251  PMB.SLPVectorize = true;
252  // Already did this in verifyLoadedModule().
253  PMB.VerifyInput = false;
254  PMB.VerifyOutput = false;
255  PMB.ImportSummary = Index;
256 
258 
259  // Add the TTI (required to inform the vectorizer about register size for
260  // instance)
261  PM.add(createTargetTransformInfoWrapperPass(TM.getTargetIRAnalysis()));
262 
263  // Add optimizations
265 
266  PM.run(TheModule);
267 }
268 
269 static void optimizeModuleNewPM(Module &TheModule, TargetMachine &TM,
270  unsigned OptLevel, bool Freestanding,
271  bool DebugPassManager,
273  Optional<PGOOptions> PGOOpt;
278 
280  StandardInstrumentations SI(DebugPassManager);
283  PTO.LoopVectorization = true;
284  PTO.SLPVectorization = true;
285  PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
286 
287  std::unique_ptr<TargetLibraryInfoImpl> TLII(
288  new TargetLibraryInfoImpl(Triple(TM.getTargetTriple())));
289  if (Freestanding)
290  TLII->disableAllFunctions();
291  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
292 
294 
295  // Register the AA manager first so that our version is the one used.
296  FAM.registerPass([&] { return std::move(AA); });
297 
298  // Register all the basic analyses with the managers.
304 
306 
308 
309  switch (OptLevel) {
310  default:
311  llvm_unreachable("Invalid optimization level");
312  case 0:
314  break;
315  case 1:
317  break;
318  case 2:
320  break;
321  case 3:
323  break;
324  }
325 
327 
328  MPM.run(TheModule, MAM);
329 }
330 
331 static void
332 addUsedSymbolToPreservedGUID(const lto::InputFile &File,
333  DenseSet<GlobalValue::GUID> &PreservedGUID) {
334  for (const auto &Sym : File.symbols()) {
335  if (Sym.isUsed())
336  PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
337  }
338 }
339 
340 // Convert the PreservedSymbols map from "Name" based to "GUID" based.
341 static void computeGUIDPreservedSymbols(const lto::InputFile &File,
342  const StringSet<> &PreservedSymbols,
343  const Triple &TheTriple,
345  // Iterate the symbols in the input file and if the input has preserved symbol
346  // compute the GUID for the symbol.
347  for (const auto &Sym : File.symbols()) {
348  if (PreservedSymbols.count(Sym.getName()) && !Sym.getIRName().empty())
350  Sym.getIRName(), GlobalValue::ExternalLinkage, "")));
351  }
352 }
353 
355 computeGUIDPreservedSymbols(const lto::InputFile &File,
356  const StringSet<> &PreservedSymbols,
357  const Triple &TheTriple) {
358  DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
359  computeGUIDPreservedSymbols(File, PreservedSymbols, TheTriple,
360  GUIDPreservedSymbols);
361  return GUIDPreservedSymbols;
362 }
363 
364 std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
365  TargetMachine &TM) {
366  SmallVector<char, 128> OutputBuffer;
367 
368  // CodeGen
369  {
370  raw_svector_ostream OS(OutputBuffer);
372 
373  // If the bitcode files contain ARC code and were compiled with optimization,
374  // the ObjCARCContractPass must be run, so do it unconditionally here.
376 
377  // Setup the codegen now.
378  if (TM.addPassesToEmitFile(PM, OS, nullptr, CGFT_ObjectFile,
379  /* DisableVerify */ true))
380  report_fatal_error("Failed to setup codegen");
381 
382  // Run codegen now. resulting binary is in OutputBuffer.
383  PM.run(TheModule);
384  }
385  return std::make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
386 }
387 
388 /// Manage caching for a single Module.
389 class ModuleCacheEntry {
390  SmallString<128> EntryPath;
391 
392 public:
393  // Create a cache entry. This compute a unique hash for the Module considering
394  // the current list of export/import, and offer an interface to query to
395  // access the content in the cache.
396  ModuleCacheEntry(
397  StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID,
398  const FunctionImporter::ImportMapTy &ImportList,
399  const FunctionImporter::ExportSetTy &ExportList,
400  const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
401  const GVSummaryMapTy &DefinedGVSummaries, unsigned OptLevel,
402  bool Freestanding, const TargetMachineBuilder &TMBuilder) {
403  if (CachePath.empty())
404  return;
405 
406  if (!Index.modulePaths().count(ModuleID))
407  // The module does not have an entry, it can't have a hash at all
408  return;
409 
410  if (all_of(Index.getModuleHash(ModuleID),
411  [](uint32_t V) { return V == 0; }))
412  // No hash entry, no caching!
413  return;
414 
415  llvm::lto::Config Conf;
416  Conf.OptLevel = OptLevel;
417  Conf.Options = TMBuilder.Options;
418  Conf.CPU = TMBuilder.MCpu;
419  Conf.MAttrs.push_back(TMBuilder.MAttr);
420  Conf.RelocModel = TMBuilder.RelocModel;
421  Conf.CGOptLevel = TMBuilder.CGOptLevel;
422  Conf.Freestanding = Freestanding;
424  computeLTOCacheKey(Key, Conf, Index, ModuleID, ImportList, ExportList,
425  ResolvedODR, DefinedGVSummaries);
426 
427  // This choice of file name allows the cache to be pruned (see pruneCache()
428  // in include/llvm/Support/CachePruning.h).
429  sys::path::append(EntryPath, CachePath, "llvmcache-" + Key);
430  }
431 
432  // Access the path to this entry in the cache.
433  StringRef getEntryPath() { return EntryPath; }
434 
435  // Try loading the buffer for this cache entry.
436  ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
437  if (EntryPath.empty())
438  return std::error_code();
439  SmallString<64> ResultPath;
441  Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
442  if (!FDOrErr)
443  return errorToErrorCode(FDOrErr.takeError());
445  *FDOrErr, EntryPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
446  sys::fs::closeFile(*FDOrErr);
447  return MBOrErr;
448  }
449 
450  // Cache the Produced object file
451  void write(const MemoryBuffer &OutputBuffer) {
452  if (EntryPath.empty())
453  return;
454 
455  // Write to a temporary to avoid race condition
456  SmallString<128> TempFilename;
457  SmallString<128> CachePath(EntryPath);
459  sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
460 
461  if (auto Err = handleErrors(
462  llvm::writeFileAtomically(TempFilename, EntryPath,
463  OutputBuffer.getBuffer()),
464  [](const llvm::AtomicFileWriteError &E) {
465  std::string ErrorMsgBuffer;
466  llvm::raw_string_ostream S(ErrorMsgBuffer);
467  E.log(S);
468 
469  if (E.Error ==
470  llvm::atomic_write_error::failed_to_create_uniq_file) {
471  errs() << "Error: " << ErrorMsgBuffer << "\n";
472  report_fatal_error("ThinLTO: Can't get a temporary file");
473  }
474  })) {
475  // FIXME
476  consumeError(std::move(Err));
477  }
478  }
479 };
480 
481 static std::unique_ptr<MemoryBuffer>
482 ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
484  const FunctionImporter::ImportMapTy &ImportList,
485  const FunctionImporter::ExportSetTy &ExportList,
486  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
487  const GVSummaryMapTy &DefinedGlobals,
488  const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
489  bool DisableCodeGen, StringRef SaveTempsDir,
490  bool Freestanding, unsigned OptLevel, unsigned count,
491  bool UseNewPM, bool DebugPassManager) {
492 
493  // "Benchmark"-like optimization: single-source case
494  bool SingleModule = (ModuleMap.size() == 1);
495 
496  // When linking an ELF shared object, dso_local should be dropped. We
497  // conservatively do this for -fpic.
498  bool ClearDSOLocalOnDeclarations =
499  TM.getTargetTriple().isOSBinFormatELF() &&
500  TM.getRelocationModel() != Reloc::Static &&
501  TheModule.getPIELevel() == PIELevel::Default;
502 
503  if (!SingleModule) {
504  promoteModule(TheModule, Index, ClearDSOLocalOnDeclarations);
505 
506  // Apply summary-based prevailing-symbol resolution decisions.
507  thinLTOResolvePrevailingInModule(TheModule, DefinedGlobals);
508 
509  // Save temps: after promotion.
510  saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc");
511  }
512 
513  // Be friendly and don't nuke totally the module when the client didn't
514  // supply anything to preserve.
515  if (!ExportList.empty() || !GUIDPreservedSymbols.empty()) {
516  // Apply summary-based internalization decisions.
517  thinLTOInternalizeModule(TheModule, DefinedGlobals);
518  }
519 
520  // Save internalized bitcode
521  saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc");
522 
523  if (!SingleModule) {
524  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
525  ClearDSOLocalOnDeclarations);
526 
527  // Save temps: after cross-module import.
528  saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
529  }
530 
531  if (UseNewPM)
532  optimizeModuleNewPM(TheModule, TM, OptLevel, Freestanding, DebugPassManager,
533  &Index);
534  else
535  optimizeModule(TheModule, TM, OptLevel, Freestanding, &Index);
536 
537  saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
538 
539  if (DisableCodeGen) {
540  // Configured to stop before CodeGen, serialize the bitcode and return.
541  SmallVector<char, 128> OutputBuffer;
542  {
543  raw_svector_ostream OS(OutputBuffer);
544  ProfileSummaryInfo PSI(TheModule);
545  auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
546  WriteBitcodeToFile(TheModule, OS, true, &Index);
547  }
548  return std::make_unique<SmallVectorMemoryBuffer>(std::move(OutputBuffer));
549  }
550 
551  return codegenModule(TheModule, TM);
552 }
553 
554 /// Resolve prevailing symbols. Record resolutions in the \p ResolvedODR map
555 /// for caching, and in the \p Index for application during the ThinLTO
556 /// backends. This is needed for correctness for exported symbols (ensure
557 /// at least one copy kept) and a compile-time optimization (to drop duplicate
558 /// copies when possible).
559 static void resolvePrevailingInIndex(
561  StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
562  &ResolvedODR,
563  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
565  &PrevailingCopy) {
566 
567  auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
568  const auto &Prevailing = PrevailingCopy.find(GUID);
569  // Not in map means that there was only one copy, which must be prevailing.
570  if (Prevailing == PrevailingCopy.end())
571  return true;
572  return Prevailing->second == S;
573  };
574 
575  auto recordNewLinkage = [&](StringRef ModuleIdentifier,
576  GlobalValue::GUID GUID,
577  GlobalValue::LinkageTypes NewLinkage) {
578  ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
579  };
580 
581  // TODO Conf.VisibilityScheme can be lto::Config::ELF for ELF.
582  lto::Config Conf;
583  thinLTOResolvePrevailingInIndex(Conf, Index, isPrevailing, recordNewLinkage,
584  GUIDPreservedSymbols);
585 }
586 
587 // Initialize the TargetMachine builder for a given Triple
588 static void initTMBuilder(TargetMachineBuilder &TMBuilder,
589  const Triple &TheTriple) {
590  // Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
591  // FIXME this looks pretty terrible...
592  if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
593  if (TheTriple.getArch() == llvm::Triple::x86_64)
594  TMBuilder.MCpu = "core2";
595  else if (TheTriple.getArch() == llvm::Triple::x86)
596  TMBuilder.MCpu = "yonah";
597  else if (TheTriple.getArch() == llvm::Triple::aarch64 ||
598  TheTriple.getArch() == llvm::Triple::aarch64_32)
599  TMBuilder.MCpu = "cyclone";
600  }
601  TMBuilder.TheTriple = std::move(TheTriple);
602 }
603 
604 } // end anonymous namespace
605 
606 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
607  MemoryBufferRef Buffer(Data, Identifier);
608 
609  auto InputOrError = lto::InputFile::create(Buffer);
610  if (!InputOrError)
611  report_fatal_error("ThinLTO cannot create input file: " +
612  toString(InputOrError.takeError()));
613 
614  auto TripleStr = (*InputOrError)->getTargetTriple();
615  Triple TheTriple(TripleStr);
616 
617  if (Modules.empty())
618  initTMBuilder(TMBuilder, Triple(TheTriple));
619  else if (TMBuilder.TheTriple != TheTriple) {
620  if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
621  report_fatal_error("ThinLTO modules with incompatible triples not "
622  "supported");
623  initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
624  }
625 
626  Modules.emplace_back(std::move(*InputOrError));
627 }
628 
630  PreservedSymbols.insert(Name);
631 }
632 
634  // FIXME: At the moment, we don't take advantage of this extra information,
635  // we're conservatively considering cross-references as preserved.
636  // CrossReferencedSymbols.insert(Name);
637  PreservedSymbols.insert(Name);
638 }
639 
640 // TargetMachine factory
641 std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
642  std::string ErrMsg;
643  const Target *TheTarget =
645  if (!TheTarget) {
646  report_fatal_error("Can't load target for this Triple: " + ErrMsg);
647  }
648 
649  // Use MAttr as the default set of features.
650  SubtargetFeatures Features(MAttr);
652  std::string FeatureStr = Features.getString();
653 
654  std::unique_ptr<TargetMachine> TM(
655  TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
657  assert(TM && "Cannot create target machine");
658 
659  return TM;
660 }
661 
662 /**
663  * Produce the combined summary index from all the bitcode files:
664  * "thin-link".
665  */
666 std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
667  std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
668  std::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
669  uint64_t NextModuleId = 0;
670  for (auto &Mod : Modules) {
671  auto &M = Mod->getSingleBitcodeModule();
672  if (Error Err =
673  M.readSummary(*CombinedIndex, Mod->getName(), NextModuleId++)) {
674  // FIXME diagnose
676  std::move(Err), errs(),
677  "error: can't create module summary index for buffer: ");
678  return nullptr;
679  }
680  }
681  return CombinedIndex;
682 }
683 
684 namespace {
685 struct IsExported {
686  const StringMap<FunctionImporter::ExportSetTy> &ExportLists;
687  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols;
688 
689  IsExported(const StringMap<FunctionImporter::ExportSetTy> &ExportLists,
690  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols)
691  : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
692 
693  bool operator()(StringRef ModuleIdentifier, ValueInfo VI) const {
694  const auto &ExportList = ExportLists.find(ModuleIdentifier);
695  return (ExportList != ExportLists.end() && ExportList->second.count(VI)) ||
696  GUIDPreservedSymbols.count(VI.getGUID());
697  }
698 };
699 
700 struct IsPrevailing {
703  &PrevailingCopy)
704  : PrevailingCopy(PrevailingCopy) {}
705 
706  bool operator()(GlobalValue::GUID GUID, const GlobalValueSummary *S) const {
707  const auto &Prevailing = PrevailingCopy.find(GUID);
708  // Not in map means that there was only one copy, which must be prevailing.
709  if (Prevailing == PrevailingCopy.end())
710  return true;
711  return Prevailing->second == S;
712  };
713 };
714 } // namespace
715 
718  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
719  // We have no symbols resolution available. And can't do any better now in the
720  // case where the prevailing symbol is in a native object. It can be refined
721  // with linker information in the future.
722  auto isPrevailing = [&](GlobalValue::GUID G) {
724  };
725  computeDeadSymbolsWithConstProp(Index, GUIDPreservedSymbols, isPrevailing,
726  /* ImportEnabled = */ true);
727 }
728 
729 /**
730  * Perform promotion and renaming of exported internal functions.
731  * Index is updated to reflect linkage changes from weak resolution.
732  */
734  const lto::InputFile &File) {
735  auto ModuleCount = Index.modulePaths().size();
736  auto ModuleIdentifier = TheModule.getModuleIdentifier();
737 
738  // Collect for each module the list of function it defines (GUID -> Summary).
739  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
740  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
741 
742  // Convert the preserved symbols set from string to GUID
743  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
744  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
745 
746  // Add used symbol to the preserved symbols.
747  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
748 
749  // Compute "dead" symbols, we don't want to import/export these!
750  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
751 
752  // Generate import/export list
753  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
754  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
755  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
756  ExportLists);
757 
759  computePrevailingCopies(Index, PrevailingCopy);
760 
761  // Resolve prevailing symbols
763  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
764  PrevailingCopy);
765 
767  TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
768 
769  // Promote the exported values in the index, so that they are promoted
770  // in the module.
772  Index, IsExported(ExportLists, GUIDPreservedSymbols),
773  IsPrevailing(PrevailingCopy));
774 
775  // FIXME Set ClearDSOLocalOnDeclarations.
776  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
777 }
778 
779 /**
780  * Perform cross-module importing for the module identified by ModuleIdentifier.
781  */
784  const lto::InputFile &File) {
785  auto ModuleMap = generateModuleMap(Modules);
786  auto ModuleCount = Index.modulePaths().size();
787 
788  // Collect for each module the list of function it defines (GUID -> Summary).
789  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
790  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
791 
792  // Convert the preserved symbols set from string to GUID
793  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
794  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
795 
796  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
797 
798  // Compute "dead" symbols, we don't want to import/export these!
799  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
800 
801  // Generate import/export list
802  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
803  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
804  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
805  ExportLists);
806  auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
807 
808  // FIXME Set ClearDSOLocalOnDeclarations.
809  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
810  /*ClearDSOLocalOnDeclarations=*/false);
811 }
812 
813 /**
814  * Compute the list of summaries needed for importing into module.
815  */
817  Module &TheModule, ModuleSummaryIndex &Index,
818  std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
819  const lto::InputFile &File) {
820  auto ModuleCount = Index.modulePaths().size();
821  auto ModuleIdentifier = TheModule.getModuleIdentifier();
822 
823  // Collect for each module the list of function it defines (GUID -> Summary).
824  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
825  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
826 
827  // Convert the preserved symbols set from string to GUID
828  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
829  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
830 
831  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
832 
833  // Compute "dead" symbols, we don't want to import/export these!
834  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
835 
836  // Generate import/export list
837  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
838  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
839  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
840  ExportLists);
841 
843  ModuleIdentifier, ModuleToDefinedGVSummaries,
844  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
845 }
846 
847 /**
848  * Emit the list of files needed for importing into module.
849  */
852  const lto::InputFile &File) {
853  auto ModuleCount = Index.modulePaths().size();
854  auto ModuleIdentifier = TheModule.getModuleIdentifier();
855 
856  // Collect for each module the list of function it defines (GUID -> Summary).
857  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
858  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
859 
860  // Convert the preserved symbols set from string to GUID
861  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
862  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
863 
864  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
865 
866  // Compute "dead" symbols, we don't want to import/export these!
867  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
868 
869  // Generate import/export list
870  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
871  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
872  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
873  ExportLists);
874 
875  std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
877  ModuleIdentifier, ModuleToDefinedGVSummaries,
878  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
879 
880  std::error_code EC;
881  if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,
882  ModuleToSummariesForIndex)))
883  report_fatal_error(Twine("Failed to open ") + OutputName +
884  " to save imports lists\n");
885 }
886 
887 /**
888  * Perform internalization. Runs promote and internalization together.
889  * Index is updated to reflect linkage changes.
890  */
893  const lto::InputFile &File) {
894  initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
895  auto ModuleCount = Index.modulePaths().size();
896  auto ModuleIdentifier = TheModule.getModuleIdentifier();
897 
898  // Convert the preserved symbols set from string to GUID
899  auto GUIDPreservedSymbols =
900  computeGUIDPreservedSymbols(File, PreservedSymbols, TMBuilder.TheTriple);
901 
902  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
903 
904  // Collect for each module the list of function it defines (GUID -> Summary).
905  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
906  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
907 
908  // Compute "dead" symbols, we don't want to import/export these!
909  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
910 
911  // Generate import/export list
912  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
913  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
914  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
915  ExportLists);
916  auto &ExportList = ExportLists[ModuleIdentifier];
917 
918  // Be friendly and don't nuke totally the module when the client didn't
919  // supply anything to preserve.
920  if (ExportList.empty() && GUIDPreservedSymbols.empty())
921  return;
922 
924  computePrevailingCopies(Index, PrevailingCopy);
925 
926  // Resolve prevailing symbols
928  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
929  PrevailingCopy);
930 
931  // Promote the exported values in the index, so that they are promoted
932  // in the module.
934  Index, IsExported(ExportLists, GUIDPreservedSymbols),
935  IsPrevailing(PrevailingCopy));
936 
937  // FIXME Set ClearDSOLocalOnDeclarations.
938  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
939 
940  // Internalization
942  TheModule, ModuleToDefinedGVSummaries[ModuleIdentifier]);
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("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("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) {
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  // Make sure that every module has an entry in the ExportLists, ImportList,
1134  // GVSummary and ResolvedODR maps to enable threaded access to these maps
1135  // below.
1136  for (auto &Module : Modules) {
1137  auto ModuleIdentifier = Module->getName();
1138  ExportLists[ModuleIdentifier];
1139  ImportLists[ModuleIdentifier];
1140  ResolvedODR[ModuleIdentifier];
1141  ModuleToDefinedGVSummaries[ModuleIdentifier];
1142  }
1143 
1144  std::vector<BitcodeModule *> ModulesVec;
1145  ModulesVec.reserve(Modules.size());
1146  for (auto &Mod : Modules)
1147  ModulesVec.push_back(&Mod->getSingleBitcodeModule());
1148  std::vector<int> ModulesOrdering = lto::generateModulesOrdering(ModulesVec);
1149 
1152 
1153  TimeTraceScopeExit.release();
1154 
1155  // Parallel optimizer + codegen
1156  {
1157  ThreadPool Pool(heavyweight_hardware_concurrency(ThreadCount));
1158  for (auto IndexCount : ModulesOrdering) {
1159  auto &Mod = Modules[IndexCount];
1160  Pool.async([&](int count) {
1161  auto ModuleIdentifier = Mod->getName();
1162  auto &ExportList = ExportLists[ModuleIdentifier];
1163 
1164  auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1165 
1166  // The module may be cached, this helps handling it.
1167  ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
1168  ImportLists[ModuleIdentifier], ExportList,
1169  ResolvedODR[ModuleIdentifier],
1170  DefinedGVSummaries, OptLevel, Freestanding,
1171  TMBuilder);
1172  auto CacheEntryPath = CacheEntry.getEntryPath();
1173 
1174  {
1175  auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1176  LLVM_DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss")
1177  << " '" << CacheEntryPath << "' for buffer "
1178  << count << " " << ModuleIdentifier << "\n");
1179 
1180  if (ErrOrBuffer) {
1181  // Cache Hit!
1182  if (SavedObjectsDirectoryPath.empty())
1183  ProducedBinaries[count] = std::move(ErrOrBuffer.get());
1184  else
1185  ProducedBinaryFiles[count] = writeGeneratedObject(
1186  count, CacheEntryPath, *ErrOrBuffer.get());
1187  return;
1188  }
1189  }
1190 
1194  auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(
1197  if (!DiagFileOrErr) {
1198  errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
1199  report_fatal_error("ThinLTO: Can't get an output file for the "
1200  "remarks");
1201  }
1202 
1203  // Parse module now
1204  auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
1205  /*IsImporting*/ false);
1206 
1207  // Save temps: original file.
1208  saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
1209 
1210  auto &ImportList = ImportLists[ModuleIdentifier];
1211  // Run the main process now, and generates a binary
1212  auto OutputBuffer = ProcessThinLTOModule(
1213  *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
1214  ExportList, GUIDPreservedSymbols,
1215  ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1216  DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
1217  UseNewPM, DebugPassManager);
1218 
1219  // Commit to the cache (if enabled)
1220  CacheEntry.write(*OutputBuffer);
1221 
1222  if (SavedObjectsDirectoryPath.empty()) {
1223  // We need to generated a memory buffer for the linker.
1224  if (!CacheEntryPath.empty()) {
1225  // When cache is enabled, reload from the cache if possible.
1226  // Releasing the buffer from the heap and reloading it from the
1227  // cache file with mmap helps us to lower memory pressure.
1228  // The freed memory can be used for the next input file.
1229  // The final binary link will read from the VFS cache (hopefully!)
1230  // or from disk (if the memory pressure was too high).
1231  auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1232  if (auto EC = ReloadedBufferOrErr.getError()) {
1233  // On error, keep the preexisting buffer and print a diagnostic.
1234  errs() << "remark: can't reload cached file '" << CacheEntryPath
1235  << "': " << EC.message() << "\n";
1236  } else {
1237  OutputBuffer = std::move(*ReloadedBufferOrErr);
1238  }
1239  }
1240  ProducedBinaries[count] = std::move(OutputBuffer);
1241  return;
1242  }
1243  ProducedBinaryFiles[count] = writeGeneratedObject(
1244  count, CacheEntryPath, *OutputBuffer);
1245  }, IndexCount);
1246  }
1247  }
1248 
1249  pruneCache(CacheOptions.Path, CacheOptions.Policy);
1250 
1251  // If statistics were requested, print them out now.
1255 }
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:81
llvm::ThinLTOCodeGenerator::CachingOptions
Definition: ThinLTOCodeGenerator.h:126
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1233
llvm::LLVMContext::enableDebugTypeODRUniquing
void enableDebugTypeODRUniquing()
Definition: LLVMContext.cpp:322
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:733
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:476
llvm::TargetMachineBuilder::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: ThinLTOCodeGenerator.h:42
FunctionImportUtils.h
llvm
---------------------— PointerInfo ------------------------------------—
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:935
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:39
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
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:633
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:1117
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:503
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:157
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:147
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:167
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:83
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:1020
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
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:833
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:80
SmallVectorMemoryBuffer.h
llvm::lto::InputFile::getSingleBitcodeModule
BitcodeModule & getSingleBitcodeModule()
Definition: LTO.cpp:505
llvm::PassManagerBuilder::LoopVectorize
bool LoopVectorize
Definition: PassManagerBuilder.h:160
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:37
llvm::TargetMachineBuilder
Helper to gather options relevant to the target machine creation.
Definition: ThinLTOCodeGenerator.h:36
Error.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::ThinLTOCodeGenerator::CachingOptions::Policy
CachePruningPolicy Policy
Definition: ThinLTOCodeGenerator.h:128
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:782
llvm::DK_Linker
@ DK_Linker
Definition: DiagnosticInfo.h:59
llvm::PassManagerBuilder::ImportSummary
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
Definition: PassManagerBuilder.h:155
llvm::StringMap::end
iterator end()
Definition: StringMap.h:203
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
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:84
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:850
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:82
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
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:1567
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:1645
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:969
llvm::Triple::aarch64_32
@ aarch64_32
Definition: Triple.h:54
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:1035
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:993
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:40
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
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:454
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
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:1621
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:1547
llvm::StandardInstrumentations::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM=nullptr)
Definition: StandardInstrumentations.cpp:1226
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:141
llvm::Triple::str
const std::string & str() const
Definition: Triple.h:376
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::Triple::isOSDarwin
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
Definition: Triple.h:484
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:46
BitcodeWriter.h
llvm::ThinLTOCodeGenerator::internalize
void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
Definition: ThinLTOCodeGenerator.cpp:891
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:79
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:84
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:963
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: DiagnosticInfo.h:44
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:4684
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:140
llvm::PassManagerBuilder::Inliner
Pass * Inliner
Inliner - Specifies the inliner to use.
Definition: PassManagerBuilder.h:145
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
getArchName - Get the architecture (first) component of the triple.
Definition: Triple.cpp:1023
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:102
llvm::DiagnosticPrinter
Interface for custom diagnostic printing.
Definition: DiagnosticPrinter.h:31
llvm::Triple::getArch
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:307
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:629
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:85
computeDeadSymbolsInIndex
static void computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Definition: ThinLTOCodeGenerator.cpp:716
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:59
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:1171
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:814
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::GlobalValue::isWeakForLinker
bool isWeakForLinker() const
Definition: GlobalValue.h:467
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:244
VI
@ VI
Definition: SIInstrInfo.cpp:7679
Threading.h
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:413
llvm::StandardInstrumentations
This class provides an interface to register all the standard pass instrumentations and manages their...
Definition: StandardInstrumentations.h:414
llvm::sys::fs::exists
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1073
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:1630
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
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:957
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:395
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:68
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:59
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:1273
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::PassBuilder::buildDefaultAAPipeline
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Definition: PassBuilderPipelines.cpp:1703
llvm::PassManagerBuilder::OptLevel
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Definition: PassManagerBuilder.h:132
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:816
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:79
llvm::PipelineTuningOptions::SLPVectorization
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:52
SI
StandardInstrumentations SI(Debug, VerifyEach)
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:227
llvm::PassManagerBuilder::VerifyInput
bool VerifyInput
Definition: PassManagerBuilder.h:166
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:839
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:67
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:231
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:4639
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:159
llvm::PIELevel::Default
@ Default
Definition: CodeGen.h:37
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
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:666
uint32_t
llvm::OptimizationLevel::O3
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
Definition: OptimizationLevel.h:89
llvm::ThreadPool::async
std::shared_future< void > async(Function &&F, Args &&... ArgList)
Asynchronous submission of a task to the pool.
Definition: ThreadPool.h:54
llvm::PipelineTuningOptions::LoopVectorization
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:48
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::thinLTOResolvePrevailingInModule
void thinLTOResolvePrevailingInModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve prevailing symbol linkages and constrain visibility (1.
Definition: FunctionImport.cpp:1044
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:784
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:1574
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:422
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:1626
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::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:261
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:511
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:404
llvm::TargetMachineBuilder::MCpu
std::string MCpu
Definition: ThinLTOCodeGenerator.h:38
llvm::OptimizationLevel
Definition: OptimizationLevel.h:22
llvm::LLVMContext::setDiscardValueNames
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
Definition: LLVMContext.cpp:331
llvm::TargetMachineBuilder::create
std::unique_ptr< TargetMachine > create() const
Definition: ThinLTOCodeGenerator.cpp:641
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:658
llvm::sys::fs::is_directory
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition: Path.cpp:1088
llvm::legacy::PassManager::add
void add(Pass *P) override
Add a pass to the queue of passes to run.
Definition: LegacyPassManager.cpp:1674
llvm::StringMap< NoneType, MallocAllocator >::count
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:244
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:847
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:93
llvm::TargetMachineBuilder::RelocModel
Optional< Reloc::Model > RelocModel
Definition: ThinLTOCodeGenerator.h:41
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:589
llvm::lto::generateModulesOrdering
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Definition: LTO.cpp:1611
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:1028
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:257
llvm::PassBuilder::crossRegisterProxies
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Definition: PassBuilder.cpp:1472
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::TargetMachineBuilder::TheTriple
Triple TheTriple
Definition: ThinLTOCodeGenerator.h:37
IRReader.h
TargetTransformInfo.h
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
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:472
ScopeExit.h
llvm::legacy::PassManager::run
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition: LegacyPassManager.cpp:1680
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:692
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:1173
llvm::lto::Config::CPU
std::string CPU
Definition: Config.h:47
LLVMContext.h
llvm::createObjCARCContractPass
Pass * createObjCARCContractPass()
Definition: ObjCARCContract.cpp:731
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
BitcodeReader.h
SummaryBasedOptimizations.h
llvm::PassManager::addPass
std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:558
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:958
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
llvm::DS_Error
@ DS_Error
Definition: DiagnosticInfo.h:45
Debug.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:438
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
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:1012
llvm::verifyModule
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:5786
llvm::ThinLTOCodeGenerator::CachingOptions::Path
std::string Path
Definition: ThinLTOCodeGenerator.h:127
StandardInstrumentations.h
llvm::lto::InputFile
An input file.
Definition: LTO.h:104
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:630