1 /*****************************************************************************/
5 /* Environment independent low level optimizations */
9 /* (C) 2001-2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 unsigned OptRTSJumps1 (CodeSeg* S);
53 /* Replace jumps to RTS by RTS */
55 unsigned OptRTSJumps2 (CodeSeg* S);
56 /* Replace long conditional jumps to RTS */
58 unsigned OptDeadJumps (CodeSeg* S);
59 /* Remove dead jumps (jumps to the next instruction) */
61 unsigned OptDeadCode (CodeSeg* S);
62 /* Remove dead code (code that follows an unconditional jump or an rts/rti
66 unsigned 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
74 unsigned 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.
80 unsigned 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.
87 unsigned 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.
92 unsigned OptCondBranches1 (CodeSeg* S);
93 /* If an immidiate load of a register is followed by a conditional jump that
94 * is never taken because the load of the register sets the flags in such a
95 * manner, remove the conditional branch.
98 unsigned OptCondBranches2 (CodeSeg* S);
99 /* If on entry to a "rol a" instruction the accu is zero, and a beq/bne follows,
100 * we can remove the rol and branch on the state of the carry.
103 unsigned OptUnusedLoads (CodeSeg* S);
104 /* Remove loads of registers where the value loaded is not used later. */
106 unsigned OptUnusedStores (CodeSeg* S);
107 /* Remove stores into zero page registers that aren't used later */
109 unsigned OptDupLoads (CodeSeg* S);
110 /* Remove loads of registers where the value loaded is already in the register. */
112 unsigned OptStoreLoad (CodeSeg* S);
113 /* Remove a store followed by a load from the same location. */
115 unsigned OptTransfers1 (CodeSeg* S);
116 /* Remove transfers from one register to another and back */
118 unsigned OptTransfers2 (CodeSeg* S);
119 /* Replace loads followed by a register transfer by a load with the second
120 * register if possible.
123 unsigned OptTransfers3 (CodeSeg* S);
124 /* Replace a register transfer followed by a store of the second register by a
125 * store of the first register if this is possible.
128 unsigned OptTransfers4 (CodeSeg* S);
129 /* Replace a load of a register followed by a transfer insn of the same register
130 * by a load of the second register if possible.
133 unsigned OptPushPop (CodeSeg* S);
134 /* Remove a PHA/PLA sequence were A is not used later */
136 unsigned OptPrecalc (CodeSeg* S);
137 /* Replace immediate operations with the accu where the current contents are
138 * known by a load of the final value.
141 unsigned OptBranchDist (CodeSeg* S);
142 /* Change branches for the distance needed. */
146 /* End of coptind.h */