Merge branch 'stack-repair-opt'

This commit is contained in:
Stephen Heumann 2018-03-04 16:09:08 -06:00
commit 28fa8b1853
6 changed files with 50 additions and 22 deletions

View File

@ -329,6 +329,7 @@ var
symLength: integer; {length of debug symbol table}
toolParms: boolean; {generate tool format paramaters?}
volatile: boolean; {has a volatile qualifier been used?}
hasVarargsCall: boolean; {does current function call any varargs fns?}
{desk accessory variables}
{------------------------}

View File

@ -2781,6 +2781,8 @@ var
Gen1tName(pc_cup, ord(fType^.varargs and strictVararg),
UsualUnaryConversions, fname);
end; {else}
if fType^.varargs then
hasVarargsCall := true;
end {if}
else
GenTool(pc_tl1, ftype^.toolNum, long(ftype^.ftype^.size).lsw,

64
Gen.pas
View File

@ -66,6 +66,7 @@ var
gLong: longType; {info about last long value}
namePushed: boolean; {has a name been pushed in this proc?}
skipLoad: boolean; {skip load for a pc_lli, etc?}
stackSaveDepth: integer; {nesting depth of saved stack positions}
{stack frame locations}
{---------------------}
@ -4026,13 +4027,16 @@ procedure GenTree {op: icptr};
lab1: integer; {return point}
lLong: longType; {used to reserve gLong}
begin {GenCup}
begin {GenCui}
{save the stack register}
if saveStack or checkStack or (op^.q <> 0) then begin
GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_phx);
if stackSaveDepth <> 0 then begin
GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_phx);
end; {if}
GenImplied(m_tsx);
GenNative(m_stx_dir, direct, stackLoc, nil, 0);
stackSaveDepth := stackSaveDepth + 1;
end; {if}
{generate parameters}
@ -4067,18 +4071,26 @@ procedure GenTree {op: icptr};
if checkStack then begin
{check the stack for errors}
stackSaveDepth := stackSaveDepth - 1;
GenNative(m_ldy_dir, direct, stackLoc, nil, 0);
GenCall(76);
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
if stackSaveDepth <> 0 then begin
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
end; {if}
end {if}
else if saveStack or (op^.q <> 0) then begin
GenImplied(m_txy);
stackSaveDepth := stackSaveDepth - 1;
if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_txy);
GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_txs);
GenImplied(m_tyx);
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_tyx);
if stackSaveDepth <> 0 then begin
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
end; {if}
end; {else}
{save the returned value}
@ -4097,10 +4109,13 @@ procedure GenTree {op: icptr};
begin {GenCup}
{save the stack register}
if saveStack or checkStack or (op^.q <> 0) then begin
GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_phx);
if stackSaveDepth <> 0 then begin
GenNative(m_ldx_dir, direct, stackLoc, nil, 0);
GenImplied(m_phx);
end; {if}
GenImplied(m_tsx);
GenNative(m_stx_dir, direct, stackLoc, nil, 0);
stackSaveDepth := stackSaveDepth + 1;
end; {if}
{generate parameters}
@ -4113,19 +4128,27 @@ procedure GenTree {op: icptr};
{check the stack for errors}
if checkStack then begin
stackSaveDepth := stackSaveDepth - 1;
GenNative(m_ldy_dir, direct, stackLoc, nil, 0);
GenCall(76);
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
if stackSaveDepth <> 0 then begin
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
end; {if}
GenImplied(m_tay);
end {if}
else if saveStack or (op^.q <> 0) then begin
GenImplied(m_tay);
GenNative(m_lda_dir, direct, stackLoc, nil, 0);
GenImplied(m_tcs);
GenImplied(m_pla);
GenNative(m_sta_dir, direct, stackLoc, nil, 0);
GenImplied(m_tya);
stackSaveDepth := stackSaveDepth - 1;
if not (op^.optype in [cgVoid,cgByte,cgUByte,cgWord,cgUWord]) then
GenImplied(m_txy);
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
GenImplied(m_ply);
GenNative(m_sty_dir, direct, stackLoc, nil, 0);
end; {if}
end; {else}
{save the returned value}
@ -5647,6 +5670,7 @@ parameterSize := 0;
funLoc := 0;
dworkLoc := 0;
minSize := 1;
stackSaveDepth := 0;
while bk <> nil do begin
op := bk^.code;
while op <> nil do begin
@ -5655,7 +5679,7 @@ while bk <> nil do begin
end; {while}
bk := bk^.next;
end; {while}
if saveStack or checkStack or strictVararg then begin
if saveStack or checkStack or (strictVararg and hasVarargsCall) then begin
stackLoc := minSize;
minSize := minSize + 2;
localSize := localSize + 2;

View File

@ -1762,7 +1762,7 @@ var
begin {GenNative}
{ writeln('GenNative: ',p_opcode:4, ', mode=', ord(p_mode):1,
' operand=', p_operand:1); {debug}
if npeephole then begin
if npeephole and not (strictVararg and hasVarargsCall) then begin
if (nnextspot = 1) and not (p_opcode in nleadOpcodes) then begin
if p_opcode <> d_end then
if registers then

View File

@ -3474,6 +3474,7 @@ if isFunction then begin
else
Gen2Name (dc_str, segType, 0, variable^.name);
doingMain := variable^.name^ = 'main';
hasVarargsCall := false;
firstCompoundStatement := true;
Gen0 (dc_pin);
if not isAsm then

View File

@ -2703,7 +2703,7 @@ if ch in ['a','d','e','i','l','p','u','w'] then begin
commonSubexpression := odd(val >> 4);
loopOptimizations := odd(val >> 5);
strictVararg := not odd(val >> 6);
if saveStack or strictVararg then
if saveStack then
npeepHole := false;
if token.kind <> eolsy then
Error(11);