From fab72301d9089761766b389df209986c2bc38e5d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 30 Apr 2022 20:58:42 +0200 Subject: [PATCH] Remove config parameter of optimize_fat and avoid interior mutability for module --- compiler/rustc_codegen_gcc/src/lib.rs | 2 +- compiler/rustc_codegen_llvm/src/back/lto.rs | 13 +++++-------- compiler/rustc_codegen_llvm/src/lib.rs | 5 ++--- compiler/rustc_codegen_ssa/src/back/lto.rs | 5 ++--- compiler/rustc_codegen_ssa/src/traits/write.rs | 3 +-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index 72da59a1bf8..684b845c38a 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -229,7 +229,7 @@ unsafe fn optimize(_cgcx: &CodegenContext, _diag_handler: &Handler, module Ok(()) } - fn optimize_fat(_cgcx: &CodegenContext, _module: &ModuleCodegen, _config: &ModuleConfig) -> Result<(), FatalError> { + fn optimize_fat(_cgcx: &CodegenContext, _module: &mut ModuleCodegen) -> Result<(), FatalError> { // TODO(antoyo) Ok(()) } diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 570410caaab..b5b2a27d237 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -6,9 +6,7 @@ use crate::{llvm_util, LlvmCodegenBackend, ModuleLlvm}; use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared}; use rustc_codegen_ssa::back::symbol_export; -use rustc_codegen_ssa::back::write::{ - CodegenContext, FatLTOInput, ModuleConfig, TargetMachineFactoryConfig, -}; +use rustc_codegen_ssa::back::write::{CodegenContext, FatLTOInput, TargetMachineFactoryConfig}; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind}; use rustc_data_structures::fx::FxHashMap; @@ -578,11 +576,11 @@ fn thin_lto( pub(crate) fn run_pass_manager( cgcx: &CodegenContext, diag_handler: &Handler, - module: &ModuleCodegen, - config: &ModuleConfig, + module: &mut ModuleCodegen, thin: bool, ) -> Result<(), FatalError> { let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &*module.name); + let config = cgcx.config(module.kind); // Now we have one massive module inside of llmod. Time to run the // LTO-specific optimization passes that LLVM provides. @@ -743,7 +741,7 @@ pub unsafe fn optimize_thin_module( // that LLVM Context and Module. let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names); let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _; - let module = ModuleCodegen { + let mut module = ModuleCodegen { module_llvm: ModuleLlvm { llmod_raw, llcx, tm }, name: thin_module.name().to_string(), kind: ModuleKind::Regular, @@ -859,8 +857,7 @@ pub unsafe fn optimize_thin_module( // little differently. { info!("running thin lto passes over {}", module.name); - let config = cgcx.config(module.kind); - run_pass_manager(cgcx, &diag_handler, &module, config, true)?; + run_pass_manager(cgcx, &diag_handler, &mut module, true)?; save_temp_bitcode(cgcx, &module, "thin-lto-after-pm"); } } diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index c3db6352a53..b48c738124d 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -212,11 +212,10 @@ unsafe fn optimize( } fn optimize_fat( cgcx: &CodegenContext, - module: &ModuleCodegen, - config: &ModuleConfig, + module: &mut ModuleCodegen, ) -> Result<(), FatalError> { let diag_handler = cgcx.create_diag_handler(); - back::lto::run_pass_manager(cgcx, &diag_handler, module, config, false) + back::lto::run_pass_manager(cgcx, &diag_handler, module, false) } unsafe fn optimize_thin( cgcx: &CodegenContext, diff --git a/compiler/rustc_codegen_ssa/src/back/lto.rs b/compiler/rustc_codegen_ssa/src/back/lto.rs index 6dc8cb5038e..3c5b0e5cc43 100644 --- a/compiler/rustc_codegen_ssa/src/back/lto.rs +++ b/compiler/rustc_codegen_ssa/src/back/lto.rs @@ -68,10 +68,9 @@ pub unsafe fn optimize( cgcx: &CodegenContext, ) -> Result, FatalError> { match self { - LtoModuleCodegen::Fat { module, .. } => { + LtoModuleCodegen::Fat { mut module, .. } => { { - let config = cgcx.config(module.kind); - B::optimize_fat(cgcx, &module, config)?; + B::optimize_fat(cgcx, &mut module)?; } Ok(module) } diff --git a/compiler/rustc_codegen_ssa/src/traits/write.rs b/compiler/rustc_codegen_ssa/src/traits/write.rs index ed0f6591809..e54ec34f1ce 100644 --- a/compiler/rustc_codegen_ssa/src/traits/write.rs +++ b/compiler/rustc_codegen_ssa/src/traits/write.rs @@ -43,8 +43,7 @@ unsafe fn optimize( ) -> Result<(), FatalError>; fn optimize_fat( cgcx: &CodegenContext, - llmod: &ModuleCodegen, - config: &ModuleConfig, + llmod: &mut ModuleCodegen, ) -> Result<(), FatalError>; unsafe fn optimize_thin( cgcx: &CodegenContext,