attempt to improve code quality for pascal calls

This commit is contained in:
Wolfgang Thaller 2019-01-03 20:59:51 +01:00
parent 12485f7276
commit d520ee4311
4 changed files with 50 additions and 23 deletions

View File

@ -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));

View File

@ -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

View File

@ -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);

View File

@ -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