1 /*****************************************************************************/
5 /* Environment independent low level optimizations */
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 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 unsigned OptRTSJumps (CodeSeg* S);
53 /* Replace jumps to RTS by RTS */
55 unsigned OptDeadJumps (CodeSeg* S);
56 /* Remove dead jumps (jumps to the next instruction) */
58 unsigned OptDeadCode (CodeSeg* S);
59 /* Remove dead code (code that follows an unconditional jump or an rts/rti
63 unsigned OptJumpCascades (CodeSeg* S);
64 /* Optimize jump cascades (jumps to jumps). In such a case, the jump is
65 * replaced by a jump to the final location. This will in some cases produce
66 * worse code, because some jump targets are no longer reachable by short
67 * branches, but this is quite rare, so there are more advantages than
71 unsigned OptRTS (CodeSeg* S);
72 /* Optimize subroutine calls followed by an RTS. The subroutine call will get
73 * replaced by a jump. Don't bother to delete the RTS if it does not have a
74 * label, the dead code elimination should take care of it.
77 unsigned OptJumpTarget (CodeSeg* S);
78 /* If the instruction preceeding an unconditional branch is the same as the
79 * instruction preceeding the jump target, the jump target may be moved
80 * one entry back. This is a size optimization, since the instruction before
81 * the branch gets removed.
84 unsigned OptCondBranches (CodeSeg* S);
85 /* If an immidiate load of a register is followed by a conditional jump that
86 * is never taken because the load of the register sets the flags in such a
87 * manner, remove the conditional branch.
90 unsigned OptUnusedLoads (CodeSeg* S);
91 /* Remove loads of registers where the value loaded is not used later. */
93 unsigned OptUnusedStores (CodeSeg* S);
94 /* Remove stores into zero page registers that aren't used later */
96 unsigned OptDupLoads (CodeSeg* S);
97 /* Remove loads of registers where the value loaded is already in the register. */
99 unsigned OptStoreLoad (CodeSeg* S);
100 /* Remove a store followed by a load from the same location. */
102 unsigned OptTransfers (CodeSeg* S);
103 /* Remove transfers from one register to another and back */
105 unsigned OptBranchDist (CodeSeg* S);
106 /* Change branches for the distance needed. */
110 /* End of coptind.h */