Selaa lähdekoodia

+ FindRegAllocBackward
* search reg. allocations backward in RemoveSuperfluousMove because the changed instruction could be the first one in a list

git-svn-id: trunk@25289 -

florian 12 vuotta sitten
vanhempi
commit
2806947a8f
2 muutettua tiedostoa jossa 40 lisäystä ja 4 poistoa
  1. 39 2
      compiler/aoptobj.pas
  2. 1 2
      compiler/arm/aoptcpu.pas

+ 39 - 2
compiler/aoptobj.pas

@@ -289,13 +289,23 @@ Unit AoptObj;
         { returns true if the operands o1 and o2 are completely equal }
         { returns true if the operands o1 and o2 are completely equal }
         Function OpsEqual(const o1,o2:toper): Boolean;
         Function OpsEqual(const o1,o2:toper): Boolean;
 
 
-        { Returns the next ait_alloc object with ratype ra_dealloc for
+        { Returns the next ait_alloc object with ratype ra_alloc for
           Reg is found in the block
           Reg is found in the block
           of Tai's starting with StartPai and ending with the next "real"
           of Tai's starting with StartPai and ending with the next "real"
           instruction. If none is found, it returns
           instruction. If none is found, it returns
-          nil                                                                        }
+          nil
+        }
         Function FindRegAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
         Function FindRegAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
 
 
+        { Returns the last ait_alloc object with ratype ra_alloc for
+          Reg is found in the block
+          of Tai's starting with StartPai and ending with the next "real"
+          instruction. If none is found, it returns
+          nil
+        }
+        Function FindRegAllocBackward(Reg : TRegister; StartPai : Tai) : tai_regalloc;
+
+
         { Returns the next ait_alloc object with ratype ra_dealloc
         { Returns the next ait_alloc object with ratype ra_dealloc
           for Reg which is found in the block of Tai's starting with StartPai
           for Reg which is found in the block of Tai's starting with StartPai
           and ending with the next "real" instruction. If none is found, it returns
           and ending with the next "real" instruction. If none is found, it returns
@@ -1048,6 +1058,33 @@ Unit AoptObj;
       End;
       End;
 
 
 
 
+      Function TAOptObj.FindRegAllocBackward(Reg: TRegister; StartPai: Tai): tai_regalloc;
+      Begin
+        Result:=nil;
+        Repeat
+          While Assigned(StartPai) And
+                ((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or
+                 ((StartPai.typ = ait_label) and
+                  Not(Tai_Label(StartPai).labsym.Is_Used))) Do
+            StartPai := Tai(StartPai.Previous);
+          If Assigned(StartPai) And
+             (StartPai.typ = ait_regAlloc) Then
+            Begin
+              if (tai_regalloc(StartPai).ratype=ra_alloc) and
+                (getregtype(tai_regalloc(StartPai).Reg) = getregtype(Reg)) and
+                (getsupreg(tai_regalloc(StartPai).Reg) = getsupreg(Reg)) then
+               begin
+                 Result:=tai_regalloc(StartPai);
+                 exit;
+               end;
+              StartPai := Tai(StartPai.Previous);
+            End
+          else
+            exit;
+        Until false;
+      End;
+
+
       function TAOptObj.FindRegDeAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
       function TAOptObj.FindRegDeAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
       Begin
       Begin
          Result:=nil;
          Result:=nil;

+ 1 - 2
compiler/arm/aoptcpu.pas

@@ -375,9 +375,8 @@ Implementation
 
 
               { taicpu(p).oper[0]^.reg is not used anymore, try to find its allocation
               { taicpu(p).oper[0]^.reg is not used anymore, try to find its allocation
                 and remove it if possible }
                 and remove it if possible }
-              GetLastInstruction(p,hp1);
               asml.Remove(dealloc);
               asml.Remove(dealloc);
-              alloc:=FindRegAlloc(taicpu(p).oper[0]^.reg,tai(hp1.Next));
+              alloc:=FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.previous));
               if assigned(alloc) then
               if assigned(alloc) then
                 begin
                 begin
                   asml.Remove(alloc);
                   asml.Remove(alloc);