* call firstpass before allocation and codegeneration is started

* move leftover code from pass_2.generatecode() to psub
This commit is contained in:
peter 2003-10-30 16:22:40 +00:00
parent 1953a4a4f2
commit 9e66b09843
4 changed files with 219 additions and 219 deletions

View File

@ -37,10 +37,6 @@ uses
allow_multi_pass2 : boolean; allow_multi_pass2 : boolean;
flowcontrol : tflowcontrol; flowcontrol : tflowcontrol;
{ produces assembler for the expression in variable p }
{ and produces an assembler node at the end }
procedure generatecode(var p : tnode);
{ produces the actual code } { produces the actual code }
function do_secondpass(var p : tnode) : boolean; function do_secondpass(var p : tnode) : boolean;
procedure secondpass(var p : tnode); procedure secondpass(var p : tnode);
@ -210,78 +206,15 @@ implementation
do_secondpass:=codegenerror; do_secondpass:=codegenerror;
end; end;
procedure clearrefs(p : tnamedindexitem;arg:pointer);
begin
if (tsym(p).typ=varsym) then
if tvarsym(p).refs>1 then
tvarsym(p).refs:=1;
end;
procedure generatecode(var p : tnode);
begin
flowcontrol:=[];
{ when size optimization only count occurrence }
if cs_littlesize in aktglobalswitches then
cg.t_times:=1
else
{ reference for repetition is 100 }
cg.t_times:=100;
{ clear register count }
symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
symtablestack.next.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
{ firstpass everything }
do_firstpass(p);
{ after pass 1, we should have all necessary information to set the temp. start location }
current_procinfo.set_first_temp_offset;
{ only do secondpass if there are no errors }
if ErrorCount=0 then
begin
{ caller paraloc info is also necessary in the stackframe_entry }
{ code of the ppc (and possibly other processors) }
if not current_procinfo.procdef.has_paraloc_info then
begin
paramanager.create_paraloc_info(current_procinfo.procdef,callerside);
current_procinfo.procdef.has_paraloc_info:=true;
end;
{ process register variable stuff (JM) }
{ assign_regvars(p);}
{ load_regvars(current_procinfo.aktentrycode,p);}
{ for the i386 it must be done in genexitcode because it has }
{ to add 'fstp' instructions when using fpu regvars and those }
{ must come after the "exitlabel" (JM) }
{$ifndef i386}
{ cleanup_regvars(current_procinfo.aktexitcode);}
{$endif i386}
{ current_procinfo.allocate_framepointer_reg;}
do_secondpass(p);
{$ifdef EXTDEBUG}
{
for sr:=first_int_imreg to last_int_imreg do
if not(sr in rg.unusedregsint) then
Comment(V_Warning,'Register '+std_regname(newreg(R_INTREGISTER,sr,R_SUBNONE))+' not released');
}
{$endif EXTDEBUG}
{$ifdef i386}
if assigned(current_procinfo.procdef) then
current_procinfo.procdef.fpu_used:=p.registersfpu;
{$endif i386}
end;
current_procinfo.aktproccode.concatlist(exprasmlist);
end;
end. end.
{ {
$Log$ $Log$
Revision 1.72 2003-10-19 01:34:30 florian Revision 1.73 2003-10-30 16:22:40 peter
* call firstpass before allocation and codegeneration is started
* move leftover code from pass_2.generatecode() to psub
Revision 1.72 2003/10/19 01:34:30 florian
* some ppc stuff fixed * some ppc stuff fixed
* memory leak fixed * memory leak fixed

View File

@ -566,6 +566,14 @@ implementation
end; end;
procedure clearrefs(p : tnamedindexitem;arg:pointer);
begin
if (tsym(p).typ=varsym) then
if tvarsym(p).refs>1 then
tvarsym(p).refs:=1;
end;
procedure tcgprocinfo.generate_code; procedure tcgprocinfo.generate_code;
var var
oldprocinfo : tprocinfo; oldprocinfo : tprocinfo;
@ -605,6 +613,24 @@ implementation
{ add parast/localst to symtablestack } { add parast/localst to symtablestack }
add_to_symtablestack; add_to_symtablestack;
{ when size optimization only count occurrence }
if cs_littlesize in aktglobalswitches then
cg.t_times:=1
else
{ reference for repetition is 100 }
cg.t_times:=100;
{ clear register count }
symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
symtablestack.next.foreach_static({$ifdef FPCPROCVAR}@{$endif}clearrefs,nil);
{ firstpass everything }
flowcontrol:=[];
do_firstpass(code);
{ only do secondpass if there are no errors }
if ErrorCount=0 then
begin
{ set the start offset to the start of the temp area in the stack } { set the start offset to the start of the temp area in the stack }
tg:=ttgobj.create; tg:=ttgobj.create;
@ -631,8 +657,20 @@ implementation
aktfilepos:=entrypos; aktfilepos:=entrypos;
gen_load_para_value(templist); gen_load_para_value(templist);
{ generate code for the body } { caller paraloc info is also necessary in the stackframe_entry
generatecode(code); code of the ppc (and possibly other processors) }
if not procdef.has_paraloc_info then
begin
paramanager.create_paraloc_info(procdef,callerside);
procdef.has_paraloc_info:=true;
end;
{ generate code for the node tree }
do_secondpass(code);
current_procinfo.aktproccode.concatlist(exprasmlist);
{$ifdef i386}
procdef.fpu_used:=code.registersfpu;
{$endif i386}
{ The position of the loadpara_asmnode is now known } { The position of the loadpara_asmnode is now known }
aktproccode.insertlistafter(loadpara_asmnode.currenttai,templist); aktproccode.insertlistafter(loadpara_asmnode.currenttai,templist);
@ -719,8 +757,6 @@ implementation
*) *)
end; end;
{$warning fixme translate_regvars}
{ translate_regvars(aktproccode,rg.colour);}
{ Add save and restore of used registers } { Add save and restore of used registers }
aktfilepos:=entrypos; aktfilepos:=entrypos;
gen_save_used_regs(templist); gen_save_used_regs(templist);
@ -767,6 +803,7 @@ implementation
tg.free; tg.free;
cg.done_register_allocators; cg.done_register_allocators;
tg:=nil; tg:=nil;
end;
{ restore symtablestack } { restore symtablestack }
remove_from_symtablestack; remove_from_symtablestack;
@ -1266,7 +1303,11 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.167 2003-10-24 17:40:23 peter Revision 1.168 2003-10-30 16:22:40 peter
* call firstpass before allocation and codegeneration is started
* move leftover code from pass_2.generatecode() to psub
Revision 1.167 2003/10/24 17:40:23 peter
* cleanup of the entry and exit code insertion * cleanup of the entry and exit code insertion
Revision 1.166 2003/10/21 15:14:33 peter Revision 1.166 2003/10/21 15:14:33 peter

