LLVM  15.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"
27 #include "llvm/Config/llvm-config.h"
28 #include "llvm/IR/DebugInfo.h"
31 #include "llvm/IR/LLVMContext.h"
33 #include "llvm/IR/Mangler.h"
34 #include "llvm/IR/PassTimingInfo.h"
35 #include "llvm/IR/Verifier.h"
36 #include "llvm/IRReader/IRReader.h"
37 #include "llvm/LTO/LTO.h"
40 #include "llvm/MC/TargetRegistry.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"
53 #include "llvm/Support/Threading.h"
62 
63 #include <numeric>
64 
65 #if !defined(_MSC_VER) && !defined(__MINGW32__)
66 #include <unistd.h>
67 #else
68 #include <io.h>
69 #endif
70 
71 using namespace llvm;
72 
73 #define DEBUG_TYPE "thinlto"
74 
75 namespace llvm {
76 // Flags -discard-value-names, defined in LTOCodeGenerator.cpp
84 }
85 
86 namespace {
87 
88 // Default to using all available threads in the system, but using only one
89 // thred per core, as indicated by the usage of
90 // heavyweight_hardware_concurrency() below.
91 static cl::opt<int> ThreadCount("threads", cl::init(0));
92 
93 // Simple helper to save temporary files for debug.
94 static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
95  unsigned count, StringRef Suffix) {
96  if (TempDir.empty())
97  return;
98  // User asked to save temps, let dump the bitcode file after import.
99  std::string SaveTempPath = (TempDir + llvm::Twine(count) + Suffix).str();
100  std::error_code EC;
101  raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
102  if (EC)
103  report_fatal_error(Twine("Failed to open ") + SaveTempPath +
104  " to save optimized bitcode\n");
105  WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
106 }
107 
108 static const GlobalValueSummary *
109 getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
110  // If there is any strong definition anywhere, get it.
111  auto StrongDefForLinker = llvm::find_if(
112  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
113  auto Linkage = Summary->linkage();
116  });
117  if (StrongDefForLinker != GVSummaryList.end())
118  return StrongDefForLinker->get();
119  // Get the first *linker visible* definition for this global in the summary
120  // list.
121  auto FirstDefForLinker = llvm::find_if(
122  GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
123  auto Linkage = Summary->linkage();
125  });
126  // Extern templates can be emitted as available_externally.
127  if (FirstDefForLinker == GVSummaryList.end())
128  return nullptr;
129  return FirstDefForLinker->get();
130 }
131 
132 // Populate map of GUID to the prevailing copy for any multiply defined
133 // symbols. Currently assume first copy is prevailing, or any strong
134 // definition. Can be refined with Linker information in the future.
135 static void computePrevailingCopies(
136  const ModuleSummaryIndex &Index,
138  auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
139  return GVSummaryList.size() > 1;
140  };
141 
142  for (auto &I : Index) {
143  if (HasMultipleCopies(I.second.SummaryList))
144  PrevailingCopy[I.first] =
145  getFirstDefinitionForLinker(I.second.SummaryList);
146  }
147 }
148 
150 generateModuleMap(std::vector<std::unique_ptr<lto::InputFile>> &Modules) {
151  StringMap<lto::InputFile *> ModuleMap;
152  for (auto &M : Modules) {
153  assert(ModuleMap.find(M->getName()) == ModuleMap.end() &&
154  "Expect unique Buffer Identifier");
155  ModuleMap[M->getName()] = M.get();
156  }
157  return ModuleMap;
158 }
159 
160 static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index,
161  bool ClearDSOLocalOnDeclarations) {
162  if (renameModuleForThinLTO(TheModule, Index, ClearDSOLocalOnDeclarations))
163  report_fatal_error("renameModuleForThinLTO failed");
164 }
165 
166 namespace {
167 class ThinLTODiagnosticInfo : public DiagnosticInfo {
168  const Twine &Msg;
169 public:
170  ThinLTODiagnosticInfo(const Twine &DiagMsg,
171  DiagnosticSeverity Severity = DS_Error)
172  : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
173  void print(DiagnosticPrinter &DP) const override { DP << Msg; }
174 };
175 }
176 
177 /// Verify the module and strip broken debug info.
178 static void verifyLoadedModule(Module &TheModule) {
179  bool BrokenDebugInfo = false;
180  if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
181  report_fatal_error("Broken module found, compilation aborted!");
182  if (BrokenDebugInfo) {
183  TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
184  "Invalid debug info found, debug info will be stripped", DS_Warning));
185  StripDebugInfo(TheModule);
186  }
187 }
188 
189 static std::unique_ptr<Module> loadModuleFromInput(lto::InputFile *Input,
191  bool Lazy,
192  bool IsImporting) {
193  auto &Mod = Input->getSingleBitcodeModule();
194  SMDiagnostic Err;
195  Expected<std::unique_ptr<Module>> ModuleOrErr =
196  Lazy ? Mod.getLazyModule(Context,
197  /* ShouldLazyLoadMetadata */ true, IsImporting)
198  : Mod.parseModule(Context);
199  if (!ModuleOrErr) {
200  handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
201  SMDiagnostic Err = SMDiagnostic(Mod.getModuleIdentifier(),
202  SourceMgr::DK_Error, EIB.message());
203  Err.print("ThinLTO", errs());
204  });
205  report_fatal_error("Can't load module, abort.");
206  }
207  if (!Lazy)
208  verifyLoadedModule(*ModuleOrErr.get());
209  return std::move(*ModuleOrErr);
210 }
211 
212 static void
213 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
214  StringMap<lto::InputFile *> &ModuleMap,
215  const FunctionImporter::ImportMapTy &ImportList,
216  bool ClearDSOLocalOnDeclarations) {
217  auto Loader = [&](StringRef Identifier) {
218  auto &Input = ModuleMap[Identifier];
219  return loadModuleFromInput(Input, TheModule.getContext(),
220  /*Lazy=*/true, /*IsImporting*/ true);
221  };
222 
223  FunctionImporter Importer(Index, Loader, ClearDSOLocalOnDeclarations);
224  Expected<bool> Result = Importer.importFunctions(TheModule, ImportList);
225  if (!Result) {
226  handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) {
227  SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(),
228  SourceMgr::DK_Error, EIB.message());
229  Err.print("ThinLTO", errs());
230  });
231  report_fatal_error("importFunctions failed");
232  }
233  // Verify again after cross-importing.
234  verifyLoadedModule(TheModule);
235 }
236 
237 static void optimizeModule(Module &TheModule, TargetMachine &TM,
238  unsigned OptLevel, bool Freestanding,
239  bool DebugPassManager, ModuleSummaryIndex *Index) {
240  Optional<PGOOptions> PGOOpt;
245 
247  StandardInstrumentations SI(DebugPassManager);
250  PTO.LoopVectorization = true;
251  PTO.SLPVectorization = true;
252  PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
253 
254  std::unique_ptr<TargetLibraryInfoImpl> TLII(
255  new TargetLibraryInfoImpl(Triple(TM.getTargetTriple())));
256  if (Freestanding)
257  TLII->disableAllFunctions();
258  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
259 
260  // Register all the basic analyses with the managers.
266 
268 
270 
271  switch (OptLevel) {
272  default:
273  llvm_unreachable("Invalid optimization level");
274  case 0:
276  break;
277  case 1:
279  break;
280  case 2:
282  break;
283  case 3:
285  break;
286  }
287 
289 
290  MPM.run(TheModule, MAM);
291 }
292 
293 static void
294 addUsedSymbolToPreservedGUID(const lto::InputFile &File,
295  DenseSet<GlobalValue::GUID> &PreservedGUID) {
296  for (const auto &Sym : File.symbols()) {
297  if (Sym.isUsed())
298  PreservedGUID.insert(GlobalValue::getGUID(Sym.getIRName()));
299  }
300 }
301 
302 // Convert the PreservedSymbols map from "Name" based to "GUID" based.
303 static void computeGUIDPreservedSymbols(const lto::InputFile &File,
305  const Triple &TheTriple,
307  // Iterate the symbols in the input file and if the input has preserved symbol
308  // compute the GUID for the symbol.
309  for (const auto &Sym : File.symbols()) {
310  if (PreservedSymbols.count(Sym.getName()) && !Sym.getIRName().empty())
312  Sym.getIRName(), GlobalValue::ExternalLinkage, "")));
313  }
314 }
315 
317 computeGUIDPreservedSymbols(const lto::InputFile &File,
319  const Triple &TheTriple) {
320  DenseSet<GlobalValue::GUID> GUIDPreservedSymbols(PreservedSymbols.size());
321  computeGUIDPreservedSymbols(File, PreservedSymbols, TheTriple,
322  GUIDPreservedSymbols);
323  return GUIDPreservedSymbols;
324 }
325 
326 std::unique_ptr<MemoryBuffer> codegenModule(Module &TheModule,
327  TargetMachine &TM) {
328  SmallVector<char, 128> OutputBuffer;
329 
330  // CodeGen
331  {
332  raw_svector_ostream OS(OutputBuffer);
334 
335  // If the bitcode files contain ARC code and were compiled with optimization,
336  // the ObjCARCContractPass must be run, so do it unconditionally here.
338 
339  // Setup the codegen now.
340  if (TM.addPassesToEmitFile(PM, OS, nullptr, CGFT_ObjectFile,
341  /* DisableVerify */ true))
342  report_fatal_error("Failed to setup codegen");
343 
344  // Run codegen now. resulting binary is in OutputBuffer.
345  PM.run(TheModule);
346  }
347  return std::make_unique<SmallVectorMemoryBuffer>(
348  std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
349 }
350 
351 /// Manage caching for a single Module.
352 class ModuleCacheEntry {
353  SmallString<128> EntryPath;
354 
355 public:
356  // Create a cache entry. This compute a unique hash for the Module considering
357  // the current list of export/import, and offer an interface to query to
358  // access the content in the cache.
359  ModuleCacheEntry(
360  StringRef CachePath, const ModuleSummaryIndex &Index, StringRef ModuleID,
361  const FunctionImporter::ImportMapTy &ImportList,
362  const FunctionImporter::ExportSetTy &ExportList,
363  const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
364  const GVSummaryMapTy &DefinedGVSummaries, unsigned OptLevel,
365  bool Freestanding, const TargetMachineBuilder &TMBuilder) {
366  if (CachePath.empty())
367  return;
368 
369  if (!Index.modulePaths().count(ModuleID))
370  // The module does not have an entry, it can't have a hash at all
371  return;
372 
373  if (all_of(Index.getModuleHash(ModuleID),
374  [](uint32_t V) { return V == 0; }))
375  // No hash entry, no caching!
376  return;
377 
378  llvm::lto::Config Conf;
379  Conf.OptLevel = OptLevel;
380  Conf.Options = TMBuilder.Options;
381  Conf.CPU = TMBuilder.MCpu;
382  Conf.MAttrs.push_back(TMBuilder.MAttr);
383  Conf.RelocModel = TMBuilder.RelocModel;
384  Conf.CGOptLevel = TMBuilder.CGOptLevel;
385  Conf.Freestanding = Freestanding;
387  computeLTOCacheKey(Key, Conf, Index, ModuleID, ImportList, ExportList,
388  ResolvedODR, DefinedGVSummaries);
389 
390  // This choice of file name allows the cache to be pruned (see pruneCache()
391  // in include/llvm/Support/CachePruning.h).
392  sys::path::append(EntryPath, CachePath, "llvmcache-" + Key);
393  }
394 
395  // Access the path to this entry in the cache.
396  StringRef getEntryPath() { return EntryPath; }
397 
398  // Try loading the buffer for this cache entry.
399  ErrorOr<std::unique_ptr<MemoryBuffer>> tryLoadingBuffer() {
400  if (EntryPath.empty())
401  return std::error_code();
402  SmallString<64> ResultPath;
404  Twine(EntryPath), sys::fs::OF_UpdateAtime, &ResultPath);
405  if (!FDOrErr)
406  return errorToErrorCode(FDOrErr.takeError());
408  *FDOrErr, EntryPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
409  sys::fs::closeFile(*FDOrErr);
410  return MBOrErr;
411  }
412 
413  // Cache the Produced object file
414  void write(const MemoryBuffer &OutputBuffer) {
415  if (EntryPath.empty())
416  return;
417 
418  // Write to a temporary to avoid race condition
419  SmallString<128> TempFilename;
420  SmallString<128> CachePath(EntryPath);
422  sys::path::append(TempFilename, CachePath, "Thin-%%%%%%.tmp.o");
423 
424  if (auto Err = handleErrors(
425  llvm::writeFileAtomically(TempFilename, EntryPath,
426  OutputBuffer.getBuffer()),
427  [](const llvm::AtomicFileWriteError &E) {
428  std::string ErrorMsgBuffer;
429  llvm::raw_string_ostream S(ErrorMsgBuffer);
430  E.log(S);
431 
432  if (E.Error ==
433  llvm::atomic_write_error::failed_to_create_uniq_file) {
434  errs() << "Error: " << ErrorMsgBuffer << "\n";
435  report_fatal_error("ThinLTO: Can't get a temporary file");
436  }
437  })) {
438  // FIXME
439  consumeError(std::move(Err));
440  }
441  }
442 };
443 
444 static std::unique_ptr<MemoryBuffer>
445 ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
447  const FunctionImporter::ImportMapTy &ImportList,
448  const FunctionImporter::ExportSetTy &ExportList,
449  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
450  const GVSummaryMapTy &DefinedGlobals,
451  const ThinLTOCodeGenerator::CachingOptions &CacheOptions,
452  bool DisableCodeGen, StringRef SaveTempsDir,
453  bool Freestanding, unsigned OptLevel, unsigned count,
454  bool DebugPassManager) {
455 
456  // "Benchmark"-like optimization: single-source case
457  bool SingleModule = (ModuleMap.size() == 1);
458 
459  // When linking an ELF shared object, dso_local should be dropped. We
460  // conservatively do this for -fpic.
461  bool ClearDSOLocalOnDeclarations =
462  TM.getTargetTriple().isOSBinFormatELF() &&
463  TM.getRelocationModel() != Reloc::Static &&
464  TheModule.getPIELevel() == PIELevel::Default;
465 
466  if (!SingleModule) {
467  promoteModule(TheModule, Index, ClearDSOLocalOnDeclarations);
468 
469  // Apply summary-based prevailing-symbol resolution decisions.
470  thinLTOFinalizeInModule(TheModule, DefinedGlobals, /*PropagateAttrs=*/true);
471 
472  // Save temps: after promotion.
473  saveTempBitcode(TheModule, SaveTempsDir, count, ".1.promoted.bc");
474  }
475 
476  // Be friendly and don't nuke totally the module when the client didn't
477  // supply anything to preserve.
478  if (!ExportList.empty() || !GUIDPreservedSymbols.empty()) {
479  // Apply summary-based internalization decisions.
480  thinLTOInternalizeModule(TheModule, DefinedGlobals);
481  }
482 
483  // Save internalized bitcode
484  saveTempBitcode(TheModule, SaveTempsDir, count, ".2.internalized.bc");
485 
486  if (!SingleModule) {
487  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
488  ClearDSOLocalOnDeclarations);
489 
490  // Save temps: after cross-module import.
491  saveTempBitcode(TheModule, SaveTempsDir, count, ".3.imported.bc");
492  }
493 
494  optimizeModule(TheModule, TM, OptLevel, Freestanding, DebugPassManager,
495  &Index);
496 
497  saveTempBitcode(TheModule, SaveTempsDir, count, ".4.opt.bc");
498 
499  if (DisableCodeGen) {
500  // Configured to stop before CodeGen, serialize the bitcode and return.
501  SmallVector<char, 128> OutputBuffer;
502  {
503  raw_svector_ostream OS(OutputBuffer);
504  ProfileSummaryInfo PSI(TheModule);
505  auto Index = buildModuleSummaryIndex(TheModule, nullptr, &PSI);
506  WriteBitcodeToFile(TheModule, OS, true, &Index);
507  }
508  return std::make_unique<SmallVectorMemoryBuffer>(
509  std::move(OutputBuffer), /*RequiresNullTerminator=*/false);
510  }
511 
512  return codegenModule(TheModule, TM);
513 }
514 
515 /// Resolve prevailing symbols. Record resolutions in the \p ResolvedODR map
516 /// for caching, and in the \p Index for application during the ThinLTO
517 /// backends. This is needed for correctness for exported symbols (ensure
518 /// at least one copy kept) and a compile-time optimization (to drop duplicate
519 /// copies when possible).
520 static void resolvePrevailingInIndex(
522  StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>>
523  &ResolvedODR,
524  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
526  &PrevailingCopy) {
527 
528  auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S) {
529  const auto &Prevailing = PrevailingCopy.find(GUID);
530  // Not in map means that there was only one copy, which must be prevailing.
531  if (Prevailing == PrevailingCopy.end())
532  return true;
533  return Prevailing->second == S;
534  };
535 
536  auto recordNewLinkage = [&](StringRef ModuleIdentifier,
537  GlobalValue::GUID GUID,
538  GlobalValue::LinkageTypes NewLinkage) {
539  ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
540  };
541 
542  // TODO Conf.VisibilityScheme can be lto::Config::ELF for ELF.
543  lto::Config Conf;
544  thinLTOResolvePrevailingInIndex(Conf, Index, isPrevailing, recordNewLinkage,
545  GUIDPreservedSymbols);
546 }
547 
548 // Initialize the TargetMachine builder for a given Triple
549 static void initTMBuilder(TargetMachineBuilder &TMBuilder,
550  const Triple &TheTriple) {
551  // Set a default CPU for Darwin triples (copied from LTOCodeGenerator).
552  // FIXME this looks pretty terrible...
553  if (TMBuilder.MCpu.empty() && TheTriple.isOSDarwin()) {
554  if (TheTriple.getArch() == llvm::Triple::x86_64)
555  TMBuilder.MCpu = "core2";
556  else if (TheTriple.getArch() == llvm::Triple::x86)
557  TMBuilder.MCpu = "yonah";
558  else if (TheTriple.getArch() == llvm::Triple::aarch64 ||
559  TheTriple.getArch() == llvm::Triple::aarch64_32)
560  TMBuilder.MCpu = "cyclone";
561  }
562  TMBuilder.TheTriple = std::move(TheTriple);
563 }
564 
565 } // end anonymous namespace
566 
567 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
568  MemoryBufferRef Buffer(Data, Identifier);
569 
570  auto InputOrError = lto::InputFile::create(Buffer);
571  if (!InputOrError)
572  report_fatal_error(Twine("ThinLTO cannot create input file: ") +
573  toString(InputOrError.takeError()));
574 
575  auto TripleStr = (*InputOrError)->getTargetTriple();
576  Triple TheTriple(TripleStr);
577 
578  if (Modules.empty())
579  initTMBuilder(TMBuilder, Triple(TheTriple));
580  else if (TMBuilder.TheTriple != TheTriple) {
581  if (!TMBuilder.TheTriple.isCompatibleWith(TheTriple))
582  report_fatal_error("ThinLTO modules with incompatible triples not "
583  "supported");
584  initTMBuilder(TMBuilder, Triple(TMBuilder.TheTriple.merge(TheTriple)));
585  }
586 
587  Modules.emplace_back(std::move(*InputOrError));
588 }
589 
591  PreservedSymbols.insert(Name);
592 }
593 
595  // FIXME: At the moment, we don't take advantage of this extra information,
596  // we're conservatively considering cross-references as preserved.
597  // CrossReferencedSymbols.insert(Name);
598  PreservedSymbols.insert(Name);
599 }
600 
601 // TargetMachine factory
602 std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
603  std::string ErrMsg;
604  const Target *TheTarget =
606  if (!TheTarget) {
607  report_fatal_error(Twine("Can't load target for this Triple: ") + ErrMsg);
608  }
609 
610  // Use MAttr as the default set of features.
611  SubtargetFeatures Features(MAttr);
613  std::string FeatureStr = Features.getString();
614 
615  std::unique_ptr<TargetMachine> TM(
616  TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
618  assert(TM && "Cannot create target machine");
619 
620  return TM;
621 }
622 
623 /**
624  * Produce the combined summary index from all the bitcode files:
625  * "thin-link".
626  */
627 std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
628  std::unique_ptr<ModuleSummaryIndex> CombinedIndex =
629  std::make_unique<ModuleSummaryIndex>(/*HaveGVs=*/false);
630  uint64_t NextModuleId = 0;
631  for (auto &Mod : Modules) {
632  auto &M = Mod->getSingleBitcodeModule();
633  if (Error Err =
634  M.readSummary(*CombinedIndex, Mod->getName(), NextModuleId++)) {
635  // FIXME diagnose
637  std::move(Err), errs(),
638  "error: can't create module summary index for buffer: ");
639  return nullptr;
640  }
641  }
642  return CombinedIndex;
643 }
644 
645 namespace {
646 struct IsExported {
647  const StringMap<FunctionImporter::ExportSetTy> &ExportLists;
648  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols;
649 
650  IsExported(const StringMap<FunctionImporter::ExportSetTy> &ExportLists,
651  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols)
652  : ExportLists(ExportLists), GUIDPreservedSymbols(GUIDPreservedSymbols) {}
653 
654  bool operator()(StringRef ModuleIdentifier, ValueInfo VI) const {
655  const auto &ExportList = ExportLists.find(ModuleIdentifier);
656  return (ExportList != ExportLists.end() && ExportList->second.count(VI)) ||
657  GUIDPreservedSymbols.count(VI.getGUID());
658  }
659 };
660 
661 struct IsPrevailing {
664  &PrevailingCopy)
665  : PrevailingCopy(PrevailingCopy) {}
666 
667  bool operator()(GlobalValue::GUID GUID, const GlobalValueSummary *S) const {
668  const auto &Prevailing = PrevailingCopy.find(GUID);
669  // Not in map means that there was only one copy, which must be prevailing.
670  if (Prevailing == PrevailingCopy.end())
671  return true;
672  return Prevailing->second == S;
673  };
674 };
675 } // namespace
676 
679  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
680  // We have no symbols resolution available. And can't do any better now in the
681  // case where the prevailing symbol is in a native object. It can be refined
682  // with linker information in the future.
683  auto isPrevailing = [&](GlobalValue::GUID G) {
685  };
686  computeDeadSymbolsWithConstProp(Index, GUIDPreservedSymbols, isPrevailing,
687  /* ImportEnabled = */ true);
688 }
689 
690 /**
691  * Perform promotion and renaming of exported internal functions.
692  * Index is updated to reflect linkage changes from weak resolution.
693  */
695  const lto::InputFile &File) {
696  auto ModuleCount = Index.modulePaths().size();
697  auto ModuleIdentifier = TheModule.getModuleIdentifier();
698 
699  // Collect for each module the list of function it defines (GUID -> Summary).
700  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
701  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
702 
703  // Convert the preserved symbols set from string to GUID
704  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
705  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
706 
707  // Add used symbol to the preserved symbols.
708  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
709 
710  // Compute "dead" symbols, we don't want to import/export these!
711  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
712 
713  // Generate import/export list
714  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
715  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
716  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
717  ExportLists);
718 
720  computePrevailingCopies(Index, PrevailingCopy);
721 
722  // Resolve prevailing symbols
724  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
725  PrevailingCopy);
726 
727  thinLTOFinalizeInModule(TheModule,
728  ModuleToDefinedGVSummaries[ModuleIdentifier],
729  /*PropagateAttrs=*/false);
730 
731  // Promote the exported values in the index, so that they are promoted
732  // in the module.
734  Index, IsExported(ExportLists, GUIDPreservedSymbols),
735  IsPrevailing(PrevailingCopy));
736 
737  // FIXME Set ClearDSOLocalOnDeclarations.
738  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
739 }
740 
741 /**
742  * Perform cross-module importing for the module identified by ModuleIdentifier.
743  */
746  const lto::InputFile &File) {
747  auto ModuleMap = generateModuleMap(Modules);
748  auto ModuleCount = Index.modulePaths().size();
749 
750  // Collect for each module the list of function it defines (GUID -> Summary).
751  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
752  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
753 
754  // Convert the preserved symbols set from string to GUID
755  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
756  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
757 
758  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
759 
760  // Compute "dead" symbols, we don't want to import/export these!
761  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
762 
763  // Generate import/export list
764  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
765  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
766  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
767  ExportLists);
768  auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
769 
770  // FIXME Set ClearDSOLocalOnDeclarations.
771  crossImportIntoModule(TheModule, Index, ModuleMap, ImportList,
772  /*ClearDSOLocalOnDeclarations=*/false);
773 }
774 
775 /**
776  * Compute the list of summaries needed for importing into module.
777  */
779  Module &TheModule, ModuleSummaryIndex &Index,
780  std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
781  const lto::InputFile &File) {
782  auto ModuleCount = Index.modulePaths().size();
783  auto ModuleIdentifier = TheModule.getModuleIdentifier();
784 
785  // Collect for each module the list of function it defines (GUID -> Summary).
786  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
787  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
788 
789  // Convert the preserved symbols set from string to GUID
790  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
791  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
792 
793  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
794 
795  // Compute "dead" symbols, we don't want to import/export these!
796  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
797 
798  // Generate import/export list
799  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
800  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
801  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
802  ExportLists);
803 
805  ModuleIdentifier, ModuleToDefinedGVSummaries,
806  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
807 }
808 
809 /**
810  * Emit the list of files needed for importing into module.
811  */
814  const lto::InputFile &File) {
815  auto ModuleCount = Index.modulePaths().size();
816  auto ModuleIdentifier = TheModule.getModuleIdentifier();
817 
818  // Collect for each module the list of function it defines (GUID -> Summary).
819  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
820  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
821 
822  // Convert the preserved symbols set from string to GUID
823  auto GUIDPreservedSymbols = computeGUIDPreservedSymbols(
824  File, PreservedSymbols, Triple(TheModule.getTargetTriple()));
825 
826  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
827 
828  // Compute "dead" symbols, we don't want to import/export these!
829  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
830 
831  // Generate import/export list
832  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
833  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
834  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
835  ExportLists);
836 
837  std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
839  ModuleIdentifier, ModuleToDefinedGVSummaries,
840  ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
841 
842  std::error_code EC;
843  if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,
844  ModuleToSummariesForIndex)))
845  report_fatal_error(Twine("Failed to open ") + OutputName +
846  " to save imports lists\n");
847 }
848 
849 /**
850  * Perform internalization. Runs promote and internalization together.
851  * Index is updated to reflect linkage changes.
852  */
855  const lto::InputFile &File) {
856  initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
857  auto ModuleCount = Index.modulePaths().size();
858  auto ModuleIdentifier = TheModule.getModuleIdentifier();
859 
860  // Convert the preserved symbols set from string to GUID
861  auto GUIDPreservedSymbols =
862  computeGUIDPreservedSymbols(File, PreservedSymbols, TMBuilder.TheTriple);
863 
864  addUsedSymbolToPreservedGUID(File, GUIDPreservedSymbols);
865 
866  // Collect for each module the list of function it defines (GUID -> Summary).
867  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
868  Index.collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
869 
870  // Compute "dead" symbols, we don't want to import/export these!
871  computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
872 
873  // Generate import/export list
874  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
875  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
876  ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
877  ExportLists);
878  auto &ExportList = ExportLists[ModuleIdentifier];
879 
880  // Be friendly and don't nuke totally the module when the client didn't
881  // supply anything to preserve.
882  if (ExportList.empty() && GUIDPreservedSymbols.empty())
883  return;
884 
886  computePrevailingCopies(Index, PrevailingCopy);
887 
888  // Resolve prevailing symbols
890  resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
891  PrevailingCopy);
892 
893  // Promote the exported values in the index, so that they are promoted
894  // in the module.
896  Index, IsExported(ExportLists, GUIDPreservedSymbols),
897  IsPrevailing(PrevailingCopy));
898 
899  // FIXME Set ClearDSOLocalOnDeclarations.
900  promoteModule(TheModule, Index, /*ClearDSOLocalOnDeclarations=*/false);
901 
902  // Internalization
903  thinLTOFinalizeInModule(TheModule,
904  ModuleToDefinedGVSummaries[ModuleIdentifier],
905  /*PropagateAttrs=*/false);
906 
907  thinLTOInternalizeModule(TheModule,
908  ModuleToDefinedGVSummaries[ModuleIdentifier]);
909 }
910 
911 /**
912  * Perform post-importing ThinLTO optimizations.
913  */
915  initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple()));
916 
917  // Optimize now
918  optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding,
919  DebugPassManager, nullptr);
920 }
921 
922 /// Write out the generated object file, either from CacheEntryPath or from
923 /// OutputBuffer, preferring hard-link when possible.
924 /// Returns the path to the generated file in SavedObjectsDirectoryPath.
925 std::string
927  const MemoryBuffer &OutputBuffer) {
928  auto ArchName = TMBuilder.TheTriple.getArchName();
929  SmallString<128> OutputPath(SavedObjectsDirectoryPath);
930  llvm::sys::path::append(OutputPath,
931  Twine(count) + "." + ArchName + ".thinlto.o");
932  OutputPath.c_str(); // Ensure the string is null terminated.
933  if (sys::fs::exists(OutputPath))
934  sys::fs::remove(OutputPath);
935 
936  // We don't return a memory buffer to the linker, just a list of files.
937  if (!CacheEntryPath.empty()) {
938  // Cache is enabled, hard-link the entry (or copy if hard-link fails).
939  auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
940  if (!Err)
941  return std::string(OutputPath.str());
942  // Hard linking failed, try to copy.
943  Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
944  if (!Err)
945  return std::string(OutputPath.str());
946  // Copy failed (could be because the CacheEntry was removed from the cache
947  // in the meantime by another process), fall back and try to write down the
948  // buffer to the output.
949  errs() << "remark: can't link or copy from cached entry '" << CacheEntryPath
950  << "' to '" << OutputPath << "'\n";
951  }
952  // No cache entry, just write out the buffer.
953  std::error_code Err;
954  raw_fd_ostream OS(OutputPath, Err, sys::fs::OF_None);
955  if (Err)
956  report_fatal_error(Twine("Can't open output '") + OutputPath + "'\n");
957  OS << OutputBuffer.getBuffer();
958  return std::string(OutputPath.str());
959 }
960 
961 // Main entry point for the ThinLTO processing
963  timeTraceProfilerBegin("ThinLink", StringRef(""));
964  auto TimeTraceScopeExit = llvm::make_scope_exit([]() {
967  });
968  // Prepare the resulting object vector
969  assert(ProducedBinaries.empty() && "The generator should not be reused");
970  if (SavedObjectsDirectoryPath.empty())
971  ProducedBinaries.resize(Modules.size());
972  else {
973  sys::fs::create_directories(SavedObjectsDirectoryPath);
974  bool IsDir;
975  sys::fs::is_directory(SavedObjectsDirectoryPath, IsDir);
976  if (!IsDir)
977  report_fatal_error(Twine("Unexistent dir: '") + SavedObjectsDirectoryPath + "'");
978  ProducedBinaryFiles.resize(Modules.size());
979  }
980 
981  if (CodeGenOnly) {
982  // Perform only parallel codegen and return.
983  ThreadPool Pool;
984  int count = 0;
985  for (auto &Mod : Modules) {
986  Pool.async([&](int count) {
989 
990  // Parse module now
991  auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
992  /*IsImporting*/ false);
993 
994  // CodeGen
995  auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create());
996  if (SavedObjectsDirectoryPath.empty())
997  ProducedBinaries[count] = std::move(OutputBuffer);
998  else
999  ProducedBinaryFiles[count] =
1000  writeGeneratedObject(count, "", *OutputBuffer);
1001  }, count++);
1002  }
1003 
1004  return;
1005  }
1006 
1007  // Sequential linking phase
1008  auto Index = linkCombinedIndex();
1009 
1010  // Save temps: index.
1011  if (!SaveTempsDir.empty()) {
1012  auto SaveTempPath = SaveTempsDir + "index.bc";
1013  std::error_code EC;
1014  raw_fd_ostream OS(SaveTempPath, EC, sys::fs::OF_None);
1015  if (EC)
1016  report_fatal_error(Twine("Failed to open ") + SaveTempPath +
1017  " to save optimized bitcode\n");
1018  writeIndexToFile(*Index, OS);
1019  }
1020 
1021 
1022  // Prepare the module map.
1023  auto ModuleMap = generateModuleMap(Modules);
1024  auto ModuleCount = Modules.size();
1025 
1026  // Collect for each module the list of function it defines (GUID -> Summary).
1027  StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries(ModuleCount);
1028  Index->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1029 
1030  // Convert the preserved symbols set from string to GUID, this is needed for
1031  // computing the caching hash and the internalization.
1032  DenseSet<GlobalValue::GUID> GUIDPreservedSymbols;
1033  for (const auto &M : Modules)
1034  computeGUIDPreservedSymbols(*M, PreservedSymbols, TMBuilder.TheTriple,
1035  GUIDPreservedSymbols);
1036 
1037  // Add used symbol from inputs to the preserved symbols.
1038  for (const auto &M : Modules)
1039  addUsedSymbolToPreservedGUID(*M, GUIDPreservedSymbols);
1040 
1041  // Compute "dead" symbols, we don't want to import/export these!
1042  computeDeadSymbolsInIndex(*Index, GUIDPreservedSymbols);
1043 
1044  // Synthesize entry counts for functions in the combined index.
1046 
1047  // Currently there is no support for enabling whole program visibility via a
1048  // linker option in the old LTO API, but this call allows it to be specified
1049  // via the internal option. Must be done before WPD below.
1051  /* WholeProgramVisibilityEnabledInLTO */ false,
1052  // FIXME: This needs linker information via a
1053  // TBD new interface.
1054  /* DynamicExportSymbols */ {});
1055 
1056  // Perform index-based WPD. This will return immediately if there are
1057  // no index entries in the typeIdMetadata map (e.g. if we are instead
1058  // performing IR-based WPD in hybrid regular/thin LTO mode).
1059  std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
1060  std::set<GlobalValue::GUID> ExportedGUIDs;
1061  runWholeProgramDevirtOnIndex(*Index, ExportedGUIDs, LocalWPDTargetsMap);
1062  for (auto GUID : ExportedGUIDs)
1063  GUIDPreservedSymbols.insert(GUID);
1064 
1065  // Collect the import/export lists for all modules from the call-graph in the
1066  // combined index.
1067  StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
1068  StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
1069  ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists,
1070  ExportLists);
1071 
1072  // We use a std::map here to be able to have a defined ordering when
1073  // producing a hash for the cache entry.
1074  // FIXME: we should be able to compute the caching hash for the entry based
1075  // on the index, and nuke this map.
1077 
1079  computePrevailingCopies(*Index, PrevailingCopy);
1080 
1081  // Resolve prevailing symbols, this has to be computed early because it
1082  // impacts the caching.
1083  resolvePrevailingInIndex(*Index, ResolvedODR, GUIDPreservedSymbols,
1084  PrevailingCopy);
1085 
1086  // Use global summary-based analysis to identify symbols that can be
1087  // internalized (because they aren't exported or preserved as per callback).
1088  // Changes are made in the index, consumed in the ThinLTO backends.
1090  IsExported(ExportLists, GUIDPreservedSymbols),
1091  LocalWPDTargetsMap);
1093  *Index, IsExported(ExportLists, GUIDPreservedSymbols),
1094  IsPrevailing(PrevailingCopy));
1095 
1096  thinLTOPropagateFunctionAttrs(*Index, IsPrevailing(PrevailingCopy));
1097 
1098  // Make sure that every module has an entry in the ExportLists, ImportList,
1099  // GVSummary and ResolvedODR maps to enable threaded access to these maps
1100  // below.
1101  for (auto &Module : Modules) {
1102  auto ModuleIdentifier = Module->getName();
1103  ExportLists[ModuleIdentifier];
1104  ImportLists[ModuleIdentifier];
1105  ResolvedODR[ModuleIdentifier];
1106  ModuleToDefinedGVSummaries[ModuleIdentifier];
1107  }
1108 
1109  std::vector<BitcodeModule *> ModulesVec;
1110  ModulesVec.reserve(Modules.size());
1111  for (auto &Mod : Modules)
1112  ModulesVec.push_back(&Mod->getSingleBitcodeModule());
1113  std::vector<int> ModulesOrdering = lto::generateModulesOrdering(ModulesVec);
1114 
1117 
1118  TimeTraceScopeExit.release();
1119 
1120  // Parallel optimizer + codegen
1121  {
1122  ThreadPool Pool(heavyweight_hardware_concurrency(ThreadCount));
1123  for (auto IndexCount : ModulesOrdering) {
1124  auto &Mod = Modules[IndexCount];
1125  Pool.async([&](int count) {
1126  auto ModuleIdentifier = Mod->getName();
1127  auto &ExportList = ExportLists[ModuleIdentifier];
1128 
1129  auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier];
1130 
1131  // The module may be cached, this helps handling it.
1132  ModuleCacheEntry CacheEntry(CacheOptions.Path, *Index, ModuleIdentifier,
1133  ImportLists[ModuleIdentifier], ExportList,
1134  ResolvedODR[ModuleIdentifier],
1135  DefinedGVSummaries, OptLevel, Freestanding,
1136  TMBuilder);
1137  auto CacheEntryPath = CacheEntry.getEntryPath();
1138 
1139  {
1140  auto ErrOrBuffer = CacheEntry.tryLoadingBuffer();
1141  LLVM_DEBUG(dbgs() << "Cache " << (ErrOrBuffer ? "hit" : "miss")
1142  << " '" << CacheEntryPath << "' for buffer "
1143  << count << " " << ModuleIdentifier << "\n");
1144 
1145  if (ErrOrBuffer) {
1146  // Cache Hit!
1147  if (SavedObjectsDirectoryPath.empty())
1148  ProducedBinaries[count] = std::move(ErrOrBuffer.get());
1149  else
1150  ProducedBinaryFiles[count] = writeGeneratedObject(
1151  count, CacheEntryPath, *ErrOrBuffer.get());
1152  return;
1153  }
1154  }
1155 
1159  auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(
1162  if (!DiagFileOrErr) {
1163  errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n";
1164  report_fatal_error("ThinLTO: Can't get an output file for the "
1165  "remarks");
1166  }
1167 
1168  // Parse module now
1169  auto TheModule = loadModuleFromInput(Mod.get(), Context, false,
1170  /*IsImporting*/ false);
1171 
1172  // Save temps: original file.
1173  saveTempBitcode(*TheModule, SaveTempsDir, count, ".0.original.bc");
1174 
1175  auto &ImportList = ImportLists[ModuleIdentifier];
1176  // Run the main process now, and generates a binary
1177  auto OutputBuffer = ProcessThinLTOModule(
1178  *TheModule, *Index, ModuleMap, *TMBuilder.create(), ImportList,
1179  ExportList, GUIDPreservedSymbols,
1180  ModuleToDefinedGVSummaries[ModuleIdentifier], CacheOptions,
1181  DisableCodeGen, SaveTempsDir, Freestanding, OptLevel, count,
1182  DebugPassManager);
1183 
1184  // Commit to the cache (if enabled)
1185  CacheEntry.write(*OutputBuffer);
1186 
1187  if (SavedObjectsDirectoryPath.empty()) {
1188  // We need to generated a memory buffer for the linker.
1189  if (!CacheEntryPath.empty()) {
1190  // When cache is enabled, reload from the cache if possible.
1191  // Releasing the buffer from the heap and reloading it from the
1192  // cache file with mmap helps us to lower memory pressure.
1193  // The freed memory can be used for the next input file.
1194  // The final binary link will read from the VFS cache (hopefully!)
1195  // or from disk (if the memory pressure was too high).
1196  auto ReloadedBufferOrErr = CacheEntry.tryLoadingBuffer();
1197  if (auto EC = ReloadedBufferOrErr.getError()) {
1198  // On error, keep the preexisting buffer and print a diagnostic.
1199  errs() << "remark: can't reload cached file '" << CacheEntryPath
1200  << "': " << EC.message() << "\n";
1201  } else {
1202  OutputBuffer = std::move(*ReloadedBufferOrErr);
1203  }
1204  }
1205  ProducedBinaries[count] = std::move(OutputBuffer);
1206  return;
1207  }
1208  ProducedBinaryFiles[count] = writeGeneratedObject(
1209  count, CacheEntryPath, *OutputBuffer);
1210  }, IndexCount);
1211  }
1212  }
1213 
1214  pruneCache(CacheOptions.Path, CacheOptions.Policy);
1215 
1216  // If statistics were requested, print them out now.
1220 }
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:79
llvm::ThinLTOCodeGenerator::CachingOptions
Definition: ThinLTOCodeGenerator.h:125
llvm::LLVMContext::enableDebugTypeODRUniquing
void enableDebugTypeODRUniquing()
Definition: LLVMContext.cpp:337
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:694
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:474
llvm::TargetMachineBuilder::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: ThinLTOCodeGenerator.h:41
llvm::SPIRV::StorageClass::Input
@ Input
FunctionImportUtils.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
PassBuilder.h
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:943
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:962
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:594
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:1145
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:498
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:166
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:926
print
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Definition: ArchiveWriter.cpp:189
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:52
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:80
llvm::lto::Config::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: Config.h:55
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:550
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:328
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:85
llvm::write
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
Definition: DWP.cpp:536
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
llvm::SmallVector< char, 128 >
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:898
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:78
llvm::StandardInstrumentations::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM=nullptr)
Definition: StandardInstrumentations.cpp:2171
SmallVectorMemoryBuffer.h
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:162
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:744
llvm::DK_Linker
@ DK_Linker
Definition: DiagnosticInfo.h:64
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
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:82
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:812
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:49
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:80
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:34
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:1604
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::Triple::merge
std::string merge(const Triple &Other) const
Merge target triples.
Definition: Triple.cpp:1793
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:218
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:976
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
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
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:1000
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
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:456
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:1769
CommandLine.h
llvm::GlobalValueSummary
Function and variable summary information to aid decisions and implementation of importing.
Definition: ModuleSummaryIndex.h:289
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:1617
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:286
TargetMachine.h
llvm::Triple::str
const std::string & str() const
Definition: Triple.h:404
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::Triple::isOSDarwin
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit).
Definition: Triple.h:508
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:51
BitcodeWriter.h
llvm::ThinLTOCodeGenerator::internalize
void internalize(Module &Module, ModuleSummaryIndex &Index, const lto::InputFile &File)
Perform internalization.
Definition: ThinLTOCodeGenerator.cpp:853
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:77
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:281
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:486
TargetLibraryInfo.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
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:59
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:967
llvm::DiagnosticSeverity
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
Definition: DiagnosticInfo.h:49
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:1051
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::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:1127
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:108
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:345
llvm::SubtargetFeatures::getDefaultSubtargetFeatures
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
Definition: SubtargetFeature.cpp:66
llvm::AtomicFileWriteError
Definition: FileUtilities.h:85
llvm::None
const NoneType None
Definition: None.h:24
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:46
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:590
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:110
llvm::ValueInfo
Struct that holds a reference to a particular GUID in a global value summary.
Definition: ModuleSummaryIndex.h:167
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:83
computeDeadSymbolsInIndex
static void computeDeadSymbolsInIndex(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Definition: ThinLTOCodeGenerator.cpp:677
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::lto::Config::OptLevel
unsigned OptLevel
Definition: Config.h:57
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:878
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::GlobalValue::isWeakForLinker
bool isWeakForLinker() const
Definition: GlobalValue.h:515
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::SubtargetFeatures::getString
std::string getString() const
Returns features as a string.
Definition: SubtargetFeature.cpp:50
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:263
IRObjectFile.h
llvm::Module::getName
StringRef getName() const
Get a short "name" for the module.
Definition: Module.h:245
VI
@ VI
Definition: SIInstrInfo.cpp:7845
Threading.h
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:446
llvm::StandardInstrumentations
This class provides an interface to register all the standard pass instrumentations and manages their...
Definition: StandardInstrumentations.h:504
llvm::sys::fs::exists
bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1077
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
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:1709
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:963
llvm::remarks::HotnessThresholdParser
Definition: HotnessThresholdParser.h:45
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:428
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:716
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:1400
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
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:778
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:152
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
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:48
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:228
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:904
llvm::lto::Config::MAttrs
std::vector< std::string > MAttrs
Definition: Config.h:49
llvm::GlobalValue::isAvailableExternallyLinkage
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:344
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:95
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:4687
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:23
llvm::lto::Config::RelocModel
Optional< Reloc::Model > RelocModel
Definition: Config.h:53
FileUtilities.h
llvm::PIELevel::Default
@ Default
Definition: CodeGen.h:37
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
DP
So we should use XX3Form_Rcr to implement intrinsic 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_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::ThreadPool::async
auto async(Function &&F, Args &&...ArgList)
Asynchronous submission of a task to the pool.
Definition: ThreadPool.h:66
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:567
llvm::ThinLTOCodeGenerator::linkCombinedIndex
std::unique_ptr< ModuleSummaryIndex > linkCombinedIndex()
Produce the combined summary index from all the bitcode files: "thin-link".
Definition: ThinLTOCodeGenerator.cpp:627
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:444
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:1644
llvm::AMDGPU::SendMsg::Msg
const CustomOperand< const MCSubtargetInfo & > Msg[]
Definition: AMDGPUAsmUtils.cpp:39
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:123
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:460
ThinLTOCodeGenerator.h
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:243
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
Verifier.h
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:4732
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
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:84
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition: DWARFUnitIndex.h:67
llvm::ThinLTOCodeGenerator::optimize
void optimize(Module &Module)
Perform post-importing ThinLTO optimizations.
Definition: ThinLTOCodeGenerator.cpp:914
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
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:458
llvm::timeTraceProfilerEnabled
bool timeTraceProfilerEnabled()
Is the time trace profiler enabled, i.e. initialized?
Definition: TimeProfiler.h:35
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:559
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:437
llvm::TargetMachineBuilder::MCpu
std::string MCpu
Definition: ThinLTOCodeGenerator.h:37
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:346
llvm::TargetMachineBuilder::create
std::unique_ptr< TargetMachine > create() const
Definition: ThinLTOCodeGenerator.cpp:602
llvm::object::Identifier
@ Identifier
Definition: COFFModuleDefinition.cpp:34
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:675
llvm::sys::fs::is_directory
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition: Path.cpp:1092
llvm::legacy::PassManager::add
void add(Pass *P) override
Add a pass to the queue of passes to run.
Definition: LegacyPassManager.cpp:1665
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:842
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:260
llvm::Module::getPIELevel
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition: Module.cpp:602
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:498
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:597
llvm::lto::generateModulesOrdering
std::vector< int > generateModulesOrdering(ArrayRef< BitcodeModule * > R)
Produces a container ordering for optimal multi-threaded processing.
Definition: LTO.cpp:1648
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:1087
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:258
llvm::PassBuilder::crossRegisterProxies
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Definition: PassBuilder.cpp:1605
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
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:662
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:474
ScopeExit.h
llvm::legacy::PassManager::run
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition: LegacyPassManager.cpp:1671
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:653
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:42
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::lto::Config::CPU
std::string CPU
Definition: Config.h:47
LLVMContext.h
llvm::createObjCARCContractPass
Pass * createObjCARCContractPass()
Definition: ObjCARCContract.cpp:733
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
BitcodeReader.h
llvm::ARMBuildAttrs::File
@ File
Definition: ARMBuildAttributes.h:36
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:966
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
FunctionAttrs.h
llvm::DS_Error
@ DS_Error
Definition: DiagnosticInfo.h:50
Debug.h
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:443
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:1016
llvm::verifyModule
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:6161
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:469
llvm::Module::size
size_t size() const
Definition: Module.h:633