Debian Codegraph @

arch/pdp11/order.c

raw symbols SCIP
1 /* $Id: order.c,v 1.13 2019/04/25 17:40:33 ragge Exp $ */
2 /*
3 * Copyright (c) 2003 Anders Magnusson ([email protected]).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30 # include "pass2.h"
31
32 #include <string.h>
33
34 int canaddr(NODE *);
35
36 /* is it legal to make an OREG or NAME entry which has an
37 * offset of off, (from a register of r), if the
38 * resulting thing had type t */
39 int
40 notoff(TWORD t, int r, CONSZ off, char *cp)
41 {
42 return(0); /* YES */
43 }
44
45 static int
46 inctree(NODE *p)
47 {
48 if (p->n_op == MINUS && p->n_left->n_op == ASSIGN &&
49 p->n_left->n_right->n_op == PLUS &&
50 treecmp(p->n_left->n_left, p->n_left->n_right->n_left) &&
51 p->n_right->n_op == ICON && getlval(p->n_right) == 1 &&
52 p->n_left->n_right->n_right->n_op == ICON &&
53 getlval(p->n_left->n_right->n_right) == 1) {
54 /* post-increment by 1; (r0)+ */
55 if (isreg(p->n_left->n_left)) /* Ignore if index not in reg */
56 return 1;
57 }
58 return 0;
59 }
60
61 /*
62 * Turn a UMUL-referenced node into OREG.
63 * Be careful about register classes, this is a place where classes change.
64 */
65 void
66 offstar(NODE *p, int shape)
67 {
68 if (x2debug)
69 printf("offstar(%p)\n", p);
70
71 if (isreg(p))
72 return; /* Is already OREG */
73
74 if (p->n_op == UMUL) {
75 if (p->n_type < PTR+LONG || p->n_type > PTR+ULONGLONG)
76 p = p->n_left; /* double indexed umul */
77 }
78
79 if (inctree(p)) /* Do post-inc conversion */
80 return;
81
82 if( p->n_op == PLUS || p->n_op == MINUS ){
83 if (p->n_right->n_op == ICON) {
84 if (isreg(p->n_left) == 0)
85 (void)geninsn(p->n_left, INAREG);
86 /* Converted in ormake() */
87 return;
88 }
89 }
90 (void)geninsn(p, INAREG);
91 }
92
93 /*
94 * Do the actual conversion of offstar-found OREGs into real OREGs.
95 */
96 void
97 myormake(NODE *p)
98 {
99 NODE *q = p->n_left;
100
101 if (x2debug) {
102 printf("myormake(%p)\n", p);
103 fwalk(p, e2print, 0);
104 }
105 if (inctree(q)) {
106 if (q->n_left->n_left->n_op == TEMP)
107 return;
108 p->n_op = OREG;
109 setlval(p, 0); /* Add support for index offset */
110 p->n_rval = R2PACK(regno(q->n_left->n_left), 0, 1);
111 tfree(q);
112 return;
113 }
114 if (q->n_op != OREG)
115 return;
116 if (TBLIDX(q->n_su))
117 return; /* got sub-conversion, cannot convert */
118 if (R2TEST(regno(q)))
119 return; /* cannot convert anymore */
120 if (p->n_type >= LONG && p->n_type <= ULONGLONG)
121 return;
122 p->n_op = OREG;
123 setlval(p, getlval(q));
124 p->n_rval = R2PACK(q->n_rval, 0, 0);
125 if (x2debug) {
126 printf("myormake end(%p)\n", p);
127 fwalk(p, e2print, 0);
128 }
129 nfree(q);
130 }
131
132 /*
133 * Shape matches for UMUL. Cooperates with offstar().
134 */
135 int
136 shumul(NODE *p, int shape)
137 {
138 if (x2debug)
139 printf("shumul(%p)\n", p);
140
141 if (p->n_op == NAME && (shape & STARNM))
142 return SRDIR;
143 if (shape & SOREG)
144 return SROREG; /* Calls offstar */
145 return SRNOPE;
146 }
147
148 /*
149 * Rewrite operations on binary operators (like +, -, etc...).
150 * Called as a result of table lookup.
151 */
152 int
153 setbin(NODE *p)
154 {
155
156 if (x2debug)
157 printf("setbin(%p)\n", p);
158 return 0;
159
160 }
161
162 /* setup for assignment operator */
163 int
164 setasg(NODE *p, int cookie)
165 {
166 if (x2debug)
167 printf("setasg(%p)\n", p);
168 return(0);
169 }
170
171 /* setup for unary operator */
172 int
173 setuni(NODE *p, int cookie)
174 {
175 return(0);
176 }
177
178 /*
179 * Special handling of some instruction register allocation.
180 */
181 struct rspecial *
182 nspecial(struct optab *q)
183 {
184 switch (q->op) {
185 case MUL:
186 if (q->visit == INAREG) {
187 static struct rspecial s[] = {
188 { NLEFT, R1 }, { NRES, R1 }, { 0 } };
189 return s;
190 } else if (q->visit == INBREG) {
191 static struct rspecial s[] = {
192 { NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } };
193 return s;
194 }
195 break;
196
197 case DIV:
198 if (q->visit == INAREG && q->ltype == TUNSIGNED) {
199 static struct rspecial s[] = {
200 { NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } };
201 return s;
202 } else if (q->visit == INAREG) {
203 static struct rspecial s[] = {
204 { NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 },
205 { NRES, R0 }, { NORIGHT, R0 }, { NORIGHT, R1 },
206 { 0 } };
207 return s;
208 } else if (q->visit == INBREG) {
209 static struct rspecial s[] = {
210 { NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } };
211 return s;
212 }
213 break;
214
215 case MOD:
216 if (q->visit == INAREG && q->ltype == TUNSIGNED) {
217 static struct rspecial s[] = {
218 { NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } };
219 return s;
220 } else if (q->visit == INAREG) {
221 static struct rspecial s[] = {
222 { NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 },
223 { NRES, R1 }, { NORIGHT, R0 }, { NORIGHT, R1 },
224 { 0 } };
225 return s;
226 } else if (q->visit == INBREG) {
227 static struct rspecial s[] = {
228 { NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } };
229 return s;
230 }
231 break;
232
233 case RS:
234 {
235 static struct rspecial s[] = {
236 { NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 },
237 { NRES, R1 }, { NORIGHT, R0 }, { NORIGHT, R1 },
238 { 0 } };
239 return s;
240 }
241 break;
242 case SCONV:
243 if (q->lshape == SAREG) {
244 static struct rspecial s[] = {
245 { NLEFT, R1 }, { NRES, R01 }, { 0 } };
246 return s;
247 }
248 break;
249 case STASG: {
250 /* R0 == ESI, R1 == EDI, R2 == ECX */
251 static struct rspecial s[] = {
252 { NEVER, R1 }, { NEVER, R0 }, { NRIGHT, R0 },
253 { NOLEFT, R0 }, { NOLEFT, R2 }, { NORIGHT, R2 },
254 { NEVER, R2 },
255 };
256 return s;
257 }
258 break;
259 case STARG: {
260 static struct rspecial s[] = {
261 { NEVER, R0 }, { NLEFT, R1 },
262 { NEVER, R2 }, { 0 }
263 };
264 return s;
265 }
266 break;
267 }
268 comperr("nspecial entry %d", q - table);
269 return 0; /* XXX gcc */
270 }
271
272 /*
273 * Set evaluation order of a binary node if it differs from default.
274 */
275 int
276 setorder(NODE *p)
277 {
278 return 0; /* nothing differs on x86 */
279 }
280
281 /*
282 * set registers in calling conventions live.
283 */
284 int *
285 livecall(NODE *p)
286 {
287 static int r[] = { -1 };
288
289 return r;
290 }
291
292 /*
293 * Signal whether the instruction is acceptable for this target.
294 */
295 int
296 acceptable(struct optab *op)
297 {
298 return 1;
299 }