From ec900bc2008119712860f836dd41816b43bf61f0 Mon Sep 17 00:00:00 2001 From: uz Date: Sat, 23 Jun 2012 17:33:31 +0000 Subject: [PATCH] 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 --- src/cc65/codeopt.c | 67 +++++++++-------------------------------- src/cc65/coptc02.c | 22 ++------------ src/cc65/coptcmp.c | 8 +---- src/cc65/coptind.c | 36 ---------------------- src/cc65/coptneg.c | 18 ----------- src/cc65/coptptrload.c | 12 -------- src/cc65/coptptrstore.c | 12 -------- src/cc65/coptpush.c | 20 +++--------- src/cc65/coptsize.c | 14 +-------- src/cc65/coptstop.c | 6 ---- src/cc65/coptstore.c | 16 ++-------- src/cc65/copttest.c | 8 +---- 12 files changed, 26 insertions(+), 213 deletions(-) diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index c83e965cb..1d944e203 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -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); diff --git a/src/cc65/coptc02.c b/src/cc65/coptc02.c index bffb5acc8..a45025ee5 100644 --- a/src/cc65/coptc02.c +++ b/src/cc65/coptc02.c @@ -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; } diff --git a/src/cc65/coptcmp.c b/src/cc65/coptcmp.c index bdaa929c1..b99c1a69a 100644 --- a/src/cc65/coptcmp.c +++ b/src/cc65/coptcmp.c @@ -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; } diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c index 10f747ce4..34cdea8d5 100644 --- a/src/cc65/coptind.c +++ b/src/cc65/coptind.c @@ -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; } diff --git a/src/cc65/coptneg.c b/src/cc65/coptneg.c index 8fd89b97d..a25556a01 100644 --- a/src/cc65/coptneg.c +++ b/src/cc65/coptneg.c @@ -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; } diff --git a/src/cc65/coptptrload.c b/src/cc65/coptptrload.c index 78905d8d5..479010b88 100644 --- a/src/cc65/coptptrload.c +++ b/src/cc65/coptptrload.c @@ -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; } diff --git a/src/cc65/coptptrstore.c b/src/cc65/coptptrstore.c index 6292fb832..95689b4ac 100644 --- a/src/cc65/coptptrstore.c +++ b/src/cc65/coptptrstore.c @@ -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; } diff --git a/src/cc65/coptpush.c b/src/cc65/coptpush.c index 2a26d7cca..54b54fc03 100644 --- a/src/cc65/coptpush.c +++ b/src/cc65/coptpush.c @@ -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; } diff --git a/src/cc65/coptsize.c b/src/cc65/coptsize.c index 3e54280de..fcb15854e 100644 --- a/src/cc65/coptsize.c +++ b/src/cc65/coptsize.c @@ -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; } diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index bc099a56c..85824b64d 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -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; } diff --git a/src/cc65/coptstore.c b/src/cc65/coptstore.c index 5deb2a39f..d5dad45e4 100644 --- a/src/cc65/coptstore.c +++ b/src/cc65/coptstore.c @@ -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; } diff --git a/src/cc65/copttest.c b/src/cc65/copttest.c index bc1279840..89ca80760 100644 --- a/src/cc65/copttest.c +++ b/src/cc65/copttest.c @@ -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; } -- 2.39.5