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