1 /*****************************************************************************/
5 /* Optimizer subroutines */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
63 /*****************************************************************************/
65 /*****************************************************************************/
69 static unsigned OptShift1 (CodeSeg* S)
70 /* A call to the shlaxN routine may get replaced by one or more asl insns
71 * if the value of X is not used later.
76 /* Walk over the entries */
78 while (I < CS_GetEntryCount (S)) {
81 CodeEntry* E = CS_GetEntry (S, I);
83 /* Check for the sequence */
84 if (E->OPC == OP65_JSR &&
85 (strncmp (E->Arg, "shlax", 5) == 0 ||
86 strncmp (E->Arg, "aslax", 5) == 0) &&
87 strlen (E->Arg) == 6 &&
88 IsDigit (E->Arg[5]) &&
91 /* Insert shift insns */
92 unsigned Count = E->Arg[5] - '0';
94 CodeEntry* X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI);
95 CS_InsertEntry (S, X, I+1);
98 /* Delete the call to shlax */
101 /* Remember, we had changes */
111 /* Return the number of changes made */
117 /*****************************************************************************/
118 /* nega optimizations */
119 /*****************************************************************************/
123 static unsigned OptNegA1 (CodeSeg* S)
130 * Remove the ldx if the lda does not use it.
133 unsigned Changes = 0;
135 /* Walk over the entries */
137 while (I < CS_GetEntryCount (S)) {
142 CodeEntry* E = CS_GetEntry (S, I);
144 /* Check for a ldx */
145 if (E->OPC == OP65_LDX &&
147 (E->Flags & CEF_NUMARG) != 0 &&
149 CS_GetEntries (S, L, I+1, 2) &&
150 L[0]->OPC == OP65_LDA &&
151 (L[0]->Use & REG_X) == 0 &&
152 !CE_HasLabel (L[0]) &&
153 CE_IsCall (L[1], "bnega") &&
154 !CE_HasLabel (L[1])) {
156 /* Remove the ldx instruction */
159 /* Remember, we had changes */
169 /* Return the number of changes made */
175 static unsigned OptNegA2 (CodeSeg* S)
182 * Adjust the conditional branch and remove the call to the subroutine.
185 unsigned Changes = 0;
187 /* Walk over the entries */
189 while (I < CS_GetEntryCount (S)) {
194 CodeEntry* E = CS_GetEntry (S, I);
196 /* Check for the sequence */
197 if ((E->OPC == OP65_ADC ||
198 E->OPC == OP65_AND ||
199 E->OPC == OP65_DEA ||
200 E->OPC == OP65_EOR ||
201 E->OPC == OP65_INA ||
202 E->OPC == OP65_LDA ||
203 E->OPC == OP65_ORA ||
204 E->OPC == OP65_PLA ||
205 E->OPC == OP65_SBC ||
206 E->OPC == OP65_TXA ||
207 E->OPC == OP65_TYA) &&
208 CS_GetEntries (S, L, I+1, 2) &&
209 CE_IsCall (L[0], "bnega") &&
210 !CE_HasLabel (L[0]) &&
211 (L[1]->Info & OF_ZBRA) != 0 &&
212 !CE_HasLabel (L[1])) {
214 /* Invert the branch */
215 CE_ReplaceOPC (L[1], GetInverseBranch (L[1]->OPC));
217 /* Delete the subroutine call */
218 CS_DelEntry (S, I+1);
220 /* Remember, we had changes */
230 /* Return the number of changes made */
236 /*****************************************************************************/
237 /* negax optimizations */
238 /*****************************************************************************/
242 static unsigned OptNegAX1 (CodeSeg* S)
243 /* On a call to bnegax, if X is zero, the result depends only on the value in
244 * A, so change the call to a call to bnega. This will get further optimized
248 unsigned Changes = 0;
251 /* Generate register info for this step */
254 /* Walk over the entries */
256 while (I < CS_GetEntryCount (S)) {
259 CodeEntry* E = CS_GetEntry (S, I);
261 /* Check if this is a call to bnegax, and if X is known and zero */
262 if (E->RI->In.RegX == 0 &&
263 CE_IsCall (E, "bnegax")) {
265 /* We're cheating somewhat here ... */
278 /* Free register info */
281 /* Return the number of changes made */
287 static unsigned OptNegAX2 (CodeSeg* S)
288 /* Search for the sequence:
305 unsigned Changes = 0;
307 /* Walk over the entries */
309 while (I < CS_GetEntryCount (S)) {
314 CodeEntry* E = CS_GetEntry (S, I);
316 /* Check for the sequence */
317 if (E->OPC == OP65_LDA &&
318 E->AM == AM65_ZP_INDY &&
319 CS_GetEntries (S, L, I+1, 5) &&
320 L[0]->OPC == OP65_TAX &&
321 L[1]->OPC == OP65_DEY &&
322 L[2]->OPC == OP65_LDA &&
323 L[2]->AM == AM65_ZP_INDY &&
324 strcmp (L[2]->Arg, E->Arg) == 0 &&
325 !CE_HasLabel (L[2]) &&
326 CE_IsCall (L[3], "bnegax") &&
327 !CE_HasLabel (L[3]) &&
328 (L[4]->Info & OF_ZBRA) != 0 &&
329 !CE_HasLabel (L[4])) {
332 CE_ReplaceOPC (L[2], OP65_ORA);
334 /* Invert the branch */
335 CE_ReplaceOPC (L[4], GetInverseBranch (L[4]->OPC));
337 /* Delete the entries no longer needed. Beware: Deleting entries
338 * will change the indices.
340 CS_DelEntry (S, I+4); /* jsr bnegax */
341 CS_DelEntry (S, I+1); /* tax */
343 /* Remember, we had changes */
353 /* Return the number of changes made */
359 static unsigned OptNegAX3 (CodeSeg* S)
360 /* Search for the sequence:
374 unsigned Changes = 0;
376 /* Walk over the entries */
378 while (I < CS_GetEntryCount (S)) {
383 CodeEntry* E = CS_GetEntry (S, I);
385 /* Check for the sequence */
386 if (E->OPC == OP65_LDA &&
387 CS_GetEntries (S, L, I+1, 3) &&
388 L[0]->OPC == OP65_LDX &&
389 !CE_HasLabel (L[0]) &&
390 CE_IsCall (L[1], "bnegax") &&
391 !CE_HasLabel (L[1]) &&
392 (L[2]->Info & OF_ZBRA) != 0 &&
393 !CE_HasLabel (L[2])) {
396 CE_ReplaceOPC (L[0], OP65_ORA);
398 /* Invert the branch */
399 CE_ReplaceOPC (L[2], GetInverseBranch (L[2]->OPC));
401 /* Delete the subroutine call */
402 CS_DelEntry (S, I+2);
404 /* Remember, we had changes */
414 /* Return the number of changes made */
420 static unsigned OptNegAX4 (CodeSeg* S)
421 /* Search for the sequence:
434 unsigned Changes = 0;
436 /* Walk over the entries */
438 while (I < CS_GetEntryCount (S)) {
443 CodeEntry* E = CS_GetEntry (S, I);
445 /* Check for the sequence */
446 if (E->OPC == OP65_JSR &&
447 CS_GetEntries (S, L, I+1, 2) &&
448 L[0]->OPC == OP65_JSR &&
449 strncmp (L[0]->Arg,"bnega",5) == 0 &&
450 !CE_HasLabel (L[0]) &&
451 (L[1]->Info & OF_ZBRA) != 0 &&
452 !CE_HasLabel (L[1])) {
456 /* Check if we're calling bnega or bnegax */
457 int ByteSized = (strcmp (L[0]->Arg, "bnega") == 0);
459 /* Insert apropriate test code */
462 X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, L[0]->LI);
463 CS_InsertEntry (S, X, I+2);
466 X = NewCodeEntry (OP65_STX, AM65_ZP, "tmp1", 0, L[0]->LI);
467 CS_InsertEntry (S, X, I+2);
468 X = NewCodeEntry (OP65_ORA, AM65_ZP, "tmp1", 0, L[0]->LI);
469 CS_InsertEntry (S, X, I+3);
472 /* Delete the subroutine call */
473 CS_DelEntry (S, I+1);
475 /* Invert the branch */
476 CE_ReplaceOPC (L[1], GetInverseBranch (L[1]->OPC));
478 /* Remember, we had changes */
488 /* Return the number of changes made */
494 /*****************************************************************************/
495 /* Optimize stores through pointers */
496 /*****************************************************************************/
500 static unsigned OptPtrStore1Sub (CodeSeg* S, unsigned I, CodeEntry** const L)
501 /* Check if this is one of the allowed suboperation for OptPtrStore1 */
503 /* Check for a label attached to the entry */
504 if (CE_HasLabel (L[0])) {
508 /* Check for single insn sub ops */
509 if (L[0]->OPC == OP65_AND ||
510 L[0]->OPC == OP65_EOR ||
511 L[0]->OPC == OP65_ORA ||
512 (L[0]->OPC == OP65_JSR && strncmp (L[0]->Arg, "shlax", 5) == 0) ||
513 (L[0]->OPC == OP65_JSR && strncmp (L[0]->Arg, "shrax", 5) == 0)) {
518 } else if (L[0]->OPC == OP65_CLC &&
519 (L[1] = CS_GetNextEntry (S, I)) != 0 &&
520 L[1]->OPC == OP65_ADC &&
521 !CE_HasLabel (L[1])) {
523 } else if (L[0]->OPC == OP65_SEC &&
524 (L[1] = CS_GetNextEntry (S, I)) != 0 &&
525 L[1]->OPC == OP65_SBC &&
526 !CE_HasLabel (L[1])) {
538 static unsigned OptPtrStore1 (CodeSeg* S)
539 /* Search for the sequence:
560 unsigned Changes = 0;
562 /* Walk over the entries */
564 while (I < CS_GetEntryCount (S)) {
570 L[0] = CS_GetEntry (S, I);
572 /* Check for the sequence */
573 if (CE_IsCall (L[0], "pushax") &&
574 CS_GetEntries (S, L+1, I+1, 3) &&
575 L[1]->OPC == OP65_LDY &&
576 CE_KnownImm (L[1]) &&
577 !CE_HasLabel (L[1]) &&
578 CE_IsCall (L[2], "ldauidx") &&
579 !CE_HasLabel (L[2]) &&
580 (K = OptPtrStore1Sub (S, I+3, L+3)) > 0 &&
581 CS_GetEntries (S, L+3+K, I+3+K, 2) &&
582 L[3+K]->OPC == OP65_LDY &&
583 CE_KnownImm (L[3+K]) &&
584 !CE_HasLabel (L[3+K]) &&
585 CE_IsCall (L[4+K], "staspidx") &&
586 !CE_HasLabel (L[4+K])) {
590 /* Create and insert the stores */
591 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
592 CS_InsertEntry (S, X, I+1);
594 X = NewCodeEntry (OP65_STX, AM65_ZP, "ptr1+1", 0, L[0]->LI);
595 CS_InsertEntry (S, X, I+2);
597 /* Delete the call to pushax */
600 /* Delete the call to ldauidx */
601 CS_DelEntry (S, I+3);
603 /* Insert the load from ptr1 */
604 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
605 CS_InsertEntry (S, X, I+3);
606 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[2]->LI);
607 CS_InsertEntry (S, X, I+4);
609 /* Insert the store through ptr1 */
610 X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "ptr1", 0, L[3]->LI);
611 CS_InsertEntry (S, X, I+6+K);
613 /* Delete the call to staspidx */
614 CS_DelEntry (S, I+7+K);
616 /* Remember, we had changes */
626 /* Return the number of changes made */
632 static unsigned OptPtrStore2 (CodeSeg* S)
633 /* Search for the sequence:
649 unsigned Changes = 0;
651 /* Walk over the entries */
653 while (I < CS_GetEntryCount (S)) {
658 L[0] = CS_GetEntry (S, I);
660 /* Check for the sequence */
661 if (CE_IsCall (L[0], "pushax") &&
662 CS_GetEntries (S, L+1, I+1, 3) &&
663 L[1]->OPC == OP65_LDA &&
664 !CE_HasLabel (L[1]) &&
665 L[2]->OPC == OP65_LDY &&
666 !CE_HasLabel (L[2]) &&
667 CE_IsCall (L[3], "staspidx") &&
668 !CE_HasLabel (L[3])) {
672 /* Create and insert the stores */
673 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
674 CS_InsertEntry (S, X, I+1);
676 X = NewCodeEntry (OP65_STX, AM65_ZP, "ptr1+1", 0, L[0]->LI);
677 CS_InsertEntry (S, X, I+2);
679 /* Delete the call to pushax */
682 /* Insert the store through ptr1 */
683 X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "ptr1", 0, L[3]->LI);
684 CS_InsertEntry (S, X, I+4);
686 /* Delete the call to staspidx */
687 CS_DelEntry (S, I+5);
689 /* Remember, we had changes */
699 /* Return the number of changes made */
705 /*****************************************************************************/
706 /* Optimize loads through pointers */
707 /*****************************************************************************/
711 static unsigned OptPtrLoad1 (CodeSeg* S)
712 /* Search for the sequence:
716 * lda (sp),y # May be any destination
731 unsigned Changes = 0;
733 /* Walk over the entries */
735 while (I < CS_GetEntryCount (S)) {
740 L[0] = CS_GetEntry (S, I);
742 /* Check for the sequence */
743 if (L[0]->OPC == OP65_TAX &&
744 CS_GetEntries (S, L+1, I+1, 4) &&
745 L[1]->OPC == OP65_DEY &&
746 !CE_HasLabel (L[1]) &&
747 L[2]->OPC == OP65_LDA &&
748 !CE_HasLabel (L[2]) &&
749 L[3]->OPC == OP65_LDY &&
750 !CE_HasLabel (L[3]) &&
751 CE_IsCall (L[4], "ldauidx") &&
752 !CE_HasLabel (L[4])) {
756 /* Store the high byte and remove the TAX instead */
757 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1+1", 0, L[0]->LI);
758 CS_InsertEntry (S, X, I+1);
761 /* Store the low byte */
762 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[2]->LI);
763 CS_InsertEntry (S, X, I+3);
765 /* Delete the call to ldauidx */
766 CS_DelEntry (S, I+5);
768 /* Load high and low byte */
769 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[3]->LI);
770 CS_InsertEntry (S, X, I+5);
771 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[3]->LI);
772 CS_InsertEntry (S, X, I+6);
774 /* Remember, we had changes */
784 /* Return the number of changes made */
790 static unsigned OptPtrLoad2 (CodeSeg* S)
791 /* Search for the sequence:
814 unsigned Changes = 0;
816 /* Walk over the entries */
818 while (I < CS_GetEntryCount (S)) {
823 L[0] = CS_GetEntry (S, I);
825 /* Check for the sequence */
826 if (L[0]->OPC == OP65_ADC &&
827 CS_GetEntries (S, L+1, I+1, 7) &&
828 L[1]->OPC == OP65_TAY &&
829 !CE_HasLabel (L[1]) &&
830 L[2]->OPC == OP65_TXA &&
831 !CE_HasLabel (L[2]) &&
832 L[3]->OPC == OP65_ADC &&
833 !CE_HasLabel (L[3]) &&
834 L[4]->OPC == OP65_TAX &&
835 !CE_HasLabel (L[4]) &&
836 L[5]->OPC == OP65_TYA &&
837 !CE_HasLabel (L[5]) &&
838 L[6]->OPC == OP65_LDY &&
839 !CE_HasLabel (L[6]) &&
840 CE_IsCall (L[7], "ldauidx") &&
841 !CE_HasLabel (L[7])) {
845 /* Store the low byte and remove the TAY instead */
846 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
847 CS_InsertEntry (S, X, I+1);
848 CS_DelEntry (S, I+2);
850 /* Store the high byte */
851 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1+1", 0, L[3]->LI);
852 CS_InsertEntry (S, X, I+4);
854 /* Delete more transfer insns */
855 CS_DelEntry (S, I+6);
856 CS_DelEntry (S, I+5);
858 /* Delete the call to ldauidx */
859 CS_DelEntry (S, I+6);
861 /* Load high and low byte */
862 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[6]->LI);
863 CS_InsertEntry (S, X, I+6);
864 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[6]->LI);
865 CS_InsertEntry (S, X, I+7);
867 /* Remember, we had changes */
877 /* Return the number of changes made */
883 static unsigned OptPtrLoad3 (CodeSeg* S)
884 /* Search for the sequence:
909 unsigned Changes = 0;
911 /* Walk over the entries */
913 while (I < CS_GetEntryCount (S)) {
918 L[0] = CS_GetEntry (S, I);
920 /* Check for the sequence */
921 if (L[0]->OPC == OP65_ADC &&
922 CS_GetEntries (S, L+1, I+1, 8) &&
923 L[1]->OPC == OP65_PHA &&
924 !CE_HasLabel (L[1]) &&
925 L[2]->OPC == OP65_TXA &&
926 !CE_HasLabel (L[2]) &&
927 L[3]->OPC == OP65_INY &&
928 !CE_HasLabel (L[3]) &&
929 L[4]->OPC == OP65_ADC &&
930 !CE_HasLabel (L[4]) &&
931 L[5]->OPC == OP65_TAX &&
932 !CE_HasLabel (L[5]) &&
933 L[6]->OPC == OP65_PLA &&
934 !CE_HasLabel (L[6]) &&
935 L[7]->OPC == OP65_LDY &&
936 !CE_HasLabel (L[7]) &&
937 CE_IsCall (L[8], "ldauidx") &&
938 !CE_HasLabel (L[8])) {
942 /* Store the low byte and remove the PHA instead */
943 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
944 CS_InsertEntry (S, X, I+1);
945 CS_DelEntry (S, I+2);
947 /* Store the high byte */
948 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1+1", 0, L[4]->LI);
949 CS_InsertEntry (S, X, I+5);
951 /* Delete more transfer and PLA insns */
952 CS_DelEntry (S, I+7);
953 CS_DelEntry (S, I+6);
955 /* Delete the call to ldauidx */
956 CS_DelEntry (S, I+7);
958 /* Load high and low byte */
959 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[6]->LI);
960 CS_InsertEntry (S, X, I+7);
961 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[6]->LI);
962 CS_InsertEntry (S, X, I+8);
964 /* Remember, we had changes */
974 /* Return the number of changes made */
980 static unsigned OptPtrLoad4 (CodeSeg* S)
981 /* Search for the sequence:
999 unsigned Changes = 0;
1001 /* Walk over the entries */
1003 while (I < CS_GetEntryCount (S)) {
1008 /* Get next entry */
1009 L[0] = CS_GetEntry (S, I);
1011 /* Check for the sequence */
1012 if (L[0]->OPC == OP65_LDA &&
1013 L[0]->AM == AM65_IMM &&
1014 CS_GetEntries (S, L+1, I+1, 7) &&
1015 L[1]->OPC == OP65_LDX &&
1016 L[1]->AM == AM65_IMM &&
1017 !CE_HasLabel (L[1]) &&
1018 L[2]->OPC == OP65_CLC &&
1019 !CE_HasLabel (L[2]) &&
1020 L[3]->OPC == OP65_ADC &&
1021 (L[3]->AM == AM65_ABS || L[3]->AM == AM65_ZP) &&
1022 !CE_HasLabel (L[3]) &&
1023 (L[4]->OPC == OP65_BCC || L[4]->OPC == OP65_JCC) &&
1024 L[4]->JumpTo != 0 &&
1025 L[4]->JumpTo->Owner == L[6] &&
1026 !CE_HasLabel (L[4]) &&
1027 L[5]->OPC == OP65_INX &&
1028 !CE_HasLabel (L[5]) &&
1029 L[6]->OPC == OP65_LDY &&
1030 CE_KnownImm (L[6]) &&
1032 CE_IsCall (L[7], "ldauidx") &&
1033 !CE_HasLabel (L[7]) &&
1034 /* Check the label last because this is quite costly */
1035 (Len = strlen (L[0]->Arg)) > 3 &&
1036 L[0]->Arg[0] == '<' &&
1037 L[0]->Arg[1] == '(' &&
1038 strlen (L[1]->Arg) == Len &&
1039 L[1]->Arg[0] == '>' &&
1040 memcmp (L[0]->Arg+1, L[1]->Arg+1, Len-1) == 0) {
1045 /* We will create all the new stuff behind the current one so
1046 * we keep the line references.
1048 X = NewCodeEntry (OP65_LDY, L[3]->AM, L[3]->Arg, 0, L[0]->LI);
1049 CS_InsertEntry (S, X, I+8);
1051 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[0]->LI);
1052 CS_InsertEntry (S, X, I+9);
1054 Label = memcpy (xmalloc (Len-2), L[0]->Arg+2, Len-3);
1055 Label[Len-3] = '\0';
1056 X = NewCodeEntry (OP65_LDA, AM65_ABSY, Label, 0, L[0]->LI);
1057 CS_InsertEntry (S, X, I+10);
1060 /* Remove the old code */
1061 CS_DelEntries (S, I, 8);
1063 /* Remember, we had changes */
1073 /* Return the number of changes made */
1079 static unsigned OptPtrLoad5 (CodeSeg* S)
1080 /* Search for the sequence:
1092 * and replace it by:
1101 unsigned Changes = 0;
1103 /* Walk over the entries */
1105 while (I < CS_GetEntryCount (S)) {
1110 /* Get next entry */
1111 L[0] = CS_GetEntry (S, I);
1113 /* Check for the sequence */
1114 if (L[0]->OPC == OP65_LDA &&
1115 L[0]->AM == AM65_IMM &&
1116 CS_GetEntries (S, L+1, I+1, 8) &&
1117 L[1]->OPC == OP65_LDX &&
1118 L[1]->AM == AM65_IMM &&
1119 !CE_HasLabel (L[1]) &&
1120 L[2]->OPC == OP65_LDY &&
1121 CE_KnownImm (L[2]) &&
1122 !CE_HasLabel (L[2]) &&
1123 L[3]->OPC == OP65_CLC &&
1124 !CE_HasLabel (L[3]) &&
1125 L[4]->OPC == OP65_ADC &&
1126 L[4]->AM == AM65_ZP_INDY &&
1127 !CE_HasLabel (L[4]) &&
1128 (L[5]->OPC == OP65_BCC || L[5]->OPC == OP65_JCC) &&
1129 L[5]->JumpTo != 0 &&
1130 L[5]->JumpTo->Owner == L[7] &&
1131 !CE_HasLabel (L[5]) &&
1132 L[6]->OPC == OP65_INX &&
1133 !CE_HasLabel (L[6]) &&
1134 L[7]->OPC == OP65_LDY &&
1135 CE_KnownImm (L[7]) &&
1137 CE_IsCall (L[8], "ldauidx") &&
1138 !CE_HasLabel (L[8]) &&
1139 /* Check the label last because this is quite costly */
1140 (Len = strlen (L[0]->Arg)) > 3 &&
1141 L[0]->Arg[0] == '<' &&
1142 L[0]->Arg[1] == '(' &&
1143 strlen (L[1]->Arg) == Len &&
1144 L[1]->Arg[0] == '>' &&
1145 memcmp (L[0]->Arg+1, L[1]->Arg+1, Len-1) == 0) {
1151 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, L[4]->Arg, 0, L[0]->LI);
1152 CS_InsertEntry (S, X, I+3);
1155 X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, L[0]->LI);
1156 CS_InsertEntry (S, X, I+4);
1159 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[0]->LI);
1160 CS_InsertEntry (S, X, I+5);
1163 Label = memcpy (xmalloc (Len-2), L[0]->Arg+2, Len-3);
1164 Label[Len-3] = '\0';
1165 X = NewCodeEntry (OP65_LDA, AM65_ABSY, Label, 0, L[0]->LI);
1166 CS_InsertEntry (S, X, I+6);
1169 /* Remove the old code */
1170 CS_DelEntries (S, I, 2);
1171 CS_DelEntries (S, I+5, 6);
1173 /* Remember, we had changes */
1183 /* Return the number of changes made */
1189 static unsigned OptPtrLoad6 (CodeSeg* S)
1190 /* Search for the sequence
1195 * and replace it by:
1203 * This step must be execute *after* OptPtrLoad1!
1206 unsigned Changes = 0;
1208 /* Walk over the entries */
1210 while (I < CS_GetEntryCount (S)) {
1214 /* Get next entry */
1215 L[0] = CS_GetEntry (S, I);
1217 /* Check for the sequence */
1218 if (L[0]->OPC == OP65_LDY &&
1219 CS_GetEntries (S, L+1, I+1, 1) &&
1220 CE_IsCall (L[1], "ldauidx") &&
1221 !CE_HasLabel (L[1])) {
1225 /* Store the high byte */
1226 X = NewCodeEntry (OP65_STA, AM65_ZP, "ptr1", 0, L[0]->LI);
1227 CS_InsertEntry (S, X, I+1);
1229 /* Store the low byte */
1230 X = NewCodeEntry (OP65_STX, AM65_ZP, "ptr1+1", 0, L[0]->LI);
1231 CS_InsertEntry (S, X, I+2);
1233 /* Delete the call to ldauidx */
1234 CS_DelEntry (S, I+3);
1236 /* Load the high and low byte */
1237 X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, L[0]->LI);
1238 CS_InsertEntry (S, X, I+3);
1239 X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "ptr1", 0, L[0]->LI);
1240 CS_InsertEntry (S, X, I+4);
1242 /* Remember, we had changes */
1252 /* Return the number of changes made */
1258 /*****************************************************************************/
1259 /* Decouple operations */
1260 /*****************************************************************************/
1264 static unsigned OptDecouple (CodeSeg* S)
1265 /* Decouple operations, that is, do the following replacements:
1276 * Provided that the register values are known of course.
1279 unsigned Changes = 0;
1282 /* Generate register info for the following step */
1285 /* Walk over the entries */
1287 while (I < CS_GetEntryCount (S)) {
1291 /* Get next entry */
1292 CodeEntry* E = CS_GetEntry (S, I);
1294 /* Assume we have no replacement */
1297 /* Check the instruction */
1301 if (E->RI->In.RegX >= 0) {
1302 xsprintf (Buf, sizeof (Buf), "$%02X", (E->RI->In.RegX - 1) & 0xFF);
1303 X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, E->LI);
1308 if (E->RI->In.RegY >= 0) {
1309 xsprintf (Buf, sizeof (Buf), "$%02X", (E->RI->In.RegY - 1) & 0xFF);
1310 X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI);
1315 if (E->RI->In.RegX >= 0) {
1316 xsprintf (Buf, sizeof (Buf), "$%02X", (E->RI->In.RegX + 1) & 0xFF);
1317 X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, E->LI);
1322 if (E->RI->In.RegY >= 0) {
1323 xsprintf (Buf, sizeof (Buf), "$%02X", (E->RI->In.RegY + 1) & 0xFF);
1324 X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI);
1329 if (E->RI->In.RegA >= 0) {
1330 xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegA);
1331 X = NewCodeEntry (OP65_LDX, AM65_IMM, Buf, 0, E->LI);
1336 if (E->RI->In.RegA >= 0) {
1337 xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegA);
1338 X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, E->LI);
1343 if (E->RI->In.RegX >= 0) {
1344 xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegX);
1345 X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, E->LI);
1350 if (E->RI->In.RegY >= 0) {
1351 xsprintf (Buf, sizeof (Buf), "$%02X", E->RI->In.RegY);
1352 X = NewCodeEntry (OP65_LDA, AM65_IMM, Buf, 0, E->LI);
1357 /* Avoid gcc warnings */
1362 /* Insert the replacement if we have one */
1364 CS_InsertEntry (S, X, I+1);
1374 /* Free register info */
1377 /* Return the number of changes made */
1383 /*****************************************************************************/
1384 /* Size optimization */
1385 /*****************************************************************************/
1389 static unsigned OptSize (CodeSeg* S)
1390 /* Do size optimization by using shorter code sequences, even if this
1391 * introduces relations between instructions. This step must be one of the
1392 * last steps, because it makes further work much more difficult.
1395 unsigned Changes = 0;
1398 /* Generate register info for the following step */
1401 /* Walk over the entries */
1403 while (I < CS_GetEntryCount (S)) {
1406 /* Get next entry */
1407 CodeEntry* E = CS_GetEntry (S, I);
1409 /* Assume we have no replacement */
1412 /* Check the instruction */
1416 if (CE_KnownImm (E)) {
1417 short Val = (short) E->Num;
1418 if (Val == E->RI->In.RegX) {
1419 X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, E->LI);
1420 } else if (Val == E->RI->In.RegY) {
1421 X = NewCodeEntry (OP65_TYA, AM65_IMP, 0, 0, E->LI);
1422 } else if (E->RI->In.RegA >= 0 && CPU >= CPU_65C02) {
1423 if (Val == ((E->RI->In.RegA - 1) & 0xFF)) {
1424 X = NewCodeEntry (OP65_DEA, AM65_IMP, 0, 0, E->LI);
1425 } else if (Val == ((E->RI->In.RegA + 1) & 0xFF)) {
1426 X = NewCodeEntry (OP65_INA, AM65_IMP, 0, 0, E->LI);
1433 if (CE_KnownImm (E)) {
1434 short Val = (short) E->Num;
1435 if (E->RI->In.RegX >= 0 && Val == ((E->RI->In.RegX - 1) & 0xFF)) {
1436 X = NewCodeEntry (OP65_DEX, AM65_IMP, 0, 0, E->LI);
1437 } else if (E->RI->In.RegX >= 0 && Val == ((E->RI->In.RegX + 1) & 0xFF)) {
1438 X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI);
1439 } else if (Val == E->RI->In.RegA) {
1440 X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, E->LI);
1446 if (CE_KnownImm (E)) {
1447 short Val = (short) E->Num;
1448 if (E->RI->In.RegY >= 0 && Val == ((E->RI->In.RegY - 1) & 0xFF)) {
1449 X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, E->LI);
1450 } else if (E->RI->In.RegY >= 0 && Val == ((E->RI->In.RegY + 1) & 0xFF)) {
1451 X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, E->LI);
1452 } else if (Val == E->RI->In.RegA) {
1453 X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, E->LI);
1459 /* Avoid gcc warnings */
1464 /* Insert the replacement if we have one */
1466 CS_InsertEntry (S, X, I+1);
1476 /* Free register info */
1479 /* Return the number of changes made */
1485 /*****************************************************************************/
1486 /* struct OptFunc */
1487 /*****************************************************************************/
1491 typedef struct OptFunc OptFunc;
1493 unsigned (*Func) (CodeSeg*); /* Optimizer function */
1494 const char* Name; /* Name of the function/group */
1495 unsigned long TotalRuns; /* Total number of runs */
1496 unsigned long LastRuns; /* Last number of runs */
1497 unsigned long TotalChanges; /* Total number of changes */
1498 unsigned long LastChanges; /* Last number of changes */
1499 char Disabled; /* True if function disabled */
1504 /*****************************************************************************/
1506 /*****************************************************************************/
1510 /* Macro that builds a function description */
1511 #define OptFuncEntry(func) static OptFuncDesc D##func = { func, #func, 0 }
1513 /* A list of all the function descriptions */
1514 static OptFunc DOptAdd1 = { OptAdd1, "OptAdd1", 0, 0, 0, 0, 0 };
1515 static OptFunc DOptAdd2 = { OptAdd2, "OptAdd2", 0, 0, 0, 0, 0 };
1516 static OptFunc DOptAdd3 = { OptAdd3, "OptAdd3", 0, 0, 0, 0, 0 };
1517 static OptFunc DOptBoolTrans = { OptBoolTrans, "OptBoolTrans", 0, 0, 0, 0, 0 };
1518 static OptFunc DOptBranchDist = { OptBranchDist, "OptBranchDist", 0, 0, 0, 0, 0 };
1519 static OptFunc DOptCmp1 = { OptCmp1, "OptCmp1", 0, 0, 0, 0, 0 };
1520 static OptFunc DOptCmp2 = { OptCmp2, "OptCmp2", 0, 0, 0, 0, 0 };
1521 static OptFunc DOptCmp3 = { OptCmp3, "OptCmp3", 0, 0, 0, 0, 0 };
1522 static OptFunc DOptCmp4 = { OptCmp4, "OptCmp4", 0, 0, 0, 0, 0 };
1523 static OptFunc DOptCmp5 = { OptCmp5, "OptCmp5", 0, 0, 0, 0, 0 };
1524 static OptFunc DOptCmp6 = { OptCmp6, "OptCmp6", 0, 0, 0, 0, 0 };
1525 static OptFunc DOptCmp7 = { OptCmp7, "OptCmp7", 0, 0, 0, 0, 0 };
1526 static OptFunc DOptCondBranches = { OptCondBranches, "OptCondBranches", 0, 0, 0, 0, 0 };
1527 static OptFunc DOptDeadCode = { OptDeadCode, "OptDeadCode", 0, 0, 0, 0, 0 };
1528 static OptFunc DOptDeadJumps = { OptDeadJumps, "OptDeadJumps", 0, 0, 0, 0, 0 };
1529 static OptFunc DOptDecouple = { OptDecouple, "OptDecouple", 0, 0, 0, 0, 0 };
1530 static OptFunc DOptDupLoads = { OptDupLoads, "OptDupLoads", 0, 0, 0, 0, 0 };
1531 static OptFunc DOptJumpCascades = { OptJumpCascades, "OptJumpCascades", 0, 0, 0, 0, 0 };
1532 static OptFunc DOptJumpTarget = { OptJumpTarget, "OptJumpTarget", 0, 0, 0, 0, 0 };
1533 static OptFunc DOptRTS = { OptRTS, "OptRTS", 0, 0, 0, 0, 0 };
1534 static OptFunc DOptRTSJumps = { OptRTSJumps, "OptRTSJumps", 0, 0, 0, 0, 0 };
1535 static OptFunc DOptNegA1 = { OptNegA1, "OptNegA1", 0, 0, 0, 0, 0 };
1536 static OptFunc DOptNegA2 = { OptNegA2, "OptNegA2", 0, 0, 0, 0, 0 };
1537 static OptFunc DOptNegAX1 = { OptNegAX1, "OptNegAX1", 0, 0, 0, 0, 0 };
1538 static OptFunc DOptNegAX2 = { OptNegAX2, "OptNegAX2", 0, 0, 0, 0, 0 };
1539 static OptFunc DOptNegAX3 = { OptNegAX3, "OptNegAX3", 0, 0, 0, 0, 0 };
1540 static OptFunc DOptNegAX4 = { OptNegAX4, "OptNegAX4", 0, 0, 0, 0, 0 };
1541 static OptFunc DOptPtrLoad1 = { OptPtrLoad1, "OptPtrLoad1", 0, 0, 0, 0, 0 };
1542 static OptFunc DOptPtrLoad2 = { OptPtrLoad2, "OptPtrLoad2", 0, 0, 0, 0, 0 };
1543 static OptFunc DOptPtrLoad3 = { OptPtrLoad3, "OptPtrLoad3", 0, 0, 0, 0, 0 };
1544 static OptFunc DOptPtrLoad4 = { OptPtrLoad4, "OptPtrLoad4", 0, 0, 0, 0, 0 };
1545 static OptFunc DOptPtrLoad5 = { OptPtrLoad5, "OptPtrLoad5", 0, 0, 0, 0, 0 };
1546 static OptFunc DOptPtrLoad6 = { OptPtrLoad6, "OptPtrLoad6", 0, 0, 0, 0, 0 };
1547 static OptFunc DOptPtrStore1 = { OptPtrStore1, "OptPtrStore1", 0, 0, 0, 0, 0 };
1548 static OptFunc DOptPtrStore2 = { OptPtrStore2, "OptPtrStore2", 0, 0, 0, 0, 0 };
1549 static OptFunc DOptShift1 = { OptShift1, "OptShift1", 0, 0, 0, 0, 0 };
1550 static OptFunc DOptSize = { OptSize, "OptSize", 0, 0, 0, 0, 0 };
1551 static OptFunc DOptStackOps = { OptStackOps, "OptStackOps", 0, 0, 0, 0, 0 };
1552 static OptFunc DOptStoreLoad = { OptStoreLoad, "OptStoreLoad", 0, 0, 0, 0, 0 };
1553 static OptFunc DOptSub1 = { OptSub1, "OptSub1", 0, 0, 0, 0, 0 };
1554 static OptFunc DOptSub2 = { OptSub2, "OptSub2", 0, 0, 0, 0, 0 };
1555 static OptFunc DOptTest1 = { OptTest1, "OptTest1", 0, 0, 0, 0, 0 };
1556 static OptFunc DOptTransfers = { OptTransfers, "OptTransfers", 0, 0, 0, 0, 0 };
1557 static OptFunc DOptUnusedLoads = { OptUnusedLoads, "OptUnusedLoads", 0, 0, 0, 0, 0 };
1558 static OptFunc DOptUnusedStores = { OptUnusedStores, "OptUnusedStores", 0, 0, 0, 0, 0 };
1561 /* Table containing all the steps in alphabetical order */
1562 static OptFunc* OptFuncs[] = {
1609 #define OPTFUNC_COUNT (sizeof(OptFuncs) / sizeof(OptFuncs[0]))
1613 static int CmpOptStep (const void* Key, const void* Func)
1614 /* Compare function for bsearch */
1616 return strcmp (Key, (*(const OptFunc**)Func)->Name);
1621 static OptFunc* FindOptFunc (const char* Name)
1622 /* Find an optimizer step by name in the table and return a pointer. Return
1623 * NULL if no such step is found.
1626 /* Search for the function in the list */
1627 OptFunc** O = bsearch (Name, OptFuncs, OPTFUNC_COUNT, sizeof (OptFuncs[0]), CmpOptStep);
1633 static OptFunc* GetOptFunc (const char* Name)
1634 /* Find an optimizer step by name in the table and return a pointer. Print an
1635 * error and call AbEnd if not found.
1638 /* Search for the function in the list */
1639 OptFunc* F = FindOptFunc (Name);
1642 AbEnd ("Optimization step `%s' not found", Name);
1649 void DisableOpt (const char* Name)
1650 /* Disable the optimization with the given name */
1652 if (strcmp (Name, "any") == 0) {
1654 for (I = 0; I < OPTFUNC_COUNT; ++I) {
1655 OptFuncs[I]->Disabled = 1;
1658 GetOptFunc(Name)->Disabled = 1;
1664 void EnableOpt (const char* Name)
1665 /* Enable the optimization with the given name */
1667 if (strcmp (Name, "any") == 0) {
1669 for (I = 0; I < OPTFUNC_COUNT; ++I) {
1670 OptFuncs[I]->Disabled = 0;
1673 GetOptFunc(Name)->Disabled = 0;
1679 void ListOptSteps (FILE* F)
1680 /* List all optimization steps */
1683 for (I = 0; I < OPTFUNC_COUNT; ++I) {
1684 fprintf (F, "%s\n", OptFuncs[I]->Name);
1690 static void ReadOptStats (const char* Name)
1691 /* Read the optimizer statistics file */
1696 /* Try to open the file */
1697 FILE* F = fopen (Name, "r");
1699 /* Ignore the error */
1703 /* Read and parse the lines */
1705 while (fgets (Buf, sizeof (Buf), F) != 0) {
1713 unsigned long TotalRuns;
1714 unsigned long TotalChanges;
1719 /* Remove trailing white space including the line terminator */
1722 while (Len > 0 && IsSpace (B[Len-1])) {
1727 /* Remove leading whitespace */
1728 while (IsSpace (*B)) {
1732 /* Check for empty and comment lines */
1733 if (*B == '\0' || *B == ';' || *B == '#') {
1737 /* Parse the line */
1738 if (sscanf (B, "%31s %lu %*u %lu %*u", Name, &TotalRuns, &TotalChanges) != 3) {
1743 /* Search for the optimizer step. */
1744 Func = FindOptFunc (Name);
1750 /* Found the step, set the fields */
1751 Func->TotalRuns = TotalRuns;
1752 Func->TotalChanges = TotalChanges;
1756 /* Close the file, ignore errors here. */
1762 static void WriteOptStats (const char* Name)
1763 /* Write the optimizer statistics file */
1767 /* Try to open the file */
1768 FILE* F = fopen (Name, "w");
1770 /* Ignore the error */
1774 /* Write the file */
1775 for (I = 0; I < OPTFUNC_COUNT; ++I) {
1776 const OptFunc* O = OptFuncs[I];
1778 "%-20s %6lu %6lu %6lu %6lu\n",
1786 /* Close the file, ignore errors here. */
1792 static unsigned RunOptFunc (CodeSeg* S, OptFunc* F, unsigned Max)
1793 /* Run one optimizer function Max times or until there are no more changes */
1795 unsigned Changes, C;
1797 /* Don't run the function if it is disabled */
1802 /* Run this until there are no more changes */
1806 /* Run the function */
1813 F->TotalChanges += C;
1814 F->LastChanges += C;
1816 } while (--Max && C > 0);
1818 /* Return the number of changes */
1824 static void RunOptGroup1 (CodeSeg* S)
1825 /* Run the first group of optimization steps. These steps translate known
1826 * patterns emitted by the code generator into more optimal patterns. Order
1827 * of the steps is important, because some of the steps done earlier cover
1828 * the same patterns as later steps as subpatterns.
1831 RunOptFunc (S, &DOptPtrStore1, 1);
1832 RunOptFunc (S, &DOptPtrStore2, 1);
1833 RunOptFunc (S, &DOptPtrLoad1, 1);
1834 RunOptFunc (S, &DOptPtrLoad2, 1);
1835 RunOptFunc (S, &DOptPtrLoad3, 1);
1836 RunOptFunc (S, &DOptPtrLoad4, 1);
1837 RunOptFunc (S, &DOptPtrLoad5, 1);
1838 RunOptFunc (S, &DOptNegAX1, 1);
1839 RunOptFunc (S, &DOptNegAX2, 1);
1840 RunOptFunc (S, &DOptNegAX3, 1);
1841 RunOptFunc (S, &DOptNegAX4, 1);
1842 RunOptFunc (S, &DOptAdd1, 1);
1843 RunOptFunc (S, &DOptAdd2, 1);
1844 RunOptFunc (S, &DOptShift1, 1);
1849 static void RunOptGroup2 (CodeSeg* S)
1850 /* Run one group of optimization steps. This step involves just decoupling
1851 * instructions by replacing them by instructions that do not depend on
1852 * previous instructions. This makes it easier to find instructions that
1856 RunOptFunc (S, &DOptDecouple, 1);
1862 static void RunOptGroup3 (CodeSeg* S)
1863 /* Run one group of optimization steps. These steps depend on each other,
1864 * that means that one step may allow another step to do additional work,
1865 * so we will repeat the steps as long as we see any changes.
1873 Changes += RunOptFunc (S, &DOptPtrLoad6, 1);
1874 Changes += RunOptFunc (S, &DOptNegA1, 1);
1875 Changes += RunOptFunc (S, &DOptNegA2, 1);
1876 Changes += RunOptFunc (S, &DOptSub1, 1);
1877 Changes += RunOptFunc (S, &DOptSub2, 1);
1878 Changes += RunOptFunc (S, &DOptAdd3, 1);
1879 Changes += RunOptFunc (S, &DOptJumpCascades, 1);
1880 Changes += RunOptFunc (S, &DOptDeadJumps, 1);
1881 Changes += RunOptFunc (S, &DOptRTS, 1);
1882 Changes += RunOptFunc (S, &DOptDeadCode, 1);
1883 Changes += RunOptFunc (S, &DOptJumpTarget, 1);
1884 Changes += RunOptFunc (S, &DOptCondBranches, 1);
1885 Changes += RunOptFunc (S, &DOptRTSJumps, 1);
1886 Changes += RunOptFunc (S, &DOptBoolTrans, 1);
1887 Changes += RunOptFunc (S, &DOptCmp1, 1);
1888 Changes += RunOptFunc (S, &DOptCmp2, 1);
1889 Changes += RunOptFunc (S, &DOptCmp3, 1);
1890 Changes += RunOptFunc (S, &DOptCmp4, 1);
1891 Changes += RunOptFunc (S, &DOptCmp5, 1);
1892 Changes += RunOptFunc (S, &DOptCmp6, 1);
1893 Changes += RunOptFunc (S, &DOptCmp7, 1);
1894 Changes += RunOptFunc (S, &DOptTest1, 1);
1895 Changes += RunOptFunc (S, &DOptUnusedLoads, 1);
1896 Changes += RunOptFunc (S, &DOptUnusedStores, 1);
1897 Changes += RunOptFunc (S, &DOptDupLoads, 1);
1898 Changes += RunOptFunc (S, &DOptStoreLoad, 1);
1899 Changes += RunOptFunc (S, &DOptTransfers, 1);
1900 Changes += RunOptFunc (S, &DOptStackOps, 1);
1907 static void RunOptGroup4 (CodeSeg* S)
1908 /* The last group of optimization steps. Adjust branches.
1911 /* Optimize for size, that is replace operations by shorter ones, even
1912 * if this does hinder further optimizations (no problem since we're
1915 RunOptFunc (S, &DOptSize, 1);
1917 /* Run the jump target optimization again, since the size optimization
1918 * above may have opened new oportunities.
1920 RunOptFunc (S, &DOptJumpTarget, 5);
1922 /* Finally, adjust branch distances */
1923 RunOptFunc (S, &DOptBranchDist, 3);
1928 void RunOpt (CodeSeg* S)
1929 /* Run the optimizer */
1931 const char* StatFileName;
1933 /* If we shouldn't run the optimizer, bail out */
1938 /* Check if we are requested to write optimizer statistics */
1939 StatFileName = getenv ("CC65_OPTSTATS");
1941 ReadOptStats (StatFileName);
1944 /* Print the name of the function we are working on */
1946 Print (stdout, 1, "Running optimizer for function `%s'\n", S->Func->Name);
1948 Print (stdout, 1, "Running optimizer for global code segment\n");
1951 /* Run groups of optimizations */
1957 /* Write statistics */
1959 WriteOptStats (StatFileName);