From f5bd3d81e78881e7311d4642ac4d41445b0d86d9 Mon Sep 17 00:00:00 2001 From: florian <florian@freepascal.org> Date: Sun, 11 Apr 2021 17:30:20 +0000 Subject: [PATCH] + common assembler optimizer base class for powerpc and powerpc64 * factored out TPPCAsmOptimizer.RegLoadedWithNewValue git-svn-id: trunk@49180 - --- .gitattributes | 1 + compiler/powerpc/aoptcpu.pas | 51 +------------------- compiler/powerpc64/aoptcpu.pas | 4 +- compiler/ppcgen/aoptppc.pas | 85 ++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 compiler/ppcgen/aoptppc.pas diff --git a/.gitattributes b/.gitattributes index 3f6367c2f2..95144bce98 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/powerpc/aoptcpu.pas b/compiler/powerpc/aoptcpu.pas index 513bbd4416..90b29175d5 100644 --- a/compiler/powerpc/aoptcpu.pas +++ b/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; diff --git a/compiler/powerpc64/aoptcpu.pas b/compiler/powerpc64/aoptcpu.pas index bd96f25524..6f9e840304 100644 --- a/compiler/powerpc64/aoptcpu.pas +++ b/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; diff --git a/compiler/ppcgen/aoptppc.pas b/compiler/ppcgen/aoptppc.pas new file mode 100644 index 0000000000..6c2dcbb7db --- /dev/null +++ b/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.