]>
Commit | Line | Data |
---|---|---|
ab835497 | 1 | /* Subroutines for insn-output.c for Sun SPARC. |
7c03e72e | 2 | Copyright (C) 1987, 88, 89, 92-96, 1997 Free Software Foundation, Inc. |
ab835497 | 3 | Contributed by Michael Tiemann (tiemann@cygnus.com) |
61a55e8b DE |
4 | 64 bit SPARC V9 support by Michael Tiemann, Jim Wilson, and Doug Evans, |
5 | at Cygnus Support. | |
ab835497 RK |
6 | |
7 | This file is part of GNU CC. | |
8 | ||
9 | GNU CC is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2, or (at your option) | |
12 | any later version. | |
13 | ||
14 | GNU CC is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GNU CC; see the file COPYING. If not, write to | |
c15c9075 RK |
21 | the Free Software Foundation, 59 Temple Place - Suite 330, |
22 | Boston, MA 02111-1307, USA. */ | |
ab835497 RK |
23 | |
24 | #include <stdio.h> | |
25 | #include "config.h" | |
210aa14a | 26 | #include "tree.h" |
ab835497 RK |
27 | #include "rtl.h" |
28 | #include "regs.h" | |
29 | #include "hard-reg-set.h" | |
30 | #include "real.h" | |
31 | #include "insn-config.h" | |
32 | #include "conditions.h" | |
33 | #include "insn-flags.h" | |
34 | #include "output.h" | |
35 | #include "insn-attr.h" | |
36 | #include "flags.h" | |
37 | #include "expr.h" | |
38 | #include "recog.h" | |
39 | ||
61a55e8b DE |
40 | /* 1 if the caller has placed an "unimp" insn immediately after the call. |
41 | This is used in v8 code when calling a function that returns a structure. | |
06b967f9 RK |
42 | v9 doesn't have this. Be careful to have this test be the same as that |
43 | used on the call. */ | |
44 | ||
45 | #define SKIP_CALLERS_UNIMP_P \ | |
46 | (!TARGET_ARCH64 && current_function_returns_struct \ | |
47 | && ! integer_zerop (DECL_SIZE (DECL_RESULT (current_function_decl))) \ | |
48 | && (TREE_CODE (DECL_SIZE (DECL_RESULT (current_function_decl))) \ | |
49 | == INTEGER_CST)) | |
61a55e8b | 50 | |
ab835497 RK |
51 | /* Global variables for machine-dependent things. */ |
52 | ||
61a55e8b DE |
53 | /* Size of frame. Need to know this to emit return insns from leaf procedures. |
54 | ACTUAL_FSIZE is set by compute_frame_size() which is called during the | |
55 | reload pass. This is important as the value is later used in insn | |
56 | scheduling (to see what can go in a delay slot). | |
57 | APPARENT_FSIZE is the size of the stack less the register save area and less | |
58 | the outgoing argument area. It is used when saving call preserved regs. */ | |
59 | static int apparent_fsize; | |
60 | static int actual_fsize; | |
61 | ||
ab835497 RK |
62 | /* Save the operands last given to a compare for use when we |
63 | generate a scc or bcc insn. */ | |
64 | ||
65 | rtx sparc_compare_op0, sparc_compare_op1; | |
66 | ||
61a55e8b DE |
67 | /* Count of named arguments (v9 only). |
68 | ??? INIT_CUMULATIVE_ARGS initializes these, and FUNCTION_ARG_ADVANCE | |
69 | increments SPARC_ARG_COUNT. They are then used by | |
70 | FUNCTION_ARG_CALLEE_COPIES to determine if the argument is really a named | |
71 | argument or not. This hack is necessary because the NAMED argument to the | |
72 | FUNCTION_ARG_XXX macros is not what it says it is: it does not include the | |
73 | last named argument. */ | |
74 | ||
75 | int sparc_arg_count; | |
76 | int sparc_n_named_args; | |
77 | ||
ab835497 RK |
78 | /* We may need an epilogue if we spill too many registers. |
79 | If this is non-zero, then we branch here for the epilogue. */ | |
80 | static rtx leaf_label; | |
81 | ||
82 | #ifdef LEAF_REGISTERS | |
83 | ||
84 | /* Vector to say how input registers are mapped to output | |
85 | registers. FRAME_POINTER_REGNUM cannot be remapped by | |
86 | this function to eliminate it. You must use -fomit-frame-pointer | |
87 | to get that. */ | |
88 | char leaf_reg_remap[] = | |
89 | { 0, 1, 2, 3, 4, 5, 6, 7, | |
90 | -1, -1, -1, -1, -1, -1, 14, -1, | |
91 | -1, -1, -1, -1, -1, -1, -1, -1, | |
92 | 8, 9, 10, 11, 12, 13, -1, 15, | |
93 | ||
94 | 32, 33, 34, 35, 36, 37, 38, 39, | |
95 | 40, 41, 42, 43, 44, 45, 46, 47, | |
96 | 48, 49, 50, 51, 52, 53, 54, 55, | |
61a55e8b DE |
97 | 56, 57, 58, 59, 60, 61, 62, 63, |
98 | 64, 65, 66, 67, 68, 69, 70, 71, | |
99 | 72, 73, 74, 75, 76, 77, 78, 79, | |
100 | 80, 81, 82, 83, 84, 85, 86, 87, | |
101 | 88, 89, 90, 91, 92, 93, 94, 95, | |
c4ce6853 | 102 | 96, 97, 98, 99, 100}; |
ab835497 | 103 | |
6a4bb1fa | 104 | #endif |
ab835497 | 105 | |
ab835497 RK |
106 | /* Name of where we pretend to think the frame pointer points. |
107 | Normally, this is "%fp", but if we are in a leaf procedure, | |
61a55e8b DE |
108 | this is "%sp+something". We record "something" separately as it may be |
109 | too big for reg+constant addressing. */ | |
110 | ||
111 | static char *frame_base_name; | |
112 | static int frame_base_offset; | |
ab835497 RK |
113 | |
114 | static rtx find_addr_reg (); | |
61a55e8b DE |
115 | static void sparc_init_modes (); |
116 | \f | |
117 | /* Option handling. */ | |
118 | ||
16956f6e DE |
119 | struct sparc_cpu_select sparc_select[] = |
120 | { | |
121 | /* switch name, tune arch */ | |
122 | { (char *)0, "default", 1, 1 }, | |
123 | { (char *)0, "-mcpu=", 1, 1 }, | |
124 | { (char *)0, "-mtune=", 1, 0 }, | |
125 | { 0, 0 } | |
126 | }; | |
733f53f5 | 127 | |
16956f6e DE |
128 | /* CPU type. This is set from TARGET_CPU_DEFAULT and -m{cpu,tune}=xxx. */ |
129 | enum processor_type sparc_cpu; | |
733f53f5 | 130 | |
61a55e8b DE |
131 | /* Validate and override various options, and do some machine dependent |
132 | initialization. */ | |
133 | ||
134 | void | |
135 | sparc_override_options () | |
136 | { | |
16956f6e | 137 | /* Map TARGET_CPU_DEFAULT to value for -m{arch,tune}=. */ |
733f53f5 DE |
138 | static struct cpu_default { |
139 | int cpu; | |
140 | char *name; | |
141 | } cpu_default[] = { | |
16956f6e | 142 | { TARGET_CPU_sparc, "cypress" }, |
ba542005 RK |
143 | { TARGET_CPU_v8, "v8" }, |
144 | { TARGET_CPU_supersparc, "supersparc" }, | |
3592ea0d | 145 | { TARGET_CPU_sparclet, "tsc701" }, |
16956f6e | 146 | { TARGET_CPU_sparclite, "f930" }, |
ba542005 | 147 | { TARGET_CPU_ultrasparc, "ultrasparc" }, |
16956f6e | 148 | { 0 } |
733f53f5 | 149 | }; |
16956f6e DE |
150 | struct cpu_default *def; |
151 | /* Table of values for -m{cpu,tune}=. */ | |
733f53f5 DE |
152 | static struct cpu_table { |
153 | char *name; | |
16956f6e | 154 | enum processor_type processor; |
733f53f5 DE |
155 | int disable; |
156 | int enable; | |
157 | } cpu_table[] = { | |
16956f6e DE |
158 | { "v7", PROCESSOR_V7, MASK_ISA, 0 }, |
159 | { "cypress", PROCESSOR_CYPRESS, MASK_ISA, 0 }, | |
160 | { "v8", PROCESSOR_V8, MASK_ISA, MASK_V8 }, | |
733f53f5 | 161 | /* TI TMS390Z55 supersparc */ |
16956f6e DE |
162 | { "supersparc", PROCESSOR_SUPERSPARC, MASK_ISA, MASK_V8 }, |
163 | { "sparclite", PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE }, | |
733f53f5 DE |
164 | /* The Fujitsu MB86930 is the original sparclite chip, with no fpu. |
165 | The Fujitsu MB86934 is the recent sparclite chip, with an fpu. */ | |
16956f6e DE |
166 | { "f930", PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE }, |
167 | { "f934", PROCESSOR_F934, MASK_ISA, MASK_SPARCLITE|MASK_FPU }, | |
168 | { "sparclet", PROCESSOR_SPARCLET, MASK_ISA, MASK_SPARCLET }, | |
733f53f5 | 169 | /* TEMIC sparclet */ |
3592ea0d | 170 | { "tsc701", PROCESSOR_TSC701, MASK_ISA, MASK_SPARCLET }, |
16956f6e DE |
171 | /* "v9" is used to specify a true 64 bit architecture. |
172 | "v8plus" is what Sun calls Solaris2 running on UltraSPARC's. */ | |
173 | { "v8plus", PROCESSOR_V8PLUS, MASK_ISA, MASK_V9 }, | |
174 | #if SPARC_ARCH64 | |
175 | { "v9", PROCESSOR_V9, MASK_ISA, MASK_V9 }, | |
176 | #endif | |
733f53f5 | 177 | /* TI ultrasparc */ |
16956f6e | 178 | { "ultrasparc", PROCESSOR_ULTRASPARC, MASK_ISA, MASK_V9 }, |
733f53f5 DE |
179 | { 0 } |
180 | }; | |
16956f6e DE |
181 | struct cpu_table *cpu; |
182 | struct sparc_cpu_select *sel; | |
183 | ||
1f1406b4 DE |
184 | int fpu = TARGET_FPU; /* save current -mfpu status */ |
185 | ||
16956f6e DE |
186 | /* Set the default. */ |
187 | for (def = &cpu_default[0]; def->name; ++def) | |
188 | if (def->cpu == TARGET_CPU_DEFAULT) | |
189 | break; | |
190 | if (! def->name) | |
191 | abort (); | |
192 | sparc_select[0].string = def->name; | |
193 | ||
194 | for (sel = &sparc_select[0]; sel->name; ++sel) | |
61a55e8b | 195 | { |
16956f6e | 196 | if (sel->string) |
733f53f5 | 197 | { |
16956f6e DE |
198 | for (cpu = &cpu_table[0]; cpu->name; ++cpu) |
199 | if (! strcmp (sel->string, cpu->name)) | |
200 | { | |
201 | if (sel->set_tune_p) | |
202 | sparc_cpu = cpu->processor; | |
203 | ||
204 | if (sel->set_arch_p) | |
205 | { | |
206 | target_flags &= ~cpu->disable; | |
207 | target_flags |= cpu->enable; | |
208 | } | |
209 | break; | |
210 | } | |
211 | ||
212 | if (! cpu->name) | |
213 | error ("bad value (%s) for %s switch", sel->string, sel->name); | |
733f53f5 | 214 | } |
61a55e8b | 215 | } |
97da85b7 | 216 | |
1f1406b4 DE |
217 | /* If -mfpu or -mno-fpu was explicitly used, don't override with |
218 | the processor default. */ | |
219 | if (TARGET_FPU_SET) | |
220 | target_flags = (target_flags & ~MASK_FPU) | fpu; | |
221 | ||
16956f6e DE |
222 | /* Use the deprecated v8 insns for sparc64 in 32 bit mode. */ |
223 | if (TARGET_V9 && TARGET_ARCH32) | |
733f53f5 | 224 | target_flags |= MASK_DEPRECATED_V8_INSNS; |
61a55e8b DE |
225 | |
226 | /* Do various machine dependent initializations. */ | |
227 | sparc_init_modes (); | |
228 | } | |
229 | \f | |
230 | /* Float conversions (v9 only). | |
231 | ||
232 | The floating point registers cannot hold DImode values because SUBREG's | |
233 | on them get the wrong register. "(subreg:SI (reg:DI M int-reg) 0)" is the | |
234 | same as "(subreg:SI (reg:DI N float-reg) 1)", but gcc doesn't know how to | |
235 | turn the "0" to a "1". Therefore, we must explicitly do the conversions | |
236 | to/from int/fp regs. `sparc64_fpconv_stack_slot' is the address of an | |
237 | 8 byte stack slot used during the transfer. | |
238 | ??? I could have used [%fp-16] but I didn't want to add yet another | |
239 | dependence on this. */ | |
240 | /* ??? Can we use assign_stack_temp here? */ | |
241 | ||
242 | static rtx fpconv_stack_temp; | |
243 | ||
244 | /* Called once for each function. */ | |
245 | ||
246 | void | |
247 | sparc64_init_expanders () | |
248 | { | |
249 | fpconv_stack_temp = NULL_RTX; | |
250 | } | |
251 | ||
252 | /* Assign a stack temp for fp/int DImode conversions. */ | |
ab835497 | 253 | |
61a55e8b DE |
254 | rtx |
255 | sparc64_fpconv_stack_temp () | |
256 | { | |
257 | if (fpconv_stack_temp == NULL_RTX) | |
258 | fpconv_stack_temp = | |
259 | assign_stack_local (DImode, GET_MODE_SIZE (DImode), 0); | |
260 | ||
261 | return fpconv_stack_temp; | |
262 | } | |
263 | \f | |
cd5fb1ee DE |
264 | /* Miscellaneous utilities. */ |
265 | ||
266 | /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move | |
267 | or branch on register contents instructions. */ | |
268 | ||
269 | int | |
270 | v9_regcmp_p (code) | |
271 | enum rtx_code code; | |
272 | { | |
273 | return (code == EQ || code == NE || code == GE || code == LT | |
274 | || code == LE || code == GT); | |
275 | } | |
276 | \f | |
277 | /* Operand constraints. */ | |
278 | ||
ab835497 | 279 | /* Return non-zero only if OP is a register of mode MODE, |
c4ce6853 DE |
280 | or const0_rtx. Don't allow const0_rtx if TARGET_LIVE_G0 because |
281 | %g0 may contain anything. */ | |
282 | ||
ab835497 RK |
283 | int |
284 | reg_or_0_operand (op, mode) | |
285 | rtx op; | |
286 | enum machine_mode mode; | |
287 | { | |
c4ce6853 DE |
288 | if (register_operand (op, mode)) |
289 | return 1; | |
290 | if (TARGET_LIVE_G0) | |
291 | return 0; | |
292 | if (op == const0_rtx) | |
ab835497 | 293 | return 1; |
5b486ce0 | 294 | if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE |
ab835497 RK |
295 | && CONST_DOUBLE_HIGH (op) == 0 |
296 | && CONST_DOUBLE_LOW (op) == 0) | |
297 | return 1; | |
302484ff JW |
298 | if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT |
299 | && GET_CODE (op) == CONST_DOUBLE | |
300 | && fp_zero_operand (op)) | |
301 | return 1; | |
ab835497 RK |
302 | return 0; |
303 | } | |
304 | ||
302484ff | 305 | /* Nonzero if OP is a floating point value with value 0.0. */ |
c4ce6853 | 306 | |
302484ff JW |
307 | int |
308 | fp_zero_operand (op) | |
309 | rtx op; | |
310 | { | |
311 | REAL_VALUE_TYPE r; | |
312 | ||
313 | REAL_VALUE_FROM_CONST_DOUBLE (r, op); | |
d61ba4f4 | 314 | return (REAL_VALUES_EQUAL (r, dconst0) && ! REAL_VALUE_MINUS_ZERO (r)); |
302484ff JW |
315 | } |
316 | ||
61a55e8b DE |
317 | /* Nonzero if OP is an integer register. */ |
318 | ||
319 | int | |
320 | intreg_operand (op, mode) | |
321 | rtx op; | |
322 | enum machine_mode mode; | |
323 | { | |
324 | return (register_operand (op, SImode) | |
a9e27770 | 325 | || (TARGET_ARCH64 && register_operand (op, DImode))); |
61a55e8b DE |
326 | } |
327 | ||
328 | /* Nonzero if OP is a floating point condition code register. */ | |
329 | ||
330 | int | |
c4ce6853 | 331 | fcc_reg_operand (op, mode) |
61a55e8b DE |
332 | rtx op; |
333 | enum machine_mode mode; | |
334 | { | |
335 | /* This can happen when recog is called from combine. Op may be a MEM. | |
336 | Fail instead of calling abort in this case. */ | |
c4ce6853 | 337 | if (GET_CODE (op) != REG) |
61a55e8b | 338 | return 0; |
304b7a23 | 339 | |
c4ce6853 | 340 | if (mode != VOIDmode && mode != GET_MODE (op)) |
61a55e8b | 341 | return 0; |
304b7a23 DE |
342 | if (mode == VOIDmode |
343 | && (GET_MODE (op) != CCFPmode && GET_MODE (op) != CCFPEmode)) | |
344 | return 0; | |
61a55e8b | 345 | |
c4ce6853 | 346 | #if 0 /* ??? ==> 1 when %fcc0-3 are pseudos first. See gen_compare_reg(). */ |
61a55e8b DE |
347 | if (reg_renumber == 0) |
348 | return REGNO (op) >= FIRST_PSEUDO_REGISTER; | |
349 | return REGNO_OK_FOR_CCFP_P (REGNO (op)); | |
350 | #else | |
c4ce6853 | 351 | return (unsigned) REGNO (op) - SPARC_FIRST_V9_FCC_REG < 4; |
61a55e8b DE |
352 | #endif |
353 | } | |
354 | ||
c4ce6853 DE |
355 | /* Nonzero if OP is an integer or floating point condition code register. */ |
356 | ||
357 | int | |
358 | icc_or_fcc_reg_operand (op, mode) | |
359 | rtx op; | |
360 | enum machine_mode mode; | |
361 | { | |
362 | if (GET_CODE (op) == REG && REGNO (op) == SPARC_ICC_REG) | |
304b7a23 DE |
363 | { |
364 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
365 | return 0; | |
366 | if (mode == VOIDmode | |
367 | && GET_MODE (op) != CCmode && GET_MODE (op) != CCXmode) | |
368 | return 0; | |
369 | return 1; | |
370 | } | |
371 | ||
c4ce6853 DE |
372 | return fcc_reg_operand (op, mode); |
373 | } | |
374 | ||
ab835497 RK |
375 | /* Nonzero if OP can appear as the dest of a RESTORE insn. */ |
376 | int | |
377 | restore_operand (op, mode) | |
378 | rtx op; | |
379 | enum machine_mode mode; | |
380 | { | |
381 | return (GET_CODE (op) == REG && GET_MODE (op) == mode | |
382 | && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32))); | |
383 | } | |
384 | ||
401cec23 JW |
385 | /* Call insn on SPARC can take a PC-relative constant address, or any regular |
386 | memory address. */ | |
ab835497 RK |
387 | |
388 | int | |
389 | call_operand (op, mode) | |
390 | rtx op; | |
391 | enum machine_mode mode; | |
392 | { | |
393 | if (GET_CODE (op) != MEM) | |
394 | abort (); | |
395 | op = XEXP (op, 0); | |
2445f289 | 396 | return (symbolic_operand (op, mode) || memory_address_p (Pmode, op)); |
ab835497 RK |
397 | } |
398 | ||
399 | int | |
400 | call_operand_address (op, mode) | |
401 | rtx op; | |
402 | enum machine_mode mode; | |
403 | { | |
2445f289 | 404 | return (symbolic_operand (op, mode) || memory_address_p (Pmode, op)); |
ab835497 RK |
405 | } |
406 | ||
407 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
408 | reference and a constant. */ | |
409 | ||
410 | int | |
411 | symbolic_operand (op, mode) | |
412 | register rtx op; | |
413 | enum machine_mode mode; | |
414 | { | |
415 | switch (GET_CODE (op)) | |
416 | { | |
417 | case SYMBOL_REF: | |
418 | case LABEL_REF: | |
419 | return 1; | |
420 | ||
421 | case CONST: | |
422 | op = XEXP (op, 0); | |
423 | return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
424 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
425 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
426 | ||
228b4037 | 427 | /* ??? This clause seems to be irrelevant. */ |
ab835497 RK |
428 | case CONST_DOUBLE: |
429 | return GET_MODE (op) == mode; | |
430 | ||
431 | default: | |
432 | return 0; | |
433 | } | |
434 | } | |
435 | ||
436 | /* Return truth value of statement that OP is a symbolic memory | |
437 | operand of mode MODE. */ | |
438 | ||
439 | int | |
440 | symbolic_memory_operand (op, mode) | |
441 | rtx op; | |
442 | enum machine_mode mode; | |
443 | { | |
444 | if (GET_CODE (op) == SUBREG) | |
445 | op = SUBREG_REG (op); | |
446 | if (GET_CODE (op) != MEM) | |
447 | return 0; | |
448 | op = XEXP (op, 0); | |
449 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST | |
450 | || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF); | |
451 | } | |
452 | ||
5ab7138b DE |
453 | /* Return truth value of statement that OP is a LABEL_REF of mode MODE. */ |
454 | ||
455 | int | |
456 | label_ref_operand (op, mode) | |
457 | rtx op; | |
458 | enum machine_mode mode; | |
459 | { | |
460 | if (GET_CODE (op) != LABEL_REF) | |
461 | return 0; | |
462 | if (GET_MODE (op) != mode) | |
463 | return 0; | |
464 | return 1; | |
465 | } | |
466 | ||
95726648 DE |
467 | /* Return 1 if the operand is an argument used in generating pic references |
468 | in either the medium/low or medium/anywhere code models of sparc64. */ | |
469 | ||
470 | int | |
471 | sp64_medium_pic_operand (op, mode) | |
472 | rtx op; | |
473 | enum machine_mode mode; | |
474 | { | |
475 | /* Check for (const (minus (symbol_ref:GOT) | |
476 | (const (minus (label) (pc))))). */ | |
477 | if (GET_CODE (op) != CONST) | |
478 | return 0; | |
479 | op = XEXP (op, 0); | |
480 | if (GET_CODE (op) != MINUS) | |
481 | return 0; | |
482 | if (GET_CODE (XEXP (op, 0)) != SYMBOL_REF) | |
483 | return 0; | |
484 | /* ??? Ensure symbol is GOT. */ | |
485 | if (GET_CODE (XEXP (op, 1)) != CONST) | |
486 | return 0; | |
487 | if (GET_CODE (XEXP (XEXP (op, 1), 0)) != MINUS) | |
488 | return 0; | |
489 | return 1; | |
490 | } | |
491 | ||
61a55e8b DE |
492 | /* Return 1 if the operand is a data segment reference. This includes |
493 | the readonly data segment, or in other words anything but the text segment. | |
494 | This is needed in the medium/anywhere code model on v9. These values | |
495 | are accessed with MEDANY_BASE_REG. */ | |
496 | ||
497 | int | |
498 | data_segment_operand (op, mode) | |
499 | rtx op; | |
500 | enum machine_mode mode; | |
501 | { | |
502 | switch (GET_CODE (op)) | |
503 | { | |
504 | case SYMBOL_REF : | |
505 | return ! SYMBOL_REF_FLAG (op); | |
506 | case PLUS : | |
95726648 DE |
507 | /* Assume canonical format of symbol + constant. |
508 | Fall through. */ | |
61a55e8b DE |
509 | case CONST : |
510 | return data_segment_operand (XEXP (op, 0)); | |
511 | default : | |
512 | return 0; | |
513 | } | |
514 | } | |
515 | ||
516 | /* Return 1 if the operand is a text segment reference. | |
517 | This is needed in the medium/anywhere code model on v9. */ | |
518 | ||
519 | int | |
520 | text_segment_operand (op, mode) | |
521 | rtx op; | |
522 | enum machine_mode mode; | |
523 | { | |
524 | switch (GET_CODE (op)) | |
525 | { | |
526 | case LABEL_REF : | |
527 | return 1; | |
528 | case SYMBOL_REF : | |
529 | return SYMBOL_REF_FLAG (op); | |
530 | case PLUS : | |
95726648 DE |
531 | /* Assume canonical format of symbol + constant. |
532 | Fall through. */ | |
61a55e8b DE |
533 | case CONST : |
534 | return text_segment_operand (XEXP (op, 0)); | |
535 | default : | |
536 | return 0; | |
537 | } | |
538 | } | |
539 | ||
ab835497 RK |
540 | /* Return 1 if the operand is either a register or a memory operand that is |
541 | not symbolic. */ | |
542 | ||
543 | int | |
544 | reg_or_nonsymb_mem_operand (op, mode) | |
545 | register rtx op; | |
546 | enum machine_mode mode; | |
547 | { | |
548 | if (register_operand (op, mode)) | |
549 | return 1; | |
550 | ||
551 | if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode)) | |
552 | return 1; | |
553 | ||
554 | return 0; | |
555 | } | |
556 | ||
557 | int | |
558 | sparc_operand (op, mode) | |
559 | rtx op; | |
560 | enum machine_mode mode; | |
561 | { | |
562 | if (register_operand (op, mode)) | |
563 | return 1; | |
564 | if (GET_CODE (op) == CONST_INT) | |
565 | return SMALL_INT (op); | |
566 | if (GET_MODE (op) != mode) | |
567 | return 0; | |
568 | if (GET_CODE (op) == SUBREG) | |
569 | op = SUBREG_REG (op); | |
570 | if (GET_CODE (op) != MEM) | |
571 | return 0; | |
572 | ||
573 | op = XEXP (op, 0); | |
574 | if (GET_CODE (op) == LO_SUM) | |
575 | return (GET_CODE (XEXP (op, 0)) == REG | |
576 | && symbolic_operand (XEXP (op, 1), Pmode)); | |
577 | return memory_address_p (mode, op); | |
578 | } | |
579 | ||
580 | int | |
581 | move_operand (op, mode) | |
582 | rtx op; | |
583 | enum machine_mode mode; | |
584 | { | |
585 | if (mode == DImode && arith_double_operand (op, mode)) | |
586 | return 1; | |
587 | if (register_operand (op, mode)) | |
588 | return 1; | |
589 | if (GET_CODE (op) == CONST_INT) | |
590 | return (SMALL_INT (op) || (INTVAL (op) & 0x3ff) == 0); | |
591 | ||
592 | if (GET_MODE (op) != mode) | |
593 | return 0; | |
594 | if (GET_CODE (op) == SUBREG) | |
595 | op = SUBREG_REG (op); | |
596 | if (GET_CODE (op) != MEM) | |
597 | return 0; | |
598 | op = XEXP (op, 0); | |
599 | if (GET_CODE (op) == LO_SUM) | |
600 | return (register_operand (XEXP (op, 0), Pmode) | |
601 | && CONSTANT_P (XEXP (op, 1))); | |
602 | return memory_address_p (mode, op); | |
603 | } | |
604 | ||
ab835497 | 605 | int |
6ac34277 | 606 | splittable_symbolic_memory_operand (op, mode) |
ab835497 RK |
607 | rtx op; |
608 | enum machine_mode mode; | |
609 | { | |
6ac34277 DE |
610 | if (GET_CODE (op) != MEM) |
611 | return 0; | |
612 | if (! symbolic_operand (XEXP (op, 0), Pmode)) | |
613 | return 0; | |
614 | return 1; | |
615 | } | |
616 | ||
617 | int | |
618 | splittable_immediate_memory_operand (op, mode) | |
619 | rtx op; | |
620 | enum machine_mode mode; | |
621 | { | |
622 | if (GET_CODE (op) != MEM) | |
623 | return 0; | |
624 | if (! immediate_operand (XEXP (op, 0), Pmode)) | |
625 | return 0; | |
626 | return 1; | |
ab835497 RK |
627 | } |
628 | ||
629 | /* Return truth value of whether OP is EQ or NE. */ | |
630 | ||
631 | int | |
632 | eq_or_neq (op, mode) | |
633 | rtx op; | |
634 | enum machine_mode mode; | |
635 | { | |
636 | return (GET_CODE (op) == EQ || GET_CODE (op) == NE); | |
637 | } | |
638 | ||
639 | /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU, | |
640 | or LTU for non-floating-point. We handle those specially. */ | |
641 | ||
642 | int | |
643 | normal_comp_operator (op, mode) | |
644 | rtx op; | |
645 | enum machine_mode mode; | |
646 | { | |
647 | enum rtx_code code = GET_CODE (op); | |
648 | ||
649 | if (GET_RTX_CLASS (code) != '<') | |
650 | return 0; | |
651 | ||
4d449554 JW |
652 | if (GET_MODE (XEXP (op, 0)) == CCFPmode |
653 | || GET_MODE (XEXP (op, 0)) == CCFPEmode) | |
ab835497 RK |
654 | return 1; |
655 | ||
656 | return (code != NE && code != EQ && code != GEU && code != LTU); | |
657 | } | |
658 | ||
659 | /* Return 1 if this is a comparison operator. This allows the use of | |
660 | MATCH_OPERATOR to recognize all the branch insns. */ | |
661 | ||
662 | int | |
663 | noov_compare_op (op, mode) | |
664 | register rtx op; | |
665 | enum machine_mode mode; | |
666 | { | |
667 | enum rtx_code code = GET_CODE (op); | |
668 | ||
669 | if (GET_RTX_CLASS (code) != '<') | |
670 | return 0; | |
671 | ||
672 | if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode) | |
673 | /* These are the only branches which work with CC_NOOVmode. */ | |
674 | return (code == EQ || code == NE || code == GE || code == LT); | |
675 | return 1; | |
676 | } | |
677 | ||
61a55e8b DE |
678 | /* Nonzero if OP is a comparison operator suitable for use in v9 |
679 | conditional move or branch on register contents instructions. */ | |
680 | ||
681 | int | |
682 | v9_regcmp_op (op, mode) | |
683 | register rtx op; | |
684 | enum machine_mode mode; | |
685 | { | |
686 | enum rtx_code code = GET_CODE (op); | |
687 | ||
688 | if (GET_RTX_CLASS (code) != '<') | |
689 | return 0; | |
690 | ||
cd5fb1ee | 691 | return v9_regcmp_p (code); |
61a55e8b DE |
692 | } |
693 | ||
ab835497 RK |
694 | /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */ |
695 | ||
696 | int | |
697 | extend_op (op, mode) | |
698 | rtx op; | |
699 | enum machine_mode mode; | |
700 | { | |
701 | return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND; | |
702 | } | |
703 | ||
704 | /* Return nonzero if OP is an operator of mode MODE which can set | |
705 | the condition codes explicitly. We do not include PLUS and MINUS | |
706 | because these require CC_NOOVmode, which we handle explicitly. */ | |
707 | ||
708 | int | |
709 | cc_arithop (op, mode) | |
710 | rtx op; | |
711 | enum machine_mode mode; | |
712 | { | |
713 | if (GET_CODE (op) == AND | |
714 | || GET_CODE (op) == IOR | |
715 | || GET_CODE (op) == XOR) | |
716 | return 1; | |
717 | ||
718 | return 0; | |
719 | } | |
720 | ||
721 | /* Return nonzero if OP is an operator of mode MODE which can bitwise | |
722 | complement its second operand and set the condition codes explicitly. */ | |
723 | ||
724 | int | |
725 | cc_arithopn (op, mode) | |
726 | rtx op; | |
727 | enum machine_mode mode; | |
728 | { | |
729 | /* XOR is not here because combine canonicalizes (xor (not ...) ...) | |
730 | and (xor ... (not ...)) to (not (xor ...)). */ | |
731 | return (GET_CODE (op) == AND | |
732 | || GET_CODE (op) == IOR); | |
733 | } | |
734 | \f | |
58cbf20e DE |
735 | /* Return true if OP is a register, or is a CONST_INT that can fit in a |
736 | signed 13 bit immediate field. This is an acceptable SImode operand for | |
737 | most 3 address instructions. */ | |
ab835497 RK |
738 | |
739 | int | |
740 | arith_operand (op, mode) | |
741 | rtx op; | |
742 | enum machine_mode mode; | |
743 | { | |
744 | return (register_operand (op, mode) | |
745 | || (GET_CODE (op) == CONST_INT && SMALL_INT (op))); | |
746 | } | |
747 | ||
58cbf20e DE |
748 | /* Return true if OP is a register, or is a CONST_INT that can fit in a |
749 | signed 11 bit immediate field. This is an acceptable SImode operand for | |
750 | the movcc instructions. */ | |
61a55e8b DE |
751 | |
752 | int | |
753 | arith11_operand (op, mode) | |
754 | rtx op; | |
755 | enum machine_mode mode; | |
756 | { | |
757 | return (register_operand (op, mode) | |
58cbf20e | 758 | || (GET_CODE (op) == CONST_INT && SPARC_SIMM11_P (INTVAL (op)))); |
61a55e8b DE |
759 | } |
760 | ||
58cbf20e DE |
761 | /* Return true if OP is a register, or is a CONST_INT that can fit in a |
762 | signed 10 bit immediate field. This is an acceptable SImode operand for | |
763 | the movrcc instructions. */ | |
61a55e8b DE |
764 | |
765 | int | |
766 | arith10_operand (op, mode) | |
767 | rtx op; | |
768 | enum machine_mode mode; | |
769 | { | |
770 | return (register_operand (op, mode) | |
58cbf20e | 771 | || (GET_CODE (op) == CONST_INT && SPARC_SIMM10_P (INTVAL (op)))); |
61a55e8b DE |
772 | } |
773 | ||
23b8a89f JW |
774 | /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit |
775 | immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit | |
61a55e8b DE |
776 | immediate field. |
777 | v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that | |
778 | can fit in a 13 bit immediate field. This is an acceptable DImode operand | |
779 | for most 3 address instructions. */ | |
ab835497 RK |
780 | |
781 | int | |
782 | arith_double_operand (op, mode) | |
783 | rtx op; | |
784 | enum machine_mode mode; | |
785 | { | |
786 | return (register_operand (op, mode) | |
23b8a89f | 787 | || (GET_CODE (op) == CONST_INT && SMALL_INT (op)) |
a9e27770 | 788 | || (! TARGET_ARCH64 |
61a55e8b | 789 | && GET_CODE (op) == CONST_DOUBLE |
ab835497 | 790 | && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000 |
61a55e8b | 791 | && (unsigned) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000) |
a9e27770 | 792 | || (TARGET_ARCH64 |
61a55e8b DE |
793 | && GET_CODE (op) == CONST_DOUBLE |
794 | && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000 | |
795 | && ((CONST_DOUBLE_HIGH (op) == -1 | |
796 | && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000) | |
797 | || (CONST_DOUBLE_HIGH (op) == 0 | |
798 | && (CONST_DOUBLE_LOW (op) & 0x1000) == 0)))); | |
799 | } | |
800 | ||
801 | /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that | |
802 | can fit in an 11 bit immediate field. This is an acceptable DImode | |
803 | operand for the movcc instructions. */ | |
804 | /* ??? Replace with arith11_operand? */ | |
805 | ||
806 | int | |
807 | arith11_double_operand (op, mode) | |
808 | rtx op; | |
809 | enum machine_mode mode; | |
810 | { | |
811 | return (register_operand (op, mode) | |
812 | || (GET_CODE (op) == CONST_DOUBLE | |
813 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
814 | && (unsigned) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800 | |
815 | && ((CONST_DOUBLE_HIGH (op) == -1 | |
816 | && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400) | |
817 | || (CONST_DOUBLE_HIGH (op) == 0 | |
818 | && (CONST_DOUBLE_LOW (op) & 0x400) == 0))) | |
819 | || (GET_CODE (op) == CONST_INT | |
820 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
821 | && (unsigned) (INTVAL (op) + 0x400) < 0x800)); | |
822 | } | |
823 | ||
824 | /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that | |
825 | can fit in an 10 bit immediate field. This is an acceptable DImode | |
826 | operand for the movrcc instructions. */ | |
827 | /* ??? Replace with arith10_operand? */ | |
828 | ||
829 | int | |
830 | arith10_double_operand (op, mode) | |
831 | rtx op; | |
832 | enum machine_mode mode; | |
833 | { | |
834 | return (register_operand (op, mode) | |
835 | || (GET_CODE (op) == CONST_DOUBLE | |
836 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
837 | && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400 | |
838 | && ((CONST_DOUBLE_HIGH (op) == -1 | |
839 | && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200) | |
840 | || (CONST_DOUBLE_HIGH (op) == 0 | |
841 | && (CONST_DOUBLE_LOW (op) & 0x200) == 0))) | |
842 | || (GET_CODE (op) == CONST_INT | |
843 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
844 | && (unsigned) (INTVAL (op) + 0x200) < 0x400)); | |
ab835497 RK |
845 | } |
846 | ||
847 | /* Return truth value of whether OP is a integer which fits the | |
228b4037 JW |
848 | range constraining immediate operands in most three-address insns, |
849 | which have a 13 bit immediate field. */ | |
ab835497 RK |
850 | |
851 | int | |
852 | small_int (op, mode) | |
853 | rtx op; | |
854 | enum machine_mode mode; | |
855 | { | |
856 | return (GET_CODE (op) == CONST_INT && SMALL_INT (op)); | |
857 | } | |
858 | ||
9b3fad96 JW |
859 | /* Recognize operand values for the umul instruction. That instruction sign |
860 | extends immediate values just like all other sparc instructions, but | |
861 | interprets the extended result as an unsigned number. */ | |
862 | ||
863 | int | |
864 | uns_small_int (op, mode) | |
865 | rtx op; | |
866 | enum machine_mode mode; | |
867 | { | |
868 | #if HOST_BITS_PER_WIDE_INT > 32 | |
869 | /* All allowed constants will fit a CONST_INT. */ | |
870 | return (GET_CODE (op) == CONST_INT | |
871 | && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000) | |
872 | || (INTVAL (op) >= 0xFFFFF000 && INTVAL (op) < 0x100000000L))); | |
873 | #else | |
874 | return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000) | |
875 | || (GET_CODE (op) == CONST_DOUBLE | |
876 | && CONST_DOUBLE_HIGH (op) == 0 | |
877 | && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000)); | |
878 | #endif | |
879 | } | |
880 | ||
881 | int | |
882 | uns_arith_operand (op, mode) | |
883 | rtx op; | |
884 | enum machine_mode mode; | |
885 | { | |
886 | return register_operand (op, mode) || uns_small_int (op, mode); | |
887 | } | |
888 | ||
ab835497 RK |
889 | /* Return truth value of statement that OP is a call-clobbered register. */ |
890 | int | |
891 | clobbered_register (op, mode) | |
892 | rtx op; | |
893 | enum machine_mode mode; | |
894 | { | |
895 | return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]); | |
896 | } | |
897 | \f | |
898 | /* X and Y are two things to compare using CODE. Emit the compare insn and | |
61a55e8b | 899 | return the rtx for the cc reg in the proper mode. */ |
ab835497 RK |
900 | |
901 | rtx | |
902 | gen_compare_reg (code, x, y) | |
903 | enum rtx_code code; | |
904 | rtx x, y; | |
905 | { | |
679655e6 | 906 | enum machine_mode mode = SELECT_CC_MODE (code, x, y); |
61a55e8b DE |
907 | rtx cc_reg; |
908 | ||
909 | /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the | |
c4ce6853 | 910 | fcc regs (cse can't tell they're really call clobbered regs and will |
61a55e8b DE |
911 | remove a duplicate comparison even if there is an intervening function |
912 | call - it will then try to reload the cc reg via an int reg which is why | |
913 | we need the movcc patterns). It is possible to provide the movcc | |
914 | patterns by using the ldxfsr/stxfsr v9 insns. I tried it: you need two | |
915 | registers (say %g1,%g5) and it takes about 6 insns. A better fix would be | |
ddd5a7c1 | 916 | to tell cse that CCFPE mode registers (even pseudos) are call |
61a55e8b DE |
917 | clobbered. */ |
918 | ||
919 | /* ??? This is an experiment. Rather than making changes to cse which may | |
920 | or may not be easy/clean, we do our own cse. This is possible because | |
921 | we will generate hard registers. Cse knows they're call clobbered (it | |
922 | doesn't know the same thing about pseudos). If we guess wrong, no big | |
923 | deal, but if we win, great! */ | |
924 | ||
925 | if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
926 | #if 1 /* experiment */ | |
927 | { | |
928 | int reg; | |
929 | /* We cycle through the registers to ensure they're all exercised. */ | |
c4ce6853 DE |
930 | static int next_fcc_reg = 0; |
931 | /* Previous x,y for each fcc reg. */ | |
61a55e8b DE |
932 | static rtx prev_args[4][2]; |
933 | ||
934 | /* Scan prev_args for x,y. */ | |
935 | for (reg = 0; reg < 4; reg++) | |
936 | if (prev_args[reg][0] == x && prev_args[reg][1] == y) | |
937 | break; | |
938 | if (reg == 4) | |
939 | { | |
c4ce6853 | 940 | reg = next_fcc_reg; |
61a55e8b DE |
941 | prev_args[reg][0] = x; |
942 | prev_args[reg][1] = y; | |
c4ce6853 | 943 | next_fcc_reg = (next_fcc_reg + 1) & 3; |
61a55e8b | 944 | } |
c4ce6853 | 945 | cc_reg = gen_rtx (REG, mode, reg + SPARC_FIRST_V9_FCC_REG); |
61a55e8b DE |
946 | } |
947 | #else | |
948 | cc_reg = gen_reg_rtx (mode); | |
949 | #endif /* ! experiment */ | |
c4ce6853 DE |
950 | else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) |
951 | cc_reg = gen_rtx (REG, mode, SPARC_FCC_REG); | |
61a55e8b | 952 | else |
c4ce6853 | 953 | cc_reg = gen_rtx (REG, mode, SPARC_ICC_REG); |
ab835497 RK |
954 | |
955 | emit_insn (gen_rtx (SET, VOIDmode, cc_reg, | |
956 | gen_rtx (COMPARE, mode, x, y))); | |
957 | ||
958 | return cc_reg; | |
959 | } | |
61a55e8b DE |
960 | |
961 | /* This function is used for v9 only. | |
962 | CODE is the code for an Scc's comparison. | |
963 | OPERANDS[0] is the target of the Scc insn. | |
964 | OPERANDS[1] is the value we compare against const0_rtx (which hasn't | |
965 | been generated yet). | |
966 | ||
967 | This function is needed to turn | |
968 | ||
969 | (set (reg:SI 110) | |
970 | (gt (reg:CCX 0 %g0) | |
971 | (const_int 0))) | |
972 | into | |
973 | (set (reg:SI 110) | |
974 | (gt:DI (reg:CCX 0 %g0) | |
975 | (const_int 0))) | |
976 | ||
977 | IE: The instruction recognizer needs to see the mode of the comparison to | |
978 | find the right instruction. We could use "gt:DI" right in the | |
979 | define_expand, but leaving it out allows us to handle DI, SI, etc. | |
980 | ||
981 | We refer to the global sparc compare operands sparc_compare_op0 and | |
982 | sparc_compare_op1. | |
983 | ||
984 | ??? Some of this is outdated as the scc insns set the mode of the | |
985 | comparison now. | |
986 | ||
987 | ??? We optimize for the case where op1 is 0 and the comparison allows us to | |
988 | use the "movrCC" insns. This reduces the generated code from three to two | |
989 | insns. This way seems too brute force though. Is there a more elegant way | |
990 | to achieve the same effect? | |
a9e27770 | 991 | */ |
61a55e8b DE |
992 | |
993 | int | |
994 | gen_v9_scc (compare_code, operands) | |
995 | enum rtx_code compare_code; | |
996 | register rtx *operands; | |
997 | { | |
998 | rtx temp; | |
999 | ||
a9e27770 DE |
1000 | /* It might be that we'll never be called if this is true, |
1001 | but keep this here for documentation at least. */ | |
1002 | if (! TARGET_ARCH64 | |
1003 | && (GET_MODE (sparc_compare_op0) == DImode | |
1004 | || GET_MODE (operands[0]) == DImode)) | |
1005 | return 0; | |
1006 | ||
1007 | /* Try to use the movrCC insns. */ | |
1008 | if (TARGET_ARCH64 | |
1009 | && GET_MODE_CLASS (GET_MODE (sparc_compare_op0)) == MODE_INT | |
61a55e8b | 1010 | && sparc_compare_op1 == const0_rtx |
a9e27770 | 1011 | && v9_regcmp_p (compare_code)) |
61a55e8b DE |
1012 | { |
1013 | /* Special case for op0 != 0. This can be done with one instruction if | |
1014 | op0 can be clobbered. We store to a temp, and then clobber the temp, | |
1015 | but the combiner will remove the first insn. */ | |
1016 | ||
1017 | if (compare_code == NE | |
1018 | && GET_MODE (operands[0]) == DImode | |
1019 | && GET_MODE (sparc_compare_op0) == DImode) | |
1020 | { | |
1021 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], sparc_compare_op0)); | |
1022 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], | |
304b7a23 | 1023 | gen_rtx (IF_THEN_ELSE, DImode, |
61a55e8b DE |
1024 | gen_rtx (compare_code, DImode, |
1025 | sparc_compare_op0, const0_rtx), | |
1026 | const1_rtx, | |
1027 | operands[0]))); | |
1028 | return 1; | |
1029 | } | |
1030 | ||
1031 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], const0_rtx)); | |
1032 | if (GET_MODE (sparc_compare_op0) != DImode) | |
1033 | { | |
1034 | temp = gen_reg_rtx (DImode); | |
1035 | convert_move (temp, sparc_compare_op0, 0); | |
1036 | } | |
1037 | else | |
1038 | { | |
1039 | temp = sparc_compare_op0; | |
1040 | } | |
1041 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], | |
304b7a23 | 1042 | gen_rtx (IF_THEN_ELSE, GET_MODE (operands[0]), |
61a55e8b DE |
1043 | gen_rtx (compare_code, DImode, |
1044 | temp, const0_rtx), | |
1045 | const1_rtx, | |
1046 | operands[0]))); | |
1047 | return 1; | |
1048 | } | |
1049 | else | |
1050 | { | |
1051 | operands[1] = gen_compare_reg (compare_code, | |
1052 | sparc_compare_op0, sparc_compare_op1); | |
1053 | ||
1054 | switch (GET_MODE (operands[1])) | |
1055 | { | |
1056 | case CCmode : | |
1057 | case CCXmode : | |
1058 | case CCFPEmode : | |
1059 | case CCFPmode : | |
1060 | break; | |
1061 | default : | |
1062 | abort (); | |
1063 | } | |
304b7a23 DE |
1064 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], const0_rtx)); |
1065 | emit_insn (gen_rtx (SET, VOIDmode, operands[0], | |
1066 | gen_rtx (IF_THEN_ELSE, GET_MODE (operands[0]), | |
1067 | gen_rtx (compare_code, | |
1068 | GET_MODE (operands[1]), | |
1069 | operands[1], const0_rtx), | |
1070 | const1_rtx, operands[0]))); | |
1071 | return 1; | |
61a55e8b DE |
1072 | } |
1073 | } | |
1074 | ||
1075 | /* Emit a conditional jump insn for the v9 architecture using comparison code | |
1076 | CODE and jump target LABEL. | |
1077 | This function exists to take advantage of the v9 brxx insns. */ | |
1078 | ||
1079 | void | |
1080 | emit_v9_brxx_insn (code, op0, label) | |
1081 | enum rtx_code code; | |
1082 | rtx op0, label; | |
1083 | { | |
1084 | emit_jump_insn (gen_rtx (SET, VOIDmode, | |
1085 | pc_rtx, | |
1086 | gen_rtx (IF_THEN_ELSE, VOIDmode, | |
1087 | gen_rtx (code, GET_MODE (op0), | |
1088 | op0, const0_rtx), | |
1089 | gen_rtx (LABEL_REF, VOIDmode, label), | |
1090 | pc_rtx))); | |
1091 | } | |
ab835497 RK |
1092 | \f |
1093 | /* Return nonzero if a return peephole merging return with | |
1094 | setting of output register is ok. */ | |
1095 | int | |
1096 | leaf_return_peephole_ok () | |
1097 | { | |
1098 | return (actual_fsize == 0); | |
1099 | } | |
1100 | ||
1101 | /* Return nonzero if TRIAL can go into the function epilogue's | |
1102 | delay slot. SLOT is the slot we are trying to fill. */ | |
1103 | ||
1104 | int | |
1105 | eligible_for_epilogue_delay (trial, slot) | |
1106 | rtx trial; | |
1107 | int slot; | |
1108 | { | |
ab835497 RK |
1109 | rtx pat, src; |
1110 | ||
1111 | if (slot >= 1) | |
1112 | return 0; | |
4bf7135b RK |
1113 | |
1114 | if (GET_CODE (trial) != INSN || GET_CODE (PATTERN (trial)) != SET) | |
ab835497 | 1115 | return 0; |
4bf7135b | 1116 | |
ab835497 RK |
1117 | if (get_attr_length (trial) != 1) |
1118 | return 0; | |
1119 | ||
c4ce6853 DE |
1120 | /* If %g0 is live, there are lots of things we can't handle. |
1121 | Rather than trying to find them all now, let's punt and only | |
1122 | optimize things as necessary. */ | |
1123 | if (TARGET_LIVE_G0) | |
1124 | return 0; | |
1125 | ||
915f619f JW |
1126 | /* In the case of a true leaf function, anything can go into the delay slot. |
1127 | A delay slot only exists however if the frame size is zero, otherwise | |
1128 | we will put an insn to adjust the stack after the return. */ | |
ab835497 RK |
1129 | if (leaf_function) |
1130 | { | |
1131 | if (leaf_return_peephole_ok ()) | |
4bf7135b RK |
1132 | return ((get_attr_in_uncond_branch_delay (trial) |
1133 | == IN_BRANCH_DELAY_TRUE)); | |
ab835497 RK |
1134 | return 0; |
1135 | } | |
4bf7135b | 1136 | |
3592ea0d DE |
1137 | /* If only trivial `restore' insns work, nothing can go in the |
1138 | delay slot. */ | |
1139 | else if (TARGET_BROKEN_SAVERESTORE) | |
1140 | return 0; | |
ab835497 | 1141 | |
1ee4af95 DE |
1142 | pat = PATTERN (trial); |
1143 | ||
ab835497 RK |
1144 | /* Otherwise, only operations which can be done in tandem with |
1145 | a `restore' insn can go into the delay slot. */ | |
ab835497 | 1146 | if (GET_CODE (SET_DEST (pat)) != REG |
915f619f JW |
1147 | || REGNO (SET_DEST (pat)) >= 32 |
1148 | || REGNO (SET_DEST (pat)) < 24) | |
ab835497 | 1149 | return 0; |
915f619f | 1150 | |
4bf7135b RK |
1151 | /* The set of insns matched here must agree precisely with the set of |
1152 | patterns paired with a RETURN in sparc.md. */ | |
1153 | ||
ab835497 | 1154 | src = SET_SRC (pat); |
4bf7135b RK |
1155 | |
1156 | /* This matches "*return_[qhs]". */ | |
ab835497 RK |
1157 | if (arith_operand (src, GET_MODE (src))) |
1158 | return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode); | |
4bf7135b RK |
1159 | |
1160 | /* This matches "*return_di". */ | |
1161 | else if (arith_double_operand (src, GET_MODE (src))) | |
ab835497 | 1162 | return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode); |
4bf7135b RK |
1163 | |
1164 | /* This matches "*return_sf_no_fpu". */ | |
1165 | else if (! TARGET_FPU && restore_operand (SET_DEST (pat), SFmode) | |
1166 | && register_operand (src, SFmode)) | |
1167 | return 1; | |
1168 | ||
1169 | /* This matches "*return_addsi". */ | |
1170 | else if (GET_CODE (src) == PLUS | |
1171 | && arith_operand (XEXP (src, 0), SImode) | |
1172 | && arith_operand (XEXP (src, 1), SImode) | |
1173 | && (register_operand (XEXP (src, 0), SImode) | |
1174 | || register_operand (XEXP (src, 1), SImode))) | |
ab835497 | 1175 | return 1; |
4bf7135b RK |
1176 | |
1177 | /* This matches "*return_adddi". */ | |
1178 | else if (GET_CODE (src) == PLUS | |
1179 | && arith_double_operand (XEXP (src, 0), DImode) | |
1180 | && arith_double_operand (XEXP (src, 1), DImode) | |
1181 | && (register_operand (XEXP (src, 0), DImode) | |
1182 | || register_operand (XEXP (src, 1), DImode))) | |
ab835497 | 1183 | return 1; |
4bf7135b RK |
1184 | |
1185 | /* This matches "*return_subsi". */ | |
1186 | else if (GET_CODE (src) == MINUS | |
1187 | && register_operand (XEXP (src, 0), SImode) | |
1188 | && small_int (XEXP (src, 1), VOIDmode) | |
1189 | && INTVAL (XEXP (src, 1)) != -4096) | |
1190 | return 1; | |
1191 | ||
ab835497 RK |
1192 | return 0; |
1193 | } | |
1194 | ||
1195 | int | |
1196 | short_branch (uid1, uid2) | |
1197 | int uid1, uid2; | |
1198 | { | |
1199 | unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2]; | |
1200 | if (delta + 1024 < 2048) | |
1201 | return 1; | |
1202 | /* warning ("long branch, distance %d", delta); */ | |
1203 | return 0; | |
1204 | } | |
1205 | ||
1206 | /* Return non-zero if REG is not used after INSN. | |
1207 | We assume REG is a reload reg, and therefore does | |
1208 | not live past labels or calls or jumps. */ | |
1209 | int | |
1210 | reg_unused_after (reg, insn) | |
1211 | rtx reg; | |
1212 | rtx insn; | |
1213 | { | |
1214 | enum rtx_code code, prev_code = UNKNOWN; | |
1215 | ||
1216 | while (insn = NEXT_INSN (insn)) | |
1217 | { | |
1218 | if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)]) | |
1219 | return 1; | |
1220 | ||
1221 | code = GET_CODE (insn); | |
1222 | if (GET_CODE (insn) == CODE_LABEL) | |
1223 | return 1; | |
1224 | ||
1225 | if (GET_RTX_CLASS (code) == 'i') | |
1226 | { | |
1227 | rtx set = single_set (insn); | |
1228 | int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set)); | |
1229 | if (set && in_src) | |
1230 | return 0; | |
1231 | if (set && reg_overlap_mentioned_p (reg, SET_DEST (set))) | |
1232 | return 1; | |
1233 | if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn))) | |
1234 | return 0; | |
1235 | } | |
1236 | prev_code = code; | |
1237 | } | |
1238 | return 1; | |
1239 | } | |
1240 | \f | |
6a4bb1fa DE |
1241 | /* The rtx for the global offset table which is a special form |
1242 | that *is* a position independent symbolic constant. */ | |
1243 | static rtx pic_pc_rtx; | |
1244 | ||
1245 | /* Ensure that we are not using patterns that are not OK with PIC. */ | |
1246 | ||
1247 | int | |
1248 | check_pic (i) | |
1249 | int i; | |
1250 | { | |
1251 | switch (flag_pic) | |
1252 | { | |
1253 | case 1: | |
1254 | if (GET_CODE (recog_operand[i]) == SYMBOL_REF | |
1255 | || (GET_CODE (recog_operand[i]) == CONST | |
1256 | && ! rtx_equal_p (pic_pc_rtx, recog_operand[i]))) | |
1257 | abort (); | |
1258 | case 2: | |
1259 | default: | |
1260 | return 1; | |
1261 | } | |
1262 | } | |
1263 | ||
1264 | /* Return true if X is an address which needs a temporary register when | |
1265 | reloaded while generating PIC code. */ | |
1266 | ||
1267 | int | |
1268 | pic_address_needs_scratch (x) | |
1269 | rtx x; | |
1270 | { | |
1271 | /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */ | |
1272 | if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS | |
1273 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF | |
1274 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
1275 | && ! SMALL_INT (XEXP (XEXP (x, 0), 1))) | |
1276 | return 1; | |
1277 | ||
1278 | return 0; | |
1279 | } | |
1280 | ||
ab835497 RK |
1281 | /* Legitimize PIC addresses. If the address is already position-independent, |
1282 | we return ORIG. Newly generated position-independent addresses go into a | |
1283 | reg. This is REG if non zero, otherwise we allocate register(s) as | |
7e2feebf | 1284 | necessary. */ |
ab835497 RK |
1285 | |
1286 | rtx | |
7e2feebf | 1287 | legitimize_pic_address (orig, mode, reg) |
ab835497 RK |
1288 | rtx orig; |
1289 | enum machine_mode mode; | |
7e2feebf | 1290 | rtx reg; |
ab835497 RK |
1291 | { |
1292 | if (GET_CODE (orig) == SYMBOL_REF) | |
1293 | { | |
1294 | rtx pic_ref, address; | |
1295 | rtx insn; | |
1296 | ||
1297 | if (reg == 0) | |
1298 | { | |
01c0e9dc | 1299 | if (reload_in_progress || reload_completed) |
ab835497 RK |
1300 | abort (); |
1301 | else | |
1302 | reg = gen_reg_rtx (Pmode); | |
1303 | } | |
1304 | ||
1305 | if (flag_pic == 2) | |
1306 | { | |
1307 | /* If not during reload, allocate another temp reg here for loading | |
1308 | in the address, so that these instructions can be optimized | |
1309 | properly. */ | |
01c0e9dc JW |
1310 | rtx temp_reg = ((reload_in_progress || reload_completed) |
1311 | ? reg : gen_reg_rtx (Pmode)); | |
ab835497 | 1312 | |
b4ac57ab RS |
1313 | /* Must put the SYMBOL_REF inside an UNSPEC here so that cse |
1314 | won't get confused into thinking that these two instructions | |
1315 | are loading in the true address of the symbol. If in the | |
1316 | future a PIC rtx exists, that should be used instead. */ | |
95726648 DE |
1317 | emit_insn (gen_pic_sethi_si (temp_reg, orig)); |
1318 | emit_insn (gen_pic_lo_sum_si (temp_reg, temp_reg, orig)); | |
1319 | ||
ab835497 RK |
1320 | address = temp_reg; |
1321 | } | |
1322 | else | |
1323 | address = orig; | |
1324 | ||
1325 | pic_ref = gen_rtx (MEM, Pmode, | |
1326 | gen_rtx (PLUS, Pmode, | |
1327 | pic_offset_table_rtx, address)); | |
1328 | current_function_uses_pic_offset_table = 1; | |
1329 | RTX_UNCHANGING_P (pic_ref) = 1; | |
1330 | insn = emit_move_insn (reg, pic_ref); | |
1331 | /* Put a REG_EQUAL note on this insn, so that it can be optimized | |
1332 | by loop. */ | |
1333 | REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig, | |
1334 | REG_NOTES (insn)); | |
1335 | return reg; | |
1336 | } | |
1337 | else if (GET_CODE (orig) == CONST) | |
1338 | { | |
1339 | rtx base, offset; | |
1340 | ||
1341 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
1342 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
1343 | return orig; | |
1344 | ||
1345 | if (reg == 0) | |
1346 | { | |
01c0e9dc | 1347 | if (reload_in_progress || reload_completed) |
ab835497 RK |
1348 | abort (); |
1349 | else | |
1350 | reg = gen_reg_rtx (Pmode); | |
1351 | } | |
1352 | ||
1353 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
1354 | { | |
7e2feebf | 1355 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg); |
ab835497 | 1356 | offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, |
7e2feebf | 1357 | base == reg ? 0 : reg); |
ab835497 RK |
1358 | } |
1359 | else | |
1360 | abort (); | |
1361 | ||
1362 | if (GET_CODE (offset) == CONST_INT) | |
1363 | { | |
1364 | if (SMALL_INT (offset)) | |
1365 | return plus_constant_for_output (base, INTVAL (offset)); | |
01c0e9dc | 1366 | else if (! reload_in_progress && ! reload_completed) |
ab835497 | 1367 | offset = force_reg (Pmode, offset); |
ab835497 | 1368 | else |
7e2feebf | 1369 | /* If we reach here, then something is seriously wrong. */ |
ab835497 RK |
1370 | abort (); |
1371 | } | |
1372 | return gen_rtx (PLUS, Pmode, base, offset); | |
1373 | } | |
1374 | else if (GET_CODE (orig) == LABEL_REF) | |
95726648 | 1375 | /* ??? Why do we do this? */ |
ab835497 RK |
1376 | current_function_uses_pic_offset_table = 1; |
1377 | ||
1378 | return orig; | |
1379 | } | |
1380 | ||
1381 | /* Set up PIC-specific rtl. This should not cause any insns | |
1382 | to be emitted. */ | |
1383 | ||
1384 | void | |
1385 | initialize_pic () | |
1386 | { | |
1387 | } | |
1388 | ||
1389 | /* Emit special PIC prologues and epilogues. */ | |
1390 | ||
1391 | void | |
1392 | finalize_pic () | |
1393 | { | |
1394 | /* The table we use to reference PIC data. */ | |
1395 | rtx global_offset_table; | |
1396 | /* Labels to get the PC in the prologue of this function. */ | |
1397 | rtx l1, l2; | |
1398 | rtx seq; | |
1399 | int orig_flag_pic = flag_pic; | |
1400 | ||
1401 | if (current_function_uses_pic_offset_table == 0) | |
1402 | return; | |
1403 | ||
1404 | if (! flag_pic) | |
1405 | abort (); | |
1406 | ||
1407 | flag_pic = 0; | |
95726648 DE |
1408 | |
1409 | /* ??? sparc64 pic currently under construction. */ | |
ab835497 RK |
1410 | |
1411 | start_sequence (); | |
1412 | ||
95726648 | 1413 | l1 = gen_label_rtx (); |
ab835497 RK |
1414 | |
1415 | /* Initialize every time through, since we can't easily | |
1416 | know this to be permanent. */ | |
c4eb2bd7 | 1417 | global_offset_table = gen_rtx (SYMBOL_REF, Pmode, "_GLOBAL_OFFSET_TABLE_"); |
ab835497 RK |
1418 | pic_pc_rtx = gen_rtx (CONST, Pmode, |
1419 | gen_rtx (MINUS, Pmode, | |
1420 | global_offset_table, | |
1421 | gen_rtx (CONST, Pmode, | |
1422 | gen_rtx (MINUS, Pmode, | |
1423 | gen_rtx (LABEL_REF, VOIDmode, l1), | |
1424 | pc_rtx)))); | |
1425 | ||
95726648 DE |
1426 | if (! TARGET_ARCH64) |
1427 | { | |
1428 | l2 = gen_label_rtx (); | |
1429 | emit_label (l1); | |
1430 | /* Note that we pun calls and jumps here! */ | |
1431 | emit_jump_insn (gen_get_pc_sp32 (l2)); | |
1432 | emit_label (l2); | |
1433 | ||
1434 | emit_insn (gen_rtx (SET, VOIDmode, pic_offset_table_rtx, | |
1435 | gen_rtx (HIGH, Pmode, pic_pc_rtx))); | |
1436 | ||
1437 | emit_insn (gen_rtx (SET, VOIDmode, | |
1438 | pic_offset_table_rtx, | |
1439 | gen_rtx (LO_SUM, Pmode, | |
1440 | pic_offset_table_rtx, pic_pc_rtx))); | |
1441 | emit_insn (gen_rtx (SET, VOIDmode, | |
1442 | pic_offset_table_rtx, | |
1443 | gen_rtx (PLUS, Pmode, | |
1444 | pic_offset_table_rtx, | |
1445 | gen_rtx (REG, Pmode, 15)))); | |
1446 | ||
1447 | /* emit_insn (gen_rtx (ASM_INPUT, VOIDmode, "!#PROLOGUE# 1")); */ | |
1448 | LABEL_PRESERVE_P (l1) = 1; | |
1449 | LABEL_PRESERVE_P (l2) = 1; | |
1450 | } | |
61a55e8b | 1451 | else |
95726648 DE |
1452 | { |
1453 | /* ??? This definately isn't right for -mfullany. */ | |
1454 | /* ??? And it doesn't quite seem right for the others either. */ | |
1455 | emit_label (l1); | |
1456 | emit_insn (gen_get_pc_sp64 (gen_rtx (REG, Pmode, 1))); | |
1457 | ||
1458 | /* Don't let the scheduler separate the previous insn from `l1'. */ | |
1459 | emit_insn (gen_blockage ()); | |
1460 | ||
1461 | emit_insn (gen_rtx (SET, VOIDmode, pic_offset_table_rtx, | |
1462 | gen_rtx (HIGH, Pmode, pic_pc_rtx))); | |
1463 | ||
1464 | emit_insn (gen_rtx (SET, VOIDmode, | |
1465 | pic_offset_table_rtx, | |
1466 | gen_rtx (LO_SUM, Pmode, | |
1467 | pic_offset_table_rtx, pic_pc_rtx))); | |
1468 | emit_insn (gen_rtx (SET, VOIDmode, | |
1469 | pic_offset_table_rtx, | |
1470 | gen_rtx (PLUS, Pmode, | |
1471 | pic_offset_table_rtx, gen_rtx (REG, Pmode, 1)))); | |
1472 | ||
1473 | /* emit_insn (gen_rtx (ASM_INPUT, VOIDmode, "!#PROLOGUE# 1")); */ | |
1474 | LABEL_PRESERVE_P (l1) = 1; | |
1475 | } | |
1476 | ||
ab835497 RK |
1477 | flag_pic = orig_flag_pic; |
1478 | ||
1479 | seq = gen_sequence (); | |
1480 | end_sequence (); | |
1481 | emit_insn_after (seq, get_insns ()); | |
1482 | ||
1483 | /* Need to emit this whether or not we obey regdecls, | |
1484 | since setjmp/longjmp can cause life info to screw up. */ | |
1485 | emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx)); | |
1486 | } | |
1487 | \f | |
ab835497 RK |
1488 | /* Emit insns to move operands[1] into operands[0]. |
1489 | ||
1490 | Return 1 if we have written out everything that needs to be done to | |
1491 | do the move. Otherwise, return 0 and the caller will emit the move | |
7e2feebf | 1492 | normally. */ |
ab835497 RK |
1493 | |
1494 | int | |
7e2feebf | 1495 | emit_move_sequence (operands, mode) |
ab835497 RK |
1496 | rtx *operands; |
1497 | enum machine_mode mode; | |
ab835497 RK |
1498 | { |
1499 | register rtx operand0 = operands[0]; | |
1500 | register rtx operand1 = operands[1]; | |
1501 | ||
7e2feebf JW |
1502 | if (CONSTANT_P (operand1) && flag_pic |
1503 | && pic_address_needs_scratch (operand1)) | |
1504 | operands[1] = operand1 = legitimize_pic_address (operand1, mode, 0); | |
1505 | ||
ab835497 RK |
1506 | /* Handle most common case first: storing into a register. */ |
1507 | if (register_operand (operand0, mode)) | |
1508 | { | |
1509 | if (register_operand (operand1, mode) | |
1510 | || (GET_CODE (operand1) == CONST_INT && SMALL_INT (operand1)) | |
1511 | || (GET_CODE (operand1) == CONST_DOUBLE | |
1512 | && arith_double_operand (operand1, DImode)) | |
1513 | || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) != DImode) | |
1514 | /* Only `general_operands' can come here, so MEM is ok. */ | |
1515 | || GET_CODE (operand1) == MEM) | |
1516 | { | |
1517 | /* Run this case quickly. */ | |
1518 | emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1)); | |
1519 | return 1; | |
1520 | } | |
1521 | } | |
1522 | else if (GET_CODE (operand0) == MEM) | |
1523 | { | |
c4ce6853 DE |
1524 | if (register_operand (operand1, mode) |
1525 | || (operand1 == const0_rtx && ! TARGET_LIVE_G0)) | |
ab835497 RK |
1526 | { |
1527 | /* Run this case quickly. */ | |
1528 | emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1)); | |
1529 | return 1; | |
1530 | } | |
1531 | if (! reload_in_progress) | |
1532 | { | |
1533 | operands[0] = validize_mem (operand0); | |
1534 | operands[1] = operand1 = force_reg (mode, operand1); | |
1535 | } | |
1536 | } | |
1537 | ||
95726648 DE |
1538 | if (GET_CODE (operand1) == LABEL_REF |
1539 | && mode == SImode && flag_pic) | |
1540 | { | |
1541 | if (TARGET_ARCH64) | |
1542 | abort (); | |
d6b65167 | 1543 | emit_insn (gen_move_pic_label_si (operand0, operand1)); |
95726648 DE |
1544 | return 1; |
1545 | } | |
1546 | /* Non-pic LABEL_REF's in sparc64 are expensive to do the normal way, | |
1547 | so always use special code. */ | |
1548 | else if (GET_CODE (operand1) == LABEL_REF | |
1549 | && mode == DImode) | |
1550 | { | |
1551 | if (! TARGET_ARCH64) | |
1552 | abort (); | |
5ab7138b | 1553 | emit_insn (gen_move_label_di (operand0, operand1)); |
95726648 DE |
1554 | return 1; |
1555 | } | |
1556 | /* DImode HIGH values in sparc64 need a clobber added. */ | |
1557 | else if (TARGET_ARCH64 | |
1558 | && GET_CODE (operand1) == HIGH && GET_MODE (operand1) == DImode) | |
1559 | { | |
1560 | emit_insn (gen_sethi_di_sp64 (operand0, XEXP (operand1, 0))); | |
1561 | return 1; | |
1562 | } | |
1563 | /* Simplify the source if we need to. */ | |
1564 | else if (GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode)) | |
ab835497 RK |
1565 | { |
1566 | if (flag_pic && symbolic_operand (operand1, mode)) | |
1567 | { | |
1568 | rtx temp_reg = reload_in_progress ? operand0 : 0; | |
1569 | ||
7e2feebf | 1570 | operands[1] = legitimize_pic_address (operand1, mode, temp_reg); |
ab835497 RK |
1571 | } |
1572 | else if (GET_CODE (operand1) == CONST_INT | |
1573 | ? (! SMALL_INT (operand1) | |
1574 | && (INTVAL (operand1) & 0x3ff) != 0) | |
1575 | : (GET_CODE (operand1) == CONST_DOUBLE | |
1576 | ? ! arith_double_operand (operand1, DImode) | |
1577 | : 1)) | |
1578 | { | |
1579 | /* For DImode values, temp must be operand0 because of the way | |
1580 | HI and LO_SUM work. The LO_SUM operator only copies half of | |
1581 | the LSW from the dest of the HI operator. If the LO_SUM dest is | |
1582 | not the same as the HI dest, then the MSW of the LO_SUM dest will | |
1583 | never be set. | |
1584 | ||
1585 | ??? The real problem here is that the ...(HI:DImode pattern emits | |
1586 | multiple instructions, and the ...(LO_SUM:DImode pattern emits | |
1587 | one instruction. This fails, because the compiler assumes that | |
1588 | LO_SUM copies all bits of the first operand to its dest. Better | |
1589 | would be to have the HI pattern emit one instruction and the | |
1590 | LO_SUM pattern multiple instructions. Even better would be | |
1591 | to use four rtl insns. */ | |
1592 | rtx temp = ((reload_in_progress || mode == DImode) | |
1593 | ? operand0 : gen_reg_rtx (mode)); | |
1594 | ||
a9e27770 | 1595 | if (TARGET_ARCH64 && mode == DImode) |
95726648 | 1596 | emit_insn (gen_sethi_di_sp64 (temp, operand1)); |
61a55e8b DE |
1597 | else |
1598 | emit_insn (gen_rtx (SET, VOIDmode, temp, | |
1599 | gen_rtx (HIGH, mode, operand1))); | |
1600 | ||
ab835497 RK |
1601 | operands[1] = gen_rtx (LO_SUM, mode, temp, operand1); |
1602 | } | |
1603 | } | |
1604 | ||
ab835497 RK |
1605 | /* Now have insn-emit do whatever it normally does. */ |
1606 | return 0; | |
1607 | } | |
1608 | \f | |
1609 | /* Return the best assembler insn template | |
1610 | for moving operands[1] into operands[0] as a fullword. */ | |
1611 | ||
1612 | char * | |
1613 | singlemove_string (operands) | |
1614 | rtx *operands; | |
1615 | { | |
1616 | if (GET_CODE (operands[0]) == MEM) | |
1617 | { | |
1618 | if (GET_CODE (operands[1]) != MEM) | |
1619 | return "st %r1,%0"; | |
1620 | else | |
1621 | abort (); | |
1622 | } | |
2b9a9aea | 1623 | else if (GET_CODE (operands[1]) == MEM) |
ab835497 | 1624 | return "ld %1,%0"; |
2b9a9aea JW |
1625 | else if (GET_CODE (operands[1]) == CONST_DOUBLE) |
1626 | { | |
c90fb4e6 JW |
1627 | REAL_VALUE_TYPE r; |
1628 | long i; | |
2b9a9aea JW |
1629 | |
1630 | /* Must be SFmode, otherwise this doesn't make sense. */ | |
1631 | if (GET_MODE (operands[1]) != SFmode) | |
1632 | abort (); | |
1633 | ||
c90fb4e6 JW |
1634 | REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]); |
1635 | REAL_VALUE_TO_TARGET_SINGLE (r, i); | |
2b9a9aea JW |
1636 | operands[1] = gen_rtx (CONST_INT, VOIDmode, i); |
1637 | ||
1638 | if (CONST_OK_FOR_LETTER_P (i, 'I')) | |
1639 | return "mov %1,%0"; | |
1640 | else if ((i & 0x000003FF) != 0) | |
1641 | return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0"; | |
1642 | else | |
1643 | return "sethi %%hi(%a1),%0"; | |
1644 | } | |
1645 | else if (GET_CODE (operands[1]) == CONST_INT | |
1646 | && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'I')) | |
ab835497 RK |
1647 | { |
1648 | int i = INTVAL (operands[1]); | |
1649 | ||
915f619f | 1650 | /* If all low order 10 bits are clear, then we only need a single |
ab835497 | 1651 | sethi insn to load the constant. */ |
915f619f | 1652 | if ((i & 0x000003FF) != 0) |
ab835497 RK |
1653 | return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0"; |
1654 | else | |
1655 | return "sethi %%hi(%a1),%0"; | |
1656 | } | |
2b9a9aea | 1657 | /* Operand 1 must be a register, or a 'I' type CONST_INT. */ |
ab835497 RK |
1658 | return "mov %1,%0"; |
1659 | } | |
1660 | \f | |
795068a4 JW |
1661 | /* Return non-zero if it is OK to assume that the given memory operand is |
1662 | aligned at least to a 8-byte boundary. This should only be called | |
1663 | for memory accesses whose size is 8 bytes or larger. */ | |
1664 | ||
7c56249d | 1665 | int |
795068a4 JW |
1666 | mem_aligned_8 (mem) |
1667 | register rtx mem; | |
1668 | { | |
1669 | register rtx addr; | |
1670 | register rtx base; | |
1671 | register rtx offset; | |
1672 | ||
1673 | if (GET_CODE (mem) != MEM) | |
7c56249d | 1674 | return 0; /* It's gotta be a MEM! */ |
795068a4 JW |
1675 | |
1676 | addr = XEXP (mem, 0); | |
1677 | ||
795068a4 | 1678 | /* Now that all misaligned double parms are copied on function entry, |
1934ceca JW |
1679 | we can assume any 64-bit object is 64-bit aligned except those which |
1680 | are at unaligned offsets from the stack or frame pointer. If the | |
1681 | TARGET_UNALIGNED_DOUBLES switch is given, we do not make this | |
1682 | assumption. */ | |
795068a4 JW |
1683 | |
1684 | /* See what register we use in the address. */ | |
1685 | base = 0; | |
1686 | if (GET_CODE (addr) == PLUS) | |
1687 | { | |
1688 | if (GET_CODE (XEXP (addr, 0)) == REG | |
1689 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
1690 | { | |
1691 | base = XEXP (addr, 0); | |
1692 | offset = XEXP (addr, 1); | |
1693 | } | |
1694 | } | |
1695 | else if (GET_CODE (addr) == REG) | |
1696 | { | |
1697 | base = addr; | |
1698 | offset = const0_rtx; | |
1699 | } | |
1700 | ||
1701 | /* If it's the stack or frame pointer, check offset alignment. | |
2296cba3 | 1702 | We can have improper alignment in the function entry code. */ |
795068a4 JW |
1703 | if (base |
1704 | && (REGNO (base) == FRAME_POINTER_REGNUM | |
1705 | || REGNO (base) == STACK_POINTER_REGNUM)) | |
1706 | { | |
61a55e8b | 1707 | if (((INTVAL (offset) - SPARC_STACK_BIAS) & 0x7) == 0) |
795068a4 JW |
1708 | return 1; |
1709 | } | |
1934ceca JW |
1710 | /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES |
1711 | is true, in which case we can only assume that an access is aligned if | |
f5da225e JW |
1712 | it is to a constant address, or the address involves a LO_SUM. |
1713 | ||
1714 | We used to assume an address was aligned if MEM_IN_STRUCT_P was true. | |
1715 | That assumption was deleted so that gcc generated code can be used with | |
1716 | memory allocators that only guarantee 4 byte alignment. */ | |
1717 | else if (! TARGET_UNALIGNED_DOUBLES || CONSTANT_P (addr) | |
1718 | || GET_CODE (addr) == LO_SUM) | |
795068a4 | 1719 | return 1; |
795068a4 JW |
1720 | |
1721 | /* An obviously unaligned address. */ | |
1722 | return 0; | |
1723 | } | |
1724 | ||
1725 | enum optype { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP }; | |
1726 | ||
ab835497 | 1727 | /* Output assembler code to perform a doubleword move insn |
795068a4 JW |
1728 | with operands OPERANDS. This is very similar to the following |
1729 | output_move_quad function. */ | |
ab835497 RK |
1730 | |
1731 | char * | |
1732 | output_move_double (operands) | |
1733 | rtx *operands; | |
1734 | { | |
795068a4 JW |
1735 | register rtx op0 = operands[0]; |
1736 | register rtx op1 = operands[1]; | |
1737 | register enum optype optype0; | |
1738 | register enum optype optype1; | |
ab835497 | 1739 | rtx latehalf[2]; |
795068a4 JW |
1740 | rtx addreg0 = 0; |
1741 | rtx addreg1 = 0; | |
3b76513a | 1742 | int highest_first = 0; |
f3a9d1e6 | 1743 | int no_addreg1_decrement = 0; |
ab835497 RK |
1744 | |
1745 | /* First classify both operands. */ | |
1746 | ||
795068a4 | 1747 | if (REG_P (op0)) |
ab835497 | 1748 | optype0 = REGOP; |
795068a4 | 1749 | else if (offsettable_memref_p (op0)) |
ab835497 | 1750 | optype0 = OFFSOP; |
795068a4 | 1751 | else if (GET_CODE (op0) == MEM) |
ab835497 RK |
1752 | optype0 = MEMOP; |
1753 | else | |
1754 | optype0 = RNDOP; | |
1755 | ||
795068a4 | 1756 | if (REG_P (op1)) |
ab835497 | 1757 | optype1 = REGOP; |
795068a4 | 1758 | else if (CONSTANT_P (op1)) |
ab835497 | 1759 | optype1 = CNSTOP; |
795068a4 | 1760 | else if (offsettable_memref_p (op1)) |
ab835497 | 1761 | optype1 = OFFSOP; |
795068a4 | 1762 | else if (GET_CODE (op1) == MEM) |
ab835497 RK |
1763 | optype1 = MEMOP; |
1764 | else | |
1765 | optype1 = RNDOP; | |
1766 | ||
1767 | /* Check for the cases that the operand constraints are not | |
1768 | supposed to allow to happen. Abort if we get one, | |
1769 | because generating code for these cases is painful. */ | |
1770 | ||
795068a4 JW |
1771 | if (optype0 == RNDOP || optype1 == RNDOP |
1772 | || (optype0 == MEM && optype1 == MEM)) | |
ab835497 RK |
1773 | abort (); |
1774 | ||
1775 | /* If an operand is an unoffsettable memory ref, find a register | |
1776 | we can increment temporarily to make it refer to the second word. */ | |
1777 | ||
1778 | if (optype0 == MEMOP) | |
795068a4 | 1779 | addreg0 = find_addr_reg (XEXP (op0, 0)); |
ab835497 RK |
1780 | |
1781 | if (optype1 == MEMOP) | |
795068a4 | 1782 | addreg1 = find_addr_reg (XEXP (op1, 0)); |
ab835497 RK |
1783 | |
1784 | /* Ok, we can do one word at a time. | |
795068a4 | 1785 | Set up in LATEHALF the operands to use for the |
ab835497 RK |
1786 | high-numbered (least significant) word and in some cases alter the |
1787 | operands in OPERANDS to be suitable for the low-numbered word. */ | |
1788 | ||
1789 | if (optype0 == REGOP) | |
795068a4 | 1790 | latehalf[0] = gen_rtx (REG, SImode, REGNO (op0) + 1); |
ab835497 | 1791 | else if (optype0 == OFFSOP) |
795068a4 | 1792 | latehalf[0] = adj_offsettable_operand (op0, 4); |
ab835497 | 1793 | else |
795068a4 | 1794 | latehalf[0] = op0; |
ab835497 RK |
1795 | |
1796 | if (optype1 == REGOP) | |
795068a4 | 1797 | latehalf[1] = gen_rtx (REG, SImode, REGNO (op1) + 1); |
ab835497 | 1798 | else if (optype1 == OFFSOP) |
795068a4 | 1799 | latehalf[1] = adj_offsettable_operand (op1, 4); |
ab835497 | 1800 | else if (optype1 == CNSTOP) |
61a55e8b | 1801 | { |
a9e27770 | 1802 | if (TARGET_ARCH64) |
61a55e8b DE |
1803 | { |
1804 | if (arith_double_operand (op1, DImode)) | |
1805 | { | |
1806 | operands[1] = gen_rtx (CONST_INT, VOIDmode, | |
1807 | CONST_DOUBLE_LOW (op1)); | |
1808 | return "mov %1,%0"; | |
1809 | } | |
1810 | else | |
1811 | { | |
1812 | /* The only way to handle CONST_DOUBLEs or other 64 bit | |
1813 | constants here is to use a temporary, such as is done | |
1814 | for the V9 DImode sethi insn pattern. This is not | |
1815 | a practical solution, so abort if we reach here. | |
1816 | The md file should always force such constants to | |
1817 | memory. */ | |
1818 | abort (); | |
1819 | } | |
1820 | } | |
1821 | else | |
1822 | split_double (op1, &operands[1], &latehalf[1]); | |
1823 | } | |
ab835497 | 1824 | else |
795068a4 | 1825 | latehalf[1] = op1; |
ab835497 | 1826 | |
795068a4 JW |
1827 | /* Easy case: try moving both words at once. Check for moving between |
1828 | an even/odd register pair and a memory location. */ | |
ab835497 | 1829 | if ((optype0 == REGOP && optype1 != REGOP && optype1 != CNSTOP |
a9e27770 | 1830 | && (TARGET_ARCH64 || (REGNO (op0) & 1) == 0)) |
ab835497 | 1831 | || (optype0 != REGOP && optype0 != CNSTOP && optype1 == REGOP |
a9e27770 | 1832 | && (TARGET_ARCH64 || (REGNO (op1) & 1) == 0))) |
ab835497 | 1833 | { |
61a55e8b | 1834 | register rtx mem,reg; |
bc961ed7 RS |
1835 | |
1836 | if (optype0 == REGOP) | |
61a55e8b | 1837 | mem = op1, reg = op0; |
bc961ed7 | 1838 | else |
61a55e8b DE |
1839 | mem = op0, reg = op1; |
1840 | ||
1841 | /* In v9, ldd can be used for word aligned addresses, so technically | |
1842 | some of this logic is unneeded. We still avoid ldd if the address | |
1843 | is obviously unaligned though. */ | |
1844 | ||
1845 | if (mem_aligned_8 (mem) | |
1846 | /* If this is a floating point register higher than %f31, | |
1847 | then we *must* use an aligned load, since `ld' will not accept | |
1848 | the register number. */ | |
1849 | || (TARGET_V9 && REGNO (reg) >= 64)) | |
1850 | { | |
a9e27770 | 1851 | if (FP_REG_P (reg) || ! TARGET_ARCH64) |
61a55e8b DE |
1852 | return (mem == op1 ? "ldd %1,%0" : "std %1,%0"); |
1853 | else | |
1854 | return (mem == op1 ? "ldx %1,%0" : "stx %1,%0"); | |
1855 | } | |
1856 | } | |
bc961ed7 | 1857 | |
a9e27770 | 1858 | if (TARGET_ARCH64) |
61a55e8b DE |
1859 | { |
1860 | if (optype0 == REGOP && optype1 == REGOP) | |
1861 | { | |
1862 | if (FP_REG_P (op0)) | |
1863 | return "fmovd %1,%0"; | |
1864 | else | |
1865 | return "mov %1,%0"; | |
1866 | } | |
ab835497 RK |
1867 | } |
1868 | ||
795068a4 JW |
1869 | /* If the first move would clobber the source of the second one, |
1870 | do them in the other order. */ | |
1871 | ||
1872 | /* Overlapping registers. */ | |
ab835497 | 1873 | if (optype0 == REGOP && optype1 == REGOP |
795068a4 | 1874 | && REGNO (op0) == REGNO (latehalf[1])) |
ab835497 | 1875 | { |
ab835497 RK |
1876 | /* Do that word. */ |
1877 | output_asm_insn (singlemove_string (latehalf), latehalf); | |
ab835497 RK |
1878 | /* Do low-numbered word. */ |
1879 | return singlemove_string (operands); | |
1880 | } | |
795068a4 | 1881 | /* Loading into a register which overlaps a register used in the address. */ |
ab835497 | 1882 | else if (optype0 == REGOP && optype1 != REGOP |
795068a4 | 1883 | && reg_overlap_mentioned_p (op0, op1)) |
ab835497 | 1884 | { |
f3a9d1e6 JW |
1885 | /* If both halves of dest are used in the src memory address, |
1886 | add the two regs and put them in the low reg (op0). | |
1887 | Then it works to load latehalf first. */ | |
bdec790c RS |
1888 | if (reg_mentioned_p (op0, XEXP (op1, 0)) |
1889 | && reg_mentioned_p (latehalf[0], XEXP (op1, 0))) | |
1890 | { | |
bdec790c RS |
1891 | rtx xops[2]; |
1892 | xops[0] = latehalf[0]; | |
1893 | xops[1] = op0; | |
1894 | output_asm_insn ("add %1,%0,%1", xops); | |
3b76513a | 1895 | operands[1] = gen_rtx (MEM, DImode, op0); |
bdec790c | 1896 | latehalf[1] = adj_offsettable_operand (operands[1], 4); |
3b76513a | 1897 | addreg1 = 0; |
f3a9d1e6 | 1898 | highest_first = 1; |
bdec790c | 1899 | } |
f3a9d1e6 JW |
1900 | /* Only one register in the dest is used in the src memory address, |
1901 | and this is the first register of the dest, so we want to do | |
1902 | the late half first here also. */ | |
1903 | else if (! reg_mentioned_p (latehalf[0], XEXP (op1, 0))) | |
1904 | highest_first = 1; | |
1905 | /* Only one register in the dest is used in the src memory address, | |
1906 | and this is the second register of the dest, so we want to do | |
1907 | the late half last. If addreg1 is set, and addreg1 is the same | |
1908 | register as latehalf, then we must suppress the trailing decrement, | |
1909 | because it would clobber the value just loaded. */ | |
1910 | else if (addreg1 && reg_mentioned_p (addreg1, latehalf[0])) | |
1911 | no_addreg1_decrement = 1; | |
ab835497 RK |
1912 | } |
1913 | ||
3b76513a RS |
1914 | /* Normal case: do the two words, low-numbered first. |
1915 | Overlap case (highest_first set): do high-numbered word first. */ | |
ab835497 | 1916 | |
3b76513a RS |
1917 | if (! highest_first) |
1918 | output_asm_insn (singlemove_string (operands), operands); | |
ab835497 RK |
1919 | |
1920 | /* Make any unoffsettable addresses point at high-numbered word. */ | |
1921 | if (addreg0) | |
1922 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
1923 | if (addreg1) | |
1924 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
1925 | ||
1926 | /* Do that word. */ | |
1927 | output_asm_insn (singlemove_string (latehalf), latehalf); | |
1928 | ||
1929 | /* Undo the adds we just did. */ | |
1930 | if (addreg0) | |
1931 | output_asm_insn ("add %0,-0x4,%0", &addreg0); | |
f3a9d1e6 | 1932 | if (addreg1 && ! no_addreg1_decrement) |
ab835497 RK |
1933 | output_asm_insn ("add %0,-0x4,%0", &addreg1); |
1934 | ||
3b76513a RS |
1935 | if (highest_first) |
1936 | output_asm_insn (singlemove_string (operands), operands); | |
1937 | ||
ab835497 RK |
1938 | return ""; |
1939 | } | |
795068a4 JW |
1940 | |
1941 | /* Output assembler code to perform a quadword move insn | |
2296cba3 | 1942 | with operands OPERANDS. This is very similar to the preceding |
795068a4 JW |
1943 | output_move_double function. */ |
1944 | ||
1945 | char * | |
1946 | output_move_quad (operands) | |
1947 | rtx *operands; | |
1948 | { | |
1949 | register rtx op0 = operands[0]; | |
1950 | register rtx op1 = operands[1]; | |
1951 | register enum optype optype0; | |
1952 | register enum optype optype1; | |
1953 | rtx wordpart[4][2]; | |
1954 | rtx addreg0 = 0; | |
1955 | rtx addreg1 = 0; | |
1956 | ||
1957 | /* First classify both operands. */ | |
1958 | ||
1959 | if (REG_P (op0)) | |
1960 | optype0 = REGOP; | |
1961 | else if (offsettable_memref_p (op0)) | |
1962 | optype0 = OFFSOP; | |
1963 | else if (GET_CODE (op0) == MEM) | |
1964 | optype0 = MEMOP; | |
1965 | else | |
1966 | optype0 = RNDOP; | |
1967 | ||
1968 | if (REG_P (op1)) | |
1969 | optype1 = REGOP; | |
1970 | else if (CONSTANT_P (op1)) | |
1971 | optype1 = CNSTOP; | |
1972 | else if (offsettable_memref_p (op1)) | |
1973 | optype1 = OFFSOP; | |
1974 | else if (GET_CODE (op1) == MEM) | |
1975 | optype1 = MEMOP; | |
1976 | else | |
1977 | optype1 = RNDOP; | |
1978 | ||
1979 | /* Check for the cases that the operand constraints are not | |
1980 | supposed to allow to happen. Abort if we get one, | |
1981 | because generating code for these cases is painful. */ | |
1982 | ||
1983 | if (optype0 == RNDOP || optype1 == RNDOP | |
1984 | || (optype0 == MEM && optype1 == MEM)) | |
1985 | abort (); | |
1986 | ||
1987 | /* If an operand is an unoffsettable memory ref, find a register | |
1988 | we can increment temporarily to make it refer to the later words. */ | |
1989 | ||
1990 | if (optype0 == MEMOP) | |
1991 | addreg0 = find_addr_reg (XEXP (op0, 0)); | |
1992 | ||
1993 | if (optype1 == MEMOP) | |
1994 | addreg1 = find_addr_reg (XEXP (op1, 0)); | |
1995 | ||
1996 | /* Ok, we can do one word at a time. | |
1997 | Set up in wordpart the operands to use for each word of the arguments. */ | |
1998 | ||
1999 | if (optype0 == REGOP) | |
2000 | { | |
2001 | wordpart[0][0] = gen_rtx (REG, SImode, REGNO (op0) + 0); | |
2002 | wordpart[1][0] = gen_rtx (REG, SImode, REGNO (op0) + 1); | |
2003 | wordpart[2][0] = gen_rtx (REG, SImode, REGNO (op0) + 2); | |
2004 | wordpart[3][0] = gen_rtx (REG, SImode, REGNO (op0) + 3); | |
2005 | } | |
2006 | else if (optype0 == OFFSOP) | |
2007 | { | |
2008 | wordpart[0][0] = adj_offsettable_operand (op0, 0); | |
2009 | wordpart[1][0] = adj_offsettable_operand (op0, 4); | |
2010 | wordpart[2][0] = adj_offsettable_operand (op0, 8); | |
2011 | wordpart[3][0] = adj_offsettable_operand (op0, 12); | |
2012 | } | |
2013 | else | |
2014 | { | |
2015 | wordpart[0][0] = op0; | |
2016 | wordpart[1][0] = op0; | |
2017 | wordpart[2][0] = op0; | |
2018 | wordpart[3][0] = op0; | |
2019 | } | |
2020 | ||
2021 | if (optype1 == REGOP) | |
2022 | { | |
2023 | wordpart[0][1] = gen_rtx (REG, SImode, REGNO (op1) + 0); | |
2024 | wordpart[1][1] = gen_rtx (REG, SImode, REGNO (op1) + 1); | |
2025 | wordpart[2][1] = gen_rtx (REG, SImode, REGNO (op1) + 2); | |
2026 | wordpart[3][1] = gen_rtx (REG, SImode, REGNO (op1) + 3); | |
2027 | } | |
2028 | else if (optype1 == OFFSOP) | |
2029 | { | |
2030 | wordpart[0][1] = adj_offsettable_operand (op1, 0); | |
2031 | wordpart[1][1] = adj_offsettable_operand (op1, 4); | |
2032 | wordpart[2][1] = adj_offsettable_operand (op1, 8); | |
2033 | wordpart[3][1] = adj_offsettable_operand (op1, 12); | |
2034 | } | |
2035 | else if (optype1 == CNSTOP) | |
2036 | { | |
61a66555 JW |
2037 | REAL_VALUE_TYPE r; |
2038 | long l[4]; | |
2039 | ||
2040 | /* This only works for TFmode floating point constants. */ | |
2041 | if (GET_CODE (op1) != CONST_DOUBLE || GET_MODE (op1) != TFmode) | |
2042 | abort (); | |
2043 | ||
2044 | REAL_VALUE_FROM_CONST_DOUBLE (r, op1); | |
2045 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l); | |
2046 | ||
2047 | wordpart[0][1] = GEN_INT (l[0]); | |
2048 | wordpart[1][1] = GEN_INT (l[1]); | |
2049 | wordpart[2][1] = GEN_INT (l[2]); | |
2050 | wordpart[3][1] = GEN_INT (l[3]); | |
795068a4 JW |
2051 | } |
2052 | else | |
2053 | { | |
2054 | wordpart[0][1] = op1; | |
2055 | wordpart[1][1] = op1; | |
2056 | wordpart[2][1] = op1; | |
2057 | wordpart[3][1] = op1; | |
2058 | } | |
2059 | ||
2060 | /* Easy case: try moving the quad as two pairs. Check for moving between | |
61a55e8b DE |
2061 | an even/odd register pair and a memory location. |
2062 | Also handle new v9 fp regs here. */ | |
795068a4 JW |
2063 | /* ??? Should also handle the case of non-offsettable addresses here. |
2064 | We can at least do the first pair as a ldd/std, and then do the third | |
2065 | and fourth words individually. */ | |
2066 | if ((optype0 == REGOP && optype1 == OFFSOP && (REGNO (op0) & 1) == 0) | |
2067 | || (optype0 == OFFSOP && optype1 == REGOP && (REGNO (op1) & 1) == 0)) | |
2068 | { | |
61a55e8b | 2069 | rtx mem, reg; |
795068a4 JW |
2070 | |
2071 | if (optype0 == REGOP) | |
61a55e8b | 2072 | mem = op1, reg = op0; |
795068a4 | 2073 | else |
61a55e8b | 2074 | mem = op0, reg = op1; |
795068a4 | 2075 | |
61a55e8b DE |
2076 | if (mem_aligned_8 (mem) |
2077 | /* If this is a floating point register higher than %f31, | |
2078 | then we *must* use an aligned load, since `ld' will not accept | |
2079 | the register number. */ | |
2080 | || (TARGET_V9 && REGNO (reg) >= 64)) | |
795068a4 | 2081 | { |
eb582c5d | 2082 | if (TARGET_V9 && FP_REG_P (reg) && TARGET_HARD_QUAD) |
61a55e8b DE |
2083 | { |
2084 | if ((REGNO (reg) & 3) != 0) | |
2085 | abort (); | |
2086 | return (mem == op1 ? "ldq %1,%0" : "stq %1,%0"); | |
2087 | } | |
795068a4 | 2088 | operands[2] = adj_offsettable_operand (mem, 8); |
eb582c5d | 2089 | /* ??? In arch64 case, shouldn't we use ldd/std for fp regs. */ |
795068a4 | 2090 | if (mem == op1) |
a9e27770 | 2091 | return TARGET_ARCH64 ? "ldx %1,%0;ldx %2,%R0" : "ldd %1,%0;ldd %2,%S0"; |
795068a4 | 2092 | else |
a9e27770 | 2093 | return TARGET_ARCH64 ? "stx %1,%0;stx %R1,%2" : "std %1,%0;std %S1,%2"; |
795068a4 JW |
2094 | } |
2095 | } | |
2096 | ||
2097 | /* If the first move would clobber the source of the second one, | |
2098 | do them in the other order. */ | |
2099 | ||
2100 | /* Overlapping registers. */ | |
2101 | if (optype0 == REGOP && optype1 == REGOP | |
2102 | && (REGNO (op0) == REGNO (wordpart[1][3]) | |
2103 | || REGNO (op0) == REGNO (wordpart[1][2]) | |
2104 | || REGNO (op0) == REGNO (wordpart[1][1]))) | |
2105 | { | |
2106 | /* Do fourth word. */ | |
2107 | output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]); | |
2108 | /* Do the third word. */ | |
2109 | output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]); | |
2110 | /* Do the second word. */ | |
2111 | output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]); | |
2112 | /* Do lowest-numbered word. */ | |
2113 | return singlemove_string (wordpart[0]); | |
2114 | } | |
2115 | /* Loading into a register which overlaps a register used in the address. */ | |
2116 | if (optype0 == REGOP && optype1 != REGOP | |
2117 | && reg_overlap_mentioned_p (op0, op1)) | |
2118 | { | |
2119 | /* ??? Not implemented yet. This is a bit complicated, because we | |
2120 | must load which ever part overlaps the address last. If the address | |
2121 | is a double-reg address, then there are two parts which need to | |
2122 | be done last, which is impossible. We would need a scratch register | |
2123 | in that case. */ | |
2124 | abort (); | |
2125 | } | |
2126 | ||
ddd5a7c1 | 2127 | /* Normal case: move the four words in lowest to highest address order. */ |
795068a4 JW |
2128 | |
2129 | output_asm_insn (singlemove_string (wordpart[0]), wordpart[0]); | |
2130 | ||
2131 | /* Make any unoffsettable addresses point at the second word. */ | |
2132 | if (addreg0) | |
2133 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
2134 | if (addreg1) | |
2135 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
2136 | ||
2137 | /* Do the second word. */ | |
2138 | output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]); | |
2139 | ||
2140 | /* Make any unoffsettable addresses point at the third word. */ | |
2141 | if (addreg0) | |
2142 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
2143 | if (addreg1) | |
2144 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
2145 | ||
2146 | /* Do the third word. */ | |
2147 | output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]); | |
2148 | ||
2149 | /* Make any unoffsettable addresses point at the fourth word. */ | |
2150 | if (addreg0) | |
2151 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
2152 | if (addreg1) | |
2153 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
2154 | ||
2155 | /* Do the fourth word. */ | |
2156 | output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]); | |
2157 | ||
2158 | /* Undo the adds we just did. */ | |
2159 | if (addreg0) | |
2160 | output_asm_insn ("add %0,-0xc,%0", &addreg0); | |
2161 | if (addreg1) | |
2162 | output_asm_insn ("add %0,-0xc,%0", &addreg1); | |
2163 | ||
2164 | return ""; | |
2165 | } | |
ab835497 | 2166 | \f |
795068a4 | 2167 | /* Output assembler code to perform a doubleword move insn with operands |
a3ee5899 JW |
2168 | OPERANDS, one of which must be a floating point register. */ |
2169 | ||
ab835497 RK |
2170 | char * |
2171 | output_fp_move_double (operands) | |
2172 | rtx *operands; | |
2173 | { | |
ab835497 RK |
2174 | if (FP_REG_P (operands[0])) |
2175 | { | |
2176 | if (FP_REG_P (operands[1])) | |
61a55e8b DE |
2177 | { |
2178 | if (TARGET_V9) | |
2179 | return "fmovd %1,%0"; | |
2180 | else | |
2181 | return "fmovs %1,%0\n\tfmovs %R1,%R0"; | |
2182 | } | |
a3ee5899 | 2183 | else if (GET_CODE (operands[1]) == REG) |
019c2b24 | 2184 | abort (); |
a3ee5899 JW |
2185 | else |
2186 | return output_move_double (operands); | |
ab835497 RK |
2187 | } |
2188 | else if (FP_REG_P (operands[1])) | |
2189 | { | |
2190 | if (GET_CODE (operands[0]) == REG) | |
019c2b24 | 2191 | abort (); |
a3ee5899 JW |
2192 | else |
2193 | return output_move_double (operands); | |
ab835497 RK |
2194 | } |
2195 | else abort (); | |
2196 | } | |
795068a4 JW |
2197 | |
2198 | /* Output assembler code to perform a quadword move insn with operands | |
2199 | OPERANDS, one of which must be a floating point register. */ | |
2200 | ||
2201 | char * | |
2202 | output_fp_move_quad (operands) | |
2203 | rtx *operands; | |
2204 | { | |
2205 | register rtx op0 = operands[0]; | |
2206 | register rtx op1 = operands[1]; | |
795068a4 JW |
2207 | |
2208 | if (FP_REG_P (op0)) | |
2209 | { | |
2210 | if (FP_REG_P (op1)) | |
61a55e8b DE |
2211 | { |
2212 | if (TARGET_V9) | |
2213 | return "fmovq %1,%0"; | |
2214 | else | |
2215 | return "fmovs %1,%0\n\tfmovs %R1,%R0\n\tfmovs %S1,%S0\n\tfmovs %T1,%T0"; | |
2216 | } | |
019c2b24 JW |
2217 | else if (GET_CODE (op1) == REG) |
2218 | abort (); | |
795068a4 JW |
2219 | else |
2220 | return output_move_quad (operands); | |
2221 | } | |
2222 | else if (FP_REG_P (op1)) | |
2223 | { | |
2224 | if (GET_CODE (op0) == REG) | |
019c2b24 | 2225 | abort (); |
795068a4 JW |
2226 | else |
2227 | return output_move_quad (operands); | |
2228 | } | |
2229 | else | |
2230 | abort (); | |
2231 | } | |
ab835497 RK |
2232 | \f |
2233 | /* Return a REG that occurs in ADDR with coefficient 1. | |
2234 | ADDR can be effectively incremented by incrementing REG. */ | |
2235 | ||
2236 | static rtx | |
2237 | find_addr_reg (addr) | |
2238 | rtx addr; | |
2239 | { | |
2240 | while (GET_CODE (addr) == PLUS) | |
2241 | { | |
2242 | /* We absolutely can not fudge the frame pointer here, because the | |
2243 | frame pointer must always be 8 byte aligned. It also confuses | |
2244 | debuggers. */ | |
2245 | if (GET_CODE (XEXP (addr, 0)) == REG | |
2246 | && REGNO (XEXP (addr, 0)) != FRAME_POINTER_REGNUM) | |
2247 | addr = XEXP (addr, 0); | |
2248 | else if (GET_CODE (XEXP (addr, 1)) == REG | |
2249 | && REGNO (XEXP (addr, 1)) != FRAME_POINTER_REGNUM) | |
2250 | addr = XEXP (addr, 1); | |
2251 | else if (CONSTANT_P (XEXP (addr, 0))) | |
2252 | addr = XEXP (addr, 1); | |
2253 | else if (CONSTANT_P (XEXP (addr, 1))) | |
2254 | addr = XEXP (addr, 0); | |
2255 | else | |
2256 | abort (); | |
2257 | } | |
2258 | if (GET_CODE (addr) == REG) | |
2259 | return addr; | |
2260 | abort (); | |
2261 | } | |
2262 | ||
6a4bb1fa DE |
2263 | #if 0 /* not currently used */ |
2264 | ||
ab835497 RK |
2265 | void |
2266 | output_sized_memop (opname, mode, signedp) | |
2267 | char *opname; | |
2268 | enum machine_mode mode; | |
2269 | int signedp; | |
2270 | { | |
2271 | static char *ld_size_suffix_u[] = { "ub", "uh", "", "?", "d" }; | |
2272 | static char *ld_size_suffix_s[] = { "sb", "sh", "", "?", "d" }; | |
2273 | static char *st_size_suffix[] = { "b", "h", "", "?", "d" }; | |
2274 | char **opnametab, *modename; | |
2275 | ||
2276 | if (opname[0] == 'l') | |
2277 | if (signedp) | |
2278 | opnametab = ld_size_suffix_s; | |
2279 | else | |
2280 | opnametab = ld_size_suffix_u; | |
2281 | else | |
2282 | opnametab = st_size_suffix; | |
2283 | modename = opnametab[GET_MODE_SIZE (mode) >> 1]; | |
2284 | ||
2285 | fprintf (asm_out_file, "\t%s%s", opname, modename); | |
2286 | } | |
2287 | \f | |
2288 | void | |
2289 | output_move_with_extension (operands) | |
2290 | rtx *operands; | |
2291 | { | |
2292 | if (GET_MODE (operands[2]) == HImode) | |
2293 | output_asm_insn ("sll %2,0x10,%0", operands); | |
2294 | else if (GET_MODE (operands[2]) == QImode) | |
2295 | output_asm_insn ("sll %2,0x18,%0", operands); | |
2296 | else | |
2297 | abort (); | |
2298 | } | |
6a4bb1fa | 2299 | #endif /* not currently used */ |
ab835497 | 2300 | \f |
09aa6559 JW |
2301 | #if 0 |
2302 | /* ??? These are only used by the movstrsi pattern, but we get better code | |
2303 | in general without that, because emit_block_move can do just as good a | |
2304 | job as this function does when alignment and size are known. When they | |
2305 | aren't known, a call to strcpy may be faster anyways, because it is | |
2306 | likely to be carefully crafted assembly language code, and below we just | |
2307 | do a byte-wise copy. | |
2308 | ||
2309 | Also, emit_block_move expands into multiple read/write RTL insns, which | |
2310 | can then be optimized, whereas our movstrsi pattern can not be optimized | |
2311 | at all. */ | |
2312 | ||
ab835497 RK |
2313 | /* Load the address specified by OPERANDS[3] into the register |
2314 | specified by OPERANDS[0]. | |
2315 | ||
2316 | OPERANDS[3] may be the result of a sum, hence it could either be: | |
2317 | ||
2318 | (1) CONST | |
2319 | (2) REG | |
2320 | (2) REG + CONST_INT | |
2321 | (3) REG + REG + CONST_INT | |
2322 | (4) REG + REG (special case of 3). | |
2323 | ||
2324 | Note that (3) is not a legitimate address. | |
2325 | All cases are handled here. */ | |
2326 | ||
2327 | void | |
2328 | output_load_address (operands) | |
2329 | rtx *operands; | |
2330 | { | |
2331 | rtx base, offset; | |
2332 | ||
2333 | if (CONSTANT_P (operands[3])) | |
2334 | { | |
2335 | output_asm_insn ("set %3,%0", operands); | |
2336 | return; | |
2337 | } | |
2338 | ||
2339 | if (REG_P (operands[3])) | |
2340 | { | |
2341 | if (REGNO (operands[0]) != REGNO (operands[3])) | |
2342 | output_asm_insn ("mov %3,%0", operands); | |
2343 | return; | |
2344 | } | |
2345 | ||
2346 | if (GET_CODE (operands[3]) != PLUS) | |
2347 | abort (); | |
2348 | ||
2349 | base = XEXP (operands[3], 0); | |
2350 | offset = XEXP (operands[3], 1); | |
2351 | ||
2352 | if (GET_CODE (base) == CONST_INT) | |
2353 | { | |
2354 | rtx tmp = base; | |
2355 | base = offset; | |
2356 | offset = tmp; | |
2357 | } | |
2358 | ||
2359 | if (GET_CODE (offset) != CONST_INT) | |
2360 | { | |
2361 | /* Operand is (PLUS (REG) (REG)). */ | |
2362 | base = operands[3]; | |
2363 | offset = const0_rtx; | |
2364 | } | |
2365 | ||
2366 | if (REG_P (base)) | |
2367 | { | |
2368 | operands[6] = base; | |
2369 | operands[7] = offset; | |
2370 | if (SMALL_INT (offset)) | |
2371 | output_asm_insn ("add %6,%7,%0", operands); | |
2372 | else | |
2373 | output_asm_insn ("set %7,%0\n\tadd %0,%6,%0", operands); | |
2374 | } | |
2375 | else if (GET_CODE (base) == PLUS) | |
2376 | { | |
2377 | operands[6] = XEXP (base, 0); | |
2378 | operands[7] = XEXP (base, 1); | |
2379 | operands[8] = offset; | |
2380 | ||
2381 | if (SMALL_INT (offset)) | |
2382 | output_asm_insn ("add %6,%7,%0\n\tadd %0,%8,%0", operands); | |
2383 | else | |
2384 | output_asm_insn ("set %8,%0\n\tadd %0,%6,%0\n\tadd %0,%7,%0", operands); | |
2385 | } | |
2386 | else | |
2387 | abort (); | |
2388 | } | |
2389 | ||
2390 | /* Output code to place a size count SIZE in register REG. | |
2391 | ALIGN is the size of the unit of transfer. | |
2392 | ||
2393 | Because block moves are pipelined, we don't include the | |
2394 | first element in the transfer of SIZE to REG. */ | |
2395 | ||
2396 | static void | |
2397 | output_size_for_block_move (size, reg, align) | |
2398 | rtx size, reg; | |
2399 | rtx align; | |
2400 | { | |
2401 | rtx xoperands[3]; | |
2402 | ||
2403 | xoperands[0] = reg; | |
2404 | xoperands[1] = size; | |
2405 | xoperands[2] = align; | |
2406 | if (GET_CODE (size) == REG) | |
2407 | output_asm_insn ("sub %1,%2,%0", xoperands); | |
2408 | else | |
2409 | { | |
2410 | xoperands[1] | |
2411 | = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align)); | |
2412 | output_asm_insn ("set %1,%0", xoperands); | |
2413 | } | |
2414 | } | |
2415 | ||
2416 | /* Emit code to perform a block move. | |
2417 | ||
2418 | OPERANDS[0] is the destination. | |
2419 | OPERANDS[1] is the source. | |
2420 | OPERANDS[2] is the size. | |
2421 | OPERANDS[3] is the alignment safe to use. | |
2422 | OPERANDS[4] is a register we can safely clobber as a temp. */ | |
2423 | ||
2424 | char * | |
2425 | output_block_move (operands) | |
2426 | rtx *operands; | |
2427 | { | |
2428 | /* A vector for our computed operands. Note that load_output_address | |
2429 | makes use of (and can clobber) up to the 8th element of this vector. */ | |
2430 | rtx xoperands[10]; | |
2431 | rtx zoperands[10]; | |
2432 | static int movstrsi_label = 0; | |
2433 | int i; | |
2434 | rtx temp1 = operands[4]; | |
2435 | rtx sizertx = operands[2]; | |
2436 | rtx alignrtx = operands[3]; | |
2437 | int align = INTVAL (alignrtx); | |
210aa14a | 2438 | char label3[30], label5[30]; |
ab835497 RK |
2439 | |
2440 | xoperands[0] = operands[0]; | |
2441 | xoperands[1] = operands[1]; | |
2442 | xoperands[2] = temp1; | |
2443 | ||
391b99c9 RS |
2444 | /* We can't move more than this many bytes at a time because we have only |
2445 | one register, %g1, to move them through. */ | |
2446 | if (align > UNITS_PER_WORD) | |
ab835497 | 2447 | { |
391b99c9 RS |
2448 | align = UNITS_PER_WORD; |
2449 | alignrtx = gen_rtx (CONST_INT, VOIDmode, UNITS_PER_WORD); | |
ab835497 RK |
2450 | } |
2451 | ||
391b99c9 RS |
2452 | /* We consider 8 ld/st pairs, for a total of 16 inline insns to be |
2453 | reasonable here. (Actually will emit a maximum of 18 inline insns for | |
2454 | the case of size == 31 and align == 4). */ | |
2455 | ||
2456 | if (GET_CODE (sizertx) == CONST_INT && (INTVAL (sizertx) / align) <= 8 | |
2457 | && memory_address_p (QImode, plus_constant_for_output (xoperands[0], | |
2458 | INTVAL (sizertx))) | |
2459 | && memory_address_p (QImode, plus_constant_for_output (xoperands[1], | |
2460 | INTVAL (sizertx)))) | |
ab835497 RK |
2461 | { |
2462 | int size = INTVAL (sizertx); | |
391b99c9 | 2463 | int offset = 0; |
ab835497 | 2464 | |
391b99c9 RS |
2465 | /* We will store different integers into this particular RTX. */ |
2466 | xoperands[2] = rtx_alloc (CONST_INT); | |
2467 | PUT_MODE (xoperands[2], VOIDmode); | |
ab835497 | 2468 | |
391b99c9 RS |
2469 | /* This case is currently not handled. Abort instead of generating |
2470 | bad code. */ | |
61a55e8b | 2471 | if (align > UNITS_PER_WORD) |
391b99c9 | 2472 | abort (); |
ab835497 | 2473 | |
a9e27770 | 2474 | if (TARGET_ARCH64 && align >= 8) |
61a55e8b DE |
2475 | { |
2476 | for (i = (size >> 3) - 1; i >= 0; i--) | |
2477 | { | |
2478 | INTVAL (xoperands[2]) = (i << 3) + offset; | |
2479 | output_asm_insn ("ldx [%a1+%2],%%g1\n\tstx %%g1,[%a0+%2]", | |
2480 | xoperands); | |
2481 | } | |
2482 | offset += (size & ~0x7); | |
2483 | size = size & 0x7; | |
2484 | if (size == 0) | |
2485 | return ""; | |
2486 | } | |
2487 | ||
391b99c9 | 2488 | if (align >= 4) |
ab835497 | 2489 | { |
391b99c9 | 2490 | for (i = (size >> 2) - 1; i >= 0; i--) |
ab835497 | 2491 | { |
391b99c9 RS |
2492 | INTVAL (xoperands[2]) = (i << 2) + offset; |
2493 | output_asm_insn ("ld [%a1+%2],%%g1\n\tst %%g1,[%a0+%2]", | |
2494 | xoperands); | |
ab835497 | 2495 | } |
391b99c9 RS |
2496 | offset += (size & ~0x3); |
2497 | size = size & 0x3; | |
2498 | if (size == 0) | |
2499 | return ""; | |
ab835497 | 2500 | } |
391b99c9 RS |
2501 | |
2502 | if (align >= 2) | |
ab835497 | 2503 | { |
391b99c9 | 2504 | for (i = (size >> 1) - 1; i >= 0; i--) |
ab835497 | 2505 | { |
391b99c9 RS |
2506 | INTVAL (xoperands[2]) = (i << 1) + offset; |
2507 | output_asm_insn ("lduh [%a1+%2],%%g1\n\tsth %%g1,[%a0+%2]", | |
2508 | xoperands); | |
ab835497 | 2509 | } |
391b99c9 RS |
2510 | offset += (size & ~0x1); |
2511 | size = size & 0x1; | |
2512 | if (size == 0) | |
2513 | return ""; | |
ab835497 | 2514 | } |
391b99c9 RS |
2515 | |
2516 | if (align >= 1) | |
ab835497 | 2517 | { |
391b99c9 | 2518 | for (i = size - 1; i >= 0; i--) |
ab835497 | 2519 | { |
391b99c9 RS |
2520 | INTVAL (xoperands[2]) = i + offset; |
2521 | output_asm_insn ("ldub [%a1+%2],%%g1\n\tstb %%g1,[%a0+%2]", | |
2522 | xoperands); | |
ab835497 | 2523 | } |
391b99c9 | 2524 | return ""; |
ab835497 | 2525 | } |
391b99c9 RS |
2526 | |
2527 | /* We should never reach here. */ | |
2528 | abort (); | |
ab835497 RK |
2529 | } |
2530 | ||
391b99c9 RS |
2531 | /* If the size isn't known to be a multiple of the alignment, |
2532 | we have to do it in smaller pieces. If we could determine that | |
2533 | the size was a multiple of 2 (or whatever), we could be smarter | |
2534 | about this. */ | |
2535 | if (GET_CODE (sizertx) != CONST_INT) | |
2536 | align = 1; | |
2537 | else | |
2538 | { | |
2539 | int size = INTVAL (sizertx); | |
2540 | while (size % align) | |
2541 | align >>= 1; | |
2542 | } | |
2543 | ||
2544 | if (align != INTVAL (alignrtx)) | |
2545 | alignrtx = gen_rtx (CONST_INT, VOIDmode, align); | |
2546 | ||
ab835497 RK |
2547 | xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++); |
2548 | xoperands[4] = gen_rtx (CONST_INT, VOIDmode, align); | |
2549 | xoperands[5] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++); | |
2550 | ||
210aa14a RS |
2551 | ASM_GENERATE_INTERNAL_LABEL (label3, "Lm", INTVAL (xoperands[3])); |
2552 | ASM_GENERATE_INTERNAL_LABEL (label5, "Lm", INTVAL (xoperands[5])); | |
2553 | ||
391b99c9 RS |
2554 | /* This is the size of the transfer. Emit code to decrement the size |
2555 | value by ALIGN, and store the result in the temp1 register. */ | |
ab835497 RK |
2556 | output_size_for_block_move (sizertx, temp1, alignrtx); |
2557 | ||
2558 | /* Must handle the case when the size is zero or negative, so the first thing | |
2559 | we do is compare the size against zero, and only copy bytes if it is | |
2560 | zero or greater. Note that we have already subtracted off the alignment | |
2561 | once, so we must copy 1 alignment worth of bytes if the size is zero | |
2562 | here. | |
2563 | ||
2564 | The SUN assembler complains about labels in branch delay slots, so we | |
b4ac57ab | 2565 | do this before outputting the load address, so that there will always |
ab835497 RK |
2566 | be a harmless insn between the branch here and the next label emitted |
2567 | below. */ | |
2568 | ||
210aa14a RS |
2569 | { |
2570 | char pattern[100]; | |
2571 | ||
2572 | sprintf (pattern, "cmp %%2,0\n\tbl %s", &label5[1]); | |
2573 | output_asm_insn (pattern, xoperands); | |
2574 | } | |
ab835497 RK |
2575 | |
2576 | zoperands[0] = operands[0]; | |
2577 | zoperands[3] = plus_constant_for_output (operands[0], align); | |
2578 | output_load_address (zoperands); | |
2579 | ||
2580 | /* ??? This might be much faster if the loops below were preconditioned | |
2581 | and unrolled. | |
2582 | ||
2583 | That is, at run time, copy enough bytes one at a time to ensure that the | |
2584 | target and source addresses are aligned to the the largest possible | |
2585 | alignment. Then use a preconditioned unrolled loop to copy say 16 | |
2586 | bytes at a time. Then copy bytes one at a time until finish the rest. */ | |
2587 | ||
2588 | /* Output the first label separately, so that it is spaced properly. */ | |
2589 | ||
ab835497 | 2590 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "Lm", INTVAL (xoperands[3])); |
ab835497 | 2591 | |
210aa14a RS |
2592 | { |
2593 | char pattern[200]; | |
61a55e8b | 2594 | register char *ld_suffix = ((align == 1) ? "ub" : (align == 2) ? "uh" |
a9e27770 | 2595 | : (align == 8 && TARGET_ARCH64) ? "x" : ""); |
61a55e8b | 2596 | register char *st_suffix = ((align == 1) ? "b" : (align == 2) ? "h" |
a9e27770 | 2597 | : (align == 8 && TARGET_ARCH64) ? "x" : ""); |
210aa14a RS |
2598 | |
2599 | sprintf (pattern, "ld%s [%%1+%%2],%%%%g1\n\tsubcc %%2,%%4,%%2\n\tbge %s\n\tst%s %%%%g1,[%%0+%%2]\n%s:", ld_suffix, &label3[1], st_suffix, &label5[1]); | |
2600 | output_asm_insn (pattern, xoperands); | |
2601 | } | |
2602 | ||
ab835497 | 2603 | return ""; |
ab835497 | 2604 | } |
09aa6559 | 2605 | #endif |
ab835497 RK |
2606 | \f |
2607 | /* Output reasonable peephole for set-on-condition-code insns. | |
2608 | Note that these insns assume a particular way of defining | |
2609 | labels. Therefore, *both* sparc.h and this function must | |
2610 | be changed if a new syntax is needed. */ | |
2611 | ||
2612 | char * | |
2613 | output_scc_insn (operands, insn) | |
2614 | rtx operands[]; | |
2615 | rtx insn; | |
2616 | { | |
2617 | static char string[100]; | |
2618 | rtx label = 0, next = insn; | |
2619 | int need_label = 0; | |
2620 | ||
2621 | /* Try doing a jump optimization which jump.c can't do for us | |
2622 | because we did not expose that setcc works by using branches. | |
2623 | ||
2624 | If this scc insn is followed by an unconditional branch, then have | |
2625 | the jump insn emitted here jump to that location, instead of to | |
2626 | the end of the scc sequence as usual. */ | |
2627 | ||
2628 | do | |
2629 | { | |
2630 | if (GET_CODE (next) == CODE_LABEL) | |
2631 | label = next; | |
2632 | next = NEXT_INSN (next); | |
2633 | if (next == 0) | |
2634 | break; | |
2635 | } | |
2636 | while (GET_CODE (next) == NOTE || GET_CODE (next) == CODE_LABEL); | |
2637 | ||
2638 | /* If we are in a sequence, and the following insn is a sequence also, | |
2639 | then just following the current insn's next field will take us to the | |
2640 | first insn of the next sequence, which is the wrong place. We don't | |
2641 | want to optimize with a branch that has had its delay slot filled. | |
2642 | Avoid this by verifying that NEXT_INSN (PREV_INSN (next)) == next | |
2643 | which fails only if NEXT is such a branch. */ | |
2644 | ||
2645 | if (next && GET_CODE (next) == JUMP_INSN && simplejump_p (next) | |
2646 | && (! final_sequence || NEXT_INSN (PREV_INSN (next)) == next)) | |
2647 | label = JUMP_LABEL (next); | |
2648 | /* If not optimizing, jump label fields are not set. To be safe, always | |
2649 | check here to whether label is still zero. */ | |
2650 | if (label == 0) | |
2651 | { | |
2652 | label = gen_label_rtx (); | |
2653 | need_label = 1; | |
2654 | } | |
2655 | ||
2656 | LABEL_NUSES (label) += 1; | |
2657 | ||
c4ce6853 DE |
2658 | /* operands[3] is an unused slot. */ |
2659 | operands[3] = label; | |
ab835497 RK |
2660 | |
2661 | /* If we are in a delay slot, assume it is the delay slot of an fpcc | |
2662 | insn since our type isn't allowed anywhere else. */ | |
2663 | ||
2664 | /* ??? Fpcc instructions no longer have delay slots, so this code is | |
2665 | probably obsolete. */ | |
2666 | ||
2667 | /* The fastest way to emit code for this is an annulled branch followed | |
2668 | by two move insns. This will take two cycles if the branch is taken, | |
2669 | and three cycles if the branch is not taken. | |
2670 | ||
2671 | However, if we are in the delay slot of another branch, this won't work, | |
2672 | because we can't put a branch in the delay slot of another branch. | |
2673 | The above sequence would effectively take 3 or 4 cycles respectively | |
2674 | since a no op would have be inserted between the two branches. | |
2675 | In this case, we want to emit a move, annulled branch, and then the | |
2676 | second move. This sequence always takes 3 cycles, and hence is faster | |
2677 | when we are in a branch delay slot. */ | |
2678 | ||
2679 | if (final_sequence) | |
2680 | { | |
2681 | strcpy (string, "mov 0,%0\n\t"); | |
c4ce6853 | 2682 | strcat (string, output_cbranch (operands[2], 3, 0, 1, 0)); |
ab835497 RK |
2683 | strcat (string, "\n\tmov 1,%0"); |
2684 | } | |
2685 | else | |
2686 | { | |
c4ce6853 | 2687 | strcpy (string, output_cbranch (operands[2], 3, 0, 1, 0)); |
ab835497 RK |
2688 | strcat (string, "\n\tmov 1,%0\n\tmov 0,%0"); |
2689 | } | |
2690 | ||
2691 | if (need_label) | |
c4ce6853 | 2692 | strcat (string, "\n%l3:"); |
ab835497 RK |
2693 | |
2694 | return string; | |
2695 | } | |
2696 | \f | |
61a55e8b DE |
2697 | /* Vectors to keep interesting information about registers where it can easily |
2698 | be got. We use to use the actual mode value as the bit number, but there | |
2699 | are more than 32 modes now. Instead we use two tables: one indexed by | |
2700 | hard register number, and one indexed by mode. */ | |
2701 | ||
2702 | /* The purpose of sparc_mode_class is to shrink the range of modes so that | |
2703 | they all fit (as bit numbers) in a 32 bit word (again). Each real mode is | |
2704 | mapped into one sparc_mode_class mode. */ | |
2705 | ||
2706 | enum sparc_mode_class { | |
61a55e8b | 2707 | S_MODE, D_MODE, T_MODE, O_MODE, |
c4ce6853 DE |
2708 | SF_MODE, DF_MODE, TF_MODE, OF_MODE, |
2709 | CC_MODE, CCFP_MODE | |
61a55e8b | 2710 | }; |
ab835497 | 2711 | |
61a55e8b DE |
2712 | /* Modes for single-word and smaller quantities. */ |
2713 | #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE)) | |
2714 | ||
2715 | /* Modes for double-word and smaller quantities. */ | |
2716 | #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE)) | |
2717 | ||
2718 | /* Modes for quad-word and smaller quantities. */ | |
2719 | #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE)) | |
ab835497 | 2720 | |
1e4eb8d1 JW |
2721 | /* Modes for single-float quantities. We must allow any single word or |
2722 | smaller quantity. This is because the fix/float conversion instructions | |
2723 | take integer inputs/outputs from the float registers. */ | |
2724 | #define SF_MODES (S_MODES) | |
ab835497 | 2725 | |
61a55e8b DE |
2726 | /* Modes for double-float and smaller quantities. */ |
2727 | #define DF_MODES (S_MODES | D_MODES) | |
2728 | ||
2729 | /* ??? Sparc64 fp regs cannot hold DImode values. */ | |
2730 | #define DF_MODES64 (SF_MODES | DF_MODE /* | D_MODE*/) | |
2731 | ||
2732 | /* Modes for double-float only quantities. */ | |
c4ce6853 DE |
2733 | /* ??? Sparc64 fp regs cannot hold DImode values. |
2734 | See fix_truncsfdi2. */ | |
61a55e8b DE |
2735 | #define DF_ONLY_MODES ((1 << (int) DF_MODE) /*| (1 << (int) D_MODE)*/) |
2736 | ||
2737 | /* Modes for double-float and larger quantities. */ | |
2738 | #define DF_UP_MODES (DF_ONLY_MODES | TF_ONLY_MODES) | |
ab835497 | 2739 | |
61a55e8b DE |
2740 | /* Modes for quad-float only quantities. */ |
2741 | #define TF_ONLY_MODES (1 << (int) TF_MODE) | |
2742 | ||
2743 | /* Modes for quad-float and smaller quantities. */ | |
2744 | #define TF_MODES (DF_MODES | TF_ONLY_MODES) | |
2745 | ||
c4ce6853 DE |
2746 | /* ??? Sparc64 fp regs cannot hold DImode values. |
2747 | See fix_truncsfdi2. */ | |
61a55e8b | 2748 | #define TF_MODES64 (DF_MODES64 | TF_ONLY_MODES) |
ab835497 | 2749 | |
c4ce6853 DE |
2750 | /* Modes for condition codes. */ |
2751 | #define CC_MODES (1 << (int) CC_MODE) | |
2752 | #define CCFP_MODES (1 << (int) CCFP_MODE) | |
2753 | ||
ab835497 RK |
2754 | /* Value is 1 if register/mode pair is acceptable on sparc. |
2755 | The funny mixture of D and T modes is because integer operations | |
2756 | do not specially operate on tetra quantities, so non-quad-aligned | |
2757 | registers can hold quadword quantities (except %o4 and %i4 because | |
c4ce6853 | 2758 | they cross fixed registers). */ |
ab835497 | 2759 | |
61a55e8b DE |
2760 | /* This points to either the 32 bit or the 64 bit version. */ |
2761 | int *hard_regno_mode_classes; | |
2762 | ||
2763 | static int hard_32bit_mode_classes[] = { | |
c4ce6853 | 2764 | S_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, |
ab835497 RK |
2765 | T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES, |
2766 | T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, | |
2767 | T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES, | |
2768 | ||
2769 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
2770 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
2771 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
61a55e8b | 2772 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, |
a9e27770 DE |
2773 | |
2774 | /* FP regs f32 to f63. Only the even numbered registers actually exist, | |
2775 | and none can hold SFmode/SImode values. */ | |
2776 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2777 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2778 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2779 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2780 | ||
2781 | /* %fcc[0123] */ | |
c4ce6853 DE |
2782 | CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES, |
2783 | ||
2784 | /* %icc */ | |
2785 | CC_MODES | |
61a55e8b DE |
2786 | }; |
2787 | ||
2788 | static int hard_64bit_mode_classes[] = { | |
c4ce6853 | 2789 | D_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, |
61a55e8b DE |
2790 | T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, |
2791 | T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, | |
2792 | T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, | |
2793 | ||
2794 | TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, | |
2795 | TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, | |
2796 | TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, | |
2797 | TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, | |
2798 | ||
a9e27770 | 2799 | /* FP regs f32 to f63. Only the even numbered registers actually exist, |
61a55e8b DE |
2800 | and none can hold SFmode/SImode values. */ |
2801 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2802 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2803 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2804 | DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0, | |
2805 | ||
2806 | /* %fcc[0123] */ | |
c4ce6853 DE |
2807 | CCFP_MODES, CCFP_MODES, CCFP_MODES, CCFP_MODES, |
2808 | ||
2809 | /* %icc */ | |
2810 | CC_MODES | |
61a55e8b DE |
2811 | }; |
2812 | ||
2813 | int sparc_mode_class [NUM_MACHINE_MODES]; | |
2814 | ||
c4ce6853 DE |
2815 | enum reg_class sparc_regno_reg_class[FIRST_PSEUDO_REGISTER]; |
2816 | ||
61a55e8b DE |
2817 | static void |
2818 | sparc_init_modes () | |
2819 | { | |
2820 | int i; | |
2821 | ||
61a55e8b DE |
2822 | for (i = 0; i < NUM_MACHINE_MODES; i++) |
2823 | { | |
2824 | switch (GET_MODE_CLASS (i)) | |
2825 | { | |
2826 | case MODE_INT: | |
2827 | case MODE_PARTIAL_INT: | |
2828 | case MODE_COMPLEX_INT: | |
2829 | if (GET_MODE_SIZE (i) <= 4) | |
2830 | sparc_mode_class[i] = 1 << (int) S_MODE; | |
2831 | else if (GET_MODE_SIZE (i) == 8) | |
2832 | sparc_mode_class[i] = 1 << (int) D_MODE; | |
2833 | else if (GET_MODE_SIZE (i) == 16) | |
2834 | sparc_mode_class[i] = 1 << (int) T_MODE; | |
2835 | else if (GET_MODE_SIZE (i) == 32) | |
2836 | sparc_mode_class[i] = 1 << (int) O_MODE; | |
2837 | else | |
2838 | sparc_mode_class[i] = 0; | |
2839 | break; | |
2840 | case MODE_FLOAT: | |
2841 | case MODE_COMPLEX_FLOAT: | |
2842 | if (GET_MODE_SIZE (i) <= 4) | |
2843 | sparc_mode_class[i] = 1 << (int) SF_MODE; | |
2844 | else if (GET_MODE_SIZE (i) == 8) | |
2845 | sparc_mode_class[i] = 1 << (int) DF_MODE; | |
2846 | else if (GET_MODE_SIZE (i) == 16) | |
2847 | sparc_mode_class[i] = 1 << (int) TF_MODE; | |
2848 | else if (GET_MODE_SIZE (i) == 32) | |
2849 | sparc_mode_class[i] = 1 << (int) OF_MODE; | |
2850 | else | |
2851 | sparc_mode_class[i] = 0; | |
2852 | break; | |
2853 | case MODE_CC: | |
2854 | default: | |
2855 | /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so | |
2856 | we must explicitly check for them here. */ | |
2857 | if (i == (int) CCFPmode || i == (int) CCFPEmode) | |
2858 | sparc_mode_class[i] = 1 << (int) CCFP_MODE; | |
2859 | else if (i == (int) CCmode || i == (int) CC_NOOVmode | |
a9e27770 | 2860 | || i == (int) CCXmode || i == (int) CCX_NOOVmode) |
c4ce6853 | 2861 | sparc_mode_class[i] = 1 << (int) CC_MODE; |
61a55e8b DE |
2862 | else |
2863 | sparc_mode_class[i] = 0; | |
2864 | break; | |
2865 | } | |
2866 | } | |
2867 | ||
a9e27770 | 2868 | if (TARGET_ARCH64) |
61a55e8b DE |
2869 | hard_regno_mode_classes = hard_64bit_mode_classes; |
2870 | else | |
2871 | hard_regno_mode_classes = hard_32bit_mode_classes; | |
c4ce6853 DE |
2872 | |
2873 | /* Initialize the array used by REGNO_REG_CLASS. */ | |
2874 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
2875 | { | |
2876 | if (i < 32) | |
2877 | sparc_regno_reg_class[i] = GENERAL_REGS; | |
2878 | else if (i < 64) | |
2879 | sparc_regno_reg_class[i] = FP_REGS; | |
2880 | else if (i < 96) | |
2881 | sparc_regno_reg_class[i] = EXTRA_FP_REGS; | |
2882 | else if (i < 100) | |
2883 | sparc_regno_reg_class[i] = FPCC_REGS; | |
2884 | else | |
2885 | sparc_regno_reg_class[i] = NO_REGS; | |
2886 | } | |
61a55e8b | 2887 | } |
ab835497 | 2888 | \f |
61a55e8b DE |
2889 | /* Save non call used registers from LOW to HIGH at BASE+OFFSET. |
2890 | N_REGS is the number of 4-byte regs saved thus far. This applies even to | |
2891 | v9 int regs as it simplifies the code. */ | |
2892 | ||
ab835497 | 2893 | #ifdef __GNUC__ |
99c7b2f6 | 2894 | __inline__ |
ab835497 RK |
2895 | #endif |
2896 | static int | |
c53aa195 | 2897 | save_regs (file, low, high, base, offset, n_regs, real_offset) |
ab835497 RK |
2898 | FILE *file; |
2899 | int low, high; | |
2900 | char *base; | |
2901 | int offset; | |
61a55e8b | 2902 | int n_regs; |
c53aa195 | 2903 | int real_offset; |
ab835497 RK |
2904 | { |
2905 | int i; | |
2906 | ||
a9e27770 | 2907 | if (TARGET_ARCH64 && high <= 32) |
ab835497 | 2908 | { |
61a55e8b DE |
2909 | for (i = low; i < high; i++) |
2910 | { | |
2911 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
c53aa195 JM |
2912 | { |
2913 | fprintf (file, "\tstx %s,[%s+%d]\n", | |
2914 | reg_names[i], base, offset + 4 * n_regs); | |
2915 | #ifdef DWARF2_DEBUGGING_INFO | |
2916 | if (write_symbols == DWARF2_DEBUG) | |
2917 | dwarf2out_reg_save ("", i, real_offset + 4 * n_regs); | |
2918 | #endif | |
2919 | n_regs += 2; | |
2920 | } | |
61a55e8b | 2921 | } |
ab835497 | 2922 | } |
61a55e8b DE |
2923 | else |
2924 | { | |
2925 | for (i = low; i < high; i += 2) | |
2926 | { | |
2927 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
2928 | if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
c53aa195 JM |
2929 | { |
2930 | fprintf (file, "\tstd %s,[%s+%d]\n", | |
2931 | reg_names[i], base, offset + 4 * n_regs); | |
2932 | #ifdef DWARF2_DEBUGGING_INFO | |
2933 | if (write_symbols == DWARF2_DEBUG) | |
2934 | { | |
2935 | char *l = (char *) dwarf2out_cfi_label (); | |
2936 | dwarf2out_reg_save (l, i, real_offset + 4 * n_regs); | |
2937 | dwarf2out_reg_save (l, i+1, real_offset + 4 * n_regs + 4); | |
2938 | } | |
2939 | #endif | |
2940 | n_regs += 2; | |
2941 | } | |
61a55e8b | 2942 | else |
c53aa195 JM |
2943 | { |
2944 | fprintf (file, "\tst %s,[%s+%d]\n", | |
2945 | reg_names[i], base, offset + 4 * n_regs); | |
2946 | #ifdef DWARF2_DEBUGGING_INFO | |
2947 | if (write_symbols == DWARF2_DEBUG) | |
2948 | dwarf2out_reg_save ("", i, real_offset + 4 * n_regs); | |
2949 | #endif | |
2950 | n_regs += 2; | |
2951 | } | |
2952 | else if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
2953 | { | |
61a55e8b | 2954 | fprintf (file, "\tst %s,[%s+%d]\n", |
c53aa195 JM |
2955 | reg_names[i+1], base, offset + 4 * n_regs + 4); |
2956 | #ifdef DWARF2_DEBUGGING_INFO | |
2957 | if (write_symbols == DWARF2_DEBUG) | |
2958 | dwarf2out_reg_save ("", i + 1, real_offset + 4 * n_regs + 4); | |
2959 | #endif | |
61a55e8b | 2960 | n_regs += 2; |
c53aa195 | 2961 | } |
61a55e8b DE |
2962 | } |
2963 | } | |
2964 | return n_regs; | |
ab835497 RK |
2965 | } |
2966 | ||
61a55e8b DE |
2967 | /* Restore non call used registers from LOW to HIGH at BASE+OFFSET. |
2968 | ||
2969 | N_REGS is the number of 4-byte regs saved thus far. This applies even to | |
2970 | v9 int regs as it simplifies the code. */ | |
2971 | ||
ab835497 | 2972 | #ifdef __GNUC__ |
99c7b2f6 | 2973 | __inline__ |
ab835497 RK |
2974 | #endif |
2975 | static int | |
61a55e8b | 2976 | restore_regs (file, low, high, base, offset, n_regs) |
ab835497 RK |
2977 | FILE *file; |
2978 | int low, high; | |
2979 | char *base; | |
2980 | int offset; | |
61a55e8b | 2981 | int n_regs; |
ab835497 RK |
2982 | { |
2983 | int i; | |
2984 | ||
a9e27770 | 2985 | if (TARGET_ARCH64 && high <= 32) |
61a55e8b DE |
2986 | { |
2987 | for (i = low; i < high; i++) | |
2988 | { | |
2989 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
2990 | fprintf (file, "\tldx [%s+%d], %s\n", | |
2991 | base, offset + 4 * n_regs, reg_names[i]), | |
2992 | n_regs += 2; | |
2993 | } | |
2994 | } | |
2995 | else | |
ab835497 | 2996 | { |
61a55e8b DE |
2997 | for (i = low; i < high; i += 2) |
2998 | { | |
2999 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
3000 | if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
3001 | fprintf (file, "\tldd [%s+%d], %s\n", | |
3002 | base, offset + 4 * n_regs, reg_names[i]), | |
3003 | n_regs += 2; | |
3004 | else | |
3005 | fprintf (file, "\tld [%s+%d],%s\n", | |
3006 | base, offset + 4 * n_regs, reg_names[i]), | |
3007 | n_regs += 2; | |
3008 | else if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
3009 | fprintf (file, "\tld [%s+%d],%s\n", | |
3010 | base, offset + 4 * n_regs + 4, reg_names[i+1]), | |
3011 | n_regs += 2; | |
3012 | } | |
ab835497 | 3013 | } |
61a55e8b | 3014 | return n_regs; |
ab835497 RK |
3015 | } |
3016 | ||
3017 | /* Static variables we want to share between prologue and epilogue. */ | |
3018 | ||
61a55e8b DE |
3019 | /* Number of live general or floating point registers needed to be saved |
3020 | (as 4-byte quantities). This is only done if TARGET_EPILOGUE. */ | |
3021 | static int num_gfregs; | |
3022 | ||
3023 | /* Compute the frame size required by the function. This function is called | |
3024 | during the reload pass and also by output_function_prologue(). */ | |
ab835497 | 3025 | |
ab835497 RK |
3026 | int |
3027 | compute_frame_size (size, leaf_function) | |
3028 | int size; | |
3029 | int leaf_function; | |
3030 | { | |
61a55e8b | 3031 | int n_regs = 0, i; |
ab835497 | 3032 | int outgoing_args_size = (current_function_outgoing_args_size |
a9e27770 | 3033 | #if ! SPARC_ARCH64 |
61a55e8b DE |
3034 | + REG_PARM_STACK_SPACE (current_function_decl) |
3035 | #endif | |
3036 | ); | |
ab835497 | 3037 | |
61a55e8b | 3038 | if (TARGET_EPILOGUE) |
ab835497 | 3039 | { |
61a55e8b DE |
3040 | /* N_REGS is the number of 4-byte regs saved thus far. This applies |
3041 | even to v9 int regs to be consistent with save_regs/restore_regs. */ | |
3042 | ||
a9e27770 | 3043 | if (TARGET_ARCH64) |
61a55e8b DE |
3044 | { |
3045 | for (i = 0; i < 8; i++) | |
3046 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
3047 | n_regs += 2; | |
3048 | } | |
3049 | else | |
3050 | { | |
3051 | for (i = 0; i < 8; i += 2) | |
3052 | if ((regs_ever_live[i] && ! call_used_regs[i]) | |
3053 | || (regs_ever_live[i+1] && ! call_used_regs[i+1])) | |
3054 | n_regs += 2; | |
3055 | } | |
3056 | ||
3057 | for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2) | |
ab835497 RK |
3058 | if ((regs_ever_live[i] && ! call_used_regs[i]) |
3059 | || (regs_ever_live[i+1] && ! call_used_regs[i+1])) | |
61a55e8b | 3060 | n_regs += 2; |
ab835497 RK |
3061 | } |
3062 | ||
3063 | /* Set up values for use in `function_epilogue'. */ | |
61a55e8b | 3064 | num_gfregs = n_regs; |
ab835497 | 3065 | |
61a55e8b DE |
3066 | if (leaf_function && n_regs == 0 |
3067 | && size == 0 && current_function_outgoing_args_size == 0) | |
3068 | { | |
3069 | actual_fsize = apparent_fsize = 0; | |
3070 | } | |
3071 | else | |
3072 | { | |
3073 | /* We subtract STARTING_FRAME_OFFSET, remember it's negative. | |
3074 | The stack bias (if any) is taken out to undo its effects. */ | |
3075 | apparent_fsize = (size - STARTING_FRAME_OFFSET + SPARC_STACK_BIAS + 7) & -8; | |
3076 | apparent_fsize += n_regs * 4; | |
3077 | actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8); | |
3078 | } | |
ab835497 RK |
3079 | |
3080 | /* Make sure nothing can clobber our register windows. | |
3081 | If a SAVE must be done, or there is a stack-local variable, | |
61a55e8b DE |
3082 | the register window area must be allocated. |
3083 | ??? For v9 we need an additional 8 bytes of reserved space, apparently | |
3084 | it's needed by v8 as well. */ | |
ab835497 | 3085 | if (leaf_function == 0 || size > 0) |
61a55e8b | 3086 | actual_fsize += (16 * UNITS_PER_WORD) + 8; |
ab835497 | 3087 | |
61a55e8b DE |
3088 | return SPARC_STACK_ALIGN (actual_fsize); |
3089 | } | |
3090 | ||
3091 | /* Build a (32 bit) big number in a register. */ | |
86735b02 | 3092 | /* ??? We may be able to use the set macro here too. */ |
61a55e8b DE |
3093 | |
3094 | static void | |
3095 | build_big_number (file, num, reg) | |
3096 | FILE *file; | |
3097 | int num; | |
3098 | char *reg; | |
3099 | { | |
a9e27770 | 3100 | if (num >= 0 || ! TARGET_ARCH64) |
61a55e8b DE |
3101 | { |
3102 | fprintf (file, "\tsethi %%hi(%d),%s\n", num, reg); | |
3103 | if ((num & 0x3ff) != 0) | |
3104 | fprintf (file, "\tor %s,%%lo(%d),%s\n", reg, num, reg); | |
3105 | } | |
a9e27770 | 3106 | else /* num < 0 && TARGET_ARCH64 */ |
61a55e8b DE |
3107 | { |
3108 | /* Sethi does not sign extend, so we must use a little trickery | |
3109 | to use it for negative numbers. Invert the constant before | |
3110 | loading it in, then use xor immediate to invert the loaded bits | |
3111 | (along with the upper 32 bits) to the desired constant. This | |
3112 | works because the sethi and immediate fields overlap. */ | |
3113 | int asize = num; | |
3114 | int inv = ~asize; | |
3115 | int low = -0x400 + (asize & 0x3FF); | |
3116 | ||
3117 | fprintf (file, "\tsethi %%hi(%d),%s\n\txor %s,%d,%s\n", | |
3118 | inv, reg, reg, low, reg); | |
3119 | } | |
ab835497 RK |
3120 | } |
3121 | ||
915f619f JW |
3122 | /* Output code for the function prologue. */ |
3123 | ||
ab835497 RK |
3124 | void |
3125 | output_function_prologue (file, size, leaf_function) | |
3126 | FILE *file; | |
3127 | int size; | |
915f619f | 3128 | int leaf_function; |
ab835497 | 3129 | { |
915f619f JW |
3130 | /* Need to use actual_fsize, since we are also allocating |
3131 | space for our callee (and our own register save area). */ | |
ab835497 RK |
3132 | actual_fsize = compute_frame_size (size, leaf_function); |
3133 | ||
61a55e8b DE |
3134 | if (leaf_function) |
3135 | { | |
3136 | frame_base_name = "%sp"; | |
3137 | frame_base_offset = actual_fsize + SPARC_STACK_BIAS; | |
3138 | } | |
3139 | else | |
3140 | { | |
3141 | frame_base_name = "%fp"; | |
3142 | frame_base_offset = SPARC_STACK_BIAS; | |
3143 | } | |
3144 | ||
c6aa9ce1 | 3145 | /* This is only for the human reader. */ |
ab835497 | 3146 | fprintf (file, "\t!#PROLOGUE# 0\n"); |
c6aa9ce1 | 3147 | |
915f619f JW |
3148 | if (actual_fsize == 0) |
3149 | /* do nothing. */ ; | |
3592ea0d | 3150 | else if (! leaf_function && ! TARGET_BROKEN_SAVERESTORE) |
ab835497 | 3151 | { |
3592ea0d | 3152 | if (actual_fsize <= 4096) |
ab835497 | 3153 | fprintf (file, "\tsave %%sp,-%d,%%sp\n", actual_fsize); |
3592ea0d | 3154 | else if (actual_fsize <= 8192) |
915f619f JW |
3155 | { |
3156 | fprintf (file, "\tsave %%sp,-4096,%%sp\n"); | |
3157 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096); | |
3158 | } | |
3159 | else | |
3160 | { | |
3592ea0d DE |
3161 | build_big_number (file, -actual_fsize, "%g1"); |
3162 | fprintf (file, "\tsave %%sp,%%g1,%%sp\n"); | |
915f619f | 3163 | } |
ab835497 | 3164 | } |
5f4241d5 | 3165 | else if (! leaf_function && TARGET_BROKEN_SAVERESTORE) |
ab835497 | 3166 | { |
5f4241d5 | 3167 | /* We assume the environment will properly handle or otherwise avoid |
3592ea0d DE |
3168 | trouble associated with an interrupt occuring after the `save' or |
3169 | trap occuring during it. */ | |
5f4241d5 | 3170 | fprintf (file, "\tsave\n"); |
3592ea0d | 3171 | |
5f4241d5 DE |
3172 | if (actual_fsize <= 4096) |
3173 | fprintf (file, "\tadd %%fp,-%d,%%sp\n", actual_fsize); | |
3174 | else if (actual_fsize <= 8192) | |
3175 | { | |
3176 | fprintf (file, "\tadd %%fp,-4096,%%sp\n"); | |
3177 | fprintf (file, "\tadd %%fp,-%d,%%sp\n", actual_fsize - 4096); | |
3178 | } | |
3179 | else | |
3180 | { | |
3181 | build_big_number (file, -actual_fsize, "%g1"); | |
3182 | fprintf (file, "\tadd %%fp,%%g1,%%sp\n"); | |
3183 | } | |
3184 | } | |
3185 | else /* leaf function */ | |
3186 | { | |
3592ea0d DE |
3187 | if (actual_fsize <= 4096) |
3188 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize); | |
3189 | else if (actual_fsize <= 8192) | |
3190 | { | |
3191 | fprintf (file, "\tadd %%sp,-4096,%%sp\n"); | |
3192 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096); | |
3193 | } | |
915f619f | 3194 | else |
3592ea0d DE |
3195 | { |
3196 | build_big_number (file, -actual_fsize, "%g1"); | |
3197 | fprintf (file, "\tadd %%sp,%%g1,%%sp\n"); | |
3198 | } | |
ab835497 RK |
3199 | } |
3200 | ||
c53aa195 JM |
3201 | #ifdef DWARF2_DEBUGGING_INFO |
3202 | if (write_symbols == DWARF2_DEBUG && actual_fsize) | |
3203 | { | |
3204 | char *label = (char *) dwarf2out_cfi_label (); | |
3205 | ||
3206 | /* The canonical frame address refers to the top of the frame. */ | |
3207 | dwarf2out_def_cfa (label, (leaf_function ? STACK_POINTER_REGNUM | |
3208 | : FRAME_POINTER_REGNUM), | |
3209 | frame_base_offset); | |
3210 | ||
3211 | if (! leaf_function) | |
3212 | { | |
3213 | /* Note the register window save. This tells the unwinder that | |
3214 | it needs to restore the window registers from the previous | |
3215 | frame's window save area at 0(cfa). */ | |
3216 | dwarf2out_window_save (label); | |
3217 | ||
3218 | /* The return address (-8) is now in %i7. */ | |
3219 | dwarf2out_return_reg (label, 31); | |
3220 | } | |
3221 | } | |
3222 | #endif | |
3223 | ||
ab835497 RK |
3224 | /* If doing anything with PIC, do it now. */ |
3225 | if (! flag_pic) | |
3226 | fprintf (file, "\t!#PROLOGUE# 1\n"); | |
3227 | ||
61a55e8b DE |
3228 | /* Call saved registers are saved just above the outgoing argument area. */ |
3229 | if (num_gfregs) | |
ab835497 | 3230 | { |
c53aa195 | 3231 | int offset, real_offset, n_regs; |
61a55e8b | 3232 | char *base; |
ab835497 | 3233 | |
84e884e9 JM |
3234 | real_offset = -apparent_fsize; |
3235 | offset = -apparent_fsize + frame_base_offset; | |
61a55e8b DE |
3236 | if (offset < -4096 || offset + num_gfregs * 4 > 4096) |
3237 | { | |
3238 | /* ??? This might be optimized a little as %g1 might already have a | |
3239 | value close enough that a single add insn will do. */ | |
3240 | /* ??? Although, all of this is probably only a temporary fix | |
3241 | because if %g1 can hold a function result, then | |
3242 | output_function_epilogue will lose (the result will get | |
3243 | clobbered). */ | |
3244 | build_big_number (file, offset, "%g1"); | |
3245 | fprintf (file, "\tadd %s,%%g1,%%g1\n", frame_base_name); | |
3246 | base = "%g1"; | |
3247 | offset = 0; | |
3248 | } | |
ab835497 | 3249 | else |
61a55e8b DE |
3250 | { |
3251 | base = frame_base_name; | |
3252 | } | |
ab835497 RK |
3253 | |
3254 | if (TARGET_EPILOGUE && ! leaf_function) | |
61a55e8b | 3255 | /* ??? Originally saved regs 0-15 here. */ |
c53aa195 | 3256 | n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset); |
ab835497 | 3257 | else if (leaf_function) |
61a55e8b | 3258 | /* ??? Originally saved regs 0-31 here. */ |
c53aa195 | 3259 | n_regs = save_regs (file, 0, 8, base, offset, 0, real_offset); |
ab835497 | 3260 | if (TARGET_EPILOGUE) |
c53aa195 JM |
3261 | save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs, |
3262 | real_offset); | |
ab835497 RK |
3263 | } |
3264 | ||
ab835497 RK |
3265 | leaf_label = 0; |
3266 | if (leaf_function && actual_fsize != 0) | |
3267 | { | |
3268 | /* warning ("leaf procedure with frame size %d", actual_fsize); */ | |
3269 | if (! TARGET_EPILOGUE) | |
3270 | leaf_label = gen_label_rtx (); | |
3271 | } | |
3272 | } | |
3273 | ||
915f619f JW |
3274 | /* Output code for the function epilogue. */ |
3275 | ||
ab835497 | 3276 | void |
ef8200df | 3277 | output_function_epilogue (file, size, leaf_function) |
ab835497 RK |
3278 | FILE *file; |
3279 | int size; | |
ef8200df | 3280 | int leaf_function; |
ab835497 | 3281 | { |
ab835497 RK |
3282 | char *ret; |
3283 | ||
3284 | if (leaf_label) | |
3285 | { | |
ab835497 RK |
3286 | emit_label_after (leaf_label, get_last_insn ()); |
3287 | final_scan_insn (get_last_insn (), file, 0, 0, 1); | |
3288 | } | |
3289 | ||
b69649e4 RK |
3290 | #ifdef FUNCTION_BLOCK_PROFILER_EXIT |
3291 | else if (profile_block_flag == 2) | |
3292 | { | |
3293 | FUNCTION_BLOCK_PROFILER_EXIT(file); | |
3294 | } | |
3295 | #endif | |
3296 | ||
61a55e8b DE |
3297 | /* Restore any call saved registers. */ |
3298 | if (num_gfregs) | |
ab835497 | 3299 | { |
61a55e8b DE |
3300 | int offset, n_regs; |
3301 | char *base; | |
ab835497 | 3302 | |
61a55e8b DE |
3303 | offset = -apparent_fsize + frame_base_offset; |
3304 | if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/) | |
3305 | { | |
3306 | build_big_number (file, offset, "%g1"); | |
3307 | fprintf (file, "\tadd %s,%%g1,%%g1\n", frame_base_name); | |
3308 | base = "%g1"; | |
3309 | offset = 0; | |
3310 | } | |
ab835497 | 3311 | else |
61a55e8b DE |
3312 | { |
3313 | base = frame_base_name; | |
3314 | } | |
ab835497 RK |
3315 | |
3316 | if (TARGET_EPILOGUE && ! leaf_function) | |
61a55e8b DE |
3317 | /* ??? Originally saved regs 0-15 here. */ |
3318 | n_regs = restore_regs (file, 0, 8, base, offset, 0); | |
ab835497 | 3319 | else if (leaf_function) |
61a55e8b DE |
3320 | /* ??? Originally saved regs 0-31 here. */ |
3321 | n_regs = restore_regs (file, 0, 8, base, offset, 0); | |
ab835497 | 3322 | if (TARGET_EPILOGUE) |
61a55e8b | 3323 | restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs); |
ab835497 RK |
3324 | } |
3325 | ||
3326 | /* Work out how to skip the caller's unimp instruction if required. */ | |
3327 | if (leaf_function) | |
61a55e8b | 3328 | ret = (SKIP_CALLERS_UNIMP_P ? "jmp %o7+12" : "retl"); |
ab835497 | 3329 | else |
61a55e8b | 3330 | ret = (SKIP_CALLERS_UNIMP_P ? "jmp %i7+12" : "ret"); |
ab835497 | 3331 | |
ef8200df | 3332 | if (TARGET_EPILOGUE || leaf_label) |
ab835497 | 3333 | { |
ef8200df JW |
3334 | int old_target_epilogue = TARGET_EPILOGUE; |
3335 | target_flags &= ~old_target_epilogue; | |
ab835497 | 3336 | |
ef8200df JW |
3337 | if (! leaf_function) |
3338 | { | |
3339 | /* If we wound up with things in our delay slot, flush them here. */ | |
3340 | if (current_function_epilogue_delay_list) | |
ab835497 | 3341 | { |
ef8200df JW |
3342 | rtx insn = emit_jump_insn_after (gen_rtx (RETURN, VOIDmode), |
3343 | get_last_insn ()); | |
3344 | PATTERN (insn) = gen_rtx (PARALLEL, VOIDmode, | |
3345 | gen_rtvec (2, | |
3346 | PATTERN (XEXP (current_function_epilogue_delay_list, 0)), | |
3347 | PATTERN (insn))); | |
3348 | final_scan_insn (insn, file, 1, 0, 1); | |
ab835497 RK |
3349 | } |
3350 | else | |
ef8200df JW |
3351 | fprintf (file, "\t%s\n\trestore\n", ret); |
3352 | } | |
915f619f JW |
3353 | /* All of the following cases are for leaf functions. */ |
3354 | else if (current_function_epilogue_delay_list) | |
ef8200df | 3355 | { |
915f619f JW |
3356 | /* eligible_for_epilogue_delay_slot ensures that if this is a |
3357 | leaf function, then we will only have insn in the delay slot | |
3358 | if the frame size is zero, thus no adjust for the stack is | |
3359 | needed here. */ | |
3360 | if (actual_fsize != 0) | |
ef8200df | 3361 | abort (); |
915f619f JW |
3362 | fprintf (file, "\t%s\n", ret); |
3363 | final_scan_insn (XEXP (current_function_epilogue_delay_list, 0), | |
3364 | file, 1, 0, 1); | |
ab835497 | 3365 | } |
9bb7ffda JW |
3366 | /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to |
3367 | avoid generating confusing assembly language output. */ | |
3368 | else if (actual_fsize == 0) | |
3369 | fprintf (file, "\t%s\n\tnop\n", ret); | |
915f619f JW |
3370 | else if (actual_fsize <= 4096) |
3371 | fprintf (file, "\t%s\n\tsub %%sp,-%d,%%sp\n", ret, actual_fsize); | |
3372 | else if (actual_fsize <= 8192) | |
3373 | fprintf (file, "\tsub %%sp,-4096,%%sp\n\t%s\n\tsub %%sp,-%d,%%sp\n", | |
3374 | ret, actual_fsize - 4096); | |
3375 | else if ((actual_fsize & 0x3ff) == 0) | |
3376 | fprintf (file, "\tsethi %%hi(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n", | |
3377 | actual_fsize, ret); | |
3378 | else | |
3379 | fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n", | |
3380 | actual_fsize, actual_fsize, ret); | |
ef8200df | 3381 | target_flags |= old_target_epilogue; |
ab835497 RK |
3382 | } |
3383 | } | |
3ea1fdd3 | 3384 | |
61a55e8b DE |
3385 | /* Do what is necessary for `va_start'. The argument is ignored. |
3386 | !v9: We look at the current function to determine if stdarg or varargs | |
3387 | is used and return the address of the first unnamed parameter. | |
3388 | v9: We save the argument integer and floating point regs in a buffer, and | |
3389 | return the address of this buffer. The rest is handled in va-sparc.h. */ | |
a9e27770 | 3390 | /* ??? This is currently conditioned on SPARC_ARCH64 because |
61a55e8b DE |
3391 | current_function_args_info is different in each compiler. */ |
3392 | ||
a9e27770 | 3393 | #if SPARC_ARCH64 |
61a55e8b DE |
3394 | |
3395 | rtx | |
3396 | sparc_builtin_saveregs (arglist) | |
3397 | tree arglist; | |
3398 | { | |
3399 | tree fntype = TREE_TYPE (current_function_decl); | |
3400 | /* First unnamed integer register. */ | |
a7acd911 | 3401 | int first_intreg = current_function_args_info.arg_count[(int) SPARC_ARG_INT]; |
61a55e8b DE |
3402 | /* Number of integer registers we need to save. */ |
3403 | int n_intregs = MAX (0, NPARM_REGS (SImode) - first_intreg); | |
3404 | /* First unnamed SFmode float reg (no, you can't pass SFmode floats as | |
a7acd911 DE |
3405 | unnamed arguments, we just number them that way). We must round up to |
3406 | the next double word float reg - that is the first one to save. */ | |
3407 | int first_floatreg = current_function_args_info.arg_count[(int) SPARC_ARG_FLOAT] + 1 & ~1; | |
61a55e8b DE |
3408 | /* Number of SFmode float regs to save. */ |
3409 | int n_floatregs = MAX (0, NPARM_REGS (SFmode) - first_floatreg); | |
3410 | int ptrsize = GET_MODE_SIZE (Pmode); | |
3411 | rtx valist, regbuf, fpregs; | |
a7acd911 | 3412 | int bufsize, adjust, regno; |
61a55e8b DE |
3413 | |
3414 | /* Allocate block of memory for the regs. | |
a7acd911 DE |
3415 | We only allocate as much as we need, but we must ensure quadword float |
3416 | regs are stored with the appropriate alignment. */ | |
61a55e8b DE |
3417 | /* ??? If n_intregs + n_floatregs == 0, should we allocate at least 1 byte? |
3418 | Or can assign_stack_local accept a 0 SIZE argument? */ | |
3419 | ||
a7acd911 DE |
3420 | bufsize = (n_intregs * UNITS_PER_WORD) + (n_floatregs * (UNITS_PER_WORD / 2)); |
3421 | /* Add space in front of the int regs to ensure proper alignment of quadword | |
3422 | fp regs. We must add the space in front because va_start assumes this. */ | |
3423 | if (n_floatregs >= 4) | |
3424 | adjust = ((n_intregs + first_floatreg / 2) % 2) * UNITS_PER_WORD; | |
3425 | else | |
3426 | adjust = 0; | |
3427 | ||
3428 | regbuf = assign_stack_local (BLKmode, bufsize + adjust, | |
3429 | GET_MODE_BITSIZE (TFmode)); | |
3430 | regbuf = gen_rtx (MEM, BLKmode, plus_constant (XEXP (regbuf, 0), adjust)); | |
61a55e8b DE |
3431 | MEM_IN_STRUCT_P (regbuf) = 1; |
3432 | ||
3433 | /* Save int args. | |
3434 | This is optimized to only save the regs that are necessary. Explicitly | |
3435 | named args need not be saved. */ | |
3436 | ||
3437 | if (n_intregs > 0) | |
3438 | move_block_from_reg (BASE_INCOMING_ARG_REG (SImode) + first_intreg, | |
3439 | regbuf, n_intregs, n_intregs * UNITS_PER_WORD); | |
3440 | ||
3441 | /* Save float args. | |
3442 | This is optimized to only save the regs that are necessary. Explicitly | |
3443 | named args need not be saved. | |
3444 | We explicitly build a pointer to the buffer because it halves the insn | |
3445 | count when not optimizing (otherwise the pointer is built for each reg | |
3446 | saved). */ | |
3447 | ||
3448 | fpregs = gen_reg_rtx (Pmode); | |
3449 | emit_move_insn (fpregs, plus_constant (XEXP (regbuf, 0), | |
3450 | n_intregs * UNITS_PER_WORD)); | |
3451 | for (regno = first_floatreg; regno < NPARM_REGS (SFmode); regno += 2) | |
3452 | emit_move_insn (gen_rtx (MEM, DFmode, | |
3453 | plus_constant (fpregs, | |
a7acd911 DE |
3454 | GET_MODE_SIZE (SFmode) |
3455 | * (regno - first_floatreg))), | |
3456 | gen_rtx (REG, DFmode, | |
3457 | BASE_INCOMING_ARG_REG (DFmode) + regno)); | |
61a55e8b DE |
3458 | |
3459 | /* Return the address of the regbuf. */ | |
3460 | ||
3461 | return XEXP (regbuf, 0); | |
3462 | } | |
3463 | ||
a9e27770 | 3464 | #else /* ! SPARC_ARCH64 */ |
3ea1fdd3 JW |
3465 | |
3466 | rtx | |
3467 | sparc_builtin_saveregs (arglist) | |
3468 | tree arglist; | |
3469 | { | |
3470 | tree fntype = TREE_TYPE (current_function_decl); | |
3471 | int stdarg = (TYPE_ARG_TYPES (fntype) != 0 | |
3472 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
3473 | != void_type_node)); | |
3474 | int first_reg = current_function_args_info; | |
3475 | rtx address; | |
3476 | int regno; | |
3477 | ||
227f7fd9 RS |
3478 | #if 0 /* This code seemed to have no effect except to make |
3479 | varargs not work right when va_list wasn't the first arg. */ | |
3ea1fdd3 JW |
3480 | if (! stdarg) |
3481 | first_reg = 0; | |
227f7fd9 | 3482 | #endif |
3ea1fdd3 | 3483 | |
61a55e8b | 3484 | for (regno = first_reg; regno < NPARM_REGS (SImode); regno++) |
3ea1fdd3 JW |
3485 | emit_move_insn (gen_rtx (MEM, word_mode, |
3486 | gen_rtx (PLUS, Pmode, | |
3487 | frame_pointer_rtx, | |
3488 | GEN_INT (STACK_POINTER_OFFSET | |
3489 | + UNITS_PER_WORD * regno))), | |
3490 | gen_rtx (REG, word_mode, BASE_INCOMING_ARG_REG (word_mode) | |
3491 | + regno)); | |
3492 | ||
3493 | address = gen_rtx (PLUS, Pmode, | |
3494 | frame_pointer_rtx, | |
3495 | GEN_INT (STACK_POINTER_OFFSET | |
3496 | + UNITS_PER_WORD * first_reg)); | |
3497 | ||
3498 | return address; | |
3499 | } | |
61a55e8b | 3500 | |
a9e27770 | 3501 | #endif /* ! SPARC_ARCH64 */ |
ab835497 RK |
3502 | \f |
3503 | /* Return the string to output a conditional branch to LABEL, which is | |
c4ce6853 DE |
3504 | the operand number of the label. OP is the conditional expression. |
3505 | XEXP (OP, 0) is assumed to be a condition code register (integer or | |
3506 | floating point) and its mode specifies what kind of comparison we made. | |
61a55e8b | 3507 | |
ab835497 RK |
3508 | REVERSED is non-zero if we should reverse the sense of the comparison. |
3509 | ||
3510 | ANNUL is non-zero if we should generate an annulling branch. | |
3511 | ||
3512 | NOOP is non-zero if we have to follow this branch by a noop. */ | |
3513 | ||
3514 | char * | |
c4ce6853 DE |
3515 | output_cbranch (op, label, reversed, annul, noop) |
3516 | rtx op; | |
ab835497 RK |
3517 | int label; |
3518 | int reversed, annul, noop; | |
3519 | { | |
3520 | static char string[20]; | |
3521 | enum rtx_code code = GET_CODE (op); | |
c4ce6853 DE |
3522 | rtx cc_reg = XEXP (op, 0); |
3523 | enum machine_mode mode = GET_MODE (cc_reg); | |
61a55e8b DE |
3524 | static char v8_labelno[] = " %lX"; |
3525 | static char v9_icc_labelno[] = " %%icc,%lX"; | |
3526 | static char v9_xcc_labelno[] = " %%xcc,%lX"; | |
3527 | static char v9_fcc_labelno[] = " %%fccX,%lY"; | |
3528 | char *labelno; | |
3529 | int labeloff; | |
3530 | ||
3531 | /* ??? !v9: FP branches cannot be preceded by another floating point insn. | |
ab835497 RK |
3532 | Because there is currently no concept of pre-delay slots, we can fix |
3533 | this only by always emitting a nop before a floating point branch. */ | |
3534 | ||
61a55e8b | 3535 | if ((mode == CCFPmode || mode == CCFPEmode) && ! TARGET_V9) |
ab835497 | 3536 | strcpy (string, "nop\n\t"); |
61a55e8b DE |
3537 | else |
3538 | string[0] = '\0'; | |
ab835497 RK |
3539 | |
3540 | /* If not floating-point or if EQ or NE, we can just reverse the code. */ | |
4d449554 JW |
3541 | if (reversed |
3542 | && ((mode != CCFPmode && mode != CCFPEmode) || code == EQ || code == NE)) | |
ab835497 RK |
3543 | code = reverse_condition (code), reversed = 0; |
3544 | ||
3545 | /* Start by writing the branch condition. */ | |
3546 | switch (code) | |
3547 | { | |
3548 | case NE: | |
4d449554 | 3549 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3550 | strcat (string, "fbne"); |
3551 | else | |
3552 | strcpy (string, "bne"); | |
3553 | break; | |
3554 | ||
3555 | case EQ: | |
4d449554 | 3556 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3557 | strcat (string, "fbe"); |
3558 | else | |
3559 | strcpy (string, "be"); | |
3560 | break; | |
3561 | ||
3562 | case GE: | |
4d449554 | 3563 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3564 | { |
3565 | if (reversed) | |
3566 | strcat (string, "fbul"); | |
3567 | else | |
3568 | strcat (string, "fbge"); | |
3569 | } | |
3570 | else if (mode == CC_NOOVmode) | |
3571 | strcpy (string, "bpos"); | |
3572 | else | |
3573 | strcpy (string, "bge"); | |
3574 | break; | |
3575 | ||
3576 | case GT: | |
4d449554 | 3577 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3578 | { |
3579 | if (reversed) | |
3580 | strcat (string, "fbule"); | |
3581 | else | |
3582 | strcat (string, "fbg"); | |
3583 | } | |
3584 | else | |
3585 | strcpy (string, "bg"); | |
3586 | break; | |
3587 | ||
3588 | case LE: | |
4d449554 | 3589 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3590 | { |
3591 | if (reversed) | |
3592 | strcat (string, "fbug"); | |
3593 | else | |
3594 | strcat (string, "fble"); | |
3595 | } | |
3596 | else | |
3597 | strcpy (string, "ble"); | |
3598 | break; | |
3599 | ||
3600 | case LT: | |
4d449554 | 3601 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
3602 | { |
3603 | if (reversed) | |
3604 | strcat (string, "fbuge"); | |
3605 | else | |
3606 | strcat (string, "fbl"); | |
3607 | } | |
3608 | else if (mode == CC_NOOVmode) | |
3609 | strcpy (string, "bneg"); | |
3610 | else | |
3611 | strcpy (string, "bl"); | |
3612 | break; | |
3613 | ||
3614 | case GEU: | |
3615 | strcpy (string, "bgeu"); | |
3616 | break; | |
3617 | ||
3618 | case GTU: | |
3619 | strcpy (string, "bgu"); | |
3620 | break; | |
3621 | ||
3622 | case LEU: | |
3623 | strcpy (string, "bleu"); | |
3624 | break; | |
3625 | ||
3626 | case LTU: | |
3627 | strcpy (string, "blu"); | |
3628 | break; | |
3629 | } | |
3630 | ||
3631 | /* Now add the annulling, the label, and a possible noop. */ | |
3632 | if (annul) | |
3633 | strcat (string, ",a"); | |
3634 | ||
61a55e8b DE |
3635 | /* ??? If v9, optional prediction bit ",pt" or ",pf" goes here. */ |
3636 | ||
3637 | if (! TARGET_V9) | |
3638 | { | |
3639 | labeloff = 3; | |
3640 | labelno = v8_labelno; | |
3641 | } | |
3642 | else | |
3643 | { | |
3644 | labeloff = 9; | |
3645 | if (mode == CCFPmode || mode == CCFPEmode) | |
3646 | { | |
3647 | labeloff = 10; | |
3648 | labelno = v9_fcc_labelno; | |
3649 | /* Set the char indicating the number of the fcc reg to use. */ | |
c4ce6853 | 3650 | labelno[6] = REGNO (cc_reg) - SPARC_FIRST_V9_FCC_REG + '0'; |
61a55e8b DE |
3651 | } |
3652 | else if (mode == CCXmode || mode == CCX_NOOVmode) | |
3653 | labelno = v9_xcc_labelno; | |
3654 | else | |
3655 | labelno = v9_icc_labelno; | |
3656 | } | |
3657 | /* Set the char indicating the number of the operand containing the | |
3658 | label_ref. */ | |
3659 | labelno[labeloff] = label + '0'; | |
3660 | strcat (string, labelno); | |
3661 | ||
3662 | if (noop) | |
3663 | strcat (string, "\n\tnop"); | |
3664 | ||
3665 | return string; | |
3666 | } | |
3667 | ||
3668 | /* Return the string to output a conditional branch to LABEL, testing | |
3669 | register REG. LABEL is the operand number of the label; REG is the | |
3670 | operand number of the reg. OP is the conditional expression. The mode | |
3671 | of REG says what kind of comparison we made. | |
3672 | ||
3673 | REVERSED is non-zero if we should reverse the sense of the comparison. | |
3674 | ||
3675 | ANNUL is non-zero if we should generate an annulling branch. | |
3676 | ||
3677 | NOOP is non-zero if we have to follow this branch by a noop. */ | |
3678 | ||
3679 | char * | |
3680 | output_v9branch (op, reg, label, reversed, annul, noop) | |
3681 | rtx op; | |
3682 | int reg, label; | |
3683 | int reversed, annul, noop; | |
3684 | { | |
3685 | static char string[20]; | |
3686 | enum rtx_code code = GET_CODE (op); | |
3687 | enum machine_mode mode = GET_MODE (XEXP (op, 0)); | |
3688 | static char labelno[] = " %X,%lX"; | |
3689 | ||
3690 | /* If not floating-point or if EQ or NE, we can just reverse the code. */ | |
3691 | if (reversed) | |
3692 | code = reverse_condition (code), reversed = 0; | |
3693 | ||
3694 | /* Only 64 bit versions of these instructions exist. */ | |
3695 | if (mode != DImode) | |
3696 | abort (); | |
3697 | ||
3698 | /* Start by writing the branch condition. */ | |
3699 | ||
3700 | switch (code) | |
3701 | { | |
3702 | case NE: | |
3703 | strcpy (string, "brnz"); | |
3704 | break; | |
3705 | ||
3706 | case EQ: | |
3707 | strcpy (string, "brz"); | |
3708 | break; | |
3709 | ||
3710 | case GE: | |
3711 | strcpy (string, "brgez"); | |
3712 | break; | |
3713 | ||
3714 | case LT: | |
3715 | strcpy (string, "brlz"); | |
3716 | break; | |
3717 | ||
3718 | case LE: | |
3719 | strcpy (string, "brlez"); | |
3720 | break; | |
3721 | ||
3722 | case GT: | |
3723 | strcpy (string, "brgz"); | |
3724 | break; | |
3725 | ||
3726 | default: | |
3727 | abort (); | |
3728 | } | |
3729 | ||
3730 | /* Now add the annulling, reg, label, and nop. */ | |
3731 | if (annul) | |
3732 | strcat (string, ",a"); | |
3733 | ||
3734 | /* ??? Optional prediction bit ",pt" or ",pf" goes here. */ | |
3735 | ||
3736 | labelno[2] = reg + '0'; | |
3737 | labelno[6] = label + '0'; | |
ab835497 RK |
3738 | strcat (string, labelno); |
3739 | ||
3740 | if (noop) | |
3741 | strcat (string, "\n\tnop"); | |
3742 | ||
3743 | return string; | |
3744 | } | |
3745 | ||
795068a4 JW |
3746 | /* Output assembler code to return from a function. */ |
3747 | ||
61a55e8b DE |
3748 | /* ??? v9: Update to use the new `return' instruction. Also, add patterns to |
3749 | md file for the `return' instruction. */ | |
3750 | ||
ab835497 RK |
3751 | char * |
3752 | output_return (operands) | |
3753 | rtx *operands; | |
3754 | { | |
3755 | if (leaf_label) | |
3756 | { | |
3757 | operands[0] = leaf_label; | |
3758 | return "b,a %l0"; | |
3759 | } | |
3760 | else if (leaf_function) | |
3761 | { | |
915f619f JW |
3762 | /* If we didn't allocate a frame pointer for the current function, |
3763 | the stack pointer might have been adjusted. Output code to | |
3764 | restore it now. */ | |
3765 | ||
ab835497 | 3766 | operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize); |
915f619f JW |
3767 | |
3768 | /* Use sub of negated value in first two cases instead of add to | |
3769 | allow actual_fsize == 4096. */ | |
3770 | ||
3771 | if (actual_fsize <= 4096) | |
ab835497 | 3772 | { |
61a55e8b | 3773 | if (SKIP_CALLERS_UNIMP_P) |
915f619f | 3774 | return "jmp %%o7+12\n\tsub %%sp,-%0,%%sp"; |
ab835497 | 3775 | else |
915f619f | 3776 | return "retl\n\tsub %%sp,-%0,%%sp"; |
ab835497 | 3777 | } |
915f619f | 3778 | else if (actual_fsize <= 8192) |
ab835497 | 3779 | { |
915f619f | 3780 | operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize - 4096); |
61a55e8b | 3781 | if (SKIP_CALLERS_UNIMP_P) |
915f619f JW |
3782 | return "sub %%sp,-4096,%%sp\n\tjmp %%o7+12\n\tsub %%sp,-%0,%%sp"; |
3783 | else | |
3784 | return "sub %%sp,-4096,%%sp\n\tretl\n\tsub %%sp,-%0,%%sp"; | |
3785 | } | |
61a55e8b | 3786 | else if (SKIP_CALLERS_UNIMP_P) |
915f619f JW |
3787 | { |
3788 | if ((actual_fsize & 0x3ff) != 0) | |
ab835497 RK |
3789 | return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp"; |
3790 | else | |
915f619f JW |
3791 | return "sethi %%hi(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp"; |
3792 | } | |
3793 | else | |
3794 | { | |
3795 | if ((actual_fsize & 0x3ff) != 0) | |
ab835497 | 3796 | return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp"; |
915f619f JW |
3797 | else |
3798 | return "sethi %%hi(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp"; | |
ab835497 RK |
3799 | } |
3800 | } | |
3801 | else | |
3802 | { | |
61a55e8b | 3803 | if (SKIP_CALLERS_UNIMP_P) |
ab835497 RK |
3804 | return "jmp %%i7+12\n\trestore"; |
3805 | else | |
3806 | return "ret\n\trestore"; | |
3807 | } | |
3808 | } | |
ab835497 RK |
3809 | \f |
3810 | /* Leaf functions and non-leaf functions have different needs. */ | |
3811 | ||
3812 | static int | |
3813 | reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER; | |
3814 | ||
3815 | static int | |
3816 | reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER; | |
3817 | ||
3818 | static int *reg_alloc_orders[] = { | |
3819 | reg_leaf_alloc_order, | |
3820 | reg_nonleaf_alloc_order}; | |
3821 | ||
3822 | void | |
3823 | order_regs_for_local_alloc () | |
3824 | { | |
3825 | static int last_order_nonleaf = 1; | |
3826 | ||
3827 | if (regs_ever_live[15] != last_order_nonleaf) | |
3828 | { | |
3829 | last_order_nonleaf = !last_order_nonleaf; | |
d2889939 RK |
3830 | bcopy ((char *) reg_alloc_orders[last_order_nonleaf], |
3831 | (char *) reg_alloc_order, FIRST_PSEUDO_REGISTER * sizeof (int)); | |
ab835497 RK |
3832 | } |
3833 | } | |
3834 | \f | |
35016322 JW |
3835 | /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1. |
3836 | This makes them candidates for using ldd and std insns. | |
3837 | ||
3838 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
3839 | abort if we are passed pseudo registers. */ | |
3840 | ||
3841 | int | |
7c56249d | 3842 | registers_ok_for_ldd_peep (reg1, reg2) |
35016322 JW |
3843 | rtx reg1, reg2; |
3844 | { | |
35016322 JW |
3845 | /* We might have been passed a SUBREG. */ |
3846 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
3847 | return 0; | |
3848 | ||
35016322 JW |
3849 | if (REGNO (reg1) % 2 != 0) |
3850 | return 0; | |
3851 | ||
3852 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
35016322 JW |
3853 | } |
3854 | ||
3855 | /* Return 1 if addr1 and addr2 are suitable for use in an ldd or | |
3856 | std insn. | |
3857 | ||
3858 | This can only happen when addr1 and addr2 are consecutive memory | |
3859 | locations (addr1 + 4 == addr2). addr1 must also be aligned on a | |
3860 | 64 bit boundary (addr1 % 8 == 0). | |
3861 | ||
3862 | We know %sp and %fp are kept aligned on a 64 bit boundary. Other | |
3863 | registers are assumed to *never* be properly aligned and are | |
3864 | rejected. | |
3865 | ||
3866 | Knowing %sp and %fp are kept aligned on a 64 bit boundary, we | |
3867 | need only check that the offset for addr1 % 8 == 0. */ | |
3868 | ||
3869 | int | |
7c56249d | 3870 | addrs_ok_for_ldd_peep (addr1, addr2) |
35016322 JW |
3871 | rtx addr1, addr2; |
3872 | { | |
3873 | int reg1, offset1; | |
3874 | ||
3875 | /* Extract a register number and offset (if used) from the first addr. */ | |
3876 | if (GET_CODE (addr1) == PLUS) | |
3877 | { | |
3878 | /* If not a REG, return zero. */ | |
3879 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
3880 | return 0; | |
3881 | else | |
3882 | { | |
3883 | reg1 = REGNO (XEXP (addr1, 0)); | |
3884 | /* The offset must be constant! */ | |
3885 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
3886 | return 0; | |
3887 | offset1 = INTVAL (XEXP (addr1, 1)); | |
3888 | } | |
3889 | } | |
3890 | else if (GET_CODE (addr1) != REG) | |
3891 | return 0; | |
3892 | else | |
3893 | { | |
3894 | reg1 = REGNO (addr1); | |
3895 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
3896 | offset1 = 0; | |
3897 | } | |
3898 | ||
3899 | /* Make sure the second address is a (mem (plus (reg) (const_int). */ | |
3900 | if (GET_CODE (addr2) != PLUS) | |
3901 | return 0; | |
3902 | ||
3903 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
3904 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
3905 | return 0; | |
3906 | ||
3907 | /* Only %fp and %sp are allowed. Additionally both addresses must | |
3908 | use the same register. */ | |
3909 | if (reg1 != FRAME_POINTER_REGNUM && reg1 != STACK_POINTER_REGNUM) | |
3910 | return 0; | |
3911 | ||
3912 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
3913 | return 0; | |
3914 | ||
2296cba3 | 3915 | /* The first offset must be evenly divisible by 8 to ensure the |
35016322 JW |
3916 | address is 64 bit aligned. */ |
3917 | if (offset1 % 8 != 0) | |
3918 | return 0; | |
3919 | ||
3920 | /* The offset for the second addr must be 4 more than the first addr. */ | |
3921 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 4) | |
3922 | return 0; | |
3923 | ||
3924 | /* All the tests passed. addr1 and addr2 are valid for ldd and std | |
3925 | instructions. */ | |
3926 | return 1; | |
3927 | } | |
7c56249d JL |
3928 | |
3929 | /* Return 1 if reg is a pseudo, or is the first register in | |
3930 | a hard register pair. This makes it a candidate for use in | |
3931 | ldd and std insns. */ | |
3932 | ||
3933 | int | |
3934 | register_ok_for_ldd (reg) | |
3935 | rtx reg; | |
3936 | { | |
7c56249d JL |
3937 | /* We might have been passed a SUBREG. */ |
3938 | if (GET_CODE (reg) != REG) | |
3939 | return 0; | |
3940 | ||
3941 | if (REGNO (reg) < FIRST_PSEUDO_REGISTER) | |
3942 | return (REGNO (reg) % 2 == 0); | |
3943 | else | |
3944 | return 1; | |
7c56249d | 3945 | } |
ab835497 | 3946 | \f |
ab835497 RK |
3947 | /* Print operand X (an rtx) in assembler syntax to file FILE. |
3948 | CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified. | |
3949 | For `%' followed by punctuation, CODE is the punctuation and X is null. */ | |
3950 | ||
3951 | void | |
3952 | print_operand (file, x, code) | |
3953 | FILE *file; | |
3954 | rtx x; | |
3955 | int code; | |
3956 | { | |
3957 | switch (code) | |
3958 | { | |
3959 | case '#': | |
3960 | /* Output a 'nop' if there's nothing for the delay slot. */ | |
3961 | if (dbr_sequence_length () == 0) | |
3962 | fputs ("\n\tnop", file); | |
3963 | return; | |
3964 | case '*': | |
c6ce0969 JW |
3965 | /* Output an annul flag if there's nothing for the delay slot and we |
3966 | are optimizing. This is always used with '(' below. */ | |
3967 | /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch; | |
3968 | this is a dbx bug. So, we only do this when optimizing. */ | |
3969 | if (dbr_sequence_length () == 0 && optimize) | |
3970 | fputs (",a", file); | |
3971 | return; | |
3972 | case '(': | |
3973 | /* Output a 'nop' if there's nothing for the delay slot and we are | |
3974 | not optimizing. This is always used with '*' above. */ | |
3975 | if (dbr_sequence_length () == 0 && ! optimize) | |
3976 | fputs ("\n\tnop", file); | |
ab835497 | 3977 | return; |
61a55e8b DE |
3978 | case '_': |
3979 | /* Output the Medium/Anywhere code model base register. */ | |
3980 | fputs (MEDANY_BASE_REG, file); | |
3981 | return; | |
3982 | case '@': | |
3983 | /* Print out what we are using as the frame pointer. This might | |
3984 | be %fp, or might be %sp+offset. */ | |
3985 | /* ??? What if offset is too big? Perhaps the caller knows it isn't? */ | |
3986 | fprintf (file, "%s+%d", frame_base_name, frame_base_offset); | |
3987 | return; | |
ab835497 RK |
3988 | case 'Y': |
3989 | /* Adjust the operand to take into account a RESTORE operation. */ | |
3990 | if (GET_CODE (x) != REG) | |
b3b1e8bd JW |
3991 | output_operand_lossage ("Invalid %%Y operand"); |
3992 | else if (REGNO (x) < 8) | |
ab835497 RK |
3993 | fputs (reg_names[REGNO (x)], file); |
3994 | else if (REGNO (x) >= 24 && REGNO (x) < 32) | |
3995 | fputs (reg_names[REGNO (x)-16], file); | |
3996 | else | |
b3b1e8bd | 3997 | output_operand_lossage ("Invalid %%Y operand"); |
ab835497 | 3998 | return; |
0f39a9aa DE |
3999 | case 'L': |
4000 | /* Print out the low order register name of a register pair. */ | |
4001 | if (WORDS_BIG_ENDIAN) | |
4002 | fputs (reg_names[REGNO (x)+1], file); | |
4003 | else | |
4004 | fputs (reg_names[REGNO (x)], file); | |
4005 | return; | |
4006 | case 'H': | |
4007 | /* Print out the high order register name of a register pair. */ | |
4008 | if (WORDS_BIG_ENDIAN) | |
4009 | fputs (reg_names[REGNO (x)], file); | |
4010 | else | |
4011 | fputs (reg_names[REGNO (x)+1], file); | |
4012 | return; | |
ab835497 | 4013 | case 'R': |
795068a4 | 4014 | /* Print out the second register name of a register pair or quad. |
ab835497 RK |
4015 | I.e., R (%o0) => %o1. */ |
4016 | fputs (reg_names[REGNO (x)+1], file); | |
4017 | return; | |
795068a4 JW |
4018 | case 'S': |
4019 | /* Print out the third register name of a register quad. | |
4020 | I.e., S (%o0) => %o2. */ | |
4021 | fputs (reg_names[REGNO (x)+2], file); | |
4022 | return; | |
4023 | case 'T': | |
4024 | /* Print out the fourth register name of a register quad. | |
4025 | I.e., T (%o0) => %o3. */ | |
4026 | fputs (reg_names[REGNO (x)+3], file); | |
4027 | return; | |
304b7a23 DE |
4028 | case 'x': |
4029 | /* Print a condition code register. */ | |
4030 | if (REGNO (x) == SPARC_ICC_REG) | |
4031 | { | |
4032 | /* We don't handle CC[X]_NOOVmode because they're not supposed | |
4033 | to occur here. */ | |
4034 | if (GET_MODE (x) == CCmode) | |
4035 | fputs ("%icc", file); | |
4036 | else if (GET_MODE (x) == CCXmode) | |
4037 | fputs ("%xcc", file); | |
4038 | else | |
4039 | abort (); | |
4040 | } | |
4041 | else | |
4042 | /* %fccN register */ | |
4043 | fputs (reg_names[REGNO (x)], file); | |
4044 | return; | |
ab835497 RK |
4045 | case 'm': |
4046 | /* Print the operand's address only. */ | |
4047 | output_address (XEXP (x, 0)); | |
4048 | return; | |
4049 | case 'r': | |
4050 | /* In this case we need a register. Use %g0 if the | |
77a02b01 | 4051 | operand is const0_rtx. */ |
76052e74 RS |
4052 | if (x == const0_rtx |
4053 | || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x)))) | |
ab835497 RK |
4054 | { |
4055 | fputs ("%g0", file); | |
4056 | return; | |
4057 | } | |
4058 | else | |
4059 | break; | |
4060 | ||
61a55e8b | 4061 | case 'A': |
ab835497 RK |
4062 | switch (GET_CODE (x)) |
4063 | { | |
4064 | case IOR: fputs ("or", file); break; | |
4065 | case AND: fputs ("and", file); break; | |
4066 | case XOR: fputs ("xor", file); break; | |
b3b1e8bd | 4067 | default: output_operand_lossage ("Invalid %%A operand"); |
ab835497 RK |
4068 | } |
4069 | return; | |
4070 | ||
4071 | case 'B': | |
4072 | switch (GET_CODE (x)) | |
4073 | { | |
4074 | case IOR: fputs ("orn", file); break; | |
4075 | case AND: fputs ("andn", file); break; | |
4076 | case XOR: fputs ("xnor", file); break; | |
b3b1e8bd | 4077 | default: output_operand_lossage ("Invalid %%B operand"); |
ab835497 RK |
4078 | } |
4079 | return; | |
4080 | ||
304b7a23 DE |
4081 | /* These are used by the conditional move instructions. */ |
4082 | case 'c' : | |
61a55e8b | 4083 | case 'C': |
304b7a23 DE |
4084 | { |
4085 | enum rtx_code rc = (code == 'c' | |
4086 | ? reverse_condition (GET_CODE (x)) | |
4087 | : GET_CODE (x)); | |
4088 | switch (rc) | |
4089 | { | |
4090 | case NE: fputs ("ne", file); break; | |
4091 | case EQ: fputs ("e", file); break; | |
4092 | case GE: fputs ("ge", file); break; | |
4093 | case GT: fputs ("g", file); break; | |
4094 | case LE: fputs ("le", file); break; | |
4095 | case LT: fputs ("l", file); break; | |
4096 | case GEU: fputs ("geu", file); break; | |
4097 | case GTU: fputs ("gu", file); break; | |
4098 | case LEU: fputs ("leu", file); break; | |
4099 | case LTU: fputs ("lu", file); break; | |
4100 | default: output_operand_lossage (code == 'c' | |
4101 | ? "Invalid %%c operand" | |
4102 | : "Invalid %%C operand"); | |
4103 | } | |
4104 | return; | |
4105 | } | |
4106 | ||
4107 | /* These are used by the movr instruction pattern. */ | |
4108 | case 'd': | |
61a55e8b | 4109 | case 'D': |
304b7a23 DE |
4110 | { |
4111 | enum rtx_code rc = (code == 'd' | |
4112 | ? reverse_condition (GET_CODE (x)) | |
4113 | : GET_CODE (x)); | |
4114 | switch (rc) | |
4115 | { | |
4116 | case NE: fputs ("ne", file); break; | |
4117 | case EQ: fputs ("e", file); break; | |
4118 | case GE: fputs ("gez", file); break; | |
4119 | case LT: fputs ("lz", file); break; | |
4120 | case LE: fputs ("lez", file); break; | |
4121 | case GT: fputs ("gz", file); break; | |
4122 | default: output_operand_lossage (code == 'd' | |
4123 | ? "Invalid %%d operand" | |
4124 | : "Invalid %%D operand"); | |
4125 | } | |
4126 | return; | |
4127 | } | |
61a55e8b | 4128 | |
ab835497 RK |
4129 | case 'b': |
4130 | { | |
4131 | /* Print a sign-extended character. */ | |
4132 | int i = INTVAL (x) & 0xff; | |
4133 | if (i & 0x80) | |
4134 | i |= 0xffffff00; | |
4135 | fprintf (file, "%d", i); | |
4136 | return; | |
4137 | } | |
4138 | ||
d2889939 RK |
4139 | case 'f': |
4140 | /* Operand must be a MEM; write its address. */ | |
4141 | if (GET_CODE (x) != MEM) | |
4142 | output_operand_lossage ("Invalid %%f operand"); | |
4143 | output_address (XEXP (x, 0)); | |
4144 | return; | |
4145 | ||
ab835497 RK |
4146 | case 0: |
4147 | /* Do nothing special. */ | |
4148 | break; | |
4149 | ||
4150 | default: | |
4151 | /* Undocumented flag. */ | |
415f583e | 4152 | output_operand_lossage ("invalid operand output code"); |
ab835497 RK |
4153 | } |
4154 | ||
4155 | if (GET_CODE (x) == REG) | |
4156 | fputs (reg_names[REGNO (x)], file); | |
4157 | else if (GET_CODE (x) == MEM) | |
4158 | { | |
4159 | fputc ('[', file); | |
ab835497 | 4160 | /* Poor Sun assembler doesn't understand absolute addressing. */ |
c4ce6853 DE |
4161 | if (CONSTANT_P (XEXP (x, 0)) |
4162 | && ! TARGET_LIVE_G0) | |
ab835497 RK |
4163 | fputs ("%g0+", file); |
4164 | output_address (XEXP (x, 0)); | |
4165 | fputc (']', file); | |
4166 | } | |
4167 | else if (GET_CODE (x) == HIGH) | |
4168 | { | |
4169 | fputs ("%hi(", file); | |
4170 | output_addr_const (file, XEXP (x, 0)); | |
4171 | fputc (')', file); | |
4172 | } | |
4173 | else if (GET_CODE (x) == LO_SUM) | |
4174 | { | |
4175 | print_operand (file, XEXP (x, 0), 0); | |
4176 | fputs ("+%lo(", file); | |
4177 | output_addr_const (file, XEXP (x, 1)); | |
4178 | fputc (')', file); | |
4179 | } | |
e601abce JW |
4180 | else if (GET_CODE (x) == CONST_DOUBLE |
4181 | && (GET_MODE (x) == VOIDmode | |
4182 | || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)) | |
ab835497 RK |
4183 | { |
4184 | if (CONST_DOUBLE_HIGH (x) == 0) | |
4185 | fprintf (file, "%u", CONST_DOUBLE_LOW (x)); | |
4186 | else if (CONST_DOUBLE_HIGH (x) == -1 | |
4187 | && CONST_DOUBLE_LOW (x) < 0) | |
4188 | fprintf (file, "%d", CONST_DOUBLE_LOW (x)); | |
4189 | else | |
e601abce | 4190 | output_operand_lossage ("long long constant not a valid immediate operand"); |
ab835497 | 4191 | } |
e601abce JW |
4192 | else if (GET_CODE (x) == CONST_DOUBLE) |
4193 | output_operand_lossage ("floating point constant not a valid immediate operand"); | |
ab835497 RK |
4194 | else { output_addr_const (file, x); } |
4195 | } | |
4196 | \f | |
4197 | /* This function outputs assembler code for VALUE to FILE, where VALUE is | |
4198 | a 64 bit (DImode) value. */ | |
4199 | ||
4200 | /* ??? If there is a 64 bit counterpart to .word that the assembler | |
4201 | understands, then using that would simply this code greatly. */ | |
61a55e8b DE |
4202 | /* ??? We only output .xword's for symbols and only then in environments |
4203 | where the assembler can handle them. */ | |
ab835497 RK |
4204 | |
4205 | void | |
4206 | output_double_int (file, value) | |
4207 | FILE *file; | |
4208 | rtx value; | |
4209 | { | |
4210 | if (GET_CODE (value) == CONST_INT) | |
4211 | { | |
4212 | if (INTVAL (value) < 0) | |
4213 | ASM_OUTPUT_INT (file, constm1_rtx); | |
4214 | else | |
4215 | ASM_OUTPUT_INT (file, const0_rtx); | |
4216 | ASM_OUTPUT_INT (file, value); | |
4217 | } | |
4218 | else if (GET_CODE (value) == CONST_DOUBLE) | |
4219 | { | |
4220 | ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode, | |
4221 | CONST_DOUBLE_HIGH (value))); | |
4222 | ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode, | |
4223 | CONST_DOUBLE_LOW (value))); | |
4224 | } | |
4225 | else if (GET_CODE (value) == SYMBOL_REF | |
4226 | || GET_CODE (value) == CONST | |
61a55e8b | 4227 | || GET_CODE (value) == PLUS |
a9e27770 | 4228 | || (TARGET_ARCH64 && |
61a55e8b | 4229 | (GET_CODE (value) == LABEL_REF |
9fa9626b | 4230 | || GET_CODE (value) == CODE_LABEL |
61a55e8b | 4231 | || GET_CODE (value) == MINUS))) |
ab835497 | 4232 | { |
a9e27770 | 4233 | if (!TARGET_V9 || TARGET_MEDLOW) |
61a55e8b DE |
4234 | { |
4235 | ASM_OUTPUT_INT (file, const0_rtx); | |
4236 | ASM_OUTPUT_INT (file, value); | |
4237 | } | |
4238 | else | |
4239 | { | |
4240 | fprintf (file, "\t%s\t", ASM_LONGLONG); | |
4241 | output_addr_const (file, value); | |
4242 | fprintf (file, "\n"); | |
4243 | } | |
ab835497 RK |
4244 | } |
4245 | else | |
4246 | abort (); | |
4247 | } | |
210aa14a | 4248 | \f |
b0468b84 RK |
4249 | /* Return the value of a code used in the .proc pseudo-op that says |
4250 | what kind of result this function returns. For non-C types, we pick | |
4251 | the closest C type. */ | |
4252 | ||
77a02b01 JW |
4253 | #ifndef CHAR_TYPE_SIZE |
4254 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
4255 | #endif | |
4256 | ||
4257 | #ifndef SHORT_TYPE_SIZE | |
4258 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) | |
4259 | #endif | |
4260 | ||
4261 | #ifndef INT_TYPE_SIZE | |
4262 | #define INT_TYPE_SIZE BITS_PER_WORD | |
4263 | #endif | |
4264 | ||
4265 | #ifndef LONG_TYPE_SIZE | |
4266 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
4267 | #endif | |
4268 | ||
4269 | #ifndef LONG_LONG_TYPE_SIZE | |
4270 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
4271 | #endif | |
4272 | ||
4273 | #ifndef FLOAT_TYPE_SIZE | |
4274 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
4275 | #endif | |
4276 | ||
4277 | #ifndef DOUBLE_TYPE_SIZE | |
4278 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
4279 | #endif | |
4280 | ||
4281 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
4282 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
4283 | #endif | |
210aa14a RS |
4284 | |
4285 | unsigned long | |
4286 | sparc_type_code (type) | |
4287 | register tree type; | |
4288 | { | |
4289 | register unsigned long qualifiers = 0; | |
4290 | register unsigned shift = 6; | |
4291 | ||
abc95ed3 | 4292 | /* Only the first 30 bits of the qualifier are valid. We must refrain from |
aee2c3c5 JW |
4293 | setting more, since some assemblers will give an error for this. Also, |
4294 | we must be careful to avoid shifts of 32 bits or more to avoid getting | |
4295 | unpredictable results. */ | |
4296 | ||
210aa14a RS |
4297 | for (;;) |
4298 | { | |
4299 | switch (TREE_CODE (type)) | |
4300 | { | |
4301 | case ERROR_MARK: | |
4302 | return qualifiers; | |
4303 | ||
4304 | case ARRAY_TYPE: | |
aee2c3c5 JW |
4305 | if (shift < 30) |
4306 | qualifiers |= (3 << shift); | |
210aa14a RS |
4307 | shift += 2; |
4308 | type = TREE_TYPE (type); | |
4309 | break; | |
4310 | ||
4311 | case FUNCTION_TYPE: | |
4312 | case METHOD_TYPE: | |
aee2c3c5 JW |
4313 | if (shift < 30) |
4314 | qualifiers |= (2 << shift); | |
210aa14a RS |
4315 | shift += 2; |
4316 | type = TREE_TYPE (type); | |
4317 | break; | |
4318 | ||
4319 | case POINTER_TYPE: | |
4320 | case REFERENCE_TYPE: | |
4321 | case OFFSET_TYPE: | |
aee2c3c5 JW |
4322 | if (shift < 30) |
4323 | qualifiers |= (1 << shift); | |
210aa14a RS |
4324 | shift += 2; |
4325 | type = TREE_TYPE (type); | |
4326 | break; | |
ab835497 | 4327 | |
210aa14a RS |
4328 | case RECORD_TYPE: |
4329 | return (qualifiers | 8); | |
4330 | ||
4331 | case UNION_TYPE: | |
b0468b84 | 4332 | case QUAL_UNION_TYPE: |
210aa14a RS |
4333 | return (qualifiers | 9); |
4334 | ||
4335 | case ENUMERAL_TYPE: | |
4336 | return (qualifiers | 10); | |
4337 | ||
4338 | case VOID_TYPE: | |
4339 | return (qualifiers | 16); | |
4340 | ||
4341 | case INTEGER_TYPE: | |
654209e6 JW |
4342 | /* If this is a range type, consider it to be the underlying |
4343 | type. */ | |
4344 | if (TREE_TYPE (type) != 0) | |
4345 | { | |
4346 | type = TREE_TYPE (type); | |
4347 | break; | |
4348 | } | |
4349 | ||
77a02b01 | 4350 | /* Carefully distinguish all the standard types of C, |
b0468b84 RK |
4351 | without messing up if the language is not C. We do this by |
4352 | testing TYPE_PRECISION and TREE_UNSIGNED. The old code used to | |
4353 | look at both the names and the above fields, but that's redundant. | |
4354 | Any type whose size is between two C types will be considered | |
4355 | to be the wider of the two types. Also, we do not have a | |
4356 | special code to use for "long long", so anything wider than | |
4357 | long is treated the same. Note that we can't distinguish | |
4358 | between "int" and "long" in this code if they are the same | |
4359 | size, but that's fine, since neither can the assembler. */ | |
4360 | ||
4361 | if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE) | |
4362 | return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2)); | |
77a02b01 | 4363 | |
b0468b84 RK |
4364 | else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE) |
4365 | return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3)); | |
77a02b01 | 4366 | |
b0468b84 | 4367 | else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE) |
77a02b01 JW |
4368 | return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4)); |
4369 | ||
b0468b84 | 4370 | else |
77a02b01 JW |
4371 | return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5)); |
4372 | ||
210aa14a | 4373 | case REAL_TYPE: |
77a02b01 JW |
4374 | /* Carefully distinguish all the standard types of C, |
4375 | without messing up if the language is not C. */ | |
b0468b84 | 4376 | |
77a02b01 | 4377 | if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) |
210aa14a | 4378 | return (qualifiers | 6); |
b0468b84 RK |
4379 | |
4380 | else | |
4381 | return (qualifiers | 7); | |
210aa14a RS |
4382 | |
4383 | case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */ | |
13d39dbc | 4384 | /* ??? We need to distinguish between double and float complex types, |
c82aa69a JW |
4385 | but I don't know how yet because I can't reach this code from |
4386 | existing front-ends. */ | |
4387 | return (qualifiers | 7); /* Who knows? */ | |
4388 | ||
210aa14a RS |
4389 | case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */ |
4390 | case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */ | |
4391 | case FILE_TYPE: /* GNU Pascal FILE type. */ | |
26902ae0 | 4392 | case SET_TYPE: /* GNU Pascal SET type. */ |
210aa14a | 4393 | case LANG_TYPE: /* ? */ |
26902ae0 | 4394 | return qualifiers; |
210aa14a RS |
4395 | |
4396 | default: | |
4397 | abort (); /* Not a type! */ | |
4398 | } | |
4399 | } | |
4400 | } | |
ead69aea | 4401 | \f |
61a55e8b DE |
4402 | /* Nested function support. */ |
4403 | ||
4404 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
4405 | FNADDR is an RTX for the address of the function's pure code. | |
4406 | CXT is an RTX for the static chain value for the function. | |
4407 | ||
4408 | This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi | |
4409 | (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes | |
4410 | (to store insns). This is a bit excessive. Perhaps a different | |
4411 | mechanism would be better here. | |
4412 | ||
849a528d | 4413 | Emit enough FLUSH insns to synchronize the data and instruction caches. */ |
61a55e8b DE |
4414 | |
4415 | void | |
4416 | sparc_initialize_trampoline (tramp, fnaddr, cxt) | |
4417 | rtx tramp, fnaddr, cxt; | |
4418 | { | |
4419 | rtx high_cxt = expand_shift (RSHIFT_EXPR, SImode, cxt, | |
4420 | size_int (10), 0, 1); | |
4421 | rtx high_fn = expand_shift (RSHIFT_EXPR, SImode, fnaddr, | |
4422 | size_int (10), 0, 1); | |
4423 | rtx low_cxt = expand_and (cxt, gen_rtx (CONST_INT, VOIDmode, 0x3ff), 0); | |
4424 | rtx low_fn = expand_and (fnaddr, gen_rtx (CONST_INT, VOIDmode, 0x3ff), 0); | |
4425 | rtx g1_sethi = gen_rtx (HIGH, SImode, | |
4426 | gen_rtx (CONST_INT, VOIDmode, 0x03000000)); | |
4427 | rtx g2_sethi = gen_rtx (HIGH, SImode, | |
4428 | gen_rtx (CONST_INT, VOIDmode, 0x05000000)); | |
4429 | rtx g1_ori = gen_rtx (HIGH, SImode, | |
4430 | gen_rtx (CONST_INT, VOIDmode, 0x82106000)); | |
4431 | rtx g2_ori = gen_rtx (HIGH, SImode, | |
4432 | gen_rtx (CONST_INT, VOIDmode, 0x8410A000)); | |
4433 | rtx tem = gen_reg_rtx (SImode); | |
4434 | emit_move_insn (tem, g1_sethi); | |
4435 | emit_insn (gen_iorsi3 (high_fn, high_fn, tem)); | |
4436 | emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 0)), high_fn); | |
4437 | emit_move_insn (tem, g1_ori); | |
4438 | emit_insn (gen_iorsi3 (low_fn, low_fn, tem)); | |
4439 | emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 4)), low_fn); | |
4440 | emit_move_insn (tem, g2_sethi); | |
4441 | emit_insn (gen_iorsi3 (high_cxt, high_cxt, tem)); | |
4442 | emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 8)), high_cxt); | |
4443 | emit_move_insn (tem, g2_ori); | |
4444 | emit_insn (gen_iorsi3 (low_cxt, low_cxt, tem)); | |
4445 | emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 16)), low_cxt); | |
d2889939 RK |
4446 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode, tramp)))); |
4447 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode, | |
4448 | plus_constant (tramp, 8))))); | |
4449 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode, | |
4450 | plus_constant (tramp, 16))))); | |
61a55e8b DE |
4451 | } |
4452 | ||
849a528d RK |
4453 | /* The 64 bit version is simpler because it makes more sense to load the |
4454 | values as "immediate" data out of the trampoline. It's also easier since | |
4455 | we can read the PC without clobbering a register. */ | |
4456 | ||
61a55e8b DE |
4457 | void |
4458 | sparc64_initialize_trampoline (tramp, fnaddr, cxt) | |
4459 | rtx tramp, fnaddr, cxt; | |
4460 | { | |
849a528d RK |
4461 | emit_move_insn (gen_rtx (MEM, DImode, plus_constant (tramp, 24)), cxt); |
4462 | emit_move_insn (gen_rtx (MEM, DImode, plus_constant (tramp, 32)), fnaddr); | |
38489316 DE |
4463 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, tramp)))); |
4464 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, | |
4465 | plus_constant (tramp, 8))))); | |
4466 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, | |
4467 | plus_constant (tramp, 16))))); | |
849a528d RK |
4468 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, |
4469 | plus_constant (tramp, 24))))); | |
4470 | emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, | |
4471 | plus_constant (tramp, 32))))); | |
61a55e8b DE |
4472 | } |
4473 | \f | |
c819be5b JW |
4474 | /* Subroutines to support a flat (single) register window calling |
4475 | convention. */ | |
4476 | ||
4477 | /* Single-register window sparc stack frames look like: | |
4478 | ||
4479 | Before call After call | |
4480 | +-----------------------+ +-----------------------+ | |
86735b02 DE |
4481 | high | | | | |
4482 | mem | caller's temps. | | caller's temps. | | |
c819be5b JW |
4483 | | | | | |
4484 | +-----------------------+ +-----------------------+ | |
4485 | | | | | | |
4486 | | arguments on stack. | | arguments on stack. | | |
86735b02 DE |
4487 | | | | | |
4488 | +-----------------------+FP+92->+-----------------------+ | |
c819be5b JW |
4489 | | 6 words to save | | 6 words to save | |
4490 | | arguments passed | | arguments passed | | |
4491 | | in registers, even | | in registers, even | | |
86735b02 DE |
4492 | | if not passed. | | if not passed. | |
4493 | SP+68->+-----------------------+FP+68->+-----------------------+ | |
4494 | | 1 word struct addr | | 1 word struct addr | | |
4495 | +-----------------------+FP+64->+-----------------------+ | |
4496 | | | | | | |
4497 | | 16 word reg save area | | 16 word reg save area | | |
4498 | | | | | | |
4499 | SP->+-----------------------+ FP->+-----------------------+ | |
4500 | | 4 word area for | | |
4501 | | fp/alu reg moves | | |
4502 | FP-16->+-----------------------+ | |
4503 | | | | |
4504 | | local variables | | |
4505 | | | | |
4506 | +-----------------------+ | |
4507 | | | | |
c819be5b | 4508 | | fp register save | |
86735b02 DE |
4509 | | | |
4510 | +-----------------------+ | |
4511 | | | | |
c819be5b JW |
4512 | | gp register save | |
4513 | | | | |
86735b02 DE |
4514 | +-----------------------+ |
4515 | | | | |
c819be5b | 4516 | | alloca allocations | |
86735b02 DE |
4517 | | | |
4518 | +-----------------------+ | |
4519 | | | | |
c819be5b | 4520 | | arguments on stack | |
86735b02 DE |
4521 | | | |
4522 | SP+92->+-----------------------+ | |
c819be5b | 4523 | | 6 words to save | |
86735b02 | 4524 | | arguments passed | |
c819be5b | 4525 | | in registers, even | |
86735b02 DE |
4526 | low | if not passed. | |
4527 | memory SP+68->+-----------------------+ | |
4528 | | 1 word struct addr | | |
4529 | SP+64->+-----------------------+ | |
4530 | | | | |
4531 | I 16 word reg save area | | |
4532 | | | | |
4533 | SP->+-----------------------+ */ | |
c819be5b | 4534 | |
c6aa9ce1 | 4535 | /* Structure to be filled in by sparc_flat_compute_frame_size with register |
c819be5b JW |
4536 | save masks, and offsets for the current function. */ |
4537 | ||
4538 | struct sparc_frame_info | |
4539 | { | |
4540 | unsigned long total_size; /* # bytes that the entire frame takes up. */ | |
4541 | unsigned long var_size; /* # bytes that variables take up. */ | |
4542 | unsigned long args_size; /* # bytes that outgoing arguments take up. */ | |
4543 | unsigned long extra_size; /* # bytes of extra gunk. */ | |
4544 | unsigned int gp_reg_size; /* # bytes needed to store gp regs. */ | |
4545 | unsigned int fp_reg_size; /* # bytes needed to store fp regs. */ | |
86735b02 | 4546 | unsigned long gmask; /* Mask of saved gp registers. */ |
c819be5b | 4547 | unsigned long fmask; /* Mask of saved fp registers. */ |
86735b02 | 4548 | unsigned long reg_offset; /* Offset from new sp to store regs. */ |
c819be5b JW |
4549 | int initialized; /* Nonzero if frame size already calculated. */ |
4550 | }; | |
4551 | ||
c6aa9ce1 | 4552 | /* Current frame information calculated by sparc_flat_compute_frame_size. */ |
c819be5b JW |
4553 | struct sparc_frame_info current_frame_info; |
4554 | ||
4555 | /* Zero structure to initialize current_frame_info. */ | |
4556 | struct sparc_frame_info zero_frame_info; | |
4557 | ||
4558 | /* Tell prologue and epilogue if register REGNO should be saved / restored. */ | |
4559 | ||
86735b02 DE |
4560 | #define RETURN_ADDR_REGNUM 15 |
4561 | #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM)) | |
4562 | #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM)) | |
4563 | ||
c819be5b JW |
4564 | #define MUST_SAVE_REGISTER(regno) \ |
4565 | ((regs_ever_live[regno] && !call_used_regs[regno]) \ | |
4566 | || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) \ | |
86735b02 | 4567 | || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM])) |
c819be5b JW |
4568 | |
4569 | /* Return the bytes needed to compute the frame pointer from the current | |
4570 | stack pointer. */ | |
4571 | ||
4572 | unsigned long | |
c6aa9ce1 | 4573 | sparc_flat_compute_frame_size (size) |
c819be5b JW |
4574 | int size; /* # of var. bytes allocated. */ |
4575 | { | |
4576 | int regno; | |
4577 | unsigned long total_size; /* # bytes that the entire frame takes up. */ | |
4578 | unsigned long var_size; /* # bytes that variables take up. */ | |
4579 | unsigned long args_size; /* # bytes that outgoing arguments take up. */ | |
4580 | unsigned long extra_size; /* # extra bytes. */ | |
4581 | unsigned int gp_reg_size; /* # bytes needed to store gp regs. */ | |
4582 | unsigned int fp_reg_size; /* # bytes needed to store fp regs. */ | |
86735b02 | 4583 | unsigned long gmask; /* Mask of saved gp registers. */ |
c819be5b | 4584 | unsigned long fmask; /* Mask of saved fp registers. */ |
86735b02 DE |
4585 | unsigned long reg_offset; /* Offset to register save area. */ |
4586 | int need_aligned_p; /* 1 if need the save area 8 byte aligned. */ | |
c819be5b JW |
4587 | |
4588 | /* This is the size of the 16 word reg save area, 1 word struct addr | |
4589 | area, and 4 word fp/alu register copy area. */ | |
4590 | extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0); | |
4591 | var_size = size; | |
4592 | /* Also include the size needed for the 6 parameter registers. */ | |
4593 | args_size = current_function_outgoing_args_size + 24; | |
4594 | total_size = var_size + args_size + extra_size; | |
4595 | gp_reg_size = 0; | |
4596 | fp_reg_size = 0; | |
86735b02 | 4597 | gmask = 0; |
c819be5b | 4598 | fmask = 0; |
86735b02 DE |
4599 | reg_offset = 0; |
4600 | need_aligned_p = 0; | |
c819be5b JW |
4601 | |
4602 | /* Calculate space needed for gp registers. */ | |
4603 | for (regno = 1; regno <= 31; regno++) | |
4604 | { | |
4605 | if (MUST_SAVE_REGISTER (regno)) | |
4606 | { | |
86735b02 DE |
4607 | /* If we need to save two regs in a row, ensure there's room to bump |
4608 | up the address to align it to a doubleword boundary. */ | |
c819be5b JW |
4609 | if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1)) |
4610 | { | |
4611 | if (gp_reg_size % 8 != 0) | |
86735b02 | 4612 | gp_reg_size += 4; |
c819be5b | 4613 | gp_reg_size += 2 * UNITS_PER_WORD; |
86735b02 | 4614 | gmask |= 3 << regno; |
c819be5b | 4615 | regno++; |
86735b02 | 4616 | need_aligned_p = 1; |
c819be5b JW |
4617 | } |
4618 | else | |
4619 | { | |
4620 | gp_reg_size += UNITS_PER_WORD; | |
86735b02 | 4621 | gmask |= 1 << regno; |
c819be5b JW |
4622 | } |
4623 | } | |
4624 | } | |
c819be5b JW |
4625 | |
4626 | /* Calculate space needed for fp registers. */ | |
4627 | for (regno = 32; regno <= 63; regno++) | |
4628 | { | |
4629 | if (regs_ever_live[regno] && !call_used_regs[regno]) | |
4630 | { | |
4631 | fp_reg_size += UNITS_PER_WORD; | |
4632 | fmask |= 1 << (regno - 32); | |
4633 | } | |
4634 | } | |
4635 | ||
86735b02 DE |
4636 | if (gmask || fmask) |
4637 | { | |
4638 | int n; | |
4639 | reg_offset = FIRST_PARM_OFFSET(0) + args_size; | |
4640 | /* Ensure save area is 8 byte aligned if we need it. */ | |
4641 | n = reg_offset % 8; | |
4642 | if (need_aligned_p && n != 0) | |
4643 | { | |
4644 | total_size += 8 - n; | |
4645 | reg_offset += 8 - n; | |
4646 | } | |
4647 | total_size += gp_reg_size + fp_reg_size; | |
4648 | } | |
c819be5b | 4649 | |
86735b02 | 4650 | /* ??? This looks a little suspicious. Clarify. */ |
c819be5b JW |
4651 | if (total_size == extra_size) |
4652 | total_size = extra_size = 0; | |
4653 | ||
4654 | total_size = SPARC_STACK_ALIGN (total_size); | |
4655 | ||
4656 | /* Save other computed information. */ | |
4657 | current_frame_info.total_size = total_size; | |
4658 | current_frame_info.var_size = var_size; | |
4659 | current_frame_info.args_size = args_size; | |
4660 | current_frame_info.extra_size = extra_size; | |
4661 | current_frame_info.gp_reg_size = gp_reg_size; | |
4662 | current_frame_info.fp_reg_size = fp_reg_size; | |
86735b02 | 4663 | current_frame_info.gmask = gmask; |
c819be5b | 4664 | current_frame_info.fmask = fmask; |
86735b02 | 4665 | current_frame_info.reg_offset = reg_offset; |
c819be5b JW |
4666 | current_frame_info.initialized = reload_completed; |
4667 | ||
c819be5b JW |
4668 | /* Ok, we're done. */ |
4669 | return total_size; | |
4670 | } | |
4671 | \f | |
86735b02 DE |
4672 | /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset |
4673 | OFFSET. | |
4674 | ||
4675 | BASE_REG must be 8 byte aligned. This allows us to test OFFSET for | |
4676 | appropriate alignment and use DOUBLEWORD_OP when we can. We assume | |
4677 | [BASE_REG+OFFSET] will always be a valid address. | |
4678 | ||
4679 | WORD_OP is either "st" for save, "ld" for restore. | |
4680 | DOUBLEWORD_OP is either "std" for save, "ldd" for restore. */ | |
c819be5b JW |
4681 | |
4682 | void | |
c53aa195 | 4683 | sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op, doubleword_op, base_offset) |
86735b02 DE |
4684 | FILE *file; |
4685 | char *base_reg; | |
4686 | unsigned int offset; | |
4687 | unsigned long gmask; | |
4688 | unsigned long fmask; | |
4689 | char *word_op; | |
4690 | char *doubleword_op; | |
c53aa195 | 4691 | unsigned long base_offset; |
c819be5b JW |
4692 | { |
4693 | int regno; | |
c819be5b | 4694 | |
86735b02 DE |
4695 | if (gmask == 0 && fmask == 0) |
4696 | return; | |
c819be5b | 4697 | |
86735b02 DE |
4698 | /* Save registers starting from high to low. We've already saved the |
4699 | previous frame pointer and previous return address for the debugger's | |
4700 | sake. The debugger allows us to not need a nop in the epilog if at least | |
4701 | one register is reloaded in addition to return address. */ | |
c819be5b | 4702 | |
86735b02 | 4703 | if (gmask) |
c819be5b JW |
4704 | { |
4705 | for (regno = 1; regno <= 31; regno++) | |
4706 | { | |
86735b02 | 4707 | if ((gmask & (1L << regno)) != 0) |
c819be5b | 4708 | { |
86735b02 | 4709 | if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0)) |
c819be5b | 4710 | { |
86735b02 DE |
4711 | /* We can save two registers in a row. If we're not at a |
4712 | double word boundary, move to one. | |
4713 | sparc_flat_compute_frame_size ensures there's room to do | |
4714 | this. */ | |
4715 | if (offset % 8 != 0) | |
4716 | offset += UNITS_PER_WORD; | |
4717 | ||
c819be5b | 4718 | if (word_op[0] == 's') |
c53aa195 JM |
4719 | { |
4720 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
4721 | doubleword_op, reg_names[regno], | |
4722 | base_reg, offset); | |
4723 | #ifdef DWARF2_DEBUGGING_INFO | |
4724 | if (write_symbols == DWARF2_DEBUG) | |
4725 | { | |
4726 | char *l = (char *) dwarf2out_cfi_label (); | |
4727 | dwarf2out_reg_save (l, regno, offset + base_offset); | |
4728 | dwarf2out_reg_save | |
4729 | (l, regno+1, offset+base_offset + UNITS_PER_WORD); | |
4730 | } | |
4731 | #endif | |
4732 | } | |
c819be5b JW |
4733 | else |
4734 | fprintf (file, "\t%s [%s+%d],%s\n", | |
86735b02 | 4735 | doubleword_op, base_reg, offset, |
c819be5b JW |
4736 | reg_names[regno]); |
4737 | ||
86735b02 | 4738 | offset += 2 * UNITS_PER_WORD; |
c819be5b JW |
4739 | regno++; |
4740 | } | |
4741 | else | |
4742 | { | |
4743 | if (word_op[0] == 's') | |
c53aa195 JM |
4744 | { |
4745 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
4746 | word_op, reg_names[regno], | |
4747 | base_reg, offset); | |
4748 | #ifdef DWARF2_DEBUGGING_INFO | |
4749 | if (write_symbols == DWARF2_DEBUG) | |
4750 | dwarf2out_reg_save ("", regno, offset + base_offset); | |
4751 | #endif | |
4752 | } | |
c819be5b JW |
4753 | else |
4754 | fprintf (file, "\t%s [%s+%d],%s\n", | |
86735b02 | 4755 | word_op, base_reg, offset, reg_names[regno]); |
c819be5b | 4756 | |
86735b02 | 4757 | offset += UNITS_PER_WORD; |
c819be5b JW |
4758 | } |
4759 | } | |
4760 | } | |
4761 | } | |
4762 | ||
4763 | if (fmask) | |
4764 | { | |
4765 | for (regno = 32; regno <= 63; regno++) | |
4766 | { | |
4767 | if ((fmask & (1L << (regno - 32))) != 0) | |
4768 | { | |
4769 | if (word_op[0] == 's') | |
c53aa195 JM |
4770 | { |
4771 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
4772 | word_op, reg_names[regno], | |
4773 | base_reg, offset); | |
4774 | #ifdef DWARF2_DEBUGGING_INFO | |
4775 | if (write_symbols == DWARF2_DEBUG) | |
4776 | dwarf2out_reg_save ("", regno, offset + base_offset); | |
4777 | #endif | |
4778 | } | |
c819be5b JW |
4779 | else |
4780 | fprintf (file, "\t%s [%s+%d],%s\n", | |
86735b02 | 4781 | word_op, base_reg, offset, reg_names[regno]); |
c819be5b | 4782 | |
86735b02 | 4783 | offset += UNITS_PER_WORD; |
c819be5b JW |
4784 | } |
4785 | } | |
4786 | } | |
4787 | } | |
4788 | \f | |
4789 | /* Set up the stack and frame (if desired) for the function. */ | |
4790 | ||
4791 | void | |
c6aa9ce1 | 4792 | sparc_flat_output_function_prologue (file, size) |
c819be5b JW |
4793 | FILE *file; |
4794 | int size; | |
4795 | { | |
c819be5b | 4796 | char *sp_str = reg_names[STACK_POINTER_REGNUM]; |
86735b02 | 4797 | unsigned long gmask = current_frame_info.gmask; |
a07c1915 | 4798 | |
c6aa9ce1 | 4799 | /* This is only for the human reader. */ |
c819be5b | 4800 | fprintf (file, "\t!#PROLOGUE# 0\n"); |
86735b02 DE |
4801 | fprintf (file, "\t!# vars= %d, regs= %d/%d, args= %d, extra= %d\n", |
4802 | current_frame_info.var_size, | |
4803 | current_frame_info.gp_reg_size / 4, | |
9f8b85b8 | 4804 | current_frame_info.fp_reg_size / 4, |
86735b02 DE |
4805 | current_function_outgoing_args_size, |
4806 | current_frame_info.extra_size); | |
c819be5b JW |
4807 | |
4808 | size = SPARC_STACK_ALIGN (size); | |
86735b02 DE |
4809 | size = (! current_frame_info.initialized |
4810 | ? sparc_flat_compute_frame_size (size) | |
4811 | : current_frame_info.total_size); | |
c819be5b | 4812 | |
86735b02 DE |
4813 | /* These cases shouldn't happen. Catch them now. */ |
4814 | if (size == 0 && (gmask || current_frame_info.fmask)) | |
4815 | abort (); | |
c819be5b | 4816 | |
86735b02 DE |
4817 | /* Allocate our stack frame by decrementing %sp. |
4818 | At present, the only algorithm gdb can use to determine if this is a | |
4819 | flat frame is if we always set %i7 if we set %sp. This can be optimized | |
4820 | in the future by putting in some sort of debugging information that says | |
4821 | this is a `flat' function. However, there is still the case of debugging | |
4822 | code without such debugging information (including cases where most fns | |
4823 | have such info, but there is one that doesn't). So, always do this now | |
4824 | so we don't get a lot of code out there that gdb can't handle. | |
4825 | If the frame pointer isn't needn't then that's ok - gdb won't be able to | |
4826 | distinguish us from a non-flat function but there won't (and shouldn't) | |
4827 | be any differences anyway. The return pc is saved (if necessary) right | |
4828 | after %i7 so gdb won't have to look too far to find it. */ | |
4829 | if (size > 0) | |
c819be5b | 4830 | { |
86735b02 | 4831 | unsigned int reg_offset = current_frame_info.reg_offset; |
c6aa9ce1 | 4832 | char *fp_str = reg_names[FRAME_POINTER_REGNUM]; |
86735b02 DE |
4833 | char *t1_str = "%g1"; |
4834 | ||
4835 | /* Things get a little tricky if local variables take up more than ~4096 | |
4836 | bytes and outgoing arguments take up more than ~4096 bytes. When that | |
4837 | happens, the register save area can't be accessed from either end of | |
4838 | the frame. Handle this by decrementing %sp to the start of the gp | |
4839 | register save area, save the regs, update %i7, and then set %sp to its | |
4840 | final value. Given that we only have one scratch register to play | |
4841 | with it is the cheapest solution, and it helps gdb out as it won't | |
4842 | slow down recognition of flat functions. | |
4843 | Don't change the order of insns emitted here without checking with | |
4844 | the gdb folk first. */ | |
4845 | ||
ddd5a7c1 | 4846 | /* Is the entire register save area offsettable from %sp? */ |
86735b02 DE |
4847 | if (reg_offset < 4096 - 64 * UNITS_PER_WORD) |
4848 | { | |
4849 | if (size <= 4096) | |
4850 | { | |
4851 | fprintf (file, "\tadd %s,%d,%s\n", | |
4852 | sp_str, -size, sp_str); | |
4853 | if (gmask & FRAME_POINTER_MASK) | |
4854 | { | |
4855 | fprintf (file, "\tst %s,[%s+%d]\n", | |
4856 | fp_str, sp_str, reg_offset); | |
4857 | fprintf (file, "\tsub %s,%d,%s\t!# set up frame pointer\n", | |
4858 | sp_str, -size, fp_str); | |
4859 | reg_offset += 4; | |
4860 | } | |
4861 | } | |
4862 | else | |
4863 | { | |
4864 | fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n", | |
4865 | size, t1_str, sp_str, t1_str, sp_str); | |
4866 | if (gmask & FRAME_POINTER_MASK) | |
4867 | { | |
4868 | fprintf (file, "\tst %s,[%s+%d]\n", | |
4869 | fp_str, sp_str, reg_offset); | |
4870 | fprintf (file, "\tadd %s,%s,%s\t!# set up frame pointer\n", | |
4871 | sp_str, t1_str, fp_str); | |
4872 | reg_offset += 4; | |
4873 | } | |
4874 | } | |
c53aa195 JM |
4875 | #ifdef DWARF2_DEBUGGING_INFO |
4876 | if (write_symbols == DWARF2_DEBUG) | |
4877 | { | |
4878 | char *l = (char *) dwarf2out_cfi_label (); | |
4879 | if (gmask & FRAME_POINTER_MASK) | |
4880 | { | |
4881 | dwarf2out_reg_save (l, FRAME_POINTER_REGNUM, | |
4882 | reg_offset - 4 - size); | |
4883 | dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0); | |
4884 | } | |
4885 | else | |
4886 | dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size); | |
4887 | } | |
4888 | #endif | |
86735b02 DE |
4889 | if (gmask & RETURN_ADDR_MASK) |
4890 | { | |
4891 | fprintf (file, "\tst %s,[%s+%d]\n", | |
4892 | reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset); | |
c53aa195 JM |
4893 | #ifdef DWARF2_DEBUGGING_INFO |
4894 | if (write_symbols == DWARF2_DEBUG) | |
4895 | dwarf2out_return_save ("", reg_offset - size); | |
4896 | #endif | |
86735b02 DE |
4897 | reg_offset += 4; |
4898 | } | |
4899 | sparc_flat_save_restore (file, sp_str, reg_offset, | |
4900 | gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK), | |
4901 | current_frame_info.fmask, | |
84e884e9 | 4902 | "st", "std", -size); |
86735b02 | 4903 | } |
c819be5b | 4904 | else |
86735b02 DE |
4905 | { |
4906 | /* Subtract %sp in two steps, but make sure there is always a | |
4907 | 64 byte register save area, and %sp is properly aligned. */ | |
4908 | /* Amount to decrement %sp by, the first time. */ | |
4909 | unsigned int size1 = ((size - reg_offset + 64) + 15) & -16; | |
4910 | /* Offset to register save area from %sp. */ | |
4911 | unsigned int offset = size1 - (size - reg_offset); | |
4912 | ||
4913 | if (size1 <= 4096) | |
4914 | { | |
4915 | fprintf (file, "\tadd %s,%d,%s\n", | |
4916 | sp_str, -size1, sp_str); | |
4917 | if (gmask & FRAME_POINTER_MASK) | |
4918 | { | |
4919 | fprintf (file, "\tst %s,[%s+%d]\n\tsub %s,%d,%s\t!# set up frame pointer\n", | |
4920 | fp_str, sp_str, offset, sp_str, -size1, fp_str); | |
4921 | offset += 4; | |
4922 | } | |
4923 | } | |
4924 | else | |
4925 | { | |
4926 | fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n", | |
4927 | size1, t1_str, sp_str, t1_str, sp_str); | |
4928 | if (gmask & FRAME_POINTER_MASK) | |
4929 | { | |
4930 | fprintf (file, "\tst %s,[%s+%d]\n\tadd %s,%s,%s\t!# set up frame pointer\n", | |
4931 | fp_str, sp_str, offset, sp_str, t1_str, fp_str); | |
4932 | offset += 4; | |
4933 | } | |
4934 | } | |
c53aa195 JM |
4935 | #ifdef DWARF2_DEBUGGING_INFO |
4936 | if (write_symbols == DWARF2_DEBUG) | |
4937 | { | |
4938 | char *l = (char *) dwarf2out_cfi_label (); | |
4939 | if (gmask & FRAME_POINTER_MASK) | |
4940 | { | |
4941 | dwarf2out_reg_save (l, FRAME_POINTER_REGNUM, | |
4942 | offset - 4 - size1); | |
4943 | dwarf2out_def_cfa (l, FRAME_POINTER_REGNUM, 0); | |
4944 | } | |
4945 | else | |
4946 | dwarf2out_def_cfa (l, STACK_POINTER_REGNUM, size1); | |
4947 | } | |
4948 | #endif | |
86735b02 DE |
4949 | if (gmask & RETURN_ADDR_MASK) |
4950 | { | |
4951 | fprintf (file, "\tst %s,[%s+%d]\n", | |
4952 | reg_names[RETURN_ADDR_REGNUM], sp_str, offset); | |
c53aa195 JM |
4953 | #ifdef DWARF2_DEBUGGING_INFO |
4954 | if (write_symbols == DWARF2_DEBUG) | |
4955 | /* offset - size1 == reg_offset - size | |
4956 | if reg_offset were updated above like offset. */ | |
4957 | dwarf2out_return_save ("", offset - size1); | |
4958 | #endif | |
86735b02 DE |
4959 | offset += 4; |
4960 | } | |
4961 | sparc_flat_save_restore (file, sp_str, offset, | |
4962 | gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK), | |
4963 | current_frame_info.fmask, | |
84e884e9 | 4964 | "st", "std", -size1); |
86735b02 DE |
4965 | fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n", |
4966 | size - size1, t1_str, sp_str, t1_str, sp_str); | |
c53aa195 JM |
4967 | #ifdef DWARF2_DEBUGGING_INFO |
4968 | if (write_symbols == DWARF2_DEBUG) | |
4969 | if (! (gmask & FRAME_POINTER_MASK)) | |
4970 | dwarf2out_def_cfa ("", STACK_POINTER_REGNUM, size); | |
4971 | #endif | |
86735b02 | 4972 | } |
c819be5b | 4973 | } |
c6aa9ce1 DE |
4974 | |
4975 | fprintf (file, "\t!#PROLOGUE# 1\n"); | |
c819be5b JW |
4976 | } |
4977 | \f | |
4978 | /* Do any necessary cleanup after a function to restore stack, frame, | |
4979 | and regs. */ | |
4980 | ||
4981 | void | |
c6aa9ce1 | 4982 | sparc_flat_output_function_epilogue (file, size) |
c819be5b JW |
4983 | FILE *file; |
4984 | int size; | |
4985 | { | |
c819be5b JW |
4986 | rtx epilogue_delay = current_function_epilogue_delay_list; |
4987 | int noepilogue = FALSE; | |
c819be5b | 4988 | |
c6aa9ce1 DE |
4989 | /* This is only for the human reader. */ |
4990 | fprintf (file, "\t!#EPILOGUE#\n"); | |
4991 | ||
c819be5b JW |
4992 | /* The epilogue does not depend on any registers, but the stack |
4993 | registers, so we assume that if we have 1 pending nop, it can be | |
4994 | ignored, and 2 it must be filled (2 nops occur for integer | |
4995 | multiply and divide). */ | |
4996 | ||
4997 | size = SPARC_STACK_ALIGN (size); | |
86735b02 | 4998 | size = (!current_frame_info.initialized |
c6aa9ce1 | 4999 | ? sparc_flat_compute_frame_size (size) |
c819be5b JW |
5000 | : current_frame_info.total_size); |
5001 | ||
86735b02 | 5002 | if (size == 0 && epilogue_delay == 0) |
c819be5b JW |
5003 | { |
5004 | rtx insn = get_last_insn (); | |
5005 | ||
5006 | /* If the last insn was a BARRIER, we don't have to write any code | |
5007 | because a jump (aka return) was put there. */ | |
5008 | if (GET_CODE (insn) == NOTE) | |
5009 | insn = prev_nonnote_insn (insn); | |
5010 | if (insn && GET_CODE (insn) == BARRIER) | |
5011 | noepilogue = TRUE; | |
5012 | } | |
5013 | ||
5014 | if (!noepilogue) | |
5015 | { | |
86735b02 DE |
5016 | unsigned int reg_offset = current_frame_info.reg_offset; |
5017 | unsigned int size1; | |
5018 | char *sp_str = reg_names[STACK_POINTER_REGNUM]; | |
5019 | char *fp_str = reg_names[FRAME_POINTER_REGNUM]; | |
5020 | char *t1_str = "%g1"; | |
5021 | ||
c819be5b JW |
5022 | /* In the reload sequence, we don't need to fill the load delay |
5023 | slots for most of the loads, also see if we can fill the final | |
5024 | delay slot if not otherwise filled by the reload sequence. */ | |
5025 | ||
86735b02 DE |
5026 | if (size > 4095) |
5027 | fprintf (file, "\tset %d,%s\n", size, t1_str); | |
c819be5b JW |
5028 | |
5029 | if (frame_pointer_needed) | |
5030 | { | |
86735b02 DE |
5031 | if (size > 4095) |
5032 | fprintf (file,"\tsub %s,%s,%s\t\t!# sp not trusted here\n", | |
c819be5b JW |
5033 | fp_str, t1_str, sp_str); |
5034 | else | |
86735b02 DE |
5035 | fprintf (file,"\tsub %s,%d,%s\t\t!# sp not trusted here\n", |
5036 | fp_str, size, sp_str); | |
c819be5b JW |
5037 | } |
5038 | ||
ddd5a7c1 | 5039 | /* Is the entire register save area offsettable from %sp? */ |
86735b02 DE |
5040 | if (reg_offset < 4096 - 64 * UNITS_PER_WORD) |
5041 | { | |
5042 | size1 = 0; | |
5043 | } | |
5044 | else | |
5045 | { | |
5046 | /* Restore %sp in two steps, but make sure there is always a | |
5047 | 64 byte register save area, and %sp is properly aligned. */ | |
5048 | /* Amount to increment %sp by, the first time. */ | |
5049 | size1 = ((reg_offset - 64 - 16) + 15) & -16; | |
5050 | /* Offset to register save area from %sp. */ | |
5051 | reg_offset = size1 - reg_offset; | |
5052 | ||
5053 | fprintf (file, "\tset %d,%s\n\tadd %s,%s,%s\n", | |
5054 | size1, t1_str, sp_str, t1_str, sp_str); | |
5055 | } | |
5056 | ||
5057 | /* We must restore the frame pointer and return address reg first | |
5058 | because they are treated specially by the prologue output code. */ | |
5059 | if (current_frame_info.gmask & FRAME_POINTER_MASK) | |
5060 | { | |
5061 | fprintf (file, "\tld [%s+%d],%s\n", | |
5062 | sp_str, reg_offset, fp_str); | |
5063 | reg_offset += 4; | |
5064 | } | |
5065 | if (current_frame_info.gmask & RETURN_ADDR_MASK) | |
5066 | { | |
5067 | fprintf (file, "\tld [%s+%d],%s\n", | |
5068 | sp_str, reg_offset, reg_names[RETURN_ADDR_REGNUM]); | |
5069 | reg_offset += 4; | |
5070 | } | |
5071 | ||
5072 | /* Restore any remaining saved registers. */ | |
5073 | sparc_flat_save_restore (file, sp_str, reg_offset, | |
5074 | current_frame_info.gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK), | |
5075 | current_frame_info.fmask, | |
c53aa195 | 5076 | "ld", "ldd", 0); |
86735b02 DE |
5077 | |
5078 | /* If we had to increment %sp in two steps, record it so the second | |
5079 | restoration in the epilogue finishes up. */ | |
5080 | if (size1 > 0) | |
5081 | { | |
5082 | size -= size1; | |
5083 | if (size > 4095) | |
5084 | fprintf (file, "\tset %d,%s\n", | |
5085 | size, t1_str); | |
5086 | } | |
c819be5b | 5087 | |
c819be5b JW |
5088 | if (current_function_returns_struct) |
5089 | fprintf (file, "\tjmp %%o7+12\n"); | |
5090 | else | |
5091 | fprintf (file, "\tretl\n"); | |
5092 | ||
5093 | /* If the only register saved is the return address, we need a | |
5094 | nop, unless we have an instruction to put into it. Otherwise | |
5095 | we don't since reloading multiple registers doesn't reference | |
5096 | the register being loaded. */ | |
5097 | ||
5098 | if (epilogue_delay) | |
5099 | { | |
86735b02 | 5100 | if (size) |
c819be5b JW |
5101 | abort (); |
5102 | final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1); | |
5103 | } | |
5104 | ||
86735b02 | 5105 | else if (size > 4095) |
c819be5b JW |
5106 | fprintf (file, "\tadd %s,%s,%s\n", sp_str, t1_str, sp_str); |
5107 | ||
86735b02 DE |
5108 | else if (size > 0) |
5109 | fprintf (file, "\tadd %s,%d,%s\n", sp_str, size, sp_str); | |
c819be5b JW |
5110 | |
5111 | else | |
5112 | fprintf (file, "\tnop\n"); | |
5113 | } | |
5114 | ||
5115 | /* Reset state info for each function. */ | |
5116 | current_frame_info = zero_frame_info; | |
5117 | } | |
5118 | \f | |
5119 | /* Define the number of delay slots needed for the function epilogue. | |
5120 | ||
5121 | On the sparc, we need a slot if either no stack has been allocated, | |
5122 | or the only register saved is the return register. */ | |
5123 | ||
5124 | int | |
c6aa9ce1 | 5125 | sparc_flat_epilogue_delay_slots () |
c819be5b JW |
5126 | { |
5127 | if (!current_frame_info.initialized) | |
c6aa9ce1 | 5128 | (void) sparc_flat_compute_frame_size (get_frame_size ()); |
c819be5b JW |
5129 | |
5130 | if (current_frame_info.total_size == 0) | |
5131 | return 1; | |
5132 | ||
c819be5b JW |
5133 | return 0; |
5134 | } | |
5135 | ||
5136 | /* Return true is TRIAL is a valid insn for the epilogue delay slot. | |
5137 | Any single length instruction which doesn't reference the stack or frame | |
5138 | pointer is OK. */ | |
5139 | ||
5140 | int | |
c6aa9ce1 | 5141 | sparc_flat_eligible_for_epilogue_delay (trial, slot) |
c819be5b JW |
5142 | rtx trial; |
5143 | int slot; | |
5144 | { | |
c4ce6853 DE |
5145 | rtx pat = PATTERN (trial); |
5146 | ||
5147 | if (get_attr_length (trial) != 1) | |
5148 | return 0; | |
5149 | ||
5150 | /* If %g0 is live, there are lots of things we can't handle. | |
5151 | Rather than trying to find them all now, let's punt and only | |
5152 | optimize things as necessary. */ | |
5153 | if (TARGET_LIVE_G0) | |
5154 | return 0; | |
5155 | ||
5156 | if (! reg_mentioned_p (stack_pointer_rtx, pat) | |
5157 | && ! reg_mentioned_p (frame_pointer_rtx, pat)) | |
c819be5b | 5158 | return 1; |
c4ce6853 | 5159 | |
c819be5b JW |
5160 | return 0; |
5161 | } | |
dbb54862 JW |
5162 | \f |
5163 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
5164 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
5165 | ||
5166 | int | |
5167 | supersparc_adjust_cost (insn, link, dep_insn, cost) | |
5168 | rtx insn; | |
5169 | rtx link; | |
5170 | rtx dep_insn; | |
5171 | int cost; | |
5172 | { | |
5173 | enum attr_type insn_type; | |
5174 | ||
5175 | if (! recog_memoized (insn)) | |
5176 | return 0; | |
5177 | ||
5178 | insn_type = get_attr_type (insn); | |
5179 | ||
5180 | if (REG_NOTE_KIND (link) == 0) | |
5181 | { | |
5182 | /* Data dependency; DEP_INSN writes a register that INSN reads some | |
5183 | cycles later. */ | |
5184 | ||
5185 | /* if a load, then the dependence must be on the memory address; | |
5186 | add an extra 'cycle'. Note that the cost could be two cycles | |
5187 | if the reg was written late in an instruction group; we can't tell | |
5188 | here. */ | |
5189 | if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD) | |
5190 | return cost + 3; | |
5191 | ||
5192 | /* Get the delay only if the address of the store is the dependence. */ | |
5193 | if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE) | |
5194 | { | |
5195 | rtx pat = PATTERN(insn); | |
5196 | rtx dep_pat = PATTERN (dep_insn); | |
5197 | ||
5198 | if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET) | |
5199 | return cost; /* This shouldn't happen! */ | |
5200 | ||
5201 | /* The dependency between the two instructions was on the data that | |
5202 | is being stored. Assume that this implies that the address of the | |
5203 | store is not dependent. */ | |
5204 | if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat))) | |
5205 | return cost; | |
5206 | ||
5207 | return cost + 3; /* An approximation. */ | |
5208 | } | |
5209 | ||
5210 | /* A shift instruction cannot receive its data from an instruction | |
5211 | in the same cycle; add a one cycle penalty. */ | |
5212 | if (insn_type == TYPE_SHIFT) | |
5213 | return cost + 3; /* Split before cascade into shift. */ | |
5214 | } | |
5215 | else | |
5216 | { | |
5217 | /* Anti- or output- dependency; DEP_INSN reads/writes a register that | |
5218 | INSN writes some cycles later. */ | |
5219 | ||
5220 | /* These are only significant for the fpu unit; writing a fp reg before | |
5221 | the fpu has finished with it stalls the processor. */ | |
5222 | ||
5223 | /* Reusing an integer register causes no problems. */ | |
5224 | if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT) | |
5225 | return 0; | |
5226 | } | |
5227 | ||
5228 | return cost; | |
5229 | } |