Browse Source

* finer granularity for allocation of reused/replaced registers

Jonas Maebe 24 years ago
parent
commit
97c1152c6d
1 changed files with 13 additions and 4 deletions
  1. 13 4
      compiler/i386/rropt386.pas

+ 13 - 4
compiler/i386/rropt386.pas

@@ -184,7 +184,7 @@ end;
 function switchRegs(asml: TAAsmoutput; reg1, reg2: tregister; start: Tai): Boolean;
 function switchRegs(asml: TAAsmoutput; reg1, reg2: tregister; start: Tai): Boolean;
 { change movl  %reg1,%reg2 ... bla ... to ... bla with reg1 and reg2 switched }
 { change movl  %reg1,%reg2 ... bla ... to ... bla with reg1 and reg2 switched }
 var
 var
-  endP, hp: Tai;
+  endP, hp, lastreg1,lastreg2: Tai;
   switchDone, switchLast, tmpResult, sequenceEnd, reg1Modified, reg2Modified: boolean;
   switchDone, switchLast, tmpResult, sequenceEnd, reg1Modified, reg2Modified: boolean;
   reg1StillUsed, reg2StillUsed, isInstruction: boolean;
   reg1StillUsed, reg2StillUsed, isInstruction: boolean;
 begin
 begin
@@ -263,6 +263,8 @@ begin
       switchRegs := true;
       switchRegs := true;
       reg1Modified := false;
       reg1Modified := false;
       reg2Modified := false;
       reg2Modified := false;
+      lastreg1 := start;
+      lastreg2 := start;
       getNextInstruction(start,hp);
       getNextInstruction(start,hp);
       while hp <> endP do
       while hp <> endP do
         begin
         begin
@@ -285,13 +287,17 @@ begin
                 else
                 else
                   doReplaceReg(Taicpu(hp),reg2,reg1);
                   doReplaceReg(Taicpu(hp),reg2,reg1);
             end;
             end;
+          if regininstruction(reg1,hp) then
+             lastreg1 := hp;
+          if regininstruction(reg2,hp) then
+             lastreg2 := hp;
           getNextInstruction(hp,hp);
           getNextInstruction(hp,hp);
         end;
         end;
       if switchLast then
       if switchLast then
         doSwitchReg(Taicpu(hp),reg1,reg2)
         doSwitchReg(Taicpu(hp),reg1,reg2)
       else getLastInstruction(hp,hp);
       else getLastInstruction(hp,hp);
-      allocRegBetween(asmL,reg1,start,hp);
-      allocRegBetween(asmL,reg2,start,hp);
+      allocRegBetween(asmL,reg1,start,lastreg1);
+      allocRegBetween(asmL,reg2,start,lastreg2);
     end;
     end;
 end;
 end;
 
 
@@ -338,7 +344,10 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.7  2001-08-29 14:07:43  jonas
+  Revision 1.8  2001-10-12 13:55:03  jonas
+    * finer granularity for allocation of reused/replaced registers
+
+  Revision 1.7  2001/08/29 14:07:43  jonas
     * the optimizer now keeps track of flags register usage. This fixes some
     * the optimizer now keeps track of flags register usage. This fixes some
       optimizer bugs with int64 calculations (because of the carry flag usage)
       optimizer bugs with int64 calculations (because of the carry flag usage)
     * fixed another bug which caused wrong optimizations with complex
     * fixed another bug which caused wrong optimizations with complex