]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/mmix/mmix.c
2002-02-05 Eric Christopher <echristo@redhat.com>
[thirdparty/gcc.git] / gcc / config / mmix / mmix.c
CommitLineData
68cbb7e3 1/* Definitions of target machine for GNU compiler, for MMIX.
f38f90bf 2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
68cbb7e3 3 Contributed by Hans-Peter Nilsson (hp@bitrange.com)
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, 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. */
67rtx mmix_compare_op0;
68rtx 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. */
25037517 73const char *mmix_cc1_ignored_option;
68cbb7e3 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. */
79static int mmix_highest_saved_stack_register;
80
81/* Intermediate for insn output. */
82static int mmix_output_destination_register;
83
84static void mmix_output_shiftvalue_op_from_str
85 PARAMS ((FILE *, const char *, HOST_WIDEST_INT));
86static void mmix_output_shifted_value PARAMS ((FILE *, HOST_WIDEST_INT));
87static void mmix_output_condition PARAMS ((FILE *, rtx, int));
88static HOST_WIDEST_INT mmix_intval PARAMS ((rtx));
89static void mmix_output_octa PARAMS ((FILE *, HOST_WIDEST_INT, int));
58356836 90static bool mmix_assemble_integer PARAMS ((rtx, unsigned int, int));
68cbb7e3 91static void mmix_init_machine_status PARAMS ((struct function *));
92
93extern void mmix_target_asm_function_prologue
94 PARAMS ((FILE *, HOST_WIDE_INT));
95extern 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
58356836 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
68cbb7e3 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
121struct 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
128void
129mmix_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
150void
151mmix_init_expanders ()
152{
153 init_machine_status = mmix_init_machine_status;
154}
155
156/* Set the per-function data. */
157
25037517 158static void
68cbb7e3 159mmix_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
170int
171mmix_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
183int
184mmix_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
196int
197mmix_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
209void
210mmix_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
243enum reg_class
244mmix_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
256enum reg_class
257mmix_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
269enum reg_class
270mmix_secondary_reload_class (class, mode, x, in_p)
271 enum reg_class class;
0103ffd2 272 enum machine_mode mode ATTRIBUTE_UNUSED;
273 rtx x ATTRIBUTE_UNUSED;
274 int in_p ATTRIBUTE_UNUSED;
68cbb7e3 275{
276 if (class == REMAINDER_REG
277 || class == HIMULT_REG
278 || class == SYSTEM_REGS)
279 return GENERAL_REGS;
280
68cbb7e3 281 return NO_REGS;
282}
283
284/* CONST_OK_FOR_LETTER_P. */
285
286int
287mmix_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
305int
306mmix_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
319int
0103ffd2 320mmix_extra_constraint (x, c, strict)
68cbb7e3 321 rtx x;
322 int c;
0103ffd2 323 int strict;
68cbb7e3 324{
325 HOST_WIDEST_INT value;
326
0103ffd2 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. */
68cbb7e3 331 if (c == 'U')
0103ffd2 332 return
333 strict
334 ? strict_memory_address_p (Pmode, x)
335 : memory_address_p (Pmode, x);
68cbb7e3 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
354rtx
355mmix_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
367int
368mmix_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
384rtx
385mmix_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
399void
400mmix_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
408int
409mmix_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
460rtx
461mmix_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
501int
502mmix_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
520int
521mmix_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
534rtx
535mmix_function_outgoing_value (valtype, func)
536 tree valtype;
537 tree func ATTRIBUTE_UNUSED;
538{
539 enum machine_mode mode = TYPE_MODE (valtype);
68cbb7e3 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)
68435912 564 internal_error ("too large function value type, needs %d registers,\
68cbb7e3 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
585int
586mmix_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
597rtx
598mmix_eh_return_stackadj_rtx ()
599{
600 return gen_rtx_REG (Pmode, MMIX_EH_RETURN_STACKADJ_REGNUM);
601}
602
603/* EH_RETURN_HANDLER_RTX. */
604
605rtx
606mmix_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
614int
615mmix_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
629void
630mmix_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)
68435912 679 internal_error ("stack frame not a multiple of 8 bytes: %d",
68cbb7e3 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;
68cbb7e3 969}
970
971/* TARGET_ASM_FUNCTION_EPILOGUE. */
972
973void
974mmix_target_asm_function_epilogue (stream, locals_size)
975 FILE *stream;
976 HOST_WIDE_INT locals_size;
977
978{
979 int regno;
980 int stack_space_to_deallocate
981 = (current_function_outgoing_args_size
982 + current_function_pretend_args_size
983 + (int) locals_size + 8 + 7) & ~7;
984
985 /* The assumption that locals_size fits in an int is asserted in
986 mmix_target_asm_function_prologue. */
987
988 /* The first address to access is beyond the outgoing_args area. */
989 int offset = current_function_outgoing_args_size;
990 int empty_stack_frame
991 = (current_function_outgoing_args_size == 0
992 && locals_size == 0
993 && current_function_pretend_args_size == 0
994 && ! MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS
995 && ! MMIX_CFUN_HAS_LANDING_PAD);
996
997 /* Add the space for global non-register-stack registers.
998 It is assumed that the frame-pointer register can be one of these
999 registers, in which case it is excluded from the count when needed. */
1000 for (regno = 255;
1001 regno >= MMIX_FIRST_GLOBAL_REGNUM;
1002 regno--)
1003 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1004 && regs_ever_live[regno] && !call_used_regs[regno])
1005 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1006 stack_space_to_deallocate += 8;
1007
1008 /* Add in the space for register stack-pointer. If so, always add room
1009 for the saved PC. */
1010 if (MMIX_CFUN_HAS_LANDING_PAD)
1011 stack_space_to_deallocate += 16;
1012 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1013 /* If we have a saved return-address slot, add it in. */
1014 stack_space_to_deallocate += 8;
1015
1016 /* Add in the frame-pointer. */
1017 if (frame_pointer_needed)
1018 stack_space_to_deallocate += 8;
1019
1020 /* Make sure we don't get an unaligned stack. */
1021 if ((stack_space_to_deallocate % 8) != 0)
68435912 1022 internal_error ("stack frame not a multiple of octabyte: %d",
68cbb7e3 1023 stack_space_to_deallocate);
1024
1025 /* We will add back small offsets to the stack pointer as we go.
1026 First, we restore all registers that are global, i.e. not saved by
1027 the register file machinery. */
1028
1029 for (regno = MMIX_FIRST_GLOBAL_REGNUM;
1030 regno <= 255;
1031 regno++)
1032 if (((regno != MMIX_FRAME_POINTER_REGNUM || !frame_pointer_needed)
1033 && regs_ever_live[regno] && !call_used_regs[regno])
1034 || IS_MMIX_EH_RETURN_DATA_REG (regno))
1035 {
1036 empty_stack_frame = 0;
1037
1038 if (offset > 255)
1039 {
1040 if (offset > 65535)
1041 {
1042 /* There's better support for incrementing than
1043 decrementing, so we might be able to optimize this as
1044 we see a need. */
1045 mmix_output_register_setting (stream, 255, offset, 1);
1046 fprintf (stream, "\tADDU %s,%s,$255\n",
1047 reg_names[MMIX_STACK_POINTER_REGNUM],
1048 reg_names[MMIX_STACK_POINTER_REGNUM]);
1049 }
1050 else
1051 fprintf (stream, "\tINCL %s,%d\n",
1052 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1053
1054 stack_space_to_deallocate -= offset;
1055 offset = 0;
1056 }
1057
1058 fprintf (stream, "\tLDOU %s,%s,%d\n",
1059 reg_names[regno],
1060 reg_names[MMIX_STACK_POINTER_REGNUM],
1061 offset);
1062 offset += 8;
1063 }
1064
1065 /* Here is where the local variables were. As in the prologue, they
1066 might be of an unaligned size. */
1067 offset += (locals_size + 7) & ~7;
1068
1069
1070 /* The saved register stack pointer is just below the frame-pointer
1071 register. We don't need to restore it "manually"; the POP
1072 instruction does that. */
1073 if (MMIX_CFUN_HAS_LANDING_PAD)
1074 offset += 16;
1075 else if (MMIX_CFUN_NEEDS_SAVED_EH_RETURN_ADDRESS)
1076 /* The return-address slot is just below the frame-pointer register.
1077 We don't need to restore it because we don't really use it. */
1078 offset += 8;
1079
1080 /* Get back the old frame-pointer-value. */
1081 if (frame_pointer_needed)
1082 {
1083 empty_stack_frame = 0;
1084
1085 if (offset > 255)
1086 {
1087 if (offset > 65535)
1088 {
1089 /* There's better support for incrementing than
1090 decrementing, so we might be able to optimize this as
1091 we see a need. */
1092 mmix_output_register_setting (stream, 255, offset, 1);
1093 fprintf (stream, "\tADDU %s,%s,$255\n",
1094 reg_names[MMIX_STACK_POINTER_REGNUM],
1095 reg_names[MMIX_STACK_POINTER_REGNUM]);
1096 }
1097 else
1098 fprintf (stream, "\tINCL %s,%d\n",
1099 reg_names[MMIX_STACK_POINTER_REGNUM], offset);
1100
1101 stack_space_to_deallocate -= offset;
1102 offset = 0;
1103 }
1104
1105 fprintf (stream, "\tLDOU %s,%s,%d\n",
1106 reg_names[MMIX_FRAME_POINTER_REGNUM],
1107 reg_names[MMIX_STACK_POINTER_REGNUM],
1108 offset);
1109 offset += 8;
1110 }
1111
1112 /* Do not deallocate the return-address slot if the stack frame is
1113 empty, because then it was never allocated. */
1114 if (! empty_stack_frame)
1115 {
1116 /* We do not need to restore pretended incoming args, just add
1117 back offset to sp. */
1118 if (stack_space_to_deallocate > 65535)
1119 {
1120 /* There's better support for incrementing than decrementing, so
1121 we might be able to optimize this as we see a need. */
1122 mmix_output_register_setting (stream, 255,
1123 stack_space_to_deallocate, 1);
1124 fprintf (stream, "\tADDU %s,%s,$255\n",
1125 reg_names[MMIX_STACK_POINTER_REGNUM],
1126 reg_names[MMIX_STACK_POINTER_REGNUM]);
1127 }
1128 else
1129 fprintf (stream, "\tINCL %s,%d\n",
1130 reg_names[MMIX_STACK_POINTER_REGNUM],
1131 stack_space_to_deallocate);
1132 }
1133
1134 if (current_function_calls_eh_return)
1135 /* Adjustment the (normal) stack-pointer to that of the receiver.
1136 FIXME: It would be nice if we could also adjust the register stack
1137 here, but we need to express it through DWARF 2 too. */
1138 fprintf (stream, "\tADDU %s,%s,%s\n",
1139 reg_names [MMIX_STACK_POINTER_REGNUM],
1140 reg_names [MMIX_STACK_POINTER_REGNUM],
1141 reg_names [MMIX_EH_RETURN_STACKADJ_REGNUM]);
1142
1143 /* The extra \n is so we have a blank line between the assembly code of
1144 separate functions. */
1145 fprintf (stream, "\tPOP %d,0\n\n",
1146 (! TARGET_ABI_GNU
1147 && current_function_return_rtx != NULL
1148 && ! current_function_returns_struct)
1149 ? (GET_CODE (current_function_return_rtx) == PARALLEL
1150 ? GET_NUM_ELEM (XVEC (current_function_return_rtx, 0)) : 1)
1151 : 0);
1152}
1153
1154/* ASM_OUTPUT_MI_THUNK. */
1155
1156void
1157mmix_asm_output_mi_thunk (stream, fndecl, delta, func)
1158 FILE * stream;
1159 tree fndecl ATTRIBUTE_UNUSED;
1160 int delta;
1161 tree func;
1162{
1163 /* If you define STRUCT_VALUE to 0, rather than use STRUCT_VALUE_REGNUM,
1164 (i.e. pass location of structure to return as invisible first
1165 argument) you need to tweak this code too. */
1166 const char *regname = reg_names[MMIX_FIRST_INCOMING_ARG_REGNUM];
1167
1168 if (delta >= 0 && delta < 65536)
1169 asm_fprintf (stream, "\tINCL %s,%d\n", delta, regname);
1170 else if (delta < 0 && delta >= -255)
1171 asm_fprintf (stream, "\tSUBU %s,%s,%d\n", regname, regname, -delta);
1172 else
1173 {
1174 mmix_output_register_setting (stream, 255, delta, 1);
1175 asm_fprintf (stream, "\tADDU %s,%s,$255\n", regname, regname);
1176 }
1177
1178 fprintf (stream, "\tJMP ");
1179 assemble_name (stream, XSTR (XEXP (DECL_RTL (func), 0), 0));
1180 fprintf (stream, "\n");
1181}
1182
1183/* FUNCTION_PROFILER. */
1184
1185void
1186mmix_function_profiler (stream, labelno)
1187 FILE *stream ATTRIBUTE_UNUSED;
1188 int labelno ATTRIBUTE_UNUSED;
1189{
1190 sorry ("function_profiler support for MMIX");
1191}
1192
68cbb7e3 1193/* SETUP_INCOMING_VARARGS. */
1194
1195void
1196mmix_setup_incoming_varargs (args_so_farp, mode, vartype, pretend_sizep,
1197 second_time)
1198 CUMULATIVE_ARGS * args_so_farp;
1199 enum machine_mode mode;
1200 tree vartype;
1201 int * pretend_sizep;
1202 int second_time ATTRIBUTE_UNUSED;
1203{
1204 /* For stdarg, the last named variable has been handled, but
1205 args_so_farp has not been advanced for it. For varargs, the current
1206 argument is to be counted to the anonymous ones. */
1207 if (current_function_stdarg)
1208 {
1209 if (args_so_farp->regs + 1 < MMIX_MAX_ARGS_IN_REGS)
1210 *pretend_sizep
1211 = (MMIX_MAX_ARGS_IN_REGS - (args_so_farp->regs + 1)) * 8;
1212 }
1213 else if (current_function_varargs)
1214 {
1215 if (args_so_farp->regs < MMIX_MAX_ARGS_IN_REGS)
1216 *pretend_sizep
1217 = (MMIX_MAX_ARGS_IN_REGS - args_so_farp->regs) * 8;
1218
1219 /* For varargs, we get here when we see the last named parameter,
1220 which will actually be passed on stack. So make the next call
1221 (there will be one) to FUNCTION_ARG return 0, to count it on
1222 stack, so va_arg for it will get right. FIXME: The GCC core
1223 should provide TRT. */
1224 args_so_farp->now_varargs = 1;
1225 }
1226 else
68435912 1227 internal_error ("neither varargs or stdarg in mmix_setup_incoming_varargs");
68cbb7e3 1228
1229
1230 /* We assume that one argument takes up one register here. That should
1231 be true until we start messing with multi-reg parameters. */
1232 if ((7 + (MMIX_FUNCTION_ARG_SIZE (mode, vartype))) / 8 != 1)
1233 internal_error ("MMIX Internal: Last named vararg would not fit in a register");
1234}
1235
1236/* EXPAND_BUILTIN_VA_ARG. */
1237
1238/* This is modified from the "standard" implementation of va_arg: read the
1239 value from the current (padded) address and increment by the (padded)
1240 size. The difference for MMIX is that if the type is
1241 pass-by-reference, then perform an indirection. */
1242
1243rtx
1244mmix_expand_builtin_va_arg (valist, type)
1245 tree valist;
1246 tree type;
1247{
1248 tree addr_tree, t;
1249 HOST_WIDE_INT align;
1250 HOST_WIDE_INT rounded_size;
1251 rtx addr;
1252
1253 /* Compute the rounded size of the type. */
1254 align = PARM_BOUNDARY / BITS_PER_UNIT;
1255 rounded_size = (((int_size_in_bytes (type) + align - 1) / align) * align);
1256
1257 /* Get AP. */
1258 addr_tree = valist;
1259
1260 if (AGGREGATE_TYPE_P (type)
1261 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) < 8
1262 && GET_MODE_UNIT_SIZE (TYPE_MODE (type)) != 0)
1263 {
1264 /* Adjust for big-endian the location of aggregates passed in a
1265 register, but where the aggregate is accessed in a shorter mode
1266 than the natural register mode (i.e. it is accessed as SFmode(?),
1267 SImode, HImode or QImode rather than DImode or DFmode(?)). FIXME:
1268 Or should we adjust the mode in which the aggregate is read, to be
1269 a register size mode? (Hum, nah, a small offset is generally
1270 cheaper than a wider memory access on MMIX.) */
1271 addr_tree
1272 = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1273 build_int_2 ((BITS_PER_WORD / BITS_PER_UNIT)
1274 - GET_MODE_UNIT_SIZE (TYPE_MODE (type)), 0));
1275 }
1276 else
1277 {
1278 HOST_WIDE_INT adj;
1279 adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT;
1280 if (rounded_size > align)
1281 adj = rounded_size;
1282
1283 addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
1284 build_int_2 (rounded_size - adj, 0));
1285
1286 /* If this type is larger than what fits in a register, then it is
1287 passed by reference. */
1288 if (rounded_size > BITS_PER_WORD / BITS_PER_UNIT)
1289 {
1290 tree type_ptr = build_pointer_type (type);
1291 addr_tree = build1 (INDIRECT_REF, type_ptr, addr_tree);
1292 }
1293 }
1294
1295 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
1296 addr = copy_to_reg (addr);
1297
1298 /* Compute new value for AP. For MMIX, it is always advanced by the
1299 size of a register. */
1300 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
1301 build (PLUS_EXPR, TREE_TYPE (valist), valist,
1302 build_int_2 (BITS_PER_WORD / BITS_PER_UNIT, 0)));
1303 TREE_SIDE_EFFECTS (t) = 1;
1304 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1305
1306 return addr;
1307}
1308
1309/* TRAMPOLINE_SIZE. */
1310/* Four 4-byte insns plus two 8-byte values. */
1311int mmix_trampoline_size = 32;
1312
1313
1314/* TRAMPOLINE_TEMPLATE. */
1315
1316void
1317mmix_trampoline_template (stream)
1318 FILE * stream;
1319{
1320 /* Read a value from to static-chain, jump somewhere. The static chain
1321 is stored at offset 16, and the function address is stored at offset
1322 24. */
1323 /* FIXME: GCC copies this using *intsize* (tetra), when it should use
1324 register size (octa). */
1325 fprintf (stream, "\tGETA $255,1F\n\t");
1326 fprintf (stream, "LDOU %s,$255,0\n\t",
1327 reg_names[MMIX_STATIC_CHAIN_REGNUM]);
1328 fprintf (stream, "LDOU $255,$255,8\n\t");
1329 fprintf (stream, "GO $255,$255,0\n");
1330 fprintf (stream, "1H\tOCTA 0\n\t");
1331 fprintf (stream, "OCTA 0\n");
1332}
1333
1334/* INITIALIZE_TRAMPOLINE. */
1335/* Set the static chain and function pointer field in the trampoline.
1336 We also SYNCID here to be sure (doesn't matter in the simulator, but
1337 some day it will). */
1338
1339void
1340mmix_initialize_trampoline (trampaddr, fnaddr, static_chain)
1341 rtx trampaddr;
1342 rtx fnaddr;
1343 rtx static_chain;
1344{
1345 emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
1346 static_chain);
1347 emit_move_insn (gen_rtx_MEM (DImode,
1348 plus_constant (trampaddr, 24)),
1349 fnaddr);
1350 emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
1351 trampaddr)),
1352 GEN_INT (mmix_trampoline_size - 1)));
1353}
1354
1355/* We must exclude constant addresses that have an increment that is not a
1356 multiple of four bytes because of restrictions of the GETA
1357 instruction. FIXME: No, I don't think so. Just add a constraint. */
1358
1359int
1360mmix_constant_address_p (x)
1361 rtx x;
1362{
1363 RTX_CODE code = GET_CODE (x);
1364 int addend = 0;
1365
1366 if (code == LABEL_REF || code == SYMBOL_REF)
1367 return 1;
1368
1369 if (code == CONSTANT_P_RTX || code == HIGH)
1370 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1371 return 0;
1372
1373 switch (code)
1374 {
1375 case LABEL_REF:
1376 case SYMBOL_REF:
1377 return 1;
1378
1379 case PLUS:
1380 /* Can we get a naked PLUS? */
1381 case CONSTANT_P_RTX:
1382 case HIGH:
1383 /* FIXME: Don't know how to dissect these. Avoid them for now. */
1384 return 0;
1385
1386 case CONST_INT:
1387 addend = INTVAL (x);
1388 break;
1389
1390 case CONST_DOUBLE:
1391 if (GET_MODE (x) != VOIDmode)
1392 /* Strange that we got here. FIXME: Check if we do. */
1393 return 0;
1394 addend = CONST_DOUBLE_LOW (x);
1395 break;
1396
1397 case CONST:
1398 /* Note that expressions with arithmetic on forward references don't
1399 work in mmixal. People using gcc assembly code with mmixal might
1400 need to move arrays and such to before the point of use. */
1401 if (GET_CODE (XEXP (x, 0)) == PLUS)
1402 {
1403 rtx x0 = XEXP (XEXP (x, 0), 0);
1404 rtx x1 = XEXP (XEXP (x, 0), 1);
1405
1406 if ((GET_CODE (x0) == SYMBOL_REF
1407 || GET_CODE (x0) == LABEL_REF)
1408 && (GET_CODE (x1) == CONST_INT
1409 || (GET_CODE (x1) == CONST_DOUBLE
1410 && GET_MODE (x1) == VOIDmode)))
1411 addend = mmix_intval (x1);
1412 else
1413 return 0;
1414 }
1415 else
1416 return 0;
1417 break;
1418
1419 default:
1420 return 0;
1421 }
1422
1423 return (addend & 3) == 0;
1424}
1425
1426/* Return 1 if the address is OK, otherwise 0.
1427 Used by GO_IF_LEGITIMATE_ADDRESS. */
1428
1429int
1430mmix_legitimate_address (mode, x, strict_checking)
1431 enum machine_mode mode ATTRIBUTE_UNUSED;
1432 rtx x;
1433 int strict_checking;
1434{
1435#define MMIX_REG_OK(X) \
1436 ((strict_checking \
1437 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1438 || (reg_renumber[REGNO (X)] > 0 \
1439 && reg_renumber[REGNO (X)] <= MMIX_LAST_GENERAL_REGISTER))) \
1440 || (!strict_checking \
1441 && (REGNO (X) <= MMIX_LAST_GENERAL_REGISTER \
1442 || REGNO (X) >= FIRST_PSEUDO_REGISTER \
1443 || REGNO (X) == ARG_POINTER_REGNUM)))
1444
1445 /* We only accept:
1446 (mem reg)
1447 (mem (plus reg reg))
1448 (mem (plus reg 0..255)). */
1449
1450
1451 /* (mem reg) */
1452 if (REG_P (x) && MMIX_REG_OK (x))
1453 return 1;
1454
1455 if (GET_CODE(x) == PLUS)
1456 {
1457 rtx x1 = XEXP (x, 0);
1458 rtx x2 = XEXP (x, 1);
1459
1460 /* Try swapping the order. FIXME: Do we need this? */
1461 if (! REG_P (x1))
1462 {
1463 rtx tem = x1;
1464 x1 = x2;
1465 x2 = tem;
1466 }
1467
1468 /* (mem (plus (reg) (?))) */
1469 if (!REG_P (x1) || !MMIX_REG_OK (x1))
1470 return 0;
1471
1472 /* (mem (plus (reg) (reg))) */
1473 if (REG_P (x2) && MMIX_REG_OK (x2))
1474 return 1;
1475
1476 /* (mem (plus (reg) (0..255))) */
1477 if (GET_CODE (x2) == CONST_INT
1478 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
1479 return 1;
1480 }
1481
1482 return 0;
1483}
1484
1485/* LEGITIMATE_CONSTANT_P. */
1486
1487int
1488mmix_legitimate_constant_p (x)
1489 rtx x;
1490{
1491 RTX_CODE code = GET_CODE (x);
1492
1493 /* We must allow any number due to the way the cse passes works; if we
1494 do not allow any number here, general_operand will fail, and insns
1495 will fatally fail recognition instead of "softly". */
1496 if (code == CONST_INT || code == CONST_DOUBLE)
1497 return 1;
1498
1499 return CONSTANT_ADDRESS_P (x);
1500}
1501
1502/* SELECT_CC_MODE. */
1503
1504enum machine_mode
1505mmix_select_cc_mode (op, x, y)
1506 RTX_CODE op;
1507 rtx x;
1508 rtx y ATTRIBUTE_UNUSED;
1509{
1510 /* We use CCmode, CC_UNSmode, CC_FPmode, CC_FPEQmode and CC_FUNmode to
1511 output different compare insns. Note that we do not check the
1512 validity of the comparison here. */
1513
1514 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1515 {
1516 if (op == ORDERED || op == UNORDERED || op == UNGE
1517 || op == UNGT || op == UNLE || op == UNLT)
1518 return CC_FUNmode;
1519
1520 if (op == EQ || op == NE)
1521 return CC_FPEQmode;
1522
1523 return CC_FPmode;
1524 }
1525
1526 if (op == GTU || op == LTU || op == GEU || op == LEU)
1527 return CC_UNSmode;
1528
1529 return CCmode;
1530}
1531
1532/* CANONICALIZE_COMPARISON.
1533 FIXME: Check if the number adjustments trig. */
1534
1535void
1536mmix_canonicalize_comparison (codep, op0p, op1p)
1537 RTX_CODE * codep;
1538 rtx * op0p ATTRIBUTE_UNUSED;
1539 rtx * op1p;
1540{
1541 /* Change -1 to zero, if possible. */
1542 if ((*codep == LE || *codep == GT)
1543 && GET_CODE (*op1p) == CONST_INT
1544 && *op1p == constm1_rtx)
1545 {
1546 *codep = *codep == LE ? LT : GE;
1547 *op1p = const0_rtx;
1548 }
1549
1550 /* Fix up 256 to 255, if possible. */
1551 if ((*codep == LT || *codep == LTU || *codep == GE || *codep == GEU)
1552 && GET_CODE (*op1p) == CONST_INT
1553 && INTVAL (*op1p) == 256)
1554 {
1555 /* FIXME: Remove when I know this trigs. */
68435912 1556 fatal_insn ("oops, not debugged; fixing up value:", *op1p);
68cbb7e3 1557 *codep = *codep == LT ? LE : *codep == LTU ? LEU : *codep
1558 == GE ? GT : GTU;
1559 *op1p = GEN_INT (255);
1560 }
1561}
1562
1563/* REVERSIBLE_CC_MODE. */
1564
1565int
1566mmix_reversible_cc_mode (mode)
1567 enum machine_mode mode;
1568{
1569 /* That is, all integer and the EQ, NE, ORDERED and UNORDERED float
1570 cmpares. */
1571 return mode != CC_FPmode;
1572}
1573
1574/* DEFAULT_RTX_COSTS. */
1575
1576int
1577mmix_rtx_cost_recalculated (x, code, outer_code, costp)
1578 rtx x ATTRIBUTE_UNUSED;
1579 RTX_CODE code ATTRIBUTE_UNUSED;
1580 RTX_CODE outer_code ATTRIBUTE_UNUSED;
1581 int *costp ATTRIBUTE_UNUSED;
1582{
1583 /* For the time being, this is just a stub and we'll accept the
1584 generic calculations, until we can do measurements, at least.
1585 Say we did not modify any calculated costs. */
1586 return 0;
1587}
1588
1589/* ADDRESS_COST. */
1590
1591int
1592mmix_address_cost (addr)
1593 rtx addr ATTRIBUTE_UNUSED;
1594{
1595 /* There's no difference in the address costs and we have lots of
1596 registers. Some targets use constant 0, many others use 1 to say
1597 this. Let's start with 1. */
1598 return 1;
1599}
1600
1601/* REGISTER_MOVE_COST. */
1602
1603int
1604mmix_register_move_cost (mode, from, to)
1605 enum machine_mode mode ATTRIBUTE_UNUSED;
1606 enum reg_class from;
1607 enum reg_class to;
1608{
1609 return (from == GENERAL_REGS && from == to) ? 2 : 3;
1610}
1611
1612/* Note that we don't have a TEXT_SECTION_ASM_OP, because it has to be a
1613 compile-time constant; it's used in an asm in crtstuff.c, compiled for
1614 the target. */
1615
1616/* DATA_SECTION_ASM_OP. */
1617
1618const char *
1619mmix_data_section_asm_op ()
1620{
1621 return "\t.data ! mmixal:= 8H LOC 9B";
1622}
1623
1624/* SELECT_SECTION.
1625 The meat is from elfos.h, which we will eventually consider using. */
1626
1627void
1628mmix_select_section (decl, reloc, align)
1629 tree decl;
1630 int reloc;
1631 int align ATTRIBUTE_UNUSED;
1632{
1633 if (TREE_CODE (decl) == STRING_CST)
1634 {
1635 if (! flag_writable_strings)
1636 const_section ();
1637 else
1638 data_section ();
1639 }
1640 else if (TREE_CODE (decl) == VAR_DECL)
1641 {
1642 if ((flag_pic && reloc)
1643 || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl)
1644 || !DECL_INITIAL (decl)
1645 || (DECL_INITIAL (decl) != error_mark_node
1646 && !TREE_CONSTANT (DECL_INITIAL (decl))))
1647 data_section ();
1648 else
1649 const_section ();
1650 }
1651 else if (TREE_CODE (decl) == CONSTRUCTOR)
1652 {
1653 if ((flag_pic && reloc)
1654 || !TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl)
1655 || ! TREE_CONSTANT (decl))
1656 data_section ();
1657 else
1658 const_section ();
1659 }
1660 else
1661 const_section ();
1662}
1663
1664/* ENCODE_SECTION_INFO. */
1665
1666void
1667mmix_encode_section_info (decl)
1668 tree decl;
1669{
1670 /* Test for an external declaration, and do nothing if it is one. */
1671 if ((TREE_CODE (decl) == VAR_DECL
91009d64 1672 && (DECL_EXTERNAL (decl) || TREE_PUBLIC (decl)))
1673 || (TREE_CODE (decl) == FUNCTION_DECL && TREE_PUBLIC (decl)))
68cbb7e3 1674 ;
1675 else if (DECL_P (decl))
1676 {
1677 /* For non-visible declarations, add a "@" prefix, which we skip
1678 when the label is output. If the label does not have this
1679 prefix, a ":" is output.
1680
1681 Note that this does not work for data that is declared extern and
1682 later defined as static. If there's code in between, that code
1683 will refer to the extern declaration. And vice versa. Until we
91009d64 1684 can get rid of mmixal, we have to assume that code is
1685 well-behaved. */
68cbb7e3 1686
1687 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1688 int len = strlen (str);
1689 char *newstr;
1690
1691 /* Doing as rs6000 seems safe; always use ggc. Except don't copy
1692 the suspected off-by-one bug.
1693 FIXME: Is it still there? yes 2001-08-23
1694 Why is the return type of ggc_alloc_string const? */
1695 newstr = (char *) ggc_alloc_string ("", len + 2);
1696
1697 strcpy (newstr + 1, str);
1698 *newstr = '@';
1699 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
1700 }
1701
1702 /* FIXME: Later on, add SYMBOL_REF_FLAG for things that we can reach
1703 from here via GETA, to check in LEGITIMATE_CONSTANT_P. Needs to have
1704 different options for the cases where we want *all* to be assumed
1705 reachable via GETA, or all constant symbols, or just text symbols in
1706 this file, or perhaps just the constant pool. */
1707}
1708
1709/* STRIP_NAME_ENCODING. */
1710
1711const char *
1712mmix_strip_name_encoding (name)
1713 const char *name;
1714{
1715 for (; (*name == '@' || *name == '*'); name++)
1716 ;
1717
1718 return name;
1719}
1720
1721/* UNIQUE_SECTION.
1722 The meat is from elfos.h, which we should consider using. */
1723
1724void
1725mmix_unique_section (decl, reloc)
1726 tree decl;
1727 int reloc;
1728{
1729 int len;
1730 int sec;
1731 const char *name;
1732 char *string;
1733 const char *prefix;
25037517 1734 static const char *const prefixes[4][2] =
68cbb7e3 1735 {
1736 { ".text.", ".gnu.linkonce.t." },
1737 { ".rodata.", ".gnu.linkonce.r." },
1738 { ".data.", ".gnu.linkonce.d." },
1739 { ".bss.", ".gnu.linkonce.b." }
1740 };
1741
1742 if (TREE_CODE (decl) == FUNCTION_DECL)
1743 sec = 0;
1744 else if (DECL_INITIAL (decl) == 0
1745 || DECL_INITIAL (decl) == error_mark_node)
1746 sec = 3;
1747 else if (DECL_READONLY_SECTION (decl, reloc))
1748 sec = 1;
1749 else
1750 sec = 2;
1751
1752 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1753 /* Strip off any encoding in name. */
1754 STRIP_NAME_ENCODING (name, name);
1755 prefix = prefixes[sec][DECL_ONE_ONLY (decl)];
1756 len = strlen (name) + strlen (prefix);
1757 string = alloca (len + 1);
1758
1759 sprintf (string, "%s%s", prefix, name);
1760
1761 DECL_SECTION_NAME (decl) = build_string (len, string);
1762}
1763
1764/* ASM_FILE_START. */
1765
1766void
1767mmix_asm_file_start (stream)
1768 FILE * stream;
1769{
1770 /* We just emit a little comment for the time being. FIXME: Perhaps add
1771 -mstandalone and some segment and prefix setup here. */
1772 ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
1773
1774 fprintf (stream, "! mmixal:= 8H LOC Data_Section\n");
1775
1776 /* Make sure each file starts with the text section. */
1777 text_section ();
1778}
1779
1780/* ASM_FILE_END. */
1781
1782void
1783mmix_asm_file_end (stream)
1784 FILE * stream ATTRIBUTE_UNUSED;
1785{
1786 /* Make sure each file ends with the data section. */
1787 data_section ();
1788}
1789
68cbb7e3 1790/* ASM_OUTPUT_SOURCE_FILENAME. */
1791
1792void
1793mmix_asm_output_source_filename (stream, name)
1794 FILE * stream;
1795 const char * name;
1796{
1797 fprintf (stream, "# 1 ");
1798 OUTPUT_QUOTED_STRING (stream, name);
1799 fprintf (stream, "\n");
1800}
1801
1802/* OUTPUT_QUOTED_STRING. */
1803
1804void
1805mmix_output_quoted_string (stream, string, length)
1806 FILE * stream;
1807 const char * string;
1808 int length;
1809{
1810 const char * string_end = string + length;
25037517 1811 static const char *const unwanted_chars = "\"[]\\";
68cbb7e3 1812
1813 /* Output "any character except newline and double quote character". We
1814 play it safe and avoid all control characters too. We also do not
1815 want [] as characters, should input be passed through m4 with [] as
1816 quotes. Further, we avoid "\", because the GAS port handles it as a
1817 quoting character. */
1818 while (string < string_end)
1819 {
1820 if (*string
1821 && (unsigned char) *string < 128
1822 && !ISCNTRL (*string)
1823 && strchr (unwanted_chars, *string) == NULL)
1824 {
1825 fputc ('"', stream);
1826 while (*string
1827 && (unsigned char) *string < 128
1828 && !ISCNTRL (*string)
1829 && strchr (unwanted_chars, *string) == NULL
1830 && string < string_end)
1831 {
1832 fputc (*string, stream);
1833 string++;
1834 }
1835 fputc ('"', stream);
1836 if (string < string_end)
1837 fprintf (stream, ",");
1838 }
1839 if (string < string_end)
1840 {
1841 fprintf (stream, "#%x", *string & 255);
1842 string++;
1843 if (string < string_end)
1844 fprintf (stream, ",");
1845 }
1846 }
1847}
1848
1849/* ASM_OUTPUT_SOURCE_LINE. */
1850
1851void
1852mmix_asm_output_source_line (stream, lineno)
1853 FILE * stream;
1854 int lineno;
1855{
1856 fprintf (stream, "# %d ", lineno);
1857 OUTPUT_QUOTED_STRING (stream, main_input_filename);
1858 fprintf (stream, "\n");
1859}
1860
58356836 1861/* Target hook for assembling integer objects. Use mmix_print_operand
1862 for WYDE and TETRA. Use mmix_output_octa to output 8-byte
1863 CONST_DOUBLEs. */
68cbb7e3 1864
58356836 1865static bool
1866mmix_assemble_integer (x, size, aligned_p)
1867 rtx x;
1868 unsigned int size;
1869 int aligned_p;
68cbb7e3 1870{
58356836 1871 if (aligned_p)
1872 switch (size)
1873 {
1874 case 1:
1875 fputs ("\tBYTE\t", asm_out_file);
1876 mmix_print_operand (asm_out_file, x, 'B');
1877 fputc ('\n', asm_out_file);
1878 return true;
1879
1880 case 2:
1881 fputs ("\tWYDE\t", asm_out_file);
1882 mmix_print_operand (asm_out_file, x, 'W');
1883 fputc ('\n', asm_out_file);
1884 return true;
1885
1886 case 4:
1887 fputs ("\tTETRA\t", asm_out_file);
1888 mmix_print_operand (asm_out_file, x, 'L');
1889 fputc ('\n', asm_out_file);
1890 return true;
1891
1892 case 8:
1893 if (GET_CODE (x) == CONST_DOUBLE)
1894 mmix_output_octa (asm_out_file, mmix_intval (x), 0);
1895 else
1896 assemble_integer_with_op ("\tOCTA\t", x);
1897 return true;
1898 }
1899 return default_assemble_integer (x, size, aligned_p);
68cbb7e3 1900}
1901
1902/* ASM_OUTPUT_ASCII. */
1903
1904void
1905mmix_asm_output_ascii (stream, string, length)
1906 FILE *stream;
1907 const char *string;
1908 int length;
1909{
1910 while (length > 0)
1911 {
1912 int chunk_size = length > 60 ? 60 : length;
1913 fprintf (stream, "\tBYTE ");
1914 mmix_output_quoted_string (stream, string, chunk_size);
1915 string += chunk_size;
1916 length -= chunk_size;
1917 fprintf (stream, "\n");
1918 }
1919}
1920
1921/* ASM_OUTPUT_ALIGNED_COMMON. */
1922
1923void
1924mmix_asm_output_aligned_common (stream, name, size, align)
1925 FILE *stream;
1926 const char *name;
1927 int size;
1928 int align;
1929{
1930 /* This is mostly the elfos.h one. There doesn't seem to be a way to
1931 express this in a mmixal-compatible way. */
1932 fprintf (stream, "\t.comm\t");
1933 assemble_name (stream, name);
1934 fprintf (stream, ",%u,%u ! mmixal-incompatible COMMON\n",
1935 size, align / BITS_PER_UNIT);
1936}
1937
1938/* ASM_OUTPUT_ALIGNED_LOCAL. */
1939
1940void
1941mmix_asm_output_aligned_local (stream, name, size, align)
1942 FILE * stream;
1943 const char * name;
1944 int size;
1945 int align;
1946{
1947 data_section ();
1948
1949 ASM_OUTPUT_ALIGN (stream, exact_log2 (align/BITS_PER_UNIT));
1950 assemble_name (stream, name);
1951 fprintf (stream, "\tLOC @+%d\n", size);
1952}
1953
1954/* ASM_OUTPUT_LABEL. */
1955
1956void
1957mmix_asm_output_label (stream, name)
1958 FILE *stream;
1959 const char * name;
1960{
1961 assemble_name (stream, name);
1962 fprintf (stream, "\tIS @\n");
1963}
1964
1965/* ASM_DECLARE_REGISTER_GLOBAL. */
1966
1967void
1968mmix_asm_declare_register_global (stream, decl, regno, name)
1969 FILE *stream ATTRIBUTE_UNUSED;
1970 tree decl ATTRIBUTE_UNUSED;
1971 int regno ATTRIBUTE_UNUSED;
1972 const char *name ATTRIBUTE_UNUSED;
1973{
1974 /* Nothing to do here, but there *will* be, therefore the framework is
1975 here. */
1976}
1977
1978/* ASM_GLOBALIZE_LABEL. */
1979
1980void
1981mmix_asm_globalize_label (stream, name)
1982 FILE * stream ATTRIBUTE_UNUSED;
1983 const char * name ATTRIBUTE_UNUSED;
1984{
1985 asm_fprintf (stream, "\t.global ");
1986 assemble_name (stream, name);
1987 putc ('\n', stream);
1988}
1989
1990/* ASM_WEAKEN_LABEL. */
1991
1992void
1993mmix_asm_weaken_label (stream, name)
1994 FILE * stream ATTRIBUTE_UNUSED;
1995 const char * name ATTRIBUTE_UNUSED;
1996{
1997 asm_fprintf (stream, "\t.weak ");
1998 assemble_name (stream, name);
1999 asm_fprintf (stream, " ! mmixal-incompatible\n");
2000}
2001
2002/* MAKE_DECL_ONE_ONLY. */
2003
2004void
2005mmix_make_decl_one_only (decl)
2006 tree decl;
2007{
2008 DECL_WEAK (decl) = 1;
2009}
2010
2011/* ASM_OUTPUT_LABELREF.
2012 Strip GCC's '*' and our own '@'. No order is assumed. */
2013
2014void
2015mmix_asm_output_labelref (stream, name)
2016 FILE *stream;
2017 const char *name;
2018{
91009d64 2019 int is_extern = 1;
68cbb7e3 2020
2021 for (; (*name == '@' || *name == '*'); name++)
2022 if (*name == '@')
91009d64 2023 is_extern = 0;
68cbb7e3 2024
2025 asm_fprintf (stream, "%s%U%s",
2026 is_extern && TARGET_TOPLEVEL_SYMBOLS ? ":" : "",
2027 name);
2028}
2029
2030/* ASM_OUTPUT_INTERNAL_LABEL. */
2031
2032void
2033mmix_asm_output_internal_label (stream, name, num)
2034 FILE * stream;
2035 const char * name;
2036 int num;
2037{
2038 fprintf (stream, "%s:%d\tIS @\n", name, num);
2039}
2040
2041/* ASM_OUTPUT_DEF. */
2042
2043void
2044mmix_asm_output_def (stream, name, value)
2045 FILE * stream;
2046 const char * name;
2047 const char * value;
2048{
2049 assemble_name (stream, name);
2050 fprintf (stream, "\tIS ");
2051 assemble_name (stream, value);
2052 fputc ('\n', stream);
2053}
2054
2055/* ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL. */
2056
2057void
2058mmix_asm_output_define_label_difference_symbol (stream, symbol, hi, lo)
2059 FILE *stream;
2060 const char *symbol;
2061 const char *hi;
2062 const char *lo;
2063{
2064 assemble_name (stream, symbol);
2065 fprintf (stream, "\tIS\t");
2066 assemble_name (stream, hi);
2067 fputc ('-', stream);
2068 assemble_name (stream, lo);
2069 fprintf (stream, "\n");
2070}
2071
2072/* PRINT_OPERAND. */
2073
2074void
2075mmix_print_operand (stream, x, code)
2076 FILE * stream;
2077 rtx x;
2078 int code;
2079{
2080 /* When we add support for different codes later, we can, when needed,
2081 drop through to the main handler with a modified operand. */
2082 rtx modified_x = x;
2083
2084 switch (code)
2085 {
2086 /* Unrelated codes are in alphabetic order. */
2087
91009d64 2088 case '+':
2089 /* For conditional branches, output "P" for a probable branch. */
2090 if (TARGET_BRANCH_PREDICT)
2091 {
2092 x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
2093 if (x && INTVAL (XEXP (x, 0)) > REG_BR_PROB_BASE / 2)
2094 putc ('P', stream);
2095 }
2096 return;
2097
68cbb7e3 2098 case 'B':
2099 if (GET_CODE (x) != CONST_INT)
2100 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2101 fprintf (stream, "%d", (int) (INTVAL (x) & 0xff));
2102 return;
2103
2104 case 'H':
2105 /* Highpart. Must be general register, and not the last one, as
2106 that one cannot be part of a consecutive register pair. */
2107 if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1)
2108 internal_error ("MMIX Internal: Bad register: %d", REGNO (x));
2109
2110 /* This is big-endian, so the high-part is the first one. */
2111 fprintf (stream, "%s", reg_names[REGNO (x)]);
2112 return;
2113
2114 case 'L':
2115 /* Lowpart. Must be CONST_INT or general register, and not the last
2116 one, as that one cannot be part of a consecutive register pair. */
2117 if (GET_CODE (x) == CONST_INT)
2118 {
2119 fprintf (stream, "#%lx",
2120 (unsigned long) (INTVAL (x)
2121 & ((unsigned int) 0x7fffffff * 2 + 1)));
2122 return;
2123 }
2124
2125 if (GET_CODE (x) == SYMBOL_REF)
2126 {
2127 output_addr_const (stream, x);
2128 return;
2129 }
2130
2131 if (REGNO (x) > MMIX_LAST_GENERAL_REGISTER - 1)
2132 internal_error ("MMIX Internal: Bad register: %d", REGNO (x));
2133
2134 /* This is big-endian, so the low-part is + 1. */
2135 fprintf (stream, "%s", reg_names[REGNO (x) + 1]);
2136 return;
2137
2138 /* Can't use 'a' because that's a generic modifier for address
2139 output. */
2140 case 'A':
2141 mmix_output_shiftvalue_op_from_str (stream, "ANDN",
2142 ~(unsigned HOST_WIDEST_INT)
2143 mmix_intval (x));
2144 return;
2145
2146 case 'i':
2147 mmix_output_shiftvalue_op_from_str (stream, "INC",
2148 (unsigned HOST_WIDEST_INT)
2149 mmix_intval (x));
2150 return;
2151
2152 case 'o':
2153 mmix_output_shiftvalue_op_from_str (stream, "OR",
2154 (unsigned HOST_WIDEST_INT)
2155 mmix_intval (x));
2156 return;
2157
2158 case 's':
2159 mmix_output_shiftvalue_op_from_str (stream, "SET",
2160 (unsigned HOST_WIDEST_INT)
2161 mmix_intval (x));
2162 return;
2163
2164 case 'd':
2165 case 'D':
2166 mmix_output_condition (stream, x, (code == 'D'));
2167 return;
2168
2169 case 'e':
2170 /* Output an extra "e" to make fcmpe, fune. */
2171 if (TARGET_FCMP_EPSILON)
2172 fprintf (stream, "e");
2173 return;
2174
2175 case 'm':
2176 /* Output the number minus 1. */
2177 if (GET_CODE (x) != CONST_INT)
2178 {
2179 fatal_insn ("MMIX Internal: Bad value for 'm', not a CONST_INT",
2180 x);
2181 }
2182 fprintf (stream, HOST_WIDEST_INT_PRINT_DEC,
2183 (HOST_WIDEST_INT) (mmix_intval (x) - 1));
2184 return;
2185
2186 case 'p':
2187 /* Store the number of registers we want to save. This was setup
2188 by the prologue. The actual operand contains the number of
2189 registers to pass, but we don't use it currently. Anyway, we
2190 need to output the number of saved registers here. */
2191 if (TARGET_ABI_GNU)
2192 fprintf (stream, "%d", mmix_highest_saved_stack_register + 1);
2193 else
2194 /* FIXME: Get the effect of renaming $16, $17.. to the first
2195 unused call-saved reg. */
2196 fprintf (stream, "15");
2197 return;
2198
2199 case 'r':
2200 /* Store the register to output a constant to. */
2201 if (! REG_P (x))
68435912 2202 fatal_insn ("MMIX Internal: Expected a register, not this", x);
68cbb7e3 2203 mmix_output_destination_register = REGNO (x);
2204 return;
2205
2206 case 'I':
2207 /* Output the constant. Note that we use this for floats as well. */
2208 if (GET_CODE (x) != CONST_INT
2209 && (GET_CODE (x) != CONST_DOUBLE
2210 || (GET_MODE (x) != VOIDmode && GET_MODE (x) != DFmode
2211 && GET_MODE (x) != SFmode)))
68435912 2212 fatal_insn ("MMIX Internal: Expected a constant, not this", x);
68cbb7e3 2213 mmix_output_register_setting (stream,
2214 mmix_output_destination_register,
2215 mmix_intval (x), 0);
2216 return;
2217
2218 case 'U':
2219 /* An U for unsigned, if TARGET_ZERO_EXTEND. Ignore the operand. */
2220 if (TARGET_ZERO_EXTEND)
2221 putc ('U', stream);
2222 return;
2223
2224 case 'v':
2225 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) mmix_intval (x));
2226 return;
2227
2228 case 'V':
2229 mmix_output_shifted_value (stream, (HOST_WIDEST_INT) ~mmix_intval (x));
2230 return;
2231
2232 case 'W':
2233 if (GET_CODE (x) != CONST_INT)
2234 fatal_insn ("MMIX Internal: Expected a CONST_INT, not this", x);
2235 fprintf (stream, "#%x", (int) (INTVAL (x) & 0xffff));
2236 return;
2237
2238 case 0:
2239 /* Nothing to do. */
2240 break;
2241
2242 default:
2243 /* Presumably there's a missing case above if we get here. */
2244 internal_error ("MMIX Internal: Missing `%c' case in mmix_print_operand", code);
2245 }
2246
2247 switch (GET_CODE (modified_x))
2248 {
2249 case REG:
2250 if (REGNO (modified_x) >= FIRST_PSEUDO_REGISTER)
2251 internal_error ("MMIX Internal: Bad register: %d", REGNO (modified_x));
2252 fprintf (stream, "%s", reg_names[REGNO (modified_x)]);
2253 return;
2254
2255 case MEM:
2256 output_address (XEXP (modified_x, 0));
2257 return;
2258
2259 case CONST_INT:
2260 /* For -2147483648, mmixal complains that the constant does not fit
2261 in 4 bytes, so let's output it as hex. Take care to handle hosts
2262 where HOST_WIDE_INT is longer than an int.
2263
2264 Print small constants +-255 using decimal. */
2265
2266 if (INTVAL (modified_x) > -256 && INTVAL (modified_x) < 256)
2267 fprintf (stream, "%d", (int) (INTVAL (modified_x)));
2268 else
2269 fprintf (stream, "#%x",
2270 (int) (INTVAL (modified_x)) & (unsigned int) ~0);
2271 return;
2272
2273 case CONST_DOUBLE:
2274 /* Do somewhat as CONST_INT. */
58356836 2275 mmix_output_octa (stream, mmix_intval (modified_x), 0);
68cbb7e3 2276 return;
2277
2278 case CONST:
2279 output_addr_const (stream, modified_x);
2280 return;
2281
2282 default:
2283 /* No need to test for all strange things. Let output_addr_const do
2284 it for us. */
2285 if (CONSTANT_P (modified_x)
2286 /* Strangely enough, this is not included in CONSTANT_P.
2287 FIXME: Ask/check about sanity here. */
2288 || GET_CODE (modified_x) == CODE_LABEL)
2289 {
2290 output_addr_const (stream, modified_x);
2291 return;
2292 }
2293
2294 /* We need the original here. */
2295 fatal_insn ("MMIX Internal: Cannot decode this operand", x);
2296 }
2297}
2298
2299/* PRINT_OPERAND_PUNCT_VALID_P. */
2300
2301int
2302mmix_print_operand_punct_valid_p (code)
2303 int code ATTRIBUTE_UNUSED;
2304{
91009d64 2305 /* A '+' is used for branch prediction, similar to other ports. */
2306 return code == '+';
68cbb7e3 2307}
2308
2309/* PRINT_OPERAND_ADDRESS. */
2310
2311void
2312mmix_print_operand_address (stream, x)
2313 FILE *stream;
2314 rtx x;
2315{
2316 if (REG_P (x))
2317 {
2318 /* I find the generated assembly code harder to read without
2319 the ",0". */
2320 fprintf (stream, "%s,0",reg_names[REGNO (x)]);
2321 return;
2322 }
2323 else if (GET_CODE (x) == PLUS)
2324 {
2325 rtx x1 = XEXP (x, 0);
2326 rtx x2 = XEXP (x, 1);
2327
2328 /* Try swap the order. FIXME: Do we need this? */
2329 if (! REG_P (x1))
2330 {
2331 rtx tem = x1;
2332 x1 = x2;
2333 x2 = tem;
2334 }
2335
2336 if (REG_P (x1))
2337 {
2338 fprintf (stream, "%s,", reg_names[REGNO (x1)]);
2339
2340 if (REG_P (x2))
2341 {
2342 fprintf (stream, "%s", reg_names[REGNO (x2)]);
2343 return;
2344 }
2345 else if (GET_CODE (x2) == CONST_INT
2346 && CONST_OK_FOR_LETTER_P (INTVAL (x2), 'I'))
2347 {
2348 output_addr_const (stream, x2);
2349 return;
2350 }
2351 }
2352 }
2353
2354 fatal_insn ("MMIX Internal: This is not a recognized address", x);
2355}
2356
2357/* ASM_OUTPUT_REG_PUSH. */
2358
2359void
2360mmix_asm_output_reg_push (stream, regno)
2361 FILE * stream;
2362 int regno;
2363{
2364 fprintf (stream, "\tSUBU %s,%s,8\n\tSTOU %s,%s,0\n",
2365 reg_names[MMIX_STACK_POINTER_REGNUM],
2366 reg_names[MMIX_STACK_POINTER_REGNUM],
2367 reg_names[regno],
2368 reg_names[MMIX_STACK_POINTER_REGNUM]);
2369}
2370
2371/* ASM_OUTPUT_REG_POP. */
2372
2373void
2374mmix_asm_output_reg_pop (stream, regno)
2375 FILE * stream;
2376 int regno;
2377{
2378 fprintf (stream, "\tLDOU %s,%s,0\n\tINCL %s,8\n",
2379 reg_names[regno],
2380 reg_names[MMIX_STACK_POINTER_REGNUM],
2381 reg_names[MMIX_STACK_POINTER_REGNUM]);
2382}
2383
2384/* ASM_OUTPUT_ADDR_DIFF_ELT. */
2385
2386void
2387mmix_asm_output_addr_diff_elt (stream, body, value, rel)
2388 FILE *stream;
2389 rtx body ATTRIBUTE_UNUSED;
2390 int value;
2391 int rel;
2392{
2393 fprintf (stream, "\tTETRA L%d-L%d\n", value, rel);
2394}
2395
2396/* ASM_OUTPUT_ADDR_VEC_ELT. */
2397
2398void
2399mmix_asm_output_addr_vec_elt (stream, value)
2400 FILE *stream;
2401 int value;
2402{
2403 fprintf (stream, "\tOCTA L:%d\n", value);
2404}
2405
2406/* ASM_OUTPUT_SKIP. */
2407
2408void
2409mmix_asm_output_skip (stream, nbytes)
2410 FILE *stream;
2411 int nbytes;
2412{
2413 fprintf (stream, "\tLOC @+%d\n", nbytes);
2414}
2415
2416/* ASM_OUTPUT_ALIGN. */
2417
2418void
2419mmix_asm_output_align (stream, power)
2420 FILE *stream;
2421 int power;
2422{
2423 /* We need to record the needed alignment of this section in the object,
2424 so we have to output an alignment directive. Use a .p2align (not
2425 .align) so people will never have to wonder about whether the
2426 argument is in number of bytes or the log2 thereof. We do it in
2427 addition to the LOC directive, so nothing needs tweaking when
2428 copy-pasting assembly into mmixal. */
2429 fprintf (stream, "\t.p2align %d\n", power);
2430 fprintf (stream, "\tLOC @+(%d-@)&%d\n", 1 << power, (1 << power) - 1);
2431}
2432
2433/* DBX_REGISTER_NUMBER. */
2434
2435int
2436mmix_dbx_register_number (regno)
2437 int regno;
2438{
2439 /* FIXME: Implement final register renumbering if necessary. (Use
2440 target state in cfun). */
2441
2442 /* We need to renumber registers to get the number of the return address
2443 register in the range 0..255. It is also space-saving if registers
2444 mentioned in the call-frame information (which uses this function by
2445 defaulting DWARF_FRAME_REGNUM to DBX_REGISTER_NUMBER) are numbered
2446 0 .. 63. So map 224 .. 256+15 -> 0 .. 47 and 0 .. 223 -> 48..223+48. */
2447 return regno >= 224 ? (regno - 224) : (regno + 48);
2448}
2449
35a3065a 2450/* End of target macro support functions.
68cbb7e3 2451
2452 Now MMIX's own functions. First the exported ones. */
2453
2454/* Output an optimal sequence for setting a register to a specific
2455 constant. Used in an alternative for const_ints in movdi, and when
2456 using large stack-frame offsets.
2457
2458 Use do_begin_end to say if a line-starting TAB and newline before the
2459 first insn and after the last insn is wanted. */
2460
2461void
2462mmix_output_register_setting (stream, regno, value, do_begin_end)
2463 FILE *stream;
2464 int regno;
2465 HOST_WIDEST_INT value;
2466 int do_begin_end;
2467{
2468 if (do_begin_end)
2469 fprintf (stream, "\t");
2470
2471 if (mmix_shiftable_wyde_value ((unsigned HOST_WIDEST_INT) value))
2472 {
2473 /* First, the one-insn cases. */
2474 mmix_output_shiftvalue_op_from_str (stream, "SET",
2475 (unsigned HOST_WIDEST_INT)
2476 value);
2477 fprintf (stream, " %s,", reg_names[regno]);
2478 mmix_output_shifted_value (stream, (unsigned HOST_WIDEST_INT) value);
2479 }
2480 else if (mmix_shiftable_wyde_value (-(unsigned HOST_WIDEST_INT) value))
2481 {
2482 /* We do this to get a bit more legible assembly code. The next
2483 alternative is mostly redundant with this. */
2484
2485 mmix_output_shiftvalue_op_from_str (stream, "SET",
2486 -(unsigned HOST_WIDEST_INT)
2487 value);
2488 fprintf (stream, " %s,", reg_names[regno]);
2489 mmix_output_shifted_value (stream, -(unsigned HOST_WIDEST_INT) value);
2490 fprintf (stream, "\n\tNEGU %s,0,%s", reg_names[regno],
2491 reg_names[regno]);
2492 }
2493 else if (mmix_shiftable_wyde_value (~(unsigned HOST_WIDEST_INT) value))
2494 {
2495 /* Slightly more expensive, the two-insn cases. */
2496
2497 /* FIXME: We could of course also test if 0..255-N or ~(N | 1..255)
2498 is shiftable, or any other one-insn transformation of the value.
2499 FIXME: Check first if the value is "shiftable" by two loading
2500 with two insns, since it makes more readable assembly code (if
2501 anyone else cares). */
2502
2503 mmix_output_shiftvalue_op_from_str (stream, "SET",
2504 ~(unsigned HOST_WIDEST_INT)
2505 value);
2506 fprintf (stream, " %s,", reg_names[regno]);
2507 mmix_output_shifted_value (stream, ~(unsigned HOST_WIDEST_INT) value);
2508 fprintf (stream, "\n\tNOR %s,%s,0", reg_names[regno],
2509 reg_names[regno]);
2510 }
2511 else
2512 {
2513 /* The generic case. 2..4 insns. */
25037517 2514 static const char *const higher_parts[] = {"L", "ML", "MH", "H"};
68cbb7e3 2515 const char *op = "SET";
2516 const char *line_begin = "";
2517 int i;
2518
2519 /* Output pertinent parts of the 4-wyde sequence.
2520 Still more to do if we want this to be optimal, but hey...
2521 Note that the zero case has been handled above. */
2522 for (i = 0; i < 4 && value != 0; i++)
2523 {
2524 if (value & 65535)
2525 {
2526 fprintf (stream, "%s%s%s %s,#%x", line_begin, op,
2527 higher_parts[i], reg_names[regno],
2528 (int) (value & 65535));
2529 /* The first one sets the rest of the bits to 0, the next
2530 ones add set bits. */
2531 op = "INC";
2532 line_begin = "\n\t";
2533 }
2534
2535 value >>= 16;
2536 }
2537 }
2538
2539 if (do_begin_end)
2540 fprintf (stream, "\n");
2541}
2542
2543/* Return 1 if value is 0..65535*2**(16*N) for N=0..3.
2544 else return 0. */
2545
2546int
2547mmix_shiftable_wyde_value (value)
2548 unsigned HOST_WIDEST_INT value;
2549{
2550 /* Shift by 16 bits per group, stop when we've found two groups with
2551 nonzero bits. */
2552 int i;
2553 int has_candidate = 0;
2554
2555 for (i = 0; i < 4; i++)
2556 {
2557 if (value & 65535)
2558 {
2559 if (has_candidate)
2560 return 0;
2561 else
2562 has_candidate = 1;
2563 }
2564
2565 value >>= 16;
2566 }
2567
2568 return 1;
2569}
2570
2571/* True if this is an address_operand or a symbolic operand. */
2572
2573int
2574mmix_symbolic_or_address_operand (op, mode)
2575 rtx op;
2576 enum machine_mode mode;
2577{
2578 switch (GET_CODE (op))
2579 {
2580 case SYMBOL_REF:
2581 case LABEL_REF:
2582 return 1;
2583 case CONST:
2584 op = XEXP (op, 0);
2585 if ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
2586 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
2587 && (GET_CODE (XEXP (op, 1)) == CONST_INT
2588 || (GET_CODE (XEXP (op, 1)) == CONST_DOUBLE
2589 && GET_MODE (XEXP (op, 1)) == VOIDmode)))
2590 return 1;
2591 /* FALLTHROUGH */
2592 default:
2593 return address_operand (op, mode);
2594 }
2595}
2596
2597/* True if this is a register or CONST_INT (or CONST_DOUBLE for DImode).
2598 We could narrow the value down with a couple of predicated, but that
2599 doesn't seem to be worth it at the moment. */
2600
2601int
2602mmix_reg_or_constant_operand (op, mode)
2603 rtx op;
2604 enum machine_mode mode;
2605{
2606 return register_operand (op, mode)
2607 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
2608 || GET_CODE (op) == CONST_INT;
2609}
2610
2611/* True if this is a register with a condition-code mode. */
2612
2613int
2614mmix_reg_cc_operand (op, mode)
2615 rtx op;
2616 enum machine_mode mode;
2617{
2618 if (mode == VOIDmode)
2619 mode = GET_MODE (op);
2620
2621 return register_operand (op, mode)
2622 && (mode == CCmode || mode == CC_UNSmode || mode == CC_FPmode
2623 || mode == CC_FPEQmode || mode == CC_FUNmode);
2624}
2625
2626/* True if this is a foldable comparison operator
2627 - one where a the result of (compare:CC (reg) (const_int 0)) can be
2628 replaced by (reg). */
2629
2630int
2631mmix_foldable_comparison_operator (op, mode)
2632 rtx op;
2633 enum machine_mode mode;
2634{
2635 RTX_CODE code = GET_CODE (op);
2636
2637 if (mode == VOIDmode)
2638 mode = GET_MODE (op);
2639
2640 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2641 mode = GET_MODE (XEXP (op, 0));
2642
2643 return ((mode == CCmode || mode == DImode)
2644 && (code == NE || code == EQ || code == GE || code == GT
2645 || code == LE))
2646 /* FIXME: This may be a stupid trick. What happens when GCC wants to
2647 reverse the condition? Can it do that by itself? Maybe it can
2648 even reverse the condition to fit a foldable one in the first
2649 place? */
2650 || (mode == CC_UNSmode && (code == GTU || code == LEU));
2651}
2652
2653/* Like comparison_operator, but only true if this comparison operator is
2654 applied to a valid mode. Needed to avoid jump.c generating invalid
2655 code with -ffast-math (gcc.dg/20001228-1.c). */
2656
2657int
2658mmix_comparison_operator (op, mode)
2659 rtx op;
2660 enum machine_mode mode;
2661{
2662 RTX_CODE code = GET_CODE (op);
2663
2664 /* Comparison operators usually don't have a mode, but let's try and get
2665 one anyway for the day that changes. */
2666 if (mode == VOIDmode)
2667 mode = GET_MODE (op);
2668
2669 /* Get the mode from the first operand if we don't have one. */
2670 if (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2671 mode = GET_MODE (XEXP (op, 0));
2672
2673 /* FIXME: This needs to be kept in sync with the tables in
2674 mmix_output_condition. */
2675 return
2676 (mode == VOIDmode && GET_RTX_CLASS (GET_CODE (op)) == '<')
2677 || (mode == CC_FUNmode
2678 && (code == ORDERED || code == UNORDERED))
2679 || (mode == CC_FPmode
2680 && (code == GT || code == LT))
2681 || (mode == CC_FPEQmode
2682 && (code == NE || code == EQ))
2683 || (mode == CC_UNSmode
2684 && (code == GEU || code == GTU || code == LEU || code == LTU))
2685 || (mode == CCmode
2686 && (code == NE || code == EQ || code == GE || code == GT
2687 || code == LE || code == LT))
2688 || (mode == DImode
2689 && (code == NE || code == EQ || code == GE || code == GT
2690 || code == LE || code == LT || code == LEU || code == GTU));
2691}
2692
2693/* True if this is a register or 0 (int or float). */
2694
2695int
2696mmix_reg_or_0_operand (op, mode)
2697 rtx op;
2698 enum machine_mode mode;
2699{
2700 /* FIXME: Is mode calculation necessary and correct? */
2701 return
2702 op == CONST0_RTX (mode == VOIDmode ? GET_MODE (op) : mode)
2703 || register_operand (op, mode);
2704}
2705
2706/* True if this is a register or an int 0..255. */
2707
2708int
2709mmix_reg_or_8bit_operand (op, mode)
2710 rtx op;
2711 enum machine_mode mode;
2712{
2713 return register_operand (op, mode)
2714 || (GET_CODE (op) == CONST_INT
2715 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
2716}
2717
2718/* True if this is a register or an int 0..256. We include 256,
2719 because it can be canonicalized into 255 for comparisons, which is
2720 currently the only use of this predicate.
2721 FIXME: Check that this happens and does TRT. */
2722
2723int
2724mmix_reg_or_8bit_or_256_operand (op, mode)
2725 rtx op;
2726 enum machine_mode mode;
2727{
2728 return mmix_reg_or_8bit_operand (op, mode)
2729 || (GET_CODE (op) == CONST_INT && INTVAL (op) == 256);
2730}
2731
2732/* Returns zero if code and mode is not a valid condition from a
2733 compare-type insn. Nonzero if it is. The parameter op, if non-NULL,
2734 is the comparison of mode is CC-somethingmode. */
2735
2736int
2737mmix_valid_comparison (code, mode, op)
2738 RTX_CODE code;
2739 enum machine_mode mode;
2740 rtx op;
2741{
2742 if (mode == VOIDmode && op != NULL_RTX)
2743 mode = GET_MODE (op);
2744
2745 /* We don't care to look at these, they should always be valid. */
2746 if (mode == CCmode || mode == CC_UNSmode || mode == DImode)
2747 return 1;
2748
2749 if ((mode == CC_FPmode || mode == DFmode)
2750 && (code == GT || code == LT))
2751 return 1;
2752
2753 if ((mode == CC_FPEQmode || mode == DFmode)
2754 && (code == EQ || code == NE))
2755 return 1;
2756
2757 if ((mode == CC_FUNmode || mode == DFmode)
2758 && (code == ORDERED || code == UNORDERED))
2759 return 1;
2760
2761 return 0;
2762}
2763
2764/* X and Y are two things to compare using CODE. Emit a compare insn if
2765 possible and return the rtx for the cc-reg in the proper mode, or
2766 NULL_RTX if this is not a valid comparison. */
2767
2768rtx
2769mmix_gen_compare_reg (code, x, y)
2770 RTX_CODE code;
2771 rtx x, y;
2772{
2773 enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
2774 rtx cc_reg;
2775
2776 /* FIXME: Do we get constants here? Of double mode? */
2777 enum machine_mode mode
2778 = GET_MODE (x) == VOIDmode
2779 ? GET_MODE (y)
2780 : GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT ? DFmode : DImode;
2781
2782 if (! mmix_valid_comparison (code, mode, x))
2783 return NULL_RTX;
2784
2785 cc_reg = gen_reg_rtx (ccmode);
2786
2787 /* FIXME: Can we avoid emitting a compare insn here? */
2788 if (! REG_P (x) && ! REG_P (y))
2789 x = force_reg (mode, x);
2790
2791 CANONICALIZE_COMPARISON (code, x, y);
2792
2793 /* If it's not quite right yet, put y in a register. */
2794 if (! REG_P (y)
2795 && (GET_CODE (y) != CONST_INT
2796 || ! CONST_OK_FOR_LETTER_P (INTVAL (y), 'I')))
2797 y = force_reg (mode, y);
2798
2799 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
2800 gen_rtx_COMPARE (ccmode, x, y)));
2801
2802 return cc_reg;
2803}
2804
2805/* Local (static) helper functions. */
2806
2807/* Print operator suitable for doing something with a shiftable
ebb11c7b 2808 wyde. The type of operator is passed as an asm output modifier. */
68cbb7e3 2809
2810static void
2811mmix_output_shiftvalue_op_from_str (stream, mainop, value)
2812 FILE *stream;
2813 const char *mainop;
2814 HOST_WIDEST_INT value;
2815{
25037517 2816 static const char *const op_part[] = {"L", "ML", "MH", "H"};
68cbb7e3 2817 int i;
2818
2819 if (! mmix_shiftable_wyde_value (value))
2820 {
2821 char s[sizeof ("0xffffffffffffffff")];
2822 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2823 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2824 }
2825
2826 for (i = 0; i < 4; i++)
2827 {
2828 /* We know we're through when we find one-bits in the low
2829 16 bits. */
2830 if (value & 0xffff)
2831 {
2832 fprintf (stream, "%s%s", mainop, op_part[i]);
2833 return;
2834 }
2835 value >>= 16;
2836 }
2837
2838 /* No bits set? Then it must have been zero. */
2839 fprintf (stream, "%sL", mainop);
2840}
2841
2842/* Print a 64-bit value, optionally prefixed by assembly pseudo. */
2843
2844static void
2845mmix_output_octa (stream, value, do_begin_end)
2846 FILE *stream;
2847 HOST_WIDEST_INT value;
2848 int do_begin_end;
2849{
2850 /* Snipped from final.c:output_addr_const. We need to avoid the
2851 presumed universal "0x" prefix. We can do it by replacing "0x" with
2852 "#0" here; we must avoid a space in the operands and no, the zero
2853 won't cause the number to be assumed in octal format. */
2854 char hex_format[sizeof (HOST_WIDEST_INT_PRINT_HEX)];
2855
2856 if (do_begin_end)
2857 fprintf (stream, "\tOCTA ");
2858
2859 strcpy (hex_format, HOST_WIDEST_INT_PRINT_HEX);
2860 hex_format[0] = '#';
2861 hex_format[1] = '0';
2862
2863 /* Provide a few alternative output formats depending on the number, to
2864 improve legibility of assembler output. */
2865 if ((value < (HOST_WIDEST_INT) 0 && value > (HOST_WIDEST_INT) -10000)
2866 || (value >= (HOST_WIDEST_INT) 0 && value <= (HOST_WIDEST_INT) 16384))
2867 fprintf (stream, "%d", (int) value);
2868 else if (value > (HOST_WIDEST_INT) 0
2869 && value < ((HOST_WIDEST_INT) 1 << 31) * 2)
2870 fprintf (stream, "#%x", (unsigned int) value);
2871 else
2872 fprintf (stream, hex_format, value);
2873
2874 if (do_begin_end)
2875 fprintf (stream, "\n");
2876}
2877
2878/* Print the presumed shiftable wyde argument shifted into place (to
2879 be output with an operand). */
2880
2881static void
2882mmix_output_shifted_value (stream, value)
2883 FILE * stream;
2884 HOST_WIDEST_INT value;
2885{
2886 int i;
2887
2888 if (! mmix_shiftable_wyde_value (value))
2889 {
2890 char s[16+2+1];
2891 sprintf (s, HOST_WIDEST_INT_PRINT_HEX, value);
2892 internal_error ("MMIX Internal: %s is not a shiftable int", s);
2893 }
2894
2895 for (i = 0; i < 4; i++)
2896 {
2897 /* We know we're through when we find one-bits in the low 16 bits. */
2898 if (value & 0xffff)
2899 {
2900 fprintf (stream, "#%x", (int) (value & 0xffff));
2901 return;
2902 }
2903
2904 value >>= 16;
2905 }
2906
2907 /* No bits set? Then it must have been zero. */
2908 fprintf (stream, "0");
2909}
2910
2911/* Output an MMIX condition name corresponding to an operator
2912 and operands:
2913 (comparison_operator [(comparison_operator ...) (const_int 0)])
2914 which means we have to look at *two* operators.
2915
2916 The argument "reversed" refers to reversal of the condition (not the
2917 same as swapping the arguments). */
2918
2919static void
2920mmix_output_condition (stream, x, reversed)
2921 FILE *stream;
2922 rtx x;
2923 int reversed;
2924{
2925 struct cc_conv
2926 {
2927 RTX_CODE cc;
2928
2929 /* The normal output cc-code. */
2930 const char *const normal;
2931
2932 /* The reversed cc-code, or NULL if invalid. */
2933 const char *const reversed;
2934 };
2935
2936 struct cc_type_conv
2937 {
2938 enum machine_mode cc_mode;
2939
2940 /* Terminated with {NIL, NULL, NULL} */
2941 const struct cc_conv *const convs;
2942 };
2943
2944#undef CCEND
2945#define CCEND {NIL, NULL, NULL}
2946
2947 static const struct cc_conv cc_fun_convs[]
2948 = {{ORDERED, "Z", "P"},
2949 {UNORDERED, "P", "Z"},
2950 CCEND};
2951 static const struct cc_conv cc_fp_convs[]
2952 = {{GT, "P", NULL},
2953 {LT, "N", NULL},
2954 CCEND};
2955 static const struct cc_conv cc_fpeq_convs[]
2956 = {{NE, "Z", "P"},
2957 {EQ, "P", "Z"},
2958 CCEND};
2959 static const struct cc_conv cc_uns_convs[]
2960 = {{GEU, "NN", "N"},
2961 {GTU, "P", "NP"},
2962 {LEU, "NP", "P"},
2963 {LTU, "N", "NN"},
2964 CCEND};
2965 static const struct cc_conv cc_signed_convs[]
2966 = {{NE, "NZ", "Z"},
2967 {EQ, "Z", "NZ"},
2968 {GE, "NN", "N"},
2969 {GT, "P", "NP"},
2970 {LE, "NP", "P"},
2971 {LT, "N", "NN"},
2972 CCEND};
2973 static const struct cc_conv cc_di_convs[]
2974 = {{NE, "NZ", "Z"},
2975 {EQ, "Z", "NZ"},
2976 {GE, "NN", "N"},
2977 {GT, "P", "NP"},
2978 {LE, "NP", "P"},
2979 {LT, "N", "NN"},
2980 {GTU, "NZ", "Z"},
2981 {LEU, "Z", "NZ"},
2982 CCEND};
2983#undef CCEND
2984
2985 static const struct cc_type_conv cc_convs[]
2986 = {{CC_FUNmode, cc_fun_convs},
2987 {CC_FPmode, cc_fp_convs},
2988 {CC_FPEQmode, cc_fpeq_convs},
2989 {CC_UNSmode, cc_uns_convs},
2990 {CCmode, cc_signed_convs},
2991 {DImode, cc_di_convs}};
2992
2993 unsigned int i;
2994 int j;
2995
2996 enum machine_mode mode = GET_MODE (XEXP (x, 0));
2997 RTX_CODE cc = GET_CODE (x);
2998
2999 for (i = 0; i < sizeof (cc_convs)/sizeof(*cc_convs); i++)
3000 {
3001 if (mode == cc_convs[i].cc_mode)
3002 {
3003 for (j = 0; cc_convs[i].convs[j].cc != NIL; j++)
3004 if (cc == cc_convs[i].convs[j].cc)
3005 {
3006 const char *mmix_cc
3007 = (reversed ? cc_convs[i].convs[j].reversed
3008 : cc_convs[i].convs[j].normal);
3009
3010 if (mmix_cc == NULL)
3011 fatal_insn ("MMIX Internal: Trying to output invalidly\
3012 reversed condition:", x);
3013
3014 fprintf (stream, "%s", mmix_cc);
3015 return;
3016 }
3017
3018 fatal_insn ("MMIX Internal: What's the CC of this?", x);
3019 }
3020 }
3021
3022 fatal_insn ("MMIX Internal: What is the CC of this?", x);
3023}
3024
3025/* Return the bit-value for a const_int or const_double. */
3026
3027static HOST_WIDEST_INT
3028mmix_intval (x)
3029 rtx x;
3030{
3031 unsigned HOST_WIDEST_INT retval;
3032
3033 if (GET_CODE (x) == CONST_INT)
3034 return INTVAL (x);
3035
3036 /* We make a little song and dance because converting to long long in
3037 gcc-2.7.2 is broken. I still want people to be able to use it for
3038 cross-compilation to MMIX. */
3039 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == VOIDmode)
3040 {
3041 if (sizeof (HOST_WIDE_INT) < sizeof (HOST_WIDEST_INT))
3042 {
3043 retval = (unsigned) CONST_DOUBLE_LOW (x) / 2;
3044 retval *= 2;
3045 retval |= CONST_DOUBLE_LOW (x) & 1;
3046
3047 retval |=
3048 (unsigned HOST_WIDEST_INT) CONST_DOUBLE_HIGH (x)
3049 << (HOST_BITS_PER_LONG);
3050 }
3051 else
3052 retval = CONST_DOUBLE_HIGH (x);
3053
3054 return retval;
3055 }
3056
3057 if (GET_CODE (x) == CONST_DOUBLE)
3058 {
3059 REAL_VALUE_TYPE value;
3060
3061 /* FIXME: This macro is not in the manual but should be. */
3062 REAL_VALUE_FROM_CONST_DOUBLE (value, x);
3063
3064 if (GET_MODE (x) == DFmode)
3065 {
3066 long bits[2];
dc8dc4ce 3067
68cbb7e3 3068 REAL_VALUE_TO_TARGET_DOUBLE (value, bits);
3069
3070 if (sizeof (long) < sizeof (HOST_WIDEST_INT))
3071 {
3072 retval = (unsigned long) bits[1] / 2;
3073 retval *= 2;
3074 retval |= (unsigned long) bits[1] & 1;
3075 retval
3076 |= (unsigned HOST_WIDEST_INT) bits[0]
3077 << (sizeof (bits[0]) * 8);
3078 }
3079 else
3080 retval = (unsigned long) bits[1];
3081
3082 return retval;
3083 }
3084 else if (GET_MODE (x) == SFmode)
3085 {
3086 long bits;
3087 REAL_VALUE_TO_TARGET_SINGLE (value, bits);
3088
3089 return (unsigned long) bits;
3090 }
3091 }
3092
3093 fatal_insn ("MMIX Internal: This is not a constant:", x);
3094}
3095
3096/*
3097 * Local variables:
3098 * eval: (c-set-style "gnu")
3099 * indent-tabs-mode: t
3100 * End:
3101 */