]>
Commit | Line | Data |
---|---|---|
68cbb7e3 | 1 | /* Definitions of target machine for GNU compiler, for MMIX. |
2 | Copyright (C) 2000, 2001 Free Software Foundation, Inc. | |
3 | Contributed by Hans-Peter Nilsson (hp@bitrange.com) | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "rtl.h" | |
25 | #include "regs.h" | |
26 | #include "hard-reg-set.h" | |
27 | #include "hashtab.h" | |
28 | #include "insn-config.h" | |
29 | #include "output.h" | |
30 | #include "flags.h" | |
31 | #include "tree.h" | |
32 | #include "function.h" | |
33 | #include "expr.h" | |
34 | #include "toplev.h" | |
35 | #include "recog.h" | |
36 | #include "ggc.h" | |
37 | #include "dwarf2.h" | |
38 | #include "debug.h" | |
39 | #include "tm_p.h" | |
40 | #include "integrate.h" | |
41 | #include "target.h" | |
42 | #include "target-def.h" | |
43 | ||
44 | /* First some local helper definitions. */ | |
45 | #define MMIX_FIRST_GLOBAL_REGNUM 32 | |
46 | ||
47 | /* We'd need a current_function_has_landing_pad. It's marked as such when | |
48 | a nonlocal_goto_receiver is expanded. Not just a C++ thing, but | |
49 | mostly. */ | |
50 | #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0) | |
51 | ||
52 | /* We have no means to tell DWARF 2 about the register stack, so we need | |
53 | to store the return address on the stack if an exception can get into | |
54 | this function. FIXME: Narrow condition. */ | |
55 | #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \ | |
56 | (flag_exceptions && ! leaf_function_p ()) | |
57 | ||
58 | #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \ | |
59 | (current_function_calls_eh_return \ | |
60 | && (EH_RETURN_DATA_REGNO (0) == REGNO \ | |
61 | || EH_RETURN_DATA_REGNO (1) == REGNO \ | |
62 | || EH_RETURN_DATA_REGNO (2) == REGNO \ | |
63 | || EH_RETURN_DATA_REGNO (3) == REGNO)) | |
64 | ||
65 | /* The canonical saved comparison operands for non-cc0 machines, set in | |
66 | the compare expander. */ | |
67 | rtx mmix_compare_op0; | |
68 | rtx mmix_compare_op1; | |
69 | ||
70 | /* We ignore some options with arguments. They are passed to the linker, | |
71 | but also ends up here because they start with "-m". We tell the driver | |
72 | to store them in a variable we don't inspect. */ | |
25037517 | 73 | const char *mmix_cc1_ignored_option; |
68cbb7e3 | 74 | |
75 | /* Declarations of locals. */ | |
76 | ||
77 | /* This is used in the prologue for what number to pass in a PUSHJ or | |
78 | PUSHGO insn. */ | |
79 | static int mmix_highest_saved_stack_register; | |
80 | ||
81 | /* Intermediate for insn output. */ | |
82 | static int mmix_output_destination_register; | |
83 | ||
84 | static void mmix_output_shiftvalue_op_from_str | |
85 | PARAMS ((FILE *, const char *, HOST_WIDEST_INT)); | |
86 | static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT)); | |
87 | static void mmix_output_condition PARAMS ((FILE *, rtx, int)); | |
88 | static HOST_WIDEST_INT mmix_intval PARAMS ((rtx)); | |
89 | static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int)); | |
90 | static void mmix_init_machine_status PARAMS ((struct function *)); | |
91 | ||
92 | extern void mmix_target_asm_function_prologue | |
93 | PARAMS ((FILE *, HOST_WIDE_INT)); | |
94 | extern void mmix_target_asm_function_epilogue | |
95 | PARAMS ((FILE *, HOST_WIDE_INT)); | |
96 | ||
97 | ||
98 | /* Target structure macros. Listed by node. See `Using and Porting GCC' | |
99 | for a general description. */ | |
100 | ||
101 | /* Node: Function Entry */ | |
102 | ||
103 | #undef TARGET_ASM_FUNCTION_PROLOGUE | |
104 | #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue | |
105 | ||
106 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
107 | #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue | |
108 | ||
109 | struct gcc_target targetm = TARGET_INITIALIZER; | |
110 | ||
111 | /* Functions that are expansions for target macros. | |
112 | See Target Macros in `Using and Porting GCC'. */ | |
113 | ||
114 | /* OVERRIDE_OPTIONS. */ | |
115 | ||
116 | void | |
117 | mmix_override_options () | |
118 | { | |
119 | /* Should we err or should we warn? Hmm. At least we must neutralize | |
120 | it. For example the wrong kind of case-tables will be generated with | |
121 | PIC; we use absolute address items for mmixal compatibility. FIXME: | |
122 | They could be relative if we just elide them to after all pertinent | |
123 | labels. */ | |
124 | if (flag_pic) | |
125 | { | |
126 | warning ("-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic"); | |
127 | flag_pic = 0; | |
128 | } | |
129 | ||
130 | /* All other targets add GC roots from their override_options function, | |
131 | so play along. */ | |
132 | ggc_add_rtx_root (&mmix_compare_op0, 1); | |
133 | ggc_add_rtx_root (&mmix_compare_op1, 1); | |
134 | } | |
135 | ||
136 | /* INIT_EXPANDERS. */ | |
137 | ||
138 | void | |
139 | mmix_init_expanders () | |
140 | { | |
141 | init_machine_status = mmix_init_machine_status; | |
142 | } | |
143 | ||
144 | /* Set the per-function data. */ | |
145 | ||
25037517 | 146 | static void |
68cbb7e3 | 147 | mmix_init_machine_status (f) |
148 | struct function *f; | |
149 | { | |
150 | f->machine = xcalloc (1, sizeof (struct machine_function)); | |
151 | } | |
152 | ||
153 | /* DATA_ALIGNMENT. | |
154 | We have trouble getting the address of stuff that is located at other | |
155 | than 32-bit alignments (GETA requirements), so try to give everything | |
156 | at least 32-bit alignment. */ | |
157 | ||
158 | int | |
159 | mmix_data_alignment (type, basic_align) | |
160 | tree type ATTRIBUTE_UNUSED; | |
161 | int basic_align; | |
162 | { | |
163 | if (basic_align < 32) | |
164 | return 32; | |
165 | ||
166 | return basic_align; | |
167 | } | |
168 | ||
169 | /* CONSTANT_ALIGNMENT. */ | |
170 | ||
171 | int | |
172 | mmix_constant_alignment (constant, basic_align) | |
173 | tree constant ATTRIBUTE_UNUSED; | |
174 | int basic_align; | |
175 | { | |
176 | if (basic_align < 32) | |
177 | return 32; | |
178 | ||
179 | return basic_align; | |
180 | } | |
181 | ||
182 | /* LOCAL_ALIGNMENT. */ | |
183 | ||
184 | int | |
185 | mmix_local_alignment (type, basic_align) | |
186 | tree type ATTRIBUTE_UNUSED; | |
187 | int basic_align; | |
188 | { | |
189 | if (basic_align < 32) | |
190 | return 32; | |
191 | ||
192 | return basic_align; | |
193 | } | |
194 | ||
195 | /* CONDITIONAL_REGISTER_USAGE. */ | |
196 | ||
197 | void | |
198 | mmix_conditional_register_usage () | |
199 | { | |
200 | int i; | |
201 | ||
202 | if (TARGET_ABI_GNU) | |
203 | { | |
204 | static const int gnu_abi_reg_alloc_order[] | |
205 | = MMIX_GNU_ABI_REG_ALLOC_ORDER; | |
206 | ||
207 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
208 | reg_alloc_order[i] = gnu_abi_reg_alloc_order[i]; | |
209 | ||
210 | /* Change the default from the mmixware ABI. For the GNU ABI, | |
211 | $15..$30 are call-saved just as $0..$14. There must be one | |
212 | call-clobbered local register for the "hole" describing number of | |
213 | saved local registers saved by PUSHJ/PUSHGO during the function | |
214 | call, receiving the return value at return. So best is to use | |
215 | the highest, $31. It's already marked call-clobbered for the | |
216 | mmixware ABI. */ | |
217 | for (i = 15; i <= 30; i++) | |
218 | call_used_regs[i] = 0; | |
219 | } | |
220 | ||
221 | /* Step over the ":" in special register names. */ | |
222 | if (! TARGET_TOPLEVEL_SYMBOLS) | |
223 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
224 | if (reg_names[i][0] == ':') | |
225 | reg_names[i]++; | |
226 | } | |
227 | ||
228 | /* PREFERRED_RELOAD_CLASS. | |
229 | We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */ | |
230 | ||
231 | enum reg_class | |
232 | mmix_preferred_reload_class (x, class) | |
233 | rtx x ATTRIBUTE_UNUSED; | |
234 | enum reg_class class; | |
235 | { | |
236 | /* FIXME: Revisit. */ | |
237 | return GET_CODE (x) == MOD && GET_MODE (x) == DImode | |
238 | ? REMAINDER_REG : class; | |
239 | } | |
240 | ||
241 | /* PREFERRED_OUTPUT_RELOAD_CLASS. | |
242 | We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */ | |
243 | ||
244 | enum reg_class | |
245 | mmix_preferred_output_reload_class (x, class) | |
246 | rtx x ATTRIBUTE_UNUSED; | |
247 | enum reg_class class; | |
248 | { | |
249 | /* FIXME: Revisit. */ | |
250 | return GET_CODE (x) == MOD && GET_MODE (x) == DImode | |
251 | ? REMAINDER_REG : class; | |
252 | } | |
253 | ||
254 | /* SECONDARY_RELOAD_CLASS. | |
255 | We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */ | |
256 | ||
257 | enum reg_class | |
258 | mmix_secondary_reload_class (class, mode, x, in_p) | |
259 | enum reg_class class; | |
260 | enum machine_mode mode; | |
261 | rtx x; | |
262 | int in_p; | |
263 | { | |
264 | if (class == REMAINDER_REG | |
265 | || class == HIMULT_REG | |
266 | || class == SYSTEM_REGS) | |
267 | return GENERAL_REGS; | |
268 | ||
269 | if (mode != DImode || in_p) | |
270 | return NO_REGS; | |
271 | ||
272 | /* We have to help reload. */ | |
273 | if (mode == DImode && GET_CODE (x) == MEM | |
274 | && ! address_operand (XEXP (x, 0), GET_MODE (x))) | |
275 | return GENERAL_REGS; | |
276 | ||
277 | /* FIXME: Optimize this; there are lots of PLUS:es that don't need a | |
278 | reload register. */ | |
279 | if (GET_CODE (x) == PLUS) | |
280 | return GENERAL_REGS; | |
281 | ||
282 | return NO_REGS; | |
283 | } | |
284 | ||
285 | /* CONST_OK_FOR_LETTER_P. */ | |
286 | ||
287 | int | |
288 | mmix_const_ok_for_letter_p (value, c) | |
289 | HOST_WIDE_INT value; | |
290 | int c; | |
291 | { | |
292 | return | |
293 | (c == 'I' ? value >= 0 && value <= 255 | |
294 | : c == 'J' ? value >= 0 && value <= 65535 | |
295 | : c == 'K' ? value <= 0 && value >= -255 | |
296 | : c == 'L' ? mmix_shiftable_wyde_value (value) | |
297 | : c == 'M' ? value == 0 | |
298 | : c == 'N' ? mmix_shiftable_wyde_value (~value) | |
299 | : c == 'O' ? (value == 3 || value == 5 || value == 9 | |
300 | || value == 17) | |
301 | : 0); | |
302 | } | |
303 | ||
304 | /* CONST_DOUBLE_OK_FOR_LETTER_P. */ | |
305 | ||
306 | int | |
307 | mmix_const_double_ok_for_letter_p (value, c) | |
308 | rtx value; | |
309 | int c; | |
310 | { | |
311 | return | |
312 | (c == 'G' ? value == CONST0_RTX (GET_MODE (value)) | |
313 | : 0); | |
314 | } | |
315 | ||
316 | /* EXTRA_CONSTRAINT. | |
317 | We need this since our constants are not always expressible as | |
318 | CONST_INT:s, but rather often as CONST_DOUBLE:s. */ | |
319 | ||
320 | int | |
321 | mmix_extra_constraint (x, c) | |
322 | rtx x; | |
323 | int c; | |
324 | { | |
325 | HOST_WIDEST_INT value; | |
326 | ||
327 | if (c == 'U') | |
328 | return address_operand (x, Pmode); | |
329 | ||
330 | if (GET_CODE (x) != CONST_DOUBLE || GET_MODE (x) != VOIDmode) | |
331 | return 0; | |
332 | ||
333 | value = mmix_intval (x); | |
334 | ||
335 | /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any | |
336 | more ('U' taken for address_operand). Some letters map outside of | |
337 | CONST_INT, though; we still use 'S' and 'T'. */ | |
338 | if (c == 'S') | |
339 | return mmix_shiftable_wyde_value (value); | |
340 | else if (c == 'T') | |
341 | return mmix_shiftable_wyde_value (~value); | |
342 | return 0; | |
343 | } | |
344 | ||
345 | /* DYNAMIC_CHAIN_ADDRESS. */ | |
346 | ||
347 | rtx | |
348 | mmix_dynamic_chain_address (frame) | |
349 | rtx frame; | |
350 | { | |
351 | /* FIXME: the frame-pointer is stored at offset -8 from the current | |
352 | frame-pointer. Unfortunately, the caller assumes that a | |
353 | frame-pointer is present for *all* previous frames. There should be | |
354 | a way to say that that cannot be done, like for RETURN_ADDR_RTX. */ | |
355 | return plus_constant (frame, -8); | |
356 | } | |
357 | ||
358 | /* STARTING_FRAME_OFFSET. */ | |
359 | ||
360 | int | |
361 | mmix_starting_frame_offset () | |
362 | { | |
363 | /* The old frame pointer is in the slot below the new one, so | |
364 | FIRST_PARM_OFFSET does not need to depend on whether the | |
365 | frame-pointer is needed or not. We have to adjust for the register | |
366 | stack pointer being located below the saved frame pointer. | |
367 | Similarly, we store the return address on the stack too, for | |
368 | exception handling, and always if we save the register stack pointer. */ | |
369 | return | |
370 | (-8 | |
371 | + (MMIX_CFUN_HAS_LANDING_PAD | |
372 | ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0))); | |
373 | } | |
374 | ||
375 | /* RETURN_ADDR_RTX. */ | |
376 | ||
377 | rtx | |
378 | mmix_return_addr_rtx (count, frame) | |
379 | int count; | |
380 | rtx frame ATTRIBUTE_UNUSED; | |
381 | { | |
382 | return count == 0 | |
383 | ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS | |
384 | /* FIXME: Set frame_alias_set on the following. */ | |
385 | ? validize_mem (gen_rtx_MEM (Pmode, plus_constant (frame_pointer_rtx, -16))) | |
386 | : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM)) | |
387 | : NULL_RTX; | |
388 | } | |
389 | ||
390 | /* SETUP_FRAME_ADDRESSES. */ | |
391 | ||
392 | void | |
393 | mmix_setup_frame_addresses () | |
394 | { | |
395 | /* Nothing needed at the moment. */ | |
396 | } | |
397 | ||
398 | /* The difference between the (imaginary) frame pointer and the stack | |
399 | pointer. Used to eliminate the frame pointer. */ | |
400 | ||
401 | int | |
402 | mmix_initial_elimination_offset (fromreg, toreg) | |
403 | int fromreg; | |
404 | int toreg; | |
405 | { | |
406 | int regno; | |
407 | int fp_sp_offset | |
408 | = (get_frame_size () + current_function_outgoing_args_size + 7) & ~7; | |
409 | ||
410 | /* There is no actual difference between these two. */ | |
411 | if (fromreg == MMIX_ARG_POINTER_REGNUM | |
412 | && toreg == MMIX_FRAME_POINTER_REGNUM) | |
413 | return 0; | |
414 | ||
415 | /* The difference is the size of local variables plus the size of | |
416 | outgoing function arguments that would normally be passed as | |
417 | registers but must be passed on stack because we're out of | |
418 | function-argument registers. Only global saved registers are | |
419 | counted; the others go on the register stack. | |
420 | ||
421 | The frame-pointer is counted too if it is what is eliminated, as we | |
422 | need to balance the offset for it from STARTING_FRAME_OFFSET. | |
423 | ||
424 | Also add in the slot for the register stack pointer we save if we | |
425 | have a landing pad. | |
426 | ||
427 | Unfortunately, we can't access $0..$14, from unwinder code easily, so | |
428 | store the return address in a frame slot too. FIXME: Only for | |
429 | non-leaf functions. FIXME: Always with a landing pad, because it's | |
430 | hard to know whether we need the other at the time we know we need | |
431 | the offset for one (and have to state it). It's a kludge until we | |
432 | can express the register stack in the EH frame info. | |
433 | ||
434 | We have to do alignment here; get_frame_size will not return a | |
435 | multiple of STACK_BOUNDARY. FIXME: Add note in manual. */ | |
436 | ||
437 | for (regno = MMIX_FIRST_GLOBAL_REGNUM; | |
438 | regno <= 255; | |
439 | regno++) | |
440 | if ((regs_ever_live[regno] && ! call_used_regs[regno]) | |
441 | || IS_MMIX_EH_RETURN_DATA_REG (regno)) | |
442 | fp_sp_offset += 8; | |
443 | ||
444 | return fp_sp_offset | |
445 | + (MMIX_CFUN_HAS_LANDING_PAD | |
446 | ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0)) | |
447 | + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8); | |
448 | } | |
449 | ||
450 | /* Return an rtx for a function argument to go in a register, and 0 for | |
451 | one that must go on stack. */ | |
452 | ||
453 | rtx | |
454 | mmix_function_arg (argsp, mode, type, named, incoming) | |
455 | const CUMULATIVE_ARGS * argsp; | |
456 | enum machine_mode mode; | |
457 | tree type; | |
458 | int named ATTRIBUTE_UNUSED; | |
459 | int incoming; | |
460 | { | |
461 | /* Handling of the positional dummy parameter for varargs gets nasty. | |
462 | Check execute/991216-3 and function.c:assign_params. We have to say | |
463 | that the dummy parameter goes on stack in order to get the correct | |
464 | offset when va_start and va_arg is applied. FIXME: Should do TRT by | |
465 | itself in the gcc core. */ | |
466 | if ((! named && incoming && current_function_varargs) || argsp->now_varargs) | |
467 | return NULL_RTX; | |
468 | ||
469 | /* Last-argument marker. */ | |
470 | if (type == void_type_node) | |
471 | return (argsp->regs < MMIX_MAX_ARGS_IN_REGS) | |
472 | ? gen_rtx_REG (mode, | |
473 | (incoming | |
474 | ? MMIX_FIRST_INCOMING_ARG_REGNUM | |
475 | : MMIX_FIRST_ARG_REGNUM) + argsp->regs) | |
476 | : NULL_RTX; | |
477 | ||
478 | return (argsp->regs < MMIX_MAX_ARGS_IN_REGS | |
479 | && !MUST_PASS_IN_STACK (mode, type) | |
480 | && (GET_MODE_BITSIZE (mode) <= 64 | |
481 | || argsp->lib | |
482 | || TARGET_LIBFUNC)) | |
483 | ? gen_rtx_REG (mode, | |
484 | (incoming | |
485 | ? MMIX_FIRST_INCOMING_ARG_REGNUM | |
486 | : MMIX_FIRST_ARG_REGNUM) | |
487 | + argsp->regs) | |
488 | : NULL_RTX; | |
489 | } | |
490 | ||
491 | /* Returns nonzero for everything that goes by reference, 0 for | |
492 | everything that goes by value. */ | |
493 | ||
494 | int | |
495 | mmix_function_arg_pass_by_reference (argsp, mode, type, named) | |
496 | const CUMULATIVE_ARGS * argsp; | |
497 | enum machine_mode mode; | |
498 | tree type; | |
499 | int named ATTRIBUTE_UNUSED; | |
500 | { | |
501 | /* FIXME: Check: I'm not sure the MUST_PASS_IN_STACK check is | |
502 | necessary. */ | |
503 | return | |
504 | MUST_PASS_IN_STACK (mode, type) | |
505 | || (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8 | |
506 | && !TARGET_LIBFUNC | |
507 | && !argsp->lib); | |
508 | } | |
509 | ||
510 | /* Return nonzero if regno is a register number where a parameter is | |
511 | passed, and 0 otherwise. */ | |
512 | ||
513 | int | |
514 | mmix_function_arg_regno_p (regno, incoming) | |
515 | int regno; | |
516 | int incoming; | |
517 | { | |
518 | int first_arg_regnum | |
519 | = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM; | |
520 | ||
521 | return regno >= first_arg_regnum | |
522 | && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS; | |
523 | } | |
524 | ||
525 | /* FUNCTION_OUTGOING_VALUE. */ | |
526 | ||
527 | rtx | |
528 | mmix_function_outgoing_value (valtype, func) | |
529 | tree valtype; | |
530 | tree func ATTRIBUTE_UNUSED; | |
531 | { | |
532 | enum machine_mode mode = TYPE_MODE (valtype); | |
68cbb7e3 | 533 | enum machine_mode cmode; |
534 | int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM; | |
535 | rtx vec[MMIX_MAX_REGS_FOR_VALUE]; | |
536 | int i; | |
537 | int nregs; | |
538 | ||
539 | /* Return values that fit in a register need no special handling. | |
540 | There's no register hole when parameters are passed in global | |
541 | registers. */ | |
542 | if (TARGET_ABI_GNU | |
543 | || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD) | |
544 | return | |
545 | gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM); | |
546 | ||
547 | /* A complex type, made up of components. */ | |
548 | cmode = TYPE_MODE (TREE_TYPE (valtype)); | |
549 | nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD); | |
550 | ||
551 | /* We need to take care of the effect of the register hole on return | |
552 | values of large sizes; the last register will appear as the first | |
553 | register, with the rest shifted. (For complex modes, this is just | |
554 | swapped registers.) */ | |
555 | ||
556 | if (nregs > MMIX_MAX_REGS_FOR_VALUE) | |
557 | internal_error ("Too large function value type, needs %d registers,\ | |
558 | have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE); | |
559 | ||
560 | /* FIXME: Maybe we should handle structure values like this too | |
561 | (adjusted for BLKmode), perhaps for both ABI:s. */ | |
562 | for (i = 0; i < nregs - 1; i++) | |
563 | vec[i] | |
564 | = gen_rtx_EXPR_LIST (VOIDmode, | |
565 | gen_rtx_REG (cmode, first_val_regnum + i), | |
566 | GEN_INT ((i + 1) * BITS_PER_UNIT)); | |
567 | ||
568 | vec[nregs - 1] | |
569 | = gen_rtx_EXPR_LIST (VOIDmode, | |
570 | gen_rtx_REG (cmode, first_val_regnum + nregs - 1), | |
571 | GEN_INT (0)); | |
572 | ||
573 | return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nregs, vec)); | |
574 | } | |
575 | ||
576 | /* EH_RETURN_DATA_REGNO. */ | |
577 | ||
578 | int | |
579 | mmix_eh_return_data_regno (n) | |
580 | int n ATTRIBUTE_UNUSED; | |
581 | { | |
582 | if (n >= 0 && n < 4) | |
583 | return MMIX_EH_RETURN_DATA_REGNO_START + n; | |
584 | ||
585 | return INVALID_REGNUM; | |
586 | } | |
587 | ||
588 | /* EH_RETURN_STACKADJ_RTX. */ | |
589 | ||
590 | rtx | |
591 | mmix_eh_return_stackadj_rtx () | |
592 | { | |
593 | return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM); | |
594 | } | |
595 | ||
596 | /* EH_RETURN_HANDLER_RTX. */ | |
597 | ||
598 | rtx | |
599 | mmix_eh_return_handler_rtx () | |
600 | { | |
601 | return | |
602 | gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM); | |
603 | } | |
604 | ||
605 | /* ASM_PREFERRED_EH_DATA_FORMAT. */ | |
606 | ||
607 | int | |
608 | mmix_asm_preferred_eh_data_format (code, global) | |
609 | int code ATTRIBUTE_UNUSED; | |
610 | int global ATTRIBUTE_UNUSED; | |
611 | { | |
612 | /* This is the default (was at 2001-07-20). Revisit when needed. */ | |
613 | return DW_EH_PE_absptr; | |
614 | } | |
615 | ||
616 | /* Emit the function prologue. For simplicity while the port is still | |
617 | in a flux, we do it as text rather than the now preferred RTL way, | |
618 | as (define_insn "function_prologue"). | |
619 | ||
620 | FIXME: Translate to RTL and/or optimize some of the DWARF 2 stuff. */ | |
621 | ||
622 | void | |
623 | mmix_target_asm_function_prologue (stream, locals_size) | |
624 | FILE *stream; | |
625 | HOST_WIDE_INT locals_size; | |
626 | { | |
627 | int regno; | |
628 | int stack_space_to_allocate | |
629 | = (current_function_outgoing_args_size | |
630 | + current_function_pretend_args_size | |
631 | + (int) locals_size + 8 + 7) & ~7; | |
632 | int offset = -8; | |
633 | int empty_stack_frame | |
634 | = (current_function_outgoing_args_size == 0 | |
635 | && locals_size == 0 | |
636 | && current_function_pretend_args_size == 0 | |
637 | && current_function_varargs == 0 | |
638 | && current_function_stdarg == 0); | |
639 | int doing_dwarf = dwarf2out_do_frame (); | |
640 | long cfa_offset = 0; | |
641 | ||
642 | /* Guard our assumptions. Very low priority FIXME. */ | |
643 | if (locals_size != (int) locals_size) | |
644 | error ("stack frame too big"); | |
645 | ||
646 | /* Add room needed to save global non-register-stack registers. */ | |
647 | for (regno = 255; | |
648 | regno >= MMIX_FIRST_GLOBAL_REGNUM; | |
649 | regno--) | |
650 | /* Note that we assume that the frame-pointer-register is one of these | |
651 | registers, in which case we don't count it here. */ | |
652 | if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed) | |
653 | && regs_ever_live[regno] && !call_used_regs[regno])) | |
654 | || IS_MMIX_EH_RETURN_DATA_REG (regno)) | |
655 | stack_space_to_allocate += 8; | |
656 | ||
657 | /* If we do have a frame-pointer, add room for it. */ | |
658 | if (frame_pointer_needed) | |
659 | stack_space_to_allocate += 8; | |
660 | ||
661 | /* If we have a non-local label, we need to be able to unwind to it, so | |
662 | store the current register stack pointer. Also store the return | |
663 | address if we do that. */ | |
664 | if (MMIX_CFUN_HAS_LANDING_PAD) | |
665 | stack_space_to_allocate += 16; | |
666 | else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS) | |
667 | /* If we do have a saved return-address slot, add room for it. */ | |
668 | stack_space_to_allocate += 8; | |
669 | ||
670 | /* Make sure we don't get an unaligned stack. */ | |
671 | if ((stack_space_to_allocate % 8) != 0) | |
672 | internal_error ("Stack frame not a multiple of 8 bytes: %d", | |
673 | stack_space_to_allocate); | |
674 | ||
675 | if (current_function_pretend_args_size) | |
676 | { | |
677 | int mmix_first_vararg_reg | |
678 | = (MMIX_FIRST_INCOMING_ARG_REGNUM | |
679 | + (MMIX_MAX_ARGS_IN_REGS | |
680 | - current_function_pretend_args_size / 8)); | |
681 | ||
682 | for (regno | |
683 | = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1; | |
684 | regno >= mmix_first_vararg_reg; | |
685 | regno--) | |
686 | { | |
687 | if (offset < 0) | |
688 | { | |
689 | int stack_chunk | |
690 | = stack_space_to_allocate > (256 - 8) | |
691 | ? (256 - 8) : stack_space_to_allocate; | |
692 | ||
693 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
694 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
695 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
696 | stack_chunk); | |
697 | ||
698 | if (doing_dwarf) | |
699 | { | |
700 | /* Each call to dwarf2out_def_cfa overrides the previous | |
701 | setting; they don't accumulate. We must keep track | |
702 | of the offset ourselves. */ | |
703 | cfa_offset += stack_chunk; | |
704 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
705 | cfa_offset); | |
706 | } | |
707 | offset += stack_chunk; | |
708 | stack_space_to_allocate -= stack_chunk; | |
709 | } | |
710 | ||
711 | fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno], | |
712 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
713 | offset); | |
714 | ||
715 | /* These registers aren't actually saved (as in "will be | |
716 | restored"), so don't tell DWARF2 they're saved. */ | |
717 | ||
718 | offset -= 8; | |
719 | } | |
720 | } | |
721 | ||
722 | /* In any case, skip over the return-address slot. FIXME: Not needed | |
723 | now. */ | |
724 | offset -= 8; | |
725 | ||
726 | /* Store the frame-pointer. */ | |
727 | ||
728 | if (frame_pointer_needed) | |
729 | { | |
730 | empty_stack_frame = 0; | |
731 | ||
732 | if (offset < 0) | |
733 | { | |
734 | /* Get 8 less than otherwise, since we need to reach offset + 8. */ | |
735 | int stack_chunk | |
736 | = stack_space_to_allocate > (256 - 8 - 8) | |
737 | ? (256 - 8 - 8) : stack_space_to_allocate; | |
738 | ||
739 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
740 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
741 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
742 | stack_chunk); | |
743 | if (doing_dwarf) | |
744 | { | |
745 | cfa_offset += stack_chunk; | |
746 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
747 | cfa_offset); | |
748 | } | |
749 | offset += stack_chunk; | |
750 | stack_space_to_allocate -= stack_chunk; | |
751 | } | |
752 | ||
753 | fprintf (stream, "\tSTOU %s,%s,%d\n\tADDU %s,%s,%d\n", | |
754 | reg_names[MMIX_FRAME_POINTER_REGNUM], | |
755 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
756 | offset, | |
757 | reg_names[MMIX_FRAME_POINTER_REGNUM], | |
758 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
759 | offset + 8); | |
760 | if (doing_dwarf) | |
761 | dwarf2out_reg_save ("", MMIX_FRAME_POINTER_REGNUM, | |
762 | -cfa_offset + offset); | |
763 | ||
764 | offset -= 8; | |
765 | } | |
766 | ||
767 | if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS) | |
768 | { | |
769 | /* Store the return-address, if one is needed on the stack. */ | |
770 | empty_stack_frame = 0; | |
771 | ||
772 | if (offset < 0) | |
773 | { | |
774 | /* Get 8 less than otherwise, since we need to reach offset + 8. */ | |
775 | int stack_chunk | |
776 | = stack_space_to_allocate > (256 - 8 - 8) | |
777 | ? (256 - 8 - 8) : stack_space_to_allocate; | |
778 | ||
779 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
780 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
781 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
782 | stack_chunk); | |
783 | if (doing_dwarf) | |
784 | { | |
785 | cfa_offset += stack_chunk; | |
786 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
787 | cfa_offset); | |
788 | } | |
789 | offset += stack_chunk; | |
790 | stack_space_to_allocate -= stack_chunk; | |
791 | } | |
792 | ||
793 | fprintf (stream, "\tGET $255,rJ\n\tSTOU $255,%s,%d\n", | |
794 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
795 | offset); | |
796 | if (doing_dwarf) | |
797 | dwarf2out_return_save ("", -cfa_offset + offset); | |
798 | offset -= 8; | |
799 | } | |
800 | else if (MMIX_CFUN_HAS_LANDING_PAD) | |
801 | offset -= 8; | |
802 | ||
803 | if (MMIX_CFUN_HAS_LANDING_PAD) | |
804 | { | |
805 | /* Store the register defining the numbering of local registers, so | |
806 | we know how long to unwind the register stack. */ | |
807 | ||
808 | empty_stack_frame = 0; | |
809 | ||
810 | if (offset < 0) | |
811 | { | |
812 | /* Get 8 less than otherwise, since we need to reach offset + 8. */ | |
813 | int stack_chunk | |
814 | = stack_space_to_allocate > (256 - 8 - 8) | |
815 | ? (256 - 8 - 8) : stack_space_to_allocate; | |
816 | ||
817 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
818 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
819 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
820 | stack_chunk); | |
821 | offset += stack_chunk; | |
822 | stack_space_to_allocate -= stack_chunk; | |
823 | ||
824 | if (doing_dwarf) | |
825 | { | |
826 | cfa_offset += stack_chunk; | |
827 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
828 | cfa_offset); | |
829 | } | |
830 | } | |
831 | ||
832 | /* We don't tell dwarf2 about this one; we just have it to unwind | |
833 | the register stack at landing pads. FIXME: It's a kludge because | |
834 | we can't describe the effect of the PUSHJ and PUSHGO insns on the | |
835 | register stack at the moment. Best thing would be to handle it | |
836 | like stack-pointer offsets. Better: some hook into dwarf2out.c | |
837 | to produce DW_CFA_expression:s that specify the increment of rO, | |
838 | and unwind it at eh_return (preferred) or at the landing pad. | |
839 | Then saves to $0..$G-1 could be specified through that register. */ | |
840 | ||
841 | fprintf (stream, "\tGET $255,rO\n\tSTOU $255,%s,%d\n", | |
842 | reg_names[MMIX_STACK_POINTER_REGNUM], offset); | |
843 | ||
844 | offset -= 8; | |
845 | } | |
846 | ||
847 | /* After the return-address and the frame-pointer, we have the local | |
848 | variables. They're the ones that may have an "unaligned" size. */ | |
849 | offset -= (locals_size + 7) & ~7; | |
850 | ||
851 | /* Now store all registers that are global, i.e. not saved by the | |
852 | register file machinery. | |
853 | ||
854 | It is assumed that the frame-pointer is one of these registers, so it | |
855 | is explicitly excluded in the count. */ | |
856 | ||
857 | for (regno = 255; | |
858 | regno >= MMIX_FIRST_GLOBAL_REGNUM; | |
859 | regno--) | |
860 | if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed) | |
861 | && regs_ever_live[regno] && ! call_used_regs[regno]) | |
862 | || IS_MMIX_EH_RETURN_DATA_REG (regno)) | |
863 | { | |
864 | empty_stack_frame = 0; | |
865 | ||
866 | if (offset < 0) | |
867 | { | |
868 | int stack_chunk; | |
869 | ||
870 | /* Since the local variables go above, we may get a large | |
871 | offset here. */ | |
872 | if (offset < -248) | |
873 | { | |
874 | /* We're not going to access the locals area in the | |
875 | prologue, so we'll just silently subtract the slab we | |
876 | will not access. */ | |
877 | stack_chunk = | |
878 | stack_space_to_allocate > (256 - offset - 8) | |
879 | ? (256 - offset - 8) : stack_space_to_allocate; | |
880 | ||
881 | mmix_output_register_setting (stream, 255, stack_chunk, 1); | |
882 | fprintf (stream, "\tSUBU %s,%s,$255\n", | |
883 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
884 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
885 | ||
886 | if (doing_dwarf) | |
887 | { | |
888 | cfa_offset += stack_chunk; | |
889 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
890 | cfa_offset); | |
891 | } | |
892 | } | |
893 | else | |
894 | { | |
895 | stack_chunk = stack_space_to_allocate > (256 - 8) | |
896 | ? (256 - 8) : stack_space_to_allocate; | |
897 | ||
898 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
899 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
900 | reg_names[MMIX_STACK_POINTER_REGNUM], stack_chunk); | |
901 | if (doing_dwarf) | |
902 | { | |
903 | cfa_offset += stack_chunk; | |
904 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
905 | cfa_offset); | |
906 | } | |
907 | } | |
908 | ||
909 | offset += stack_chunk; | |
910 | stack_space_to_allocate -= stack_chunk; | |
911 | } | |
912 | ||
913 | fprintf (stream, "\tSTOU %s,%s,%d\n", reg_names[regno], | |
914 | reg_names[MMIX_STACK_POINTER_REGNUM], offset); | |
915 | if (doing_dwarf) | |
916 | dwarf2out_reg_save ("", regno, -cfa_offset + offset); | |
917 | offset -= 8; | |
918 | } | |
919 | ||
920 | /* Finally, allocate room for local vars (if they weren't allocated for | |
921 | above) and outgoing args. This might be any number of bytes (well, | |
922 | we assume it fits in a host-int). | |
923 | Don't allocate (the return-address slot) if the stack frame is empty. */ | |
924 | if (stack_space_to_allocate && ! empty_stack_frame) | |
925 | { | |
926 | if (stack_space_to_allocate < 256) | |
927 | { | |
928 | fprintf (stream, "\tSUBU %s,%s,%d\n", | |
929 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
930 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
931 | stack_space_to_allocate); | |
932 | } | |
933 | else | |
934 | { | |
935 | mmix_output_register_setting (stream, 255, | |
936 | stack_space_to_allocate, 1); | |
937 | fprintf (stream, "\tSUBU %s,%s,$255\n", | |
938 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
939 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
940 | } | |
941 | ||
942 | if (doing_dwarf) | |
943 | { | |
944 | cfa_offset += stack_space_to_allocate; | |
945 | dwarf2out_def_cfa ("", MMIX_STACK_POINTER_REGNUM, | |
946 | cfa_offset); | |
947 | } | |
948 | } | |
949 | ||
950 | /* We put the number of the highest saved register-file register in a | |
951 | location convenient for the call-patterns to output. Note that we | |
952 | don't tell dwarf2 about these registers, since it can't restore them | |
953 | anyway. */ | |
954 | for (regno = MMIX_LAST_REGISTER_FILE_REGNUM; | |
955 | regno >= 0; | |
956 | regno--) | |
957 | if ((regs_ever_live[regno] && !call_used_regs[regno]) | |
958 | || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed)) | |
959 | break; | |
960 | ||
961 | mmix_highest_saved_stack_register = regno; | |
962 | ||
963 | /* FIXME: A kludge for the MMIXware ABI. The return value comes back in | |
964 | L of the caller, not just the register number of the X field of | |
965 | PUSH{J,GO}. So we need to make L agree with that number if there's a | |
966 | function call in this function that returns a value but takes no | |
967 | parameters (if there were parameters, L would be set to at least the | |
968 | first parameter register, $16). A real solution includes a pass to | |
969 | test that settings of $15 (MMIX_RETURN_VALUE_REGNUM for the MMIXware | |
970 | ABI) dominate all function calls that return a value. This could be | |
971 | done in the planned machine_dep_reorg pass to rename all registers. */ | |
972 | if (! TARGET_ABI_GNU && cfun->machine->has_call_value_without_parameters) | |
973 | fprintf (stream, "\tSET %s,%s\n", | |
974 | reg_names[MMIX_RETURN_VALUE_REGNUM], | |
975 | reg_names[MMIX_RETURN_VALUE_REGNUM]); | |
976 | } | |
977 | ||
978 | /* TARGET_ASM_FUNCTION_EPILOGUE. */ | |
979 | ||
980 | void | |
981 | mmix_target_asm_function_epilogue (stream, locals_size) | |
982 | FILE *stream; | |
983 | HOST_WIDE_INT locals_size; | |
984 | ||
985 | { | |
986 | int regno; | |
987 | int stack_space_to_deallocate | |
988 | = (current_function_outgoing_args_size | |
989 | + current_function_pretend_args_size | |
990 | + (int) locals_size + 8 + 7) & ~7; | |
991 | ||
992 | /* The assumption that locals_size fits in an int is asserted in | |
993 | mmix_target_asm_function_prologue. */ | |
994 | ||
995 | /* The first address to access is beyond the outgoing_args area. */ | |
996 | int offset = current_function_outgoing_args_size; | |
997 | int empty_stack_frame | |
998 | = (current_function_outgoing_args_size == 0 | |
999 | && locals_size == 0 | |
1000 | && current_function_pretend_args_size == 0 | |
1001 | && ! MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS | |
1002 | && ! MMIX_CFUN_HAS_LANDING_PAD); | |
1003 | ||
1004 | /* Add the space for global non-register-stack registers. | |
1005 | It is assumed that the frame-pointer register can be one of these | |
1006 | registers, in which case it is excluded from the count when needed. */ | |
1007 | for (regno = 255; | |
1008 | regno >= MMIX_FIRST_GLOBAL_REGNUM; | |
1009 | regno--) | |
1010 | if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed) | |
1011 | && regs_ever_live[regno] && !call_used_regs[regno]) | |
1012 | || IS_MMIX_EH_RETURN_DATA_REG (regno)) | |
1013 | stack_space_to_deallocate += 8; | |
1014 | ||
1015 | /* Add in the space for register stack-pointer. If so, always add room | |
1016 | for the saved PC. */ | |
1017 | if (MMIX_CFUN_HAS_LANDING_PAD) | |
1018 | stack_space_to_deallocate += 16; | |
1019 | else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS) | |
1020 | /* If we have a saved return-address slot, add it in. */ | |
1021 | stack_space_to_deallocate += 8; | |
1022 | ||
1023 | /* Add in the frame-pointer. */ | |
1024 | if (frame_pointer_needed) | |
1025 | stack_space_to_deallocate += 8; | |
1026 | ||
1027 | /* Make sure we don't get an unaligned stack. */ | |
1028 | if ((stack_space_to_deallocate % 8) != 0) | |
1029 | internal_error ("Stack frame not a multiple of octabyte: %d", | |
1030 | stack_space_to_deallocate); | |
1031 | ||
1032 | /* We will add back small offsets to the stack pointer as we go. | |
1033 | First, we restore all registers that are global, i.e. not saved by | |
1034 | the register file machinery. */ | |
1035 | ||
1036 | for (regno = MMIX_FIRST_GLOBAL_REGNUM; | |
1037 | regno <= 255; | |
1038 | regno++) | |
1039 | if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed) | |
1040 | && regs_ever_live[regno] && !call_used_regs[regno]) | |
1041 | || IS_MMIX_EH_RETURN_DATA_REG (regno)) | |
1042 | { | |
1043 | empty_stack_frame = 0; | |
1044 | ||
1045 | if (offset > 255) | |
1046 | { | |
1047 | if (offset > 65535) | |
1048 | { | |
1049 | /* There's better support for incrementing than | |
1050 | decrementing, so we might be able to optimize this as | |
1051 | we see a need. */ | |
1052 | mmix_output_register_setting (stream, 255, offset, 1); | |
1053 | fprintf (stream, "\tADDU %s,%s,$255\n", | |
1054 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1055 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
1056 | } | |
1057 | else | |
1058 | fprintf (stream, "\tINCL %s,%d\n", | |
1059 | reg_names[MMIX_STACK_POINTER_REGNUM], offset); | |
1060 | ||
1061 | stack_space_to_deallocate -= offset; | |
1062 | offset = 0; | |
1063 | } | |
1064 | ||
1065 | fprintf (stream, "\tLDOU %s,%s,%d\n", | |
1066 | reg_names[regno], | |
1067 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1068 | offset); | |
1069 | offset += 8; | |
1070 | } | |
1071 | ||
1072 | /* Here is where the local variables were. As in the prologue, they | |
1073 | might be of an unaligned size. */ | |
1074 | offset += (locals_size + 7) & ~7; | |
1075 | ||
1076 | ||
1077 | /* The saved register stack pointer is just below the frame-pointer | |
1078 | register. We don't need to restore it "manually"; the POP | |
1079 | instruction does that. */ | |
1080 | if (MMIX_CFUN_HAS_LANDING_PAD) | |
1081 | offset += 16; | |
1082 | else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS) | |
1083 | /* The return-address slot is just below the frame-pointer register. | |
1084 | We don't need to restore it because we don't really use it. */ | |
1085 | offset += 8; | |
1086 | ||
1087 | /* Get back the old frame-pointer-value. */ | |
1088 | if (frame_pointer_needed) | |
1089 | { | |
1090 | empty_stack_frame = 0; | |
1091 | ||
1092 | if (offset > 255) | |
1093 | { | |
1094 | if (offset > 65535) | |
1095 | { | |
1096 | /* There's better support for incrementing than | |
1097 | decrementing, so we might be able to optimize this as | |
1098 | we see a need. */ | |
1099 | mmix_output_register_setting (stream, 255, offset, 1); | |
1100 | fprintf (stream, "\tADDU %s,%s,$255\n", | |
1101 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1102 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
1103 | } | |
1104 | else | |
1105 | fprintf (stream, "\tINCL %s,%d\n", | |
1106 | reg_names[MMIX_STACK_POINTER_REGNUM], offset); | |
1107 | ||
1108 | stack_space_to_deallocate -= offset; | |
1109 | offset = 0; | |
1110 | } | |
1111 | ||
1112 | fprintf (stream, "\tLDOU %s,%s,%d\n", | |
1113 | reg_names[MMIX_FRAME_POINTER_REGNUM], | |
1114 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1115 | offset); | |
1116 | offset += 8; | |
1117 | } | |
1118 | ||
1119 | /* Do not deallocate the return-address slot if the stack frame is | |
1120 | empty, because then it was never allocated. */ | |
1121 | if (! empty_stack_frame) | |
1122 | { | |
1123 | /* We do not need to restore pretended incoming args, just add | |
1124 | back offset to sp. */ | |
1125 | if (stack_space_to_deallocate > 65535) | |
1126 | { | |
1127 | /* There's better support for incrementing than decrementing, so | |
1128 | we might be able to optimize this as we see a need. */ | |
1129 | mmix_output_register_setting (stream, 255, | |
1130 | stack_space_to_deallocate, 1); | |
1131 | fprintf (stream, "\tADDU %s,%s,$255\n", | |
1132 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1133 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
1134 | } | |
1135 | else | |
1136 | fprintf (stream, "\tINCL %s,%d\n", | |
1137 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
1138 | stack_space_to_deallocate); | |
1139 | } | |
1140 | ||
1141 | if (current_function_calls_eh_return) | |
1142 | /* Adjustment the (normal) stack-pointer to that of the receiver. | |
1143 | FIXME: It would be nice if we could also adjust the register stack | |
1144 | here, but we need to express it through DWARF 2 too. */ | |
1145 | fprintf (stream, "\tADDU %s,%s,%s\n", | |
1146 | reg_names [MMIX_STACK_POINTER_REGNUM], | |
1147 | reg_names [MMIX_STACK_POINTER_REGNUM], | |
1148 | reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]); | |
1149 | ||
1150 | /* The extra \n is so we have a blank line between the assembly code of | |
1151 | separate functions. */ | |
1152 | fprintf (stream, "\tPOP %d,0\n\n", | |
1153 | (! TARGET_ABI_GNU | |
1154 | && current_function_return_rtx != NULL | |
1155 | && ! current_function_returns_struct) | |
1156 | ? (GET_CODE (current_function_return_rtx) == PARALLEL | |
1157 | ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1) | |
1158 | : 0); | |
1159 | } | |
1160 | ||
1161 | /* ASM_OUTPUT_MI_THUNK. */ | |
1162 | ||
1163 | void | |
1164 | mmix_asm_output_mi_thunk (stream, fndecl, delta, func) | |
1165 | FILE * stream; | |
1166 | tree fndecl ATTRIBUTE_UNUSED; | |
1167 | int delta; | |
1168 | tree func; | |
1169 | { | |
1170 | /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM, | |
1171 | (i.e. pass location of structure to return as invisible first | |
1172 | argument) you need to tweak this code too. */ | |
1173 | const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM]; | |
1174 | ||
1175 | if (delta >= 0 && delta < 65536) | |
1176 | asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname); | |
1177 | else if (delta < 0 && delta >= -255) | |
1178 | asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta); | |
1179 | else | |
1180 | { | |
1181 | mmix_output_register_setting (stream, 255, delta, 1); | |
1182 | asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname); | |
1183 | } | |
1184 | ||
1185 | fprintf (stream, "\tJMP "); | |
1186 | assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0)); | |
1187 | fprintf (stream, "\n"); | |
1188 | } | |
1189 | ||
1190 | /* FUNCTION_PROFILER. */ | |
1191 | ||
1192 | void | |
1193 | mmix_function_profiler (stream, labelno) | |
1194 | FILE *stream ATTRIBUTE_UNUSED; | |
1195 | int labelno ATTRIBUTE_UNUSED; | |
1196 | { | |
1197 | sorry ("function_profiler support for MMIX"); | |
1198 | } | |
1199 | ||
1200 | /* FUNCTION_BLOCK_PROFILER. */ | |
1201 | ||
1202 | void | |
1203 | mmix_function_block_profiler (stream, labelno) | |
1204 | FILE *stream ATTRIBUTE_UNUSED; | |
1205 | int labelno ATTRIBUTE_UNUSED; | |
1206 | { | |
1207 | sorry ("function_block_profiler support for MMIX"); | |
1208 | } | |
1209 | ||
1210 | /* BLOCK_PROFILER. */ | |
1211 | ||
1212 | void | |
1213 | mmix_block_profiler (stream, labelno) | |
1214 | FILE *stream ATTRIBUTE_UNUSED; | |
1215 | int labelno ATTRIBUTE_UNUSED; | |
1216 | { | |
1217 | sorry ("block_profiler support for MMIX"); | |
1218 | } | |
1219 | ||
1220 | /* FUNCTION_BLOCK_PROFILER_EXIT. */ | |
1221 | ||
1222 | void | |
1223 | mmix_function_block_profiler_exit (stream) | |
1224 | FILE *stream ATTRIBUTE_UNUSED; | |
1225 | { | |
1226 | sorry ("block_profiler_exit support for MMIX"); | |
1227 | } | |
1228 | ||
1229 | /* SETUP_INCOMING_VARARGS. */ | |
1230 | ||
1231 | void | |
1232 | mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep, | |
1233 | second_time) | |
1234 | CUMULATIVE_ARGS * args_so_farp; | |
1235 | enum machine_mode mode; | |
1236 | tree vartype; | |
1237 | int * pretend_sizep; | |
1238 | int second_time ATTRIBUTE_UNUSED; | |
1239 | { | |
1240 | /* For stdarg, the last named variable has been handled, but | |
1241 | args_so_farp has not been advanced for it. For varargs, the current | |
1242 | argument is to be counted to the anonymous ones. */ | |
1243 | if (current_function_stdarg) | |
1244 | { | |
1245 | if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS) | |
1246 | *pretend_sizep | |
1247 | = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8; | |
1248 | } | |
1249 | else if (current_function_varargs) | |
1250 | { | |
1251 | if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS) | |
1252 | *pretend_sizep | |
1253 | = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8; | |
1254 | ||
1255 | /* For varargs, we get here when we see the last named parameter, | |
1256 | which will actually be passed on stack. So make the next call | |
1257 | (there will be one) to FUNCTION_ARG return 0, to count it on | |
1258 | stack, so va_arg for it will get right. FIXME: The GCC core | |
1259 | should provide TRT. */ | |
1260 | args_so_farp->now_varargs = 1; | |
1261 | } | |
1262 | else | |
1263 | internal_error ("Neither varargs or stdarg in mmix_setup_incoming_varargs"); | |
1264 | ||
1265 | ||
1266 | /* We assume that one argument takes up one register here. That should | |
1267 | be true until we start messing with multi-reg parameters. */ | |
1268 | if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1) | |
1269 | internal_error ("MMIX Internal: Last named vararg would not fit in a register"); | |
1270 | } | |
1271 | ||
1272 | /* EXPAND_BUILTIN_VA_ARG. */ | |
1273 | ||
1274 | /* This is modified from the "standard" implementation of va_arg: read the | |
1275 | value from the current (padded) address and increment by the (padded) | |
1276 | size. The difference for MMIX is that if the type is | |
1277 | pass-by-reference, then perform an indirection. */ | |
1278 | ||
1279 | rtx | |
1280 | mmix_expand_builtin_va_arg (valist, type) | |
1281 | tree valist; | |
1282 | tree type; | |
1283 | { | |
1284 | tree addr_tree, t; | |
1285 | HOST_WIDE_INT align; | |
1286 | HOST_WIDE_INT rounded_size; | |
1287 | rtx addr; | |
1288 | ||
1289 | /* Compute the rounded size of the type. */ | |
1290 | align = PARM_BOUNDARY / BITS_PER_UNIT; | |
1291 | rounded_size = (((int_size_in_bytes (type) + align - 1) / align) * align); | |
1292 | ||
1293 | /* Get AP. */ | |
1294 | addr_tree = valist; | |
1295 | ||
1296 | if (AGGREGATE_TYPE_P (type) | |
1297 | && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8 | |
1298 | && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0) | |
1299 | { | |
1300 | /* Adjust for big-endian the location of aggregates passed in a | |
1301 | register, but where the aggregate is accessed in a shorter mode | |
1302 | than the natural register mode (i.e. it is accessed as SFmode(?), | |
1303 | SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME: | |
1304 | Or should we adjust the mode in which the aggregate is read, to be | |
1305 | a register size mode? (Hum, nah, a small offset is generally | |
1306 | cheaper than a wider memory access on MMIX.) */ | |
1307 | addr_tree | |
1308 | = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree, | |
1309 | build_int_2 ((BITS_PER_WORD / BITS_PER_UNIT) | |
1310 | - GET_MODE_UNIT_SIZE (TYPE_MODE (type)), 0)); | |
1311 | } | |
1312 | else | |
1313 | { | |
1314 | HOST_WIDE_INT adj; | |
1315 | adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT; | |
1316 | if (rounded_size > align) | |
1317 | adj = rounded_size; | |
1318 | ||
1319 | addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree, | |
1320 | build_int_2 (rounded_size - adj, 0)); | |
1321 | ||
1322 | /* If this type is larger than what fits in a register, then it is | |
1323 | passed by reference. */ | |
1324 | if (rounded_size > BITS_PER_WORD / BITS_PER_UNIT) | |
1325 | { | |
1326 | tree type_ptr = build_pointer_type (type); | |
1327 | addr_tree = build1 (INDIRECT_REF, type_ptr, addr_tree); | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL); | |
1332 | addr = copy_to_reg (addr); | |
1333 | ||
1334 | /* Compute new value for AP. For MMIX, it is always advanced by the | |
1335 | size of a register. */ | |
1336 | t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, | |
1337 | build (PLUS_EXPR, TREE_TYPE (valist), valist, | |
1338 | build_int_2 (BITS_PER_WORD / BITS_PER_UNIT, 0))); | |
1339 | TREE_SIDE_EFFECTS (t) = 1; | |
1340 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
1341 | ||
1342 | return addr; | |
1343 | } | |
1344 | ||
1345 | /* TRAMPOLINE_SIZE. */ | |
1346 | /* Four 4-byte insns plus two 8-byte values. */ | |
1347 | int mmix_trampoline_size = 32; | |
1348 | ||
1349 | ||
1350 | /* TRAMPOLINE_TEMPLATE. */ | |
1351 | ||
1352 | void | |
1353 | mmix_trampoline_template (stream) | |
1354 | FILE * stream; | |
1355 | { | |
1356 | /* Read a value from to static-chain, jump somewhere. The static chain | |
1357 | is stored at offset 16, and the function address is stored at offset | |
1358 | 24. */ | |
1359 | /* FIXME: GCC copies this using *intsize* (tetra), when it should use | |
1360 | register size (octa). */ | |
1361 | fprintf (stream, "\tGETA $255,1F\n\t"); | |
1362 | fprintf (stream, "LDOU %s,$255,0\n\t", | |
1363 | reg_names[MMIX_STATIC_CHAIN_REGNUM]); | |
1364 | fprintf (stream, "LDOU $255,$255,8\n\t"); | |
1365 | fprintf (stream, "GO $255,$255,0\n"); | |
1366 | fprintf (stream, "1H\tOCTA 0\n\t"); | |
1367 | fprintf (stream, "OCTA 0\n"); | |
1368 | } | |
1369 | ||
1370 | /* INITIALIZE_TRAMPOLINE. */ | |
1371 | /* Set the static chain and function pointer field in the trampoline. | |
1372 | We also SYNCID here to be sure (doesn't matter in the simulator, but | |
1373 | some day it will). */ | |
1374 | ||
1375 | void | |
1376 | mmix_initialize_trampoline (trampaddr, fnaddr, static_chain) | |
1377 | rtx trampaddr; | |
1378 | rtx fnaddr; | |
1379 | rtx static_chain; | |
1380 | { | |
1381 | emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)), | |
1382 | static_chain); | |
1383 | emit_move_insn (gen_rtx_MEM (DImode, | |
1384 | plus_constant (trampaddr, 24)), | |
1385 | fnaddr); | |
1386 | emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode, | |
1387 | trampaddr)), | |
1388 | GEN_INT (mmix_trampoline_size - 1))); | |
1389 | } | |
1390 | ||
1391 | /* We must exclude constant addresses that have an increment that is not a | |
1392 | multiple of four bytes because of restrictions of the GETA | |
1393 | instruction. FIXME: No, I don't think so. Just add a constraint. */ | |
1394 | ||
1395 | int | |
1396 | mmix_constant_address_p (x) | |
1397 | rtx x; | |
1398 | { | |
1399 | RTX_CODE code = GET_CODE (x); | |
1400 | int addend = 0; | |
1401 | ||
1402 | if (code == LABEL_REF || code == SYMBOL_REF) | |
1403 | return 1; | |
1404 | ||
1405 | if (code == CONSTANT_P_RTX || code == HIGH) | |
1406 | /* FIXME: Don't know how to dissect these. Avoid them for now. */ | |
1407 | return 0; | |
1408 | ||
1409 | switch (code) | |
1410 | { | |
1411 | case LABEL_REF: | |
1412 | case SYMBOL_REF: | |
1413 | return 1; | |
1414 | ||
1415 | case PLUS: | |
1416 | /* Can we get a naked PLUS? */ | |
1417 | case CONSTANT_P_RTX: | |
1418 | case HIGH: | |
1419 | /* FIXME: Don't know how to dissect these. Avoid them for now. */ | |
1420 | return 0; | |
1421 | ||
1422 | case CONST_INT: | |
1423 | addend = INTVAL (x); | |
1424 | break; | |
1425 | ||
1426 | case CONST_DOUBLE: | |
1427 | if (GET_MODE (x) != VOIDmode) | |
1428 | /* Strange that we got here. FIXME: Check if we do. */ | |
1429 | return 0; | |
1430 | addend = CONST_DOUBLE_LOW (x); | |
1431 | break; | |
1432 | ||
1433 | case CONST: | |
1434 | /* Note that expressions with arithmetic on forward references don't | |
1435 | work in mmixal. People using gcc assembly code with mmixal might | |
1436 | need to move arrays and such to before the point of use. */ | |
1437 | if (GET_CODE (XEXP (x, 0)) == PLUS) | |
1438 | { | |
1439 | rtx x0 = XEXP (XEXP (x, 0), 0); | |
1440 | rtx x1 = XEXP (XEXP (x, 0), 1); | |
1441 | ||
1442 | if ((GET_CODE (x0) == SYMBOL_REF | |
1443 | || GET_CODE (x0) == LABEL_REF) | |
1444 | && (GET_CODE (x1) == CONST_INT | |
1445 | || (GET_CODE (x1) == CONST_DOUBLE | |
1446 | && GET_MODE (x1) == VOIDmode))) | |
1447 | addend = mmix_intval (x1); | |
1448 | else | |
1449 | return 0; | |
1450 | } | |
1451 | else | |
1452 | return 0; | |
1453 | break; | |
1454 | ||
1455 | default: | |
1456 | return 0; | |
1457 | } | |
1458 | ||
1459 | return (addend & 3) == 0; | |
1460 | } | |
1461 | ||
1462 | /* Return 1 if the address is OK, otherwise 0. | |
1463 | Used by GO_IF_LEGITIMATE_ADDRESS. */ | |
1464 | ||
1465 | int | |
1466 | mmix_legitimate_address (mode, x, strict_checking) | |
1467 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1468 | rtx x; | |
1469 | int strict_checking; | |
1470 | { | |
1471 | #define MMIX_REG_OK(X) \ | |
1472 | ((strict_checking \ | |
1473 | && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \ | |
1474 | || (reg_renumber[REGNO (X)] > 0 \ | |
1475 | && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \ | |
1476 | || (!strict_checking \ | |
1477 | && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \ | |
1478 | || REGNO (X) >= FIRST_PSEUDO_REGISTER \ | |
1479 | || REGNO (X) == ARG_POINTER_REGNUM))) | |
1480 | ||
1481 | /* We only accept: | |
1482 | (mem reg) | |
1483 | (mem (plus reg reg)) | |
1484 | (mem (plus reg 0..255)). */ | |
1485 | ||
1486 | ||
1487 | /* (mem reg) */ | |
1488 | if (REG_P (x) && MMIX_REG_OK (x)) | |
1489 | return 1; | |
1490 | ||
1491 | if (GET_CODE(x) == PLUS) | |
1492 | { | |
1493 | rtx x1 = XEXP (x, 0); | |
1494 | rtx x2 = XEXP (x, 1); | |
1495 | ||
1496 | /* Try swapping the order. FIXME: Do we need this? */ | |
1497 | if (! REG_P (x1)) | |
1498 | { | |
1499 | rtx tem = x1; | |
1500 | x1 = x2; | |
1501 | x2 = tem; | |
1502 | } | |
1503 | ||
1504 | /* (mem (plus (reg) (?))) */ | |
1505 | if (!REG_P (x1) || !MMIX_REG_OK (x1)) | |
1506 | return 0; | |
1507 | ||
1508 | /* (mem (plus (reg) (reg))) */ | |
1509 | if (REG_P (x2) && MMIX_REG_OK (x2)) | |
1510 | return 1; | |
1511 | ||
1512 | /* (mem (plus (reg) (0..255))) */ | |
1513 | if (GET_CODE (x2) == CONST_INT | |
1514 | && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I')) | |
1515 | return 1; | |
1516 | } | |
1517 | ||
1518 | return 0; | |
1519 | } | |
1520 | ||
1521 | /* LEGITIMATE_CONSTANT_P. */ | |
1522 | ||
1523 | int | |
1524 | mmix_legitimate_constant_p (x) | |
1525 | rtx x; | |
1526 | { | |
1527 | RTX_CODE code = GET_CODE (x); | |
1528 | ||
1529 | /* We must allow any number due to the way the cse passes works; if we | |
1530 | do not allow any number here, general_operand will fail, and insns | |
1531 | will fatally fail recognition instead of "softly". */ | |
1532 | if (code == CONST_INT || code == CONST_DOUBLE) | |
1533 | return 1; | |
1534 | ||
1535 | return CONSTANT_ADDRESS_P (x); | |
1536 | } | |
1537 | ||
1538 | /* SELECT_CC_MODE. */ | |
1539 | ||
1540 | enum machine_mode | |
1541 | mmix_select_cc_mode (op, x, y) | |
1542 | RTX_CODE op; | |
1543 | rtx x; | |
1544 | rtx y ATTRIBUTE_UNUSED; | |
1545 | { | |
1546 | /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to | |
1547 | output different compare insns. Note that we do not check the | |
1548 | validity of the comparison here. */ | |
1549 | ||
1550 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
1551 | { | |
1552 | if (op == ORDERED || op == UNORDERED || op == UNGE | |
1553 | || op == UNGT || op == UNLE || op == UNLT) | |
1554 | return CC_FUNmode; | |
1555 | ||
1556 | if (op == EQ || op == NE) | |
1557 | return CC_FPEQmode; | |
1558 | ||
1559 | return CC_FPmode; | |
1560 | } | |
1561 | ||
1562 | if (op == GTU || op == LTU || op == GEU || op == LEU) | |
1563 | return CC_UNSmode; | |
1564 | ||
1565 | return CCmode; | |
1566 | } | |
1567 | ||
1568 | /* CANONICALIZE_COMPARISON. | |
1569 | FIXME: Check if the number adjustments trig. */ | |
1570 | ||
1571 | void | |
1572 | mmix_canonicalize_comparison (codep, op0p, op1p) | |
1573 | RTX_CODE * codep; | |
1574 | rtx * op0p ATTRIBUTE_UNUSED; | |
1575 | rtx * op1p; | |
1576 | { | |
1577 | /* Change -1 to zero, if possible. */ | |
1578 | if ((*codep == LE || *codep == GT) | |
1579 | && GET_CODE (*op1p) == CONST_INT | |
1580 | && *op1p == constm1_rtx) | |
1581 | { | |
1582 | *codep = *codep == LE ? LT : GE; | |
1583 | *op1p = const0_rtx; | |
1584 | } | |
1585 | ||
1586 | /* Fix up 256 to 255, if possible. */ | |
1587 | if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU) | |
1588 | && GET_CODE (*op1p) == CONST_INT | |
1589 | && INTVAL (*op1p) == 256) | |
1590 | { | |
1591 | /* FIXME: Remove when I know this trigs. */ | |
1592 | fatal_insn ("Oops, not debugged; fixing up value:", *op1p); | |
1593 | *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep | |
1594 | == GE ? GT : GTU; | |
1595 | *op1p = GEN_INT (255); | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | /* REVERSIBLE_CC_MODE. */ | |
1600 | ||
1601 | int | |
1602 | mmix_reversible_cc_mode (mode) | |
1603 | enum machine_mode mode; | |
1604 | { | |
1605 | /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float | |
1606 | cmpares. */ | |
1607 | return mode != CC_FPmode; | |
1608 | } | |
1609 | ||
1610 | /* DEFAULT_RTX_COSTS. */ | |
1611 | ||
1612 | int | |
1613 | mmix_rtx_cost_recalculated (x, code, outer_code, costp) | |
1614 | rtx x ATTRIBUTE_UNUSED; | |
1615 | RTX_CODE code ATTRIBUTE_UNUSED; | |
1616 | RTX_CODE outer_code ATTRIBUTE_UNUSED; | |
1617 | int *costp ATTRIBUTE_UNUSED; | |
1618 | { | |
1619 | /* For the time being, this is just a stub and we'll accept the | |
1620 | generic calculations, until we can do measurements, at least. | |
1621 | Say we did not modify any calculated costs. */ | |
1622 | return 0; | |
1623 | } | |
1624 | ||
1625 | /* ADDRESS_COST. */ | |
1626 | ||
1627 | int | |
1628 | mmix_address_cost (addr) | |
1629 | rtx addr ATTRIBUTE_UNUSED; | |
1630 | { | |
1631 | /* There's no difference in the address costs and we have lots of | |
1632 | registers. Some targets use constant 0, many others use 1 to say | |
1633 | this. Let's start with 1. */ | |
1634 | return 1; | |
1635 | } | |
1636 | ||
1637 | /* REGISTER_MOVE_COST. */ | |
1638 | ||
1639 | int | |
1640 | mmix_register_move_cost (mode, from, to) | |
1641 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1642 | enum reg_class from; | |
1643 | enum reg_class to; | |
1644 | { | |
1645 | return (from == GENERAL_REGS && from == to) ? 2 : 3; | |
1646 | } | |
1647 | ||
1648 | /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a | |
1649 | compile-time constant; it's used in an asm in crtstuff.c, compiled for | |
1650 | the target. */ | |
1651 | ||
1652 | /* DATA_SECTION_ASM_OP. */ | |
1653 | ||
1654 | const char * | |
1655 | mmix_data_section_asm_op () | |
1656 | { | |
1657 | return "\t.data ! mmixal:= 8H LOC 9B"; | |
1658 | } | |
1659 | ||
1660 | /* SELECT_SECTION. | |
1661 | The meat is from elfos.h, which we will eventually consider using. */ | |
1662 | ||
1663 | void | |
1664 | mmix_select_section (decl, reloc, align) | |
1665 | tree decl; | |
1666 | int reloc; | |
1667 | int align ATTRIBUTE_UNUSED; | |
1668 | { | |
1669 | if (TREE_CODE (decl) == STRING_CST) | |
1670 | { | |
1671 | if (! flag_writable_strings) | |
1672 | const_section (); | |
1673 | else | |
1674 | data_section (); | |
1675 | } | |
1676 | else if (TREE_CODE (decl) == VAR_DECL) | |
1677 | { | |
1678 | if ((flag_pic && reloc) | |
1679 | || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl) | |
1680 | || !DECL_INITIAL (decl) | |
1681 | || (DECL_INITIAL (decl) != error_mark_node | |
1682 | && !TREE_CONSTANT (DECL_INITIAL (decl)))) | |
1683 | data_section (); | |
1684 | else | |
1685 | const_section (); | |
1686 | } | |
1687 | else if (TREE_CODE (decl) == CONSTRUCTOR) | |
1688 | { | |
1689 | if ((flag_pic && reloc) | |
1690 | || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl) | |
1691 | || ! TREE_CONSTANT (decl)) | |
1692 | data_section (); | |
1693 | else | |
1694 | const_section (); | |
1695 | } | |
1696 | else | |
1697 | const_section (); | |
1698 | } | |
1699 | ||
1700 | /* ENCODE_SECTION_INFO. */ | |
1701 | ||
1702 | void | |
1703 | mmix_encode_section_info (decl) | |
1704 | tree decl; | |
1705 | { | |
1706 | /* Test for an external declaration, and do nothing if it is one. */ | |
1707 | if ((TREE_CODE (decl) == VAR_DECL | |
1708 | && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)) | |
1709 | && ! TREE_STATIC (decl)) | |
1710 | || (TREE_CODE (decl) == FUNCTION_DECL | |
1711 | && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))) | |
1712 | ; | |
1713 | else if (DECL_P (decl)) | |
1714 | { | |
1715 | /* For non-visible declarations, add a "@" prefix, which we skip | |
1716 | when the label is output. If the label does not have this | |
1717 | prefix, a ":" is output. | |
1718 | ||
1719 | Note that this does not work for data that is declared extern and | |
1720 | later defined as static. If there's code in between, that code | |
1721 | will refer to the extern declaration. And vice versa. Until we | |
1722 | can get rid of mmixal, we have to assume that code is well-behaved | |
1723 | or come up with a contorted scheme to work around bad code. */ | |
1724 | ||
1725 | const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0); | |
1726 | int len = strlen (str); | |
1727 | char *newstr; | |
1728 | ||
1729 | /* Doing as rs6000 seems safe; always use ggc. Except don't copy | |
1730 | the suspected off-by-one bug. | |
1731 | FIXME: Is it still there? yes 2001-08-23 | |
1732 | Why is the return type of ggc_alloc_string const? */ | |
1733 | newstr = (char *) ggc_alloc_string ("", len + 2); | |
1734 | ||
1735 | strcpy (newstr + 1, str); | |
1736 | *newstr = '@'; | |
1737 | XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr; | |
1738 | } | |
1739 | ||
1740 | /* FIXME: Later on, add SYMBOL_REF_FLAG for things that we can reach | |
1741 | from here via GETA, to check in LEGITIMATE_CONSTANT_P. Needs to have | |
1742 | different options for the cases where we want *all* to be assumed | |
1743 | reachable via GETA, or all constant symbols, or just text symbols in | |
1744 | this file, or perhaps just the constant pool. */ | |
1745 | } | |
1746 | ||
1747 | /* STRIP_NAME_ENCODING. */ | |
1748 | ||
1749 | const char * | |
1750 | mmix_strip_name_encoding (name) | |
1751 | const char *name; | |
1752 | { | |
1753 | for (; (*name == '@' || *name == '*'); name++) | |
1754 | ; | |
1755 | ||
1756 | return name; | |
1757 | } | |
1758 | ||
1759 | /* UNIQUE_SECTION. | |
1760 | The meat is from elfos.h, which we should consider using. */ | |
1761 | ||
1762 | void | |
1763 | mmix_unique_section (decl, reloc) | |
1764 | tree decl; | |
1765 | int reloc; | |
1766 | { | |
1767 | int len; | |
1768 | int sec; | |
1769 | const char *name; | |
1770 | char *string; | |
1771 | const char *prefix; | |
25037517 | 1772 | static const char *const prefixes[4][2] = |
68cbb7e3 | 1773 | { |
1774 | { ".text.", ".gnu.linkonce.t." }, | |
1775 | { ".rodata.", ".gnu.linkonce.r." }, | |
1776 | { ".data.", ".gnu.linkonce.d." }, | |
1777 | { ".bss.", ".gnu.linkonce.b." } | |
1778 | }; | |
1779 | ||
1780 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1781 | sec = 0; | |
1782 | else if (DECL_INITIAL (decl) == 0 | |
1783 | || DECL_INITIAL (decl) == error_mark_node) | |
1784 | sec = 3; | |
1785 | else if (DECL_READONLY_SECTION (decl, reloc)) | |
1786 | sec = 1; | |
1787 | else | |
1788 | sec = 2; | |
1789 | ||
1790 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
1791 | /* Strip off any encoding in name. */ | |
1792 | STRIP_NAME_ENCODING (name, name); | |
1793 | prefix = prefixes[sec][DECL_ONE_ONLY (decl)]; | |
1794 | len = strlen (name) + strlen (prefix); | |
1795 | string = alloca (len + 1); | |
1796 | ||
1797 | sprintf (string, "%s%s", prefix, name); | |
1798 | ||
1799 | DECL_SECTION_NAME (decl) = build_string (len, string); | |
1800 | } | |
1801 | ||
1802 | /* ASM_FILE_START. */ | |
1803 | ||
1804 | void | |
1805 | mmix_asm_file_start (stream) | |
1806 | FILE * stream; | |
1807 | { | |
1808 | /* We just emit a little comment for the time being. FIXME: Perhaps add | |
1809 | -mstandalone and some segment and prefix setup here. */ | |
1810 | ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename); | |
1811 | ||
1812 | fprintf (stream, "! mmixal:= 8H LOC Data_Section\n"); | |
1813 | ||
1814 | /* Make sure each file starts with the text section. */ | |
1815 | text_section (); | |
1816 | } | |
1817 | ||
1818 | /* ASM_FILE_END. */ | |
1819 | ||
1820 | void | |
1821 | mmix_asm_file_end (stream) | |
1822 | FILE * stream ATTRIBUTE_UNUSED; | |
1823 | { | |
1824 | /* Make sure each file ends with the data section. */ | |
1825 | data_section (); | |
1826 | } | |
1827 | ||
1828 | /* ASM_IDENTIFY_GCC. */ | |
1829 | ||
1830 | void | |
1831 | mmix_asm_identify_gcc (stream) | |
1832 | FILE * stream; | |
1833 | { | |
1834 | /* No real need for the time being. May be useful to GDB later on. */ | |
1835 | fprintf (stream, "# Compiled by GCC version %s\n", | |
1836 | version_string); | |
1837 | } | |
1838 | ||
1839 | /* ASM_OUTPUT_SOURCE_FILENAME. */ | |
1840 | ||
1841 | void | |
1842 | mmix_asm_output_source_filename (stream, name) | |
1843 | FILE * stream; | |
1844 | const char * name; | |
1845 | { | |
1846 | fprintf (stream, "# 1 "); | |
1847 | OUTPUT_QUOTED_STRING (stream, name); | |
1848 | fprintf (stream, "\n"); | |
1849 | } | |
1850 | ||
1851 | /* OUTPUT_QUOTED_STRING. */ | |
1852 | ||
1853 | void | |
1854 | mmix_output_quoted_string (stream, string, length) | |
1855 | FILE * stream; | |
1856 | const char * string; | |
1857 | int length; | |
1858 | { | |
1859 | const char * string_end = string + length; | |
25037517 | 1860 | static const char *const unwanted_chars = "\"[]\\"; |
68cbb7e3 | 1861 | |
1862 | /* Output "any character except newline and double quote character". We | |
1863 | play it safe and avoid all control characters too. We also do not | |
1864 | want [] as characters, should input be passed through m4 with [] as | |
1865 | quotes. Further, we avoid "\", because the GAS port handles it as a | |
1866 | quoting character. */ | |
1867 | while (string < string_end) | |
1868 | { | |
1869 | if (*string | |
1870 | && (unsigned char) *string < 128 | |
1871 | && !ISCNTRL (*string) | |
1872 | && strchr (unwanted_chars, *string) == NULL) | |
1873 | { | |
1874 | fputc ('"', stream); | |
1875 | while (*string | |
1876 | && (unsigned char) *string < 128 | |
1877 | && !ISCNTRL (*string) | |
1878 | && strchr (unwanted_chars, *string) == NULL | |
1879 | && string < string_end) | |
1880 | { | |
1881 | fputc (*string, stream); | |
1882 | string++; | |
1883 | } | |
1884 | fputc ('"', stream); | |
1885 | if (string < string_end) | |
1886 | fprintf (stream, ","); | |
1887 | } | |
1888 | if (string < string_end) | |
1889 | { | |
1890 | fprintf (stream, "#%x", *string & 255); | |
1891 | string++; | |
1892 | if (string < string_end) | |
1893 | fprintf (stream, ","); | |
1894 | } | |
1895 | } | |
1896 | } | |
1897 | ||
1898 | /* ASM_OUTPUT_SOURCE_LINE. */ | |
1899 | ||
1900 | void | |
1901 | mmix_asm_output_source_line (stream, lineno) | |
1902 | FILE * stream; | |
1903 | int lineno; | |
1904 | { | |
1905 | fprintf (stream, "# %d ", lineno); | |
1906 | OUTPUT_QUOTED_STRING (stream, main_input_filename); | |
1907 | fprintf (stream, "\n"); | |
1908 | } | |
1909 | ||
1910 | /* ASM_OUTPUT_DOUBLE. */ | |
1911 | ||
1912 | void | |
1913 | mmix_asm_output_double (stream, valuep) | |
1914 | FILE * stream; | |
1915 | REAL_VALUE_TYPE * valuep; | |
1916 | { | |
1917 | unsigned long bits[2]; | |
1918 | HOST_WIDEST_INT value; | |
1919 | ||
1920 | REAL_VALUE_TO_TARGET_DOUBLE (*valuep, (long *) bits); | |
1921 | value | |
1922 | = (((HOST_WIDEST_INT) bits[0]) << 32) | (HOST_WIDEST_INT) bits[1]; | |
1923 | mmix_output_octa (stream, value, 1); | |
1924 | } | |
1925 | ||
1926 | /* ASM_OUTPUT_FLOAT. */ | |
1927 | ||
1928 | void | |
1929 | mmix_asm_output_float (stream, valuep) | |
1930 | FILE * stream; | |
1931 | REAL_VALUE_TYPE * valuep; | |
1932 | { | |
1933 | unsigned long bits; | |
1934 | ||
1935 | REAL_VALUE_TO_TARGET_SINGLE (*valuep, bits); | |
1936 | ||
1937 | fprintf (stream, "\tTETRA #%lx\n", | |
1938 | (unsigned long) (bits | |
1939 | & (((unsigned HOST_WIDEST_INT) (1 << 31) - 1) * 2 | |
1940 | + 1))); | |
1941 | } | |
1942 | ||
1943 | /* ASM_OUTPUT_DOUBLE_INT. */ | |
1944 | ||
1945 | void | |
1946 | mmix_asm_output_double_int (stream, value, do_begin_end) | |
1947 | FILE * stream; | |
1948 | rtx value; | |
1949 | int do_begin_end; | |
1950 | { | |
1951 | if (do_begin_end) | |
1952 | fprintf (stream, "\tOCTA "); | |
1953 | ||
1954 | if (GET_CODE (value) == CONST_DOUBLE) | |
1955 | { | |
1956 | /* Get the bit representation of this number. */ | |
1957 | HOST_WIDE_INT wval = mmix_intval (value); | |
1958 | mmix_output_octa (stream, wval, 0); | |
1959 | } | |
1960 | else | |
1961 | /* FIXME: We scrap the '@' symbol-modifier since it's not used | |
1962 | anymore; we used to jump through lots of hoops, attempting to get | |
1963 | mmixal-compatible symbols; defined before use (still failed). */ | |
1964 | output_addr_const (stream, value); | |
1965 | ||
1966 | if (do_begin_end) | |
1967 | fprintf (stream, "\n"); | |
1968 | } | |
1969 | ||
1970 | /* ASM_OUTPUT_ASCII. */ | |
1971 | ||
1972 | void | |
1973 | mmix_asm_output_ascii (stream, string, length) | |
1974 | FILE *stream; | |
1975 | const char *string; | |
1976 | int length; | |
1977 | { | |
1978 | while (length > 0) | |
1979 | { | |
1980 | int chunk_size = length > 60 ? 60 : length; | |
1981 | fprintf (stream, "\tBYTE "); | |
1982 | mmix_output_quoted_string (stream, string, chunk_size); | |
1983 | string += chunk_size; | |
1984 | length -= chunk_size; | |
1985 | fprintf (stream, "\n"); | |
1986 | } | |
1987 | } | |
1988 | ||
1989 | /* ASM_OUTPUT_ALIGNED_COMMON. */ | |
1990 | ||
1991 | void | |
1992 | mmix_asm_output_aligned_common (stream, name, size, align) | |
1993 | FILE *stream; | |
1994 | const char *name; | |
1995 | int size; | |
1996 | int align; | |
1997 | { | |
1998 | /* This is mostly the elfos.h one. There doesn't seem to be a way to | |
1999 | express this in a mmixal-compatible way. */ | |
2000 | fprintf (stream, "\t.comm\t"); | |
2001 | assemble_name (stream, name); | |
2002 | fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n", | |
2003 | size, align / BITS_PER_UNIT); | |
2004 | } | |
2005 | ||
2006 | /* ASM_OUTPUT_ALIGNED_LOCAL. */ | |
2007 | ||
2008 | void | |
2009 | mmix_asm_output_aligned_local (stream, name, size, align) | |
2010 | FILE * stream; | |
2011 | const char * name; | |
2012 | int size; | |
2013 | int align; | |
2014 | { | |
2015 | data_section (); | |
2016 | ||
2017 | ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT)); | |
2018 | assemble_name (stream, name); | |
2019 | fprintf (stream, "\tLOC @+%d\n", size); | |
2020 | } | |
2021 | ||
2022 | /* ASM_OUTPUT_LABEL. */ | |
2023 | ||
2024 | void | |
2025 | mmix_asm_output_label (stream, name) | |
2026 | FILE *stream; | |
2027 | const char * name; | |
2028 | { | |
2029 | assemble_name (stream, name); | |
2030 | fprintf (stream, "\tIS @\n"); | |
2031 | } | |
2032 | ||
2033 | /* ASM_DECLARE_REGISTER_GLOBAL. */ | |
2034 | ||
2035 | void | |
2036 | mmix_asm_declare_register_global (stream, decl, regno, name) | |
2037 | FILE *stream ATTRIBUTE_UNUSED; | |
2038 | tree decl ATTRIBUTE_UNUSED; | |
2039 | int regno ATTRIBUTE_UNUSED; | |
2040 | const char *name ATTRIBUTE_UNUSED; | |
2041 | { | |
2042 | /* Nothing to do here, but there *will* be, therefore the framework is | |
2043 | here. */ | |
2044 | } | |
2045 | ||
2046 | /* ASM_GLOBALIZE_LABEL. */ | |
2047 | ||
2048 | void | |
2049 | mmix_asm_globalize_label (stream, name) | |
2050 | FILE * stream ATTRIBUTE_UNUSED; | |
2051 | const char * name ATTRIBUTE_UNUSED; | |
2052 | { | |
2053 | asm_fprintf (stream, "\t.global "); | |
2054 | assemble_name (stream, name); | |
2055 | putc ('\n', stream); | |
2056 | } | |
2057 | ||
2058 | /* ASM_WEAKEN_LABEL. */ | |
2059 | ||
2060 | void | |
2061 | mmix_asm_weaken_label (stream, name) | |
2062 | FILE * stream ATTRIBUTE_UNUSED; | |
2063 | const char * name ATTRIBUTE_UNUSED; | |
2064 | { | |
2065 | asm_fprintf (stream, "\t.weak "); | |
2066 | assemble_name (stream, name); | |
2067 | asm_fprintf (stream, " ! mmixal-incompatible\n"); | |
2068 | } | |
2069 | ||
2070 | /* MAKE_DECL_ONE_ONLY. */ | |
2071 | ||
2072 | void | |
2073 | mmix_make_decl_one_only (decl) | |
2074 | tree decl; | |
2075 | { | |
2076 | DECL_WEAK (decl) = 1; | |
2077 | } | |
2078 | ||
2079 | /* ASM_OUTPUT_LABELREF. | |
2080 | Strip GCC's '*' and our own '@'. No order is assumed. */ | |
2081 | ||
2082 | void | |
2083 | mmix_asm_output_labelref (stream, name) | |
2084 | FILE *stream; | |
2085 | const char *name; | |
2086 | { | |
2087 | int is_extern = 0; | |
2088 | ||
2089 | for (; (*name == '@' || *name == '*'); name++) | |
2090 | if (*name == '@') | |
2091 | is_extern = 1; | |
2092 | ||
2093 | asm_fprintf (stream, "%s%U%s", | |
2094 | is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "", | |
2095 | name); | |
2096 | } | |
2097 | ||
2098 | /* ASM_OUTPUT_INTERNAL_LABEL. */ | |
2099 | ||
2100 | void | |
2101 | mmix_asm_output_internal_label (stream, name, num) | |
2102 | FILE * stream; | |
2103 | const char * name; | |
2104 | int num; | |
2105 | { | |
2106 | fprintf (stream, "%s:%d\tIS @\n", name, num); | |
2107 | } | |
2108 | ||
2109 | /* ASM_OUTPUT_DEF. */ | |
2110 | ||
2111 | void | |
2112 | mmix_asm_output_def (stream, name, value) | |
2113 | FILE * stream; | |
2114 | const char * name; | |
2115 | const char * value; | |
2116 | { | |
2117 | assemble_name (stream, name); | |
2118 | fprintf (stream, "\tIS "); | |
2119 | assemble_name (stream, value); | |
2120 | fputc ('\n', stream); | |
2121 | } | |
2122 | ||
2123 | /* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */ | |
2124 | ||
2125 | void | |
2126 | mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo) | |
2127 | FILE *stream; | |
2128 | const char *symbol; | |
2129 | const char *hi; | |
2130 | const char *lo; | |
2131 | { | |
2132 | assemble_name (stream, symbol); | |
2133 | fprintf (stream, "\tIS\t"); | |
2134 | assemble_name (stream, hi); | |
2135 | fputc ('-', stream); | |
2136 | assemble_name (stream, lo); | |
2137 | fprintf (stream, "\n"); | |
2138 | } | |
2139 | ||
2140 | /* PRINT_OPERAND. */ | |
2141 | ||
2142 | void | |
2143 | mmix_print_operand (stream, x, code) | |
2144 | FILE * stream; | |
2145 | rtx x; | |
2146 | int code; | |
2147 | { | |
2148 | /* When we add support for different codes later, we can, when needed, | |
2149 | drop through to the main handler with a modified operand. */ | |
2150 | rtx modified_x = x; | |
2151 | ||
2152 | switch (code) | |
2153 | { | |
2154 | /* Unrelated codes are in alphabetic order. */ | |
2155 | ||
2156 | case 'B': | |
2157 | if (GET_CODE (x) != CONST_INT) | |
2158 | fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x); | |
2159 | fprintf (stream, "%d", (int) (INTVAL (x) & 0xff)); | |
2160 | return; | |
2161 | ||
2162 | case 'H': | |
2163 | /* Highpart. Must be general register, and not the last one, as | |
2164 | that one cannot be part of a consecutive register pair. */ | |
2165 | if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1) | |
2166 | internal_error ("MMIX Internal: Bad register: %d", REGNO (x)); | |
2167 | ||
2168 | /* This is big-endian, so the high-part is the first one. */ | |
2169 | fprintf (stream, "%s", reg_names[REGNO (x)]); | |
2170 | return; | |
2171 | ||
2172 | case 'L': | |
2173 | /* Lowpart. Must be CONST_INT or general register, and not the last | |
2174 | one, as that one cannot be part of a consecutive register pair. */ | |
2175 | if (GET_CODE (x) == CONST_INT) | |
2176 | { | |
2177 | fprintf (stream, "#%lx", | |
2178 | (unsigned long) (INTVAL (x) | |
2179 | & ((unsigned int) 0x7fffffff * 2 + 1))); | |
2180 | return; | |
2181 | } | |
2182 | ||
2183 | if (GET_CODE (x) == SYMBOL_REF) | |
2184 | { | |
2185 | output_addr_const (stream, x); | |
2186 | return; | |
2187 | } | |
2188 | ||
2189 | if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1) | |
2190 | internal_error ("MMIX Internal: Bad register: %d", REGNO (x)); | |
2191 | ||
2192 | /* This is big-endian, so the low-part is + 1. */ | |
2193 | fprintf (stream, "%s", reg_names[REGNO (x) + 1]); | |
2194 | return; | |
2195 | ||
2196 | /* Can't use 'a' because that's a generic modifier for address | |
2197 | output. */ | |
2198 | case 'A': | |
2199 | mmix_output_shiftvalue_op_from_str (stream, "ANDN", | |
2200 | ~(unsigned HOST_WIDEST_INT) | |
2201 | mmix_intval (x)); | |
2202 | return; | |
2203 | ||
2204 | case 'i': | |
2205 | mmix_output_shiftvalue_op_from_str (stream, "INC", | |
2206 | (unsigned HOST_WIDEST_INT) | |
2207 | mmix_intval (x)); | |
2208 | return; | |
2209 | ||
2210 | case 'o': | |
2211 | mmix_output_shiftvalue_op_from_str (stream, "OR", | |
2212 | (unsigned HOST_WIDEST_INT) | |
2213 | mmix_intval (x)); | |
2214 | return; | |
2215 | ||
2216 | case 's': | |
2217 | mmix_output_shiftvalue_op_from_str (stream, "SET", | |
2218 | (unsigned HOST_WIDEST_INT) | |
2219 | mmix_intval (x)); | |
2220 | return; | |
2221 | ||
2222 | case 'd': | |
2223 | case 'D': | |
2224 | mmix_output_condition (stream, x, (code == 'D')); | |
2225 | return; | |
2226 | ||
2227 | case 'e': | |
2228 | /* Output an extra "e" to make fcmpe, fune. */ | |
2229 | if (TARGET_FCMP_EPSILON) | |
2230 | fprintf (stream, "e"); | |
2231 | return; | |
2232 | ||
2233 | case 'm': | |
2234 | /* Output the number minus 1. */ | |
2235 | if (GET_CODE (x) != CONST_INT) | |
2236 | { | |
2237 | fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT", | |
2238 | x); | |
2239 | } | |
2240 | fprintf (stream, HOST_WIDEST_INT_PRINT_DEC, | |
2241 | (HOST_WIDEST_INT) (mmix_intval (x) - 1)); | |
2242 | return; | |
2243 | ||
2244 | case 'p': | |
2245 | /* Store the number of registers we want to save. This was setup | |
2246 | by the prologue. The actual operand contains the number of | |
2247 | registers to pass, but we don't use it currently. Anyway, we | |
2248 | need to output the number of saved registers here. */ | |
2249 | if (TARGET_ABI_GNU) | |
2250 | fprintf (stream, "%d", mmix_highest_saved_stack_register + 1); | |
2251 | else | |
2252 | /* FIXME: Get the effect of renaming $16, $17.. to the first | |
2253 | unused call-saved reg. */ | |
2254 | fprintf (stream, "15"); | |
2255 | return; | |
2256 | ||
2257 | case 'r': | |
2258 | /* Store the register to output a constant to. */ | |
2259 | if (! REG_P (x)) | |
2260 | fatal_insn ("MMIX Internal: Expected a register, not this.", x); | |
2261 | mmix_output_destination_register = REGNO (x); | |
2262 | return; | |
2263 | ||
2264 | case 'I': | |
2265 | /* Output the constant. Note that we use this for floats as well. */ | |
2266 | if (GET_CODE (x) != CONST_INT | |
2267 | && (GET_CODE (x) != CONST_DOUBLE | |
2268 | || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode | |
2269 | && GET_MODE (x) != SFmode))) | |
2270 | fatal_insn ("MMIX Internal: Expected a constant, not this.", x); | |
2271 | mmix_output_register_setting (stream, | |
2272 | mmix_output_destination_register, | |
2273 | mmix_intval (x), 0); | |
2274 | return; | |
2275 | ||
2276 | case 'U': | |
2277 | /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */ | |
2278 | if (TARGET_ZERO_EXTEND) | |
2279 | putc ('U', stream); | |
2280 | return; | |
2281 | ||
2282 | case 'v': | |
2283 | mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x)); | |
2284 | return; | |
2285 | ||
2286 | case 'V': | |
2287 | mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x)); | |
2288 | return; | |
2289 | ||
2290 | case 'W': | |
2291 | if (GET_CODE (x) != CONST_INT) | |
2292 | fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x); | |
2293 | fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff)); | |
2294 | return; | |
2295 | ||
2296 | case 0: | |
2297 | /* Nothing to do. */ | |
2298 | break; | |
2299 | ||
2300 | default: | |
2301 | /* Presumably there's a missing case above if we get here. */ | |
2302 | internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code); | |
2303 | } | |
2304 | ||
2305 | switch (GET_CODE (modified_x)) | |
2306 | { | |
2307 | case REG: | |
2308 | if (REGNO (modified_x) >= FIRST_PSEUDO_REGISTER) | |
2309 | internal_error ("MMIX Internal: Bad register: %d", REGNO (modified_x)); | |
2310 | fprintf (stream, "%s", reg_names[REGNO (modified_x)]); | |
2311 | return; | |
2312 | ||
2313 | case MEM: | |
2314 | output_address (XEXP (modified_x, 0)); | |
2315 | return; | |
2316 | ||
2317 | case CONST_INT: | |
2318 | /* For -2147483648, mmixal complains that the constant does not fit | |
2319 | in 4 bytes, so let's output it as hex. Take care to handle hosts | |
2320 | where HOST_WIDE_INT is longer than an int. | |
2321 | ||
2322 | Print small constants +-255 using decimal. */ | |
2323 | ||
2324 | if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256) | |
2325 | fprintf (stream, "%d", (int) (INTVAL (modified_x))); | |
2326 | else | |
2327 | fprintf (stream, "#%x", | |
2328 | (int) (INTVAL (modified_x)) & (unsigned int) ~0); | |
2329 | return; | |
2330 | ||
2331 | case CONST_DOUBLE: | |
2332 | /* Do somewhat as CONST_INT. */ | |
2333 | mmix_asm_output_double_int (stream, modified_x, 0); | |
2334 | return; | |
2335 | ||
2336 | case CONST: | |
2337 | output_addr_const (stream, modified_x); | |
2338 | return; | |
2339 | ||
2340 | default: | |
2341 | /* No need to test for all strange things. Let output_addr_const do | |
2342 | it for us. */ | |
2343 | if (CONSTANT_P (modified_x) | |
2344 | /* Strangely enough, this is not included in CONSTANT_P. | |
2345 | FIXME: Ask/check about sanity here. */ | |
2346 | || GET_CODE (modified_x) == CODE_LABEL) | |
2347 | { | |
2348 | output_addr_const (stream, modified_x); | |
2349 | return; | |
2350 | } | |
2351 | ||
2352 | /* We need the original here. */ | |
2353 | fatal_insn ("MMIX Internal: Cannot decode this operand", x); | |
2354 | } | |
2355 | } | |
2356 | ||
2357 | /* PRINT_OPERAND_PUNCT_VALID_P. */ | |
2358 | ||
2359 | int | |
2360 | mmix_print_operand_punct_valid_p (code) | |
2361 | int code ATTRIBUTE_UNUSED; | |
2362 | { | |
2363 | /* None at the moment. */ | |
2364 | return 0; | |
2365 | } | |
2366 | ||
2367 | /* PRINT_OPERAND_ADDRESS. */ | |
2368 | ||
2369 | void | |
2370 | mmix_print_operand_address (stream, x) | |
2371 | FILE *stream; | |
2372 | rtx x; | |
2373 | { | |
2374 | if (REG_P (x)) | |
2375 | { | |
2376 | /* I find the generated assembly code harder to read without | |
2377 | the ",0". */ | |
2378 | fprintf (stream, "%s,0",reg_names[REGNO (x)]); | |
2379 | return; | |
2380 | } | |
2381 | else if (GET_CODE (x) == PLUS) | |
2382 | { | |
2383 | rtx x1 = XEXP (x, 0); | |
2384 | rtx x2 = XEXP (x, 1); | |
2385 | ||
2386 | /* Try swap the order. FIXME: Do we need this? */ | |
2387 | if (! REG_P (x1)) | |
2388 | { | |
2389 | rtx tem = x1; | |
2390 | x1 = x2; | |
2391 | x2 = tem; | |
2392 | } | |
2393 | ||
2394 | if (REG_P (x1)) | |
2395 | { | |
2396 | fprintf (stream, "%s,", reg_names[REGNO (x1)]); | |
2397 | ||
2398 | if (REG_P (x2)) | |
2399 | { | |
2400 | fprintf (stream, "%s", reg_names[REGNO (x2)]); | |
2401 | return; | |
2402 | } | |
2403 | else if (GET_CODE (x2) == CONST_INT | |
2404 | && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I')) | |
2405 | { | |
2406 | output_addr_const (stream, x2); | |
2407 | return; | |
2408 | } | |
2409 | } | |
2410 | } | |
2411 | ||
2412 | fatal_insn ("MMIX Internal: This is not a recognized address", x); | |
2413 | } | |
2414 | ||
2415 | /* ASM_OUTPUT_REG_PUSH. */ | |
2416 | ||
2417 | void | |
2418 | mmix_asm_output_reg_push (stream, regno) | |
2419 | FILE * stream; | |
2420 | int regno; | |
2421 | { | |
2422 | fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n", | |
2423 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
2424 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
2425 | reg_names[regno], | |
2426 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
2427 | } | |
2428 | ||
2429 | /* ASM_OUTPUT_REG_POP. */ | |
2430 | ||
2431 | void | |
2432 | mmix_asm_output_reg_pop (stream, regno) | |
2433 | FILE * stream; | |
2434 | int regno; | |
2435 | { | |
2436 | fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n", | |
2437 | reg_names[regno], | |
2438 | reg_names[MMIX_STACK_POINTER_REGNUM], | |
2439 | reg_names[MMIX_STACK_POINTER_REGNUM]); | |
2440 | } | |
2441 | ||
2442 | /* ASM_OUTPUT_ADDR_DIFF_ELT. */ | |
2443 | ||
2444 | void | |
2445 | mmix_asm_output_addr_diff_elt (stream, body, value, rel) | |
2446 | FILE *stream; | |
2447 | rtx body ATTRIBUTE_UNUSED; | |
2448 | int value; | |
2449 | int rel; | |
2450 | { | |
2451 | fprintf (stream, "\tTETRA L%d-L%d\n", value, rel); | |
2452 | } | |
2453 | ||
2454 | /* ASM_OUTPUT_ADDR_VEC_ELT. */ | |
2455 | ||
2456 | void | |
2457 | mmix_asm_output_addr_vec_elt (stream, value) | |
2458 | FILE *stream; | |
2459 | int value; | |
2460 | { | |
2461 | fprintf (stream, "\tOCTA L:%d\n", value); | |
2462 | } | |
2463 | ||
2464 | /* ASM_OUTPUT_SKIP. */ | |
2465 | ||
2466 | void | |
2467 | mmix_asm_output_skip (stream, nbytes) | |
2468 | FILE *stream; | |
2469 | int nbytes; | |
2470 | { | |
2471 | fprintf (stream, "\tLOC @+%d\n", nbytes); | |
2472 | } | |
2473 | ||
2474 | /* ASM_OUTPUT_ALIGN. */ | |
2475 | ||
2476 | void | |
2477 | mmix_asm_output_align (stream, power) | |
2478 | FILE *stream; | |
2479 | int power; | |
2480 | { | |
2481 | /* We need to record the needed alignment of this section in the object, | |
2482 | so we have to output an alignment directive. Use a .p2align (not | |
2483 | .align) so people will never have to wonder about whether the | |
2484 | argument is in number of bytes or the log2 thereof. We do it in | |
2485 | addition to the LOC directive, so nothing needs tweaking when | |
2486 | copy-pasting assembly into mmixal. */ | |
2487 | fprintf (stream, "\t.p2align %d\n", power); | |
2488 | fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1); | |
2489 | } | |
2490 | ||
2491 | /* DBX_REGISTER_NUMBER. */ | |
2492 | ||
2493 | int | |
2494 | mmix_dbx_register_number (regno) | |
2495 | int regno; | |
2496 | { | |
2497 | /* FIXME: Implement final register renumbering if necessary. (Use | |
2498 | target state in cfun). */ | |
2499 | ||
2500 | /* We need to renumber registers to get the number of the return address | |
2501 | register in the range 0..255. It is also space-saving if registers | |
2502 | mentioned in the call-frame information (which uses this function by | |
2503 | defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered | |
2504 | 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */ | |
2505 | return regno >= 224 ? (regno - 224) : (regno + 48); | |
2506 | } | |
2507 | ||
35a3065a | 2508 | /* End of target macro support functions. |
68cbb7e3 | 2509 | |
2510 | Now MMIX's own functions. First the exported ones. */ | |
2511 | ||
2512 | /* Output an optimal sequence for setting a register to a specific | |
2513 | constant. Used in an alternative for const_ints in movdi, and when | |
2514 | using large stack-frame offsets. | |
2515 | ||
2516 | Use do_begin_end to say if a line-starting TAB and newline before the | |
2517 | first insn and after the last insn is wanted. */ | |
2518 | ||
2519 | void | |
2520 | mmix_output_register_setting (stream, regno, value, do_begin_end) | |
2521 | FILE *stream; | |
2522 | int regno; | |
2523 | HOST_WIDEST_INT value; | |
2524 | int do_begin_end; | |
2525 | { | |
2526 | if (do_begin_end) | |
2527 | fprintf (stream, "\t"); | |
2528 | ||
2529 | if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value)) | |
2530 | { | |
2531 | /* First, the one-insn cases. */ | |
2532 | mmix_output_shiftvalue_op_from_str (stream, "SET", | |
2533 | (unsigned HOST_WIDEST_INT) | |
2534 | value); | |
2535 | fprintf (stream, " %s,", reg_names[regno]); | |
2536 | mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value); | |
2537 | } | |
2538 | else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value)) | |
2539 | { | |
2540 | /* We do this to get a bit more legible assembly code. The next | |
2541 | alternative is mostly redundant with this. */ | |
2542 | ||
2543 | mmix_output_shiftvalue_op_from_str (stream, "SET", | |
2544 | -(unsigned HOST_WIDEST_INT) | |
2545 | value); | |
2546 | fprintf (stream, " %s,", reg_names[regno]); | |
2547 | mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value); | |
2548 | fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno], | |
2549 | reg_names[regno]); | |
2550 | } | |
2551 | else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value)) | |
2552 | { | |
2553 | /* Slightly more expensive, the two-insn cases. */ | |
2554 | ||
2555 | /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255) | |
2556 | is shiftable, or any other one-insn transformation of the value. | |
2557 | FIXME: Check first if the value is "shiftable" by two loading | |
2558 | with two insns, since it makes more readable assembly code (if | |
2559 | anyone else cares). */ | |
2560 | ||
2561 | mmix_output_shiftvalue_op_from_str (stream, "SET", | |
2562 | ~(unsigned HOST_WIDEST_INT) | |
2563 | value); | |
2564 | fprintf (stream, " %s,", reg_names[regno]); | |
2565 | mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value); | |
2566 | fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno], | |
2567 | reg_names[regno]); | |
2568 | } | |
2569 | else | |
2570 | { | |
2571 | /* The generic case. 2..4 insns. */ | |
25037517 | 2572 | static const char *const higher_parts[] = {"L", "ML", "MH", "H"}; |
68cbb7e3 | 2573 | const char *op = "SET"; |
2574 | const char *line_begin = ""; | |
2575 | int i; | |
2576 | ||
2577 | /* Output pertinent parts of the 4-wyde sequence. | |
2578 | Still more to do if we want this to be optimal, but hey... | |
2579 | Note that the zero case has been handled above. */ | |
2580 | for (i = 0; i < 4 && value != 0; i++) | |
2581 | { | |
2582 | if (value & 65535) | |
2583 | { | |
2584 | fprintf (stream, "%s%s%s %s,#%x", line_begin, op, | |
2585 | higher_parts[i], reg_names[regno], | |
2586 | (int) (value & 65535)); | |
2587 | /* The first one sets the rest of the bits to 0, the next | |
2588 | ones add set bits. */ | |
2589 | op = "INC"; | |
2590 | line_begin = "\n\t"; | |
2591 | } | |
2592 | ||
2593 | value >>= 16; | |
2594 | } | |
2595 | } | |
2596 | ||
2597 | if (do_begin_end) | |
2598 | fprintf (stream, "\n"); | |
2599 | } | |
2600 | ||
2601 | /* Return 1 if value is 0..65535*2**(16*N) for N=0..3. | |
2602 | else return 0. */ | |
2603 | ||
2604 | int | |
2605 | mmix_shiftable_wyde_value (value) | |
2606 | unsigned HOST_WIDEST_INT value; | |
2607 | { | |
2608 | /* Shift by 16 bits per group, stop when we've found two groups with | |
2609 | nonzero bits. */ | |
2610 | int i; | |
2611 | int has_candidate = 0; | |
2612 | ||
2613 | for (i = 0; i < 4; i++) | |
2614 | { | |
2615 | if (value & 65535) | |
2616 | { | |
2617 | if (has_candidate) | |
2618 | return 0; | |
2619 | else | |
2620 | has_candidate = 1; | |
2621 | } | |
2622 | ||
2623 | value >>= 16; | |
2624 | } | |
2625 | ||
2626 | return 1; | |
2627 | } | |
2628 | ||
2629 | /* True if this is an address_operand or a symbolic operand. */ | |
2630 | ||
2631 | int | |
2632 | mmix_symbolic_or_address_operand (op, mode) | |
2633 | rtx op; | |
2634 | enum machine_mode mode; | |
2635 | { | |
2636 | switch (GET_CODE (op)) | |
2637 | { | |
2638 | case SYMBOL_REF: | |
2639 | case LABEL_REF: | |
2640 | return 1; | |
2641 | case CONST: | |
2642 | op = XEXP (op, 0); | |
2643 | if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
2644 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
2645 | && (GET_CODE (XEXP (op, 1)) == CONST_INT | |
2646 | || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE | |
2647 | && GET_MODE (XEXP (op, 1)) == VOIDmode))) | |
2648 | return 1; | |
2649 | /* FALLTHROUGH */ | |
2650 | default: | |
2651 | return address_operand (op, mode); | |
2652 | } | |
2653 | } | |
2654 | ||
2655 | /* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode). | |
2656 | We could narrow the value down with a couple of predicated, but that | |
2657 | doesn't seem to be worth it at the moment. */ | |
2658 | ||
2659 | int | |
2660 | mmix_reg_or_constant_operand (op, mode) | |
2661 | rtx op; | |
2662 | enum machine_mode mode; | |
2663 | { | |
2664 | return register_operand (op, mode) | |
2665 | || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode) | |
2666 | || GET_CODE (op) == CONST_INT; | |
2667 | } | |
2668 | ||
2669 | /* True if this is a register with a condition-code mode. */ | |
2670 | ||
2671 | int | |
2672 | mmix_reg_cc_operand (op, mode) | |
2673 | rtx op; | |
2674 | enum machine_mode mode; | |
2675 | { | |
2676 | if (mode == VOIDmode) | |
2677 | mode = GET_MODE (op); | |
2678 | ||
2679 | return register_operand (op, mode) | |
2680 | && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode | |
2681 | || mode == CC_FPEQmode || mode == CC_FUNmode); | |
2682 | } | |
2683 | ||
2684 | /* True if this is a foldable comparison operator | |
2685 | - one where a the result of (compare:CC (reg) (const_int 0)) can be | |
2686 | replaced by (reg). */ | |
2687 | ||
2688 | int | |
2689 | mmix_foldable_comparison_operator (op, mode) | |
2690 | rtx op; | |
2691 | enum machine_mode mode; | |
2692 | { | |
2693 | RTX_CODE code = GET_CODE (op); | |
2694 | ||
2695 | if (mode == VOIDmode) | |
2696 | mode = GET_MODE (op); | |
2697 | ||
2698 | if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<') | |
2699 | mode = GET_MODE (XEXP (op, 0)); | |
2700 | ||
2701 | return ((mode == CCmode || mode == DImode) | |
2702 | && (code == NE || code == EQ || code == GE || code == GT | |
2703 | || code == LE)) | |
2704 | /* FIXME: This may be a stupid trick. What happens when GCC wants to | |
2705 | reverse the condition? Can it do that by itself? Maybe it can | |
2706 | even reverse the condition to fit a foldable one in the first | |
2707 | place? */ | |
2708 | || (mode == CC_UNSmode && (code == GTU || code == LEU)); | |
2709 | } | |
2710 | ||
2711 | /* Like comparison_operator, but only true if this comparison operator is | |
2712 | applied to a valid mode. Needed to avoid jump.c generating invalid | |
2713 | code with -ffast-math (gcc.dg/20001228-1.c). */ | |
2714 | ||
2715 | int | |
2716 | mmix_comparison_operator (op, mode) | |
2717 | rtx op; | |
2718 | enum machine_mode mode; | |
2719 | { | |
2720 | RTX_CODE code = GET_CODE (op); | |
2721 | ||
2722 | /* Comparison operators usually don't have a mode, but let's try and get | |
2723 | one anyway for the day that changes. */ | |
2724 | if (mode == VOIDmode) | |
2725 | mode = GET_MODE (op); | |
2726 | ||
2727 | /* Get the mode from the first operand if we don't have one. */ | |
2728 | if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<') | |
2729 | mode = GET_MODE (XEXP (op, 0)); | |
2730 | ||
2731 | /* FIXME: This needs to be kept in sync with the tables in | |
2732 | mmix_output_condition. */ | |
2733 | return | |
2734 | (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<') | |
2735 | || (mode == CC_FUNmode | |
2736 | && (code == ORDERED || code == UNORDERED)) | |
2737 | || (mode == CC_FPmode | |
2738 | && (code == GT || code == LT)) | |
2739 | || (mode == CC_FPEQmode | |
2740 | && (code == NE || code == EQ)) | |
2741 | || (mode == CC_UNSmode | |
2742 | && (code == GEU || code == GTU || code == LEU || code == LTU)) | |
2743 | || (mode == CCmode | |
2744 | && (code == NE || code == EQ || code == GE || code == GT | |
2745 | || code == LE || code == LT)) | |
2746 | || (mode == DImode | |
2747 | && (code == NE || code == EQ || code == GE || code == GT | |
2748 | || code == LE || code == LT || code == LEU || code == GTU)); | |
2749 | } | |
2750 | ||
2751 | /* True if this is a register or 0 (int or float). */ | |
2752 | ||
2753 | int | |
2754 | mmix_reg_or_0_operand (op, mode) | |
2755 | rtx op; | |
2756 | enum machine_mode mode; | |
2757 | { | |
2758 | /* FIXME: Is mode calculation necessary and correct? */ | |
2759 | return | |
2760 | op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode) | |
2761 | || register_operand (op, mode); | |
2762 | } | |
2763 | ||
2764 | /* True if this is a register or an int 0..255. */ | |
2765 | ||
2766 | int | |
2767 | mmix_reg_or_8bit_operand (op, mode) | |
2768 | rtx op; | |
2769 | enum machine_mode mode; | |
2770 | { | |
2771 | return register_operand (op, mode) | |
2772 | || (GET_CODE (op) == CONST_INT | |
2773 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
2774 | } | |
2775 | ||
2776 | /* True if this is a register or an int 0..256. We include 256, | |
2777 | because it can be canonicalized into 255 for comparisons, which is | |
2778 | currently the only use of this predicate. | |
2779 | FIXME: Check that this happens and does TRT. */ | |
2780 | ||
2781 | int | |
2782 | mmix_reg_or_8bit_or_256_operand (op, mode) | |
2783 | rtx op; | |
2784 | enum machine_mode mode; | |
2785 | { | |
2786 | return mmix_reg_or_8bit_operand (op, mode) | |
2787 | || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256); | |
2788 | } | |
2789 | ||
2790 | /* Returns zero if code and mode is not a valid condition from a | |
2791 | compare-type insn. Nonzero if it is. The parameter op, if non-NULL, | |
2792 | is the comparison of mode is CC-somethingmode. */ | |
2793 | ||
2794 | int | |
2795 | mmix_valid_comparison (code, mode, op) | |
2796 | RTX_CODE code; | |
2797 | enum machine_mode mode; | |
2798 | rtx op; | |
2799 | { | |
2800 | if (mode == VOIDmode && op != NULL_RTX) | |
2801 | mode = GET_MODE (op); | |
2802 | ||
2803 | /* We don't care to look at these, they should always be valid. */ | |
2804 | if (mode == CCmode || mode == CC_UNSmode || mode == DImode) | |
2805 | return 1; | |
2806 | ||
2807 | if ((mode == CC_FPmode || mode == DFmode) | |
2808 | && (code == GT || code == LT)) | |
2809 | return 1; | |
2810 | ||
2811 | if ((mode == CC_FPEQmode || mode == DFmode) | |
2812 | && (code == EQ || code == NE)) | |
2813 | return 1; | |
2814 | ||
2815 | if ((mode == CC_FUNmode || mode == DFmode) | |
2816 | && (code == ORDERED || code == UNORDERED)) | |
2817 | return 1; | |
2818 | ||
2819 | return 0; | |
2820 | } | |
2821 | ||
2822 | /* X and Y are two things to compare using CODE. Emit a compare insn if | |
2823 | possible and return the rtx for the cc-reg in the proper mode, or | |
2824 | NULL_RTX if this is not a valid comparison. */ | |
2825 | ||
2826 | rtx | |
2827 | mmix_gen_compare_reg (code, x, y) | |
2828 | RTX_CODE code; | |
2829 | rtx x, y; | |
2830 | { | |
2831 | enum machine_mode ccmode = SELECT_CC_MODE (code, x, y); | |
2832 | rtx cc_reg; | |
2833 | ||
2834 | /* FIXME: Do we get constants here? Of double mode? */ | |
2835 | enum machine_mode mode | |
2836 | = GET_MODE (x) == VOIDmode | |
2837 | ? GET_MODE (y) | |
2838 | : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode; | |
2839 | ||
2840 | if (! mmix_valid_comparison (code, mode, x)) | |
2841 | return NULL_RTX; | |
2842 | ||
2843 | cc_reg = gen_reg_rtx (ccmode); | |
2844 | ||
2845 | /* FIXME: Can we avoid emitting a compare insn here? */ | |
2846 | if (! REG_P (x) && ! REG_P (y)) | |
2847 | x = force_reg (mode, x); | |
2848 | ||
2849 | CANONICALIZE_COMPARISON (code, x, y); | |
2850 | ||
2851 | /* If it's not quite right yet, put y in a register. */ | |
2852 | if (! REG_P (y) | |
2853 | && (GET_CODE (y) != CONST_INT | |
2854 | || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I'))) | |
2855 | y = force_reg (mode, y); | |
2856 | ||
2857 | emit_insn (gen_rtx_SET (VOIDmode, cc_reg, | |
2858 | gen_rtx_COMPARE (ccmode, x, y))); | |
2859 | ||
2860 | return cc_reg; | |
2861 | } | |
2862 | ||
2863 | /* Local (static) helper functions. */ | |
2864 | ||
2865 | /* Print operator suitable for doing something with a shiftable | |
2866 | wyde. The type of operator is passed as a asm output modifier. */ | |
2867 | ||
2868 | static void | |
2869 | mmix_output_shiftvalue_op_from_str (stream, mainop, value) | |
2870 | FILE *stream; | |
2871 | const char *mainop; | |
2872 | HOST_WIDEST_INT value; | |
2873 | { | |
25037517 | 2874 | static const char *const op_part[] = {"L", "ML", "MH", "H"}; |
68cbb7e3 | 2875 | int i; |
2876 | ||
2877 | if (! mmix_shiftable_wyde_value (value)) | |
2878 | { | |
2879 | char s[sizeof ("0xffffffffffffffff")]; | |
2880 | sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value); | |
2881 | internal_error ("MMIX Internal: %s is not a shiftable int", s); | |
2882 | } | |
2883 | ||
2884 | for (i = 0; i < 4; i++) | |
2885 | { | |
2886 | /* We know we're through when we find one-bits in the low | |
2887 | 16 bits. */ | |
2888 | if (value & 0xffff) | |
2889 | { | |
2890 | fprintf (stream, "%s%s", mainop, op_part[i]); | |
2891 | return; | |
2892 | } | |
2893 | value >>= 16; | |
2894 | } | |
2895 | ||
2896 | /* No bits set? Then it must have been zero. */ | |
2897 | fprintf (stream, "%sL", mainop); | |
2898 | } | |
2899 | ||
2900 | /* Print a 64-bit value, optionally prefixed by assembly pseudo. */ | |
2901 | ||
2902 | static void | |
2903 | mmix_output_octa (stream, value, do_begin_end) | |
2904 | FILE *stream; | |
2905 | HOST_WIDEST_INT value; | |
2906 | int do_begin_end; | |
2907 | { | |
2908 | /* Snipped from final.c:output_addr_const. We need to avoid the | |
2909 | presumed universal "0x" prefix. We can do it by replacing "0x" with | |
2910 | "#0" here; we must avoid a space in the operands and no, the zero | |
2911 | won't cause the number to be assumed in octal format. */ | |
2912 | char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)]; | |
2913 | ||
2914 | if (do_begin_end) | |
2915 | fprintf (stream, "\tOCTA "); | |
2916 | ||
2917 | strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX); | |
2918 | hex_format[0] = '#'; | |
2919 | hex_format[1] = '0'; | |
2920 | ||
2921 | /* Provide a few alternative output formats depending on the number, to | |
2922 | improve legibility of assembler output. */ | |
2923 | if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000) | |
2924 | || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384)) | |
2925 | fprintf (stream, "%d", (int) value); | |
2926 | else if (value > (HOST_WIDEST_INT) 0 | |
2927 | && value < ((HOST_WIDEST_INT) 1 << 31) * 2) | |
2928 | fprintf (stream, "#%x", (unsigned int) value); | |
2929 | else | |
2930 | fprintf (stream, hex_format, value); | |
2931 | ||
2932 | if (do_begin_end) | |
2933 | fprintf (stream, "\n"); | |
2934 | } | |
2935 | ||
2936 | /* Print the presumed shiftable wyde argument shifted into place (to | |
2937 | be output with an operand). */ | |
2938 | ||
2939 | static void | |
2940 | mmix_output_shifted_value (stream, value) | |
2941 | FILE * stream; | |
2942 | HOST_WIDEST_INT value; | |
2943 | { | |
2944 | int i; | |
2945 | ||
2946 | if (! mmix_shiftable_wyde_value (value)) | |
2947 | { | |
2948 | char s[16+2+1]; | |
2949 | sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value); | |
2950 | internal_error ("MMIX Internal: %s is not a shiftable int", s); | |
2951 | } | |
2952 | ||
2953 | for (i = 0; i < 4; i++) | |
2954 | { | |
2955 | /* We know we're through when we find one-bits in the low 16 bits. */ | |
2956 | if (value & 0xffff) | |
2957 | { | |
2958 | fprintf (stream, "#%x", (int) (value & 0xffff)); | |
2959 | return; | |
2960 | } | |
2961 | ||
2962 | value >>= 16; | |
2963 | } | |
2964 | ||
2965 | /* No bits set? Then it must have been zero. */ | |
2966 | fprintf (stream, "0"); | |
2967 | } | |
2968 | ||
2969 | /* Output an MMIX condition name corresponding to an operator | |
2970 | and operands: | |
2971 | (comparison_operator [(comparison_operator ...) (const_int 0)]) | |
2972 | which means we have to look at *two* operators. | |
2973 | ||
2974 | The argument "reversed" refers to reversal of the condition (not the | |
2975 | same as swapping the arguments). */ | |
2976 | ||
2977 | static void | |
2978 | mmix_output_condition (stream, x, reversed) | |
2979 | FILE *stream; | |
2980 | rtx x; | |
2981 | int reversed; | |
2982 | { | |
2983 | struct cc_conv | |
2984 | { | |
2985 | RTX_CODE cc; | |
2986 | ||
2987 | /* The normal output cc-code. */ | |
2988 | const char *const normal; | |
2989 | ||
2990 | /* The reversed cc-code, or NULL if invalid. */ | |
2991 | const char *const reversed; | |
2992 | }; | |
2993 | ||
2994 | struct cc_type_conv | |
2995 | { | |
2996 | enum machine_mode cc_mode; | |
2997 | ||
2998 | /* Terminated with {NIL, NULL, NULL} */ | |
2999 | const struct cc_conv *const convs; | |
3000 | }; | |
3001 | ||
3002 | #undef CCEND | |
3003 | #define CCEND {NIL, NULL, NULL} | |
3004 | ||
3005 | static const struct cc_conv cc_fun_convs[] | |
3006 | = {{ORDERED, "Z", "P"}, | |
3007 | {UNORDERED, "P", "Z"}, | |
3008 | CCEND}; | |
3009 | static const struct cc_conv cc_fp_convs[] | |
3010 | = {{GT, "P", NULL}, | |
3011 | {LT, "N", NULL}, | |
3012 | CCEND}; | |
3013 | static const struct cc_conv cc_fpeq_convs[] | |
3014 | = {{NE, "Z", "P"}, | |
3015 | {EQ, "P", "Z"}, | |
3016 | CCEND}; | |
3017 | static const struct cc_conv cc_uns_convs[] | |
3018 | = {{GEU, "NN", "N"}, | |
3019 | {GTU, "P", "NP"}, | |
3020 | {LEU, "NP", "P"}, | |
3021 | {LTU, "N", "NN"}, | |
3022 | CCEND}; | |
3023 | static const struct cc_conv cc_signed_convs[] | |
3024 | = {{NE, "NZ", "Z"}, | |
3025 | {EQ, "Z", "NZ"}, | |
3026 | {GE, "NN", "N"}, | |
3027 | {GT, "P", "NP"}, | |
3028 | {LE, "NP", "P"}, | |
3029 | {LT, "N", "NN"}, | |
3030 | CCEND}; | |
3031 | static const struct cc_conv cc_di_convs[] | |
3032 | = {{NE, "NZ", "Z"}, | |
3033 | {EQ, "Z", "NZ"}, | |
3034 | {GE, "NN", "N"}, | |
3035 | {GT, "P", "NP"}, | |
3036 | {LE, "NP", "P"}, | |
3037 | {LT, "N", "NN"}, | |
3038 | {GTU, "NZ", "Z"}, | |
3039 | {LEU, "Z", "NZ"}, | |
3040 | CCEND}; | |
3041 | #undef CCEND | |
3042 | ||
3043 | static const struct cc_type_conv cc_convs[] | |
3044 | = {{CC_FUNmode, cc_fun_convs}, | |
3045 | {CC_FPmode, cc_fp_convs}, | |
3046 | {CC_FPEQmode, cc_fpeq_convs}, | |
3047 | {CC_UNSmode, cc_uns_convs}, | |
3048 | {CCmode, cc_signed_convs}, | |
3049 | {DImode, cc_di_convs}}; | |
3050 | ||
3051 | unsigned int i; | |
3052 | int j; | |
3053 | ||
3054 | enum machine_mode mode = GET_MODE (XEXP (x, 0)); | |
3055 | RTX_CODE cc = GET_CODE (x); | |
3056 | ||
3057 | for (i = 0; i < sizeof (cc_convs)/sizeof(*cc_convs); i++) | |
3058 | { | |
3059 | if (mode == cc_convs[i].cc_mode) | |
3060 | { | |
3061 | for (j = 0; cc_convs[i].convs[j].cc != NIL; j++) | |
3062 | if (cc == cc_convs[i].convs[j].cc) | |
3063 | { | |
3064 | const char *mmix_cc | |
3065 | = (reversed ? cc_convs[i].convs[j].reversed | |
3066 | : cc_convs[i].convs[j].normal); | |
3067 | ||
3068 | if (mmix_cc == NULL) | |
3069 | fatal_insn ("MMIX Internal: Trying to output invalidly\ | |
3070 | reversed condition:", x); | |
3071 | ||
3072 | fprintf (stream, "%s", mmix_cc); | |
3073 | return; | |
3074 | } | |
3075 | ||
3076 | fatal_insn ("MMIX Internal: What's the CC of this?", x); | |
3077 | } | |
3078 | } | |
3079 | ||
3080 | fatal_insn ("MMIX Internal: What is the CC of this?", x); | |
3081 | } | |
3082 | ||
3083 | /* Return the bit-value for a const_int or const_double. */ | |
3084 | ||
3085 | static HOST_WIDEST_INT | |
3086 | mmix_intval (x) | |
3087 | rtx x; | |
3088 | { | |
3089 | unsigned HOST_WIDEST_INT retval; | |
3090 | ||
3091 | if (GET_CODE (x) == CONST_INT) | |
3092 | return INTVAL (x); | |
3093 | ||
3094 | /* We make a little song and dance because converting to long long in | |
3095 | gcc-2.7.2 is broken. I still want people to be able to use it for | |
3096 | cross-compilation to MMIX. */ | |
3097 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode) | |
3098 | { | |
3099 | if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT)) | |
3100 | { | |
3101 | retval = (unsigned) CONST_DOUBLE_LOW (x) / 2; | |
3102 | retval *= 2; | |
3103 | retval |= CONST_DOUBLE_LOW (x) & 1; | |
3104 | ||
3105 | retval |= | |
3106 | (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x) | |
3107 | << (HOST_BITS_PER_LONG); | |
3108 | } | |
3109 | else | |
3110 | retval = CONST_DOUBLE_HIGH (x); | |
3111 | ||
3112 | return retval; | |
3113 | } | |
3114 | ||
3115 | if (GET_CODE (x) == CONST_DOUBLE) | |
3116 | { | |
3117 | REAL_VALUE_TYPE value; | |
3118 | ||
3119 | /* FIXME: This macro is not in the manual but should be. */ | |
3120 | REAL_VALUE_FROM_CONST_DOUBLE (value, x); | |
3121 | ||
3122 | if (GET_MODE (x) == DFmode) | |
3123 | { | |
3124 | long bits[2]; | |
dc8dc4ce | 3125 | |
68cbb7e3 | 3126 | REAL_VALUE_TO_TARGET_DOUBLE (value, bits); |
3127 | ||
3128 | if (sizeof (long) < sizeof (HOST_WIDEST_INT)) | |
3129 | { | |
3130 | retval = (unsigned long) bits[1] / 2; | |
3131 | retval *= 2; | |
3132 | retval |= (unsigned long) bits[1] & 1; | |
3133 | retval | |
3134 | |= (unsigned HOST_WIDEST_INT) bits[0] | |
3135 | << (sizeof (bits[0]) * 8); | |
3136 | } | |
3137 | else | |
3138 | retval = (unsigned long) bits[1]; | |
3139 | ||
3140 | return retval; | |
3141 | } | |
3142 | else if (GET_MODE (x) == SFmode) | |
3143 | { | |
3144 | long bits; | |
3145 | REAL_VALUE_TO_TARGET_SINGLE (value, bits); | |
3146 | ||
3147 | return (unsigned long) bits; | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | fatal_insn ("MMIX Internal: This is not a constant:", x); | |
3152 | } | |
3153 | ||
3154 | /* | |
3155 | * Local variables: | |
3156 | * eval: (c-set-style "gnu") | |
3157 | * indent-tabs-mode: t | |
3158 | * End: | |
3159 | */ |