瀏覽代碼

* The for node does a check if the first comparision can be skipped. I moved
the check from the second pass to the resulttype pass. The advantage is
that the state tracker can now decide to skip the first comparision too.

daniel 23 年之前
父節點
當前提交
8cbd40c2f0
共有 2 個文件被更改,包括 26 次插入6 次删除
  1. 10 5
      compiler/ncgflw.pas
  2. 16 1
      compiler/nflw.pas

+ 10 - 5
compiler/ncgflw.pas

@@ -278,7 +278,7 @@ implementation
     procedure tcgfornode.pass_2;
     procedure tcgfornode.pass_2;
       var
       var
          l3,oldclabel,oldblabel : tasmlabel;
          l3,oldclabel,oldblabel : tasmlabel;
-         omitfirstcomp,temptovalue : boolean;
+         {omitfirstcomp,}temptovalue : boolean;
          hs : byte;
          hs : byte;
          temp1 : treference;
          temp1 : treference;
          hop : topcg;
          hop : topcg;
@@ -294,13 +294,13 @@ implementation
          getlabel(l3);
          getlabel(l3);
 
 
          { could we spare the first comparison ? }
          { could we spare the first comparison ? }
-         omitfirstcomp:=false;
+{         omitfirstcomp:=false;
          if right.nodetype=ordconstn then
          if right.nodetype=ordconstn then
            if tassignmentnode(left).right.nodetype=ordconstn then
            if tassignmentnode(left).right.nodetype=ordconstn then
              omitfirstcomp:=((nf_backward in flags) and
              omitfirstcomp:=((nf_backward in flags) and
                (tordconstnode(tassignmentnode(left).right).value>=tordconstnode(right).value))
                (tordconstnode(tassignmentnode(left).right).value>=tordconstnode(right).value))
                or (not(nf_backward in flags) and
                or (not(nf_backward in flags) and
-                  (tordconstnode(tassignmentnode(left).right).value<=tordconstnode(right).value));
+                  (tordconstnode(tassignmentnode(left).right).value<=tordconstnode(right).value));}
 
 
          { only calculate reference }
          { only calculate reference }
          rg.cleartempgen;
          rg.cleartempgen;
@@ -358,7 +358,7 @@ implementation
            end
            end
          else
          else
            begin
            begin
-             if not(omitfirstcomp) then
+             if testatbegin then
                begin
                begin
                  cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond,
                  cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond,
                    aword(tordconstnode(right).value),
                    aword(tordconstnode(right).value),
@@ -631,7 +631,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.24  2002-07-20 08:14:24  daniel
+  Revision 1.25  2002-07-20 11:15:51  daniel
+  * The for node does a check if the first comparision can be skipped. I moved
+    the check from the second pass to the resulttype pass. The advantage is
+    that the state tracker can now decide to skip the first comparision too.
+
+  Revision 1.24  2002/07/20 08:14:24  daniel
   * Loops should not be aligned when optimizing for size
   * Loops should not be aligned when optimizing for size
 
 
   Revision 1.23  2002/07/19 11:41:35  daniel
   Revision 1.23  2002/07/19 11:41:35  daniel

+ 16 - 1
compiler/nflw.pas

@@ -63,6 +63,7 @@ interface
        tifnodeclass = class of tifnode;
        tifnodeclass = class of tifnode;
 
 
        tfornode = class(tloopnode)
        tfornode = class(tloopnode)
+	  testatbegin:boolean;
           constructor create(l,r,_t1,_t2 : tnode;back : boolean);virtual;
           constructor create(l,r,_t1,_t2 : tnode;back : boolean);virtual;
           function det_resulttype:tnode;override;
           function det_resulttype:tnode;override;
           function pass_1 : tnode;override;
           function pass_1 : tnode;override;
@@ -590,6 +591,15 @@ implementation
          result:=nil;
          result:=nil;
          resulttype:=voidtype;
          resulttype:=voidtype;
 
 
+	 {Can we spare the first comparision.}
+         {testatbegin:=false; Already false by constructor}
+         if right.nodetype=ordconstn then
+            if Tassignmentnode(left).right.nodetype=ordconstn then
+        	testatbegin:=((nf_backward in flags) and
+                 (Tordconstnode(Tassignmentnode(left).right).value>=Tordconstnode(right).value))
+                 or (not(nf_backward in flags) and
+                 (Tordconstnode(Tassignmentnode(left).right).value<=Tordconstnode(right).value));
+											  											  
          if left.nodetype<>assignn then
          if left.nodetype<>assignn then
            begin
            begin
               CGMessage(cg_e_illegal_expression);
               CGMessage(cg_e_illegal_expression);
@@ -1234,7 +1244,12 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.40  2002-07-20 08:19:31  daniel
+  Revision 1.41  2002-07-20 11:15:51  daniel
+  * The for node does a check if the first comparision can be skipped. I moved
+    the check from the second pass to the resulttype pass. The advantage is
+    that the state tracker can now decide to skip the first comparision too.
+
+  Revision 1.40  2002/07/20 08:19:31  daniel
   * State tracker automatically changes while loops into repeat loops
   * State tracker automatically changes while loops into repeat loops
 
 
   Revision 1.39  2002/07/19 12:55:27  daniel
   Revision 1.39  2002/07/19 12:55:27  daniel