LLVM  14.0.0git
LTOBackend.cpp
Go to the documentation of this file.
1 //===-LTOBackend.cpp - LLVM Link Time Optimizer Backend -------------------===//
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 "backend" phase of LTO, i.e. it performs
10 // optimization and code generation on a loaded module. It is generally used
11 // internally by the LTO class but can also be used independently, for example
12 // to implement a standalone ThinLTO backend.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "llvm/LTO/LTOBackend.h"
26 #include "llvm/IR/PassManager.h"
27 #include "llvm/IR/Verifier.h"
28 #include "llvm/LTO/LTO.h"
32 #include "llvm/Passes/PassPlugin.h"
34 #include "llvm/Support/Error.h"
37 #include "llvm/Support/Path.h"
38 #include "llvm/Support/Program.h"
44 #include "llvm/Transforms/IPO.h"
49 
50 using namespace llvm;
51 using namespace lto;
52 
53 #define DEBUG_TYPE "lto-backend"
54 
55 enum class LTOBitcodeEmbedding {
56  DoNotEmbed = 0,
57  EmbedOptimized = 1,
59 };
60 
62  "lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed),
64  "Do not embed"),
66  "Embed after all optimization passes"),
68  "post-merge-pre-opt",
69  "Embed post merge, but before optimizations")),
70  cl::desc("Embed LLVM bitcode in object files produced by LTO"));
71 
73  "thinlto-assume-merged", cl::init(false),
74  cl::desc("Assume the input has already undergone ThinLTO function "
75  "importing and the other pre-optimization pipeline changes."));
76 
77 namespace llvm {
79 }
80 
81 [[noreturn]] static void reportOpenError(StringRef Path, Twine Msg) {
82  errs() << "failed to open " << Path << ": " << Msg << '\n';
83  errs().flush();
84  exit(1);
85 }
86 
87 Error Config::addSaveTemps(std::string OutputFileName,
88  bool UseInputModulePath) {
90 
91  std::error_code EC;
93  std::make_unique<raw_fd_ostream>(OutputFileName + "resolution.txt", EC,
95  if (EC) {
96  ResolutionFile.reset();
97  return errorCodeToError(EC);
98  }
99 
100  auto setHook = [&](std::string PathSuffix, ModuleHookFn &Hook) {
101  // Keep track of the hook provided by the linker, which also needs to run.
102  ModuleHookFn LinkerHook = Hook;
103  Hook = [=](unsigned Task, const Module &M) {
104  // If the linker's hook returned false, we need to pass that result
105  // through.
106  if (LinkerHook && !LinkerHook(Task, M))
107  return false;
108 
109  std::string PathPrefix;
110  // If this is the combined module (not a ThinLTO backend compile) or the
111  // user hasn't requested using the input module's path, emit to a file
112  // named from the provided OutputFileName with the Task ID appended.
113  if (M.getModuleIdentifier() == "ld-temp.o" || !UseInputModulePath) {
114  PathPrefix = OutputFileName;
115  if (Task != (unsigned)-1)
116  PathPrefix += utostr(Task) + ".";
117  } else
118  PathPrefix = M.getModuleIdentifier() + ".";
119  std::string Path = PathPrefix + PathSuffix + ".bc";
120  std::error_code EC;
122  // Because -save-temps is a debugging feature, we report the error
123  // directly and exit.
124  if (EC)
125  reportOpenError(Path, EC.message());
126  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false);
127  return true;
128  };
129  };
130 
131  setHook("0.preopt", PreOptModuleHook);
132  setHook("1.promote", PostPromoteModuleHook);
133  setHook("2.internalize", PostInternalizeModuleHook);
134  setHook("3.import", PostImportModuleHook);
135  setHook("4.opt", PostOptModuleHook);
136  setHook("5.precodegen", PreCodeGenModuleHook);
137 
139  [=](const ModuleSummaryIndex &Index,
140  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
141  std::string Path = OutputFileName + "index.bc";
142  std::error_code EC;
144  // Because -save-temps is a debugging feature, we report the error
145  // directly and exit.
146  if (EC)
147  reportOpenError(Path, EC.message());
148  WriteIndexToFile(Index, OS);
149 
150  Path = OutputFileName + "index.dot";
152  if (EC)
153  reportOpenError(Path, EC.message());
154  Index.exportToDot(OSDot, GUIDPreservedSymbols);
155  return true;
156  };
157 
158  return Error::success();
159 }
160 
161 #define HANDLE_EXTENSION(Ext) \
162  llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
163 #include "llvm/Support/Extension.def"
164 
166  PassBuilder &PB) {
167 #define HANDLE_EXTENSION(Ext) \
168  get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
169 #include "llvm/Support/Extension.def"
170 
171  // Load requested pass plugins and let them register pass builder callbacks
172  for (auto &PluginFN : PassPlugins) {
173  auto PassPlugin = PassPlugin::Load(PluginFN);
174  if (!PassPlugin) {
175  errs() << "Failed to load passes from '" << PluginFN
176  << "'. Request ignored.\n";
177  continue;
178  }
179 
181  }
182 }
183 
184 static std::unique_ptr<TargetMachine>
185 createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
186  StringRef TheTriple = M.getTargetTriple();
187  SubtargetFeatures Features;
188  Features.getDefaultSubtargetFeatures(Triple(TheTriple));
189  for (const std::string &A : Conf.MAttrs)
190  Features.AddFeature(A);
191 
192  Optional<Reloc::Model> RelocModel = None;
193  if (Conf.RelocModel)
194  RelocModel = *Conf.RelocModel;
195  else if (M.getModuleFlag("PIC Level"))
196  RelocModel =
197  M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_;
198 
199  Optional<CodeModel::Model> CodeModel;
200  if (Conf.CodeModel)
201  CodeModel = *Conf.CodeModel;
202  else
203  CodeModel = M.getCodeModel();
204 
205  std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
206  TheTriple, Conf.CPU, Features.getString(), Conf.Options, RelocModel,
207  CodeModel, Conf.CGOptLevel));
208  assert(TM && "Failed to create target machine");
209  return TM;
210 }
211 
212 static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
213  unsigned OptLevel, bool IsThinLTO,
214  ModuleSummaryIndex *ExportSummary,
215  const ModuleSummaryIndex *ImportSummary) {
216  Optional<PGOOptions> PGOOpt;
217  if (!Conf.SampleProfile.empty())
218  PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
220  else if (Conf.RunCSIRInstr) {
221  PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping,
223  Conf.AddFSDiscriminator);
224  } else if (!Conf.CSIRProfile.empty()) {
225  PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
227  Conf.AddFSDiscriminator);
229  } else if (Conf.AddFSDiscriminator) {
230  PGOOpt = PGOOptions("", "", "", PGOOptions::NoAction,
231  PGOOptions::NoCSAction, true);
232  }
233  if (TM)
234  TM->setPGOOption(PGOOpt);
235 
240 
244  PassBuilder PB(TM, Conf.PTO, PGOOpt, &PIC);
245 
247 
248  std::unique_ptr<TargetLibraryInfoImpl> TLII(
249  new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
250  if (Conf.Freestanding)
251  TLII->disableAllFunctions();
252  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
253 
254  AAManager AA;
255  // Parse a custom AA pipeline if asked to.
256  if (!Conf.AAPipeline.empty()) {
257  if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
258  report_fatal_error("unable to parse AA pipeline description '" +
259  Conf.AAPipeline + "': " + toString(std::move(Err)));
260  }
261  } else {
262  AA = PB.buildDefaultAAPipeline();
263  }
264  // Register the AA manager first so that our version is the one used.
265  FAM.registerPass([&] { return std::move(AA); });
266 
267  // Register all the basic analyses with the managers.
273 
275 
276  if (!Conf.DisableVerify)
278 
280 
281  switch (OptLevel) {
282  default:
283  llvm_unreachable("Invalid optimization level");
284  case 0:
286  break;
287  case 1:
289  break;
290  case 2:
292  break;
293  case 3:
295  break;
296  }
297 
298  // Parse a custom pipeline if asked to.
299  if (!Conf.OptPipeline.empty()) {
300  if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
301  report_fatal_error("unable to parse pass pipeline description '" +
302  Conf.OptPipeline + "': " + toString(std::move(Err)));
303  }
304  } else if (IsThinLTO) {
305  MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
306  } else {
307  MPM.addPass(PB.buildLTODefaultPipeline(OL, ExportSummary));
308  }
309 
310  if (!Conf.DisableVerify)
312 
313  MPM.run(Mod, MAM);
314 }
315 
316 static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
317  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
318  const ModuleSummaryIndex *ImportSummary) {
319  legacy::PassManager passes;
320  passes.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
321 
322  PassManagerBuilder PMB;
323  PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()));
324  if (Conf.Freestanding)
327  PMB.ExportSummary = ExportSummary;
328  PMB.ImportSummary = ImportSummary;
329  // Unconditionally verify input since it is not verified before this
330  // point and has unknown origin.
331  PMB.VerifyInput = true;
332  PMB.VerifyOutput = !Conf.DisableVerify;
333  PMB.LoopVectorize = true;
334  PMB.SLPVectorize = true;
335  PMB.OptLevel = Conf.OptLevel;
336  PMB.PGOSampleUse = Conf.SampleProfile;
338  if (!Conf.RunCSIRInstr && !Conf.CSIRProfile.empty()) {
339  PMB.EnablePGOCSInstrUse = true;
340  PMB.PGOInstrUse = Conf.CSIRProfile;
341  }
342  if (IsThinLTO)
343  PMB.populateThinLTOPassManager(passes);
344  else
345  PMB.populateLTOPassManager(passes);
346  passes.run(Mod);
347 }
348 
349 bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
350  bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
351  const ModuleSummaryIndex *ImportSummary,
352  const std::vector<uint8_t> &CmdArgs) {
354  // FIXME: the motivation for capturing post-merge bitcode and command line
355  // is replicating the compilation environment from bitcode, without needing
356  // to understand the dependencies (the functions to be imported). This
357  // assumes a clang - based invocation, case in which we have the command
358  // line.
359  // It's not very clear how the above motivation would map in the
360  // linker-based case, so we currently don't plumb the command line args in
361  // that case.
362  if (CmdArgs.empty())
363  LLVM_DEBUG(
364  dbgs() << "Post-(Thin)LTO merge bitcode embedding was requested, but "
365  "command line arguments are not available");
367  /*EmbedBitcode*/ true, /*EmbedCmdline*/ true,
368  /*Cmdline*/ CmdArgs);
369  }
370  // FIXME: Plumb the combined index into the new pass manager.
371  if (Conf.UseNewPM || !Conf.OptPipeline.empty()) {
372  runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
373  ImportSummary);
374  } else {
375  runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
376  }
377  return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
378 }
379 
380 static void codegen(const Config &Conf, TargetMachine *TM,
381  AddStreamFn AddStream, unsigned Task, Module &Mod,
382  const ModuleSummaryIndex &CombinedIndex) {
383  if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod))
384  return;
385 
388  /*EmbedBitcode*/ true,
389  /*EmbedCmdline*/ false,
390  /*CmdArgs*/ std::vector<uint8_t>());
391 
392  std::unique_ptr<ToolOutputFile> DwoOut;
393  SmallString<1024> DwoFile(Conf.SplitDwarfOutput);
394  if (!Conf.DwoDir.empty()) {
395  std::error_code EC;
396  if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
397  report_fatal_error("Failed to create directory " + Conf.DwoDir + ": " +
398  EC.message());
399 
400  DwoFile = Conf.DwoDir;
401  sys::path::append(DwoFile, std::to_string(Task) + ".dwo");
402  TM->Options.MCOptions.SplitDwarfFile = std::string(DwoFile);
403  } else
404  TM->Options.MCOptions.SplitDwarfFile = Conf.SplitDwarfFile;
405 
406  if (!DwoFile.empty()) {
407  std::error_code EC;
408  DwoOut = std::make_unique<ToolOutputFile>(DwoFile, EC, sys::fs::OF_None);
409  if (EC)
410  report_fatal_error("Failed to open " + DwoFile + ": " + EC.message());
411  }
412 
413  auto Stream = AddStream(Task);
414  legacy::PassManager CodeGenPasses;
415  CodeGenPasses.add(
417  if (Conf.PreCodeGenPassesHook)
418  Conf.PreCodeGenPassesHook(CodeGenPasses);
419  if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS,
420  DwoOut ? &DwoOut->os() : nullptr,
421  Conf.CGFileType))
422  report_fatal_error("Failed to setup codegen");
423  CodeGenPasses.run(Mod);
424 
425  if (DwoOut)
426  DwoOut->keep();
427 }
428 
429 static void splitCodeGen(const Config &C, TargetMachine *TM,
430  AddStreamFn AddStream,
431  unsigned ParallelCodeGenParallelismLevel, Module &Mod,
432  const ModuleSummaryIndex &CombinedIndex) {
433  ThreadPool CodegenThreadPool(
434  heavyweight_hardware_concurrency(ParallelCodeGenParallelismLevel));
435  unsigned ThreadCount = 0;
436  const Target *T = &TM->getTarget();
437 
438  SplitModule(
439  Mod, ParallelCodeGenParallelismLevel,
440  [&](std::unique_ptr<Module> MPart) {
441  // We want to clone the module in a new context to multi-thread the
442  // codegen. We do it by serializing partition modules to bitcode
443  // (while still on the main thread, in order to avoid data races) and
444  // spinning up new threads which deserialize the partitions into
445  // separate contexts.
446  // FIXME: Provide a more direct way to do this in LLVM.
447  SmallString<0> BC;
448  raw_svector_ostream BCOS(BC);
449  WriteBitcodeToFile(*MPart, BCOS);
450 
451  // Enqueue the task
452  CodegenThreadPool.async(
453  [&](const SmallString<0> &BC, unsigned ThreadId) {
454  LTOLLVMContext Ctx(C);
456  MemoryBufferRef(StringRef(BC.data(), BC.size()), "ld-temp.o"),
457  Ctx);
458  if (!MOrErr)
459  report_fatal_error("Failed to read bitcode");
460  std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
461 
462  std::unique_ptr<TargetMachine> TM =
463  createTargetMachine(C, T, *MPartInCtx);
464 
465  codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx,
466  CombinedIndex);
467  },
468  // Pass BC using std::move to ensure that it get moved rather than
469  // copied into the thread's context.
470  std::move(BC), ThreadCount++);
471  },
472  false);
473 
474  // Because the inner lambda (which runs in a worker thread) captures our local
475  // variables, we need to wait for the worker threads to terminate before we
476  // can leave the function scope.
477  CodegenThreadPool.wait();
478 }
479 
481  Module &Mod) {
482  if (!C.OverrideTriple.empty())
483  Mod.setTargetTriple(C.OverrideTriple);
484  else if (Mod.getTargetTriple().empty())
485  Mod.setTargetTriple(C.DefaultTriple);
486 
487  std::string Msg;
489  if (!T)
490  return make_error<StringError>(Msg, inconvertibleErrorCode());
491  return T;
492 }
493 
495  std::unique_ptr<ToolOutputFile> DiagOutputFile) {
496  // Make sure we flush the diagnostic remarks file in case the linker doesn't
497  // call the global destructors before exiting.
498  if (!DiagOutputFile)
499  return Error::success();
500  DiagOutputFile->keep();
501  DiagOutputFile->os().flush();
502  return Error::success();
503 }
504 
506  unsigned ParallelCodeGenParallelismLevel, Module &Mod,
507  ModuleSummaryIndex &CombinedIndex) {
509  if (!TOrErr)
510  return TOrErr.takeError();
511 
512  std::unique_ptr<TargetMachine> TM = createTargetMachine(C, *TOrErr, Mod);
513 
514  if (!C.CodeGenOnly) {
515  if (!opt(C, TM.get(), 0, Mod, /*IsThinLTO=*/false,
516  /*ExportSummary=*/&CombinedIndex, /*ImportSummary=*/nullptr,
517  /*CmdArgs*/ std::vector<uint8_t>()))
518  return Error::success();
519  }
520 
521  if (ParallelCodeGenParallelismLevel == 1) {
522  codegen(C, TM.get(), AddStream, 0, Mod, CombinedIndex);
523  } else {
524  splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel, Mod,
525  CombinedIndex);
526  }
527  return Error::success();
528 }
529 
530 static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals,
531  const ModuleSummaryIndex &Index) {
532  std::vector<GlobalValue*> DeadGVs;
533  for (auto &GV : Mod.global_values())
534  if (GlobalValueSummary *GVS = DefinedGlobals.lookup(GV.getGUID()))
535  if (!Index.isGlobalValueLive(GVS)) {
536  DeadGVs.push_back(&GV);
538  }
539 
540  // Now that all dead bodies have been dropped, delete the actual objects
541  // themselves when possible.
542  for (GlobalValue *GV : DeadGVs) {
543  GV->removeDeadConstantUsers();
544  // Might reference something defined in native object (i.e. dropped a
545  // non-prevailing IR def, but we need to keep the declaration).
546  if (GV->use_empty())
547  GV->eraseFromParent();
548  }
549 }
550 
551 Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
552  Module &Mod, const ModuleSummaryIndex &CombinedIndex,
553  const FunctionImporter::ImportMapTy &ImportList,
554  const GVSummaryMapTy &DefinedGlobals,
556  const std::vector<uint8_t> &CmdArgs) {
558  if (!TOrErr)
559  return TOrErr.takeError();
560 
561  std::unique_ptr<TargetMachine> TM = createTargetMachine(Conf, *TOrErr, Mod);
562 
563  // Setup optimization remarks.
564  auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks(
567  Task);
568  if (!DiagFileOrErr)
569  return DiagFileOrErr.takeError();
570  auto DiagnosticOutputFile = std::move(*DiagFileOrErr);
571 
572  // Set the partial sample profile ratio in the profile summary module flag of
573  // the module, if applicable.
574  Mod.setPartialSampleProfileRatio(CombinedIndex);
575 
576  if (Conf.CodeGenOnly) {
577  codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex);
578  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
579  }
580 
581  if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod))
582  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
583 
584  auto OptimizeAndCodegen =
585  [&](Module &Mod, TargetMachine *TM,
586  std::unique_ptr<ToolOutputFile> DiagnosticOutputFile) {
587  if (!opt(Conf, TM, Task, Mod, /*IsThinLTO=*/true,
588  /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex,
589  CmdArgs))
590  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
591 
592  codegen(Conf, TM, AddStream, Task, Mod, CombinedIndex);
593  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
594  };
595 
597  return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
598 
599  // When linking an ELF shared object, dso_local should be dropped. We
600  // conservatively do this for -fpic.
601  bool ClearDSOLocalOnDeclarations =
602  TM->getTargetTriple().isOSBinFormatELF() &&
603  TM->getRelocationModel() != Reloc::Static &&
605  renameModuleForThinLTO(Mod, CombinedIndex, ClearDSOLocalOnDeclarations);
606 
607  dropDeadSymbols(Mod, DefinedGlobals, CombinedIndex);
608 
609  thinLTOResolvePrevailingInModule(Mod, DefinedGlobals);
610 
611  if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod))
612  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
613 
614  if (!DefinedGlobals.empty())
615  thinLTOInternalizeModule(Mod, DefinedGlobals);
616 
617  if (Conf.PostInternalizeModuleHook &&
618  !Conf.PostInternalizeModuleHook(Task, Mod))
619  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
620 
621  auto ModuleLoader = [&](StringRef Identifier) {
623  "ODR Type uniquing should be enabled on the context");
624  if (ModuleMap) {
625  auto I = ModuleMap->find(Identifier);
626  assert(I != ModuleMap->end());
627  return I->second.getLazyModule(Mod.getContext(),
628  /*ShouldLazyLoadMetadata=*/true,
629  /*IsImporting*/ true);
630  }
631 
633  llvm::MemoryBuffer::getFile(Identifier);
634  if (!MBOrErr)
635  return Expected<std::unique_ptr<llvm::Module>>(make_error<StringError>(
636  Twine("Error loading imported file ") + Identifier + " : ",
637  MBOrErr.getError()));
638 
639  Expected<BitcodeModule> BMOrErr = findThinLTOModule(**MBOrErr);
640  if (!BMOrErr)
641  return Expected<std::unique_ptr<llvm::Module>>(make_error<StringError>(
642  Twine("Error loading imported file ") + Identifier + " : " +
643  toString(BMOrErr.takeError()),
645 
647  BMOrErr->getLazyModule(Mod.getContext(),
648  /*ShouldLazyLoadMetadata=*/true,
649  /*IsImporting*/ true);
650  if (MOrErr)
651  (*MOrErr)->setOwnedMemoryBuffer(std::move(*MBOrErr));
652  return MOrErr;
653  };
654 
655  FunctionImporter Importer(CombinedIndex, ModuleLoader,
656  ClearDSOLocalOnDeclarations);
657  if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
658  return Err;
659 
660  if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
661  return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile));
662 
663  return OptimizeAndCodegen(Mod, TM.get(), std::move(DiagnosticOutputFile));
664 }
665 
667  if (ThinLTOAssumeMerged && BMs.size() == 1)
668  return BMs.begin();
669 
670  for (BitcodeModule &BM : BMs) {
671  Expected<BitcodeLTOInfo> LTOInfo = BM.getLTOInfo();
672  if (LTOInfo && LTOInfo->IsThinLTO)
673  return &BM;
674  }
675  return nullptr;
676 }
677 
680  if (!BMsOrErr)
681  return BMsOrErr.takeError();
682 
683  // The bitcode file may contain multiple modules, we want the one that is
684  // marked as being the ThinLTO module.
685  if (const BitcodeModule *Bm = lto::findThinLTOModule(*BMsOrErr))
686  return *Bm;
687 
688  return make_error<StringError>("Could not find module summary",
690 }
691 
693  const ModuleSummaryIndex &CombinedIndex,
694  FunctionImporter::ImportMapTy &ImportList) {
696  return true;
697  // We can simply import the values mentioned in the combined index, since
698  // we should only invoke this using the individual indexes written out
699  // via a WriteIndexesThinBackend.
700  for (const auto &GlobalList : CombinedIndex) {
701  // Ignore entries for undefined references.
702  if (GlobalList.second.SummaryList.empty())
703  continue;
704 
705  auto GUID = GlobalList.first;
706  for (const auto &Summary : GlobalList.second.SummaryList) {
707  // Skip the summaries for the importing module. These are included to
708  // e.g. record required linkage changes.
709  if (Summary->modulePath() == M.getModuleIdentifier())
710  continue;
711  // Add an entry to provoke importing by thinBackend.
712  ImportList[Summary->modulePath()].insert(GUID);
713  }
714  }
715  return true;
716 }
llvm::Module::global_values
iterator_range< global_value_iterator > global_values()
Definition: Module.cpp:424
MemoryBuffer.h
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1233
llvm::PassManagerBuilder::PGOSampleUse
std::string PGOSampleUse
Path of the sample Profile data file.
Definition: PassManagerBuilder.h:187
FunctionImportUtils.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
PassBuilder.h
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::lto::initImportList
bool initImportList(const Module &M, const ModuleSummaryIndex &CombinedIndex, FunctionImporter::ImportMapTy &ImportList)
Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList...
Definition: LTOBackend.cpp:692
llvm::OptimizationLevel::O1
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
Definition: OptimizationLevel.h:57
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
FileSystem.h
llvm::sys::fs::OF_None
@ OF_None
Definition: FileSystem.h:757
LTOBitcodeEmbedding::EmbedOptimized
@ EmbedOptimized
LTOBitcodeEmbedding
LTOBitcodeEmbedding
Definition: LTOBackend.cpp:55
llvm::lto::Config::DisableVerify
bool DisableVerify
Definition: Config.h:58
llvm::lto::finalizeOptimizationRemarks
Error finalizeOptimizationRemarks(std::unique_ptr< ToolOutputFile > DiagOutputFile)
Definition: LTOBackend.cpp:494
llvm::ThreadPool
A ThreadPool for asynchronous parallel execution on a defined number of threads.
Definition: ThreadPool.h:37
llvm::lto::Config::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: Config.h:55
llvm::PassManagerBuilder::VerifyOutput
bool VerifyOutput
Definition: PassManagerBuilder.h:167
llvm::DenseMapBase::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:197
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::PassPlugin
A loaded pass plugin.
Definition: PassPlugin.h:60
llvm::lto::Config::RemarksFormat
std::string RemarksFormat
The format used for serializing remarks (default: YAML).
Definition: Config.h:157
llvm::lto::Config::CodeModel
Optional< CodeModel::Model > CodeModel
Definition: Config.h:54
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
RegisterPassPlugins
static void RegisterPassPlugins(ArrayRef< std::string > PassPlugins, PassBuilder &PB)
Definition: LTOBackend.cpp:165
llvm::SubtargetFeatures::AddFeature
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Definition: SubtargetFeature.cpp:41
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1020
llvm::lto::Config::RemarksWithHotness
bool RemarksWithHotness
Whether to emit optimization remarks with hotness informations.
Definition: Config.h:139
Path.h
llvm::PassManagerBuilder::populateLTOPassManager
void populateLTOPassManager(legacy::PassManagerBase &PM)
Definition: PassManagerBuilder.cpp:1211
SmallVectorMemoryBuffer.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::PassManagerBuilder::LoopVectorize
bool LoopVectorize
Definition: PassManagerBuilder.h:160
Error.h
llvm::VerifierPass
Create a verifier pass.
Definition: Verifier.h:137
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
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::PassManagerBuilder::ImportSummary
const ModuleSummaryIndex * ImportSummary
The module summary index to use for importing information to the thin LTO backends,...
Definition: PassManagerBuilder.h:155
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
llvm::createImmutableModuleSummaryIndexWrapperPass
ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)
Definition: ModuleSummaryAnalysis.cpp:939
llvm::lto::Config
LTO configuration.
Definition: Config.h:40
llvm::Optional< Reloc::Model >
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
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:48
llvm::MapVector< StringRef, BitcodeModule >
llvm::PassManagerBuilder::ExportSummary
ModuleSummaryIndex * ExportSummary
The module summary index to use for exporting information from the regular LTO phase,...
Definition: PassManagerBuilder.h:150
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
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:1572
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::lto::Config::ShouldDiscardValueNames
bool ShouldDiscardValueNames
Definition: Config.h:174
ModuleSummaryAnalysis.h
llvm::lto::Config::PostImportModuleHook
ModuleHookFn PostImportModuleHook
This hook is called after importing from other modules (ThinLTO-specific).
Definition: Config.h:227
llvm::lto::Config::CodeGenOnly
bool CodeGenOnly
Disable entirely the optimizer, including importing for ThinLTO.
Definition: Config.h:68
llvm::PGOOptions::SampleUse
@ SampleUse
Definition: PGOOptions.h:23
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
PassManagerBuilder.h
runNewPMPasses
static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, unsigned OptLevel, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary)
Definition: LTOBackend.cpp:212
llvm::lto::findThinLTOModule
BitcodeModule * findThinLTOModule(MutableArrayRef< BitcodeModule > BMs)
Returns the BitcodeModule that is ThinLTO.
Definition: LTOBackend.cpp:666
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::lto::Config::CombinedIndexHook
CombinedIndexHookFn CombinedIndexHook
Definition: Config.h:249
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
initAndLookupTarget
static Expected< const Target * > initAndLookupTarget(const Config &C, Module &Mod)
Definition: LTOBackend.cpp:480
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
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::PassBuilder::parsePassPipeline
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
Definition: PassBuilder.cpp:1523
llvm::lto::Config::SplitDwarfFile
std::string SplitDwarfFile
The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...
Definition: Config.h:125
llvm::FunctionImporter::importFunctions
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
Definition: FunctionImport.cpp:1184
llvm::PassPlugin::Load
static Expected< PassPlugin > Load(const std::string &Filename)
Attempts to load a pass plugin from a given file.
Definition: PassPlugin.cpp:16
llvm::lto::Config::RunCSIRInstr
bool RunCSIRInstr
Run PGO context sensitive IR instrumentation.
Definition: Config.h:71
llvm::GlobalValueSummary
Function and variable summary information to aid decisions and implementation of importing.
Definition: ModuleSummaryIndex.h:290
llvm::StandardInstrumentations::registerCallbacks
void registerCallbacks(PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM=nullptr)
Definition: StandardInstrumentations.cpp:1226
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:246
llvm::lto::Config::PostPromoteModuleHook
ModuleHookFn PostPromoteModuleHook
This hook is called after promoting any internal functions (ThinLTO-specific).
Definition: Config.h:221
SubtargetFeature.h
TargetMachine.h
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
llvm::lto::opt
bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary, const std::vector< uint8_t > &CmdArgs)
Runs middle-end LTO optimizations on Mod.
Definition: LTOBackend.cpp:349
llvm::PassManagerBuilder::LibraryInfo
TargetLibraryInfoImpl * LibraryInfo
LibraryInfo - Specifies information about the runtime library for the optimizer.
Definition: PassManagerBuilder.h:141
llvm::lto::Config::SampleProfile
std::string SampleProfile
Sample PGO profile path.
Definition: Config.h:113
BitcodeWriter.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:274
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
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::lto::Config::PreCodeGenPassesHook
std::function< void(legacy::PassManager &)> PreCodeGenPassesHook
For adding passes that run right before codegen.
Definition: Config.h:52
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:183
llvm::PGOOptions::IRUse
@ IRUse
Definition: PGOOptions.h:23
TargetLibraryInfo.h
SplitModule.h
llvm::ErrorOr::getError
std::error_code getError() const
Definition: ErrorOr.h:153
llvm::LLVMContext::isODRUniquingDebugTypes
bool isODRUniquingDebugTypes() const
Whether there is a string map for uniquing debug info identifiers across the context.
Definition: LLVMContext.cpp:320
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::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::Config::ResolutionFile
std::unique_ptr< raw_ostream > ResolutionFile
If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 comman...
Definition: Config.h:184
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
LTOBitcodeEmbedding::DoNotEmbed
@ DoNotEmbed
llvm::PassManagerBuilder::Inliner
Pass * Inliner
Inliner - Specifies the inliner to use.
Definition: PassManagerBuilder.h:145
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:186
llvm::PGOOptions::CSIRInstr
@ CSIRInstr
Definition: PGOOptions.h:24
llvm::lto::Config::ModuleHookFn
std::function< bool(unsigned Task, const Module &)> ModuleHookFn
The following callbacks deal with tasks, which normally represent the entire optimization and code ge...
Definition: Config.h:213
llvm::lto::Config::DebugPassManager
bool DebugPassManager
Whether to emit the pass manager debuggging informations.
Definition: Config.h:160
llvm::SubtargetFeatures::getDefaultSubtargetFeatures
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
Definition: SubtargetFeature.cpp:70
llvm::EmbedBitcodeInModule
void EmbedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
Definition: BitcodeWriter.cpp:4896
llvm::Module::setTargetTriple
void setTargetTriple(StringRef T)
Set the target triple.
Definition: Module.h:300
llvm::None
const NoneType None
Definition: None.h:23
llvm::lto::Config::PostInternalizeModuleHook
ModuleHookFn PostInternalizeModuleHook
This hook is called after internalizing the module.
Definition: Config.h:224
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
llvm::createFunctionInliningPass
Pass * createFunctionInliningPass()
createFunctionInliningPass - Return a new pass object that uses a heuristic to inline direct function...
Definition: InlineSimple.cpp:97
llvm::sys::fs::OF_TextWithCRLF
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition: FileSystem.h:770
LTOBackend.h
llvm::PassManagerBuilder
PassManagerBuilder - This class is used to set up a standard optimization sequence for languages like...
Definition: PassManagerBuilder.h:59
llvm::lto::Config::PreCodeGenModuleHook
ModuleHookFn PreCodeGenModuleHook
This module hook is called before code generation.
Definition: Config.h:235
llvm::lto::Config::OptLevel
unsigned OptLevel
Definition: Config.h:57
llvm::convertToDeclaration
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
Definition: FunctionImport.cpp:1009
llvm::createTargetTransformInfoWrapperPass
ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
Definition: TargetTransformInfo.cpp:1171
llvm::PGOOptions::NoCSAction
@ NoCSAction
Definition: PGOOptions.h:24
PB
PassBuilder PB(Machine, PassOpts->PTO, None, &PIC)
llvm::PassPlugin::registerPassBuilderCallbacks
void registerPassBuilderCallbacks(PassBuilder &PB) const
Invoke the PassBuilder callback registration.
Definition: PassPlugin.h:82
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::lto::Config::RemarksFilename
std::string RemarksFilename
Optimization remarks file path.
Definition: Config.h:133
llvm::cl::opt
Definition: CommandLine.h:1434
llvm::lto::backend
Error backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &M, ModuleSummaryIndex &CombinedIndex)
Runs a regular LTO backend.
Definition: LTOBackend.cpp:505
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:415
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:699
llvm::StandardInstrumentations
This class provides an interface to register all the standard pass instrumentations and manages their...
Definition: StandardInstrumentations.h:414
llvm::MapVector::find
iterator find(const KeyT &Key)
Definition: MapVector.h:147
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::parseBitcodeFile
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback=[](StringRef) { return None;})
Read the specified bitcode file, returning the module.
Definition: BitcodeReader.cpp:7011
IPO.h
llvm::lto::Config::DwoDir
std::string DwoDir
The directory to store .dwo files.
Definition: Config.h:119
llvm::lto::Config::AddFSDiscriminator
bool AddFSDiscriminator
Add FSAFDO discriminators.
Definition: Config.h:178
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:397
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::DenseMap
Definition: DenseMap.h:714
CGSCCPassManager.h
llvm::PassBuilder::buildLTODefaultPipeline
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1343
llvm::lto::LTOLLVMContext
A derived class of LLVMContext that initializes itself according to a given Config object.
Definition: Config.h:284
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::PICLevel::NotPIC
@ NotPIC
Definition: CodeGen.h:33
llvm::PassBuilder::buildThinLTODefaultPipeline
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1278
createTargetMachine
static std::unique_ptr< TargetMachine > createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M)
Definition: LTOBackend.cpp:185
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:1708
llvm::lto::Config::addSaveTemps
Error addSaveTemps(std::string OutputFileName, bool UseInputModulePath=false)
This is a convenience function that configures this Config object to write temporary files named afte...
Definition: LTOBackend.cpp:87
llvm::PassManagerBuilder::OptLevel
unsigned OptLevel
The Optimization Level - Specify the basic optimization level.
Definition: PassManagerBuilder.h:132
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::PassManagerBuilder::PGOInstrUse
std::string PGOInstrUse
Path of the profile data file.
Definition: PassManagerBuilder.h:185
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::lto::Config::SplitDwarfOutput
std::string SplitDwarfOutput
The path to write a .dwo file to.
Definition: Config.h:130
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::PassManagerBuilder::VerifyInput
bool VerifyInput
Definition: PassManagerBuilder.h:166
llvm::lto::Config::MAttrs
std::vector< std::string > MAttrs
Definition: Config.h:49
llvm::MutableArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:356
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
LoopPassManager.h
llvm::lto::Config::ProfileRemapping
std::string ProfileRemapping
Name remapping file for profile data.
Definition: Config.h:116
llvm::PGOOptions::NoAction
@ NoAction
Definition: PGOOptions.h:23
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
ModuleSymbolTable.h
llvm::lto::Config::RelocModel
Optional< Reloc::Model > RelocModel
Definition: Config.h:53
llvm::ArrayRef< std::string >
llvm::lto::Config::PostOptModuleHook
ModuleHookFn PostOptModuleHook
This module hook is called after optimization is complete.
Definition: Config.h:230
llvm::lto::Config::RemarksHotnessThreshold
llvm::Optional< uint64_t > RemarksHotnessThreshold
The minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.
Definition: Config.h:154
llvm::PassManagerBuilder::SLPVectorize
bool SLPVectorize
Definition: PassManagerBuilder.h:159
llvm::Reloc::PIC_
@ PIC_
Definition: CodeGen.h:22
llvm::lto::thinBackend
Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, Module &M, const ModuleSummaryIndex &CombinedIndex, const FunctionImporter::ImportMapTy &ImportList, const GVSummaryMapTy &DefinedGlobals, MapVector< StringRef, BitcodeModule > *ModuleMap, const std::vector< uint8_t > &CmdArgs=std::vector< uint8_t >())
Runs a ThinLTO backend.
Definition: LTOBackend.cpp:551
llvm::PIELevel::Default
@ Default
Definition: CodeGen.h:37
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
LTOBitcodeEmbedding::EmbedPostMergePreOptimized
@ EmbedPostMergePreOptimized
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
PassPlugin.h
llvm::PGOOptions
A struct capturing PGO tunables.
Definition: PGOOptions.h:22
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
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:674
llvm::lto::Config::OptPipeline
std::string OptPipeline
If this field is set, the set of passes run in the middle-end optimizer will be the one specified by ...
Definition: Config.h:94
ThinLTOAssumeMerged
static cl::opt< bool > ThinLTOAssumeMerged("thinlto-assume-merged", cl::init(false), cl::desc("Assume the input has already undergone ThinLTO function " "importing and the other pre-optimization pipeline changes."))
llvm::NoPGOWarnMismatch
cl::opt< bool > NoPGOWarnMismatch
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::PassBuilder::parseAAPipeline
Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
Definition: PassBuilder.cpp:1626
llvm::MapVector::end
iterator end()
Definition: MapVector.h:71
runOldPMPasses
static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary)
Definition: LTOBackend.cpp:316
llvm::PassManager< Module >
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
EmbedBitcode
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:424
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::lto::AddStreamFn
std::function< std::unique_ptr< NativeObjectStream >(unsigned Task)> AddStreamFn
This type defines the callback to add a native object that is generated on the fly.
Definition: LTO.h:206
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
LLVMRemarkStreamer.h
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::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:261
dropDeadSymbols
static void dropDeadSymbols(Module &Mod, const GVSummaryMapTy &DefinedGlobals, const ModuleSummaryIndex &Index)
Definition: LTOBackend.cpp:530
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:406
llvm::OptimizationLevel
Definition: OptimizationLevel.h:22
llvm::lto::Config::AAPipeline
std::string AAPipeline
Definition: Config.h:99
PassManager.h
llvm::lto::Config::PreOptModuleHook
ModuleHookFn PreOptModuleHook
This module hook is called after linking (regular LTO) or loading (ThinLTO) the module,...
Definition: Config.h:217
llvm::PGOOptions::CSIRUse
@ CSIRUse
Definition: PGOOptions.h:24
llvm::lto::Config::PTO
PipelineTuningOptions PTO
Tunable parameters for passes in the default pipelines.
Definition: Config.h:187
llvm::legacy::PassManager::add
void add(Pass *P) override
Add a pass to the queue of passes to run.
Definition: LegacyPassManager.cpp:1674
llvm::lto::Config::CSIRProfile
std::string CSIRProfile
Context Sensitive PGO profile path.
Definition: Config.h:110
reportOpenError
static void reportOpenError(StringRef Path, Twine Msg)
Definition: LTOBackend.cpp:81
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:841
llvm::PassManagerBuilder::EnablePGOCSInstrGen
bool EnablePGOCSInstrGen
Enable profile context sensitive instrumentation pass.
Definition: PassManagerBuilder.h:179
llvm::Module::getPIELevel
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition: Module.cpp:605
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
llvm::PassManagerBuilder::EnablePGOCSInstrUse
bool EnablePGOCSInstrUse
Enable profile context sensitive profile use pass.
Definition: PassManagerBuilder.h:181
llvm::Module::setPartialSampleProfileRatio
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index)
Set the partial sample profile ratio in the profile summary module flag, if applicable.
Definition: Module.cpp:793
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:589
llvm::ThreadPool::wait
void wait()
Blocking wait for all the threads to complete and the queue to be empty.
Definition: ThreadPool.cpp:69
codegen
static void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, unsigned Task, Module &Mod, const ModuleSummaryIndex &CombinedIndex)
Definition: LTOBackend.cpp:380
llvm::lto::Config::CGFileType
CodeGenFileType CGFileType
Definition: Config.h:56
llvm::lto::Config::UseNewPM
bool UseNewPM
Use the new pass manager.
Definition: Config.h:61
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
exit
declare void exit(i32) noreturn nounwind This compiles into
Definition: README.txt:1072
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:1498
Program.h
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:63
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
TargetTransformInfo.h
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::legacy::PassManager::run
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
Definition: LegacyPassManager.cpp:1680
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::PassManagerBuilder::populateThinLTOPassManager
void populateThinLTOPassManager(legacy::PassManagerBase &PM)
Definition: PassManagerBuilder.cpp:1178
llvm::lto::Config::PassPlugins
std::vector< std::string > PassPlugins
Definition: Config.h:50
llvm::lto::Config::CPU
std::string CPU
Definition: Config.h:47
llvm::getBitcodeModuleList
Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)
Returns a list of modules in the specified bitcode buffer.
Definition: BitcodeReader.cpp:6664
llvm::BitcodeModule
Represents a module in a bitcode file.
Definition: BitcodeReader.h:60
llvm::cl::desc
Definition: CommandLine.h:414
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
BitcodeReader.h
raw_ostream.h
llvm::PassManager::addPass
std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:552
TargetRegistry.h
llvm::SplitModule
void SplitModule(Module &M, unsigned N, function_ref< void(std::unique_ptr< Module > MPart)> ModuleCallback, bool PreserveLocals=false)
Splits the module M into N linkable partitions.
Definition: SplitModule.cpp:248
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:438
llvm::splitCodeGen
void splitCodeGen(Module &M, ArrayRef< raw_pwrite_stream * > OSs, ArrayRef< llvm::raw_pwrite_stream * > BCOSs, const std::function< std::unique_ptr< TargetMachine >()> &TMFactory, CodeGenFileType FileType=CGFT_ObjectFile, bool PreserveLocals=false)
Split M into OSs.size() partitions, and generate code for each.
Definition: ParallelCG.cpp:39
llvm::lto::Config::RemarksPasses
std::string RemarksPasses
Optimization remarks pass filter.
Definition: Config.h:136
llvm::lto::Config::PGOWarnMismatch
bool PGOWarnMismatch
Turn on/off the warning about a hash mismatch in the PGO profile data.
Definition: Config.h:74
StandardInstrumentations.h
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