fpc/compiler/optcse.pas
florian 7cd67ea3f0 * node optimizer branch merged
* gotonode and gotolabel refactored
  * -Nu added to enable for loop unrolling

git-svn-id: trunk@446 -
2005-06-19 17:42:10 +00:00

57 lines
1.9 KiB
ObjectPascal

unit optcse;
interface
procedure docse(rootnode : tnode);
implementation
procedure docse(rootnode : tnode);
begin
{ create a linear list of nodes }
{ create hash values }
{ sort by hash values, taking care of nf_csebarrier and keeping the
original order of the nodes }
{ compare nodes with equal hash values }
{ search barrier }
for i:=0 to nodelist.length-1 do
begin
{ and then search backward so we get always the largest equal trees }
j:=i+1;
{ collect equal nodes }
while (j<=nodelist.length-1) and
nodelist[i].docompare(nodelist[j]) do
inc(j);
dec(j);
if j>i then
begin
{ cse found }
{ create temp. location }
{ replace first node by
- temp. creation
- expression calculation
- assignment of expression to temp. }
tempnode:=ctempcreatenode.create(nodelist[i].resulttype,nodelist[i].resulttype.def.size,tt_persistent,
nodelist[i].resulttype.def.is_intregable or nodelist[i].resulttype.def.is_fpuregable);
addstatement(createstatement,tempnode);
addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
caddrnode.create_internal(para.left)));
para.left := ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),para.left.resulttype);
addstatement(deletestatement,ctempdeletenode.create(tempnode));
{ replace next nodes by loading the temp. reference }
{ replace last node by loading the temp. reference and
delete the temp. }
end;
end;
end;
end.