Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:11

0001 //===-LTOBackend.h - LLVM Link Time Optimizer Backend ---------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements the "backend" phase of LTO, i.e. it performs
0010 // optimization and code generation on a loaded module. It is generally used
0011 // internally by the LTO class but can also be used independently, for example
0012 // to implement a standalone ThinLTO backend.
0013 //
0014 //===----------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_LTO_LTOBACKEND_H
0017 #define LLVM_LTO_LTOBACKEND_H
0018 
0019 #include "llvm/ADT/MapVector.h"
0020 #include "llvm/IR/DiagnosticInfo.h"
0021 #include "llvm/IR/ModuleSummaryIndex.h"
0022 #include "llvm/LTO/LTO.h"
0023 #include "llvm/Support/MemoryBuffer.h"
0024 #include "llvm/Target/TargetOptions.h"
0025 #include "llvm/Transforms/IPO/FunctionImport.h"
0026 
0027 namespace llvm {
0028 
0029 class BitcodeModule;
0030 class Error;
0031 class Module;
0032 class Target;
0033 
0034 namespace lto {
0035 
0036 /// Runs middle-end LTO optimizations on \p Mod.
0037 bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
0038          bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
0039          const ModuleSummaryIndex *ImportSummary,
0040          const std::vector<uint8_t> &CmdArgs);
0041 
0042 /// Runs a regular LTO backend. The regular LTO backend can also act as the
0043 /// regular LTO phase of ThinLTO, which may need to access the combined index.
0044 Error backend(const Config &C, AddStreamFn AddStream,
0045               unsigned ParallelCodeGenParallelismLevel, Module &M,
0046               ModuleSummaryIndex &CombinedIndex);
0047 
0048 /// Runs a ThinLTO backend.
0049 /// If \p ModuleMap is not nullptr, all the module files to be imported have
0050 /// already been mapped to memory and the corresponding BitcodeModule objects
0051 /// are saved in the ModuleMap. If \p ModuleMap is nullptr, module files will
0052 /// be mapped to memory on demand and at any given time during importing, only
0053 /// one source module will be kept open at the most. If \p CodeGenOnly is true,
0054 /// the backend will skip optimization and only perform code generation. If
0055 /// \p IRAddStream is not nullptr, it will be called just before code generation
0056 /// to serialize the optimized IR.
0057 Error thinBackend(const Config &C, unsigned Task, AddStreamFn AddStream,
0058                   Module &M, const ModuleSummaryIndex &CombinedIndex,
0059                   const FunctionImporter::ImportMapTy &ImportList,
0060                   const GVSummaryMapTy &DefinedGlobals,
0061                   MapVector<StringRef, BitcodeModule> *ModuleMap,
0062                   bool CodeGenOnly, AddStreamFn IRAddStream = nullptr,
0063                   const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
0064 
0065 Error finalizeOptimizationRemarks(
0066     std::unique_ptr<ToolOutputFile> DiagOutputFile);
0067 
0068 /// Returns the BitcodeModule that is ThinLTO.
0069 BitcodeModule *findThinLTOModule(MutableArrayRef<BitcodeModule> BMs);
0070 
0071 /// Variant of the above.
0072 Expected<BitcodeModule> findThinLTOModule(MemoryBufferRef MBRef);
0073 
0074 /// Distributed ThinLTO: collect the referenced modules based on
0075 /// module summary and initialize ImportList. Returns false if the
0076 /// operation failed.
0077 bool initImportList(const Module &M, const ModuleSummaryIndex &CombinedIndex,
0078                     FunctionImporter::ImportMapTy &ImportList);
0079 }
0080 }
0081 
0082 #endif