Browse Source

* New UpdateUsedRegsBetween utility subroutine

J. Gareth "Curious Kit" Moreton 3 years ago
parent
commit
9ee672f9eb
1 changed files with 19 additions and 0 deletions
  1. 19 0
      compiler/aoptobj.pas

+ 19 - 0
compiler/aoptobj.pas

@@ -274,6 +274,10 @@ Unit AoptObj;
         Procedure UpdateUsedRegs(p : Tai);
         Procedure UpdateUsedRegs(p : Tai);
         class procedure UpdateUsedRegs(var Regs: TAllUsedRegs; p: Tai); static;
         class procedure UpdateUsedRegs(var Regs: TAllUsedRegs; p: Tai); static;
 
 
+        { UpdateUsedRegsBetween updates the given TUsedRegs from p1 to p2 exclusive, calling GetNextInstruction
+          to move between instructions and sending p1.Next to UpdateUsedRegs }
+        class procedure UpdateUsedRegsBetween(var Regs: TAllUsedRegs; p1, p2: Tai); static;
+
         { If UpdateUsedRegsAndOptimize has read ahead, the result is one before
         { If UpdateUsedRegsAndOptimize has read ahead, the result is one before
           the next valid entry (so "p.Next" returns what's expected).  If no
           the next valid entry (so "p.Next" returns what's expected).  If no
           reading ahead happened, then the result is equal to p. }
           reading ahead happened, then the result is equal to p. }
@@ -1118,6 +1122,21 @@ Unit AoptObj;
         end;
         end;
 
 
 
 
+      class procedure TAOptObj.UpdateUsedRegsBetween(var Regs: TAllUsedRegs; p1, p2: Tai); static;
+        var
+          i : TRegisterType;
+        begin
+          while (p1 <> p2) do
+            begin
+              for i:=low(TRegisterType) to high(TRegisterType) do
+                Regs[i].Update(tai(p1.Next));
+
+              if not GetNextInstruction(p1, p1) then
+                InternalError(2022010701);
+            end;
+        end;
+
+
       function TAOptObj.CopyUsedRegs(var dest: TAllUsedRegs): boolean;
       function TAOptObj.CopyUsedRegs(var dest: TAllUsedRegs): boolean;
       var
       var
         i : TRegisterType;
         i : TRegisterType;