LLVM 23.0.0git
LTOBackend.h
Go to the documentation of this file.
1//===-LTOBackend.h - 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#ifndef LLVM_LTO_LTOBACKEND_H
17#define LLVM_LTO_LTOBACKEND_H
18
19#include "llvm/ADT/MapVector.h"
22#include "llvm/LTO/LTO.h"
27
28namespace llvm {
29
30class BitcodeModule;
31class Error;
32class Module;
33class Target;
34
35namespace lto {
36
37/// Runs middle-end LTO optimizations on \p Mod.
38LLVM_ABI bool opt(const Config &Conf, TargetMachine *TM, unsigned Task,
39 Module &Mod, bool IsThinLTO,
40 ModuleSummaryIndex *ExportSummary,
41 const ModuleSummaryIndex *ImportSummary,
42 const std::vector<uint8_t> &CmdArgs,
43 ArrayRef<StringRef> BitcodeLibFuncs);
44
45/// Runs a regular LTO backend. The regular LTO backend can also act as the
46/// regular LTO phase of ThinLTO, which may need to access the combined index.
47LLVM_ABI Error backend(const Config &C, AddStreamFn AddStream,
48 unsigned ParallelCodeGenParallelismLevel, Module &M,
49 ModuleSummaryIndex &CombinedIndex,
50 ArrayRef<StringRef> BitcodeLibFuncs);
51
52/// Runs a ThinLTO backend.
53/// If \p ModuleMap is not nullptr, all the module files to be imported have
54/// already been mapped to memory and the corresponding BitcodeModule objects
55/// are saved in the ModuleMap. If \p ModuleMap is nullptr, module files will
56/// be mapped to memory on demand and at any given time during importing, only
57/// one source module will be kept open at the most. If \p CodeGenOnly is true,
58/// the backend will skip optimization and only perform code generation. If
59/// \p IRAddStream is not nullptr, it will be called just before code generation
60/// to serialize the optimized IR.
62 const Config &C, unsigned Task, AddStreamFn AddStream, Module &M,
63 const ModuleSummaryIndex &CombinedIndex,
64 const FunctionImporter::ImportMapTy &ImportList,
65 const GVSummaryMapTy &DefinedGlobals,
66 MapVector<StringRef, BitcodeModule> *ModuleMap, bool CodeGenOnly,
67 ArrayRef<StringRef> BitcodeLibFuncs, AddStreamFn IRAddStream = nullptr,
68 const std::vector<uint8_t> &CmdArgs = std::vector<uint8_t>());
69
70LLVM_ABI Error finalizeOptimizationRemarks(LLVMRemarkFileHandle DiagOutputFile);
71
72/// Returns the BitcodeModule that is ThinLTO.
74
75/// Variant of the above.
76LLVM_ABI Expected<BitcodeModule> findThinLTOModule(MemoryBufferRef MBRef);
77
78/// Distributed ThinLTO: collect the referenced modules based on
79/// module summary and initialize ImportList. Returns false if the
80/// operation failed.
81LLVM_ABI bool initImportList(const Module &M,
82 const ModuleSummaryIndex &CombinedIndex,
83 FunctionImporter::ImportMapTy &ImportList);
84}
85}
86
87#endif
#define LLVM_ABI
Definition Compiler.h:213
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Represents a module in a bitcode file.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Target - Wrapper for Target specific information.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI bool opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod, bool IsThinLTO, ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary, const std::vector< uint8_t > &CmdArgs, ArrayRef< StringRef > BitcodeLibFuncs)
Runs middle-end LTO optimizations on Mod.
LLVM_ABI 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, bool CodeGenOnly, ArrayRef< StringRef > BitcodeLibFuncs, AddStreamFn IRAddStream=nullptr, const std::vector< uint8_t > &CmdArgs=std::vector< uint8_t >())
Runs a ThinLTO backend.
LLVM_ABI BitcodeModule * findThinLTOModule(MutableArrayRef< BitcodeModule > BMs)
Returns the BitcodeModule that is ThinLTO.
LLVM_ABI Error backend(const Config &C, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, Module &M, ModuleSummaryIndex &CombinedIndex, ArrayRef< StringRef > BitcodeLibFuncs)
Runs a regular LTO backend.
LLVM_ABI Error finalizeOptimizationRemarks(LLVMRemarkFileHandle DiagOutputFile)
LLVM_ABI bool initImportList(const Module &M, const ModuleSummaryIndex &CombinedIndex, FunctionImporter::ImportMapTy &ImportList)
Distributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList...
This is an optimization pass for GlobalISel generic memory operations.
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::function< Expected< std::unique_ptr< CachedFileStream > >( unsigned Task, const Twine &ModuleName)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
Definition Caching.h:58
LTO configuration.
Definition Config.h:43