瀏覽代碼

* comments and explanations on tai_regalloc.keep field
* write/read tai_regalloc. field to/from ppu

git-svn-id: trunk@22190 -

florian 13 年之前
父節點
當前提交
e1a2b1859a
共有 2 個文件被更改,包括 14 次插入3 次删除
  1. 3 0
      compiler/aasmtai.pas
  2. 11 3
      compiler/aopt.pas

+ 3 - 0
compiler/aasmtai.pas

@@ -644,6 +644,7 @@ interface
        tai_regalloc = class(tai)
           reg     : tregister;
           ratype  : TRegAllocType;
+          { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
           keep    : boolean;
           { reg(de)alloc belongs to this instruction, this
             is only used for automatic inserted (de)alloc for
@@ -2103,6 +2104,7 @@ implementation
         inherited ppuload(t,ppufile);
         ppufile.getdata(reg,sizeof(Tregister));
         ratype:=tregalloctype(ppufile.getbyte);
+        keep:=boolean(ppufile.getbyte);
       end;
 
 
@@ -2111,6 +2113,7 @@ implementation
         inherited ppuwrite(ppufile);
         ppufile.putdata(reg,sizeof(Tregister));
         ppufile.putbyte(byte(ratype));
+        ppufile.putbyte(byte(keep));
       end;
 
 

+ 11 - 3
compiler/aopt.pas

@@ -189,6 +189,7 @@ Unit aopt;
                               GetNextInstruction(hp1, hp1) And
                               RegInInstruction(tai_regalloc(p).Reg, hp1) Do
                           hp2 := hp1;
+                        { move deallocations }
                         If hp2 <> nil Then
                           Begin
                             hp1 := tai(p.previous);
@@ -197,14 +198,23 @@ Unit aopt;
 {$endif DEBUG_OPTALLOC}
                             AsmL.Remove(p);
                             InsertLLItem(hp2, tai(hp2.Next), p);
+                            { don't remove this deallocation later on when merging dealloc/alloc pairs because
+                              it marks indenpendent use of a register
+
+                              This could be also achieved by a separate passes for merging first and then later
+                              moving but I did not choose this solution because it takes more time and code (FK) }
                             tai_regalloc(p).keep:=true;
 {$ifdef DEBUG_OPTALLOC}
                             AsmL.InsertAfter(tai_comment.Create(strpnew('Moved deallocation of '+std_regname(tai_regalloc(p).Reg)+' here')),hp2);
 {$endif DEBUG_OPTALLOC}
                             p := hp1;
                           End
+                        { merge allocations/deallocations }
                         else if findregalloc(tai_regalloc(p).reg, tai(p.next))
-                          and getnextinstruction(p,hp1) and not(tai_regalloc(p).keep) then
+                          and getnextinstruction(p,hp1) and
+                          { don't merge deallocations/allocation which mark a new use of register, this
+                            enables more possibilities for the peephole optimizer }
+                          not(tai_regalloc(p).keep) then
                           begin
                             hp1 := tai(p.previous);
 {$ifdef DEBUG_OPTALLOC}
@@ -213,8 +223,6 @@ Unit aopt;
                             AsmL.remove(p);
                             p.free;
                             p := hp1;
-      //                      don't include here, since then the allocation will be removed when it's processed
-      //                      include(usedregs,supreg);
                           end;
                       End
                   End