1/*****************************************************************************/
2/* */
3/* coptind.h */
4/* */
5/* Environment independent low level optimizations */
6/* */
7/* */
8/* */
9/* (C) 2001-2009, Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
13/* */
14/* */
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. */
18/* */
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: */
22/* */
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 */
30/* distribution. */
31/* */
32/*****************************************************************************/
33
34
35
36#ifndef COPTIND_H
37#define COPTIND_H
38
39
40
41/* cc65 */
42#include "codeseg.h"
43
44
45
46/*****************************************************************************/
47/* Code */
48/*****************************************************************************/
49
50
51
52unsigned OptRTSJumps1 (CodeSeg* S);
53/* Replace jumps to RTS by RTS */
54
55unsigned OptRTSJumps2 (CodeSeg* S);
56/* Replace long conditional jumps to RTS */
57
58unsigned OptDeadJumps (CodeSeg* S);
59/* Remove dead jumps (jumps to the next instruction) */
60
61unsigned OptDeadCode (CodeSeg* S);
62/* Remove dead code (code that follows an unconditional jump or an rts/rti
63** and has no label)
64*/
65
66unsigned OptJumpCascades (CodeSeg* S);
67/* Optimize jump cascades (jumps to jumps). In such a case, the jump is
68** replaced by a jump to the final location. This will in some cases produce
69** worse code, because some jump targets are no longer reachable by short
70** branches, but this is quite rare, so there are more advantages than
71** disadvantages.
72*/
73
74unsigned OptRTS (CodeSeg* S);
75/* Optimize subroutine calls followed by an RTS. The subroutine call will get
76** replaced by a jump. Don't bother to delete the RTS if it does not have a
77** label, the dead code elimination should take care of it.
78*/
79
80unsigned OptJumpTarget1 (CodeSeg* S);
81/* If the instruction preceeding an unconditional branch is the same as the
82** instruction preceeding the jump target, the jump target may be moved
83** one entry back. This is a size optimization, since the instruction before
84** the branch gets removed.
85*/
86
87unsigned OptJumpTarget2 (CodeSeg* S);
88/* If a bcs jumps to a sec insn or a bcc jumps to clc, skip this insn, since
89** it's job is already done.
90*/
91
92unsigned OptJumpTarget3 (CodeSeg* S);
93/* Jumps to load instructions of a register, that do already have the matching
94** register contents may skip the load instruction, since it's job is already
95** done.
96*/
97
98unsigned OptCondBranches1 (CodeSeg* S);
99/* If an immidiate load of a register is followed by a conditional jump that
100** is never taken because the load of the register sets the flags in such a
101** manner, remove the conditional branch.
102*/
103
104unsigned OptCondBranches2 (CodeSeg* S);
105/* If on entry to a "rol a" instruction the accu is zero, and a beq/bne follows,
106** we can remove the rol and branch on the state of the carry.
107*/
108
109unsigned OptUnusedLoads (CodeSeg* S);
110/* Remove loads of registers where the value loaded is not used later. */
111
112unsigned OptUnusedStores (CodeSeg* S);
113/* Remove stores into zero page registers that aren't used later */
114
115unsigned OptDupLoads (CodeSeg* S);
116/* Remove loads of registers where the value loaded is already in the register. */
117
118unsigned OptStoreLoad (CodeSeg* S);
119/* Remove a store followed by a load from the same location. */
120
121unsigned OptTransfers1 (CodeSeg* S);
122/* Remove transfers from one register to another and back */
123
124unsigned OptTransfers2 (CodeSeg* S);
125/* Replace loads followed by a register transfer by a load with the second
126** register if possible.
127*/
128
129unsigned OptTransfers3 (CodeSeg* S);
130/* Replace a register transfer followed by a store of the second register by a
131** store of the first register if this is possible.
132*/
133
134unsigned OptTransfers4 (CodeSeg* S);
135/* Replace a load of a register followed by a transfer insn of the same register
136** by a load of the second register if possible.
137*/
138
139unsigned OptPushPop (CodeSeg* S);
140/* Remove a PHA/PLA sequence were A is not used later */
141
142unsigned OptPrecalc (CodeSeg* S);
143/* Replace immediate operations with the accu where the current contents are
144** known by a load of the final value.
145*/
146
147unsigned OptBranchDist (CodeSeg* S);
148/* Change branches for the distance needed. */
149
150unsigned OptIndLoads1 (CodeSeg* S);
151/* Change
152**
153** lda (zp),y
154**
155** into
156**
157** lda (zp,x)
158**
159** provided that x and y are both zero.
160*/
161
162unsigned OptIndLoads2 (CodeSeg* S);
163/* Change
164**
165** lda (zp,x)
166**
167** into
168**
169** lda (zp),y
170**
171** provided that x and y are both zero.
172*/
173
174
175
176/* End of coptind.h */
177
178#endif
179