From cde0d7d08450e2ee313d3ca5ab0ab8ca2cdce99a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 8 Apr 2000 16:22:11 +0000 Subject: [PATCH] * fixed concat_string optimization and enabled it when -dnewoptimizations is used --- compiler/tcld.pas | 20 ++++++++++++++------ compiler/tree.pas | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/compiler/tcld.pas b/compiler/tcld.pas index 6378bae802..8a49894a70 100644 --- a/compiler/tcld.pas +++ b/compiler/tcld.pas @@ -201,10 +201,10 @@ implementation *****************************************************************************} procedure firstassignment(var p : ptree); -{$ifdef dummyi386} +{$ifdef newoptimizations} var hp : ptree; -{$endif} +{$endif newoptimizations} begin { must be made unique } set_unique(p^.left); @@ -273,8 +273,11 @@ implementation { the problem is for s:=s+s+s; this is broken here !! } - { while hp^.treetype=addn do hp:=hp^.left; - if equal_trees(p^.left,hp) then +{$ifdef newoptimizations} + hp := p^.right; + while hp^.treetype=addn do hp:=hp^.left; + if equal_trees(p^.left,hp) and + not multiple_uses(p^.left,p^.right) then begin p^.concat_string:=true; hp:=p^.right; @@ -283,7 +286,8 @@ implementation hp^.use_strconcat:=true; hp:=hp^.left; end; - end; } + end; +{$endif newoptimizations} end else begin @@ -486,7 +490,11 @@ implementation end. { $Log$ - Revision 1.61 2000-02-24 18:41:39 peter + Revision 1.62 2000-04-08 16:22:11 jonas + * fixed concat_string optimization and enabled it when + -dnewoptimizations is used + + Revision 1.61 2000/02/24 18:41:39 peter * removed warnings/notes Revision 1.60 2000/02/17 14:53:43 florian diff --git a/compiler/tree.pas b/compiler/tree.pas index 15a2fb2ecf..1505e21634 100644 --- a/compiler/tree.pas +++ b/compiler/tree.pas @@ -307,6 +307,10 @@ unit tree; function getcopy(p : ptree) : ptree; function equal_trees(t1,t2 : ptree) : boolean; +{$ifdef newoptimizations} + { checks if t1 is loaded more than once in t2 and its sub-trees } + function multiple_uses(t1,t2: ptree): boolean; +{$endif newoptimizations} procedure swaptree(p:Ptree); procedure disposetree(p : ptree); @@ -1731,6 +1735,26 @@ unit tree; equal_trees:=false; end; +{$ifdef newoptimizations} + function multiple_uses(t1,t2: ptree): boolean; + var nr: longint; + + procedure check_tree(t: ptree); + begin + inc(nr,ord(equal_trees(t1,t))); + if (nr < 2) and assigned(t^.left) then + check_tree(t^.left); + if (nr < 2) and assigned(t^.right) then + check_tree(t^.right); + end; + + begin + nr := 0; + check_tree(t2); + multiple_uses := nr > 1; + end; +{$endif newoptimizations} + procedure set_unique(p : ptree); begin @@ -2066,7 +2090,11 @@ unit tree; end. { $Log$ - Revision 1.116 2000-03-01 15:36:12 florian + Revision 1.117 2000-04-08 16:22:11 jonas + * fixed concat_string optimization and enabled it when + -dnewoptimizations is used + + Revision 1.116 2000/03/01 15:36:12 florian * some new stuff for the new cg Revision 1.115 2000/03/01 11:43:55 daniel