浏览代码

+ Notification implementation complete
+ Add for loop code optimization using notifications
results in 1.5-1.9% speed improvement in nestloop benchmark
Optimization incomplete, compiler does not cycle yet with
notifications enabled.

daniel 22 年之前
父节点
当前提交
158e9689d7
共有 5 个文件被更改,包括 136 次插入37 次删除
  1. 64 22
      compiler/ncgflw.pas
  2. 16 4
      compiler/nflw.pas
  3. 8 2
      compiler/nld.pas
  4. 9 2
      compiler/symnot.pas
  5. 39 7
      compiler/symsym.pas

+ 64 - 22
compiler/ncgflw.pas

@@ -379,24 +379,35 @@ implementation
                    t2.location,aktbreaklabel);
                end;
            end;
-
-         if lnf_backward in loopflags then
-           hop:=OP_ADD
-         else
-           hop:=OP_SUB;
-         cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
+           
+         {If the loopvar doesn't mind on exit, we avoid this ugly
+          dec instruction and do the loopvar inc/dec after the loop
+          body.}
+         if not(lnf_dont_mind_loopvar_on_exit in loopflags) then
+            begin
+              if lnf_backward in loopflags then
+                hop:=OP_ADD
+              else
+                hop:=OP_SUB;
+              cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
+            end;
 
          if not(cs_littlesize in aktglobalswitches) then
             { align loop target }
             exprasmList.concat(Tai_align.Create(aktalignment.loopalign));
          cg.a_label(exprasmlist,l3);
 
-         { according to count direction DEC or INC... }
-         if lnf_backward in loopflags then
-           hop:=OP_SUB
-         else
-           hop:=OP_ADD;
-         cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
+         {If the loopvar doesn't mind on exit, we avoid the loopvar inc/dec
+          after the loop body instead of here.}
+         if not(lnf_dont_mind_loopvar_on_exit in loopflags) then
+            begin
+              { according to count direction DEC or INC... }
+              if lnf_backward in loopflags then
+                hop:=OP_SUB
+              else
+                hop:=OP_ADD;
+              cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
+            end;
 
          { help register must not be in instruction block }
          rg.cleartempgen;
@@ -406,21 +417,45 @@ implementation
              load_all_regvars(exprasmlist);
            end;
 
+         {If the loopvar doesn't mind on exit, we do the loopvar inc/dec
+          after the loop body instead of here.}
+         if lnf_dont_mind_loopvar_on_exit in loopflags then
+            begin
+              { according to count direction DEC or INC... }
+              if lnf_backward in loopflags then
+                hop:=OP_SUB
+              else
+                hop:=OP_ADD;
+              cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
+            end;
+
          cg.a_label(exprasmlist,aktcontinuelabel);
 
          { makes no problems there }
          rg.cleartempgen;
 
-         if lnf_backward in loopflags then
-           if count_var_is_signed then
-             hcond:=OC_GT
-           else
-             hcond:=OC_A
-          else
-            if count_var_is_signed then
-              hcond:=OC_LT
+         if lnf_dont_mind_loopvar_on_exit in loopflags then
+           if lnf_backward in loopflags then
+             if count_var_is_signed then
+               hcond:=OC_GTE
+             else
+               hcond:=OC_AE
             else
-              hcond:=OC_B;
+              if count_var_is_signed then
+                hcond:=OC_LTE
+              else
+                hcond:=OC_BE
+         else
+           if lnf_backward in loopflags then
+             if count_var_is_signed then
+               hcond:=OC_GT
+             else
+               hcond:=OC_A
+            else
+              if count_var_is_signed then
+                hcond:=OC_LT
+              else
+                hcond:=OC_B;
          load_all_regvars(exprasmlist);
 
          { produce comparison and the corresponding }
@@ -1247,7 +1282,14 @@ begin
 end.
 {
   $Log$
-  Revision 1.45  2002-11-28 11:17:01  florian
+  Revision 1.46  2002-12-31 09:55:58  daniel
+   + Notification implementation complete
+   + Add for loop code optimization using notifications
+     results in 1.5-1.9% speed improvement in nestloop benchmark
+     Optimization incomplete, compiler does not cycle yet with
+     notifications enabled.
+
+  Revision 1.45  2002/11/28 11:17:01  florian
     * loop node flags from node flags splitted
 
   Revision 1.44  2002/11/25 17:43:17  peter

+ 16 - 4
compiler/nflw.pas

@@ -668,11 +668,14 @@ implementation
        had in the last iteration.}
       if not_type=vn_onwrite then
         begin
-          include(loopflags,lnf_dont_mind_loopvar_on_exit);
-        writeln('Loopvar does not matter on exit');
+          writeln('Loopvar does not matter on exit');
         end
       else
-        writeln('Loopvar does matter on exit');
+        begin
+          exclude(loopflags,lnf_dont_mind_loopvar_on_exit);
+          writeln('Loopvar does matter on exit');
+        end;
+      Tvarsym(symbol).unregister_notification(loopvar_notid);
     end;
 {$endif}
 
