@@ -33,8 +33,8 @@ extern crate rustc_target;
3333extern crate rustc_driver;
3434
3535use std:: any:: Any ;
36- use std:: cell:: OnceCell ;
3736use std:: env;
37+ use std:: process:: ExitCode ;
3838use std:: sync:: Arc ;
3939
4040use cranelift_codegen:: isa:: TargetIsa ;
@@ -48,7 +48,6 @@ use rustc_session::config::OutputFilenames;
4848use rustc_span:: { Symbol , sym} ;
4949use rustc_target:: spec:: { Abi , Arch , Env , Os } ;
5050
51- pub use crate :: config:: * ;
5251use crate :: prelude:: * ;
5352
5453mod abi;
@@ -61,7 +60,6 @@ mod codegen_i128;
6160mod common;
6261mod compiler_builtins;
6362mod concurrency_limiter;
64- mod config;
6563mod constant;
6664mod debuginfo;
6765mod discriminant;
@@ -119,9 +117,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
119117 }
120118}
121119
122- pub struct CraneliftCodegenBackend {
123- pub config : OnceCell < BackendConfig > ,
124- }
120+ pub struct CraneliftCodegenBackend ;
125121
126122impl CodegenBackend for CraneliftCodegenBackend {
127123 fn name ( & self ) -> & ' static str {
@@ -141,15 +137,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
141137 sess. dcx ( )
142138 . fatal ( "`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift" ) ;
143139 }
144-
145- let config = self . config . get_or_init ( || {
146- BackendConfig :: from_opts ( & sess. opts . cg . llvm_args )
147- . unwrap_or_else ( |err| sess. dcx ( ) . fatal ( err) )
148- } ) ;
149-
150- if config. jit_mode && !sess. opts . output_types . should_codegen ( ) {
151- sess. dcx ( ) . fatal ( "JIT mode doesn't work with `cargo check`" ) ;
152- }
153140 }
154141
155142 fn target_config ( & self , sess : & Session ) -> TargetConfig {
@@ -211,16 +198,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
211198
212199 fn codegen_crate ( & self , tcx : TyCtxt < ' _ > , _crate_info : & CrateInfo ) -> Box < dyn Any > {
213200 info ! ( "codegen crate {}" , tcx. crate_name( LOCAL_CRATE ) ) ;
214- let config = self . config . get ( ) . unwrap ( ) ;
215- if config. jit_mode {
216- #[ cfg( feature = "jit" ) ]
217- driver:: jit:: run_jit ( tcx, _crate_info, config. jit_args . clone ( ) ) ;
218201
219- #[ cfg( not( feature = "jit" ) ) ]
220- tcx. dcx ( ) . fatal ( "jit support was disabled when compiling rustc_codegen_cranelift" ) ;
221- } else {
222- driver:: aot:: run_aot ( tcx)
202+ for opt in & tcx. sess . opts . cg . llvm_args {
203+ if opt. starts_with ( "-import-instr-limit" ) {
204+ // Silently ignore -import-instr-limit. It is set by rust's build system even when
205+ // testing cg_clif.
206+ continue ;
207+ }
208+ tcx. sess . dcx ( ) . fatal ( format ! ( "Unknown option `{}`" , opt) ) ;
223209 }
210+
211+ driver:: aot:: run_aot ( tcx)
224212 }
225213
226214 fn join_codegen (
@@ -231,6 +219,29 @@ impl CodegenBackend for CraneliftCodegenBackend {
231219 ) -> ( CompiledModules , FxIndexMap < WorkProductId , WorkProduct > ) {
232220 ongoing_codegen. downcast :: < driver:: aot:: OngoingCodegen > ( ) . unwrap ( ) . join ( sess, outputs)
233221 }
222+
223+ fn jit_crate < ' tcx > ( & self , tcx : TyCtxt < ' tcx > , args : Vec < String > ) -> ExitCode {
224+ info ! ( "jit crate {}" , tcx. crate_name( LOCAL_CRATE ) ) ;
225+
226+ for opt in & tcx. sess . opts . cg . llvm_args {
227+ if opt. starts_with ( "-import-instr-limit" ) {
228+ // Silently ignore -import-instr-limit. It is set by rust's build system even when
229+ // testing cg_clif.
230+ continue ;
231+ }
232+ tcx. sess . dcx ( ) . fatal ( format ! ( "Unknown option `{}`" , opt) ) ;
233+ }
234+
235+ #[ cfg( feature = "jit" ) ]
236+ #[ allow( unreachable_code) ]
237+ return driver:: jit:: run_jit ( tcx, self . target_cpu ( & tcx. sess ) , args) ;
238+
239+ #[ cfg( not( feature = "jit" ) ) ]
240+ {
241+ let _ = args;
242+ tcx. dcx ( ) . fatal ( "jit support was disabled when compiling rustc_codegen_cranelift" ) ;
243+ }
244+ }
234245}
235246
236247/// Determine if the Cranelift ir verifier should run.
@@ -360,5 +371,5 @@ fn build_isa(sess: &Session, jit: bool) -> Arc<dyn TargetIsa + 'static> {
360371/// This is the entrypoint for a hot plugged rustc_codegen_cranelift
361372#[ unsafe( no_mangle) ]
362373pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
363- Box :: new ( CraneliftCodegenBackend { config : OnceCell :: new ( ) } )
374+ Box :: new ( CraneliftCodegenBackend )
364375}
0 commit comments