1- use std:: collections:: HashSet ;
2- use std:: env;
31use std:: sync:: Arc ;
42use std:: time:: Instant ;
53
6- use gccjit:: { CType , Context , FunctionType , GlobalKind } ;
4+ use gccjit:: { CType , FunctionType , GlobalKind } ;
75use rustc_codegen_ssa:: ModuleCodegen ;
86use rustc_codegen_ssa:: base:: maybe_create_entry_wrapper;
97use rustc_codegen_ssa:: mono_item:: MonoItemExt ;
@@ -18,11 +16,11 @@ use rustc_session::config::DebugInfo;
1816use rustc_span:: Symbol ;
1917#[ cfg( feature = "master" ) ]
2018use rustc_target:: spec:: SymbolVisibility ;
21- use rustc_target:: spec:: { Arch , RelocModel } ;
2219
2320use crate :: builder:: Builder ;
2421use crate :: context:: CodegenCx ;
25- use crate :: { GccContext , LockedTargetInfo , LtoMode , SyncContext , gcc_util, new_context} ;
22+ use crate :: gcc_util:: new_context;
23+ use crate :: { GccContext , LockedTargetInfo , LtoMode , SyncContext } ;
2624
2725#[ cfg( feature = "master" ) ]
2826pub fn visibility_to_gcc ( visibility : Visibility ) -> gccjit:: Visibility {
@@ -101,41 +99,7 @@ pub fn compile_codegen_unit(
10199 ) -> ModuleCodegen < GccContext > {
102100 let cgu = tcx. codegen_unit ( cgu_name) ;
103101 // Instantiate monomorphizations without filling out definitions yet...
104- let context = new_context ( tcx) ;
105-
106- if tcx. sess . panic_strategy ( ) . unwinds ( ) {
107- context. add_command_line_option ( "-fexceptions" ) ;
108- context. add_driver_option ( "-fexceptions" ) ;
109- }
110-
111- let disabled_features: HashSet < _ > = tcx
112- . sess
113- . opts
114- . cg
115- . target_feature
116- . split ( ',' )
117- . filter ( |feature| feature. starts_with ( '-' ) )
118- . map ( |string| & string[ 1 ..] )
119- . collect ( ) ;
120-
121- if !disabled_features. contains ( "avx" ) && tcx. sess . target . arch == Arch :: X86_64 {
122- // NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for
123- // SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead.
124- // FIXME(antoyo): use the proper builtins for llvm.x86.sse2.cmp.pd and similar.
125- context. add_command_line_option ( "-mavx" ) ;
126- }
127-
128- for arg in & tcx. sess . opts . cg . llvm_args {
129- context. add_command_line_option ( arg) ;
130- }
131- // NOTE: This is needed to compile the file src/intrinsic/archs.rs during a bootstrap of rustc.
132- context. add_command_line_option ( "-fno-var-tracking-assignments" ) ;
133- // NOTE: an optimization (https://github.com/rust-lang/rustc_codegen_gcc/issues/53).
134- context. add_command_line_option ( "-fno-semantic-interposition" ) ;
135- // NOTE: Rust relies on LLVM not doing TBAA (https://github.com/rust-lang/unsafe-code-guidelines/issues/292).
136- context. add_command_line_option ( "-fno-strict-aliasing" ) ;
137- // NOTE: Rust relies on LLVM doing wrapping on overflow.
138- context. add_command_line_option ( "-fwrapv" ) ;
102+ let context = new_context ( tcx. sess ) ;
139103
140104 // NOTE: We need to honor the `#![no_builtins]` attribute to prevent GCC from
141105 // replacing code patterns (like loops) with calls to builtins (like memset).
@@ -148,64 +112,6 @@ pub fn compile_codegen_unit(
148112 context. add_command_line_option ( "-fno-tree-loop-distribute-patterns" ) ;
149113 }
150114
151- if let Some ( model) = tcx. sess . code_model ( ) {
152- use rustc_target:: spec:: CodeModel ;
153-
154- context. add_command_line_option ( match model {
155- CodeModel :: Tiny => "-mcmodel=tiny" ,
156- CodeModel :: Small => "-mcmodel=small" ,
157- CodeModel :: Kernel => "-mcmodel=kernel" ,
158- CodeModel :: Medium => "-mcmodel=medium" ,
159- CodeModel :: Large => "-mcmodel=large" ,
160- } ) ;
161- }
162-
163- add_pic_option ( & context, tcx. sess . relocation_model ( ) ) ;
164-
165- let target_cpu = gcc_util:: target_cpu ( tcx. sess ) ;
166- if target_cpu != "generic" {
167- context. add_command_line_option ( format ! ( "-march={}" , target_cpu) ) ;
168- }
169-
170- if tcx
171- . sess
172- . opts
173- . unstable_opts
174- . function_sections
175- . unwrap_or ( tcx. sess . target . function_sections )
176- {
177- context. add_command_line_option ( "-ffunction-sections" ) ;
178- context. add_command_line_option ( "-fdata-sections" ) ;
179- }
180-
181- if env:: var ( "CG_GCCJIT_DUMP_RTL" ) . as_deref ( ) == Ok ( "1" ) {
182- context. add_command_line_option ( "-fdump-rtl-vregs" ) ;
183- }
184- if env:: var ( "CG_GCCJIT_DUMP_RTL_ALL" ) . as_deref ( ) == Ok ( "1" ) {
185- context. add_command_line_option ( "-fdump-rtl-all" ) ;
186- }
187- if env:: var ( "CG_GCCJIT_DUMP_TREE_ALL" ) . as_deref ( ) == Ok ( "1" ) {
188- context. add_command_line_option ( "-fdump-tree-all-eh" ) ;
189- }
190- if env:: var ( "CG_GCCJIT_DUMP_IPA_ALL" ) . as_deref ( ) == Ok ( "1" ) {
191- context. add_command_line_option ( "-fdump-ipa-all-eh" ) ;
192- }
193- if env:: var ( "CG_GCCJIT_DUMP_CODE" ) . as_deref ( ) == Ok ( "1" ) {
194- context. set_dump_code_on_compile ( true ) ;
195- }
196- if env:: var ( "CG_GCCJIT_DUMP_GIMPLE" ) . as_deref ( ) == Ok ( "1" ) {
197- context. set_dump_initial_gimple ( true ) ;
198- }
199- if env:: var ( "CG_GCCJIT_DUMP_EVERYTHING" ) . as_deref ( ) == Ok ( "1" ) {
200- context. set_dump_everything ( true ) ;
201- }
202- if env:: var ( "CG_GCCJIT_KEEP_INTERMEDIATES" ) . as_deref ( ) == Ok ( "1" ) {
203- context. set_keep_intermediates ( true ) ;
204- }
205- if env:: var ( "CG_GCCJIT_VERBOSE" ) . as_deref ( ) == Ok ( "1" ) {
206- context. add_driver_option ( "-v" ) ;
207- }
208-
209115 // NOTE: The codegen generates unreachable blocks.
210116 context. set_allow_unreachable_blocks ( true ) ;
211117
@@ -269,24 +175,3 @@ pub fn compile_codegen_unit(
269175
270176 ( module, cost)
271177}
272-
273- pub fn add_pic_option < ' gcc > ( context : & Context < ' gcc > , relocation_model : RelocModel ) {
274- match relocation_model {
275- rustc_target:: spec:: RelocModel :: Static => {
276- context. add_command_line_option ( "-fno-pie" ) ;
277- context. add_driver_option ( "-fno-pie" ) ;
278- }
279- rustc_target:: spec:: RelocModel :: Pic => {
280- context. add_command_line_option ( "-fPIC" ) ;
281- // NOTE: we use both add_command_line_option and add_driver_option because the usage in
282- // this module (compile_codegen_unit) requires add_command_line_option while the usage
283- // in the back::write module (codegen) requires add_driver_option.
284- context. add_driver_option ( "-fPIC" ) ;
285- }
286- rustc_target:: spec:: RelocModel :: Pie => {
287- context. add_command_line_option ( "-fPIE" ) ;
288- context. add_driver_option ( "-fPIE" ) ;
289- }
290- model => eprintln ! ( "Unsupported relocation model: {:?}" , model) ,
291- }
292- }
0 commit comments