Просмотр исходного кода

+ CalcUseSum: calculates a sum of all use sets of the current node and its children

git-svn-id: trunk@43904 -
florian 5 лет назад
Родитель
Сommit
b5659df425
2 измененных файлов с 32 добавлено и 0 удалено
  1. 3 0
      compiler/optbase.pas
  2. 29 0
      compiler/optutils.pas

+ 3 - 0
compiler/optbase.pas

@@ -41,7 +41,10 @@ unit optbase;
         def : tdfaset;
         use : tdfaset;
         life : tdfaset;
+        { all definitions made by this node and its children }
         defsum : tdfaset;
+        { all used nodes by this node and its children }
+        usesum : tdfaset;
         avail : tdfaset;
         { estimation, how often the node is executed per subroutine call times 100, calculated by optutils.CalcExecutionWeight }
         executionweight : longint;

+ 29 - 0
compiler/optutils.pas

@@ -42,6 +42,7 @@ unit optutils;
     procedure SetNodeSucessors(p,last : tnode);
     procedure PrintDFAInfo(var f : text;p : tnode);
     procedure PrintIndexedNodeSet(var f : text;s : TIndexedNodeSet);
+
     { determines the optinfo.defsum field for the given node
       this field contains a sum of all expressions defined by
       all child expressions reachable through p
@@ -51,6 +52,12 @@ unit optutils;
     { calculates/estimates the field execution weight of optinfo }
     procedure CalcExecutionWeights(p : tnode;Initial : longint = 100);
 
+    { determines the optinfo.defsum field for the given node
+      this field contains a sum of all expressions defined by
+      all child expressions reachable through p
+    }
+    procedure CalcUseSum(p : tnode);
+
     { returns true, if n is a valid node and has life info }
     function has_life_info(n : tnode) : boolean;
 
@@ -357,6 +364,8 @@ unit optutils;
           end;
       end;
 
+    var
+      usesum : TDFASet;
 
     function SetExecutionWeight(var n: tnode; arg: pointer): foreachnoderesult;
       var
@@ -404,6 +413,26 @@ unit optutils;
       end;
 
 
+    function adduse(var n: tnode; arg: pointer): foreachnoderesult;
+      begin
+        if assigned(n.optinfo) then
+          DFASetIncludeSet(usesum,n.optinfo^.use);
+        Result:=fen_false;
+      end;
+
+
+    procedure CalcUseSum(p : tnode);
+      begin
+        p.allocoptinfo;
+        if not assigned(p.optinfo^.usesum) then
+          begin
+            usesum:=nil;
+            foreachnodestatic(pm_postprocess,p,@adduse,nil);
+            p.optinfo^.usesum:=usesum;
+          end;
+      end;
+
+
     function has_life_info(n : tnode) : boolean;
       begin
         result:=assigned(n) and assigned(n.optinfo) and