@@ -756,6 +759,7 @@ implementation
          inserttypeconv(right,t2.resulttype);
 (*
       {$ifdef var_notification}
+         include(loopflags,lnf_dont_mind_loopvar_on_exit);
          if (hp.nodetype=loadn) and (Tloadnode(hp).symtableentry.typ=varsym) then
             loopvar_notid:=Tvarsym(Tloadnode(hp).symtableentry).
              register_notification([vn_onread,vn_onwrite],@loop_var_access);
@@ -817,6 +821,7 @@ implementation
          firstpass(right);
       {$ifdef var_notification}
          { Check count var, record fields are also allowed in tp7 }
+         include(loopflags,lnf_dont_mind_loopvar_on_exit);
          hp:=t2;
          while (hp.nodetype=subscriptn) or
                ((hp.nodetype=vecn) and
@@ -1463,7 +1468,14 @@ begin
 end.
 {
   $Log$
-  Revision 1.59  2002-12-30 22:44:53  daniel
+  Revision 1.60  2002-12-31 09:55:58  daniel
+   + Notification implementation complete
+   + Add for loop code optimization using notifications
+     results in 1.5-1.9% speed improvement in nestloop benchmark
+     Optimization incomplete, compiler does not cycle yet with
+     notifications enabled.
+
+  Revision 1.59  2002/12/30 22:44:53  daniel
   * Some work on notifications
 
   Revision 1.58  2002/12/27 15:25:40  peter

+ 8 - 2
compiler/nld.pas

@@ -435,7 +435,6 @@ implementation
 
     begin
       include(flags,nf_write);
-      writeln('Mark ',symtableentry.name);
     end;
 {$endif}
 
@@ -1298,7 +1297,14 @@ begin
 end.
 {
   $Log$
-  Revision 1.76  2002-12-30 22:44:53  daniel
+  Revision 1.77  2002-12-31 09:55:58  daniel
+   + Notification implementation complete
+   + Add for loop code optimization using notifications
+     results in 1.5-1.9% speed improvement in nestloop benchmark
+     Optimization incomplete, compiler does not cycle yet with
+     notifications enabled.
+
+  Revision 1.76  2002/12/30 22:44:53  daniel
   * Some work on notifications
 
   Revision 1.75  2002/12/27 15:27:25  peter

+ 9 - 2
compiler/symnot.pas

@@ -30,7 +30,7 @@ interface
 
 uses  cclasses,symbase,symtype;
 
-type  Tnotification_flag=(vn_onread,vn_onwrite);
+type  Tnotification_flag=(vn_onread,vn_onwrite,vn_unknown);
       Tnotification_flags=set of Tnotification_flag;
 
       Tnotification_callback=procedure(not_type:Tnotification_flag;
@@ -65,7 +65,14 @@ end.
 
 {
   $Log$
-  Revision 1.1  2002-09-01 08:04:42  daniel
+  Revision 1.2  2002-12-31 09:55:58  daniel
+   + Notification implementation complete
+   + Add for loop code optimization using notifications
+     results in 1.5-1.9% speed improvement in nestloop benchmark
+     Optimization incomplete, compiler does not cycle yet with
+     notifications enabled.
+
+  Revision 1.1  2002/09/01 08:04:42  daniel
    + Added read/write notifications of variables. These will be usefull
      for providing information for several optimizations. For example
      the value of the loop variable of a for loop does matter is the

+ 39 - 7
compiler/symsym.pas

@@ -198,6 +198,7 @@ interface
           procedure trigger_notifications(what:Tnotification_flag);
           function register_notification(flags:Tnotification_flags;
                                          callback:Tnotification_callback):cardinal;
+          procedure unregister_notification(id:cardinal);
 {$endif}
 {$ifdef GDB}
           function  stabstring : pchar;override;
@@ -1716,17 +1717,17 @@ implementation
 {$ifdef var_notification}
     procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
     
-    var p:Tnotification;
+    var n:Tnotification;
     
     begin
         if assigned(notifications) then
           begin
-            p:=Tnotification(notifications.first);
-            while assigned(p) do
+            n:=Tnotification(notifications.first);
+            while assigned(n) do
               begin
-                if what in p.flags then
-                  p.callback(what,self);
-                p:=Tnotification(p.next);
+                if what in n.flags then
+                  n.callback(what,self);
+                n:=Tnotification(n.next);
               end;
           end;
     end;
@@ -1743,6 +1744,30 @@ implementation
       register_notification:=n.id;
       notifications.concat(n);
     end;
+
+    procedure Tvarsym.unregister_notification(id:cardinal);
+    
+    var n:Tnotification;
+
+    begin
+      if not assigned(notifications) then
+        internalerror(200212311)
+      else
+        begin
+            n:=Tnotification(notifications.first);
+            while assigned(n) do
+              begin
+                if n.id=id then
+                  begin
+                    notifications.remove(n);
+                    n.destroy;
+                    exit;
+                  end;
+                n:=Tnotification(n.next);
+              end;
+            internalerror(200212311)
+        end;
+    end;
 {$endif}
 
 {$ifdef GDB}
@@ -2538,7 +2563,14 @@ implementation
 end.
 {
   $Log$
-  Revision 1.86  2002-12-30 22:44:53  daniel
+  Revision 1.87  2002-12-31 09:55:58  daniel
+   + Notification implementation complete
+   + Add for loop code optimization using notifications
+     results in 1.5-1.9% speed improvement in nestloop benchmark
+     Optimization incomplete, compiler does not cycle yet with
+     notifications enabled.
+
+  Revision 1.86  2002/12/30 22:44:53  daniel
   * Some work on notifications
 
   Revision 1.85  2002/12/27 18:07:44  peter