2
0
Эх сурвалжийг харах

* the temp. locations created by cse were not properly cleanup up, this patch fixes this

git-svn-id: trunk@38624 -
florian 7 жил өмнө
parent
commit
1497b64804

+ 7 - 1
compiler/nbas.pas

@@ -163,7 +163,13 @@ interface
          { the temp. needs no final sync instruction if it is located in a register,
          { the temp. needs no final sync instruction if it is located in a register,
            so there are no loops involved in the usage of the temp.
            so there are no loops involved in the usage of the temp.
          }
          }
-         ti_no_final_regsync
+         ti_no_final_regsync,
+         { this applied only to delete nodes: the single purpose of the temp. delete node is to clean up memory. In case
+           of cse it might happen that the tempcreate node is optimized away so tempinfo is never initialized properly but
+           the allocated memory must be disposed
+           If a temp. node has this flag set, the life time of the temp. data must be determined by reg. life, the temp.
+           location (in the sense of stack space/register) is never release }
+         ti_cleanup_only
          );
          );
        ttempinfoflags = set of ttempinfoflag;
        ttempinfoflags = set of ttempinfoflag;
 
 

+ 3 - 0
compiler/ncgbas.pas

@@ -589,6 +589,9 @@ interface
 
 
         location_reset(location,LOC_VOID,OS_NO);
         location_reset(location,LOC_VOID,OS_NO);
 
 
+        if ti_cleanup_only in tempflags then
+          exit;
+
         { see comments at ti_const declaration: if we initialised this temp with
         { see comments at ti_const declaration: if we initialised this temp with
           the value of another temp, that other temp was not freed because the
           the value of another temp, that other temp was not freed because the
           ti_const flag was set }
           ti_const flag was set }

+ 33 - 7
compiler/optcse.pas

@@ -284,6 +284,7 @@ unit optcse;
         nodes : tblocknode;
         nodes : tblocknode;
         creates,
         creates,
         statements : tstatementnode;
         statements : tstatementnode;
+        deletetemp : ttempdeletenode;
         hp : ttempcreatenode;
         hp : ttempcreatenode;
         addrstored : boolean;
         addrstored : boolean;
         hp2 : tnode;
         hp2 : tnode;
@@ -414,6 +415,12 @@ unit optcse;
                         tnode(templist[i]).fileinfo:=tnode(lists.nodelist[i]).fileinfo;
                         tnode(templist[i]).fileinfo:=tnode(lists.nodelist[i]).fileinfo;
 
 
                         addstatement(creates,tnode(templist[i]));
                         addstatement(creates,tnode(templist[i]));
+
+                        { the delete node has no semantic use yet, it is just used to clean up memory }
+                        deletetemp:=ctempdeletenode.create(ttempcreatenode(templist[i]));
+                        deletetemp.includetempflag(ti_cleanup_only);
+                        addstatement(tstatementnode(arg^),deletetemp);
+
                         { make debugging easier and set temp. location to the original location }
                         { make debugging easier and set temp. location to the original location }
                         creates.fileinfo:=tnode(lists.nodelist[i]).fileinfo;
                         creates.fileinfo:=tnode(lists.nodelist[i]).fileinfo;
 
 
@@ -505,16 +512,35 @@ unit optcse;
 
 
 
 
     function do_optcse(var rootnode : tnode) : tnode;
     function do_optcse(var rootnode : tnode) : tnode;
+      var
+        deletes,
+        statements : tstatementnode;
+        deleteblock,
+        rootblock : tblocknode;
       begin
       begin
 {$ifdef csedebug}
 {$ifdef csedebug}
-         writeln('====================================================================================');
-         writeln('CSE optimization pass started');
-         writeln('====================================================================================');
-         printnode(rootnode);
-         writeln('====================================================================================');
-         writeln;
+        writeln('====================================================================================');
+        writeln('CSE optimization pass started');
+        writeln('====================================================================================');
+        printnode(rootnode);
+        writeln('====================================================================================');
+        writeln;
+{$endif csedebug}
+        deleteblock:=internalstatements(deletes);
+        foreachnodestatic(pm_postprocess,rootnode,@searchcsedomain,@deletes);
+        rootblock:=internalstatements(statements);
+        addstatement(statements,rootnode);
+        addstatement(statements,deleteblock);
+        rootnode:=rootblock;
+        do_firstpass(rootnode);
+{$ifdef csedebug}
+        writeln('====================================================================================');
+        writeln('CSE optimization result');
+        writeln('====================================================================================');
+        printnode(rootnode);
+        writeln('====================================================================================');
+        writeln;
 {$endif csedebug}
 {$endif csedebug}
-        foreachnodestatic(pm_postprocess,rootnode,@searchcsedomain,nil);
         result:=nil;
         result:=nil;
       end;
       end;
 
 

+ 0 - 3
compiler/psub.pas

@@ -31,9 +31,6 @@ interface
       symdef,procinfo,optdfa;
       symdef,procinfo,optdfa;
 
 
     type
     type
-
-      { tcgprocinfo }
-
       tcgprocinfo = class(tprocinfo)
       tcgprocinfo = class(tprocinfo)
       private
       private
         procedure CreateInlineInfo;
         procedure CreateInlineInfo;