Browse Source

Properly do NR_DEFAULTFLAGS detection/allocation/deallocation

git-svn-id: branches/laksen/arm-embedded@22787 -
Jeppe Johansen 12 years ago
parent
commit
5751bbecee
1 changed files with 21 additions and 31 deletions
  1. 21 31
      compiler/arm/aoptcpu.pas

+ 21 - 31
compiler/arm/aoptcpu.pas

@@ -61,9 +61,6 @@ Type
   end;
 
   TCpuThumb2AsmOptimizer = class(TCpuAsmOptimizer)
-  private
-    function RegAllocated(hp: tai; areg: TRegister): boolean;
-  public
     { uses the same constructor as TAopObj }
     function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
     procedure PeepHoleOptPass2;override;
@@ -1748,28 +1745,6 @@ Implementation
         end;
     end;
 
-  function TCpuThumb2AsmOptimizer.RegAllocated(hp: tai; areg: TRegister): boolean;
-    var
-      p: tai;
-    begin
-      result := true;
-      p := hp;
-      while assigned(p) do
-        begin
-          if (p.typ=ait_regalloc) and
-             (tai_regalloc(p).reg = areg) then
-            begin
-              if tai_regalloc(p).ratype = ra_alloc then
-                exit(false)
-              else if tai_regalloc(p).ratype = ra_dealloc then
-                exit;
-            end;
-
-          p := tai(p.Next);
-        end;
-      result := false;
-    end;
-
   function TCpuThumb2AsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
     var
       hp : taicpu;
@@ -1833,16 +1808,22 @@ Implementation
         (taicpu(p).oper[1]^.typ=top_const) and
         (taicpu(p).oper[1]^.val >= 0) and
         (taicpu(p).oper[1]^.val < 256) and
-        (not RegAllocated(p, NR_DEFAULTFLAGS)) then
+        (not RegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs)) then
         begin
+          asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
+          asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,p), p);
+          IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
           taicpu(p).oppostfix:=PF_S;
           result:=true;
         end
       else if (p.typ=ait_instruction) and
-        MatchInstruction(p, A_MVN, [], [PF_None]) and
+        MatchInstruction(p, A_MVN, [C_None], [PF_None]) and
         (taicpu(p).oper[1]^.typ=top_reg) and
-        (not RegAllocated(p, NR_DEFAULTFLAGS)) then
+        (not RegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs)) then
         begin
+          asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
+          asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,p), p);
+          IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
           taicpu(p).oppostfix:=PF_S;
           result:=true;
         end
@@ -1854,8 +1835,11 @@ Implementation
         (taicpu(p).oper[2]^.typ=top_const) and
         (taicpu(p).oper[2]^.val >= 0) and
         (taicpu(p).oper[2]^.val < 256) and
-        (not RegAllocated(p, NR_DEFAULTFLAGS)) then
+        (not RegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs)) then
         begin
+          asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
+          asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,p), p);
+          IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
           taicpu(p).loadconst(1,taicpu(p).oper[2]^.val);
           taicpu(p).oppostfix:=PF_S;
           taicpu(p).ops := 2;
@@ -1866,8 +1850,11 @@ Implementation
         (taicpu(p).ops = 3) and
         MatchOperand(taicpu(p).oper[0]^, taicpu(p).oper[1]^) and
         (taicpu(p).oper[2]^.typ=top_reg) and
-        (not RegAllocated(p, NR_DEFAULTFLAGS)) then
+        (not RegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs)) then
         begin
+          asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
+          asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,p), p);
+          IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
           taicpu(p).ops := 2;
           taicpu(p).loadreg(1,taicpu(p).oper[2]^.reg);
           taicpu(p).oppostfix:=PF_S;
@@ -1877,8 +1864,11 @@ Implementation
         MatchInstruction(p, [A_AND,A_ORR,A_EOR], [], [PF_None,PF_S]) and
         (taicpu(p).ops = 3) and
         MatchOperand(taicpu(p).oper[0]^, taicpu(p).oper[2]^) and
-        (not RegAllocated(p, NR_DEFAULTFLAGS)) then
+        (not RegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs)) then
         begin
+          asml.InsertBefore(tai_regalloc.alloc(NR_DEFAULTFLAGS,p), p);
+          asml.InsertAfter(tai_regalloc.dealloc(NR_DEFAULTFLAGS,p), p);
+          IncludeRegInUsedRegs(NR_DEFAULTFLAGS,UsedRegs);
           taicpu(p).oppostfix:=PF_S;
           taicpu(p).ops := 2;
           result:=true;