diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index ce3741b582827..6fde623d46f73 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -22,7 +22,7 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle}; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mono::{MonoItem, MonoItemData, Visibility}; -use rustc_session::config::{OptLevel, OutputFilenames, OutputType}; +use rustc_session::config::{OutputFilenames, OutputType}; use rustc_session::{BorrowedIncrCompSession, Session}; use rustc_span::Symbol; @@ -318,11 +318,7 @@ impl WriteBackendMethods for AotDriver { type TargetMachine = (); type ThinData = Infallible; - fn target_machine_factory( - &self, - _sess: &Session, - _opt_level: OptLevel, - ) -> TargetMachineFactoryFn { + fn target_machine_factory(&self, _sess: &Session) -> TargetMachineFactoryFn { Arc::new(|_, _| ()) } diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index 17034d0c195e7..fa15ec2838b24 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -409,11 +409,7 @@ impl WriteBackendMethods for GccCodegenBackend { false } - fn target_machine_factory( - &self, - _sess: &Session, - _opt_level: OptLevel, - ) -> TargetMachineFactoryFn { + fn target_machine_factory(&self, _sess: &Session) -> TargetMachineFactoryFn { // FIXME(antoyo): set opt level. Arc::new(|_, _| ()) } diff --git a/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs b/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs index 69d63c52e4b88..7864d0cc81491 100644 --- a/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs +++ b/compiler/rustc_codegen_llvm/src/back/llvm_backend.rs @@ -22,7 +22,7 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle}; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductMap}; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest}; +use rustc_session::config::{OutputFilenames, PrintKind, PrintRequest}; use rustc_session::{ BorrowedIncrCompSession, CodegenBackendInit, EarlySession, IncrCompSession, Session, }; @@ -89,12 +89,8 @@ impl WriteBackendMethods for LlvmCodegenBackend { fn thread_profiler() -> Box { Box::new(TimeTraceProfiler::new()) } - fn target_machine_factory( - &self, - sess: &Session, - optlvl: OptLevel, - ) -> TargetMachineFactoryFn { - back::write::target_machine_factory(sess, optlvl) + fn target_machine_factory(&self, sess: &Session) -> TargetMachineFactoryFn { + back::write::target_machine_factory(sess, sess.opts.optimize) } fn optimize_and_codegen_fat_lto( sess: &Session, diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index e43b9ba6359ed..4e1a3f998a265 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -116,7 +116,7 @@ pub(crate) fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> OwnedTar Some(tcx.output_filenames(()).temp_path_for_cgu(OutputType::Object, mod_name)); let config = TargetMachineFactoryConfig { split_dwarf_file, output_obj_file }; - target_machine_factory(tcx.sess, tcx.backend_optimization_level(()))(tcx.dcx(), config) + target_machine_factory(tcx.sess, tcx.sess.opts.optimize)(tcx.dcx(), config) } // `s` and `z` are the same codegen level; what tells LLVM that they are size builds is the diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 406e5a5b04c61..24fcab7218f7e 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -23,8 +23,8 @@ use rustc_metadata::fs::copy_to_stdout; use rustc_middle::dep_graph::{WorkProduct, WorkProductMap}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{ - self, JobsMode, Lto, OptLevel, OptimizationObjective, OutFileName, OutputFilenames, OutputType, - Passes, SwitchWithOptPath, + self, JobsMode, Lto, OptimizationObjective, OutFileName, OutputFilenames, OutputType, Passes, + SwitchWithOptPath, }; use rustc_session::{BorrowedIncrCompSession, IncrCompSession, Session}; use rustc_span::source_map::SourceMap; @@ -328,7 +328,6 @@ pub struct CodegenContext { pub crate_types: Vec, pub output_filenames: Arc, pub module_config: Arc, - pub opt_level: OptLevel, pub msvc_imps_needed: bool, pub is_pe_coff: bool, pub target_can_use_split_dwarf: bool, @@ -1243,8 +1242,7 @@ fn start_executing_work( .expect("failed to spawn helper thread") }); - let opt_level = tcx.backend_optimization_level(()); - let tm_factory = backend.target_machine_factory(tcx.sess, opt_level); + let tm_factory = backend.target_machine_factory(tcx.sess); let remark_dir = if let Some(ref dir) = sess.opts.unstable_opts.remark_dir { let result = fs::create_dir_all(dir).and_then(|_| dir.canonicalize()); @@ -1271,7 +1269,6 @@ fn start_executing_work( remark_dir, output_filenames: Arc::clone(tcx.output_filenames(())), module_config: regular_config, - opt_level, msvc_imps_needed: msvc_imps_needed(tcx), is_pe_coff: tcx.sess.target.is_like_windows, target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(), @@ -2147,7 +2144,7 @@ impl OngoingCodegen { (compiled_modules, work_products) } MaybeLtoModules::FatLto { cgcx, needs_fat_lto } => { - let tm_factory = self.backend.target_machine_factory(sess, cgcx.opt_level); + let tm_factory = self.backend.target_machine_factory(sess); // FIXME cache local pre-LTO bitcode let work_products = WorkProductMap::default(); @@ -2168,7 +2165,7 @@ impl OngoingCodegen { (compiled_modules, work_products) } MaybeLtoModules::ThinLto { cgcx, needs_thin_lto } => { - let tm_factory = self.backend.target_machine_factory(sess, cgcx.opt_level); + let tm_factory = self.backend.target_machine_factory(sess); let compiled_modules = CompiledModules { modules: do_thin_lto::( diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index ae35dcfe42e60..4361e192972f4 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -11,14 +11,13 @@ use rustc_ast::expand::allocator::{ }; use rustc_attr_ir::lang_items::LangItem; use rustc_attr_ir::target::Target; -use rustc_attr_ir::{DebuggerVisualizerType, EiiDecl, EiiImpl, OptimizeAttr, find_attr}; +use rustc_attr_ir::{DebuggerVisualizerType, EiiDecl, EiiImpl, find_attr}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet}; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_data_structures::sync::{IntoDynSyncSend, par_map}; use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; use rustc_middle::middle::dependency_format::{Dependencies, Linkage}; use rustc_middle::middle::exported_symbols::{self, SymbolExportKind}; @@ -26,7 +25,6 @@ use rustc_middle::middle::lang_items; use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, ErrorHandled, Scalar}; use rustc_middle::mir::{BinOp, ConstValue}; use rustc_middle::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem, MonoItemPartitions}; -use rustc_middle::query::Providers; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Instance, PatternKind, Ty, TyCtxt, UintTy, Unnormalized}; use rustc_session::config::{self, EntryFnType, JobsMode}; @@ -1217,30 +1215,6 @@ impl CrateInfo { } } -pub(crate) fn provide(providers: &mut Providers) { - providers.backend_optimization_level = |tcx, cratenum| { - let global = tcx.sess.opts.optimize; - - // Nothing to promote outside a size build. At `-Copt-level=0` the upgrade would populate - // the pass manager, and its module-wide passes ignore the `optnone` annotation. - if global.objective() != config::OptimizationObjective::Size { - return global; - } - - // A speed-marked body in a size build needs a speed level, and `-O2` is the lowest one. - let for_speed = config::OptLevel::More; - - let defids = tcx.collect_and_partition_mono_items(cratenum).all_mono_items; - - let any_for_speed = defids.items().any(|id| { - let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id); - matches!(optimize, OptimizeAttr::Speed) - }); - - if any_for_speed { for_speed } else { global } - }; -} - pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguReuse { if !tcx.dep_graph.is_fully_enabled() || tcx.sess.opts.unstable_opts.disable_incr_comp_backend_caching diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 1ac9564db0149..d19b80897a21d 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -326,7 +326,6 @@ pub enum CodegenError { pub fn provide(providers: &mut Providers) { crate::back::symbol_export::provide(providers); - crate::base::provide(&mut providers.queries); crate::target_features::provide(&mut providers.queries); crate::codegen_attrs::provide(&mut providers.queries); } diff --git a/compiler/rustc_codegen_ssa/src/traits/write.rs b/compiler/rustc_codegen_ssa/src/traits/write.rs index 36bc0a68d882e..1576c438f54ae 100644 --- a/compiler/rustc_codegen_ssa/src/traits/write.rs +++ b/compiler/rustc_codegen_ssa/src/traits/write.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_errors::DiagCtxtHandle; use rustc_middle::dep_graph::WorkProduct; -use rustc_session::{BorrowedIncrCompSession, Session, config}; +use rustc_session::{BorrowedIncrCompSession, Session}; use crate::back::lto::ThinModule; use crate::back::write::{ @@ -28,11 +28,7 @@ pub trait WriteBackendMethods: Clone + 'static { fn thread_profiler() -> Box { Box::new(()) } - fn target_machine_factory( - &self, - sess: &Session, - opt_level: config::OptLevel, - ) -> TargetMachineFactoryFn; + fn target_machine_factory(&self, sess: &Session) -> TargetMachineFactoryFn; /// Performs fat LTO by merging all modules into a single one, running autodiff /// if necessary and running any further optimizations fn optimize_and_codegen_fat_lto( diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 7442daa296f03..9b58174f58ebe 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -74,7 +74,7 @@ use rustc_lint_defs::{LintId, StableLintExpectationId}; use rustc_macros::rustc_queries; use rustc_middle::middle::resolve::TypeRelativeDelegationRes; use rustc_session::Limits; -use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; +use rustc_session::config::{EntryFnType, OutputFilenames, SymbolManglingVersion}; use rustc_span::def_id::{LOCAL_CRATE, ModId}; use rustc_span::{DUMMY_SP, LocalExpnId, Span, Spanned, Symbol}; use rustc_target::spec::PanicStrategy; @@ -2488,10 +2488,6 @@ rustc_queries! { desc { "getting codegen unit `{sym}`" } } - query backend_optimization_level(_: ()) -> OptLevel { - desc { "optimization level used by backend" } - } - /// Return the filenames where output artefacts shall be stored. /// /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`