瀏覽代碼

* patch by J. Gareth Moreton: get rid of another pass through the assembler list by integrating OptReferences
into the post optimizer pass

git-svn-id: trunk@44001 -

florian 5 年之前
父節點
當前提交
16152cf948
共有 4 個文件被更改,包括 26 次插入40 次删除
  1. 7 9
      compiler/i386/aoptcpu.pas
  2. 5 8
      compiler/i8086/aoptcpu.pas
  3. 8 16
      compiler/x86/aoptx86.pas
  4. 6 7
      compiler/x86_64/aoptcpu.pas

+ 7 - 9
compiler/i386/aoptcpu.pas

@@ -39,8 +39,6 @@ unit aoptcpu;
         function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
         function PeepHoleOptPass2Cpu(var p: tai): boolean; override;
         function PostPeepHoleOptsCpu(var p : tai) : boolean; override;
-
-        procedure PostPeepHoleOpts; override;
       end;
 
     Var
@@ -299,6 +297,7 @@ unit aoptcpu;
                                       taicpu(p).opcode := A_MOV;
                                       taicpu(p).changeopsize(S_B);
                                       setsubreg(taicpu(p).oper[1]^.reg,R_SUBL);
+                                      Result := True;
                                     end;
                                 end;
                               else
@@ -320,6 +319,7 @@ unit aoptcpu;
                               taicpu(p).changeopsize(S_B);
                               setsubreg(taicpu(p).oper[1]^.reg,R_SUBL);
                               InsertLLItem(p.previous, p, hp1);
+                              Result := True;
                             end;
                    end;
                 A_TEST, A_OR:
@@ -329,6 +329,11 @@ unit aoptcpu;
                 else
                   ;
               end;
+
+              { Optimise any reference-type operands (if Result is True, the
+                instruction will be checked on the next iteration) }
+              if not Result then
+                OptimizeRefs(taicpu(p));
             end;
           else
             ;
@@ -336,13 +341,6 @@ unit aoptcpu;
       end;
 
 
-    procedure TCpuAsmOptimizer.PostPeepHoleOpts;
-      begin
-        inherited;
-        OptReferences;
-      end;
-
-
 begin
   casmoptimizer:=TCpuAsmOptimizer;
 end.

+ 5 - 8
compiler/i8086/aoptcpu.pas

@@ -37,7 +37,6 @@ unit aoptcpu;
       TCpuAsmOptimizer = class(TX86AsmOptimizer)
         function PeepHoleOptPass1Cpu(var p : tai) : boolean; override;
         function PostPeepHoleOptsCpu(var p : tai) : boolean; override;
-        procedure PostPeepHoleOpts; override;
       End;
 
   Implementation
@@ -166,19 +165,17 @@ unit aoptcpu;
                 else
                   ;
               end;
+
+              { Optimise any reference-type operands (if Result is True, the
+                instruction will be checked on the next iteration) }
+              if not Result then
+                OptimizeRefs(taicpu(p));
             end;
           else
             ;
         end;
       end;
 
-
-    procedure TCpuAsmOptimizer.PostPeepHoleOpts;
-      begin
-        inherited;
-        OptReferences;
-      end;
-
 begin
   casmoptimizer:=TCpuAsmOptimizer;
 end.

+ 8 - 16
compiler/x86/aoptx86.pas

@@ -94,9 +94,10 @@ unit aoptx86;
         function PostPeepholeOptCall(var p : tai) : Boolean;
         function PostPeepholeOptLea(var p : tai) : Boolean;
 
-        procedure OptReferences;
-
         procedure ConvertJumpToRET(const p: tai; const ret_p: tai);
+
+        { Processor-dependent reference optimisation }
+        class procedure OptimizeRefs(var p: taicpu); static;
       end;
 
     function MatchInstruction(const instr: tai; const op: TAsmOp; const opsize: topsizes): boolean;
@@ -5310,22 +5311,13 @@ unit aoptx86;
 {$endif}
 
 
-    procedure TX86AsmOptimizer.OptReferences;
+    class procedure TX86AsmOptimizer.OptimizeRefs(var p: taicpu);
       var
-        p: tai;
-        i: Integer;
+        OperIdx: Integer;
       begin
-        p := BlockStart;
-        while (p <> BlockEnd) Do
-          begin
-            if p.typ=ait_instruction then
-              begin
-                for i:=0 to taicpu(p).ops-1 do
-                  if taicpu(p).oper[i]^.typ=top_ref then
-                    optimize_ref(taicpu(p).oper[i]^.ref^,false);
-              end;
-            p:=tai(p.next);
-          end;
+        for OperIdx := 0 to p.ops - 1 do
+          if p.oper[OperIdx]^.typ = top_ref then
+            optimize_ref(p.oper[OperIdx]^.ref^, False);
       end;
 
 end.

+ 6 - 7
compiler/x86_64/aoptcpu.pas

@@ -35,7 +35,6 @@ type
     function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
     function PeepHoleOptPass2Cpu(var p: tai): boolean; override;
     function PostPeepHoleOptsCpu(var p : tai) : boolean; override;
-    procedure PostPeepHoleOpts; override;
   end;
 
 implementation
@@ -192,6 +191,12 @@ uses
                 else
                   ;
               end;
+
+              { Optimise any reference-type operands (if Result is True, the
+                instruction will be checked on the next iteration) }
+              if not Result then
+                OptimizeRefs(taicpu(p));
+
             end;
           else
             ;
@@ -199,12 +204,6 @@ uses
       end;
 
 
-    procedure TCpuAsmOptimizer.PostPeepHoleOpts;
-      begin
-        inherited;
-        OptReferences;
-      end;
-
 begin
   casmoptimizer := TCpuAsmOptimizer;
 end.