From 4a7644e0b55a764e1ad43bee5a0ef24c42af326a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 13 Jan 2018 20:02:43 -0600 Subject: [PATCH] Don't allocate stack space for varargs stack repair unless it's needed. If there are no varargs calls (and nothing else that saves stack positions), then space doesn't need to be allocated for the saved stack position. This can also lead to more efficient prolog/epilog code for small functions. --- CGI.pas | 1 + Expression.pas | 2 ++ Gen.pas | 2 +- Parser.pas | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CGI.pas b/CGI.pas index a243c67..262e671 100644 --- a/CGI.pas +++ b/CGI.pas @@ -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} {------------------------} diff --git a/Expression.pas b/Expression.pas index 84ca69d..1565443 100644 --- a/Expression.pas +++ b/Expression.pas @@ -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, diff --git a/Gen.pas b/Gen.pas index 0068af3..7e39220 100644 --- a/Gen.pas +++ b/Gen.pas @@ -5679,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; diff --git a/Parser.pas b/Parser.pas index 278e46a..cce68d6 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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