1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00

Centralize generation of register infos for a code segment. This means that

all optimizer functions can rely on it.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5733 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2012-06-23 17:33:31 +00:00
parent d5810a818c
commit ec900bc200
12 changed files with 26 additions and 213 deletions

View File

@ -106,9 +106,6 @@ static unsigned OptShift1 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -173,9 +170,6 @@ static unsigned OptShift1 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -194,9 +188,6 @@ static unsigned OptShift2(CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -241,9 +232,6 @@ static unsigned OptShift2(CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -271,9 +259,6 @@ static unsigned OptShift3 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -320,9 +305,6 @@ static unsigned OptShift3 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -337,9 +319,6 @@ static unsigned OptShift4 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -375,9 +354,6 @@ static unsigned OptShift4 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -627,9 +603,6 @@ static unsigned OptLoad1 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -668,9 +641,6 @@ static unsigned OptLoad1 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -683,9 +653,6 @@ static unsigned OptLoad2 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -771,9 +738,6 @@ static unsigned OptLoad2 (CodeSeg* S)
++I;
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -807,9 +771,6 @@ static unsigned OptDecouple (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info for the following step */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -1007,9 +968,6 @@ static unsigned OptDecouple (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -1050,9 +1008,6 @@ static unsigned OptStackPtrOps (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info for the following step */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -1107,9 +1062,6 @@ static unsigned OptStackPtrOps (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -1511,10 +1463,10 @@ static void WriteOptStats (const char* Name)
fprintf (F,
"%-20s %10lu %10lu %10lu %10lu\n",
O->Name,
O->TotalRuns,
O->TotalRuns,
O->LastRuns,
O->TotalChanges,
O->LastChanges);
O->TotalChanges,
O->LastChanges);
}
/* Close the file, ignore errors here. */
@ -1539,7 +1491,7 @@ static unsigned RunOptFunc (CodeSeg* S, OptFunc* F, unsigned Max)
Changes = 0;
do {
/* Run the function */
/* Run the function */
C = F->Func (S);
if (Debug && C > 0) {
printf ("Applied %s: %u changes\n", F->Name, C);
@ -1552,6 +1504,11 @@ static unsigned RunOptFunc (CodeSeg* S, OptFunc* F, unsigned Max)
F->TotalChanges += C;
F->LastChanges += C;
/* If we had changes, regenerate register info */
if (C) {
CS_GenRegInfo (S);
}
} while (--Max && C > 0);
/* Return the number of changes */
@ -1847,6 +1804,9 @@ void RunOpt (CodeSeg* S)
Print (stdout, 1, "Running optimizer for global code segment\n");
}
/* Generate register info for all instructions */
CS_GenRegInfo (S);
/* Run groups of optimizations */
RunOptGroup1 (S);
RunOptGroup2 (S);
@ -1856,6 +1816,9 @@ void RunOpt (CodeSeg* S)
RunOptGroup6 (S);
RunOptGroup7 (S);
/* Free register info */
CS_FreeRegInfo (S);
/* Write statistics */
if (StatFileName) {
WriteOptStats (StatFileName);

View File

@ -6,8 +6,8 @@
/* */
/* */
/* */
/* (C) 2001-2005, Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* (C) 2001-2012, Ullrich von Bassewitz */
/* Roeerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@ -67,9 +67,6 @@ unsigned Opt65C02Ind (CodeSeg* S)
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)) {
@ -98,9 +95,6 @@ unsigned Opt65C02Ind (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -113,9 +107,6 @@ unsigned Opt65C02BitOps (CodeSeg* S)
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)) {
@ -176,9 +167,6 @@ unsigned Opt65C02BitOps (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -191,9 +179,6 @@ unsigned Opt65C02Stores (CodeSeg* S)
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)) {
@ -226,9 +211,6 @@ unsigned Opt65C02Stores (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2001-2009, Ullrich von Bassewitz */
/* (C) 2001-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -785,9 +785,6 @@ unsigned OptCmp8 (CodeSeg* S)
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)) {
@ -884,9 +881,6 @@ NextEntry:
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -794,9 +794,6 @@ unsigned OptJumpTarget3 (CodeSeg* S)
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)) {
@ -864,9 +861,6 @@ unsigned OptJumpTarget3 (CodeSeg* S)
++I;
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -980,9 +974,6 @@ unsigned OptCondBranches2 (CodeSeg* S)
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)) {
@ -1019,9 +1010,6 @@ unsigned OptCondBranches2 (CodeSeg* S)
++I;
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -1150,9 +1138,6 @@ unsigned OptDupLoads (CodeSeg* S)
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)) {
@ -1341,9 +1326,6 @@ unsigned OptDupLoads (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -2019,9 +2001,6 @@ unsigned OptPrecalc (CodeSeg* S)
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)) {
@ -2138,9 +2117,6 @@ unsigned OptPrecalc (CodeSeg* S)
++I;
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -2235,9 +2211,6 @@ unsigned OptIndLoads1 (CodeSeg* S)
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)) {
@ -2265,9 +2238,6 @@ unsigned OptIndLoads1 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -2289,9 +2259,6 @@ unsigned OptIndLoads2 (CodeSeg* S)
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)) {
@ -2319,9 +2286,6 @@ unsigned OptIndLoads2 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -174,9 +174,6 @@ unsigned OptBNegAX1 (CodeSeg* S)
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)) {
@ -200,9 +197,6 @@ unsigned OptBNegAX1 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -436,9 +430,6 @@ unsigned OptNegAX1 (CodeSeg* S)
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)) {
@ -476,9 +467,6 @@ unsigned OptNegAX1 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -502,9 +490,6 @@ unsigned OptNegAX2 (CodeSeg* S)
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)) {
@ -566,9 +551,6 @@ unsigned OptNegAX2 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -683,9 +683,6 @@ unsigned OptPtrLoad7 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -833,9 +830,6 @@ unsigned OptPtrLoad7 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -1165,9 +1159,6 @@ unsigned OptPtrLoad14 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -1213,9 +1204,6 @@ unsigned OptPtrLoad14 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -266,9 +266,6 @@ unsigned OptPtrStore1 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -379,9 +376,6 @@ unsigned OptPtrStore1 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -442,9 +436,6 @@ unsigned OptPtrStore2 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -627,9 +618,6 @@ unsigned OptPtrStore2 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2001-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* (C) 2001-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -63,9 +63,6 @@ unsigned OptPush1 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -110,9 +107,6 @@ unsigned OptPush1 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -134,9 +128,6 @@ unsigned OptPush2 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -172,9 +163,6 @@ unsigned OptPush2 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2002-2009, Ullrich von Bassewitz */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -881,9 +881,6 @@ unsigned OptSize1 (CodeSeg* S)
/* Are we optimizing for size */
int OptForSize = (S->CodeSizeFactor < 100);
/* Generate register info for the following step */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -942,9 +939,6 @@ unsigned OptSize1 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -960,9 +954,6 @@ unsigned OptSize2 (CodeSeg* S)
unsigned Changes = 0;
unsigned I;
/* Generate register info for the following step */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -1040,9 +1031,6 @@ unsigned OptSize2 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -1753,9 +1753,6 @@ unsigned OptStackOps (CodeSeg* S)
} State = Initialize;
/* Generate register info */
CS_GenRegInfo (S);
/* Remember the code segment in the info struct */
Data.Code = S;
@ -1942,9 +1939,6 @@ unsigned OptStackOps (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -6,8 +6,8 @@
/* */
/* */
/* */
/* (C) 2002-2006, Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* (C) 2002-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
@ -115,9 +115,6 @@ unsigned OptStore2 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -173,9 +170,6 @@ unsigned OptStore2 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}
@ -191,9 +185,6 @@ unsigned OptStore3 (CodeSeg* S)
unsigned I;
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
I = 0;
while (I < CS_GetEntryCount (S)) {
@ -318,9 +309,6 @@ unsigned OptStore3 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}

View File

@ -6,7 +6,7 @@
/* */
/* */
/* */
/* (C) 2001-2009, Ullrich von Bassewitz */
/* (C) 2001-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
@ -70,9 +70,6 @@ unsigned OptTest1 (CodeSeg* S)
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)) {
@ -126,9 +123,6 @@ unsigned OptTest1 (CodeSeg* S)
}
/* Free register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}