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