瀏覽代碼

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

git-svn-id: trunk@38624 -
florian 7 年之前
父節點
當前提交
1497b64804
共有 4 個文件被更改,包括 43 次插入11 次删除
  1. 7 1
      compiler/nbas.pas
  2. 3 0
      compiler/ncgbas.pas
  3. 33 7
      compiler/optcse.pas
  4. 0 3
      compiler/psub.pas

+ 7 - 1
compiler/nbas.pas

@@ -163,7 +163,13 @@ interface
          { 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.
          }
-         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;
 

+ 3 - 0
compiler/ncgbas.pas

@@ -589,6 +589,9 @@ interface
 
         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
           the value of another temp, that other temp was not freed because the
           ti_const flag was set }

+ 33 - 7
compiler/optcse.pas

@@ -284,6 +284,7 @@ unit optcse;
         nodes : tblocknode;
         creates,
         statements : tstatementnode;
+        deletetemp : ttempdeletenode;
         hp : ttempcreatenode;
         addrstored : boolean;
         hp2 : tnode;
@@ -414,6 +415,12 @@ unit optcse;
                         tnode(templist[i]).fileinfo:=tnode(lists.nodelist[i]).fileinfo;
 
                         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 }
                         creates.fileinfo:=tnode(lists.nodelist[i]).fileinfo;
 
@@ -505,16 +512,35 @@ unit optcse;
 
 
     function do_optcse(var rootnode : tnode) : tnode;
+      var
+        deletes,
+        statements : tstatementnode;
+        deleteblock,
+        rootblock : tblocknode;
       begin
 {$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}
-        foreachnodestatic(pm_postprocess,rootnode,@searchcsedomain,nil);
         result:=nil;
       end;
 

+ 0 - 3
compiler/psub.pas

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