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