1 /* Subroutines used for MIPS code generation.
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by A. Lichnewsky, lich@inria.inria.fr.
5 Changes by Michael Meissner, meissner@osf.org.
6 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 Brendan Eich, brendan@microunity.com.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GCC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING. If not, write to
23 the Free Software Foundation, 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
28 #include "coretypes.h"
33 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "conditions.h"
37 #include "insn-attr.h"
53 #include "target-def.h"
54 #include "integrate.h"
55 #include "langhooks.h"
57 /* Enumeration for all of the relational tests, so that we can build
58 arrays indexed by the test type, and not worry about the order
75 /* Return true if it is likely that the given mode will be accessed
76 using only a single instruction. */
77 #define SINGLE_WORD_MODE_P(MODE) \
78 ((MODE) != BLKmode && GET_MODE_SIZE (MODE) <= UNITS_PER_WORD)
80 /* True if X is an unspec wrapper around a SYMBOL_REF or LABEL_REF. */
81 #define UNSPEC_ADDRESS_P(X) \
82 (GET_CODE (X) == UNSPEC \
83 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
84 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
86 /* Extract the symbol or label from UNSPEC wrapper X. */
87 #define UNSPEC_ADDRESS(X) \
90 /* Extract the symbol type from UNSPEC wrapper X. */
91 #define UNSPEC_ADDRESS_TYPE(X) \
92 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
94 /* True if X is (const $gp). This is used to initialize the mips16
95 gp pseudo register. */
96 #define CONST_GP_P(X) \
97 (GET_CODE (X) == CONST && XEXP (X, 0) == pic_offset_table_rtx)
99 /* The maximum distance between the top of the stack frame and the
100 value $sp has when we save & restore registers.
102 Use a maximum gap of 0x100 in the mips16 case. We can then use
103 unextended instructions to save and restore registers, and to
104 allocate and deallocate the top part of the frame.
106 The value in the !mips16 case must be a SMALL_OPERAND and must
107 preserve the maximum stack alignment. It could really be 0x7ff0,
108 but SGI's assemblers implement daddiu $sp,$sp,-0x7ff0 as a
109 multi-instruction addu sequence. Use 0x7fe0 to work around this. */
110 #define MIPS_MAX_FIRST_STACK_STEP (TARGET_MIPS16 ? 0x100 : 0x7fe0)
112 /* Classifies a SYMBOL_REF, LABEL_REF or UNSPEC address.
115 Used when none of the below apply.
118 The symbol refers to something in a small data section.
121 The symbol refers to something in the mips16 constant pool.
124 The symbol refers to local data that will be found using
125 the global offset table.
128 Likewise non-local data.
131 An UNSPEC wrapper around a SYMBOL_GOT_LOCAL. It represents the
132 offset from _gp of a GOT page entry.
135 An UNSPEC wrapper around a SYMBOL_GOT_GLOBAL. It represents the
136 the offset from _gp of the symbol's GOT entry.
139 Like SYMBOL_GOTOFF_GLOBAL, but used when calling a global function.
140 The GOT entry is allowed to point to a stub rather than to the
144 An UNSPEC wrapper around a function's address. It represents the
145 offset of _gp from the start of the function. */
146 enum mips_symbol_type
{
149 SYMBOL_CONSTANT_POOL
,
153 SYMBOL_GOTOFF_GLOBAL
,
157 #define NUM_SYMBOL_TYPES (SYMBOL_GOTOFF_LOADGP + 1)
160 /* Classifies an address.
163 A natural register + offset address. The register satisfies
164 mips_valid_base_register_p and the offset is a const_arith_operand.
167 A LO_SUM rtx. The first operand is a valid base register and
168 the second operand is a symbolic address.
171 A signed 16-bit constant address.
174 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
175 enum mips_address_type
{
182 /* A function to save or store a register. The first argument is the
183 register and the second is the stack slot. */
184 typedef void (*mips_save_restore_fn
) (rtx
, rtx
);
187 struct mips_arg_info
;
188 struct mips_address_info
;
189 struct mips_integer_op
;
191 static enum mips_symbol_type
mips_classify_symbol (rtx
);
192 static void mips_split_const (rtx
, rtx
*, HOST_WIDE_INT
*);
193 static bool mips_symbolic_constant_p (rtx
, enum mips_symbol_type
*);
194 static bool mips_valid_base_register_p (rtx
, enum machine_mode
, int);
195 static bool mips_symbolic_address_p (enum mips_symbol_type
, enum machine_mode
);
196 static bool mips_classify_address (struct mips_address_info
*, rtx
,
197 enum machine_mode
, int);
198 static int mips_symbol_insns (enum mips_symbol_type
);
199 static bool mips16_unextended_reference_p (enum machine_mode mode
, rtx
, rtx
);
200 static rtx
mips_force_temporary (rtx
, rtx
);
201 static rtx
mips_split_symbol (rtx
, rtx
);
202 static rtx
mips_unspec_address (rtx
, enum mips_symbol_type
);
203 static rtx
mips_unspec_offset_high (rtx
, rtx
, enum mips_symbol_type
);
204 static rtx
mips_load_got (rtx
, rtx
, enum mips_symbol_type
);
205 static rtx
mips_add_offset (rtx
, HOST_WIDE_INT
);
206 static unsigned int mips_build_shift (struct mips_integer_op
*, HOST_WIDE_INT
);
207 static unsigned int mips_build_lower (struct mips_integer_op
*,
208 unsigned HOST_WIDE_INT
);
209 static unsigned int mips_build_integer (struct mips_integer_op
*,
210 unsigned HOST_WIDE_INT
);
211 static void mips_move_integer (rtx
, unsigned HOST_WIDE_INT
);
212 static void mips_legitimize_const_move (enum machine_mode
, rtx
, rtx
);
213 static int m16_check_op (rtx
, int, int, int);
214 static bool mips_rtx_costs (rtx
, int, int, int *);
215 static int mips_address_cost (rtx
);
216 static enum internal_test
map_test_to_internal_test (enum rtx_code
);
217 static void get_float_compare_codes (enum rtx_code
, enum rtx_code
*,
219 static bool mips_function_ok_for_sibcall (tree
, tree
);
220 static void mips_block_move_straight (rtx
, rtx
, HOST_WIDE_INT
);
221 static void mips_adjust_block_mem (rtx
, HOST_WIDE_INT
, rtx
*, rtx
*);
222 static void mips_block_move_loop (rtx
, rtx
, HOST_WIDE_INT
);
223 static void mips_arg_info (const CUMULATIVE_ARGS
*, enum machine_mode
,
224 tree
, int, struct mips_arg_info
*);
225 static bool mips_get_unaligned_mem (rtx
*, unsigned int, int, rtx
*, rtx
*);
226 static void mips_set_architecture (const struct mips_cpu_info
*);
227 static void mips_set_tune (const struct mips_cpu_info
*);
228 static struct machine_function
*mips_init_machine_status (void);
229 static void print_operand_reloc (FILE *, rtx
, const char **);
230 static bool mips_assemble_integer (rtx
, unsigned int, int);
231 static void mips_file_start (void);
232 static void mips_file_end (void);
233 static bool mips_rewrite_small_data_p (rtx
);
234 static int small_data_pattern_1 (rtx
*, void *);
235 static int mips_rewrite_small_data_1 (rtx
*, void *);
236 static bool mips_function_has_gp_insn (void);
237 static unsigned int mips_global_pointer (void);
238 static bool mips_save_reg_p (unsigned int);
239 static void mips_save_restore_reg (enum machine_mode
, int, HOST_WIDE_INT
,
240 mips_save_restore_fn
);
241 static void mips_for_each_saved_reg (HOST_WIDE_INT
, mips_save_restore_fn
);
242 static void mips_output_function_prologue (FILE *, HOST_WIDE_INT
);
243 static void mips_set_frame_expr (rtx
);
244 static rtx
mips_frame_set (rtx
, rtx
);
245 static void mips_save_reg (rtx
, rtx
);
246 static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT
);
247 static void mips_restore_reg (rtx
, rtx
);
248 static int symbolic_expression_p (rtx
);
249 static void mips_select_rtx_section (enum machine_mode
, rtx
,
250 unsigned HOST_WIDE_INT
);
251 static void mips_select_section (tree
, int, unsigned HOST_WIDE_INT
)
253 static bool mips_in_small_data_p (tree
);
254 static void mips_encode_section_info (tree
, rtx
, int);
255 static int mips_fpr_return_fields (tree
, tree
*);
256 static bool mips_return_in_msb (tree
);
257 static rtx
mips_return_fpr_pair (enum machine_mode mode
,
258 enum machine_mode mode1
, HOST_WIDE_INT
,
259 enum machine_mode mode2
, HOST_WIDE_INT
);
260 static rtx
mips16_gp_pseudo_reg (void);
261 static void mips16_fp_args (FILE *, int, int);
262 static void build_mips16_function_stub (FILE *);
263 static void mips16_optimize_gp (void);
264 static rtx
add_constant (struct constant
**, rtx
, enum machine_mode
);
265 static void dump_constants (struct constant
*, rtx
);
266 static rtx
mips_find_symbol (rtx
);
267 static void mips16_lay_out_constants (void);
268 static void mips_avoid_hazard (rtx
, rtx
, int *, rtx
*, rtx
);
269 static void mips_avoid_hazards (void);
270 static void mips_reorg (void);
271 static bool mips_strict_matching_cpu_name_p (const char *, const char *);
272 static bool mips_matching_cpu_name_p (const char *, const char *);
273 static const struct mips_cpu_info
*mips_parse_cpu (const char *, const char *);
274 static const struct mips_cpu_info
*mips_cpu_info_from_isa (int);
275 static int mips_adjust_cost (rtx
, rtx
, rtx
, int);
276 static int mips_issue_rate (void);
277 static int mips_use_dfa_pipeline_interface (void);
278 static void mips_init_libfuncs (void);
279 static tree
mips_build_builtin_va_list (void);
282 static void irix_asm_named_section_1 (const char *, unsigned int,
284 static void irix_asm_named_section (const char *, unsigned int);
285 static int irix_section_align_entry_eq (const void *, const void *);
286 static hashval_t
irix_section_align_entry_hash (const void *);
287 static void irix_file_start (void);
288 static int irix_section_align_1 (void **, void *);
289 static void copy_file_data (FILE *, FILE *);
290 static void irix_file_end (void);
291 static unsigned int irix_section_type_flags (tree
, const char *, int);
294 /* Structure to be filled in by compute_frame_size with register
295 save masks, and offsets for the current function. */
297 struct mips_frame_info
GTY(())
299 HOST_WIDE_INT total_size
; /* # bytes that the entire frame takes up */
300 HOST_WIDE_INT var_size
; /* # bytes that variables take up */
301 HOST_WIDE_INT args_size
; /* # bytes that outgoing arguments take up */
302 HOST_WIDE_INT cprestore_size
; /* # bytes that the .cprestore slot takes up */
303 HOST_WIDE_INT gp_reg_size
; /* # bytes needed to store gp regs */
304 HOST_WIDE_INT fp_reg_size
; /* # bytes needed to store fp regs */
305 unsigned int mask
; /* mask of saved gp registers */
306 unsigned int fmask
; /* mask of saved fp registers */
307 HOST_WIDE_INT gp_save_offset
; /* offset from vfp to store gp registers */
308 HOST_WIDE_INT fp_save_offset
; /* offset from vfp to store fp registers */
309 HOST_WIDE_INT gp_sp_offset
; /* offset from new sp to store gp registers */
310 HOST_WIDE_INT fp_sp_offset
; /* offset from new sp to store fp registers */
311 bool initialized
; /* true if frame size already calculated */
312 int num_gp
; /* number of gp registers saved */
313 int num_fp
; /* number of fp registers saved */
316 struct machine_function
GTY(()) {
317 /* Pseudo-reg holding the address of the current function when
318 generating embedded PIC code. */
319 rtx embedded_pic_fnaddr_rtx
;
321 /* Pseudo-reg holding the value of $28 in a mips16 function which
322 refers to GP relative global variables. */
323 rtx mips16_gp_pseudo_rtx
;
325 /* Current frame information, calculated by compute_frame_size. */
326 struct mips_frame_info frame
;
328 /* Length of instructions in function; mips16 only. */
331 /* The register to use as the global pointer within this function. */
332 unsigned int global_pointer
;
334 /* True if mips_adjust_insn_length should ignore an instruction's
336 bool ignore_hazard_length_p
;
338 /* True if the whole function is suitable for .set noreorder and
340 bool all_noreorder_p
;
342 /* True if the function is known to have an instruction that needs $gp. */
346 /* Information about a single argument. */
349 /* True if the argument is passed in a floating-point register, or
350 would have been if we hadn't run out of registers. */
353 /* The argument's size, in bytes. */
354 unsigned int num_bytes
;
356 /* The number of words passed in registers, rounded up. */
357 unsigned int reg_words
;
359 /* The offset of the first register from GP_ARG_FIRST or FP_ARG_FIRST,
360 or MAX_ARGS_IN_REGISTERS if the argument is passed entirely
362 unsigned int reg_offset
;
364 /* The number of words that must be passed on the stack, rounded up. */
365 unsigned int stack_words
;
367 /* The offset from the start of the stack overflow area of the argument's
368 first stack word. Only meaningful when STACK_WORDS is nonzero. */
369 unsigned int stack_offset
;
373 /* Information about an address described by mips_address_type.
379 REG is the base register and OFFSET is the constant offset.
382 REG is the register that contains the high part of the address,
383 OFFSET is the symbolic address being referenced and SYMBOL_TYPE
384 is the type of OFFSET's symbol.
387 SYMBOL_TYPE is the type of symbol being referenced. */
389 struct mips_address_info
391 enum mips_address_type type
;
394 enum mips_symbol_type symbol_type
;
398 /* One stage in a constant building sequence. These sequences have
402 A = A CODE[1] VALUE[1]
403 A = A CODE[2] VALUE[2]
406 where A is an accumulator, each CODE[i] is a binary rtl operation
407 and each VALUE[i] is a constant integer. */
408 struct mips_integer_op
{
410 unsigned HOST_WIDE_INT value
;
414 /* The largest number of operations needed to load an integer constant.
415 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
416 When the lowest bit is clear, we can try, but reject a sequence with
417 an extra SLL at the end. */
418 #define MIPS_MAX_INTEGER_OPS 7
421 /* Global variables for machine-dependent things. */
423 /* Threshold for data being put into the small data/bss area, instead
424 of the normal data area. */
425 int mips_section_threshold
= -1;
427 /* Count the number of .file directives, so that .loc is up to date. */
428 int num_source_filenames
= 0;
430 /* Count the number of sdb related labels are generated (to find block
431 start and end boundaries). */
432 int sdb_label_count
= 0;
434 /* Next label # for each statement for Silicon Graphics IRIS systems. */
437 /* Linked list of all externals that are to be emitted when optimizing
438 for the global pointer if they haven't been declared by the end of
439 the program with an appropriate .comm or initialization. */
441 struct extern_list
GTY (())
443 struct extern_list
*next
; /* next external */
444 const char *name
; /* name of the external */
445 int size
; /* size in bytes */
448 static GTY (()) struct extern_list
*extern_head
= 0;
450 /* Name of the file containing the current function. */
451 const char *current_function_file
= "";
453 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
459 /* The next branch instruction is a branch likely, not branch normal. */
460 int mips_branch_likely
;
462 /* Cached operands, and operator to compare for use in set/branch/trap
463 on condition codes. */
466 /* what type of branch to use */
467 enum cmp_type branch_type
;
469 /* The target cpu for code generation. */
470 enum processor_type mips_arch
;
471 const struct mips_cpu_info
*mips_arch_info
;
473 /* The target cpu for optimization and scheduling. */
474 enum processor_type mips_tune
;
475 const struct mips_cpu_info
*mips_tune_info
;
477 /* Which instruction set architecture to use. */
480 /* Which ABI to use. */
483 /* Strings to hold which cpu and instruction set architecture to use. */
484 const char *mips_arch_string
; /* for -march=<xxx> */
485 const char *mips_tune_string
; /* for -mtune=<xxx> */
486 const char *mips_isa_string
; /* for -mips{1,2,3,4} */
487 const char *mips_abi_string
; /* for -mabi={32,n32,64,eabi} */
489 /* Whether we are generating mips16 hard float code. In mips16 mode
490 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
491 -msoft-float was not specified by the user, which means that we
492 should arrange to call mips32 hard floating point code. */
493 int mips16_hard_float
;
495 const char *mips_cache_flush_func
= CACHE_FLUSH_FUNC
;
497 /* If TRUE, we split addresses into their high and low parts in the RTL. */
498 int mips_split_addresses
;
500 /* Mode used for saving/restoring general purpose registers. */
501 static enum machine_mode gpr_mode
;
503 /* Array giving truth value on whether or not a given hard register
504 can support a given mode. */
505 char mips_hard_regno_mode_ok
[(int)MAX_MACHINE_MODE
][FIRST_PSEUDO_REGISTER
];
507 /* The length of all strings seen when compiling for the mips16. This
508 is used to tell how many strings are in the constant pool, so that
509 we can see if we may have an overflow. This is reset each time the
510 constant pool is output. */
511 int mips_string_length
;
513 /* When generating mips16 code, a list of all strings that are to be
514 output after the current function. */
516 static GTY(()) rtx mips16_strings
;
518 /* In mips16 mode, we build a list of all the string constants we see
519 in a particular function. */
521 struct string_constant
523 struct string_constant
*next
;
527 static struct string_constant
*string_constants
;
529 /* List of all MIPS punctuation characters used by print_operand. */
530 char mips_print_operand_punct
[256];
532 /* Map GCC register number to debugger register number. */
533 int mips_dbx_regno
[FIRST_PSEUDO_REGISTER
];
535 /* An alias set for the GOT. */
536 static int mips_got_alias_set
;
538 /* A copy of the original flag_delayed_branch: see override_options. */
539 static int mips_flag_delayed_branch
;
541 static GTY (()) int mips_output_filename_first_time
= 1;
543 /* mips_split_p[X] is true if symbols of type X can be split by
544 mips_split_symbol(). */
545 static bool mips_split_p
[NUM_SYMBOL_TYPES
];
547 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
548 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
549 if they are matched by a special .md file pattern. */
550 static const char *mips_lo_relocs
[NUM_SYMBOL_TYPES
];
552 /* Likewise for HIGHs. */
553 static const char *mips_hi_relocs
[NUM_SYMBOL_TYPES
];
555 /* Hardware names for the registers. If -mrnames is used, this
556 will be overwritten with mips_sw_reg_names. */
558 char mips_reg_names
[][8] =
560 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
561 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
562 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
563 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
564 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
565 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
566 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
567 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
568 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
569 "$fcc5","$fcc6","$fcc7","", "", "", "", "$fakec",
570 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
571 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
572 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
573 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
574 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
575 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
576 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
577 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
578 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
579 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
580 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
581 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
584 /* Mips software names for the registers, used to overwrite the
585 mips_reg_names array. */
587 char mips_sw_reg_names
[][8] =
589 "$zero","$at", "$v0", "$v1", "$a0", "$a1", "$a2", "$a3",
590 "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
591 "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7",
592 "$t8", "$t9", "$k0", "$k1", "$gp", "$sp", "$fp", "$ra",
593 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
594 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
595 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
596 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
597 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
598 "$fcc5","$fcc6","$fcc7","$rap", "", "", "", "$fakec",
599 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
600 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
601 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
602 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
603 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
604 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
605 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
606 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
607 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
608 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
609 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
610 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
613 /* Map hard register number to register class */
614 const enum reg_class mips_regno_to_class
[] =
616 LEA_REGS
, LEA_REGS
, M16_NA_REGS
, M16_NA_REGS
,
617 M16_REGS
, M16_REGS
, M16_REGS
, M16_REGS
,
618 LEA_REGS
, LEA_REGS
, LEA_REGS
, LEA_REGS
,
619 LEA_REGS
, LEA_REGS
, LEA_REGS
, LEA_REGS
,
620 M16_NA_REGS
, M16_NA_REGS
, LEA_REGS
, LEA_REGS
,
621 LEA_REGS
, LEA_REGS
, LEA_REGS
, LEA_REGS
,
622 T_REG
, PIC_FN_ADDR_REG
, LEA_REGS
, LEA_REGS
,
623 LEA_REGS
, LEA_REGS
, LEA_REGS
, LEA_REGS
,
624 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
625 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
626 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
627 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
628 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
629 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
630 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
631 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
632 HI_REG
, LO_REG
, NO_REGS
, ST_REGS
,
633 ST_REGS
, ST_REGS
, ST_REGS
, ST_REGS
,
634 ST_REGS
, ST_REGS
, ST_REGS
, NO_REGS
,
635 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
636 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
637 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
638 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
639 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
640 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
641 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
642 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
643 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
644 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
645 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
646 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
647 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
648 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
649 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
650 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
651 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
652 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
653 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
654 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
655 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
656 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
657 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
658 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
659 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
662 /* Map register constraint character to register class. */
663 enum reg_class mips_char_to_class
[256];
665 /* A table describing all the processors gcc knows about. Names are
666 matched in the order listed. The first mention of an ISA level is
667 taken as the canonical name for that ISA.
669 To ease comparison, please keep this table in the same order as
670 gas's mips_cpu_info_table[]. */
671 const struct mips_cpu_info mips_cpu_info_table
[] = {
672 /* Entries for generic ISAs */
673 { "mips1", PROCESSOR_R3000
, 1 },
674 { "mips2", PROCESSOR_R6000
, 2 },
675 { "mips3", PROCESSOR_R4000
, 3 },
676 { "mips4", PROCESSOR_R8000
, 4 },
677 { "mips32", PROCESSOR_4KC
, 32 },
678 { "mips32r2", PROCESSOR_M4K
, 33 },
679 { "mips64", PROCESSOR_5KC
, 64 },
682 { "r3000", PROCESSOR_R3000
, 1 },
683 { "r2000", PROCESSOR_R3000
, 1 }, /* = r3000 */
684 { "r3900", PROCESSOR_R3900
, 1 },
687 { "r6000", PROCESSOR_R6000
, 2 },
690 { "r4000", PROCESSOR_R4000
, 3 },
691 { "vr4100", PROCESSOR_R4100
, 3 },
692 { "vr4111", PROCESSOR_R4111
, 3 },
693 { "vr4120", PROCESSOR_R4120
, 3 },
694 { "vr4300", PROCESSOR_R4300
, 3 },
695 { "r4400", PROCESSOR_R4000
, 3 }, /* = r4000 */
696 { "r4600", PROCESSOR_R4600
, 3 },
697 { "orion", PROCESSOR_R4600
, 3 }, /* = r4600 */
698 { "r4650", PROCESSOR_R4650
, 3 },
701 { "r8000", PROCESSOR_R8000
, 4 },
702 { "vr5000", PROCESSOR_R5000
, 4 },
703 { "vr5400", PROCESSOR_R5400
, 4 },
704 { "vr5500", PROCESSOR_R5500
, 4 },
705 { "rm7000", PROCESSOR_R7000
, 4 },
706 { "rm9000", PROCESSOR_R9000
, 4 },
709 { "4kc", PROCESSOR_4KC
, 32 },
710 { "4kp", PROCESSOR_4KC
, 32 }, /* = 4kc */
712 /* MIPS32 Release 2 */
713 { "m4k", PROCESSOR_M4K
, 33 },
716 { "5kc", PROCESSOR_5KC
, 64 },
717 { "20kc", PROCESSOR_20KC
, 64 },
718 { "sb1", PROCESSOR_SB1
, 64 },
719 { "sr71000", PROCESSOR_SR71000
, 64 },
725 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
726 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
727 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
730 /* Initialize the GCC target structure. */
731 #undef TARGET_ASM_ALIGNED_HI_OP
732 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
733 #undef TARGET_ASM_ALIGNED_SI_OP
734 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
735 #undef TARGET_ASM_INTEGER
736 #define TARGET_ASM_INTEGER mips_assemble_integer
738 #undef TARGET_ASM_FUNCTION_PROLOGUE
739 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
740 #undef TARGET_ASM_FUNCTION_EPILOGUE
741 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
742 #undef TARGET_ASM_SELECT_RTX_SECTION
743 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
745 #undef TARGET_SCHED_ADJUST_COST
746 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
747 #undef TARGET_SCHED_ISSUE_RATE
748 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
749 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
750 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE mips_use_dfa_pipeline_interface
752 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
753 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
755 #undef TARGET_VALID_POINTER_MODE
756 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
757 #undef TARGET_RTX_COSTS
758 #define TARGET_RTX_COSTS mips_rtx_costs
759 #undef TARGET_ADDRESS_COST
760 #define TARGET_ADDRESS_COST mips_address_cost
762 #undef TARGET_ENCODE_SECTION_INFO
763 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
764 #undef TARGET_IN_SMALL_DATA_P
765 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
767 #undef TARGET_MACHINE_DEPENDENT_REORG
768 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
770 #undef TARGET_ASM_FILE_START
771 #undef TARGET_ASM_FILE_END
773 #define TARGET_ASM_FILE_START irix_file_start
774 #define TARGET_ASM_FILE_END irix_file_end
776 #define TARGET_ASM_FILE_START mips_file_start
777 #define TARGET_ASM_FILE_END mips_file_end
779 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
780 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
783 #undef TARGET_SECTION_TYPE_FLAGS
784 #define TARGET_SECTION_TYPE_FLAGS irix_section_type_flags
787 #undef TARGET_INIT_LIBFUNCS
788 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
790 #undef TARGET_BUILD_BUILTIN_VA_LIST
791 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
792 #undef TARGET_RETURN_IN_MSB
793 #define TARGET_RETURN_IN_MSB mips_return_in_msb
795 struct gcc_target targetm
= TARGET_INITIALIZER
;
797 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
799 static enum mips_symbol_type
800 mips_classify_symbol (rtx x
)
802 if (GET_CODE (x
) == LABEL_REF
)
803 return (TARGET_ABICALLS
? SYMBOL_GOT_LOCAL
: SYMBOL_GENERAL
);
805 if (GET_CODE (x
) != SYMBOL_REF
)
808 if (CONSTANT_POOL_ADDRESS_P (x
))
811 return SYMBOL_CONSTANT_POOL
;
814 return SYMBOL_GOT_LOCAL
;
816 if (GET_MODE_SIZE (get_pool_mode (x
)) <= mips_section_threshold
)
817 return SYMBOL_SMALL_DATA
;
819 return SYMBOL_GENERAL
;
822 if (SYMBOL_REF_SMALL_P (x
))
823 return SYMBOL_SMALL_DATA
;
825 /* When generating mips16 code, SYMBOL_REF_FLAG indicates a string
826 in the current function's constant pool. */
827 if (TARGET_MIPS16
&& SYMBOL_REF_FLAG (x
))
828 return SYMBOL_CONSTANT_POOL
;
832 if (SYMBOL_REF_DECL (x
) == 0)
833 return SYMBOL_REF_LOCAL_P (x
) ? SYMBOL_GOT_LOCAL
: SYMBOL_GOT_GLOBAL
;
835 /* There are three cases to consider:
837 - o32 PIC (either with or without explicit relocs)
838 - n32/n64 PIC without explicit relocs
839 - n32/n64 PIC with explicit relocs
841 In the first case, both local and global accesses will use an
842 R_MIPS_GOT16 relocation. We must correctly predict which of
843 the two semantics (local or global) the assembler and linker
844 will apply. The choice doesn't depend on the symbol's
845 visibility, so we deliberately ignore decl_visibility and
848 In the second case, the assembler will not use R_MIPS_GOT16
849 relocations, but it chooses between local and global accesses
850 in the same way as for o32 PIC.
852 In the third case we have more freedom since both forms of
853 access will work for any kind of symbol. However, there seems
854 little point in doing things differently. */
855 if (DECL_P (SYMBOL_REF_DECL (x
)) && TREE_PUBLIC (SYMBOL_REF_DECL (x
)))
856 return SYMBOL_GOT_GLOBAL
;
858 return SYMBOL_GOT_LOCAL
;
861 return SYMBOL_GENERAL
;
865 /* Split X into a base and a constant offset, storing them in *BASE
866 and *OFFSET respectively. */
869 mips_split_const (rtx x
, rtx
*base
, HOST_WIDE_INT
*offset
)
873 if (GET_CODE (x
) == CONST
)
876 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
878 *offset
+= INTVAL (XEXP (x
, 1));
885 /* Return true if X is a symbolic constant that can be calculated in
886 the same way as a bare symbol. If it is, store the type of the
887 symbol in *SYMBOL_TYPE. */
890 mips_symbolic_constant_p (rtx x
, enum mips_symbol_type
*symbol_type
)
892 HOST_WIDE_INT offset
;
894 mips_split_const (x
, &x
, &offset
);
895 if (UNSPEC_ADDRESS_P (x
))
896 *symbol_type
= UNSPEC_ADDRESS_TYPE (x
);
897 else if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
898 *symbol_type
= mips_classify_symbol (x
);
905 /* If X refers to a string constant, and that constant is put into a
906 mergeable section, the linker will need to know which string is
907 being accessed. It has no way of distinguishing an out-of-bounds
908 access to X from an in-bounds access to a later or earlier string. */
909 if (GET_CODE (x
) == SYMBOL_REF
910 && SYMBOL_REF_DECL (x
) != 0
911 && TREE_CODE (SYMBOL_REF_DECL (x
)) == STRING_CST
912 && !(offset
> 0 && offset
< TREE_STRING_LENGTH (SYMBOL_REF_DECL (x
))))
915 /* Check whether a nonzero offset is valid for the underlying
917 switch (*symbol_type
)
920 /* %hi() and %lo() can handle anything. */
923 case SYMBOL_SMALL_DATA
:
924 /* Make sure that the offset refers to something within the
925 -G limit. If the offset is allowed to grow too much,
926 it could overflow the range of %gp_rel(). */
927 return (offset
> 0 && offset
< mips_section_threshold
);
929 case SYMBOL_CONSTANT_POOL
:
930 /* We don't generate out-of-bounds accesses to normal constant
931 pool entries. String constants were handled above. */
934 case SYMBOL_GOT_LOCAL
:
935 case SYMBOL_GOTOFF_PAGE
:
936 /* The linker should provide enough local GOT entries for a
937 16-bit offset. Larger offsets may lead to GOT overflow. */
938 return SMALL_OPERAND (offset
);
940 case SYMBOL_GOT_GLOBAL
:
941 case SYMBOL_GOTOFF_GLOBAL
:
942 case SYMBOL_GOTOFF_CALL
:
943 case SYMBOL_GOTOFF_LOADGP
:
950 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
953 mips_reg_mode_ok_for_base_p (rtx reg
, enum machine_mode mode
, int strict
)
956 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg
), mode
)
957 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg
), mode
));
961 /* Return true if X is a valid base register for the given mode.
962 Allow only hard registers if STRICT. */
965 mips_valid_base_register_p (rtx x
, enum machine_mode mode
, int strict
)
967 if (!strict
&& GET_CODE (x
) == SUBREG
)
970 return (GET_CODE (x
) == REG
971 && mips_reg_mode_ok_for_base_p (x
, mode
, strict
));
975 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
976 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
979 mips_symbolic_address_p (enum mips_symbol_type symbol_type
,
980 enum machine_mode mode
)
985 return !TARGET_MIPS16
;
987 case SYMBOL_SMALL_DATA
:
990 case SYMBOL_CONSTANT_POOL
:
991 /* PC-relative addressing is only available for lw, sw, ld and sd. */
992 return GET_MODE_SIZE (mode
) == 4 || GET_MODE_SIZE (mode
) == 8;
994 case SYMBOL_GOT_LOCAL
:
997 case SYMBOL_GOT_GLOBAL
:
998 /* The address will have to be loaded from the GOT first. */
1001 case SYMBOL_GOTOFF_PAGE
:
1002 case SYMBOL_GOTOFF_GLOBAL
:
1003 case SYMBOL_GOTOFF_CALL
:
1004 case SYMBOL_GOTOFF_LOADGP
:
1011 /* Return true if X is a valid address for machine mode MODE. If it is,
1012 fill in INFO appropriately. STRICT is true if we should only accept
1013 hard base registers. */
1016 mips_classify_address (struct mips_address_info
*info
, rtx x
,
1017 enum machine_mode mode
, int strict
)
1019 switch (GET_CODE (x
))
1023 info
->type
= ADDRESS_REG
;
1025 info
->offset
= const0_rtx
;
1026 return mips_valid_base_register_p (info
->reg
, mode
, strict
);
1029 info
->type
= ADDRESS_REG
;
1030 info
->reg
= XEXP (x
, 0);
1031 info
->offset
= XEXP (x
, 1);
1032 return (mips_valid_base_register_p (info
->reg
, mode
, strict
)
1033 && const_arith_operand (info
->offset
, VOIDmode
));
1036 info
->type
= ADDRESS_LO_SUM
;
1037 info
->reg
= XEXP (x
, 0);
1038 info
->offset
= XEXP (x
, 1);
1039 return (mips_valid_base_register_p (info
->reg
, mode
, strict
)
1040 && mips_symbolic_constant_p (info
->offset
, &info
->symbol_type
)
1041 && mips_symbolic_address_p (info
->symbol_type
, mode
)
1042 && mips_lo_relocs
[info
->symbol_type
] != 0);
1045 /* Small-integer addresses don't occur very often, but they
1046 are legitimate if $0 is a valid base register. */
1047 info
->type
= ADDRESS_CONST_INT
;
1048 return !TARGET_MIPS16
&& SMALL_INT (x
);
1053 info
->type
= ADDRESS_SYMBOLIC
;
1054 return (mips_symbolic_constant_p (x
, &info
->symbol_type
)
1055 && mips_symbolic_address_p (info
->symbol_type
, mode
)
1056 && !mips_split_p
[info
->symbol_type
]);
1063 /* Return the number of instructions needed to load a symbol of the
1064 given type into a register. If valid in an address, the same number
1065 of instructions are needed for loads and stores. Treat extended
1066 mips16 instructions as two instructions. */
1069 mips_symbol_insns (enum mips_symbol_type type
)
1073 case SYMBOL_GENERAL
:
1074 /* In mips16 code, general symbols must be fetched from the
1079 /* When using 64-bit symbols, we need 5 preparatory instructions,
1082 lui $at,%highest(symbol)
1083 daddiu $at,$at,%higher(symbol)
1085 daddiu $at,$at,%hi(symbol)
1088 The final address is then $at + %lo(symbol). With 32-bit
1089 symbols we just need a preparatory lui. */
1090 return (ABI_HAS_64BIT_SYMBOLS
? 6 : 2);
1092 case SYMBOL_SMALL_DATA
:
1095 case SYMBOL_CONSTANT_POOL
:
1096 /* This case is for mips16 only. Assume we'll need an
1097 extended instruction. */
1100 case SYMBOL_GOT_LOCAL
:
1101 case SYMBOL_GOT_GLOBAL
:
1102 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1103 the local/global classification is accurate. See override_options
1106 The worst cases are:
1108 (1) For local symbols when generating o32 or o64 code. The assembler
1114 ...and the final address will be $at + %lo(symbol).
1116 (2) For global symbols when -mxgot. The assembler will use:
1118 lui $at,%got_hi(symbol)
1121 ...and the final address will be $at + %got_lo(symbol). */
1124 case SYMBOL_GOTOFF_PAGE
:
1125 case SYMBOL_GOTOFF_GLOBAL
:
1126 case SYMBOL_GOTOFF_CALL
:
1127 case SYMBOL_GOTOFF_LOADGP
:
1128 /* Check whether the offset is a 16- or 32-bit value. */
1129 return mips_split_p
[type
] ? 2 : 1;
1135 /* Return true if a value at OFFSET bytes from BASE can be accessed
1136 using an unextended mips16 instruction. MODE is the mode of the
1139 Usually the offset in an unextended instruction is a 5-bit field.
1140 The offset is unsigned and shifted left once for HIs, twice
1141 for SIs, and so on. An exception is SImode accesses off the
1142 stack pointer, which have an 8-bit immediate field. */
1145 mips16_unextended_reference_p (enum machine_mode mode
, rtx base
, rtx offset
)
1148 && GET_CODE (offset
) == CONST_INT
1149 && INTVAL (offset
) >= 0
1150 && (INTVAL (offset
) & (GET_MODE_SIZE (mode
) - 1)) == 0)
1152 if (GET_MODE_SIZE (mode
) == 4 && base
== stack_pointer_rtx
)
1153 return INTVAL (offset
) < 256 * GET_MODE_SIZE (mode
);
1154 return INTVAL (offset
) < 32 * GET_MODE_SIZE (mode
);
1160 /* Return the number of instructions needed to load or store a value
1161 of mode MODE at X. Return 0 if X isn't valid for MODE.
1163 For mips16 code, count extended instructions as two instructions. */
1166 mips_address_insns (rtx x
, enum machine_mode mode
)
1168 struct mips_address_info addr
;
1171 /* Each word of a multi-word value will be accessed individually. */
1172 factor
= (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
1173 if (mips_classify_address (&addr
, x
, mode
, false))
1178 && !mips16_unextended_reference_p (mode
, addr
.reg
, addr
.offset
))
1182 case ADDRESS_LO_SUM
:
1183 return (TARGET_MIPS16
? factor
* 2 : factor
);
1185 case ADDRESS_CONST_INT
:
1188 case ADDRESS_SYMBOLIC
:
1189 return factor
* mips_symbol_insns (addr
.symbol_type
);
1195 /* Likewise for constant X. */
1198 mips_const_insns (rtx x
)
1200 struct mips_integer_op codes
[MIPS_MAX_INTEGER_OPS
];
1201 enum mips_symbol_type symbol_type
;
1202 HOST_WIDE_INT offset
;
1204 switch (GET_CODE (x
))
1206 case CONSTANT_P_RTX
:
1211 || !mips_symbolic_constant_p (XEXP (x
, 0), &symbol_type
)
1212 || !mips_split_p
[symbol_type
])
1219 /* Unsigned 8-bit constants can be loaded using an unextended
1220 LI instruction. Unsigned 16-bit constants can be loaded
1221 using an extended LI. Negative constants must be loaded
1222 using LI and then negated. */
1223 return (INTVAL (x
) >= 0 && INTVAL (x
) < 256 ? 1
1224 : SMALL_OPERAND_UNSIGNED (INTVAL (x
)) ? 2
1225 : INTVAL (x
) > -256 && INTVAL (x
) < 0 ? 2
1226 : SMALL_OPERAND_UNSIGNED (-INTVAL (x
)) ? 3
1229 return mips_build_integer (codes
, INTVAL (x
));
1232 return (!TARGET_MIPS16
&& x
== CONST0_RTX (GET_MODE (x
)) ? 1 : 0);
1238 /* See if we can refer to X directly. */
1239 if (mips_symbolic_constant_p (x
, &symbol_type
))
1240 return mips_symbol_insns (symbol_type
);
1242 /* Otherwise try splitting the constant into a base and offset.
1243 16-bit offsets can be added using an extra addiu. Larger offsets
1244 must be calculated separately and then added to the base. */
1245 mips_split_const (x
, &x
, &offset
);
1248 int n
= mips_const_insns (x
);
1251 if (SMALL_OPERAND (offset
))
1254 return n
+ 1 + mips_build_integer (codes
, offset
);
1261 return mips_symbol_insns (mips_classify_symbol (x
));
1269 /* Return the number of instructions needed for memory reference X.
1270 Count extended mips16 instructions as two instructions. */
1273 mips_fetch_insns (rtx x
)
1275 if (GET_CODE (x
) != MEM
)
1278 return mips_address_insns (XEXP (x
, 0), GET_MODE (x
));
1282 /* Return truth value of whether OP can be used as an operands
1283 where a register or 16 bit unsigned integer is needed. */
1286 uns_arith_operand (rtx op
, enum machine_mode mode
)
1288 if (GET_CODE (op
) == CONST_INT
&& SMALL_INT_UNSIGNED (op
))
1291 return register_operand (op
, mode
);
1295 /* True if OP can be treated as a signed 16-bit constant. */
1298 const_arith_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1300 return GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
);
1304 /* Return true if OP is a register operand or a signed 16-bit constant. */
1307 arith_operand (rtx op
, enum machine_mode mode
)
1309 return const_arith_operand (op
, mode
) || register_operand (op
, mode
);
1312 /* Return truth value of whether OP is an integer which fits in 16 bits. */
1315 small_int (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1317 return (GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
));
1320 /* Return truth value of whether OP is a register or the constant 0.
1321 Do not accept 0 in mips16 mode since $0 is not one of the core 8
1325 reg_or_0_operand (rtx op
, enum machine_mode mode
)
1327 switch (GET_CODE (op
))
1332 return INTVAL (op
) == 0;
1337 return op
== CONST0_RTX (mode
);
1340 return register_operand (op
, mode
);
1344 /* Accept a register or the floating point constant 1 in the appropriate mode. */
1347 reg_or_const_float_1_operand (rtx op
, enum machine_mode mode
)
1351 switch (GET_CODE (op
))
1354 if (mode
!= GET_MODE (op
)
1355 || (mode
!= DFmode
&& mode
!= SFmode
))
1358 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
1359 return REAL_VALUES_EQUAL (d
, dconst1
);
1362 return register_operand (op
, mode
);
1366 /* Accept the floating point constant 1 in the appropriate mode. */
1369 const_float_1_operand (rtx op
, enum machine_mode mode
)
1373 if (GET_CODE (op
) != CONST_DOUBLE
1374 || mode
!= GET_MODE (op
)
1375 || (mode
!= DFmode
&& mode
!= SFmode
))
1378 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
1380 return REAL_VALUES_EQUAL (d
, dconst1
);
1383 /* Return true if OP is either the HI or LO register. */
1386 hilo_operand (rtx op
, enum machine_mode mode
)
1388 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
1389 && REG_P (op
) && MD_REG_P (REGNO (op
)));
1392 /* Return true if OP is an extension operator. */
1395 extend_operator (rtx op
, enum machine_mode mode
)
1397 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
1398 && (GET_CODE (op
) == ZERO_EXTEND
|| GET_CODE (op
) == SIGN_EXTEND
));
1401 /* Return nonzero if the code of this rtx pattern is EQ or NE. */
1404 equality_op (rtx op
, enum machine_mode mode
)
1406 if (mode
!= GET_MODE (op
))
1409 return GET_CODE (op
) == EQ
|| GET_CODE (op
) == NE
;
1412 /* Return nonzero if the code is a relational operations (EQ, LE, etc.) */
1415 cmp_op (rtx op
, enum machine_mode mode
)
1417 if (mode
!= GET_MODE (op
))
1420 return GET_RTX_CLASS (GET_CODE (op
)) == '<';
1423 /* Return nonzero if the code is a relational operation suitable for a
1424 conditional trap instruction (only EQ, NE, LT, LTU, GE, GEU).
1425 We need this in the insn that expands `trap_if' in order to prevent
1426 combine from erroneously altering the condition. */
1429 trap_cmp_op (rtx op
, enum machine_mode mode
)
1431 if (mode
!= GET_MODE (op
))
1434 switch (GET_CODE (op
))
1449 /* Return nonzero if the operand is either the PC or a label_ref. */
1452 pc_or_label_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1457 if (GET_CODE (op
) == LABEL_REF
)
1463 /* Test for a valid call address. */
1466 call_insn_operand (rtx op
, enum machine_mode mode
)
1468 enum mips_symbol_type symbol_type
;
1470 if (mips_symbolic_constant_p (op
, &symbol_type
))
1471 switch (symbol_type
)
1473 case SYMBOL_GENERAL
:
1474 /* If -mlong-calls, force all calls to use register addressing. */
1475 return !TARGET_LONG_CALLS
;
1477 case SYMBOL_GOT_GLOBAL
:
1478 /* Without explicit relocs, there is no special syntax for
1479 loading the address of a call destination into a register.
1480 Using "la $25,foo; jal $25" would prevent the lazy binding
1481 of "foo", so keep the address of global symbols with the
1483 return !TARGET_EXPLICIT_RELOCS
;
1488 return register_operand (op
, mode
);
1492 /* Return nonzero if OP is valid as a source operand for a move
1496 move_operand (rtx op
, enum machine_mode mode
)
1498 enum mips_symbol_type symbol_type
;
1500 if (!general_operand (op
, mode
))
1503 switch (GET_CODE (op
))
1506 /* When generating mips16 code, LEGITIMATE_CONSTANT_P rejects
1507 CONST_INTs that can't be loaded using simple insns. */
1511 /* Otherwise check whether the constant can be loaded in a single
1513 return LUI_INT (op
) || SMALL_INT (op
) || SMALL_INT_UNSIGNED (op
);
1518 if (CONST_GP_P (op
))
1521 return (mips_symbolic_constant_p (op
, &symbol_type
)
1522 && !mips_split_p
[symbol_type
]);
1530 /* Accept any operand that can appear in a mips16 constant table
1531 instruction. We can't use any of the standard operand functions
1532 because for these instructions we accept values that are not
1533 accepted by LEGITIMATE_CONSTANT, such as arbitrary SYMBOL_REFs. */
1536 consttable_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1538 return CONSTANT_P (op
);
1541 /* Return 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
1542 possibly with an offset. */
1545 symbolic_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1547 enum mips_symbol_type symbol_type
;
1549 return mips_symbolic_constant_p (op
, &symbol_type
);
1553 /* Return true if we're generating PIC and OP is a global symbol. */
1556 global_got_operand (rtx op
, enum machine_mode mode
)
1558 enum mips_symbol_type symbol_type
;
1560 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
1561 && mips_symbolic_constant_p (op
, &symbol_type
)
1562 && symbol_type
== SYMBOL_GOT_GLOBAL
);
1566 /* Likewise for local symbols. */
1569 local_got_operand (rtx op
, enum machine_mode mode
)
1571 enum mips_symbol_type symbol_type
;
1573 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
1574 && mips_symbolic_constant_p (op
, &symbol_type
)
1575 && symbol_type
== SYMBOL_GOT_LOCAL
);
1579 /* Return true if OP is a memory reference that uses the stack pointer
1580 as a base register. */
1583 stack_operand (rtx op
, enum machine_mode mode
)
1585 struct mips_address_info addr
;
1587 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
1588 && GET_CODE (op
) == MEM
1589 && mips_classify_address (&addr
, XEXP (op
, 0), GET_MODE (op
), false)
1590 && addr
.type
== ADDRESS_REG
1591 && addr
.reg
== stack_pointer_rtx
);
1595 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1596 returns a nonzero value if X is a legitimate address for a memory
1597 operand of the indicated MODE. STRICT is nonzero if this function
1598 is called during reload. */
1601 mips_legitimate_address_p (enum machine_mode mode
, rtx x
, int strict
)
1603 struct mips_address_info addr
;
1605 return mips_classify_address (&addr
, x
, mode
, strict
);
1609 /* Copy VALUE to a register and return that register. If new psuedos
1610 are allowed, copy it into a new register, otherwise use DEST. */
1613 mips_force_temporary (rtx dest
, rtx value
)
1615 if (!no_new_pseudos
)
1616 return force_reg (Pmode
, value
);
1619 emit_move_insn (copy_rtx (dest
), value
);
1625 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1626 and is used to load the high part into a register. */
1629 mips_split_symbol (rtx temp
, rtx addr
)
1634 high
= mips16_gp_pseudo_reg ();
1636 high
= mips_force_temporary (temp
, gen_rtx_HIGH (Pmode
, copy_rtx (addr
)));
1637 return gen_rtx_LO_SUM (Pmode
, high
, addr
);
1641 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1642 type SYMBOL_TYPE. */
1645 mips_unspec_address (rtx address
, enum mips_symbol_type symbol_type
)
1648 HOST_WIDE_INT offset
;
1650 mips_split_const (address
, &base
, &offset
);
1651 base
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, base
),
1652 UNSPEC_ADDRESS_FIRST
+ symbol_type
);
1653 return plus_constant (gen_rtx_CONST (Pmode
, base
), offset
);
1657 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
1658 high part to BASE and return the result. Just return BASE otherwise.
1660 The returned expression can be used as the first operand to a LO_SUM. */
1663 mips_unspec_offset_high (rtx base
, rtx addr
, enum mips_symbol_type symbol_type
)
1665 if (mips_split_p
[symbol_type
])
1667 addr
= gen_rtx_HIGH (Pmode
, mips_unspec_address (addr
, symbol_type
));
1668 base
= force_reg (Pmode
, expand_simple_binop (Pmode
, PLUS
, base
, addr
,
1669 NULL
, 0, OPTAB_WIDEN
));
1675 /* Return a memory reference for the GOT slot whose offset is given by
1676 mips_unspec_address (ADDR, SYMBOL_TYPE). Register BASE contains the
1677 high part of the offset plus $gp. */
1680 mips_load_got (rtx base
, rtx addr
, enum mips_symbol_type symbol_type
)
1684 offset
= mips_unspec_address (addr
, symbol_type
);
1685 mem
= gen_rtx_MEM (ptr_mode
, gen_rtx_LO_SUM (Pmode
, base
, offset
));
1686 set_mem_alias_set (mem
, mips_got_alias_set
);
1688 /* GOT entries are constant and references to them can't trap. */
1689 RTX_UNCHANGING_P (mem
) = 1;
1690 MEM_NOTRAP_P (mem
) = 1;
1696 /* Return the offset of ADDR's GOT entry from _gp. ADDR is a
1697 global_got_operand. */
1700 mips_gotoff_global (rtx addr
)
1702 return mips_unspec_address (addr
, SYMBOL_GOTOFF_GLOBAL
);
1706 /* Fetch the high part of local_got_operand ADDR from the GOT. */
1709 mips_load_got_page (rtx addr
)
1711 return mips_load_got (pic_offset_table_rtx
, addr
, SYMBOL_GOTOFF_PAGE
);
1715 /* Fetch the address of global_got_operand ADDR from the GOT. BASE is a
1716 register that holds the address _gp + %got_hi(ADDR). */
1719 mips_load_got_global (rtx base
, rtx addr
)
1721 return mips_load_got (base
, addr
, SYMBOL_GOTOFF_GLOBAL
);
1725 /* Return a legitimate address for REG + OFFSET. This function will
1726 create a temporary register if OFFSET is not a SMALL_OPERAND. */
1729 mips_add_offset (rtx reg
, HOST_WIDE_INT offset
)
1731 if (!SMALL_OPERAND (offset
))
1732 reg
= expand_simple_binop (GET_MODE (reg
), PLUS
,
1733 GEN_INT (CONST_HIGH_PART (offset
)),
1734 reg
, NULL
, 0, OPTAB_WIDEN
);
1736 return plus_constant (reg
, CONST_LOW_PART (offset
));
1740 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
1741 be legitimized in a way that the generic machinery might not expect,
1742 put the new address in *XLOC and return true. MODE is the mode of
1743 the memory being accessed. */
1746 mips_legitimize_address (rtx
*xloc
, enum machine_mode mode
)
1748 enum mips_symbol_type symbol_type
;
1750 /* See if the address can split into a high part and a LO_SUM. */
1751 if (mips_symbolic_constant_p (*xloc
, &symbol_type
)
1752 && mips_symbolic_address_p (symbol_type
, mode
)
1753 && mips_split_p
[symbol_type
])
1755 *xloc
= mips_split_symbol (0, *xloc
);
1759 if (GET_CODE (*xloc
) == PLUS
&& GET_CODE (XEXP (*xloc
, 1)) == CONST_INT
)
1761 /* Handle REG + CONSTANT using mips_add_offset. */
1764 reg
= XEXP (*xloc
, 0);
1765 if (!mips_valid_base_register_p (reg
, mode
, 0))
1766 reg
= copy_to_mode_reg (Pmode
, reg
);
1767 *xloc
= mips_add_offset (reg
, INTVAL (XEXP (*xloc
, 1)));
1775 /* Subroutine of mips_build_integer (with the same interface).
1776 Assume that the final action in the sequence should be a left shift. */
1779 mips_build_shift (struct mips_integer_op
*codes
, HOST_WIDE_INT value
)
1781 unsigned int i
, shift
;
1783 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1784 since signed numbers are easier to load than unsigned ones. */
1786 while ((value
& 1) == 0)
1787 value
/= 2, shift
++;
1789 i
= mips_build_integer (codes
, value
);
1790 codes
[i
].code
= ASHIFT
;
1791 codes
[i
].value
= shift
;
1796 /* As for mips_build_shift, but assume that the final action will be
1797 an IOR or PLUS operation. */
1800 mips_build_lower (struct mips_integer_op
*codes
, unsigned HOST_WIDE_INT value
)
1802 unsigned HOST_WIDE_INT high
;
1805 high
= value
& ~(unsigned HOST_WIDE_INT
) 0xffff;
1806 if (!LUI_OPERAND (high
) && (value
& 0x18000) == 0x18000)
1808 /* The constant is too complex to load with a simple lui/ori pair
1809 so our goal is to clear as many trailing zeros as possible.
1810 In this case, we know bit 16 is set and that the low 16 bits
1811 form a negative number. If we subtract that number from VALUE,
1812 we will clear at least the lowest 17 bits, maybe more. */
1813 i
= mips_build_integer (codes
, CONST_HIGH_PART (value
));
1814 codes
[i
].code
= PLUS
;
1815 codes
[i
].value
= CONST_LOW_PART (value
);
1819 i
= mips_build_integer (codes
, high
);
1820 codes
[i
].code
= IOR
;
1821 codes
[i
].value
= value
& 0xffff;
1827 /* Fill CODES with a sequence of rtl operations to load VALUE.
1828 Return the number of operations needed. */
1831 mips_build_integer (struct mips_integer_op
*codes
,
1832 unsigned HOST_WIDE_INT value
)
1834 if (SMALL_OPERAND (value
)
1835 || SMALL_OPERAND_UNSIGNED (value
)
1836 || LUI_OPERAND (value
))
1838 /* The value can be loaded with a single instruction. */
1839 codes
[0].code
= NIL
;
1840 codes
[0].value
= value
;
1843 else if ((value
& 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value
)))
1845 /* Either the constant is a simple LUI/ORI combination or its
1846 lowest bit is set. We don't want to shift in this case. */
1847 return mips_build_lower (codes
, value
);
1849 else if ((value
& 0xffff) == 0)
1851 /* The constant will need at least three actions. The lowest
1852 16 bits are clear, so the final action will be a shift. */
1853 return mips_build_shift (codes
, value
);
1857 /* The final action could be a shift, add or inclusive OR.
1858 Rather than use a complex condition to select the best
1859 approach, try both mips_build_shift and mips_build_lower
1860 and pick the one that gives the shortest sequence.
1861 Note that this case is only used once per constant. */
1862 struct mips_integer_op alt_codes
[MIPS_MAX_INTEGER_OPS
];
1863 unsigned int cost
, alt_cost
;
1865 cost
= mips_build_shift (codes
, value
);
1866 alt_cost
= mips_build_lower (alt_codes
, value
);
1867 if (alt_cost
< cost
)
1869 memcpy (codes
, alt_codes
, alt_cost
* sizeof (codes
[0]));
1877 /* Move VALUE into register DEST. */
1880 mips_move_integer (rtx dest
, unsigned HOST_WIDE_INT value
)
1882 struct mips_integer_op codes
[MIPS_MAX_INTEGER_OPS
];
1883 enum machine_mode mode
;
1884 unsigned int i
, cost
;
1887 mode
= GET_MODE (dest
);
1888 cost
= mips_build_integer (codes
, value
);
1890 /* Apply each binary operation to X. Invariant: X is a legitimate
1891 source operand for a SET pattern. */
1892 x
= GEN_INT (codes
[0].value
);
1893 for (i
= 1; i
< cost
; i
++)
1896 emit_move_insn (dest
, x
), x
= dest
;
1898 x
= force_reg (mode
, x
);
1899 x
= gen_rtx_fmt_ee (codes
[i
].code
, mode
, x
, GEN_INT (codes
[i
].value
));
1902 emit_insn (gen_rtx_SET (VOIDmode
, dest
, x
));
1906 /* Subroutine of mips_legitimize_move. Move constant SRC into register
1907 DEST given that SRC satisfies immediate_operand but doesn't satisfy
1911 mips_legitimize_const_move (enum machine_mode mode
, rtx dest
, rtx src
)
1914 HOST_WIDE_INT offset
;
1915 enum mips_symbol_type symbol_type
;
1917 /* Split moves of big integers into smaller pieces. In mips16 code,
1918 it's better to force the constant into memory instead. */
1919 if (GET_CODE (src
) == CONST_INT
&& !TARGET_MIPS16
)
1921 mips_move_integer (dest
, INTVAL (src
));
1925 /* See if the symbol can be split. For mips16, this is often worse than
1926 forcing it in the constant pool since it needs the single-register form
1927 of addiu or daddiu. */
1929 && mips_symbolic_constant_p (src
, &symbol_type
)
1930 && mips_split_p
[symbol_type
])
1932 emit_move_insn (dest
, mips_split_symbol (dest
, src
));
1936 /* If we have (const (plus symbol offset)), load the symbol first
1937 and then add in the offset. This is usually better than forcing
1938 the constant into memory, at least in non-mips16 code. */
1939 mips_split_const (src
, &base
, &offset
);
1942 && (!no_new_pseudos
|| SMALL_OPERAND (offset
)))
1944 base
= mips_force_temporary (dest
, base
);
1945 emit_move_insn (dest
, mips_add_offset (base
, offset
));
1949 src
= force_const_mem (mode
, src
);
1951 /* When using explicit relocs, constant pool references are sometimes
1952 not legitimate addresses. */
1953 if (!memory_operand (src
, VOIDmode
))
1954 src
= replace_equiv_address (src
, mips_split_symbol (dest
, XEXP (src
, 0)));
1955 emit_move_insn (dest
, src
);
1959 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
1960 sequence that is valid. */
1963 mips_legitimize_move (enum machine_mode mode
, rtx dest
, rtx src
)
1965 if (!register_operand (dest
, mode
) && !reg_or_0_operand (src
, mode
))
1967 emit_move_insn (dest
, force_reg (mode
, src
));
1971 /* The source of an SImode move must be a move_operand. Likewise
1972 DImode moves on 64-bit targets. We need to deal with constants
1973 that would be legitimate immediate_operands but not legitimate
1975 if (GET_MODE_SIZE (mode
) <= UNITS_PER_WORD
1977 && !move_operand (src
, mode
))
1979 mips_legitimize_const_move (mode
, dest
, src
);
1980 set_unique_reg_note (get_last_insn (), REG_EQUAL
, copy_rtx (src
));
1986 /* We need a lot of little routines to check constant values on the
1987 mips16. These are used to figure out how long the instruction will
1988 be. It would be much better to do this using constraints, but
1989 there aren't nearly enough letters available. */
1992 m16_check_op (rtx op
, int low
, int high
, int mask
)
1994 return (GET_CODE (op
) == CONST_INT
1995 && INTVAL (op
) >= low
1996 && INTVAL (op
) <= high
1997 && (INTVAL (op
) & mask
) == 0);
2001 m16_uimm3_b (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2003 return m16_check_op (op
, 0x1, 0x8, 0);
2007 m16_simm4_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2009 return m16_check_op (op
, - 0x8, 0x7, 0);
2013 m16_nsimm4_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2015 return m16_check_op (op
, - 0x7, 0x8, 0);
2019 m16_simm5_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2021 return m16_check_op (op
, - 0x10, 0xf, 0);
2025 m16_nsimm5_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2027 return m16_check_op (op
, - 0xf, 0x10, 0);
2031 m16_uimm5_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2033 return m16_check_op (op
, (- 0x10) << 2, 0xf << 2, 3);
2037 m16_nuimm5_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2039 return m16_check_op (op
, (- 0xf) << 2, 0x10 << 2, 3);
2043 m16_simm8_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2045 return m16_check_op (op
, - 0x80, 0x7f, 0);
2049 m16_nsimm8_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2051 return m16_check_op (op
, - 0x7f, 0x80, 0);
2055 m16_uimm8_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2057 return m16_check_op (op
, 0x0, 0xff, 0);
2061 m16_nuimm8_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2063 return m16_check_op (op
, - 0xff, 0x0, 0);
2067 m16_uimm8_m1_1 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2069 return m16_check_op (op
, - 0x1, 0xfe, 0);
2073 m16_uimm8_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2075 return m16_check_op (op
, 0x0, 0xff << 2, 3);
2079 m16_nuimm8_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2081 return m16_check_op (op
, (- 0xff) << 2, 0x0, 3);
2085 m16_simm8_8 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2087 return m16_check_op (op
, (- 0x80) << 3, 0x7f << 3, 7);
2091 m16_nsimm8_8 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2093 return m16_check_op (op
, (- 0x7f) << 3, 0x80 << 3, 7);
2096 /* References to the string table on the mips16 only use a small
2097 offset if the function is small. We can't check for LABEL_REF here,
2098 because the offset is always large if the label is before the
2099 referencing instruction. */
2102 m16_usym8_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2104 if (GET_CODE (op
) == SYMBOL_REF
2105 && SYMBOL_REF_FLAG (op
)
2106 && cfun
->machine
->insns_len
> 0
2107 && (cfun
->machine
->insns_len
+ get_pool_size () + mips_string_length
2110 struct string_constant
*l
;
2112 /* Make sure this symbol is on thelist of string constants to be
2113 output for this function. It is possible that it has already
2114 been output, in which case this requires a large offset. */
2115 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
2116 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
2124 m16_usym5_4 (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2126 if (GET_CODE (op
) == SYMBOL_REF
2127 && SYMBOL_REF_FLAG (op
)
2128 && cfun
->machine
->insns_len
> 0
2129 && (cfun
->machine
->insns_len
+ get_pool_size () + mips_string_length
2132 struct string_constant
*l
;
2134 /* Make sure this symbol is on thelist of string constants to be
2135 output for this function. It is possible that it has already
2136 been output, in which case this requires a large offset. */
2137 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
2138 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
2146 mips_rtx_costs (rtx x
, int code
, int outer_code
, int *total
)
2148 enum machine_mode mode
= GET_MODE (x
);
2155 /* Always return 0, since we don't have different sized
2156 instructions, hence different costs according to Richard
2162 /* A number between 1 and 8 inclusive is efficient for a shift.
2163 Otherwise, we will need an extended instruction. */
2164 if ((outer_code
) == ASHIFT
|| (outer_code
) == ASHIFTRT
2165 || (outer_code
) == LSHIFTRT
)
2167 if (INTVAL (x
) >= 1 && INTVAL (x
) <= 8)
2170 *total
= COSTS_N_INSNS (1);
2174 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2175 if ((outer_code
) == XOR
2176 && INTVAL (x
) >= 0 && INTVAL (x
) < 0x10000)
2182 /* We may be able to use slt or sltu for a comparison with a
2183 signed 16 bit value. (The boundary conditions aren't quite
2184 right, but this is just a heuristic anyhow.) */
2185 if (((outer_code
) == LT
|| (outer_code
) == LE
2186 || (outer_code
) == GE
|| (outer_code
) == GT
2187 || (outer_code
) == LTU
|| (outer_code
) == LEU
2188 || (outer_code
) == GEU
|| (outer_code
) == GTU
)
2189 && INTVAL (x
) >= -0x8000 && INTVAL (x
) < 0x8000)
2195 /* Equality comparisons with 0 are cheap. */
2196 if (((outer_code
) == EQ
|| (outer_code
) == NE
)
2203 /* Otherwise fall through to the handling below. */
2209 if (LEGITIMATE_CONSTANT_P (x
))
2211 *total
= COSTS_N_INSNS (1);
2216 /* The value will need to be fetched from the constant pool. */
2217 *total
= CONSTANT_POOL_COST
;
2223 /* If the address is legitimate, return the number of
2224 instructions it needs, otherwise use the default handling. */
2225 int n
= mips_address_insns (XEXP (x
, 0), GET_MODE (x
));
2228 *total
= COSTS_N_INSNS (1 + n
);
2235 *total
= COSTS_N_INSNS (6);
2239 *total
= COSTS_N_INSNS ((mode
== DImode
&& !TARGET_64BIT
) ? 2 : 1);
2245 if (mode
== DImode
&& !TARGET_64BIT
)
2247 *total
= COSTS_N_INSNS (2);
2255 if (mode
== DImode
&& !TARGET_64BIT
)
2257 *total
= COSTS_N_INSNS ((GET_CODE (XEXP (x
, 1)) == CONST_INT
)
2264 if (mode
== SFmode
|| mode
== DFmode
)
2265 *total
= COSTS_N_INSNS (1);
2267 *total
= COSTS_N_INSNS (4);
2271 *total
= COSTS_N_INSNS (1);
2276 if (mode
== SFmode
|| mode
== DFmode
)
2278 if (TUNE_MIPS3000
|| TUNE_MIPS3900
)
2279 *total
= COSTS_N_INSNS (2);
2280 else if (TUNE_MIPS6000
)
2281 *total
= COSTS_N_INSNS (3);
2283 *total
= COSTS_N_INSNS (6);
2286 if (mode
== DImode
&& !TARGET_64BIT
)
2288 *total
= COSTS_N_INSNS (4);
2294 if (mode
== DImode
&& !TARGET_64BIT
)
2307 *total
= COSTS_N_INSNS (4);
2308 else if (TUNE_MIPS6000
2311 *total
= COSTS_N_INSNS (5);
2313 *total
= COSTS_N_INSNS (7);
2322 *total
= COSTS_N_INSNS (5);
2323 else if (TUNE_MIPS6000
2326 *total
= COSTS_N_INSNS (6);
2328 *total
= COSTS_N_INSNS (8);
2333 *total
= COSTS_N_INSNS (12);
2334 else if (TUNE_MIPS3900
)
2335 *total
= COSTS_N_INSNS (2);
2336 else if (TUNE_MIPS5400
|| TUNE_MIPS5500
)
2337 *total
= COSTS_N_INSNS ((mode
== DImode
) ? 4 : 3);
2338 else if (TUNE_MIPS7000
)
2339 *total
= COSTS_N_INSNS (mode
== DImode
? 9 : 5);
2340 else if (TUNE_MIPS9000
)
2341 *total
= COSTS_N_INSNS (mode
== DImode
? 8 : 3);
2342 else if (TUNE_MIPS6000
)
2343 *total
= COSTS_N_INSNS (17);
2344 else if (TUNE_MIPS5000
)
2345 *total
= COSTS_N_INSNS (5);
2347 *total
= COSTS_N_INSNS (10);
2356 *total
= COSTS_N_INSNS (12);
2357 else if (TUNE_MIPS6000
)
2358 *total
= COSTS_N_INSNS (15);
2359 else if (TUNE_MIPS5400
|| TUNE_MIPS5500
)
2360 *total
= COSTS_N_INSNS (30);
2362 *total
= COSTS_N_INSNS (23);
2370 *total
= COSTS_N_INSNS (19);
2371 else if (TUNE_MIPS5400
|| TUNE_MIPS5500
)
2372 *total
= COSTS_N_INSNS (59);
2373 else if (TUNE_MIPS6000
)
2374 *total
= COSTS_N_INSNS (16);
2376 *total
= COSTS_N_INSNS (36);
2385 *total
= COSTS_N_INSNS (35);
2386 else if (TUNE_MIPS6000
)
2387 *total
= COSTS_N_INSNS (38);
2388 else if (TUNE_MIPS5000
)
2389 *total
= COSTS_N_INSNS (36);
2390 else if (TUNE_MIPS5400
|| TUNE_MIPS5500
)
2391 *total
= COSTS_N_INSNS ((mode
== SImode
) ? 42 : 74);
2393 *total
= COSTS_N_INSNS (69);
2397 /* A sign extend from SImode to DImode in 64 bit mode is often
2398 zero instructions, because the result can often be used
2399 directly by another instruction; we'll call it one. */
2400 if (TARGET_64BIT
&& mode
== DImode
2401 && GET_MODE (XEXP (x
, 0)) == SImode
)
2402 *total
= COSTS_N_INSNS (1);
2404 *total
= COSTS_N_INSNS (2);
2408 if (TARGET_64BIT
&& mode
== DImode
2409 && GET_MODE (XEXP (x
, 0)) == SImode
)
2410 *total
= COSTS_N_INSNS (2);
2412 *total
= COSTS_N_INSNS (1);
2420 /* Provide the costs of an addressing mode that contains ADDR.
2421 If ADDR is not a valid address, its cost is irrelevant. */
2424 mips_address_cost (rtx addr
)
2426 return mips_address_insns (addr
, SImode
);
2429 /* Return a pseudo that points to the address of the current function.
2430 The first time it is called for a function, an initializer for the
2431 pseudo is emitted in the beginning of the function. */
2434 embedded_pic_fnaddr_reg (void)
2436 if (cfun
->machine
->embedded_pic_fnaddr_rtx
== NULL
)
2440 cfun
->machine
->embedded_pic_fnaddr_rtx
= gen_reg_rtx (Pmode
);
2442 /* Output code at function start to initialize the pseudo-reg. */
2443 /* ??? We used to do this in FINALIZE_PIC, but that does not work for
2444 inline functions, because it is called after RTL for the function
2445 has been copied. The pseudo-reg in embedded_pic_fnaddr_rtx however
2446 does not get copied, and ends up not matching the rest of the RTL.
2447 This solution works, but means that we get unnecessary code to
2448 initialize this value every time a function is inlined into another
2451 emit_insn (gen_get_fnaddr (cfun
->machine
->embedded_pic_fnaddr_rtx
,
2452 XEXP (DECL_RTL (current_function_decl
), 0)));
2455 push_topmost_sequence ();
2456 emit_insn_after (seq
, get_insns ());
2457 pop_topmost_sequence ();
2460 return cfun
->machine
->embedded_pic_fnaddr_rtx
;
2463 /* Return RTL for the offset from the current function to the argument.
2464 X is the symbol whose offset from the current function we want. */
2467 embedded_pic_offset (rtx x
)
2469 /* Make sure it is emitted. */
2470 embedded_pic_fnaddr_reg ();
2473 gen_rtx_CONST (Pmode
,
2474 gen_rtx_MINUS (Pmode
, x
,
2475 XEXP (DECL_RTL (current_function_decl
), 0)));
2478 /* Return one word of double-word value OP, taking into account the fixed
2479 endianness of certain registers. HIGH_P is true to select the high part,
2480 false to select the low part. */
2483 mips_subword (rtx op
, int high_p
)
2486 enum machine_mode mode
;
2488 mode
= GET_MODE (op
);
2489 if (mode
== VOIDmode
)
2492 if (TARGET_BIG_ENDIAN
? !high_p
: high_p
)
2493 byte
= UNITS_PER_WORD
;
2497 if (GET_CODE (op
) == REG
)
2499 if (FP_REG_P (REGNO (op
)))
2500 return gen_rtx_REG (word_mode
, high_p
? REGNO (op
) + 1 : REGNO (op
));
2501 if (REGNO (op
) == HI_REGNUM
)
2502 return gen_rtx_REG (word_mode
, high_p
? HI_REGNUM
: LO_REGNUM
);
2505 if (GET_CODE (op
) == MEM
)
2506 return mips_rewrite_small_data (adjust_address (op
, word_mode
, byte
));
2508 return simplify_gen_subreg (word_mode
, op
, mode
, byte
);
2512 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2515 mips_split_64bit_move_p (rtx dest
, rtx src
)
2520 /* FP->FP moves can be done in a single instruction. */
2521 if (FP_REG_RTX_P (src
) && FP_REG_RTX_P (dest
))
2524 /* Check for floating-point loads and stores. They can be done using
2525 ldc1 and sdc1 on MIPS II and above. */
2528 if (FP_REG_RTX_P (dest
) && GET_CODE (src
) == MEM
)
2530 if (FP_REG_RTX_P (src
) && GET_CODE (dest
) == MEM
)
2537 /* Split a 64-bit move from SRC to DEST assuming that
2538 mips_split_64bit_move_p holds.
2540 Moves into and out of FPRs cause some difficulty here. Such moves
2541 will always be DFmode, since paired FPRs are not allowed to store
2542 DImode values. The most natural representation would be two separate
2543 32-bit moves, such as:
2545 (set (reg:SI $f0) (mem:SI ...))
2546 (set (reg:SI $f1) (mem:SI ...))
2548 However, the second insn is invalid because odd-numbered FPRs are
2549 not allowed to store independent values. Use the patterns load_df_low,
2550 load_df_high and store_df_high instead. */
2553 mips_split_64bit_move (rtx dest
, rtx src
)
2555 if (FP_REG_RTX_P (dest
))
2557 /* Loading an FPR from memory or from GPRs. */
2558 emit_insn (gen_load_df_low (copy_rtx (dest
), mips_subword (src
, 0)));
2559 emit_insn (gen_load_df_high (dest
, mips_subword (src
, 1),
2562 else if (FP_REG_RTX_P (src
))
2564 /* Storing an FPR into memory or GPRs. */
2565 emit_move_insn (mips_subword (dest
, 0), mips_subword (src
, 0));
2566 emit_insn (gen_store_df_high (mips_subword (dest
, 1), src
));
2570 /* The operation can be split into two normal moves. Decide in
2571 which order to do them. */
2574 low_dest
= mips_subword (dest
, 0);
2575 if (GET_CODE (low_dest
) == REG
2576 && reg_overlap_mentioned_p (low_dest
, src
))
2578 emit_move_insn (mips_subword (dest
, 1), mips_subword (src
, 1));
2579 emit_move_insn (low_dest
, mips_subword (src
, 0));
2583 emit_move_insn (low_dest
, mips_subword (src
, 0));
2584 emit_move_insn (mips_subword (dest
, 1), mips_subword (src
, 1));
2589 /* Return the appropriate instructions to move SRC into DEST. Assume
2590 that SRC is operand 1 and DEST is operand 0. */
2593 mips_output_move (rtx dest
, rtx src
)
2595 enum rtx_code dest_code
, src_code
;
2598 dest_code
= GET_CODE (dest
);
2599 src_code
= GET_CODE (src
);
2600 dbl_p
= (GET_MODE_SIZE (GET_MODE (dest
)) == 8);
2602 if (dbl_p
&& mips_split_64bit_move_p (dest
, src
))
2605 if ((src_code
== REG
&& GP_REG_P (REGNO (src
)))
2606 || (!TARGET_MIPS16
&& src
== CONST0_RTX (GET_MODE (dest
))))
2608 if (dest_code
== REG
)
2610 if (GP_REG_P (REGNO (dest
)))
2611 return "move\t%0,%z1";
2613 if (MD_REG_P (REGNO (dest
)))
2616 if (FP_REG_P (REGNO (dest
)))
2617 return (dbl_p
? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2619 if (ALL_COP_REG_P (REGNO (dest
)))
2621 static char retval
[] = "dmtc_\t%z1,%0";
2623 retval
[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest
));
2624 return (dbl_p
? retval
: retval
+ 1);
2627 if (dest_code
== MEM
)
2628 return (dbl_p
? "sd\t%z1,%0" : "sw\t%z1,%0");
2630 if (dest_code
== REG
&& GP_REG_P (REGNO (dest
)))
2632 if (src_code
== REG
)
2634 if (MD_REG_P (REGNO (src
)))
2637 if (ST_REG_P (REGNO (src
)) && ISA_HAS_8CC
)
2638 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2640 if (FP_REG_P (REGNO (src
)))
2641 return (dbl_p
? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2643 if (ALL_COP_REG_P (REGNO (src
)))
2645 static char retval
[] = "dmfc_\t%0,%1";
2647 retval
[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src
));
2648 return (dbl_p
? retval
: retval
+ 1);
2652 if (src_code
== MEM
)
2653 return (dbl_p
? "ld\t%0,%1" : "lw\t%0,%1");
2655 if (src_code
== CONST_INT
)
2657 /* Don't use the X format, because that will give out of
2658 range numbers for 64 bit hosts and 32 bit targets. */
2660 return "li\t%0,%1\t\t\t# %X1";
2662 if (INTVAL (src
) >= 0 && INTVAL (src
) <= 0xffff)
2665 if (INTVAL (src
) < 0 && INTVAL (src
) >= -0xffff)
2666 return "li\t%0,%n1\n\tneg\t%0";
2669 if (src_code
== HIGH
)
2670 return "lui\t%0,%h1";
2672 if (CONST_GP_P (src
))
2673 return "move\t%0,%1";
2675 if (symbolic_operand (src
, VOIDmode
))
2676 return (dbl_p
? "dla\t%0,%1" : "la\t%0,%1");
2678 if (src_code
== REG
&& FP_REG_P (REGNO (src
)))
2680 if (dest_code
== REG
&& FP_REG_P (REGNO (dest
)))
2681 return (dbl_p
? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2683 if (dest_code
== MEM
)
2684 return (dbl_p
? "sdc1\t%1,%0" : "swc1\t%1,%0");
2686 if (dest_code
== REG
&& FP_REG_P (REGNO (dest
)))
2688 if (src_code
== MEM
)
2689 return (dbl_p
? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2691 if (dest_code
== REG
&& ALL_COP_REG_P (REGNO (dest
)) && src_code
== MEM
)
2693 static char retval
[] = "l_c_\t%0,%1";
2695 retval
[1] = (dbl_p
? 'd' : 'w');
2696 retval
[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest
));
2699 if (dest_code
== MEM
&& src_code
== REG
&& ALL_COP_REG_P (REGNO (src
)))
2701 static char retval
[] = "s_c_\t%1,%0";
2703 retval
[1] = (dbl_p
? 'd' : 'w');
2704 retval
[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src
));
2710 /* Return an rtx for the gp save slot. Valid only when using o32 or
2714 mips_gp_save_slot (void)
2718 if (!TARGET_ABICALLS
|| TARGET_NEWABI
)
2721 if (frame_pointer_needed
)
2722 loc
= hard_frame_pointer_rtx
;
2724 loc
= stack_pointer_rtx
;
2725 loc
= plus_constant (loc
, current_function_outgoing_args_size
);
2726 loc
= gen_rtx_MEM (Pmode
, loc
);
2727 RTX_UNCHANGING_P (loc
) = 1;
2731 /* Make normal rtx_code into something we can index from an array */
2733 static enum internal_test
2734 map_test_to_internal_test (enum rtx_code test_code
)
2736 enum internal_test test
= ITEST_MAX
;
2740 case EQ
: test
= ITEST_EQ
; break;
2741 case NE
: test
= ITEST_NE
; break;
2742 case GT
: test
= ITEST_GT
; break;
2743 case GE
: test
= ITEST_GE
; break;
2744 case LT
: test
= ITEST_LT
; break;
2745 case LE
: test
= ITEST_LE
; break;
2746 case GTU
: test
= ITEST_GTU
; break;
2747 case GEU
: test
= ITEST_GEU
; break;
2748 case LTU
: test
= ITEST_LTU
; break;
2749 case LEU
: test
= ITEST_LEU
; break;
2757 /* Generate the code to compare two integer values. The return value is:
2758 (reg:SI xx) The pseudo register the comparison is in
2759 0 No register, generate a simple branch.
2761 ??? This is called with result nonzero by the Scond patterns in
2762 mips.md. These patterns are called with a target in the mode of
2763 the Scond instruction pattern. Since this must be a constant, we
2764 must use SImode. This means that if RESULT is nonzero, it will
2765 always be an SImode register, even if TARGET_64BIT is true. We
2766 cope with this by calling convert_move rather than emit_move_insn.
2767 This will sometimes lead to an unnecessary extension of the result;
2776 TEST_CODE is the rtx code for the comparison.
2777 CMP0 and CMP1 are the two operands to compare.
2778 RESULT is the register in which the result should be stored (null for
2780 For branches, P_INVERT points to an integer that is nonzero on return
2781 if the branch should be inverted. */
2784 gen_int_relational (enum rtx_code test_code
, rtx result
, rtx cmp0
,
2785 rtx cmp1
, int *p_invert
)
2789 enum rtx_code test_code
; /* code to use in instruction (LT vs. LTU) */
2790 int const_low
; /* low bound of constant we can accept */
2791 int const_high
; /* high bound of constant we can accept */
2792 int const_add
; /* constant to add (convert LE -> LT) */
2793 int reverse_regs
; /* reverse registers in test */
2794 int invert_const
; /* != 0 if invert value if cmp1 is constant */
2795 int invert_reg
; /* != 0 if invert value if cmp1 is register */
2796 int unsignedp
; /* != 0 for unsigned comparisons. */
2799 static const struct cmp_info info
[ (int)ITEST_MAX
] = {
2801 { XOR
, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
2802 { XOR
, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
2803 { LT
, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
2804 { LT
, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
2805 { LT
, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
2806 { LT
, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
2807 { LTU
, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
2808 { LTU
, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
2809 { LTU
, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
2810 { LTU
, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
2813 enum internal_test test
;
2814 enum machine_mode mode
;
2815 const struct cmp_info
*p_info
;
2822 test
= map_test_to_internal_test (test_code
);
2823 if (test
== ITEST_MAX
)
2826 p_info
= &info
[(int) test
];
2827 eqne_p
= (p_info
->test_code
== XOR
);
2829 mode
= GET_MODE (cmp0
);
2830 if (mode
== VOIDmode
)
2831 mode
= GET_MODE (cmp1
);
2833 /* Eliminate simple branches */
2834 branch_p
= (result
== 0);
2837 if (GET_CODE (cmp0
) == REG
|| GET_CODE (cmp0
) == SUBREG
)
2839 /* Comparisons against zero are simple branches */
2840 if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0
2841 && (! TARGET_MIPS16
|| eqne_p
))
2844 /* Test for beq/bne. */
2845 if (eqne_p
&& ! TARGET_MIPS16
)
2849 /* Allocate a pseudo to calculate the value in. */
2850 result
= gen_reg_rtx (mode
);
2853 /* Make sure we can handle any constants given to us. */
2854 if (GET_CODE (cmp0
) == CONST_INT
)
2855 cmp0
= force_reg (mode
, cmp0
);
2857 if (GET_CODE (cmp1
) == CONST_INT
)
2859 HOST_WIDE_INT value
= INTVAL (cmp1
);
2861 if (value
< p_info
->const_low
2862 || value
> p_info
->const_high
2863 /* ??? Why? And why wasn't the similar code below modified too? */
2865 && HOST_BITS_PER_WIDE_INT
< 64
2866 && p_info
->const_add
!= 0
2867 && ((p_info
->unsignedp
2868 ? ((unsigned HOST_WIDE_INT
) (value
+ p_info
->const_add
)
2869 > (unsigned HOST_WIDE_INT
) INTVAL (cmp1
))
2870 : (value
+ p_info
->const_add
) > INTVAL (cmp1
))
2871 != (p_info
->const_add
> 0))))
2872 cmp1
= force_reg (mode
, cmp1
);
2875 /* See if we need to invert the result. */
2876 invert
= (GET_CODE (cmp1
) == CONST_INT
2877 ? p_info
->invert_const
: p_info
->invert_reg
);
2879 if (p_invert
!= (int *)0)
2885 /* Comparison to constants, may involve adding 1 to change a LT into LE.
2886 Comparison between two registers, may involve switching operands. */
2887 if (GET_CODE (cmp1
) == CONST_INT
)
2889 if (p_info
->const_add
!= 0)
2891 HOST_WIDE_INT
new = INTVAL (cmp1
) + p_info
->const_add
;
2893 /* If modification of cmp1 caused overflow,
2894 we would get the wrong answer if we follow the usual path;
2895 thus, x > 0xffffffffU would turn into x > 0U. */
2896 if ((p_info
->unsignedp
2897 ? (unsigned HOST_WIDE_INT
) new >
2898 (unsigned HOST_WIDE_INT
) INTVAL (cmp1
)
2899 : new > INTVAL (cmp1
))
2900 != (p_info
->const_add
> 0))
2902 /* This test is always true, but if INVERT is true then
2903 the result of the test needs to be inverted so 0 should
2904 be returned instead. */
2905 emit_move_insn (result
, invert
? const0_rtx
: const_true_rtx
);
2909 cmp1
= GEN_INT (new);
2913 else if (p_info
->reverse_regs
)
2920 if (test
== ITEST_NE
&& GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0)
2924 reg
= (invert
|| eqne_p
) ? gen_reg_rtx (mode
) : result
;
2925 convert_move (reg
, gen_rtx (p_info
->test_code
, mode
, cmp0
, cmp1
), 0);
2928 if (test
== ITEST_NE
)
2930 if (! TARGET_MIPS16
)
2932 convert_move (result
, gen_rtx (GTU
, mode
, reg
, const0_rtx
), 0);
2933 if (p_invert
!= NULL
)
2939 reg2
= invert
? gen_reg_rtx (mode
) : result
;
2940 convert_move (reg2
, gen_rtx (LTU
, mode
, reg
, const1_rtx
), 0);
2945 else if (test
== ITEST_EQ
)
2947 reg2
= invert
? gen_reg_rtx (mode
) : result
;
2948 convert_move (reg2
, gen_rtx_LTU (mode
, reg
, const1_rtx
), 0);
2956 if (! TARGET_MIPS16
)
2960 /* The value is in $24. Copy it to another register, so
2961 that reload doesn't think it needs to store the $24 and
2962 the input to the XOR in the same location. */
2963 reg2
= gen_reg_rtx (mode
);
2964 emit_move_insn (reg2
, reg
);
2966 one
= force_reg (mode
, const1_rtx
);
2968 convert_move (result
, gen_rtx (XOR
, mode
, reg
, one
), 0);
2974 /* Work out how to check a floating-point condition. We need a
2975 separate comparison instruction (C.cond.fmt), followed by a
2976 branch or conditional move. Given that IN_CODE is the
2977 required condition, set *CMP_CODE to the C.cond.fmt code
2978 and *action_code to the branch or move code. */
2981 get_float_compare_codes (enum rtx_code in_code
, enum rtx_code
*cmp_code
,
2982 enum rtx_code
*action_code
)
2991 *cmp_code
= reverse_condition_maybe_unordered (in_code
);
2996 *cmp_code
= in_code
;
3002 /* Emit the common code for doing conditional branches.
3003 operand[0] is the label to jump to.
3004 The comparison operands are saved away by cmp{si,di,sf,df}. */
3007 gen_conditional_branch (rtx
*operands
, enum rtx_code test_code
)
3009 enum cmp_type type
= branch_type
;
3010 rtx cmp0
= branch_cmp
[0];
3011 rtx cmp1
= branch_cmp
[1];
3012 enum machine_mode mode
;
3013 enum rtx_code cmp_code
;
3022 mode
= type
== CMP_SI
? SImode
: DImode
;
3024 reg
= gen_int_relational (test_code
, NULL_RTX
, cmp0
, cmp1
, &invert
);
3032 else if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) != 0)
3033 /* We don't want to build a comparison against a nonzero
3035 cmp1
= force_reg (mode
, cmp1
);
3042 reg
= gen_rtx_REG (CCmode
, FPSW_REGNUM
);
3044 reg
= gen_reg_rtx (CCmode
);
3046 get_float_compare_codes (test_code
, &cmp_code
, &test_code
);
3047 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
3048 gen_rtx (cmp_code
, CCmode
, cmp0
, cmp1
)));
3057 fatal_insn ("bad test", gen_rtx (test_code
, VOIDmode
, cmp0
, cmp1
));
3060 /* Generate the branch. */
3062 label1
= gen_rtx_LABEL_REF (VOIDmode
, operands
[0]);
3071 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
,
3072 gen_rtx_IF_THEN_ELSE (VOIDmode
,
3073 gen_rtx (test_code
, mode
,
3078 /* Emit the common code for conditional moves. OPERANDS is the array
3079 of operands passed to the conditional move define_expand. */
3082 gen_conditional_move (rtx
*operands
)
3084 rtx op0
= branch_cmp
[0];
3085 rtx op1
= branch_cmp
[1];
3086 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3087 enum rtx_code cmp_code
= GET_CODE (operands
[1]);
3088 enum rtx_code move_code
= NE
;
3089 enum machine_mode op_mode
= GET_MODE (operands
[0]);
3090 enum machine_mode cmp_mode
;
3093 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
3112 op0
= force_reg (mode
, branch_cmp
[1]);
3113 op1
= branch_cmp
[0];
3117 op0
= force_reg (mode
, branch_cmp
[1]);
3118 op1
= branch_cmp
[0];
3129 op0
= force_reg (mode
, branch_cmp
[1]);
3130 op1
= branch_cmp
[0];
3134 op0
= force_reg (mode
, branch_cmp
[1]);
3135 op1
= branch_cmp
[0];
3143 get_float_compare_codes (cmp_code
, &cmp_code
, &move_code
);
3145 if (mode
== SImode
|| mode
== DImode
)
3147 else if (mode
== SFmode
|| mode
== DFmode
)
3152 cmp_reg
= gen_reg_rtx (cmp_mode
);
3153 emit_insn (gen_rtx_SET (cmp_mode
, cmp_reg
,
3154 gen_rtx (cmp_code
, cmp_mode
, op0
, op1
)));
3156 emit_insn (gen_rtx_SET (op_mode
, operands
[0],
3157 gen_rtx_IF_THEN_ELSE (op_mode
,
3158 gen_rtx (move_code
, VOIDmode
,
3160 CONST0_RTX (SImode
)),
3161 operands
[2], operands
[3])));
3164 /* Emit a conditional trap. OPERANDS is the array of operands passed to
3165 the conditional_trap expander. */
3168 mips_gen_conditional_trap (rtx
*operands
)
3171 enum rtx_code cmp_code
= GET_CODE (operands
[0]);
3172 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3174 /* MIPS conditional trap machine instructions don't have GT or LE
3175 flavors, so we must invert the comparison and convert to LT and
3176 GE, respectively. */
3179 case GT
: cmp_code
= LT
; break;
3180 case LE
: cmp_code
= GE
; break;
3181 case GTU
: cmp_code
= LTU
; break;
3182 case LEU
: cmp_code
= GEU
; break;
3185 if (cmp_code
== GET_CODE (operands
[0]))
3187 op0
= force_reg (mode
, branch_cmp
[0]);
3188 op1
= branch_cmp
[1];
3192 op0
= force_reg (mode
, branch_cmp
[1]);
3193 op1
= branch_cmp
[0];
3195 if (GET_CODE (op1
) == CONST_INT
&& ! SMALL_INT (op1
))
3196 op1
= force_reg (mode
, op1
);
3198 emit_insn (gen_rtx_TRAP_IF (VOIDmode
,
3199 gen_rtx (cmp_code
, GET_MODE (operands
[0]), op0
, op1
),
3203 /* Expand a call or call_value instruction. RESULT is where the
3204 result will go (null for calls), ADDR is the address of the
3205 function, ARGS_SIZE is the size of the arguments and AUX is
3206 the value passed to us by mips_function_arg. SIBCALL_P is true
3207 if we are expanding a sibling call, false if we're expanding
3211 mips_expand_call (rtx result
, rtx addr
, rtx args_size
, rtx aux
, int sibcall_p
)
3213 if (!call_insn_operand (addr
, VOIDmode
))
3215 /* If we're generating PIC, and this call is to a global function,
3216 try to allow its address to be resolved lazily. This isn't
3217 possible for NewABI sibcalls since the value of $gp on entry
3218 to the stub would be our caller's gp, not ours. */
3219 if (TARGET_EXPLICIT_RELOCS
3220 && !(sibcall_p
&& TARGET_NEWABI
)
3221 && global_got_operand (addr
, VOIDmode
))
3223 rtx high
, lo_sum_symbol
;
3225 high
= mips_unspec_offset_high (pic_offset_table_rtx
,
3226 addr
, SYMBOL_GOTOFF_CALL
);
3227 lo_sum_symbol
= mips_unspec_address (addr
, SYMBOL_GOTOFF_CALL
);
3228 addr
= gen_reg_rtx (Pmode
);
3229 if (Pmode
== SImode
)
3230 emit_insn (gen_load_callsi (addr
, high
, lo_sum_symbol
));
3232 emit_insn (gen_load_calldi (addr
, high
, lo_sum_symbol
));
3235 addr
= force_reg (Pmode
, addr
);
3239 && mips16_hard_float
3240 && build_mips16_call_stub (result
, addr
, args_size
,
3241 aux
== 0 ? 0 : (int) GET_MODE (aux
)))
3242 /* Nothing more to do */;
3243 else if (result
== 0)
3244 emit_call_insn (sibcall_p
3245 ? gen_sibcall_internal (addr
, args_size
)
3246 : gen_call_internal (addr
, args_size
));
3247 else if (GET_CODE (result
) == PARALLEL
&& XVECLEN (result
, 0) == 2)
3251 reg1
= XEXP (XVECEXP (result
, 0, 0), 0);
3252 reg2
= XEXP (XVECEXP (result
, 0, 1), 0);
3255 ? gen_sibcall_value_multiple_internal (reg1
, addr
, args_size
, reg2
)
3256 : gen_call_value_multiple_internal (reg1
, addr
, args_size
, reg2
));
3259 emit_call_insn (sibcall_p
3260 ? gen_sibcall_value_internal (result
, addr
, args_size
)
3261 : gen_call_value_internal (result
, addr
, args_size
));
3265 /* We can handle any sibcall when TARGET_SIBCALLS is true. */
3268 mips_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED
,
3269 tree exp ATTRIBUTE_UNUSED
)
3271 return TARGET_SIBCALLS
;
3274 /* Return true if operand OP is a condition code register.
3275 Only for use during or after reload. */
3278 fcc_register_operand (rtx op
, enum machine_mode mode
)
3280 return ((mode
== VOIDmode
|| mode
== GET_MODE (op
))
3281 && (reload_in_progress
|| reload_completed
)
3282 && (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
3283 && ST_REG_P (true_regnum (op
)));
3286 /* Emit code to move general operand SRC into condition-code
3287 register DEST. SCRATCH is a scratch TFmode float register.
3294 where FP1 and FP2 are single-precision float registers
3295 taken from SCRATCH. */
3298 mips_emit_fcc_reload (rtx dest
, rtx src
, rtx scratch
)
3302 /* Change the source to SFmode. */
3303 if (GET_CODE (src
) == MEM
)
3304 src
= adjust_address (src
, SFmode
, 0);
3305 else if (GET_CODE (src
) == REG
|| GET_CODE (src
) == SUBREG
)
3306 src
= gen_rtx_REG (SFmode
, true_regnum (src
));
3308 fp1
= gen_rtx_REG (SFmode
, REGNO (scratch
));
3309 fp2
= gen_rtx_REG (SFmode
, REGNO (scratch
) + FP_INC
);
3311 emit_move_insn (copy_rtx (fp1
), src
);
3312 emit_move_insn (copy_rtx (fp2
), CONST0_RTX (SFmode
));
3313 emit_insn (gen_slt_sf (dest
, fp2
, fp1
));
3316 /* Emit code to change the current function's return address to
3317 ADDRESS. SCRATCH is available as a scratch register, if needed.
3318 ADDRESS and SCRATCH are both word-mode GPRs. */
3321 mips_set_return_address (rtx address
, rtx scratch
)
3323 HOST_WIDE_INT gp_offset
;
3325 compute_frame_size (get_frame_size ());
3326 if (((cfun
->machine
->frame
.mask
>> 31) & 1) == 0)
3328 gp_offset
= cfun
->machine
->frame
.gp_sp_offset
;
3330 /* Reduce SP + GP_OFSET to a legitimate address and put it in SCRATCH. */
3331 if (gp_offset
< 32768)
3332 scratch
= plus_constant (stack_pointer_rtx
, gp_offset
);
3335 emit_move_insn (scratch
, GEN_INT (gp_offset
));
3336 if (Pmode
== DImode
)
3337 emit_insn (gen_adddi3 (scratch
, scratch
, stack_pointer_rtx
));
3339 emit_insn (gen_addsi3 (scratch
, scratch
, stack_pointer_rtx
));
3342 emit_move_insn (gen_rtx_MEM (GET_MODE (address
), scratch
), address
);
3345 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
3346 Assume that the areas do not overlap. */
3349 mips_block_move_straight (rtx dest
, rtx src
, HOST_WIDE_INT length
)
3351 HOST_WIDE_INT offset
, delta
;
3352 unsigned HOST_WIDE_INT bits
;
3354 enum machine_mode mode
;
3357 /* Work out how many bits to move at a time. If both operands have
3358 half-word alignment, it is usually better to move in half words.
3359 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
3360 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
3361 Otherwise move word-sized chunks. */
3362 if (MEM_ALIGN (src
) == BITS_PER_WORD
/ 2
3363 && MEM_ALIGN (dest
) == BITS_PER_WORD
/ 2)
3364 bits
= BITS_PER_WORD
/ 2;
3366 bits
= BITS_PER_WORD
;
3368 mode
= mode_for_size (bits
, MODE_INT
, 0);
3369 delta
= bits
/ BITS_PER_UNIT
;
3371 /* Allocate a buffer for the temporary registers. */
3372 regs
= alloca (sizeof (rtx
) * length
/ delta
);
3374 /* Load as many BITS-sized chunks as possible. Use a normal load if
3375 the source has enough alignment, otherwise use left/right pairs. */
3376 for (offset
= 0, i
= 0; offset
+ delta
<= length
; offset
+= delta
, i
++)
3380 regs
[i
] = gen_reg_rtx (mode
);
3381 part
= adjust_address (src
, mode
, offset
);
3382 if (MEM_ALIGN (part
) >= bits
)
3383 emit_move_insn (regs
[i
], part
);
3384 else if (!mips_expand_unaligned_load (regs
[i
], part
, bits
, 0))
3388 /* Copy the chunks to the destination. */
3389 for (offset
= 0, i
= 0; offset
+ delta
<= length
; offset
+= delta
, i
++)
3393 part
= adjust_address (dest
, mode
, offset
);
3394 if (MEM_ALIGN (part
) >= bits
)
3395 emit_move_insn (part
, regs
[i
]);
3396 else if (!mips_expand_unaligned_store (part
, regs
[i
], bits
, 0))
3400 /* Mop up any left-over bytes. */
3401 if (offset
< length
)
3403 src
= adjust_address (src
, mode
, offset
);
3404 dest
= adjust_address (dest
, mode
, offset
);
3405 move_by_pieces (dest
, src
, length
- offset
,
3406 MIN (MEM_ALIGN (src
), MEM_ALIGN (dest
)), 0);
3410 #define MAX_MOVE_REGS 4
3411 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3414 /* Helper function for doing a loop-based block operation on memory
3415 reference MEM. Each iteration of the loop will operate on LENGTH
3418 Create a new base register for use within the loop and point it to
3419 the start of MEM. Create a new memory reference that uses this
3420 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
3423 mips_adjust_block_mem (rtx mem
, HOST_WIDE_INT length
,
3424 rtx
*loop_reg
, rtx
*loop_mem
)
3426 *loop_reg
= copy_addr_to_reg (XEXP (mem
, 0));
3428 /* Although the new mem does not refer to a known location,
3429 it does keep up to LENGTH bytes of alignment. */
3430 *loop_mem
= change_address (mem
, BLKmode
, *loop_reg
);
3431 set_mem_align (*loop_mem
, MIN (MEM_ALIGN (mem
), length
* BITS_PER_UNIT
));
3435 /* Move LENGTH bytes from SRC to DEST using a loop that moves MAX_MOVE_BYTES
3436 per iteration. LENGTH must be at least MAX_MOVE_BYTES. Assume that the
3437 memory regions do not overlap. */
3440 mips_block_move_loop (rtx dest
, rtx src
, HOST_WIDE_INT length
)
3442 rtx label
, src_reg
, dest_reg
, final_src
;
3443 HOST_WIDE_INT leftover
;
3445 leftover
= length
% MAX_MOVE_BYTES
;
3448 /* Create registers and memory references for use within the loop. */
3449 mips_adjust_block_mem (src
, MAX_MOVE_BYTES
, &src_reg
, &src
);
3450 mips_adjust_block_mem (dest
, MAX_MOVE_BYTES
, &dest_reg
, &dest
);
3452 /* Calculate the value that SRC_REG should have after the last iteration
3454 final_src
= expand_simple_binop (Pmode
, PLUS
, src_reg
, GEN_INT (length
),
3457 /* Emit the start of the loop. */
3458 label
= gen_label_rtx ();
3461 /* Emit the loop body. */
3462 mips_block_move_straight (dest
, src
, MAX_MOVE_BYTES
);
3464 /* Move on to the next block. */
3465 emit_move_insn (src_reg
, plus_constant (src_reg
, MAX_MOVE_BYTES
));
3466 emit_move_insn (dest_reg
, plus_constant (dest_reg
, MAX_MOVE_BYTES
));
3468 /* Emit the loop condition. */
3469 if (Pmode
== DImode
)
3470 emit_insn (gen_cmpdi (src_reg
, final_src
));
3472 emit_insn (gen_cmpsi (src_reg
, final_src
));
3473 emit_jump_insn (gen_bne (label
));
3475 /* Mop up any left-over bytes. */
3477 mips_block_move_straight (dest
, src
, leftover
);
3480 /* Expand a movstrsi instruction. */
3483 mips_expand_block_move (rtx dest
, rtx src
, rtx length
)
3485 if (GET_CODE (length
) == CONST_INT
)
3487 if (INTVAL (length
) <= 2 * MAX_MOVE_BYTES
)
3489 mips_block_move_straight (dest
, src
, INTVAL (length
));
3494 mips_block_move_loop (dest
, src
, INTVAL (length
));
3501 /* Argument support functions. */
3503 /* Initialize CUMULATIVE_ARGS for a function. */
3506 init_cumulative_args (CUMULATIVE_ARGS
*cum
, tree fntype
,
3507 rtx libname ATTRIBUTE_UNUSED
)
3509 static CUMULATIVE_ARGS zero_cum
;
3510 tree param
, next_param
;
3512 if (TARGET_DEBUG_E_MODE
)
3515 "\ninit_cumulative_args, fntype = 0x%.8lx", (long)fntype
);
3518 fputc ('\n', stderr
);
3522 tree ret_type
= TREE_TYPE (fntype
);
3523 fprintf (stderr
, ", fntype code = %s, ret code = %s\n",
3524 tree_code_name
[(int)TREE_CODE (fntype
)],
3525 tree_code_name
[(int)TREE_CODE (ret_type
)]);
3530 cum
->prototype
= (fntype
&& TYPE_ARG_TYPES (fntype
));
3532 /* Determine if this function has variable arguments. This is
3533 indicated by the last argument being 'void_type_mode' if there
3534 are no variable arguments. The standard MIPS calling sequence
3535 passes all arguments in the general purpose registers in this case. */
3537 for (param
= fntype
? TYPE_ARG_TYPES (fntype
) : 0;
3538 param
!= 0; param
= next_param
)
3540 next_param
= TREE_CHAIN (param
);
3541 if (next_param
== 0 && TREE_VALUE (param
) != void_type_node
)
3542 cum
->gp_reg_found
= 1;
3547 /* Fill INFO with information about a single argument. CUM is the
3548 cumulative state for earlier arguments. MODE is the mode of this
3549 argument and TYPE is its type (if known). NAMED is true if this
3550 is a named (fixed) argument rather than a variable one. */
3553 mips_arg_info (const CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
3554 tree type
, int named
, struct mips_arg_info
*info
)
3557 unsigned int num_words
, max_regs
;
3559 /* Decide whether this argument should go in a floating-point register,
3560 assuming one is free. Later code checks for availability. */
3562 info
->fpr_p
= (GET_MODE_CLASS (mode
) == MODE_FLOAT
3563 && GET_MODE_SIZE (mode
) <= UNITS_PER_FPVALUE
);
3570 info
->fpr_p
= (!cum
->gp_reg_found
3571 && cum
->arg_number
< 2
3572 && (type
== 0 || FLOAT_TYPE_P (type
)));
3577 info
->fpr_p
= (named
&& (type
== 0 || FLOAT_TYPE_P (type
)));
3581 /* Now decide whether the argument must go in an even-numbered register. */
3586 /* Under the O64 ABI, the second float argument goes in $f13 if it
3587 is a double, but $f14 if it is a single. Otherwise, on a
3588 32-bit double-float machine, each FP argument must start in a
3589 new register pair. */
3590 even_reg_p
= (GET_MODE_SIZE (mode
) > UNITS_PER_HWFPVALUE
3591 || (mips_abi
== ABI_O64
&& mode
== SFmode
)
3594 else if (!TARGET_64BIT
|| LONG_DOUBLE_TYPE_SIZE
== 128)
3596 if (GET_MODE_CLASS (mode
) == MODE_INT
3597 || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3598 even_reg_p
= (GET_MODE_SIZE (mode
) > UNITS_PER_WORD
);
3600 else if (type
!= NULL_TREE
&& TYPE_ALIGN (type
) > BITS_PER_WORD
)
3604 if (mips_abi
!= ABI_EABI
&& MUST_PASS_IN_STACK (mode
, type
))
3605 /* This argument must be passed on the stack. Eat up all the
3606 remaining registers. */
3607 info
->reg_offset
= MAX_ARGS_IN_REGISTERS
;
3610 /* Set REG_OFFSET to the register count we're interested in.
3611 The EABI allocates the floating-point registers separately,
3612 but the other ABIs allocate them like integer registers. */
3613 info
->reg_offset
= (mips_abi
== ABI_EABI
&& info
->fpr_p
3618 info
->reg_offset
+= info
->reg_offset
& 1;
3621 /* The alignment applied to registers is also applied to stack arguments. */
3622 info
->stack_offset
= cum
->stack_words
;
3624 info
->stack_offset
+= info
->stack_offset
& 1;
3626 if (mode
== BLKmode
)
3627 info
->num_bytes
= int_size_in_bytes (type
);
3629 info
->num_bytes
= GET_MODE_SIZE (mode
);
3631 num_words
= (info
->num_bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
3632 max_regs
= MAX_ARGS_IN_REGISTERS
- info
->reg_offset
;
3634 /* Partition the argument between registers and stack. */
3635 info
->reg_words
= MIN (num_words
, max_regs
);
3636 info
->stack_words
= num_words
- info
->reg_words
;
3640 /* Implement FUNCTION_ARG_ADVANCE. */
3643 function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
3644 tree type
, int named
)
3646 struct mips_arg_info info
;
3648 mips_arg_info (cum
, mode
, type
, named
, &info
);
3651 cum
->gp_reg_found
= true;
3653 /* See the comment above the cumulative args structure in mips.h
3654 for an explanation of what this code does. It assumes the O32
3655 ABI, which passes at most 2 arguments in float registers. */
3656 if (cum
->arg_number
< 2 && info
.fpr_p
)
3657 cum
->fp_code
+= (mode
== SFmode
? 1 : 2) << ((cum
->arg_number
- 1) * 2);
3659 if (mips_abi
!= ABI_EABI
|| !info
.fpr_p
)
3660 cum
->num_gprs
= info
.reg_offset
+ info
.reg_words
;
3661 else if (info
.reg_words
> 0)
3662 cum
->num_fprs
+= FP_INC
;
3664 if (info
.stack_words
> 0)
3665 cum
->stack_words
= info
.stack_offset
+ info
.stack_words
;
3670 /* Implement FUNCTION_ARG. */
3673 function_arg (const CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
3674 tree type
, int named
)
3676 struct mips_arg_info info
;
3678 /* We will be called with a mode of VOIDmode after the last argument
3679 has been seen. Whatever we return will be passed to the call
3680 insn. If we need a mips16 fp_code, return a REG with the code
3681 stored as the mode. */
3682 if (mode
== VOIDmode
)
3684 if (TARGET_MIPS16
&& cum
->fp_code
!= 0)
3685 return gen_rtx_REG ((enum machine_mode
) cum
->fp_code
, 0);
3691 mips_arg_info (cum
, mode
, type
, named
, &info
);
3693 /* Return straight away if the whole argument is passed on the stack. */
3694 if (info
.reg_offset
== MAX_ARGS_IN_REGISTERS
)
3698 && TREE_CODE (type
) == RECORD_TYPE
3699 && (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
)
3700 && TYPE_SIZE_UNIT (type
)
3701 && host_integerp (TYPE_SIZE_UNIT (type
), 1)
3704 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
3705 structure contains a double in its entirety, then that 64 bit
3706 chunk is passed in a floating point register. */
3709 /* First check to see if there is any such field. */
3710 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3711 if (TREE_CODE (field
) == FIELD_DECL
3712 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
3713 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
3714 && host_integerp (bit_position (field
), 0)
3715 && int_bit_position (field
) % BITS_PER_WORD
== 0)
3720 /* Now handle the special case by returning a PARALLEL
3721 indicating where each 64 bit chunk goes. INFO.REG_WORDS
3722 chunks are passed in registers. */
3724 HOST_WIDE_INT bitpos
;
3727 /* assign_parms checks the mode of ENTRY_PARM, so we must
3728 use the actual mode here. */
3729 ret
= gen_rtx_PARALLEL (mode
, rtvec_alloc (info
.reg_words
));
3732 field
= TYPE_FIELDS (type
);
3733 for (i
= 0; i
< info
.reg_words
; i
++)
3737 for (; field
; field
= TREE_CHAIN (field
))
3738 if (TREE_CODE (field
) == FIELD_DECL
3739 && int_bit_position (field
) >= bitpos
)
3743 && int_bit_position (field
) == bitpos
3744 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
3745 && !TARGET_SOFT_FLOAT
3746 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
)
3747 reg
= gen_rtx_REG (DFmode
, FP_ARG_FIRST
+ info
.reg_offset
+ i
);
3749 reg
= gen_rtx_REG (DImode
, GP_ARG_FIRST
+ info
.reg_offset
+ i
);
3752 = gen_rtx_EXPR_LIST (VOIDmode
, reg
,
3753 GEN_INT (bitpos
/ BITS_PER_UNIT
));
3755 bitpos
+= BITS_PER_WORD
;
3762 return gen_rtx_REG (mode
, FP_ARG_FIRST
+ info
.reg_offset
);
3764 return gen_rtx_REG (mode
, GP_ARG_FIRST
+ info
.reg_offset
);
3768 /* Implement FUNCTION_ARG_PARTIAL_NREGS. */
3771 function_arg_partial_nregs (const CUMULATIVE_ARGS
*cum
,
3772 enum machine_mode mode
, tree type
, int named
)
3774 struct mips_arg_info info
;
3776 mips_arg_info (cum
, mode
, type
, named
, &info
);
3777 return info
.stack_words
> 0 ? info
.reg_words
: 0;
3781 /* Return true if FUNCTION_ARG_PADDING (MODE, TYPE) should return
3782 upward rather than downward. In other words, return true if the
3783 first byte of the stack slot has useful data, false if the last
3787 mips_pad_arg_upward (enum machine_mode mode
, tree type
)
3789 /* On little-endian targets, the first byte of every stack argument
3790 is passed in the first byte of the stack slot. */
3791 if (!BYTES_BIG_ENDIAN
)
3794 /* Otherwise, integral types are padded downward: the last byte of a
3795 stack argument is passed in the last byte of the stack slot. */
3797 ? INTEGRAL_TYPE_P (type
) || POINTER_TYPE_P (type
)
3798 : GET_MODE_CLASS (mode
) == MODE_INT
)
3801 /* Big-endian o64 pads floating-point arguments downward. */
3802 if (mips_abi
== ABI_O64
)
3803 if (type
!= 0 ? FLOAT_TYPE_P (type
) : GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3806 /* Other types are padded upward for o32, o64, n32 and n64. */
3807 if (mips_abi
!= ABI_EABI
)
3810 /* Arguments smaller than a stack slot are padded downward. */
3811 if (mode
!= BLKmode
)
3812 return (GET_MODE_BITSIZE (mode
) >= PARM_BOUNDARY
);
3814 return (int_size_in_bytes (type
) >= (PARM_BOUNDARY
/ BITS_PER_UNIT
));
3818 /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN
3819 if the least significant byte of the register has useful data. Return
3820 the opposite if the most significant byte does. */
3823 mips_pad_reg_upward (enum machine_mode mode
, tree type
)
3825 /* No shifting is required for floating-point arguments. */
3826 if (type
!= 0 ? FLOAT_TYPE_P (type
) : GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3827 return !BYTES_BIG_ENDIAN
;
3829 /* Otherwise, apply the same padding to register arguments as we do
3830 to stack arguments. */
3831 return mips_pad_arg_upward (mode
, type
);
3835 mips_setup_incoming_varargs (const CUMULATIVE_ARGS
*cum
,
3836 enum machine_mode mode
, tree type
, int no_rtl
)
3838 CUMULATIVE_ARGS local_cum
;
3839 int gp_saved
, fp_saved
;
3841 /* The caller has advanced CUM up to, but not beyond, the last named
3842 argument. Advance a local copy of CUM past the last "real" named
3843 argument, to find out how many registers are left over. */
3846 FUNCTION_ARG_ADVANCE (local_cum
, mode
, type
, 1);
3848 /* Found out how many registers we need to save. */
3849 gp_saved
= MAX_ARGS_IN_REGISTERS
- local_cum
.num_gprs
;
3850 fp_saved
= (EABI_FLOAT_VARARGS_P
3851 ? MAX_ARGS_IN_REGISTERS
- local_cum
.num_fprs
3860 ptr
= virtual_incoming_args_rtx
;
3865 ptr
= plus_constant (ptr
, local_cum
.num_gprs
* UNITS_PER_WORD
);
3869 ptr
= plus_constant (ptr
, -gp_saved
* UNITS_PER_WORD
);
3872 mem
= gen_rtx_MEM (BLKmode
, ptr
);
3873 set_mem_alias_set (mem
, get_varargs_alias_set ());
3875 move_block_from_reg (local_cum
.num_gprs
+ GP_ARG_FIRST
,
3880 /* We can't use move_block_from_reg, because it will use
3882 enum machine_mode mode
;
3885 /* Set OFF to the offset from virtual_incoming_args_rtx of
3886 the first float register. The FP save area lies below
3887 the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */
3888 off
= -gp_saved
* UNITS_PER_WORD
;
3889 off
&= ~(UNITS_PER_FPVALUE
- 1);
3890 off
-= fp_saved
* UNITS_PER_FPREG
;
3892 mode
= TARGET_SINGLE_FLOAT
? SFmode
: DFmode
;
3894 for (i
= local_cum
.num_fprs
; i
< MAX_ARGS_IN_REGISTERS
; i
+= FP_INC
)
3898 ptr
= plus_constant (virtual_incoming_args_rtx
, off
);
3899 mem
= gen_rtx_MEM (mode
, ptr
);
3900 set_mem_alias_set (mem
, get_varargs_alias_set ());
3901 emit_move_insn (mem
, gen_rtx_REG (mode
, FP_ARG_FIRST
+ i
));
3902 off
+= UNITS_PER_HWFPVALUE
;
3906 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
3907 /* No need for pretend arguments: the register parameter area was
3908 allocated by the caller. */
3910 return (gp_saved
* UNITS_PER_WORD
) + (fp_saved
* UNITS_PER_FPREG
);
3913 /* Create the va_list data type.
3914 We keep 3 pointers, and two offsets.
3915 Two pointers are to the overflow area, which starts at the CFA.
3916 One of these is constant, for addressing into the GPR save area below it.
3917 The other is advanced up the stack through the overflow region.
3918 The third pointer is to the GPR save area. Since the FPR save area
3919 is just below it, we can address FPR slots off this pointer.
3920 We also keep two one-byte offsets, which are to be subtracted from the
3921 constant pointers to yield addresses in the GPR and FPR save areas.
3922 These are downcounted as float or non-float arguments are used,
3923 and when they get to zero, the argument must be obtained from the
3925 If !EABI_FLOAT_VARARGS_P, then no FPR save area exists, and a single
3926 pointer is enough. It's started at the GPR save area, and is
3928 Note that the GPR save area is not constant size, due to optimization
3929 in the prologue. Hence, we can't use a design with two pointers
3930 and two offsets, although we could have designed this with two pointers
3931 and three offsets. */
3934 mips_build_builtin_va_list (void)
3936 if (EABI_FLOAT_VARARGS_P
)
3938 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
, f_res
, record
;
3941 record
= (*lang_hooks
.types
.make_type
) (RECORD_TYPE
);
3943 f_ovfl
= build_decl (FIELD_DECL
, get_identifier ("__overflow_argptr"),
3945 f_gtop
= build_decl (FIELD_DECL
, get_identifier ("__gpr_top"),
3947 f_ftop
= build_decl (FIELD_DECL
, get_identifier ("__fpr_top"),
3949 f_goff
= build_decl (FIELD_DECL
, get_identifier ("__gpr_offset"),
3950 unsigned_char_type_node
);
3951 f_foff
= build_decl (FIELD_DECL
, get_identifier ("__fpr_offset"),
3952 unsigned_char_type_node
);
3953 /* Explicitly pad to the size of a pointer, so that -Wpadded won't
3954 warn on every user file. */
3955 index
= build_int_2 (GET_MODE_SIZE (ptr_mode
) - 2 - 1, 0);
3956 array
= build_array_type (unsigned_char_type_node
,
3957 build_index_type (index
));
3958 f_res
= build_decl (FIELD_DECL
, get_identifier ("__reserved"), array
);
3960 DECL_FIELD_CONTEXT (f_ovfl
) = record
;
3961 DECL_FIELD_CONTEXT (f_gtop
) = record
;
3962 DECL_FIELD_CONTEXT (f_ftop
) = record
;
3963 DECL_FIELD_CONTEXT (f_goff
) = record
;
3964 DECL_FIELD_CONTEXT (f_foff
) = record
;
3965 DECL_FIELD_CONTEXT (f_res
) = record
;
3967 TYPE_FIELDS (record
) = f_ovfl
;
3968 TREE_CHAIN (f_ovfl
) = f_gtop
;
3969 TREE_CHAIN (f_gtop
) = f_ftop
;
3970 TREE_CHAIN (f_ftop
) = f_goff
;
3971 TREE_CHAIN (f_goff
) = f_foff
;
3972 TREE_CHAIN (f_foff
) = f_res
;
3974 layout_type (record
);
3977 else if (TARGET_IRIX
&& !TARGET_IRIX5
)
3978 /* On IRIX 6, this type is 'char *'. */
3979 return build_pointer_type (char_type_node
);
3981 /* Otherwise, we use 'void *'. */
3982 return ptr_type_node
;
3985 /* Implement va_start. */
3988 mips_va_start (tree valist
, rtx nextarg
)
3990 const CUMULATIVE_ARGS
*cum
= ¤t_function_args_info
;
3992 /* ARG_POINTER_REGNUM is initialized to STACK_POINTER_BOUNDARY, but
3993 since the stack is aligned for a pair of argument-passing slots,
3994 and the beginning of a variable argument list may be an odd slot,
3995 we have to decrease its alignment. */
3996 if (cfun
&& cfun
->emit
->regno_pointer_align
)
3997 while (((current_function_pretend_args_size
* BITS_PER_UNIT
)
3998 & (REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM
) - 1)) != 0)
3999 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM
) /= 2;
4001 if (mips_abi
== ABI_EABI
)
4003 int gpr_save_area_size
;
4006 = (MAX_ARGS_IN_REGISTERS
- cum
->num_gprs
) * UNITS_PER_WORD
;
4008 if (EABI_FLOAT_VARARGS_P
)
4010 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4011 tree ovfl
, gtop
, ftop
, goff
, foff
;
4014 int fpr_save_area_size
;
4016 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4017 f_gtop
= TREE_CHAIN (f_ovfl
);
4018 f_ftop
= TREE_CHAIN (f_gtop
);
4019 f_goff
= TREE_CHAIN (f_ftop
);
4020 f_foff
= TREE_CHAIN (f_goff
);
4022 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4023 gtop
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4024 ftop
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4025 goff
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4026 foff
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4028 /* Emit code to initialize OVFL, which points to the next varargs
4029 stack argument. CUM->STACK_WORDS gives the number of stack
4030 words used by named arguments. */
4031 t
= make_tree (TREE_TYPE (ovfl
), virtual_incoming_args_rtx
);
4032 if (cum
->stack_words
> 0)
4033 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), t
,
4034 build_int_2 (cum
->stack_words
* UNITS_PER_WORD
, 0));
4035 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4036 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4038 /* Emit code to initialize GTOP, the top of the GPR save area. */
4039 t
= make_tree (TREE_TYPE (gtop
), virtual_incoming_args_rtx
);
4040 t
= build (MODIFY_EXPR
, TREE_TYPE (gtop
), gtop
, t
);
4041 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4043 /* Emit code to initialize FTOP, the top of the FPR save area.
4044 This address is gpr_save_area_bytes below GTOP, rounded
4045 down to the next fp-aligned boundary. */
4046 t
= make_tree (TREE_TYPE (ftop
), virtual_incoming_args_rtx
);
4047 fpr_offset
= gpr_save_area_size
+ UNITS_PER_FPVALUE
- 1;
4048 fpr_offset
&= ~(UNITS_PER_FPVALUE
- 1);
4050 t
= build (PLUS_EXPR
, TREE_TYPE (ftop
), t
,
4051 build_int_2 (-fpr_offset
, -1));
4052 t
= build (MODIFY_EXPR
, TREE_TYPE (ftop
), ftop
, t
);
4053 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4055 /* Emit code to initialize GOFF, the offset from GTOP of the
4056 next GPR argument. */
4057 t
= build (MODIFY_EXPR
, TREE_TYPE (goff
), goff
,
4058 build_int_2 (gpr_save_area_size
, 0));
4059 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4061 /* Likewise emit code to initialize FOFF, the offset from FTOP
4062 of the next FPR argument. */
4064 = (MAX_ARGS_IN_REGISTERS
- cum
->num_fprs
) * UNITS_PER_FPREG
;
4065 t
= build (MODIFY_EXPR
, TREE_TYPE (foff
), foff
,
4066 build_int_2 (fpr_save_area_size
, 0));
4067 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4071 /* Everything is in the GPR save area, or in the overflow
4072 area which is contiguous with it. */
4073 nextarg
= plus_constant (nextarg
, -gpr_save_area_size
);
4074 std_expand_builtin_va_start (valist
, nextarg
);
4078 std_expand_builtin_va_start (valist
, nextarg
);
4081 /* Implement va_arg. */
4084 mips_va_arg (tree valist
, tree type
)
4086 HOST_WIDE_INT size
, rsize
;
4090 size
= int_size_in_bytes (type
);
4091 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
4093 if (mips_abi
== ABI_EABI
)
4099 = function_arg_pass_by_reference (NULL
, TYPE_MODE (type
), type
, 0);
4103 size
= POINTER_SIZE
/ BITS_PER_UNIT
;
4104 rsize
= UNITS_PER_WORD
;
4107 addr_rtx
= gen_reg_rtx (Pmode
);
4109 if (!EABI_FLOAT_VARARGS_P
)
4111 /* Case of all args in a merged stack. No need to check bounds,
4112 just advance valist along the stack. */
4117 && TYPE_ALIGN (type
) > (unsigned) BITS_PER_WORD
)
4119 /* Align the pointer using: ap = (ap + align - 1) & -align,
4120 where align is 2 * UNITS_PER_WORD. */
4121 t
= build (PLUS_EXPR
, TREE_TYPE (gpr
), gpr
,
4122 build_int_2 (2 * UNITS_PER_WORD
- 1, 0));
4123 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
,
4124 build_int_2 (-2 * UNITS_PER_WORD
, -1));
4125 t
= build (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
, t
);
4126 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4129 /* Emit code to set addr_rtx to the valist, and postincrement
4130 the valist by the size of the argument, rounded up to the
4132 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (gpr
), gpr
,
4134 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4136 emit_move_insn (addr_rtx
, r
);
4138 /* Flush the POSTINCREMENT. */
4143 /* Not a simple merged stack. */
4145 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4146 tree ovfl
, top
, off
;
4147 rtx lab_over
= NULL_RTX
, lab_false
;
4148 HOST_WIDE_INT osize
;
4150 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4151 f_gtop
= TREE_CHAIN (f_ovfl
);
4152 f_ftop
= TREE_CHAIN (f_gtop
);
4153 f_goff
= TREE_CHAIN (f_ftop
);
4154 f_foff
= TREE_CHAIN (f_goff
);
4156 /* We maintain separate pointers and offsets for floating-point
4157 and integer arguments, but we need similar code in both cases.
4160 TOP be the top of the register save area;
4161 OFF be the offset from TOP of the next register;
4162 ADDR_RTX be the address of the argument;
4163 RSIZE be the number of bytes used to store the argument
4164 when it's in the register save area;
4165 OSIZE be the number of bytes used to store it when it's
4166 in the stack overflow area; and
4167 PADDING be (BYTES_BIG_ENDIAN ? OSIZE - RSIZE : 0)
4169 The code we want is:
4171 1: off &= -rsize; // round down
4174 4: addr_rtx = top - off;
4179 9: ovfl += ((intptr_t) ovfl + osize - 1) & -osize;
4180 10: addr_rtx = ovfl + PADDING;
4184 [1] and [9] can sometimes be optimized away. */
4186 lab_false
= gen_label_rtx ();
4187 lab_over
= gen_label_rtx ();
4189 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4190 if (GET_MODE_CLASS (TYPE_MODE (type
)) == MODE_FLOAT
4191 && GET_MODE_SIZE (TYPE_MODE (type
)) <= UNITS_PER_FPVALUE
)
4193 top
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4194 off
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4196 /* When floating-point registers are saved to the stack,
4197 each one will take up UNITS_PER_HWFPVALUE bytes, regardless
4198 of the float's precision. */
4199 rsize
= UNITS_PER_HWFPVALUE
;
4203 top
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4204 off
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4205 if (rsize
> UNITS_PER_WORD
)
4207 /* [1] Emit code for: off &= -rsize. */
4208 t
= build (BIT_AND_EXPR
, TREE_TYPE (off
), off
,
4209 build_int_2 (-rsize
, -1));
4210 t
= build (MODIFY_EXPR
, TREE_TYPE (off
), off
, t
);
4211 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4214 /* Every overflow argument must take up at least UNITS_PER_WORD
4215 bytes (= PARM_BOUNDARY bits). RSIZE can sometimes be smaller
4216 than that, such as in the combination -mgp64 -msingle-float
4217 -fshort-double. Doubles passed in registers will then take
4218 up UNITS_PER_HWFPVALUE bytes, but those passed on the stack
4219 take up UNITS_PER_WORD bytes. */
4220 osize
= MAX (rsize
, UNITS_PER_WORD
);
4222 /* [2] Emit code to branch if off == 0. */
4223 r
= expand_expr (off
, NULL_RTX
, TYPE_MODE (TREE_TYPE (off
)),
4225 emit_cmp_and_jump_insns (r
, const0_rtx
, EQ
, const1_rtx
, GET_MODE (r
),
4228 /* [4] Emit code for: addr_rtx = top - off. */
4229 t
= build (MINUS_EXPR
, TREE_TYPE (top
), top
, off
);
4230 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4232 emit_move_insn (addr_rtx
, r
);
4234 /* [5] Emit code for: off -= rsize. */
4235 t
= build (MINUS_EXPR
, TREE_TYPE (off
), off
, build_int_2 (rsize
, 0));
4236 t
= build (MODIFY_EXPR
, TREE_TYPE (off
), off
, t
);
4237 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4239 /* [7] Emit code to jump over the else clause, then the label
4242 emit_jump (lab_over
);
4244 emit_label (lab_false
);
4246 if (osize
> UNITS_PER_WORD
)
4248 /* [9] Emit: ovfl += ((intptr_t) ovfl + osize - 1) & -osize. */
4249 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), ovfl
,
4250 build_int_2 (osize
- 1, 0));
4251 t
= build (BIT_AND_EXPR
, TREE_TYPE (ovfl
), t
,
4252 build_int_2 (-osize
, -1));
4253 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4254 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4257 /* [10, 11]. Emit code to store ovfl in addr_rtx, then
4258 post-increment ovfl by osize. On big-endian machines,
4259 the argument has OSIZE - RSIZE bytes of leading padding. */
4260 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (ovfl
), ovfl
,
4262 if (BYTES_BIG_ENDIAN
&& osize
> rsize
)
4263 t
= build (PLUS_EXPR
, TREE_TYPE (t
), t
,
4264 build_int_2 (osize
- rsize
, 0));
4265 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4267 emit_move_insn (addr_rtx
, r
);
4270 emit_label (lab_over
);
4272 if (BYTES_BIG_ENDIAN
&& rsize
!= size
)
4273 addr_rtx
= plus_constant (addr_rtx
, rsize
- size
);
4276 addr_rtx
= force_reg (Pmode
, addr_rtx
);
4277 r
= gen_rtx_MEM (Pmode
, addr_rtx
);
4278 set_mem_alias_set (r
, get_varargs_alias_set ());
4279 emit_move_insn (addr_rtx
, r
);
4287 HOST_WIDE_INT min_offset
;
4289 /* ??? The original va-mips.h did always align, despite the fact
4290 that alignments <= UNITS_PER_WORD are preserved by the va_arg
4291 increment mechanism. */
4293 if ((mips_abi
== ABI_N32
|| mips_abi
== ABI_64
)
4294 && TYPE_ALIGN (type
) > 64)
4296 else if (TARGET_64BIT
)
4298 else if (TYPE_ALIGN (type
) > 32)
4303 t
= build (PLUS_EXPR
, TREE_TYPE (valist
), valist
,
4304 build_int_2 (align
- 1, 0));
4305 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
, build_int_2 (-align
, -1));
4307 /* If arguments of type TYPE must be passed on the stack,
4308 set MIN_OFFSET to the offset of the first stack parameter. */
4309 if (!MUST_PASS_IN_STACK (TYPE_MODE (type
), type
))
4311 else if (TARGET_NEWABI
)
4312 min_offset
= current_function_pretend_args_size
;
4314 min_offset
= REG_PARM_STACK_SPACE (current_function_decl
);
4316 /* Make sure the new address is at least MIN_OFFSET bytes from
4317 the incoming argument pointer. */
4319 t
= build (MAX_EXPR
, TREE_TYPE (valist
), t
,
4320 make_tree (TREE_TYPE (valist
),
4321 plus_constant (virtual_incoming_args_rtx
,
4324 t
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
, t
);
4325 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4327 /* Everything past the alignment is standard. */
4328 return std_expand_builtin_va_arg (valist
, type
);
4332 /* Return true if it is possible to use left/right accesses for a
4333 bitfield of WIDTH bits starting BITPOS bits into *OP. When
4334 returning true, update *OP, *LEFT and *RIGHT as follows:
4336 *OP is a BLKmode reference to the whole field.
4338 *LEFT is a QImode reference to the first byte if big endian or
4339 the last byte if little endian. This address can be used in the
4340 left-side instructions (lwl, swl, ldl, sdl).
4342 *RIGHT is a QImode reference to the opposite end of the field and
4343 can be used in the parterning right-side instruction. */
4346 mips_get_unaligned_mem (rtx
*op
, unsigned int width
, int bitpos
,
4347 rtx
*left
, rtx
*right
)
4351 /* Check that the operand really is a MEM. Not all the extv and
4352 extzv predicates are checked. */
4353 if (GET_CODE (*op
) != MEM
)
4356 /* Check that the size is valid. */
4357 if (width
!= 32 && (!TARGET_64BIT
|| width
!= 64))
4360 /* We can only access byte-aligned values. Since we are always passed
4361 a reference to the first byte of the field, it is not necessary to
4362 do anything with BITPOS after this check. */
4363 if (bitpos
% BITS_PER_UNIT
!= 0)
4366 /* Reject aligned bitfields: we want to use a normal load or store
4367 instead of a left/right pair. */
4368 if (MEM_ALIGN (*op
) >= width
)
4371 /* Adjust *OP to refer to the whole field. This also has the effect
4372 of legitimizing *OP's address for BLKmode, possibly simplifying it. */
4373 *op
= adjust_address (*op
, BLKmode
, 0);
4374 set_mem_size (*op
, GEN_INT (width
/ BITS_PER_UNIT
));
4376 /* Get references to both ends of the field. We deliberately don't
4377 use the original QImode *OP for FIRST since the new BLKmode one
4378 might have a simpler address. */
4379 first
= adjust_address (*op
, QImode
, 0);
4380 last
= adjust_address (*op
, QImode
, width
/ BITS_PER_UNIT
- 1);
4382 /* Allocate to LEFT and RIGHT according to endiannes. LEFT should
4383 be the upper word and RIGHT the lower word. */
4384 if (TARGET_BIG_ENDIAN
)
4385 *left
= first
, *right
= last
;
4387 *left
= last
, *right
= first
;
4393 /* Try to emit the equivalent of (set DEST (zero_extract SRC WIDTH BITPOS)).
4394 Return true on success. We only handle cases where zero_extract is
4395 equivalent to sign_extract. */
4398 mips_expand_unaligned_load (rtx dest
, rtx src
, unsigned int width
, int bitpos
)
4402 /* If TARGET_64BIT, the destination of a 32-bit load will be a
4403 paradoxical word_mode subreg. This is the only case in which
4404 we allow the destination to be larger than the source. */
4405 if (GET_CODE (dest
) == SUBREG
4406 && GET_MODE (dest
) == DImode
4407 && SUBREG_BYTE (dest
) == 0
4408 && GET_MODE (SUBREG_REG (dest
)) == SImode
)
4409 dest
= SUBREG_REG (dest
);
4411 /* After the above adjustment, the destination must be the same
4412 width as the source. */
4413 if (GET_MODE_BITSIZE (GET_MODE (dest
)) != width
)
4416 if (!mips_get_unaligned_mem (&src
, width
, bitpos
, &left
, &right
))
4419 if (GET_MODE (dest
) == DImode
)
4421 emit_insn (gen_mov_ldl (dest
, src
, left
));
4422 emit_insn (gen_mov_ldr (copy_rtx (dest
), copy_rtx (src
),
4423 right
, copy_rtx (dest
)));
4427 emit_insn (gen_mov_lwl (dest
, src
, left
));
4428 emit_insn (gen_mov_lwr (copy_rtx (dest
), copy_rtx (src
),
4429 right
, copy_rtx (dest
)));
4435 /* Try to expand (set (zero_extract DEST WIDTH BITPOS) SRC). Return
4439 mips_expand_unaligned_store (rtx dest
, rtx src
, unsigned int width
, int bitpos
)
4443 if (!mips_get_unaligned_mem (&dest
, width
, bitpos
, &left
, &right
))
4446 src
= gen_lowpart (mode_for_size (width
, MODE_INT
, 0), src
);
4448 if (GET_MODE (src
) == DImode
)
4450 emit_insn (gen_mov_sdl (dest
, src
, left
));
4451 emit_insn (gen_mov_sdr (copy_rtx (dest
), copy_rtx (src
), right
));
4455 emit_insn (gen_mov_swl (dest
, src
, left
));
4456 emit_insn (gen_mov_swr (copy_rtx (dest
), copy_rtx (src
), right
));
4461 /* Set up globals to generate code for the ISA or processor
4462 described by INFO. */
4465 mips_set_architecture (const struct mips_cpu_info
*info
)
4469 mips_arch_info
= info
;
4470 mips_arch
= info
->cpu
;
4471 mips_isa
= info
->isa
;
4476 /* Likewise for tuning. */
4479 mips_set_tune (const struct mips_cpu_info
*info
)
4483 mips_tune_info
= info
;
4484 mips_tune
= info
->cpu
;
4489 /* Set up the threshold for data to go into the small data area, instead
4490 of the normal data area, and detect any conflicts in the switches. */
4493 override_options (void)
4495 int i
, start
, regno
;
4496 enum machine_mode mode
;
4498 mips_section_threshold
= g_switch_set
? g_switch_value
: MIPS_DEFAULT_GVALUE
;
4500 /* Interpret -mabi. */
4501 mips_abi
= MIPS_ABI_DEFAULT
;
4502 if (mips_abi_string
!= 0)
4504 if (strcmp (mips_abi_string
, "32") == 0)
4506 else if (strcmp (mips_abi_string
, "o64") == 0)
4508 else if (strcmp (mips_abi_string
, "n32") == 0)
4510 else if (strcmp (mips_abi_string
, "64") == 0)
4512 else if (strcmp (mips_abi_string
, "eabi") == 0)
4513 mips_abi
= ABI_EABI
;
4515 fatal_error ("bad value (%s) for -mabi= switch", mips_abi_string
);
4518 /* The following code determines the architecture and register size.
4519 Similar code was added to GAS 2.14 (see tc-mips.c:md_after_parse_args()).
4520 The GAS and GCC code should be kept in sync as much as possible. */
4522 if (mips_arch_string
!= 0)
4523 mips_set_architecture (mips_parse_cpu ("-march", mips_arch_string
));
4525 if (mips_isa_string
!= 0)
4527 /* Handle -mipsN. */
4528 char *whole_isa_str
= concat ("mips", mips_isa_string
, NULL
);
4529 const struct mips_cpu_info
*isa_info
;
4531 isa_info
= mips_parse_cpu ("-mips option", whole_isa_str
);
4532 free (whole_isa_str
);
4534 /* -march takes precedence over -mipsN, since it is more descriptive.
4535 There's no harm in specifying both as long as the ISA levels
4537 if (mips_arch_info
!= 0 && mips_isa
!= isa_info
->isa
)
4538 error ("-mips%s conflicts with the other architecture options, "
4539 "which specify a MIPS%d processor",
4540 mips_isa_string
, mips_isa
);
4542 /* Set architecture based on the given option. */
4543 mips_set_architecture (isa_info
);
4546 if (mips_arch_info
== 0)
4548 #ifdef MIPS_CPU_STRING_DEFAULT
4549 mips_set_architecture (mips_parse_cpu ("default CPU",
4550 MIPS_CPU_STRING_DEFAULT
));
4552 mips_set_architecture (mips_cpu_info_from_isa (MIPS_ISA_DEFAULT
));
4556 if (ABI_NEEDS_64BIT_REGS
&& !ISA_HAS_64BIT_REGS
)
4557 error ("-march=%s is not compatible with the selected ABI",
4558 mips_arch_info
->name
);
4560 /* Optimize for mips_arch, unless -mtune selects a different processor. */
4561 if (mips_tune_string
!= 0)
4562 mips_set_tune (mips_parse_cpu ("-mtune", mips_tune_string
));
4564 if (mips_tune_info
== 0)
4565 mips_set_tune (mips_arch_info
);
4567 if ((target_flags_explicit
& MASK_64BIT
) != 0)
4569 /* The user specified the size of the integer registers. Make sure
4570 it agrees with the ABI and ISA. */
4571 if (TARGET_64BIT
&& !ISA_HAS_64BIT_REGS
)
4572 error ("-mgp64 used with a 32-bit processor");
4573 else if (!TARGET_64BIT
&& ABI_NEEDS_64BIT_REGS
)
4574 error ("-mgp32 used with a 64-bit ABI");
4575 else if (TARGET_64BIT
&& ABI_NEEDS_32BIT_REGS
)
4576 error ("-mgp64 used with a 32-bit ABI");
4580 /* Infer the integer register size from the ABI and processor.
4581 Restrict ourselves to 32-bit registers if that's all the
4582 processor has, or if the ABI cannot handle 64-bit registers. */
4583 if (ABI_NEEDS_32BIT_REGS
|| !ISA_HAS_64BIT_REGS
)
4584 target_flags
&= ~MASK_64BIT
;
4586 target_flags
|= MASK_64BIT
;
4589 if ((target_flags_explicit
& MASK_FLOAT64
) != 0)
4591 /* Really, -mfp32 and -mfp64 are ornamental options. There's
4592 only one right answer here. */
4593 if (TARGET_64BIT
&& TARGET_DOUBLE_FLOAT
&& !TARGET_FLOAT64
)
4594 error ("unsupported combination: %s", "-mgp64 -mfp32 -mdouble-float");
4595 else if (!TARGET_64BIT
&& TARGET_FLOAT64
)
4596 error ("unsupported combination: %s", "-mgp32 -mfp64");
4597 else if (TARGET_SINGLE_FLOAT
&& TARGET_FLOAT64
)
4598 error ("unsupported combination: %s", "-mfp64 -msingle-float");
4602 /* -msingle-float selects 32-bit float registers. Otherwise the
4603 float registers should be the same size as the integer ones. */
4604 if (TARGET_64BIT
&& TARGET_DOUBLE_FLOAT
)
4605 target_flags
|= MASK_FLOAT64
;
4607 target_flags
&= ~MASK_FLOAT64
;
4610 /* End of code shared with GAS. */
4612 if ((target_flags_explicit
& MASK_LONG64
) == 0)
4614 /* If no type size setting options (-mlong64,-mint64,-mlong32)
4615 were used, then set the type sizes. In the EABI in 64 bit mode,
4616 longs and pointers are 64 bits. Likewise for the SGI Irix6 N64
4618 if ((mips_abi
== ABI_EABI
&& TARGET_64BIT
) || mips_abi
== ABI_64
)
4619 target_flags
|= MASK_LONG64
;
4621 target_flags
&= ~MASK_LONG64
;
4624 if (MIPS_MARCH_CONTROLS_SOFT_FLOAT
4625 && (target_flags_explicit
& MASK_SOFT_FLOAT
) == 0)
4627 /* For some configurations, it is useful to have -march control
4628 the default setting of MASK_SOFT_FLOAT. */
4629 switch ((int) mips_arch
)
4631 case PROCESSOR_R4100
:
4632 case PROCESSOR_R4111
:
4633 case PROCESSOR_R4120
:
4634 target_flags
|= MASK_SOFT_FLOAT
;
4638 target_flags
&= ~MASK_SOFT_FLOAT
;
4643 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
4644 flag_pcc_struct_return
= 0;
4646 #if defined(USE_COLLECT2)
4647 /* For IRIX 5 or IRIX 6 with integrated O32 ABI support, USE_COLLECT2 is
4648 always defined when GNU as is not in use, but collect2 is only used
4649 for the O32 ABI, so override the toplev.c and target-def.h defaults
4650 for flag_gnu_linker, TARGET_ASM_{CONSTRUCTOR, DESTRUCTOR} and
4651 TARGET_HAVE_CTORS_DTORS.
4653 Since the IRIX 5 and IRIX 6 O32 assemblers cannot handle named
4654 sections, constructor/destructor handling depends on the ABI in use.
4656 Since USE_COLLECT2 is defined, we only need to restore the non-collect2
4657 defaults for the N32/N64 ABIs. */
4658 if (TARGET_IRIX
&& !TARGET_SGI_O32_AS
)
4660 targetm
.have_ctors_dtors
= true;
4661 targetm
.asm_out
.constructor
= default_named_section_asm_out_constructor
;
4662 targetm
.asm_out
.destructor
= default_named_section_asm_out_destructor
;
4666 /* Handle some quirks of the IRIX 5 and IRIX 6 O32 assemblers. */
4668 if (TARGET_SGI_O32_AS
)
4670 /* They don't recognize `.[248]byte'. */
4671 targetm
.asm_out
.unaligned_op
.hi
= "\t.align 0\n\t.half\t";
4672 targetm
.asm_out
.unaligned_op
.si
= "\t.align 0\n\t.word\t";
4673 /* The IRIX 6 O32 assembler gives an error for `align 0; .dword',
4674 contrary to the documentation, so disable it. */
4675 targetm
.asm_out
.unaligned_op
.di
= NULL
;
4677 /* They cannot handle named sections. */
4678 targetm
.have_named_sections
= false;
4679 /* Therefore, EH_FRAME_SECTION_NAME isn't defined and we must use
4681 targetm
.terminate_dw2_eh_frame_info
= true;
4682 targetm
.asm_out
.eh_frame_section
= collect2_eh_frame_section
;
4684 /* They cannot handle debug information. */
4685 if (write_symbols
!= NO_DEBUG
)
4687 /* Adapt wording to IRIX version: IRIX 5 only had a single ABI,
4688 so -mabi=32 isn't usually specified. */
4690 inform ("-g is only supported using GNU as,");
4692 inform ("-g is only supported using GNU as with -mabi=32,");
4693 inform ("-g option disabled");
4694 write_symbols
= NO_DEBUG
;
4698 if ((target_flags_explicit
& MASK_BRANCHLIKELY
) == 0)
4700 /* If neither -mbranch-likely nor -mno-branch-likely was given
4701 on the command line, set MASK_BRANCHLIKELY based on the target
4704 By default, we enable use of Branch Likely instructions on
4705 all architectures which support them except for MIPS32 and MIPS64
4706 (i.e., the generic MIPS32 and MIPS64 ISAs, and processors which
4709 The MIPS32 and MIPS64 architecture specifications say "Software
4710 is strongly encouraged to avoid use of Branch Likely
4711 instructions, as they will be removed from a future revision
4712 of the [MIPS32 and MIPS64] architecture." Therefore, we do not
4713 issue those instructions unless instructed to do so by
4715 if (ISA_HAS_BRANCHLIKELY
&& !(ISA_MIPS32
|| ISA_MIPS32R2
|| ISA_MIPS64
))
4716 target_flags
|= MASK_BRANCHLIKELY
;
4718 target_flags
&= ~MASK_BRANCHLIKELY
;
4720 if (TARGET_BRANCHLIKELY
&& !ISA_HAS_BRANCHLIKELY
)
4721 warning ("generation of Branch Likely instructions enabled, but not supported by architecture");
4723 /* The effect of -mabicalls isn't defined for the EABI. */
4724 if (mips_abi
== ABI_EABI
&& TARGET_ABICALLS
)
4726 error ("unsupported combination: %s", "-mabicalls -mabi=eabi");
4727 target_flags
&= ~MASK_ABICALLS
;
4730 /* -fpic (-KPIC) is the default when TARGET_ABICALLS is defined. We need
4731 to set flag_pic so that the LEGITIMATE_PIC_OPERAND_P macro will work. */
4732 /* ??? -non_shared turns off pic code generation, but this is not
4734 if (TARGET_ABICALLS
)
4737 if (mips_section_threshold
> 0)
4738 warning ("-G is incompatible with PIC code which is the default");
4741 /* The MIPS and SGI o32 assemblers expect small-data variables to
4742 be declared before they are used. Although we once had code to
4743 do this, it was very invasive and fragile. It no longer seems
4744 worth the effort. */
4745 if (!TARGET_EXPLICIT_RELOCS
&& !TARGET_GAS
)
4746 mips_section_threshold
= 0;
4748 /* We switch to small data sections using ".section", which the native
4749 o32 irix assemblers don't understand. Disable -G accordingly.
4750 We must do this regardless of command-line options since otherwise
4751 the compiler would abort. */
4752 if (!targetm
.have_named_sections
)
4753 mips_section_threshold
= 0;
4755 /* -membedded-pic is a form of PIC code suitable for embedded
4756 systems. All calls are made using PC relative addressing, and
4757 all data is addressed using the $gp register. This requires gas,
4758 which does most of the work, and GNU ld, which automatically
4759 expands PC relative calls which are out of range into a longer
4760 instruction sequence. All gcc really does differently is
4761 generate a different sequence for a switch. */
4762 if (TARGET_EMBEDDED_PIC
)
4765 if (TARGET_ABICALLS
)
4766 warning ("-membedded-pic and -mabicalls are incompatible");
4769 warning ("-G and -membedded-pic are incompatible");
4771 /* Setting mips_section_threshold is not required, because gas
4772 will force everything to be GP addressable anyhow, but
4773 setting it will cause gcc to make better estimates of the
4774 number of instructions required to access a particular data
4776 mips_section_threshold
= 0x7fffffff;
4779 /* mips_split_addresses is a half-way house between explicit
4780 relocations and the traditional assembler macros. It can
4781 split absolute 32-bit symbolic constants into a high/lo_sum
4782 pair but uses macros for other sorts of access.
4784 Like explicit relocation support for REL targets, it relies
4785 on GNU extensions in the assembler and the linker.
4787 Although this code should work for -O0, it has traditionally
4788 been treated as an optimization. */
4789 if (TARGET_GAS
&& !TARGET_MIPS16
&& TARGET_SPLIT_ADDRESSES
4790 && optimize
&& !flag_pic
4791 && !ABI_HAS_64BIT_SYMBOLS
)
4792 mips_split_addresses
= 1;
4794 mips_split_addresses
= 0;
4796 /* -mexplicit-relocs doesn't yet support non-PIC n64. We don't know
4797 how to generate %highest/%higher/%hi/%lo sequences. */
4798 if (mips_abi
== ABI_64
&& !TARGET_ABICALLS
)
4800 if ((target_flags_explicit
& target_flags
& MASK_EXPLICIT_RELOCS
) != 0)
4801 sorry ("non-PIC n64 with explicit relocations");
4802 target_flags
&= ~MASK_EXPLICIT_RELOCS
;
4805 /* Explicit relocations for "old" ABIs are a GNU extension. Unless
4806 the user has said otherwise, assume that they are not available
4807 with assemblers other than gas. */
4808 if (!TARGET_NEWABI
&& !TARGET_GAS
4809 && (target_flags_explicit
& MASK_EXPLICIT_RELOCS
) == 0)
4810 target_flags
&= ~MASK_EXPLICIT_RELOCS
;
4812 /* Make -mabicalls -fno-unit-at-a-time imply -mno-explicit-relocs
4813 unless the user says otherwise.
4815 There are two problems here:
4817 (1) The value of an R_MIPS_GOT16 relocation depends on whether
4818 the symbol is local or global. We therefore need to know
4819 a symbol's binding before refering to it using %got().
4821 (2) R_MIPS_CALL16 can only be applied to global symbols.
4823 When not using -funit-at-a-time, a symbol's binding may change
4824 after it has been used. For example, the C++ front-end will
4825 initially assume that the typeinfo for an incomplete type will be
4826 comdat, on the basis that the type could be completed later in the
4827 file. But if the type never is completed, the typeinfo will become
4829 if (!flag_unit_at_a_time
4831 && (target_flags_explicit
& MASK_EXPLICIT_RELOCS
) == 0)
4832 target_flags
&= ~MASK_EXPLICIT_RELOCS
;
4834 /* -mrnames says to use the MIPS software convention for register
4835 names instead of the hardware names (ie, $a0 instead of $4).
4836 We do this by switching the names in mips_reg_names, which the
4837 reg_names points into via the REGISTER_NAMES macro. */
4839 if (TARGET_NAME_REGS
)
4840 memcpy (mips_reg_names
, mips_sw_reg_names
, sizeof (mips_reg_names
));
4842 /* When compiling for the mips16, we can not use floating point. We
4843 record the original hard float value in mips16_hard_float. */
4846 if (TARGET_SOFT_FLOAT
)
4847 mips16_hard_float
= 0;
4849 mips16_hard_float
= 1;
4850 target_flags
|= MASK_SOFT_FLOAT
;
4852 /* Don't run the scheduler before reload, since it tends to
4853 increase register pressure. */
4854 flag_schedule_insns
= 0;
4856 /* Silently disable -mexplicit-relocs since it doesn't apply
4857 to mips16 code. Even so, it would overly pedantic to warn
4858 about "-mips16 -mexplicit-relocs", especially given that
4859 we use a %gprel() operator. */
4860 target_flags
&= ~MASK_EXPLICIT_RELOCS
;
4863 /* When using explicit relocs, we call dbr_schedule from within
4865 if (TARGET_EXPLICIT_RELOCS
)
4867 mips_flag_delayed_branch
= flag_delayed_branch
;
4868 flag_delayed_branch
= 0;
4871 #ifdef MIPS_TFMODE_FORMAT
4872 REAL_MODE_FORMAT (TFmode
) = &MIPS_TFMODE_FORMAT
;
4875 mips_print_operand_punct
['?'] = 1;
4876 mips_print_operand_punct
['#'] = 1;
4877 mips_print_operand_punct
['/'] = 1;
4878 mips_print_operand_punct
['&'] = 1;
4879 mips_print_operand_punct
['!'] = 1;
4880 mips_print_operand_punct
['*'] = 1;
4881 mips_print_operand_punct
['@'] = 1;
4882 mips_print_operand_punct
['.'] = 1;
4883 mips_print_operand_punct
['('] = 1;
4884 mips_print_operand_punct
[')'] = 1;
4885 mips_print_operand_punct
['['] = 1;
4886 mips_print_operand_punct
[']'] = 1;
4887 mips_print_operand_punct
['<'] = 1;
4888 mips_print_operand_punct
['>'] = 1;
4889 mips_print_operand_punct
['{'] = 1;
4890 mips_print_operand_punct
['}'] = 1;
4891 mips_print_operand_punct
['^'] = 1;
4892 mips_print_operand_punct
['$'] = 1;
4893 mips_print_operand_punct
['+'] = 1;
4894 mips_print_operand_punct
['~'] = 1;
4896 mips_char_to_class
['d'] = TARGET_MIPS16
? M16_REGS
: GR_REGS
;
4897 mips_char_to_class
['e'] = M16_NA_REGS
;
4898 mips_char_to_class
['t'] = T_REG
;
4899 mips_char_to_class
['f'] = (TARGET_HARD_FLOAT
? FP_REGS
: NO_REGS
);
4900 mips_char_to_class
['h'] = HI_REG
;
4901 mips_char_to_class
['l'] = LO_REG
;
4902 mips_char_to_class
['x'] = MD_REGS
;
4903 mips_char_to_class
['b'] = ALL_REGS
;
4904 mips_char_to_class
['c'] = (TARGET_ABICALLS
? PIC_FN_ADDR_REG
:
4905 TARGET_MIPS16
? M16_NA_REGS
:
4907 mips_char_to_class
['e'] = LEA_REGS
;
4908 mips_char_to_class
['j'] = PIC_FN_ADDR_REG
;
4909 mips_char_to_class
['y'] = GR_REGS
;
4910 mips_char_to_class
['z'] = ST_REGS
;
4911 mips_char_to_class
['B'] = COP0_REGS
;
4912 mips_char_to_class
['C'] = COP2_REGS
;
4913 mips_char_to_class
['D'] = COP3_REGS
;
4915 /* Set up array to map GCC register number to debug register number.
4916 Ignore the special purpose register numbers. */
4918 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4919 mips_dbx_regno
[i
] = -1;
4921 start
= GP_DBX_FIRST
- GP_REG_FIRST
;
4922 for (i
= GP_REG_FIRST
; i
<= GP_REG_LAST
; i
++)
4923 mips_dbx_regno
[i
] = i
+ start
;
4925 start
= FP_DBX_FIRST
- FP_REG_FIRST
;
4926 for (i
= FP_REG_FIRST
; i
<= FP_REG_LAST
; i
++)
4927 mips_dbx_regno
[i
] = i
+ start
;
4929 mips_dbx_regno
[HI_REGNUM
] = MD_DBX_FIRST
+ 0;
4930 mips_dbx_regno
[LO_REGNUM
] = MD_DBX_FIRST
+ 1;
4932 /* Set up array giving whether a given register can hold a given mode. */
4934 for (mode
= VOIDmode
;
4935 mode
!= MAX_MACHINE_MODE
;
4936 mode
= (enum machine_mode
) ((int)mode
+ 1))
4938 register int size
= GET_MODE_SIZE (mode
);
4939 register enum mode_class
class = GET_MODE_CLASS (mode
);
4941 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
4948 temp
= (regno
== FPSW_REGNUM
);
4950 temp
= (ST_REG_P (regno
) || GP_REG_P (regno
)
4951 || FP_REG_P (regno
));
4954 else if (GP_REG_P (regno
))
4955 temp
= ((regno
& 1) == 0 || size
<= UNITS_PER_WORD
);
4957 else if (FP_REG_P (regno
))
4958 temp
= ((regno
% FP_INC
) == 0)
4959 && (((class == MODE_FLOAT
|| class == MODE_COMPLEX_FLOAT
)
4960 && size
<= UNITS_PER_FPVALUE
)
4961 /* Allow integer modes that fit into a single
4962 register. We need to put integers into FPRs
4963 when using instructions like cvt and trunc. */
4964 || (class == MODE_INT
&& size
<= UNITS_PER_FPREG
)
4965 /* Allow TFmode for CCmode reloads. */
4966 || (ISA_HAS_8CC
&& mode
== TFmode
));
4968 else if (MD_REG_P (regno
))
4969 temp
= (class == MODE_INT
4970 && (size
<= UNITS_PER_WORD
4971 || (regno
== MD_REG_FIRST
4972 && size
== 2 * UNITS_PER_WORD
)));
4974 else if (ALL_COP_REG_P (regno
))
4975 temp
= (class == MODE_INT
&& size
<= UNITS_PER_WORD
);
4979 mips_hard_regno_mode_ok
[(int)mode
][regno
] = temp
;
4983 /* Save GPR registers in word_mode sized hunks. word_mode hasn't been
4984 initialized yet, so we can't use that here. */
4985 gpr_mode
= TARGET_64BIT
? DImode
: SImode
;
4987 /* Provide default values for align_* for 64-bit targets. */
4988 if (TARGET_64BIT
&& !TARGET_MIPS16
)
4990 if (align_loops
== 0)
4992 if (align_jumps
== 0)
4994 if (align_functions
== 0)
4995 align_functions
= 8;
4998 /* Function to allocate machine-dependent function status. */
4999 init_machine_status
= &mips_init_machine_status
;
5001 /* Create a unique alias set for GOT references. */
5002 mips_got_alias_set
= new_alias_set ();
5004 if (TARGET_EXPLICIT_RELOCS
|| mips_split_addresses
)
5006 mips_split_p
[SYMBOL_GENERAL
] = true;
5007 mips_hi_relocs
[SYMBOL_GENERAL
] = "%hi(";
5008 mips_lo_relocs
[SYMBOL_GENERAL
] = "%lo(";
5013 /* The high part is provided by a pseudo copy of $gp. */
5014 mips_split_p
[SYMBOL_SMALL_DATA
] = true;
5015 mips_lo_relocs
[SYMBOL_SMALL_DATA
] = "%gprel(";
5018 if (TARGET_EXPLICIT_RELOCS
)
5020 /* Small data constants are kept whole until after reload,
5021 then lowered by mips_rewrite_small_data. */
5022 mips_lo_relocs
[SYMBOL_SMALL_DATA
] = "%gp_rel(";
5024 mips_split_p
[SYMBOL_GOT_LOCAL
] = true;
5027 mips_lo_relocs
[SYMBOL_GOTOFF_PAGE
] = "%got_page(";
5028 mips_lo_relocs
[SYMBOL_GOT_LOCAL
] = "%got_ofst(";
5032 mips_lo_relocs
[SYMBOL_GOTOFF_PAGE
] = "%got(";
5033 mips_lo_relocs
[SYMBOL_GOT_LOCAL
] = "%lo(";
5038 /* The HIGH and LO_SUM are matched by special .md patterns. */
5039 mips_split_p
[SYMBOL_GOT_GLOBAL
] = true;
5041 mips_split_p
[SYMBOL_GOTOFF_GLOBAL
] = true;
5042 mips_hi_relocs
[SYMBOL_GOTOFF_GLOBAL
] = "%got_hi(";
5043 mips_lo_relocs
[SYMBOL_GOTOFF_GLOBAL
] = "%got_lo(";
5045 mips_split_p
[SYMBOL_GOTOFF_CALL
] = true;
5046 mips_hi_relocs
[SYMBOL_GOTOFF_CALL
] = "%call_hi(";
5047 mips_lo_relocs
[SYMBOL_GOTOFF_CALL
] = "%call_lo(";
5052 mips_lo_relocs
[SYMBOL_GOTOFF_GLOBAL
] = "%got_disp(";
5054 mips_lo_relocs
[SYMBOL_GOTOFF_GLOBAL
] = "%got(";
5055 mips_lo_relocs
[SYMBOL_GOTOFF_CALL
] = "%call16(";
5061 mips_split_p
[SYMBOL_GOTOFF_LOADGP
] = true;
5062 mips_hi_relocs
[SYMBOL_GOTOFF_LOADGP
] = "%hi(%neg(%gp_rel(";
5063 mips_lo_relocs
[SYMBOL_GOTOFF_LOADGP
] = "%lo(%neg(%gp_rel(";
5067 /* Implement CONDITIONAL_REGISTER_USAGE. */
5070 mips_conditional_register_usage (void)
5072 if (!TARGET_HARD_FLOAT
)
5076 for (regno
= FP_REG_FIRST
; regno
<= FP_REG_LAST
; regno
++)
5077 fixed_regs
[regno
] = call_used_regs
[regno
] = 1;
5078 for (regno
= ST_REG_FIRST
; regno
<= ST_REG_LAST
; regno
++)
5079 fixed_regs
[regno
] = call_used_regs
[regno
] = 1;
5081 else if (! ISA_HAS_8CC
)
5085 /* We only have a single condition code register. We
5086 implement this by hiding all the condition code registers,
5087 and generating RTL that refers directly to ST_REG_FIRST. */
5088 for (regno
= ST_REG_FIRST
; regno
<= ST_REG_LAST
; regno
++)
5089 fixed_regs
[regno
] = call_used_regs
[regno
] = 1;
5091 /* In mips16 mode, we permit the $t temporary registers to be used
5092 for reload. We prohibit the unused $s registers, since they
5093 are caller saved, and saving them via a mips16 register would
5094 probably waste more time than just reloading the value. */
5097 fixed_regs
[18] = call_used_regs
[18] = 1;
5098 fixed_regs
[19] = call_used_regs
[19] = 1;
5099 fixed_regs
[20] = call_used_regs
[20] = 1;
5100 fixed_regs
[21] = call_used_regs
[21] = 1;
5101 fixed_regs
[22] = call_used_regs
[22] = 1;
5102 fixed_regs
[23] = call_used_regs
[23] = 1;
5103 fixed_regs
[26] = call_used_regs
[26] = 1;
5104 fixed_regs
[27] = call_used_regs
[27] = 1;
5105 fixed_regs
[30] = call_used_regs
[30] = 1;
5107 /* fp20-23 are now caller saved. */
5108 if (mips_abi
== ABI_64
)
5111 for (regno
= FP_REG_FIRST
+ 20; regno
< FP_REG_FIRST
+ 24; regno
++)
5112 call_really_used_regs
[regno
] = call_used_regs
[regno
] = 1;
5114 /* Odd registers from fp21 to fp31 are now caller saved. */
5115 if (mips_abi
== ABI_N32
)
5118 for (regno
= FP_REG_FIRST
+ 21; regno
<= FP_REG_FIRST
+ 31; regno
+=2)
5119 call_really_used_regs
[regno
] = call_used_regs
[regno
] = 1;
5123 /* Allocate a chunk of memory for per-function machine-dependent data. */
5124 static struct machine_function
*
5125 mips_init_machine_status (void)
5127 return ((struct machine_function
*)
5128 ggc_alloc_cleared (sizeof (struct machine_function
)));
5131 /* On the mips16, we want to allocate $24 (T_REG) before other
5132 registers for instructions for which it is possible. This helps
5133 avoid shuffling registers around in order to set up for an xor,
5134 encouraging the compiler to use a cmp instead. */
5137 mips_order_regs_for_local_alloc (void)
5141 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5142 reg_alloc_order
[i
] = i
;
5146 /* It really doesn't matter where we put register 0, since it is
5147 a fixed register anyhow. */
5148 reg_alloc_order
[0] = 24;
5149 reg_alloc_order
[24] = 0;
5154 /* The MIPS debug format wants all automatic variables and arguments
5155 to be in terms of the virtual frame pointer (stack pointer before
5156 any adjustment in the function), while the MIPS 3.0 linker wants
5157 the frame pointer to be the stack pointer after the initial
5158 adjustment. So, we do the adjustment here. The arg pointer (which
5159 is eliminated) points to the virtual frame pointer, while the frame
5160 pointer (which may be eliminated) points to the stack pointer after
5161 the initial adjustments. */
5164 mips_debugger_offset (rtx addr
, HOST_WIDE_INT offset
)
5166 rtx offset2
= const0_rtx
;
5167 rtx reg
= eliminate_constant_term (addr
, &offset2
);
5170 offset
= INTVAL (offset2
);
5172 if (reg
== stack_pointer_rtx
|| reg
== frame_pointer_rtx
5173 || reg
== hard_frame_pointer_rtx
)
5175 HOST_WIDE_INT frame_size
= (!cfun
->machine
->frame
.initialized
)
5176 ? compute_frame_size (get_frame_size ())
5177 : cfun
->machine
->frame
.total_size
;
5179 /* MIPS16 frame is smaller */
5180 if (frame_pointer_needed
&& TARGET_MIPS16
)
5181 frame_size
-= cfun
->machine
->frame
.args_size
;
5183 offset
= offset
- frame_size
;
5186 /* sdbout_parms does not want this to crash for unrecognized cases. */
5188 else if (reg
!= arg_pointer_rtx
)
5189 fatal_insn ("mips_debugger_offset called with non stack/frame/arg pointer",
5196 /* Implement the PRINT_OPERAND macro. The MIPS-specific operand codes are:
5198 'X' OP is CONST_INT, prints 32 bits in hexadecimal format = "0x%08x",
5199 'x' OP is CONST_INT, prints 16 bits in hexadecimal format = "0x%04x",
5200 'h' OP is HIGH, prints %hi(X),
5201 'd' output integer constant in decimal,
5202 'z' if the operand is 0, use $0 instead of normal operand.
5203 'D' print second part of double-word register or memory operand.
5204 'L' print low-order register of double-word register operand.
5205 'M' print high-order register of double-word register operand.
5206 'C' print part of opcode for a branch condition.
5207 'F' print part of opcode for a floating-point branch condition.
5208 'N' print part of opcode for a branch condition, inverted.
5209 'W' print part of opcode for a floating-point branch condition, inverted.
5210 'S' OP is CODE_LABEL, print with prefix of "LS" (for embedded switch).
5211 'B' print 'z' for EQ, 'n' for NE
5212 'b' print 'n' for EQ, 'z' for NE
5213 'T' print 'f' for EQ, 't' for NE
5214 't' print 't' for EQ, 'f' for NE
5215 'Z' print register and a comma, but print nothing for $fcc0
5216 'R' print the reloc associated with LO_SUM
5218 The punctuation characters are:
5220 '(' Turn on .set noreorder
5221 ')' Turn on .set reorder
5222 '[' Turn on .set noat
5224 '<' Turn on .set nomacro
5225 '>' Turn on .set macro
5226 '{' Turn on .set volatile (not GAS)
5227 '}' Turn on .set novolatile (not GAS)
5228 '&' Turn on .set noreorder if filling delay slots
5229 '*' Turn on both .set noreorder and .set nomacro if filling delay slots
5230 '!' Turn on .set nomacro if filling delay slots
5231 '#' Print nop if in a .set noreorder section.
5232 '/' Like '#', but does nothing within a delayed branch sequence
5233 '?' Print 'l' if we are to use a branch likely instead of normal branch.
5234 '@' Print the name of the assembler temporary register (at or $1).
5235 '.' Print the name of the register with a hard-wired zero (zero or $0).
5236 '^' Print the name of the pic call-through register (t9 or $25).
5237 '$' Print the name of the stack pointer register (sp or $29).
5238 '+' Print the name of the gp register (usually gp or $28).
5239 '~' Output a branch alignment to LABEL_ALIGN(NULL). */
5242 print_operand (FILE *file
, rtx op
, int letter
)
5244 register enum rtx_code code
;
5246 if (PRINT_OPERAND_PUNCT_VALID_P (letter
))
5251 if (mips_branch_likely
)
5256 fputs (reg_names
[GP_REG_FIRST
+ 1], file
);
5260 fputs (reg_names
[PIC_FUNCTION_ADDR_REGNUM
], file
);
5264 fputs (reg_names
[GP_REG_FIRST
+ 0], file
);
5268 fputs (reg_names
[STACK_POINTER_REGNUM
], file
);
5272 fputs (reg_names
[PIC_OFFSET_TABLE_REGNUM
], file
);
5276 if (final_sequence
!= 0 && set_noreorder
++ == 0)
5277 fputs (".set\tnoreorder\n\t", file
);
5281 if (final_sequence
!= 0)
5283 if (set_noreorder
++ == 0)
5284 fputs (".set\tnoreorder\n\t", file
);
5286 if (set_nomacro
++ == 0)
5287 fputs (".set\tnomacro\n\t", file
);
5292 if (final_sequence
!= 0 && set_nomacro
++ == 0)
5293 fputs ("\n\t.set\tnomacro", file
);
5297 if (set_noreorder
!= 0)
5298 fputs ("\n\tnop", file
);
5302 /* Print an extra newline so that the delayed insn is separated
5303 from the following ones. This looks neater and is consistent
5304 with non-nop delayed sequences. */
5305 if (set_noreorder
!= 0 && final_sequence
== 0)
5306 fputs ("\n\tnop\n", file
);
5310 if (set_noreorder
++ == 0)
5311 fputs (".set\tnoreorder\n\t", file
);
5315 if (set_noreorder
== 0)
5316 error ("internal error: %%) found without a %%( in assembler pattern");
5318 else if (--set_noreorder
== 0)
5319 fputs ("\n\t.set\treorder", file
);
5324 if (set_noat
++ == 0)
5325 fputs (".set\tnoat\n\t", file
);
5330 error ("internal error: %%] found without a %%[ in assembler pattern");
5331 else if (--set_noat
== 0)
5332 fputs ("\n\t.set\tat", file
);
5337 if (set_nomacro
++ == 0)
5338 fputs (".set\tnomacro\n\t", file
);
5342 if (set_nomacro
== 0)
5343 error ("internal error: %%> found without a %%< in assembler pattern");
5344 else if (--set_nomacro
== 0)
5345 fputs ("\n\t.set\tmacro", file
);
5350 if (set_volatile
++ == 0)
5351 fprintf (file
, "%s.set\tvolatile\n\t", TARGET_MIPS_AS
? "" : "#");
5355 if (set_volatile
== 0)
5356 error ("internal error: %%} found without a %%{ in assembler pattern");
5357 else if (--set_volatile
== 0)
5358 fprintf (file
, "\n\t%s.set\tnovolatile", (TARGET_MIPS_AS
) ? "" : "#");
5364 if (align_labels_log
> 0)
5365 ASM_OUTPUT_ALIGN (file
, align_labels_log
);
5370 error ("PRINT_OPERAND: unknown punctuation '%c'", letter
);
5379 error ("PRINT_OPERAND null pointer");
5383 code
= GET_CODE (op
);
5388 case EQ
: fputs ("eq", file
); break;
5389 case NE
: fputs ("ne", file
); break;
5390 case GT
: fputs ("gt", file
); break;
5391 case GE
: fputs ("ge", file
); break;
5392 case LT
: fputs ("lt", file
); break;
5393 case LE
: fputs ("le", file
); break;
5394 case GTU
: fputs ("gtu", file
); break;
5395 case GEU
: fputs ("geu", file
); break;
5396 case LTU
: fputs ("ltu", file
); break;
5397 case LEU
: fputs ("leu", file
); break;
5399 fatal_insn ("PRINT_OPERAND, invalid insn for %%C", op
);
5402 else if (letter
== 'N')
5405 case EQ
: fputs ("ne", file
); break;
5406 case NE
: fputs ("eq", file
); break;
5407 case GT
: fputs ("le", file
); break;
5408 case GE
: fputs ("lt", file
); break;
5409 case LT
: fputs ("ge", file
); break;
5410 case LE
: fputs ("gt", file
); break;
5411 case GTU
: fputs ("leu", file
); break;
5412 case GEU
: fputs ("ltu", file
); break;
5413 case LTU
: fputs ("geu", file
); break;
5414 case LEU
: fputs ("gtu", file
); break;
5416 fatal_insn ("PRINT_OPERAND, invalid insn for %%N", op
);
5419 else if (letter
== 'F')
5422 case EQ
: fputs ("c1f", file
); break;
5423 case NE
: fputs ("c1t", file
); break;
5425 fatal_insn ("PRINT_OPERAND, invalid insn for %%F", op
);
5428 else if (letter
== 'W')
5431 case EQ
: fputs ("c1t", file
); break;
5432 case NE
: fputs ("c1f", file
); break;
5434 fatal_insn ("PRINT_OPERAND, invalid insn for %%W", op
);
5437 else if (letter
== 'h')
5439 if (GET_CODE (op
) == HIGH
)
5442 print_operand_reloc (file
, op
, mips_hi_relocs
);
5445 else if (letter
== 'R')
5446 print_operand_reloc (file
, op
, mips_lo_relocs
);
5448 else if (letter
== 'S')
5452 ASM_GENERATE_INTERNAL_LABEL (buffer
, "LS", CODE_LABEL_NUMBER (op
));
5453 assemble_name (file
, buffer
);
5456 else if (letter
== 'Z')
5458 register int regnum
;
5463 regnum
= REGNO (op
);
5464 if (! ST_REG_P (regnum
))
5467 if (regnum
!= ST_REG_FIRST
)
5468 fprintf (file
, "%s,", reg_names
[regnum
]);
5471 else if (code
== REG
|| code
== SUBREG
)
5473 register int regnum
;
5476 regnum
= REGNO (op
);
5478 regnum
= true_regnum (op
);
5480 if ((letter
== 'M' && ! WORDS_BIG_ENDIAN
)
5481 || (letter
== 'L' && WORDS_BIG_ENDIAN
)
5485 fprintf (file
, "%s", reg_names
[regnum
]);
5488 else if (code
== MEM
)
5491 output_address (plus_constant (XEXP (op
, 0), 4));
5493 output_address (XEXP (op
, 0));
5496 else if (letter
== 'x' && GET_CODE (op
) == CONST_INT
)
5497 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, 0xffff & INTVAL(op
));
5499 else if (letter
== 'X' && GET_CODE(op
) == CONST_INT
)
5500 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (op
));
5502 else if (letter
== 'd' && GET_CODE(op
) == CONST_INT
)
5503 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, (INTVAL(op
)));
5505 else if (letter
== 'z' && op
== CONST0_RTX (GET_MODE (op
)))
5506 fputs (reg_names
[GP_REG_FIRST
], file
);
5508 else if (letter
== 'd' || letter
== 'x' || letter
== 'X')
5509 output_operand_lossage ("invalid use of %%d, %%x, or %%X");
5511 else if (letter
== 'B')
5512 fputs (code
== EQ
? "z" : "n", file
);
5513 else if (letter
== 'b')
5514 fputs (code
== EQ
? "n" : "z", file
);
5515 else if (letter
== 'T')
5516 fputs (code
== EQ
? "f" : "t", file
);
5517 else if (letter
== 't')
5518 fputs (code
== EQ
? "t" : "f", file
);
5520 else if (CONST_GP_P (op
))
5521 print_operand (file
, XEXP (op
, 0), letter
);
5524 output_addr_const (file
, op
);
5528 /* Print symbolic operand OP, which is part of a HIGH or LO_SUM.
5529 RELOCS is the array of relocations to use. */
5532 print_operand_reloc (FILE *file
, rtx op
, const char **relocs
)
5534 enum mips_symbol_type symbol_type
;
5537 HOST_WIDE_INT offset
;
5539 if (!mips_symbolic_constant_p (op
, &symbol_type
) || relocs
[symbol_type
] == 0)
5540 fatal_insn ("PRINT_OPERAND, invalid operand for relocation", op
);
5542 /* If OP uses an UNSPEC address, we want to print the inner symbol. */
5543 mips_split_const (op
, &base
, &offset
);
5544 if (UNSPEC_ADDRESS_P (base
))
5545 op
= plus_constant (UNSPEC_ADDRESS (base
), offset
);
5547 fputs (relocs
[symbol_type
], file
);
5548 output_addr_const (file
, op
);
5549 for (p
= relocs
[symbol_type
]; *p
!= 0; p
++)
5554 /* Output address operand X to FILE. */
5557 print_operand_address (FILE *file
, rtx x
)
5559 struct mips_address_info addr
;
5561 if (mips_classify_address (&addr
, x
, word_mode
, true))
5565 print_operand (file
, addr
.offset
, 0);
5566 fprintf (file
, "(%s)", reg_names
[REGNO (addr
.reg
)]);
5569 case ADDRESS_LO_SUM
:
5570 print_operand (file
, addr
.offset
, 'R');
5571 fprintf (file
, "(%s)", reg_names
[REGNO (addr
.reg
)]);
5574 case ADDRESS_CONST_INT
:
5575 case ADDRESS_SYMBOLIC
:
5576 output_addr_const (file
, x
);
5582 /* Target hook for assembling integer objects. It appears that the Irix
5583 6 assembler can't handle 64-bit decimal integers, so avoid printing
5584 such an integer here. */
5587 mips_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
5589 if ((TARGET_64BIT
|| TARGET_GAS
) && size
== 8 && aligned_p
)
5591 fputs ("\t.dword\t", asm_out_file
);
5592 if (HOST_BITS_PER_WIDE_INT
< 64 || GET_CODE (x
) != CONST_INT
)
5593 output_addr_const (asm_out_file
, x
);
5595 print_operand (asm_out_file
, x
, 'X');
5596 fputc ('\n', asm_out_file
);
5599 return default_assemble_integer (x
, size
, aligned_p
);
5602 /* When using assembler macros, keep track of all of small-data externs
5603 so that mips_file_end can emit the appropriate declarations for them.
5605 In most cases it would be safe (though pointless) to emit .externs
5606 for other symbols too. One exception is when an object is within
5607 the -G limit but declared by the user to be in a section other
5608 than .sbss or .sdata. */
5611 mips_output_external (FILE *file ATTRIBUTE_UNUSED
, tree decl
, const char *name
)
5613 register struct extern_list
*p
;
5615 if (!TARGET_EXPLICIT_RELOCS
&& mips_in_small_data_p (decl
))
5617 p
= (struct extern_list
*) ggc_alloc (sizeof (struct extern_list
));
5618 p
->next
= extern_head
;
5620 p
->size
= int_size_in_bytes (TREE_TYPE (decl
));
5624 if (TARGET_IRIX
&& mips_abi
== ABI_32
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5626 p
= (struct extern_list
*) ggc_alloc (sizeof (struct extern_list
));
5627 p
->next
= extern_head
;
5638 irix_output_external_libcall (rtx fun
)
5640 register struct extern_list
*p
;
5642 if (mips_abi
== ABI_32
)
5644 p
= (struct extern_list
*) ggc_alloc (sizeof (struct extern_list
));
5645 p
->next
= extern_head
;
5646 p
->name
= XSTR (fun
, 0);
5653 /* Emit a new filename to a stream. If we are smuggling stabs, try to
5654 put out a MIPS ECOFF file and a stab. */
5657 mips_output_filename (FILE *stream
, const char *name
)
5659 char ltext_label_name
[100];
5661 /* If we are emitting DWARF-2, let dwarf2out handle the ".file"
5663 if (write_symbols
== DWARF2_DEBUG
)
5665 else if (mips_output_filename_first_time
)
5667 mips_output_filename_first_time
= 0;
5669 current_function_file
= name
;
5670 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
5671 /* This tells mips-tfile that stabs will follow. */
5672 if (!TARGET_GAS
&& write_symbols
== DBX_DEBUG
)
5673 fprintf (stream
, "\t#@stabs\n");
5676 else if (write_symbols
== DBX_DEBUG
)
5678 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name
, "Ltext", 0);
5679 fprintf (stream
, "%s", ASM_STABS_OP
);
5680 output_quoted_string (stream
, name
);
5681 fprintf (stream
, ",%d,0,0,%s\n", N_SOL
, <ext_label_name
[1]);
5684 else if (name
!= current_function_file
5685 && strcmp (name
, current_function_file
) != 0)
5688 current_function_file
= name
;
5689 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
5693 /* Emit a linenumber. For encapsulated stabs, we need to put out a stab
5694 as well as a .loc, since it is possible that MIPS ECOFF might not be
5695 able to represent the location for inlines that come from a different
5699 mips_output_lineno (FILE *stream
, int line
)
5701 if (write_symbols
== DBX_DEBUG
)
5704 fprintf (stream
, "%sLM%d:\n%s%d,0,%d,%sLM%d\n",
5705 LOCAL_LABEL_PREFIX
, sym_lineno
, ASM_STABN_OP
, N_SLINE
, line
,
5706 LOCAL_LABEL_PREFIX
, sym_lineno
);
5710 fprintf (stream
, "\n\t.loc\t%d %d\n", num_source_filenames
, line
);
5711 LABEL_AFTER_LOC (stream
);
5715 /* Output an ASCII string, in a space-saving way. */
5718 mips_output_ascii (FILE *stream
, const char *string_param
, size_t len
)
5722 register const unsigned char *string
=
5723 (const unsigned char *)string_param
;
5725 fprintf (stream
, "\t.ascii\t\"");
5726 for (i
= 0; i
< len
; i
++)
5728 register int c
= string
[i
];
5734 putc ('\\', stream
);
5739 case TARGET_NEWLINE
:
5740 fputs ("\\n", stream
);
5742 && (((c
= string
[i
+1]) >= '\040' && c
<= '~')
5743 || c
== TARGET_TAB
))
5744 cur_pos
= 32767; /* break right here */
5750 fputs ("\\t", stream
);
5755 fputs ("\\f", stream
);
5760 fputs ("\\b", stream
);
5765 fputs ("\\r", stream
);
5770 if (c
>= ' ' && c
< 0177)
5777 fprintf (stream
, "\\%03o", c
);
5782 if (cur_pos
> 72 && i
+1 < len
)
5785 fprintf (stream
, "\"\n\t.ascii\t\"");
5788 fprintf (stream
, "\"\n");
5791 /* Implement TARGET_ASM_FILE_START. */
5794 mips_file_start (void)
5796 default_file_start ();
5798 /* Versions of the MIPS assembler before 2.20 generate errors if a branch
5799 inside of a .set noreorder section jumps to a label outside of the .set
5800 noreorder section. Revision 2.20 just set nobopt silently rather than
5803 if (TARGET_MIPS_AS
&& optimize
&& flag_delayed_branch
)
5804 fprintf (asm_out_file
, "\t.set\tnobopt\n");
5808 #if defined(OBJECT_FORMAT_ELF) && !TARGET_IRIX
5809 /* Generate a special section to describe the ABI switches used to
5810 produce the resultant binary. This used to be done by the assembler
5811 setting bits in the ELF header's flags field, but we have run out of
5812 bits. GDB needs this information in order to be able to correctly
5813 debug these binaries. See the function mips_gdbarch_init() in
5814 gdb/mips-tdep.c. This is unnecessary for the IRIX 5/6 ABIs and
5815 causes unnecessary IRIX 6 ld warnings. */
5816 const char * abi_string
= NULL
;
5820 case ABI_32
: abi_string
= "abi32"; break;
5821 case ABI_N32
: abi_string
= "abiN32"; break;
5822 case ABI_64
: abi_string
= "abi64"; break;
5823 case ABI_O64
: abi_string
= "abiO64"; break;
5824 case ABI_EABI
: abi_string
= TARGET_64BIT
? "eabi64" : "eabi32"; break;
5828 /* Note - we use fprintf directly rather than called named_section()
5829 because in this way we can avoid creating an allocated section. We
5830 do not want this section to take up any space in the running
5832 fprintf (asm_out_file
, "\t.section .mdebug.%s\n", abi_string
);
5834 /* Restore the default section. */
5835 fprintf (asm_out_file
, "\t.previous\n");
5839 /* Generate the pseudo ops that System V.4 wants. */
5840 #ifndef ABICALLS_ASM_OP
5841 #define ABICALLS_ASM_OP "\t.abicalls"
5843 if (TARGET_ABICALLS
)
5844 /* ??? but do not want this (or want pic0) if -non-shared? */
5845 fprintf (asm_out_file
, "%s\n", ABICALLS_ASM_OP
);
5848 fprintf (asm_out_file
, "\t.set\tmips16\n");
5850 if (flag_verbose_asm
)
5851 fprintf (asm_out_file
, "\n%s -G value = %d, Arch = %s, ISA = %d\n",
5853 mips_section_threshold
, mips_arch_info
->name
, mips_isa
);
5856 #ifdef BSS_SECTION_ASM_OP
5857 /* Implement ASM_OUTPUT_ALIGNED_BSS. This differs from the default only
5858 in the use of sbss. */
5861 mips_output_aligned_bss (FILE *stream
, tree decl
, const char *name
,
5862 unsigned HOST_WIDE_INT size
, int align
)
5864 extern tree last_assemble_variable_decl
;
5866 if (mips_in_small_data_p (decl
))
5867 named_section (0, ".sbss", 0);
5870 ASM_OUTPUT_ALIGN (stream
, floor_log2 (align
/ BITS_PER_UNIT
));
5871 last_assemble_variable_decl
= decl
;
5872 ASM_DECLARE_OBJECT_NAME (stream
, name
, decl
);
5873 ASM_OUTPUT_SKIP (stream
, size
!= 0 ? size
: 1);
5877 /* Implement TARGET_ASM_FILE_END. When using assembler macros, emit
5878 .externs for any small-data variables that turned out to be external. */
5881 mips_file_end (void)
5884 struct extern_list
*p
;
5888 fputs ("\n", asm_out_file
);
5890 for (p
= extern_head
; p
!= 0; p
= p
->next
)
5892 name_tree
= get_identifier (p
->name
);
5894 /* Positively ensure only one .extern for any given symbol. */
5895 if (!TREE_ASM_WRITTEN (name_tree
)
5896 && TREE_SYMBOL_REFERENCED (name_tree
))
5898 TREE_ASM_WRITTEN (name_tree
) = 1;
5899 /* In IRIX 5 or IRIX 6 for the O32 ABI, we must output a
5900 `.global name .text' directive for every used but
5901 undefined function. If we don't, the linker may perform
5902 an optimization (skipping over the insns that set $gp)
5903 when it is unsafe. */
5904 if (TARGET_IRIX
&& mips_abi
== ABI_32
&& p
->size
== -1)
5906 fputs ("\t.globl ", asm_out_file
);
5907 assemble_name (asm_out_file
, p
->name
);
5908 fputs (" .text\n", asm_out_file
);
5912 fputs ("\t.extern\t", asm_out_file
);
5913 assemble_name (asm_out_file
, p
->name
);
5914 fprintf (asm_out_file
, ", %d\n", p
->size
);
5921 /* Emit either a label, .comm, or .lcomm directive. When using assembler
5922 macros, mark the symbol as written so that mips_file_end won't emit an
5926 mips_declare_object (FILE *stream
, const char *name
, const char *init_string
,
5927 const char *final_string
, int size
)
5929 fputs (init_string
, stream
); /* "", "\t.comm\t", or "\t.lcomm\t" */
5930 assemble_name (stream
, name
);
5931 fprintf (stream
, final_string
, size
); /* ":\n", ",%u\n", ",%u\n" */
5933 if (!TARGET_EXPLICIT_RELOCS
)
5935 tree name_tree
= get_identifier (name
);
5936 TREE_ASM_WRITTEN (name_tree
) = 1;
5940 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
5941 extern int size_directive_output
;
5943 /* Implement ASM_DECLARE_OBJECT_NAME. This is like most of the standard ELF
5944 definitions except that it uses mips_declare_object() to emit the label. */
5947 mips_declare_object_name (FILE *stream
, const char *name
,
5948 tree decl ATTRIBUTE_UNUSED
)
5950 if (!TARGET_SGI_O32_AS
)
5952 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
5953 ASM_OUTPUT_TYPE_DIRECTIVE (stream
, name
, "object");
5956 size_directive_output
= 0;
5957 if (!flag_inhibit_size_directive
&& DECL_SIZE (decl
))
5961 size_directive_output
= 1;
5962 size
= int_size_in_bytes (TREE_TYPE (decl
));
5963 ASM_OUTPUT_SIZE_DIRECTIVE (stream
, name
, size
);
5967 mips_declare_object (stream
, name
, "", ":\n", 0);
5970 /* Implement ASM_FINISH_DECLARE_OBJECT. This is generic ELF stuff. */
5973 mips_finish_declare_object (FILE *stream
, tree decl
, int top_level
, int at_end
)
5977 name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5978 if (!TARGET_SGI_O32_AS
5979 && !flag_inhibit_size_directive
5980 && DECL_SIZE (decl
) != 0
5981 && !at_end
&& top_level
5982 && DECL_INITIAL (decl
) == error_mark_node
5983 && !size_directive_output
)
5987 size_directive_output
= 1;
5988 size
= int_size_in_bytes (TREE_TYPE (decl
));
5989 ASM_OUTPUT_SIZE_DIRECTIVE (stream
, name
, size
);
5994 /* Return true if X is a small data address that can be rewritten
5998 mips_rewrite_small_data_p (rtx x
)
6000 enum mips_symbol_type symbol_type
;
6002 return (TARGET_EXPLICIT_RELOCS
6003 && mips_symbolic_constant_p (x
, &symbol_type
)
6004 && symbol_type
== SYMBOL_SMALL_DATA
);
6008 /* A for_each_rtx callback for small_data_pattern. */
6011 small_data_pattern_1 (rtx
*loc
, void *data ATTRIBUTE_UNUSED
)
6013 if (GET_CODE (*loc
) == LO_SUM
)
6016 return mips_rewrite_small_data_p (*loc
);
6019 /* Return true if OP refers to small data symbols directly, not through
6023 small_data_pattern (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
6025 return (GET_CODE (op
) != SEQUENCE
6026 && for_each_rtx (&op
, small_data_pattern_1
, 0));
6029 /* A for_each_rtx callback, used by mips_rewrite_small_data. */
6032 mips_rewrite_small_data_1 (rtx
*loc
, void *data ATTRIBUTE_UNUSED
)
6034 if (mips_rewrite_small_data_p (*loc
))
6035 *loc
= gen_rtx_LO_SUM (Pmode
, pic_offset_table_rtx
, *loc
);
6037 if (GET_CODE (*loc
) == LO_SUM
)
6043 /* If possible, rewrite OP so that it refers to small data using
6044 explicit relocations. */
6047 mips_rewrite_small_data (rtx op
)
6049 op
= copy_insn (op
);
6050 for_each_rtx (&op
, mips_rewrite_small_data_1
, 0);
6054 /* Return true if the current function has an insn that implicitly
6058 mips_function_has_gp_insn (void)
6060 /* Don't bother rechecking if we found one last time. */
6061 if (!cfun
->machine
->has_gp_insn_p
)
6065 push_topmost_sequence ();
6066 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6068 && GET_CODE (PATTERN (insn
)) != USE
6069 && GET_CODE (PATTERN (insn
)) != CLOBBER
6070 && (get_attr_got (insn
) != GOT_UNSET
6071 || small_data_pattern (PATTERN (insn
), VOIDmode
)))
6073 pop_topmost_sequence ();
6075 cfun
->machine
->has_gp_insn_p
= (insn
!= 0);
6077 return cfun
->machine
->has_gp_insn_p
;
6081 /* Return the register that should be used as the global pointer
6082 within this function. Return 0 if the function doesn't need
6083 a global pointer. */
6086 mips_global_pointer (void)
6090 /* $gp is always available in non-abicalls code. */
6091 if (!TARGET_ABICALLS
)
6092 return GLOBAL_POINTER_REGNUM
;
6094 /* We must always provide $gp when it is used implicitly. */
6095 if (!TARGET_EXPLICIT_RELOCS
)
6096 return GLOBAL_POINTER_REGNUM
;
6098 /* FUNCTION_PROFILER includes a jal macro, so we need to give it
6100 if (current_function_profile
)
6101 return GLOBAL_POINTER_REGNUM
;
6103 /* If the function has a nonlocal goto, $gp must hold the correct
6104 global pointer for the target function. */
6105 if (current_function_has_nonlocal_goto
)
6106 return GLOBAL_POINTER_REGNUM
;
6108 /* If the gp is never referenced, there's no need to initialize it.
6109 Note that reload can sometimes introduce constant pool references
6110 into a function that otherwise didn't need them. For example,
6111 suppose we have an instruction like:
6113 (set (reg:DF R1) (float:DF (reg:SI R2)))
6115 If R2 turns out to be constant such as 1, the instruction may have a
6116 REG_EQUAL note saying that R1 == 1.0. Reload then has the option of
6117 using this constant if R2 doesn't get allocated to a register.
6119 In cases like these, reload will have added the constant to the pool
6120 but no instruction will yet refer to it. */
6121 if (!regs_ever_live
[GLOBAL_POINTER_REGNUM
]
6122 && !current_function_uses_const_pool
6123 && !mips_function_has_gp_insn ())
6126 /* We need a global pointer, but perhaps we can use a call-clobbered
6127 register instead of $gp. */
6128 if (TARGET_NEWABI
&& current_function_is_leaf
)
6129 for (regno
= GP_REG_FIRST
; regno
<= GP_REG_LAST
; regno
++)
6130 if (!regs_ever_live
[regno
]
6131 && call_used_regs
[regno
]
6132 && !fixed_regs
[regno
]
6133 && regno
!= PIC_FUNCTION_ADDR_REGNUM
)
6136 return GLOBAL_POINTER_REGNUM
;
6140 /* Return true if the current function must save REGNO. */
6143 mips_save_reg_p (unsigned int regno
)
6145 /* We only need to save $gp for NewABI PIC. */
6146 if (regno
== GLOBAL_POINTER_REGNUM
)
6147 return (TARGET_ABICALLS
&& TARGET_NEWABI
6148 && cfun
->machine
->global_pointer
== regno
);
6150 /* Check call-saved registers. */
6151 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
6154 /* We need to save the old frame pointer before setting up a new one. */
6155 if (regno
== HARD_FRAME_POINTER_REGNUM
&& frame_pointer_needed
)
6158 /* We need to save the incoming return address if it is ever clobbered
6159 within the function. */
6160 if (regno
== GP_REG_FIRST
+ 31 && regs_ever_live
[regno
])
6167 return_type
= DECL_RESULT (current_function_decl
);
6169 /* $18 is a special case in mips16 code. It may be used to call
6170 a function which returns a floating point value, but it is
6171 marked in call_used_regs. */
6172 if (regno
== GP_REG_FIRST
+ 18 && regs_ever_live
[regno
])
6175 /* $31 is also a special case. It will be used to copy a return
6176 value into the floating point registers if the return value is
6178 if (regno
== GP_REG_FIRST
+ 31
6179 && mips16_hard_float
6180 && !aggregate_value_p (return_type
, current_function_decl
)
6181 && GET_MODE_CLASS (DECL_MODE (return_type
)) == MODE_FLOAT
6182 && GET_MODE_SIZE (DECL_MODE (return_type
)) <= UNITS_PER_FPVALUE
)
6190 /* Return the bytes needed to compute the frame pointer from the current
6191 stack pointer. SIZE is the size (in bytes) of the local variables.
6193 Mips stack frames look like:
6195 Before call After call
6196 +-----------------------+ +-----------------------+
6199 | caller's temps. | | caller's temps. |
6201 +-----------------------+ +-----------------------+
6203 | arguments on stack. | | arguments on stack. |
6205 +-----------------------+ +-----------------------+
6206 | 4 words to save | | 4 words to save |
6207 | arguments passed | | arguments passed |
6208 | in registers, even | | in registers, even |
6209 SP->| if not passed. | VFP->| if not passed. |
6210 +-----------------------+ +-----------------------+
6212 | fp register save |
6214 +-----------------------+
6216 | gp register save |
6218 +-----------------------+
6222 +-----------------------+
6224 | alloca allocations |
6226 +-----------------------+
6228 | GP save for V.4 abi |
6230 +-----------------------+
6232 | arguments on stack |
6234 +-----------------------+
6236 | arguments passed |
6237 | in registers, even |
6238 low SP->| if not passed. |
6239 memory +-----------------------+
6244 compute_frame_size (HOST_WIDE_INT size
)
6247 HOST_WIDE_INT total_size
; /* # bytes that the entire frame takes up */
6248 HOST_WIDE_INT var_size
; /* # bytes that variables take up */
6249 HOST_WIDE_INT args_size
; /* # bytes that outgoing arguments take up */
6250 HOST_WIDE_INT cprestore_size
; /* # bytes that the cprestore slot takes up */
6251 HOST_WIDE_INT gp_reg_rounded
; /* # bytes needed to store gp after rounding */
6252 HOST_WIDE_INT gp_reg_size
; /* # bytes needed to store gp regs */
6253 HOST_WIDE_INT fp_reg_size
; /* # bytes needed to store fp regs */
6254 unsigned int mask
; /* mask of saved gp registers */
6255 unsigned int fmask
; /* mask of saved fp registers */
6257 cfun
->machine
->global_pointer
= mips_global_pointer ();
6263 var_size
= MIPS_STACK_ALIGN (size
);
6264 args_size
= current_function_outgoing_args_size
;
6265 cprestore_size
= MIPS_STACK_ALIGN (STARTING_FRAME_OFFSET
) - args_size
;
6267 /* The space set aside by STARTING_FRAME_OFFSET isn't needed in leaf
6268 functions. If the function has local variables, we're committed
6269 to allocating it anyway. Otherwise reclaim it here. */
6270 if (var_size
== 0 && current_function_is_leaf
)
6271 cprestore_size
= args_size
= 0;
6273 /* The MIPS 3.0 linker does not like functions that dynamically
6274 allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it
6275 looks like we are trying to create a second frame pointer to the
6276 function, so allocate some stack space to make it happy. */
6278 if (args_size
== 0 && current_function_calls_alloca
)
6279 args_size
= 4 * UNITS_PER_WORD
;
6281 total_size
= var_size
+ args_size
+ cprestore_size
;
6283 /* Calculate space needed for gp registers. */
6284 for (regno
= GP_REG_FIRST
; regno
<= GP_REG_LAST
; regno
++)
6285 if (mips_save_reg_p (regno
))
6287 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6288 mask
|= 1 << (regno
- GP_REG_FIRST
);
6291 /* We need to restore these for the handler. */
6292 if (current_function_calls_eh_return
)
6297 regno
= EH_RETURN_DATA_REGNO (i
);
6298 if (regno
== INVALID_REGNUM
)
6300 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6301 mask
|= 1 << (regno
- GP_REG_FIRST
);
6305 /* This loop must iterate over the same space as its companion in
6306 save_restore_insns. */
6307 for (regno
= (FP_REG_LAST
- FP_INC
+ 1);
6308 regno
>= FP_REG_FIRST
;
6311 if (mips_save_reg_p (regno
))
6313 fp_reg_size
+= FP_INC
* UNITS_PER_FPREG
;
6314 fmask
|= ((1 << FP_INC
) - 1) << (regno
- FP_REG_FIRST
);
6318 gp_reg_rounded
= MIPS_STACK_ALIGN (gp_reg_size
);
6319 total_size
+= gp_reg_rounded
+ MIPS_STACK_ALIGN (fp_reg_size
);
6321 /* Add in space reserved on the stack by the callee for storing arguments
6322 passed in registers. */
6323 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
6324 total_size
+= MIPS_STACK_ALIGN (current_function_pretend_args_size
);
6326 /* Save other computed information. */
6327 cfun
->machine
->frame
.total_size
= total_size
;
6328 cfun
->machine
->frame
.var_size
= var_size
;
6329 cfun
->machine
->frame
.args_size
= args_size
;
6330 cfun
->machine
->frame
.cprestore_size
= cprestore_size
;
6331 cfun
->machine
->frame
.gp_reg_size
= gp_reg_size
;
6332 cfun
->machine
->frame
.fp_reg_size
= fp_reg_size
;
6333 cfun
->machine
->frame
.mask
= mask
;
6334 cfun
->machine
->frame
.fmask
= fmask
;
6335 cfun
->machine
->frame
.initialized
= reload_completed
;
6336 cfun
->machine
->frame
.num_gp
= gp_reg_size
/ UNITS_PER_WORD
;
6337 cfun
->machine
->frame
.num_fp
= fp_reg_size
/ (FP_INC
* UNITS_PER_FPREG
);
6341 HOST_WIDE_INT offset
;
6343 offset
= (args_size
+ cprestore_size
+ var_size
6344 + gp_reg_size
- GET_MODE_SIZE (gpr_mode
));
6345 cfun
->machine
->frame
.gp_sp_offset
= offset
;
6346 cfun
->machine
->frame
.gp_save_offset
= offset
- total_size
;
6350 cfun
->machine
->frame
.gp_sp_offset
= 0;
6351 cfun
->machine
->frame
.gp_save_offset
= 0;
6356 HOST_WIDE_INT offset
;
6358 offset
= (args_size
+ cprestore_size
+ var_size
6359 + gp_reg_rounded
+ fp_reg_size
6360 - FP_INC
* UNITS_PER_FPREG
);
6361 cfun
->machine
->frame
.fp_sp_offset
= offset
;
6362 cfun
->machine
->frame
.fp_save_offset
= offset
- total_size
;
6366 cfun
->machine
->frame
.fp_sp_offset
= 0;
6367 cfun
->machine
->frame
.fp_save_offset
= 0;
6370 /* Ok, we're done. */
6374 /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame
6375 pointer or argument pointer. TO is either the stack pointer or
6376 hard frame pointer. */
6379 mips_initial_elimination_offset (int from
, int to
)
6381 HOST_WIDE_INT offset
;
6383 compute_frame_size (get_frame_size ());
6385 /* Set OFFSET to the offset from the stack pointer. */
6388 case FRAME_POINTER_REGNUM
:
6392 case ARG_POINTER_REGNUM
:
6393 offset
= cfun
->machine
->frame
.total_size
;
6394 if (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
)
6395 offset
-= current_function_pretend_args_size
;
6402 if (TARGET_MIPS16
&& to
== HARD_FRAME_POINTER_REGNUM
)
6403 offset
-= cfun
->machine
->frame
.args_size
;
6408 /* Implement RETURN_ADDR_RTX. Note, we do not support moving
6409 back to a previous frame. */
6411 mips_return_addr (int count
, rtx frame ATTRIBUTE_UNUSED
)
6416 return get_hard_reg_initial_val (Pmode
, GP_REG_FIRST
+ 31);
6419 /* Use FN to save or restore register REGNO. MODE is the register's
6420 mode and OFFSET is the offset of its save slot from the current
6424 mips_save_restore_reg (enum machine_mode mode
, int regno
,
6425 HOST_WIDE_INT offset
, mips_save_restore_fn fn
)
6429 mem
= gen_rtx_MEM (mode
, plus_constant (stack_pointer_rtx
, offset
));
6430 if (!current_function_calls_eh_return
)
6431 RTX_UNCHANGING_P (mem
) = 1;
6433 fn (gen_rtx_REG (mode
, regno
), mem
);
6437 /* Call FN for each register that is saved by the current function.
6438 SP_OFFSET is the offset of the current stack pointer from the start
6442 mips_for_each_saved_reg (HOST_WIDE_INT sp_offset
, mips_save_restore_fn fn
)
6444 #define BITSET_P(VALUE, BIT) (((VALUE) & (1L << (BIT))) != 0)
6446 enum machine_mode fpr_mode
;
6447 HOST_WIDE_INT offset
;
6450 /* Save registers starting from high to low. The debuggers prefer at least
6451 the return register be stored at func+4, and also it allows us not to
6452 need a nop in the epilog if at least one register is reloaded in
6453 addition to return address. */
6454 offset
= cfun
->machine
->frame
.gp_sp_offset
- sp_offset
;
6455 for (regno
= GP_REG_LAST
; regno
>= GP_REG_FIRST
; regno
--)
6456 if (BITSET_P (cfun
->machine
->frame
.mask
, regno
- GP_REG_FIRST
))
6458 mips_save_restore_reg (gpr_mode
, regno
, offset
, fn
);
6459 offset
-= GET_MODE_SIZE (gpr_mode
);
6462 /* This loop must iterate over the same space as its companion in
6463 compute_frame_size. */
6464 offset
= cfun
->machine
->frame
.fp_sp_offset
- sp_offset
;
6465 fpr_mode
= (TARGET_SINGLE_FLOAT
? SFmode
: DFmode
);
6466 for (regno
= (FP_REG_LAST
- FP_INC
+ 1);
6467 regno
>= FP_REG_FIRST
;
6469 if (BITSET_P (cfun
->machine
->frame
.fmask
, regno
- FP_REG_FIRST
))
6471 mips_save_restore_reg (fpr_mode
, regno
, offset
, fn
);
6472 offset
-= GET_MODE_SIZE (fpr_mode
);
6477 /* Set up the stack and frame (if desired) for the function. */
6480 mips_output_function_prologue (FILE *file
, HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6483 HOST_WIDE_INT tsize
= cfun
->machine
->frame
.total_size
;
6485 /* ??? When is this really needed? At least the GNU assembler does not
6486 need the source filename more than once in the file, beyond what is
6487 emitted by the debug information. */
6489 ASM_OUTPUT_SOURCE_FILENAME (file
, DECL_SOURCE_FILE (current_function_decl
));
6491 #ifdef SDB_DEBUGGING_INFO
6492 if (debug_info_level
!= DINFO_LEVEL_TERSE
&& write_symbols
== SDB_DEBUG
)
6493 ASM_OUTPUT_SOURCE_LINE (file
, DECL_SOURCE_LINE (current_function_decl
), 0);
6496 /* In mips16 mode, we may need to generate a 32 bit to handle
6497 floating point arguments. The linker will arrange for any 32 bit
6498 functions to call this stub, which will then jump to the 16 bit
6500 if (TARGET_MIPS16
&& !TARGET_SOFT_FLOAT
6501 && current_function_args_info
.fp_code
!= 0)
6502 build_mips16_function_stub (file
);
6504 if (!FUNCTION_NAME_ALREADY_DECLARED
)
6506 /* Get the function name the same way that toplev.c does before calling
6507 assemble_start_function. This is needed so that the name used here
6508 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
6509 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
6511 if (!flag_inhibit_size_directive
)
6513 fputs ("\t.ent\t", file
);
6514 assemble_name (file
, fnname
);
6518 assemble_name (file
, fnname
);
6519 fputs (":\n", file
);
6522 if (!flag_inhibit_size_directive
)
6524 /* .frame FRAMEREG, FRAMESIZE, RETREG */
6526 "\t.frame\t%s," HOST_WIDE_INT_PRINT_DEC
",%s\t\t"
6527 "# vars= " HOST_WIDE_INT_PRINT_DEC
", regs= %d/%d"
6528 ", args= " HOST_WIDE_INT_PRINT_DEC
6529 ", gp= " HOST_WIDE_INT_PRINT_DEC
"\n",
6530 (reg_names
[(frame_pointer_needed
)
6531 ? HARD_FRAME_POINTER_REGNUM
: STACK_POINTER_REGNUM
]),
6532 ((frame_pointer_needed
&& TARGET_MIPS16
)
6533 ? tsize
- cfun
->machine
->frame
.args_size
6535 reg_names
[GP_REG_FIRST
+ 31],
6536 cfun
->machine
->frame
.var_size
,
6537 cfun
->machine
->frame
.num_gp
,
6538 cfun
->machine
->frame
.num_fp
,
6539 cfun
->machine
->frame
.args_size
,
6540 cfun
->machine
->frame
.cprestore_size
);
6542 /* .mask MASK, GPOFFSET; .fmask FPOFFSET */
6543 fprintf (file
, "\t.mask\t0x%08x," HOST_WIDE_INT_PRINT_DEC
"\n",
6544 cfun
->machine
->frame
.mask
,
6545 cfun
->machine
->frame
.gp_save_offset
);
6546 fprintf (file
, "\t.fmask\t0x%08x," HOST_WIDE_INT_PRINT_DEC
"\n",
6547 cfun
->machine
->frame
.fmask
,
6548 cfun
->machine
->frame
.fp_save_offset
);
6551 OLD_SP == *FRAMEREG + FRAMESIZE => can find old_sp from nominated FP reg.
6552 HIGHEST_GP_SAVED == *FRAMEREG + FRAMESIZE + GPOFFSET => can find saved regs. */
6555 if (TARGET_ABICALLS
&& !TARGET_NEWABI
&& cfun
->machine
->global_pointer
> 0)
6557 /* Handle the initialization of $gp for SVR4 PIC. */
6558 if (!cfun
->machine
->all_noreorder_p
)
6559 output_asm_insn ("%(.cpload\t%^%)", 0);
6561 output_asm_insn ("%(.cpload\t%^\n\t%<", 0);
6563 else if (cfun
->machine
->all_noreorder_p
)
6564 output_asm_insn ("%(%<", 0);
6567 /* Make the last instruction frame related and note that it performs
6568 the operation described by FRAME_PATTERN. */
6571 mips_set_frame_expr (rtx frame_pattern
)
6575 insn
= get_last_insn ();
6576 RTX_FRAME_RELATED_P (insn
) = 1;
6577 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
6583 /* Return a frame-related rtx that stores REG at MEM.
6584 REG must be a single register. */
6587 mips_frame_set (rtx mem
, rtx reg
)
6589 rtx set
= gen_rtx_SET (VOIDmode
, mem
, reg
);
6590 RTX_FRAME_RELATED_P (set
) = 1;
6595 /* Save register REG to MEM. Make the instruction frame-related. */
6598 mips_save_reg (rtx reg
, rtx mem
)
6600 if (GET_MODE (reg
) == DFmode
&& !TARGET_FLOAT64
)
6604 if (mips_split_64bit_move_p (mem
, reg
))
6605 mips_split_64bit_move (mem
, reg
);
6607 emit_move_insn (mem
, reg
);
6609 x1
= mips_frame_set (mips_subword (mem
, 0), mips_subword (reg
, 0));
6610 x2
= mips_frame_set (mips_subword (mem
, 1), mips_subword (reg
, 1));
6611 mips_set_frame_expr (gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, x1
, x2
)));
6616 && REGNO (reg
) != GP_REG_FIRST
+ 31
6617 && !M16_REG_P (REGNO (reg
)))
6619 /* Save a non-mips16 register by moving it through a temporary.
6620 We don't need to do this for $31 since there's a special
6621 instruction for it. */
6622 emit_move_insn (MIPS_PROLOGUE_TEMP (GET_MODE (reg
)), reg
);
6623 emit_move_insn (mem
, MIPS_PROLOGUE_TEMP (GET_MODE (reg
)));
6626 emit_move_insn (mem
, reg
);
6628 mips_set_frame_expr (mips_frame_set (mem
, reg
));
6633 /* Expand the prologue into a bunch of separate insns. */
6636 mips_expand_prologue (void)
6640 if (cfun
->machine
->global_pointer
> 0)
6641 REGNO (pic_offset_table_rtx
) = cfun
->machine
->global_pointer
;
6643 size
= compute_frame_size (get_frame_size ());
6645 /* Save the registers. Allocate up to MIPS_MAX_FIRST_STACK_STEP
6646 bytes beforehand; this is enough to cover the register save area
6647 without going out of range. */
6648 if ((cfun
->machine
->frame
.mask
| cfun
->machine
->frame
.fmask
) != 0)
6650 HOST_WIDE_INT step1
;
6652 step1
= MIN (size
, MIPS_MAX_FIRST_STACK_STEP
);
6653 RTX_FRAME_RELATED_P (emit_insn (gen_add3_insn (stack_pointer_rtx
,
6655 GEN_INT (-step1
)))) = 1;
6657 mips_for_each_saved_reg (size
, mips_save_reg
);
6660 /* Allocate the rest of the frame. */
6663 if (SMALL_OPERAND (-size
))
6664 RTX_FRAME_RELATED_P (emit_insn (gen_add3_insn (stack_pointer_rtx
,
6666 GEN_INT (-size
)))) = 1;
6669 emit_move_insn (MIPS_PROLOGUE_TEMP (Pmode
), GEN_INT (size
));
6672 /* There are no instructions to add or subtract registers
6673 from the stack pointer, so use the frame pointer as a
6674 temporary. We should always be using a frame pointer
6675 in this case anyway. */
6676 if (!frame_pointer_needed
)
6679 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
6680 emit_insn (gen_sub3_insn (hard_frame_pointer_rtx
,
6681 hard_frame_pointer_rtx
,
6682 MIPS_PROLOGUE_TEMP (Pmode
)));
6683 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
6686 emit_insn (gen_sub3_insn (stack_pointer_rtx
,
6688 MIPS_PROLOGUE_TEMP (Pmode
)));
6690 /* Describe the combined effect of the previous instructions. */
6692 (gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
6693 plus_constant (stack_pointer_rtx
, -size
)));
6697 /* Set up the frame pointer, if we're using one. In mips16 code,
6698 we point the frame pointer ahead of the outgoing argument area.
6699 This should allow more variables & incoming arguments to be
6700 accessed with unextended instructions. */
6701 if (frame_pointer_needed
)
6703 if (TARGET_MIPS16
&& cfun
->machine
->frame
.args_size
!= 0)
6705 rtx offset
= GEN_INT (cfun
->machine
->frame
.args_size
);
6707 (emit_insn (gen_add3_insn (hard_frame_pointer_rtx
,
6712 RTX_FRAME_RELATED_P (emit_move_insn (hard_frame_pointer_rtx
,
6713 stack_pointer_rtx
)) = 1;
6716 /* If generating o32/o64 abicalls, save $gp on the stack. */
6717 if (TARGET_ABICALLS
&& !TARGET_NEWABI
&& !current_function_is_leaf
)
6718 emit_insn (gen_cprestore (GEN_INT (current_function_outgoing_args_size
)));
6720 /* If generating n32/n64 abicalls, emit the instructions to load $gp. */
6721 if (TARGET_ABICALLS
&& TARGET_NEWABI
&& cfun
->machine
->global_pointer
> 0)
6723 rtx addr
, offset
, incoming_address
;
6725 addr
= XEXP (DECL_RTL (current_function_decl
), 0);
6726 offset
= mips_unspec_address (addr
, SYMBOL_GOTOFF_LOADGP
);
6727 incoming_address
= gen_rtx_REG (Pmode
, PIC_FUNCTION_ADDR_REGNUM
);
6728 emit_insn (gen_loadgp (offset
, incoming_address
));
6729 if (!TARGET_EXPLICIT_RELOCS
)
6730 emit_insn (gen_loadgp_blockage ());
6733 /* If we are profiling, make sure no instructions are scheduled before
6734 the call to mcount. */
6736 if (current_function_profile
)
6737 emit_insn (gen_blockage ());
6740 /* Do any necessary cleanup after a function to restore stack, frame,
6743 #define RA_MASK BITMASK_HIGH /* 1 << 31 */
6744 #define PIC_OFFSET_TABLE_MASK (1 << (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
6747 mips_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED
,
6748 HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
6752 if (cfun
->machine
->all_noreorder_p
)
6754 /* Avoid using %>%) since it adds excess whitespace. */
6755 output_asm_insn (".set\tmacro", 0);
6756 output_asm_insn (".set\treorder", 0);
6757 set_noreorder
= set_nomacro
= 0;
6760 if (!FUNCTION_NAME_ALREADY_DECLARED
&& !flag_inhibit_size_directive
)
6764 /* Get the function name the same way that toplev.c does before calling
6765 assemble_start_function. This is needed so that the name used here
6766 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
6767 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
6768 fputs ("\t.end\t", file
);
6769 assemble_name (file
, fnname
);
6773 while (string_constants
!= NULL
)
6775 struct string_constant
*next
;
6777 next
= string_constants
->next
;
6778 free (string_constants
);
6779 string_constants
= next
;
6782 /* If any following function uses the same strings as this one, force
6783 them to refer those strings indirectly. Nearby functions could
6784 refer them using pc-relative addressing, but it isn't safe in
6785 general. For instance, some functions may be placed in sections
6786 other than .text, and we don't know whether they be close enough
6787 to this one. In large files, even other .text functions can be
6789 for (string
= mips16_strings
; string
!= 0; string
= XEXP (string
, 1))
6790 SYMBOL_REF_FLAG (XEXP (string
, 0)) = 0;
6791 free_EXPR_LIST_list (&mips16_strings
);
6793 /* Reinstate the normal $gp. */
6794 REGNO (pic_offset_table_rtx
) = GLOBAL_POINTER_REGNUM
;
6797 /* Emit instructions to restore register REG from slot MEM. */
6800 mips_restore_reg (rtx reg
, rtx mem
)
6802 /* There's no mips16 instruction to load $31 directly. Load into
6803 $7 instead and adjust the return insn appropriately. */
6804 if (TARGET_MIPS16
&& REGNO (reg
) == GP_REG_FIRST
+ 31)
6805 reg
= gen_rtx_REG (GET_MODE (reg
), 7);
6807 if (TARGET_MIPS16
&& !M16_REG_P (REGNO (reg
)))
6809 /* Can't restore directly; move through a temporary. */
6810 emit_move_insn (MIPS_EPILOGUE_TEMP (GET_MODE (reg
)), mem
);
6811 emit_move_insn (reg
, MIPS_EPILOGUE_TEMP (GET_MODE (reg
)));
6814 emit_move_insn (reg
, mem
);
6818 /* Expand the epilogue into a bunch of separate insns. SIBCALL_P is true
6819 if this epilogue precedes a sibling call, false if it is for a normal
6820 "epilogue" pattern. */
6823 mips_expand_epilogue (int sibcall_p
)
6825 HOST_WIDE_INT step1
, step2
;
6828 if (!sibcall_p
&& mips_can_use_return_insn ())
6830 emit_jump_insn (gen_return ());
6834 /* Split the frame into two. STEP1 is the amount of stack we should
6835 deallocate before restoring the registers. STEP2 is the amount we
6836 should deallocate afterwards.
6838 Start off by assuming that no registers need to be restored. */
6839 step1
= cfun
->machine
->frame
.total_size
;
6842 /* Work out which register holds the frame address. Account for the
6843 frame pointer offset used by mips16 code. */
6844 if (!frame_pointer_needed
)
6845 base
= stack_pointer_rtx
;
6848 base
= hard_frame_pointer_rtx
;
6850 step1
-= cfun
->machine
->frame
.args_size
;
6853 /* If we need to restore registers, deallocate as much stack as
6854 possible in the second step without going out of range. */
6855 if ((cfun
->machine
->frame
.mask
| cfun
->machine
->frame
.fmask
) != 0)
6857 step2
= MIN (step1
, MIPS_MAX_FIRST_STACK_STEP
);
6861 /* Set TARGET to BASE + STEP1. */
6867 /* Get an rtx for STEP1 that we can add to BASE. */
6868 adjust
= GEN_INT (step1
);
6869 if (!SMALL_OPERAND (step1
))
6871 emit_move_insn (MIPS_EPILOGUE_TEMP (Pmode
), adjust
);
6872 adjust
= MIPS_EPILOGUE_TEMP (Pmode
);
6875 /* Normal mode code can copy the result straight into $sp. */
6877 target
= stack_pointer_rtx
;
6879 emit_insn (gen_add3_insn (target
, base
, adjust
));
6882 /* Copy TARGET into the stack pointer. */
6883 if (target
!= stack_pointer_rtx
)
6884 emit_move_insn (stack_pointer_rtx
, target
);
6886 /* If we're using addressing macros for n32/n64 abicalls, $gp is
6887 implicitly used by all SYMBOL_REFs. We must emit a blockage
6888 insn before restoring it. */
6889 if (TARGET_ABICALLS
&& TARGET_NEWABI
&& !TARGET_EXPLICIT_RELOCS
)
6890 emit_insn (gen_blockage ());
6892 /* Restore the registers. */
6893 mips_for_each_saved_reg (cfun
->machine
->frame
.total_size
- step2
,
6896 /* Deallocate the final bit of the frame. */
6898 emit_insn (gen_add3_insn (stack_pointer_rtx
,
6902 /* Add in the __builtin_eh_return stack adjustment. We need to
6903 use a temporary in mips16 code. */
6904 if (current_function_calls_eh_return
)
6908 emit_move_insn (MIPS_EPILOGUE_TEMP (Pmode
), stack_pointer_rtx
);
6909 emit_insn (gen_add3_insn (MIPS_EPILOGUE_TEMP (Pmode
),
6910 MIPS_EPILOGUE_TEMP (Pmode
),
6911 EH_RETURN_STACKADJ_RTX
));
6912 emit_move_insn (stack_pointer_rtx
, MIPS_EPILOGUE_TEMP (Pmode
));
6915 emit_insn (gen_add3_insn (stack_pointer_rtx
,
6917 EH_RETURN_STACKADJ_RTX
));
6922 /* The mips16 loads the return address into $7, not $31. */
6923 if (TARGET_MIPS16
&& (cfun
->machine
->frame
.mask
& RA_MASK
) != 0)
6924 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
6925 GP_REG_FIRST
+ 7)));
6927 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
6928 GP_REG_FIRST
+ 31)));
6932 /* Return nonzero if this function is known to have a null epilogue.
6933 This allows the optimizer to omit jumps to jumps if no stack
6937 mips_can_use_return_insn (void)
6941 if (! reload_completed
)
6944 if (regs_ever_live
[31] || current_function_profile
)
6947 return_type
= DECL_RESULT (current_function_decl
);
6949 /* In mips16 mode, a function which returns a floating point value
6950 needs to arrange to copy the return value into the floating point
6953 && mips16_hard_float
6954 && ! aggregate_value_p (return_type
, current_function_decl
)
6955 && GET_MODE_CLASS (DECL_MODE (return_type
)) == MODE_FLOAT
6956 && GET_MODE_SIZE (DECL_MODE (return_type
)) <= UNITS_PER_FPVALUE
)
6959 if (cfun
->machine
->frame
.initialized
)
6960 return cfun
->machine
->frame
.total_size
== 0;
6962 return compute_frame_size (get_frame_size ()) == 0;
6965 /* Returns nonzero if X contains a SYMBOL_REF. */
6968 symbolic_expression_p (rtx x
)
6970 if (GET_CODE (x
) == SYMBOL_REF
)
6973 if (GET_CODE (x
) == CONST
)
6974 return symbolic_expression_p (XEXP (x
, 0));
6976 if (GET_RTX_CLASS (GET_CODE (x
)) == '1')
6977 return symbolic_expression_p (XEXP (x
, 0));
6979 if (GET_RTX_CLASS (GET_CODE (x
)) == 'c'
6980 || GET_RTX_CLASS (GET_CODE (x
)) == '2')
6981 return (symbolic_expression_p (XEXP (x
, 0))
6982 || symbolic_expression_p (XEXP (x
, 1)));
6987 /* Choose the section to use for the constant rtx expression X that has
6991 mips_select_rtx_section (enum machine_mode mode
, rtx x
,
6992 unsigned HOST_WIDE_INT align
)
6996 /* In mips16 mode, the constant table always goes in the same section
6997 as the function, so that constants can be loaded using PC relative
6999 function_section (current_function_decl
);
7001 else if (TARGET_EMBEDDED_DATA
)
7003 /* For embedded applications, always put constants in read-only data,
7004 in order to reduce RAM usage. */
7005 mergeable_constant_section (mode
, align
, 0);
7009 /* For hosted applications, always put constants in small data if
7010 possible, as this gives the best performance. */
7011 /* ??? Consider using mergeable small data sections. */
7013 if (GET_MODE_SIZE (mode
) <= (unsigned) mips_section_threshold
7014 && mips_section_threshold
> 0)
7015 named_section (0, ".sdata", 0);
7016 else if (flag_pic
&& symbolic_expression_p (x
))
7018 if (targetm
.have_named_sections
)
7019 named_section (0, ".data.rel.ro", 3);
7024 mergeable_constant_section (mode
, align
, 0);
7028 /* Choose the section to use for DECL. RELOC is true if its value contains
7029 any relocatable expression. */
7032 mips_select_section (tree decl
, int reloc
,
7033 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
7035 if ((TARGET_EMBEDDED_PIC
|| TARGET_MIPS16
)
7036 && TREE_CODE (decl
) == STRING_CST
7037 && !flag_writable_strings
)
7038 /* For embedded position independent code, put constant strings in the
7039 text section, because the data section is limited to 64K in size.
7040 For mips16 code, put strings in the text section so that a PC
7041 relative load instruction can be used to get their address. */
7043 else if (targetm
.have_named_sections
)
7044 default_elf_select_section (decl
, reloc
, align
);
7046 /* The native irix o32 assembler doesn't support named sections. */
7047 default_select_section (decl
, reloc
, align
);
7051 /* Implement TARGET_IN_SMALL_DATA_P. Return true if it would be safe to
7052 access DECL using %gp_rel(...)($gp). */
7055 mips_in_small_data_p (tree decl
)
7059 if (TREE_CODE (decl
) == STRING_CST
|| TREE_CODE (decl
) == FUNCTION_DECL
)
7062 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_SECTION_NAME (decl
) != 0)
7066 /* Reject anything that isn't in a known small-data section. */
7067 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
7068 if (strcmp (name
, ".sdata") != 0 && strcmp (name
, ".sbss") != 0)
7071 /* If a symbol is defined externally, the assembler will use the
7072 usual -G rules when deciding how to implement macros. */
7073 if (TARGET_EXPLICIT_RELOCS
|| !DECL_EXTERNAL (decl
))
7076 else if (TARGET_EMBEDDED_DATA
)
7078 /* Don't put constants into the small data section: we want them
7079 to be in ROM rather than RAM. */
7080 if (TREE_CODE (decl
) != VAR_DECL
)
7083 if (TREE_READONLY (decl
)
7084 && !TREE_SIDE_EFFECTS (decl
)
7085 && (!DECL_INITIAL (decl
) || TREE_CONSTANT (DECL_INITIAL (decl
))))
7089 size
= int_size_in_bytes (TREE_TYPE (decl
));
7090 return (size
> 0 && size
<= mips_section_threshold
);
7094 /* When generating embedded PIC code, SYMBOL_REF_FLAG is set for
7095 symbols which are not in the .text section.
7097 When generating mips16 code, SYMBOL_REF_FLAG is set for string
7098 constants which are put in the .text section. We also record the
7099 total length of all such strings; this total is used to decide
7100 whether we need to split the constant table, and need not be
7101 precisely correct. */
7104 mips_encode_section_info (tree decl
, rtx rtl
, int first
)
7108 if (GET_CODE (rtl
) != MEM
)
7111 symbol
= XEXP (rtl
, 0);
7113 if (GET_CODE (symbol
) != SYMBOL_REF
)
7118 if (first
&& TREE_CODE (decl
) == STRING_CST
7119 && ! flag_writable_strings
7120 /* If this string is from a function, and the function will
7121 go in a gnu linkonce section, then we can't directly
7122 access the string. This gets an assembler error
7123 "unsupported PC relative reference to different section".
7124 If we modify SELECT_SECTION to put it in function_section
7125 instead of text_section, it still fails because
7126 DECL_SECTION_NAME isn't set until assemble_start_function.
7127 If we fix that, it still fails because strings are shared
7128 among multiple functions, and we have cross section
7129 references again. We force it to work by putting string
7130 addresses in the constant pool and indirecting. */
7131 && (! current_function_decl
7132 || ! DECL_ONE_ONLY (current_function_decl
)))
7134 mips16_strings
= alloc_EXPR_LIST (0, symbol
, mips16_strings
);
7135 SYMBOL_REF_FLAG (symbol
) = 1;
7136 mips_string_length
+= TREE_STRING_LENGTH (decl
);
7140 if (TARGET_EMBEDDED_PIC
)
7142 if (TREE_CODE (decl
) == VAR_DECL
)
7143 SYMBOL_REF_FLAG (symbol
) = 1;
7144 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
7145 SYMBOL_REF_FLAG (symbol
) = 0;
7146 else if (TREE_CODE (decl
) == STRING_CST
7147 && ! flag_writable_strings
)
7148 SYMBOL_REF_FLAG (symbol
) = 0;
7150 SYMBOL_REF_FLAG (symbol
) = 1;
7153 default_encode_section_info (decl
, rtl
, first
);
7156 /* See whether VALTYPE is a record whose fields should be returned in
7157 floating-point registers. If so, return the number of fields and
7158 list them in FIELDS (which should have two elements). Return 0
7161 For n32 & n64, a structure with one or two fields is returned in
7162 floating-point registers as long as every field has a floating-point
7166 mips_fpr_return_fields (tree valtype
, tree
*fields
)
7174 if (TREE_CODE (valtype
) != RECORD_TYPE
)
7178 for (field
= TYPE_FIELDS (valtype
); field
!= 0; field
= TREE_CHAIN (field
))
7180 if (TREE_CODE (field
) != FIELD_DECL
)
7183 if (TREE_CODE (TREE_TYPE (field
)) != REAL_TYPE
)
7189 fields
[i
++] = field
;
7195 /* Implement TARGET_RETURN_IN_MSB. For n32 & n64, we should return
7196 a value in the most significant part of $2/$3 if:
7198 - the target is big-endian;
7200 - the value has a structure or union type (we generalize this to
7201 cover aggregates from other languages too); and
7203 - the structure is not returned in floating-point registers. */
7206 mips_return_in_msb (tree valtype
)
7210 return (TARGET_NEWABI
7211 && TARGET_BIG_ENDIAN
7212 && AGGREGATE_TYPE_P (valtype
)
7213 && mips_fpr_return_fields (valtype
, fields
) == 0);
7217 /* Return a composite value in a pair of floating-point registers.
7218 MODE1 and OFFSET1 are the mode and byte offset for the first value,
7219 likewise MODE2 and OFFSET2 for the second. MODE is the mode of the
7222 For n32 & n64, $f0 always holds the first value and $f2 the second.
7223 Otherwise the values are packed together as closely as possible. */
7226 mips_return_fpr_pair (enum machine_mode mode
,
7227 enum machine_mode mode1
, HOST_WIDE_INT offset1
,
7228 enum machine_mode mode2
, HOST_WIDE_INT offset2
)
7232 inc
= (TARGET_NEWABI
? 2 : FP_INC
);
7233 return gen_rtx_PARALLEL
7236 gen_rtx_EXPR_LIST (VOIDmode
,
7237 gen_rtx_REG (mode1
, FP_RETURN
),
7239 gen_rtx_EXPR_LIST (VOIDmode
,
7240 gen_rtx_REG (mode2
, FP_RETURN
+ inc
),
7241 GEN_INT (offset2
))));
7246 /* Implement FUNCTION_VALUE and LIBCALL_VALUE. For normal calls,
7247 VALTYPE is the return type and MODE is VOIDmode. For libcalls,
7248 VALTYPE is null and MODE is the mode of the return value. */
7251 mips_function_value (tree valtype
, tree func ATTRIBUTE_UNUSED
,
7252 enum machine_mode mode
)
7259 mode
= TYPE_MODE (valtype
);
7260 unsignedp
= TREE_UNSIGNED (valtype
);
7262 /* Since we define PROMOTE_FUNCTION_RETURN, we must promote
7263 the mode just as PROMOTE_MODE does. */
7264 mode
= promote_mode (valtype
, mode
, &unsignedp
, 1);
7266 /* Handle structures whose fields are returned in $f0/$f2. */
7267 switch (mips_fpr_return_fields (valtype
, fields
))
7270 return gen_rtx_REG (mode
, FP_RETURN
);
7273 return mips_return_fpr_pair (mode
,
7274 TYPE_MODE (TREE_TYPE (fields
[0])),
7275 int_byte_position (fields
[0]),
7276 TYPE_MODE (TREE_TYPE (fields
[1])),
7277 int_byte_position (fields
[1]));
7280 /* If a value is passed in the most significant part of a register, see
7281 whether we have to round the mode up to a whole number of words. */
7282 if (mips_return_in_msb (valtype
))
7284 HOST_WIDE_INT size
= int_size_in_bytes (valtype
);
7285 if (size
% UNITS_PER_WORD
!= 0)
7287 size
+= UNITS_PER_WORD
- size
% UNITS_PER_WORD
;
7288 mode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
7293 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
7294 && GET_MODE_SIZE (mode
) <= UNITS_PER_HWFPVALUE
)
7295 return gen_rtx_REG (mode
, FP_RETURN
);
7297 /* Handle long doubles for n32 & n64. */
7299 return mips_return_fpr_pair (mode
,
7301 DImode
, GET_MODE_SIZE (mode
) / 2);
7303 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
7304 && GET_MODE_SIZE (mode
) <= UNITS_PER_HWFPVALUE
* 2)
7305 return mips_return_fpr_pair (mode
,
7306 GET_MODE_INNER (mode
), 0,
7307 GET_MODE_INNER (mode
),
7308 GET_MODE_SIZE (mode
) / 2);
7310 return gen_rtx_REG (mode
, GP_RETURN
);
7313 /* The implementation of FUNCTION_ARG_PASS_BY_REFERENCE. Return
7314 nonzero when an argument must be passed by reference. */
7317 function_arg_pass_by_reference (const CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
7318 enum machine_mode mode
, tree type
,
7319 int named ATTRIBUTE_UNUSED
)
7323 /* The EABI is the only one to pass args by reference. */
7324 if (mips_abi
!= ABI_EABI
)
7327 /* ??? How should SCmode be handled? */
7328 if (type
== NULL_TREE
|| mode
== DImode
|| mode
== DFmode
)
7331 size
= int_size_in_bytes (type
);
7332 return size
== -1 || size
> UNITS_PER_WORD
;
7335 /* Return the class of registers for which a mode change from FROM to TO
7338 In little-endian mode, the hi-lo registers are numbered backwards,
7339 so (subreg:SI (reg:DI hi) 0) gets the high word instead of the low
7342 Similarly, when using paired floating-point registers, the first
7343 register holds the low word, regardless of endianness. So in big
7344 endian mode, (subreg:SI (reg:DF $f0) 0) does not get the high word
7347 Also, loading a 32-bit value into a 64-bit floating-point register
7348 will not sign-extend the value, despite what LOAD_EXTEND_OP says.
7349 We can't allow 64-bit float registers to change from a 32-bit
7350 mode to a 64-bit mode. */
7353 mips_cannot_change_mode_class (enum machine_mode from
,
7354 enum machine_mode to
, enum reg_class
class)
7356 if (GET_MODE_SIZE (from
) != GET_MODE_SIZE (to
))
7358 if (TARGET_BIG_ENDIAN
)
7359 return reg_classes_intersect_p (FP_REGS
, class);
7361 return reg_classes_intersect_p (HI_AND_FP_REGS
, class);
7362 return reg_classes_intersect_p (HI_REG
, class);
7367 /* Return true if X should not be moved directly into register $25.
7368 We need this because many versions of GAS will treat "la $25,foo" as
7369 part of a call sequence and so allow a global "foo" to be lazily bound. */
7372 mips_dangerous_for_la25_p (rtx x
)
7374 HOST_WIDE_INT offset
;
7376 if (TARGET_EXPLICIT_RELOCS
)
7379 mips_split_const (x
, &x
, &offset
);
7380 return global_got_operand (x
, VOIDmode
);
7383 /* Implement PREFERRED_RELOAD_CLASS. */
7386 mips_preferred_reload_class (rtx x
, enum reg_class
class)
7388 if (mips_dangerous_for_la25_p (x
) && reg_class_subset_p (LEA_REGS
, class))
7391 if (TARGET_HARD_FLOAT
7392 && FLOAT_MODE_P (GET_MODE (x
))
7393 && reg_class_subset_p (FP_REGS
, class))
7396 if (reg_class_subset_p (GR_REGS
, class))
7399 if (TARGET_MIPS16
&& reg_class_subset_p (M16_REGS
, class))
7405 /* This function returns the register class required for a secondary
7406 register when copying between one of the registers in CLASS, and X,
7407 using MODE. If IN_P is nonzero, the copy is going from X to the
7408 register, otherwise the register is the source. A return value of
7409 NO_REGS means that no secondary register is required. */
7412 mips_secondary_reload_class (enum reg_class
class,
7413 enum machine_mode mode
, rtx x
, int in_p
)
7415 enum reg_class gr_regs
= TARGET_MIPS16
? M16_REGS
: GR_REGS
;
7419 if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
7420 regno
= true_regnum (x
);
7422 gp_reg_p
= TARGET_MIPS16
? M16_REG_P (regno
) : GP_REG_P (regno
);
7424 if (mips_dangerous_for_la25_p (x
))
7427 if (TEST_HARD_REG_BIT (reg_class_contents
[(int) class], 25))
7431 /* Copying from HI or LO to anywhere other than a general register
7432 requires a general register. */
7433 if (class == HI_REG
|| class == LO_REG
|| class == MD_REGS
)
7435 if (TARGET_MIPS16
&& in_p
)
7437 /* We can't really copy to HI or LO at all in mips16 mode. */
7440 return gp_reg_p
? NO_REGS
: gr_regs
;
7442 if (MD_REG_P (regno
))
7444 if (TARGET_MIPS16
&& ! in_p
)
7446 /* We can't really copy to HI or LO at all in mips16 mode. */
7449 return class == gr_regs
? NO_REGS
: gr_regs
;
7452 /* We can only copy a value to a condition code register from a
7453 floating point register, and even then we require a scratch
7454 floating point register. We can only copy a value out of a
7455 condition code register into a general register. */
7456 if (class == ST_REGS
)
7460 return gp_reg_p
? NO_REGS
: gr_regs
;
7462 if (ST_REG_P (regno
))
7466 return class == gr_regs
? NO_REGS
: gr_regs
;
7469 if (class == FP_REGS
)
7471 if (GET_CODE (x
) == MEM
)
7473 /* In this case we can use lwc1, swc1, ldc1 or sdc1. */
7476 else if (CONSTANT_P (x
) && GET_MODE_CLASS (mode
) == MODE_FLOAT
)
7478 /* We can use the l.s and l.d macros to load floating-point
7479 constants. ??? For l.s, we could probably get better
7480 code by returning GR_REGS here. */
7483 else if (gp_reg_p
|| x
== CONST0_RTX (mode
))
7485 /* In this case we can use mtc1, mfc1, dmtc1 or dmfc1. */
7488 else if (FP_REG_P (regno
))
7490 /* In this case we can use mov.s or mov.d. */
7495 /* Otherwise, we need to reload through an integer register. */
7500 /* In mips16 mode, going between memory and anything but M16_REGS
7501 requires an M16_REG. */
7504 if (class != M16_REGS
&& class != M16_NA_REGS
)
7512 if (class == M16_REGS
|| class == M16_NA_REGS
)
7521 /* Implement CLASS_MAX_NREGS.
7523 Usually all registers are word-sized. The only supported exception
7524 is -mgp64 -msingle-float, which has 64-bit words but 32-bit float
7525 registers. A word-based calculation is correct even in that case,
7526 since -msingle-float disallows multi-FPR values. */
7529 mips_class_max_nregs (enum reg_class
class ATTRIBUTE_UNUSED
,
7530 enum machine_mode mode
)
7532 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
7536 mips_valid_pointer_mode (enum machine_mode mode
)
7538 return (mode
== SImode
|| (TARGET_64BIT
&& mode
== DImode
));
7542 /* If we can access small data directly (using gp-relative relocation
7543 operators) return the small data pointer, otherwise return null.
7545 For each mips16 function which refers to GP relative symbols, we
7546 use a pseudo register, initialized at the start of the function, to
7547 hold the $gp value. */
7550 mips16_gp_pseudo_reg (void)
7552 if (cfun
->machine
->mips16_gp_pseudo_rtx
== NULL_RTX
)
7557 cfun
->machine
->mips16_gp_pseudo_rtx
= gen_reg_rtx (Pmode
);
7558 RTX_UNCHANGING_P (cfun
->machine
->mips16_gp_pseudo_rtx
) = 1;
7560 /* We want to initialize this to a value which gcc will believe
7562 const_gp
= gen_rtx_CONST (Pmode
, pic_offset_table_rtx
);
7564 emit_move_insn (cfun
->machine
->mips16_gp_pseudo_rtx
,
7566 insn
= get_insns ();
7569 push_topmost_sequence ();
7570 /* We need to emit the initialization after the FUNCTION_BEG
7571 note, so that it will be integrated. */
7572 for (scan
= get_insns (); scan
!= NULL_RTX
; scan
= NEXT_INSN (scan
))
7573 if (GET_CODE (scan
) == NOTE
7574 && NOTE_LINE_NUMBER (scan
) == NOTE_INSN_FUNCTION_BEG
)
7576 if (scan
== NULL_RTX
)
7577 scan
= get_insns ();
7578 insn
= emit_insn_after (insn
, scan
);
7579 pop_topmost_sequence ();
7582 return cfun
->machine
->mips16_gp_pseudo_rtx
;
7585 /* Write out code to move floating point arguments in or out of
7586 general registers. Output the instructions to FILE. FP_CODE is
7587 the code describing which arguments are present (see the comment at
7588 the definition of CUMULATIVE_ARGS in mips.h). FROM_FP_P is nonzero if
7589 we are copying from the floating point registers. */
7592 mips16_fp_args (FILE *file
, int fp_code
, int from_fp_p
)
7598 /* This code only works for the original 32 bit ABI and the O64 ABI. */
7599 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
7606 gparg
= GP_ARG_FIRST
;
7607 fparg
= FP_ARG_FIRST
;
7608 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
7612 if ((fparg
& 1) != 0)
7614 fprintf (file
, "\t%s\t%s,%s\n", s
,
7615 reg_names
[gparg
], reg_names
[fparg
]);
7617 else if ((f
& 3) == 2)
7620 fprintf (file
, "\td%s\t%s,%s\n", s
,
7621 reg_names
[gparg
], reg_names
[fparg
]);
7624 if ((fparg
& 1) != 0)
7626 if (TARGET_BIG_ENDIAN
)
7627 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
7628 reg_names
[gparg
], reg_names
[fparg
+ 1], s
,
7629 reg_names
[gparg
+ 1], reg_names
[fparg
]);
7631 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
7632 reg_names
[gparg
], reg_names
[fparg
], s
,
7633 reg_names
[gparg
+ 1], reg_names
[fparg
+ 1]);
7646 /* Build a mips16 function stub. This is used for functions which
7647 take arguments in the floating point registers. It is 32 bit code
7648 that moves the floating point args into the general registers, and
7649 then jumps to the 16 bit code. */
7652 build_mips16_function_stub (FILE *file
)
7655 char *secname
, *stubname
;
7656 tree stubid
, stubdecl
;
7660 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
7661 secname
= (char *) alloca (strlen (fnname
) + 20);
7662 sprintf (secname
, ".mips16.fn.%s", fnname
);
7663 stubname
= (char *) alloca (strlen (fnname
) + 20);
7664 sprintf (stubname
, "__fn_stub_%s", fnname
);
7665 stubid
= get_identifier (stubname
);
7666 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
7667 build_function_type (void_type_node
, NULL_TREE
));
7668 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
7670 fprintf (file
, "\t# Stub function for %s (", current_function_name
);
7672 for (f
= (unsigned int) current_function_args_info
.fp_code
; f
!= 0; f
>>= 2)
7674 fprintf (file
, "%s%s",
7675 need_comma
? ", " : "",
7676 (f
& 3) == 1 ? "float" : "double");
7679 fprintf (file
, ")\n");
7681 fprintf (file
, "\t.set\tnomips16\n");
7682 function_section (stubdecl
);
7683 ASM_OUTPUT_ALIGN (file
, floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
));
7685 /* ??? If FUNCTION_NAME_ALREADY_DECLARED is defined, then we are
7686 within a .ent, and we can not emit another .ent. */
7687 if (!FUNCTION_NAME_ALREADY_DECLARED
)
7689 fputs ("\t.ent\t", file
);
7690 assemble_name (file
, stubname
);
7694 assemble_name (file
, stubname
);
7695 fputs (":\n", file
);
7697 /* We don't want the assembler to insert any nops here. */
7698 fprintf (file
, "\t.set\tnoreorder\n");
7700 mips16_fp_args (file
, current_function_args_info
.fp_code
, 1);
7702 fprintf (asm_out_file
, "\t.set\tnoat\n");
7703 fprintf (asm_out_file
, "\tla\t%s,", reg_names
[GP_REG_FIRST
+ 1]);
7704 assemble_name (file
, fnname
);
7705 fprintf (file
, "\n");
7706 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
7707 fprintf (asm_out_file
, "\t.set\tat\n");
7709 /* Unfortunately, we can't fill the jump delay slot. We can't fill
7710 with one of the mfc1 instructions, because the result is not
7711 available for one instruction, so if the very first instruction
7712 in the function refers to the register, it will see the wrong
7714 fprintf (file
, "\tnop\n");
7716 fprintf (file
, "\t.set\treorder\n");
7718 if (!FUNCTION_NAME_ALREADY_DECLARED
)
7720 fputs ("\t.end\t", file
);
7721 assemble_name (file
, stubname
);
7725 fprintf (file
, "\t.set\tmips16\n");
7727 function_section (current_function_decl
);
7730 /* We keep a list of functions for which we have already built stubs
7731 in build_mips16_call_stub. */
7735 struct mips16_stub
*next
;
7740 static struct mips16_stub
*mips16_stubs
;
7742 /* Build a call stub for a mips16 call. A stub is needed if we are
7743 passing any floating point values which should go into the floating
7744 point registers. If we are, and the call turns out to be to a 32
7745 bit function, the stub will be used to move the values into the
7746 floating point registers before calling the 32 bit function. The
7747 linker will magically adjust the function call to either the 16 bit
7748 function or the 32 bit stub, depending upon where the function call
7749 is actually defined.
7751 Similarly, we need a stub if the return value might come back in a
7752 floating point register.
7754 RETVAL is the location of the return value, or null if this is
7755 a call rather than a call_value. FN is the address of the
7756 function and ARG_SIZE is the size of the arguments. FP_CODE
7757 is the code built by function_arg. This function returns a nonzero
7758 value if it builds the call instruction itself. */
7761 build_mips16_call_stub (rtx retval
, rtx fn
, rtx arg_size
, int fp_code
)
7765 char *secname
, *stubname
;
7766 struct mips16_stub
*l
;
7767 tree stubid
, stubdecl
;
7771 /* We don't need to do anything if we aren't in mips16 mode, or if
7772 we were invoked with the -msoft-float option. */
7773 if (! TARGET_MIPS16
|| ! mips16_hard_float
)
7776 /* Figure out whether the value might come back in a floating point
7778 fpret
= (retval
!= 0
7779 && GET_MODE_CLASS (GET_MODE (retval
)) == MODE_FLOAT
7780 && GET_MODE_SIZE (GET_MODE (retval
)) <= UNITS_PER_FPVALUE
);
7782 /* We don't need to do anything if there were no floating point
7783 arguments and the value will not be returned in a floating point
7785 if (fp_code
== 0 && ! fpret
)
7788 /* We don't need to do anything if this is a call to a special
7789 mips16 support function. */
7790 if (GET_CODE (fn
) == SYMBOL_REF
7791 && strncmp (XSTR (fn
, 0), "__mips16_", 9) == 0)
7794 /* This code will only work for o32 and o64 abis. The other ABI's
7795 require more sophisticated support. */
7796 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
7799 /* We can only handle SFmode and DFmode floating point return
7801 if (fpret
&& GET_MODE (retval
) != SFmode
&& GET_MODE (retval
) != DFmode
)
7804 /* If we're calling via a function pointer, then we must always call
7805 via a stub. There are magic stubs provided in libgcc.a for each
7806 of the required cases. Each of them expects the function address
7807 to arrive in register $2. */
7809 if (GET_CODE (fn
) != SYMBOL_REF
)
7815 /* ??? If this code is modified to support other ABI's, we need
7816 to handle PARALLEL return values here. */
7818 sprintf (buf
, "__mips16_call_stub_%s%d",
7820 ? (GET_MODE (retval
) == SFmode
? "sf_" : "df_")
7823 id
= get_identifier (buf
);
7824 stub_fn
= gen_rtx (SYMBOL_REF
, Pmode
, IDENTIFIER_POINTER (id
));
7826 emit_move_insn (gen_rtx (REG
, Pmode
, 2), fn
);
7828 if (retval
== NULL_RTX
)
7829 insn
= gen_call_internal (stub_fn
, arg_size
);
7831 insn
= gen_call_value_internal (retval
, stub_fn
, arg_size
);
7832 insn
= emit_call_insn (insn
);
7834 /* Put the register usage information on the CALL. */
7835 if (GET_CODE (insn
) != CALL_INSN
)
7837 CALL_INSN_FUNCTION_USAGE (insn
) =
7838 gen_rtx (EXPR_LIST
, VOIDmode
,
7839 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, Pmode
, 2)),
7840 CALL_INSN_FUNCTION_USAGE (insn
));
7842 /* If we are handling a floating point return value, we need to
7843 save $18 in the function prologue. Putting a note on the
7844 call will mean that regs_ever_live[$18] will be true if the
7845 call is not eliminated, and we can check that in the prologue
7848 CALL_INSN_FUNCTION_USAGE (insn
) =
7849 gen_rtx (EXPR_LIST
, VOIDmode
,
7850 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
7851 CALL_INSN_FUNCTION_USAGE (insn
));
7853 /* Return 1 to tell the caller that we've generated the call
7858 /* We know the function we are going to call. If we have already
7859 built a stub, we don't need to do anything further. */
7861 fnname
= XSTR (fn
, 0);
7862 for (l
= mips16_stubs
; l
!= NULL
; l
= l
->next
)
7863 if (strcmp (l
->name
, fnname
) == 0)
7868 /* Build a special purpose stub. When the linker sees a
7869 function call in mips16 code, it will check where the target
7870 is defined. If the target is a 32 bit call, the linker will
7871 search for the section defined here. It can tell which
7872 symbol this section is associated with by looking at the
7873 relocation information (the name is unreliable, since this
7874 might be a static function). If such a section is found, the
7875 linker will redirect the call to the start of the magic
7878 If the function does not return a floating point value, the
7879 special stub section is named
7882 If the function does return a floating point value, the stub
7884 .mips16.call.fp.FNNAME
7887 secname
= (char *) alloca (strlen (fnname
) + 40);
7888 sprintf (secname
, ".mips16.call.%s%s",
7891 stubname
= (char *) alloca (strlen (fnname
) + 20);
7892 sprintf (stubname
, "__call_stub_%s%s",
7895 stubid
= get_identifier (stubname
);
7896 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
7897 build_function_type (void_type_node
, NULL_TREE
));
7898 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
7900 fprintf (asm_out_file
, "\t# Stub function to call %s%s (",
7902 ? (GET_MODE (retval
) == SFmode
? "float " : "double ")
7906 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
7908 fprintf (asm_out_file
, "%s%s",
7909 need_comma
? ", " : "",
7910 (f
& 3) == 1 ? "float" : "double");
7913 fprintf (asm_out_file
, ")\n");
7915 fprintf (asm_out_file
, "\t.set\tnomips16\n");
7916 assemble_start_function (stubdecl
, stubname
);
7918 if (!FUNCTION_NAME_ALREADY_DECLARED
)
7920 fputs ("\t.ent\t", asm_out_file
);
7921 assemble_name (asm_out_file
, stubname
);
7922 fputs ("\n", asm_out_file
);
7924 assemble_name (asm_out_file
, stubname
);
7925 fputs (":\n", asm_out_file
);
7928 /* We build the stub code by hand. That's the only way we can
7929 do it, since we can't generate 32 bit code during a 16 bit
7932 /* We don't want the assembler to insert any nops here. */
7933 fprintf (asm_out_file
, "\t.set\tnoreorder\n");
7935 mips16_fp_args (asm_out_file
, fp_code
, 0);
7939 fprintf (asm_out_file
, "\t.set\tnoat\n");
7940 fprintf (asm_out_file
, "\tla\t%s,%s\n", reg_names
[GP_REG_FIRST
+ 1],
7942 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
7943 fprintf (asm_out_file
, "\t.set\tat\n");
7944 /* Unfortunately, we can't fill the jump delay slot. We
7945 can't fill with one of the mtc1 instructions, because the
7946 result is not available for one instruction, so if the
7947 very first instruction in the function refers to the
7948 register, it will see the wrong value. */
7949 fprintf (asm_out_file
, "\tnop\n");
7953 fprintf (asm_out_file
, "\tmove\t%s,%s\n",
7954 reg_names
[GP_REG_FIRST
+ 18], reg_names
[GP_REG_FIRST
+ 31]);
7955 fprintf (asm_out_file
, "\tjal\t%s\n", fnname
);
7956 /* As above, we can't fill the delay slot. */
7957 fprintf (asm_out_file
, "\tnop\n");
7958 if (GET_MODE (retval
) == SFmode
)
7959 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
7960 reg_names
[GP_REG_FIRST
+ 2], reg_names
[FP_REG_FIRST
+ 0]);
7963 if (TARGET_BIG_ENDIAN
)
7965 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
7966 reg_names
[GP_REG_FIRST
+ 2],
7967 reg_names
[FP_REG_FIRST
+ 1]);
7968 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
7969 reg_names
[GP_REG_FIRST
+ 3],
7970 reg_names
[FP_REG_FIRST
+ 0]);
7974 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
7975 reg_names
[GP_REG_FIRST
+ 2],
7976 reg_names
[FP_REG_FIRST
+ 0]);
7977 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
7978 reg_names
[GP_REG_FIRST
+ 3],
7979 reg_names
[FP_REG_FIRST
+ 1]);
7982 fprintf (asm_out_file
, "\tj\t%s\n", reg_names
[GP_REG_FIRST
+ 18]);
7983 /* As above, we can't fill the delay slot. */
7984 fprintf (asm_out_file
, "\tnop\n");
7987 fprintf (asm_out_file
, "\t.set\treorder\n");
7989 #ifdef ASM_DECLARE_FUNCTION_SIZE
7990 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, stubname
, stubdecl
);
7993 if (!FUNCTION_NAME_ALREADY_DECLARED
)
7995 fputs ("\t.end\t", asm_out_file
);
7996 assemble_name (asm_out_file
, stubname
);
7997 fputs ("\n", asm_out_file
);
8000 fprintf (asm_out_file
, "\t.set\tmips16\n");
8002 /* Record this stub. */
8003 l
= (struct mips16_stub
*) xmalloc (sizeof *l
);
8004 l
->name
= xstrdup (fnname
);
8006 l
->next
= mips16_stubs
;
8010 /* If we expect a floating point return value, but we've built a
8011 stub which does not expect one, then we're in trouble. We can't
8012 use the existing stub, because it won't handle the floating point
8013 value. We can't build a new stub, because the linker won't know
8014 which stub to use for the various calls in this object file.
8015 Fortunately, this case is illegal, since it means that a function
8016 was declared in two different ways in a single compilation. */
8017 if (fpret
&& ! l
->fpret
)
8018 error ("can not handle inconsistent calls to `%s'", fnname
);
8020 /* If we are calling a stub which handles a floating point return
8021 value, we need to arrange to save $18 in the prologue. We do
8022 this by marking the function call as using the register. The
8023 prologue will later see that it is used, and emit code to save
8030 if (retval
== NULL_RTX
)
8031 insn
= gen_call_internal (fn
, arg_size
);
8033 insn
= gen_call_value_internal (retval
, fn
, arg_size
);
8034 insn
= emit_call_insn (insn
);
8036 if (GET_CODE (insn
) != CALL_INSN
)
8039 CALL_INSN_FUNCTION_USAGE (insn
) =
8040 gen_rtx (EXPR_LIST
, VOIDmode
,
8041 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
8042 CALL_INSN_FUNCTION_USAGE (insn
));
8044 /* Return 1 to tell the caller that we've generated the call
8049 /* Return 0 to let the caller generate the call insn. */
8053 /* This function looks through the code for a function, and tries to
8054 optimize the usage of the $gp register. We arrange to copy $gp
8055 into a pseudo-register, and then let gcc's normal reload handling
8056 deal with the pseudo-register. Unfortunately, if reload choose to
8057 put the pseudo-register into a call-clobbered register, it will
8058 emit saves and restores for that register around any function
8059 calls. We don't need the saves, and it's faster to copy $gp than
8060 to do an actual restore. ??? This still means that we waste a
8063 This is an optimization, and the code which gcc has actually
8064 generated is correct, so we do not need to catch all cases. */
8067 mips16_optimize_gp (void)
8069 rtx gpcopy
, slot
, insn
;
8071 /* Look through the instructions. Set GPCOPY to the register which
8072 holds a copy of $gp. Set SLOT to the stack slot where it is
8073 saved. If we find an instruction which sets GPCOPY to anything
8074 other than $gp or SLOT, then we can't use it. If we find an
8075 instruction which sets SLOT to anything other than GPCOPY, we
8080 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
8084 if (! INSN_P (insn
))
8087 set
= PATTERN (insn
);
8089 /* We know that all references to memory will be inside a SET,
8090 because there is no other way to access memory on the mips16.
8091 We don't have to worry about a PARALLEL here, because the
8092 mips.md file will never generate them for memory references. */
8093 if (GET_CODE (set
) != SET
)
8096 if (gpcopy
== NULL_RTX
8097 && GET_CODE (SET_SRC (set
)) == CONST
8098 && XEXP (SET_SRC (set
), 0) == pic_offset_table_rtx
8099 && GET_CODE (SET_DEST (set
)) == REG
)
8100 gpcopy
= SET_DEST (set
);
8101 else if (slot
== NULL_RTX
8102 && gpcopy
!= NULL_RTX
8103 && GET_CODE (SET_DEST (set
)) == MEM
8104 && GET_CODE (SET_SRC (set
)) == REG
8105 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
))
8109 offset
= const0_rtx
;
8110 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8111 if (GET_CODE (base
) == REG
8112 && (REGNO (base
) == STACK_POINTER_REGNUM
8113 || REGNO (base
) == FRAME_POINTER_REGNUM
))
8114 slot
= SET_DEST (set
);
8116 else if (gpcopy
!= NULL_RTX
8117 && (GET_CODE (SET_DEST (set
)) == REG
8118 || GET_CODE (SET_DEST (set
)) == SUBREG
)
8119 && reg_overlap_mentioned_p (SET_DEST (set
), gpcopy
)
8120 && (GET_CODE (SET_DEST (set
)) != REG
8121 || REGNO (SET_DEST (set
)) != REGNO (gpcopy
)
8122 || ((GET_CODE (SET_SRC (set
)) != CONST
8123 || XEXP (SET_SRC (set
), 0) != pic_offset_table_rtx
)
8124 && ! rtx_equal_p (SET_SRC (set
), slot
))))
8126 else if (slot
!= NULL_RTX
8127 && GET_CODE (SET_DEST (set
)) == MEM
8128 && rtx_equal_p (SET_DEST (set
), slot
)
8129 && (GET_CODE (SET_SRC (set
)) != REG
8130 || REGNO (SET_SRC (set
)) != REGNO (gpcopy
)))
8134 /* If we couldn't find a unique value for GPCOPY or SLOT, then try a
8135 different optimization. Any time we find a copy of $28 into a
8136 register, followed by an add of a symbol_ref to that register, we
8137 convert it to load the value from the constant table instead.
8138 The copy and add will take six bytes, just as the load and
8139 constant table entry will take six bytes. However, it is
8140 possible that the constant table entry will be shared.
8142 This could be a peephole optimization, but I don't know if the
8143 peephole code can call force_const_mem.
8145 Using the same register for the copy of $28 and the add of the
8146 symbol_ref is actually pretty likely, since the add instruction
8147 requires the destination and the first addend to be the same
8150 if (insn
!= NULL_RTX
|| gpcopy
== NULL_RTX
|| slot
== NULL_RTX
)
8153 /* Used below in #if 0 area. */
8156 /* This optimization is only reasonable if the constant table
8157 entries are only 4 bytes. */
8158 if (Pmode
!= SImode
)
8162 /* ??? FIXME. Rewrite for new UNSPEC_RELOC stuff. */
8163 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= next
)
8170 next
= NEXT_INSN (next
);
8172 while (next
!= NULL_RTX
8173 && (GET_CODE (next
) == NOTE
8174 || (GET_CODE (next
) == INSN
8175 && (GET_CODE (PATTERN (next
)) == USE
8176 || GET_CODE (PATTERN (next
)) == CLOBBER
))));
8178 if (next
== NULL_RTX
)
8181 if (! INSN_P (insn
))
8184 if (! INSN_P (next
))
8187 set1
= PATTERN (insn
);
8188 if (GET_CODE (set1
) != SET
)
8190 set2
= PATTERN (next
);
8191 if (GET_CODE (set2
) != SET
)
8194 if (GET_CODE (SET_DEST (set1
)) == REG
8195 && GET_CODE (SET_SRC (set1
)) == CONST
8196 && XEXP (SET_SRC (set1
), 0) == pic_offset_table_rtx
8197 && rtx_equal_p (SET_DEST (set1
), SET_DEST (set2
))
8198 && GET_CODE (SET_SRC (set2
)) == PLUS
8199 && rtx_equal_p (SET_DEST (set1
), XEXP (SET_SRC (set2
), 0))
8200 && mips16_gp_offset_p (XEXP (SET_SRC (set2
), 1))
8201 && GET_CODE (XEXP (XEXP (SET_SRC (set2
), 1), 0)) == MINUS
)
8205 /* We've found a case we can change to load from the
8208 sym
= XEXP (XEXP (XEXP (SET_SRC (set2
), 1), 0), 0);
8209 if (GET_CODE (sym
) != SYMBOL_REF
)
8211 emit_insn_after (gen_rtx (SET
, VOIDmode
, SET_DEST (set1
),
8212 force_const_mem (Pmode
, sym
)),
8215 PUT_CODE (insn
, NOTE
);
8216 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
8217 NOTE_SOURCE_FILE (insn
) = 0;
8219 PUT_CODE (next
, NOTE
);
8220 NOTE_LINE_NUMBER (next
) = NOTE_INSN_DELETED
;
8221 NOTE_SOURCE_FILE (next
) = 0;
8228 /* We can safely remove all assignments to SLOT from GPCOPY, and
8229 replace all assignments from SLOT to GPCOPY with assignments from
8232 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
8236 if (! INSN_P (insn
))
8239 set
= PATTERN (insn
);
8240 if (GET_CODE (set
) != SET
)
8243 if (GET_CODE (SET_DEST (set
)) == MEM
8244 && rtx_equal_p (SET_DEST (set
), slot
)
8245 && GET_CODE (SET_SRC (set
)) == REG
8246 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
))
8248 PUT_CODE (insn
, NOTE
);
8249 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
8250 NOTE_SOURCE_FILE (insn
) = 0;
8252 else if (GET_CODE (SET_DEST (set
)) == REG
8253 && REGNO (SET_DEST (set
)) == REGNO (gpcopy
)
8254 && GET_CODE (SET_SRC (set
)) == MEM
8255 && rtx_equal_p (SET_SRC (set
), slot
))
8257 enum machine_mode mode
;
8260 mode
= GET_MODE (SET_DEST (set
));
8261 src
= gen_rtx_CONST (mode
, pic_offset_table_rtx
);
8262 emit_insn_after (gen_rtx_SET (VOIDmode
, SET_DEST (set
), src
), insn
);
8263 PUT_CODE (insn
, NOTE
);
8264 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
8265 NOTE_SOURCE_FILE (insn
) = 0;
8270 /* We keep a list of constants we which we have to add to internal
8271 constant tables in the middle of large functions. */
8275 struct constant
*next
;
8278 enum machine_mode mode
;
8281 /* Add a constant to the list in *PCONSTANTS. */
8284 add_constant (struct constant
**pconstants
, rtx val
, enum machine_mode mode
)
8288 for (c
= *pconstants
; c
!= NULL
; c
= c
->next
)
8289 if (mode
== c
->mode
&& rtx_equal_p (val
, c
->value
))
8292 c
= (struct constant
*) xmalloc (sizeof *c
);
8295 c
->label
= gen_label_rtx ();
8296 c
->next
= *pconstants
;
8301 /* Dump out the constants in CONSTANTS after INSN. */
8304 dump_constants (struct constant
*constants
, rtx insn
)
8314 struct constant
*next
;
8316 switch (GET_MODE_SIZE (c
->mode
))
8323 insn
= emit_insn_after (gen_align_2 (), insn
);
8328 insn
= emit_insn_after (gen_align_4 (), insn
);
8333 insn
= emit_insn_after (gen_align_8 (), insn
);
8338 insn
= emit_label_after (c
->label
, insn
);
8343 r
= gen_consttable_qi (c
->value
);
8346 r
= gen_consttable_hi (c
->value
);
8349 r
= gen_consttable_si (c
->value
);
8352 r
= gen_consttable_sf (c
->value
);
8355 r
= gen_consttable_di (c
->value
);
8358 r
= gen_consttable_df (c
->value
);
8364 insn
= emit_insn_after (r
, insn
);
8371 emit_barrier_after (insn
);
8374 /* Find the symbol in an address expression. */
8377 mips_find_symbol (rtx addr
)
8379 if (GET_CODE (addr
) == MEM
)
8380 addr
= XEXP (addr
, 0);
8381 while (GET_CODE (addr
) == CONST
)
8382 addr
= XEXP (addr
, 0);
8383 if (GET_CODE (addr
) == SYMBOL_REF
|| GET_CODE (addr
) == LABEL_REF
)
8385 if (GET_CODE (addr
) == PLUS
)
8389 l1
= mips_find_symbol (XEXP (addr
, 0));
8390 l2
= mips_find_symbol (XEXP (addr
, 1));
8391 if (l1
!= NULL_RTX
&& l2
== NULL_RTX
)
8393 else if (l1
== NULL_RTX
&& l2
!= NULL_RTX
)
8399 /* In mips16 mode, we need to look through the function to check for
8400 PC relative loads that are out of range. */
8403 mips16_lay_out_constants (void)
8405 int insns_len
, max_internal_pool_size
, pool_size
, addr
, first_constant_ref
;
8407 struct constant
*constants
;
8409 first
= get_insns ();
8411 /* Scan the function looking for PC relative loads which may be out
8412 of range. All such loads will either be from the constant table,
8413 or be getting the address of a constant string. If the size of
8414 the function plus the size of the constant table is less than
8415 0x8000, then all loads are in range. */
8418 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
8420 insns_len
+= get_attr_length (insn
);
8422 /* ??? We put switch tables in .text, but we don't define
8423 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
8424 compute their lengths correctly. */
8425 if (GET_CODE (insn
) == JUMP_INSN
)
8429 body
= PATTERN (insn
);
8430 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
8431 insns_len
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
8432 * GET_MODE_SIZE (GET_MODE (body
)));
8433 insns_len
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
8437 /* Store the original value of insns_len in cfun->machine, so
8438 that simple_memory_operand can look at it. */
8439 cfun
->machine
->insns_len
= insns_len
;
8441 pool_size
= get_pool_size ();
8442 if (insns_len
+ pool_size
+ mips_string_length
< 0x8000)
8445 /* Loop over the insns and figure out what the maximum internal pool
8447 max_internal_pool_size
= 0;
8448 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
8450 if (GET_CODE (insn
) == INSN
8451 && GET_CODE (PATTERN (insn
)) == SET
)
8455 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
8456 if (src
== NULL_RTX
)
8458 if (CONSTANT_POOL_ADDRESS_P (src
))
8459 max_internal_pool_size
+= GET_MODE_SIZE (get_pool_mode (src
));
8460 else if (SYMBOL_REF_FLAG (src
))
8461 max_internal_pool_size
+= GET_MODE_SIZE (Pmode
);
8467 first_constant_ref
= -1;
8469 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
8471 if (GET_CODE (insn
) == INSN
8472 && GET_CODE (PATTERN (insn
)) == SET
)
8475 enum machine_mode mode
= VOIDmode
;
8478 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
8479 if (src
!= NULL_RTX
&& CONSTANT_POOL_ADDRESS_P (src
))
8481 /* ??? This is very conservative, which means that we
8482 will generate too many copies of the constant table.
8483 The only solution would seem to be some form of
8485 if (((insns_len
- addr
)
8486 + max_internal_pool_size
8487 + get_pool_offset (src
))
8490 val
= get_pool_constant (src
);
8491 mode
= get_pool_mode (src
);
8493 max_internal_pool_size
-= GET_MODE_SIZE (get_pool_mode (src
));
8495 else if (src
!= NULL_RTX
&& SYMBOL_REF_FLAG (src
))
8497 /* Including all of mips_string_length is conservative,
8498 and so is including all of max_internal_pool_size. */
8499 if (((insns_len
- addr
)
8500 + max_internal_pool_size
8502 + mips_string_length
)
8508 max_internal_pool_size
-= Pmode
;
8511 if (val
!= NULL_RTX
)
8515 /* This PC relative load is out of range. ??? In the
8516 case of a string constant, we are only guessing that
8517 it is range, since we don't know the offset of a
8518 particular string constant. */
8520 lab
= add_constant (&constants
, val
, mode
);
8521 newsrc
= gen_rtx (MEM
, mode
,
8522 gen_rtx (LABEL_REF
, VOIDmode
, lab
));
8523 RTX_UNCHANGING_P (newsrc
) = 1;
8524 PATTERN (insn
) = gen_rtx (SET
, VOIDmode
,
8525 SET_DEST (PATTERN (insn
)),
8527 INSN_CODE (insn
) = -1;
8529 if (first_constant_ref
< 0)
8530 first_constant_ref
= addr
;
8534 addr
+= get_attr_length (insn
);
8536 /* ??? We put switch tables in .text, but we don't define
8537 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
8538 compute their lengths correctly. */
8539 if (GET_CODE (insn
) == JUMP_INSN
)
8543 body
= PATTERN (insn
);
8544 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
8545 addr
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
8546 * GET_MODE_SIZE (GET_MODE (body
)));
8547 addr
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
8550 if (GET_CODE (insn
) == BARRIER
)
8552 /* Output any constants we have accumulated. Note that we
8553 don't need to change ADDR, since its only use is
8554 subtraction from INSNS_LEN, and both would be changed by
8556 ??? If the instructions up to the next barrier reuse a
8557 constant, it would often be better to continue
8559 if (constants
!= NULL
)
8560 dump_constants (constants
, insn
);
8562 first_constant_ref
= -1;
8565 if (constants
!= NULL
8566 && (NEXT_INSN (insn
) == NULL
8567 || (first_constant_ref
>= 0
8568 && (((addr
- first_constant_ref
)
8569 + 2 /* for alignment */
8570 + 2 /* for a short jump insn */
8574 /* If we haven't had a barrier within 0x8000 bytes of a
8575 constant reference or we are at the end of the function,
8576 emit a barrier now. */
8578 rtx label
, jump
, barrier
;
8580 label
= gen_label_rtx ();
8581 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
8582 JUMP_LABEL (jump
) = label
;
8583 LABEL_NUSES (label
) = 1;
8584 barrier
= emit_barrier_after (jump
);
8585 emit_label_after (label
, barrier
);
8586 first_constant_ref
= -1;
8590 /* ??? If we output all references to a constant in internal
8591 constants table, we don't need to output the constant in the real
8592 constant table, but we have no way to prevent that. */
8596 /* Subroutine of mips_reorg. If there is a hazard between INSN
8597 and a previous instruction, avoid it by inserting nops after
8600 *DELAYED_REG and *HILO_DELAY describe the hazards that apply at
8601 this point. If *DELAYED_REG is non-null, INSN must wait a cycle
8602 before using the value of that register. *HILO_DELAY counts the
8603 number of instructions since the last hilo hazard (that is,
8604 the number of instructions since the last mflo or mfhi).
8606 After inserting nops for INSN, update *DELAYED_REG and *HILO_DELAY
8607 for the next instruction.
8609 LO_REG is an rtx for the LO register, used in dependence checking. */
8612 mips_avoid_hazard (rtx after
, rtx insn
, int *hilo_delay
,
8613 rtx
*delayed_reg
, rtx lo_reg
)
8621 pattern
= PATTERN (insn
);
8623 /* Do not put the whole function in .set noreorder if it contains
8624 an asm statement. We don't know whether there will be hazards
8625 between the asm statement and the gcc-generated code. */
8626 if (GET_CODE (pattern
) == ASM_INPUT
|| asm_noperands (pattern
) >= 0)
8627 cfun
->machine
->all_noreorder_p
= false;
8629 /* Ignore zero-length instructions (barriers and the like). */
8630 ninsns
= get_attr_length (insn
) / 4;
8634 /* Work out how many nops are needed. Note that we only care about
8635 registers that are explicitly mentioned in the instruction's pattern.
8636 It doesn't matter that calls use the argument registers or that they
8637 clobber hi and lo. */
8638 if (*hilo_delay
< 2 && reg_set_p (lo_reg
, pattern
))
8639 nops
= 2 - *hilo_delay
;
8640 else if (*delayed_reg
!= 0 && reg_referenced_p (*delayed_reg
, pattern
))
8645 /* Insert the nops between this instruction and the previous one.
8646 Each new nop takes us further from the last hilo hazard. */
8647 *hilo_delay
+= nops
;
8649 emit_insn_after (gen_hazard_nop (), after
);
8651 /* Set up the state for the next instruction. */
8652 *hilo_delay
+= ninsns
;
8654 if (INSN_CODE (insn
) >= 0)
8655 switch (get_attr_hazard (insn
))
8665 set
= single_set (insn
);
8668 *delayed_reg
= SET_DEST (set
);
8674 /* Go through the instruction stream and insert nops where necessary.
8675 See if the whole function can then be put into .set noreorder &
8679 mips_avoid_hazards (void)
8681 rtx insn
, last_insn
, lo_reg
, delayed_reg
;
8684 /* Recalculate instruction lengths without taking nops into account. */
8685 cfun
->machine
->ignore_hazard_length_p
= true;
8686 shorten_branches (get_insns ());
8688 /* The profiler code uses assembler macros. */
8689 cfun
->machine
->all_noreorder_p
= !current_function_profile
;
8694 lo_reg
= gen_rtx_REG (SImode
, LO_REGNUM
);
8696 for (insn
= get_insns (); insn
!= 0; insn
= NEXT_INSN (insn
))
8699 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
8700 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
8701 mips_avoid_hazard (last_insn
, XVECEXP (PATTERN (insn
), 0, i
),
8702 &hilo_delay
, &delayed_reg
, lo_reg
);
8704 mips_avoid_hazard (last_insn
, insn
, &hilo_delay
,
8705 &delayed_reg
, lo_reg
);
8712 /* Implement TARGET_MACHINE_DEPENDENT_REORG. */
8720 mips16_optimize_gp ();
8721 mips16_lay_out_constants ();
8723 else if (TARGET_EXPLICIT_RELOCS
)
8725 if (mips_flag_delayed_branch
)
8726 dbr_schedule (get_insns (), rtl_dump_file
);
8727 mips_avoid_hazards ();
8731 /* We need to use a special set of functions to handle hard floating
8732 point code in mips16 mode. Also, allow for --enable-gofast. */
8734 #include "config/gofast.h"
8737 mips_init_libfuncs (void)
8739 if (TARGET_MIPS16
&& mips16_hard_float
)
8741 set_optab_libfunc (add_optab
, SFmode
, "__mips16_addsf3");
8742 set_optab_libfunc (sub_optab
, SFmode
, "__mips16_subsf3");
8743 set_optab_libfunc (smul_optab
, SFmode
, "__mips16_mulsf3");
8744 set_optab_libfunc (sdiv_optab
, SFmode
, "__mips16_divsf3");
8746 set_optab_libfunc (eq_optab
, SFmode
, "__mips16_eqsf2");
8747 set_optab_libfunc (ne_optab
, SFmode
, "__mips16_nesf2");
8748 set_optab_libfunc (gt_optab
, SFmode
, "__mips16_gtsf2");
8749 set_optab_libfunc (ge_optab
, SFmode
, "__mips16_gesf2");
8750 set_optab_libfunc (lt_optab
, SFmode
, "__mips16_ltsf2");
8751 set_optab_libfunc (le_optab
, SFmode
, "__mips16_lesf2");
8753 set_conv_libfunc (sfix_optab
, SImode
, SFmode
, "__mips16_fixsfsi");
8754 set_conv_libfunc (sfloat_optab
, SFmode
, SImode
, "__mips16_floatsisf");
8756 if (TARGET_DOUBLE_FLOAT
)
8758 set_optab_libfunc (add_optab
, DFmode
, "__mips16_adddf3");
8759 set_optab_libfunc (sub_optab
, DFmode
, "__mips16_subdf3");
8760 set_optab_libfunc (smul_optab
, DFmode
, "__mips16_muldf3");
8761 set_optab_libfunc (sdiv_optab
, DFmode
, "__mips16_divdf3");
8763 set_optab_libfunc (eq_optab
, DFmode
, "__mips16_eqdf2");
8764 set_optab_libfunc (ne_optab
, DFmode
, "__mips16_nedf2");
8765 set_optab_libfunc (gt_optab
, DFmode
, "__mips16_gtdf2");
8766 set_optab_libfunc (ge_optab
, DFmode
, "__mips16_gedf2");
8767 set_optab_libfunc (lt_optab
, DFmode
, "__mips16_ltdf2");
8768 set_optab_libfunc (le_optab
, DFmode
, "__mips16_ledf2");
8770 set_conv_libfunc (sext_optab
, DFmode
, SFmode
, "__mips16_extendsfdf2");
8771 set_conv_libfunc (trunc_optab
, SFmode
, DFmode
, "__mips16_truncdfsf2");
8773 set_conv_libfunc (sfix_optab
, SImode
, DFmode
, "__mips16_fixdfsi");
8774 set_conv_libfunc (sfloat_optab
, DFmode
, SImode
, "__mips16_floatsidf");
8778 gofast_maybe_init_libfuncs ();
8781 /* Return a number assessing the cost of moving a register in class
8782 FROM to class TO. The classes are expressed using the enumeration
8783 values such as `GENERAL_REGS'. A value of 2 is the default; other
8784 values are interpreted relative to that.
8786 It is not required that the cost always equal 2 when FROM is the
8787 same as TO; on some machines it is expensive to move between
8788 registers if they are not general registers.
8790 If reload sees an insn consisting of a single `set' between two
8791 hard registers, and if `REGISTER_MOVE_COST' applied to their
8792 classes returns a value of 2, reload does not check to ensure that
8793 the constraints of the insn are met. Setting a cost of other than
8794 2 will allow reload to verify that the constraints are met. You
8795 should do this if the `movM' pattern's constraints do not allow
8798 ??? We make the cost of moving from HI/LO into general
8799 registers the same as for one of moving general registers to
8800 HI/LO for TARGET_MIPS16 in order to prevent allocating a
8801 pseudo to HI/LO. This might hurt optimizations though, it
8802 isn't clear if it is wise. And it might not work in all cases. We
8803 could solve the DImode LO reg problem by using a multiply, just
8804 like reload_{in,out}si. We could solve the SImode/HImode HI reg
8805 problem by using divide instructions. divu puts the remainder in
8806 the HI reg, so doing a divide by -1 will move the value in the HI
8807 reg for all values except -1. We could handle that case by using a
8808 signed divide, e.g. -1 / 2 (or maybe 1 / -2?). We'd have to emit
8809 a compare/branch to test the input value to see which instruction
8810 we need to use. This gets pretty messy, but it is feasible. */
8813 mips_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
8814 enum reg_class to
, enum reg_class from
)
8816 if (from
== M16_REGS
&& GR_REG_CLASS_P (to
))
8818 else if (from
== M16_NA_REGS
&& GR_REG_CLASS_P (to
))
8820 else if (GR_REG_CLASS_P (from
))
8824 else if (to
== M16_NA_REGS
)
8826 else if (GR_REG_CLASS_P (to
))
8833 else if (to
== FP_REGS
)
8835 else if (to
== HI_REG
|| to
== LO_REG
|| to
== MD_REGS
)
8842 else if (COP_REG_CLASS_P (to
))
8846 } /* GR_REG_CLASS_P (from) */
8847 else if (from
== FP_REGS
)
8849 if (GR_REG_CLASS_P (to
))
8851 else if (to
== FP_REGS
)
8853 else if (to
== ST_REGS
)
8855 } /* from == FP_REGS */
8856 else if (from
== HI_REG
|| from
== LO_REG
|| from
== MD_REGS
)
8858 if (GR_REG_CLASS_P (to
))
8865 } /* from == HI_REG, etc. */
8866 else if (from
== ST_REGS
&& GR_REG_CLASS_P (to
))
8868 else if (COP_REG_CLASS_P (from
))
8871 } /* COP_REG_CLASS_P (from) */
8878 /* Return the length of INSN. LENGTH is the initial length computed by
8879 attributes in the machine-description file. */
8882 mips_adjust_insn_length (rtx insn
, int length
)
8884 /* A unconditional jump has an unfilled delay slot if it is not part
8885 of a sequence. A conditional jump normally has a delay slot, but
8886 does not on MIPS16. */
8887 if (simplejump_p (insn
)
8888 || (!TARGET_MIPS16
&& (GET_CODE (insn
) == JUMP_INSN
8889 || GET_CODE (insn
) == CALL_INSN
)))
8892 /* See how many nops might be needed to avoid hardware hazards. */
8893 if (!cfun
->machine
->ignore_hazard_length_p
&& INSN_CODE (insn
) >= 0)
8894 switch (get_attr_hazard (insn
))
8908 /* All MIPS16 instructions are a measly two bytes. */
8916 /* Return an asm sequence to start a noat block and load the address
8917 of a label into $1. */
8920 mips_output_load_label (void)
8922 if (TARGET_EXPLICIT_RELOCS
)
8926 return "%[lw\t%@,%%got_page(%0)(%+)\n\taddiu\t%@,%@,%%got_ofst(%0)";
8929 return "%[ld\t%@,%%got_page(%0)(%+)\n\tdaddiu\t%@,%@,%%got_ofst(%0)";
8932 if (ISA_HAS_LOAD_DELAY
)
8933 return "%[lw\t%@,%%got(%0)(%+)%#\n\taddiu\t%@,%@,%%lo(%0)";
8934 return "%[lw\t%@,%%got(%0)(%+)\n\taddiu\t%@,%@,%%lo(%0)";
8938 if (Pmode
== DImode
)
8939 return "%[dla\t%@,%0";
8941 return "%[la\t%@,%0";
8946 /* Output assembly instructions to peform a conditional branch.
8948 INSN is the branch instruction. OPERANDS[0] is the condition.
8949 OPERANDS[1] is the target of the branch. OPERANDS[2] is the target
8950 of the first operand to the condition. If TWO_OPERANDS_P is
8951 nonzero the comparison takes two operands; OPERANDS[3] will be the
8954 If INVERTED_P is nonzero we are to branch if the condition does
8955 not hold. If FLOAT_P is nonzero this is a floating-point comparison.
8957 LENGTH is the length (in bytes) of the sequence we are to generate.
8958 That tells us whether to generate a simple conditional branch, or a
8959 reversed conditional branch around a `jr' instruction. */
8961 mips_output_conditional_branch (rtx insn
, rtx
*operands
, int two_operands_p
,
8962 int float_p
, int inverted_p
, int length
)
8964 static char buffer
[200];
8965 /* The kind of comparison we are doing. */
8966 enum rtx_code code
= GET_CODE (operands
[0]);
8967 /* Nonzero if the opcode for the comparison needs a `z' indicating
8968 that it is a comparison against zero. */
8970 /* A string to use in the assembly output to represent the first
8972 const char *op1
= "%z2";
8973 /* A string to use in the assembly output to represent the second
8974 operand. Use the hard-wired zero register if there's no second
8976 const char *op2
= (two_operands_p
? ",%z3" : ",%.");
8977 /* The operand-printing string for the comparison. */
8978 const char *const comp
= (float_p
? "%F0" : "%C0");
8979 /* The operand-printing string for the inverted comparison. */
8980 const char *const inverted_comp
= (float_p
? "%W0" : "%N0");
8982 /* The MIPS processors (for levels of the ISA at least two), have
8983 "likely" variants of each branch instruction. These instructions
8984 annul the instruction in the delay slot if the branch is not
8986 mips_branch_likely
= (final_sequence
&& INSN_ANNULLED_BRANCH_P (insn
));
8988 if (!two_operands_p
)
8990 /* To compute whether than A > B, for example, we normally
8991 subtract B from A and then look at the sign bit. But, if we
8992 are doing an unsigned comparison, and B is zero, we don't
8993 have to do the subtraction. Instead, we can just check to
8994 see if A is nonzero. Thus, we change the CODE here to
8995 reflect the simpler comparison operation. */
9007 /* A condition which will always be true. */
9013 /* A condition which will always be false. */
9019 /* Not a special case. */
9024 /* Relative comparisons are always done against zero. But
9025 equality comparisons are done between two operands, and therefore
9026 do not require a `z' in the assembly language output. */
9027 need_z_p
= (!float_p
&& code
!= EQ
&& code
!= NE
);
9028 /* For comparisons against zero, the zero is not provided
9033 /* Begin by terminating the buffer. That way we can always use
9034 strcat to add to it. */
9041 /* Just a simple conditional branch. */
9043 sprintf (buffer
, "%%*b%s%%?\t%%Z2%%1%%/",
9044 inverted_p
? inverted_comp
: comp
);
9046 sprintf (buffer
, "%%*b%s%s%%?\t%s%s,%%1%%/",
9047 inverted_p
? inverted_comp
: comp
,
9048 need_z_p
? "z" : "",
9058 /* Generate a reversed conditional branch around ` j'
9071 If the original branch was a likely branch, the delay slot
9072 must be executed only if the branch is taken, so generate:
9084 When generating non-embedded PIC, instead of:
9097 rtx target
= gen_label_rtx ();
9099 orig_target
= operands
[1];
9100 operands
[1] = target
;
9101 /* Generate the reversed comparison. This takes four
9104 sprintf (buffer
, "%%*b%s\t%%Z2%%1",
9105 inverted_p
? comp
: inverted_comp
);
9107 sprintf (buffer
, "%%*b%s%s\t%s%s,%%1",
9108 inverted_p
? comp
: inverted_comp
,
9109 need_z_p
? "z" : "",
9112 output_asm_insn (buffer
, operands
);
9114 if (length
!= 16 && length
!= 28 && ! mips_branch_likely
)
9116 /* Output delay slot instruction. */
9117 rtx insn
= final_sequence
;
9118 final_scan_insn (XVECEXP (insn
, 0, 1), asm_out_file
,
9120 INSN_DELETED_P (XVECEXP (insn
, 0, 1)) = 1;
9123 output_asm_insn ("%#", 0);
9126 output_asm_insn ("j\t%0", &orig_target
);
9129 output_asm_insn (mips_output_load_label (), &orig_target
);
9130 output_asm_insn ("jr\t%@%]", 0);
9133 if (length
!= 16 && length
!= 28 && mips_branch_likely
)
9135 /* Output delay slot instruction. */
9136 rtx insn
= final_sequence
;
9137 final_scan_insn (XVECEXP (insn
, 0, 1), asm_out_file
,
9139 INSN_DELETED_P (XVECEXP (insn
, 0, 1)) = 1;
9142 output_asm_insn ("%#", 0);
9144 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
9145 CODE_LABEL_NUMBER (target
));
9158 /* Used to output div or ddiv instruction DIVISION, which has the
9159 operands given by OPERANDS. If we need a divide-by-zero check,
9160 output the instruction and return an asm string that traps if
9161 operand 2 is zero. Otherwise just return DIVISION itself. */
9164 mips_output_division (const char *division
, rtx
*operands
)
9166 if (TARGET_CHECK_ZERO_DIV
)
9168 output_asm_insn (division
, operands
);
9171 return "bnez\t%2,1f\n\tbreak\t7\n1:";
9173 return "bne\t%2,%.,1f%#\n\tbreak\t7\n1:";
9178 /* Return true if GIVEN is the same as CANONICAL, or if it is CANONICAL
9179 with a final "000" replaced by "k". Ignore case.
9181 Note: this function is shared between GCC and GAS. */
9184 mips_strict_matching_cpu_name_p (const char *canonical
, const char *given
)
9186 while (*given
!= 0 && TOLOWER (*given
) == TOLOWER (*canonical
))
9187 given
++, canonical
++;
9189 return ((*given
== 0 && *canonical
== 0)
9190 || (strcmp (canonical
, "000") == 0 && strcasecmp (given
, "k") == 0));
9194 /* Return true if GIVEN matches CANONICAL, where GIVEN is a user-supplied
9195 CPU name. We've traditionally allowed a lot of variation here.
9197 Note: this function is shared between GCC and GAS. */
9200 mips_matching_cpu_name_p (const char *canonical
, const char *given
)
9202 /* First see if the name matches exactly, or with a final "000"
9204 if (mips_strict_matching_cpu_name_p (canonical
, given
))
9207 /* If not, try comparing based on numerical designation alone.
9208 See if GIVEN is an unadorned number, or 'r' followed by a number. */
9209 if (TOLOWER (*given
) == 'r')
9211 if (!ISDIGIT (*given
))
9214 /* Skip over some well-known prefixes in the canonical name,
9215 hoping to find a number there too. */
9216 if (TOLOWER (canonical
[0]) == 'v' && TOLOWER (canonical
[1]) == 'r')
9218 else if (TOLOWER (canonical
[0]) == 'r' && TOLOWER (canonical
[1]) == 'm')
9220 else if (TOLOWER (canonical
[0]) == 'r')
9223 return mips_strict_matching_cpu_name_p (canonical
, given
);
9227 /* Parse an option that takes the name of a processor as its argument.
9228 OPTION is the name of the option and CPU_STRING is the argument.
9229 Return the corresponding processor enumeration if the CPU_STRING is
9230 recognized, otherwise report an error and return null.
9232 A similar function exists in GAS. */
9234 static const struct mips_cpu_info
*
9235 mips_parse_cpu (const char *option
, const char *cpu_string
)
9237 const struct mips_cpu_info
*p
;
9240 /* In the past, we allowed upper-case CPU names, but it doesn't
9241 work well with the multilib machinery. */
9242 for (s
= cpu_string
; *s
!= 0; s
++)
9245 warning ("the cpu name must be lower case");
9249 /* 'from-abi' selects the most compatible architecture for the given
9250 ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit ABIs. For the
9251 EABIs, we have to decide whether we're using the 32-bit or 64-bit
9252 version. Look first at the -mgp options, if given, otherwise base
9253 the choice on MASK_64BIT in TARGET_DEFAULT. */
9254 if (strcasecmp (cpu_string
, "from-abi") == 0)
9255 return mips_cpu_info_from_isa (ABI_NEEDS_32BIT_REGS
? 1
9256 : ABI_NEEDS_64BIT_REGS
? 3
9257 : (TARGET_64BIT
? 3 : 1));
9259 /* 'default' has traditionally been a no-op. Probably not very useful. */
9260 if (strcasecmp (cpu_string
, "default") == 0)
9263 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
9264 if (mips_matching_cpu_name_p (p
->name
, cpu_string
))
9267 error ("bad value (%s) for %s", cpu_string
, option
);
9272 /* Return the processor associated with the given ISA level, or null
9273 if the ISA isn't valid. */
9275 static const struct mips_cpu_info
*
9276 mips_cpu_info_from_isa (int isa
)
9278 const struct mips_cpu_info
*p
;
9280 for (p
= mips_cpu_info_table
; p
->name
!= 0; p
++)
9287 /* Adjust the cost of INSN based on the relationship between INSN that
9288 is dependent on DEP_INSN through the dependence LINK. The default
9289 is to make no adjustment to COST.
9291 On the MIPS, ignore the cost of anti- and output-dependencies. */
9293 mips_adjust_cost (rtx insn ATTRIBUTE_UNUSED
, rtx link
,
9294 rtx dep ATTRIBUTE_UNUSED
, int cost
)
9296 if (REG_NOTE_KIND (link
) != 0)
9297 return 0; /* Anti or output dependence. */
9301 /* Implement HARD_REGNO_NREGS. The size of FP registers are controlled
9302 by UNITS_PER_FPREG. All other registers are word sized. */
9305 mips_hard_regno_nregs (int regno
, enum machine_mode mode
)
9307 if (! FP_REG_P (regno
))
9308 return ((GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
);
9310 return ((GET_MODE_SIZE (mode
) + UNITS_PER_FPREG
- 1) / UNITS_PER_FPREG
);
9313 /* Implement RETURN_IN_MEMORY. Under the old (i.e., 32 and O64 ABIs)
9314 all BLKmode objects are returned in memory. Under the new (N32 and
9315 64-bit MIPS ABIs) small structures are returned in a register.
9316 Objects with varying size must still be returned in memory, of
9320 mips_return_in_memory (tree type
)
9322 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
9323 return (TYPE_MODE (type
) == BLKmode
);
9325 return ((int_size_in_bytes (type
) > (2 * UNITS_PER_WORD
))
9326 || (int_size_in_bytes (type
) == -1));
9330 mips_issue_rate (void)
9334 case PROCESSOR_R5400
:
9335 case PROCESSOR_R5500
:
9336 case PROCESSOR_R7000
:
9337 case PROCESSOR_R9000
:
9348 /* Implements TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE. Return true for
9349 processors that have a DFA pipeline description. */
9352 mips_use_dfa_pipeline_interface (void)
9356 case PROCESSOR_R5400
:
9357 case PROCESSOR_R5500
:
9358 case PROCESSOR_R7000
:
9359 case PROCESSOR_R9000
:
9360 case PROCESSOR_SR71000
:
9370 mips_emit_prefetch (rtx
*operands
)
9372 int write
= INTVAL (operands
[1]);
9373 int locality
= INTVAL (operands
[2]);
9374 int indexed
= GET_CODE (operands
[3]) == REG
;
9379 code
= (write
? 5 : 4); /* store_streamed / load_streamed. */
9380 else if (locality
<= 2)
9381 code
= (write
? 1 : 0); /* store / load. */
9383 code
= (write
? 7 : 6); /* store_retained / load_retained. */
9385 sprintf (buffer
, "%s\t%d,%%3(%%0)", indexed
? "prefx" : "pref", code
);
9386 output_asm_insn (buffer
, operands
);
9393 /* Output assembly to switch to section NAME with attribute FLAGS. */
9396 irix_asm_named_section_1 (const char *name
, unsigned int flags
,
9399 unsigned int sh_type
, sh_flags
, sh_entsize
;
9402 if (!(flags
& SECTION_DEBUG
))
9403 sh_flags
|= 2; /* SHF_ALLOC */
9404 if (flags
& SECTION_WRITE
)
9405 sh_flags
|= 1; /* SHF_WRITE */
9406 if (flags
& SECTION_CODE
)
9407 sh_flags
|= 4; /* SHF_EXECINSTR */
9408 if (flags
& SECTION_SMALL
)
9409 sh_flags
|= 0x10000000; /* SHF_MIPS_GPREL */
9410 if (strcmp (name
, ".debug_frame") == 0)
9411 sh_flags
|= 0x08000000; /* SHF_MIPS_NOSTRIP */
9412 if (flags
& SECTION_DEBUG
)
9413 sh_type
= 0x7000001e; /* SHT_MIPS_DWARF */
9414 else if (flags
& SECTION_BSS
)
9415 sh_type
= 8; /* SHT_NOBITS */
9417 sh_type
= 1; /* SHT_PROGBITS */
9419 if (flags
& SECTION_CODE
)
9424 fprintf (asm_out_file
, "\t.section %s,%#x,%#x,%u,%u\n",
9425 name
, sh_type
, sh_flags
, sh_entsize
, align
);
9429 irix_asm_named_section (const char *name
, unsigned int flags
)
9431 if (TARGET_SGI_O32_AS
)
9432 default_no_named_section (name
, flags
);
9433 else if (mips_abi
== ABI_32
&& TARGET_GAS
)
9434 default_elf_asm_named_section (name
, flags
);
9436 irix_asm_named_section_1 (name
, flags
, 0);
9439 /* In addition to emitting a .align directive, record the maximum
9440 alignment requested for the current section. */
9442 struct GTY (()) irix_section_align_entry
9449 static htab_t irix_section_align_htab
;
9450 static FILE *irix_orig_asm_out_file
;
9453 irix_section_align_entry_eq (const void *p1
, const void *p2
)
9455 const struct irix_section_align_entry
*old
= p1
;
9456 const char *new = p2
;
9458 return strcmp (old
->name
, new) == 0;
9462 irix_section_align_entry_hash (const void *p
)
9464 const struct irix_section_align_entry
*old
= p
;
9465 return htab_hash_string (old
->name
);
9469 irix_asm_output_align (FILE *file
, unsigned int log
)
9471 const char *section
= current_section_name ();
9472 struct irix_section_align_entry
**slot
, *entry
;
9474 if (mips_abi
!= ABI_32
)
9479 slot
= (struct irix_section_align_entry
**)
9480 htab_find_slot_with_hash (irix_section_align_htab
, section
,
9481 htab_hash_string (section
), INSERT
);
9485 entry
= (struct irix_section_align_entry
*)
9486 xmalloc (sizeof (struct irix_section_align_entry
));
9488 entry
->name
= section
;
9490 entry
->flags
= current_section_flags ();
9492 else if (entry
->log
< log
)
9496 fprintf (file
, "\t.align\t%u\n", log
);
9499 /* The IRIX assembler does not record alignment from .align directives,
9500 but takes it from the first .section directive seen. Play file
9501 switching games so that we can emit a .section directive at the
9502 beginning of the file with the proper alignment attached. */
9505 irix_file_start (void)
9509 if (mips_abi
== ABI_32
)
9512 irix_orig_asm_out_file
= asm_out_file
;
9513 asm_out_file
= tmpfile ();
9515 irix_section_align_htab
= htab_create (31, irix_section_align_entry_hash
,
9516 irix_section_align_entry_eq
, NULL
);
9520 irix_section_align_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
9522 const struct irix_section_align_entry
*entry
9523 = *(const struct irix_section_align_entry
**) slot
;
9525 irix_asm_named_section_1 (entry
->name
, entry
->flags
, 1 << entry
->log
);
9530 copy_file_data (FILE *to
, FILE *from
)
9536 fatal_error ("can't rewind temp file: %m");
9538 while ((len
= fread (buffer
, 1, sizeof (buffer
), from
)) > 0)
9539 if (fwrite (buffer
, 1, len
, to
) != len
)
9540 fatal_error ("can't write to output file: %m");
9543 fatal_error ("can't read from temp file: %m");
9546 fatal_error ("can't close temp file: %m");
9550 irix_file_end (void)
9552 if (mips_abi
!= ABI_32
)
9554 /* Emit section directives with the proper alignment at the top of the
9555 real output file. */
9556 FILE *temp
= asm_out_file
;
9557 asm_out_file
= irix_orig_asm_out_file
;
9558 htab_traverse (irix_section_align_htab
, irix_section_align_1
, NULL
);
9560 /* Copy the data emitted to the temp file to the real output file. */
9561 copy_file_data (asm_out_file
, temp
);
9568 /* Implement TARGET_SECTION_TYPE_FLAGS. Make sure that .sdata and
9569 .sbss sections get the SECTION_SMALL flag: this isn't set by the
9573 irix_section_type_flags (tree decl
, const char *section
, int relocs_p
)
9577 flags
= default_section_type_flags (decl
, section
, relocs_p
);
9579 if (strcmp (section
, ".sdata") == 0
9580 || strcmp (section
, ".sbss") == 0
9581 || strncmp (section
, ".gnu.linkonce.s.", 16) == 0
9582 || strncmp (section
, ".gnu.linkonce.sb.", 17) == 0)
9583 flags
|= SECTION_SMALL
;
9588 #endif /* TARGET_IRIX */
9590 #include "gt-mips.h"