6 // The peep hole optimizer searchs the
7 // the SDCC generated code for small snippets
8 // that can be optimized. As a user, you have
9 // control over this optimization process without
10 // having to learn the SDCC source code. (However
11 // you'll still need access to the source since
12 // these rules are compiled into the source.)
14 // The way it works is you specify the target
15 // snippet that you want replaced with a more
16 // efficient snippet that you write. Wild card
17 // variables allow the rules to be parameterized.
19 // In all of the SDCC ports, labels and operands
20 // can be wild cards. However, in the PIC even the
21 // instructions can be wild cards.
25 // Consider Peep Rule 1 as an example. This rule
26 // replaces some code like:
28 // skpz ;i.e. btfss status,Z
35 // skpnz ;i.e. btfsc status,Z
39 // However, the Rule has four wild cards.
40 // The first allows the btfss instruction operator
41 // be anything, not just the Z bit in status register.
42 // The second wild card applies to a label.
43 // The third wild card is for an instruction - any
44 // single instruction can be substituted.
45 // The fourth wild card is also an instruction. It's
46 // just an instruction place holder associated with
47 // a label (think of it as the PIC Port author's laziness
48 // imposed upon the user).
53 // There are certain instances where a peep rule may not
54 // be applicable. Consider this subtle example:
59 // It would seem that the second move is unnecessary. But
60 // be careful! The movf instruction affects the 'Z' bit.
61 // So if this sequence is followed by a btfsc status,Z, you
62 // will have to leave the second move in.
64 // To get around this proble, the peep rule can be followed
65 // by a conditon: "if NZ". Which is to say, apply the rule
66 // if Z bit is not needed in the code that follows. The optimizer
67 // is smart enough to look more than one instruction past the
73 // _NOTBITSKIP_ %1 - Creates a wild card instruction that
74 // will match all instructions except for
75 // bit skip instructions (btfsc or btfss)
76 // _BITSKIP_ %1 - Creates a wild card instruction that only
77 // will match a bit skip instruction (btfsc
79 // _INVERTBITSKIP_ %1 - For the wild card instruction %1, invert
80 // the state of the bit skip. If %1 is not
81 // a bit skip instruction, then there's an
82 // error in the peep rule.
102 // Notice that wild cards will allow any instruction
103 // besides incf to be used in the above.
105 // Also, notice that this snippet is not valid if
106 // it follows another skip
115 ;peep 1 - test/jump to test/skip
129 ;peep 1b - test/jump to test/skip
137 //bogus test for pcode
139 // movf %1,w ;comment at end
148 // ; peep test remove redundant move
149 //%4: movf %1,w ;another comment
159 ; peep 2 - Removed redundant move
170 ; peep 3 - decf/mov/skpz to decfsz
180 ; peep 4 - Removed redundant move
190 ; peep 5 - Removed redundant move
199 ; peep 6 - Removed redundant move
207 ; peep 7 - Removed redundant move
216 ; peep 8 - Removed redundant move
226 ; peep 9a - Removed redundant move
236 ; peep 9b - Removed redundant move