Jelajahi Sumber

* SetExecutionWeight(): Set execution weight also for nodes with special handling. Minor code cleanup/improvements.
* Restore previous execution weight before exiting secondpass().
* It all improves register allocation for variables inside loops in some cases.

git-svn-id: trunk@40059 -

yury 6 tahun lalu
induk
melakukan
bf4eda478d
2 mengubah file dengan 11 tambahan dan 17 penghapusan
  1. 8 17
      compiler/optutils.pas
  2. 3 0
      compiler/pass_2.pas

+ 8 - 17
compiler/optutils.pas

@@ -364,41 +364,32 @@ unit optutils;
       begin
         Result:=fen_false;
         n.allocoptinfo;
-        Weight:=PAWord(arg)^;
+        Weight:=max(PAWord(arg)^,1);
         case n.nodetype of
           casen:
             begin
               CalcExecutionWeights(tcasenode(n).left,Weight);
               for i:=0 to tcasenode(n).blocks.count-1 do
-                CalcExecutionWeights(pcaseblock(tcasenode(n).blocks[i])^.statement,max(1,Weight div case_count_labels(tcasenode(n).labels)));
+                CalcExecutionWeights(pcaseblock(tcasenode(n).blocks[i])^.statement,Weight div case_count_labels(tcasenode(n).labels));
 
-              CalcExecutionWeights(tcasenode(n).elseblock,max(1,Weight div case_count_labels(tcasenode(n).labels)));
+              CalcExecutionWeights(tcasenode(n).elseblock,Weight div case_count_labels(tcasenode(n).labels));
               Result:=fen_norecurse_false;
             end;
           whilerepeatn:
             begin
-              CalcExecutionWeights(twhilerepeatnode(n).right,max(Weight,1)*8);
-              CalcExecutionWeights(twhilerepeatnode(n).left,max(Weight,1)*8);
+              CalcExecutionWeights(twhilerepeatnode(n).right,Weight*8);
+              CalcExecutionWeights(twhilerepeatnode(n).left,Weight*8);
               Result:=fen_norecurse_false;
             end;
           ifn:
             begin
               CalcExecutionWeights(tifnode(n).left,Weight);
-              CalcExecutionWeights(tifnode(n).right,max(Weight div 2,1));
-              CalcExecutionWeights(tifnode(n).t1,max(Weight div 2,1));
+              CalcExecutionWeights(tifnode(n).right,Weight div 2);
+              CalcExecutionWeights(tifnode(n).t1,Weight div 2);
               Result:=fen_norecurse_false;
             end;
-          else
-{$push}
-{ The code below emits two warnings if ptruint and aword are the same type }
-{$warn 4044 off}
-{$warn 6018 off}
-            if PAWord(arg)^ > high(aword) then
-              n.optinfo^.executionweight:=high(AWord)
-            else
-              n.optinfo^.executionweight:=PAWord(arg)^;
-{$pop}
         end;
+        n.optinfo^.executionweight:=Weight;
       end;
 
 

+ 3 - 0
compiler/pass_2.pas

@@ -180,6 +180,7 @@ implementation
          oldcodegenerror  : boolean;
          oldlocalswitches : tlocalswitches;
          oldpos    : tfileposinfo;
+         oldexecutionweight : longint;
       begin
          if not assigned(p) then
           internalerror(200208221);
@@ -191,6 +192,7 @@ implementation
             current_filepos:=p.fileinfo;
             current_settings.localswitches:=p.localswitches;
             codegenerror:=false;
+            oldexecutionweight:=cg.executionweight;
             if assigned(p.optinfo) then
               cg.executionweight:=min(p.optinfo^.executionweight,QWord(high(cg.executionweight)))
             else
@@ -227,6 +229,7 @@ implementation
             codegenerror:=codegenerror or oldcodegenerror;
             current_settings.localswitches:=oldlocalswitches;
             current_filepos:=oldpos;
+            cg.executionweight:=oldexecutionweight;
           end
          else
            codegenerror:=true;