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