* Xtensa: various stack handling fixes

git-svn-id: trunk@46732 -
This commit is contained in:
florian 2020-08-29 20:24:32 +00:00
parent 2c00016fdd
commit 867ed59459
2 changed files with 41 additions and 21 deletions

View File

@ -699,21 +699,20 @@ implementation
begin begin
if stack_parameters and (pi_estimatestacksize in current_procinfo.flags) then if stack_parameters and (pi_estimatestacksize in current_procinfo.flags) then
begin begin
list.concat(tai_comment.Create(strpnew('Stackframe size was estimated before code generation due to stack parameters')));
list.concat(tai_comment.Create(strpnew(' Calculated stackframe size: '+tostr(txtensaprocinfo(current_procinfo).stackframesize))));
list.concat(tai_comment.Create(strpnew(' Max. outgoing parameter size: '+tostr(txtensaprocinfo(current_procinfo).maxpushedparasize))));
list.concat(tai_comment.Create(strpnew(' End of last temporary location: '+tostr(tg.lasttemp))));
list.concat(tai_comment.Create(strpnew(' Max. window rotation in bytes: '+tostr(txtensaprocinfo(current_procinfo).maxcall*4))));
{ should never happen as localsize is derived from
txtensaprocinfo(current_procinfo).stackframesize }
if localsize>txtensaprocinfo(current_procinfo).stackframesize then if localsize>txtensaprocinfo(current_procinfo).stackframesize then
internalerror(2020031402) internalerror(2020031402);
else localsize:=txtensaprocinfo(current_procinfo).stackframesize;
localsize:=txtensaprocinfo(current_procinfo).stackframesize-registerarea;
end end
else else
begin localsize:=align(localsize,current_settings.alignment.localalignmax);
{ default spill area }
inc(localsize,4*4);
{ additional spill area? }
if pi_do_call in current_procinfo.flags then
inc(localsize,txtensaprocinfo(current_procinfo).maxcall*4);
localsize:=align(localsize,current_settings.alignment.localalignmax);
end;
if localsize>32760 then if localsize>32760 then
begin begin

View File

@ -56,6 +56,7 @@ unit cpupi;
uses uses
globals,systems, globals,systems,
verbose,
tgobj, tgobj,
symconst,symtype,symsym,symcpu,paramgr, symconst,symtype,symsym,symcpu,paramgr,
cgutils, cgutils,
@ -102,25 +103,36 @@ unit cpupi;
{ estimate stack frame size } { estimate stack frame size }
if pi_estimatestacksize in flags then if pi_estimatestacksize in flags then
begin begin
stackframesize:=maxpushedparasize; stackframesize:=align(maxpushedparasize,target_info.alignment.localalignmax);
localsize:=0; localsize:=0;
for i:=0 to procdef.localst.SymList.Count-1 do for i:=0 to procdef.localst.SymList.Count-1 do
if tsym(procdef.localst.SymList[i]).typ=localvarsym then if tsym(procdef.localst.SymList[i]).typ=localvarsym then
inc(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).getsize); begin
localsize:=align(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).vardef.alignment);
inc(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).getsize);
end;
inc(stackframesize,localsize); inc(stackframesize,localsize);
stackframesize:=align(stackframesize,target_info.alignment.localalignmax);
localsize:=0; localsize:=0;
for i:=0 to procdef.parast.SymList.Count-1 do for i:=0 to procdef.parast.SymList.Count-1 do
if tsym(procdef.parast.SymList[i]).typ=paravarsym then if tsym(procdef.parast.SymList[i]).typ=paravarsym then
begin begin
if tabstractnormalvarsym(procdef.parast.SymList[i]).varspez in [vs_var,vs_out,vs_constref] then if tabstractnormalvarsym(procdef.parast.SymList[i]).varspez in [vs_var,vs_out,vs_constref] then
inc(localsize,4) begin
localsize:=align(localsize,4);
inc(localsize,4)
end
else if is_open_string(tabstractnormalvarsym(procdef.parast.SymList[i]).vardef) then else if is_open_string(tabstractnormalvarsym(procdef.parast.SymList[i]).vardef) then
inc(localsize,256) inc(localsize,256)
else else
inc(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).getsize); begin
localsize:=align(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).vardef.alignment);
inc(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).getsize);
end;
end; end;
inc(stackframesize,localsize); inc(stackframesize,localsize);
stackframesize:=align(stackframesize,4);
if pi_needs_implicit_finally in flags then if pi_needs_implicit_finally in flags then
inc(stackframesize,40); inc(stackframesize,40);
@ -131,6 +143,13 @@ unit cpupi;
if procdef.proctypeoption in [potype_constructor] then if procdef.proctypeoption in [potype_constructor] then
inc(stackframesize,40*2); inc(stackframesize,40*2);
{ default spill area }
inc(stackframesize,4*4);
{ additional spill area? }
if pi_do_call in current_procinfo.flags then
inc(stackframesize,maxcall*4);
inc(stackframesize,estimatedtempsize); inc(stackframesize,estimatedtempsize);
stackframesize:=Align(stackframesize,target_info.alignment.localalignmax); stackframesize:=Align(stackframesize,target_info.alignment.localalignmax);
@ -143,13 +162,15 @@ unit cpupi;
r : byte; r : byte;
regs: tcpuregisterset; regs: tcpuregisterset;
begin begin
maxpushedparasize:=align(maxpushedparasize,max(current_settings.alignment.localalignmin,4));
if pi_estimatestacksize in flags then if pi_estimatestacksize in flags then
result:=stackframesize
else
begin begin
maxpushedparasize:=align(maxpushedparasize,max(current_settings.alignment.localalignmin,4)); if Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+4*4+maxcall*4>stackframesize then
result:=Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+maxpushedparasize; InternalError(2020082801);
end; result:=stackframesize
end
else
result:=Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+maxpushedparasize;
end; end;