Browse Source

* Fixed the optimizer

daniel 22 years ago
parent
commit
18ab545cb7
5 changed files with 39 additions and 25 deletions
  1. 6 3
      compiler/i386/aopt386.pas
  2. 10 7
      compiler/i386/csopt386.pas
  3. 7 3
      compiler/i386/daopt386.pas
  4. 10 4
      compiler/ncgutil.pas
  5. 6 8
      compiler/x86/cgx86.pas

+ 6 - 3
compiler/i386/aopt386.pas

@@ -73,7 +73,7 @@ Begin
            PeepHoleOptPass1(AsmL, BlockStart, BlockEnd);
         { Data flow analyzer }
          If (cs_fastoptimize in aktglobalswitches) Then
-           Begin
+           begin
              If DFAPass2(
 {$ifdef statedebug}
                          AsmL,
@@ -81,7 +81,7 @@ Begin
                                BlockStart, BlockEnd) Then
               { common subexpression elimination }
                changed := CSE(asmL, blockStart, blockEnd, pass) or changed;
-           End;
+           end;
         { More peephole optimizations }
          PeepHoleOptPass2(AsmL, BlockStart, BlockEnd);
          if lastLoop then
@@ -118,7 +118,10 @@ End;
 End.
 {
   $Log$
-  Revision 1.7  2002-07-01 18:46:29  peter
+  Revision 1.8  2003-02-26 21:15:43  daniel
+    * Fixed the optimizer
+
+  Revision 1.7  2002/07/01 18:46:29  peter
     * internal linker
     * reorganized aasm layer
 

+ 10 - 7
compiler/i386/csopt386.pas

@@ -193,7 +193,7 @@ begin
     not(ref.base.enum in (rg.usableregsint+[R_EDI]));}
   isSimpleMemLoc :=
     (ref.index.enum = R_NO) and
-    not(ref.base.enum in [R_ESI,R_EDI]);
+    not(ref.base.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI]);
 end;
 
 {checks whether the current instruction sequence (starting with p) and the
@@ -277,7 +277,7 @@ var
 {    if (passedJump and not(reg.enum in (rg.usableregsint+[R_EDI]))) or
        not getLastInstruction(currentPrev,hp) then
       exit;}
-    if (passedJump and not(reg.enum in [R_ESI,R_EDI])) or
+    if (passedJump and not(reg.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI])) or
        not getLastInstruction(currentPrev,hp) then
       exit;
 
@@ -305,7 +305,7 @@ var
            { jump with a new value, since if the jump is taken, the old value }
            { is (probably) still necessary                                    }
 {           (passedJump and not(reg.enum in (rg.usableregsint+[R_EDI]))) or}
-           (passedJump and not(reg.enum in [R_ESI,R_EDI])) or
+           (passedJump and not(reg.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI])) or
            not getLastInstruction(hp,hp) then
           break;
       end;
