On Fri, Jan 8, 2021 at 9:24 AM Jakub Jelinek <ja...@redhat.com> wrote: > > Hi! > > My patch to save/restore opts_set rather than essentially treating > global_options_set as a logical or whether some option has ever been > explicitly set somewhere apparently broke -mcmodel= vs. target attribute > (and as the patch shows some other options too). > The thing is, at least for options for which we ever test opts_set->x_* > or global_options_set.x_*, we need to save/restore them next to the > saving/restoring of the actual option values. > If an option has Save keyword or in case of TargetVariable, it is the > generic code that handles the saving and restoring of both the option > and corresponding opts_set flag automatically, for other variables > (TargetSave, or Target without Save) the backend needs to do that in the > target hook manually and in that case should save/restore both the option > values (the hooks mostly did that) and opts_set (they didn't). > > As it seems much easier to let the automatic saving/restoring do the work > for us unless the saving/restoring of the option needs some specific magic, > the following patch is a result of grepping through the backend for > opts_set->x_ and global_options_set.x_ and for all such referenced > variables, grepping whether it is saved/restored including opts_set properly > in the generated options-save.c or not. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2021-01-07 Jakub Jelinek <ja...@redhat.com> > > PR target/98585 > * config/i386/i386.opt (ix86_cmodel, ix86_incoming_stack_boundary_arg, > ix86_pmode, ix86_preferred_stack_boundary_arg, ix86_regparm, > ix86_veclibabi_type): Remove x_ prefix, use TargetVariable instead of > TargetSave and initialize for variables with enum types. > (mfentry, mstack-protector-guard-reg=, mstack-protector-guard-offset=, > mstack-protector-guard-symbol=): Add Save. > > * config/i386/i386-options.c (ix86_function_specific_save, > ix86_function_specific_restore): Don't save or restore x_ix86_cmodel, > x_ix86_incoming_stack_boundary_arg, x_ix86_pmode, > x_ix86_preferred_stack_boundary_arg, x_ix86_regparm, > x_ix86_veclibabi_type. > > * gcc.target/i386/pr98585.c: New test.
LGTM. Thanks, Uros. > --- gcc/config/i386/i386.opt.jj 2021-01-07 21:08:41.017459644 +0100 > +++ gcc/config/i386/i386.opt 2021-01-07 21:16:02.468563270 +0100 > @@ -105,8 +105,8 @@ TargetSave > unsigned char arch_specified > > ;; -mcmodel= model > -TargetSave > -enum cmodel x_ix86_cmodel > +TargetVariable > +enum cmodel ix86_cmodel = CM_32 > > ;; -mabi= > TargetSave > @@ -133,24 +133,24 @@ TargetSave > int x_ix86_force_drap > > ;; -mincoming-stack-boundary= > -TargetSave > -int x_ix86_incoming_stack_boundary_arg > +TargetVariable > +int ix86_incoming_stack_boundary_arg > > ;; -maddress-mode= > -TargetSave > -enum pmode x_ix86_pmode > +TargetVariable > +enum pmode ix86_pmode = PMODE_SI > > ;; -mpreferred-stack-boundary= > -TargetSave > -int x_ix86_preferred_stack_boundary_arg > +TargetVariable > +int ix86_preferred_stack_boundary_arg > > ;; -mrecip= > TargetSave > const char *x_ix86_recip_name > > ;; -mregparm= > -TargetSave > -int x_ix86_regparm > +TargetVariable > +int ix86_regparm > > ;; -mlarge-data-threshold= > TargetSave > @@ -189,8 +189,8 @@ TargetSave > int x_ix86_tune_no_default > > ;; -mveclibabi= > -TargetSave > -enum ix86_veclibabi x_ix86_veclibabi_type > +TargetVariable > +enum ix86_veclibabi ix86_veclibabi_type = ix86_veclibabi_type_none > > ;; x86 options > m128bit-long-double > @@ -934,7 +934,7 @@ Target Mask(ISA_PREFETCHWT1) Var(ix86_is > Support PREFETCHWT1 built-in functions and code generation. > > mfentry > -Target Var(flag_fentry) > +Target Save Var(flag_fentry) > Emit profiling counter call at function entry before prologue. > > mrecord-mcount > @@ -1005,21 +1005,21 @@ EnumValue > Enum(stack_protector_guard) String(global) Value(SSP_GLOBAL) > > mstack-protector-guard-reg= > -Target RejectNegative Joined Var(ix86_stack_protector_guard_reg_str) > +Target Save RejectNegative Joined Var(ix86_stack_protector_guard_reg_str) > Use the given base register for addressing the stack-protector guard. > > TargetVariable > addr_space_t ix86_stack_protector_guard_reg = ADDR_SPACE_GENERIC > > mstack-protector-guard-offset= > -Target RejectNegative Joined Integer > Var(ix86_stack_protector_guard_offset_str) > +Target Save RejectNegative Joined Integer > Var(ix86_stack_protector_guard_offset_str) > Use the given offset for addressing the stack-protector guard. > > TargetVariable > HOST_WIDE_INT ix86_stack_protector_guard_offset = 0 > > mstack-protector-guard-symbol= > -Target RejectNegative Joined Integer > Var(ix86_stack_protector_guard_symbol_str) > +Target Save RejectNegative Joined Integer > Var(ix86_stack_protector_guard_symbol_str) > Use the given symbol for addressing the stack-protector guard. > > mmitigate-rop > --- gcc/config/i386/i386-options.c.jj 2021-01-04 10:25:45.426159170 +0100 > +++ gcc/config/i386/i386-options.c 2021-01-07 21:08:57.175280431 +0100 > @@ -651,18 +651,13 @@ ix86_function_specific_save (struct cl_t > ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit; > ptr->x_ix86_arch_string = opts->x_ix86_arch_string; > ptr->x_ix86_tune_string = opts->x_ix86_tune_string; > - ptr->x_ix86_cmodel = opts->x_ix86_cmodel; > ptr->x_ix86_abi = opts->x_ix86_abi; > ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect; > ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost; > ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes; > ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer; > ptr->x_ix86_force_drap = opts->x_ix86_force_drap; > - ptr->x_ix86_incoming_stack_boundary_arg = > opts->x_ix86_incoming_stack_boundary_arg; > - ptr->x_ix86_pmode = opts->x_ix86_pmode; > - ptr->x_ix86_preferred_stack_boundary_arg = > opts->x_ix86_preferred_stack_boundary_arg; > ptr->x_ix86_recip_name = opts->x_ix86_recip_name; > - ptr->x_ix86_regparm = opts->x_ix86_regparm; > ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold; > ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx; > ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard; > @@ -672,7 +667,6 @@ ix86_function_specific_save (struct cl_t > ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy; > ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy; > ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default; > - ptr->x_ix86_veclibabi_type = opts->x_ix86_veclibabi_type; > > /* The fields are char but the variables are not; make sure the > values fit in the fields. */ > @@ -788,18 +782,13 @@ ix86_function_specific_restore (struct g > opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit; > opts->x_ix86_arch_string = ptr->x_ix86_arch_string; > opts->x_ix86_tune_string = ptr->x_ix86_tune_string; > - opts->x_ix86_cmodel = ptr->x_ix86_cmodel; > opts->x_ix86_abi = ptr->x_ix86_abi; > opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect; > opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost; > opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes; > opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer; > opts->x_ix86_force_drap = ptr->x_ix86_force_drap; > - opts->x_ix86_incoming_stack_boundary_arg = > ptr->x_ix86_incoming_stack_boundary_arg; > - opts->x_ix86_pmode = ptr->x_ix86_pmode; > - opts->x_ix86_preferred_stack_boundary_arg = > ptr->x_ix86_preferred_stack_boundary_arg; > opts->x_ix86_recip_name = ptr->x_ix86_recip_name; > - opts->x_ix86_regparm = ptr->x_ix86_regparm; > opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold; > opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx; > opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard; > @@ -809,7 +798,6 @@ ix86_function_specific_restore (struct g > opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy; > opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy; > opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default; > - opts->x_ix86_veclibabi_type = ptr->x_ix86_veclibabi_type; > ix86_tune_cost = processor_cost_table[ix86_tune]; > /* TODO: ix86_cost should be chosen at instruction or function granuality > so for cold code we use size_cost even in !optimize_size compilation. > */ > --- gcc/testsuite/gcc.target/i386/pr98585.c.jj 2021-01-07 21:19:06.323524031 > +0100 > +++ gcc/testsuite/gcc.target/i386/pr98585.c 2021-01-07 21:18:51.171692091 > +0100 > @@ -0,0 +1,14 @@ > +/* PR target/98585 */ > +/* { dg-do compile { target *-*-linux* } } */ > +/* { dg-require-effective-target lp64 } */ > +/* { dg-options "-O2 -mcmodel=large -masm=att" } */ > +/* { dg-final { scan-assembler "movabs\[^\n\r]*bar" } } */ > + > +void bar (void); > + > +void > +__attribute__ ((target ("bmi2"))) > +foo() > +{ > + bar (); > +} > > Jakub >