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