@@ -64,9 +64,15 @@ mod type_of;
64
64
65
65
use std:: any:: Any ;
66
66
use std:: sync:: Arc ;
67
+ #[ cfg( not( feature="master" ) ) ]
68
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
67
69
68
70
use crate :: errors:: LTONotSupported ;
69
- use gccjit:: { Context , OptimizationLevel , TargetInfo } ;
71
+ use gccjit:: { Context , OptimizationLevel } ;
72
+ #[ cfg( feature="master" ) ]
73
+ use gccjit:: TargetInfo ;
74
+ #[ cfg( not( feature="master" ) ) ]
75
+ use gccjit:: CType ;
70
76
use rustc_ast:: expand:: allocator:: AllocatorKind ;
71
77
use rustc_codegen_ssa:: { CodegenResults , CompiledModule , ModuleCodegen } ;
72
78
use rustc_codegen_ssa:: base:: codegen_crate;
@@ -85,6 +91,8 @@ use rustc_session::config::{Lto, OptLevel, OutputFilenames};
85
91
use rustc_session:: Session ;
86
92
use rustc_span:: Symbol ;
87
93
use rustc_span:: fatal_error:: FatalError ;
94
+ #[ cfg( not( feature="master" ) ) ]
95
+ use tempfile:: TempDir ;
88
96
89
97
fluent_messages ! { "../messages.ftl" }
90
98
@@ -98,6 +106,23 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
98
106
}
99
107
}
100
108
109
+ #[ cfg( not( feature="master" ) ) ]
110
+ #[ derive( Debug ) ]
111
+ pub struct TargetInfo {
112
+ supports_128bit_integers : AtomicBool ,
113
+ }
114
+
115
+ #[ cfg( not( feature="master" ) ) ]
116
+ impl TargetInfo {
117
+ fn cpu_supports ( & self , _feature : & str ) -> bool {
118
+ false
119
+ }
120
+
121
+ fn supports_128bit_int ( & self ) -> bool {
122
+ self . supports_128bit_integers . load ( Ordering :: SeqCst )
123
+ }
124
+ }
125
+
101
126
#[ derive( Clone ) ]
102
127
pub struct GccCodegenBackend {
103
128
target_info : Arc < TargetInfo > ,
@@ -114,6 +139,18 @@ impl CodegenBackend for GccCodegenBackend {
114
139
if sess. lto ( ) != Lto :: No {
115
140
sess. emit_warning ( LTONotSupported { } ) ;
116
141
}
142
+
143
+ #[ cfg( not( feature="master" ) ) ]
144
+ {
145
+ let temp_dir = TempDir :: new ( ) . expect ( "cannot create temporary directory" ) ;
146
+ let temp_file = temp_dir. into_path ( ) . join ( "result.asm" ) ;
147
+ let check_context = Context :: default ( ) ;
148
+ check_context. set_print_errors_to_stderr ( false ) ;
149
+ let _int128_ty = check_context. new_c_type ( CType :: UInt128t ) ;
150
+ // NOTE: we cannot just call compile() as this would require other files than libgccjit.so.
151
+ check_context. compile_to_file ( gccjit:: OutputKind :: Assembler , temp_file. to_str ( ) . expect ( "path to str" ) ) ;
152
+ self . target_info . supports_128bit_integers . store ( check_context. get_last_error ( ) == Ok ( None ) , Ordering :: SeqCst ) ;
153
+ }
117
154
}
118
155
119
156
fn provide ( & self , providers : & mut Providers ) {
@@ -266,14 +303,21 @@ impl WriteBackendMethods for GccCodegenBackend {
266
303
/// This is the entrypoint for a hot plugged rustc_codegen_gccjit
267
304
#[ no_mangle]
268
305
pub fn __rustc_codegen_backend ( ) -> Box < dyn CodegenBackend > {
269
- // Get the native arch and check whether the target supports 128-bit integers.
270
- let context = Context :: default ( ) ;
271
- let arch = context. get_target_info ( ) . arch ( ) . unwrap ( ) ;
272
-
273
- // Get the second TargetInfo with the correct CPU features by setting the arch.
274
- let context = Context :: default ( ) ;
275
- context. add_driver_option ( & format ! ( "-march={}" , arch. to_str( ) . unwrap( ) ) ) ;
276
- let target_info = Arc :: new ( context. get_target_info ( ) ) ;
306
+ #[ cfg( feature="master" ) ]
307
+ let target_info = {
308
+ // Get the native arch and check whether the target supports 128-bit integers.
309
+ let context = Context :: default ( ) ;
310
+ let arch = context. get_target_info ( ) . arch ( ) . unwrap ( ) ;
311
+
312
+ // Get the second TargetInfo with the correct CPU features by setting the arch.
313
+ let context = Context :: default ( ) ;
314
+ context. add_driver_option ( & format ! ( "-march={}" , arch. to_str( ) . unwrap( ) ) ) ;
315
+ Arc :: new ( context. get_target_info ( ) )
316
+ } ;
317
+ #[ cfg( not( feature="master" ) ) ]
318
+ let target_info = Arc :: new ( TargetInfo {
319
+ supports_128bit_integers : AtomicBool :: new ( false ) ,
320
+ } ) ;
277
321
278
322
Box :: new ( GccCodegenBackend {
279
323
target_info,
@@ -319,14 +363,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Arc<T
319
363
} ,
320
364
)
321
365
. filter ( |_feature| {
322
- #[ cfg( feature="master" ) ]
323
- {
324
- target_info. cpu_supports ( _feature)
325
- }
326
- #[ cfg( not( feature="master" ) ) ]
327
- {
328
- false
329
- }
366
+ target_info. cpu_supports ( _feature)
330
367
/*
331
368
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
332
369
avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,
0 commit comments