Browse Source

+ TAOptObj.*PeepHoleOpts* check if p is really assigned
+ TAOptObj.RemoveCurrentP

git-svn-id: trunk@38488 -

florian 7 years ago
parent
commit
ae950956af
1 changed files with 37 additions and 8 deletions
  1. 37 8
      compiler/aoptobj.pas

+ 37 - 8
compiler/aoptobj.pas

@@ -326,6 +326,9 @@ Unit AoptObj;
           reloaded with a new value or it is deallocated afterwards }
           reloaded with a new value or it is deallocated afterwards }
         function RegEndOfLife(reg: TRegister;p: taicpu): boolean;
         function RegEndOfLife(reg: TRegister;p: taicpu): boolean;
 
 
+        { removes p from asml, updates registers and replaces it by a valid value, if this is the case true is returned }
+        function RemoveCurrentP(var p : taicpu): boolean;
+
        { traces sucessive jumps to their final destination and sets it, e.g.
        { traces sucessive jumps to their final destination and sets it, e.g.
          je l1                je l3
          je l1                je l3
          <code>               <code>
          <code>               <code>
@@ -1286,6 +1289,20 @@ Unit AoptObj;
       end;
       end;
 
 
 
 
+    function TAOptObj.RemoveCurrentP(var p : taicpu) : boolean;
+      var
+        hp1 : tai;
+      begin
+        result:=GetNextInstruction(p,hp1);
+        { p will be removed, update used register as we continue
+          with the next instruction after p }
+        UpdateUsedRegs(tai(p.Next));
+        AsmL.Remove(p);
+        p.Free;
+        p:=taicpu(hp1);
+      end;
+
+
     function FindAnyLabel(hp: tai; var l: tasmlabel): Boolean;
     function FindAnyLabel(hp: tai; var l: tasmlabel): Boolean;
       begin
       begin
         FindAnyLabel := false;
         FindAnyLabel := false;
@@ -1477,8 +1494,11 @@ Unit AoptObj;
             UpdateUsedRegs(tai(p.next));
             UpdateUsedRegs(tai(p.next));
             if PrePeepHoleOptsCpu(p) then
             if PrePeepHoleOptsCpu(p) then
               continue;
               continue;
-            UpdateUsedRegs(p);
-            p:=tai(p.next);
+            if assigned(p) then
+              begin
+                UpdateUsedRegs(p);
+                p:=tai(p.next);
+              end;
           end;
           end;
       end;
       end;
 
 
@@ -1633,8 +1653,11 @@ Unit AoptObj;
                       end; { if is_jmp }
                       end; { if is_jmp }
                   end;
                   end;
               end;
               end;
-              UpdateUsedRegs(p);
-              p:=tai(p.next);
+              if assigned(p) then
+                begin
+                  UpdateUsedRegs(p);
+                  p:=tai(p.next);
+                end;
             end;
             end;
         until stoploop or not(cs_opt_level3 in current_settings.optimizerswitches);
         until stoploop or not(cs_opt_level3 in current_settings.optimizerswitches);
       end;
       end;
@@ -1651,8 +1674,11 @@ Unit AoptObj;
             UpdateUsedRegs(tai(p.next));
             UpdateUsedRegs(tai(p.next));
             if PeepHoleOptPass2Cpu(p) then
             if PeepHoleOptPass2Cpu(p) then
               continue;
               continue;
-            UpdateUsedRegs(p);
-            p:=tai(p.next);
+            if assigned(p) then
+              begin
+                UpdateUsedRegs(p);
+                p:=tai(p.next);
+              end;
           end;
           end;
       end;
       end;
 
 
@@ -1668,8 +1694,11 @@ Unit AoptObj;
             UpdateUsedRegs(tai(p.next));
             UpdateUsedRegs(tai(p.next));
             if PostPeepHoleOptsCpu(p) then
             if PostPeepHoleOptsCpu(p) then
               continue;
               continue;
-            UpdateUsedRegs(p);
-            p:=tai(p.next);
+            if assigned(p) then
+              begin
+                UpdateUsedRegs(p);
+                p:=tai(p.next);
+              end;
           end;
           end;
       end;
       end;