LTOBackend.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-LTOBackend.h - LLVM Link Time Optimizer Backend ---------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file implements the "backend" phase of LTO, i.e. it performs
  15. // optimization and code generation on a loaded module. It is generally used
  16. // internally by the LTO class but can also be used independently, for example
  17. // to implement a standalone ThinLTO backend.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_LTO_LTOBACKEND_H
  21. #define LLVM_LTO_LTOBACKEND_H
  22. #include "llvm/ADT/MapVector.h"
  23. #include "llvm/IR/DiagnosticInfo.h"
  24. #include "llvm/IR/ModuleSummaryIndex.h"
  25. #include "llvm/LTO/LTO.h"
  26. #include "llvm/Support/MemoryBuffer.h"
  27. #include "llvm/Target/TargetOptions.h"
  28. #include "llvm/Transforms/IPO/FunctionImport.h"
  29. namespace llvm {
  30. class BitcodeModule;
  31. class Error;
  32. class Module;
  33. class Target;
  34. namespace lto {
  35. /// Runs middle-end LTO optimizations on \p Mod.
  36. bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
  37. bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
  38. const ModuleSummaryIndex *ImportSummary,
  39. const std::vector<uint8_t> &CmdArgs);
  40. /// Runs a regular LTO backend. The regular LTO backend can also act as the
  41. /// regular LTO phase of ThinLTO, which may need to access the combined index.
  42. Error backend(const Config &C, AddStreamFn AddStream,
  43. unsigned ParallelCodeGenParallelismLevel, Module &M,
  44. ModuleSummaryIndex &CombinedIndex);
  45. /// Runs a ThinLTO backend.
  46. /// If \p ModuleMap is not nullptr, all the module files to be imported have
  47. /// already been mapped to memory and the corresponding BitcodeModule objects
  48. /// are saved in the ModuleMap. If \p ModuleMap is nullptr, module files will
  49. /// be mapped to memory on demand and at any given time during importing, only
  50. /// one source module will be kept open at the most.
  51. Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream,
  52. Module &M, const ModuleSummaryIndex &CombinedIndex,
  53. const FunctionImporter::ImportMapTy &ImportList,
  54. const GVSummaryMapTy &DefinedGlobals,
  55. MapVector<StringRef, BitcodeModule> *ModuleMap,
  56. const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
  57. Error finalizeOptimizationRemarks(
  58. std::unique_ptr<ToolOutputFile> DiagOutputFile);
  59. /// Returns the BitcodeModule that is ThinLTO.
  60. BitcodeModule *findThinLTOModule(MutableArrayRef<BitcodeModule> BMs);
  61. /// Variant of the above.
  62. Expected<BitcodeModule> findThinLTOModule(MemoryBufferRef MBRef);
  63. /// Distributed ThinLTO: collect the referenced modules based on
  64. /// module summary and initialize ImportList. Returns false if the
  65. /// operation failed.
  66. bool initImportList(const Module &M, const ModuleSummaryIndex &CombinedIndex,
  67. FunctionImporter::ImportMapTy &ImportList);
  68. }
  69. }
  70. #endif
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif