Browse Source

* released -dalignreg
* some small fixes to -dnewOptimizations helper procedures

Jonas Maebe 25 years ago
parent
commit
5910b48cbe
3 changed files with 138 additions and 89 deletions
  1. 6 2
      compiler/aasm.pas
  2. 118 79
      compiler/csopt386.pas
  3. 14 8
      compiler/daopt386.pas

+ 6 - 2
compiler/aasm.pas

@@ -76,7 +76,7 @@ unit aasm;
 
 {$ifdef newcg}
     const
-      SkipInstr = [ait_comment, ait_align, ait_symbol
+      SkipInstr = [ait_comment, ait_symbol
 {$ifdef GDB}
                    ,ait_stabs, ait_stabn, ait_stab_function_name
 {$endif GDB}
@@ -1038,7 +1038,11 @@ uses
 end.
 {
   $Log$
-  Revision 1.71  2000-01-12 10:38:16  peter
+  Revision 1.72  2000-01-13 13:07:05  jonas
+    * released -dalignreg
+    * some small fixes to -dnewOptimizations helper procedures
+
+  Revision 1.71  2000/01/12 10:38:16  peter
     * smartlinking fixes for binary writer
     * release alignreg code and moved instruction writing align to cpuasm,
       but it doesn't use the specified register yet

+ 118 - 79
compiler/csopt386.pas

@@ -246,7 +246,6 @@ Begin
   Until p1 = p2;
 End;
 
-{$ifdef alignreg}
 Procedure SetAlignReg(p: Pai);
 Const alignSearch = 12;
 var regsUsable: TRegSet;
@@ -410,7 +409,6 @@ begin
 {$endif alignregdebug}
   pai_align(p)^.reg := lastRemoved;
 End;
-{$endif alignreg}
 
 {$ifdef replacereg}
 function FindRegDealloc(reg: tregister; p: pai): boolean;
@@ -528,14 +526,19 @@ end;
 function NoHardCodedRegs(p: paicpu): boolean;
 var chCount: byte;
 begin
-  NoHardCodedRegs := true;
-  with InsProp[p^.opcode] do
-    for chCount := 1 to MaxCh do
-      if Ch[chCount] in ([Ch_REAX..Ch_MEDI]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
-        begin
-          NoHardCodedRegs := false;
-          break
-        end;
+  if (p^.opcode = A_IMUL) then
+    noHardCodedRegs := p^.ops <> 1
+  else
+    begin
+      NoHardCodedRegs := true;
+      with InsProp[p^.opcode] do
+      for chCount := 1 to MaxCh do
+        if Ch[chCount] in ([Ch_REAX..Ch_MEDI,Ch_WMemEDI,Ch_All]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
+          begin
+            NoHardCodedRegs := false;
+            break
+          end;
+    end;
 end;
 
 Procedure ChangeReg(var Reg: TRegister; orgReg, newReg: TRegister);
@@ -548,19 +551,23 @@ begin
          reg := regtoreg16(orgReg);
 end;
 
+procedure changeOp(var o: toper; orgReg, newReg: tregister);
+begin
+  case o.typ of
+    top_reg: changeReg(o.reg,orgReg,newReg);
+    top_ref:
+      begin
+        changeReg(o.ref^.base,orgReg,newReg);
+        changeReg(o.ref^.index,orgReg,newReg);
+      end;
+  end;
+end;
+
 Procedure DoReplaceReg(orgReg,newReg: tregister; hp: paicpu);
 var opCount: byte;
 begin
   for opCount := 0 to 2 do
-    with hp^.oper[opCount] Do
-      case typ of
-        top_reg: ChangeReg(reg,orgReg,newReg);
-        top_ref:
-          begin
-            ChangeReg(ref^.base,orgReg,newReg);
-            ChangeReg(ref^.index,orgReg,newReg);
-          end;
-      end;
+    changeOp(hp^.oper[opCount],orgReg,newReg)
 end;
 
 function RegSizesOK(oldReg,newReg: TRegister; p: paicpu): boolean;
@@ -590,60 +597,96 @@ begin
   p := paicpu(hp);
   if hp^.typ <> ait_instruction then
     exit;
-  for opCount := 0 to 2 do
-    if (p^.oper[opCount].typ = top_ref) and
-       RegInRef(reg,p^.oper[opCount].ref^) then
-      begin
-        RegReadByInstruction := true;
-        exit
+  case p^.opcode of
+    A_IMUL:
+      case p^.ops of
+        1: regReadByInstruction := (reg = R_EAX) or reginOp(reg,p^.oper[0]);
+        2,3:
+          regReadByInstruction := regInOp(reg,p^.oper[0]) or
+            regInOp(reg,p^.oper[1]);
       end;
-  for opCount := 1 to MaxCh do
-    case InsProp[p^.opcode].Ch[opCount] of
-      Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
-        if (p^.oper[0].typ = top_reg) and
-           (reg32(p^.oper[0].reg) = reg) then
-          begin
-            RegReadByInstruction := true;
-            exit
-          end;
-      Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
-        if (p^.oper[1].typ = top_reg) and
-           (reg32(p^.oper[1].reg) = reg) then
-          begin
-            RegReadByInstruction := true;
-            exit
-          end;
-      Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
-        if (p^.oper[2].typ = top_reg) and
-           (reg32(p^.oper[2].reg) = reg) then
-          begin
-            RegReadByInstruction := true;
-            exit
+{    A_IDIV,A_DIV,A_IMUL:
+      begin
+        regReadByInstruction :=
+          regInOp(reg,p^.oper[0]) or
+          (((p^.opcode = A_IDIV) or
+            (p^.opcode = A_DIV)) and
+           (reg = R_EAX));
+      end;}
+    else
+      begin
+        for opCount := 0 to 2 do
+          if (p^.oper[opCount].typ = top_ref) and
+             RegInRef(reg,p^.oper[opCount].ref^) then
+            begin
+              RegReadByInstruction := true;
+              exit
+            end;
+        for opCount := 1 to MaxCh do
+          case InsProp[p^.opcode].Ch[opCount] of
+            Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
+              if (p^.oper[0].typ = top_reg) and
+                 (reg32(p^.oper[0].reg) = reg) then
+                begin
+                  RegReadByInstruction := true;
+                  exit
+                end;
+            Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
+              if (p^.oper[1].typ = top_reg) and
+                 (reg32(p^.oper[1].reg) = reg) then
+                begin
+                  RegReadByInstruction := true;
+                  exit
+                end;
+            Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
+              if (p^.oper[2].typ = top_reg) and
+                 (reg32(p^.oper[2].reg) = reg) then
+                begin
+                  RegReadByInstruction := true;
+                  exit
+                end;
           end;
-    end;
+      end;
+  end;
 end;
 
 procedure DoReplaceReadReg(orgReg,newReg: tregister; p: paicpu);
 var opCount: byte;
 begin
-  for opCount := 0 to 2 do
-    if p^.oper[opCount].typ = top_ref then
+  { handle special case }
+  case p^.opcode of
+    A_IMUL:
+      begin
+        case p^.ops of
+          1: internalerror(1301001);
+          2,3:
+            begin
+              changeOp(p^.oper[0],orgReg,newReg);
+              if p^.ops = 3 then
+                changeOp(p^.oper[1],orgReg,newReg);
+            end;
+        end;
+      end;
+    A_DIV,A_IDIV,A_MUL: internalerror(1301002);
+    else
       begin
-        ChangeReg(p^.oper[opCount].ref^.base,orgReg,newReg);
-        ChangeReg(p^.oper[opCount].ref^.index,orgReg,newReg);
+        for opCount := 0 to 2 do
+          if p^.oper[opCount].typ = top_ref then
+            changeOp(p^.oper[opCount],orgReg,newReg);
+        for opCount := 1 to MaxCh do
+          case InsProp[p^.opcode].Ch[opCount] of
+            Ch_ROp1:
+              if p^.oper[0].typ = top_reg then
+                ChangeReg(p^.oper[0].reg,orgReg,newReg);
+            Ch_ROp2:
+              if p^.oper[1].typ = top_reg then
+                ChangeReg(p^.oper[1].reg,orgReg,newReg);
+            Ch_ROp3:
+              if p^.oper[2].typ = top_reg then
+                ChangeReg(p^.oper[2].reg,orgReg,newReg);
+          end;
       end;
-  for opCount := 1 to MaxCh do
-    case InsProp[p^.opcode].Ch[opCount] of
-      Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
-        if p^.oper[0].typ = top_reg then
-          ChangeReg(p^.oper[0].reg,orgReg,newReg);
-      Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
-        if p^.oper[1].typ = top_reg then
-          ChangeReg(p^.oper[1].reg,orgReg,newReg);
-      Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
-        if p^.oper[2].typ = top_reg then
-          ChangeReg(p^.oper[2].reg,orgReg,newReg);
-    end;
+  end;
 end;
 
 function ReplaceReg(orgReg, newReg: TRegister; p: pai;
@@ -662,14 +705,6 @@ begin
   newRegModified := false;
   orgRegRead := false;
   endP := p;
-(*
-  endP := pai(p^.previous);
-  { skip over the instructions that will be removed }
-  while getNextInstruction(endP,hp) and
-        assigned(hp) and
-        PPaiProp(hp^.optInfo)^.canBeRemoved do
-    endP := hp;
-*)
   while tmpResult and not sequenceEnd do
     begin
       tmpResult :=
@@ -679,9 +714,10 @@ begin
          Not (PPaiProp(endP^.optInfo)^.canBeRemoved) then
         begin
           sequenceEnd :=
-            RegLoadedWithNewValue(newReg,paicpu(endP)) or
-            (GetNextInstruction(endp,hp) and
-             FindRegDealloc(newReg,hp));
+            noHardCodedRegs(paicpu(endP)) and
+            (RegLoadedWithNewValue(newReg,paicpu(endP)) or
+             (GetNextInstruction(endp,hp) and
+              FindRegDealloc(newReg,hp)));
           newRegModified :=
             newRegModified or
             (not(sequenceEnd) and
@@ -832,10 +868,9 @@ Begin
   While (p <> Last) Do
     Begin
       Case p^.typ Of
-{$ifdef alignreg}
         ait_align:
-          SetAlignReg(p);
-{$endif alignreg}
+          if not(pai_align(p)^.use_op) then
+            SetAlignReg(p);
         ait_instruction:
           Begin
             Case Paicpu(p)^.opcode Of
@@ -1114,7 +1149,11 @@ End.
 
 {
  $Log$
- Revision 1.38  2000-01-07 01:14:23  peter
+ Revision 1.39  2000-01-13 13:07:05  jonas
+   * released -dalignreg
+   * some small fixes to -dnewOptimizations helper procedures
+
+ Revision 1.38  2000/01/07 01:14:23  peter
    * updated copyright to 2000
 
  Revision 1.37  2000/01/03 17:11:17  jonas

+ 14 - 8
compiler/daopt386.pas

@@ -64,6 +64,9 @@ Function RefsEqual(Const R1, R2: TReference): Boolean;
 Function IsGP32Reg(Reg: TRegister): Boolean;
 Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
 Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
+{$ifdef newOptimizations}
+Function RegInOp(Reg: TRegister; const o:toper): Boolean;
+{$endif newOptimizations}
 Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
 
 Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
@@ -96,9 +99,6 @@ Const
 {$ifdef GDB}
   ,ait_stabs, ait_stabn, ait_stab_function_name
 {$endif GDB}
-{$ifndef alignreg}
-  ,ait_align
-{$endif alignreg}
   ,ait_regalloc, ait_tempalloc
   ];
 
@@ -458,7 +458,7 @@ Var TempP: Pai;
 Begin
   TempP := hp;
   While Assigned(TempP) and
-       (TempP^.typ In SkipInstr + [ait_label]) Do
+       (TempP^.typ In SkipInstr + [ait_label,ait_align]) Do
     If (TempP^.typ <> ait_Label) Or
        (pai_label(TempP)^.l <> L)
       Then GetNextInstruction(TempP, TempP)
@@ -705,15 +705,17 @@ Begin
   RegInInstruction := TmpResult
 End;
 
-{Function RegInOp(Reg: TRegister; const o:toper): Boolean;
+{$ifdef newOptimizations}
+Function RegInOp(Reg: TRegister; const o:toper): Boolean;
 Begin
   RegInOp := False;
-  Case opt Of
+  Case o.typ Of
     top_reg: RegInOp := Reg = o.reg;
     top_ref: RegInOp := (Reg = o.ref^.Base) Or
                         (Reg = o.ref^.Index);
   End;
-End;}
+End;
+{$endif newOptimizations}
 (*
 Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
 {returns true if Reg is modified by the instruction p1. P1 is assumed to be
@@ -2017,7 +2019,11 @@ End.
 
 {
  $Log$
- Revision 1.77  2000-01-09 01:44:21  jonas
+ Revision 1.78  2000-01-13 13:07:06  jonas
+   * released -dalignreg
+   * some small fixes to -dnewOptimizations helper procedures
+
+ Revision 1.77  2000/01/09 01:44:21  jonas
    + (de)allocation info for EDI to fix reported bug on mailinglist.
      Also some (de)allocation info for ESI added. Between -dallocEDI
      because at this time of the night bugs could easily slip in ;)