浏览代码

* fixed a potential bug in destroyregs regarding the removal of
unused loads
* added destroyDependingRegs() procedure and use it for the fix in
the previous commit (safer/more complete than what was done before)

Jonas Maebe 25 年之前
父节点
当前提交
c9de6bc568
共有 1 个文件被更改,包括 41 次插入34 次删除
  1. 41 34
      compiler/daopt386.pas

+ 41 - 34
compiler/daopt386.pas

@@ -1229,6 +1229,21 @@ Begin
   sequenceDependsonReg := TmpResult
   sequenceDependsonReg := TmpResult
 End;
 End;
 
 
+procedure invalidateDepedingRegs(p1: ppaiProp; reg: tregister);
+var
+  counter: tregister;
+begin
+  for counter := R_EAX to R_EDI Do
+    if counter <> reg then
+      with p1^.regs[counter] Do
+        if (typ in [con_ref,con_noRemoveRef]) and
+           sequenceDependsOnReg(p1^.Regs[counter],counter,reg) then
+          if typ = con_ref then
+            typ := con_invalid
+          { con_invalid and con_noRemoveRef = con_unknown }
+          else typ := con_unknown;
+end;
+
 Procedure DestroyReg(p1: PPaiProp; Reg: TRegister; doIncState:Boolean);
 Procedure DestroyReg(p1: PPaiProp; Reg: TRegister; doIncState:Boolean);
 {Destroys the contents of the register Reg in the PPaiProp p1, as well as the
 {Destroys the contents of the register Reg in the PPaiProp p1, as well as the
  contents of registers are loaded with a memory location based on Reg.
  contents of registers are loaded with a memory location based on Reg.
@@ -1245,29 +1260,20 @@ Begin
      (reg > high(NrOfInstrSinceLastMod)) then
      (reg > high(NrOfInstrSinceLastMod)) then
     exit;
     exit;
   NrOfInstrSinceLastMod[Reg] := 0;
   NrOfInstrSinceLastMod[Reg] := 0;
-  If (Reg >= R_EAX) And (Reg <= R_EDI)
-    Then
-      Begin
-        With p1^.Regs[Reg] Do
-          Begin
-            if doIncState then
-              begin
-                IncState(WState);
-                TmpWState := WState;
-                TmpRState := RState;
-                FillChar(p1^.Regs[Reg], SizeOf(TContent), 0);
-                WState := TmpWState;
-                RState := TmpRState;
-              end
-            else
-              typ := con_invalid;
-          End;
-        For counter := R_EAX to R_EDI Do
-          With p1^.Regs[counter] Do
-            if (typ in [con_ref,con_noRemoveRef]) and
-               sequenceDependsOnReg(p1^.Regs[counter],counter,reg) Then
-              typ := con_invalid;
-       End;
+  if (reg >= R_EAX) and (reg <= R_EDI) then
+    begin
+      with p1^.regs[reg] do
+        begin
+          if doIncState then
+            begin
+              incState(WState);
+              typ := con_unknown;
+            end
+          else
+            typ := con_invalid;
+        end;
+      invalidateDepedingRegs(p1,reg);
+    end;
 End;
 End;
 
 
 {Procedure AddRegsToSet(p: Pai; Var RegSet: TRegSet);
 {Procedure AddRegsToSet(p: Pai; Var RegSet: TRegSet);
@@ -1736,15 +1742,15 @@ BlockStart, BlockEnd: Pai);
  been processed}
  been processed}
 Var
 Var
     CurProp: PPaiProp;
     CurProp: PPaiProp;
-{$ifdef AnalyzeLoops}
-    TmpState: Byte;
-{$endif AnalyzeLoops}
     Cnt, InstrCnt : Longint;
     Cnt, InstrCnt : Longint;
     InstrProp: TInsProp;
     InstrProp: TInsProp;
     UsedRegs: TRegSet;
     UsedRegs: TRegSet;
     p, hp : Pai;
     p, hp : Pai;
     TmpRef: TReference;
     TmpRef: TReference;
-    TmpReg, regCounter: TRegister;
+    TmpReg: TRegister;
+{$ifdef AnalyzeLoops}
+    TmpState: Byte;
+{$endif AnalyzeLoops}
 Begin
 Begin
   p := BlockStart;
   p := BlockStart;
   UsedRegs := [];
   UsedRegs := [];
@@ -2032,12 +2038,7 @@ Begin
                                   { Destroy the contents of the registers  }
                                   { Destroy the contents of the registers  }
                                   { that depended on the previous value of }
                                   { that depended on the previous value of }
                                   { this register                          }
                                   { this register                          }
-                                  for regCounter := R_EAX to R_EDI Do
-                                    if regCounter <> tmpReg then
-                                      With curProp^.Regs[regCounter] Do
-                                        if (typ in [con_ref,con_noRemoveRef]) and
-                                           sequenceDependsOnReg(curProp^.Regs[regCounter],regCounter,tmpReg) Then
-                                          typ := con_invalid;
+                                  invalidateDepedingRegs(curProp,tmpReg);
                                 End;
                                 End;
                             End
                             End
                           Else
                           Else
@@ -2329,7 +2330,13 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2000-08-19 09:08:59  jonas
+  Revision 1.6  2000-08-19 17:53:29  jonas
+    * fixed a potential bug in destroyregs regarding the removal of
+      unused loads
+    * added destroyDependingRegs() procedure and use it for the fix in
+      the previous commit (safer/more complete than what was done before)
+
+  Revision 1.5  2000/08/19 09:08:59  jonas
     * fixed bug where the contents of a register would not be destroyed
     * fixed bug where the contents of a register would not be destroyed
       if another register on which these contents depend is modified
       if another register on which these contents depend is modified
       (not really merged, but same idea as fix in fixes branch,
       (not really merged, but same idea as fix in fixes branch,