Browse Source

Add debugging of changed nodes inside opttail unit with DEBUG_OPTTAIL

Pierre Muller 2 weeks ago
parent
commit
cafe1e3391
1 changed files with 42 additions and 1 deletions
  1. 42 1
      compiler/opttail.pas

+ 42 - 1
compiler/opttail.pas

@@ -244,16 +244,57 @@ unit opttail;
                  makes no sense
                  makes no sense
                }
                }
                is_managed_type(vardef) then
                is_managed_type(vardef) then
-               exit;
+              begin
+{$ifdef debug_opttail}
+        writeln('====================================================================================');
+        write('callnode: ',p.gettypename,' tail call opt disabled because parameter ',i,' ',realname,' ');
+        if is_managed_type(vardef) then
+          write('is managed ')
+        else if (varspez=vs_out) then
+          write('is out parameter');
+        writeln;
+        writeln('====================================================================================');
+{$endif debug_opttail}
+                exit;
+              end;
+
+{$ifdef fix_opttail}
+        { check if the local parameters should prevent tail recursion elimination }
+        for i:=0 to p.localst.count-1 do
+          with tabstractvarsym(p.localst[i]) do
+            if is_managed_type(vardef) then
+              begin
+{$ifdef debug_opttail}
+        writeln('====================================================================================');
+        writeln('callnode: ',p.gettypename,' tail call opt disabled because local ',i,' ',realname,' is managed');
+        writeln('====================================================================================');
+{$endif debug_opttail}
+                exit;
+              end;
+{$endif fix_opttail}
 
 
         labelsym:=clabelsym.create('$opttail');
         labelsym:=clabelsym.create('$opttail');
         labelnode:=clabelnode.create(cnothingnode.create,labelsym);
         labelnode:=clabelnode.create(cnothingnode.create,labelsym);
         if find_and_replace_tailcalls(n) then
         if find_and_replace_tailcalls(n) then
           begin
           begin
+{$ifdef debug_opttail}
+        writeln('====================================================================================');
+        writeln('Tail call optimization found:');
+        writeln('====================================================================================');
+        write('callnode: ',p.gettypename);
+        writeln('====================================================================================');
+{$endif debug_opttail}
             oldnodes:=n;
             oldnodes:=n;
             n:=internalstatements(s);
             n:=internalstatements(s);
             addstatement(s,labelnode);
             addstatement(s,labelnode);
             addstatement(s,oldnodes);
             addstatement(s,oldnodes);
+{$ifdef debug_opttail}
+        writeln('====================================================================================');
+        write('Tail call replaced by: ');
+        printnode(n);
+        writeln('====================================================================================');
+        writeln;
+{$endif debug_opttail}
           end
           end
         else
         else
           labelnode.free;
           labelnode.free;