1 /* Definitions of target machine for GNU compiler, for MMIX.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc.
5 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
33 #include "basic-block.h"
38 #include "diagnostic-core.h"
45 #include "integrate.h"
47 #include "target-def.h"
49 /* First some local helper definitions. */
50 #define MMIX_FIRST_GLOBAL_REGNUM 32
52 /* We'd need a current_function_has_landing_pad. It's marked as such when
53 a nonlocal_goto_receiver is expanded. Not just a C++ thing, but
55 #define MMIX_CFUN_HAS_LANDING_PAD (cfun->machine->has_landing_pad != 0)
57 /* We have no means to tell DWARF 2 about the register stack, so we need
58 to store the return address on the stack if an exception can get into
59 this function. FIXME: Narrow condition. Before any whole-function
60 analysis, df_regs_ever_live_p () isn't initialized. We know it's up-to-date
61 after reload_completed; it may contain incorrect information some time
62 before that. Within a RTL sequence (after a call to start_sequence,
63 such as in RTL expanders), leaf_function_p doesn't see all insns
64 (perhaps any insn). But regs_ever_live is up-to-date when
65 leaf_function_p () isn't, so we "or" them together to get accurate
66 information. FIXME: Some tweak to leaf_function_p might be
68 #define MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS \
70 && ((reload_completed && df_regs_ever_live_p (MMIX_rJ_REGNUM)) \
71 || !leaf_function_p ()))
73 #define IS_MMIX_EH_RETURN_DATA_REG(REGNO) \
74 (crtl->calls_eh_return \
75 && (EH_RETURN_DATA_REGNO (0) == REGNO \
76 || EH_RETURN_DATA_REGNO (1) == REGNO \
77 || EH_RETURN_DATA_REGNO (2) == REGNO \
78 || EH_RETURN_DATA_REGNO (3) == REGNO))
80 /* For the default ABI, we rename registers at output-time to fill the gap
81 between the (statically partitioned) saved registers and call-clobbered
82 registers. In effect this makes unused call-saved registers to be used
83 as call-clobbered registers. The benefit comes from keeping the number
84 of local registers (value of rL) low, since there's a cost of
85 increasing rL and clearing unused (unset) registers with lower numbers.
86 Don't translate while outputting the prologue. */
87 #define MMIX_OUTPUT_REGNO(N) \
89 || (int) (N) < MMIX_RETURN_VALUE_REGNUM \
90 || (int) (N) > MMIX_LAST_STACK_REGISTER_REGNUM \
92 || cfun->machine == NULL \
93 || cfun->machine->in_prologue \
94 ? (N) : ((N) - MMIX_RETURN_VALUE_REGNUM \
95 + cfun->machine->highest_saved_stack_register + 1))
97 /* The %d in "POP %d,0". */
98 #define MMIX_POP_ARGUMENT() \
100 && crtl->return_rtx != NULL \
101 && ! cfun->returns_struct) \
102 ? (GET_CODE (crtl->return_rtx) == PARALLEL \
103 ? GET_NUM_ELEM (XVEC (crtl->return_rtx, 0)) : 1) \
106 /* The canonical saved comparison operands for non-cc0 machines, set in
107 the compare expander. */
108 rtx mmix_compare_op0
;
109 rtx mmix_compare_op1
;
111 /* Declarations of locals. */
113 /* Intermediate for insn output. */
114 static int mmix_output_destination_register
;
116 static void mmix_option_override (void);
117 static void mmix_asm_output_source_filename (FILE *, const char *);
118 static void mmix_output_shiftvalue_op_from_str
119 (FILE *, const char *, HOST_WIDEST_INT
);
120 static void mmix_output_shifted_value (FILE *, HOST_WIDEST_INT
);
121 static void mmix_output_condition (FILE *, rtx
, int);
122 static HOST_WIDEST_INT
mmix_intval (rtx
);
123 static void mmix_output_octa (FILE *, HOST_WIDEST_INT
, int);
124 static bool mmix_assemble_integer (rtx
, unsigned int, int);
125 static struct machine_function
*mmix_init_machine_status (void);
126 static void mmix_encode_section_info (tree
, rtx
, int);
127 static const char *mmix_strip_name_encoding (const char *);
128 static void mmix_emit_sp_add (HOST_WIDE_INT offset
);
129 static void mmix_target_asm_function_prologue (FILE *, HOST_WIDE_INT
);
130 static void mmix_target_asm_function_end_prologue (FILE *);
131 static void mmix_target_asm_function_epilogue (FILE *, HOST_WIDE_INT
);
132 static bool mmix_legitimate_address_p (enum machine_mode
, rtx
, bool);
133 static void mmix_reorg (void);
134 static void mmix_asm_output_mi_thunk
135 (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
136 static void mmix_setup_incoming_varargs
137 (CUMULATIVE_ARGS
*, enum machine_mode
, tree
, int *, int);
138 static void mmix_file_start (void);
139 static void mmix_file_end (void);
140 static bool mmix_rtx_costs (rtx
, int, int, int *, bool);
141 static rtx
mmix_struct_value_rtx (tree
, int);
142 static enum machine_mode
mmix_promote_function_mode (const_tree
,
144 int *, const_tree
, int);
145 static void mmix_function_arg_advance (CUMULATIVE_ARGS
*, enum machine_mode
,
147 static rtx
mmix_function_arg_1 (const CUMULATIVE_ARGS
*, enum machine_mode
,
148 const_tree
, bool, bool);
149 static rtx
mmix_function_incoming_arg (CUMULATIVE_ARGS
*, enum machine_mode
,
151 static rtx
mmix_function_arg (CUMULATIVE_ARGS
*, enum machine_mode
,
153 static rtx
mmix_function_value (const_tree
, const_tree
, bool);
154 static rtx
mmix_libcall_value (enum machine_mode
, const_rtx
);
155 static bool mmix_function_value_regno_p (const unsigned int);
156 static bool mmix_pass_by_reference (CUMULATIVE_ARGS
*,
157 enum machine_mode
, const_tree
, bool);
158 static bool mmix_frame_pointer_required (void);
159 static void mmix_asm_trampoline_template (FILE *);
160 static void mmix_trampoline_init (rtx
, tree
, rtx
);
162 /* TARGET_OPTION_OPTIMIZATION_TABLE. */
164 static const struct default_options mmix_option_optimization_table
[] =
166 { OPT_LEVELS_1_PLUS
, OPT_fregmove
, NULL
, 1 },
167 { OPT_LEVELS_2_PLUS
, OPT_fomit_frame_pointer
, NULL
, 1 },
168 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
171 /* Target structure macros. Listed by node. See `Using and Porting GCC'
172 for a general description. */
174 /* Node: Function Entry */
176 #undef TARGET_ASM_BYTE_OP
177 #define TARGET_ASM_BYTE_OP NULL
178 #undef TARGET_ASM_ALIGNED_HI_OP
179 #define TARGET_ASM_ALIGNED_HI_OP NULL
180 #undef TARGET_ASM_ALIGNED_SI_OP
181 #define TARGET_ASM_ALIGNED_SI_OP NULL
182 #undef TARGET_ASM_ALIGNED_DI_OP
183 #define TARGET_ASM_ALIGNED_DI_OP NULL
184 #undef TARGET_ASM_INTEGER
185 #define TARGET_ASM_INTEGER mmix_assemble_integer
187 #undef TARGET_ASM_FUNCTION_PROLOGUE
188 #define TARGET_ASM_FUNCTION_PROLOGUE mmix_target_asm_function_prologue
190 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
191 #define TARGET_ASM_FUNCTION_END_PROLOGUE mmix_target_asm_function_end_prologue
193 #undef TARGET_ASM_FUNCTION_EPILOGUE
194 #define TARGET_ASM_FUNCTION_EPILOGUE mmix_target_asm_function_epilogue
196 #undef TARGET_ENCODE_SECTION_INFO
197 #define TARGET_ENCODE_SECTION_INFO mmix_encode_section_info
198 #undef TARGET_STRIP_NAME_ENCODING
199 #define TARGET_STRIP_NAME_ENCODING mmix_strip_name_encoding
201 #undef TARGET_ASM_OUTPUT_MI_THUNK
202 #define TARGET_ASM_OUTPUT_MI_THUNK mmix_asm_output_mi_thunk
203 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
204 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
205 #undef TARGET_ASM_FILE_START
206 #define TARGET_ASM_FILE_START mmix_file_start
207 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
208 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
209 #undef TARGET_ASM_FILE_END
210 #define TARGET_ASM_FILE_END mmix_file_end
211 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
212 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mmix_asm_output_source_filename
214 #undef TARGET_RTX_COSTS
215 #define TARGET_RTX_COSTS mmix_rtx_costs
216 #undef TARGET_ADDRESS_COST
217 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
219 #undef TARGET_MACHINE_DEPENDENT_REORG
220 #define TARGET_MACHINE_DEPENDENT_REORG mmix_reorg
222 #undef TARGET_PROMOTE_FUNCTION_MODE
223 #define TARGET_PROMOTE_FUNCTION_MODE mmix_promote_function_mode
225 #undef TARGET_FUNCTION_VALUE
226 #define TARGET_FUNCTION_VALUE mmix_function_value
227 #undef TARGET_LIBCALL_VALUE
228 #define TARGET_LIBCALL_VALUE mmix_libcall_value
229 #undef TARGET_FUNCTION_VALUE_REGNO_P
230 #define TARGET_FUNCTION_VALUE_REGNO_P mmix_function_value_regno_p
232 #undef TARGET_FUNCTION_ARG
233 #define TARGET_FUNCTION_ARG mmix_function_arg
234 #undef TARGET_FUNCTION_INCOMING_ARG
235 #define TARGET_FUNCTION_INCOMING_ARG mmix_function_incoming_arg
236 #undef TARGET_FUNCTION_ARG_ADVANCE
237 #define TARGET_FUNCTION_ARG_ADVANCE mmix_function_arg_advance
238 #undef TARGET_STRUCT_VALUE_RTX
239 #define TARGET_STRUCT_VALUE_RTX mmix_struct_value_rtx
240 #undef TARGET_SETUP_INCOMING_VARARGS
241 #define TARGET_SETUP_INCOMING_VARARGS mmix_setup_incoming_varargs
242 #undef TARGET_PASS_BY_REFERENCE
243 #define TARGET_PASS_BY_REFERENCE mmix_pass_by_reference
244 #undef TARGET_CALLEE_COPIES
245 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
246 #undef TARGET_DEFAULT_TARGET_FLAGS
247 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
249 #undef TARGET_LEGITIMATE_ADDRESS_P
250 #define TARGET_LEGITIMATE_ADDRESS_P mmix_legitimate_address_p
252 #undef TARGET_FRAME_POINTER_REQUIRED
253 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
255 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
256 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
257 #undef TARGET_TRAMPOLINE_INIT
258 #define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
260 #undef TARGET_OPTION_OVERRIDE
261 #define TARGET_OPTION_OVERRIDE mmix_option_override
262 #undef TARGET_OPTION_OPTIMIZATION_TABLE
263 #define TARGET_OPTION_OPTIMIZATION_TABLE mmix_option_optimization_table
265 struct gcc_target targetm
= TARGET_INITIALIZER
;
267 /* Functions that are expansions for target macros.
268 See Target Macros in `Using and Porting GCC'. */
270 /* TARGET_OPTION_OVERRIDE. */
273 mmix_option_override (void)
275 /* Should we err or should we warn? Hmm. At least we must neutralize
276 it. For example the wrong kind of case-tables will be generated with
277 PIC; we use absolute address items for mmixal compatibility. FIXME:
278 They could be relative if we just elide them to after all pertinent
282 warning (0, "-f%s not supported: ignored", (flag_pic
> 1) ? "PIC" : "pic");
287 /* INIT_EXPANDERS. */
290 mmix_init_expanders (void)
292 init_machine_status
= mmix_init_machine_status
;
295 /* Set the per-function data. */
297 static struct machine_function
*
298 mmix_init_machine_status (void)
300 return ggc_alloc_cleared_machine_function ();
304 We have trouble getting the address of stuff that is located at other
305 than 32-bit alignments (GETA requirements), so try to give everything
306 at least 32-bit alignment. */
309 mmix_data_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
311 if (basic_align
< 32)
317 /* CONSTANT_ALIGNMENT. */
320 mmix_constant_alignment (tree constant ATTRIBUTE_UNUSED
, int basic_align
)
322 if (basic_align
< 32)
328 /* LOCAL_ALIGNMENT. */
331 mmix_local_alignment (tree type ATTRIBUTE_UNUSED
, int basic_align
)
333 if (basic_align
< 32)
339 /* CONDITIONAL_REGISTER_USAGE. */
342 mmix_conditional_register_usage (void)
348 static const int gnu_abi_reg_alloc_order
[]
349 = MMIX_GNU_ABI_REG_ALLOC_ORDER
;
351 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
352 reg_alloc_order
[i
] = gnu_abi_reg_alloc_order
[i
];
354 /* Change the default from the mmixware ABI. For the GNU ABI,
355 $15..$30 are call-saved just as $0..$14. There must be one
356 call-clobbered local register for the "hole" that holds the
357 number of saved local registers saved by PUSHJ/PUSHGO during the
358 function call, receiving the return value at return. So best is
359 to use the highest, $31. It's already marked call-clobbered for
361 for (i
= 15; i
<= 30; i
++)
362 call_used_regs
[i
] = 0;
364 /* "Unfix" the parameter registers. */
365 for (i
= MMIX_RESERVED_GNU_ARG_0_REGNUM
;
366 i
< MMIX_RESERVED_GNU_ARG_0_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
;
371 /* Step over the ":" in special register names. */
372 if (! TARGET_TOPLEVEL_SYMBOLS
)
373 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
374 if (reg_names
[i
][0] == ':')
378 /* INCOMING_REGNO and OUTGOING_REGNO worker function.
379 Those two macros must only be applied to function argument
380 registers. FIXME: for their current use in gcc, it'd be better
381 with an explicit specific additional FUNCTION_INCOMING_ARG_REGNO_P
382 a'la TARGET_FUNCTION_ARG / TARGET_FUNCTION_INCOMING_ARG instead of
383 forcing the target to commit to a fixed mapping and for any
384 unspecified register use. */
387 mmix_opposite_regno (int regno
, int incoming
)
389 if (!mmix_function_arg_regno_p (regno
, incoming
))
394 ? MMIX_FIRST_INCOMING_ARG_REGNUM
- MMIX_FIRST_ARG_REGNUM
395 : MMIX_FIRST_ARG_REGNUM
- MMIX_FIRST_INCOMING_ARG_REGNUM
);
399 All registers that are part of the register stack and that will be
403 mmix_local_regno (int regno
)
405 return regno
<= MMIX_LAST_STACK_REGISTER_REGNUM
&& !call_used_regs
[regno
];
408 /* PREFERRED_RELOAD_CLASS.
409 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
412 mmix_preferred_reload_class (rtx x ATTRIBUTE_UNUSED
, enum reg_class rclass
)
414 /* FIXME: Revisit. */
415 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
416 ? REMAINDER_REG
: rclass
;
419 /* PREFERRED_OUTPUT_RELOAD_CLASS.
420 We need to extend the reload class of REMAINDER_REG and HIMULT_REG. */
423 mmix_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED
,
424 enum reg_class rclass
)
426 /* FIXME: Revisit. */
427 return GET_CODE (x
) == MOD
&& GET_MODE (x
) == DImode
428 ? REMAINDER_REG
: rclass
;
431 /* SECONDARY_RELOAD_CLASS.
432 We need to reload regs of REMAINDER_REG and HIMULT_REG elsewhere. */
435 mmix_secondary_reload_class (enum reg_class rclass
,
436 enum machine_mode mode ATTRIBUTE_UNUSED
,
437 rtx x ATTRIBUTE_UNUSED
,
438 int in_p ATTRIBUTE_UNUSED
)
440 if (rclass
== REMAINDER_REG
441 || rclass
== HIMULT_REG
442 || rclass
== SYSTEM_REGS
)
448 /* CONST_OK_FOR_LETTER_P. */
451 mmix_const_ok_for_letter_p (HOST_WIDE_INT value
, int c
)
454 (c
== 'I' ? value
>= 0 && value
<= 255
455 : c
== 'J' ? value
>= 0 && value
<= 65535
456 : c
== 'K' ? value
<= 0 && value
>= -255
457 : c
== 'L' ? mmix_shiftable_wyde_value (value
)
458 : c
== 'M' ? value
== 0
459 : c
== 'N' ? mmix_shiftable_wyde_value (~value
)
460 : c
== 'O' ? (value
== 3 || value
== 5 || value
== 9
465 /* CONST_DOUBLE_OK_FOR_LETTER_P. */
468 mmix_const_double_ok_for_letter_p (rtx value
, int c
)
471 (c
== 'G' ? value
== CONST0_RTX (GET_MODE (value
))
476 We need this since our constants are not always expressible as
477 CONST_INT:s, but rather often as CONST_DOUBLE:s. */
480 mmix_extra_constraint (rtx x
, int c
, int strict
)
482 HOST_WIDEST_INT value
;
484 /* When checking for an address, we need to handle strict vs. non-strict
485 register checks. Don't use address_operand, but instead its
486 equivalent (its callee, which it is just a wrapper for),
487 memory_operand_p and the strict-equivalent strict_memory_address_p. */
491 ? strict_memory_address_p (Pmode
, x
)
492 : memory_address_p (Pmode
, x
);
494 /* R asks whether x is to be loaded with GETA or something else. Right
495 now, only a SYMBOL_REF and LABEL_REF can fit for
496 TARGET_BASE_ADDRESSES.
498 Only constant symbolic addresses apply. With TARGET_BASE_ADDRESSES,
499 we just allow straight LABEL_REF or SYMBOL_REFs with SYMBOL_REF_FLAG
500 set right now; only function addresses and code labels. If we change
501 to let SYMBOL_REF_FLAG be set on other symbols, we have to check
502 inside CONST expressions. When TARGET_BASE_ADDRESSES is not in
503 effect, a "raw" constant check together with mmix_constant_address_p
504 is all that's needed; we want all constant addresses to be loaded
508 GET_CODE (x
) != CONST_INT
&& GET_CODE (x
) != CONST_DOUBLE
509 && mmix_constant_address_p (x
)
510 && (! TARGET_BASE_ADDRESSES
511 || (GET_CODE (x
) == LABEL_REF
512 || (GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (x
))));
514 if (GET_CODE (x
) != CONST_DOUBLE
|| GET_MODE (x
) != VOIDmode
)
517 value
= mmix_intval (x
);
519 /* We used to map Q->J, R->K, S->L, T->N, U->O, but we don't have to any
520 more ('U' taken for address_operand, 'R' similarly). Some letters map
521 outside of CONST_INT, though; we still use 'S' and 'T'. */
523 return mmix_shiftable_wyde_value (value
);
525 return mmix_shiftable_wyde_value (~value
);
529 /* DYNAMIC_CHAIN_ADDRESS. */
532 mmix_dynamic_chain_address (rtx frame
)
534 /* FIXME: the frame-pointer is stored at offset -8 from the current
535 frame-pointer. Unfortunately, the caller assumes that a
536 frame-pointer is present for *all* previous frames. There should be
537 a way to say that that cannot be done, like for RETURN_ADDR_RTX. */
538 return plus_constant (frame
, -8);
541 /* STARTING_FRAME_OFFSET. */
544 mmix_starting_frame_offset (void)
546 /* The old frame pointer is in the slot below the new one, so
547 FIRST_PARM_OFFSET does not need to depend on whether the
548 frame-pointer is needed or not. We have to adjust for the register
549 stack pointer being located below the saved frame pointer.
550 Similarly, we store the return address on the stack too, for
551 exception handling, and always if we save the register stack pointer. */
554 + (MMIX_CFUN_HAS_LANDING_PAD
555 ? -16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? -8 : 0)));
558 /* RETURN_ADDR_RTX. */
561 mmix_return_addr_rtx (int count
, rtx frame ATTRIBUTE_UNUSED
)
564 ? (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
565 /* FIXME: Set frame_alias_set on the following. (Why?)
566 See mmix_initial_elimination_offset for the reason we can't use
567 get_hard_reg_initial_val for both. Always using a stack slot
568 and not a register would be suboptimal. */
569 ? validize_mem (gen_rtx_MEM (Pmode
, plus_constant (frame_pointer_rtx
, -16)))
570 : get_hard_reg_initial_val (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
))
574 /* SETUP_FRAME_ADDRESSES. */
577 mmix_setup_frame_addresses (void)
579 /* Nothing needed at the moment. */
582 /* The difference between the (imaginary) frame pointer and the stack
583 pointer. Used to eliminate the frame pointer. */
586 mmix_initial_elimination_offset (int fromreg
, int toreg
)
590 = (get_frame_size () + crtl
->outgoing_args_size
+ 7) & ~7;
592 /* There is no actual offset between these two virtual values, but for
593 the frame-pointer, we have the old one in the stack position below
594 it, so the offset for the frame-pointer to the stack-pointer is one
596 if (fromreg
== MMIX_ARG_POINTER_REGNUM
597 && toreg
== MMIX_FRAME_POINTER_REGNUM
)
600 /* The difference is the size of local variables plus the size of
601 outgoing function arguments that would normally be passed as
602 registers but must be passed on stack because we're out of
603 function-argument registers. Only global saved registers are
604 counted; the others go on the register stack.
606 The frame-pointer is counted too if it is what is eliminated, as we
607 need to balance the offset for it from STARTING_FRAME_OFFSET.
609 Also add in the slot for the register stack pointer we save if we
612 Unfortunately, we can't access $0..$14, from unwinder code easily, so
613 store the return address in a frame slot too. FIXME: Only for
614 non-leaf functions. FIXME: Always with a landing pad, because it's
615 hard to know whether we need the other at the time we know we need
616 the offset for one (and have to state it). It's a kludge until we
617 can express the register stack in the EH frame info.
619 We have to do alignment here; get_frame_size will not return a
620 multiple of STACK_BOUNDARY. FIXME: Add note in manual. */
622 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
625 if ((df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
626 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
630 + (MMIX_CFUN_HAS_LANDING_PAD
631 ? 16 : (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
? 8 : 0))
632 + (fromreg
== MMIX_ARG_POINTER_REGNUM
? 0 : 8);
636 mmix_function_arg_advance (CUMULATIVE_ARGS
*argsp
, enum machine_mode mode
,
637 const_tree type
, bool named ATTRIBUTE_UNUSED
)
639 int arg_size
= MMIX_FUNCTION_ARG_SIZE (mode
, type
);
641 argsp
->regs
= ((targetm
.calls
.must_pass_in_stack (mode
, type
)
645 ? (MMIX_MAX_ARGS_IN_REGS
) + 1
646 : argsp
->regs
+ (7 + arg_size
) / 8);
649 /* Helper function for mmix_function_arg and mmix_function_incoming_arg. */
652 mmix_function_arg_1 (const CUMULATIVE_ARGS
*argsp
,
653 enum machine_mode mode
,
655 bool named ATTRIBUTE_UNUSED
,
658 /* Last-argument marker. */
659 if (type
== void_type_node
)
660 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
)
663 ? MMIX_FIRST_INCOMING_ARG_REGNUM
664 : MMIX_FIRST_ARG_REGNUM
) + argsp
->regs
)
667 return (argsp
->regs
< MMIX_MAX_ARGS_IN_REGS
668 && !targetm
.calls
.must_pass_in_stack (mode
, type
)
669 && (GET_MODE_BITSIZE (mode
) <= 64
674 ? MMIX_FIRST_INCOMING_ARG_REGNUM
675 : MMIX_FIRST_ARG_REGNUM
)
680 /* Return an rtx for a function argument to go in a register, and 0 for
681 one that must go on stack. */
684 mmix_function_arg (CUMULATIVE_ARGS
*argsp
,
685 enum machine_mode mode
,
689 return mmix_function_arg_1 (argsp
, mode
, type
, named
, false);
693 mmix_function_incoming_arg (CUMULATIVE_ARGS
*argsp
,
694 enum machine_mode mode
,
698 return mmix_function_arg_1 (argsp
, mode
, type
, named
, true);
701 /* Returns nonzero for everything that goes by reference, 0 for
702 everything that goes by value. */
705 mmix_pass_by_reference (CUMULATIVE_ARGS
*argsp
, enum machine_mode mode
,
706 const_tree type
, bool named ATTRIBUTE_UNUSED
)
708 /* FIXME: Check: I'm not sure the must_pass_in_stack check is
710 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
713 if (MMIX_FUNCTION_ARG_SIZE (mode
, type
) > 8
715 && (!argsp
|| !argsp
->lib
))
721 /* Return nonzero if regno is a register number where a parameter is
722 passed, and 0 otherwise. */
725 mmix_function_arg_regno_p (int regno
, int incoming
)
728 = incoming
? MMIX_FIRST_INCOMING_ARG_REGNUM
: MMIX_FIRST_ARG_REGNUM
;
730 return regno
>= first_arg_regnum
731 && regno
< first_arg_regnum
+ MMIX_MAX_ARGS_IN_REGS
;
734 /* Implements TARGET_FUNCTION_VALUE. */
737 mmix_function_value (const_tree valtype
,
738 const_tree func ATTRIBUTE_UNUSED
,
741 enum machine_mode mode
= TYPE_MODE (valtype
);
742 enum machine_mode cmode
;
743 int first_val_regnum
= MMIX_OUTGOING_RETURN_VALUE_REGNUM
;
744 rtx vec
[MMIX_MAX_REGS_FOR_VALUE
];
749 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
751 /* Return values that fit in a register need no special handling.
752 There's no register hole when parameters are passed in global
755 || GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
)
757 gen_rtx_REG (mode
, MMIX_OUTGOING_RETURN_VALUE_REGNUM
);
759 if (COMPLEX_MODE_P (mode
))
760 /* A complex type, made up of components. */
761 cmode
= TYPE_MODE (TREE_TYPE (valtype
));
764 /* Of the other larger-than-register modes, we only support
765 scalar mode TImode. (At least, that's the only one that's
766 been rudimentally tested.) Make sure we're alerted for
769 sorry ("support for mode %qs", GET_MODE_NAME (mode
));
771 /* In any case, we will fill registers to the natural size. */
775 nregs
= ((GET_MODE_BITSIZE (mode
) + BITS_PER_WORD
- 1) / BITS_PER_WORD
);
777 /* We need to take care of the effect of the register hole on return
778 values of large sizes; the last register will appear as the first
779 register, with the rest shifted. (For complex modes, this is just
780 swapped registers.) */
782 if (nregs
> MMIX_MAX_REGS_FOR_VALUE
)
783 internal_error ("too large function value type, needs %d registers,\
784 have only %d registers for this", nregs
, MMIX_MAX_REGS_FOR_VALUE
);
786 /* FIXME: Maybe we should handle structure values like this too
787 (adjusted for BLKmode), perhaps for both ABI:s. */
788 for (i
= 0; i
< nregs
- 1; i
++)
790 = gen_rtx_EXPR_LIST (VOIDmode
,
791 gen_rtx_REG (cmode
, first_val_regnum
+ i
),
792 GEN_INT ((i
+ 1) * BITS_PER_UNIT
));
795 = gen_rtx_EXPR_LIST (VOIDmode
,
796 gen_rtx_REG (cmode
, first_val_regnum
+ nregs
- 1),
799 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nregs
, vec
));
802 /* Implements TARGET_LIBCALL_VALUE. */
805 mmix_libcall_value (enum machine_mode mode
,
806 const_rtx fun ATTRIBUTE_UNUSED
)
808 return gen_rtx_REG (mode
, MMIX_RETURN_VALUE_REGNUM
);
811 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
814 mmix_function_value_regno_p (const unsigned int regno
)
816 return regno
== MMIX_RETURN_VALUE_REGNUM
;
819 /* EH_RETURN_DATA_REGNO. */
822 mmix_eh_return_data_regno (int n
)
825 return MMIX_EH_RETURN_DATA_REGNO_START
+ n
;
827 return INVALID_REGNUM
;
830 /* EH_RETURN_STACKADJ_RTX. */
833 mmix_eh_return_stackadj_rtx (void)
835 return gen_rtx_REG (Pmode
, MMIX_EH_RETURN_STACKADJ_REGNUM
);
838 /* EH_RETURN_HANDLER_RTX. */
841 mmix_eh_return_handler_rtx (void)
843 return gen_rtx_REG (Pmode
, MMIX_INCOMING_RETURN_ADDRESS_REGNUM
);
846 /* ASM_PREFERRED_EH_DATA_FORMAT. */
849 mmix_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED
,
850 int global ATTRIBUTE_UNUSED
)
852 /* This is the default (was at 2001-07-20). Revisit when needed. */
853 return DW_EH_PE_absptr
;
856 /* Make a note that we've seen the beginning of the prologue. This
857 matters to whether we'll translate register numbers as calculated by
861 mmix_target_asm_function_prologue (FILE *stream ATTRIBUTE_UNUSED
,
862 HOST_WIDE_INT framesize ATTRIBUTE_UNUSED
)
864 cfun
->machine
->in_prologue
= 1;
867 /* Make a note that we've seen the end of the prologue. */
870 mmix_target_asm_function_end_prologue (FILE *stream ATTRIBUTE_UNUSED
)
872 cfun
->machine
->in_prologue
= 0;
875 /* Implement TARGET_MACHINE_DEPENDENT_REORG. No actual rearrangements
876 done here; just virtually by calculating the highest saved stack
877 register number used to modify the register numbers at output time. */
884 /* We put the number of the highest saved register-file register in a
885 location convenient for the call-patterns to output. Note that we
886 don't tell dwarf2 about these registers, since it can't restore them
888 for (regno
= MMIX_LAST_STACK_REGISTER_REGNUM
;
891 if ((df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
892 || (regno
== MMIX_FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
895 /* Regardless of whether they're saved (they might be just read), we
896 mustn't include registers that carry parameters. We could scan the
897 insns to see whether they're actually used (and indeed do other less
898 trivial register usage analysis and transformations), but it seems
899 wasteful to optimize for unused parameter registers. As of
900 2002-04-30, df_regs_ever_live_p (n) seems to be set for only-reads too, but
901 that might change. */
902 if (!TARGET_ABI_GNU
&& regno
< crtl
->args
.info
.regs
- 1)
904 regno
= crtl
->args
.info
.regs
- 1;
906 /* We don't want to let this cause us to go over the limit and make
907 incoming parameter registers be misnumbered and treating the last
908 parameter register and incoming return value register call-saved.
909 Stop things at the unmodified scheme. */
910 if (regno
> MMIX_RETURN_VALUE_REGNUM
- 1)
911 regno
= MMIX_RETURN_VALUE_REGNUM
- 1;
914 cfun
->machine
->highest_saved_stack_register
= regno
;
917 /* TARGET_ASM_FUNCTION_EPILOGUE. */
920 mmix_target_asm_function_epilogue (FILE *stream
,
921 HOST_WIDE_INT locals_size ATTRIBUTE_UNUSED
)
923 /* Emit an \n for readability of the generated assembly. */
924 fputc ('\n', stream
);
927 /* TARGET_ASM_OUTPUT_MI_THUNK. */
930 mmix_asm_output_mi_thunk (FILE *stream
,
931 tree fndecl ATTRIBUTE_UNUSED
,
933 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
936 /* If you define TARGET_STRUCT_VALUE_RTX that returns 0 (i.e. pass
937 location of structure to return as invisible first argument), you
938 need to tweak this code too. */
939 const char *regname
= reg_names
[MMIX_FIRST_INCOMING_ARG_REGNUM
];
941 if (delta
>= 0 && delta
< 65536)
942 fprintf (stream
, "\tINCL %s,%d\n", regname
, (int)delta
);
943 else if (delta
< 0 && delta
>= -255)
944 fprintf (stream
, "\tSUBU %s,%s,%d\n", regname
, regname
, (int)-delta
);
947 mmix_output_register_setting (stream
, 255, delta
, 1);
948 fprintf (stream
, "\tADDU %s,%s,$255\n", regname
, regname
);
951 fprintf (stream
, "\tJMP ");
952 assemble_name (stream
, XSTR (XEXP (DECL_RTL (func
), 0), 0));
953 fprintf (stream
, "\n");
956 /* FUNCTION_PROFILER. */
959 mmix_function_profiler (FILE *stream ATTRIBUTE_UNUSED
,
960 int labelno ATTRIBUTE_UNUSED
)
962 sorry ("function_profiler support for MMIX");
965 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. For the moment,
966 let's stick to pushing argument registers on the stack. Later, we
967 can parse all arguments in registers, to improve performance. */
970 mmix_setup_incoming_varargs (CUMULATIVE_ARGS
*args_so_farp
,
971 enum machine_mode mode
,
974 int second_time ATTRIBUTE_UNUSED
)
976 /* The last named variable has been handled, but
977 args_so_farp has not been advanced for it. */
978 if (args_so_farp
->regs
+ 1 < MMIX_MAX_ARGS_IN_REGS
)
979 *pretend_sizep
= (MMIX_MAX_ARGS_IN_REGS
- (args_so_farp
->regs
+ 1)) * 8;
981 /* We assume that one argument takes up one register here. That should
982 be true until we start messing with multi-reg parameters. */
983 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode
, vartype
))) / 8 != 1)
984 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
987 /* TARGET_ASM_TRAMPOLINE_TEMPLATE. */
990 mmix_asm_trampoline_template (FILE *stream
)
992 /* Read a value into the static-chain register and jump somewhere. The
993 static chain is stored at offset 16, and the function address is
994 stored at offset 24. */
996 fprintf (stream
, "\tGETA $255,1F\n\t");
997 fprintf (stream
, "LDOU %s,$255,0\n\t", reg_names
[MMIX_STATIC_CHAIN_REGNUM
]);
998 fprintf (stream
, "LDOU $255,$255,8\n\t");
999 fprintf (stream
, "GO $255,$255,0\n");
1000 fprintf (stream
, "1H\tOCTA 0\n\t");
1001 fprintf (stream
, "OCTA 0\n");
1004 /* TARGET_TRAMPOLINE_INIT. */
1005 /* Set the static chain and function pointer field in the trampoline.
1006 We also SYNCID here to be sure (doesn't matter in the simulator, but
1007 some day it will). */
1010 mmix_trampoline_init (rtx m_tramp
, tree fndecl
, rtx static_chain
)
1012 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1015 emit_block_move (m_tramp
, assemble_trampoline_template (),
1016 GEN_INT (2*UNITS_PER_WORD
), BLOCK_OP_NORMAL
);
1018 mem
= adjust_address (m_tramp
, DImode
, 2*UNITS_PER_WORD
);
1019 emit_move_insn (mem
, static_chain
);
1020 mem
= adjust_address (m_tramp
, DImode
, 3*UNITS_PER_WORD
);
1021 emit_move_insn (mem
, fnaddr
);
1023 mem
= adjust_address (m_tramp
, DImode
, 0);
1024 emit_insn (gen_sync_icache (mem
, GEN_INT (TRAMPOLINE_SIZE
- 1)));
1027 /* We must exclude constant addresses that have an increment that is not a
1028 multiple of four bytes because of restrictions of the GETA
1029 instruction, unless TARGET_BASE_ADDRESSES. */
1032 mmix_constant_address_p (rtx x
)
1034 RTX_CODE code
= GET_CODE (x
);
1036 /* When using "base addresses", anything constant goes. */
1037 int constant_ok
= TARGET_BASE_ADDRESSES
!= 0;
1046 /* FIXME: Don't know how to dissect these. Avoid them for now,
1047 except we know they're constants. */
1051 addend
= INTVAL (x
);
1055 if (GET_MODE (x
) != VOIDmode
)
1056 /* Strange that we got here. FIXME: Check if we do. */
1058 addend
= CONST_DOUBLE_LOW (x
);
1062 /* Note that expressions with arithmetic on forward references don't
1063 work in mmixal. People using gcc assembly code with mmixal might
1064 need to move arrays and such to before the point of use. */
1065 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
1067 rtx x0
= XEXP (XEXP (x
, 0), 0);
1068 rtx x1
= XEXP (XEXP (x
, 0), 1);
1070 if ((GET_CODE (x0
) == SYMBOL_REF
1071 || GET_CODE (x0
) == LABEL_REF
)
1072 && (GET_CODE (x1
) == CONST_INT
1073 || (GET_CODE (x1
) == CONST_DOUBLE
1074 && GET_MODE (x1
) == VOIDmode
)))
1075 addend
= mmix_intval (x1
);
1087 return constant_ok
|| (addend
& 3) == 0;
1090 /* Return 1 if the address is OK, otherwise 0. */
1093 mmix_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
1095 bool strict_checking
)
1097 #define MMIX_REG_OK(X) \
1099 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1100 || (reg_renumber[REGNO (X)] > 0 \
1101 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1102 || (!strict_checking \
1103 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1104 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1105 || REGNO (X) == ARG_POINTER_REGNUM)))
1109 (mem (plus reg reg))
1110 (mem (plus reg 0..255)).
1111 unless TARGET_BASE_ADDRESSES, in which case we accept all
1112 (mem constant_address) too. */
1116 if (REG_P (x
) && MMIX_REG_OK (x
))
1119 if (GET_CODE(x
) == PLUS
)
1121 rtx x1
= XEXP (x
, 0);
1122 rtx x2
= XEXP (x
, 1);
1124 /* Try swapping the order. FIXME: Do we need this? */
1132 /* (mem (plus (reg?) (?))) */
1133 if (!REG_P (x1
) || !MMIX_REG_OK (x1
))
1134 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1136 /* (mem (plus (reg) (reg?))) */
1137 if (REG_P (x2
) && MMIX_REG_OK (x2
))
1140 /* (mem (plus (reg) (0..255?))) */
1141 if (GET_CODE (x2
) == CONST_INT
1142 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1148 return TARGET_BASE_ADDRESSES
&& mmix_constant_address_p (x
);
1151 /* LEGITIMATE_CONSTANT_P. */
1154 mmix_legitimate_constant_p (rtx x
)
1156 RTX_CODE code
= GET_CODE (x
);
1158 /* We must allow any number due to the way the cse passes works; if we
1159 do not allow any number here, general_operand will fail, and insns
1160 will fatally fail recognition instead of "softly". */
1161 if (code
== CONST_INT
|| code
== CONST_DOUBLE
)
1164 return CONSTANT_ADDRESS_P (x
);
1167 /* SELECT_CC_MODE. */
1170 mmix_select_cc_mode (RTX_CODE op
, rtx x
, rtx y ATTRIBUTE_UNUSED
)
1172 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1173 output different compare insns. Note that we do not check the
1174 validity of the comparison here. */
1176 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
1178 if (op
== ORDERED
|| op
== UNORDERED
|| op
== UNGE
1179 || op
== UNGT
|| op
== UNLE
|| op
== UNLT
)
1182 if (op
== EQ
|| op
== NE
)
1188 if (op
== GTU
|| op
== LTU
|| op
== GEU
|| op
== LEU
)
1194 /* REVERSIBLE_CC_MODE. */
1197 mmix_reversible_cc_mode (enum machine_mode mode
)
1199 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1201 return mode
!= CC_FPmode
;
1204 /* TARGET_RTX_COSTS. */
1207 mmix_rtx_costs (rtx x ATTRIBUTE_UNUSED
,
1208 int code ATTRIBUTE_UNUSED
,
1209 int outer_code ATTRIBUTE_UNUSED
,
1210 int *total ATTRIBUTE_UNUSED
,
1211 bool speed ATTRIBUTE_UNUSED
)
1213 /* For the time being, this is just a stub and we'll accept the
1214 generic calculations, until we can do measurements, at least.
1215 Say we did not modify any calculated costs. */
1219 /* REGISTER_MOVE_COST. */
1222 mmix_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1223 enum reg_class from
,
1226 return (from
== GENERAL_REGS
&& from
== to
) ? 2 : 3;
1229 /* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1230 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1233 /* DATA_SECTION_ASM_OP. */
1236 mmix_data_section_asm_op (void)
1238 return "\t.data ! mmixal:= 8H LOC 9B";
1242 mmix_encode_section_info (tree decl
, rtx rtl
, int first
)
1244 /* Test for an external declaration, and do nothing if it is one. */
1245 if ((TREE_CODE (decl
) == VAR_DECL
1246 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
)))
1247 || (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_PUBLIC (decl
)))
1249 else if (first
&& DECL_P (decl
))
1251 /* For non-visible declarations, add a "@" prefix, which we skip
1252 when the label is output. If the label does not have this
1253 prefix, a ":" is output if -mtoplevel-symbols.
1255 Note that this does not work for data that is declared extern and
1256 later defined as static. If there's code in between, that code
1257 will refer to the extern declaration, and vice versa. This just
1258 means that when -mtoplevel-symbols is in use, we can just handle
1259 well-behaved ISO-compliant code. */
1261 const char *str
= XSTR (XEXP (rtl
, 0), 0);
1262 int len
= strlen (str
);
1263 char *newstr
= XALLOCAVEC (char, len
+ 2);
1265 strcpy (newstr
+ 1, str
);
1266 XSTR (XEXP (rtl
, 0), 0) = ggc_alloc_string (newstr
, len
+ 1);
1269 /* Set SYMBOL_REF_FLAG for things that we want to access with GETA. We
1270 may need different options to reach for different things with GETA.
1271 For now, functions and things we know or have been told are constant. */
1272 if (TREE_CODE (decl
) == FUNCTION_DECL
1273 || TREE_CONSTANT (decl
)
1274 || (TREE_CODE (decl
) == VAR_DECL
1275 && TREE_READONLY (decl
)
1276 && !TREE_SIDE_EFFECTS (decl
)
1277 && (!DECL_INITIAL (decl
)
1278 || TREE_CONSTANT (DECL_INITIAL (decl
)))))
1279 SYMBOL_REF_FLAG (XEXP (rtl
, 0)) = 1;
1283 mmix_strip_name_encoding (const char *name
)
1285 for (; (*name
== '@' || *name
== '*'); name
++)
1291 /* TARGET_ASM_FILE_START.
1292 We just emit a little comment for the time being. */
1295 mmix_file_start (void)
1297 default_file_start ();
1299 fputs ("! mmixal:= 8H LOC Data_Section\n", asm_out_file
);
1301 /* Make sure each file starts with the text section. */
1302 switch_to_section (text_section
);
1305 /* TARGET_ASM_FILE_END. */
1308 mmix_file_end (void)
1310 /* Make sure each file ends with the data section. */
1311 switch_to_section (data_section
);
1314 /* TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
1317 mmix_asm_output_source_filename (FILE *stream
, const char *name
)
1319 fprintf (stream
, "# 1 ");
1320 OUTPUT_QUOTED_STRING (stream
, name
);
1321 fprintf (stream
, "\n");
1324 /* OUTPUT_QUOTED_STRING. */
1327 mmix_output_quoted_string (FILE *stream
, const char *string
, int length
)
1329 const char * string_end
= string
+ length
;
1330 static const char *const unwanted_chars
= "\"[]\\";
1332 /* Output "any character except newline and double quote character". We
1333 play it safe and avoid all control characters too. We also do not
1334 want [] as characters, should input be passed through m4 with [] as
1335 quotes. Further, we avoid "\", because the GAS port handles it as a
1336 quoting character. */
1337 while (string
< string_end
)
1340 && (unsigned char) *string
< 128
1341 && !ISCNTRL (*string
)
1342 && strchr (unwanted_chars
, *string
) == NULL
)
1344 fputc ('"', stream
);
1346 && (unsigned char) *string
< 128
1347 && !ISCNTRL (*string
)
1348 && strchr (unwanted_chars
, *string
) == NULL
1349 && string
< string_end
)
1351 fputc (*string
, stream
);
1354 fputc ('"', stream
);
1355 if (string
< string_end
)
1356 fprintf (stream
, ",");
1358 if (string
< string_end
)
1360 fprintf (stream
, "#%x", *string
& 255);
1362 if (string
< string_end
)
1363 fprintf (stream
, ",");
1368 /* Target hook for assembling integer objects. Use mmix_print_operand
1369 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1373 mmix_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
1378 /* We handle a limited number of types of operands in here. But
1379 that's ok, because we can punt to generic functions. We then
1380 pretend that aligned data isn't needed, so the usual .<pseudo>
1381 syntax is used (which works for aligned data too). We actually
1382 *must* do that, since we say we don't have simple aligned
1383 pseudos, causing this function to be called. We just try and
1384 keep as much compatibility as possible with mmixal syntax for
1385 normal cases (i.e. without GNU extensions and C only). */
1387 if (GET_CODE (x
) != CONST_INT
)
1392 fputs ("\tBYTE\t", asm_out_file
);
1393 mmix_print_operand (asm_out_file
, x
, 'B');
1394 fputc ('\n', asm_out_file
);
1398 if (GET_CODE (x
) != CONST_INT
)
1403 fputs ("\tWYDE\t", asm_out_file
);
1404 mmix_print_operand (asm_out_file
, x
, 'W');
1405 fputc ('\n', asm_out_file
);
1409 if (GET_CODE (x
) != CONST_INT
)
1414 fputs ("\tTETRA\t", asm_out_file
);
1415 mmix_print_operand (asm_out_file
, x
, 'L');
1416 fputc ('\n', asm_out_file
);
1420 /* We don't get here anymore for CONST_DOUBLE, because DImode
1421 isn't expressed as CONST_DOUBLE, and DFmode is handled
1423 gcc_assert (GET_CODE (x
) != CONST_DOUBLE
);
1424 assemble_integer_with_op ("\tOCTA\t", x
);
1427 return default_assemble_integer (x
, size
, aligned_p
);
1430 /* ASM_OUTPUT_ASCII. */
1433 mmix_asm_output_ascii (FILE *stream
, const char *string
, int length
)
1437 int chunk_size
= length
> 60 ? 60 : length
;
1438 fprintf (stream
, "\tBYTE ");
1439 mmix_output_quoted_string (stream
, string
, chunk_size
);
1440 string
+= chunk_size
;
1441 length
-= chunk_size
;
1442 fprintf (stream
, "\n");
1446 /* ASM_OUTPUT_ALIGNED_COMMON. */
1449 mmix_asm_output_aligned_common (FILE *stream
,
1454 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1455 express this in a mmixal-compatible way. */
1456 fprintf (stream
, "\t.comm\t");
1457 assemble_name (stream
, name
);
1458 fprintf (stream
, ",%u,%u ! mmixal-incompatible COMMON\n",
1459 size
, align
/ BITS_PER_UNIT
);
1462 /* ASM_OUTPUT_ALIGNED_LOCAL. */
1465 mmix_asm_output_aligned_local (FILE *stream
,
1470 switch_to_section (data_section
);
1472 ASM_OUTPUT_ALIGN (stream
, exact_log2 (align
/BITS_PER_UNIT
));
1473 assemble_name (stream
, name
);
1474 fprintf (stream
, "\tLOC @+%d\n", size
);
1477 /* ASM_OUTPUT_LABEL. */
1480 mmix_asm_output_label (FILE *stream
, const char *name
)
1482 assemble_name (stream
, name
);
1483 fprintf (stream
, "\tIS @\n");
1486 /* ASM_OUTPUT_INTERNAL_LABEL. */
1489 mmix_asm_output_internal_label (FILE *stream
, const char *name
)
1491 assemble_name_raw (stream
, name
);
1492 fprintf (stream
, "\tIS @\n");
1495 /* ASM_DECLARE_REGISTER_GLOBAL. */
1498 mmix_asm_declare_register_global (FILE *stream ATTRIBUTE_UNUSED
,
1499 tree decl ATTRIBUTE_UNUSED
,
1500 int regno ATTRIBUTE_UNUSED
,
1501 const char *name ATTRIBUTE_UNUSED
)
1503 /* Nothing to do here, but there *will* be, therefore the framework is
1507 /* ASM_WEAKEN_LABEL. */
1510 mmix_asm_weaken_label (FILE *stream ATTRIBUTE_UNUSED
,
1511 const char *name ATTRIBUTE_UNUSED
)
1513 fprintf (stream
, "\t.weak ");
1514 assemble_name (stream
, name
);
1515 fprintf (stream
, " ! mmixal-incompatible\n");
1518 /* MAKE_DECL_ONE_ONLY. */
1521 mmix_make_decl_one_only (tree decl
)
1523 DECL_WEAK (decl
) = 1;
1526 /* ASM_OUTPUT_LABELREF.
1527 Strip GCC's '*' and our own '@'. No order is assumed. */
1530 mmix_asm_output_labelref (FILE *stream
, const char *name
)
1534 for (; (*name
== '@' || *name
== '*'); name
++)
1538 asm_fprintf (stream
, "%s%U%s",
1539 is_extern
&& TARGET_TOPLEVEL_SYMBOLS
? ":" : "",
1543 /* ASM_OUTPUT_DEF. */
1546 mmix_asm_output_def (FILE *stream
, const char *name
, const char *value
)
1548 assemble_name (stream
, name
);
1549 fprintf (stream
, "\tIS ");
1550 assemble_name (stream
, value
);
1551 fputc ('\n', stream
);
1554 /* PRINT_OPERAND. */
1557 mmix_print_operand (FILE *stream
, rtx x
, int code
)
1559 /* When we add support for different codes later, we can, when needed,
1560 drop through to the main handler with a modified operand. */
1562 int regno
= x
!= NULL_RTX
&& REG_P (x
) ? REGNO (x
) : 0;
1566 /* Unrelated codes are in alphabetic order. */
1569 /* For conditional branches, output "P" for a probable branch. */
1570 if (TARGET_BRANCH_PREDICT
)
1572 x
= find_reg_note (current_output_insn
, REG_BR_PROB
, 0);
1573 if (x
&& INTVAL (XEXP (x
, 0)) > REG_BR_PROB_BASE
/ 2)
1579 /* For the %d in POP %d,0. */
1580 fprintf (stream
, "%d", MMIX_POP_ARGUMENT ());
1584 if (GET_CODE (x
) != CONST_INT
)
1585 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1586 fprintf (stream
, "%d", (int) (INTVAL (x
) & 0xff));
1590 /* Highpart. Must be general register, and not the last one, as
1591 that one cannot be part of a consecutive register pair. */
1592 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1593 internal_error ("MMIX Internal: Bad register: %d", regno
);
1595 /* This is big-endian, so the high-part is the first one. */
1596 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1600 /* Lowpart. Must be CONST_INT or general register, and not the last
1601 one, as that one cannot be part of a consecutive register pair. */
1602 if (GET_CODE (x
) == CONST_INT
)
1604 fprintf (stream
, "#%lx",
1605 (unsigned long) (INTVAL (x
)
1606 & ((unsigned int) 0x7fffffff * 2 + 1)));
1610 if (GET_CODE (x
) == SYMBOL_REF
)
1612 output_addr_const (stream
, x
);
1616 if (regno
> MMIX_LAST_GENERAL_REGISTER
- 1)
1617 internal_error ("MMIX Internal: Bad register: %d", regno
);
1619 /* This is big-endian, so the low-part is + 1. */
1620 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
) + 1]);
1623 /* Can't use 'a' because that's a generic modifier for address
1626 mmix_output_shiftvalue_op_from_str (stream
, "ANDN",
1627 ~(unsigned HOST_WIDEST_INT
)
1632 mmix_output_shiftvalue_op_from_str (stream
, "INC",
1633 (unsigned HOST_WIDEST_INT
)
1638 mmix_output_shiftvalue_op_from_str (stream
, "OR",
1639 (unsigned HOST_WIDEST_INT
)
1644 mmix_output_shiftvalue_op_from_str (stream
, "SET",
1645 (unsigned HOST_WIDEST_INT
)
1651 mmix_output_condition (stream
, x
, (code
== 'D'));
1655 /* Output an extra "e" to make fcmpe, fune. */
1656 if (TARGET_FCMP_EPSILON
)
1657 fprintf (stream
, "e");
1661 /* Output the number minus 1. */
1662 if (GET_CODE (x
) != CONST_INT
)
1664 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
1667 fprintf (stream
, HOST_WIDEST_INT_PRINT_DEC
,
1668 (HOST_WIDEST_INT
) (mmix_intval (x
) - 1));
1672 /* Store the number of registers we want to save. This was setup
1673 by the prologue. The actual operand contains the number of
1674 registers to pass, but we don't use it currently. Anyway, we
1675 need to output the number of saved registers here. */
1676 fprintf (stream
, "%d",
1677 cfun
->machine
->highest_saved_stack_register
+ 1);
1681 /* Store the register to output a constant to. */
1683 fatal_insn ("MMIX Internal: Expected a register, not this", x
);
1684 mmix_output_destination_register
= MMIX_OUTPUT_REGNO (regno
);
1688 /* Output the constant. Note that we use this for floats as well. */
1689 if (GET_CODE (x
) != CONST_INT
1690 && (GET_CODE (x
) != CONST_DOUBLE
1691 || (GET_MODE (x
) != VOIDmode
&& GET_MODE (x
) != DFmode
1692 && GET_MODE (x
) != SFmode
)))
1693 fatal_insn ("MMIX Internal: Expected a constant, not this", x
);
1694 mmix_output_register_setting (stream
,
1695 mmix_output_destination_register
,
1696 mmix_intval (x
), 0);
1700 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
1701 if (TARGET_ZERO_EXTEND
)
1706 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) mmix_intval (x
));
1710 mmix_output_shifted_value (stream
, (HOST_WIDEST_INT
) ~mmix_intval (x
));
1714 if (GET_CODE (x
) != CONST_INT
)
1715 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x
);
1716 fprintf (stream
, "#%x", (int) (INTVAL (x
) & 0xffff));
1720 /* Nothing to do. */
1724 /* Presumably there's a missing case above if we get here. */
1725 internal_error ("MMIX Internal: Missing %qc case in mmix_print_operand", code
);
1728 switch (GET_CODE (modified_x
))
1731 regno
= REGNO (modified_x
);
1732 if (regno
>= FIRST_PSEUDO_REGISTER
)
1733 internal_error ("MMIX Internal: Bad register: %d", regno
);
1734 fprintf (stream
, "%s", reg_names
[MMIX_OUTPUT_REGNO (regno
)]);
1738 output_address (XEXP (modified_x
, 0));
1742 /* For -2147483648, mmixal complains that the constant does not fit
1743 in 4 bytes, so let's output it as hex. Take care to handle hosts
1744 where HOST_WIDE_INT is longer than an int.
1746 Print small constants +-255 using decimal. */
1748 if (INTVAL (modified_x
) > -256 && INTVAL (modified_x
) < 256)
1749 fprintf (stream
, "%d", (int) (INTVAL (modified_x
)));
1751 fprintf (stream
, "#%x",
1752 (int) (INTVAL (modified_x
)) & (unsigned int) ~0);
1756 /* Do somewhat as CONST_INT. */
1757 mmix_output_octa (stream
, mmix_intval (modified_x
), 0);
1761 output_addr_const (stream
, modified_x
);
1765 /* No need to test for all strange things. Let output_addr_const do
1767 if (CONSTANT_P (modified_x
)
1768 /* Strangely enough, this is not included in CONSTANT_P.
1769 FIXME: Ask/check about sanity here. */
1770 || GET_CODE (modified_x
) == CODE_LABEL
)
1772 output_addr_const (stream
, modified_x
);
1776 /* We need the original here. */
1777 fatal_insn ("MMIX Internal: Cannot decode this operand", x
);
1781 /* PRINT_OPERAND_PUNCT_VALID_P. */
1784 mmix_print_operand_punct_valid_p (int code ATTRIBUTE_UNUSED
)
1786 /* A '+' is used for branch prediction, similar to other ports. */
1788 /* A '.' is used for the %d in the POP %d,0 return insn. */
1792 /* PRINT_OPERAND_ADDRESS. */
1795 mmix_print_operand_address (FILE *stream
, rtx x
)
1799 /* I find the generated assembly code harder to read without
1801 fprintf (stream
, "%s,0", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x
))]);
1804 else if (GET_CODE (x
) == PLUS
)
1806 rtx x1
= XEXP (x
, 0);
1807 rtx x2
= XEXP (x
, 1);
1811 fprintf (stream
, "%s,", reg_names
[MMIX_OUTPUT_REGNO (REGNO (x1
))]);
1815 fprintf (stream
, "%s",
1816 reg_names
[MMIX_OUTPUT_REGNO (REGNO (x2
))]);
1819 else if (GET_CODE (x2
) == CONST_INT
1820 && CONST_OK_FOR_LETTER_P (INTVAL (x2
), 'I'))
1822 output_addr_const (stream
, x2
);
1828 if (TARGET_BASE_ADDRESSES
&& mmix_legitimate_constant_p (x
))
1830 output_addr_const (stream
, x
);
1834 fatal_insn ("MMIX Internal: This is not a recognized address", x
);
1837 /* ASM_OUTPUT_REG_PUSH. */
1840 mmix_asm_output_reg_push (FILE *stream
, int regno
)
1842 fprintf (stream
, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
1843 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1844 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1845 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1846 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1849 /* ASM_OUTPUT_REG_POP. */
1852 mmix_asm_output_reg_pop (FILE *stream
, int regno
)
1854 fprintf (stream
, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
1855 reg_names
[MMIX_OUTPUT_REGNO (regno
)],
1856 reg_names
[MMIX_STACK_POINTER_REGNUM
],
1857 reg_names
[MMIX_STACK_POINTER_REGNUM
]);
1860 /* ASM_OUTPUT_ADDR_DIFF_ELT. */
1863 mmix_asm_output_addr_diff_elt (FILE *stream
,
1864 rtx body ATTRIBUTE_UNUSED
,
1868 fprintf (stream
, "\tTETRA L%d-L%d\n", value
, rel
);
1871 /* ASM_OUTPUT_ADDR_VEC_ELT. */
1874 mmix_asm_output_addr_vec_elt (FILE *stream
, int value
)
1876 fprintf (stream
, "\tOCTA L:%d\n", value
);
1879 /* ASM_OUTPUT_SKIP. */
1882 mmix_asm_output_skip (FILE *stream
, int nbytes
)
1884 fprintf (stream
, "\tLOC @+%d\n", nbytes
);
1887 /* ASM_OUTPUT_ALIGN. */
1890 mmix_asm_output_align (FILE *stream
, int power
)
1892 /* We need to record the needed alignment of this section in the object,
1893 so we have to output an alignment directive. Use a .p2align (not
1894 .align) so people will never have to wonder about whether the
1895 argument is in number of bytes or the log2 thereof. We do it in
1896 addition to the LOC directive, so nothing needs tweaking when
1897 copy-pasting assembly into mmixal. */
1898 fprintf (stream
, "\t.p2align %d\n", power
);
1899 fprintf (stream
, "\tLOC @+(%d-@)&%d\n", 1 << power
, (1 << power
) - 1);
1902 /* DBX_REGISTER_NUMBER. */
1905 mmix_dbx_register_number (int regno
)
1907 /* Adjust the register number to the one it will be output as, dammit.
1908 It'd be nice if we could check the assumption that we're filling a
1909 gap, but every register between the last saved register and parameter
1910 registers might be a valid parameter register. */
1911 regno
= MMIX_OUTPUT_REGNO (regno
);
1913 /* We need to renumber registers to get the number of the return address
1914 register in the range 0..255. It is also space-saving if registers
1915 mentioned in the call-frame information (which uses this function by
1916 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
1917 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
1918 return regno
>= 224 ? (regno
- 224) : (regno
+ 48);
1921 /* End of target macro support functions.
1923 Now the MMIX port's own functions. First the exported ones. */
1925 /* Wrapper for get_hard_reg_initial_val since integrate.h isn't included
1926 from insn-emit.c. */
1929 mmix_get_hard_reg_initial_val (enum machine_mode mode
, int regno
)
1931 return get_hard_reg_initial_val (mode
, regno
);
1934 /* Nonzero when the function epilogue is simple enough that a single
1935 "POP %d,0" should be used even within the function. */
1938 mmix_use_simple_return (void)
1942 int stack_space_to_allocate
1943 = (crtl
->outgoing_args_size
1944 + crtl
->args
.pretend_args_size
1945 + get_frame_size () + 7) & ~7;
1947 if (!TARGET_USE_RETURN_INSN
|| !reload_completed
)
1951 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1953 /* Note that we assume that the frame-pointer-register is one of these
1954 registers, in which case we don't count it here. */
1955 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1956 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1957 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1960 if (frame_pointer_needed
)
1961 stack_space_to_allocate
+= 8;
1963 if (MMIX_CFUN_HAS_LANDING_PAD
)
1964 stack_space_to_allocate
+= 16;
1965 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
1966 stack_space_to_allocate
+= 8;
1968 return stack_space_to_allocate
== 0;
1972 /* Expands the function prologue into RTX. */
1975 mmix_expand_prologue (void)
1977 HOST_WIDE_INT locals_size
= get_frame_size ();
1979 HOST_WIDE_INT stack_space_to_allocate
1980 = (crtl
->outgoing_args_size
1981 + crtl
->args
.pretend_args_size
1982 + locals_size
+ 7) & ~7;
1983 HOST_WIDE_INT offset
= -8;
1985 /* Add room needed to save global non-register-stack registers. */
1987 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
1989 /* Note that we assume that the frame-pointer-register is one of these
1990 registers, in which case we don't count it here. */
1991 if ((((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
1992 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
]))
1993 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
1994 stack_space_to_allocate
+= 8;
1996 /* If we do have a frame-pointer, add room for it. */
1997 if (frame_pointer_needed
)
1998 stack_space_to_allocate
+= 8;
2000 /* If we have a non-local label, we need to be able to unwind to it, so
2001 store the current register stack pointer. Also store the return
2002 address if we do that. */
2003 if (MMIX_CFUN_HAS_LANDING_PAD
)
2004 stack_space_to_allocate
+= 16;
2005 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2006 /* If we do have a saved return-address slot, add room for it. */
2007 stack_space_to_allocate
+= 8;
2009 /* Make sure we don't get an unaligned stack. */
2010 if ((stack_space_to_allocate
% 8) != 0)
2011 internal_error ("stack frame not a multiple of 8 bytes: %wd",
2012 stack_space_to_allocate
);
2014 if (crtl
->args
.pretend_args_size
)
2016 int mmix_first_vararg_reg
2017 = (MMIX_FIRST_INCOMING_ARG_REGNUM
2018 + (MMIX_MAX_ARGS_IN_REGS
2019 - crtl
->args
.pretend_args_size
/ 8));
2022 = MMIX_FIRST_INCOMING_ARG_REGNUM
+ MMIX_MAX_ARGS_IN_REGS
- 1;
2023 regno
>= mmix_first_vararg_reg
;
2028 HOST_WIDE_INT stack_chunk
2029 = stack_space_to_allocate
> (256 - 8)
2030 ? (256 - 8) : stack_space_to_allocate
;
2032 mmix_emit_sp_add (-stack_chunk
);
2033 offset
+= stack_chunk
;
2034 stack_space_to_allocate
-= stack_chunk
;
2037 /* These registers aren't actually saved (as in "will be
2038 restored"), so don't tell DWARF2 they're saved. */
2039 emit_move_insn (gen_rtx_MEM (DImode
,
2040 plus_constant (stack_pointer_rtx
,
2042 gen_rtx_REG (DImode
, regno
));
2047 /* Store the frame-pointer. */
2049 if (frame_pointer_needed
)
2055 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2056 HOST_WIDE_INT stack_chunk
2057 = stack_space_to_allocate
> (256 - 8 - 8)
2058 ? (256 - 8 - 8) : stack_space_to_allocate
;
2060 mmix_emit_sp_add (-stack_chunk
);
2062 offset
+= stack_chunk
;
2063 stack_space_to_allocate
-= stack_chunk
;
2066 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2067 plus_constant (stack_pointer_rtx
,
2069 hard_frame_pointer_rtx
);
2070 RTX_FRAME_RELATED_P (insn
) = 1;
2071 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
2073 GEN_INT (offset
+ 8)));
2074 RTX_FRAME_RELATED_P (insn
) = 1;
2078 if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2083 /* Store the return-address, if one is needed on the stack. We
2084 usually store it in a register when needed, but that doesn't work
2085 with -fexceptions. */
2089 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2090 HOST_WIDE_INT stack_chunk
2091 = stack_space_to_allocate
> (256 - 8 - 8)
2092 ? (256 - 8 - 8) : stack_space_to_allocate
;
2094 mmix_emit_sp_add (-stack_chunk
);
2096 offset
+= stack_chunk
;
2097 stack_space_to_allocate
-= stack_chunk
;
2100 tmpreg
= gen_rtx_REG (DImode
, 255);
2101 retreg
= gen_rtx_REG (DImode
, MMIX_rJ_REGNUM
);
2103 /* Dwarf2 code is confused by the use of a temporary register for
2104 storing the return address, so we have to express it as a note,
2105 which we attach to the actual store insn. */
2106 emit_move_insn (tmpreg
, retreg
);
2108 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2109 plus_constant (stack_pointer_rtx
,
2112 RTX_FRAME_RELATED_P (insn
) = 1;
2114 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
2115 gen_rtx_SET (VOIDmode
,
2116 gen_rtx_MEM (DImode
,
2117 plus_constant (stack_pointer_rtx
,
2124 else if (MMIX_CFUN_HAS_LANDING_PAD
)
2127 if (MMIX_CFUN_HAS_LANDING_PAD
)
2129 /* Store the register defining the numbering of local registers, so
2130 we know how long to unwind the register stack. */
2134 /* Get 8 less than otherwise, since we need to reach offset + 8. */
2135 HOST_WIDE_INT stack_chunk
2136 = stack_space_to_allocate
> (256 - 8 - 8)
2137 ? (256 - 8 - 8) : stack_space_to_allocate
;
2139 mmix_emit_sp_add (-stack_chunk
);
2141 offset
+= stack_chunk
;
2142 stack_space_to_allocate
-= stack_chunk
;
2145 /* We don't tell dwarf2 about this one; we just have it to unwind
2146 the register stack at landing pads. FIXME: It's a kludge because
2147 we can't describe the effect of the PUSHJ and PUSHGO insns on the
2148 register stack at the moment. Best thing would be to handle it
2149 like stack-pointer offsets. Better: some hook into dwarf2out.c
2150 to produce DW_CFA_expression:s that specify the increment of rO,
2151 and unwind it at eh_return (preferred) or at the landing pad.
2152 Then saves to $0..$G-1 could be specified through that register. */
2154 emit_move_insn (gen_rtx_REG (DImode
, 255),
2155 gen_rtx_REG (DImode
,
2157 emit_move_insn (gen_rtx_MEM (DImode
,
2158 plus_constant (stack_pointer_rtx
, offset
)),
2159 gen_rtx_REG (DImode
, 255));
2163 /* After the return-address and the frame-pointer, we have the local
2164 variables. They're the ones that may have an "unaligned" size. */
2165 offset
-= (locals_size
+ 7) & ~7;
2167 /* Now store all registers that are global, i.e. not saved by the
2168 register file machinery.
2170 It is assumed that the frame-pointer is one of these registers, so it
2171 is explicitly excluded in the count. */
2174 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2176 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2177 && df_regs_ever_live_p (regno
) && ! call_used_regs
[regno
])
2178 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2184 HOST_WIDE_INT stack_chunk
2185 = (stack_space_to_allocate
> (256 - offset
- 8)
2186 ? (256 - offset
- 8) : stack_space_to_allocate
);
2188 mmix_emit_sp_add (-stack_chunk
);
2189 offset
+= stack_chunk
;
2190 stack_space_to_allocate
-= stack_chunk
;
2193 insn
= emit_move_insn (gen_rtx_MEM (DImode
,
2194 plus_constant (stack_pointer_rtx
,
2196 gen_rtx_REG (DImode
, regno
));
2197 RTX_FRAME_RELATED_P (insn
) = 1;
2201 /* Finally, allocate room for outgoing args and local vars if room
2202 wasn't allocated above. */
2203 if (stack_space_to_allocate
)
2204 mmix_emit_sp_add (-stack_space_to_allocate
);
2207 /* Expands the function epilogue into RTX. */
2210 mmix_expand_epilogue (void)
2212 HOST_WIDE_INT locals_size
= get_frame_size ();
2214 HOST_WIDE_INT stack_space_to_deallocate
2215 = (crtl
->outgoing_args_size
2216 + crtl
->args
.pretend_args_size
2217 + locals_size
+ 7) & ~7;
2219 /* The first address to access is beyond the outgoing_args area. */
2220 HOST_WIDE_INT offset
= crtl
->outgoing_args_size
;
2222 /* Add the space for global non-register-stack registers.
2223 It is assumed that the frame-pointer register can be one of these
2224 registers, in which case it is excluded from the count when needed. */
2226 regno
>= MMIX_FIRST_GLOBAL_REGNUM
;
2228 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2229 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2230 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2231 stack_space_to_deallocate
+= 8;
2233 /* Add in the space for register stack-pointer. If so, always add room
2234 for the saved PC. */
2235 if (MMIX_CFUN_HAS_LANDING_PAD
)
2236 stack_space_to_deallocate
+= 16;
2237 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2238 /* If we have a saved return-address slot, add it in. */
2239 stack_space_to_deallocate
+= 8;
2241 /* Add in the frame-pointer. */
2242 if (frame_pointer_needed
)
2243 stack_space_to_deallocate
+= 8;
2245 /* Make sure we don't get an unaligned stack. */
2246 if ((stack_space_to_deallocate
% 8) != 0)
2247 internal_error ("stack frame not a multiple of octabyte: %wd",
2248 stack_space_to_deallocate
);
2250 /* We will add back small offsets to the stack pointer as we go.
2251 First, we restore all registers that are global, i.e. not saved by
2252 the register file machinery. */
2254 for (regno
= MMIX_FIRST_GLOBAL_REGNUM
;
2257 if (((regno
!= MMIX_FRAME_POINTER_REGNUM
|| !frame_pointer_needed
)
2258 && df_regs_ever_live_p (regno
) && !call_used_regs
[regno
])
2259 || IS_MMIX_EH_RETURN_DATA_REG (regno
))
2263 mmix_emit_sp_add (offset
);
2264 stack_space_to_deallocate
-= offset
;
2268 emit_move_insn (gen_rtx_REG (DImode
, regno
),
2269 gen_rtx_MEM (DImode
,
2270 plus_constant (stack_pointer_rtx
,
2275 /* Here is where the local variables were. As in the prologue, they
2276 might be of an unaligned size. */
2277 offset
+= (locals_size
+ 7) & ~7;
2279 /* The saved register stack pointer is just below the frame-pointer
2280 register. We don't need to restore it "manually"; the POP
2281 instruction does that. */
2282 if (MMIX_CFUN_HAS_LANDING_PAD
)
2284 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
)
2285 /* The return-address slot is just below the frame-pointer register.
2286 We don't need to restore it because we don't really use it. */
2289 /* Get back the old frame-pointer-value. */
2290 if (frame_pointer_needed
)
2294 mmix_emit_sp_add (offset
);
2296 stack_space_to_deallocate
-= offset
;
2300 emit_move_insn (hard_frame_pointer_rtx
,
2301 gen_rtx_MEM (DImode
,
2302 plus_constant (stack_pointer_rtx
,
2307 /* We do not need to restore pretended incoming args, just add back
2309 if (stack_space_to_deallocate
!= 0)
2310 mmix_emit_sp_add (stack_space_to_deallocate
);
2312 if (crtl
->calls_eh_return
)
2313 /* Adjust the (normal) stack-pointer to that of the receiver.
2314 FIXME: It would be nice if we could also adjust the register stack
2315 here, but we need to express it through DWARF 2 too. */
2316 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2317 gen_rtx_REG (DImode
,
2318 MMIX_EH_RETURN_STACKADJ_REGNUM
)));
2321 /* Output an optimal sequence for setting a register to a specific
2322 constant. Used in an alternative for const_ints in movdi, and when
2323 using large stack-frame offsets.
2325 Use do_begin_end to say if a line-starting TAB and newline before the
2326 first insn and after the last insn is wanted. */
2329 mmix_output_register_setting (FILE *stream
,
2331 HOST_WIDEST_INT value
,
2335 fprintf (stream
, "\t");
2337 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT
) value
))
2339 /* First, the one-insn cases. */
2340 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2341 (unsigned HOST_WIDEST_INT
)
2343 fprintf (stream
, " %s,", reg_names
[regno
]);
2344 mmix_output_shifted_value (stream
, (unsigned HOST_WIDEST_INT
) value
);
2346 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT
) value
))
2348 /* We do this to get a bit more legible assembly code. The next
2349 alternative is mostly redundant with this. */
2351 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2352 -(unsigned HOST_WIDEST_INT
)
2354 fprintf (stream
, " %s,", reg_names
[regno
]);
2355 mmix_output_shifted_value (stream
, -(unsigned HOST_WIDEST_INT
) value
);
2356 fprintf (stream
, "\n\tNEGU %s,0,%s", reg_names
[regno
],
2359 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT
) value
))
2361 /* Slightly more expensive, the two-insn cases. */
2363 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2364 is shiftable, or any other one-insn transformation of the value.
2365 FIXME: Check first if the value is "shiftable" by two loading
2366 with two insns, since it makes more readable assembly code (if
2367 anyone else cares). */
2369 mmix_output_shiftvalue_op_from_str (stream
, "SET",
2370 ~(unsigned HOST_WIDEST_INT
)
2372 fprintf (stream
, " %s,", reg_names
[regno
]);
2373 mmix_output_shifted_value (stream
, ~(unsigned HOST_WIDEST_INT
) value
);
2374 fprintf (stream
, "\n\tNOR %s,%s,0", reg_names
[regno
],
2379 /* The generic case. 2..4 insns. */
2380 static const char *const higher_parts
[] = {"L", "ML", "MH", "H"};
2381 const char *op
= "SET";
2382 const char *line_begin
= "";
2385 HOST_WIDEST_INT tmpvalue
= value
;
2387 /* Compute the number of insns needed to output this constant. */
2388 for (i
= 0; i
< 4 && tmpvalue
!= 0; i
++)
2390 if (tmpvalue
& 65535)
2394 if (TARGET_BASE_ADDRESSES
&& insns
== 3)
2396 /* The number three is based on a static observation on
2397 ghostscript-6.52. Two and four are excluded because there
2398 are too many such constants, and each unique constant (maybe
2399 offset by 1..255) were used few times compared to other uses,
2402 We use base-plus-offset addressing to force it into a global
2403 register; we just use a "LDA reg,VALUE", which will cause the
2404 assembler and linker to DTRT (for constants as well as
2406 fprintf (stream
, "LDA %s,", reg_names
[regno
]);
2407 mmix_output_octa (stream
, value
, 0);
2411 /* Output pertinent parts of the 4-wyde sequence.
2412 Still more to do if we want this to be optimal, but hey...
2413 Note that the zero case has been handled above. */
2414 for (i
= 0; i
< 4 && value
!= 0; i
++)
2418 fprintf (stream
, "%s%s%s %s,#%x", line_begin
, op
,
2419 higher_parts
[i
], reg_names
[regno
],
2420 (int) (value
& 65535));
2421 /* The first one sets the rest of the bits to 0, the next
2422 ones add set bits. */
2424 line_begin
= "\n\t";
2433 fprintf (stream
, "\n");
2436 /* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2440 mmix_shiftable_wyde_value (unsigned HOST_WIDEST_INT value
)
2442 /* Shift by 16 bits per group, stop when we've found two groups with
2445 int has_candidate
= 0;
2447 for (i
= 0; i
< 4; i
++)
2463 /* X and Y are two things to compare using CODE. Return the rtx for
2464 the cc-reg in the proper mode. */
2467 mmix_gen_compare_reg (RTX_CODE code
, rtx x
, rtx y
)
2469 enum machine_mode ccmode
= SELECT_CC_MODE (code
, x
, y
);
2470 return gen_reg_rtx (ccmode
);
2473 /* Local (static) helper functions. */
2476 mmix_emit_sp_add (HOST_WIDE_INT offset
)
2482 /* Negative stack-pointer adjustments are allocations and appear in
2483 the prologue only. We mark them as frame-related so unwind and
2484 debug info is properly emitted for them. */
2486 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2491 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2492 RTX_FRAME_RELATED_P (emit_move_insn (tmpr
, GEN_INT (offset
))) = 1;
2493 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2494 stack_pointer_rtx
, tmpr
));
2496 RTX_FRAME_RELATED_P (insn
) = 1;
2500 /* Positive adjustments are in the epilogue only. Don't mark them
2501 as "frame-related" for unwind info. */
2502 if (CONST_OK_FOR_LETTER_P (offset
, 'L'))
2503 emit_insn (gen_adddi3 (stack_pointer_rtx
,
2508 rtx tmpr
= gen_rtx_REG (DImode
, 255);
2509 emit_move_insn (tmpr
, GEN_INT (offset
));
2510 insn
= emit_insn (gen_adddi3 (stack_pointer_rtx
,
2511 stack_pointer_rtx
, tmpr
));
2516 /* Print operator suitable for doing something with a shiftable
2517 wyde. The type of operator is passed as an asm output modifier. */
2520 mmix_output_shiftvalue_op_from_str (FILE *stream
,
2522 HOST_WIDEST_INT value
)
2524 static const char *const op_part
[] = {"L", "ML", "MH", "H"};
2527 if (! mmix_shiftable_wyde_value (value
))
2529 char s
[sizeof ("0xffffffffffffffff")];
2530 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2531 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2534 for (i
= 0; i
< 4; i
++)
2536 /* We know we're through when we find one-bits in the low
2540 fprintf (stream
, "%s%s", mainop
, op_part
[i
]);
2546 /* No bits set? Then it must have been zero. */
2547 fprintf (stream
, "%sL", mainop
);
2550 /* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2553 mmix_output_octa (FILE *stream
, HOST_WIDEST_INT value
, int do_begin_end
)
2555 /* Snipped from final.c:output_addr_const. We need to avoid the
2556 presumed universal "0x" prefix. We can do it by replacing "0x" with
2557 "#0" here; we must avoid a space in the operands and no, the zero
2558 won't cause the number to be assumed in octal format. */
2559 char hex_format
[sizeof (HOST_WIDEST_INT_PRINT_HEX
)];
2562 fprintf (stream
, "\tOCTA ");
2564 strcpy (hex_format
, HOST_WIDEST_INT_PRINT_HEX
);
2565 hex_format
[0] = '#';
2566 hex_format
[1] = '0';
2568 /* Provide a few alternative output formats depending on the number, to
2569 improve legibility of assembler output. */
2570 if ((value
< (HOST_WIDEST_INT
) 0 && value
> (HOST_WIDEST_INT
) -10000)
2571 || (value
>= (HOST_WIDEST_INT
) 0 && value
<= (HOST_WIDEST_INT
) 16384))
2572 fprintf (stream
, "%d", (int) value
);
2573 else if (value
> (HOST_WIDEST_INT
) 0
2574 && value
< ((HOST_WIDEST_INT
) 1 << 31) * 2)
2575 fprintf (stream
, "#%x", (unsigned int) value
);
2577 fprintf (stream
, hex_format
, value
);
2580 fprintf (stream
, "\n");
2583 /* Print the presumed shiftable wyde argument shifted into place (to
2584 be output with an operand). */
2587 mmix_output_shifted_value (FILE *stream
, HOST_WIDEST_INT value
)
2591 if (! mmix_shiftable_wyde_value (value
))
2594 sprintf (s
, HOST_WIDEST_INT_PRINT_HEX
, value
);
2595 internal_error ("MMIX Internal: %s is not a shiftable int", s
);
2598 for (i
= 0; i
< 4; i
++)
2600 /* We know we're through when we find one-bits in the low 16 bits. */
2603 fprintf (stream
, "#%x", (int) (value
& 0xffff));
2610 /* No bits set? Then it must have been zero. */
2611 fprintf (stream
, "0");
2614 /* Output an MMIX condition name corresponding to an operator
2616 (comparison_operator [(comparison_operator ...) (const_int 0)])
2617 which means we have to look at *two* operators.
2619 The argument "reversed" refers to reversal of the condition (not the
2620 same as swapping the arguments). */
2623 mmix_output_condition (FILE *stream
, rtx x
, int reversed
)
2629 /* The normal output cc-code. */
2630 const char *const normal
;
2632 /* The reversed cc-code, or NULL if invalid. */
2633 const char *const reversed
;
2638 enum machine_mode cc_mode
;
2640 /* Terminated with {UNKNOWN, NULL, NULL} */
2641 const struct cc_conv
*const convs
;
2645 #define CCEND {UNKNOWN, NULL, NULL}
2647 static const struct cc_conv cc_fun_convs
[]
2648 = {{ORDERED
, "Z", "P"},
2649 {UNORDERED
, "P", "Z"},
2651 static const struct cc_conv cc_fp_convs
[]
2655 static const struct cc_conv cc_fpeq_convs
[]
2659 static const struct cc_conv cc_uns_convs
[]
2660 = {{GEU
, "NN", "N"},
2665 static const struct cc_conv cc_signed_convs
[]
2673 static const struct cc_conv cc_di_convs
[]
2685 static const struct cc_type_conv cc_convs
[]
2686 = {{CC_FUNmode
, cc_fun_convs
},
2687 {CC_FPmode
, cc_fp_convs
},
2688 {CC_FPEQmode
, cc_fpeq_convs
},
2689 {CC_UNSmode
, cc_uns_convs
},
2690 {CCmode
, cc_signed_convs
},
2691 {DImode
, cc_di_convs
}};
2696 enum machine_mode mode
= GET_MODE (XEXP (x
, 0));
2697 RTX_CODE cc
= GET_CODE (x
);
2699 for (i
= 0; i
< ARRAY_SIZE (cc_convs
); i
++)
2701 if (mode
== cc_convs
[i
].cc_mode
)
2703 for (j
= 0; cc_convs
[i
].convs
[j
].cc
!= UNKNOWN
; j
++)
2704 if (cc
== cc_convs
[i
].convs
[j
].cc
)
2707 = (reversed
? cc_convs
[i
].convs
[j
].reversed
2708 : cc_convs
[i
].convs
[j
].normal
);
2710 if (mmix_cc
== NULL
)
2711 fatal_insn ("MMIX Internal: Trying to output invalidly\
2712 reversed condition:", x
);
2714 fprintf (stream
, "%s", mmix_cc
);
2718 fatal_insn ("MMIX Internal: What's the CC of this?", x
);
2722 fatal_insn ("MMIX Internal: What is the CC of this?", x
);
2725 /* Return the bit-value for a const_int or const_double. */
2727 static HOST_WIDEST_INT
2730 unsigned HOST_WIDEST_INT retval
;
2732 if (GET_CODE (x
) == CONST_INT
)
2735 /* We make a little song and dance because converting to long long in
2736 gcc-2.7.2 is broken. I still want people to be able to use it for
2737 cross-compilation to MMIX. */
2738 if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == VOIDmode
)
2740 if (sizeof (HOST_WIDE_INT
) < sizeof (HOST_WIDEST_INT
))
2742 retval
= (unsigned) CONST_DOUBLE_LOW (x
) / 2;
2744 retval
|= CONST_DOUBLE_LOW (x
) & 1;
2747 (unsigned HOST_WIDEST_INT
) CONST_DOUBLE_HIGH (x
)
2748 << (HOST_BITS_PER_LONG
);
2751 retval
= CONST_DOUBLE_HIGH (x
);
2756 if (GET_CODE (x
) == CONST_DOUBLE
)
2758 REAL_VALUE_TYPE value
;
2760 /* FIXME: This macro is not in the manual but should be. */
2761 REAL_VALUE_FROM_CONST_DOUBLE (value
, x
);
2763 if (GET_MODE (x
) == DFmode
)
2767 REAL_VALUE_TO_TARGET_DOUBLE (value
, bits
);
2769 /* The double cast is necessary to avoid getting the long
2770 sign-extended to unsigned long long(!) when they're of
2771 different size (usually 32-bit hosts). */
2773 ((unsigned HOST_WIDEST_INT
) (unsigned long) bits
[0]
2774 << (unsigned HOST_WIDEST_INT
) 32U)
2775 | (unsigned HOST_WIDEST_INT
) (unsigned long) bits
[1];
2777 else if (GET_MODE (x
) == SFmode
)
2780 REAL_VALUE_TO_TARGET_SINGLE (value
, bits
);
2782 return (unsigned long) bits
;
2786 fatal_insn ("MMIX Internal: This is not a constant:", x
);
2789 /* Worker function for TARGET_PROMOTE_FUNCTION_MODE. */
2792 mmix_promote_function_mode (const_tree type ATTRIBUTE_UNUSED
,
2793 enum machine_mode mode
,
2794 int *punsignedp ATTRIBUTE_UNUSED
,
2795 const_tree fntype ATTRIBUTE_UNUSED
,
2798 /* Apparently not doing TRT if int < register-size. FIXME: Perhaps
2799 FUNCTION_VALUE and LIBCALL_VALUE needs tweaking as some ports say. */
2800 if (for_return
== 1)
2803 /* Promotion of modes currently generates slow code, extending before
2804 operation, so we do it only for arguments. */
2805 if (GET_MODE_CLASS (mode
) == MODE_INT
2806 && GET_MODE_SIZE (mode
) < 8)
2811 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
2814 mmix_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
2815 int incoming ATTRIBUTE_UNUSED
)
2817 return gen_rtx_REG (Pmode
, MMIX_STRUCT_VALUE_REGNUM
);
2820 /* Worker function for TARGET_FRAME_POINTER_REQUIRED.
2822 FIXME: Is this requirement built-in? Anyway, we should try to get rid
2823 of it; we can deduce the value. */
2826 mmix_frame_pointer_required (void)
2828 return (cfun
->has_nonlocal_label
);
2833 * eval: (c-set-style "gnu")
2834 * indent-tabs-mode: t