Hello,
It looks that I could finally figure out why the hell every type
conversion was done involving an intermediate temp.
This happened because node processing order was a bit incorrect.
See the attached patch. Since argument of firstpass is passed by
reference, freeing the old node before firstpassing the new one
actually causes the tree contain an invalid pointer for the duration of
firstpassing that new node.
In case of string type conversion, the typeconvn was replaced by a
calln, but that calln never optimized its return location because it
failed the test "if aktassignmentnode.right=self";
aktassignmentnode.right was still equal to the typeconvn.
The patch has great effect on generated code in general and on low-level
RTL stuff in particular.
Regards,
Sergei
Index: pass_1.pas
===================================================================
--- pass_1.pas (revision 13740)
+++ pass_1.pas (working copy)
@@ -83,10 +83,10 @@
begin
node_changed:=true;
p.free;
- { run typecheckpass }
- typecheckpass(hp);
{ switch to new node }
p:=hp;
+ { run typecheckpass }
+ typecheckpass(p);
end;
current_settings.localswitches:=oldlocalswitches;
current_filepos:=oldpos;
@@ -164,10 +164,10 @@
if assigned(hp) then
begin
p.free;
- { run typecheckpass }
- typecheckpass(hp);
{ switch to new node }
p:=hp;
+ { run typecheckpass }
+ typecheckpass(p);
end;
if codegenerror then
begin
@@ -186,10 +186,10 @@
if assigned(hp) then
begin
p.free;
+ { switch to new node }
+ p := hp;
{ run firstpass }
- firstpass(hp);
- { switch to new node }
- p:=hp;
+ firstpass(p);
end
else
begin
@@ -199,8 +199,8 @@
if assigned(hp) then
begin
p.free;
- firstpass(hp);
- p:=hp;
+ p := hp;
+ firstpass(p);
end;
end;
if codegenerror then
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel