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