annotate include/llvm/LTO/Config.h @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
1 //===-Config.h - LLVM Link Time Optimizer Configuration -------------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
2 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
4 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
7 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
9 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
10 // This file defines the lto::Config data structure, which allows clients to
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
11 // configure LTO.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
12 //
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
14
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
15 #ifndef LLVM_LTO_CONFIG_H
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
16 #define LLVM_LTO_CONFIG_H
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
17
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
18 #include "llvm/IR/DiagnosticInfo.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
19 #include "llvm/Support/CodeGen.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
20 #include "llvm/Target/TargetMachine.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
21 #include "llvm/Target/TargetOptions.h"
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
22
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
23 #include <functional>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
24
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
25 namespace llvm {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
26
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
27 class Error;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
28 class Module;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
29 class ModuleSummaryIndex;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
30 class raw_pwrite_stream;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
31
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
32 namespace lto {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
33
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
34 /// LTO configuration. A linker can configure LTO by setting fields in this data
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
35 /// structure and passing it to the lto::LTO constructor.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
36 struct Config {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
37 // Note: when adding fields here, consider whether they need to be added to
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
38 // computeCacheKey in LTO.cpp.
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
39 std::string CPU;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
40 TargetOptions Options;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
41 std::vector<std::string> MAttrs;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
42 Optional<Reloc::Model> RelocModel = Reloc::PIC_;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
43 Optional<CodeModel::Model> CodeModel = None;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
44 CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
45 TargetMachine::CodeGenFileType CGFileType = TargetMachine::CGFT_ObjectFile;
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
46 unsigned OptLevel = 2;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
47 bool DisableVerify = false;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
48
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
49 /// Use the new pass manager
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
50 bool UseNewPM = false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
51
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
52 /// Disable entirely the optimizer, including importing for ThinLTO
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
53 bool CodeGenOnly = false;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
54
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
55 /// If this field is set, the set of passes run in the middle-end optimizer
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
56 /// will be the one specified by the string. Only works with the new pass
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
57 /// manager as the old one doesn't have this ability.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
58 std::string OptPipeline;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
59
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
60 // If this field is set, it has the same effect of specifying an AA pipeline
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
61 // identified by the string. Only works with the new pass manager, in
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
62 // conjunction OptPipeline.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
63 std::string AAPipeline;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
64
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
65 /// Setting this field will replace target triples in input files with this
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
66 /// triple.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
67 std::string OverrideTriple;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
68
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
69 /// Setting this field will replace unspecified target triples in input files
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
70 /// with this triple.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
71 std::string DefaultTriple;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
72
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
73 /// Sample PGO profile path.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
74 std::string SampleProfile;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
75
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
76 /// Optimization remarks file path.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
77 std::string RemarksFilename = "";
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
78
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
79 /// Whether to emit optimization remarks with hotness informations.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
80 bool RemarksWithHotness = false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
81
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
82 /// Whether to emit the pass manager debuggging informations.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
83 bool DebugPassManager = false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
84
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
85 bool ShouldDiscardValueNames = true;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
86 DiagnosticHandlerFunction DiagHandler;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
87
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
88 /// If this field is set, LTO will write input file paths and symbol
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
89 /// resolutions here in llvm-lto2 command line flag format. This can be
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
90 /// used for testing and for running the LTO pipeline outside of the linker
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
91 /// with llvm-lto2.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
92 std::unique_ptr<raw_ostream> ResolutionFile;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
93
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
94 /// The following callbacks deal with tasks, which normally represent the
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
95 /// entire optimization and code generation pipeline for what will become a
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
96 /// single native object file. Each task has a unique identifier between 0 and
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
97 /// getMaxTasks()-1, which is supplied to the callback via the Task parameter.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
98 /// A task represents the entire pipeline for ThinLTO and regular
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
99 /// (non-parallel) LTO, but a parallel code generation task will be split into
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
100 /// N tasks before code generation, where N is the parallelism level.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
101 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
102 /// LTO may decide to stop processing a task at any time, for example if the
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
103 /// module is empty or if a module hook (see below) returns false. For this
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
104 /// reason, the client should not expect to receive exactly getMaxTasks()
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
105 /// native object files.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
106
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
107 /// A module hook may be used by a linker to perform actions during the LTO
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
108 /// pipeline. For example, a linker may use this function to implement
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
109 /// -save-temps. If this function returns false, any further processing for
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
110 /// that task is aborted.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
111 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
112 /// Module hooks must be thread safe with respect to the linker's internal
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
113 /// data structures. A module hook will never be called concurrently from
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
114 /// multiple threads with the same task ID, or the same module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
115 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
116 /// Note that in out-of-process backend scenarios, none of the hooks will be
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
117 /// called for ThinLTO tasks.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
118 typedef std::function<bool(unsigned Task, const Module &)> ModuleHookFn;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
119
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
120 /// This module hook is called after linking (regular LTO) or loading
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
121 /// (ThinLTO) the module, before modifying it.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
122 ModuleHookFn PreOptModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
123
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
124 /// This hook is called after promoting any internal functions
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
125 /// (ThinLTO-specific).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
126 ModuleHookFn PostPromoteModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
127
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
128 /// This hook is called after internalizing the module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
129 ModuleHookFn PostInternalizeModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
130
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
131 /// This hook is called after importing from other modules (ThinLTO-specific).
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
132 ModuleHookFn PostImportModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
133
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
134 /// This module hook is called after optimization is complete.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
135 ModuleHookFn PostOptModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
136
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
137 /// This module hook is called before code generation. It is similar to the
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
138 /// PostOptModuleHook, but for parallel code generation it is called after
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
139 /// splitting the module.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
140 ModuleHookFn PreCodeGenModuleHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
141
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
142 /// A combined index hook is called after all per-module indexes have been
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
143 /// combined (ThinLTO-specific). It can be used to implement -save-temps for
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
144 /// the combined index.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
145 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
146 /// If this function returns false, any further processing for ThinLTO tasks
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
147 /// is aborted.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
148 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
149 /// It is called regardless of whether the backend is in-process, although it
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
150 /// is not called from individual backend processes.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
151 typedef std::function<bool(const ModuleSummaryIndex &Index)>
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
152 CombinedIndexHookFn;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
153 CombinedIndexHookFn CombinedIndexHook;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
154
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
155 /// This is a convenience function that configures this Config object to write
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
156 /// temporary files named after the given OutputFileName for each of the LTO
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
157 /// phases to disk. A client can use this function to implement -save-temps.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
158 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
159 /// FIXME: Temporary files derived from ThinLTO backends are currently named
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
160 /// after the input file name, rather than the output file name, when
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
161 /// UseInputModulePath is set to true.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
162 ///
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
163 /// Specifically, it (1) sets each of the above module hooks and the combined
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
164 /// index hook to a function that calls the hook function (if any) that was
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
165 /// present in the appropriate field when the addSaveTemps function was
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
166 /// called, and writes the module to a bitcode file with a name prefixed by
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
167 /// the given output file name, and (2) creates a resolution file whose name
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
168 /// is prefixed by the given output file name and sets ResolutionFile to its
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
169 /// file handle.
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
170 Error addSaveTemps(std::string OutputFileName,
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
171 bool UseInputModulePath = false);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
172 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
173
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
174 struct LTOLLVMDiagnosticHandler : public DiagnosticHandler {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
175 DiagnosticHandlerFunction *Fn;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
176 LTOLLVMDiagnosticHandler(DiagnosticHandlerFunction *DiagHandlerFn)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
177 : Fn(DiagHandlerFn) {}
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
178 bool handleDiagnostics(const DiagnosticInfo &DI) override {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
179 (*Fn)(DI);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
180 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
181 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
182 };
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
183 /// A derived class of LLVMContext that initializes itself according to a given
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
184 /// Config object. The purpose of this class is to tie ownership of the
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
185 /// diagnostic handler to the context, as opposed to the Config object (which
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
186 /// may be ephemeral).
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
187 // FIXME: This should not be required as diagnostic handler is not callback.
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
188 struct LTOLLVMContext : LLVMContext {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
189
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
190 LTOLLVMContext(const Config &C) : DiagHandler(C.DiagHandler) {
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
191 setDiscardValueNames(C.ShouldDiscardValueNames);
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
192 enableDebugTypeODRUniquing();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
193 setDiagnosticHandler(
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
194 llvm::make_unique<LTOLLVMDiagnosticHandler>(&DiagHandler), true);
120
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
195 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
196 DiagnosticHandlerFunction DiagHandler;
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
197 };
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
198
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
199 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
200 }
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
201
1172e4bd9c6f update 4.0.0
mir3636
parents:
diff changeset
202 #endif