| [a7de7182] | 1 | /* $OpenBSD$ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Copyright (c) 2007 Michael Shalayeff
|
|---|
| 5 | * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
|
|---|
| 6 | * All rights reserved.
|
|---|
| 7 | *
|
|---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 9 | * modification, are permitted provided that the following conditions
|
|---|
| 10 | * are met:
|
|---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright
|
|---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 15 | * documentation and/or other materials provided with the distribution.
|
|---|
| 16 | * 3. The name of the author may not be used to endorse or promote products
|
|---|
| 17 | * derived from this software without specific prior written permission
|
|---|
| 18 | *
|
|---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | # include "pass2.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <string.h>
|
|---|
| 35 |
|
|---|
| 36 | int canaddr(NODE *);
|
|---|
| 37 |
|
|---|
| 38 | /* is it legal to make an OREG or NAME entry which has an
|
|---|
| 39 | * offset of off, (from a register of r), if the
|
|---|
| 40 | * resulting thing had type t */
|
|---|
| 41 | int
|
|---|
| 42 | notoff(TWORD t, int r, CONSZ off, char *cp)
|
|---|
| 43 | {
|
|---|
| 44 | return(0); /* YES */
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /*
|
|---|
| 48 | * Turn a UMUL-referenced node into OREG.
|
|---|
| 49 | * Be careful about register classes, this is a place where classes change.
|
|---|
| 50 | */
|
|---|
| 51 | void
|
|---|
| 52 | offstar(NODE *p, int shape)
|
|---|
| 53 | {
|
|---|
| 54 | NODE *r;
|
|---|
| 55 |
|
|---|
| 56 | if (x2debug)
|
|---|
| 57 | printf("offstar(%p)\n", p);
|
|---|
| 58 |
|
|---|
| 59 | if (isreg(p))
|
|---|
| 60 | return; /* Is already OREG */
|
|---|
| 61 |
|
|---|
| 62 | r = p->n_right;
|
|---|
| 63 | if (p->n_op == PLUS || p->n_op == MINUS) {
|
|---|
| 64 | if (r->n_op == ICON) {
|
|---|
| 65 | if (isreg(p->n_left) == 0)
|
|---|
| 66 | (void)geninsn(p->n_left, INAREG);
|
|---|
| 67 | /* Converted in ormake() */
|
|---|
| 68 | return;
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | (void)geninsn(p, INAREG);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /*
|
|---|
| 75 | * Do the actual conversion of offstar-found OREGs into real OREGs.
|
|---|
| 76 | */
|
|---|
| 77 | void
|
|---|
| 78 | myormake(NODE *q)
|
|---|
| 79 | {
|
|---|
| 80 | NODE *p, *r;
|
|---|
| 81 |
|
|---|
| 82 | if (x2debug)
|
|---|
| 83 | printf("myormake(%p)\n", q);
|
|---|
| 84 |
|
|---|
| 85 | p = q->n_left;
|
|---|
| 86 | if (p->n_op == PLUS && (r = p->n_right)->n_op == LS &&
|
|---|
| 87 | r->n_right->n_op == ICON && r->n_right->n_lval == 2 &&
|
|---|
| 88 | p->n_left->n_op == REG && r->n_left->n_op == REG) {
|
|---|
| 89 | q->n_op = OREG;
|
|---|
| 90 | q->n_lval = 0;
|
|---|
| 91 | q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval, 0);
|
|---|
| 92 | tfree(p);
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /*
|
|---|
| 97 | * Shape matches for UMUL. Cooperates with offstar().
|
|---|
| 98 | */
|
|---|
| 99 | int
|
|---|
| 100 | shumul(NODE *p, int shape)
|
|---|
| 101 | {
|
|---|
| 102 |
|
|---|
| 103 | if (x2debug)
|
|---|
| 104 | printf("shumul(%p)\n", p);
|
|---|
| 105 |
|
|---|
| 106 | /* Turns currently anything into OREG on hppa */
|
|---|
| 107 | if (shape & SOREG)
|
|---|
| 108 | return SOREG;
|
|---|
| 109 | return SRNOPE;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /*
|
|---|
| 113 | * Rewrite operations on binary operators (like +, -, etc...).
|
|---|
| 114 | * Called as a result of table lookup.
|
|---|
| 115 | */
|
|---|
| 116 | int
|
|---|
| 117 | setbin(NODE *p)
|
|---|
| 118 | {
|
|---|
| 119 | if (x2debug)
|
|---|
| 120 | printf("setbin(%p)\n", p);
|
|---|
| 121 |
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /* setup for assignment operator */
|
|---|
| 126 | int
|
|---|
| 127 | setasg(NODE *p, int cookie)
|
|---|
| 128 | {
|
|---|
| 129 | if (x2debug)
|
|---|
| 130 | printf("setasg(%p,%s)\n", p, prcook(cookie));
|
|---|
| 131 |
|
|---|
| 132 | if (p->n_left->n_op == FLD && !isreg(p->n_left->n_left)) {
|
|---|
| 133 | NODE *l, *r;
|
|---|
| 134 | int reg;
|
|---|
| 135 |
|
|---|
| 136 | geninsn(p->n_left->n_left, INAREG);
|
|---|
| 137 |
|
|---|
| 138 | reg = DECRA(p->n_left->n_left->n_reg, 0);
|
|---|
| 139 | l = tcopy(p->n_left->n_left);
|
|---|
| 140 | p->n_left->n_left->n_op = REG;
|
|---|
| 141 | p->n_left->n_left->n_rval = reg;
|
|---|
| 142 | p->n_left->n_left->n_lval = 0;
|
|---|
| 143 | r = tcopy(p->n_left->n_left);
|
|---|
| 144 |
|
|---|
| 145 | geninsn(p->n_left, INAREG);
|
|---|
| 146 | l = mkbinode(ASSIGN, l, r, l->n_type);
|
|---|
| 147 | geninsn(l, INAREG);
|
|---|
| 148 | return (1);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | return (0);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /* setup for unary operator */
|
|---|
| 155 | int
|
|---|
| 156 | setuni(NODE *p, int cookie)
|
|---|
| 157 | {
|
|---|
| 158 | if (x2debug)
|
|---|
| 159 | printf("setuni(%p,%s)\n", p, prcook(cookie));
|
|---|
| 160 |
|
|---|
| 161 | return 0;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /*
|
|---|
| 165 | * Special handling of some instruction register allocation.
|
|---|
| 166 | */
|
|---|
| 167 | struct rspecial *
|
|---|
| 168 | nspecial(struct optab *q)
|
|---|
| 169 | {
|
|---|
| 170 | comperr("nspecial entry %d", q - table);
|
|---|
| 171 | return 0; /* XXX gcc */
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | /*
|
|---|
| 175 | * Set evaluation order of a binary node if it differs from default.
|
|---|
| 176 | */
|
|---|
| 177 | int
|
|---|
| 178 | setorder(NODE *p)
|
|---|
| 179 | {
|
|---|
| 180 | return 0; /* nothing differs on hppa */
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | /*
|
|---|
| 184 | * Set registers "live" at function calls (like arguments in registers).
|
|---|
| 185 | * This is for liveness analysis of registers.
|
|---|
| 186 | */
|
|---|
| 187 | int *
|
|---|
| 188 | livecall(NODE *p)
|
|---|
| 189 | {
|
|---|
| 190 | static int r[5], *s = &r[4];
|
|---|
| 191 |
|
|---|
| 192 | *s = -1;
|
|---|
| 193 | if (p->n_op == UCALL || p->n_op == UFORTCALL || p->n_op == USTCALL ||
|
|---|
| 194 | p->n_op == FORTCALL)
|
|---|
| 195 | return s;
|
|---|
| 196 |
|
|---|
| 197 | for (p = p->n_right; p->n_op == CM; p = p->n_left)
|
|---|
| 198 | if (p->n_right->n_op == ASSIGN &&
|
|---|
| 199 | p->n_right->n_left->n_op == REG)
|
|---|
| 200 | *--s = p->n_right->n_left->n_rval;
|
|---|
| 201 |
|
|---|
| 202 | if (p->n_op == ASSIGN &&
|
|---|
| 203 | p->n_left->n_op == REG)
|
|---|
| 204 | *--s = p->n_left->n_rval;
|
|---|
| 205 |
|
|---|
| 206 | return s;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | /*
|
|---|
| 210 | * Signal whether the instruction is acceptable for this target.
|
|---|
| 211 | */
|
|---|
| 212 | int
|
|---|
| 213 | acceptable(struct optab *op)
|
|---|
| 214 | {
|
|---|
| 215 | return 1;
|
|---|
| 216 | }
|
|---|