View File

@ -235,6 +235,7 @@ unit rgobj;
procedure translate_registers(list:Taasmoutput); procedure translate_registers(list:Taasmoutput);
{# Adds an interference edge.} {# Adds an interference edge.}
procedure add_edge(u,v:Tsuperregister); procedure add_edge(u,v:Tsuperregister);
procedure check_unreleasedregs;
unusedregs : Tsuperregisterset; unusedregs : Tsuperregisterset;
@ -1801,10 +1802,29 @@ implementation
end; end;
end; end;
procedure Trgobj.check_unreleasedregs;
{$ifdef EXTDEBUG}
var
sr : tsuperregister;
{$endif EXTDEBUG}
begin
{$ifdef EXTDEBUG}
for sr:=first_imaginary to maxreg-1 do
if not(supregset_in(unusedregs,sr)) then
Comment(V_Warning,'Register '+std_regname(newreg(R_INTREGISTER,sr,R_SUBNONE))+' not released');
{$endif EXTDEBUG}
end;
end. end.
{ {
$Log$ $Log$
Revision 1.92 2003-10-29 21:29:14 jonas Revision 1.93 2003-10-30 16:22:40 peter
* call firstpass before allocation and codegeneration is started
* move leftover code from pass_2.generatecode() to psub
Revision 1.92 2003/10/29 21:29:14 jonas
* some ALLOWDUPREG improvements * some ALLOWDUPREG improvements
Revision 1.91 2003/10/21 15:15:36 peter Revision 1.91 2003/10/21 15:15:36 peter

View File

@ -310,9 +310,11 @@ unit cgx86;
begin begin
{ Int } { Int }
rgint.check_unreleasedregs;
rgint.do_register_allocation(list,headertai); rgint.do_register_allocation(list,headertai);
rgint.translate_registers(list); rgint.translate_registers(list);
{ SSE } { SSE }
rgmm.check_unreleasedregs;
rgmm.do_register_allocation(list,headertai); rgmm.do_register_allocation(list,headertai);
rgmm.translate_registers(list); rgmm.translate_registers(list);
end; end;
@ -1735,7 +1737,11 @@ unit cgx86;
end. end.
{ {
$Log$ $Log$
Revision 1.84 2003-10-29 21:24:14 jonas Revision 1.85 2003-10-30 16:22:40 peter
* call firstpass before allocation and codegeneration is started
* move leftover code from pass_2.generatecode() to psub
Revision 1.84 2003/10/29 21:24:14 jonas
+ support for fpu temp parameters + support for fpu temp parameters
+ saving/restoring of fpu register before/after a procedure call + saving/restoring of fpu register before/after a procedure call