@@ -1328,7 +1328,7 @@ begin
          (rState = pTaiprop(startmod.optInfo)^.regs[reg.enum].rState) and
          (not(check) or
           (not(regInInstruction(reg.enum,p)) and
-           (not(reg.enum in [R_ESI,R_EDI]) and
+           (not(reg.enum in [R_EAX,R_EBX,R_ECX,R_EDX]) and
 {           (not(reg.enum in rg.usableregsint) and}
             (startmod.typ = ait_instruction) and
             ((Taicpu(startmod).opcode = A_MOV) or
@@ -1589,7 +1589,7 @@ Begin
                                              getLastInstruction(p,hp3);
                                              If (hp4 <> prevSeq) or
                                                 {not(regCounter.enum in rg.usableregsint + [R_EDI,R_ESI]) or}
-                                                not(regCounter.enum in [R_EDI,R_ESI]) or
+                                                not(regCounter.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI,R_ESI]) or
                                                 not ReplaceReg(asmL,RegInfo.New2OldReg[RegCounter.enum],
                                                       regCounter,hp3,
                                                       PTaiProp(PrevSeq.optInfo)^.Regs[regCounter.enum],true,hp5) then
@@ -1695,7 +1695,7 @@ Begin
                         if (Taicpu(p).oper[0].typ = top_reg) and
                            (Taicpu(p).oper[1].typ = top_reg) and
                            { only remove if we're not storing something in a regvar }
-                           (Taicpu(p).oper[1].reg.enum in [R_ESI,R_EDI]) and
+                           (Taicpu(p).oper[1].reg.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI]) and
 {                           (Taicpu(p).oper[1].reg.enum in (rg.usableregsint+[R_EDI])) and}
                            (Taicpu(p).opcode = A_MOV) and
                            getLastInstruction(p,hp4) and
@@ -1999,7 +1999,10 @@ End.
 
 {
   $Log$
-  Revision 1.40  2003-02-19 22:00:15  daniel
+  Revision 1.41  2003-02-26 21:15:43  daniel
+    * Fixed the optimizer
+
+  Revision 1.40  2003/02/19 22:00:15  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 7 - 3
compiler/i386/daopt386.pas

@@ -452,7 +452,8 @@ begin
     exit;
   getNoDeallocRegs(funcResRegs);
 {  funcResRegs := funcResRegs - rg.usableregsint;}
-  funcResRegs := funcResRegs - [R_ESI,R_EDI];
+{  funcResRegs := funcResRegs - [R_ESI,R_EDI];}
+  funcResRegs := funcResRegs - [R_EAX,R_EBX,R_ECX,R_EDX];
   funcResReg := reg.enum in funcResRegs;
   hp1 := p;
   while not(funcResReg and
@@ -1203,7 +1204,7 @@ Begin
     internalerror(200301081);
 { If not(reg.enum in rg.usableregsint+[R_EDI,R_ESI]) or
      not(assigned(p1)) then}
- If not(reg.enum in [R_EDI,R_ESI]) or
+ If not(reg.enum in [R_EAX,R_EBX,R_ECX,R_EDX,R_EDI,R_ESI]) or
      not(assigned(p1)) then
     { this happens with registers which are loaded implicitely, outside the }
     { current block (e.g. esi with self)                                    }
@@ -2670,7 +2671,10 @@ End.
 
 {
   $Log$
-  Revision 1.46  2003-02-19 22:00:15  daniel
+  Revision 1.47  2003-02-26 21:15:43  daniel
+    * Fixed the optimizer
+
+  Revision 1.46  2003/02/19 22:00:15  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 10 - 4
compiler/ncgutil.pas

@@ -1776,14 +1776,17 @@ function returns in a register and the caller receives it in an other one}
                 { AfterConstruction                          }
                 if is_object(procinfo._class) then
                   begin
-                    r.enum:=self_pointer_reg;
-                    r2.enum:=accumulator;
+                    r.enum:=R_INTREGISTER;
+                    r.number:=NR_SELF_POINTER_REG;
+                    r2.enum:=R_INTREGISTER;
+                    r2.number:=NR_ACCUMULATOR;
                     cg.a_reg_alloc(list,r2);
                     cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,r,r2);
                     usesacc:=true;
                   end;
 {$ifdef i386}
-                r.enum:=R_ESI;
+                r.enum:=R_INTREGISTER;
+                r.number:=NR_SELF_POINTER_REG;
                 list.concat(taicpu.op_reg_reg(A_TEST,S_L,r,r));
 {$else}
 {$warning constructor returns in flags for i386}
@@ -1991,7 +1994,10 @@ function returns in a register and the caller receives it in an other one}
 end.
 {
   $Log$
-  Revision 1.77  2003-02-19 22:00:14  daniel
+  Revision 1.78  2003-02-26 21:15:43  daniel
+    * Fixed the optimizer
+
+  Revision 1.77  2003/02/19 22:00:14  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed
 

+ 6 - 8
compiler/x86/cgx86.pas

@@ -491,11 +491,6 @@ unit cgx86;
             sizes2load(fromsize,subreg2opsize[reg2.number and $ff],op,s);
             eq:=(reg1.number shr 8)=(reg2.number shr 8);
           end
-        else if (reg1.enum<lastreg) and (reg2.enum<lastreg) then
-          begin
-            sizes2load(fromsize,reg2opsize[reg2.enum],op,s);
-            eq:=(rg.makeregsize(reg1,OS_INT).enum = rg.makeregsize(reg2,OS_INT).enum);
-          end
         else
           internalerror(200301081);
         if eq then
@@ -509,12 +504,12 @@ unit cgx86;
               case fromsize of
                 OS_8:
                   begin
-                    list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2.enum],255,reg2));
+                    list.concat(taicpu.op_const_reg(A_AND,subreg2opsize[reg2.number and $ff],255,reg2));
                     exit;
                   end;
                 OS_16:
                   begin
-                    list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2.enum],65535,reg2));
+                    list.concat(taicpu.op_const_reg(A_AND,subreg2opsize[reg2.number and $ff],65535,reg2));
                     exit;
                   end;
               end;
@@ -1930,7 +1925,10 @@ unit cgx86;
 end.
 {
   $Log$
-  Revision 1.32  2003-02-19 22:00:17  daniel
+  Revision 1.33  2003-02-26 21:15:43  daniel
+    * Fixed the optimizer
+
+  Revision 1.32  2003/02/19 22:00:17  daniel
     * Code generator converted to new register notation
     - Horribily outdated todo.txt removed