]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/mmix/mmix.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / mmix / mmix.c
1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
4
5 This file is part of GCC.
6
7 GCC 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 3, or (at your option)
10 any later version.
11
12 GCC 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 GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "target.h"
26 #include "rtl.h"
27 #include "tree.h"
28 #include "df.h"
29 #include "memmodel.h"
30 #include "tm_p.h"
31 #include "insn-config.h"
32 #include "regs.h"
33 #include "emit-rtl.h"
34 #include "recog.h"
35 #include "diagnostic-core.h"
36 #include "output.h"
37 #include "varasm.h"
38 #include "stor-layout.h"
39 #include "calls.h"
40 #include "explow.h"
41 #include "expr.h"
42 #include "dwarf2.h"
43 #include "tm-constrs.h"
44 #include "builtins.h"
45
46 /* This file should be included last. */
47 #include "target-def.h"
48
49 /* First some local helper definitions. */
50 #define MMIX_FIRST_GLOBAL_REGNUM 32
51
52 /* We'd need a current_function_has_landing_pad. It's marked as such when
53 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
54 mostly. */
55 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
56
57 /* We have no means to tell DWARF 2 about the register stack, so we need
58 to store the return address on the stack if an exception can get into
59 this function. FIXME: Narrow condition. Before any whole-function
60 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
61 after reload_completed; it may contain incorrect information some time
62 before that. Within a RTL sequence (after a call to start_sequence,
63 such as in RTL expanders), leaf_function_p doesn't see all insns
64 (perhaps any insn). But regs_ever_live is up-to-date when
65 leaf_function_p () isn't, so we "or" them together to get accurate
66 information. FIXME: Some tweak to leaf_function_p might be
67 preferable. */
68 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
69 (flag_exceptions \
70 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
71 || !leaf_function_p ()))
72
73 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
74 (crtl->calls_eh_return \
75 && (EH_RETURN_DATA_REGNO (0) == REGNO \
76 || EH_RETURN_DATA_REGNO (1) == REGNO \
77 || EH_RETURN_DATA_REGNO (2) == REGNO \
78 || EH_RETURN_DATA_REGNO (3) == REGNO))
79
80 /* For the default ABI, we rename registers at output-time to fill the gap
81 between the (statically partitioned) saved registers and call-clobbered
82 registers. In effect this makes unused call-saved registers to be used
83 as call-clobbered registers. The benefit comes from keeping the number
84 of local registers (value of rL) low, since there's a cost of
85 increasing rL and clearing unused (unset) registers with lower numbers.
86 Don't translate while outputting the prologue. */
87 #define MMIX_OUTPUT_REGNO(N) \
88 (TARGET_ABI_GNU \
89 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
90 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
91 || cfun == NULL \
92 || cfun->machine == NULL \
93 || cfun->machine->in_prologue \
94 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
95 + cfun->machine->highest_saved_stack_register + 1))
96
97 /* The %d in "POP %d,0". */
98 #define MMIX_POP_ARGUMENT() \
99 ((! TARGET_ABI_GNU \
100 && crtl->return_rtx != NULL \
101 && ! cfun->returns_struct) \
102 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
103 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
104 : 0)
105
106 /* The canonical saved comparison operands for non-cc0 machines, set in
107 the compare expander. */
108 rtx mmix_compare_op0;
109 rtx mmix_compare_op1;
110
111 /* Declarations of locals. */
112
113 /* Intermediate for insn output. */
114 static int mmix_output_destination_register;
115
116 static void mmix_option_override (void);
117 static void mmix_asm_output_source_filename (FILE *, const char *);
118 static void mmix_output_shiftvalue_op_from_str
119 (FILE *, const char *, int64_t);
120 static void mmix_output_shifted_value (FILE *, int64_t);
121 static void mmix_output_condition (FILE *, const_rtx, int);
122 static void mmix_output_octa (FILE *, int64_t, int);
123 static bool mmix_assemble_integer (rtx, unsigned int, int);
124 static struct machine_function *mmix_init_machine_status (void);
125 static void mmix_encode_section_info (tree, rtx, int);
126 static const char *mmix_strip_name_encoding (const char *);
127 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
128 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
129 static void mmix_target_asm_function_end_prologue (FILE *);
130 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
131 static reg_class_t mmix_preferred_reload_class (rtx, reg_class_t);
132 static reg_class_t mmix_preferred_output_reload_class (rtx, reg_class_t);
133 static bool mmix_legitimate_address_p (machine_mode, rtx, bool);
134 static bool mmix_legitimate_constant_p (machine_mode, rtx);
135 static void mmix_reorg (void);
136 static void mmix_asm_output_mi_thunk
137 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
138 static void mmix_setup_incoming_varargs
139 (cumulative_args_t, machine_mode, tree, int *, int);
140 static void mmix_file_start (void);
141 static void mmix_file_end (void);
142 static bool mmix_rtx_costs (rtx, machine_mode, int, int, int *, bool);
143 static int mmix_register_move_cost (machine_mode,
144 reg_class_t, reg_class_t);
145 static rtx mmix_struct_value_rtx (tree, int);
146 static machine_mode mmix_promote_function_mode (const_tree,
147 machine_mode,
148 int *, const_tree, int);
149 static void mmix_function_arg_advance (cumulative_args_t, machine_mode,
150 const_tree, bool);
151 static rtx mmix_function_arg_1 (const cumulative_args_t, machine_mode,
152 const_tree, bool, bool);
153 static rtx mmix_function_incoming_arg (cumulative_args_t, machine_mode,
154 const_tree, bool);
155 static rtx mmix_function_arg (cumulative_args_t, machine_mode,
156 const_tree, bool);
157 static rtx mmix_function_value (const_tree, const_tree, bool);
158 static rtx mmix_libcall_value (machine_mode, const_rtx);
159 static bool mmix_function_value_regno_p (const unsigned int);
160 static bool mmix_pass_by_reference (cumulative_args_t,
161 machine_mode, const_tree, bool);
162 static bool mmix_frame_pointer_required (void);
163 static void mmix_asm_trampoline_template (FILE *);
164 static void mmix_trampoline_init (rtx, tree, rtx);
165 static void mmix_print_operand (FILE *, rtx, int);
166 static void mmix_print_operand_address (FILE *, machine_mode, rtx);
167 static bool mmix_print_operand_punct_valid_p (unsigned char);
168 static void mmix_conditional_register_usage (void);
169
170 /* Target structure macros. Listed by node. See `Using and Porting GCC'
171 for a general description. */
172
173 /* Node: Function Entry */
174
175 #undef TARGET_ASM_BYTE_OP
176 #define TARGET_ASM_BYTE_OP NULL
177 #undef TARGET_ASM_ALIGNED_HI_OP
178 #define TARGET_ASM_ALIGNED_HI_OP NULL
179 #undef TARGET_ASM_ALIGNED_SI_OP
180 #define TARGET_ASM_ALIGNED_SI_OP NULL
181 #undef TARGET_ASM_ALIGNED_DI_OP
182 #define TARGET_ASM_ALIGNED_DI_OP NULL
183 #undef TARGET_ASM_INTEGER
184 #define TARGET_ASM_INTEGER mmix_assemble_integer
185
186 #undef TARGET_ASM_FUNCTION_PROLOGUE
187 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
188
189 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
190 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
191
192 #undef TARGET_ASM_FUNCTION_EPILOGUE
193 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
194
195 #undef TARGET_PRINT_OPERAND
196 #define TARGET_PRINT_OPERAND mmix_print_operand
197 #undef TARGET_PRINT_OPERAND_ADDRESS
198 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
199 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
200 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
201
202 #undef TARGET_ENCODE_SECTION_INFO
203 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
204 #undef TARGET_STRIP_NAME_ENCODING
205 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
206
207 #undef TARGET_ASM_OUTPUT_MI_THUNK
208 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
209 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
210 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
211 #undef TARGET_ASM_FILE_START
212 #define TARGET_ASM_FILE_START mmix_file_start
213 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
214 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
215 #undef TARGET_ASM_FILE_END
216 #define TARGET_ASM_FILE_END mmix_file_end
217 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
218 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
219
220 #undef TARGET_CONDITIONAL_REGISTER_USAGE
221 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
222
223 #undef TARGET_RTX_COSTS
224 #define TARGET_RTX_COSTS mmix_rtx_costs
225 #undef TARGET_ADDRESS_COST
226 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
227
228 #undef TARGET_REGISTER_MOVE_COST
229 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
230
231 #undef TARGET_MACHINE_DEPENDENT_REORG
232 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
233
234 #undef TARGET_PROMOTE_FUNCTION_MODE
235 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
236
237 #undef TARGET_FUNCTION_VALUE
238 #define TARGET_FUNCTION_VALUE mmix_function_value
239 #undef TARGET_LIBCALL_VALUE
240 #define TARGET_LIBCALL_VALUE mmix_libcall_value
241 #undef TARGET_FUNCTION_VALUE_REGNO_P
242 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
243
244 #undef TARGET_FUNCTION_ARG
245 #define TARGET_FUNCTION_ARG mmix_function_arg
246 #undef TARGET_FUNCTION_INCOMING_ARG
247 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
248 #undef TARGET_FUNCTION_ARG_ADVANCE
249 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
250 #undef TARGET_STRUCT_VALUE_RTX
251 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
252 #undef TARGET_SETUP_INCOMING_VARARGS
253 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
254 #undef TARGET_PASS_BY_REFERENCE
255 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
256 #undef TARGET_CALLEE_COPIES
257 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
258
259 #undef TARGET_PREFERRED_RELOAD_CLASS
260 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
261 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
262 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
263
264 #undef TARGET_LRA_P
265 #define TARGET_LRA_P hook_bool_void_false
266
267 #undef TARGET_LEGITIMATE_ADDRESS_P
268 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
269 #undef TARGET_LEGITIMATE_CONSTANT_P
270 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
271
272 #undef TARGET_FRAME_POINTER_REQUIRED
273 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
274
275 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
276 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
277 #undef TARGET_TRAMPOLINE_INIT
278 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
279
280 #undef TARGET_OPTION_OVERRIDE
281 #define TARGET_OPTION_OVERRIDE mmix_option_override
282
283 struct gcc_target targetm = TARGET_INITIALIZER;
284
285 /* Functions that are expansions for target macros.
286 See Target Macros in `Using and Porting GCC'. */
287
288 /* TARGET_OPTION_OVERRIDE. */
289
290 static void
291 mmix_option_override (void)
292 {
293 /* Should we err or should we warn? Hmm. At least we must neutralize
294 it. For example the wrong kind of case-tables will be generated with
295 PIC; we use absolute address items for mmixal compatibility. FIXME:
296 They could be relative if we just elide them to after all pertinent
297 labels. */
298 if (flag_pic)
299 {
300 warning (0, "-f%s not supported: ignored", (flag_pic > 1) ? "PIC" : "pic");
301 flag_pic = 0;
302 }
303 }
304
305 /* INIT_EXPANDERS. */
306
307 void
308 mmix_init_expanders (void)
309 {
310 init_machine_status = mmix_init_machine_status;
311 }
312
313 /* Set the per-function data. */
314
315 static struct machine_function *
316 mmix_init_machine_status (void)
317 {
318 return ggc_cleared_alloc<machine_function> ();
319 }
320
321 /* DATA_ABI_ALIGNMENT.
322 We have trouble getting the address of stuff that is located at other
323 than 32-bit alignments (GETA requirements), so try to give everything
324 at least 32-bit alignment. */
325
326 int
327 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
328 {
329 if (basic_align < 32)
330 return 32;
331
332 return basic_align;
333 }
334
335 /* CONSTANT_ALIGNMENT. */
336
337 int
338 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED, int basic_align)
339 {
340 if (basic_align < 32)
341 return 32;
342
343 return basic_align;
344 }
345
346 /* LOCAL_ALIGNMENT. */
347
348 unsigned
349 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, unsigned basic_align)
350 {
351 if (basic_align < 32)
352 return 32;
353
354 return basic_align;
355 }
356
357 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
358
359 static void
360 mmix_conditional_register_usage (void)
361 {
362 int i;
363
364 if (TARGET_ABI_GNU)
365 {
366 static const int gnu_abi_reg_alloc_order[]
367 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
368
369 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
370 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
371
372 /* Change the default from the mmixware ABI. For the GNU ABI,
373 $15..$30 are call-saved just as $0..$14. There must be one
374 call-clobbered local register for the "hole" that holds the
375 number of saved local registers saved by PUSHJ/PUSHGO during the
376 function call, receiving the return value at return. So best is
377 to use the highest, $31. It's already marked call-clobbered for
378 the mmixware ABI. */
379 for (i = 15; i <= 30; i++)
380 call_used_regs[i] = 0;
381
382 /* "Unfix" the parameter registers. */
383 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
384 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
385 i++)
386 fixed_regs[i] = 0;
387 }
388
389 /* Step over the ":" in special register names. */
390 if (! TARGET_TOPLEVEL_SYMBOLS)
391 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
392 if (reg_names[i][0] == ':')
393 reg_names[i]++;
394 }
395
396 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
397 Those two macros must only be applied to function argument
398 registers and the function return value register for the opposite
399 use. FIXME: for their current use in gcc, it'd be better with an
400 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
401 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
402 forcing the target to commit to a fixed mapping and for any
403 unspecified register use. Particularly when thinking about the
404 return-value, it is better to imagine INCOMING_REGNO and
405 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
406 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
407 and "outgoing" is from the perspective of the parameter-registers,
408 but the same macro is (must be, lacking an alternative like
409 suggested above) used to map the return-value-register from the
410 same perspective. To make directions even more confusing, the macro
411 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
412 in which to return a value, i.e. INCOMING_REGNO for the return-value-
413 register as received from a called function; the return-value on the
414 way out. */
415
416 int
417 mmix_opposite_regno (int regno, int incoming)
418 {
419 if (incoming && regno == MMIX_OUTGOING_RETURN_VALUE_REGNUM)
420 return MMIX_RETURN_VALUE_REGNUM;
421
422 if (!incoming && regno == MMIX_RETURN_VALUE_REGNUM)
423 return MMIX_OUTGOING_RETURN_VALUE_REGNUM;
424
425 if (!mmix_function_arg_regno_p (regno, incoming))
426 return regno;
427
428 return
429 regno - (incoming
430 ? MMIX_FIRST_INCOMING_ARG_REGNUM - MMIX_FIRST_ARG_REGNUM
431 : MMIX_FIRST_ARG_REGNUM - MMIX_FIRST_INCOMING_ARG_REGNUM);
432 }
433
434 /* LOCAL_REGNO.
435 All registers that are part of the register stack and that will be
436 saved are local. */
437
438 int
439 mmix_local_regno (int regno)
440 {
441 return regno <= MMIX_LAST_STACK_REGISTER_REGNUM && !call_used_regs[regno];
442 }
443
444 /* TARGET_PREFERRED_RELOAD_CLASS.
445 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
446
447 static reg_class_t
448 mmix_preferred_reload_class (rtx x, reg_class_t rclass)
449 {
450 /* FIXME: Revisit. */
451 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
452 ? REMAINDER_REG : rclass;
453 }
454
455 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
456 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
457
458 static reg_class_t
459 mmix_preferred_output_reload_class (rtx x, reg_class_t rclass)
460 {
461 /* FIXME: Revisit. */
462 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
463 ? REMAINDER_REG : rclass;
464 }
465
466 /* SECONDARY_RELOAD_CLASS.
467 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
468
469 enum reg_class
470 mmix_secondary_reload_class (enum reg_class rclass,
471 machine_mode mode ATTRIBUTE_UNUSED,
472 rtx x ATTRIBUTE_UNUSED,
473 int in_p ATTRIBUTE_UNUSED)
474 {
475 if (rclass == REMAINDER_REG
476 || rclass == HIMULT_REG
477 || rclass == SYSTEM_REGS)
478 return GENERAL_REGS;
479
480 return NO_REGS;
481 }
482
483 /* DYNAMIC_CHAIN_ADDRESS. */
484
485 rtx
486 mmix_dynamic_chain_address (rtx frame)
487 {
488 /* FIXME: the frame-pointer is stored at offset -8 from the current
489 frame-pointer. Unfortunately, the caller assumes that a
490 frame-pointer is present for *all* previous frames. There should be
491 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
492 return plus_constant (Pmode, frame, -8);
493 }
494
495 /* STARTING_FRAME_OFFSET. */
496
497 int
498 mmix_starting_frame_offset (void)
499 {
500 /* The old frame pointer is in the slot below the new one, so
501 FIRST_PARM_OFFSET does not need to depend on whether the
502 frame-pointer is needed or not. We have to adjust for the register
503 stack pointer being located below the saved frame pointer.
504 Similarly, we store the return address on the stack too, for
505 exception handling, and always if we save the register stack pointer. */
506 return
507 (-8
508 + (MMIX_CFUN_HAS_LANDING_PAD
509 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
510 }
511
512 /* RETURN_ADDR_RTX. */
513
514 rtx
515 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
516 {
517 return count == 0
518 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
519 /* FIXME: Set frame_alias_set on the following. (Why?)
520 See mmix_initial_elimination_offset for the reason we can't use
521 get_hard_reg_initial_val for both. Always using a stack slot
522 and not a register would be suboptimal. */
523 ? validize_mem (gen_rtx_MEM (Pmode,
524 plus_constant (Pmode,
525 frame_pointer_rtx, -16)))
526 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
527 : NULL_RTX;
528 }
529
530 /* SETUP_FRAME_ADDRESSES. */
531
532 void
533 mmix_setup_frame_addresses (void)
534 {
535 /* Nothing needed at the moment. */
536 }
537
538 /* The difference between the (imaginary) frame pointer and the stack
539 pointer. Used to eliminate the frame pointer. */
540
541 int
542 mmix_initial_elimination_offset (int fromreg, int toreg)
543 {
544 int regno;
545 int fp_sp_offset
546 = (get_frame_size () + crtl->outgoing_args_size + 7) & ~7;
547
548 /* There is no actual offset between these two virtual values, but for
549 the frame-pointer, we have the old one in the stack position below
550 it, so the offset for the frame-pointer to the stack-pointer is one
551 octabyte larger. */
552 if (fromreg == MMIX_ARG_POINTER_REGNUM
553 && toreg == MMIX_FRAME_POINTER_REGNUM)
554 return 0;
555
556 /* The difference is the size of local variables plus the size of
557 outgoing function arguments that would normally be passed as
558 registers but must be passed on stack because we're out of
559 function-argument registers. Only global saved registers are
560 counted; the others go on the register stack.
561
562 The frame-pointer is counted too if it is what is eliminated, as we
563 need to balance the offset for it from STARTING_FRAME_OFFSET.
564
565 Also add in the slot for the register stack pointer we save if we
566 have a landing pad.
567
568 Unfortunately, we can't access $0..$14, from unwinder code easily, so
569 store the return address in a frame slot too. FIXME: Only for
570 non-leaf functions. FIXME: Always with a landing pad, because it's
571 hard to know whether we need the other at the time we know we need
572 the offset for one (and have to state it). It's a kludge until we
573 can express the register stack in the EH frame info.
574
575 We have to do alignment here; get_frame_size will not return a
576 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
577
578 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
579 regno <= 255;
580 regno++)
581 if ((df_regs_ever_live_p (regno) && ! call_used_regs[regno])
582 || IS_MMIX_EH_RETURN_DATA_REG (regno))
583 fp_sp_offset += 8;
584
585 return fp_sp_offset
586 + (MMIX_CFUN_HAS_LANDING_PAD
587 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
588 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
589 }
590
591 static void
592 mmix_function_arg_advance (cumulative_args_t argsp_v, machine_mode mode,
593 const_tree type, bool named ATTRIBUTE_UNUSED)
594 {
595 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
596 int arg_size = MMIX_FUNCTION_ARG_SIZE (mode, type);
597
598 argsp->regs = ((targetm.calls.must_pass_in_stack (mode, type)
599 || (arg_size > 8
600 && !TARGET_LIBFUNC
601 && !argsp->lib))
602 ? (MMIX_MAX_ARGS_IN_REGS) + 1
603 : argsp->regs + (7 + arg_size) / 8);
604 }
605
606 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
607
608 static rtx
609 mmix_function_arg_1 (const cumulative_args_t argsp_v,
610 machine_mode mode,
611 const_tree type,
612 bool named ATTRIBUTE_UNUSED,
613 bool incoming)
614 {
615 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
616
617 /* Last-argument marker. */
618 if (type == void_type_node)
619 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
620 ? gen_rtx_REG (mode,
621 (incoming
622 ? MMIX_FIRST_INCOMING_ARG_REGNUM
623 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
624 : NULL_RTX;
625
626 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
627 && !targetm.calls.must_pass_in_stack (mode, type)
628 && (GET_MODE_BITSIZE (mode) <= 64
629 || argsp->lib
630 || TARGET_LIBFUNC))
631 ? gen_rtx_REG (mode,
632 (incoming
633 ? MMIX_FIRST_INCOMING_ARG_REGNUM
634 : MMIX_FIRST_ARG_REGNUM)
635 + argsp->regs)
636 : NULL_RTX;
637 }
638
639 /* Return an rtx for a function argument to go in a register, and 0 for
640 one that must go on stack. */
641
642 static rtx
643 mmix_function_arg (cumulative_args_t argsp,
644 machine_mode mode,
645 const_tree type,
646 bool named)
647 {
648 return mmix_function_arg_1 (argsp, mode, type, named, false);
649 }
650
651 static rtx
652 mmix_function_incoming_arg (cumulative_args_t argsp,
653 machine_mode mode,
654 const_tree type,
655 bool named)
656 {
657 return mmix_function_arg_1 (argsp, mode, type, named, true);
658 }
659
660 /* Returns nonzero for everything that goes by reference, 0 for
661 everything that goes by value. */
662
663 static bool
664 mmix_pass_by_reference (cumulative_args_t argsp_v, machine_mode mode,
665 const_tree type, bool named ATTRIBUTE_UNUSED)
666 {
667 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
668
669 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
670 necessary. */
671 if (targetm.calls.must_pass_in_stack (mode, type))
672 return true;
673
674 if (MMIX_FUNCTION_ARG_SIZE (mode, type) > 8
675 && !TARGET_LIBFUNC
676 && (!argsp || !argsp->lib))
677 return true;
678
679 return false;
680 }
681
682 /* Return nonzero if regno is a register number where a parameter is
683 passed, and 0 otherwise. */
684
685 int
686 mmix_function_arg_regno_p (int regno, int incoming)
687 {
688 int first_arg_regnum
689 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
690
691 return regno >= first_arg_regnum
692 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
693 }
694
695 /* Implements TARGET_FUNCTION_VALUE. */
696
697 static rtx
698 mmix_function_value (const_tree valtype,
699 const_tree func ATTRIBUTE_UNUSED,
700 bool outgoing)
701 {
702 machine_mode mode = TYPE_MODE (valtype);
703 machine_mode cmode;
704 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
705 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
706 int i;
707 int nregs;
708
709 if (!outgoing)
710 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
711
712 /* Return values that fit in a register need no special handling.
713 There's no register hole when parameters are passed in global
714 registers. */
715 if (TARGET_ABI_GNU
716 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
717 return
718 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
719
720 if (COMPLEX_MODE_P (mode))
721 /* A complex type, made up of components. */
722 cmode = TYPE_MODE (TREE_TYPE (valtype));
723 else
724 {
725 /* Of the other larger-than-register modes, we only support
726 scalar mode TImode. (At least, that's the only one that's
727 been rudimentally tested.) Make sure we're alerted for
728 unexpected cases. */
729 if (mode != TImode)
730 sorry ("support for mode %qs", GET_MODE_NAME (mode));
731
732 /* In any case, we will fill registers to the natural size. */
733 cmode = DImode;
734 }
735
736 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
737
738 /* We need to take care of the effect of the register hole on return
739 values of large sizes; the last register will appear as the first
740 register, with the rest shifted. (For complex modes, this is just
741 swapped registers.) */
742
743 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
744 internal_error ("too large function value type, needs %d registers,\
745 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
746
747 /* FIXME: Maybe we should handle structure values like this too
748 (adjusted for BLKmode), perhaps for both ABI:s. */
749 for (i = 0; i < nregs - 1; i++)
750 vec[i]
751 = gen_rtx_EXPR_LIST (VOIDmode,
752 gen_rtx_REG (cmode, first_val_regnum + i),
753 GEN_INT ((i + 1) * BITS_PER_UNIT));
754
755 vec[nregs - 1]
756 = gen_rtx_EXPR_LIST (VOIDmode,
757 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
758 const0_rtx);
759
760 return gen_rtx_PARALLEL (mode, gen_rtvec_v (nregs, vec));
761 }
762
763 /* Implements TARGET_LIBCALL_VALUE. */
764
765 static rtx
766 mmix_libcall_value (machine_mode mode,
767 const_rtx fun ATTRIBUTE_UNUSED)
768 {
769 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
770 }
771
772 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
773
774 static bool
775 mmix_function_value_regno_p (const unsigned int regno)
776 {
777 return regno == MMIX_RETURN_VALUE_REGNUM;
778 }
779
780 /* EH_RETURN_DATA_REGNO. */
781
782 int
783 mmix_eh_return_data_regno (int n)
784 {
785 if (n >= 0 && n < 4)
786 return MMIX_EH_RETURN_DATA_REGNO_START + n;
787
788 return INVALID_REGNUM;
789 }
790
791 /* EH_RETURN_STACKADJ_RTX. */
792
793 rtx
794 mmix_eh_return_stackadj_rtx (void)
795 {
796 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
797 }
798
799 /* EH_RETURN_HANDLER_RTX. */
800
801 rtx
802 mmix_eh_return_handler_rtx (void)
803 {
804 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
805 }
806
807 /* ASM_PREFERRED_EH_DATA_FORMAT. */
808
809 int
810 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
811 int global ATTRIBUTE_UNUSED)
812 {
813 /* This is the default (was at 2001-07-20). Revisit when needed. */
814 return DW_EH_PE_absptr;
815 }
816
817 /* Make a note that we've seen the beginning of the prologue. This
818 matters to whether we'll translate register numbers as calculated by
819 mmix_reorg. */
820
821 static void
822 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED,
823 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED)
824 {
825 cfun->machine->in_prologue = 1;
826 }
827
828 /* Make a note that we've seen the end of the prologue. */
829
830 static void
831 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
832 {
833 cfun->machine->in_prologue = 0;
834 }
835
836 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
837 done here; just virtually by calculating the highest saved stack
838 register number used to modify the register numbers at output time. */
839
840 static void
841 mmix_reorg (void)
842 {
843 int regno;
844
845 /* We put the number of the highest saved register-file register in a
846 location convenient for the call-patterns to output. Note that we
847 don't tell dwarf2 about these registers, since it can't restore them
848 anyway. */
849 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
850 regno >= 0;
851 regno--)
852 if ((df_regs_ever_live_p (regno) && !call_used_regs[regno])
853 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
854 break;
855
856 /* Regardless of whether they're saved (they might be just read), we
857 mustn't include registers that carry parameters. We could scan the
858 insns to see whether they're actually used (and indeed do other less
859 trivial register usage analysis and transformations), but it seems
860 wasteful to optimize for unused parameter registers. As of
861 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
862 that might change. */
863 if (!TARGET_ABI_GNU && regno < crtl->args.info.regs - 1)
864 {
865 regno = crtl->args.info.regs - 1;
866
867 /* We don't want to let this cause us to go over the limit and make
868 incoming parameter registers be misnumbered and treating the last
869 parameter register and incoming return value register call-saved.
870 Stop things at the unmodified scheme. */
871 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
872 regno = MMIX_RETURN_VALUE_REGNUM - 1;
873 }
874
875 cfun->machine->highest_saved_stack_register = regno;
876 }
877
878 /* TARGET_ASM_FUNCTION_EPILOGUE. */
879
880 static void
881 mmix_target_asm_function_epilogue (FILE *stream,
882 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED)
883 {
884 /* Emit an \n for readability of the generated assembly. */
885 fputc ('\n', stream);
886 }
887
888 /* TARGET_ASM_OUTPUT_MI_THUNK. */
889
890 static void
891 mmix_asm_output_mi_thunk (FILE *stream,
892 tree fndecl ATTRIBUTE_UNUSED,
893 HOST_WIDE_INT delta,
894 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
895 tree func)
896 {
897 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
898 location of structure to return as invisible first argument), you
899 need to tweak this code too. */
900 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
901
902 if (delta >= 0 && delta < 65536)
903 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
904 else if (delta < 0 && delta >= -255)
905 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
906 else
907 {
908 mmix_output_register_setting (stream, 255, delta, 1);
909 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
910 }
911
912 fprintf (stream, "\tJMP ");
913 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
914 fprintf (stream, "\n");
915 }
916
917 /* FUNCTION_PROFILER. */
918
919 void
920 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
921 int labelno ATTRIBUTE_UNUSED)
922 {
923 sorry ("function_profiler support for MMIX");
924 }
925
926 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
927 let's stick to pushing argument registers on the stack. Later, we
928 can parse all arguments in registers, to improve performance. */
929
930 static void
931 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v,
932 machine_mode mode,
933 tree vartype,
934 int *pretend_sizep,
935 int second_time ATTRIBUTE_UNUSED)
936 {
937 CUMULATIVE_ARGS *args_so_farp = get_cumulative_args (args_so_farp_v);
938
939 /* The last named variable has been handled, but
940 args_so_farp has not been advanced for it. */
941 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
942 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
943
944 /* We assume that one argument takes up one register here. That should
945 be true until we start messing with multi-reg parameters. */
946 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
947 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
948 }
949
950 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
951
952 static void
953 mmix_asm_trampoline_template (FILE *stream)
954 {
955 /* Read a value into the static-chain register and jump somewhere. The
956 static chain is stored at offset 16, and the function address is
957 stored at offset 24. */
958
959 fprintf (stream, "\tGETA $255,1F\n\t");
960 fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
961 fprintf (stream, "LDOU $255,$255,8\n\t");
962 fprintf (stream, "GO $255,$255,0\n");
963 fprintf (stream, "1H\tOCTA 0\n\t");
964 fprintf (stream, "OCTA 0\n");
965 }
966
967 /* TARGET_TRAMPOLINE_INIT. */
968 /* Set the static chain and function pointer field in the trampoline.
969 We also SYNCID here to be sure (doesn't matter in the simulator, but
970 some day it will). */
971
972 static void
973 mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
974 {
975 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
976 rtx mem;
977
978 emit_block_move (m_tramp, assemble_trampoline_template (),
979 GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
980
981 mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
982 emit_move_insn (mem, static_chain);
983 mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
984 emit_move_insn (mem, fnaddr);
985
986 mem = adjust_address (m_tramp, DImode, 0);
987 emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
988 }
989
990 /* We must exclude constant addresses that have an increment that is not a
991 multiple of four bytes because of restrictions of the GETA
992 instruction, unless TARGET_BASE_ADDRESSES. */
993
994 int
995 mmix_constant_address_p (rtx x)
996 {
997 RTX_CODE code = GET_CODE (x);
998 int addend = 0;
999 /* When using "base addresses", anything constant goes. */
1000 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1001
1002 switch (code)
1003 {
1004 case LABEL_REF:
1005 case SYMBOL_REF:
1006 return 1;
1007
1008 case HIGH:
1009 /* FIXME: Don't know how to dissect these. Avoid them for now,
1010 except we know they're constants. */
1011 return constant_ok;
1012
1013 case CONST_INT:
1014 addend = INTVAL (x);
1015 break;
1016
1017 case CONST_DOUBLE:
1018 if (GET_MODE (x) != VOIDmode)
1019 /* Strange that we got here. FIXME: Check if we do. */
1020 return constant_ok;
1021 addend = CONST_DOUBLE_LOW (x);
1022 break;
1023
1024 case CONST:
1025 /* Note that expressions with arithmetic on forward references don't
1026 work in mmixal. People using gcc assembly code with mmixal might
1027 need to move arrays and such to before the point of use. */
1028 if (GET_CODE (XEXP (x, 0)) == PLUS)
1029 {
1030 rtx x0 = XEXP (XEXP (x, 0), 0);
1031 rtx x1 = XEXP (XEXP (x, 0), 1);
1032
1033 if ((GET_CODE (x0) == SYMBOL_REF
1034 || GET_CODE (x0) == LABEL_REF)
1035 && (GET_CODE (x1) == CONST_INT
1036 || (GET_CODE (x1) == CONST_DOUBLE
1037 && GET_MODE (x1) == VOIDmode)))
1038 addend = mmix_intval (x1);
1039 else
1040 return constant_ok;
1041 }
1042 else
1043 return constant_ok;
1044 break;
1045
1046 default:
1047 return 0;
1048 }
1049
1050 return constant_ok || (addend & 3) == 0;
1051 }
1052
1053 /* Return 1 if the address is OK, otherwise 0. */
1054
1055 bool
1056 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED,
1057 rtx x,
1058 bool strict_checking)
1059 {
1060 #define MMIX_REG_OK(X) \
1061 ((strict_checking \
1062 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1063 || (reg_renumber[REGNO (X)] > 0 \
1064 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1065 || (!strict_checking \
1066 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1067 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1068 || REGNO (X) == ARG_POINTER_REGNUM)))
1069
1070 /* We only accept:
1071 (mem reg)
1072 (mem (plus reg reg))
1073 (mem (plus reg 0..255)).
1074 unless TARGET_BASE_ADDRESSES, in which case we accept all
1075 (mem constant_address) too. */
1076
1077
1078 /* (mem reg) */
1079 if (REG_P (x) && MMIX_REG_OK (x))
1080 return 1;
1081
1082 if (GET_CODE(x) == PLUS)
1083 {
1084 rtx x1 = XEXP (x, 0);
1085 rtx x2 = XEXP (x, 1);
1086
1087 /* Try swapping the order. FIXME: Do we need this? */
1088 if (! REG_P (x1))
1089 {
1090 rtx tem = x1;
1091 x1 = x2;
1092 x2 = tem;
1093 }
1094
1095 /* (mem (plus (reg?) (?))) */
1096 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1097 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1098
1099 /* (mem (plus (reg) (reg?))) */
1100 if (REG_P (x2) && MMIX_REG_OK (x2))
1101 return 1;
1102
1103 /* (mem (plus (reg) (0..255?))) */
1104 if (satisfies_constraint_I (x2))
1105 return 1;
1106
1107 return 0;
1108 }
1109
1110 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1111 }
1112
1113 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1114
1115 static bool
1116 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1117 {
1118 RTX_CODE code = GET_CODE (x);
1119
1120 /* We must allow any number due to the way the cse passes works; if we
1121 do not allow any number here, general_operand will fail, and insns
1122 will fatally fail recognition instead of "softly". */
1123 if (code == CONST_INT || code == CONST_DOUBLE)
1124 return 1;
1125
1126 return CONSTANT_ADDRESS_P (x);
1127 }
1128
1129 /* SELECT_CC_MODE. */
1130
1131 machine_mode
1132 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1133 {
1134 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1135 output different compare insns. Note that we do not check the
1136 validity of the comparison here. */
1137
1138 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1139 {
1140 if (op == ORDERED || op == UNORDERED || op == UNGE
1141 || op == UNGT || op == UNLE || op == UNLT)
1142 return CC_FUNmode;
1143
1144 if (op == EQ || op == NE)
1145 return CC_FPEQmode;
1146
1147 return CC_FPmode;
1148 }
1149
1150 if (op == GTU || op == LTU || op == GEU || op == LEU)
1151 return CC_UNSmode;
1152
1153 return CCmode;
1154 }
1155
1156 /* REVERSIBLE_CC_MODE. */
1157
1158 int
1159 mmix_reversible_cc_mode (machine_mode mode)
1160 {
1161 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1162 compares. */
1163 return mode != CC_FPmode;
1164 }
1165
1166 /* TARGET_RTX_COSTS. */
1167
1168 static bool
1169 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1170 machine_mode mode ATTRIBUTE_UNUSED,
1171 int outer_code ATTRIBUTE_UNUSED,
1172 int opno ATTRIBUTE_UNUSED,
1173 int *total ATTRIBUTE_UNUSED,
1174 bool speed ATTRIBUTE_UNUSED)
1175 {
1176 /* For the time being, this is just a stub and we'll accept the
1177 generic calculations, until we can do measurements, at least.
1178 Say we did not modify any calculated costs. */
1179 return false;
1180 }
1181
1182 /* TARGET_REGISTER_MOVE_COST.
1183
1184 The special registers can only move to and from general regs, and we
1185 need to check that their constraints match, so say 3 for them. */
1186
1187 static int
1188 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
1189 reg_class_t from,
1190 reg_class_t to)
1191 {
1192 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1193 }
1194
1195 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1196 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1197 the target. */
1198
1199 /* DATA_SECTION_ASM_OP. */
1200
1201 const char *
1202 mmix_data_section_asm_op (void)
1203 {
1204 return "\t.data ! mmixal:= 8H LOC 9B";
1205 }
1206
1207 static void
1208 mmix_encode_section_info (tree decl, rtx rtl, int first)
1209 {
1210 /* Test for an external declaration, and do nothing if it is one. */
1211 if ((TREE_CODE (decl) == VAR_DECL
1212 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1213 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1214 ;
1215 else if (first && DECL_P (decl))
1216 {
1217 /* For non-visible declarations, add a "@" prefix, which we skip
1218 when the label is output. If the label does not have this
1219 prefix, a ":" is output if -mtoplevel-symbols.
1220
1221 Note that this does not work for data that is declared extern and
1222 later defined as static. If there's code in between, that code
1223 will refer to the extern declaration, and vice versa. This just
1224 means that when -mtoplevel-symbols is in use, we can just handle
1225 well-behaved ISO-compliant code. */
1226
1227 const char *str = XSTR (XEXP (rtl, 0), 0);
1228 int len = strlen (str);
1229 char *newstr = XALLOCAVEC (char, len + 2);
1230 newstr[0] = '@';
1231 strcpy (newstr + 1, str);
1232 XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
1233 }
1234
1235 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1236 may need different options to reach for different things with GETA.
1237 For now, functions and things we know or have been told are constant. */
1238 if (TREE_CODE (decl) == FUNCTION_DECL
1239 || TREE_CONSTANT (decl)
1240 || (TREE_CODE (decl) == VAR_DECL
1241 && TREE_READONLY (decl)
1242 && !TREE_SIDE_EFFECTS (decl)
1243 && (!DECL_INITIAL (decl)
1244 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1245 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1246 }
1247
1248 static const char *
1249 mmix_strip_name_encoding (const char *name)
1250 {
1251 for (; (*name == '@' || *name == '*'); name++)
1252 ;
1253
1254 return name;
1255 }
1256
1257 /* TARGET_ASM_FILE_START.
1258 We just emit a little comment for the time being. */
1259
1260 static void
1261 mmix_file_start (void)
1262 {
1263 default_file_start ();
1264
1265 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1266
1267 /* Make sure each file starts with the text section. */
1268 switch_to_section (text_section);
1269 }
1270
1271 /* TARGET_ASM_FILE_END. */
1272
1273 static void
1274 mmix_file_end (void)
1275 {
1276 /* Make sure each file ends with the data section. */
1277 switch_to_section (data_section);
1278 }
1279
1280 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1281
1282 static void
1283 mmix_asm_output_source_filename (FILE *stream, const char *name)
1284 {
1285 fprintf (stream, "# 1 ");
1286 OUTPUT_QUOTED_STRING (stream, name);
1287 fprintf (stream, "\n");
1288 }
1289
1290 /* OUTPUT_QUOTED_STRING. */
1291
1292 void
1293 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1294 {
1295 const char * string_end = string + length;
1296 static const char *const unwanted_chars = "\"[]\\";
1297
1298 /* Output "any character except newline and double quote character". We
1299 play it safe and avoid all control characters too. We also do not
1300 want [] as characters, should input be passed through m4 with [] as
1301 quotes. Further, we avoid "\", because the GAS port handles it as a
1302 quoting character. */
1303 while (string < string_end)
1304 {
1305 if (*string
1306 && (unsigned char) *string < 128
1307 && !ISCNTRL (*string)
1308 && strchr (unwanted_chars, *string) == NULL)
1309 {
1310 fputc ('"', stream);
1311 while (*string
1312 && (unsigned char) *string < 128
1313 && !ISCNTRL (*string)
1314 && strchr (unwanted_chars, *string) == NULL
1315 && string < string_end)
1316 {
1317 fputc (*string, stream);
1318 string++;
1319 }
1320 fputc ('"', stream);
1321 if (string < string_end)
1322 fprintf (stream, ",");
1323 }
1324 if (string < string_end)
1325 {
1326 fprintf (stream, "#%x", *string & 255);
1327 string++;
1328 if (string < string_end)
1329 fprintf (stream, ",");
1330 }
1331 }
1332 }
1333
1334 /* Target hook for assembling integer objects. Use mmix_print_operand
1335 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1336 CONST_DOUBLEs. */
1337
1338 static bool
1339 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1340 {
1341 if (aligned_p)
1342 switch (size)
1343 {
1344 /* We handle a limited number of types of operands in here. But
1345 that's ok, because we can punt to generic functions. We then
1346 pretend that aligned data isn't needed, so the usual .<pseudo>
1347 syntax is used (which works for aligned data too). We actually
1348 *must* do that, since we say we don't have simple aligned
1349 pseudos, causing this function to be called. We just try and
1350 keep as much compatibility as possible with mmixal syntax for
1351 normal cases (i.e. without GNU extensions and C only). */
1352 case 1:
1353 if (GET_CODE (x) != CONST_INT)
1354 {
1355 aligned_p = 0;
1356 break;
1357 }
1358 fputs ("\tBYTE\t", asm_out_file);
1359 mmix_print_operand (asm_out_file, x, 'B');
1360 fputc ('\n', asm_out_file);
1361 return true;
1362
1363 case 2:
1364 if (GET_CODE (x) != CONST_INT)
1365 {
1366 aligned_p = 0;
1367 break;
1368 }
1369 fputs ("\tWYDE\t", asm_out_file);
1370 mmix_print_operand (asm_out_file, x, 'W');
1371 fputc ('\n', asm_out_file);
1372 return true;
1373
1374 case 4:
1375 if (GET_CODE (x) != CONST_INT)
1376 {
1377 aligned_p = 0;
1378 break;
1379 }
1380 fputs ("\tTETRA\t", asm_out_file);
1381 mmix_print_operand (asm_out_file, x, 'L');
1382 fputc ('\n', asm_out_file);
1383 return true;
1384
1385 case 8:
1386 /* We don't get here anymore for CONST_DOUBLE, because DImode
1387 isn't expressed as CONST_DOUBLE, and DFmode is handled
1388 elsewhere. */
1389 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1390 assemble_integer_with_op ("\tOCTA\t", x);
1391 return true;
1392 }
1393 return default_assemble_integer (x, size, aligned_p);
1394 }
1395
1396 /* ASM_OUTPUT_ASCII. */
1397
1398 void
1399 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1400 {
1401 while (length > 0)
1402 {
1403 int chunk_size = length > 60 ? 60 : length;
1404 fprintf (stream, "\tBYTE ");
1405 mmix_output_quoted_string (stream, string, chunk_size);
1406 string += chunk_size;
1407 length -= chunk_size;
1408 fprintf (stream, "\n");
1409 }
1410 }
1411
1412 /* ASM_OUTPUT_ALIGNED_COMMON. */
1413
1414 void
1415 mmix_asm_output_aligned_common (FILE *stream,
1416 const char *name,
1417 int size,
1418 int align)
1419 {
1420 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1421 express this in a mmixal-compatible way. */
1422 fprintf (stream, "\t.comm\t");
1423 assemble_name (stream, name);
1424 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1425 size, align / BITS_PER_UNIT);
1426 }
1427
1428 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1429
1430 void
1431 mmix_asm_output_aligned_local (FILE *stream,
1432 const char *name,
1433 int size,
1434 int align)
1435 {
1436 switch_to_section (data_section);
1437
1438 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1439 assemble_name (stream, name);
1440 fprintf (stream, "\tLOC @+%d\n", size);
1441 }
1442
1443 /* ASM_OUTPUT_LABEL. */
1444
1445 void
1446 mmix_asm_output_label (FILE *stream, const char *name)
1447 {
1448 assemble_name (stream, name);
1449 fprintf (stream, "\tIS @\n");
1450 }
1451
1452 /* ASM_OUTPUT_INTERNAL_LABEL. */
1453
1454 void
1455 mmix_asm_output_internal_label (FILE *stream, const char *name)
1456 {
1457 assemble_name_raw (stream, name);
1458 fprintf (stream, "\tIS @\n");
1459 }
1460
1461 /* ASM_DECLARE_REGISTER_GLOBAL. */
1462
1463 void
1464 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1465 tree decl ATTRIBUTE_UNUSED,
1466 int regno ATTRIBUTE_UNUSED,
1467 const char *name ATTRIBUTE_UNUSED)
1468 {
1469 /* Nothing to do here, but there *will* be, therefore the framework is
1470 here. */
1471 }
1472
1473 /* ASM_WEAKEN_LABEL. */
1474
1475 void
1476 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1477 const char *name ATTRIBUTE_UNUSED)
1478 {
1479 fprintf (stream, "\t.weak ");
1480 assemble_name (stream, name);
1481 fprintf (stream, " ! mmixal-incompatible\n");
1482 }
1483
1484 /* MAKE_DECL_ONE_ONLY. */
1485
1486 void
1487 mmix_make_decl_one_only (tree decl)
1488 {
1489 DECL_WEAK (decl) = 1;
1490 }
1491
1492 /* ASM_OUTPUT_LABELREF.
1493 Strip GCC's '*' and our own '@'. No order is assumed. */
1494
1495 void
1496 mmix_asm_output_labelref (FILE *stream, const char *name)
1497 {
1498 int is_extern = 1;
1499
1500 for (; (*name == '@' || *name == '*'); name++)
1501 if (*name == '@')
1502 is_extern = 0;
1503
1504 asm_fprintf (stream, "%s%U%s",
1505 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1506 name);
1507 }
1508
1509 /* ASM_OUTPUT_DEF. */
1510
1511 void
1512 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1513 {
1514 assemble_name (stream, name);
1515 fprintf (stream, "\tIS ");
1516 assemble_name (stream, value);
1517 fputc ('\n', stream);
1518 }
1519
1520 /* TARGET_PRINT_OPERAND. */
1521
1522 static void
1523 mmix_print_operand (FILE *stream, rtx x, int code)
1524 {
1525 /* When we add support for different codes later, we can, when needed,
1526 drop through to the main handler with a modified operand. */
1527 rtx modified_x = x;
1528 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1529
1530 switch (code)
1531 {
1532 /* Unrelated codes are in alphabetic order. */
1533
1534 case '+':
1535 /* For conditional branches, output "P" for a probable branch. */
1536 if (TARGET_BRANCH_PREDICT)
1537 {
1538 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1539 if (x && XINT (x, 0) > REG_BR_PROB_BASE / 2)
1540 putc ('P', stream);
1541 }
1542 return;
1543
1544 case '.':
1545 /* For the %d in POP %d,0. */
1546 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1547 return;
1548
1549 case 'B':
1550 if (GET_CODE (x) != CONST_INT)
1551 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1552 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1553 return;
1554
1555 case 'H':
1556 /* Highpart. Must be general register, and not the last one, as
1557 that one cannot be part of a consecutive register pair. */
1558 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1559 internal_error ("MMIX Internal: Bad register: %d", regno);
1560
1561 /* This is big-endian, so the high-part is the first one. */
1562 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1563 return;
1564
1565 case 'L':
1566 /* Lowpart. Must be CONST_INT or general register, and not the last
1567 one, as that one cannot be part of a consecutive register pair. */
1568 if (GET_CODE (x) == CONST_INT)
1569 {
1570 fprintf (stream, "#%lx",
1571 (unsigned long) (INTVAL (x)
1572 & ((unsigned int) 0x7fffffff * 2 + 1)));
1573 return;
1574 }
1575
1576 if (GET_CODE (x) == SYMBOL_REF)
1577 {
1578 output_addr_const (stream, x);
1579 return;
1580 }
1581
1582 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1583 internal_error ("MMIX Internal: Bad register: %d", regno);
1584
1585 /* This is big-endian, so the low-part is + 1. */
1586 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1587 return;
1588
1589 /* Can't use 'a' because that's a generic modifier for address
1590 output. */
1591 case 'A':
1592 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1593 ~(uint64_t)
1594 mmix_intval (x));
1595 return;
1596
1597 case 'i':
1598 mmix_output_shiftvalue_op_from_str (stream, "INC",
1599 (uint64_t)
1600 mmix_intval (x));
1601 return;
1602
1603 case 'o':
1604 mmix_output_shiftvalue_op_from_str (stream, "OR",
1605 (uint64_t)
1606 mmix_intval (x));
1607 return;
1608
1609 case 's':
1610 mmix_output_shiftvalue_op_from_str (stream, "SET",
1611 (uint64_t)
1612 mmix_intval (x));
1613 return;
1614
1615 case 'd':
1616 case 'D':
1617 mmix_output_condition (stream, x, (code == 'D'));
1618 return;
1619
1620 case 'e':
1621 /* Output an extra "e" to make fcmpe, fune. */
1622 if (TARGET_FCMP_EPSILON)
1623 fprintf (stream, "e");
1624 return;
1625
1626 case 'm':
1627 /* Output the number minus 1. */
1628 if (GET_CODE (x) != CONST_INT)
1629 {
1630 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1631 x);
1632 }
1633 fprintf (stream, "%" PRId64,
1634 (int64_t) (mmix_intval (x) - 1));
1635 return;
1636
1637 case 'p':
1638 /* Store the number of registers we want to save. This was setup
1639 by the prologue. The actual operand contains the number of
1640 registers to pass, but we don't use it currently. Anyway, we
1641 need to output the number of saved registers here. */
1642 fprintf (stream, "%d",
1643 cfun->machine->highest_saved_stack_register + 1);
1644 return;
1645
1646 case 'r':
1647 /* Store the register to output a constant to. */
1648 if (! REG_P (x))
1649 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1650 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1651 return;
1652
1653 case 'I':
1654 /* Output the constant. Note that we use this for floats as well. */
1655 if (GET_CODE (x) != CONST_INT
1656 && (GET_CODE (x) != CONST_DOUBLE
1657 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1658 && GET_MODE (x) != SFmode)))
1659 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1660 mmix_output_register_setting (stream,
1661 mmix_output_destination_register,
1662 mmix_intval (x), 0);
1663 return;
1664
1665 case 'U':
1666 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1667 if (TARGET_ZERO_EXTEND)
1668 putc ('U', stream);
1669 return;
1670
1671 case 'v':
1672 mmix_output_shifted_value (stream, (int64_t) mmix_intval (x));
1673 return;
1674
1675 case 'V':
1676 mmix_output_shifted_value (stream, (int64_t) ~mmix_intval (x));
1677 return;
1678
1679 case 'W':
1680 if (GET_CODE (x) != CONST_INT)
1681 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1682 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1683 return;
1684
1685 case 0:
1686 /* Nothing to do. */
1687 break;
1688
1689 default:
1690 /* Presumably there's a missing case above if we get here. */
1691 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code);
1692 }
1693
1694 switch (GET_CODE (modified_x))
1695 {
1696 case REG:
1697 regno = REGNO (modified_x);
1698 if (regno >= FIRST_PSEUDO_REGISTER)
1699 internal_error ("MMIX Internal: Bad register: %d", regno);
1700 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1701 return;
1702
1703 case MEM:
1704 output_address (GET_MODE (modified_x), XEXP (modified_x, 0));
1705 return;
1706
1707 case CONST_INT:
1708 /* For -2147483648, mmixal complains that the constant does not fit
1709 in 4 bytes, so let's output it as hex. Take care to handle hosts
1710 where HOST_WIDE_INT is longer than an int.
1711
1712 Print small constants +-255 using decimal. */
1713
1714 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1715 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1716 else
1717 fprintf (stream, "#%x",
1718 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1719 return;
1720
1721 case CONST_DOUBLE:
1722 /* Do somewhat as CONST_INT. */
1723 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1724 return;
1725
1726 case CONST:
1727 output_addr_const (stream, modified_x);
1728 return;
1729
1730 default:
1731 /* No need to test for all strange things. Let output_addr_const do
1732 it for us. */
1733 if (CONSTANT_P (modified_x)
1734 /* Strangely enough, this is not included in CONSTANT_P.
1735 FIXME: Ask/check about sanity here. */
1736 || LABEL_P (modified_x))
1737 {
1738 output_addr_const (stream, modified_x);
1739 return;
1740 }
1741
1742 /* We need the original here. */
1743 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1744 }
1745 }
1746
1747 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1748
1749 static bool
1750 mmix_print_operand_punct_valid_p (unsigned char code)
1751 {
1752 /* A '+' is used for branch prediction, similar to other ports. */
1753 return code == '+'
1754 /* A '.' is used for the %d in the POP %d,0 return insn. */
1755 || code == '.';
1756 }
1757
1758 /* TARGET_PRINT_OPERAND_ADDRESS. */
1759
1760 static void
1761 mmix_print_operand_address (FILE *stream, machine_mode /*mode*/, rtx x)
1762 {
1763 if (REG_P (x))
1764 {
1765 /* I find the generated assembly code harder to read without
1766 the ",0". */
1767 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1768 return;
1769 }
1770 else if (GET_CODE (x) == PLUS)
1771 {
1772 rtx x1 = XEXP (x, 0);
1773 rtx x2 = XEXP (x, 1);
1774
1775 if (REG_P (x1))
1776 {
1777 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1778
1779 if (REG_P (x2))
1780 {
1781 fprintf (stream, "%s",
1782 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1783 return;
1784 }
1785 else if (satisfies_constraint_I (x2))
1786 {
1787 output_addr_const (stream, x2);
1788 return;
1789 }
1790 }
1791 }
1792
1793 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (Pmode, x))
1794 {
1795 output_addr_const (stream, x);
1796 return;
1797 }
1798
1799 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1800 }
1801
1802 /* ASM_OUTPUT_REG_PUSH. */
1803
1804 void
1805 mmix_asm_output_reg_push (FILE *stream, int regno)
1806 {
1807 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1808 reg_names[MMIX_STACK_POINTER_REGNUM],
1809 reg_names[MMIX_STACK_POINTER_REGNUM],
1810 reg_names[MMIX_OUTPUT_REGNO (regno)],
1811 reg_names[MMIX_STACK_POINTER_REGNUM]);
1812 }
1813
1814 /* ASM_OUTPUT_REG_POP. */
1815
1816 void
1817 mmix_asm_output_reg_pop (FILE *stream, int regno)
1818 {
1819 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1820 reg_names[MMIX_OUTPUT_REGNO (regno)],
1821 reg_names[MMIX_STACK_POINTER_REGNUM],
1822 reg_names[MMIX_STACK_POINTER_REGNUM]);
1823 }
1824
1825 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1826
1827 void
1828 mmix_asm_output_addr_diff_elt (FILE *stream,
1829 rtx body ATTRIBUTE_UNUSED,
1830 int value,
1831 int rel)
1832 {
1833 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1834 }
1835
1836 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1837
1838 void
1839 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1840 {
1841 fprintf (stream, "\tOCTA L:%d\n", value);
1842 }
1843
1844 /* ASM_OUTPUT_SKIP. */
1845
1846 void
1847 mmix_asm_output_skip (FILE *stream, int nbytes)
1848 {
1849 fprintf (stream, "\tLOC @+%d\n", nbytes);
1850 }
1851
1852 /* ASM_OUTPUT_ALIGN. */
1853
1854 void
1855 mmix_asm_output_align (FILE *stream, int power)
1856 {
1857 /* We need to record the needed alignment of this section in the object,
1858 so we have to output an alignment directive. Use a .p2align (not
1859 .align) so people will never have to wonder about whether the
1860 argument is in number of bytes or the log2 thereof. We do it in
1861 addition to the LOC directive, so nothing needs tweaking when
1862 copy-pasting assembly into mmixal. */
1863 fprintf (stream, "\t.p2align %d\n", power);
1864 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1865 }
1866
1867 /* DBX_REGISTER_NUMBER. */
1868
1869 unsigned
1870 mmix_dbx_register_number (unsigned regno)
1871 {
1872 /* Adjust the register number to the one it will be output as, dammit.
1873 It'd be nice if we could check the assumption that we're filling a
1874 gap, but every register between the last saved register and parameter
1875 registers might be a valid parameter register. */
1876 regno = MMIX_OUTPUT_REGNO (regno);
1877
1878 /* We need to renumber registers to get the number of the return address
1879 register in the range 0..255. It is also space-saving if registers
1880 mentioned in the call-frame information (which uses this function by
1881 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1882 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1883 return regno >= 224 ? (regno - 224) : (regno + 48);
1884 }
1885
1886 /* End of target macro support functions.
1887
1888 Now the MMIX port's own functions. First the exported ones. */
1889
1890 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1891 from insn-emit.c. */
1892
1893 rtx
1894 mmix_get_hard_reg_initial_val (machine_mode mode, int regno)
1895 {
1896 return get_hard_reg_initial_val (mode, regno);
1897 }
1898
1899 /* Nonzero when the function epilogue is simple enough that a single
1900 "POP %d,0" should be used even within the function. */
1901
1902 int
1903 mmix_use_simple_return (void)
1904 {
1905 int regno;
1906
1907 int stack_space_to_allocate
1908 = (crtl->outgoing_args_size
1909 + crtl->args.pretend_args_size
1910 + get_frame_size () + 7) & ~7;
1911
1912 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1913 return 0;
1914
1915 for (regno = 255;
1916 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1917 regno--)
1918 /* Note that we assume that the frame-pointer-register is one of these
1919 registers, in which case we don't count it here. */
1920 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1921 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1922 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1923 return 0;
1924
1925 if (frame_pointer_needed)
1926 stack_space_to_allocate += 8;
1927
1928 if (MMIX_CFUN_HAS_LANDING_PAD)
1929 stack_space_to_allocate += 16;
1930 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1931 stack_space_to_allocate += 8;
1932
1933 return stack_space_to_allocate == 0;
1934 }
1935
1936
1937 /* Expands the function prologue into RTX. */
1938
1939 void
1940 mmix_expand_prologue (void)
1941 {
1942 HOST_WIDE_INT locals_size = get_frame_size ();
1943 int regno;
1944 HOST_WIDE_INT stack_space_to_allocate
1945 = (crtl->outgoing_args_size
1946 + crtl->args.pretend_args_size
1947 + locals_size + 7) & ~7;
1948 HOST_WIDE_INT offset = -8;
1949
1950 /* Add room needed to save global non-register-stack registers. */
1951 for (regno = 255;
1952 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1953 regno--)
1954 /* Note that we assume that the frame-pointer-register is one of these
1955 registers, in which case we don't count it here. */
1956 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1957 && df_regs_ever_live_p (regno) && !call_used_regs[regno]))
1958 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1959 stack_space_to_allocate += 8;
1960
1961 /* If we do have a frame-pointer, add room for it. */
1962 if (frame_pointer_needed)
1963 stack_space_to_allocate += 8;
1964
1965 /* If we have a non-local label, we need to be able to unwind to it, so
1966 store the current register stack pointer. Also store the return
1967 address if we do that. */
1968 if (MMIX_CFUN_HAS_LANDING_PAD)
1969 stack_space_to_allocate += 16;
1970 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1971 /* If we do have a saved return-address slot, add room for it. */
1972 stack_space_to_allocate += 8;
1973
1974 /* Make sure we don't get an unaligned stack. */
1975 if ((stack_space_to_allocate % 8) != 0)
1976 internal_error ("stack frame not a multiple of 8 bytes: %wd",
1977 stack_space_to_allocate);
1978
1979 if (crtl->args.pretend_args_size)
1980 {
1981 int mmix_first_vararg_reg
1982 = (MMIX_FIRST_INCOMING_ARG_REGNUM
1983 + (MMIX_MAX_ARGS_IN_REGS
1984 - crtl->args.pretend_args_size / 8));
1985
1986 for (regno
1987 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
1988 regno >= mmix_first_vararg_reg;
1989 regno--)
1990 {
1991 if (offset < 0)
1992 {
1993 HOST_WIDE_INT stack_chunk
1994 = stack_space_to_allocate > (256 - 8)
1995 ? (256 - 8) : stack_space_to_allocate;
1996
1997 mmix_emit_sp_add (-stack_chunk);
1998 offset += stack_chunk;
1999 stack_space_to_allocate -= stack_chunk;
2000 }
2001
2002 /* These registers aren't actually saved (as in "will be
2003 restored"), so don't tell DWARF2 they're saved. */
2004 emit_move_insn (gen_rtx_MEM (DImode,
2005 plus_constant (Pmode, stack_pointer_rtx,
2006 offset)),
2007 gen_rtx_REG (DImode, regno));
2008 offset -= 8;
2009 }
2010 }
2011
2012 /* Store the frame-pointer. */
2013
2014 if (frame_pointer_needed)
2015 {
2016 rtx insn;
2017
2018 if (offset < 0)
2019 {
2020 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2021 HOST_WIDE_INT stack_chunk
2022 = stack_space_to_allocate > (256 - 8 - 8)
2023 ? (256 - 8 - 8) : stack_space_to_allocate;
2024
2025 mmix_emit_sp_add (-stack_chunk);
2026
2027 offset += stack_chunk;
2028 stack_space_to_allocate -= stack_chunk;
2029 }
2030
2031 insn = emit_move_insn (gen_rtx_MEM (DImode,
2032 plus_constant (Pmode,
2033 stack_pointer_rtx,
2034 offset)),
2035 hard_frame_pointer_rtx);
2036 RTX_FRAME_RELATED_P (insn) = 1;
2037 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2038 stack_pointer_rtx,
2039 GEN_INT (offset + 8)));
2040 RTX_FRAME_RELATED_P (insn) = 1;
2041 offset -= 8;
2042 }
2043
2044 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2045 {
2046 rtx tmpreg, retreg;
2047 rtx insn;
2048
2049 /* Store the return-address, if one is needed on the stack. We
2050 usually store it in a register when needed, but that doesn't work
2051 with -fexceptions. */
2052
2053 if (offset < 0)
2054 {
2055 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2056 HOST_WIDE_INT stack_chunk
2057 = stack_space_to_allocate > (256 - 8 - 8)
2058 ? (256 - 8 - 8) : stack_space_to_allocate;
2059
2060 mmix_emit_sp_add (-stack_chunk);
2061
2062 offset += stack_chunk;
2063 stack_space_to_allocate -= stack_chunk;
2064 }
2065
2066 tmpreg = gen_rtx_REG (DImode, 255);
2067 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2068
2069 /* Dwarf2 code is confused by the use of a temporary register for
2070 storing the return address, so we have to express it as a note,
2071 which we attach to the actual store insn. */
2072 emit_move_insn (tmpreg, retreg);
2073
2074 insn = emit_move_insn (gen_rtx_MEM (DImode,
2075 plus_constant (Pmode,
2076 stack_pointer_rtx,
2077 offset)),
2078 tmpreg);
2079 RTX_FRAME_RELATED_P (insn) = 1;
2080 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
2081 gen_rtx_SET (gen_rtx_MEM (DImode,
2082 plus_constant (Pmode,
2083 stack_pointer_rtx,
2084 offset)),
2085 retreg));
2086
2087 offset -= 8;
2088 }
2089 else if (MMIX_CFUN_HAS_LANDING_PAD)
2090 offset -= 8;
2091
2092 if (MMIX_CFUN_HAS_LANDING_PAD)
2093 {
2094 /* Store the register defining the numbering of local registers, so
2095 we know how long to unwind the register stack. */
2096
2097 if (offset < 0)
2098 {
2099 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2100 HOST_WIDE_INT stack_chunk
2101 = stack_space_to_allocate > (256 - 8 - 8)
2102 ? (256 - 8 - 8) : stack_space_to_allocate;
2103
2104 mmix_emit_sp_add (-stack_chunk);
2105
2106 offset += stack_chunk;
2107 stack_space_to_allocate -= stack_chunk;
2108 }
2109
2110 /* We don't tell dwarf2 about this one; we just have it to unwind
2111 the register stack at landing pads. FIXME: It's a kludge because
2112 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2113 register stack at the moment. Best thing would be to handle it
2114 like stack-pointer offsets. Better: some hook into dwarf2out.c
2115 to produce DW_CFA_expression:s that specify the increment of rO,
2116 and unwind it at eh_return (preferred) or at the landing pad.
2117 Then saves to $0..$G-1 could be specified through that register. */
2118
2119 emit_move_insn (gen_rtx_REG (DImode, 255),
2120 gen_rtx_REG (DImode,
2121 MMIX_rO_REGNUM));
2122 emit_move_insn (gen_rtx_MEM (DImode,
2123 plus_constant (Pmode, stack_pointer_rtx,
2124 offset)),
2125 gen_rtx_REG (DImode, 255));
2126 offset -= 8;
2127 }
2128
2129 /* After the return-address and the frame-pointer, we have the local
2130 variables. They're the ones that may have an "unaligned" size. */
2131 offset -= (locals_size + 7) & ~7;
2132
2133 /* Now store all registers that are global, i.e. not saved by the
2134 register file machinery.
2135
2136 It is assumed that the frame-pointer is one of these registers, so it
2137 is explicitly excluded in the count. */
2138
2139 for (regno = 255;
2140 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2141 regno--)
2142 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2143 && df_regs_ever_live_p (regno) && ! call_used_regs[regno])
2144 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2145 {
2146 rtx insn;
2147
2148 if (offset < 0)
2149 {
2150 HOST_WIDE_INT stack_chunk
2151 = (stack_space_to_allocate > (256 - offset - 8)
2152 ? (256 - offset - 8) : stack_space_to_allocate);
2153
2154 mmix_emit_sp_add (-stack_chunk);
2155 offset += stack_chunk;
2156 stack_space_to_allocate -= stack_chunk;
2157 }
2158
2159 insn = emit_move_insn (gen_rtx_MEM (DImode,
2160 plus_constant (Pmode,
2161 stack_pointer_rtx,
2162 offset)),
2163 gen_rtx_REG (DImode, regno));
2164 RTX_FRAME_RELATED_P (insn) = 1;
2165 offset -= 8;
2166 }
2167
2168 /* Finally, allocate room for outgoing args and local vars if room
2169 wasn't allocated above. */
2170 if (stack_space_to_allocate)
2171 mmix_emit_sp_add (-stack_space_to_allocate);
2172 }
2173
2174 /* Expands the function epilogue into RTX. */
2175
2176 void
2177 mmix_expand_epilogue (void)
2178 {
2179 HOST_WIDE_INT locals_size = get_frame_size ();
2180 int regno;
2181 HOST_WIDE_INT stack_space_to_deallocate
2182 = (crtl->outgoing_args_size
2183 + crtl->args.pretend_args_size
2184 + locals_size + 7) & ~7;
2185
2186 /* The first address to access is beyond the outgoing_args area. */
2187 HOST_WIDE_INT offset = crtl->outgoing_args_size;
2188
2189 /* Add the space for global non-register-stack registers.
2190 It is assumed that the frame-pointer register can be one of these
2191 registers, in which case it is excluded from the count when needed. */
2192 for (regno = 255;
2193 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2194 regno--)
2195 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2196 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2197 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2198 stack_space_to_deallocate += 8;
2199
2200 /* Add in the space for register stack-pointer. If so, always add room
2201 for the saved PC. */
2202 if (MMIX_CFUN_HAS_LANDING_PAD)
2203 stack_space_to_deallocate += 16;
2204 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2205 /* If we have a saved return-address slot, add it in. */
2206 stack_space_to_deallocate += 8;
2207
2208 /* Add in the frame-pointer. */
2209 if (frame_pointer_needed)
2210 stack_space_to_deallocate += 8;
2211
2212 /* Make sure we don't get an unaligned stack. */
2213 if ((stack_space_to_deallocate % 8) != 0)
2214 internal_error ("stack frame not a multiple of octabyte: %wd",
2215 stack_space_to_deallocate);
2216
2217 /* We will add back small offsets to the stack pointer as we go.
2218 First, we restore all registers that are global, i.e. not saved by
2219 the register file machinery. */
2220
2221 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2222 regno <= 255;
2223 regno++)
2224 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2225 && df_regs_ever_live_p (regno) && !call_used_regs[regno])
2226 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2227 {
2228 if (offset > 255)
2229 {
2230 mmix_emit_sp_add (offset);
2231 stack_space_to_deallocate -= offset;
2232 offset = 0;
2233 }
2234
2235 emit_move_insn (gen_rtx_REG (DImode, regno),
2236 gen_rtx_MEM (DImode,
2237 plus_constant (Pmode, stack_pointer_rtx,
2238 offset)));
2239 offset += 8;
2240 }
2241
2242 /* Here is where the local variables were. As in the prologue, they
2243 might be of an unaligned size. */
2244 offset += (locals_size + 7) & ~7;
2245
2246 /* The saved register stack pointer is just below the frame-pointer
2247 register. We don't need to restore it "manually"; the POP
2248 instruction does that. */
2249 if (MMIX_CFUN_HAS_LANDING_PAD)
2250 offset += 16;
2251 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2252 /* The return-address slot is just below the frame-pointer register.
2253 We don't need to restore it because we don't really use it. */
2254 offset += 8;
2255
2256 /* Get back the old frame-pointer-value. */
2257 if (frame_pointer_needed)
2258 {
2259 if (offset > 255)
2260 {
2261 mmix_emit_sp_add (offset);
2262
2263 stack_space_to_deallocate -= offset;
2264 offset = 0;
2265 }
2266
2267 emit_move_insn (hard_frame_pointer_rtx,
2268 gen_rtx_MEM (DImode,
2269 plus_constant (Pmode, stack_pointer_rtx,
2270 offset)));
2271 offset += 8;
2272 }
2273
2274 /* We do not need to restore pretended incoming args, just add back
2275 offset to sp. */
2276 if (stack_space_to_deallocate != 0)
2277 mmix_emit_sp_add (stack_space_to_deallocate);
2278
2279 if (crtl->calls_eh_return)
2280 /* Adjust the (normal) stack-pointer to that of the receiver.
2281 FIXME: It would be nice if we could also adjust the register stack
2282 here, but we need to express it through DWARF 2 too. */
2283 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2284 gen_rtx_REG (DImode,
2285 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2286 }
2287
2288 /* Output an optimal sequence for setting a register to a specific
2289 constant. Used in an alternative for const_ints in movdi, and when
2290 using large stack-frame offsets.
2291
2292 Use do_begin_end to say if a line-starting TAB and newline before the
2293 first insn and after the last insn is wanted. */
2294
2295 void
2296 mmix_output_register_setting (FILE *stream,
2297 int regno,
2298 int64_t value,
2299 int do_begin_end)
2300 {
2301 if (do_begin_end)
2302 fprintf (stream, "\t");
2303
2304 if (insn_const_int_ok_for_constraint (value, CONSTRAINT_K))
2305 fprintf (stream, "NEGU %s,0,%" PRId64, reg_names[regno], -value);
2306 else if (mmix_shiftable_wyde_value ((uint64_t) value))
2307 {
2308 /* First, the one-insn cases. */
2309 mmix_output_shiftvalue_op_from_str (stream, "SET",
2310 (uint64_t)
2311 value);
2312 fprintf (stream, " %s,", reg_names[regno]);
2313 mmix_output_shifted_value (stream, (uint64_t) value);
2314 }
2315 else if (mmix_shiftable_wyde_value (-(uint64_t) value))
2316 {
2317 /* We do this to get a bit more legible assembly code. The next
2318 alternative is mostly redundant with this. */
2319
2320 mmix_output_shiftvalue_op_from_str (stream, "SET",
2321 -(uint64_t)
2322 value);
2323 fprintf (stream, " %s,", reg_names[regno]);
2324 mmix_output_shifted_value (stream, -(uint64_t) value);
2325 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2326 reg_names[regno]);
2327 }
2328 else if (mmix_shiftable_wyde_value (~(uint64_t) value))
2329 {
2330 /* Slightly more expensive, the two-insn cases. */
2331
2332 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2333 is shiftable, or any other one-insn transformation of the value.
2334 FIXME: Check first if the value is "shiftable" by two loading
2335 with two insns, since it makes more readable assembly code (if
2336 anyone else cares). */
2337
2338 mmix_output_shiftvalue_op_from_str (stream, "SET",
2339 ~(uint64_t)
2340 value);
2341 fprintf (stream, " %s,", reg_names[regno]);
2342 mmix_output_shifted_value (stream, ~(uint64_t) value);
2343 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2344 reg_names[regno]);
2345 }
2346 else
2347 {
2348 /* The generic case. 2..4 insns. */
2349 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2350 const char *op = "SET";
2351 const char *line_begin = "";
2352 int insns = 0;
2353 int i;
2354 int64_t tmpvalue = value;
2355
2356 /* Compute the number of insns needed to output this constant. */
2357 for (i = 0; i < 4 && tmpvalue != 0; i++)
2358 {
2359 if (tmpvalue & 65535)
2360 insns++;
2361 tmpvalue >>= 16;
2362 }
2363 if (TARGET_BASE_ADDRESSES && insns == 3)
2364 {
2365 /* The number three is based on a static observation on
2366 ghostscript-6.52. Two and four are excluded because there
2367 are too many such constants, and each unique constant (maybe
2368 offset by 1..255) were used few times compared to other uses,
2369 e.g. addresses.
2370
2371 We use base-plus-offset addressing to force it into a global
2372 register; we just use a "LDA reg,VALUE", which will cause the
2373 assembler and linker to DTRT (for constants as well as
2374 addresses). */
2375 fprintf (stream, "LDA %s,", reg_names[regno]);
2376 mmix_output_octa (stream, value, 0);
2377 }
2378 else
2379 {
2380 /* Output pertinent parts of the 4-wyde sequence.
2381 Still more to do if we want this to be optimal, but hey...
2382 Note that the zero case has been handled above. */
2383 for (i = 0; i < 4 && value != 0; i++)
2384 {
2385 if (value & 65535)
2386 {
2387 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2388 higher_parts[i], reg_names[regno],
2389 (int) (value & 65535));
2390 /* The first one sets the rest of the bits to 0, the next
2391 ones add set bits. */
2392 op = "INC";
2393 line_begin = "\n\t";
2394 }
2395
2396 value >>= 16;
2397 }
2398 }
2399 }
2400
2401 if (do_begin_end)
2402 fprintf (stream, "\n");
2403 }
2404
2405 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2406 else return 0. */
2407
2408 int
2409 mmix_shiftable_wyde_value (uint64_t value)
2410 {
2411 /* Shift by 16 bits per group, stop when we've found two groups with
2412 nonzero bits. */
2413 int i;
2414 int has_candidate = 0;
2415
2416 for (i = 0; i < 4; i++)
2417 {
2418 if (value & 65535)
2419 {
2420 if (has_candidate)
2421 return 0;
2422 else
2423 has_candidate = 1;
2424 }
2425
2426 value >>= 16;
2427 }
2428
2429 return 1;
2430 }
2431
2432 /* X and Y are two things to compare using CODE. Return the rtx for
2433 the cc-reg in the proper mode. */
2434
2435 rtx
2436 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2437 {
2438 machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2439 return gen_reg_rtx (ccmode);
2440 }
2441
2442 /* Local (static) helper functions. */
2443
2444 static void
2445 mmix_emit_sp_add (HOST_WIDE_INT offset)
2446 {
2447 rtx insn;
2448
2449 if (offset < 0)
2450 {
2451 /* Negative stack-pointer adjustments are allocations and appear in
2452 the prologue only. We mark them as frame-related so unwind and
2453 debug info is properly emitted for them. */
2454 if (offset > -255)
2455 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2456 stack_pointer_rtx,
2457 GEN_INT (offset)));
2458 else
2459 {
2460 rtx tmpr = gen_rtx_REG (DImode, 255);
2461 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2462 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2463 stack_pointer_rtx, tmpr));
2464 }
2465 RTX_FRAME_RELATED_P (insn) = 1;
2466 }
2467 else
2468 {
2469 /* Positive adjustments are in the epilogue only. Don't mark them
2470 as "frame-related" for unwind info. */
2471 if (insn_const_int_ok_for_constraint (offset, CONSTRAINT_L))
2472 emit_insn (gen_adddi3 (stack_pointer_rtx,
2473 stack_pointer_rtx,
2474 GEN_INT (offset)));
2475 else
2476 {
2477 rtx tmpr = gen_rtx_REG (DImode, 255);
2478 emit_move_insn (tmpr, GEN_INT (offset));
2479 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2480 stack_pointer_rtx, tmpr));
2481 }
2482 }
2483 }
2484
2485 /* Print operator suitable for doing something with a shiftable
2486 wyde. The type of operator is passed as an asm output modifier. */
2487
2488 static void
2489 mmix_output_shiftvalue_op_from_str (FILE *stream,
2490 const char *mainop,
2491 int64_t value)
2492 {
2493 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2494 int i;
2495
2496 if (! mmix_shiftable_wyde_value (value))
2497 {
2498 char s[sizeof ("0xffffffffffffffff")];
2499 sprintf (s, "%#" PRIx64, value);
2500 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2501 }
2502
2503 for (i = 0; i < 4; i++)
2504 {
2505 /* We know we're through when we find one-bits in the low
2506 16 bits. */
2507 if (value & 0xffff)
2508 {
2509 fprintf (stream, "%s%s", mainop, op_part[i]);
2510 return;
2511 }
2512 value >>= 16;
2513 }
2514
2515 /* No bits set? Then it must have been zero. */
2516 fprintf (stream, "%sL", mainop);
2517 }
2518
2519 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2520
2521 static void
2522 mmix_output_octa (FILE *stream, int64_t value, int do_begin_end)
2523 {
2524 if (do_begin_end)
2525 fprintf (stream, "\tOCTA ");
2526
2527 /* Provide a few alternative output formats depending on the number, to
2528 improve legibility of assembler output. */
2529 if ((value < (int64_t) 0 && value > (int64_t) -10000)
2530 || (value >= (int64_t) 0 && value <= (int64_t) 16384))
2531 fprintf (stream, "%d", (int) value);
2532 else if (value > (int64_t) 0
2533 && value < ((int64_t) 1 << 31) * 2)
2534 fprintf (stream, "#%x", (unsigned int) value);
2535 else if (sizeof (HOST_WIDE_INT) == sizeof (int64_t))
2536 /* We need to avoid the not-so-universal "0x" prefix; we need the
2537 pure hex-digits together with the mmixal "#" hex prefix. */
2538 fprintf (stream, "#" HOST_WIDE_INT_PRINT_HEX_PURE,
2539 (HOST_WIDE_INT) value);
2540 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2541 fprintf (stream, "%" PRIu64, value);
2542
2543 if (do_begin_end)
2544 fprintf (stream, "\n");
2545 }
2546
2547 /* Print the presumed shiftable wyde argument shifted into place (to
2548 be output with an operand). */
2549
2550 static void
2551 mmix_output_shifted_value (FILE *stream, int64_t value)
2552 {
2553 int i;
2554
2555 if (! mmix_shiftable_wyde_value (value))
2556 {
2557 char s[16+2+1];
2558 sprintf (s, "%#" PRIx64, value);
2559 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2560 }
2561
2562 for (i = 0; i < 4; i++)
2563 {
2564 /* We know we're through when we find one-bits in the low 16 bits. */
2565 if (value & 0xffff)
2566 {
2567 fprintf (stream, "#%x", (int) (value & 0xffff));
2568 return;
2569 }
2570
2571 value >>= 16;
2572 }
2573
2574 /* No bits set? Then it must have been zero. */
2575 fprintf (stream, "0");
2576 }
2577
2578 /* Output an MMIX condition name corresponding to an operator
2579 and operands:
2580 (comparison_operator [(comparison_operator ...) (const_int 0)])
2581 which means we have to look at *two* operators.
2582
2583 The argument "reversed" refers to reversal of the condition (not the
2584 same as swapping the arguments). */
2585
2586 static void
2587 mmix_output_condition (FILE *stream, const_rtx x, int reversed)
2588 {
2589 struct cc_conv
2590 {
2591 RTX_CODE cc;
2592
2593 /* The normal output cc-code. */
2594 const char *const normal;
2595
2596 /* The reversed cc-code, or NULL if invalid. */
2597 const char *const reversed;
2598 };
2599
2600 struct cc_type_conv
2601 {
2602 machine_mode cc_mode;
2603
2604 /* Terminated with {UNKNOWN, NULL, NULL} */
2605 const struct cc_conv *const convs;
2606 };
2607
2608 #undef CCEND
2609 #define CCEND {UNKNOWN, NULL, NULL}
2610
2611 static const struct cc_conv cc_fun_convs[]
2612 = {{ORDERED, "Z", "P"},
2613 {UNORDERED, "P", "Z"},
2614 CCEND};
2615 static const struct cc_conv cc_fp_convs[]
2616 = {{GT, "P", NULL},
2617 {LT, "N", NULL},
2618 CCEND};
2619 static const struct cc_conv cc_fpeq_convs[]
2620 = {{NE, "Z", "P"},
2621 {EQ, "P", "Z"},
2622 CCEND};
2623 static const struct cc_conv cc_uns_convs[]
2624 = {{GEU, "NN", "N"},
2625 {GTU, "P", "NP"},
2626 {LEU, "NP", "P"},
2627 {LTU, "N", "NN"},
2628 CCEND};
2629 static const struct cc_conv cc_signed_convs[]
2630 = {{NE, "NZ", "Z"},
2631 {EQ, "Z", "NZ"},
2632 {GE, "NN", "N"},
2633 {GT, "P", "NP"},
2634 {LE, "NP", "P"},
2635 {LT, "N", "NN"},
2636 CCEND};
2637 static const struct cc_conv cc_di_convs[]
2638 = {{NE, "NZ", "Z"},
2639 {EQ, "Z", "NZ"},
2640 {GE, "NN", "N"},
2641 {GT, "P", "NP"},
2642 {LE, "NP", "P"},
2643 {LT, "N", "NN"},
2644 {GTU, "NZ", "Z"},
2645 {LEU, "Z", "NZ"},
2646 CCEND};
2647 #undef CCEND
2648
2649 static const struct cc_type_conv cc_convs[]
2650 = {{CC_FUNmode, cc_fun_convs},
2651 {CC_FPmode, cc_fp_convs},
2652 {CC_FPEQmode, cc_fpeq_convs},
2653 {CC_UNSmode, cc_uns_convs},
2654 {CCmode, cc_signed_convs},
2655 {DImode, cc_di_convs}};
2656
2657 size_t i;
2658 int j;
2659
2660 machine_mode mode = GET_MODE (XEXP (x, 0));
2661 RTX_CODE cc = GET_CODE (x);
2662
2663 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2664 {
2665 if (mode == cc_convs[i].cc_mode)
2666 {
2667 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2668 if (cc == cc_convs[i].convs[j].cc)
2669 {
2670 const char *mmix_cc
2671 = (reversed ? cc_convs[i].convs[j].reversed
2672 : cc_convs[i].convs[j].normal);
2673
2674 if (mmix_cc == NULL)
2675 fatal_insn ("MMIX Internal: Trying to output invalidly\
2676 reversed condition:", x);
2677
2678 fprintf (stream, "%s", mmix_cc);
2679 return;
2680 }
2681
2682 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2683 }
2684 }
2685
2686 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2687 }
2688
2689 /* Return the bit-value for a const_int or const_double. */
2690
2691 int64_t
2692 mmix_intval (const_rtx x)
2693 {
2694 if (GET_CODE (x) == CONST_INT)
2695 return INTVAL (x);
2696
2697 /* We make a little song and dance because converting to long long in
2698 gcc-2.7.2 is broken. I still want people to be able to use it for
2699 cross-compilation to MMIX. */
2700 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2701 return CONST_DOUBLE_HIGH (x);
2702
2703 if (GET_CODE (x) == CONST_DOUBLE)
2704 {
2705 if (GET_MODE (x) == DFmode)
2706 {
2707 long bits[2];
2708
2709 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), bits);
2710
2711 /* The double cast is necessary to avoid getting the long
2712 sign-extended to unsigned long long(!) when they're of
2713 different size (usually 32-bit hosts). */
2714 return
2715 ((uint64_t) (unsigned long) bits[0]
2716 << (uint64_t) 32U)
2717 | (uint64_t) (unsigned long) bits[1];
2718 }
2719 else if (GET_MODE (x) == SFmode)
2720 {
2721 long bits;
2722 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), bits);
2723
2724 return (unsigned long) bits;
2725 }
2726 }
2727
2728 fatal_insn ("MMIX Internal: This is not a constant:", x);
2729 }
2730
2731 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2732
2733 machine_mode
2734 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
2735 machine_mode mode,
2736 int *punsignedp ATTRIBUTE_UNUSED,
2737 const_tree fntype ATTRIBUTE_UNUSED,
2738 int for_return)
2739 {
2740 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2741 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2742 if (for_return == 1)
2743 return mode;
2744
2745 /* Promotion of modes currently generates slow code, extending before
2746 operation, so we do it only for arguments. */
2747 if (GET_MODE_CLASS (mode) == MODE_INT
2748 && GET_MODE_SIZE (mode) < 8)
2749 return DImode;
2750 else
2751 return mode;
2752 }
2753 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2754
2755 static rtx
2756 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2757 int incoming ATTRIBUTE_UNUSED)
2758 {
2759 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2760 }
2761
2762 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2763
2764 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2765 of it; we can deduce the value. */
2766
2767 bool
2768 mmix_frame_pointer_required (void)
2769 {
2770 return (cfun->has_nonlocal_label);
2771 }
2772
2773 /*
2774 * Local variables:
2775 * eval: (c-set-style "gnu")
2776 * indent-tabs-mode: t
2777 * End:
2778 */