On Tue, May 24, 2016 at 7:18 PM, H.J. Lu <hjl.to...@gmail.com> wrote:
>> Oh, target_flags is only a 32bit integer :(. Is there a reason it >> can't be extended to HOST_WIDE_INT, as is the case with >> ix86_isa_flags? > > target_flags is generic, not target specific. I want to limit my > change to x86 backend and -mgeneral-regs-only doesn't need > to use target_flags . I have thrown together a quick patch that defines target_flags as HOST_WIDE_INT. (Patch still needs a small correction, so opth-gen.awk will emit HOST_WIDE_INT_1 for MASK_* defines, have to go now, but I was able to compile functional x86_64-apple-darwin15.5.0 crosscompiler.) Uros.
Index: common/config/i386/i386-common.c =================================================================== --- common/config/i386/i386-common.c (revision 236644) +++ common/config/i386/i386-common.c (working copy) @@ -223,6 +223,11 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_RDRND_UNSET OPTION_MASK_ISA_RDRND #define OPTION_MASK_ISA_F16C_UNSET OPTION_MASK_ISA_F16C +#define OPTION_MASK_ISA_GENERAL_REGS_ONLY_UNSET \ + (OPTION_MASK_ISA_MMX_UNSET \ + | OPTION_MASK_ISA_SSE_UNSET \ + | OPTION_MASK_ISA_MPX) + /* Implement TARGET_HANDLE_OPTION. */ bool @@ -236,6 +241,21 @@ ix86_handle_option (struct gcc_options *opts, switch (code) { + case OPT_mgeneral_regs_only: + if (value) + { + /* Disable MPX, MMX, SSE and x87 instructions if only the + general registers are allowed.. */ + opts->x_ix86_isa_flags + &= ~OPTION_MASK_ISA_GENERAL_REGS_ONLY_UNSET; + opts->x_ix86_isa_flags_explicit + |= OPTION_MASK_ISA_GENERAL_REGS_ONLY_UNSET; + opts->x_target_flags &= ~MASK_80387; + } + else + gcc_unreachable (); + return true; + case OPT_mmmx: if (value) { Index: common.opt =================================================================== --- common.opt (revision 236644) +++ common.opt (working copy) @@ -23,7 +23,7 @@ ; Please try to keep this file in ASCII collating order. Variable -int target_flags +HOST_WIDE_INT target_flags Variable int optimize Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 236645) +++ config/i386/i386.c (working copy) @@ -5337,7 +5337,10 @@ ix86_option_override_internal (bool main_args_p, && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PKU)) opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PKU; - if (!(opts_set->x_target_flags & MASK_80387)) + /* Don't enable x87 instructions if only the general registers + are allowed. */ + if (!(opts_set->x_target_flags & MASK_GENERAL_REGS_ONLY) + && !(opts_set->x_target_flags & MASK_80387)) { if (processor_alias_table[i].flags & PTA_NO_80387) opts->x_target_flags &= ~MASK_80387; Index: config/i386/i386.opt =================================================================== --- config/i386/i386.opt (revision 236644) +++ config/i386/i386.opt (working copy) @@ -74,7 +74,7 @@ HOST_WIDE_INT x_ix86_isa_flags_explicit ;; which flags were passed by the user Variable -int ix86_target_flags_explicit +HOST_WIDE_INT ix86_target_flags_explicit ;; which flags were passed by the user TargetSave @@ -897,3 +897,7 @@ Enum(stack_protector_guard) String(global) Value(S mmitigate-rop Target Var(flag_mitigate_rop) Init(0) Attempt to avoid generating instruction sequences containing ret bytes. + +mgeneral-regs-only +Target Report RejectNegative Mask(GENERAL_REGS_ONLY) Save +Generate code which uses only the general registers. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 236644) +++ doc/invoke.texi (working copy) @@ -1173,7 +1173,7 @@ See RS/6000 and PowerPC Options. -msse2avx -mfentry -mrecord-mcount -mnop-mcount -m8bit-idiv @gol -mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol -malign-data=@var{type} -mstack-protector-guard=@var{guard} @gol --mmitigate-rop} +-mmitigate-rop -mgeneral-regs-only} @emph{x86 Windows Options} @gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll @gol @@ -24298,6 +24298,12 @@ opcodes, to mitigate against certain forms of atta this option is limited in what it can do and should not be relied on to provide serious protection. +@item -mgeneral-regs-only +@opindex mgeneral-regs-only +Generate code that uses only the general-purpose registers. This +prevents the compiler from using floating-point, vector, mask and bound +registers. + @end table These @samp{-m} switches are supported in addition to the above Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 236644) +++ doc/tm.texi (working copy) @@ -652,7 +652,7 @@ macro to define @code{__ELF__}, so you probably do it yourself. @end defmac -@deftypevar {extern int} target_flags +@deftypevar {extern HOST_WIDE_INT} target_flags This variable is declared in @file{options.h}, which is included before any target-specific headers. @end deftypevar Index: doc/tm.texi.in =================================================================== --- doc/tm.texi.in (revision 236644) +++ doc/tm.texi.in (working copy) @@ -650,7 +650,7 @@ macro to define @code{__ELF__}, so you probably do it yourself. @end defmac -@deftypevar {extern int} target_flags +@deftypevar {extern HOST_WIDE_INT} target_flags This variable is declared in @file{options.h}, which is included before any target-specific headers. @end deftypevar Index: gensupport.c =================================================================== --- gensupport.c (revision 236644) +++ gensupport.c (working copy) @@ -36,7 +36,7 @@ static char used_operands_numbers[MAX_OPERANDS]; /* In case some macros used by files we include need it, define this here. */ -int target_flags; +HOST_WIDE_INT target_flags; int insn_elision = 1; Index: opth-gen.awk =================================================================== --- opth-gen.awk (revision 236644) +++ opth-gen.awk (working copy) @@ -366,17 +366,17 @@ for (i = 0; i < n_extra_masks; i++) { } for (var in masknum) { - if (var != "" && host_wide_int[var] == "yes") { + if (var == "" || host_wide_int[var] == "yes") { print" #if defined(HOST_BITS_PER_WIDE_INT) && " masknum[var] " >= HOST_BITS_PER_WIDE_INT" - print "#error too many masks for " var - print "#endif" - } - else if (masknum[var] > 31) { if (var == "") print "#error too many target masks" else print "#error too many masks for " var + print "#endif" } + else if (masknum[var] > 31) { + print "#error too many masks for " var + } } print ""