Debian Codegraph @

arch/i386/order.c

raw symbols SCIP
1 /* $Id: order.c,v 1.64 2017/03/11 09:22:09 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 /*
46 * Turn a UMUL-referenced node into OREG.
47 * Be careful about register classes, this is a place where classes change.
48 */
49 void
50 offstar(NODE *p, int shape)
51 {
52 NODE *r;
53
54 if (x2debug)
55 printf("offstar(%p)\n", p);
56
57 if (isreg(p))
58 return; /* Is already OREG */
59
60 r = p->n_right;
61 if( p->n_op == PLUS || p->n_op == MINUS ){
62 if( r->n_op == ICON ){
63 if (isreg(p->n_left) == 0)
64 (void)geninsn(p->n_left, INAREG);
65 /* Converted in ormake() */
66 return;
67 }
68 if (r->n_op == LS && r->n_right->n_op == ICON &&
69 getlval(r->n_right) == 2 && p->n_op == PLUS) {
70 if (isreg(p->n_left) == 0)
71 (void)geninsn(p->n_left, INAREG);
72 if (isreg(r->n_left) == 0)
73 (void)geninsn(r->n_left, INAREG);
74 return;
75 }
76 }
77 (void)geninsn(p, INAREG);
78 }
79
80 /*
81 * Do the actual conversion of offstar-found OREGs into real OREGs.
82 */
83 void
84 myormake(NODE *q)
85 {
86 NODE *p, *r;
87
88 if (x2debug)
89 printf("myormake(%p)\n", q);
90
91 p = q->n_left;
92 if (p->n_op == PLUS && (r = p->n_right)->n_op == LS &&
93 r->n_right->n_op == ICON && getlval(r->n_right) == 2 &&
94 p->n_left->n_op == REG && r->n_left->n_op == REG) {
95 q->n_op = OREG;
96 setlval(q, 0);
97 q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval, 0);
98 tfree(p);
99 }
100 }
101
102 /*
103 * Shape matches for UMUL. Cooperates with offstar().
104 */
105 int
106 shumul(NODE *p, int shape)
107 {
108
109 if (x2debug)
110 printf("shumul(%p)\n", p);
111
112 /* Turns currently anything into OREG on x86 */
113 if (shape & SOREG)
114 return SROREG;
115 return SRNOPE;
116 }
117
118 /*
119 * Rewrite operations on binary operators (like +, -, etc...).
120 * Called as a result of table lookup.
121 */
122 int
123 setbin(NODE *p)
124 {
125
126 if (x2debug)
127 printf("setbin(%p)\n", p);
128 return 0;
129
130 }
131
132 /* setup for assignment operator */
133 int
134 setasg(NODE *p, int cookie)
135 {
136 if (x2debug)
137 printf("setasg(%p)\n", p);
138 return(0);
139 }
140
141 /* setup for unary operator */
142 int
143 setuni(NODE *p, int cookie)
144 {
145 return 0;
146 }
147
148 /*
149 * Set evaluation order of a binary node if it differs from default.
150 */
151 int
152 setorder(NODE *p)
153 {
154 return 0; /* nothing differs on x86 */
155 }
156
157 /*
158 * set registers in calling conventions live.
159 */
160 int *
161 livecall(NODE *p)
162 {
163 static int r[] = { EAX, EBX, -1 };
164 int off = 1;
165
166 #ifdef TLS
167 if (p->n_left->n_op == ICON &&
168 strcmp(p->n_left->n_name, "___tls_get_addr@PLT") == 0)
169 off--;
170 #endif
171
172 return kflag ? &r[off] : &r[2];
173 }
174
175 /*
176 * Signal whether the instruction is acceptable for this target.
177 */
178 int
179 acceptable(struct optab *op)
180 {
181 return 1;
182 }