Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===-LTOBackend.h - LLVM Link Time Optimizer Backend ---------------------===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 | #ifndef LLVM_LTO_LTOBACKEND_H |
| 17 | #define LLVM_LTO_LTOBACKEND_H |
| 18 | |
| 19 | #include "llvm/ADT/MapVector.h" |
| 20 | #include "llvm/IR/DiagnosticInfo.h" |
| 21 | #include "llvm/IR/ModuleSummaryIndex.h" |
| 22 | #include "llvm/LTO/LTO.h" |
| 23 | #include "llvm/Support/MemoryBuffer.h" |
| 24 | #include "llvm/Target/TargetOptions.h" |
| 25 | #include "llvm/Transforms/IPO/FunctionImport.h" |
| 26 | |
| 27 | namespace llvm { |
| 28 | |
| 29 | class BitcodeModule; |
| 30 | class Error; |
| 31 | class Module; |
| 32 | class Target; |
| 33 | |
| 34 | namespace lto { |
| 35 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 36 | /// Runs middle-end LTO optimizations on \p Mod. |
| 37 | bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, |
| 38 | bool IsThinLTO, ModuleSummaryIndex *ExportSummary, |
| 39 | const ModuleSummaryIndex *ImportSummary, |
| 40 | const std::vector<uint8_t> &CmdArgs); |
| 41 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 42 | /// Runs a regular LTO backend. The regular LTO backend can also act as the |
| 43 | /// regular LTO phase of ThinLTO, which may need to access the combined index. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 44 | Error backend(const Config &C, AddStreamFn AddStream, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 45 | unsigned ParallelCodeGenParallelismLevel, |
| 46 | std::unique_ptr<Module> M, ModuleSummaryIndex &CombinedIndex); |
| 47 | |
| 48 | /// Runs a ThinLTO backend. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 49 | Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream, |
| 50 | Module &M, const ModuleSummaryIndex &CombinedIndex, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 51 | const FunctionImporter::ImportMapTy &ImportList, |
| 52 | const GVSummaryMapTy &DefinedGlobals, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame^] | 53 | MapVector<StringRef, BitcodeModule> &ModuleMap, |
| 54 | const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>()); |
| 55 | |
| 56 | Error finalizeOptimizationRemarks( |
| 57 | std::unique_ptr<ToolOutputFile> DiagOutputFile); |
| 58 | |
| 59 | /// Returns the BitcodeModule that is ThinLTO. |
| 60 | BitcodeModule *findThinLTOModule(MutableArrayRef<BitcodeModule> BMs); |
| 61 | |
| 62 | /// Variant of the above. |
| 63 | Expected<BitcodeModule> findThinLTOModule(MemoryBufferRef MBRef); |
| 64 | |
| 65 | /// Distributed ThinLTO: load the referenced modules, keeping their buffers |
| 66 | /// alive in the provided OwnedImportLifetimeManager. Returns false if the |
| 67 | /// operation failed. |
| 68 | bool loadReferencedModules( |
| 69 | const Module &M, const ModuleSummaryIndex &CombinedIndex, |
| 70 | FunctionImporter::ImportMapTy &ImportList, |
| 71 | MapVector<llvm::StringRef, llvm::BitcodeModule> &ModuleMap, |
| 72 | std::vector<std::unique_ptr<llvm::MemoryBuffer>> |
| 73 | &OwnedImportsLifetimeManager); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | #endif |