Browse Source

+ 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 years ago
parent
commit
158e9689d7
5 changed files with 136 additions and 37 deletions
  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);
                    t2.location,aktbreaklabel);
                end;
                end;
            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
          if not(cs_littlesize in aktglobalswitches) then
             { align loop target }
             { align loop target }
             exprasmList.concat(Tai_align.Create(aktalignment.loopalign));
             exprasmList.concat(Tai_align.Create(aktalignment.loopalign));
          cg.a_label(exprasmlist,l3);
          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 }
          { help register must not be in instruction block }
          rg.cleartempgen;
          rg.cleartempgen;
@@ -406,21 +417,45 @@ implementation
              load_all_regvars(exprasmlist);
              load_all_regvars(exprasmlist);
            end;
            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);
          cg.a_label(exprasmlist,aktcontinuelabel);
 
 
          { makes no problems there }
          { makes no problems there }
          rg.cleartempgen;
          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
             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);
          load_all_regvars(exprasmlist);
 
 
          { produce comparison and the corresponding }
          { produce comparison and the corresponding }
@@ -1247,7 +1282,14 @@ begin
 end.
 end.
 {
 {
   $Log$
   $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
     * loop node flags from node flags splitted
 
 
   Revision 1.44  2002/11/25 17:43:17  peter
   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.}
        had in the last iteration.}
       if not_type=vn_onwrite then
       if not_type=vn_onwrite then
         begin
         begin
-          include(loopflags,lnf_dont_mind_loopvar_on_exit);
-        writeln('Loopvar does not matter on exit');
+          writeln('Loopvar does not matter on exit');
         end
         end
       else
       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;
     end;
 {$endif}
 {$endif}
 
 
@@ -756,6 +759,7 @@ implementation
          inserttypeconv(right,t2.resulttype);
          inserttypeconv(right,t2.resulttype);
 (*
 (*
       {$ifdef var_notification}
       {$ifdef var_notification}
+         include(loopflags,lnf_dont_mind_loopvar_on_exit);
          if (hp.nodetype=loadn) and (Tloadnode(hp).symtableentry.typ=varsym) then
          if (hp.nodetype=loadn) and (Tloadnode(hp).symtableentry.typ=varsym) then
             loopvar_notid:=Tvarsym(Tloadnode(hp).symtableentry).
             loopvar_notid:=Tvarsym(Tloadnode(hp).symtableentry).
              register_notification([vn_onread,vn_onwrite],@loop_var_access);
              register_notification([vn_onread,vn_onwrite],@loop_var_access);
@@ -817,6 +821,7 @@ implementation
          firstpass(right);
          firstpass(right);
       {$ifdef var_notification}
       {$ifdef var_notification}
          { Check count var, record fields are also allowed in tp7 }
          { Check count var, record fields are also allowed in tp7 }
+         include(loopflags,lnf_dont_mind_loopvar_on_exit);
          hp:=t2;
          hp:=t2;
          while (hp.nodetype=subscriptn) or
          while (hp.nodetype=subscriptn) or
                ((hp.nodetype=vecn) and
                ((hp.nodetype=vecn) and
@@ -1463,7 +1468,14 @@ begin
 end.
 end.
 {
 {
   $Log$
   $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
   * Some work on notifications
 
 
   Revision 1.58  2002/12/27 15:25:40  peter
   Revision 1.58  2002/12/27 15:25:40  peter

+ 8 - 2
compiler/nld.pas

@@ -435,7 +435,6 @@ implementation
 
 
     begin
     begin
       include(flags,nf_write);
       include(flags,nf_write);
-      writeln('Mark ',symtableentry.name);
     end;
     end;
 {$endif}
 {$endif}
 
 
@@ -1298,7 +1297,14 @@ begin
 end.
 end.
 {
 {
   $Log$
   $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
   * Some work on notifications
 
 
   Revision 1.75  2002/12/27 15:27:25  peter
   Revision 1.75  2002/12/27 15:27:25  peter

+ 9 - 2
compiler/symnot.pas

@@ -30,7 +30,7 @@ interface
 
 
 uses  cclasses,symbase,symtype;
 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_flags=set of Tnotification_flag;
 
 
       Tnotification_callback=procedure(not_type:Tnotification_flag;
       Tnotification_callback=procedure(not_type:Tnotification_flag;
@@ -65,7 +65,14 @@ end.
 
 
 {
 {
   $Log$
   $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
    + Added read/write notifications of variables. These will be usefull
      for providing information for several optimizations. For example
      for providing information for several optimizations. For example
      the value of the loop variable of a for loop does matter is the
      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);
           procedure trigger_notifications(what:Tnotification_flag);
           function register_notification(flags:Tnotification_flags;
           function register_notification(flags:Tnotification_flags;
                                          callback:Tnotification_callback):cardinal;
                                          callback:Tnotification_callback):cardinal;
+          procedure unregister_notification(id:cardinal);
 {$endif}
 {$endif}
 {$ifdef GDB}
 {$ifdef GDB}
           function  stabstring : pchar;override;
           function  stabstring : pchar;override;
@@ -1716,17 +1717,17 @@ implementation
 {$ifdef var_notification}
 {$ifdef var_notification}
     procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
     procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
     
     
-    var p:Tnotification;
+    var n:Tnotification;
     
     
     begin
     begin
         if assigned(notifications) then
         if assigned(notifications) then
           begin
           begin
-            p:=Tnotification(notifications.first);
-            while assigned(p) do
+            n:=Tnotification(notifications.first);
+            while assigned(n) do
               begin
               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;
           end;
     end;
     end;
@@ -1743,6 +1744,30 @@ implementation
       register_notification:=n.id;
       register_notification:=n.id;
       notifications.concat(n);
       notifications.concat(n);
     end;
     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}
 {$endif}
 
 
 {$ifdef GDB}
 {$ifdef GDB}
@@ -2538,7 +2563,14 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $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
   * Some work on notifications
 
 
   Revision 1.85  2002/12/27 18:07:44  peter
   Revision 1.85  2002/12/27 18:07:44  peter