Add assember CFI directives to millicode division and remainder routines.
[official-gcc.git] / gcc / config / mmix / mmix.cc
blob4e4fb8bdac27bb67a1bd5095f066796c23373058
1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
5 This file is part of GCC.
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.
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.
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/>. */
21 #define IN_TARGET_CODE 1
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "backend.h"
27 #include "target.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "stringpool.h"
31 #include "attribs.h"
32 #include "df.h"
33 #include "memmodel.h"
34 #include "tm_p.h"
35 #include "insn-config.h"
36 #include "optabs.h"
37 #include "regs.h"
38 #include "emit-rtl.h"
39 #include "recog.h"
40 #include "diagnostic-core.h"
41 #include "output.h"
42 #include "varasm.h"
43 #include "stor-layout.h"
44 #include "calls.h"
45 #include "explow.h"
46 #include "expr.h"
47 #include "dwarf2.h"
48 #include "tm-constrs.h"
49 #include "builtins.h"
51 /* This file should be included last. */
52 #include "target-def.h"
54 /* First some local helper definitions. */
55 #define MMIX_FIRST_GLOBAL_REGNUM 32
57 /* We'd need a current_function_has_landing_pad. It's marked as such when
58 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
59 mostly. */
60 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
62 /* We have no means to tell DWARF 2 about the register stack, so we need
63 to store the return address on the stack if an exception can get into
64 this function. We'll have an "initial value" recorded for the
65 return-register if we've seen a call instruction emitted. This note
66 will be inaccurate before instructions are emitted, but the only caller
67 at that time is looking for modulo from stack-boundary, to which the
68 return-address does not contribute, and which is always 0 for MMIX
69 anyway. Beware of calling leaf_function_p here, as it'll abort if
70 called within a sequence. */
71 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
72 (flag_exceptions \
73 && has_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
75 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
76 (crtl->calls_eh_return \
77 && (EH_RETURN_DATA_REGNO (0) == REGNO \
78 || EH_RETURN_DATA_REGNO (1) == REGNO \
79 || EH_RETURN_DATA_REGNO (2) == REGNO \
80 || EH_RETURN_DATA_REGNO (3) == REGNO))
82 /* For the default ABI, we rename registers at output-time to fill the gap
83 between the (statically partitioned) saved registers and call-clobbered
84 registers. In effect this makes unused call-saved registers to be used
85 as call-clobbered registers. The benefit comes from keeping the number
86 of local registers (value of rL) low, since there's a cost of
87 increasing rL and clearing unused (unset) registers with lower numbers.
88 Don't translate while outputting the prologue. */
89 #define MMIX_OUTPUT_REGNO(N) \
90 (TARGET_ABI_GNU \
91 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
92 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
93 || cfun == NULL \
94 || cfun->machine == NULL \
95 || cfun->machine->in_prologue \
96 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
97 + cfun->machine->highest_saved_stack_register + 1))
99 /* The %d in "POP %d,0". */
100 #define MMIX_POP_ARGUMENT() \
101 ((! TARGET_ABI_GNU \
102 && crtl->return_rtx != NULL \
103 && ! cfun->returns_struct) \
104 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
105 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
106 : 0)
108 /* The canonical saved comparison operands for non-cc0 machines, set in
109 the compare expander. */
110 rtx mmix_compare_op0;
111 rtx mmix_compare_op1;
113 /* Declarations of locals. */
115 /* Intermediate for insn output. */
116 static int mmix_output_destination_register;
118 static void mmix_option_override (void);
119 static void mmix_asm_output_source_filename (FILE *, const char *);
120 static void mmix_output_shiftvalue_op_from_str
121 (FILE *, const char *, int64_t);
122 static void mmix_output_shifted_value (FILE *, int64_t);
123 static void mmix_output_condition (FILE *, const_rtx, int);
124 static void mmix_output_octa (FILE *, int64_t, int);
125 static bool mmix_assemble_integer (rtx, unsigned int, int);
126 static struct machine_function *mmix_init_machine_status (void);
127 static void mmix_encode_section_info (tree, rtx, int);
128 static const char *mmix_strip_name_encoding (const char *);
129 static void mmix_emit_sp_add (HOST_WIDE_INT offset);
130 static void mmix_target_asm_function_prologue (FILE *);
131 static void mmix_target_asm_function_end_prologue (FILE *);
132 static void mmix_target_asm_function_epilogue (FILE *);
133 static reg_class_t mmix_preferred_reload_class (rtx, reg_class_t);
134 static reg_class_t mmix_preferred_output_reload_class (rtx, reg_class_t);
135 static bool mmix_legitimate_address_p (machine_mode, rtx, bool);
136 static bool mmix_legitimate_constant_p (machine_mode, rtx);
137 static void mmix_reorg (void);
138 static void mmix_asm_output_mi_thunk
139 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
140 static void mmix_setup_incoming_varargs
141 (cumulative_args_t, const function_arg_info &, int *, int);
142 static void mmix_file_start (void);
143 static void mmix_file_end (void);
144 static void mmix_init_libfuncs (void);
145 static bool mmix_rtx_costs (rtx, machine_mode, int, int, int *, bool);
146 static int mmix_register_move_cost (machine_mode,
147 reg_class_t, reg_class_t);
148 static rtx mmix_struct_value_rtx (tree, int);
149 static machine_mode mmix_promote_function_mode (const_tree,
150 machine_mode,
151 int *, const_tree, int);
152 static void mmix_function_arg_advance (cumulative_args_t,
153 const function_arg_info &);
154 static rtx mmix_function_incoming_arg (cumulative_args_t,
155 const function_arg_info &);
156 static rtx mmix_function_arg (cumulative_args_t, const function_arg_info &);
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 const function_arg_info &);
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 static HOST_WIDE_INT mmix_static_rtx_alignment (machine_mode);
170 static HOST_WIDE_INT mmix_constant_alignment (const_tree, HOST_WIDE_INT);
171 static HOST_WIDE_INT mmix_starting_frame_offset (void);
173 /* Target structure macros. Listed by node. See `Using and Porting GCC'
174 for a general description. */
176 /* Node: Function Entry */
178 #undef TARGET_ASM_BYTE_OP
179 #define TARGET_ASM_BYTE_OP NULL
180 #undef TARGET_ASM_ALIGNED_HI_OP
181 #define TARGET_ASM_ALIGNED_HI_OP NULL
182 #undef TARGET_ASM_ALIGNED_SI_OP
183 #define TARGET_ASM_ALIGNED_SI_OP NULL
184 #undef TARGET_ASM_ALIGNED_DI_OP
185 #define TARGET_ASM_ALIGNED_DI_OP NULL
186 #undef TARGET_ASM_INTEGER
187 #define TARGET_ASM_INTEGER mmix_assemble_integer
189 #undef TARGET_ASM_FUNCTION_PROLOGUE
190 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
192 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
193 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
195 #undef TARGET_ASM_FUNCTION_EPILOGUE
196 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
198 #undef TARGET_PRINT_OPERAND
199 #define TARGET_PRINT_OPERAND mmix_print_operand
200 #undef TARGET_PRINT_OPERAND_ADDRESS
201 #define TARGET_PRINT_OPERAND_ADDRESS mmix_print_operand_address
202 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
203 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mmix_print_operand_punct_valid_p
205 #undef TARGET_ENCODE_SECTION_INFO
206 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
207 #undef TARGET_STRIP_NAME_ENCODING
208 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
210 #undef TARGET_ASM_OUTPUT_MI_THUNK
211 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
212 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
213 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
214 #undef TARGET_ASM_FILE_START
215 #define TARGET_ASM_FILE_START mmix_file_start
216 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
217 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
218 #undef TARGET_ASM_FILE_END
219 #define TARGET_ASM_FILE_END mmix_file_end
220 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
221 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
223 #undef TARGET_ASM_OUTPUT_IDENT
224 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
226 #undef TARGET_INIT_LIBFUNCS
227 #define TARGET_INIT_LIBFUNCS mmix_init_libfuncs
229 #undef TARGET_CONDITIONAL_REGISTER_USAGE
230 #define TARGET_CONDITIONAL_REGISTER_USAGE mmix_conditional_register_usage
232 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
233 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
235 #undef TARGET_RTX_COSTS
236 #define TARGET_RTX_COSTS mmix_rtx_costs
237 #undef TARGET_ADDRESS_COST
238 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
240 #undef TARGET_REGISTER_MOVE_COST
241 #define TARGET_REGISTER_MOVE_COST mmix_register_move_cost
243 #undef TARGET_MACHINE_DEPENDENT_REORG
244 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
246 #undef TARGET_PROMOTE_FUNCTION_MODE
247 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
249 #undef TARGET_FUNCTION_VALUE
250 #define TARGET_FUNCTION_VALUE mmix_function_value
251 #undef TARGET_LIBCALL_VALUE
252 #define TARGET_LIBCALL_VALUE mmix_libcall_value
253 #undef TARGET_FUNCTION_VALUE_REGNO_P
254 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
256 #undef TARGET_FUNCTION_ARG
257 #define TARGET_FUNCTION_ARG mmix_function_arg
258 #undef TARGET_FUNCTION_INCOMING_ARG
259 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
260 #undef TARGET_FUNCTION_ARG_ADVANCE
261 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
262 #undef TARGET_STRUCT_VALUE_RTX
263 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
264 #undef TARGET_SETUP_INCOMING_VARARGS
265 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
266 #undef TARGET_PASS_BY_REFERENCE
267 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
268 #undef TARGET_CALLEE_COPIES
269 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_arg_info_true
271 #undef TARGET_PREFERRED_RELOAD_CLASS
272 #define TARGET_PREFERRED_RELOAD_CLASS mmix_preferred_reload_class
273 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
274 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS mmix_preferred_output_reload_class
276 #undef TARGET_LRA_P
277 #define TARGET_LRA_P hook_bool_void_false
279 #undef TARGET_LEGITIMATE_ADDRESS_P
280 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
281 #undef TARGET_LEGITIMATE_CONSTANT_P
282 #define TARGET_LEGITIMATE_CONSTANT_P mmix_legitimate_constant_p
284 #undef TARGET_FRAME_POINTER_REQUIRED
285 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
287 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
288 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
289 #undef TARGET_TRAMPOLINE_INIT
290 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
292 #undef TARGET_OPTION_OVERRIDE
293 #define TARGET_OPTION_OVERRIDE mmix_option_override
295 #undef TARGET_STATIC_RTX_ALIGNMENT
296 #define TARGET_STATIC_RTX_ALIGNMENT mmix_static_rtx_alignment
297 #undef TARGET_CONSTANT_ALIGNMENT
298 #define TARGET_CONSTANT_ALIGNMENT mmix_constant_alignment
300 #undef TARGET_STARTING_FRAME_OFFSET
301 #define TARGET_STARTING_FRAME_OFFSET mmix_starting_frame_offset
303 struct gcc_target targetm = TARGET_INITIALIZER;
305 /* Functions that are expansions for target macros.
306 See Target Macros in `Using and Porting GCC'. */
308 /* TARGET_OPTION_OVERRIDE. */
310 static void
311 mmix_option_override (void)
313 /* Should we err or should we warn? Hmm. At least we must neutralize
314 it. For example the wrong kind of case-tables will be generated with
315 PIC; we use absolute address items for mmixal compatibility. FIXME:
316 They could be relative if we just elide them to after all pertinent
317 labels. */
318 if (flag_pic)
320 warning (0, "%<-f%s%> not supported: ignored",
321 (flag_pic > 1) ? "PIC" : "pic");
322 flag_pic = 0;
325 /* Don't bother with mmixal-compatible syntax if it's likely that a
326 certain format of the assembly is expected, like no new-line
327 after the .byte (or BYTE) parameter, when scanning debug-info
328 output, as happens in many places in the gcc testsuite. The
329 dwarf2 output code (maybe others) takes a shortcut based on the
330 presence of certain assembler directives, instead of calling
331 assemble_integer. Not worthwhile editing the test-cases:
332 mixed-syntax assembly output already looks too ugly for the
333 intent of being readable, and the resulting mix certainly fails
334 the intent of being compatible with mmixal. See
335 varasm.cc:default_file_start for this triple. See also
336 mmix_assemble_integer. */
337 if (flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm)
339 /* "Reinstate" the defaults from target-def.h that we
340 overrode. */
341 targetm.asm_out.byte_op = "\t.byte\t";
342 targetm.asm_out.aligned_op.hi = "\t.short\t";
343 targetm.asm_out.aligned_op.si = "\t.long\t";
345 /* Note that TARGET_ASM_ALIGNED_DI_OP is default NULL, so
346 there's nothing to "reinstate". Still, we add the universal
347 default (with "recent" gas) for an address. */
348 targetm.asm_out.aligned_op.di = "\t.dc.a\t";
352 /* INIT_EXPANDERS. */
354 void
355 mmix_init_expanders (void)
357 init_machine_status = mmix_init_machine_status;
360 /* Set the per-function data. */
362 static struct machine_function *
363 mmix_init_machine_status (void)
365 return ggc_cleared_alloc<machine_function> ();
368 /* DATA_ABI_ALIGNMENT.
369 We have trouble getting the address of stuff that is located at other
370 than 32-bit alignments (GETA requirements), so try to give everything
371 at least 32-bit alignment. */
374 mmix_data_alignment (tree type ATTRIBUTE_UNUSED, int basic_align)
376 if (basic_align < 32)
377 return 32;
379 return basic_align;
382 /* Implement TARGET_STATIC_RTX_ALIGNMENT. */
384 static HOST_WIDE_INT
385 mmix_static_rtx_alignment (machine_mode mode)
387 return MAX (GET_MODE_ALIGNMENT (mode), 32);
390 /* Implement tARGET_CONSTANT_ALIGNMENT. */
392 static HOST_WIDE_INT
393 mmix_constant_alignment (const_tree, HOST_WIDE_INT basic_align)
395 if (basic_align < 32)
396 return 32;
398 return basic_align;
401 /* LOCAL_ALIGNMENT. */
403 unsigned
404 mmix_local_alignment (tree type ATTRIBUTE_UNUSED, unsigned basic_align)
406 if (basic_align < 32)
407 return 32;
409 return basic_align;
412 /* TARGET_CONDITIONAL_REGISTER_USAGE. */
414 static void
415 mmix_conditional_register_usage (void)
417 int i;
419 if (TARGET_ABI_GNU)
421 static const int gnu_abi_reg_alloc_order[]
422 = MMIX_GNU_ABI_REG_ALLOC_ORDER;
424 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
425 reg_alloc_order[i] = gnu_abi_reg_alloc_order[i];
427 /* Change the default from the mmixware ABI. For the GNU ABI,
428 $15..$30 are call-saved just as $0..$14. There must be one
429 call-clobbered local register for the "hole" that holds the
430 number of saved local registers saved by PUSHJ/PUSHGO during the
431 function call, receiving the return value at return. So best is
432 to use the highest, $31. It's already marked call-clobbered for
433 the mmixware ABI. */
434 for (i = 15; i <= 30; i++)
435 call_used_regs[i] = 0;
437 /* "Unfix" the parameter registers. */
438 for (i = MMIX_RESERVED_GNU_ARG_0_REGNUM;
439 i < MMIX_RESERVED_GNU_ARG_0_REGNUM + MMIX_MAX_ARGS_IN_REGS;
440 i++)
441 fixed_regs[i] = 0;
444 /* Step over the ":" in special register names. */
445 if (! TARGET_TOPLEVEL_SYMBOLS)
446 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
447 if (reg_names[i][0] == ':')
448 reg_names[i]++;
451 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
452 Those two macros must only be applied to function argument
453 registers and the function return value register for the opposite
454 use. FIXME: for their current use in gcc, it'd be better with an
455 explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P a'la
456 TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
457 forcing the target to commit to a fixed mapping and for any
458 unspecified register use. Particularly when thinking about the
459 return-value, it is better to imagine INCOMING_REGNO and
460 OUTGOING_REGNO as named CALLEE_TO_CALLER_REGNO and INNER_REGNO as
461 named CALLER_TO_CALLEE_REGNO because the direction. The "incoming"
462 and "outgoing" is from the perspective of the parameter-registers,
463 but the same macro is (must be, lacking an alternative like
464 suggested above) used to map the return-value-register from the
465 same perspective. To make directions even more confusing, the macro
466 MMIX_OUTGOING_RETURN_VALUE_REGNUM holds the number of the register
467 in which to return a value, i.e. INCOMING_REGNO for the return-value-
468 register as received from a called function; the return-value on the
469 way out. */
472 mmix_opposite_regno (int regno, int incoming)
474 if (incoming && regno == MMIX_OUTGOING_RETURN_VALUE_REGNUM)
475 return MMIX_RETURN_VALUE_REGNUM;
477 if (!incoming && regno == MMIX_RETURN_VALUE_REGNUM)
478 return MMIX_OUTGOING_RETURN_VALUE_REGNUM;
480 if (!mmix_function_arg_regno_p (regno, incoming))
481 return regno;
483 return
484 regno - (incoming
485 ? MMIX_FIRST_INCOMING_ARG_REGNUM - MMIX_FIRST_ARG_REGNUM
486 : MMIX_FIRST_ARG_REGNUM - MMIX_FIRST_INCOMING_ARG_REGNUM);
489 /* LOCAL_REGNO.
490 All registers that are part of the register stack and that will be
491 saved are local. */
494 mmix_local_regno (int regno)
496 return (regno <= MMIX_LAST_STACK_REGISTER_REGNUM
497 && !call_used_or_fixed_reg_p (regno));
500 /* TARGET_PREFERRED_RELOAD_CLASS.
501 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
503 static reg_class_t
504 mmix_preferred_reload_class (rtx x, reg_class_t rclass)
506 /* FIXME: Revisit. */
507 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
508 ? REMAINDER_REG : rclass;
511 /* TARGET_PREFERRED_OUTPUT_RELOAD_CLASS.
512 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
514 static reg_class_t
515 mmix_preferred_output_reload_class (rtx x, reg_class_t rclass)
517 /* FIXME: Revisit. */
518 return GET_CODE (x) == MOD && GET_MODE (x) == DImode
519 ? REMAINDER_REG : rclass;
522 /* SECONDARY_RELOAD_CLASS.
523 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
525 enum reg_class
526 mmix_secondary_reload_class (enum reg_class rclass,
527 machine_mode mode ATTRIBUTE_UNUSED,
528 rtx x ATTRIBUTE_UNUSED,
529 int in_p ATTRIBUTE_UNUSED)
531 if (rclass == REMAINDER_REG
532 || rclass == HIMULT_REG
533 || rclass == SYSTEM_REGS)
534 return GENERAL_REGS;
536 return NO_REGS;
539 /* DYNAMIC_CHAIN_ADDRESS. */
542 mmix_dynamic_chain_address (rtx frame)
544 /* FIXME: the frame-pointer is stored at offset -8 from the current
545 frame-pointer. Unfortunately, the caller assumes that a
546 frame-pointer is present for *all* previous frames. There should be
547 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
548 return plus_constant (Pmode, frame, -8);
551 /* Implement TARGET_STARTING_FRAME_OFFSET. */
553 static HOST_WIDE_INT
554 mmix_starting_frame_offset (void)
556 /* The old frame pointer is in the slot below the new one, so
557 FIRST_PARM_OFFSET does not need to depend on whether the
558 frame-pointer is needed or not. We have to adjust for the register
559 stack pointer being located below the saved frame pointer.
560 Similarly, we store the return address on the stack too, for
561 exception handling, and always if we save the register stack pointer. */
562 return
564 + (MMIX_CFUN_HAS_LANDING_PAD
565 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? -8 : 0)));
568 /* RETURN_ADDR_RTX. */
571 mmix_return_addr_rtx (int count, rtx frame ATTRIBUTE_UNUSED)
573 return count == 0
574 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
575 /* FIXME: Set frame_alias_set on the following. (Why?)
576 See mmix_initial_elimination_offset for the reason we can't use
577 get_hard_reg_initial_val for both. Always using a stack slot
578 and not a register would be suboptimal. */
579 ? validize_mem (gen_rtx_MEM (Pmode,
580 plus_constant (Pmode,
581 frame_pointer_rtx, -16)))
582 : get_hard_reg_initial_val (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM))
583 : NULL_RTX;
586 /* SETUP_FRAME_ADDRESSES. */
588 void
589 mmix_setup_frame_addresses (void)
591 /* Nothing needed at the moment. */
594 /* The difference between the (imaginary) frame pointer and the stack
595 pointer. Used to eliminate the frame pointer. */
598 mmix_initial_elimination_offset (int fromreg, int toreg)
600 int regno;
601 int fp_sp_offset
602 = (get_frame_size () + crtl->outgoing_args_size + 7) & ~7;
604 /* There is no actual offset between these two virtual values, but for
605 the frame-pointer, we have the old one in the stack position below
606 it, so the offset for the frame-pointer to the stack-pointer is one
607 octabyte larger. */
608 if (fromreg == MMIX_ARG_POINTER_REGNUM
609 && toreg == MMIX_FRAME_POINTER_REGNUM)
610 return 0;
612 /* The difference is the size of local variables plus the size of
613 outgoing function arguments that would normally be passed as
614 registers but must be passed on stack because we're out of
615 function-argument registers. Only global saved registers are
616 counted; the others go on the register stack.
618 The frame-pointer is counted too if it is what is eliminated, as we
619 need to balance the offset for it from TARGET_STARTING_FRAME_OFFSET.
621 Also add in the slot for the register stack pointer we save if we
622 have a landing pad.
624 Unfortunately, we can't access $0..$14, from unwinder code easily, so
625 store the return address in a frame slot too. FIXME: Only for
626 non-leaf functions. FIXME: Always with a landing pad, because it's
627 hard to know whether we need the other at the time we know we need
628 the offset for one (and have to state it). It's a kludge until we
629 can express the register stack in the EH frame info.
631 We have to do alignment here; get_frame_size will not return a
632 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
634 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
635 regno <= 255;
636 regno++)
637 if ((df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
638 || IS_MMIX_EH_RETURN_DATA_REG (regno))
639 fp_sp_offset += 8;
641 return fp_sp_offset
642 + (MMIX_CFUN_HAS_LANDING_PAD
643 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS ? 8 : 0))
644 + (fromreg == MMIX_ARG_POINTER_REGNUM ? 0 : 8);
647 static void
648 mmix_function_arg_advance (cumulative_args_t argsp_v,
649 const function_arg_info &arg)
651 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
652 int arg_size = MMIX_FUNCTION_ARG_SIZE (arg.mode, arg.type);
654 argsp->regs = ((targetm.calls.must_pass_in_stack (arg)
655 || (arg_size > 8
656 && !TARGET_LIBFUNC
657 && !argsp->lib))
658 ? (MMIX_MAX_ARGS_IN_REGS) + 1
659 : argsp->regs + (7 + arg_size) / 8);
662 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
664 static rtx
665 mmix_function_arg_1 (const cumulative_args_t argsp_v,
666 const function_arg_info &arg, bool incoming)
668 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
670 /* The mode of the argument will be VOIDmode for the "end_marker". Make sure
671 we don't ever generate a VOIDmode register; later passes will barf on that.
672 We may want to use the register number, so return something nominally
673 useful. Thus, for VOIDmode, use DImode, being the natural mode for the
674 register. */
675 machine_mode mode = arg.mode == VOIDmode ? DImode : arg.mode;
677 /* Last-argument marker. */
678 if (arg.end_marker_p ())
679 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS)
680 ? gen_rtx_REG (mode,
681 (incoming
682 ? MMIX_FIRST_INCOMING_ARG_REGNUM
683 : MMIX_FIRST_ARG_REGNUM) + argsp->regs)
684 : NULL_RTX;
686 return (argsp->regs < MMIX_MAX_ARGS_IN_REGS
687 && !targetm.calls.must_pass_in_stack (arg)
688 && (GET_MODE_BITSIZE (mode) <= 64
689 || argsp->lib
690 || TARGET_LIBFUNC))
691 ? gen_rtx_REG (mode,
692 (incoming
693 ? MMIX_FIRST_INCOMING_ARG_REGNUM
694 : MMIX_FIRST_ARG_REGNUM)
695 + argsp->regs)
696 : NULL_RTX;
699 /* Return an rtx for a function argument to go in a register, and 0 for
700 one that must go on stack. */
702 static rtx
703 mmix_function_arg (cumulative_args_t argsp, const function_arg_info &arg)
705 return mmix_function_arg_1 (argsp, arg, false);
708 static rtx
709 mmix_function_incoming_arg (cumulative_args_t argsp,
710 const function_arg_info &arg)
712 return mmix_function_arg_1 (argsp, arg, true);
715 /* Returns nonzero for everything that goes by reference, 0 for
716 everything that goes by value. */
718 static bool
719 mmix_pass_by_reference (cumulative_args_t argsp_v,
720 const function_arg_info &arg)
722 CUMULATIVE_ARGS *argsp = get_cumulative_args (argsp_v);
724 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
725 necessary. */
726 if (targetm.calls.must_pass_in_stack (arg))
727 return true;
729 if (MMIX_FUNCTION_ARG_SIZE (arg.mode, arg.type) > 8
730 && !TARGET_LIBFUNC
731 && (!argsp || !argsp->lib))
732 return true;
734 return false;
737 /* Return nonzero if regno is a register number where a parameter is
738 passed, and 0 otherwise. */
741 mmix_function_arg_regno_p (int regno, int incoming)
743 int first_arg_regnum
744 = incoming ? MMIX_FIRST_INCOMING_ARG_REGNUM : MMIX_FIRST_ARG_REGNUM;
746 return regno >= first_arg_regnum
747 && regno < first_arg_regnum + MMIX_MAX_ARGS_IN_REGS;
750 /* Implements TARGET_FUNCTION_VALUE. */
752 static rtx
753 mmix_function_value (const_tree valtype,
754 const_tree func ATTRIBUTE_UNUSED,
755 bool outgoing)
757 machine_mode mode = TYPE_MODE (valtype);
758 machine_mode cmode;
759 int first_val_regnum = MMIX_OUTGOING_RETURN_VALUE_REGNUM;
760 rtx vec[MMIX_MAX_REGS_FOR_VALUE];
761 int i;
762 int nregs;
764 if (!outgoing)
765 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
767 /* Return values that fit in a register need no special handling.
768 There's no register hole when parameters are passed in global
769 registers. */
770 if (TARGET_ABI_GNU
771 || GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)
772 return
773 gen_rtx_REG (mode, MMIX_OUTGOING_RETURN_VALUE_REGNUM);
775 if (COMPLEX_MODE_P (mode))
776 /* A complex type, made up of components. */
777 cmode = TYPE_MODE (TREE_TYPE (valtype));
778 else
780 /* Of the other larger-than-register modes, we only support
781 scalar mode TImode. (At least, that's the only one that's
782 been rudimentally tested.) Make sure we're alerted for
783 unexpected cases. */
784 if (mode != TImode)
785 sorry ("support for mode %qs", GET_MODE_NAME (mode));
787 /* In any case, we will fill registers to the natural size. */
788 cmode = DImode;
791 nregs = ((GET_MODE_BITSIZE (mode) + BITS_PER_WORD - 1) / BITS_PER_WORD);
793 /* We need to take care of the effect of the register hole on return
794 values of large sizes; the last register will appear as the first
795 register, with the rest shifted. (For complex modes, this is just
796 swapped registers.) */
798 if (nregs > MMIX_MAX_REGS_FOR_VALUE)
799 internal_error ("too large function value type, needs %d registers,\
800 have only %d registers for this", nregs, MMIX_MAX_REGS_FOR_VALUE);
802 /* FIXME: Maybe we should handle structure values like this too
803 (adjusted for BLKmode), perhaps for both ABI:s. */
804 for (i = 0; i < nregs - 1; i++)
805 vec[i]
806 = gen_rtx_EXPR_LIST (VOIDmode,
807 gen_rtx_REG (cmode, first_val_regnum + i),
808 GEN_INT ((i + 1) * BITS_PER_UNIT));
810 vec[nregs - 1]
811 = gen_rtx_EXPR_LIST (VOIDmode,
812 gen_rtx_REG (cmode, first_val_regnum + nregs - 1),
813 const0_rtx);
815 return gen_rtx_PARALLEL (mode, gen_rtvec_v (nregs, vec));
818 /* Implements TARGET_LIBCALL_VALUE. */
820 static rtx
821 mmix_libcall_value (machine_mode mode,
822 const_rtx fun ATTRIBUTE_UNUSED)
824 return gen_rtx_REG (mode, MMIX_RETURN_VALUE_REGNUM);
827 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
829 static bool
830 mmix_function_value_regno_p (const unsigned int regno)
832 return regno == MMIX_RETURN_VALUE_REGNUM;
835 /* EH_RETURN_DATA_REGNO. */
838 mmix_eh_return_data_regno (int n)
840 if (n >= 0 && n < 4)
841 return MMIX_EH_RETURN_DATA_REGNO_START + n;
843 return INVALID_REGNUM;
846 /* EH_RETURN_STACKADJ_RTX. */
849 mmix_eh_return_stackadj_rtx (void)
851 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
854 /* EH_RETURN_HANDLER_RTX. */
857 mmix_eh_return_handler_rtx (void)
859 return gen_rtx_REG (Pmode, MMIX_INCOMING_RETURN_ADDRESS_REGNUM);
862 /* ASM_PREFERRED_EH_DATA_FORMAT. */
865 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED,
866 int global ATTRIBUTE_UNUSED)
868 /* This is the default (was at 2001-07-20). Revisit when needed. */
869 return DW_EH_PE_absptr;
872 /* Make a note that we've seen the beginning of the prologue. This
873 matters to whether we'll translate register numbers as calculated by
874 mmix_reorg. */
876 static void
877 mmix_target_asm_function_prologue (FILE *)
879 cfun->machine->in_prologue = 1;
882 /* Make a note that we've seen the end of the prologue. */
884 static void
885 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED)
887 cfun->machine->in_prologue = 0;
890 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
891 done here; just virtually by calculating the highest saved stack
892 register number used to modify the register numbers at output time. */
894 static void
895 mmix_reorg (void)
897 int regno;
899 /* We put the number of the highest saved register-file register in a
900 location convenient for the call-patterns to output. Note that we
901 don't tell dwarf2 about these registers, since it can't restore them
902 anyway. */
903 for (regno = MMIX_LAST_STACK_REGISTER_REGNUM;
904 regno >= 0;
905 regno--)
906 if ((df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
907 || (regno == MMIX_FRAME_POINTER_REGNUM && frame_pointer_needed))
908 break;
910 /* Regardless of whether they're saved (they might be just read), we
911 mustn't include registers that carry parameters. We could scan the
912 insns to see whether they're actually used (and indeed do other less
913 trivial register usage analysis and transformations), but it seems
914 wasteful to optimize for unused parameter registers. As of
915 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
916 that might change. */
917 if (!TARGET_ABI_GNU && regno < crtl->args.info.regs - 1)
919 regno = crtl->args.info.regs - 1;
921 /* We don't want to let this cause us to go over the limit and make
922 incoming parameter registers be misnumbered and treating the last
923 parameter register and incoming return value register call-saved.
924 Stop things at the unmodified scheme. */
925 if (regno > MMIX_RETURN_VALUE_REGNUM - 1)
926 regno = MMIX_RETURN_VALUE_REGNUM - 1;
929 cfun->machine->highest_saved_stack_register = regno;
932 /* TARGET_ASM_FUNCTION_EPILOGUE. */
934 static void
935 mmix_target_asm_function_epilogue (FILE *stream)
937 /* Emit an \n for readability of the generated assembly. */
938 fputc ('\n', stream);
941 /* TARGET_ASM_OUTPUT_MI_THUNK. */
943 static void
944 mmix_asm_output_mi_thunk (FILE *stream,
945 tree thunk_fndecl ATTRIBUTE_UNUSED,
946 HOST_WIDE_INT delta,
947 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
948 tree func)
950 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
951 location of structure to return as invisible first argument), you
952 need to tweak this code too. */
953 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
954 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl));
956 assemble_start_function (thunk_fndecl, fnname);
958 if (delta >= 0 && delta < 65536)
959 fprintf (stream, "\tINCL %s,%d\n", regname, (int)delta);
960 else if (delta < 0 && delta >= -255)
961 fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, (int)-delta);
962 else
964 mmix_output_register_setting (stream, 255, delta, 1);
965 fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
968 fprintf (stream, "\tJMP ");
969 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
970 fprintf (stream, "\n");
971 assemble_end_function (thunk_fndecl, fnname);
974 /* FUNCTION_PROFILER. */
976 void
977 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED,
978 int labelno ATTRIBUTE_UNUSED)
980 sorry ("%<function_profiler%> support for MMIX");
983 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
984 let's stick to pushing argument registers on the stack. Later, we
985 can parse all arguments in registers, to improve performance. */
987 static void
988 mmix_setup_incoming_varargs (cumulative_args_t args_so_farp_v,
989 const function_arg_info &arg,
990 int *pretend_sizep,
991 int second_time ATTRIBUTE_UNUSED)
993 CUMULATIVE_ARGS *args_so_farp = get_cumulative_args (args_so_farp_v);
995 /* The last named variable has been handled, but
996 args_so_farp has not been advanced for it. */
997 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
998 *pretend_sizep = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1000 /* We assume that one argument takes up one register here. That should
1001 be true until we start messing with multi-reg parameters. */
1002 if (!TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (current_function_decl))
1003 && (7 + (MMIX_FUNCTION_ARG_SIZE (arg.mode, arg.type))) / 8 != 1)
1004 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1007 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
1009 static void
1010 mmix_asm_trampoline_template (FILE *stream)
1012 /* Read a value into the static-chain register and jump somewhere. The
1013 static chain is stored at offset 16, and the function address is
1014 stored at offset 24. */
1016 fprintf (stream, "\tGETA $255,1F\n\t");
1017 fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1018 fprintf (stream, "LDOU $255,$255,8\n\t");
1019 fprintf (stream, "GO $255,$255,0\n");
1020 fprintf (stream, "1H\tOCTA 0\n\t");
1021 fprintf (stream, "OCTA 0\n");
1024 /* TARGET_TRAMPOLINE_INIT. */
1025 /* Set the static chain and function pointer field in the trampoline.
1026 We also SYNCID here to be sure (doesn't matter in the simulator, but
1027 some day it will). */
1029 static void
1030 mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
1032 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
1033 rtx mem;
1035 emit_block_move (m_tramp, assemble_trampoline_template (),
1036 GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
1038 mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
1039 emit_move_insn (mem, static_chain);
1040 mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
1041 emit_move_insn (mem, fnaddr);
1043 mem = adjust_address (m_tramp, DImode, 0);
1044 emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
1047 /* We must exclude constant addresses that have an increment that is not a
1048 multiple of four bytes because of restrictions of the GETA
1049 instruction, unless TARGET_BASE_ADDRESSES. */
1052 mmix_constant_address_p (rtx x)
1054 RTX_CODE code = GET_CODE (x);
1055 int addend = 0;
1056 /* When using "base addresses", anything constant goes. */
1057 int constant_ok = TARGET_BASE_ADDRESSES != 0;
1059 switch (code)
1061 case LABEL_REF:
1062 case SYMBOL_REF:
1063 return 1;
1065 case HIGH:
1066 /* FIXME: Don't know how to dissect these. Avoid them for now,
1067 except we know they're constants. */
1068 return constant_ok;
1070 case CONST_INT:
1071 addend = INTVAL (x);
1072 break;
1074 case CONST_DOUBLE:
1075 if (GET_MODE (x) != VOIDmode)
1076 /* Strange that we got here. FIXME: Check if we do. */
1077 return constant_ok;
1078 addend = CONST_DOUBLE_LOW (x);
1079 break;
1081 case CONST:
1082 /* Note that expressions with arithmetic on forward references don't
1083 work in mmixal. People using gcc assembly code with mmixal might
1084 need to move arrays and such to before the point of use. */
1085 if (GET_CODE (XEXP (x, 0)) == PLUS)
1087 rtx x0 = XEXP (XEXP (x, 0), 0);
1088 rtx x1 = XEXP (XEXP (x, 0), 1);
1090 if ((GET_CODE (x0) == SYMBOL_REF
1091 || GET_CODE (x0) == LABEL_REF)
1092 && (GET_CODE (x1) == CONST_INT
1093 || (GET_CODE (x1) == CONST_DOUBLE
1094 && GET_MODE (x1) == VOIDmode)))
1095 addend = mmix_intval (x1);
1096 else
1097 return constant_ok;
1099 else
1100 return constant_ok;
1101 break;
1103 default:
1104 return 0;
1107 return constant_ok || (addend & 3) == 0;
1110 /* Return 1 if the address is OK, otherwise 0. */
1112 bool
1113 mmix_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED,
1114 rtx x,
1115 bool strict_checking)
1117 #define MMIX_REG_OK(X) \
1118 ((strict_checking \
1119 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1120 || (reg_renumber[REGNO (X)] > 0 \
1121 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1122 || (!strict_checking \
1123 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1124 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1125 || REGNO (X) == ARG_POINTER_REGNUM)))
1127 /* We only accept:
1128 (mem reg)
1129 (mem (plus reg reg))
1130 (mem (plus reg 0..255)).
1131 unless TARGET_BASE_ADDRESSES, in which case we accept all
1132 (mem constant_address) too. */
1135 /* (mem reg) */
1136 if (REG_P (x) && MMIX_REG_OK (x))
1137 return 1;
1139 if (GET_CODE(x) == PLUS)
1141 rtx x1 = XEXP (x, 0);
1142 rtx x2 = XEXP (x, 1);
1144 /* Try swapping the order. FIXME: Do we need this? */
1145 if (! REG_P (x1))
1147 rtx tem = x1;
1148 x1 = x2;
1149 x2 = tem;
1152 /* (mem (plus (reg?) (?))) */
1153 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1154 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1156 /* (mem (plus (reg) (reg?))) */
1157 if (REG_P (x2) && MMIX_REG_OK (x2))
1158 return 1;
1160 /* (mem (plus (reg) (0..255?))) */
1161 if (satisfies_constraint_I (x2))
1162 return 1;
1164 return 0;
1167 return TARGET_BASE_ADDRESSES && mmix_constant_address_p (x);
1170 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1172 static bool
1173 mmix_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1175 RTX_CODE code = GET_CODE (x);
1177 /* We must allow any number due to the way the cse passes works; if we
1178 do not allow any number here, general_operand will fail, and insns
1179 will fatally fail recognition instead of "softly". */
1180 if (code == CONST_INT || code == CONST_DOUBLE)
1181 return 1;
1183 return CONSTANT_ADDRESS_P (x);
1186 /* SELECT_CC_MODE. */
1188 machine_mode
1189 mmix_select_cc_mode (RTX_CODE op, rtx x, rtx y ATTRIBUTE_UNUSED)
1191 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1192 output different compare insns. Note that we do not check the
1193 validity of the comparison here. */
1195 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1197 if (op == ORDERED || op == UNORDERED || op == UNGE
1198 || op == UNGT || op == UNLE || op == UNLT)
1199 return CC_FUNmode;
1201 if (op == EQ || op == NE)
1202 return CC_FPEQmode;
1204 return CC_FPmode;
1207 if (op == GTU || op == LTU || op == GEU || op == LEU)
1208 return CC_UNSmode;
1210 return CCmode;
1213 /* REVERSIBLE_CC_MODE. */
1216 mmix_reversible_cc_mode (machine_mode mode)
1218 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1219 compares. */
1220 return mode != CC_FPmode;
1223 /* TARGET_RTX_COSTS. */
1225 static bool
1226 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED,
1227 machine_mode mode ATTRIBUTE_UNUSED,
1228 int outer_code ATTRIBUTE_UNUSED,
1229 int opno ATTRIBUTE_UNUSED,
1230 int *total ATTRIBUTE_UNUSED,
1231 bool speed ATTRIBUTE_UNUSED)
1233 /* For the time being, this is just a stub and we'll accept the
1234 generic calculations, until we can do measurements, at least.
1235 Say we did not modify any calculated costs. */
1236 return false;
1239 /* TARGET_REGISTER_MOVE_COST.
1241 The special registers can only move to and from general regs, and we
1242 need to check that their constraints match, so say 3 for them. */
1244 static int
1245 mmix_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
1246 reg_class_t from,
1247 reg_class_t to)
1249 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1252 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1253 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1254 the target. */
1256 /* DATA_SECTION_ASM_OP. */
1258 const char *
1259 mmix_data_section_asm_op (void)
1261 return "\t.data ! mmixal:= 8H LOC 9B";
1264 static void
1265 mmix_encode_section_info (tree decl, rtx rtl, int first)
1267 /* Test for an external declaration, and do nothing if it is one. */
1268 if ((TREE_CODE (decl) == VAR_DECL
1269 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1270 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
1272 else if (first && DECL_P (decl))
1274 /* For non-visible declarations, add a "@" prefix, which we skip
1275 when the label is output. If the label does not have this
1276 prefix, a ":" is output if -mtoplevel-symbols.
1278 Note that this does not work for data that is declared extern and
1279 later defined as static. If there's code in between, that code
1280 will refer to the extern declaration, and vice versa. This just
1281 means that when -mtoplevel-symbols is in use, we can just handle
1282 well-behaved ISO-compliant code. */
1284 const char *str = XSTR (XEXP (rtl, 0), 0);
1285 int len = strlen (str);
1286 char *newstr = XALLOCAVEC (char, len + 2);
1287 newstr[0] = '@';
1288 strcpy (newstr + 1, str);
1289 XSTR (XEXP (rtl, 0), 0) = ggc_alloc_string (newstr, len + 1);
1292 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1293 may need different options to reach for different things with GETA.
1294 For now, functions and things we know or have been told are constant. */
1295 if (TREE_CODE (decl) == FUNCTION_DECL
1296 || TREE_CONSTANT (decl)
1297 || (TREE_CODE (decl) == VAR_DECL
1298 && TREE_READONLY (decl)
1299 && !TREE_SIDE_EFFECTS (decl)
1300 && (!DECL_INITIAL (decl)
1301 || TREE_CONSTANT (DECL_INITIAL (decl)))))
1302 SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
1305 static const char *
1306 mmix_strip_name_encoding (const char *name)
1308 for (; (*name == '@' || *name == '*'); name++)
1311 return name;
1314 /* TARGET_ASM_FILE_START.
1315 We just emit a little comment for the time being. */
1317 static void
1318 mmix_file_start (void)
1320 default_file_start ();
1322 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file);
1324 /* Make sure each file starts with the text section. */
1325 switch_to_section (text_section);
1328 /* TARGET_ASM_FILE_END. */
1330 static void
1331 mmix_file_end (void)
1333 /* Make sure each file ends with the data section. */
1334 switch_to_section (data_section);
1337 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1339 static void
1340 mmix_asm_output_source_filename (FILE *stream, const char *name)
1342 fprintf (stream, "# 1 ");
1343 OUTPUT_QUOTED_STRING (stream, name);
1344 fprintf (stream, "\n");
1347 /* Unfortunately, by default __builtin_ffs is expanded to ffs for
1348 targets where INT_TYPE_SIZE < BITS_PER_WORD. That together with
1349 newlib since 2017-07-04 implementing ffs as __builtin_ffs leads to
1350 (newlib) ffs recursively calling itself. But, because of argument
1351 promotion, and with ffs we're counting from the least bit, the
1352 libgcc equivalent for ffsl works equally well for int arguments, so
1353 just use that. */
1355 static void
1356 mmix_init_libfuncs (void)
1358 set_optab_libfunc (ffs_optab, SImode, "__ffsdi2");
1361 /* OUTPUT_QUOTED_STRING. */
1363 void
1364 mmix_output_quoted_string (FILE *stream, const char *string, int length)
1366 const char * string_end = string + length;
1367 static const char *const unwanted_chars = "\"[]\\";
1369 /* Output "any character except newline and double quote character". We
1370 play it safe and avoid all control characters too. We also do not
1371 want [] as characters, should input be passed through m4 with [] as
1372 quotes. Further, we avoid "\", because the GAS port handles it as a
1373 quoting character. */
1374 while (string < string_end)
1376 if (*string
1377 && (unsigned char) *string < 128
1378 && !ISCNTRL (*string)
1379 && strchr (unwanted_chars, *string) == NULL)
1381 fputc ('"', stream);
1382 while (*string
1383 && (unsigned char) *string < 128
1384 && !ISCNTRL (*string)
1385 && strchr (unwanted_chars, *string) == NULL
1386 && string < string_end)
1388 fputc (*string, stream);
1389 string++;
1391 fputc ('"', stream);
1392 if (string < string_end)
1393 fprintf (stream, ",");
1395 if (string < string_end)
1397 fprintf (stream, "#%x", *string & 255);
1398 string++;
1399 if (string < string_end)
1400 fprintf (stream, ",");
1405 /* Target hook for assembling integer objects. Use mmix_print_operand
1406 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1407 CONST_DOUBLEs. */
1409 static bool
1410 mmix_assemble_integer (rtx x, unsigned int size, int aligned_p)
1412 if (aligned_p)
1413 switch (size)
1415 /* We handle a limited number of types of operands in here. But
1416 that's ok, because we can punt to generic functions. We then
1417 pretend that aligned data isn't needed, so the usual .<pseudo>
1418 syntax is used (which works for aligned data too). We actually
1419 *must* do that, since we (usually) say we don't have simple aligned
1420 pseudos, causing this function to be called. See
1421 mmix_option_override for an exception. We just try and keep as
1422 much compatibility as possible with mmixal syntax for normal
1423 cases (i.e. without GNU extensions and C only). */
1424 case 1:
1425 if (GET_CODE (x) != CONST_INT)
1427 /* There is no "unaligned byte" op or generic function to
1428 which we can punt, so we have to handle this here. As
1429 the expression isn't a plain literal, the generated
1430 assembly-code can't be mmixal-equivalent (i.e. "BYTE"
1431 won't work) and thus it's ok to emit the default op
1432 ".byte". */
1433 assemble_integer_with_op ("\t.byte\t", x);
1434 return true;
1436 fputs ("\tBYTE\t", asm_out_file);
1437 mmix_print_operand (asm_out_file, x, 'B');
1438 fputc ('\n', asm_out_file);
1439 return true;
1441 case 2:
1442 if (GET_CODE (x) != CONST_INT)
1444 aligned_p = 0;
1445 break;
1447 fputs ("\tWYDE\t", asm_out_file);
1448 mmix_print_operand (asm_out_file, x, 'W');
1449 fputc ('\n', asm_out_file);
1450 return true;
1452 case 4:
1453 if (GET_CODE (x) != CONST_INT)
1455 aligned_p = 0;
1456 break;
1458 fputs ("\tTETRA\t", asm_out_file);
1459 mmix_print_operand (asm_out_file, x, 'L');
1460 fputc ('\n', asm_out_file);
1461 return true;
1463 case 8:
1464 /* We don't get here anymore for CONST_DOUBLE, because DImode
1465 isn't expressed as CONST_DOUBLE, and DFmode is handled
1466 elsewhere. */
1467 gcc_assert (GET_CODE (x) != CONST_DOUBLE);
1468 assemble_integer_with_op ("\tOCTA\t", x);
1469 return true;
1471 return default_assemble_integer (x, size, aligned_p);
1474 /* ASM_OUTPUT_ASCII. */
1476 void
1477 mmix_asm_output_ascii (FILE *stream, const char *string, int length)
1479 while (length > 0)
1481 int chunk_size = length > 60 ? 60 : length;
1482 fprintf (stream, "\tBYTE ");
1483 mmix_output_quoted_string (stream, string, chunk_size);
1484 string += chunk_size;
1485 length -= chunk_size;
1486 fprintf (stream, "\n");
1490 /* ASM_OUTPUT_ALIGNED_COMMON. */
1492 void
1493 mmix_asm_output_aligned_common (FILE *stream,
1494 const char *name,
1495 int size,
1496 int align)
1498 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1499 express this in a mmixal-compatible way. */
1500 fprintf (stream, "\t.comm\t");
1501 assemble_name (stream, name);
1502 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1503 size, align / BITS_PER_UNIT);
1506 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1508 void
1509 mmix_asm_output_aligned_local (FILE *stream,
1510 const char *name,
1511 int size,
1512 int align)
1514 switch_to_section (data_section);
1516 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1517 assemble_name (stream, name);
1518 fprintf (stream, "\tLOC @+%d\n", size);
1521 /* ASM_OUTPUT_LABEL. */
1523 void
1524 mmix_asm_output_label (FILE *stream, const char *name)
1526 assemble_name (stream, name);
1527 fprintf (stream, "\tIS @\n");
1530 /* ASM_OUTPUT_INTERNAL_LABEL. */
1532 void
1533 mmix_asm_output_internal_label (FILE *stream, const char *name)
1535 assemble_name_raw (stream, name);
1536 fprintf (stream, "\tIS @\n");
1539 /* ASM_DECLARE_REGISTER_GLOBAL. */
1541 void
1542 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED,
1543 tree decl ATTRIBUTE_UNUSED,
1544 int regno ATTRIBUTE_UNUSED,
1545 const char *name ATTRIBUTE_UNUSED)
1547 /* Nothing to do here, but there *will* be, therefore the framework is
1548 here. */
1551 /* ASM_WEAKEN_LABEL. */
1553 void
1554 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED,
1555 const char *name ATTRIBUTE_UNUSED)
1557 fprintf (stream, "\t.weak ");
1558 assemble_name (stream, name);
1559 fprintf (stream, " ! mmixal-incompatible\n");
1562 /* MAKE_DECL_ONE_ONLY. */
1564 void
1565 mmix_make_decl_one_only (tree decl)
1567 DECL_WEAK (decl) = 1;
1570 /* ASM_OUTPUT_LABELREF.
1571 Strip GCC's '*' and our own '@'. No order is assumed. */
1573 void
1574 mmix_asm_output_labelref (FILE *stream, const char *name)
1576 int is_extern = 1;
1578 for (; (*name == '@' || *name == '*'); name++)
1579 if (*name == '@')
1580 is_extern = 0;
1582 asm_fprintf (stream, "%s%U%s",
1583 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
1584 name);
1587 /* ASM_OUTPUT_DEF. */
1589 void
1590 mmix_asm_output_def (FILE *stream, const char *name, const char *value)
1592 assemble_name (stream, name);
1593 fprintf (stream, "\tIS ");
1594 assemble_name (stream, value);
1595 fputc ('\n', stream);
1598 /* TARGET_PRINT_OPERAND. */
1600 static void
1601 mmix_print_operand (FILE *stream, rtx x, int code)
1603 /* When we add support for different codes later, we can, when needed,
1604 drop through to the main handler with a modified operand. */
1605 rtx modified_x = x;
1606 int regno = x != NULL_RTX && REG_P (x) ? REGNO (x) : 0;
1608 switch (code)
1610 /* Unrelated codes are in alphabetic order. */
1612 case '+':
1613 /* For conditional branches, output "P" for a probable branch. */
1614 if (TARGET_BRANCH_PREDICT)
1616 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
1617 if (x && profile_probability::from_reg_br_prob_note (XINT (x, 0))
1618 > profile_probability::even ())
1619 putc ('P', stream);
1621 return;
1623 case '.':
1624 /* For the %d in POP %d,0. */
1625 fprintf (stream, "%d", MMIX_POP_ARGUMENT ());
1626 return;
1628 case '!':
1629 /* The number of registers we want to save. This was setup by the
1630 prologue. */
1631 fprintf (stream, "%d", cfun->machine->highest_saved_stack_register + 1);
1632 return;
1634 case 'B':
1635 if (GET_CODE (x) != CONST_INT)
1636 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1637 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
1638 return;
1640 case 'H':
1641 /* Highpart. Must be general register, and not the last one, as
1642 that one cannot be part of a consecutive register pair. */
1643 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1644 internal_error ("MMIX Internal: Bad register: %d", regno);
1646 /* This is big-endian, so the high-part is the first one. */
1647 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1648 return;
1650 case 'L':
1651 /* Lowpart. Must be CONST_INT or general register, and not the last
1652 one, as that one cannot be part of a consecutive register pair. */
1653 if (GET_CODE (x) == CONST_INT)
1655 fprintf (stream, "#%lx",
1656 (unsigned long) (INTVAL (x)
1657 & ((unsigned int) 0x7fffffff * 2 + 1)));
1658 return;
1661 if (GET_CODE (x) == SYMBOL_REF)
1663 output_addr_const (stream, x);
1664 return;
1667 if (regno > MMIX_LAST_GENERAL_REGISTER - 1)
1668 internal_error ("MMIX Internal: Bad register: %d", regno);
1670 /* This is big-endian, so the low-part is + 1. */
1671 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno) + 1]);
1672 return;
1674 /* Can't use 'a' because that's a generic modifier for address
1675 output. */
1676 case 'A':
1677 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
1678 ~(uint64_t)
1679 mmix_intval (x));
1680 return;
1682 case 'i':
1683 mmix_output_shiftvalue_op_from_str (stream, "INC",
1684 (uint64_t)
1685 mmix_intval (x));
1686 return;
1688 case 'o':
1689 mmix_output_shiftvalue_op_from_str (stream, "OR",
1690 (uint64_t)
1691 mmix_intval (x));
1692 return;
1694 case 's':
1695 mmix_output_shiftvalue_op_from_str (stream, "SET",
1696 (uint64_t)
1697 mmix_intval (x));
1698 return;
1700 case 'd':
1701 case 'D':
1702 mmix_output_condition (stream, x, (code == 'D'));
1703 return;
1705 case 'e':
1706 /* Output an extra "e" to make fcmpe, fune. */
1707 if (TARGET_FCMP_EPSILON)
1708 fprintf (stream, "e");
1709 return;
1711 case 'm':
1712 /* Output the number minus 1. */
1713 if (GET_CODE (x) != CONST_INT)
1715 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1718 fprintf (stream, "%" PRId64,
1719 (int64_t) (mmix_intval (x) - 1));
1720 return;
1722 case 'r':
1723 /* Store the register to output a constant to. */
1724 if (! REG_P (x))
1725 fatal_insn ("MMIX Internal: Expected a register, not this", x);
1726 mmix_output_destination_register = MMIX_OUTPUT_REGNO (regno);
1727 return;
1729 case 'I':
1730 /* Output the constant. Note that we use this for floats as well. */
1731 if (GET_CODE (x) != CONST_INT
1732 && (GET_CODE (x) != CONST_DOUBLE
1733 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
1734 && GET_MODE (x) != SFmode)))
1735 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
1736 mmix_output_register_setting (stream,
1737 mmix_output_destination_register,
1738 mmix_intval (x), 0);
1739 return;
1741 case 'U':
1742 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1743 if (TARGET_ZERO_EXTEND)
1744 putc ('U', stream);
1745 return;
1747 case 'v':
1748 mmix_output_shifted_value (stream, (int64_t) mmix_intval (x));
1749 return;
1751 case 'V':
1752 mmix_output_shifted_value (stream, (int64_t) ~mmix_intval (x));
1753 return;
1755 case 'W':
1756 if (GET_CODE (x) != CONST_INT)
1757 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
1758 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
1759 return;
1761 case 0:
1762 /* Nothing to do. */
1763 break;
1765 default:
1766 /* Presumably there's a missing case above if we get here. */
1767 internal_error ("MMIX Internal: Missing %qc case in %<mmix_print_operand%>", code);
1770 switch (GET_CODE (modified_x))
1772 case REG:
1773 regno = REGNO (modified_x);
1774 if (regno >= FIRST_PSEUDO_REGISTER)
1775 internal_error ("MMIX Internal: Bad register: %d", regno);
1776 fprintf (stream, "%s", reg_names[MMIX_OUTPUT_REGNO (regno)]);
1777 return;
1779 case MEM:
1780 output_address (GET_MODE (modified_x), XEXP (modified_x, 0));
1781 return;
1783 case CONST_INT:
1784 /* For -2147483648, mmixal complains that the constant does not fit
1785 in 4 bytes, so let's output it as hex. Take care to handle hosts
1786 where HOST_WIDE_INT is longer than an int.
1788 Print small constants +-255 using decimal. */
1790 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
1791 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
1792 else
1793 fprintf (stream, "#%x",
1794 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
1795 return;
1797 case CONST_DOUBLE:
1798 /* Do somewhat as CONST_INT. */
1799 mmix_output_octa (stream, mmix_intval (modified_x), 0);
1800 return;
1802 case CONST:
1803 output_addr_const (stream, modified_x);
1804 return;
1806 default:
1807 /* No need to test for all strange things. Let output_addr_const do
1808 it for us. */
1809 if (CONSTANT_P (modified_x)
1810 /* Strangely enough, this is not included in CONSTANT_P.
1811 FIXME: Ask/check about sanity here. */
1812 || LABEL_P (modified_x))
1814 output_addr_const (stream, modified_x);
1815 return;
1818 /* We need the original here. */
1819 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
1823 /* TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1825 static bool
1826 mmix_print_operand_punct_valid_p (unsigned char code)
1828 /* A '+' is used for branch prediction, similar to other ports. */
1829 return code == '+'
1830 /* A '.' is used for the %d in the POP %d,0 return insn. */
1831 || code == '.'
1832 /* A '!' is used for the number of saved registers, like when outputting
1833 PUSHJ and PUSHGO. */
1834 || code == '!';
1837 /* TARGET_PRINT_OPERAND_ADDRESS. */
1839 static void
1840 mmix_print_operand_address (FILE *stream, machine_mode /*mode*/, rtx x)
1842 if (REG_P (x))
1844 /* I find the generated assembly code harder to read without
1845 the ",0". */
1846 fprintf (stream, "%s,0", reg_names[MMIX_OUTPUT_REGNO (REGNO (x))]);
1847 return;
1849 else if (GET_CODE (x) == PLUS)
1851 rtx x1 = XEXP (x, 0);
1852 rtx x2 = XEXP (x, 1);
1854 if (REG_P (x1))
1856 fprintf (stream, "%s,", reg_names[MMIX_OUTPUT_REGNO (REGNO (x1))]);
1858 if (REG_P (x2))
1860 fprintf (stream, "%s",
1861 reg_names[MMIX_OUTPUT_REGNO (REGNO (x2))]);
1862 return;
1864 else if (satisfies_constraint_I (x2))
1866 output_addr_const (stream, x2);
1867 return;
1872 if (TARGET_BASE_ADDRESSES && mmix_legitimate_constant_p (Pmode, x))
1874 output_addr_const (stream, x);
1875 return;
1878 fatal_insn ("MMIX Internal: This is not a recognized address", x);
1881 /* ASM_OUTPUT_REG_PUSH. */
1883 void
1884 mmix_asm_output_reg_push (FILE *stream, int regno)
1886 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1887 reg_names[MMIX_STACK_POINTER_REGNUM],
1888 reg_names[MMIX_STACK_POINTER_REGNUM],
1889 reg_names[MMIX_OUTPUT_REGNO (regno)],
1890 reg_names[MMIX_STACK_POINTER_REGNUM]);
1893 /* ASM_OUTPUT_REG_POP. */
1895 void
1896 mmix_asm_output_reg_pop (FILE *stream, int regno)
1898 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1899 reg_names[MMIX_OUTPUT_REGNO (regno)],
1900 reg_names[MMIX_STACK_POINTER_REGNUM],
1901 reg_names[MMIX_STACK_POINTER_REGNUM]);
1904 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1906 void
1907 mmix_asm_output_addr_diff_elt (FILE *stream,
1908 rtx body ATTRIBUTE_UNUSED,
1909 int value,
1910 int rel)
1912 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
1915 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1917 void
1918 mmix_asm_output_addr_vec_elt (FILE *stream, int value)
1920 fprintf (stream, "\tOCTA L:%d\n", value);
1923 /* ASM_OUTPUT_SKIP. */
1925 void
1926 mmix_asm_output_skip (FILE *stream, int nbytes)
1928 fprintf (stream, "\tLOC @+%d\n", nbytes);
1931 /* ASM_OUTPUT_ALIGN. */
1933 void
1934 mmix_asm_output_align (FILE *stream, int power)
1936 /* We need to record the needed alignment of this section in the object,
1937 so we have to output an alignment directive. Use a .p2align (not
1938 .align) so people will never have to wonder about whether the
1939 argument is in number of bytes or the log2 thereof. We do it in
1940 addition to the LOC directive, so nothing needs tweaking when
1941 copy-pasting assembly into mmixal. */
1942 fprintf (stream, "\t.p2align %d\n", power);
1943 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
1946 /* DEBUGGER_REGNO. */
1948 unsigned
1949 mmix_debugger_regno (unsigned regno)
1951 /* Adjust the register number to the one it will be output as, dammit.
1952 It'd be nice if we could check the assumption that we're filling a
1953 gap, but every register between the last saved register and parameter
1954 registers might be a valid parameter register. */
1955 regno = MMIX_OUTPUT_REGNO (regno);
1957 /* We need to renumber registers to get the number of the return address
1958 register in the range 0..255. It is also space-saving if registers
1959 mentioned in the call-frame information (which uses this function by
1960 defaulting DWARF_FRAME_REGNUM to DEBUGGER_REGNO) are numbered
1961 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1962 return regno >= 224 ? (regno - 224) : (regno + 48);
1965 /* End of target macro support functions.
1967 Now the MMIX port's own functions. First the exported ones. */
1969 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1970 from insn-emit.cc. */
1973 mmix_get_hard_reg_initial_val (machine_mode mode, int regno)
1975 return get_hard_reg_initial_val (mode, regno);
1978 /* Nonzero when the function epilogue is simple enough that a single
1979 "POP %d,0" should be used even within the function. */
1982 mmix_use_simple_return (void)
1984 int regno;
1986 int stack_space_to_allocate
1987 = (crtl->outgoing_args_size
1988 + crtl->args.pretend_args_size
1989 + get_frame_size () + 7) & ~7;
1991 if (!TARGET_USE_RETURN_INSN || !reload_completed)
1992 return 0;
1994 for (regno = 255;
1995 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1996 regno--)
1997 /* Note that we assume that the frame-pointer-register is one of these
1998 registers, in which case we don't count it here. */
1999 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2000 && df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno)))
2001 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2002 return 0;
2004 if (frame_pointer_needed)
2005 stack_space_to_allocate += 8;
2007 if (MMIX_CFUN_HAS_LANDING_PAD)
2008 stack_space_to_allocate += 16;
2009 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2010 stack_space_to_allocate += 8;
2012 return stack_space_to_allocate == 0;
2016 /* Expands the function prologue into RTX. */
2018 void
2019 mmix_expand_prologue (void)
2021 HOST_WIDE_INT locals_size = get_frame_size ();
2022 int regno;
2023 HOST_WIDE_INT stack_space_to_allocate
2024 = (crtl->outgoing_args_size
2025 + crtl->args.pretend_args_size
2026 + locals_size + 7) & ~7;
2027 HOST_WIDE_INT offset = -8;
2028 HOST_WIDE_INT total_allocated_stack_space = 0;
2030 /* Add room needed to save global non-register-stack registers. */
2031 for (regno = 255;
2032 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2033 regno--)
2034 /* Note that we assume that the frame-pointer-register is one of these
2035 registers, in which case we don't count it here. */
2036 if ((((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2037 && df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno)))
2038 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2039 stack_space_to_allocate += 8;
2041 /* If we do have a frame-pointer, add room for it. */
2042 if (frame_pointer_needed)
2043 stack_space_to_allocate += 8;
2045 /* If we have a non-local label, we need to be able to unwind to it, so
2046 store the current register stack pointer. Also store the return
2047 address if we do that. */
2048 if (MMIX_CFUN_HAS_LANDING_PAD)
2049 stack_space_to_allocate += 16;
2050 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2051 /* If we do have a saved return-address slot, add room for it. */
2052 stack_space_to_allocate += 8;
2054 /* Make sure we don't get an unaligned stack. */
2055 if ((stack_space_to_allocate % 8) != 0)
2056 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2057 stack_space_to_allocate);
2059 if (crtl->args.pretend_args_size)
2061 int mmix_first_vararg_reg
2062 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2063 + (MMIX_MAX_ARGS_IN_REGS
2064 - crtl->args.pretend_args_size / 8));
2066 for (regno
2067 = MMIX_FIRST_INCOMING_ARG_REGNUM + MMIX_MAX_ARGS_IN_REGS - 1;
2068 regno >= mmix_first_vararg_reg;
2069 regno--)
2071 if (offset < 0)
2073 HOST_WIDE_INT stack_chunk
2074 = stack_space_to_allocate > (256 - 8)
2075 ? (256 - 8) : stack_space_to_allocate;
2077 mmix_emit_sp_add (-stack_chunk);
2078 total_allocated_stack_space += stack_chunk;
2080 offset += stack_chunk;
2081 stack_space_to_allocate -= stack_chunk;
2084 /* These registers aren't actually saved (as in "will be
2085 restored"), so don't tell DWARF2 they're saved. */
2086 emit_move_insn (gen_rtx_MEM (DImode,
2087 plus_constant (Pmode, stack_pointer_rtx,
2088 offset)),
2089 gen_rtx_REG (DImode, regno));
2090 offset -= 8;
2094 /* Store the frame-pointer. */
2096 if (frame_pointer_needed)
2098 rtx insn;
2100 if (offset < 0)
2102 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2103 HOST_WIDE_INT stack_chunk
2104 = stack_space_to_allocate > (256 - 8 - 8)
2105 ? (256 - 8 - 8) : stack_space_to_allocate;
2107 mmix_emit_sp_add (-stack_chunk);
2108 total_allocated_stack_space += stack_chunk;
2110 offset += stack_chunk;
2111 stack_space_to_allocate -= stack_chunk;
2114 insn = emit_move_insn (gen_rtx_MEM (DImode,
2115 plus_constant (Pmode,
2116 stack_pointer_rtx,
2117 offset)),
2118 hard_frame_pointer_rtx);
2119 RTX_FRAME_RELATED_P (insn) = 1;
2120 insn = emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
2121 stack_pointer_rtx,
2122 GEN_INT (offset + 8)));
2123 RTX_FRAME_RELATED_P (insn) = 1;
2124 offset -= 8;
2127 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2129 rtx tmpreg, retreg;
2130 rtx insn;
2132 /* Store the return-address, if one is needed on the stack. We
2133 usually store it in a register when needed, but that doesn't work
2134 with -fexceptions. */
2136 if (offset < 0)
2138 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2139 HOST_WIDE_INT stack_chunk
2140 = stack_space_to_allocate > (256 - 8 - 8)
2141 ? (256 - 8 - 8) : stack_space_to_allocate;
2143 mmix_emit_sp_add (-stack_chunk);
2144 total_allocated_stack_space += stack_chunk;
2146 offset += stack_chunk;
2147 stack_space_to_allocate -= stack_chunk;
2150 tmpreg = gen_rtx_REG (DImode, 255);
2151 retreg = gen_rtx_REG (DImode, MMIX_rJ_REGNUM);
2153 /* Dwarf2 code is confused by the use of a temporary register for
2154 storing the return address, so we have to express it as a note,
2155 which we attach to the actual store insn. */
2156 emit_move_insn (tmpreg, retreg);
2158 insn = emit_move_insn (gen_rtx_MEM (DImode,
2159 plus_constant (Pmode,
2160 stack_pointer_rtx,
2161 offset)),
2162 tmpreg);
2163 RTX_FRAME_RELATED_P (insn) = 1;
2164 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
2165 gen_rtx_SET (gen_rtx_MEM (DImode,
2166 plus_constant (Pmode,
2167 stack_pointer_rtx,
2168 offset)),
2169 retreg));
2171 offset -= 8;
2173 else if (MMIX_CFUN_HAS_LANDING_PAD)
2174 offset -= 8;
2176 if (MMIX_CFUN_HAS_LANDING_PAD)
2178 /* Store the register defining the numbering of local registers, so
2179 we know how long to unwind the register stack. */
2181 if (offset < 0)
2183 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2184 HOST_WIDE_INT stack_chunk
2185 = stack_space_to_allocate > (256 - 8 - 8)
2186 ? (256 - 8 - 8) : stack_space_to_allocate;
2188 mmix_emit_sp_add (-stack_chunk);
2189 total_allocated_stack_space += stack_chunk;
2191 offset += stack_chunk;
2192 stack_space_to_allocate -= stack_chunk;
2195 /* We don't tell dwarf2 about this one; we just have it to unwind
2196 the register stack at landing pads. FIXME: It's a kludge because
2197 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2198 register stack at the moment. Best thing would be to handle it
2199 like stack-pointer offsets. Better: some hook into dwarf2out.cc
2200 to produce DW_CFA_expression:s that specify the increment of rO,
2201 and unwind it at eh_return (preferred) or at the landing pad.
2202 Then saves to $0..$G-1 could be specified through that register. */
2204 emit_move_insn (gen_rtx_REG (DImode, 255),
2205 gen_rtx_REG (DImode,
2206 MMIX_rO_REGNUM));
2207 emit_move_insn (gen_rtx_MEM (DImode,
2208 plus_constant (Pmode, stack_pointer_rtx,
2209 offset)),
2210 gen_rtx_REG (DImode, 255));
2211 offset -= 8;
2214 /* After the return-address and the frame-pointer, we have the local
2215 variables. They're the ones that may have an "unaligned" size. */
2216 offset -= (locals_size + 7) & ~7;
2218 /* Now store all registers that are global, i.e. not saved by the
2219 register file machinery.
2221 It is assumed that the frame-pointer is one of these registers, so it
2222 is explicitly excluded in the count. */
2224 for (regno = 255;
2225 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2226 regno--)
2227 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2228 && df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
2229 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2231 rtx insn;
2233 if (offset < 0)
2235 HOST_WIDE_INT stack_chunk
2236 = (stack_space_to_allocate > (256 - offset - 8)
2237 ? (256 - offset - 8) : stack_space_to_allocate);
2239 mmix_emit_sp_add (-stack_chunk);
2240 total_allocated_stack_space += stack_chunk;
2242 offset += stack_chunk;
2243 stack_space_to_allocate -= stack_chunk;
2246 insn = emit_move_insn (gen_rtx_MEM (DImode,
2247 plus_constant (Pmode,
2248 stack_pointer_rtx,
2249 offset)),
2250 gen_rtx_REG (DImode, regno));
2251 RTX_FRAME_RELATED_P (insn) = 1;
2252 offset -= 8;
2255 /* Finally, allocate room for outgoing args and local vars if room
2256 wasn't allocated above. */
2257 if (stack_space_to_allocate)
2258 mmix_emit_sp_add (-stack_space_to_allocate);
2259 total_allocated_stack_space += stack_space_to_allocate;
2261 /* Let's assume that reporting the usage of the regular stack on its
2262 own, is more useful than either not supporting -fstack-usage or
2263 reporting the sum of the usages of the regular stack and the
2264 register stack. */
2265 if (flag_stack_usage_info)
2266 current_function_static_stack_size = total_allocated_stack_space;
2269 /* Expands the function epilogue into RTX. */
2271 void
2272 mmix_expand_epilogue (void)
2274 HOST_WIDE_INT locals_size = get_frame_size ();
2275 int regno;
2276 HOST_WIDE_INT stack_space_to_deallocate
2277 = (crtl->outgoing_args_size
2278 + crtl->args.pretend_args_size
2279 + locals_size + 7) & ~7;
2281 /* The first address to access is beyond the outgoing_args area. */
2282 HOST_WIDE_INT offset = crtl->outgoing_args_size;
2284 /* Add the space for global non-register-stack registers.
2285 It is assumed that the frame-pointer register can be one of these
2286 registers, in which case it is excluded from the count when needed. */
2287 for (regno = 255;
2288 regno >= MMIX_FIRST_GLOBAL_REGNUM;
2289 regno--)
2290 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2291 && df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
2292 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2293 stack_space_to_deallocate += 8;
2295 /* Add in the space for register stack-pointer. If so, always add room
2296 for the saved PC. */
2297 if (MMIX_CFUN_HAS_LANDING_PAD)
2298 stack_space_to_deallocate += 16;
2299 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2300 /* If we have a saved return-address slot, add it in. */
2301 stack_space_to_deallocate += 8;
2303 /* Add in the frame-pointer. */
2304 if (frame_pointer_needed)
2305 stack_space_to_deallocate += 8;
2307 /* Make sure we don't get an unaligned stack. */
2308 if ((stack_space_to_deallocate % 8) != 0)
2309 internal_error ("stack frame not a multiple of octabyte: %wd",
2310 stack_space_to_deallocate);
2312 /* We will add back small offsets to the stack pointer as we go.
2313 First, we restore all registers that are global, i.e. not saved by
2314 the register file machinery. */
2316 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
2317 regno <= 255;
2318 regno++)
2319 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
2320 && df_regs_ever_live_p (regno) && !call_used_or_fixed_reg_p (regno))
2321 || IS_MMIX_EH_RETURN_DATA_REG (regno))
2323 if (offset > 255)
2325 mmix_emit_sp_add (offset);
2326 stack_space_to_deallocate -= offset;
2327 offset = 0;
2330 emit_move_insn (gen_rtx_REG (DImode, regno),
2331 gen_rtx_MEM (DImode,
2332 plus_constant (Pmode, stack_pointer_rtx,
2333 offset)));
2334 offset += 8;
2337 /* Here is where the local variables were. As in the prologue, they
2338 might be of an unaligned size. */
2339 offset += (locals_size + 7) & ~7;
2341 /* The saved register stack pointer is just below the frame-pointer
2342 register. We don't need to restore it "manually"; the POP
2343 instruction does that. */
2344 if (MMIX_CFUN_HAS_LANDING_PAD)
2345 offset += 16;
2346 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
2347 /* The return-address slot is just below the frame-pointer register.
2348 We don't need to restore it because we don't really use it. */
2349 offset += 8;
2351 /* Get back the old frame-pointer-value. */
2352 if (frame_pointer_needed)
2354 if (offset > 255)
2356 mmix_emit_sp_add (offset);
2358 stack_space_to_deallocate -= offset;
2359 offset = 0;
2362 emit_move_insn (hard_frame_pointer_rtx,
2363 gen_rtx_MEM (DImode,
2364 plus_constant (Pmode, stack_pointer_rtx,
2365 offset)));
2366 offset += 8;
2369 /* We do not need to restore pretended incoming args, just add back
2370 offset to sp. */
2371 if (stack_space_to_deallocate != 0)
2372 mmix_emit_sp_add (stack_space_to_deallocate);
2374 if (crtl->calls_eh_return)
2375 /* Adjust the (normal) stack-pointer to that of the receiver.
2376 FIXME: It would be nice if we could also adjust the register stack
2377 here, but we need to express it through DWARF 2 too. */
2378 emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
2379 gen_rtx_REG (DImode,
2380 MMIX_EH_RETURN_STACKADJ_REGNUM)));
2383 /* Output an optimal sequence for setting a register to a specific
2384 constant. Used in an alternative for const_ints in movdi, and when
2385 using large stack-frame offsets.
2387 Use do_begin_end to say if a line-starting TAB and newline before the
2388 first insn and after the last insn is wanted. */
2390 void
2391 mmix_output_register_setting (FILE *stream,
2392 int regno,
2393 int64_t value,
2394 int do_begin_end)
2396 if (do_begin_end)
2397 fprintf (stream, "\t");
2399 if (insn_const_int_ok_for_constraint (value, CONSTRAINT_K))
2400 fprintf (stream, "NEGU %s,0,%" PRId64, reg_names[regno], -value);
2401 else if (mmix_shiftable_wyde_value ((uint64_t) value))
2403 /* First, the one-insn cases. */
2404 mmix_output_shiftvalue_op_from_str (stream, "SET",
2405 (uint64_t)
2406 value);
2407 fprintf (stream, " %s,", reg_names[regno]);
2408 mmix_output_shifted_value (stream, (uint64_t) value);
2410 else if (mmix_shiftable_wyde_value (-(uint64_t) value))
2412 /* We do this to get a bit more legible assembly code. The next
2413 alternative is mostly redundant with this. */
2415 mmix_output_shiftvalue_op_from_str (stream, "SET",
2416 -(uint64_t)
2417 value);
2418 fprintf (stream, " %s,", reg_names[regno]);
2419 mmix_output_shifted_value (stream, -(uint64_t) value);
2420 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2421 reg_names[regno]);
2423 else if (mmix_shiftable_wyde_value (~(uint64_t) value))
2425 /* Slightly more expensive, the two-insn cases. */
2427 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2428 is shiftable, or any other one-insn transformation of the value.
2429 FIXME: Check first if the value is "shiftable" by two loading
2430 with two insns, since it makes more readable assembly code (if
2431 anyone else cares). */
2433 mmix_output_shiftvalue_op_from_str (stream, "SET",
2434 ~(uint64_t)
2435 value);
2436 fprintf (stream, " %s,", reg_names[regno]);
2437 mmix_output_shifted_value (stream, ~(uint64_t) value);
2438 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2439 reg_names[regno]);
2441 else
2443 /* The generic case. 2..4 insns. */
2444 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
2445 const char *op = "SET";
2446 const char *line_begin = "";
2447 int insns = 0;
2448 int i;
2449 int64_t tmpvalue = value;
2451 /* Compute the number of insns needed to output this constant. */
2452 for (i = 0; i < 4 && tmpvalue != 0; i++)
2454 if (tmpvalue & 65535)
2455 insns++;
2456 tmpvalue >>= 16;
2458 if (TARGET_BASE_ADDRESSES && insns == 3)
2460 /* The number three is based on a static observation on
2461 ghostscript-6.52. Two and four are excluded because there
2462 are too many such constants, and each unique constant (maybe
2463 offset by 1..255) were used few times compared to other uses,
2464 e.g. addresses.
2466 We use base-plus-offset addressing to force it into a global
2467 register; we just use a "LDA reg,VALUE", which will cause the
2468 assembler and linker to DTRT (for constants as well as
2469 addresses). */
2470 fprintf (stream, "LDA %s,", reg_names[regno]);
2471 mmix_output_octa (stream, value, 0);
2473 else
2475 /* Output pertinent parts of the 4-wyde sequence.
2476 Still more to do if we want this to be optimal, but hey...
2477 Note that the zero case has been handled above. */
2478 for (i = 0; i < 4 && value != 0; i++)
2480 if (value & 65535)
2482 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2483 higher_parts[i], reg_names[regno],
2484 (int) (value & 65535));
2485 /* The first one sets the rest of the bits to 0, the next
2486 ones add set bits. */
2487 op = "INC";
2488 line_begin = "\n\t";
2491 value >>= 16;
2496 if (do_begin_end)
2497 fprintf (stream, "\n");
2500 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2501 else return 0. */
2504 mmix_shiftable_wyde_value (uint64_t value)
2506 /* Shift by 16 bits per group, stop when we've found two groups with
2507 nonzero bits. */
2508 int i;
2509 int has_candidate = 0;
2511 for (i = 0; i < 4; i++)
2513 if (value & 65535)
2515 if (has_candidate)
2516 return 0;
2517 else
2518 has_candidate = 1;
2521 value >>= 16;
2524 return 1;
2527 /* X and Y are two things to compare using CODE. Return the rtx for
2528 the cc-reg in the proper mode. */
2531 mmix_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
2533 machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2534 return gen_reg_rtx (ccmode);
2537 /* Local (static) helper functions. */
2539 static void
2540 mmix_emit_sp_add (HOST_WIDE_INT offset)
2542 rtx insn;
2544 if (offset < 0)
2546 /* Negative stack-pointer adjustments are allocations and appear in
2547 the prologue only. We mark them as frame-related so unwind and
2548 debug info is properly emitted for them. */
2549 if (offset > -255)
2550 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2551 stack_pointer_rtx,
2552 GEN_INT (offset)));
2553 else
2555 rtx tmpr = gen_rtx_REG (DImode, 255);
2556 RTX_FRAME_RELATED_P (emit_move_insn (tmpr, GEN_INT (offset))) = 1;
2557 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2558 stack_pointer_rtx, tmpr));
2560 RTX_FRAME_RELATED_P (insn) = 1;
2562 else
2564 /* Positive adjustments are in the epilogue only. Don't mark them
2565 as "frame-related" for unwind info. */
2566 if (insn_const_int_ok_for_constraint (offset, CONSTRAINT_L))
2567 emit_insn (gen_adddi3 (stack_pointer_rtx,
2568 stack_pointer_rtx,
2569 GEN_INT (offset)));
2570 else
2572 rtx tmpr = gen_rtx_REG (DImode, 255);
2573 emit_move_insn (tmpr, GEN_INT (offset));
2574 insn = emit_insn (gen_adddi3 (stack_pointer_rtx,
2575 stack_pointer_rtx, tmpr));
2580 /* Print operator suitable for doing something with a shiftable
2581 wyde. The type of operator is passed as an asm output modifier. */
2583 static void
2584 mmix_output_shiftvalue_op_from_str (FILE *stream,
2585 const char *mainop,
2586 int64_t value)
2588 static const char *const op_part[] = {"L", "ML", "MH", "H"};
2589 int i;
2591 if (! mmix_shiftable_wyde_value (value))
2593 char s[sizeof ("0xffffffffffffffff")];
2594 sprintf (s, "%#" PRIx64, value);
2595 internal_error ("MMIX Internal: %s is not a shiftable integer", s);
2598 for (i = 0; i < 4; i++)
2600 /* We know we're through when we find one-bits in the low
2601 16 bits. */
2602 if (value & 0xffff)
2604 fprintf (stream, "%s%s", mainop, op_part[i]);
2605 return;
2607 value >>= 16;
2610 /* No bits set? Then it must have been zero. */
2611 fprintf (stream, "%sL", mainop);
2614 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2616 static void
2617 mmix_output_octa (FILE *stream, int64_t value, int do_begin_end)
2619 if (do_begin_end)
2620 fprintf (stream, "\tOCTA ");
2622 /* Provide a few alternative output formats depending on the number, to
2623 improve legibility of assembler output. */
2624 if ((value < (int64_t) 0 && value > (int64_t) -10000)
2625 || (value >= (int64_t) 0 && value <= (int64_t) 16384))
2626 fprintf (stream, "%d", (int) value);
2627 else if (value > (int64_t) 0
2628 && value < ((int64_t) 1 << 31) * 2)
2629 fprintf (stream, "#%x", (unsigned int) value);
2630 else if (sizeof (HOST_WIDE_INT) == sizeof (int64_t))
2631 /* We need to avoid the not-so-universal "0x" prefix; we need the
2632 pure hex-digits together with the mmixal "#" hex prefix. */
2633 fprintf (stream, "#" HOST_WIDE_INT_PRINT_HEX_PURE,
2634 (HOST_WIDE_INT) value);
2635 else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
2636 fprintf (stream, "%" PRIu64, value);
2638 if (do_begin_end)
2639 fprintf (stream, "\n");
2642 /* Print the presumed shiftable wyde argument shifted into place (to
2643 be output with an operand). */
2645 static void
2646 mmix_output_shifted_value (FILE *stream, int64_t value)
2648 int i;
2650 if (! mmix_shiftable_wyde_value (value))
2652 char s[16+2+1];
2653 sprintf (s, "%#" PRIx64, value);
2654 internal_error ("MMIX Internal: %s is not a shiftable integer", s);
2657 for (i = 0; i < 4; i++)
2659 /* We know we're through when we find one-bits in the low 16 bits. */
2660 if (value & 0xffff)
2662 fprintf (stream, "#%x", (int) (value & 0xffff));
2663 return;
2666 value >>= 16;
2669 /* No bits set? Then it must have been zero. */
2670 fprintf (stream, "0");
2673 /* Output an MMIX condition name corresponding to an operator
2674 and operands:
2675 (comparison_operator [(comparison_operator ...) (const_int 0)])
2676 which means we have to look at *two* operators.
2678 The argument "reversed" refers to reversal of the condition (not the
2679 same as swapping the arguments). */
2681 static void
2682 mmix_output_condition (FILE *stream, const_rtx x, int reversed)
2684 struct cc_conv
2686 RTX_CODE cc;
2688 /* The normal output cc-code. */
2689 const char *const normal;
2691 /* The reversed cc-code, or NULL if invalid. */
2692 const char *const reversed;
2695 struct cc_type_conv
2697 machine_mode cc_mode;
2699 /* Terminated with {UNKNOWN, NULL, NULL} */
2700 const struct cc_conv *const convs;
2703 #undef CCEND
2704 #define CCEND {UNKNOWN, NULL, NULL}
2706 static const struct cc_conv cc_fun_convs[]
2707 = {{ORDERED, "Z", "P"},
2708 {UNORDERED, "P", "Z"},
2709 CCEND};
2710 static const struct cc_conv cc_fp_convs[]
2711 = {{GT, "P", NULL},
2712 {LT, "N", NULL},
2713 CCEND};
2714 static const struct cc_conv cc_fpeq_convs[]
2715 = {{NE, "Z", "P"},
2716 {EQ, "P", "Z"},
2717 CCEND};
2718 static const struct cc_conv cc_uns_convs[]
2719 = {{GEU, "NN", "N"},
2720 {GTU, "P", "NP"},
2721 {LEU, "NP", "P"},
2722 {LTU, "N", "NN"},
2723 CCEND};
2724 static const struct cc_conv cc_signed_convs[]
2725 = {{NE, "NZ", "Z"},
2726 {EQ, "Z", "NZ"},
2727 {GE, "NN", "N"},
2728 {GT, "P", "NP"},
2729 {LE, "NP", "P"},
2730 {LT, "N", "NN"},
2731 CCEND};
2732 static const struct cc_conv cc_di_convs[]
2733 = {{NE, "NZ", "Z"},
2734 {EQ, "Z", "NZ"},
2735 {GE, "NN", "N"},
2736 {GT, "P", "NP"},
2737 {LE, "NP", "P"},
2738 {LT, "N", "NN"},
2739 {GTU, "NZ", "Z"},
2740 {LEU, "Z", "NZ"},
2741 CCEND};
2742 #undef CCEND
2744 static const struct cc_type_conv cc_convs[]
2745 = {{E_CC_FUNmode, cc_fun_convs},
2746 {E_CC_FPmode, cc_fp_convs},
2747 {E_CC_FPEQmode, cc_fpeq_convs},
2748 {E_CC_UNSmode, cc_uns_convs},
2749 {E_CCmode, cc_signed_convs},
2750 {E_DImode, cc_di_convs}};
2752 size_t i;
2753 int j;
2755 machine_mode mode = GET_MODE (XEXP (x, 0));
2756 RTX_CODE cc = GET_CODE (x);
2758 for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
2760 if (mode == cc_convs[i].cc_mode)
2762 for (j = 0; cc_convs[i].convs[j].cc != UNKNOWN; j++)
2763 if (cc == cc_convs[i].convs[j].cc)
2765 const char *mmix_cc
2766 = (reversed ? cc_convs[i].convs[j].reversed
2767 : cc_convs[i].convs[j].normal);
2769 if (mmix_cc == NULL)
2770 fatal_insn ("MMIX Internal: Trying to output invalidly\
2771 reversed condition:", x);
2773 fprintf (stream, "%s", mmix_cc);
2774 return;
2777 fatal_insn ("MMIX Internal: What's the CC of this?", x);
2781 fatal_insn ("MMIX Internal: What is the CC of this?", x);
2784 /* Return the bit-value for a const_int or const_double. */
2786 int64_t
2787 mmix_intval (const_rtx x)
2789 if (GET_CODE (x) == CONST_INT)
2790 return INTVAL (x);
2792 /* We make a little song and dance because converting to long long in
2793 gcc-2.7.2 is broken. I still want people to be able to use it for
2794 cross-compilation to MMIX. */
2795 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
2796 return CONST_DOUBLE_HIGH (x);
2798 if (GET_CODE (x) == CONST_DOUBLE)
2800 if (GET_MODE (x) == DFmode)
2802 long bits[2];
2804 REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), bits);
2806 /* The double cast is necessary to avoid getting the long
2807 sign-extended to unsigned long long(!) when they're of
2808 different size (usually 32-bit hosts). */
2809 return
2810 ((uint64_t) (unsigned long) bits[0]
2811 << (uint64_t) 32U)
2812 | (uint64_t) (unsigned long) bits[1];
2814 else if (GET_MODE (x) == SFmode)
2816 long bits;
2817 REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), bits);
2819 return (unsigned long) bits;
2823 fatal_insn ("MMIX Internal: This is not a constant:", x);
2826 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2828 machine_mode
2829 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
2830 machine_mode mode,
2831 int *punsignedp ATTRIBUTE_UNUSED,
2832 const_tree fntype ATTRIBUTE_UNUSED,
2833 int for_return)
2835 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2836 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2837 if (for_return == 1)
2838 return mode;
2840 /* Promotion of modes currently generates slow code, extending before
2841 operation, so we do it only for arguments. */
2842 if (GET_MODE_CLASS (mode) == MODE_INT
2843 && GET_MODE_SIZE (mode) < 8)
2844 return DImode;
2845 else
2846 return mode;
2848 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2850 static rtx
2851 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
2852 int incoming ATTRIBUTE_UNUSED)
2854 return gen_rtx_REG (Pmode, MMIX_STRUCT_VALUE_REGNUM);
2857 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2859 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2860 of it; we can deduce the value. */
2862 bool
2863 mmix_frame_pointer_required (void)
2865 return (cfun->has_nonlocal_label);
2869 * Local variables:
2870 * eval: (c-set-style "gnu")
2871 * indent-tabs-mode: t
2872 * End: