瀏覽代碼

+ common assembler optimizer base class for powerpc and powerpc64
* factored out TPPCAsmOptimizer.RegLoadedWithNewValue

git-svn-id: trunk@49180 -

florian 4 年之前
父節點
當前提交
f5bd3d81e7
共有 4 個文件被更改,包括 90 次插入51 次删除
  1. 1 0
      .gitattributes
  2. 2 49
      compiler/powerpc/aoptcpu.pas
  3. 2 2
      compiler/powerpc64/aoptcpu.pas
  4. 85 0
      compiler/ppcgen/aoptppc.pas

+ 1 - 0
.gitattributes

@@ -662,6 +662,7 @@ compiler/ppcarm.lpi svneol=native#text/plain
 compiler/ppcavr.lpi svneol=native#text/plain
 compiler/ppcgen/aasmcpu.pas svneol=native#text/plain
 compiler/ppcgen/agppcgas.pas svneol=native#text/plain
+compiler/ppcgen/aoptppc.pas svneol=native#text/pascal
 compiler/ppcgen/cgppc.pas svneol=native#text/plain
 compiler/ppcgen/hlcgppc.pas svneol=native#text/plain
 compiler/ppcgen/ngppcadd.pas svneol=native#text/plain

+ 2 - 49
compiler/powerpc/aoptcpu.pas

@@ -28,12 +28,10 @@ Interface
 
 {$i fpcdefs.inc}
 
-uses cpubase, cgbase, aoptobj, aoptcpub, aopt, aasmtai,aasmdata, aasmcpu;
+uses cpubase, cgbase, aoptobj, aoptcpub, aopt, aasmtai,aasmdata, aasmcpu, aoptppc;
 
 Type
-  TCpuAsmOptimizer = class(TAsmOptimizer)
-    function RegLoadedWithNewValue(reg : tregister; hp : tai) : boolean; override;
-
+  TCpuAsmOptimizer = class(TPPCAsmOptimizer)
     { uses the same constructor as TAopObj }
     function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
 
@@ -48,51 +46,6 @@ Implementation
   uses
     cutils, verbose, cgcpu, cgobj;
 
-  function TCpuAsmOptimizer.RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;
-    var
-      p: taicpu;
-    begin
-      Result := false;
-      if not(assigned(hp) and (hp.typ = ait_instruction)) then
-        exit;
-
-      p := taicpu(hp);
-      if not(p.ops > 0) then
-        exit;
-
-      case p.opcode of
-        A_CMP,
-        A_CMPI,
-        A_CMPL,
-        A_CMPLI:
-          begin
-            result:=reg=NR_CR;
-            exit;
-          end;
-        A_STB,
-        { the register forming the address is modified so no new value is loaded }
-        A_STBU,
-        A_STBUX,
-        A_STBX,
-        A_STH,
-        A_STHBRX,
-        A_STHU,
-        A_STHUX,
-        A_STHX,
-        A_STMW:
-          exit;
-        else
-          ;
-      end;
-      case p.oper[0]^.typ of
-        top_reg:
-          Result := (p.oper[0]^.reg = reg) ;
-        else
-          ;
-      end;
-    end;
-
-
   function TCpuAsmOptimizer.cmpi_mfcr_opt(p, next1, next2: taicpu): boolean;
     var
       next3, prev: tai;

+ 2 - 2
compiler/powerpc64/aoptcpu.pas

@@ -27,10 +27,10 @@ interface
 
 {$I fpcdefs.inc}
 
-uses cpubase, aoptobj, aoptcpub, aopt;
+uses cpubase, aoptobj, aoptcpub, aopt, aoptppc;
 
 type
-  TCpuAsmOptimizer = class(TAsmOptimizer)
+  TCpuAsmOptimizer = class(TPPCAsmOptimizer)
     { uses the same constructor as TAopObj }
   end;
 

+ 85 - 0
compiler/ppcgen/aoptppc.pas

@@ -0,0 +1,85 @@
+{
+    Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
+    Development Team
+
+    This unit implements the generic PowerPC optimizer object
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+Unit aoptppc;
+
+Interface
+
+{$i fpcdefs.inc}
+
+uses cpubase, cgbase, aopt, aasmtai;
+
+Type
+  TPPCAsmOptimizer = class(TAsmOptimizer)
+    function RegLoadedWithNewValue(reg : tregister; hp : tai) : boolean; override;
+ End;
+
+Implementation
+
+  uses
+    cutils, verbose, cgcpu, cgobj, aasmcpu;
+
+  function TPPCAsmOptimizer.RegLoadedWithNewValue(reg: tregister; hp: tai): boolean;
+    var
+      p: taicpu;
+    begin
+      Result := false;
+      if not(assigned(hp) and (hp.typ = ait_instruction)) then
+        exit;
+
+      p := taicpu(hp);
+      if not(p.ops > 0) then
+        exit;
+
+      case p.opcode of
+        A_CMP,
+        A_CMPI,
+        A_CMPL,
+        A_CMPLI:
+          begin
+            result:=reg=NR_CR;
+            exit;
+          end;
+        A_STB,
+        { the register forming the address is modified so no new value is loaded }
+        A_STBU,
+        A_STBUX,
+        A_STBX,
+        A_STH,
+        A_STHBRX,
+        A_STHU,
+        A_STHUX,
+        A_STHX,
+        A_STMW:
+          exit;
+        else
+          ;
+      end;
+      case p.oper[0]^.typ of
+        top_reg:
+          Result := (p.oper[0]^.reg = reg) ;
+        else
+          ;
+      end;
+    end;
+
+End.