Generate more efficient stack repair code (2).

Previously, the stack repair code always generated code to save and restore a register, but this can be omitted except in cases where a 32-bit value or pointer is returned.
This commit is contained in:
Stephen Heumann 2018-01-12 22:32:12 -06:00
parent b697094c58
commit f24f37aa9f

20
Gen.pas
View File

@ -4081,10 +4081,12 @@ procedure GenTree {op: icptr};
end {if} end {if}
else if saveStack or (op^.q <> 0) then begin else if saveStack or (op^.q <> 0) then begin
stackSaveDepth := stackSaveDepth - 1; stackSaveDepth := stackSaveDepth - 1;
GenImplied(m_txy); if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_txy);
GenNative(m_ldx_dir, direct, stackLoc, nil, 0); GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_txs); GenImplied(m_txs);
GenImplied(m_tyx); if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_tyx);
if stackSaveDepth <> 0 then begin if stackSaveDepth <> 0 then begin
GenImplied(m_ply); GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0); GenNative(m_sty_dir, direct, stackLoc, nil, 0);
@ -4137,14 +4139,16 @@ procedure GenTree {op: icptr};
end {if} end {if}
else if saveStack or (op^.q <> 0) then begin else if saveStack or (op^.q <> 0) then begin
stackSaveDepth := stackSaveDepth - 1; stackSaveDepth := stackSaveDepth - 1;
GenImplied(m_tay); if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenNative(m_lda_dir, direct, stackLoc, nil, 0); GenImplied(m_txy);
GenImplied(m_tcs); GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_txs);
if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_tyx);
if stackSaveDepth <> 0 then begin if stackSaveDepth <> 0 then begin
GenImplied(m_pla); GenImplied(m_ply);
GenNative(m_sta_dir, direct, stackLoc, nil, 0); GenNative(m_sty_dir, direct, stackLoc, nil, 0);
end; {if} end; {if}
GenImplied(m_tya);
end; {else} end; {else}
{save the returned value} {save the returned value}