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.