Added 65C02 specific optimizations.
Make two runs over the code when generating register info to get info for backward jumps right. git-svn-id: svn://svn.cc65.org/cc65/trunk@1049 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
1483fa741a
commit
2435aa63b5
6 changed files with 403 additions and 193 deletions
|
@ -48,6 +48,7 @@
|
|||
#include "codeent.h"
|
||||
#include "codeinfo.h"
|
||||
#include "coptadd.h"
|
||||
#include "coptc02.h"
|
||||
#include "coptcmp.h"
|
||||
#include "coptind.h"
|
||||
#include "coptneg.h"
|
||||
|
@ -1349,6 +1350,7 @@ struct OptFunc {
|
|||
#define OptFuncEntry(func) static OptFuncDesc D##func = { func, #func, 0 }
|
||||
|
||||
/* A list of all the function descriptions */
|
||||
static OptFunc DOpt65C02Ind = { Opt65C02Ind, "Opt65C02Ind", 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptAdd1 = { OptAdd1, "OptAdd1", 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptAdd2 = { OptAdd2, "OptAdd2", 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptAdd3 = { OptAdd3, "OptAdd3", 0, 0, 0, 0, 0 };
|
||||
|
@ -1401,6 +1403,7 @@ static OptFunc DOptUnusedStores = { OptUnusedStores, "OptUnusedStores", 0, 0, 0,
|
|||
|
||||
/* Table containing all the steps in alphabetical order */
|
||||
static OptFunc* OptFuncs[] = {
|
||||
&DOpt65C02Ind,
|
||||
&DOptAdd1,
|
||||
&DOptAdd2,
|
||||
&DOptAdd3,
|
||||
|
@ -1750,7 +1753,24 @@ static void RunOptGroup3 (CodeSeg* S)
|
|||
|
||||
|
||||
static void RunOptGroup4 (CodeSeg* S)
|
||||
/* The last group of optimization steps. Adjust branches.
|
||||
/* 65C02 specific optimizations. */
|
||||
{
|
||||
if (CPU < CPU_65C02) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Replace (zp),y by (zp) if Y is zero. If we have changes, run register
|
||||
* load optimization again, since loads of Y may have become unnecessary.
|
||||
*/
|
||||
if (RunOptFunc (S, &DOpt65C02Ind, 1) > 0) {
|
||||
RunOptFunc (S, &DOptUnusedLoads, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void RunOptGroup5 (CodeSeg* S)
|
||||
/* The last group of optimization steps. Adjust branches, do size optimizations.
|
||||
*/
|
||||
{
|
||||
/* Optimize for size, that is replace operations by shorter ones, even
|
||||
|
@ -1805,6 +1825,7 @@ void RunOpt (CodeSeg* S)
|
|||
RunOptGroup2 (S);
|
||||
RunOptGroup3 (S);
|
||||
RunOptGroup4 (S);
|
||||
RunOptGroup5 (S);
|
||||
|
||||
/* Write statistics */
|
||||
if (StatFileName) {
|
||||
|
|
|
@ -1109,16 +1109,23 @@ void CS_GenRegInfo (CodeSeg* S)
|
|||
RegContents Regs; /* Initial register contents */
|
||||
RegContents* CurrentRegs; /* Current register contents */
|
||||
int WasJump; /* True if last insn was a jump */
|
||||
int Done; /* All runs done flag */
|
||||
|
||||
/* Be sure to delete all register infos */
|
||||
CS_FreeRegInfo (S);
|
||||
|
||||
/* We may need two runs to get back references right */
|
||||
do {
|
||||
|
||||
/* Assume we're done after this run */
|
||||
Done = 1;
|
||||
|
||||
/* On entry, the register contents are unknown */
|
||||
RC_Invalidate (&Regs);
|
||||
CurrentRegs = &Regs;
|
||||
|
||||
/* First pass. Walk over all insns and note just the changes from one
|
||||
* insn to the next one.
|
||||
/* Walk over all insns and note just the changes from one insn to the
|
||||
* next one.
|
||||
*/
|
||||
WasJump = 0;
|
||||
for (I = 0; I < CS_GetEntryCount (S); ++I) {
|
||||
|
@ -1160,7 +1167,13 @@ void CS_GenRegInfo (CodeSeg* S)
|
|||
/* Get this entry */
|
||||
CodeEntry* J = CL_GetRef (Label, Entry);
|
||||
if (J->RI == 0) {
|
||||
/* No register info for this entry, bail out */
|
||||
/* No register info for this entry. This means that the
|
||||
* instruction that jumps here is at higher addresses and
|
||||
* the jump is a backward jump. We need a second run to
|
||||
* get the register info right in this case. Until then,
|
||||
* assume unknown register contents.
|
||||
*/
|
||||
Done = 0;
|
||||
RC_Invalidate (&Regs);
|
||||
break;
|
||||
}
|
||||
|
@ -1320,6 +1333,8 @@ void CS_GenRegInfo (CodeSeg* S)
|
|||
}
|
||||
}
|
||||
}
|
||||
} while (!Done);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
110
src/cc65/coptc02.c
Normal file
110
src/cc65/coptc02.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*****************************************************************************/
|
||||
/* */
|
||||
/* coptc02.h */
|
||||
/* */
|
||||
/* 65C02 specific optimizations */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
/* warranty. In no event will the authors be held liable for any damages */
|
||||
/* arising from the use of this software. */
|
||||
/* */
|
||||
/* Permission is granted to anyone to use this software for any purpose, */
|
||||
/* including commercial applications, and to alter it and redistribute it */
|
||||
/* freely, subject to the following restrictions: */
|
||||
/* */
|
||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||
/* claim that you wrote the original software. If you use this software */
|
||||
/* in a product, an acknowledgment in the product documentation would be */
|
||||
/* appreciated but is not required. */
|
||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||
/* be misrepresented as being the original software. */
|
||||
/* 3. This notice may not be removed or altered from any source */
|
||||
/* distribution. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* cc65 */
|
||||
#include "codeent.h"
|
||||
#include "codeinfo.h"
|
||||
#include "error.h"
|
||||
#include "coptc02.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Helper functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
unsigned Opt65C02Ind (CodeSeg* S)
|
||||
/* Try to use the indirect addressing mode where possible */
|
||||
{
|
||||
unsigned Changes = 0;
|
||||
unsigned I;
|
||||
|
||||
/* Generate register info for this step */
|
||||
CS_GenRegInfo (S);
|
||||
|
||||
/* Walk over the entries */
|
||||
I = 0;
|
||||
while (I < CS_GetEntryCount (S)) {
|
||||
|
||||
/* Get next entry */
|
||||
CodeEntry* E = CS_GetEntry (S, I);
|
||||
|
||||
/* Check for addressing mode indirect indexed Y where Y is zero.
|
||||
* Note: All opcodes that are available as (zp),y are also available
|
||||
* as (zp), so we can ignore the actual opcode here.
|
||||
*/
|
||||
if (E->AM == AM65_ZP_INDY && E->RI->In.RegY == 0) {
|
||||
|
||||
/* Replace it by indirect addressing mode */
|
||||
CodeEntry* X = NewCodeEntry (E->OPC, AM65_ZP_IND, E->Arg, 0, E->LI);
|
||||
CS_InsertEntry (S, X, I+1);
|
||||
CS_DelEntry (S, I);
|
||||
|
||||
/* We had changes */
|
||||
++Changes;
|
||||
|
||||
}
|
||||
|
||||
/* Next entry */
|
||||
++I;
|
||||
|
||||
}
|
||||
|
||||
/* Free register info */
|
||||
CS_FreeRegInfo (S);
|
||||
|
||||
/* Return the number of changes made */
|
||||
return Changes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
61
src/cc65/coptc02.h
Normal file
61
src/cc65/coptc02.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*****************************************************************************/
|
||||
/* */
|
||||
/* coptc02.h */
|
||||
/* */
|
||||
/* 65C02 specific optimizations */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2001 Ullrich von Bassewitz */
|
||||
/* Wacholderweg 14 */
|
||||
/* D-70597 Stuttgart */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
/* warranty. In no event will the authors be held liable for any damages */
|
||||
/* arising from the use of this software. */
|
||||
/* */
|
||||
/* Permission is granted to anyone to use this software for any purpose, */
|
||||
/* including commercial applications, and to alter it and redistribute it */
|
||||
/* freely, subject to the following restrictions: */
|
||||
/* */
|
||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||
/* claim that you wrote the original software. If you use this software */
|
||||
/* in a product, an acknowledgment in the product documentation would be */
|
||||
/* appreciated but is not required. */
|
||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||
/* be misrepresented as being the original software. */
|
||||
/* 3. This notice may not be removed or altered from any source */
|
||||
/* distribution. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef COPTC02_H
|
||||
#define COPTC02_H
|
||||
|
||||
|
||||
|
||||
/* cc65 */
|
||||
#include "codeseg.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
unsigned Opt65C02Ind (CodeSeg* S);
|
||||
/* Try to use the indirect addressing mode where possible */
|
||||
|
||||
|
||||
|
||||
/* End of coptc02.h */
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ OBJS = anonname.o \
|
|||
codeseg.o \
|
||||
compile.o \
|
||||
coptadd.o \
|
||||
coptc02.o \
|
||||
coptcmp.o \
|
||||
coptind.o \
|
||||
coptneg.o \
|
||||
|
|
|
@ -80,6 +80,7 @@ OBJS = anonname.obj \
|
|||
codeseg.obj \
|
||||
compile.obj \
|
||||
coptadd.obj \
|
||||
coptc02.obj \
|
||||
coptcmp.obj \
|
||||
coptind.obj \
|
||||
coptneg.obj \
|
||||
|
@ -157,6 +158,7 @@ FILE codeopt.obj
|
|||
FILE codeseg.obj
|
||||
FILE compile.obj
|
||||
FILE coptadd.obj
|
||||
FILE coptc02.obj
|
||||
FILE coptcmp.obj
|
||||
FILE coptind.obj
|
||||
FILE coptneg.obj
|
||||
|
|
Loading…
Add table
Reference in a new issue