| 1 | /* $Id: order.c,v 1.12 2008/11/30 21:00:24 ragge Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
|
|---|
| 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 | * MIPS port by Jan Enoksson (janeno-1@student.ltu.se) and
|
|---|
| 31 | * Simon Olsson (simols-1@student.ltu.se) 2005.
|
|---|
| 32 | */
|
|---|
| 33 |
|
|---|
| 34 | #include "pass2.h"
|
|---|
| 35 |
|
|---|
| 36 | /*
|
|---|
| 37 | * is it legal to make an OREG or NAME entry which has an offset of off,
|
|---|
| 38 | * (from a register of r), if the resulting thing had type t
|
|---|
| 39 | */
|
|---|
| 40 | int
|
|---|
| 41 | notoff(TWORD t, int r, CONSZ off, char *cp)
|
|---|
| 42 | {
|
|---|
| 43 | /*
|
|---|
| 44 | * although the hardware doesn't permit offsets greater
|
|---|
| 45 | * than +/- 32K, the assembler fixes it for us.
|
|---|
| 46 | */
|
|---|
| 47 | return 0; /* YES */
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | /*
|
|---|
| 51 | * Turn a UMUL-referenced node into OREG.
|
|---|
| 52 | */
|
|---|
| 53 | void
|
|---|
| 54 | offstar(NODE * p, int shape)
|
|---|
| 55 | {
|
|---|
| 56 | if (x2debug)
|
|---|
| 57 | printf("offstar(%p)\n", p);
|
|---|
| 58 |
|
|---|
| 59 | if (p->n_op == PLUS || p->n_op == MINUS) {
|
|---|
| 60 | if (p->n_right->n_op == ICON) {
|
|---|
| 61 | if (isreg(p->n_left) == 0)
|
|---|
| 62 | (void)geninsn(p->n_left, INAREG);
|
|---|
| 63 | /* Converted in ormake() */
|
|---|
| 64 | return;
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | (void)geninsn(p, INAREG);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /*
|
|---|
| 71 | * Do the actual conversion of offstar-found OREGs into real OREGs.
|
|---|
| 72 | */
|
|---|
| 73 | void
|
|---|
| 74 | myormake(NODE * q)
|
|---|
| 75 | {
|
|---|
| 76 | if (x2debug)
|
|---|
| 77 | printf("myormake(%p)\n", q);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /*
|
|---|
| 81 | * Shape matches for UMUL. Cooperates with offstar().
|
|---|
| 82 | */
|
|---|
| 83 | int
|
|---|
| 84 | shumul(NODE *p, int shape)
|
|---|
| 85 | {
|
|---|
| 86 | if (x2debug)
|
|---|
| 87 | printf("shumul(%p)\n", p);
|
|---|
| 88 |
|
|---|
| 89 | /* Always turn it into OREG */
|
|---|
| 90 | if (shape & SOREG)
|
|---|
| 91 | return SROREG;
|
|---|
| 92 | return SRNOPE;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /*
|
|---|
| 96 | * Rewrite operations on binary operators (like +, -, etc...).
|
|---|
| 97 | * Called as a result of table lookup.
|
|---|
| 98 | */
|
|---|
| 99 | int
|
|---|
| 100 | setbin(NODE * p)
|
|---|
| 101 | {
|
|---|
| 102 |
|
|---|
| 103 | if (x2debug)
|
|---|
| 104 | printf("setbin(%p)\n", p);
|
|---|
| 105 | return 0;
|
|---|
| 106 |
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | /* setup for assignment operator */
|
|---|
| 110 | int
|
|---|
| 111 | setasg(NODE * p, int cookie)
|
|---|
| 112 | {
|
|---|
| 113 | if (x2debug)
|
|---|
| 114 | printf("setasg(%p)\n", p);
|
|---|
| 115 | return (0);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /* setup for unary operator */
|
|---|
| 119 | int
|
|---|
| 120 | setuni(NODE * p, int cookie)
|
|---|
| 121 | {
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Special handling of some instruction register allocation.
|
|---|
| 127 | * - left is the register that left node wants.
|
|---|
| 128 | * - right is the register that right node wants.
|
|---|
| 129 | * - res is in which register the result will end up.
|
|---|
| 130 | * - mask is registers that will be clobbered.
|
|---|
| 131 | */
|
|---|
| 132 | struct rspecial *
|
|---|
| 133 | nspecial(struct optab * q)
|
|---|
| 134 | {
|
|---|
| 135 | switch (q->op) {
|
|---|
| 136 |
|
|---|
| 137 | case SCONV:
|
|---|
| 138 | if (q->lshape == SBREG && q->rshape == SCREG) {
|
|---|
| 139 | static struct rspecial s[] = {
|
|---|
| 140 | { NLEFT, A0A1 },
|
|---|
| 141 | { NRES, F0 },
|
|---|
| 142 | { 0 }
|
|---|
| 143 | };
|
|---|
| 144 | return s;
|
|---|
| 145 | } else if (q->lshape == SCREG && q->rshape == SBREG) {
|
|---|
| 146 | static struct rspecial s[] = {
|
|---|
| 147 | { NLEFT, F0 },
|
|---|
| 148 | { NRES, A0A1 },
|
|---|
| 149 | { 0 }
|
|---|
| 150 | };
|
|---|
| 151 | return s;
|
|---|
| 152 | } else if (q->lshape == SAREG && q->rshape == SCREG) {
|
|---|
| 153 | static struct rspecial s[] = {
|
|---|
| 154 | { NLEFT, A0 },
|
|---|
| 155 | { NRES, F0 },
|
|---|
| 156 | { 0 }
|
|---|
| 157 | };
|
|---|
| 158 | return s;
|
|---|
| 159 | }
|
|---|
| 160 | break;
|
|---|
| 161 |
|
|---|
| 162 | case MOD:
|
|---|
| 163 | case DIV:
|
|---|
| 164 | if (q->lshape == SBREG) {
|
|---|
| 165 | static struct rspecial s[] = {
|
|---|
| 166 | { NLEFT, A0A1 },
|
|---|
| 167 | { NRIGHT, A2A3 },
|
|---|
| 168 | { NRES, V0V1 },
|
|---|
| 169 | { 0 },
|
|---|
| 170 | };
|
|---|
| 171 | return s;
|
|---|
| 172 | } else if (q->lshape == SAREG) {
|
|---|
| 173 | static struct rspecial s[] = {
|
|---|
| 174 | { NLEFT, A0 },
|
|---|
| 175 | { NRIGHT, A1 },
|
|---|
| 176 | { NRES, V0 },
|
|---|
| 177 | { 0 },
|
|---|
| 178 | };
|
|---|
| 179 | return s;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | case RS:
|
|---|
| 183 | case LS:
|
|---|
| 184 | if (q->lshape == SBREG) {
|
|---|
| 185 | static struct rspecial s[] = {
|
|---|
| 186 | { NLEFT, A0A1 },
|
|---|
| 187 | { NRIGHT, A2 },
|
|---|
| 188 | { NRES, V0V1 },
|
|---|
| 189 | { 0 },
|
|---|
| 190 | };
|
|---|
| 191 | return s;
|
|---|
| 192 | } else if (q->lshape == SAREG) {
|
|---|
| 193 | static struct rspecial s[] = {
|
|---|
| 194 | { NLEFT, A0 },
|
|---|
| 195 | { NRIGHT, A1 },
|
|---|
| 196 | { NRES, V0 },
|
|---|
| 197 | { 0 },
|
|---|
| 198 | };
|
|---|
| 199 | return s;
|
|---|
| 200 | }
|
|---|
| 201 | break;
|
|---|
| 202 |
|
|---|
| 203 | case STARG:
|
|---|
| 204 | {
|
|---|
| 205 | static struct rspecial s[] = {
|
|---|
| 206 | { NEVER, A0 },
|
|---|
| 207 | { NLEFT, A1 },
|
|---|
| 208 | { NEVER, A2 },
|
|---|
| 209 | { 0 }
|
|---|
| 210 | };
|
|---|
| 211 | return s;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | case STASG:
|
|---|
| 215 | {
|
|---|
| 216 | static struct rspecial s[] = {
|
|---|
| 217 | { NEVER, A0 },
|
|---|
| 218 | { NRIGHT, A1 },
|
|---|
| 219 | { NEVER, A2 },
|
|---|
| 220 | { 0 }
|
|---|
| 221 | };
|
|---|
| 222 | return s;
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | comperr("nspecial entry %d: %s", q - table, q->cstring);
|
|---|
| 227 |
|
|---|
| 228 | return 0; /* XXX gcc */
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | /*
|
|---|
| 232 | * Set evaluation order of a binary node if it differs from default.
|
|---|
| 233 | */
|
|---|
| 234 | int
|
|---|
| 235 | setorder(NODE * p)
|
|---|
| 236 | {
|
|---|
| 237 | return 0; /* nothing differs */
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /*
|
|---|
| 241 | * Set registers "live" at function calls (like arguments in registers).
|
|---|
| 242 | * This is for liveness analysis of registers.
|
|---|
| 243 | */
|
|---|
| 244 | int *
|
|---|
| 245 | livecall(NODE *p)
|
|---|
| 246 | {
|
|---|
| 247 | static int r[1] = { -1 }; /* Terminate with -1 */
|
|---|
| 248 |
|
|---|
| 249 | return &r[0];
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | /*
|
|---|
| 253 | * Signal whether the instruction is acceptable for this target.
|
|---|
| 254 | */
|
|---|
| 255 | int
|
|---|
| 256 | acceptable(struct optab *op)
|
|---|
| 257 | {
|
|---|
| 258 | return 1;
|
|---|
| 259 | }
|
|---|