From d520ee43111861ab0458ab96cd515355c875a528 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Thu, 3 Jan 2019 20:59:51 +0100 Subject: [PATCH] attempt to improve code quality for pascal calls --- gcc/gcc/calls.c | 45 +++++++++++++++-------------- gcc/gcc/combine-stack-adj.c | 5 +++- gcc/gcc/config/m68k/m68k-passes.def | 22 ++++++++++++++ gcc/gcc/config/m68k/t-m68k | 1 + 4 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 gcc/gcc/config/m68k/m68k-passes.def diff --git a/gcc/gcc/calls.c b/gcc/gcc/calls.c index 39d492785a..b0d56f580f 100644 --- a/gcc/gcc/calls.c +++ b/gcc/gcc/calls.c @@ -564,26 +564,6 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0) add_args_size_note (call_insn, stack_pointer_delta); - - if (is_pascal) - { - if (valreg) - { - poly_uint16 modesize = GET_MODE_SIZE (GET_MODE (valreg)); -#ifdef PUSH_ROUNDING - modesize = PUSH_ROUNDING (modesize); -#endif - rtx pop_insn = emit_move_insn(valreg, - gen_rtx_MEM( GET_MODE (valreg), - stack_pointer_rtx - )); - - adjust_stack(gen_int_mode (modesize, Pmode)); - } - } - - - if (!ACCUMULATE_OUTGOING_ARGS) { /* If returning from the subroutine does not automatically pop the args, @@ -618,6 +598,24 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU such machines. */ else if (maybe_ne (n_popped, 0)) anti_adjust_stack (gen_int_mode (n_popped, Pmode)); + + + if (is_pascal) + { + if (valreg) + { + poly_uint16 modesize = GET_MODE_SIZE (GET_MODE (valreg)); +#ifdef PUSH_ROUNDING + modesize = PUSH_ROUNDING (modesize); +#endif + rtx pop_insn = emit_move_insn(valreg, + gen_rtx_MEM( GET_MODE (valreg), + stack_pointer_rtx + )); + + adjust_stack(gen_int_mode (modesize, Pmode)); + } + } } /* Determine if the function identified by FNDECL is one with @@ -4248,7 +4246,6 @@ expand_call (tree exp, rtx target, int ignore) modesize = PUSH_ROUNDING (modesize); #endif push_block (gen_int_mode (modesize, Pmode), 0, 0); - NO_DEFER_POP; // ### UNBALANCED } /* Now store (and compute if necessary) all non-register parms. @@ -4340,7 +4337,11 @@ expand_call (tree exp, rtx target, int ignore) if (TYPE_MODE (rettype) != VOIDmode && ! structure_value_addr) { - if (pcc_struct_value) + if (is_pascal) + { + valreg = gen_reg_rtx(TYPE_MODE(rettype)); + } + else if (pcc_struct_value) { valreg = hard_function_value (build_pointer_type (rettype), fndecl, NULL, (pass == 0)); diff --git a/gcc/gcc/combine-stack-adj.c b/gcc/gcc/combine-stack-adj.c index 4573dc2a87..8b50b8a65d 100644 --- a/gcc/gcc/combine-stack-adj.c +++ b/gcc/gcc/combine-stack-adj.c @@ -726,7 +726,10 @@ public: { return rest_of_handle_stack_adjustments (); } - + virtual opt_pass *clone () + { + return new pass_stack_adjustments(m_ctxt); + } }; // class pass_stack_adjustments bool diff --git a/gcc/gcc/config/m68k/m68k-passes.def b/gcc/gcc/config/m68k/m68k-passes.def new file mode 100644 index 0000000000..0cf1c594fb --- /dev/null +++ b/gcc/gcc/config/m68k/m68k-passes.def @@ -0,0 +1,22 @@ + +/* + Macros that can be used in this file: + INSERT_PASS_AFTER (PASS, INSTANCE, TGT_PASS) + INSERT_PASS_BEFORE (PASS, INSTANCE, TGT_PASS) + REPLACE_PASS (PASS, INSTANCE, TGT_PASS) + */ + + // insert a stack adjustments (csa) pass early in compilation, + // before register allocation. + // This allows removing some extraneous moves in connection with pascal functions: + // pascal short bar(); pascal void foo(short); + // foo(bar()); + // + // subq #2, sp + // jsr bar + // move (sp), d0 ; <-- otherwise we end up with these two useless instructions + // move d0, (sp) ; <-- which are not removed if the register is already allocated + // ; <-- when csa figures out that no actual push or pop is needed + // jsr foo + + INSERT_PASS_AFTER (pass_combine, 1, pass_stack_adjustments); diff --git a/gcc/gcc/config/m68k/t-m68k b/gcc/gcc/config/m68k/t-m68k index 6213ced400..3d75d20264 100644 --- a/gcc/gcc/config/m68k/t-m68k +++ b/gcc/gcc/config/m68k/t-m68k @@ -9,3 +9,4 @@ m68k-mac-pragmas.o: $(srcdir)/config/m68k/m68k-mac-pragmas.c M68K_MLIB_CPU += && (CPU !~ "^m68060") && (CPU !~ "^cpu32") && (CPU !~ "^fidoa") +PASSES_EXTRA += $(srcdir)/config/m68k/m68k-passes.def