@@ -26,11 +26,11 @@ use std::mem::ManuallyDrop;
26
26
use back:: owned_target_machine:: OwnedTargetMachine ;
27
27
use back:: write:: { create_informational_target_machine, create_target_machine} ;
28
28
use context:: SimpleCx ;
29
- use errors:: { AutoDiffWithoutLTO , ParseTargetMachineConfig } ;
29
+ use errors:: ParseTargetMachineConfig ;
30
30
use llvm_util:: target_config;
31
31
use rustc_ast:: expand:: allocator:: AllocatorKind ;
32
32
use rustc_ast:: expand:: autodiff_attrs:: AutoDiffItem ;
33
- use rustc_codegen_ssa:: back:: lto:: { LtoModuleCodegen , SerializedModule , ThinModule } ;
33
+ use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule } ;
34
34
use rustc_codegen_ssa:: back:: write:: {
35
35
CodegenContext , FatLtoInput , ModuleConfig , TargetMachineFactoryConfig , TargetMachineFactoryFn ,
36
36
} ;
@@ -43,7 +43,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
43
43
use rustc_middle:: ty:: TyCtxt ;
44
44
use rustc_middle:: util:: Providers ;
45
45
use rustc_session:: Session ;
46
- use rustc_session:: config:: { Lto , OptLevel , OutputFilenames , PrintKind , PrintRequest } ;
46
+ use rustc_session:: config:: { OptLevel , OutputFilenames , PrintKind , PrintRequest } ;
47
47
use rustc_span:: Symbol ;
48
48
49
49
mod back {
@@ -174,18 +174,29 @@ impl WriteBackendMethods for LlvmCodegenBackend {
174
174
) -> Result < ModuleCodegen < Self :: Module > , FatalError > {
175
175
back:: write:: link ( cgcx, dcx, modules)
176
176
}
177
- fn run_fat_lto (
177
+ fn run_and_optimize_fat_lto (
178
178
cgcx : & CodegenContext < Self > ,
179
179
modules : Vec < FatLtoInput < Self > > ,
180
180
cached_modules : Vec < ( SerializedModule < Self :: ModuleBuffer > , WorkProduct ) > ,
181
- ) -> Result < LtoModuleCodegen < Self > , FatalError > {
182
- back:: lto:: run_fat ( cgcx, modules, cached_modules)
181
+ diff_fncs : Vec < AutoDiffItem > ,
182
+ ) -> Result < ModuleCodegen < Self :: Module > , FatalError > {
183
+ let mut module = back:: lto:: run_fat ( cgcx, modules, cached_modules) ?;
184
+
185
+ if !diff_fncs. is_empty ( ) {
186
+ builder:: autodiff:: differentiate ( & module, cgcx, diff_fncs) ?;
187
+ }
188
+
189
+ let dcx = cgcx. create_dcx ( ) ;
190
+ let dcx = dcx. handle ( ) ;
191
+ back:: lto:: run_pass_manager ( cgcx, dcx, & mut module, false ) ?;
192
+
193
+ Ok ( module)
183
194
}
184
195
fn run_thin_lto (
185
196
cgcx : & CodegenContext < Self > ,
186
197
modules : Vec < ( String , Self :: ThinBuffer ) > ,
187
198
cached_modules : Vec < ( SerializedModule < Self :: ModuleBuffer > , WorkProduct ) > ,
188
- ) -> Result < ( Vec < LtoModuleCodegen < Self > > , Vec < WorkProduct > ) , FatalError > {
199
+ ) -> Result < ( Vec < ThinModule < Self > > , Vec < WorkProduct > ) , FatalError > {
189
200
back:: lto:: run_thin ( cgcx, modules, cached_modules)
190
201
}
191
202
fn optimize (
@@ -196,14 +207,6 @@ impl WriteBackendMethods for LlvmCodegenBackend {
196
207
) -> Result < ( ) , FatalError > {
197
208
back:: write:: optimize ( cgcx, dcx, module, config)
198
209
}
199
- fn optimize_fat (
200
- cgcx : & CodegenContext < Self > ,
201
- module : & mut ModuleCodegen < Self :: Module > ,
202
- ) -> Result < ( ) , FatalError > {
203
- let dcx = cgcx. create_dcx ( ) ;
204
- let dcx = dcx. handle ( ) ;
205
- back:: lto:: run_pass_manager ( cgcx, dcx, module, false )
206
- }
207
210
fn optimize_thin (
208
211
cgcx : & CodegenContext < Self > ,
209
212
thin : ThinModule < Self > ,
@@ -212,11 +215,10 @@ impl WriteBackendMethods for LlvmCodegenBackend {
212
215
}
213
216
fn codegen (
214
217
cgcx : & CodegenContext < Self > ,
215
- dcx : DiagCtxtHandle < ' _ > ,
216
218
module : ModuleCodegen < Self :: Module > ,
217
219
config : & ModuleConfig ,
218
220
) -> Result < CompiledModule , FatalError > {
219
- back:: write:: codegen ( cgcx, dcx , module, config)
221
+ back:: write:: codegen ( cgcx, module, config)
220
222
}
221
223
fn prepare_thin (
222
224
module : ModuleCodegen < Self :: Module > ,
@@ -227,19 +229,6 @@ impl WriteBackendMethods for LlvmCodegenBackend {
227
229
fn serialize_module ( module : ModuleCodegen < Self :: Module > ) -> ( String , Self :: ModuleBuffer ) {
228
230
( module. name , back:: lto:: ModuleBuffer :: new ( module. module_llvm . llmod ( ) ) )
229
231
}
230
- /// Generate autodiff rules
231
- fn autodiff (
232
- cgcx : & CodegenContext < Self > ,
233
- module : & ModuleCodegen < Self :: Module > ,
234
- diff_fncs : Vec < AutoDiffItem > ,
235
- config : & ModuleConfig ,
236
- ) -> Result < ( ) , FatalError > {
237
- if cgcx. lto != Lto :: Fat {
238
- let dcx = cgcx. create_dcx ( ) ;
239
- return Err ( dcx. handle ( ) . emit_almost_fatal ( AutoDiffWithoutLTO ) ) ;
240
- }
241
- builder:: autodiff:: differentiate ( module, cgcx, diff_fncs, config)
242
- }
243
232
}
244
233
245
234
impl LlvmCodegenBackend {
0 commit comments