https://gcc.gnu.org/g:a3cfc9ff862f7fe7889ff07697f7d59dc5311801
commit r17-6593-ga3cfc9ff862f7fe7889ff07697f7d59dc5311801 Author: Uros Bizjak <[email protected]> Date: Wed Nov 18 07:54:25 2026 +0000 i386: Move reg-stack.cc to config/i386/i386-reg-stack.cc The register stack conversion pass is used only by x86 (STACK_REGS is defined only by the i386 port, for the x87 register stack), so make it a part of that port. The pass is no longer registered in the generic pipeline. Instead, i386-passes.def inserts pass_split_before_regstack and pass_stack_regs after pass_sched2, which preserves the pass order on x86. The old pass_stack_regs only served as a STACK_REGS gate and a container for these two passes, so remove it and rename pass_stack_regs_run to pass_stack_regs. No functional change. Assisted-by: Claude Sonnet 5.5 gcc/ChangeLog: * reg-stack.cc: Move to config/i386/i386-reg-stack.cc. * config/i386/i386-reg-stack.cc: New file, moved from reg-stack.cc. Include tm_p.h. Remove STACK_REGS conditionals. (regstack_completed): Make bool. (rest_of_handle_stack_regs): Update. (pass_data_stack_regs, pass_stack_regs) (make_pass_stack_regs): Remove the old gating pass. (pass_data_stack_regs_run, pass_stack_regs_run) (make_pass_stack_regs_run): Rename to pass_data_stack_regs, pass_stack_regs and make_pass_stack_regs. * Makefile.in (OBJS): Remove reg-stack.o. (GTFILES): Remove reg-stack.cc. * config.gcc (extra_objs) <i[34567]86-*-* | x86_64-*-*>: Add i386-reg-stack.o. * config/i386/t-i386 (i386-reg-stack.o): New rule. * config/i386/i386-passes.def (pass_split_before_regstack) (pass_stack_regs): Insert after pass_sched2. * config/i386/i386-protos.h (make_pass_stack_regs): Declare. * passes.def (pass_stack_regs, pass_split_before_regstack) (pass_stack_regs_run): Remove. * tree-pass.h (make_pass_stack_regs) (make_pass_stack_regs_run): Remove. * cfgcleanup.cc (old_insns_match_p): Update comment. * ira-build.cc (loop_with_complex_edge_p): Update comment. * rtl.h (regstack_completed): Make bool. Update comment. * final.cc (rest_of_clean_state): Update. * config/i386/i386.h (STACK_REGS): Ditto. * doc/passes.texi (RTL passes): Remove Register-to-stack conversion item. * doc/tm.texi.in (Stack Registers): Remove advice on porting the stack register pass to a new architecture. (STACK_REG_COVER_CLASS): Remove. * doc/tm.texi: Regenerate. Diff: --- gcc/Makefile.in | 4 +- gcc/cfgcleanup.cc | 4 +- gcc/config.gcc | 2 +- gcc/config/i386/i386-passes.def | 4 ++ gcc/config/i386/i386-protos.h | 1 + .../i386/i386-reg-stack.cc} | 73 +++++----------------- gcc/config/i386/i386.h | 4 +- gcc/config/i386/t-i386 | 4 ++ gcc/doc/passes.texi | 7 --- gcc/doc/tm.texi | 10 +-- gcc/doc/tm.texi.in | 10 +-- gcc/final.cc | 2 +- gcc/ira-build.cc | 2 +- gcc/passes.def | 5 -- gcc/rtl.h | 5 +- gcc/tree-pass.h | 2 - 16 files changed, 34 insertions(+), 105 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index b7e52696ef0b..ac105591ce27 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1707,7 +1707,6 @@ OBJS = \ real.o \ realmpfr.o \ recog.o \ - reg-stack.o \ regcprop.o \ reginfo.o \ regrename.o \ @@ -3158,8 +3157,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/gcse.cc $(srcdir)/godump.cc \ $(srcdir)/lists.cc $(srcdir)/optabs-libfuncs.cc \ $(srcdir)/profile.cc $(srcdir)/mcf.cc \ - $(srcdir)/reg-stack.cc $(srcdir)/cfgrtl.cc \ - $(srcdir)/stor-layout.cc \ + $(srcdir)/cfgrtl.cc $(srcdir)/stor-layout.cc \ $(srcdir)/stringpool.cc $(srcdir)/tree.cc $(srcdir)/varasm.cc \ $(srcdir)/gimple.h \ $(srcdir)/gimple-ssa.h \ diff --git a/gcc/cfgcleanup.cc b/gcc/cfgcleanup.cc index f9d071e128df..28a924d88b4f 100644 --- a/gcc/cfgcleanup.cc +++ b/gcc/cfgcleanup.cc @@ -1180,8 +1180,8 @@ old_insns_match_p (int mode ATTRIBUTE_UNUSED, rtx_insn *i1, rtx_insn *i2) /* If this is a CALL_INSN, compare register usage information. If we don't check this on stack register machines, the two - CALL_INSNs might be merged leaving reg-stack.cc with mismatching - numbers of stack registers in the same basic block. + CALL_INSNs might be merged leaving the register stack pass with + mismatching numbers of stack registers in the same basic block. If we don't check this on machines with delay slots, a delay slot may be filled that clobbers a parameter expected by the subroutine. diff --git a/gcc/config.gcc b/gcc/config.gcc index 91891b67bbb9..5821df3eb1e7 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -448,7 +448,7 @@ i[34567]86-*-* | x86_64-*-*) cxx_target_objs="i386-c.o" d_target_objs="i386-d.o" jit_target_objs="i386-jit.o" - extra_objs="x86-tune-sched.o x86-tune-sched-bd.o x86-tune-sched-atom.o x86-tune-sched-core.o i386-options.o i386-builtins.o i386-expand.o i386-features.o" + extra_objs="x86-tune-sched.o x86-tune-sched-bd.o x86-tune-sched-atom.o x86-tune-sched-core.o i386-reg-stack.o i386-options.o i386-builtins.o i386-expand.o i386-features.o" target_gtfiles="\$(srcdir)/config/i386/i386-builtins.cc \$(srcdir)/config/i386/i386-expand.cc \$(srcdir)/config/i386/i386-options.cc" extra_options="${extra_options} fused-madd.opt" extra_headers="cpuid.h mmintrin.h mm3dnow.h xmmintrin.h emmintrin.h diff --git a/gcc/config/i386/i386-passes.def b/gcc/config/i386/i386-passes.def index 4f461116cac3..9b2722317251 100644 --- a/gcc/config/i386/i386-passes.def +++ b/gcc/config/i386/i386-passes.def @@ -24,6 +24,10 @@ along with GCC; see the file COPYING3. If not see REPLACE_PASS (PASS, INSTANCE, TGT_PASS) */ + /* Both are inserted after pass_sched2, so the later insertion runs first. */ + INSERT_PASS_AFTER (pass_sched2, 1, pass_stack_regs); + INSERT_PASS_AFTER (pass_sched2, 1, pass_split_before_regstack); + INSERT_PASS_AFTER (pass_postreload_cse, 1, pass_insert_vzeroupper); INSERT_PASS_AFTER (pass_late_combine, 1, pass_stv, false /* timode_p */); /* Run the 64-bit STV pass before the CSE pass so that CONST0_RTX and diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 377514eb585b..42684d187da3 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -435,6 +435,7 @@ extern rtl_opt_pass *make_pass_insert_endbr_and_patchable_area extern rtl_opt_pass *make_pass_remove_partial_avx_dependency (gcc::context *); extern rtl_opt_pass *make_pass_x86_cse (gcc::context *); +extern rtl_opt_pass *make_pass_stack_regs (gcc::context *); extern rtl_opt_pass *make_pass_apx_nf_convert (gcc::context *); extern rtl_opt_pass *make_pass_align_tight_loops (gcc::context *); diff --git a/gcc/reg-stack.cc b/gcc/config/i386/i386-reg-stack.cc similarity index 99% rename from gcc/reg-stack.cc rename to gcc/config/i386/i386-reg-stack.cc index 94609c7ace8d..9deed8b08041 100644 --- a/gcc/reg-stack.cc +++ b/gcc/config/i386/i386-reg-stack.cc @@ -148,9 +148,9 @@ asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp)); - This asm takes two inputs, which are popped by the fyl2xp1 opcode, - and replaces them with one output. The user must code the "st(1)" - clobber for reg-stack.cc to know that fyl2xp1 pops both inputs. + This asm takes two inputs, which are popped by the fyl2xp1 opcode, and + replaces them with one output. The user must code the "st(1)" clobber + for the register stack pass to know that fyl2xp1 pops both inputs. asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)"); @@ -164,6 +164,7 @@ #include "rtl.h" #include "tree.h" #include "df.h" +#include "tm_p.h" #include "insn-config.h" #include "memmodel.h" #include "regs.h" @@ -180,8 +181,6 @@ #include "rtl-iter.h" #include "function-abi.h" -#ifdef STACK_REGS - /* We use this array to cache info about insns, because otherwise we spend too much time in stack_regs_mentioned_p. @@ -192,7 +191,7 @@ static vec<char> stack_regs_mentioned_data; #define REG_STACK_SIZE (LAST_STACK_REG - FIRST_STACK_REG + 1) -int regstack_completed = 0; +bool regstack_completed = false; /* This is the basic stack record. TOP is an index into REG[] such that REG[TOP] is the top of stack. If TOP is -1 the stack is empty. @@ -3458,66 +3457,22 @@ reg_to_stack (void) free_aux_for_blocks (); return true; } -#endif /* STACK_REGS */ -namespace { - -const pass_data pass_data_stack_regs = -{ - RTL_PASS, /* type */ - "*stack_regs", /* name */ - OPTGROUP_NONE, /* optinfo_flags */ - TV_REG_STACK, /* tv_id */ - 0, /* properties_required */ - 0, /* properties_provided */ - 0, /* properties_destroyed */ - 0, /* todo_flags_start */ - 0, /* todo_flags_finish */ -}; - -class pass_stack_regs : public rtl_opt_pass -{ -public: - pass_stack_regs (gcc::context *ctxt) - : rtl_opt_pass (pass_data_stack_regs, ctxt) - {} - - /* opt_pass methods: */ - bool gate (function *) final override - { -#ifdef STACK_REGS - return true; -#else - return false; -#endif - } - -}; // class pass_stack_regs - -} // anon namespace - -rtl_opt_pass * -make_pass_stack_regs (gcc::context *ctxt) -{ - return new pass_stack_regs (ctxt); -} - /* Convert register usage from flat register file usage to a stack register file. */ static unsigned int rest_of_handle_stack_regs (void) { -#ifdef STACK_REGS if (reg_to_stack ()) df_insn_rescan_all (); - regstack_completed = 1; -#endif + regstack_completed = true; + return 0; } namespace { -const pass_data pass_data_stack_regs_run = +const pass_data pass_data_stack_regs = { RTL_PASS, /* type */ "stack", /* name */ @@ -3530,11 +3485,11 @@ const pass_data pass_data_stack_regs_run = TODO_df_finish, /* todo_flags_finish */ }; -class pass_stack_regs_run : public rtl_opt_pass +class pass_stack_regs : public rtl_opt_pass { public: - pass_stack_regs_run (gcc::context *ctxt) - : rtl_opt_pass (pass_data_stack_regs_run, ctxt) + pass_stack_regs (gcc::context *ctxt) + : rtl_opt_pass (pass_data_stack_regs, ctxt) {} /* opt_pass methods: */ @@ -3543,12 +3498,12 @@ public: return rest_of_handle_stack_regs (); } -}; // class pass_stack_regs_run +}; // class pass_stack_regs } // anon namespace rtl_opt_pass * -make_pass_stack_regs_run (gcc::context *ctxt) +make_pass_stack_regs (gcc::context *ctxt) { - return new pass_stack_regs_run (ctxt); + return new pass_stack_regs (ctxt); } diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 31a36d2e274f..04237e91764e 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -967,9 +967,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); /* Standard register usage. */ -/* This processor has special stack-like registers. See reg-stack.cc - for details. */ - +/* This processor has special stack-like registers. */ #define STACK_REGS #define IS_STACK_MODE(MODE) \ diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386 index ae0fb8ed474d..126c965b3d38 100644 --- a/gcc/config/i386/t-i386 +++ b/gcc/config/i386/t-i386 @@ -54,6 +54,10 @@ i386-jit.o: $(srcdir)/config/i386/i386-jit.cc $(COMPILE) $< $(POSTCOMPILE) +i386-reg-stack.o: $(srcdir)/config/i386/i386-reg-stack.cc + $(COMPILE) $< + $(POSTCOMPILE) + i386-options.o: $(srcdir)/config/i386/i386-options.cc $(COMPILE) $< $(POSTCOMPILE) diff --git a/gcc/doc/passes.texi b/gcc/doc/passes.texi index a5bbbbcd97e6..fb47a75dc38b 100644 --- a/gcc/doc/passes.texi +++ b/gcc/doc/passes.texi @@ -1144,13 +1144,6 @@ will be from each other instruction, and therefore whether the usual instructions, or the longer sequences, must be used for each branch. The code for this pass is located in @file{final.cc}. -@item Register-to-stack conversion - -Conversion from usage of some hard registers to usage of a register -stack may be done at this point. Currently, this is supported only -for the floating-point registers of the Intel 80387 coprocessor. The -code for this pass is located in @file{reg-stack.cc}. - @item Final This pass outputs the assembler code for the function. The source files diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 65cf4c640e7b..c681943ec082 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -2400,20 +2400,12 @@ stack. Currently, GCC can only handle one group of stack-like registers, and they must be consecutively numbered. Furthermore, the existing support for stack-like registers is specific to the 80387 floating -point coprocessor. If you have a new architecture that uses -stack-like registers, you will need to do substantial work on -@file{reg-stack.cc} and write your machine description to cooperate -with it, as well as defining these macros. +point coprocessor. @defmac STACK_REGS Define this if the machine has any stack-like registers. @end defmac -@defmac STACK_REG_COVER_CLASS -This is a cover class containing the stack registers. Define this if -the machine has any stack-like registers. -@end defmac - @defmac FIRST_STACK_REG The number of the first stack-like register. This one is the top of the stack. diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 6b8203c5bedc..58059ed65940 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -1985,20 +1985,12 @@ stack. Currently, GCC can only handle one group of stack-like registers, and they must be consecutively numbered. Furthermore, the existing support for stack-like registers is specific to the 80387 floating -point coprocessor. If you have a new architecture that uses -stack-like registers, you will need to do substantial work on -@file{reg-stack.cc} and write your machine description to cooperate -with it, as well as defining these macros. +point coprocessor. @defmac STACK_REGS Define this if the machine has any stack-like registers. @end defmac -@defmac STACK_REG_COVER_CLASS -This is a cover class containing the stack registers. Define this if -the machine has any stack-like registers. -@end defmac - @defmac FIRST_STACK_REG The number of the first stack-like register. This one is the top of the stack. diff --git a/gcc/final.cc b/gcc/final.cc index ce501e8f9b02..7e0adf563dc0 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -4575,7 +4575,7 @@ rest_of_clean_state (void) post_ra_split_completed = false; epilogue_completed = 0; #ifdef STACK_REGS - regstack_completed = 0; + regstack_completed = false; #endif /* Clear out the insn_length contents now that they are no diff --git a/gcc/ira-build.cc b/gcc/ira-build.cc index d8c9da931921..0c94bd98edd9 100644 --- a/gcc/ira-build.cc +++ b/gcc/ira-build.cc @@ -2241,7 +2241,7 @@ low_pressure_loop_node_p (ira_loop_tree_node_t node) #ifdef STACK_REGS /* Return TRUE if LOOP has a complex enter or exit edge. We don't form a region from such loop if the target use stack register - because reg-stack.cc cannot deal with such edges. */ + because the register stack pass cannot deal with such edges. */ static bool loop_with_complex_edge_p (class loop *loop) { diff --git a/gcc/passes.def b/gcc/passes.def index 64b8f8102d29..1a785d516321 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -547,11 +547,6 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_leaf_regs); NEXT_PASS (pass_split_before_sched2); NEXT_PASS (pass_sched2); - NEXT_PASS (pass_stack_regs); - PUSH_INSERT_PASSES_WITHIN (pass_stack_regs) - NEXT_PASS (pass_split_before_regstack); - NEXT_PASS (pass_stack_regs_run); - POP_INSERT_PASSES () POP_INSERT_PASSES () NEXT_PASS (pass_late_thread_prologue_and_epilogue); /* No target-independent code motion is allowed beyond this point, diff --git a/gcc/rtl.h b/gcc/rtl.h index c3f46c6f2e9d..a181d884c51b 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -4330,9 +4330,8 @@ extern bool lra_in_progress; #define can_create_pseudo_p() (!reload_in_progress && !reload_completed) #ifdef STACK_REGS -/* Nonzero after end of regstack pass. - Set to 1 or 0 by reg-stack.cc. */ -extern int regstack_completed; +/* True after end of regstack pass. */ +extern bool regstack_completed; #endif /* If this is nonzero, we do not bother generating VOLATILE diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 48aebe41764d..5130ddd4cb14 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -647,8 +647,6 @@ extern rtl_opt_pass *make_pass_leaf_regs (gcc::context *ctxt); extern rtl_opt_pass *make_pass_split_before_sched2 (gcc::context *ctxt); extern rtl_opt_pass *make_pass_compare_elim_after_reload (gcc::context *ctxt); extern rtl_opt_pass *make_pass_sched2 (gcc::context *ctxt); -extern rtl_opt_pass *make_pass_stack_regs (gcc::context *ctxt); -extern rtl_opt_pass *make_pass_stack_regs_run (gcc::context *ctxt); extern rtl_opt_pass *make_pass_df_finish (gcc::context *ctxt); extern rtl_opt_pass *make_pass_compute_alignments (gcc::context *ctxt); extern rtl_opt_pass *make_pass_duplicate_computed_gotos (gcc::context *ctxt);
