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