Browse Source

* fixed optimizer incompatibilities with freelabel code in psub

Jonas Maebe 27 years ago
parent
commit
57886308d0
2 changed files with 36 additions and 21 deletions
  1. 24 12
      compiler/daopt386.pas
  2. 12 9
      compiler/popt386.pas

+ 24 - 12
compiler/daopt386.pas

@@ -610,14 +610,14 @@ Begin
               If (Pai_Label(p)^.l^.nb > HighLabel) Then
                 HighLabel := Pai_Label(p)^.l^.nb;
             End
-          Else
+{          Else
             Begin
               hp1 := pai(p^.next);
               AsmL^.Remove(p);
               Dispose(p, Done);
               p := hp1;
               continue;
-            End;
+            End};
       p := pai(p^.next);
     End;
   If LabelFound
@@ -641,7 +641,8 @@ Begin
             p := pai(AsmL^.first);
             While Assigned(p) Do
               Begin
-                If (Pai(p)^.typ = ait_label) Then
+                If (Pai(p)^.typ = ait_label) And
+                   (Pai_Label(p)^.l^.is_used) Then
                   LabelTable^[Pai_Label(p)^.l^.nb-LowLabel].PaiObj := p;
                 p := pai(p^.next);
               End;
@@ -669,8 +670,9 @@ Var TempP: Pai;
 Begin
   TempP := hp;
   While Assigned(TempP) and
-       (pai(TempP)^.typ In SkipInstr + [ait_label]) Do
-    If (pai_label(TempP)^.l <> L)
+       (TempP^.typ In SkipInstr + [ait_label]) Do
+    If (TempP^.typ <> ait_Label) Or
+       (pai_label(TempP)^.l <> L)
       Then TempP := Pai(TempP^.next)
       Else
         Begin
@@ -678,7 +680,7 @@ Begin
           FindLabel := True;
           exit
         End;
-  FindLabel := False
+  FindLabel := False;
 End;
 
 {************************ Some general functions ************************}
@@ -794,7 +796,9 @@ Begin
   GetNextInstruction := False;
   Current := Pai(Current^.Next);
   While Assigned(Current) And
-        (Pai(Current)^.typ In SkipInstr) Do
+        ((Pai(Current)^.typ In SkipInstr) or
+         ((Pai(Current)^.typ = ait_label) And
+          Not(Pai_Label(Current)^.l^.is_used))) Do
     Current := Pai(Current^.Next);
   If Assigned(Current)
     Then
@@ -811,7 +815,9 @@ Begin
   GetLastInstruction := False;
   Current := Pai(Current^.previous);
   While Assigned(Current) And
-        (Pai(Current)^.typ In SkipInstr) Do
+        ((Pai(Current)^.typ In SkipInstr) or
+         ((Pai(Current)^.typ = ait_label) And
+          Not(Pai_Label(Current)^.l^.is_used))) Do
     Current := Pai(Current^.previous);
   If Assigned(Current)
     Then
@@ -1053,10 +1059,12 @@ Begin
       Case p^.typ Of
         ait_label:
 {$Ifndef JumpAnal}
-          DestroyAllRegs(CurProp);
+          If (Pai_label(p)^.l^.is_used) Then
+            DestroyAllRegs(CurProp);
 {$Else JumpAnal}
           Begin
-            With LTable^[Pai_Label(p)^.l^.nb-LoLab] Do
+           If (Pai_Label(p)^.is_used) Then
+             With LTable^[Pai_Label(p)^.l^.nb-LoLab] Do
 {$IfDef AnalyzeLoops}
               If (RefsFound = Pai_Label(p)^.l^.RefCount)
 {$Else AnalyzeLoops}
@@ -1394,7 +1402,8 @@ Begin
           end;
         ait_label:
           Begin
-            LTable^[Pai_Label(P)^.l^.nb-LoLab].InstrNr := NrOfPaiObjs
+            If (Pai_Label(p)^.l^.is_used) Then
+              LTable^[Pai_Label(P)^.l^.nb-LoLab].InstrNr := NrOfPaiObjs
           End;
 {        ait_instruction:
           Begin
@@ -1456,7 +1465,10 @@ End.
 
 {
  $Log$
- Revision 1.10  1998-09-09 15:33:58  peter
+ Revision 1.11  1998-09-15 14:05:27  jonas
+   * fixed optimizer incompatibilities with freelabel code in psub
+
+ Revision 1.10  1998/09/09 15:33:58  peter
    * removed warnings
 
  Revision 1.9  1998/09/03 16:24:51  florian

+ 12 - 9
compiler/popt386.pas

@@ -111,11 +111,11 @@ Begin
             If (pai_labeled(p)^._operator = A_JMP) Then
               Begin
                 hp1 := pai(p^.next);
-                While Assigned(hp1) and (hp1^.typ <> ait_label) Do
+                While GetNextInstruction(p, hp1) and
+                      (hp1^.typ <> ait_label) Do
                   Begin
                     AsmL^.Remove(hp1);
                     Dispose(hp1, done);
-                    hp1 := pai(p^.next);
                   End;
                End;
             If GetNextInstruction(p, hp1) then
@@ -156,8 +156,8 @@ Begin
                       If (pai_label(hp2)^.l^.refcount = 0) Then
                         Begin
                           pai_label(hp2)^.l^.is_used := False;
-                          AsmL^.remove(hp2);
-                          Dispose(hp2, done);
+{                          AsmL^.remove(hp2);
+                          Dispose(hp2, done);}
                         End;
                       pai_labeled(p)^.lab:=pai_labeled(hp1)^.lab;
                       Inc(pai_labeled(p)^.lab^.refcount);
@@ -172,11 +172,11 @@ Begin
                           hp2:=pai(hp1^.next);
                           asml^.remove(p);
                           dispose(p,done);
-                          If Not(pai_label(hp1)^.l^.is_used) Then
+{                          If Not(pai_label(hp1)^.l^.is_used) Then
                             Begin
                               AsmL^.remove(hp1);
                               Dispose(hp1, done);
-                            End;
+                            End;}
                           p:=hp2;
                           continue;
                         end;
@@ -1265,7 +1265,7 @@ Begin
                  End;
             End;
           End;
-        ait_label:
+{        ait_label:
           Begin
             If Not(Pai_Label(p)^.l^.is_used)
               Then
@@ -1276,7 +1276,7 @@ Begin
                   p := hp1;
                   Continue
                 End;
-          End;
+          End;}
 {$ifdef regalloc}
         ait_regalloc: UsedRegs := UsedRegs + [PaiAlloc(p)^.Reg];
         ait_regdealloc: UsedRegs := UsedRegs - [PaiAlloc(p)^.Reg];
@@ -1360,7 +1360,10 @@ End.
 
 {
  $Log$
- Revision 1.11  1998-08-28 10:57:02  peter
+ Revision 1.12  1998-09-15 14:05:22  jonas
+   * fixed optimizer incompatibilities with freelabel code in psub
+
+ Revision 1.11  1998/08/28 10:57:02  peter
    * removed warnings
 
  Revision 1.10  1998/08/27 15:17:50  florian