1 /* Subroutines for insn-output.c for MIPS
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 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 GNU CC.
11 GNU CC 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 GNU CC 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 GNU CC; see the file COPYING. If not, write to
23 the Free Software Foundation, 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
26 /* ??? The TARGET_FP_CALL_32 macros are intended to simulate a 32 bit
27 calling convention in 64 bit mode. It doesn't work though, and should
28 be replaced with something better designed. */
35 #include "hard-reg-set.h"
37 #include "insn-config.h"
38 #include "conditions.h"
39 #include "insn-attr.h"
55 #include "target-def.h"
62 #define STAB_CODE_TYPE enum __stab_debug_code
64 #define STAB_CODE_TYPE int
67 extern tree lookup_name
PARAMS ((tree
));
69 /* Enumeration for all of the relational tests, so that we can build
70 arrays indexed by the test type, and not worry about the order
90 static enum internal_test map_test_to_internal_test
PARAMS ((enum rtx_code
));
91 static int mips16_simple_memory_operand
PARAMS ((rtx
, rtx
,
93 int coprocessor_operand
PARAMS ((rtx
,
95 int coprocessor2_operand
PARAMS ((rtx
,
97 static int m16_check_op
PARAMS ((rtx
, int, int, int));
98 static void block_move_loop
PARAMS ((rtx
, rtx
,
102 static void block_move_call
PARAMS ((rtx
, rtx
, rtx
));
103 static void mips_arg_info
PARAMS ((const CUMULATIVE_ARGS
*,
106 struct mips_arg_info
*));
107 static rtx mips_add_large_offset_to_sp
PARAMS ((HOST_WIDE_INT
));
108 static void mips_annotate_frame_insn
PARAMS ((rtx
, rtx
));
109 static rtx mips_frame_set
PARAMS ((enum machine_mode
,
111 static void mips_emit_frame_related_store
PARAMS ((rtx
, rtx
,
113 static void save_restore_insns
PARAMS ((int, rtx
, long));
114 static void mips16_output_gp_offset
PARAMS ((FILE *, rtx
));
115 static void mips16_fp_args
PARAMS ((FILE *, int, int));
116 static void build_mips16_function_stub
PARAMS ((FILE *));
117 static void mips16_optimize_gp
PARAMS ((rtx
));
118 static rtx add_constant
PARAMS ((struct constant
**,
121 static void dump_constants
PARAMS ((struct constant
*,
123 static rtx mips_find_symbol
PARAMS ((rtx
));
124 static void abort_with_insn
PARAMS ((rtx
, const char *))
126 static int symbolic_expression_p
PARAMS ((rtx
));
127 static void mips_add_gc_roots
PARAMS ((void));
128 static bool mips_assemble_integer
PARAMS ((rtx
, unsigned int, int));
129 static void mips_output_function_epilogue
PARAMS ((FILE *, HOST_WIDE_INT
));
130 static void mips_output_function_prologue
PARAMS ((FILE *, HOST_WIDE_INT
));
131 static enum processor_type mips_parse_cpu
PARAMS ((const char *));
132 static void copy_file_data
PARAMS ((FILE *, FILE *));
134 static void iris6_asm_named_section_1
PARAMS ((const char *,
137 static void iris6_asm_named_section
PARAMS ((const char *,
139 static int iris_section_align_entry_eq
PARAMS ((const PTR
, const PTR
));
140 static hashval_t iris_section_align_entry_hash
PARAMS ((const PTR
));
141 static int iris6_section_align_1
PARAMS ((void **, void *));
143 static int mips_adjust_cost
PARAMS ((rtx
, rtx
, rtx
, int));
144 static int mips_issue_rate
PARAMS ((void));
146 static void mips_init_machine_status
PARAMS ((struct function
*));
147 static void mips_free_machine_status
PARAMS ((struct function
*));
148 static void mips_mark_machine_status
PARAMS ((struct function
*));
149 static void mips_select_section
PARAMS ((tree
, int, unsigned HOST_WIDE_INT
))
151 static void mips_unique_section
PARAMS ((tree
, int))
153 static void mips_select_rtx_section
PARAMS ((enum machine_mode
, rtx
,
154 unsigned HOST_WIDE_INT
));
155 static void mips_encode_section_info
PARAMS ((tree
, int));
157 struct machine_function
{
158 /* Pseudo-reg holding the address of the current function when
159 generating embedded PIC code. Created by LEGITIMIZE_ADDRESS,
160 used by mips_finalize_pic if it was created. */
161 rtx embedded_pic_fnaddr_rtx
;
163 /* Pseudo-reg holding the value of $28 in a mips16 function which
164 refers to GP relative global variables. */
165 rtx mips16_gp_pseudo_rtx
;
168 /* Information about a single argument. */
171 /* True if the argument is a record or union type. */
174 /* True if the argument is passed in a floating-point register, or
175 would have been if we hadn't run out of registers. */
178 /* The argument's size, in bytes. */
179 unsigned int num_bytes
;
181 /* The number of words passed in registers, rounded up. */
182 unsigned int reg_words
;
184 /* The offset of the first register from GP_ARG_FIRST or FP_ARG_FIRST,
185 or MAX_ARGS_IN_REGISTERS if the argument is passed entirely
187 unsigned int reg_offset
;
189 /* The number of words that must be passed on the stack, rounded up. */
190 unsigned int stack_words
;
192 /* The offset from the start of the stack overflow area of the argument's
193 first stack word. Only meaningful when STACK_WORDS is non-zero. */
194 unsigned int stack_offset
;
197 /* Global variables for machine-dependent things. */
199 /* Threshold for data being put into the small data/bss area, instead
200 of the normal data area (references to the small data/bss area take
201 1 instruction, and use the global pointer, references to the normal
202 data area takes 2 instructions). */
203 int mips_section_threshold
= -1;
205 /* Count the number of .file directives, so that .loc is up to date. */
206 int num_source_filenames
= 0;
208 /* Count the number of sdb related labels are generated (to find block
209 start and end boundaries). */
210 int sdb_label_count
= 0;
212 /* Next label # for each statement for Silicon Graphics IRIS systems. */
215 /* Non-zero if inside of a function, because the stupid MIPS asm can't
216 handle .files inside of functions. */
217 int inside_function
= 0;
219 /* Files to separate the text and the data output, so that all of the data
220 can be emitted before the text, which will mean that the assembler will
221 generate smaller code, based on the global pointer. */
222 FILE *asm_out_data_file
;
223 FILE *asm_out_text_file
;
225 /* Linked list of all externals that are to be emitted when optimizing
226 for the global pointer if they haven't been declared by the end of
227 the program with an appropriate .comm or initialization. */
231 struct extern_list
*next
; /* next external */
232 const char *name
; /* name of the external */
233 int size
; /* size in bytes */
236 /* Name of the file containing the current function. */
237 const char *current_function_file
= "";
239 /* Warning given that Mips ECOFF can't support changing files
240 within a function. */
241 int file_in_function_warning
= FALSE
;
243 /* Whether to suppress issuing .loc's because the user attempted
244 to change the filename within a function. */
245 int ignore_line_number
= FALSE
;
247 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
253 /* The next branch instruction is a branch likely, not branch normal. */
254 int mips_branch_likely
;
256 /* Count of delay slots and how many are filled. */
257 int dslots_load_total
;
258 int dslots_load_filled
;
259 int dslots_jump_total
;
260 int dslots_jump_filled
;
262 /* # of nops needed by previous insn */
263 int dslots_number_nops
;
265 /* Number of 1/2/3 word references to data items (ie, not jal's). */
268 /* registers to check for load delay */
269 rtx mips_load_reg
, mips_load_reg2
, mips_load_reg3
, mips_load_reg4
;
271 /* Cached operands, and operator to compare for use in set/branch/trap
272 on condition codes. */
275 /* what type of branch to use */
276 enum cmp_type branch_type
;
278 /* Number of previously seen half-pic pointers and references. */
279 static int prev_half_pic_ptrs
= 0;
280 static int prev_half_pic_refs
= 0;
282 /* The target cpu for code generation. */
283 enum processor_type mips_arch
;
285 /* The target cpu for optimization and scheduling. */
286 enum processor_type mips_tune
;
288 /* which instruction set architecture to use. */
291 /* which abi to use. */
294 /* Strings to hold which cpu and instruction set architecture to use. */
295 const char *mips_cpu_string
; /* for -mcpu=<xxx> */
296 const char *mips_arch_string
; /* for -march=<xxx> */
297 const char *mips_tune_string
; /* for -mtune=<xxx> */
298 const char *mips_isa_string
; /* for -mips{1,2,3,4} */
299 const char *mips_abi_string
; /* for -mabi={32,n32,64,eabi} */
301 /* Whether we are generating mips16 code. This is a synonym for
302 TARGET_MIPS16, and exists for use as an attribute. */
305 /* This variable is set by -mno-mips16. We only care whether
306 -mno-mips16 appears or not, and using a string in this fashion is
307 just a way to avoid using up another bit in target_flags. */
308 const char *mips_no_mips16_string
;
310 /* This is only used to determine if an type size setting option was
311 explicitly specified (-mlong64, -mint64, -mlong32). The specs
312 set this option if such an option is used. */
313 const char *mips_explicit_type_size_string
;
315 /* Whether we are generating mips16 hard float code. In mips16 mode
316 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
317 -msoft-float was not specified by the user, which means that we
318 should arrange to call mips32 hard floating point code. */
319 int mips16_hard_float
;
321 /* This variable is set by -mentry. We only care whether -mentry
322 appears or not, and using a string in this fashion is just a way to
323 avoid using up another bit in target_flags. */
324 const char *mips_entry_string
;
326 const char *mips_cache_flush_func
= CACHE_FLUSH_FUNC
;
328 /* Whether we should entry and exit pseudo-ops in mips16 mode. */
331 /* If TRUE, we split addresses into their high and low parts in the RTL. */
332 int mips_split_addresses
;
334 /* Generating calls to position independent functions? */
335 enum mips_abicalls_type mips_abicalls
;
337 /* High and low marks for floating point values which we will accept
338 as legitimate constants for LEGITIMATE_CONSTANT_P. These are
339 initialized in override_options. */
340 REAL_VALUE_TYPE dfhigh
, dflow
, sfhigh
, sflow
;
342 /* Mode used for saving/restoring general purpose registers. */
343 static enum machine_mode gpr_mode
;
345 /* Array giving truth value on whether or not a given hard register
346 can support a given mode. */
347 char mips_hard_regno_mode_ok
[(int)MAX_MACHINE_MODE
][FIRST_PSEUDO_REGISTER
];
349 /* Current frame information calculated by compute_frame_size. */
350 struct mips_frame_info current_frame_info
;
352 /* Zero structure to initialize current_frame_info. */
353 struct mips_frame_info zero_frame_info
;
355 /* The length of all strings seen when compiling for the mips16. This
356 is used to tell how many strings are in the constant pool, so that
357 we can see if we may have an overflow. This is reset each time the
358 constant pool is output. */
359 int mips_string_length
;
361 /* In mips16 mode, we build a list of all the string constants we see
362 in a particular function. */
364 struct string_constant
366 struct string_constant
*next
;
370 static struct string_constant
*string_constants
;
372 /* List of all MIPS punctuation characters used by print_operand. */
373 char mips_print_operand_punct
[256];
375 /* Map GCC register number to debugger register number. */
376 int mips_dbx_regno
[FIRST_PSEUDO_REGISTER
];
378 /* Buffer to use to enclose a load/store operation with %{ %} to
379 turn on .set volatile. */
380 static char volatile_buffer
[60];
382 /* Hardware names for the registers. If -mrnames is used, this
383 will be overwritten with mips_sw_reg_names. */
385 char mips_reg_names
[][8] =
387 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
388 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
389 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
390 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
391 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
392 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
393 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
394 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
395 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
396 "$fcc5","$fcc6","$fcc7","$rap", "", "", "", "",
397 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
398 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
399 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
400 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
401 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
402 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
403 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
404 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
405 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
406 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
407 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
408 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
411 /* Mips software names for the registers, used to overwrite the
412 mips_reg_names array. */
414 char mips_sw_reg_names
[][8] =
416 "$zero","$at", "$v0", "$v1", "$a0", "$a1", "$a2", "$a3",
417 "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
418 "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7",
419 "$t8", "$t9", "$k0", "$k1", "$gp", "$sp", "$fp", "$ra",
420 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
421 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
422 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
423 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
424 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
425 "$fcc5","$fcc6","$fcc7","$rap", "", "", "", "",
426 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
427 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
428 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
429 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
430 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
431 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
432 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
433 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
434 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
435 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
436 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
437 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
440 /* Map hard register number to register class */
441 const enum reg_class mips_regno_to_class
[] =
443 GR_REGS
, GR_REGS
, M16_NA_REGS
, M16_NA_REGS
,
444 M16_REGS
, M16_REGS
, M16_REGS
, M16_REGS
,
445 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
446 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
447 M16_NA_REGS
, M16_NA_REGS
, GR_REGS
, GR_REGS
,
448 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
449 T_REG
, GR_REGS
, GR_REGS
, GR_REGS
,
450 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
451 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
452 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
453 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
454 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
455 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
456 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
457 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
458 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
459 HI_REG
, LO_REG
, HILO_REG
, ST_REGS
,
460 ST_REGS
, ST_REGS
, ST_REGS
, ST_REGS
,
461 ST_REGS
, ST_REGS
, ST_REGS
, GR_REGS
,
462 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
463 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
464 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
465 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
466 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
467 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
468 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
469 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
470 COP0_REGS
, COP0_REGS
, COP0_REGS
, COP0_REGS
,
471 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
472 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
473 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
474 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
475 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
476 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
477 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
478 COP2_REGS
, COP2_REGS
, COP2_REGS
, COP2_REGS
,
479 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
480 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
481 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
482 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
483 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
484 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
485 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
,
486 COP3_REGS
, COP3_REGS
, COP3_REGS
, COP3_REGS
489 /* Map register constraint character to register class. */
490 enum reg_class mips_char_to_class
[256] =
492 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
493 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
494 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
495 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
496 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
497 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
498 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
499 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
500 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
501 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
502 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
503 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
504 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
505 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
506 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
507 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
508 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
509 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
510 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
511 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
512 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
513 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
514 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
515 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
516 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
517 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
518 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
519 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
520 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
521 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
522 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
523 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
524 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
525 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
526 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
527 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
528 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
529 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
530 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
531 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
532 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
533 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
534 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
535 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
536 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
537 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
538 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
539 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
540 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
541 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
542 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
543 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
544 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
545 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
546 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
547 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
548 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
549 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
550 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
551 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
552 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
553 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
554 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
555 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
558 /* Initialize the GCC target structure. */
559 #undef TARGET_ASM_ALIGNED_HI_OP
560 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
561 #undef TARGET_ASM_ALIGNED_SI_OP
562 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
563 #undef TARGET_ASM_INTEGER
564 #define TARGET_ASM_INTEGER mips_assemble_integer
566 #if TARGET_IRIX5 && !TARGET_IRIX6
567 #undef TARGET_ASM_UNALIGNED_HI_OP
568 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.half\t"
569 #undef TARGET_ASM_UNALIGNED_SI_OP
570 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.word\t"
573 #undef TARGET_ASM_FUNCTION_PROLOGUE
574 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
575 #undef TARGET_ASM_FUNCTION_EPILOGUE
576 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
577 #undef TARGET_ASM_SELECT_RTX_SECTION
578 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
580 #undef TARGET_SCHED_ADJUST_COST
581 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
582 #undef TARGET_SCHED_ISSUE_RATE
583 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
585 #undef TARGET_ENCODE_SECTION_INFO
586 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
588 struct gcc_target targetm
= TARGET_INITIALIZER
;
590 /* Return truth value of whether OP can be used as an operands
591 where a register or 16 bit unsigned integer is needed. */
594 uns_arith_operand (op
, mode
)
596 enum machine_mode mode
;
598 if (GET_CODE (op
) == CONST_INT
&& SMALL_INT_UNSIGNED (op
))
601 return register_operand (op
, mode
);
604 /* Return truth value of whether OP can be used as an operands
605 where a 16 bit integer is needed */
608 arith_operand (op
, mode
)
610 enum machine_mode mode
;
612 if (GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
))
615 /* On the mips16, a GP relative value is a signed 16 bit offset. */
616 if (TARGET_MIPS16
&& GET_CODE (op
) == CONST
&& mips16_gp_offset_p (op
))
619 return register_operand (op
, mode
);
622 /* Return truth value of whether OP can be used as an operand in a two
623 address arithmetic insn (such as set 123456,%o4) of mode MODE. */
626 arith32_operand (op
, mode
)
628 enum machine_mode mode
;
630 if (GET_CODE (op
) == CONST_INT
)
633 return register_operand (op
, mode
);
636 /* Return truth value of whether OP is an integer which fits in 16 bits. */
641 enum machine_mode mode ATTRIBUTE_UNUSED
;
643 return (GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
));
646 /* Return truth value of whether OP is a 32 bit integer which is too big to
647 be loaded with one instruction. */
652 enum machine_mode mode ATTRIBUTE_UNUSED
;
656 if (GET_CODE (op
) != CONST_INT
)
661 /* ior reg,$r0,value */
662 if ((value
& ~ ((HOST_WIDE_INT
) 0x0000ffff)) == 0)
665 /* subu reg,$r0,value */
666 if (((unsigned HOST_WIDE_INT
) (value
+ 32768)) <= 32767)
669 /* lui reg,value>>16 */
670 if ((value
& 0x0000ffff) == 0)
676 /* Return truth value of whether OP is a register or the constant 0.
677 In mips16 mode, we only accept a register, since the mips16 does
681 reg_or_0_operand (op
, mode
)
683 enum machine_mode mode
;
685 switch (GET_CODE (op
))
690 return INTVAL (op
) == 0;
695 return op
== CONST0_RTX (mode
);
699 return register_operand (op
, mode
);
708 /* Return truth value of whether OP is a register or the constant 0,
709 even in mips16 mode. */
712 true_reg_or_0_operand (op
, mode
)
714 enum machine_mode mode
;
716 switch (GET_CODE (op
))
719 return INTVAL (op
) == 0;
722 return op
== CONST0_RTX (mode
);
726 return register_operand (op
, mode
);
735 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant. */
738 mips_const_double_ok (op
, mode
)
740 enum machine_mode mode
;
744 if (GET_CODE (op
) != CONST_DOUBLE
)
747 if (mode
== VOIDmode
)
750 if (mode
!= SFmode
&& mode
!= DFmode
)
753 if (op
== CONST0_RTX (mode
))
756 /* ??? li.s does not work right with SGI's Irix 6 assembler. */
757 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
&& mips_abi
!= ABI_EABI
)
760 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
762 if (REAL_VALUE_ISNAN (d
))
765 if (REAL_VALUE_NEGATIVE (d
))
766 d
= REAL_VALUE_NEGATE (d
);
770 if (REAL_VALUES_LESS (d
, dfhigh
)
771 && REAL_VALUES_LESS (dflow
, d
))
776 if (REAL_VALUES_LESS (d
, sfhigh
)
777 && REAL_VALUES_LESS (sflow
, d
))
784 /* Accept the floating point constant 1 in the appropriate mode. */
787 const_float_1_operand (op
, mode
)
789 enum machine_mode mode
;
792 static REAL_VALUE_TYPE onedf
;
793 static REAL_VALUE_TYPE onesf
;
794 static int one_initialized
;
796 if (GET_CODE (op
) != CONST_DOUBLE
797 || mode
!= GET_MODE (op
)
798 || (mode
!= DFmode
&& mode
!= SFmode
))
801 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
803 /* We only initialize these values if we need them, since we will
804 never get called unless mips_isa >= 4. */
805 if (! one_initialized
)
807 onedf
= REAL_VALUE_ATOF ("1.0", DFmode
);
808 onesf
= REAL_VALUE_ATOF ("1.0", SFmode
);
813 return REAL_VALUES_EQUAL (d
, onedf
);
815 return REAL_VALUES_EQUAL (d
, onesf
);
818 /* Return true if a memory load or store of REG plus OFFSET in MODE
819 can be represented in a single word on the mips16. */
822 mips16_simple_memory_operand (reg
, offset
, mode
)
825 enum machine_mode mode
;
832 /* We can't tell, because we don't know how the value will
833 eventually be accessed. Returning 0 here does no great
834 harm; it just prevents some possible instruction scheduling. */
838 size
= GET_MODE_SIZE (mode
);
840 if (INTVAL (offset
) % size
!= 0)
842 if (REGNO (reg
) == STACK_POINTER_REGNUM
&& GET_MODE_SIZE (mode
) == 4)
846 if (INTVAL (offset
) >= 0 && INTVAL (offset
) < (HOST_WIDE_INT
)(off
* size
))
851 /* Return truth value if a memory operand fits in a single instruction
852 (ie, register + small offset). */
855 simple_memory_operand (op
, mode
)
857 enum machine_mode mode
;
859 rtx addr
, plus0
, plus1
;
861 /* Eliminate non-memory operations */
862 if (GET_CODE (op
) != MEM
)
865 /* dword operations really put out 2 instructions, so eliminate them. */
866 /* ??? This isn't strictly correct. It is OK to accept multiword modes
867 here, since the length attributes are being set correctly, but only
868 if the address is offsettable. LO_SUM is not offsettable. */
869 if (GET_MODE_SIZE (GET_MODE (op
)) > (unsigned) UNITS_PER_WORD
)
872 /* Decode the address now. */
874 switch (GET_CODE (addr
))
883 return SMALL_INT (addr
);
886 plus0
= XEXP (addr
, 0);
887 plus1
= XEXP (addr
, 1);
888 if (GET_CODE (plus0
) == REG
889 && GET_CODE (plus1
) == CONST_INT
&& SMALL_INT (plus1
)
891 || mips16_simple_memory_operand (plus0
, plus1
, mode
)))
894 else if (GET_CODE (plus1
) == REG
895 && GET_CODE (plus0
) == CONST_INT
&& SMALL_INT (plus0
)
897 || mips16_simple_memory_operand (plus1
, plus0
, mode
)))
904 /* We used to allow small symbol refs here (ie, stuff in .sdata
905 or .sbss), but this causes some bugs in G++. Also, it won't
906 interfere if the MIPS linker rewrites the store instruction
907 because the function is PIC. */
909 case LABEL_REF
: /* never gp relative */
913 /* If -G 0, we can never have a GP relative memory operation.
914 Also, save some time if not optimizing. */
919 rtx offset
= const0_rtx
;
920 addr
= eliminate_constant_term (XEXP (addr
, 0), &offset
);
921 if (GET_CODE (op
) != SYMBOL_REF
)
924 /* let's be paranoid.... */
925 if (! SMALL_INT (offset
))
932 return SYMBOL_REF_FLAG (addr
);
935 /* This SYMBOL_REF case is for the mips16. If the above case is
936 reenabled, this one should be merged in. */
938 /* References to the constant pool on the mips16 use a small
939 offset if the function is small. The only time we care about
940 getting this right is during delayed branch scheduling, so
941 don't need to check until then. The machine_dependent_reorg
942 function will set the total length of the instructions used
943 in the function in current_frame_info. If that is small
944 enough, we know for sure that this is a small offset. It
945 would be better if we could take into account the location of
946 the instruction within the function, but we can't, because we
947 don't know where we are. */
949 && CONSTANT_POOL_ADDRESS_P (addr
)
950 && current_frame_info
.insns_len
> 0)
954 size
= current_frame_info
.insns_len
+ get_pool_size ();
955 if (GET_MODE_SIZE (mode
) == 4)
956 return size
< 4 * 0x100;
957 else if (GET_MODE_SIZE (mode
) == 8)
958 return size
< 8 * 0x20;
972 /* Return nonzero for a memory address that can be used to load or store
976 double_memory_operand (op
, mode
)
978 enum machine_mode mode
;
980 if (GET_CODE (op
) != MEM
981 || ! memory_operand (op
, mode
))
983 /* During reload, we accept a pseudo register if it has an
984 appropriate memory address. If we don't do this, we will
985 wind up reloading into a register, and then reloading that
986 register from memory, when we could just reload directly from
988 if (reload_in_progress
989 && GET_CODE (op
) == REG
990 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
991 && reg_renumber
[REGNO (op
)] < 0
992 && reg_equiv_mem
[REGNO (op
)] != 0
993 && double_memory_operand (reg_equiv_mem
[REGNO (op
)], mode
))
996 /* All reloaded addresses are valid in TARGET_64BIT mode. This is
997 the same test performed for 'm' in find_reloads. */
999 if (reload_in_progress
1001 && (GET_CODE (op
) == MEM
1002 || (GET_CODE (op
) == REG
1003 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
1004 && reg_renumber
[REGNO (op
)] < 0)))
1007 if (reload_in_progress
1009 && GET_CODE (op
) == MEM
)
1013 addr
= XEXP (op
, 0);
1015 /* During reload on the mips16, we accept a large offset
1016 from the frame pointer or the stack pointer. This large
1017 address will get reloaded anyhow. */
1018 if (GET_CODE (addr
) == PLUS
1019 && GET_CODE (XEXP (addr
, 0)) == REG
1020 && (REGNO (XEXP (addr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
1021 || REGNO (XEXP (addr
, 0)) == STACK_POINTER_REGNUM
)
1022 && ((GET_CODE (XEXP (addr
, 1)) == CONST_INT
1023 && ! SMALL_INT (XEXP (addr
, 1)))
1024 || (GET_CODE (XEXP (addr
, 1)) == SYMBOL_REF
1025 && CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 1)))))
1028 /* Similarly, we accept a case where the memory address is
1029 itself on the stack, and will be reloaded. */
1030 if (GET_CODE (addr
) == MEM
)
1034 maddr
= XEXP (addr
, 0);
1035 if (GET_CODE (maddr
) == PLUS
1036 && GET_CODE (XEXP (maddr
, 0)) == REG
1037 && (REGNO (XEXP (maddr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
1038 || REGNO (XEXP (maddr
, 0)) == STACK_POINTER_REGNUM
)
1039 && ((GET_CODE (XEXP (maddr
, 1)) == CONST_INT
1040 && ! SMALL_INT (XEXP (maddr
, 1)))
1041 || (GET_CODE (XEXP (maddr
, 1)) == SYMBOL_REF
1042 && CONSTANT_POOL_ADDRESS_P (XEXP (maddr
, 1)))))
1046 /* We also accept the same case when we have a 16 bit signed
1047 offset mixed in as well. The large address will get
1048 reloaded, and the 16 bit offset will be OK. */
1049 if (GET_CODE (addr
) == PLUS
1050 && GET_CODE (XEXP (addr
, 0)) == MEM
1051 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
1052 && SMALL_INT (XEXP (addr
, 1)))
1054 addr
= XEXP (XEXP (addr
, 0), 0);
1055 if (GET_CODE (addr
) == PLUS
1056 && GET_CODE (XEXP (addr
, 0)) == REG
1057 && (REGNO (XEXP (addr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
1058 || REGNO (XEXP (addr
, 0)) == STACK_POINTER_REGNUM
)
1059 && ((GET_CODE (XEXP (addr
, 1)) == CONST_INT
1060 && ! SMALL_INT (XEXP (addr
, 1)))
1061 || (GET_CODE (XEXP (addr
, 1)) == SYMBOL_REF
1062 && CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 1)))))
1072 /* In this case we can use an instruction like sd. */
1076 /* Make sure that 4 added to the address is a valid memory address.
1077 This essentially just checks for overflow in an added constant. */
1079 if (CONSTANT_ADDRESS_P (XEXP (op
, 0)))
1082 op
= adjust_address_nv (op
, GET_MODE_CLASS (mode
) == MODE_INT
1083 ? SImode
: SFmode
, 4);
1084 return memory_address_p (GET_MODE (op
), XEXP (op
, 0));
1087 /* Return nonzero if the code of this rtx pattern is EQ or NE. */
1090 equality_op (op
, mode
)
1092 enum machine_mode mode
;
1094 if (mode
!= GET_MODE (op
))
1097 return GET_CODE (op
) == EQ
|| GET_CODE (op
) == NE
;
1100 /* Return nonzero if the code is a relational operations (EQ, LE, etc.) */
1105 enum machine_mode mode
;
1107 if (mode
!= GET_MODE (op
))
1110 return GET_RTX_CLASS (GET_CODE (op
)) == '<';
1113 /* Return nonzero if the code is a relational operation suitable for a
1114 conditional trap instructuion (only EQ, NE, LT, LTU, GE, GEU).
1115 We need this in the insn that expands `trap_if' in order to prevent
1116 combine from erroneously altering the condition. */
1119 trap_cmp_op (op
, mode
)
1121 enum machine_mode mode
;
1123 if (mode
!= GET_MODE (op
))
1126 switch (GET_CODE (op
))
1141 /* Return nonzero if the operand is either the PC or a label_ref. */
1144 pc_or_label_operand (op
, mode
)
1146 enum machine_mode mode ATTRIBUTE_UNUSED
;
1151 if (GET_CODE (op
) == LABEL_REF
)
1157 /* Test for a valid operand for a call instruction.
1158 Don't allow the arg pointer register or virtual regs
1159 since they may change into reg + const, which the patterns
1160 can't handle yet. */
1163 call_insn_operand (op
, mode
)
1165 enum machine_mode mode ATTRIBUTE_UNUSED
;
1167 return (CONSTANT_ADDRESS_P (op
)
1168 || (GET_CODE (op
) == REG
&& op
!= arg_pointer_rtx
1169 && ! (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1170 && REGNO (op
) <= LAST_VIRTUAL_REGISTER
)));
1173 /* Return nonzero if OPERAND is valid as a source operand for a move
1177 move_operand (op
, mode
)
1179 enum machine_mode mode
;
1181 /* Accept any general operand after reload has started; doing so
1182 avoids losing if reload does an in-place replacement of a register
1183 with a SYMBOL_REF or CONST. */
1184 return (general_operand (op
, mode
)
1185 && (! (mips_split_addresses
&& mips_check_split (op
, mode
))
1186 || reload_in_progress
|| reload_completed
)
1188 && GET_CODE (op
) == SYMBOL_REF
1189 && ! mips16_constant (op
, mode
, 1, 0)));
1192 /* Return nonzero if OPERAND is valid as a source operand for movdi.
1193 This accepts not only general_operand, but also sign extended
1194 constants and registers. We need to accept sign extended constants
1195 in case a sign extended register which is used in an expression,
1196 and is equivalent to a constant, is spilled. */
1199 movdi_operand (op
, mode
)
1201 enum machine_mode mode
;
1205 && GET_CODE (op
) == SIGN_EXTEND
1206 && GET_MODE (op
) == DImode
1207 && (GET_MODE (XEXP (op
, 0)) == SImode
1208 || (GET_CODE (XEXP (op
, 0)) == CONST_INT
1209 && GET_MODE (XEXP (op
, 0)) == VOIDmode
))
1210 && (register_operand (XEXP (op
, 0), SImode
)
1211 || immediate_operand (XEXP (op
, 0), SImode
)))
1214 return (general_operand (op
, mode
)
1216 && GET_CODE (op
) == SYMBOL_REF
1217 && ! mips16_constant (op
, mode
, 1, 0)));
1220 /* Like register_operand, but when in 64 bit mode also accept a sign
1221 extend of a 32 bit register, since the value is known to be already
1225 se_register_operand (op
, mode
)
1227 enum machine_mode mode
;
1231 && GET_CODE (op
) == SIGN_EXTEND
1232 && GET_MODE (op
) == DImode
1233 && GET_MODE (XEXP (op
, 0)) == SImode
1234 && register_operand (XEXP (op
, 0), SImode
))
1237 return register_operand (op
, mode
);
1240 /* Like reg_or_0_operand, but when in 64 bit mode also accept a sign
1241 extend of a 32 bit register, since the value is known to be already
1245 se_reg_or_0_operand (op
, mode
)
1247 enum machine_mode mode
;
1251 && GET_CODE (op
) == SIGN_EXTEND
1252 && GET_MODE (op
) == DImode
1253 && GET_MODE (XEXP (op
, 0)) == SImode
1254 && register_operand (XEXP (op
, 0), SImode
))
1257 return reg_or_0_operand (op
, mode
);
1260 /* Like uns_arith_operand, but when in 64 bit mode also accept a sign
1261 extend of a 32 bit register, since the value is known to be already
1265 se_uns_arith_operand (op
, mode
)
1267 enum machine_mode mode
;
1271 && GET_CODE (op
) == SIGN_EXTEND
1272 && GET_MODE (op
) == DImode
1273 && GET_MODE (XEXP (op
, 0)) == SImode
1274 && register_operand (XEXP (op
, 0), SImode
))
1277 return uns_arith_operand (op
, mode
);
1280 /* Like arith_operand, but when in 64 bit mode also accept a sign
1281 extend of a 32 bit register, since the value is known to be already
1285 se_arith_operand (op
, mode
)
1287 enum machine_mode mode
;
1291 && GET_CODE (op
) == SIGN_EXTEND
1292 && GET_MODE (op
) == DImode
1293 && GET_MODE (XEXP (op
, 0)) == SImode
1294 && register_operand (XEXP (op
, 0), SImode
))
1297 return arith_operand (op
, mode
);
1300 /* Like nonmemory_operand, but when in 64 bit mode also accept a sign
1301 extend of a 32 bit register, since the value is known to be already
1305 se_nonmemory_operand (op
, mode
)
1307 enum machine_mode mode
;
1311 && GET_CODE (op
) == SIGN_EXTEND
1312 && GET_MODE (op
) == DImode
1313 && GET_MODE (XEXP (op
, 0)) == SImode
1314 && register_operand (XEXP (op
, 0), SImode
))
1317 return nonmemory_operand (op
, mode
);
1320 /* Like nonimmediate_operand, but when in 64 bit mode also accept a
1321 sign extend of a 32 bit register, since the value is known to be
1322 already sign extended. */
1325 se_nonimmediate_operand (op
, mode
)
1327 enum machine_mode mode
;
1331 && GET_CODE (op
) == SIGN_EXTEND
1332 && GET_MODE (op
) == DImode
1333 && GET_MODE (XEXP (op
, 0)) == SImode
1334 && register_operand (XEXP (op
, 0), SImode
))
1337 return nonimmediate_operand (op
, mode
);
1340 /* Accept any operand that can appear in a mips16 constant table
1341 instruction. We can't use any of the standard operand functions
1342 because for these instructions we accept values that are not
1343 accepted by LEGITIMATE_CONSTANT, such as arbitrary SYMBOL_REFs. */
1346 consttable_operand (op
, mode
)
1348 enum machine_mode mode ATTRIBUTE_UNUSED
;
1350 return CONSTANT_P (op
);
1353 /* Coprocessor operand; return true if rtx is a REG and refers to a
1357 coprocessor_operand (op
, mode
)
1359 enum machine_mode mode ATTRIBUTE_UNUSED
;
1361 return (GET_CODE (op
) == REG
1362 && COP0_REG_FIRST
<= REGNO (op
)
1363 && REGNO (op
) <= COP3_REG_LAST
);
1367 coprocessor2_operand (op
, mode
)
1369 enum machine_mode mode ATTRIBUTE_UNUSED
;
1371 return (GET_CODE (op
) == REG
1372 && COP2_REG_FIRST
<= REGNO (op
)
1373 && REGNO (op
) <= COP2_REG_LAST
);
1376 /* Return nonzero if we split the address into high and low parts. */
1378 /* ??? We should also handle reg+array somewhere. We get four
1379 instructions currently, lui %hi/addui %lo/addui reg/lw. Better is
1380 lui %hi/addui reg/lw %lo. Fixing GO_IF_LEGITIMATE_ADDRESS to accept
1381 (plus (reg) (symbol_ref)) doesn't work because the SYMBOL_REF is broken
1382 out of the address, then we have 4 instructions to combine. Perhaps
1383 add a 3->2 define_split for combine. */
1385 /* ??? We could also split a CONST_INT here if it is a large_int().
1386 However, it doesn't seem to be very useful to have %hi(constant).
1387 We would be better off by doing the masking ourselves and then putting
1388 the explicit high part of the constant in the RTL. This will give better
1389 optimization. Also, %hi(constant) needs assembler changes to work.
1390 There is already a define_split that does this. */
1393 mips_check_split (address
, mode
)
1395 enum machine_mode mode
;
1397 /* ??? This is the same check used in simple_memory_operand.
1398 We use it here because LO_SUM is not offsettable. */
1399 if (GET_MODE_SIZE (mode
) > (unsigned) UNITS_PER_WORD
)
1402 if ((GET_CODE (address
) == SYMBOL_REF
&& ! SYMBOL_REF_FLAG (address
))
1403 || (GET_CODE (address
) == CONST
1404 && GET_CODE (XEXP (XEXP (address
, 0), 0)) == SYMBOL_REF
1405 && ! SYMBOL_REF_FLAG (XEXP (XEXP (address
, 0), 0)))
1406 || GET_CODE (address
) == LABEL_REF
)
1412 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1415 mips_reg_mode_ok_for_base_p (reg
, mode
, strict
)
1417 enum machine_mode mode
;
1421 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg
), mode
)
1422 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg
), mode
));
1425 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1426 returns a nonzero value if XINSN is a legitimate address for a
1427 memory operand of the indicated MODE. STRICT is non-zero if this
1428 function is called during reload. */
1431 mips_legitimate_address_p (mode
, xinsn
, strict
)
1432 enum machine_mode mode
;
1436 if (TARGET_DEBUG_B_MODE
)
1438 GO_PRINTF2 ("\n========== GO_IF_LEGITIMATE_ADDRESS, %sstrict\n",
1439 strict
? "" : "not ");
1440 GO_DEBUG_RTX (xinsn
);
1443 /* Check for constant before stripping off SUBREG, so that we don't
1444 accept (subreg (const_int)) which will fail to reload. */
1445 if (CONSTANT_ADDRESS_P (xinsn
)
1446 && ! (mips_split_addresses
&& mips_check_split (xinsn
, mode
))
1447 && (! TARGET_MIPS16
|| mips16_constant (xinsn
, mode
, 1, 0)))
1450 while (GET_CODE (xinsn
) == SUBREG
)
1451 xinsn
= SUBREG_REG (xinsn
);
1453 /* The mips16 can only use the stack pointer as a base register when
1454 loading SImode or DImode values. */
1455 if (GET_CODE (xinsn
) == REG
1456 && mips_reg_mode_ok_for_base_p (xinsn
, mode
, strict
))
1459 if (GET_CODE (xinsn
) == LO_SUM
&& mips_split_addresses
)
1461 register rtx xlow0
= XEXP (xinsn
, 0);
1462 register rtx xlow1
= XEXP (xinsn
, 1);
1464 while (GET_CODE (xlow0
) == SUBREG
)
1465 xlow0
= SUBREG_REG (xlow0
);
1466 if (GET_CODE (xlow0
) == REG
1467 && mips_reg_mode_ok_for_base_p (xlow0
, mode
, strict
)
1468 && mips_check_split (xlow1
, mode
))
1472 if (GET_CODE (xinsn
) == PLUS
)
1474 register rtx xplus0
= XEXP (xinsn
, 0);
1475 register rtx xplus1
= XEXP (xinsn
, 1);
1476 register enum rtx_code code0
;
1477 register enum rtx_code code1
;
1479 while (GET_CODE (xplus0
) == SUBREG
)
1480 xplus0
= SUBREG_REG (xplus0
);
1481 code0
= GET_CODE (xplus0
);
1483 while (GET_CODE (xplus1
) == SUBREG
)
1484 xplus1
= SUBREG_REG (xplus1
);
1485 code1
= GET_CODE (xplus1
);
1487 /* The mips16 can only use the stack pointer as a base register
1488 when loading SImode or DImode values. */
1490 && mips_reg_mode_ok_for_base_p (xplus0
, mode
, strict
))
1492 if (code1
== CONST_INT
&& SMALL_INT (xplus1
))
1495 /* On the mips16, we represent GP relative offsets in RTL.
1496 These are 16 bit signed values, and can serve as register
1499 && mips16_gp_offset_p (xplus1
))
1502 /* For some code sequences, you actually get better code by
1503 pretending that the MIPS supports an address mode of a
1504 constant address + a register, even though the real
1505 machine doesn't support it. This is because the
1506 assembler can use $r1 to load just the high 16 bits, add
1507 in the register, and fold the low 16 bits into the memory
1508 reference, whereas the compiler generates a 4 instruction
1509 sequence. On the other hand, CSE is not as effective.
1510 It would be a win to generate the lui directly, but the
1511 MIPS assembler does not have syntax to generate the
1512 appropriate relocation. */
1514 /* Also accept CONST_INT addresses here, so no else. */
1515 /* Reject combining an embedded PIC text segment reference
1516 with a register. That requires an additional
1518 /* ??? Reject combining an address with a register for the MIPS
1519 64 bit ABI, because the SGI assembler can not handle this. */
1520 if (!TARGET_DEBUG_A_MODE
1521 && (mips_abi
== ABI_32
1522 || mips_abi
== ABI_O64
1523 || mips_abi
== ABI_EABI
)
1524 && CONSTANT_ADDRESS_P (xplus1
)
1525 && ! mips_split_addresses
1526 && (!TARGET_EMBEDDED_PIC
1528 || GET_CODE (XEXP (xplus1
, 0)) != MINUS
)
1529 /* When assembling for machines with 64 bit registers,
1530 the assembler will sign-extend the constant "foo"
1531 in "la x, foo(x)" yielding the wrong result for:
1532 (set (blah:DI) (plus x y)). */
1534 || (code1
== CONST_INT
1535 && trunc_int_for_mode (INTVAL (xplus1
),
1536 SImode
) == INTVAL (xplus1
)))
1542 if (TARGET_DEBUG_B_MODE
)
1543 GO_PRINTF ("Not a legitimate address\n");
1545 /* The address was not legitimate. */
1550 /* We need a lot of little routines to check constant values on the
1551 mips16. These are used to figure out how long the instruction will
1552 be. It would be much better to do this using constraints, but
1553 there aren't nearly enough letters available. */
1556 m16_check_op (op
, low
, high
, mask
)
1562 return (GET_CODE (op
) == CONST_INT
1563 && INTVAL (op
) >= low
1564 && INTVAL (op
) <= high
1565 && (INTVAL (op
) & mask
) == 0);
1569 m16_uimm3_b (op
, mode
)
1571 enum machine_mode mode ATTRIBUTE_UNUSED
;
1573 return m16_check_op (op
, 0x1, 0x8, 0);
1577 m16_simm4_1 (op
, mode
)
1579 enum machine_mode mode ATTRIBUTE_UNUSED
;
1581 return m16_check_op (op
, - 0x8, 0x7, 0);
1585 m16_nsimm4_1 (op
, mode
)
1587 enum machine_mode mode ATTRIBUTE_UNUSED
;
1589 return m16_check_op (op
, - 0x7, 0x8, 0);
1593 m16_simm5_1 (op
, mode
)
1595 enum machine_mode mode ATTRIBUTE_UNUSED
;
1597 return m16_check_op (op
, - 0x10, 0xf, 0);
1601 m16_nsimm5_1 (op
, mode
)
1603 enum machine_mode mode ATTRIBUTE_UNUSED
;
1605 return m16_check_op (op
, - 0xf, 0x10, 0);
1609 m16_uimm5_4 (op
, mode
)
1611 enum machine_mode mode ATTRIBUTE_UNUSED
;
1613 return m16_check_op (op
, (- 0x10) << 2, 0xf << 2, 3);
1617 m16_nuimm5_4 (op
, mode
)
1619 enum machine_mode mode ATTRIBUTE_UNUSED
;
1621 return m16_check_op (op
, (- 0xf) << 2, 0x10 << 2, 3);
1625 m16_simm8_1 (op
, mode
)
1627 enum machine_mode mode ATTRIBUTE_UNUSED
;
1629 return m16_check_op (op
, - 0x80, 0x7f, 0);
1633 m16_nsimm8_1 (op
, mode
)
1635 enum machine_mode mode ATTRIBUTE_UNUSED
;
1637 return m16_check_op (op
, - 0x7f, 0x80, 0);
1641 m16_uimm8_1 (op
, mode
)
1643 enum machine_mode mode ATTRIBUTE_UNUSED
;
1645 return m16_check_op (op
, 0x0, 0xff, 0);
1649 m16_nuimm8_1 (op
, mode
)
1651 enum machine_mode mode ATTRIBUTE_UNUSED
;
1653 return m16_check_op (op
, - 0xff, 0x0, 0);
1657 m16_uimm8_m1_1 (op
, mode
)
1659 enum machine_mode mode ATTRIBUTE_UNUSED
;
1661 return m16_check_op (op
, - 0x1, 0xfe, 0);
1665 m16_uimm8_4 (op
, mode
)
1667 enum machine_mode mode ATTRIBUTE_UNUSED
;
1669 return m16_check_op (op
, 0x0, 0xff << 2, 3);
1673 m16_nuimm8_4 (op
, mode
)
1675 enum machine_mode mode ATTRIBUTE_UNUSED
;
1677 return m16_check_op (op
, (- 0xff) << 2, 0x0, 3);
1681 m16_simm8_8 (op
, mode
)
1683 enum machine_mode mode ATTRIBUTE_UNUSED
;
1685 return m16_check_op (op
, (- 0x80) << 3, 0x7f << 3, 7);
1689 m16_nsimm8_8 (op
, mode
)
1691 enum machine_mode mode ATTRIBUTE_UNUSED
;
1693 return m16_check_op (op
, (- 0x7f) << 3, 0x80 << 3, 7);
1696 /* References to the string table on the mips16 only use a small
1697 offset if the function is small. See the comment in the SYMBOL_REF
1698 case in simple_memory_operand. We can't check for LABEL_REF here,
1699 because the offset is always large if the label is before the
1700 referencing instruction. */
1703 m16_usym8_4 (op
, mode
)
1705 enum machine_mode mode ATTRIBUTE_UNUSED
;
1707 if (GET_CODE (op
) == SYMBOL_REF
1708 && SYMBOL_REF_FLAG (op
)
1709 && current_frame_info
.insns_len
> 0
1710 && XSTR (op
, 0)[0] == '*'
1711 && strncmp (XSTR (op
, 0) + 1, LOCAL_LABEL_PREFIX
,
1712 sizeof LOCAL_LABEL_PREFIX
- 1) == 0
1713 && (current_frame_info
.insns_len
+ get_pool_size () + mips_string_length
1716 struct string_constant
*l
;
1718 /* Make sure this symbol is on thelist of string constants to be
1719 output for this function. It is possible that it has already
1720 been output, in which case this requires a large offset. */
1721 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
1722 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
1730 m16_usym5_4 (op
, mode
)
1732 enum machine_mode mode ATTRIBUTE_UNUSED
;
1734 if (GET_CODE (op
) == SYMBOL_REF
1735 && SYMBOL_REF_FLAG (op
)
1736 && current_frame_info
.insns_len
> 0
1737 && XSTR (op
, 0)[0] == '*'
1738 && strncmp (XSTR (op
, 0) + 1, LOCAL_LABEL_PREFIX
,
1739 sizeof LOCAL_LABEL_PREFIX
- 1) == 0
1740 && (current_frame_info
.insns_len
+ get_pool_size () + mips_string_length
1743 struct string_constant
*l
;
1745 /* Make sure this symbol is on thelist of string constants to be
1746 output for this function. It is possible that it has already
1747 been output, in which case this requires a large offset. */
1748 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
1749 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
1756 /* Returns an operand string for the given instruction's delay slot,
1757 after updating filled delay slot statistics.
1759 We assume that operands[0] is the target register that is set.
1761 In order to check the next insn, most of this functionality is moved
1762 to FINAL_PRESCAN_INSN, and we just set the global variables that
1765 /* ??? This function no longer does anything useful, because final_prescan_insn
1766 now will never emit a nop. */
1769 mips_fill_delay_slot (ret
, type
, operands
, cur_insn
)
1770 const char *ret
; /* normal string to return */
1771 enum delay_type type
; /* type of delay */
1772 rtx operands
[]; /* operands to use */
1773 rtx cur_insn
; /* current insn */
1775 register rtx set_reg
;
1776 register enum machine_mode mode
;
1777 register rtx next_insn
= cur_insn
? NEXT_INSN (cur_insn
) : NULL_RTX
;
1778 register int num_nops
;
1780 if (type
== DELAY_LOAD
|| type
== DELAY_FCMP
)
1783 else if (type
== DELAY_HILO
)
1789 /* Make sure that we don't put nop's after labels. */
1790 next_insn
= NEXT_INSN (cur_insn
);
1791 while (next_insn
!= 0 && GET_CODE (next_insn
) == NOTE
)
1792 next_insn
= NEXT_INSN (next_insn
);
1794 dslots_load_total
+= num_nops
;
1795 if (TARGET_DEBUG_F_MODE
1797 || type
== DELAY_NONE
1801 || GET_CODE (next_insn
) == CODE_LABEL
1802 || (set_reg
= operands
[0]) == 0)
1804 dslots_number_nops
= 0;
1812 set_reg
= operands
[0];
1816 while (GET_CODE (set_reg
) == SUBREG
)
1817 set_reg
= SUBREG_REG (set_reg
);
1819 mode
= GET_MODE (set_reg
);
1820 dslots_number_nops
= num_nops
;
1821 mips_load_reg
= set_reg
;
1822 if (GET_MODE_SIZE (mode
)
1823 > (unsigned) (FP_REG_P (REGNO (set_reg
)) ? UNITS_PER_FPREG
: UNITS_PER_WORD
))
1824 mips_load_reg2
= gen_rtx_REG (SImode
, REGNO (set_reg
) + 1);
1828 if (type
== DELAY_HILO
)
1830 mips_load_reg3
= gen_rtx_REG (SImode
, MD_REG_FIRST
);
1831 mips_load_reg4
= gen_rtx_REG (SImode
, MD_REG_FIRST
+1);
1843 /* Determine whether a memory reference takes one (based off of the GP
1844 pointer), two (normal), or three (label + reg) instructions, and bump the
1845 appropriate counter for -mstats. */
1848 mips_count_memory_refs (op
, num
)
1854 rtx addr
, plus0
, plus1
;
1855 enum rtx_code code0
, code1
;
1858 if (TARGET_DEBUG_B_MODE
)
1860 fprintf (stderr
, "\n========== mips_count_memory_refs:\n");
1864 /* Skip MEM if passed, otherwise handle movsi of address. */
1865 addr
= (GET_CODE (op
) != MEM
) ? op
: XEXP (op
, 0);
1867 /* Loop, going through the address RTL. */
1871 switch (GET_CODE (addr
))
1879 plus0
= XEXP (addr
, 0);
1880 plus1
= XEXP (addr
, 1);
1881 code0
= GET_CODE (plus0
);
1882 code1
= GET_CODE (plus1
);
1892 if (code0
== CONST_INT
)
1907 if (code1
== CONST_INT
)
1914 if (code0
== SYMBOL_REF
|| code0
== LABEL_REF
|| code0
== CONST
)
1921 if (code1
== SYMBOL_REF
|| code1
== LABEL_REF
|| code1
== CONST
)
1931 n_words
= 2; /* always 2 words */
1935 addr
= XEXP (addr
, 0);
1940 n_words
= SYMBOL_REF_FLAG (addr
) ? 1 : 2;
1952 n_words
+= additional
;
1956 num_refs
[n_words
-1] += num
;
1960 /* Return a pseudo that points to the address of the current function.
1961 The first time it is called for a function, an initializer for the
1962 pseudo is emitted in the beginning of the function. */
1965 embedded_pic_fnaddr_reg ()
1967 if (cfun
->machine
->embedded_pic_fnaddr_rtx
== NULL
)
1971 cfun
->machine
->embedded_pic_fnaddr_rtx
= gen_reg_rtx (Pmode
);
1973 /* Output code at function start to initialize the pseudo-reg. */
1974 /* ??? We used to do this in FINALIZE_PIC, but that does not work for
1975 inline functions, because it is called after RTL for the function
1976 has been copied. The pseudo-reg in embedded_pic_fnaddr_rtx however
1977 does not get copied, and ends up not matching the rest of the RTL.
1978 This solution works, but means that we get unnecessary code to
1979 initialize this value every time a function is inlined into another
1982 emit_insn (gen_get_fnaddr (cfun
->machine
->embedded_pic_fnaddr_rtx
,
1983 XEXP (DECL_RTL (current_function_decl
), 0)));
1984 seq
= gen_sequence ();
1986 push_topmost_sequence ();
1987 emit_insn_after (seq
, get_insns ());
1988 pop_topmost_sequence ();
1991 return cfun
->machine
->embedded_pic_fnaddr_rtx
;
1994 /* Return RTL for the offset from the current function to the argument.
1995 X is the symbol whose offset from the current function we want. */
1998 embedded_pic_offset (x
)
2001 /* Make sure it is emitted. */
2002 embedded_pic_fnaddr_reg ();
2005 gen_rtx_CONST (Pmode
,
2006 gen_rtx_MINUS (Pmode
, x
,
2007 XEXP (DECL_RTL (current_function_decl
), 0)));
2010 /* Return the appropriate instructions to move one operand to another. */
2013 mips_move_1word (operands
, insn
, unsignedp
)
2018 const char *ret
= 0;
2019 rtx op0
= operands
[0];
2020 rtx op1
= operands
[1];
2021 enum rtx_code code0
= GET_CODE (op0
);
2022 enum rtx_code code1
= GET_CODE (op1
);
2023 enum machine_mode mode
= GET_MODE (op0
);
2024 int subreg_offset0
= 0;
2025 int subreg_offset1
= 0;
2026 enum delay_type delay
= DELAY_NONE
;
2028 while (code0
== SUBREG
)
2030 subreg_offset0
+= subreg_regno_offset (REGNO (SUBREG_REG (op0
)),
2031 GET_MODE (SUBREG_REG (op0
)),
2034 op0
= SUBREG_REG (op0
);
2035 code0
= GET_CODE (op0
);
2038 while (code1
== SUBREG
)
2040 subreg_offset1
+= subreg_regno_offset (REGNO (SUBREG_REG (op1
)),
2041 GET_MODE (SUBREG_REG (op1
)),
2044 op1
= SUBREG_REG (op1
);
2045 code1
= GET_CODE (op1
);
2048 /* For our purposes, a condition code mode is the same as SImode. */
2054 int regno0
= REGNO (op0
) + subreg_offset0
;
2058 int regno1
= REGNO (op1
) + subreg_offset1
;
2060 /* Just in case, don't do anything for assigning a register
2061 to itself, unless we are filling a delay slot. */
2062 if (regno0
== regno1
&& set_nomacro
== 0)
2065 else if (GP_REG_P (regno0
))
2067 if (GP_REG_P (regno1
))
2068 ret
= "move\t%0,%1";
2070 else if (MD_REG_P (regno1
))
2073 if (regno1
!= HILO_REGNUM
)
2079 else if (ST_REG_P (regno1
) && ISA_HAS_8CC
)
2080 ret
= "li\t%0,1\n\tmovf\t%0,%.,%1";
2085 if (FP_REG_P (regno1
))
2086 ret
= "mfc1\t%0,%1";
2087 else if (ALL_COP_REG_P (regno1
))
2089 static char retval
[] = "mfc_\t%0,%1";
2091 retval
[3] = COPNUM_AS_CHAR_FROM_REGNUM (regno1
);
2094 else if (regno1
== FPSW_REGNUM
&& ! ISA_HAS_8CC
)
2095 ret
= "cfc1\t%0,$31";
2099 else if (FP_REG_P (regno0
))
2101 if (GP_REG_P (regno1
))
2104 ret
= "mtc1\t%1,%0";
2107 if (FP_REG_P (regno1
))
2108 ret
= "mov.s\t%0,%1";
2111 else if (MD_REG_P (regno0
))
2113 if (GP_REG_P (regno1
))
2116 if (regno0
!= HILO_REGNUM
&& ! TARGET_MIPS16
)
2121 else if (regno0
== FPSW_REGNUM
&& ! ISA_HAS_8CC
)
2123 if (GP_REG_P (regno1
))
2126 ret
= "ctc1\t%0,$31";
2129 else if (ALL_COP_REG_P (regno0
))
2131 if (GP_REG_P (regno1
))
2133 static char retval
[] = "mtc_\t%1,%0";
2134 char cop
= COPNUM_AS_CHAR_FROM_REGNUM (regno0
);
2137 abort_with_insn (insn
,
2138 "mtc0 not supported; it disturbs virtual address translation");
2146 else if (code1
== MEM
)
2151 mips_count_memory_refs (op1
, 1);
2153 if (GP_REG_P (regno0
))
2155 /* For loads, use the mode of the memory item, instead of the
2156 target, so zero/sign extend can use this code as well. */
2157 switch (GET_MODE (op1
))
2166 ret
= ((unsignedp
&& TARGET_64BIT
)
2171 ret
= (unsignedp
) ? "lhu\t%0,%1" : "lh\t%0,%1";
2174 ret
= (unsignedp
) ? "lbu\t%0,%1" : "lb\t%0,%1";
2179 else if (FP_REG_P (regno0
) && (mode
== SImode
|| mode
== SFmode
))
2182 else if (ALL_COP_REG_P (regno0
))
2184 static char retval
[] = "lwc_\t%0,%1";
2185 char cop
= COPNUM_AS_CHAR_FROM_REGNUM (regno0
);
2188 abort_with_insn (insn
,
2189 "loads from memory to COP0 are illegal");
2195 if (ret
!= (char *)0 && MEM_VOLATILE_P (op1
))
2197 size_t i
= strlen (ret
);
2198 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2201 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2202 ret
= volatile_buffer
;
2206 else if (code1
== CONST_INT
2207 || (code1
== CONST_DOUBLE
2208 && GET_MODE (op1
) == VOIDmode
))
2210 if (code1
== CONST_DOUBLE
)
2212 /* This can happen when storing constants into long long
2213 bitfields. Just store the least significant word of
2215 operands
[1] = op1
= GEN_INT (CONST_DOUBLE_LOW (op1
));
2218 if (INTVAL (op1
) == 0 && ! TARGET_MIPS16
)
2220 if (GP_REG_P (regno0
))
2221 ret
= "move\t%0,%z1";
2223 else if (FP_REG_P (regno0
))
2226 ret
= "mtc1\t%z1,%0";
2229 else if (MD_REG_P (regno0
))
2236 else if (GP_REG_P (regno0
))
2238 /* Don't use X format, because that will give out of
2239 range numbers for 64 bit host and 32 bit target. */
2240 if (! TARGET_MIPS16
)
2241 ret
= "li\t%0,%1\t\t\t# %X1";
2244 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2246 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2247 ret
= "li\t%0,%n1\n\tneg\t%0";
2252 else if (code1
== CONST_DOUBLE
&& mode
== SFmode
)
2254 if (op1
== CONST0_RTX (SFmode
))
2256 if (GP_REG_P (regno0
))
2257 ret
= "move\t%0,%.";
2259 else if (FP_REG_P (regno0
))
2262 ret
= "mtc1\t%.,%0";
2269 ret
= "li.s\t%0,%1";
2273 else if (code1
== LABEL_REF
)
2276 mips_count_memory_refs (op1
, 1);
2281 else if (code1
== SYMBOL_REF
|| code1
== CONST
)
2283 if (HALF_PIC_P () && CONSTANT_P (op1
) && HALF_PIC_ADDRESS_P (op1
))
2285 rtx offset
= const0_rtx
;
2287 if (GET_CODE (op1
) == CONST
)
2288 op1
= eliminate_constant_term (XEXP (op1
, 0), &offset
);
2290 if (GET_CODE (op1
) == SYMBOL_REF
)
2292 operands
[2] = HALF_PIC_PTR (op1
);
2295 mips_count_memory_refs (operands
[2], 1);
2297 if (INTVAL (offset
) == 0)
2300 ret
= (unsignedp
&& TARGET_64BIT
2306 dslots_load_total
++;
2307 operands
[3] = offset
;
2308 if (unsignedp
&& TARGET_64BIT
)
2309 ret
= (SMALL_INT (offset
)
2310 ? "lwu\t%0,%2%#\n\tadd\t%0,%0,%3"
2311 : "lwu\t%0,%2%#\n\t%[li\t%@,%3\n\tadd\t%0,%0,%@%]");
2313 ret
= (SMALL_INT (offset
)
2314 ? "lw\t%0,%2%#\n\tadd\t%0,%0,%3"
2315 : "lw\t%0,%2%#\n\t%[li\t%@,%3\n\tadd\t%0,%0,%@%]");
2319 else if (TARGET_MIPS16
2321 && GET_CODE (XEXP (op1
, 0)) == REG
2322 && REGNO (XEXP (op1
, 0)) == GP_REG_FIRST
+ 28)
2324 /* This case arises on the mips16; see
2325 mips16_gp_pseudo_reg. */
2326 ret
= "move\t%0,%+";
2328 else if (TARGET_MIPS16
2329 && code1
== SYMBOL_REF
2330 && SYMBOL_REF_FLAG (op1
)
2331 && (XSTR (op1
, 0)[0] != '*'
2332 || strncmp (XSTR (op1
, 0) + 1,
2334 sizeof LOCAL_LABEL_PREFIX
- 1) != 0))
2336 /* This can occur when reloading the address of a GP
2337 relative symbol on the mips16. */
2338 ret
= "move\t%0,%+\n\taddu\t%0,%%gprel(%a1)";
2343 mips_count_memory_refs (op1
, 1);
2349 else if (code1
== PLUS
)
2351 rtx add_op0
= XEXP (op1
, 0);
2352 rtx add_op1
= XEXP (op1
, 1);
2354 if (GET_CODE (XEXP (op1
, 1)) == REG
2355 && GET_CODE (XEXP (op1
, 0)) == CONST_INT
)
2356 add_op0
= XEXP (op1
, 1), add_op1
= XEXP (op1
, 0);
2358 operands
[2] = add_op0
;
2359 operands
[3] = add_op1
;
2360 ret
= "add%:\t%0,%2,%3";
2363 else if (code1
== HIGH
)
2365 operands
[1] = XEXP (op1
, 0);
2366 ret
= "lui\t%0,%%hi(%1)";
2370 else if (code0
== MEM
)
2373 mips_count_memory_refs (op0
, 1);
2377 int regno1
= REGNO (op1
) + subreg_offset1
;
2379 if (GP_REG_P (regno1
))
2383 case SFmode
: ret
= "sw\t%1,%0"; break;
2384 case SImode
: ret
= "sw\t%1,%0"; break;
2385 case HImode
: ret
= "sh\t%1,%0"; break;
2386 case QImode
: ret
= "sb\t%1,%0"; break;
2391 else if (FP_REG_P (regno1
) && (mode
== SImode
|| mode
== SFmode
))
2393 else if (ALL_COP_REG_P (regno1
))
2395 static char retval
[] = "swc_\t%1,%0";
2397 retval
[3] = COPNUM_AS_CHAR_FROM_REGNUM (regno1
);
2402 else if (code1
== CONST_INT
&& INTVAL (op1
) == 0)
2406 case SFmode
: ret
= "sw\t%z1,%0"; break;
2407 case SImode
: ret
= "sw\t%z1,%0"; break;
2408 case HImode
: ret
= "sh\t%z1,%0"; break;
2409 case QImode
: ret
= "sb\t%z1,%0"; break;
2414 else if (code1
== CONST_DOUBLE
&& op1
== CONST0_RTX (mode
))
2418 case SFmode
: ret
= "sw\t%.,%0"; break;
2419 case SImode
: ret
= "sw\t%.,%0"; break;
2420 case HImode
: ret
= "sh\t%.,%0"; break;
2421 case QImode
: ret
= "sb\t%.,%0"; break;
2426 if (ret
!= 0 && MEM_VOLATILE_P (op0
))
2428 size_t i
= strlen (ret
);
2430 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2433 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2434 ret
= volatile_buffer
;
2440 abort_with_insn (insn
, "bad move");
2444 if (delay
!= DELAY_NONE
)
2445 return mips_fill_delay_slot (ret
, delay
, operands
, insn
);
2451 /* Return the appropriate instructions to move 2 words */
2454 mips_move_2words (operands
, insn
)
2458 const char *ret
= 0;
2459 rtx op0
= operands
[0];
2460 rtx op1
= operands
[1];
2461 enum rtx_code code0
= GET_CODE (operands
[0]);
2462 enum rtx_code code1
= GET_CODE (operands
[1]);
2463 int subreg_offset0
= 0;
2464 int subreg_offset1
= 0;
2465 enum delay_type delay
= DELAY_NONE
;
2467 while (code0
== SUBREG
)
2469 subreg_offset0
+= subreg_regno_offset (REGNO (SUBREG_REG (op0
)),
2470 GET_MODE (SUBREG_REG (op0
)),
2473 op0
= SUBREG_REG (op0
);
2474 code0
= GET_CODE (op0
);
2477 if (code1
== SIGN_EXTEND
)
2479 op1
= XEXP (op1
, 0);
2480 code1
= GET_CODE (op1
);
2483 while (code1
== SUBREG
)
2485 subreg_offset1
+= subreg_regno_offset (REGNO (SUBREG_REG (op1
)),
2486 GET_MODE (SUBREG_REG (op1
)),
2489 op1
= SUBREG_REG (op1
);
2490 code1
= GET_CODE (op1
);
2494 if (GET_CODE (operands
[1]) == SIGN_EXTEND
2496 && code1
!= CONST_INT
2497 /* The following three can happen as the result of a questionable
2499 && code1
!= LABEL_REF
2500 && code1
!= SYMBOL_REF
2506 int regno0
= REGNO (op0
) + subreg_offset0
;
2510 int regno1
= REGNO (op1
) + subreg_offset1
;
2512 /* Just in case, don't do anything for assigning a register
2513 to itself, unless we are filling a delay slot. */
2514 if (regno0
== regno1
&& set_nomacro
== 0)
2517 else if (FP_REG_P (regno0
))
2519 if (FP_REG_P (regno1
))
2520 ret
= "mov.d\t%0,%1";
2528 abort_with_insn (insn
, "bad move");
2530 #ifdef TARGET_FP_CALL_32
2531 if (FP_CALL_GP_REG_P (regno1
))
2532 ret
= "dsll\t%1,32\n\tor\t%1,%D1\n\tdmtc1\t%1,%0";
2535 ret
= "dmtc1\t%1,%0";
2538 ret
= "mtc1\t%L1,%0\n\tmtc1\t%M1,%D0";
2542 else if (FP_REG_P (regno1
))
2548 abort_with_insn (insn
, "bad move");
2550 #ifdef TARGET_FP_CALL_32
2551 if (FP_CALL_GP_REG_P (regno0
))
2552 ret
= "dmfc1\t%0,%1\n\tmfc1\t%D0,%1\n\tdsrl\t%0,32";
2555 ret
= "dmfc1\t%0,%1";
2558 ret
= "mfc1\t%L0,%1\n\tmfc1\t%M0,%D1";
2561 else if (MD_REG_P (regno0
) && GP_REG_P (regno1
) && !TARGET_MIPS16
)
2566 if (regno0
!= HILO_REGNUM
)
2568 else if (regno1
== 0)
2569 ret
= "mtlo\t%.\n\tmthi\t%.";
2572 ret
= "mthi\t%M1\n\tmtlo\t%L1";
2575 else if (GP_REG_P (regno0
) && MD_REG_P (regno1
))
2580 if (regno1
!= HILO_REGNUM
)
2584 ret
= "mfhi\t%M0\n\tmflo\t%L0";
2586 else if (GP_REG_P (regno0
) && ALL_COP_REG_P (regno1
)
2589 static char retval
[] = "dmfc_\t%0,%1";
2592 retval
[4] = COPNUM_AS_CHAR_FROM_REGNUM (regno1
);
2595 else if (ALL_COP_REG_P (regno0
) && GP_REG_P (regno1
)
2598 static char retval
[] = "dmtc_\t%1,%0";
2599 char cop
= COPNUM_AS_CHAR_FROM_REGNUM (regno0
);
2602 abort_with_insn (insn
,
2603 "dmtc0 not supported; it disturbs virtual address translation");
2608 else if (TARGET_64BIT
)
2609 ret
= "move\t%0,%1";
2611 else if (regno0
!= (regno1
+1))
2612 ret
= "move\t%0,%1\n\tmove\t%D0,%D1";
2615 ret
= "move\t%D0,%D1\n\tmove\t%0,%1";
2618 else if (code1
== CONST_DOUBLE
)
2620 /* Move zero from $0 unless !TARGET_64BIT and recipient
2621 is 64-bit fp reg, in which case generate a constant. */
2622 if (op1
!= CONST0_RTX (GET_MODE (op1
))
2623 || (TARGET_FLOAT64
&& !TARGET_64BIT
&& FP_REG_P (regno0
)))
2625 if (GET_MODE (op1
) == DFmode
)
2629 #ifdef TARGET_FP_CALL_32
2630 if (FP_CALL_GP_REG_P (regno0
))
2632 if (TARGET_FLOAT64
&& !TARGET_64BIT
)
2634 split_double (op1
, operands
+ 2, operands
+ 3);
2635 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2638 ret
= "li.d\t%0,%1\n\tdsll\t%D0,%0,32\n\tdsrl\t%D0,32\n\tdsrl\t%0,32";
2642 /* GNU as emits 64-bit code for li.d if the ISA is 3
2643 or higher. For !TARGET_64BIT && gp registers we
2644 need to avoid this by using two li instructions
2646 if (ISA_HAS_64BIT_REGS
2648 && ! FP_REG_P (regno0
))
2650 split_double (op1
, operands
+ 2, operands
+ 3);
2651 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2654 ret
= "li.d\t%0,%1";
2657 else if (TARGET_64BIT
)
2659 if (! TARGET_MIPS16
)
2665 split_double (op1
, operands
+ 2, operands
+ 3);
2666 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2672 if (GP_REG_P (regno0
))
2674 #ifdef TARGET_FP_CALL_32
2675 && ! FP_CALL_GP_REG_P (regno0
)
2678 : "move\t%0,%.\n\tmove\t%D0,%.");
2680 else if (FP_REG_P (regno0
))
2685 : "mtc1\t%.,%0\n\tmtc1\t%.,%D0");
2690 else if (code1
== CONST_INT
&& INTVAL (op1
) == 0 && ! TARGET_MIPS16
)
2692 if (GP_REG_P (regno0
))
2695 : "move\t%0,%.\n\tmove\t%D0,%.");
2697 else if (FP_REG_P (regno0
))
2704 : "mtc1\t%.,%0\n\tmtc1\t%.,%D0"));
2706 else if (MD_REG_P (regno0
))
2709 ret
= (regno0
== HILO_REGNUM
2710 ? "mtlo\t%.\n\tmthi\t%."
2715 else if (code1
== CONST_INT
&& GET_MODE (op0
) == DImode
2716 && GP_REG_P (regno0
))
2722 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2724 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2725 ret
= "li\t%0,%n1\n\tneg\t%0";
2727 else if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2728 ret
= "li\t%0,%1\t\t# %X1";
2729 else if (HOST_BITS_PER_WIDE_INT
< 64)
2730 /* We can't use 'X' for negative numbers, because then we won't
2731 get the right value for the upper 32 bits. */
2732 ret
= (INTVAL (op1
) < 0
2733 ? "dli\t%0,%1\t\t\t# %X1"
2734 : "dli\t%0,%X1\t\t# %1");
2736 /* We must use 'X', because otherwise LONG_MIN will print as
2737 a number that the assembler won't accept. */
2738 ret
= "dli\t%0,%X1\t\t# %1";
2740 else if (HOST_BITS_PER_WIDE_INT
< 64)
2742 operands
[2] = GEN_INT (INTVAL (operands
[1]) >= 0 ? 0 : -1);
2745 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2746 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2747 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2749 operands
[2] = GEN_INT (1);
2750 ret
= "li\t%M0,%2\n\tneg\t%M0\n\tli\t%L0,%n1\n\tneg\t%L0";
2754 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2758 /* We use multiple shifts here, to avoid warnings about out
2759 of range shifts on 32 bit hosts. */
2760 operands
[2] = GEN_INT (INTVAL (operands
[1]) >> 16 >> 16);
2762 = GEN_INT (INTVAL (operands
[1]) << 16 << 16 >> 16 >> 16);
2765 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2766 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2767 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2769 operands
[2] = GEN_INT (1);
2770 ret
= "li\t%M0,%2\n\tneg\t%M0\n\tli\t%L0,%n1\n\tneg\t%L0";
2774 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2778 else if (code1
== MEM
)
2783 mips_count_memory_refs (op1
, 2);
2785 if (FP_REG_P (regno0
))
2788 else if (ALL_COP_REG_P (regno0
) && TARGET_64BIT
)
2790 static char retval
[] = "ldc_\t%0,%1";
2791 char cop
= COPNUM_AS_CHAR_FROM_REGNUM (regno0
);
2794 abort_with_insn (insn
,
2795 "loads from memory to COP0 are illegal");
2801 else if (TARGET_64BIT
)
2804 #ifdef TARGET_FP_CALL_32
2805 if (FP_CALL_GP_REG_P (regno0
))
2806 ret
= (double_memory_operand (op1
, GET_MODE (op1
))
2807 ? "lwu\t%0,%1\n\tlwu\t%D0,4+%1"
2808 : "ld\t%0,%1\n\tdsll\t%D0,%0,32\n\tdsrl\t%D0,32\n\tdsrl\t%0,32");
2814 else if (double_memory_operand (op1
, GET_MODE (op1
)))
2815 ret
= (reg_mentioned_p (op0
, op1
)
2816 ? "lw\t%D0,%D1\n\tlw\t%0,%1"
2817 : "lw\t%0,%1\n\tlw\t%D0,%D1");
2819 if (ret
!= 0 && MEM_VOLATILE_P (op1
))
2821 size_t i
= strlen (ret
);
2823 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2826 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2827 ret
= volatile_buffer
;
2831 else if (code1
== LABEL_REF
)
2834 mips_count_memory_refs (op1
, 2);
2836 if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2837 /* We deliberately remove the 'a' from '%1', so that we don't
2838 have to add SIGN_EXTEND support to print_operand_address.
2839 print_operand will just call print_operand_address in this
2840 case, so there is no problem. */
2843 ret
= "dla\t%0,%a1";
2845 else if (code1
== SYMBOL_REF
|| code1
== CONST
)
2849 && GET_CODE (XEXP (op1
, 0)) == REG
2850 && REGNO (XEXP (op1
, 0)) == GP_REG_FIRST
+ 28)
2852 /* This case arises on the mips16; see
2853 mips16_gp_pseudo_reg. */
2854 ret
= "move\t%0,%+";
2856 else if (TARGET_MIPS16
2857 && code1
== SYMBOL_REF
2858 && SYMBOL_REF_FLAG (op1
)
2859 && (XSTR (op1
, 0)[0] != '*'
2860 || strncmp (XSTR (op1
, 0) + 1,
2862 sizeof LOCAL_LABEL_PREFIX
- 1) != 0))
2864 /* This can occur when reloading the address of a GP
2865 relative symbol on the mips16. */
2866 ret
= "move\t%0,%+\n\taddu\t%0,%%gprel(%a1)";
2871 mips_count_memory_refs (op1
, 2);
2873 if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2874 /* We deliberately remove the 'a' from '%1', so that we don't
2875 have to add SIGN_EXTEND support to print_operand_address.
2876 print_operand will just call print_operand_address in this
2877 case, so there is no problem. */
2880 ret
= "dla\t%0,%a1";
2885 else if (code0
== MEM
)
2889 int regno1
= REGNO (op1
) + subreg_offset1
;
2891 if (FP_REG_P (regno1
))
2894 else if (ALL_COP_REG_P (regno1
) && TARGET_64BIT
)
2896 static char retval
[] = "sdc_\t%1,%0";
2898 retval
[3] = COPNUM_AS_CHAR_FROM_REGNUM (regno1
);
2901 else if (TARGET_64BIT
)
2904 #ifdef TARGET_FP_CALL_32
2905 if (FP_CALL_GP_REG_P (regno1
))
2906 ret
= "dsll\t%1,32\n\tor\t%1,%D1\n\tsd\t%1,%0";
2912 else if (double_memory_operand (op0
, GET_MODE (op0
)))
2913 ret
= "sw\t%1,%0\n\tsw\t%D1,%D0";
2916 else if (((code1
== CONST_INT
&& INTVAL (op1
) == 0)
2917 || (code1
== CONST_DOUBLE
2918 && op1
== CONST0_RTX (GET_MODE (op1
))))
2920 || double_memory_operand (op0
, GET_MODE (op0
))))
2925 ret
= "sw\t%.,%0\n\tsw\t%.,%D0";
2929 mips_count_memory_refs (op0
, 2);
2931 if (ret
!= 0 && MEM_VOLATILE_P (op0
))
2933 size_t i
= strlen (ret
);
2935 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2938 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2939 ret
= volatile_buffer
;
2945 abort_with_insn (insn
, "bad move");
2949 if (delay
!= DELAY_NONE
)
2950 return mips_fill_delay_slot (ret
, delay
, operands
, insn
);
2955 /* Provide the costs of an addressing mode that contains ADDR.
2956 If ADDR is not a valid address, its cost is irrelevant. */
2959 mips_address_cost (addr
)
2962 switch (GET_CODE (addr
))
2972 rtx offset
= const0_rtx
;
2973 addr
= eliminate_constant_term (XEXP (addr
, 0), &offset
);
2974 if (GET_CODE (addr
) == LABEL_REF
)
2977 if (GET_CODE (addr
) != SYMBOL_REF
)
2980 if (! SMALL_INT (offset
))
2984 /* ... fall through ... */
2987 return SYMBOL_REF_FLAG (addr
) ? 1 : 2;
2991 register rtx plus0
= XEXP (addr
, 0);
2992 register rtx plus1
= XEXP (addr
, 1);
2994 if (GET_CODE (plus0
) != REG
&& GET_CODE (plus1
) == REG
)
2995 plus0
= XEXP (addr
, 1), plus1
= XEXP (addr
, 0);
2997 if (GET_CODE (plus0
) != REG
)
3000 switch (GET_CODE (plus1
))
3003 return SMALL_INT (plus1
) ? 1 : 2;
3010 return mips_address_cost (plus1
) + 1;
3024 /* Return nonzero if X is an address which needs a temporary register when
3025 reloaded while generating PIC code. */
3028 pic_address_needs_scratch (x
)
3031 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
3032 if (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
3033 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
3034 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
3035 && ! SMALL_INT (XEXP (XEXP (x
, 0), 1)))
3041 /* Make normal rtx_code into something we can index from an array */
3043 static enum internal_test
3044 map_test_to_internal_test (test_code
)
3045 enum rtx_code test_code
;
3047 enum internal_test test
= ITEST_MAX
;
3051 case EQ
: test
= ITEST_EQ
; break;
3052 case NE
: test
= ITEST_NE
; break;
3053 case GT
: test
= ITEST_GT
; break;
3054 case GE
: test
= ITEST_GE
; break;
3055 case LT
: test
= ITEST_LT
; break;
3056 case LE
: test
= ITEST_LE
; break;
3057 case GTU
: test
= ITEST_GTU
; break;
3058 case GEU
: test
= ITEST_GEU
; break;
3059 case LTU
: test
= ITEST_LTU
; break;
3060 case LEU
: test
= ITEST_LEU
; break;
3068 /* Generate the code to compare two integer values. The return value is:
3069 (reg:SI xx) The pseudo register the comparison is in
3070 0 No register, generate a simple branch.
3072 ??? This is called with result nonzero by the Scond patterns in
3073 mips.md. These patterns are called with a target in the mode of
3074 the Scond instruction pattern. Since this must be a constant, we
3075 must use SImode. This means that if RESULT is non-zero, it will
3076 always be an SImode register, even if TARGET_64BIT is true. We
3077 cope with this by calling convert_move rather than emit_move_insn.
3078 This will sometimes lead to an unnecessary extension of the result;
3090 gen_int_relational (test_code
, result
, cmp0
, cmp1
, p_invert
)
3091 enum rtx_code test_code
; /* relational test (EQ, etc) */
3092 rtx result
; /* result to store comp. or 0 if branch */
3093 rtx cmp0
; /* first operand to compare */
3094 rtx cmp1
; /* second operand to compare */
3095 int *p_invert
; /* NULL or ptr to hold whether branch needs */
3096 /* to reverse its test */
3100 enum rtx_code test_code
; /* code to use in instruction (LT vs. LTU) */
3101 int const_low
; /* low bound of constant we can accept */
3102 int const_high
; /* high bound of constant we can accept */
3103 int const_add
; /* constant to add (convert LE -> LT) */
3104 int reverse_regs
; /* reverse registers in test */
3105 int invert_const
; /* != 0 if invert value if cmp1 is constant */
3106 int invert_reg
; /* != 0 if invert value if cmp1 is register */
3107 int unsignedp
; /* != 0 for unsigned comparisons. */
3110 static const struct cmp_info info
[ (int)ITEST_MAX
] = {
3112 { XOR
, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
3113 { XOR
, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
3114 { LT
, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
3115 { LT
, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
3116 { LT
, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
3117 { LT
, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
3118 { LTU
, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
3119 { LTU
, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
3120 { LTU
, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
3121 { LTU
, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
3124 enum internal_test test
;
3125 enum machine_mode mode
;
3126 const struct cmp_info
*p_info
;
3133 test
= map_test_to_internal_test (test_code
);
3134 if (test
== ITEST_MAX
)
3137 p_info
= &info
[(int) test
];
3138 eqne_p
= (p_info
->test_code
== XOR
);
3140 mode
= GET_MODE (cmp0
);
3141 if (mode
== VOIDmode
)
3142 mode
= GET_MODE (cmp1
);
3144 /* Eliminate simple branches */
3145 branch_p
= (result
== 0);
3148 if (GET_CODE (cmp0
) == REG
|| GET_CODE (cmp0
) == SUBREG
)
3150 /* Comparisons against zero are simple branches */
3151 if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0
3152 && (! TARGET_MIPS16
|| eqne_p
))
3155 /* Test for beq/bne. */
3156 if (eqne_p
&& ! TARGET_MIPS16
)
3160 /* allocate a pseudo to calculate the value in. */
3161 result
= gen_reg_rtx (mode
);
3164 /* Make sure we can handle any constants given to us. */
3165 if (GET_CODE (cmp0
) == CONST_INT
)
3166 cmp0
= force_reg (mode
, cmp0
);
3168 if (GET_CODE (cmp1
) == CONST_INT
)
3170 HOST_WIDE_INT value
= INTVAL (cmp1
);
3172 if (value
< p_info
->const_low
3173 || value
> p_info
->const_high
3174 /* ??? Why? And why wasn't the similar code below modified too? */
3176 && HOST_BITS_PER_WIDE_INT
< 64
3177 && p_info
->const_add
!= 0
3178 && ((p_info
->unsignedp
3179 ? ((unsigned HOST_WIDE_INT
) (value
+ p_info
->const_add
)
3180 > (unsigned HOST_WIDE_INT
) INTVAL (cmp1
))
3181 : (value
+ p_info
->const_add
) > INTVAL (cmp1
))
3182 != (p_info
->const_add
> 0))))
3183 cmp1
= force_reg (mode
, cmp1
);
3186 /* See if we need to invert the result. */
3187 invert
= (GET_CODE (cmp1
) == CONST_INT
3188 ? p_info
->invert_const
: p_info
->invert_reg
);
3190 if (p_invert
!= (int *)0)
3196 /* Comparison to constants, may involve adding 1 to change a LT into LE.
3197 Comparison between two registers, may involve switching operands. */
3198 if (GET_CODE (cmp1
) == CONST_INT
)
3200 if (p_info
->const_add
!= 0)
3202 HOST_WIDE_INT
new = INTVAL (cmp1
) + p_info
->const_add
;
3204 /* If modification of cmp1 caused overflow,
3205 we would get the wrong answer if we follow the usual path;
3206 thus, x > 0xffffffffU would turn into x > 0U. */
3207 if ((p_info
->unsignedp
3208 ? (unsigned HOST_WIDE_INT
) new >
3209 (unsigned HOST_WIDE_INT
) INTVAL (cmp1
)
3210 : new > INTVAL (cmp1
))
3211 != (p_info
->const_add
> 0))
3213 /* This test is always true, but if INVERT is true then
3214 the result of the test needs to be inverted so 0 should
3215 be returned instead. */
3216 emit_move_insn (result
, invert
? const0_rtx
: const_true_rtx
);
3220 cmp1
= GEN_INT (new);
3224 else if (p_info
->reverse_regs
)
3231 if (test
== ITEST_NE
&& GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0)
3235 reg
= (invert
|| eqne_p
) ? gen_reg_rtx (mode
) : result
;
3236 convert_move (reg
, gen_rtx (p_info
->test_code
, mode
, cmp0
, cmp1
), 0);
3239 if (test
== ITEST_NE
)
3241 if (! TARGET_MIPS16
)
3243 convert_move (result
, gen_rtx (GTU
, mode
, reg
, const0_rtx
), 0);
3244 if (p_invert
!= NULL
)
3250 reg2
= invert
? gen_reg_rtx (mode
) : result
;
3251 convert_move (reg2
, gen_rtx (LTU
, mode
, reg
, const1_rtx
), 0);
3256 else if (test
== ITEST_EQ
)
3258 reg2
= invert
? gen_reg_rtx (mode
) : result
;
3259 convert_move (reg2
, gen_rtx_LTU (mode
, reg
, const1_rtx
), 0);
3267 if (! TARGET_MIPS16
)
3271 /* The value is in $24. Copy it to another register, so
3272 that reload doesn't think it needs to store the $24 and
3273 the input to the XOR in the same location. */
3274 reg2
= gen_reg_rtx (mode
);
3275 emit_move_insn (reg2
, reg
);
3277 one
= force_reg (mode
, const1_rtx
);
3279 convert_move (result
, gen_rtx (XOR
, mode
, reg
, one
), 0);
3285 /* Emit the common code for doing conditional branches.
3286 operand[0] is the label to jump to.
3287 The comparison operands are saved away by cmp{si,di,sf,df}. */
3290 gen_conditional_branch (operands
, test_code
)
3292 enum rtx_code test_code
;
3294 enum cmp_type type
= branch_type
;
3295 rtx cmp0
= branch_cmp
[0];
3296 rtx cmp1
= branch_cmp
[1];
3297 enum machine_mode mode
;
3306 mode
= type
== CMP_SI
? SImode
: DImode
;
3308 reg
= gen_int_relational (test_code
, NULL_RTX
, cmp0
, cmp1
, &invert
);
3316 else if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) != 0)
3317 /* We don't want to build a comparison against a non-zero
3319 cmp1
= force_reg (mode
, cmp1
);
3326 reg
= gen_rtx_REG (CCmode
, FPSW_REGNUM
);
3328 reg
= gen_reg_rtx (CCmode
);
3330 /* For cmp0 != cmp1, build cmp0 == cmp1, and test for result ==
3331 0 in the instruction built below. The MIPS FPU handles
3332 inequality testing by testing for equality and looking for a
3334 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
3335 gen_rtx (test_code
== NE
? EQ
: test_code
,
3336 CCmode
, cmp0
, cmp1
)));
3338 test_code
= test_code
== NE
? EQ
: NE
;
3346 abort_with_insn (gen_rtx (test_code
, VOIDmode
, cmp0
, cmp1
), "bad test");
3349 /* Generate the branch. */
3351 label1
= gen_rtx_LABEL_REF (VOIDmode
, operands
[0]);
3360 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
,
3361 gen_rtx_IF_THEN_ELSE (VOIDmode
,
3362 gen_rtx (test_code
, mode
,
3367 /* Emit the common code for conditional moves. OPERANDS is the array
3368 of operands passed to the conditional move defined_expand. */
3371 gen_conditional_move (operands
)
3374 rtx op0
= branch_cmp
[0];
3375 rtx op1
= branch_cmp
[1];
3376 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3377 enum rtx_code cmp_code
= GET_CODE (operands
[1]);
3378 enum rtx_code move_code
= NE
;
3379 enum machine_mode op_mode
= GET_MODE (operands
[0]);
3380 enum machine_mode cmp_mode
;
3383 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
3402 op0
= force_reg (mode
, branch_cmp
[1]);
3403 op1
= branch_cmp
[0];
3407 op0
= force_reg (mode
, branch_cmp
[1]);
3408 op1
= branch_cmp
[0];
3419 op0
= force_reg (mode
, branch_cmp
[1]);
3420 op1
= branch_cmp
[0];
3424 op0
= force_reg (mode
, branch_cmp
[1]);
3425 op1
= branch_cmp
[0];
3432 else if (cmp_code
== NE
)
3433 cmp_code
= EQ
, move_code
= EQ
;
3435 if (mode
== SImode
|| mode
== DImode
)
3437 else if (mode
== SFmode
|| mode
== DFmode
)
3442 cmp_reg
= gen_reg_rtx (cmp_mode
);
3443 emit_insn (gen_rtx_SET (cmp_mode
, cmp_reg
,
3444 gen_rtx (cmp_code
, cmp_mode
, op0
, op1
)));
3446 emit_insn (gen_rtx_SET (op_mode
, operands
[0],
3447 gen_rtx_IF_THEN_ELSE (op_mode
,
3448 gen_rtx (move_code
, VOIDmode
,
3450 CONST0_RTX (SImode
)),
3451 operands
[2], operands
[3])));
3454 /* Emit the common code for conditional moves. OPERANDS is the array
3455 of operands passed to the conditional move defined_expand. */
3458 mips_gen_conditional_trap (operands
)
3462 enum rtx_code cmp_code
= GET_CODE (operands
[0]);
3463 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3465 /* MIPS conditional trap machine instructions don't have GT or LE
3466 flavors, so we must invert the comparison and convert to LT and
3467 GE, respectively. */
3470 case GT
: cmp_code
= LT
; break;
3471 case LE
: cmp_code
= GE
; break;
3472 case GTU
: cmp_code
= LTU
; break;
3473 case LEU
: cmp_code
= GEU
; break;
3476 if (cmp_code
== GET_CODE (operands
[0]))
3478 op0
= force_reg (mode
, branch_cmp
[0]);
3479 op1
= branch_cmp
[1];
3483 op0
= force_reg (mode
, branch_cmp
[1]);
3484 op1
= branch_cmp
[0];
3486 if (GET_CODE (op1
) == CONST_INT
&& ! SMALL_INT (op1
))
3487 op1
= force_reg (mode
, op1
);
3489 emit_insn (gen_rtx_TRAP_IF (VOIDmode
,
3490 gen_rtx (cmp_code
, GET_MODE (operands
[0]), op0
, op1
),
3494 /* Write a loop to move a constant number of bytes.
3495 Generate load/stores as follows:
3501 temp<last> = src[MAX_MOVE_REGS-1];
3505 dest[MAX_MOVE_REGS-1] = temp<last>;
3506 src += MAX_MOVE_REGS;
3507 dest += MAX_MOVE_REGS;
3508 } while (src != final);
3510 This way, no NOP's are needed, and only MAX_MOVE_REGS+3 temp
3511 registers are needed.
3513 Aligned moves move MAX_MOVE_REGS*4 bytes every (2*MAX_MOVE_REGS)+3
3514 cycles, unaligned moves move MAX_MOVE_REGS*4 bytes every
3515 (4*MAX_MOVE_REGS)+3 cycles, assuming no cache misses. */
3517 #define MAX_MOVE_REGS 4
3518 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3521 block_move_loop (dest_reg
, src_reg
, bytes
, align
, orig_dest
, orig_src
)
3522 rtx dest_reg
; /* register holding destination address */
3523 rtx src_reg
; /* register holding source address */
3524 unsigned int bytes
; /* # bytes to move */
3525 int align
; /* alignment */
3526 rtx orig_dest
; /* original dest */
3527 rtx orig_src
; /* original source for making a reg note */
3529 rtx dest_mem
= replace_equiv_address (orig_dest
, dest_reg
);
3530 rtx src_mem
= replace_equiv_address (orig_src
, src_reg
);
3531 rtx align_rtx
= GEN_INT (align
);
3537 if (bytes
< (unsigned)2 * MAX_MOVE_BYTES
)
3540 leftover
= bytes
% MAX_MOVE_BYTES
;
3543 label
= gen_label_rtx ();
3544 final_src
= gen_reg_rtx (Pmode
);
3545 bytes_rtx
= GEN_INT (bytes
);
3549 if (Pmode
== DImode
)
3551 emit_insn (gen_movdi (final_src
, bytes_rtx
));
3552 emit_insn (gen_adddi3 (final_src
, final_src
, src_reg
));
3556 emit_insn (gen_movsi (final_src
, bytes_rtx
));
3557 emit_insn (gen_addsi3 (final_src
, final_src
, src_reg
));
3562 if (Pmode
== DImode
)
3563 emit_insn (gen_adddi3 (final_src
, src_reg
, bytes_rtx
));
3565 emit_insn (gen_addsi3 (final_src
, src_reg
, bytes_rtx
));
3570 bytes_rtx
= GEN_INT (MAX_MOVE_BYTES
);
3571 emit_insn (gen_movstrsi_internal (dest_mem
, src_mem
, bytes_rtx
, align_rtx
));
3573 if (Pmode
== DImode
)
3575 emit_insn (gen_adddi3 (src_reg
, src_reg
, bytes_rtx
));
3576 emit_insn (gen_adddi3 (dest_reg
, dest_reg
, bytes_rtx
));
3577 emit_insn (gen_cmpdi (src_reg
, final_src
));
3581 emit_insn (gen_addsi3 (src_reg
, src_reg
, bytes_rtx
));
3582 emit_insn (gen_addsi3 (dest_reg
, dest_reg
, bytes_rtx
));
3583 emit_insn (gen_cmpsi (src_reg
, final_src
));
3586 emit_jump_insn (gen_bne (label
));
3589 emit_insn (gen_movstrsi_internal (dest_mem
, src_mem
, GEN_INT (leftover
),
3593 /* Use a library function to move some bytes. */
3596 block_move_call (dest_reg
, src_reg
, bytes_rtx
)
3601 /* We want to pass the size as Pmode, which will normally be SImode
3602 but will be DImode if we are using 64 bit longs and pointers. */
3603 if (GET_MODE (bytes_rtx
) != VOIDmode
3604 && GET_MODE (bytes_rtx
) != (unsigned) Pmode
)
3605 bytes_rtx
= convert_to_mode (Pmode
, bytes_rtx
, 1);
3607 #ifdef TARGET_MEM_FUNCTIONS
3608 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "memcpy"), 0,
3609 VOIDmode
, 3, dest_reg
, Pmode
, src_reg
, Pmode
,
3610 convert_to_mode (TYPE_MODE (sizetype
), bytes_rtx
,
3611 TREE_UNSIGNED (sizetype
)),
3612 TYPE_MODE (sizetype
));
3614 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "bcopy"), 0,
3615 VOIDmode
, 3, src_reg
, Pmode
, dest_reg
, Pmode
,
3616 convert_to_mode (TYPE_MODE (integer_type_node
), bytes_rtx
,
3617 TREE_UNSIGNED (integer_type_node
)),
3618 TYPE_MODE (integer_type_node
));
3622 /* Expand string/block move operations.
3624 operands[0] is the pointer to the destination.
3625 operands[1] is the pointer to the source.
3626 operands[2] is the number of bytes to move.
3627 operands[3] is the alignment. */
3630 expand_block_move (operands
)
3633 rtx bytes_rtx
= operands
[2];
3634 rtx align_rtx
= operands
[3];
3635 int constp
= GET_CODE (bytes_rtx
) == CONST_INT
;
3636 unsigned HOST_WIDE_INT bytes
= constp
? INTVAL (bytes_rtx
) : 0;
3637 unsigned int align
= INTVAL (align_rtx
);
3638 rtx orig_src
= operands
[1];
3639 rtx orig_dest
= operands
[0];
3643 if (constp
&& bytes
== 0)
3646 if (align
> (unsigned) UNITS_PER_WORD
)
3647 align
= UNITS_PER_WORD
;
3649 /* Move the address into scratch registers. */
3650 dest_reg
= copy_addr_to_reg (XEXP (orig_dest
, 0));
3651 src_reg
= copy_addr_to_reg (XEXP (orig_src
, 0));
3654 block_move_call (dest_reg
, src_reg
, bytes_rtx
);
3656 else if (constp
&& bytes
<= (unsigned)2 * MAX_MOVE_BYTES
3657 && align
== (unsigned) UNITS_PER_WORD
)
3658 move_by_pieces (orig_dest
, orig_src
, bytes
, align
* BITS_PER_WORD
);
3660 else if (constp
&& bytes
<= (unsigned)2 * MAX_MOVE_BYTES
)
3661 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest
,
3663 replace_equiv_address (orig_src
,
3665 bytes_rtx
, align_rtx
));
3667 else if (constp
&& align
>= (unsigned) UNITS_PER_WORD
&& optimize
)
3668 block_move_loop (dest_reg
, src_reg
, bytes
, align
, orig_dest
, orig_src
);
3670 else if (constp
&& optimize
)
3672 /* If the alignment is not word aligned, generate a test at
3673 runtime, to see whether things wound up aligned, and we
3674 can use the faster lw/sw instead ulw/usw. */
3676 rtx temp
= gen_reg_rtx (Pmode
);
3677 rtx aligned_label
= gen_label_rtx ();
3678 rtx join_label
= gen_label_rtx ();
3679 int leftover
= bytes
% MAX_MOVE_BYTES
;
3683 if (Pmode
== DImode
)
3685 emit_insn (gen_iordi3 (temp
, src_reg
, dest_reg
));
3686 emit_insn (gen_anddi3 (temp
, temp
, GEN_INT (UNITS_PER_WORD
- 1)));
3687 emit_insn (gen_cmpdi (temp
, const0_rtx
));
3691 emit_insn (gen_iorsi3 (temp
, src_reg
, dest_reg
));
3692 emit_insn (gen_andsi3 (temp
, temp
, GEN_INT (UNITS_PER_WORD
- 1)));
3693 emit_insn (gen_cmpsi (temp
, const0_rtx
));
3696 emit_jump_insn (gen_beq (aligned_label
));
3698 /* Unaligned loop. */
3699 block_move_loop (dest_reg
, src_reg
, bytes
, 1, orig_dest
, orig_src
);
3700 emit_jump_insn (gen_jump (join_label
));
3704 emit_label (aligned_label
);
3705 block_move_loop (dest_reg
, src_reg
, bytes
, UNITS_PER_WORD
, orig_dest
,
3707 emit_label (join_label
);
3709 /* Bytes at the end of the loop. */
3711 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest
,
3713 replace_equiv_address (orig_src
,
3720 block_move_call (dest_reg
, src_reg
, bytes_rtx
);
3723 /* Emit load/stores for a small constant block_move.
3725 operands[0] is the memory address of the destination.
3726 operands[1] is the memory address of the source.
3727 operands[2] is the number of bytes to move.
3728 operands[3] is the alignment.
3729 operands[4] is a temp register.
3730 operands[5] is a temp register.
3732 operands[3+num_regs] is the last temp register.
3734 The block move type can be one of the following:
3735 BLOCK_MOVE_NORMAL Do all of the block move.
3736 BLOCK_MOVE_NOT_LAST Do all but the last store.
3737 BLOCK_MOVE_LAST Do just the last store. */
3740 output_block_move (insn
, operands
, num_regs
, move_type
)
3744 enum block_move_type move_type
;
3746 rtx dest_reg
= XEXP (operands
[0], 0);
3747 rtx src_reg
= XEXP (operands
[1], 0);
3748 HOST_WIDE_INT bytes
= INTVAL (operands
[2]);
3749 int align
= INTVAL (operands
[3]);
3752 int use_lwl_lwr
= 0;
3753 int last_operand
= num_regs
+ 4;
3759 const char *load
; /* load insn without nop */
3760 const char *load_nop
; /* load insn with trailing nop */
3761 const char *store
; /* store insn */
3762 const char *final
; /* if last_store used: NULL or swr */
3763 const char *last_store
; /* last store instruction */
3764 int offset
; /* current offset */
3765 enum machine_mode mode
; /* mode to use on (MEM) */
3768 /* ??? Detect a bug in GCC, where it can give us a register
3769 the same as one of the addressing registers and reduce
3770 the number of registers available. */
3771 for (i
= 4; i
< last_operand
&& safe_regs
< (int) ARRAY_SIZE (xoperands
); i
++)
3772 if (! reg_mentioned_p (operands
[i
], operands
[0])
3773 && ! reg_mentioned_p (operands
[i
], operands
[1]))
3774 xoperands
[safe_regs
++] = operands
[i
];
3776 if (safe_regs
< last_operand
)
3778 xoperands
[0] = operands
[0];
3779 xoperands
[1] = operands
[1];
3780 xoperands
[2] = operands
[2];
3781 xoperands
[3] = operands
[3];
3782 return output_block_move (insn
, xoperands
, safe_regs
- 4, move_type
);
3785 /* If we are given global or static addresses, and we would be
3786 emitting a few instructions, try to save time by using a
3787 temporary register for the pointer. */
3788 /* ??? The SGI Irix6 assembler fails when a SYMBOL_REF is used in
3789 an ldl/ldr instruction pair. We play it safe, and always move
3790 constant addresses into registers when generating N32/N64 code, just
3791 in case we might emit an unaligned load instruction. */
3792 if (num_regs
> 2 && (bytes
> 2 * align
|| move_type
!= BLOCK_MOVE_NORMAL
3793 || mips_abi
== ABI_MEABI
3794 || mips_abi
== ABI_N32
3795 || mips_abi
== ABI_64
))
3797 if (CONSTANT_P (src_reg
))
3800 mips_count_memory_refs (operands
[1], 1);
3802 src_reg
= operands
[3 + num_regs
--];
3803 if (move_type
!= BLOCK_MOVE_LAST
)
3805 xoperands
[1] = operands
[1];
3806 xoperands
[0] = src_reg
;
3807 if (Pmode
== DImode
)
3808 output_asm_insn ("dla\t%0,%1", xoperands
);
3810 output_asm_insn ("la\t%0,%1", xoperands
);
3814 if (CONSTANT_P (dest_reg
))
3817 mips_count_memory_refs (operands
[0], 1);
3819 dest_reg
= operands
[3 + num_regs
--];
3820 if (move_type
!= BLOCK_MOVE_LAST
)
3822 xoperands
[1] = operands
[0];
3823 xoperands
[0] = dest_reg
;
3824 if (Pmode
== DImode
)
3825 output_asm_insn ("dla\t%0,%1", xoperands
);
3827 output_asm_insn ("la\t%0,%1", xoperands
);
3832 /* ??? We really shouldn't get any LO_SUM addresses here, because they
3833 are not offsettable, however, offsettable_address_p says they are
3834 offsettable. I think this is a bug in offsettable_address_p.
3835 For expediency, we fix this by just loading the address into a register
3836 if we happen to get one. */
3838 if (GET_CODE (src_reg
) == LO_SUM
)
3840 src_reg
= operands
[3 + num_regs
--];
3841 if (move_type
!= BLOCK_MOVE_LAST
)
3843 xoperands
[2] = XEXP (XEXP (operands
[1], 0), 1);
3844 xoperands
[1] = XEXP (XEXP (operands
[1], 0), 0);
3845 xoperands
[0] = src_reg
;
3846 if (Pmode
== DImode
)
3847 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands
);
3849 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands
);
3853 if (GET_CODE (dest_reg
) == LO_SUM
)
3855 dest_reg
= operands
[3 + num_regs
--];
3856 if (move_type
!= BLOCK_MOVE_LAST
)
3858 xoperands
[2] = XEXP (XEXP (operands
[0], 0), 1);
3859 xoperands
[1] = XEXP (XEXP (operands
[0], 0), 0);
3860 xoperands
[0] = dest_reg
;
3861 if (Pmode
== DImode
)
3862 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands
);
3864 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands
);
3868 if (num_regs
> (int) ARRAY_SIZE (load_store
))
3869 num_regs
= ARRAY_SIZE (load_store
);
3871 else if (num_regs
< 1)
3872 abort_with_insn (insn
,
3873 "cannot do block move, not enough scratch registers");
3877 load_store
[num
].offset
= offset
;
3879 if (TARGET_64BIT
&& bytes
>= 8 && align
>= 8)
3881 load_store
[num
].load
= "ld\t%0,%1";
3882 load_store
[num
].load_nop
= "ld\t%0,%1%#";
3883 load_store
[num
].store
= "sd\t%0,%1";
3884 load_store
[num
].last_store
= "sd\t%0,%1";
3885 load_store
[num
].final
= 0;
3886 load_store
[num
].mode
= DImode
;
3891 /* ??? Fails because of a MIPS assembler bug? */
3892 else if (TARGET_64BIT
&& bytes
>= 8 && ! TARGET_MIPS16
)
3894 if (BYTES_BIG_ENDIAN
)
3896 load_store
[num
].load
= "ldl\t%0,%1\n\tldr\t%0,%2";
3897 load_store
[num
].load_nop
= "ldl\t%0,%1\n\tldr\t%0,%2%#";
3898 load_store
[num
].store
= "sdl\t%0,%1\n\tsdr\t%0,%2";
3899 load_store
[num
].last_store
= "sdr\t%0,%2";
3900 load_store
[num
].final
= "sdl\t%0,%1";
3904 load_store
[num
].load
= "ldl\t%0,%2\n\tldr\t%0,%1";
3905 load_store
[num
].load_nop
= "ldl\t%0,%2\n\tldr\t%0,%1%#";
3906 load_store
[num
].store
= "sdl\t%0,%2\n\tsdr\t%0,%1";
3907 load_store
[num
].last_store
= "sdr\t%0,%1";
3908 load_store
[num
].final
= "sdl\t%0,%2";
3911 load_store
[num
].mode
= DImode
;
3917 else if (bytes
>= 4 && align
>= 4)
3919 load_store
[num
].load
= "lw\t%0,%1";
3920 load_store
[num
].load_nop
= "lw\t%0,%1%#";
3921 load_store
[num
].store
= "sw\t%0,%1";
3922 load_store
[num
].last_store
= "sw\t%0,%1";
3923 load_store
[num
].final
= 0;
3924 load_store
[num
].mode
= SImode
;
3929 else if (bytes
>= 4 && ! TARGET_MIPS16
)
3931 if (BYTES_BIG_ENDIAN
)
3933 load_store
[num
].load
= "lwl\t%0,%1\n\tlwr\t%0,%2";
3934 load_store
[num
].load_nop
= "lwl\t%0,%1\n\tlwr\t%0,%2%#";
3935 load_store
[num
].store
= "swl\t%0,%1\n\tswr\t%0,%2";
3936 load_store
[num
].last_store
= "swr\t%0,%2";
3937 load_store
[num
].final
= "swl\t%0,%1";
3941 load_store
[num
].load
= "lwl\t%0,%2\n\tlwr\t%0,%1";
3942 load_store
[num
].load_nop
= "lwl\t%0,%2\n\tlwr\t%0,%1%#";
3943 load_store
[num
].store
= "swl\t%0,%2\n\tswr\t%0,%1";
3944 load_store
[num
].last_store
= "swr\t%0,%1";
3945 load_store
[num
].final
= "swl\t%0,%2";
3948 load_store
[num
].mode
= SImode
;
3954 else if (bytes
>= 2 && align
>= 2)
3956 load_store
[num
].load
= "lh\t%0,%1";
3957 load_store
[num
].load_nop
= "lh\t%0,%1%#";
3958 load_store
[num
].store
= "sh\t%0,%1";
3959 load_store
[num
].last_store
= "sh\t%0,%1";
3960 load_store
[num
].final
= 0;
3961 load_store
[num
].mode
= HImode
;
3967 load_store
[num
].load
= "lb\t%0,%1";
3968 load_store
[num
].load_nop
= "lb\t%0,%1%#";
3969 load_store
[num
].store
= "sb\t%0,%1";
3970 load_store
[num
].last_store
= "sb\t%0,%1";
3971 load_store
[num
].final
= 0;
3972 load_store
[num
].mode
= QImode
;
3977 if (TARGET_STATS
&& move_type
!= BLOCK_MOVE_LAST
)
3979 dslots_load_total
++;
3980 dslots_load_filled
++;
3982 if (CONSTANT_P (src_reg
))
3983 mips_count_memory_refs (src_reg
, 1);
3985 if (CONSTANT_P (dest_reg
))
3986 mips_count_memory_refs (dest_reg
, 1);
3989 /* Emit load/stores now if we have run out of registers or are
3990 at the end of the move. */
3992 if (++num
== num_regs
|| bytes
== 0)
3994 /* If only load/store, we need a NOP after the load. */
3997 load_store
[0].load
= load_store
[0].load_nop
;
3998 if (TARGET_STATS
&& move_type
!= BLOCK_MOVE_LAST
)
3999 dslots_load_filled
--;
4002 if (move_type
!= BLOCK_MOVE_LAST
)
4004 for (i
= 0; i
< num
; i
++)
4008 if (!operands
[i
+ 4])
4011 if (GET_MODE (operands
[i
+ 4]) != load_store
[i
].mode
)
4012 operands
[i
+ 4] = gen_rtx_REG (load_store
[i
].mode
,
4013 REGNO (operands
[i
+ 4]));
4015 offset
= load_store
[i
].offset
;
4016 xoperands
[0] = operands
[i
+ 4];
4017 xoperands
[1] = gen_rtx_MEM (load_store
[i
].mode
,
4018 plus_constant (src_reg
, offset
));
4023 = GET_MODE_SIZE (load_store
[i
].mode
) - 1;
4025 xoperands
[2] = gen_rtx_MEM (load_store
[i
].mode
,
4026 plus_constant (src_reg
,
4031 output_asm_insn (load_store
[i
].load
, xoperands
);
4035 for (i
= 0; i
< num
; i
++)
4037 int last_p
= (i
== num
-1 && bytes
== 0);
4038 int offset
= load_store
[i
].offset
;
4040 xoperands
[0] = operands
[i
+ 4];
4041 xoperands
[1] = gen_rtx_MEM (load_store
[i
].mode
,
4042 plus_constant (dest_reg
, offset
));
4047 int extra_offset
= GET_MODE_SIZE (load_store
[i
].mode
) - 1;
4048 xoperands
[2] = gen_rtx_MEM (load_store
[i
].mode
,
4049 plus_constant (dest_reg
,
4054 if (move_type
== BLOCK_MOVE_NORMAL
)
4055 output_asm_insn (load_store
[i
].store
, xoperands
);
4057 else if (move_type
== BLOCK_MOVE_NOT_LAST
)
4060 output_asm_insn (load_store
[i
].store
, xoperands
);
4062 else if (load_store
[i
].final
!= 0)
4063 output_asm_insn (load_store
[i
].final
, xoperands
);
4067 output_asm_insn (load_store
[i
].last_store
, xoperands
);
4070 num
= 0; /* reset load_store */
4078 /* Argument support functions. */
4080 /* Initialize CUMULATIVE_ARGS for a function. */
4083 init_cumulative_args (cum
, fntype
, libname
)
4084 CUMULATIVE_ARGS
*cum
; /* argument info to initialize */
4085 tree fntype
; /* tree ptr for function decl */
4086 rtx libname ATTRIBUTE_UNUSED
; /* SYMBOL_REF of library name or 0 */
4088 static CUMULATIVE_ARGS zero_cum
;
4089 tree param
, next_param
;
4091 if (TARGET_DEBUG_E_MODE
)
4094 "\ninit_cumulative_args, fntype = 0x%.8lx", (long)fntype
);
4097 fputc ('\n', stderr
);
4101 tree ret_type
= TREE_TYPE (fntype
);
4102 fprintf (stderr
, ", fntype code = %s, ret code = %s\n",
4103 tree_code_name
[(int)TREE_CODE (fntype
)],
4104 tree_code_name
[(int)TREE_CODE (ret_type
)]);
4109 cum
->prototype
= (fntype
&& TYPE_ARG_TYPES (fntype
));
4111 /* Determine if this function has variable arguments. This is
4112 indicated by the last argument being 'void_type_mode' if there
4113 are no variable arguments. The standard MIPS calling sequence
4114 passes all arguments in the general purpose registers in this case. */
4116 for (param
= fntype
? TYPE_ARG_TYPES (fntype
) : 0;
4117 param
!= 0; param
= next_param
)
4119 next_param
= TREE_CHAIN (param
);
4120 if (next_param
== 0 && TREE_VALUE (param
) != void_type_node
)
4121 cum
->gp_reg_found
= 1;
4126 mips_arg_info (cum
, mode
, type
, named
, info
)
4127 const CUMULATIVE_ARGS
*cum
;
4128 enum machine_mode mode
;
4131 struct mips_arg_info
*info
;
4134 unsigned int num_words
, max_regs
;
4136 info
->struct_p
= (type
!= 0
4137 && (TREE_CODE (type
) == RECORD_TYPE
4138 || TREE_CODE (type
) == UNION_TYPE
4139 || TREE_CODE (type
) == QUAL_UNION_TYPE
));
4141 /* Decide whether this argument should go in a floating-point register,
4142 assuming one is free. Later code checks for availablity. */
4144 info
->fpr_p
= false;
4145 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
4146 && GET_MODE_SIZE (mode
) <= UNITS_PER_FPVALUE
)
4152 info
->fpr_p
= (!cum
->gp_reg_found
&& cum
->arg_number
< 2);
4160 /* The MIPS eabi says only structures containing doubles get
4161 passed in a fp register, so force a structure containing
4162 a float to be passed in the integer registers. */
4163 info
->fpr_p
= (named
&& !(mode
== SFmode
&& info
->struct_p
));
4167 info
->fpr_p
= named
;
4172 /* Now decide whether the argument must go in an even-numbered register. */
4177 /* Under the O64 ABI, the second float argument goes in $f13 if it
4178 is a double, but $f14 if it is a single. Otherwise, on a
4179 32-bit double-float machine, each FP argument must start in a
4180 new register pair. */
4181 even_reg_p
= ((mips_abi
== ABI_O64
&& mode
== SFmode
) || FP_INC
> 1);
4183 else if (!TARGET_64BIT
)
4185 if (GET_MODE_CLASS (mode
) == MODE_INT
4186 || GET_MODE_CLASS (mode
) == MODE_FLOAT
)
4187 even_reg_p
= (GET_MODE_SIZE (mode
) > UNITS_PER_WORD
);
4189 else if (type
!= NULL_TREE
&& TYPE_ALIGN (type
) > BITS_PER_WORD
)
4193 /* Set REG_OFFSET to the register count we're interested in.
4194 The EABI allocates the floating-point registers separately,
4195 but the other ABIs allocate them like integer registers. */
4196 info
->reg_offset
= (mips_abi
== ABI_EABI
&& info
->fpr_p
4201 info
->reg_offset
+= info
->reg_offset
& 1;
4203 /* The alignment applied to registers is also applied to stack arguments. */
4204 info
->stack_offset
= cum
->stack_words
;
4206 info
->stack_offset
+= info
->stack_offset
& 1;
4208 if (mode
== BLKmode
)
4209 info
->num_bytes
= int_size_in_bytes (type
);
4211 info
->num_bytes
= GET_MODE_SIZE (mode
);
4213 num_words
= (info
->num_bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
4214 max_regs
= MAX_ARGS_IN_REGISTERS
- info
->reg_offset
;
4216 /* Partition the argument between registers and stack. */
4217 info
->reg_words
= MIN (num_words
, max_regs
);
4218 info
->stack_words
= num_words
- info
->reg_words
;
4222 /* Advance the argument to the next argument position. */
4225 function_arg_advance (cum
, mode
, type
, named
)
4226 CUMULATIVE_ARGS
*cum
; /* current arg information */
4227 enum machine_mode mode
; /* current arg mode */
4228 tree type
; /* type of the argument or 0 if lib support */
4229 int named
; /* whether or not the argument was named */
4231 struct mips_arg_info info
;
4233 mips_arg_info (cum
, mode
, type
, named
, &info
);
4235 /* The following is a hack in order to pass 1 byte structures
4236 the same way that the MIPS compiler does (namely by passing
4237 the structure in the high byte or half word of the register).
4238 This also makes varargs work. If we have such a structure,
4239 we save the adjustment RTL, and the call define expands will
4240 emit them. For the VOIDmode argument (argument after the
4241 last real argument), pass back a parallel vector holding each
4242 of the adjustments. */
4244 /* ??? This scheme requires everything smaller than the word size to
4245 shifted to the left, but when TARGET_64BIT and ! TARGET_INT64,
4246 that would mean every int needs to be shifted left, which is very
4247 inefficient. Let's not carry this compatibility to the 64 bit
4248 calling convention for now. */
4251 && info
.reg_words
== 1
4252 && info
.num_bytes
< UNITS_PER_WORD
4254 && mips_abi
!= ABI_EABI
4255 && mips_abi
!= ABI_MEABI
)
4257 rtx amount
= GEN_INT (BITS_PER_WORD
- info
.num_bytes
* BITS_PER_UNIT
);
4258 rtx reg
= gen_rtx_REG (word_mode
, GP_ARG_FIRST
+ info
.reg_offset
);
4261 cum
->adjust
[cum
->num_adjusts
++] = gen_ashldi3 (reg
, reg
, amount
);
4263 cum
->adjust
[cum
->num_adjusts
++] = gen_ashlsi3 (reg
, reg
, amount
);
4267 cum
->gp_reg_found
= true;
4269 /* See the comment above the cumulative args structure in mips.h
4270 for an explanation of what this code does. It assumes the O32
4271 ABI, which passes at most 2 arguments in float registers. */
4272 if (cum
->arg_number
< 2 && info
.fpr_p
)
4273 cum
->fp_code
+= (mode
== SFmode
? 1 : 2) << ((cum
->arg_number
- 1) * 2);
4275 if (mips_abi
!= ABI_EABI
|| !info
.fpr_p
)
4276 cum
->num_gprs
= info
.reg_offset
+ info
.reg_words
;
4277 else if (info
.reg_words
> 0)
4278 cum
->num_fprs
+= FP_INC
;
4280 if (info
.stack_words
> 0)
4281 cum
->stack_words
= info
.stack_offset
+ info
.stack_words
;
4286 /* Return an RTL expression containing the register for the given mode,
4287 or 0 if the argument is to be passed on the stack. */
4290 function_arg (cum
, mode
, type
, named
)
4291 const CUMULATIVE_ARGS
*cum
; /* current arg information */
4292 enum machine_mode mode
; /* current arg mode */
4293 tree type
; /* type of the argument or 0 if lib support */
4294 int named
; /* != 0 for normal args, == 0 for ... args */
4296 struct mips_arg_info info
;
4298 /* We will be called with a mode of VOIDmode after the last argument
4299 has been seen. Whatever we return will be passed to the call
4300 insn. If we need any shifts for small structures, return them in
4301 a PARALLEL; in that case, stuff the mips16 fp_code in as the
4302 mode. Otherwise, if we need a mips16 fp_code, return a REG
4303 with the code stored as the mode. */
4304 if (mode
== VOIDmode
)
4306 if (cum
->num_adjusts
> 0)
4307 return gen_rtx_PARALLEL ((enum machine_mode
) cum
->fp_code
,
4308 gen_rtvec_v (cum
->num_adjusts
,
4309 (rtx
*) cum
->adjust
));
4311 else if (TARGET_MIPS16
&& cum
->fp_code
!= 0)
4312 return gen_rtx_REG ((enum machine_mode
) cum
->fp_code
, 0);
4318 mips_arg_info (cum
, mode
, type
, named
, &info
);
4320 /* Return straight away if the whole argument is passed on the stack. */
4321 if (info
.reg_offset
== MAX_ARGS_IN_REGISTERS
)
4325 && TREE_CODE (type
) == RECORD_TYPE
4326 && (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
)
4327 && TYPE_SIZE_UNIT (type
)
4328 && host_integerp (TYPE_SIZE_UNIT (type
), 1)
4332 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
4333 structure contains a double in its entirety, then that 64 bit
4334 chunk is passed in a floating point register. */
4337 /* First check to see if there is any such field. */
4338 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4339 if (TREE_CODE (field
) == FIELD_DECL
4340 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
4341 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
4342 && host_integerp (bit_position (field
), 0)
4343 && int_bit_position (field
) % BITS_PER_WORD
== 0)
4348 /* Now handle the special case by returning a PARALLEL
4349 indicating where each 64 bit chunk goes. INFO.REG_WORDS
4350 chunks are passed in registers. */
4352 HOST_WIDE_INT bitpos
;
4355 /* assign_parms checks the mode of ENTRY_PARM, so we must
4356 use the actual mode here. */
4357 ret
= gen_rtx_PARALLEL (mode
, rtvec_alloc (info
.reg_words
));
4360 field
= TYPE_FIELDS (type
);
4361 for (i
= 0; i
< info
.reg_words
; i
++)
4365 for (; field
; field
= TREE_CHAIN (field
))
4366 if (TREE_CODE (field
) == FIELD_DECL
4367 && int_bit_position (field
) >= bitpos
)
4371 && int_bit_position (field
) == bitpos
4372 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
4373 && !TARGET_SOFT_FLOAT
4374 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
)
4375 reg
= gen_rtx_REG (DFmode
, FP_ARG_FIRST
+ info
.reg_offset
+ i
);
4377 reg
= gen_rtx_REG (DImode
, GP_ARG_FIRST
+ info
.reg_offset
+ i
);
4380 = gen_rtx_EXPR_LIST (VOIDmode
, reg
,
4381 GEN_INT (bitpos
/ BITS_PER_UNIT
));
4383 bitpos
+= BITS_PER_WORD
;
4389 if (mips_abi
== ABI_MEABI
&& info
.fpr_p
&& !cum
->prototype
)
4391 /* To make K&R varargs work we need to pass floating
4392 point arguments in both integer and FP registers. */
4393 return gen_rtx_PARALLEL
4396 gen_rtx_EXPR_LIST (VOIDmode
,
4401 gen_rtx_EXPR_LIST (VOIDmode
,
4409 return gen_rtx_REG (mode
, FP_ARG_FIRST
+ info
.reg_offset
);
4411 return gen_rtx_REG (mode
, GP_ARG_FIRST
+ info
.reg_offset
);
4415 function_arg_partial_nregs (cum
, mode
, type
, named
)
4416 const CUMULATIVE_ARGS
*cum
; /* current arg information */
4417 enum machine_mode mode
; /* current arg mode */
4418 tree type
; /* type of the argument or 0 if lib support */
4419 int named
; /* != 0 for normal args, == 0 for ... args */
4421 struct mips_arg_info info
;
4423 mips_arg_info (cum
, mode
, type
, named
, &info
);
4424 return info
.stack_words
> 0 ? info
.reg_words
: 0;
4428 mips_setup_incoming_varargs (cum
, mode
, type
, no_rtl
)
4429 const CUMULATIVE_ARGS
*cum
;
4430 enum machine_mode mode
;
4434 CUMULATIVE_ARGS local_cum
;
4435 int gp_saved
, fp_saved
;
4437 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
4440 /* The caller has advanced CUM up to, but not beyond, the last named
4441 argument. Advance a local copy of CUM past the last "real" named
4442 argument, to find out how many registers are left over.
4444 For K&R varargs, the last named argument is a dummy word-sized one,
4445 so CUM already contains the information we need. For stdarg, it is
4446 a real argument (such as the format in printf()) and we need to
4449 if (!current_function_varargs
)
4450 FUNCTION_ARG_ADVANCE (local_cum
, mode
, type
, 1);
4452 /* Found out how many registers we need to save. */
4453 gp_saved
= MAX_ARGS_IN_REGISTERS
- local_cum
.num_gprs
;
4454 fp_saved
= (EABI_FLOAT_VARARGS_P
4455 ? MAX_ARGS_IN_REGISTERS
- local_cum
.num_fprs
4464 ptr
= virtual_incoming_args_rtx
;
4465 if (mips_abi
== ABI_EABI
)
4466 ptr
= plus_constant (ptr
, -gp_saved
* UNITS_PER_WORD
);
4467 mem
= gen_rtx_MEM (BLKmode
, ptr
);
4469 /* va_arg is an array access in this case, which causes
4470 it to get MEM_IN_STRUCT_P set. We must set it here
4471 so that the insn scheduler won't assume that these
4472 stores can't possibly overlap with the va_arg loads. */
4473 if (mips_abi
!= ABI_EABI
&& BYTES_BIG_ENDIAN
)
4474 MEM_SET_IN_STRUCT_P (mem
, 1);
4476 move_block_from_reg (local_cum
.num_gprs
+ GP_ARG_FIRST
, mem
,
4477 gp_saved
, gp_saved
* UNITS_PER_WORD
);
4481 /* We can't use move_block_from_reg, because it will use
4483 enum machine_mode mode
;
4486 /* Set OFF to the offset from virtual_incoming_args_rtx of
4487 the first float register. The FP save area lies below
4488 the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */
4489 off
= -gp_saved
* UNITS_PER_WORD
;
4490 off
&= ~(UNITS_PER_FPVALUE
- 1);
4491 off
-= fp_saved
* UNITS_PER_FPREG
;
4493 mode
= TARGET_SINGLE_FLOAT
? SFmode
: DFmode
;
4495 for (i
= local_cum
.num_fprs
; i
< MAX_ARGS_IN_REGISTERS
; i
+= FP_INC
)
4497 rtx ptr
= plus_constant (virtual_incoming_args_rtx
, off
);
4498 emit_move_insn (gen_rtx_MEM (mode
, ptr
),
4499 gen_rtx_REG (mode
, FP_ARG_FIRST
+ i
));
4500 off
+= UNITS_PER_FPVALUE
;
4504 return (gp_saved
* UNITS_PER_WORD
) + (fp_saved
* UNITS_PER_FPREG
);
4507 /* Create the va_list data type.
4508 We keep 3 pointers, and two offsets.
4509 Two pointers are to the overflow area, which starts at the CFA.
4510 One of these is constant, for addressing into the GPR save area below it.
4511 The other is advanced up the stack through the overflow region.
4512 The third pointer is to the GPR save area. Since the FPR save area
4513 is just below it, we can address FPR slots off this pointer.
4514 We also keep two one-byte offsets, which are to be subtracted from the
4515 constant pointers to yield addresses in the GPR and FPR save areas.
4516 These are downcounted as float or non-float arguments are used,
4517 and when they get to zero, the argument must be obtained from the
4519 If !EABI_FLOAT_VARARGS_P, then no FPR save area exists, and a single
4520 pointer is enough. It's started at the GPR save area, and is
4522 Note that the GPR save area is not constant size, due to optimization
4523 in the prologue. Hence, we can't use a design with two pointers
4524 and two offsets, although we could have designed this with two pointers
4525 and three offsets. */
4529 mips_build_va_list ()
4531 if (EABI_FLOAT_VARARGS_P
)
4533 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
, record
;
4535 record
= make_node (RECORD_TYPE
);
4537 f_ovfl
= build_decl (FIELD_DECL
, get_identifier ("__overflow_argptr"),
4539 f_gtop
= build_decl (FIELD_DECL
, get_identifier ("__gpr_top"),
4541 f_ftop
= build_decl (FIELD_DECL
, get_identifier ("__fpr_top"),
4543 f_goff
= build_decl (FIELD_DECL
, get_identifier ("__gpr_offset"),
4544 unsigned_char_type_node
);
4545 f_foff
= build_decl (FIELD_DECL
, get_identifier ("__fpr_offset"),
4546 unsigned_char_type_node
);
4549 DECL_FIELD_CONTEXT (f_ovfl
) = record
;
4550 DECL_FIELD_CONTEXT (f_gtop
) = record
;
4551 DECL_FIELD_CONTEXT (f_ftop
) = record
;
4552 DECL_FIELD_CONTEXT (f_goff
) = record
;
4553 DECL_FIELD_CONTEXT (f_foff
) = record
;
4555 TYPE_FIELDS (record
) = f_ovfl
;
4556 TREE_CHAIN (f_ovfl
) = f_gtop
;
4557 TREE_CHAIN (f_gtop
) = f_ftop
;
4558 TREE_CHAIN (f_ftop
) = f_goff
;
4559 TREE_CHAIN (f_goff
) = f_foff
;
4561 layout_type (record
);
4565 return ptr_type_node
;
4568 /* Implement va_start. stdarg_p is 0 if implementing
4569 __builtin_varargs_va_start, 1 if implementing __builtin_stdarg_va_start.
4570 Note that this routine isn't called when compiling e.g. "_vfprintf_r".
4571 (It doesn't have "...", so it inherits the pointers of its caller.) */
4574 mips_va_start (stdarg_p
, valist
, nextarg
)
4579 const CUMULATIVE_ARGS
*cum
= ¤t_function_args_info
;
4581 if (mips_abi
== ABI_EABI
)
4583 int gpr_save_area_size
;
4586 = (MAX_ARGS_IN_REGISTERS
- cum
->num_gprs
) * UNITS_PER_WORD
;
4588 if (EABI_FLOAT_VARARGS_P
)
4590 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4591 tree ovfl
, gtop
, ftop
, goff
, foff
;
4594 int fpr_save_area_size
;
4596 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4597 f_gtop
= TREE_CHAIN (f_ovfl
);
4598 f_ftop
= TREE_CHAIN (f_gtop
);
4599 f_goff
= TREE_CHAIN (f_ftop
);
4600 f_foff
= TREE_CHAIN (f_goff
);
4602 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4603 gtop
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4604 ftop
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4605 goff
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4606 foff
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4608 /* Emit code to initialize OVFL, which points to the next varargs
4609 stack argument. CUM->STACK_WORDS gives the number of stack
4610 words used by named arguments. */
4611 t
= make_tree (TREE_TYPE (ovfl
), virtual_incoming_args_rtx
);
4612 if (cum
->stack_words
> 0)
4613 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), t
,
4614 build_int_2 (cum
->stack_words
* UNITS_PER_WORD
, 0));
4615 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4616 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4618 /* Emit code to initialize GTOP, the top of the GPR save area. */
4619 t
= make_tree (TREE_TYPE (gtop
), virtual_incoming_args_rtx
);
4620 t
= build (MODIFY_EXPR
, TREE_TYPE (gtop
), gtop
, t
);
4621 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4623 /* Emit code to initialize FTOP, the top of the FPR save area.
4624 This address is gpr_save_area_bytes below GTOP, rounded
4625 down to the next fp-aligned boundary. */
4626 t
= make_tree (TREE_TYPE (ftop
), virtual_incoming_args_rtx
);
4627 fpr_offset
= gpr_save_area_size
+ UNITS_PER_FPVALUE
- 1;
4628 fpr_offset
&= ~(UNITS_PER_FPVALUE
- 1);
4630 t
= build (PLUS_EXPR
, TREE_TYPE (ftop
), t
,
4631 build_int_2 (-fpr_offset
, -1));
4632 t
= build (MODIFY_EXPR
, TREE_TYPE (ftop
), ftop
, t
);
4633 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4635 /* Emit code to initialize GOFF, the offset from GTOP of the
4636 next GPR argument. */
4637 t
= build (MODIFY_EXPR
, TREE_TYPE (goff
), goff
,
4638 build_int_2 (gpr_save_area_size
, 0));
4639 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4641 /* Likewise emit code to initialize FOFF, the offset from FTOP
4642 of the next FPR argument. */
4644 = (MAX_ARGS_IN_REGISTERS
- cum
->num_fprs
) * UNITS_PER_FPREG
;
4645 t
= build (MODIFY_EXPR
, TREE_TYPE (foff
), foff
,
4646 build_int_2 (fpr_save_area_size
, 0));
4647 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4651 /* Everything is in the GPR save area, or in the overflow
4652 area which is contiguous with it. */
4654 int offset
= -gpr_save_area_size
;
4655 if (gpr_save_area_size
== 0)
4656 offset
= (stdarg_p
? 0 : -UNITS_PER_WORD
);
4657 nextarg
= plus_constant (nextarg
, offset
);
4658 std_expand_builtin_va_start (1, valist
, nextarg
);
4670 /* ??? This had been conditional on
4671 _MIPS_SIM == _MIPS_SIM_ABI64 || _MIPS_SIM == _MIPS_SIM_NABI32
4672 and both iris5.h and iris6.h define _MIPS_SIM. */
4673 if (mips_abi
== ABI_N32
4674 || mips_abi
== ABI_64
4675 || mips_abi
== ABI_MEABI
)
4676 ofs
= (cum
->num_gprs
< MAX_ARGS_IN_REGISTERS
4680 ofs
= -UNITS_PER_WORD
;
4683 nextarg
= plus_constant (nextarg
, ofs
);
4684 std_expand_builtin_va_start (1, valist
, nextarg
);
4688 /* Implement va_arg. */
4691 mips_va_arg (valist
, type
)
4694 HOST_WIDE_INT size
, rsize
;
4698 size
= int_size_in_bytes (type
);
4699 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
4701 if (mips_abi
== ABI_EABI
)
4707 = function_arg_pass_by_reference (NULL
, TYPE_MODE (type
), type
, 0);
4711 size
= POINTER_SIZE
/ BITS_PER_UNIT
;
4712 rsize
= UNITS_PER_WORD
;
4715 addr_rtx
= gen_reg_rtx (Pmode
);
4717 if (!EABI_FLOAT_VARARGS_P
)
4719 /* Case of all args in a merged stack. No need to check bounds,
4720 just advance valist along the stack. */
4725 && TYPE_ALIGN (type
) > (unsigned) BITS_PER_WORD
)
4727 /* Align the pointer using: ap = (ap + align - 1) & -align,
4728 where align is 2 * UNITS_PER_WORD. */
4729 t
= build (PLUS_EXPR
, TREE_TYPE (gpr
), gpr
,
4730 build_int_2 (2 * UNITS_PER_WORD
- 1, 0));
4731 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
,
4732 build_int_2 (-2 * UNITS_PER_WORD
, -1));
4733 t
= build (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
, t
);
4734 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4737 /* Emit code to set addr_rtx to the valist, and postincrement
4738 the valist by the size of the argument, rounded up to the
4740 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (gpr
), gpr
,
4742 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4744 emit_move_insn (addr_rtx
, r
);
4746 /* Flush the POSTINCREMENT. */
4751 /* Not a simple merged stack. */
4753 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4754 tree ovfl
, top
, off
;
4755 rtx lab_over
= NULL_RTX
, lab_false
;
4756 HOST_WIDE_INT osize
;
4758 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4759 f_gtop
= TREE_CHAIN (f_ovfl
);
4760 f_ftop
= TREE_CHAIN (f_gtop
);
4761 f_goff
= TREE_CHAIN (f_ftop
);
4762 f_foff
= TREE_CHAIN (f_goff
);
4764 /* We maintain separate pointers and offsets for floating-point
4765 and integer arguments, but we need similar code in both cases.
4768 TOP be the top of the register save area;
4769 OFF be the offset from TOP of the next register;
4770 ADDR_RTX be the address of the argument; and
4771 RSIZE be the number of bytes used to store the argument
4772 when it's in the register save area
4773 OSIZE be the number of bytes used to store it when it's
4774 in the stack overflow area
4775 PADDING be (BYTES_BIG_ENDIAN ? OSIZE - RSIZE : 0)
4777 The code we want is:
4779 1: off &= -rsize; // round down
4782 4: addr_rtx = top - off;
4787 9: ovfl += ((intptr_t) ovfl + osize - 1) & -osize;
4788 10: addr_rtx = ovfl + PADDING;
4792 [1] and [9] can sometimes be optimized away. */
4794 lab_false
= gen_label_rtx ();
4795 lab_over
= gen_label_rtx ();
4797 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4799 if (TREE_CODE (type
) == REAL_TYPE
)
4801 top
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4802 off
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4804 /* When floating-point registers are saved to the stack,
4805 each one will take up UNITS_PER_FPVALUE bytes, regardless
4806 of the float's precision. */
4807 rsize
= UNITS_PER_FPVALUE
;
4811 top
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4812 off
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4813 if (rsize
> UNITS_PER_WORD
)
4815 /* [1] Emit code for: off &= -rsize. */
4816 t
= build (BIT_AND_EXPR
, TREE_TYPE (off
), off
,
4817 build_int_2 (-rsize
, -1));
4818 t
= build (MODIFY_EXPR
, TREE_TYPE (off
), off
, t
);
4819 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4822 /* Every overflow argument must take up at least UNITS_PER_WORD
4823 bytes (= PARM_BOUNDARY bits). RSIZE can sometimes be smaller
4824 than that, such as in the combination -mgp64 -msingle-float
4825 -fshort-double. Doubles passed in registers will then take
4826 up UNITS_PER_FPVALUE bytes, but those passed on the stack
4827 take up UNITS_PER_WORD bytes. */
4828 osize
= MAX (rsize
, UNITS_PER_WORD
);
4830 /* [2] Emit code to branch if off == 0. */
4831 r
= expand_expr (off
, NULL_RTX
, TYPE_MODE (TREE_TYPE (off
)),
4833 emit_cmp_and_jump_insns (r
, const0_rtx
, EQ
, const1_rtx
, GET_MODE (r
),
4836 /* [4] Emit code for: addr_rtx = top - off. */
4837 t
= build (MINUS_EXPR
, TREE_TYPE (top
), top
, off
);
4838 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4840 emit_move_insn (addr_rtx
, r
);
4842 /* [5] Emit code for: off -= rsize. */
4843 t
= build (MINUS_EXPR
, TREE_TYPE (off
), off
, build_int_2 (rsize
, 0));
4844 t
= build (MODIFY_EXPR
, TREE_TYPE (off
), off
, t
);
4845 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4847 /* [7] Emit code to jump over the else clause, then the label
4850 emit_jump (lab_over
);
4852 emit_label (lab_false
);
4854 if (osize
> UNITS_PER_WORD
)
4856 /* [9] Emit: ovfl += ((intptr_t) ovfl + osize - 1) & -osize. */
4857 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), ovfl
,
4858 build_int_2 (osize
- 1, 0));
4859 t
= build (BIT_AND_EXPR
, TREE_TYPE (ovfl
), t
,
4860 build_int_2 (-osize
, -1));
4861 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4862 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4865 /* [10, 11]. Emit code to store ovfl in addr_rtx, then
4866 post-increment ovfl by osize. On big-endian machines,
4867 the argument has OSIZE - RSIZE bytes of leading padding. */
4868 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (ovfl
), ovfl
,
4870 if (BYTES_BIG_ENDIAN
&& osize
> rsize
)
4871 t
= build (PLUS_EXPR
, TREE_TYPE (t
), t
,
4872 build_int_2 (osize
- rsize
, 0));
4873 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4875 emit_move_insn (addr_rtx
, r
);
4878 emit_label (lab_over
);
4882 addr_rtx
= force_reg (Pmode
, addr_rtx
);
4883 r
= gen_rtx_MEM (Pmode
, addr_rtx
);
4884 set_mem_alias_set (r
, get_varargs_alias_set ());
4885 emit_move_insn (addr_rtx
, r
);
4889 if (BYTES_BIG_ENDIAN
&& rsize
!= size
)
4890 addr_rtx
= plus_constant (addr_rtx
, rsize
- size
);
4899 /* ??? The original va-mips.h did always align, despite the fact
4900 that alignments <= UNITS_PER_WORD are preserved by the va_arg
4901 increment mechanism. */
4905 else if (TYPE_ALIGN (type
) > 32)
4910 t
= build (PLUS_EXPR
, TREE_TYPE (valist
), valist
,
4911 build_int_2 (align
- 1, 0));
4912 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
, build_int_2 (-align
, -1));
4913 t
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
, t
);
4914 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4916 /* Everything past the alignment is standard. */
4917 return std_expand_builtin_va_arg (valist
, type
);
4921 /* Abort after printing out a specific insn. */
4924 abort_with_insn (insn
, reason
)
4933 /* Set up the threshold for data to go into the small data area, instead
4934 of the normal data area, and detect any conflicts in the switches. */
4939 register int i
, start
;
4941 register enum machine_mode mode
;
4942 register enum processor_type mips_cpu
;
4944 mips_section_threshold
= g_switch_set
? g_switch_value
: MIPS_DEFAULT_GVALUE
;
4946 if (mips_section_threshold
<= 0)
4947 target_flags
&= ~MASK_GPOPT
;
4949 target_flags
|= MASK_GPOPT
;
4951 /* If both single-float and soft-float are set, then clear the one that
4952 was set by TARGET_DEFAULT, leaving the one that was set by the
4953 user. We assume here that the specs prevent both being set by the
4955 #ifdef TARGET_DEFAULT
4956 if (TARGET_SINGLE_FLOAT
&& TARGET_SOFT_FLOAT
)
4957 target_flags
&= ~((TARGET_DEFAULT
) & (MASK_SOFT_FLOAT
| MASK_SINGLE_FLOAT
));
4960 /* Get the architectural level. */
4961 if (mips_isa_string
== 0)
4962 mips_isa
= MIPS_ISA_DEFAULT
;
4964 else if (mips_isa_string
!= 0
4965 && mips_arch_string
!= 0)
4966 warning ("The -march option is incompatible to -mipsN and therefore ignored.");
4968 else if (ISDIGIT (*mips_isa_string
))
4970 mips_isa
= atoi (mips_isa_string
);
4973 /* -mno-mips16 overrides -mips16. */
4974 if (mips_no_mips16_string
== NULL
)
4976 target_flags
|= MASK_MIPS16
;
4980 mips_isa
= MIPS_ISA_DEFAULT
;
4984 mips_isa
= MIPS_ISA_DEFAULT
;
4987 else if (mips_isa
< 1
4992 error ("-mips%d not supported", mips_isa
);
4999 error ("bad value (%s) for -mips switch", mips_isa_string
);
5003 #ifdef MIPS_ABI_DEFAULT
5004 /* Get the ABI to use. */
5005 if (mips_abi_string
== (char *) 0)
5006 mips_abi
= MIPS_ABI_DEFAULT
;
5007 else if (! strcmp (mips_abi_string
, "32"))
5009 else if (! strcmp (mips_abi_string
, "o64"))
5011 else if (! strcmp (mips_abi_string
, "n32"))
5013 else if (! strcmp (mips_abi_string
, "64"))
5015 else if (! strcmp (mips_abi_string
, "eabi"))
5016 mips_abi
= ABI_EABI
;
5017 else if (! strcmp (mips_abi_string
, "meabi"))
5018 mips_abi
= ABI_MEABI
;
5020 error ("bad value (%s) for -mabi= switch", mips_abi_string
);
5022 /* A specified ISA defaults the ABI if it was not specified. */
5023 if (mips_abi_string
== 0 && mips_isa_string
5024 && mips_abi
!= ABI_EABI
5025 && mips_abi
!= ABI_O64
5026 && mips_abi
!= ABI_MEABI
)
5032 if (! ISA_HAS_64BIT_REGS
)
5034 else if (mips_abi
!= ABI_N32
)
5039 #ifdef MIPS_CPU_STRING_DEFAULT
5040 /* A specified ABI defaults the ISA if it was not specified. */
5041 else if (mips_isa_string
== 0 && mips_abi_string
5042 && mips_abi
!= ABI_EABI
&& mips_abi
!= ABI_O64
)
5044 if (mips_abi
== ABI_32
)
5046 else if (mips_abi
== ABI_N32
)
5053 /* If both ABI and ISA were specified, check for conflicts. */
5054 else if (mips_isa_string
&& mips_abi_string
)
5056 if (! ISA_HAS_64BIT_REGS
&& (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
5057 || mips_abi
== ABI_O64
))
5058 error ("-mabi=%s does not support -mips%d", mips_abi_string
, mips_isa
);
5061 /* Override TARGET_DEFAULT if necessary. */
5062 if (mips_abi
== ABI_32
)
5063 target_flags
&= ~ (MASK_FLOAT64
|MASK_64BIT
);
5065 /* If no type size setting options (-mlong64,-mint64,-mlong32) were used
5066 then set the type sizes. In the EABI in 64 bit mode, longs and
5067 pointers are 64 bits. Likewise for the SGI Irix6 N64 ABI. */
5068 if (mips_explicit_type_size_string
== NULL
5069 && ((mips_abi
== ABI_EABI
&& TARGET_64BIT
)
5070 || mips_abi
== ABI_64
))
5071 target_flags
|= MASK_LONG64
;
5074 if (mips_abi_string
)
5075 error ("this target does not support the -mabi switch");
5078 #ifdef MIPS_CPU_STRING_DEFAULT
5079 /* ??? There is a minor inconsistency here. If the user specifies an ISA
5080 greater than that supported by the default processor, then the user gets
5081 an error. Normally, the compiler will just default to the base level cpu
5082 for the indicated isa. */
5083 if (mips_arch_string
== 0)
5084 mips_arch_string
= MIPS_CPU_STRING_DEFAULT
;
5085 if (mips_tune_string
== 0)
5086 mips_tune_string
= MIPS_CPU_STRING_DEFAULT
;
5089 /* Identify the processor type. */
5091 if (mips_cpu_string
!= 0)
5093 mips_cpu
= mips_parse_cpu (mips_cpu_string
);
5094 if (mips_cpu
== PROCESSOR_DEFAULT
)
5096 error ("bad value (%s) for -mcpu= switch", mips_cpu_string
);
5097 mips_cpu_string
= "default";
5099 mips_arch
= mips_cpu
;
5100 mips_tune
= mips_cpu
;
5103 if (mips_arch_string
== 0
5104 || ! strcmp (mips_arch_string
, "default")
5105 || ! strcmp (mips_arch_string
, "DEFAULT"))
5110 mips_arch_string
= "3000";
5111 mips_arch
= PROCESSOR_R3000
;
5114 mips_arch_string
= "6000";
5115 mips_arch
= PROCESSOR_R6000
;
5118 mips_arch_string
= "4000";
5119 mips_arch
= PROCESSOR_R4000
;
5122 mips_arch_string
= "8000";
5123 mips_arch
= PROCESSOR_R8000
;
5126 mips_arch_string
= "4kc";
5127 mips_arch
= PROCESSOR_R4KC
;
5130 mips_arch_string
= "5kc";
5131 mips_arch
= PROCESSOR_R5KC
;
5137 mips_arch
= mips_parse_cpu (mips_arch_string
);
5138 if (mips_arch
== PROCESSOR_DEFAULT
)
5140 error ("bad value (%s) for -march= switch", mips_arch_string
);
5141 mips_arch_string
= "default";
5144 if (mips_tune_string
== 0
5145 || ! strcmp (mips_tune_string
, "default")
5146 || ! strcmp (mips_tune_string
, "DEFAULT"))
5148 if (mips_arch
!= PROCESSOR_DEFAULT
)
5149 mips_tune
= mips_arch
;
5154 mips_tune_string
= "3000";
5155 mips_tune
= PROCESSOR_R3000
;
5158 mips_tune_string
= "6000";
5159 mips_tune
= PROCESSOR_R6000
;
5162 mips_tune_string
= "4000";
5163 mips_tune
= PROCESSOR_R4000
;
5166 mips_tune_string
= "8000";
5167 mips_tune
= PROCESSOR_R8000
;
5170 mips_tune_string
= "4kc";
5171 mips_tune
= PROCESSOR_R4KC
;
5174 mips_tune_string
= "5kc";
5175 mips_tune
= PROCESSOR_R5KC
;
5182 mips_tune
= mips_parse_cpu (mips_tune_string
);
5183 if (mips_tune
== PROCESSOR_DEFAULT
)
5185 error ("bad value (%s) for -mtune= switch", mips_tune_string
);
5186 mips_tune_string
= "default";
5190 /* make sure sizes of ints/longs/etc. are ok */
5191 if (! ISA_HAS_64BIT_REGS
)
5195 error ("-mips%d does not support 64 bit fp registers", mips_isa
);
5196 target_flags
&= ~ MASK_FLOAT64
;
5199 else if (TARGET_64BIT
)
5201 error ("-mips%d does not support 64 bit gp registers", mips_isa
);
5202 target_flags
&= ~MASK_64BIT
;
5206 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
5207 flag_pcc_struct_return
= 0;
5209 /* Tell halfpic.c that we have half-pic code if we do. */
5210 if (TARGET_HALF_PIC
)
5213 /* -fpic (-KPIC) is the default when TARGET_ABICALLS is defined. We need
5214 to set flag_pic so that the LEGITIMATE_PIC_OPERAND_P macro will work. */
5215 /* ??? -non_shared turns off pic code generation, but this is not
5217 if (TARGET_ABICALLS
)
5219 mips_abicalls
= MIPS_ABICALLS_YES
;
5221 if (mips_section_threshold
> 0)
5222 warning ("-G is incompatible with PIC code which is the default");
5225 mips_abicalls
= MIPS_ABICALLS_NO
;
5227 /* -membedded-pic is a form of PIC code suitable for embedded
5228 systems. All calls are made using PC relative addressing, and
5229 all data is addressed using the $gp register. This requires gas,
5230 which does most of the work, and GNU ld, which automatically
5231 expands PC relative calls which are out of range into a longer
5232 instruction sequence. All gcc really does differently is
5233 generate a different sequence for a switch. */
5234 if (TARGET_EMBEDDED_PIC
)
5237 if (TARGET_ABICALLS
)
5238 warning ("-membedded-pic and -mabicalls are incompatible");
5241 warning ("-G and -membedded-pic are incompatible");
5243 /* Setting mips_section_threshold is not required, because gas
5244 will force everything to be GP addressable anyhow, but
5245 setting it will cause gcc to make better estimates of the
5246 number of instructions required to access a particular data
5248 mips_section_threshold
= 0x7fffffff;
5251 /* This optimization requires a linker that can support a R_MIPS_LO16
5252 relocation which is not immediately preceded by a R_MIPS_HI16 relocation.
5253 GNU ld has this support, but not all other MIPS linkers do, so we enable
5254 this optimization only if the user requests it, or if GNU ld is the
5255 standard linker for this configuration. */
5256 /* ??? This does not work when target addresses are DImode.
5257 This is because we are missing DImode high/lo_sum patterns. */
5258 if (TARGET_GAS
&& ! TARGET_MIPS16
&& TARGET_SPLIT_ADDRESSES
&& optimize
&& ! flag_pic
5260 mips_split_addresses
= 1;
5262 mips_split_addresses
= 0;
5264 /* -mrnames says to use the MIPS software convention for register
5265 names instead of the hardware names (ie, $a0 instead of $4).
5266 We do this by switching the names in mips_reg_names, which the
5267 reg_names points into via the REGISTER_NAMES macro. */
5269 if (TARGET_NAME_REGS
)
5270 memcpy (mips_reg_names
, mips_sw_reg_names
, sizeof (mips_reg_names
));
5272 /* When compiling for the mips16, we can not use floating point. We
5273 record the original hard float value in mips16_hard_float. */
5276 if (TARGET_SOFT_FLOAT
)
5277 mips16_hard_float
= 0;
5279 mips16_hard_float
= 1;
5280 target_flags
|= MASK_SOFT_FLOAT
;
5282 /* Don't run the scheduler before reload, since it tends to
5283 increase register pressure. */
5284 flag_schedule_insns
= 0;
5287 /* We put -mentry in TARGET_OPTIONS rather than TARGET_SWITCHES only
5288 to avoid using up another bit in target_flags. */
5289 if (mips_entry_string
!= NULL
)
5291 if (*mips_entry_string
!= '\0')
5292 error ("invalid option `entry%s'", mips_entry_string
);
5294 if (! TARGET_MIPS16
)
5295 warning ("-mentry is only meaningful with -mips-16");
5300 /* We copy TARGET_MIPS16 into the mips16 global variable, so that
5301 attributes can access it. */
5307 /* Initialize the high and low values for legitimate floating point
5308 constants. Rather than trying to get the accuracy down to the
5309 last bit, just use approximate ranges. */
5310 dfhigh
= REAL_VALUE_ATOF ("1.0e300", DFmode
);
5311 dflow
= REAL_VALUE_ATOF ("1.0e-300", DFmode
);
5312 sfhigh
= REAL_VALUE_ATOF ("1.0e38", SFmode
);
5313 sflow
= REAL_VALUE_ATOF ("1.0e-38", SFmode
);
5315 mips_print_operand_punct
['?'] = 1;
5316 mips_print_operand_punct
['#'] = 1;
5317 mips_print_operand_punct
['&'] = 1;
5318 mips_print_operand_punct
['!'] = 1;
5319 mips_print_operand_punct
['*'] = 1;
5320 mips_print_operand_punct
['@'] = 1;
5321 mips_print_operand_punct
['.'] = 1;
5322 mips_print_operand_punct
['('] = 1;
5323 mips_print_operand_punct
[')'] = 1;
5324 mips_print_operand_punct
['['] = 1;
5325 mips_print_operand_punct
[']'] = 1;
5326 mips_print_operand_punct
['<'] = 1;
5327 mips_print_operand_punct
['>'] = 1;
5328 mips_print_operand_punct
['{'] = 1;
5329 mips_print_operand_punct
['}'] = 1;
5330 mips_print_operand_punct
['^'] = 1;
5331 mips_print_operand_punct
['$'] = 1;
5332 mips_print_operand_punct
['+'] = 1;
5333 mips_print_operand_punct
['~'] = 1;
5335 mips_char_to_class
['d'] = TARGET_MIPS16
? M16_REGS
: GR_REGS
;
5336 mips_char_to_class
['e'] = M16_NA_REGS
;
5337 mips_char_to_class
['t'] = T_REG
;
5338 mips_char_to_class
['f'] = (TARGET_HARD_FLOAT
? FP_REGS
: NO_REGS
);
5339 mips_char_to_class
['h'] = HI_REG
;
5340 mips_char_to_class
['l'] = LO_REG
;
5341 mips_char_to_class
['a'] = HILO_REG
;
5342 mips_char_to_class
['x'] = MD_REGS
;
5343 mips_char_to_class
['b'] = ALL_REGS
;
5344 mips_char_to_class
['y'] = GR_REGS
;
5345 mips_char_to_class
['z'] = ST_REGS
;
5346 mips_char_to_class
['B'] = COP0_REGS
;
5347 mips_char_to_class
['C'] = COP2_REGS
;
5348 mips_char_to_class
['D'] = COP3_REGS
;
5350 /* Set up array to map GCC register number to debug register number.
5351 Ignore the special purpose register numbers. */
5353 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5354 mips_dbx_regno
[i
] = -1;
5356 start
= GP_DBX_FIRST
- GP_REG_FIRST
;
5357 for (i
= GP_REG_FIRST
; i
<= GP_REG_LAST
; i
++)
5358 mips_dbx_regno
[i
] = i
+ start
;
5360 start
= FP_DBX_FIRST
- FP_REG_FIRST
;
5361 for (i
= FP_REG_FIRST
; i
<= FP_REG_LAST
; i
++)
5362 mips_dbx_regno
[i
] = i
+ start
;
5364 /* Set up array giving whether a given register can hold a given mode.
5365 At present, restrict ints from being in FP registers, because reload
5366 is a little enthusiastic about storing extra values in FP registers,
5367 and this is not good for things like OS kernels. Also, due to the
5368 mandatory delay, it is as fast to load from cached memory as to move
5369 from the FP register. */
5371 for (mode
= VOIDmode
;
5372 mode
!= MAX_MACHINE_MODE
;
5373 mode
= (enum machine_mode
) ((int)mode
+ 1))
5375 register int size
= GET_MODE_SIZE (mode
);
5376 register enum mode_class
class = GET_MODE_CLASS (mode
);
5378 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
5385 temp
= (regno
== FPSW_REGNUM
);
5387 temp
= (ST_REG_P (regno
) || GP_REG_P (regno
)
5388 || FP_REG_P (regno
));
5391 else if (GP_REG_P (regno
))
5392 temp
= ((regno
& 1) == 0 || size
<= UNITS_PER_WORD
);
5394 else if (FP_REG_P (regno
))
5395 temp
= (((regno
% FP_INC
) == 0
5396 /* I think this change is OK regardless of abi, but
5397 I'm being cautions untill I can test this more.
5398 HARD_REGNO_MODE_OK is about whether or not you
5399 can move to and from a register without changing
5400 the value, not about whether math works on the
5402 || (mips_abi
== ABI_MEABI
&& size
<= 4))
5403 && (class == MODE_FLOAT
5404 || class == MODE_COMPLEX_FLOAT
5405 || (TARGET_DEBUG_H_MODE
&& class == MODE_INT
))
5406 && size
<= UNITS_PER_FPVALUE
);
5408 else if (MD_REG_P (regno
))
5409 temp
= (class == MODE_INT
5410 && (size
<= UNITS_PER_WORD
5411 || (regno
== MD_REG_FIRST
5412 && size
== 2 * UNITS_PER_WORD
)));
5414 else if (ALL_COP_REG_P (regno
))
5415 temp
= (class == MODE_INT
&& size
<= UNITS_PER_WORD
);
5419 mips_hard_regno_mode_ok
[(int)mode
][regno
] = temp
;
5423 /* Save GPR registers in word_mode sized hunks. word_mode hasn't been
5424 initialized yet, so we can't use that here. */
5425 gpr_mode
= TARGET_64BIT
? DImode
: SImode
;
5427 /* Provide default values for align_* for 64-bit targets. */
5428 if (TARGET_64BIT
&& !TARGET_MIPS16
)
5430 if (align_loops
== 0)
5432 if (align_jumps
== 0)
5434 if (align_functions
== 0)
5435 align_functions
= 8;
5438 /* Register global variables with the garbage collector. */
5439 mips_add_gc_roots ();
5441 /* Functions to allocate, mark and deallocate machine-dependent
5443 init_machine_status
= &mips_init_machine_status
;
5444 free_machine_status
= &mips_free_machine_status
;
5445 mark_machine_status
= &mips_mark_machine_status
;
5448 /* Allocate a chunk of memory for per-function machine-dependent data. */
5450 mips_init_machine_status (fn
)
5451 struct function
*fn
;
5453 fn
->machine
= ((struct machine_function
*)
5454 xcalloc (1, sizeof (struct machine_function
)));
5457 /* Release the chunk of memory for per-function machine-dependent data. */
5459 mips_free_machine_status (fn
)
5460 struct function
*fn
;
5466 /* Mark per-function machine-dependent data. */
5468 mips_mark_machine_status (fn
)
5469 struct function
*fn
;
5473 ggc_mark_rtx (fn
->machine
->embedded_pic_fnaddr_rtx
);
5474 ggc_mark_rtx (fn
->machine
->mips16_gp_pseudo_rtx
);
5478 /* On the mips16, we want to allocate $24 (T_REG) before other
5479 registers for instructions for which it is possible. This helps
5480 avoid shuffling registers around in order to set up for an xor,
5481 encouraging the compiler to use a cmp instead. */
5484 mips_order_regs_for_local_alloc ()
5488 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5489 reg_alloc_order
[i
] = i
;
5493 /* It really doesn't matter where we put register 0, since it is
5494 a fixed register anyhow. */
5495 reg_alloc_order
[0] = 24;
5496 reg_alloc_order
[24] = 0;
5501 /* The MIPS debug format wants all automatic variables and arguments
5502 to be in terms of the virtual frame pointer (stack pointer before
5503 any adjustment in the function), while the MIPS 3.0 linker wants
5504 the frame pointer to be the stack pointer after the initial
5505 adjustment. So, we do the adjustment here. The arg pointer (which
5506 is eliminated) points to the virtual frame pointer, while the frame
5507 pointer (which may be eliminated) points to the stack pointer after
5508 the initial adjustments. */
5511 mips_debugger_offset (addr
, offset
)
5513 HOST_WIDE_INT offset
;
5515 rtx offset2
= const0_rtx
;
5516 rtx reg
= eliminate_constant_term (addr
, &offset2
);
5519 offset
= INTVAL (offset2
);
5521 if (reg
== stack_pointer_rtx
|| reg
== frame_pointer_rtx
5522 || reg
== hard_frame_pointer_rtx
)
5524 HOST_WIDE_INT frame_size
= (!current_frame_info
.initialized
)
5525 ? compute_frame_size (get_frame_size ())
5526 : current_frame_info
.total_size
;
5528 /* MIPS16 frame is smaller */
5529 if (frame_pointer_needed
&& TARGET_MIPS16
)
5530 frame_size
-= current_function_outgoing_args_size
;
5532 offset
= offset
- frame_size
;
5535 /* sdbout_parms does not want this to crash for unrecognized cases. */
5537 else if (reg
!= arg_pointer_rtx
)
5538 abort_with_insn (addr
, "mips_debugger_offset called with non stack/frame/arg pointer");
5544 /* A C compound statement to output to stdio stream STREAM the
5545 assembler syntax for an instruction operand X. X is an RTL
5548 CODE is a value that can be used to specify one of several ways
5549 of printing the operand. It is used when identical operands
5550 must be printed differently depending on the context. CODE
5551 comes from the `%' specification that was used to request
5552 printing of the operand. If the specification was just `%DIGIT'
5553 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
5554 is the ASCII code for LTR.
5556 If X is a register, this macro should print the register's name.
5557 The names can be found in an array `reg_names' whose type is
5558 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
5560 When the machine description has a specification `%PUNCT' (a `%'
5561 followed by a punctuation character), this macro is called with
5562 a null pointer for X and the punctuation character for CODE.
5564 The MIPS specific codes are:
5566 'X' X is CONST_INT, prints 32 bits in hexadecimal format = "0x%08x",
5567 'x' X is CONST_INT, prints 16 bits in hexadecimal format = "0x%04x",
5568 'd' output integer constant in decimal,
5569 'z' if the operand is 0, use $0 instead of normal operand.
5570 'D' print second part of double-word register or memory operand.
5571 'L' print low-order register of double-word register operand.
5572 'M' print high-order register of double-word register operand.
5573 'C' print part of opcode for a branch condition.
5574 'F' print part of opcode for a floating-point branch condition.
5575 'N' print part of opcode for a branch condition, inverted.
5576 'W' print part of opcode for a floating-point branch condition, inverted.
5577 'S' X is CODE_LABEL, print with prefix of "LS" (for embedded switch).
5578 'B' print 'z' for EQ, 'n' for NE
5579 'b' print 'n' for EQ, 'z' for NE
5580 'T' print 'f' for EQ, 't' for NE
5581 't' print 't' for EQ, 'f' for NE
5582 'Z' print register and a comma, but print nothing for $fcc0
5583 '(' Turn on .set noreorder
5584 ')' Turn on .set reorder
5585 '[' Turn on .set noat
5587 '<' Turn on .set nomacro
5588 '>' Turn on .set macro
5589 '{' Turn on .set volatile (not GAS)
5590 '}' Turn on .set novolatile (not GAS)
5591 '&' Turn on .set noreorder if filling delay slots
5592 '*' Turn on both .set noreorder and .set nomacro if filling delay slots
5593 '!' Turn on .set nomacro if filling delay slots
5594 '#' Print nop if in a .set noreorder section.
5595 '?' Print 'l' if we are to use a branch likely instead of normal branch.
5596 '@' Print the name of the assembler temporary register (at or $1).
5597 '.' Print the name of the register with a hard-wired zero (zero or $0).
5598 '^' Print the name of the pic call-through register (t9 or $25).
5599 '$' Print the name of the stack pointer register (sp or $29).
5600 '+' Print the name of the gp register (gp or $28).
5601 '~' Output an branch alignment to LABEL_ALIGN(NULL). */
5604 print_operand (file
, op
, letter
)
5605 FILE *file
; /* file to write to */
5606 rtx op
; /* operand to print */
5607 int letter
; /* %<letter> or 0 */
5609 register enum rtx_code code
;
5611 if (PRINT_OPERAND_PUNCT_VALID_P (letter
))
5616 if (mips_branch_likely
)
5621 fputs (reg_names
[GP_REG_FIRST
+ 1], file
);
5625 fputs (reg_names
[PIC_FUNCTION_ADDR_REGNUM
], file
);
5629 fputs (reg_names
[GP_REG_FIRST
+ 0], file
);
5633 fputs (reg_names
[STACK_POINTER_REGNUM
], file
);
5637 fputs (reg_names
[GP_REG_FIRST
+ 28], file
);
5641 if (final_sequence
!= 0 && set_noreorder
++ == 0)
5642 fputs (".set\tnoreorder\n\t", file
);
5646 if (final_sequence
!= 0)
5648 if (set_noreorder
++ == 0)
5649 fputs (".set\tnoreorder\n\t", file
);
5651 if (set_nomacro
++ == 0)
5652 fputs (".set\tnomacro\n\t", file
);
5657 if (final_sequence
!= 0 && set_nomacro
++ == 0)
5658 fputs ("\n\t.set\tnomacro", file
);
5662 if (set_noreorder
!= 0)
5663 fputs ("\n\tnop", file
);
5664 else if (TARGET_STATS
)
5665 fputs ("\n\t#nop", file
);
5670 if (set_noreorder
++ == 0)
5671 fputs (".set\tnoreorder\n\t", file
);
5675 if (set_noreorder
== 0)
5676 error ("internal error: %%) found without a %%( in assembler pattern");
5678 else if (--set_noreorder
== 0)
5679 fputs ("\n\t.set\treorder", file
);
5684 if (set_noat
++ == 0)
5685 fputs (".set\tnoat\n\t", file
);
5690 error ("internal error: %%] found without a %%[ in assembler pattern");
5691 else if (--set_noat
== 0)
5692 fputs ("\n\t.set\tat", file
);
5697 if (set_nomacro
++ == 0)
5698 fputs (".set\tnomacro\n\t", file
);
5702 if (set_nomacro
== 0)
5703 error ("internal error: %%> found without a %%< in assembler pattern");
5704 else if (--set_nomacro
== 0)
5705 fputs ("\n\t.set\tmacro", file
);
5710 if (set_volatile
++ == 0)
5711 fprintf (file
, "%s.set\tvolatile\n\t", TARGET_MIPS_AS
? "" : "#");
5715 if (set_volatile
== 0)
5716 error ("internal error: %%} found without a %%{ in assembler pattern");
5717 else if (--set_volatile
== 0)
5718 fprintf (file
, "\n\t%s.set\tnovolatile", (TARGET_MIPS_AS
) ? "" : "#");
5724 if (align_labels_log
> 0)
5725 ASM_OUTPUT_ALIGN (file
, align_labels_log
);
5730 error ("PRINT_OPERAND: unknown punctuation '%c'", letter
);
5739 error ("PRINT_OPERAND null pointer");
5743 code
= GET_CODE (op
);
5745 if (code
== SIGN_EXTEND
)
5746 op
= XEXP (op
, 0), code
= GET_CODE (op
);
5751 case EQ
: fputs ("eq", file
); break;
5752 case NE
: fputs ("ne", file
); break;
5753 case GT
: fputs ("gt", file
); break;
5754 case GE
: fputs ("ge", file
); break;
5755 case LT
: fputs ("lt", file
); break;
5756 case LE
: fputs ("le", file
); break;
5757 case GTU
: fputs ("gtu", file
); break;
5758 case GEU
: fputs ("geu", file
); break;
5759 case LTU
: fputs ("ltu", file
); break;
5760 case LEU
: fputs ("leu", file
); break;
5762 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%C");
5765 else if (letter
== 'N')
5768 case EQ
: fputs ("ne", file
); break;
5769 case NE
: fputs ("eq", file
); break;
5770 case GT
: fputs ("le", file
); break;
5771 case GE
: fputs ("lt", file
); break;
5772 case LT
: fputs ("ge", file
); break;
5773 case LE
: fputs ("gt", file
); break;
5774 case GTU
: fputs ("leu", file
); break;
5775 case GEU
: fputs ("ltu", file
); break;
5776 case LTU
: fputs ("geu", file
); break;
5777 case LEU
: fputs ("gtu", file
); break;
5779 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%N");
5782 else if (letter
== 'F')
5785 case EQ
: fputs ("c1f", file
); break;
5786 case NE
: fputs ("c1t", file
); break;
5788 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%F");
5791 else if (letter
== 'W')
5794 case EQ
: fputs ("c1t", file
); break;
5795 case NE
: fputs ("c1f", file
); break;
5797 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%W");
5800 else if (letter
== 'S')
5804 ASM_GENERATE_INTERNAL_LABEL (buffer
, "LS", CODE_LABEL_NUMBER (op
));
5805 assemble_name (file
, buffer
);
5808 else if (letter
== 'Z')
5810 register int regnum
;
5815 regnum
= REGNO (op
);
5816 if (! ST_REG_P (regnum
))
5819 if (regnum
!= ST_REG_FIRST
)
5820 fprintf (file
, "%s,", reg_names
[regnum
]);
5823 else if (code
== REG
|| code
== SUBREG
)
5825 register int regnum
;
5828 regnum
= REGNO (op
);
5830 regnum
= true_regnum (op
);
5832 if ((letter
== 'M' && ! WORDS_BIG_ENDIAN
)
5833 || (letter
== 'L' && WORDS_BIG_ENDIAN
)
5837 fprintf (file
, "%s", reg_names
[regnum
]);
5840 else if (code
== MEM
)
5843 output_address (plus_constant (XEXP (op
, 0), 4));
5845 output_address (XEXP (op
, 0));
5848 else if (code
== CONST_DOUBLE
5849 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_FLOAT
)
5854 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
5855 REAL_VALUE_TO_DECIMAL (d
, "%.20e", s
);
5859 else if (letter
== 'x' && GET_CODE (op
) == CONST_INT
)
5860 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, 0xffff & INTVAL(op
));
5862 else if (letter
== 'X' && GET_CODE(op
) == CONST_INT
)
5863 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (op
));
5865 else if (letter
== 'd' && GET_CODE(op
) == CONST_INT
)
5866 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, (INTVAL(op
)));
5868 else if (letter
== 'z' && GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 0)
5869 fputs (reg_names
[GP_REG_FIRST
], file
);
5871 else if (letter
== 'd' || letter
== 'x' || letter
== 'X')
5872 output_operand_lossage ("invalid use of %%d, %%x, or %%X");
5874 else if (letter
== 'B')
5875 fputs (code
== EQ
? "z" : "n", file
);
5876 else if (letter
== 'b')
5877 fputs (code
== EQ
? "n" : "z", file
);
5878 else if (letter
== 'T')
5879 fputs (code
== EQ
? "f" : "t", file
);
5880 else if (letter
== 't')
5881 fputs (code
== EQ
? "t" : "f", file
);
5883 else if (code
== CONST
&& GET_CODE (XEXP (op
, 0)) == REG
)
5885 /* This case arises on the mips16; see mips16_gp_pseudo_reg. */
5886 print_operand (file
, XEXP (op
, 0), letter
);
5889 else if (TARGET_MIPS16
&& code
== CONST
&& mips16_gp_offset_p (op
))
5891 fputs ("%gprel(", file
);
5892 mips16_output_gp_offset (file
, op
);
5897 output_addr_const (file
, op
);
5900 /* A C compound statement to output to stdio stream STREAM the
5901 assembler syntax for an instruction operand that is a memory
5902 reference whose address is ADDR. ADDR is an RTL expression. */
5905 print_operand_address (file
, addr
)
5910 error ("PRINT_OPERAND_ADDRESS, null pointer");
5913 switch (GET_CODE (addr
))
5916 if (! TARGET_MIPS16
&& REGNO (addr
) == ARG_POINTER_REGNUM
)
5917 abort_with_insn (addr
, "arg pointer not eliminated");
5919 fprintf (file
, "0(%s)", reg_names
[REGNO (addr
)]);
5924 register rtx arg0
= XEXP (addr
, 0);
5925 register rtx arg1
= XEXP (addr
, 1);
5927 if (! mips_split_addresses
)
5928 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, Spurious LO_SUM");
5930 if (GET_CODE (arg0
) != REG
)
5931 abort_with_insn (addr
,
5932 "PRINT_OPERAND_ADDRESS, LO_SUM with #1 not REG");
5934 fprintf (file
, "%%lo(");
5935 print_operand_address (file
, arg1
);
5936 fprintf (file
, ")(%s)", reg_names
[REGNO (arg0
)]);
5942 register rtx reg
= 0;
5943 register rtx offset
= 0;
5944 register rtx arg0
= XEXP (addr
, 0);
5945 register rtx arg1
= XEXP (addr
, 1);
5947 if (GET_CODE (arg0
) == REG
)
5951 if (GET_CODE (offset
) == REG
)
5952 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, 2 regs");
5955 else if (GET_CODE (arg1
) == REG
)
5956 reg
= arg1
, offset
= arg0
;
5957 else if (CONSTANT_P (arg0
) && CONSTANT_P (arg1
))
5959 output_addr_const (file
, addr
);
5963 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, no regs");
5965 if (! CONSTANT_P (offset
))
5966 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #2");
5968 if (REGNO (reg
) == ARG_POINTER_REGNUM
)
5969 abort_with_insn (addr
, "arg pointer not eliminated");
5972 && GET_CODE (offset
) == CONST
5973 && mips16_gp_offset_p (offset
))
5975 fputs ("%gprel(", file
);
5976 mips16_output_gp_offset (file
, offset
);
5980 output_addr_const (file
, offset
);
5981 fprintf (file
, "(%s)", reg_names
[REGNO (reg
)]);
5989 output_addr_const (file
, addr
);
5993 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #1");
5998 /* Target hook for assembling integer objects. It appears that the Irix
5999 6 assembler can't handle 64-bit decimal integers, so avoid printing
6000 such an integer here. */
6003 mips_assemble_integer (x
, size
, aligned_p
)
6008 if ((TARGET_64BIT
|| TARGET_GAS
) && size
== 8 && aligned_p
)
6010 fputs ("\t.dword\t", asm_out_file
);
6011 if (HOST_BITS_PER_WIDE_INT
< 64 || GET_CODE (x
) != CONST_INT
)
6012 output_addr_const (asm_out_file
, x
);
6014 print_operand (asm_out_file
, x
, 'X');
6015 fputc ('\n', asm_out_file
);
6018 return default_assemble_integer (x
, size
, aligned_p
);
6021 /* If optimizing for the global pointer, keep track of all of the externs, so
6022 that at the end of the file, we can emit the appropriate .extern
6023 declaration for them, before writing out the text section. We assume all
6024 names passed to us are in the permanent obstack, so they will be valid at
6025 the end of the compilation.
6027 If we have -G 0, or the extern size is unknown, or the object is in a user
6028 specified section that is not .sbss/.sdata, don't bother emitting the
6029 .externs. In the case of user specified sections this behaviour is
6030 required as otherwise GAS will think the object lives in .sbss/.sdata. */
6033 mips_output_external (file
, decl
, name
)
6034 FILE *file ATTRIBUTE_UNUSED
;
6038 register struct extern_list
*p
;
6043 && TREE_CODE (decl
) != FUNCTION_DECL
6044 && !DECL_COMDAT (decl
)
6045 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
6046 && ((section_name
= DECL_SECTION_NAME (decl
)) == NULL
6047 || strcmp (TREE_STRING_POINTER (section_name
), ".sbss") == 0
6048 || strcmp (TREE_STRING_POINTER (section_name
), ".sdata") == 0))
6050 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
6051 p
->next
= extern_head
;
6057 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
6058 if (TREE_CODE (decl
) == FUNCTION_DECL
6059 /* ??? Don't include alloca, since gcc will always expand it
6060 inline. If we don't do this, the C++ library fails to build. */
6061 && strcmp (name
, "alloca")
6062 /* ??? Don't include __builtin_next_arg, because then gcc will not
6063 bootstrap under Irix 5.1. */
6064 && strcmp (name
, "__builtin_next_arg"))
6066 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
6067 p
->next
= extern_head
;
6077 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
6079 mips_output_external_libcall (file
, name
)
6080 FILE *file ATTRIBUTE_UNUSED
;
6083 register struct extern_list
*p
;
6085 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
6086 p
->next
= extern_head
;
6095 /* Emit a new filename to a stream. If this is MIPS ECOFF, watch out
6096 for .file's that start within a function. If we are smuggling stabs, try to
6097 put out a MIPS ECOFF file and a stab. */
6100 mips_output_filename (stream
, name
)
6104 static int first_time
= 1;
6105 char ltext_label_name
[100];
6111 current_function_file
= name
;
6112 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
6113 /* This tells mips-tfile that stabs will follow. */
6114 if (!TARGET_GAS
&& write_symbols
== DBX_DEBUG
)
6115 fprintf (stream
, "\t#@stabs\n");
6118 else if (write_symbols
== DBX_DEBUG
)
6120 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name
, "Ltext", 0);
6121 fprintf (stream
, "%s", ASM_STABS_OP
);
6122 output_quoted_string (stream
, name
);
6123 fprintf (stream
, ",%d,0,0,%s\n", N_SOL
, <ext_label_name
[1]);
6126 else if (name
!= current_function_file
6127 && strcmp (name
, current_function_file
) != 0)
6129 if (inside_function
&& !TARGET_GAS
)
6131 if (!file_in_function_warning
)
6133 file_in_function_warning
= 1;
6134 ignore_line_number
= 1;
6135 warning ("MIPS ECOFF format does not allow changing filenames within functions with #line");
6141 current_function_file
= name
;
6142 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
6147 /* Emit a linenumber. For encapsulated stabs, we need to put out a stab
6148 as well as a .loc, since it is possible that MIPS ECOFF might not be
6149 able to represent the location for inlines that come from a different
6153 mips_output_lineno (stream
, line
)
6157 if (write_symbols
== DBX_DEBUG
)
6160 fprintf (stream
, "%sLM%d:\n%s%d,0,%d,%sLM%d\n",
6161 LOCAL_LABEL_PREFIX
, sym_lineno
, ASM_STABN_OP
, N_SLINE
, line
,
6162 LOCAL_LABEL_PREFIX
, sym_lineno
);
6166 fprintf (stream
, "\n\t%s.loc\t%d %d\n",
6167 (ignore_line_number
) ? "#" : "",
6168 num_source_filenames
, line
);
6170 LABEL_AFTER_LOC (stream
);
6174 /* Output an ASCII string, in a space-saving way. */
6177 mips_output_ascii (stream
, string_param
, len
)
6179 const char *string_param
;
6184 register const unsigned char *string
=
6185 (const unsigned char *)string_param
;
6187 fprintf (stream
, "\t.ascii\t\"");
6188 for (i
= 0; i
< len
; i
++)
6190 register int c
= string
[i
];
6196 putc ('\\', stream
);
6201 case TARGET_NEWLINE
:
6202 fputs ("\\n", stream
);
6204 && (((c
= string
[i
+1]) >= '\040' && c
<= '~')
6205 || c
== TARGET_TAB
))
6206 cur_pos
= 32767; /* break right here */
6212 fputs ("\\t", stream
);
6217 fputs ("\\f", stream
);
6222 fputs ("\\b", stream
);
6227 fputs ("\\r", stream
);
6232 if (c
>= ' ' && c
< 0177)
6239 fprintf (stream
, "\\%03o", c
);
6244 if (cur_pos
> 72 && i
+1 < len
)
6247 fprintf (stream
, "\"\n\t.ascii\t\"");
6250 fprintf (stream
, "\"\n");
6253 /* If defined, a C statement to be executed just prior to the output of
6254 assembler code for INSN, to modify the extracted operands so they will be
6257 Here the argument OPVEC is the vector containing the operands extracted
6258 from INSN, and NOPERANDS is the number of elements of the vector which
6259 contain meaningful data for this insn. The contents of this vector are
6260 what will be used to convert the insn template into assembler code, so you
6261 can change the assembler output by changing the contents of the vector.
6263 We use it to check if the current insn needs a nop in front of it because
6264 of load delays, and also to update the delay slot statistics. */
6266 /* ??? There is no real need for this function, because it never actually
6267 emits a NOP anymore. */
6270 final_prescan_insn (insn
, opvec
, noperands
)
6272 rtx opvec
[] ATTRIBUTE_UNUSED
;
6273 int noperands ATTRIBUTE_UNUSED
;
6275 if (dslots_number_nops
> 0)
6277 rtx pattern
= PATTERN (insn
);
6278 int length
= get_attr_length (insn
);
6280 /* Do we need to emit a NOP? */
6282 || (mips_load_reg
!= 0 && reg_mentioned_p (mips_load_reg
, pattern
))
6283 || (mips_load_reg2
!= 0 && reg_mentioned_p (mips_load_reg2
, pattern
))
6284 || (mips_load_reg3
!= 0 && reg_mentioned_p (mips_load_reg3
, pattern
))
6285 || (mips_load_reg4
!= 0
6286 && reg_mentioned_p (mips_load_reg4
, pattern
)))
6287 fputs ("\t#nop\n", asm_out_file
);
6290 dslots_load_filled
++;
6292 while (--dslots_number_nops
> 0)
6293 fputs ("\t#nop\n", asm_out_file
);
6302 && (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CALL_INSN
))
6303 dslots_jump_total
++;
6306 /* Output at beginning of assembler file.
6308 If we are optimizing to use the global pointer, create a temporary file to
6309 hold all of the text stuff, and write it out to the end. This is needed
6310 because the MIPS assembler is evidently one pass, and if it hasn't seen the
6311 relevant .comm/.lcomm/.extern/.sdata declaration when the code is
6312 processed, it generates a two instruction sequence. */
6315 mips_asm_file_start (stream
)
6318 ASM_OUTPUT_SOURCE_FILENAME (stream
, main_input_filename
);
6320 /* Versions of the MIPS assembler before 2.20 generate errors if a branch
6321 inside of a .set noreorder section jumps to a label outside of the .set
6322 noreorder section. Revision 2.20 just set nobopt silently rather than
6325 if (TARGET_MIPS_AS
&& optimize
&& flag_delayed_branch
)
6326 fprintf (stream
, "\t.set\tnobopt\n");
6330 #if defined(OBJECT_FORMAT_ELF)
6331 /* Generate a special section to describe the ABI switches used to
6332 produce the resultant binary. This used to be done by the assembler
6333 setting bits in the ELF header's flags field, but we have run out of
6334 bits. GDB needs this information in order to be able to correctly
6335 debug these binaries. See the function mips_gdbarch_init() in
6337 const char * abi_string
= NULL
;
6341 case ABI_32
: abi_string
= "abi32"; break;
6342 case ABI_N32
: abi_string
= "abiN32"; break;
6343 case ABI_64
: abi_string
= "abi64"; break;
6344 case ABI_O64
: abi_string
= "abiO64"; break;
6345 case ABI_EABI
: abi_string
= TARGET_64BIT
? "eabi64" : "eabi32"; break;
6346 case ABI_MEABI
:abi_string
= TARGET_64BIT
? "meabi64" : "meabi32"; break;
6350 /* Note - we use fprintf directly rather than called named_section()
6351 because in this way we can avoid creating an allocated section. We
6352 do not want this section to take up any space in the running
6354 fprintf (stream
, "\t.section .mdebug.%s\n", abi_string
);
6356 /* Restore the default section. */
6357 fprintf (stream
, "\t.previous\n");
6363 /* Generate the pseudo ops that System V.4 wants. */
6364 #ifndef ABICALLS_ASM_OP
6365 #define ABICALLS_ASM_OP "\t.abicalls"
6367 if (TARGET_ABICALLS
)
6368 /* ??? but do not want this (or want pic0) if -non-shared? */
6369 fprintf (stream
, "%s\n", ABICALLS_ASM_OP
);
6372 fprintf (stream
, "\t.set\tmips16\n");
6374 /* This code exists so that we can put all externs before all symbol
6375 references. This is necessary for the MIPS assembler's global pointer
6376 optimizations to work. */
6377 if (TARGET_FILE_SWITCHING
)
6379 asm_out_data_file
= stream
;
6380 asm_out_text_file
= tmpfile ();
6383 asm_out_data_file
= asm_out_text_file
= stream
;
6385 if (flag_verbose_asm
)
6386 fprintf (stream
, "\n%s -G value = %d, Arch = %s, ISA = %d\n",
6388 mips_section_threshold
, mips_arch_string
, mips_isa
);
6391 /* If we are optimizing the global pointer, emit the text section now and any
6392 small externs which did not have .comm, etc that are needed. Also, give a
6393 warning if the data area is more than 32K and -pic because 3 instructions
6394 are needed to reference the data pointers. */
6397 mips_asm_file_end (file
)
6401 struct extern_list
*p
;
6405 HALF_PIC_FINISH (file
);
6412 for (p
= extern_head
; p
!= 0; p
= p
->next
)
6414 name_tree
= get_identifier (p
->name
);
6416 /* Positively ensure only one .extern for any given symbol. */
6417 if (! TREE_ASM_WRITTEN (name_tree
))
6419 TREE_ASM_WRITTEN (name_tree
) = 1;
6420 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
6422 ASM_OUTPUT_UNDEF_FUNCTION (file
, p
->name
);
6426 fputs ("\t.extern\t", file
);
6427 assemble_name (file
, p
->name
);
6428 fprintf (file
, ", %d\n", p
->size
);
6434 if (TARGET_FILE_SWITCHING
)
6436 fprintf (file
, "\n\t.text\n");
6437 copy_file_data (file
, asm_out_text_file
);
6442 copy_file_data (to
, from
)
6449 fatal_io_error ("can't rewind temp file");
6451 while ((len
= fread (buffer
, 1, sizeof (buffer
), from
)) > 0)
6452 if (fwrite (buffer
, 1, len
, to
) != len
)
6453 fatal_io_error ("can't write to output file");
6456 fatal_io_error ("can't read from temp file");
6459 fatal_io_error ("can't close temp file");
6462 /* Emit either a label, .comm, or .lcomm directive, and mark that the symbol
6463 is used, so that we don't emit an .extern for it in mips_asm_file_end. */
6466 mips_declare_object (stream
, name
, init_string
, final_string
, size
)
6469 const char *init_string
;
6470 const char *final_string
;
6473 fputs (init_string
, stream
); /* "", "\t.comm\t", or "\t.lcomm\t" */
6474 assemble_name (stream
, name
);
6475 fprintf (stream
, final_string
, size
); /* ":\n", ",%u\n", ",%u\n" */
6479 tree name_tree
= get_identifier (name
);
6480 TREE_ASM_WRITTEN (name_tree
) = 1;
6484 /* Return the bytes needed to compute the frame pointer from the current
6487 Mips stack frames look like:
6489 Before call After call
6490 +-----------------------+ +-----------------------+
6493 | caller's temps. | | caller's temps. |
6495 +-----------------------+ +-----------------------+
6497 | arguments on stack. | | arguments on stack. |
6499 +-----------------------+ +-----------------------+
6500 | 4 words to save | | 4 words to save |
6501 | arguments passed | | arguments passed |
6502 | in registers, even | | in registers, even |
6503 SP->| if not passed. | VFP->| if not passed. |
6504 +-----------------------+ +-----------------------+
6506 | fp register save |
6508 +-----------------------+
6510 | gp register save |
6512 +-----------------------+
6516 +-----------------------+
6518 | alloca allocations |
6520 +-----------------------+
6522 | GP save for V.4 abi |
6524 +-----------------------+
6526 | arguments on stack |
6528 +-----------------------+
6530 | arguments passed |
6531 | in registers, even |
6532 low SP->| if not passed. |
6533 memory +-----------------------+
6538 compute_frame_size (size
)
6539 HOST_WIDE_INT size
; /* # of var. bytes allocated */
6542 HOST_WIDE_INT total_size
; /* # bytes that the entire frame takes up */
6543 HOST_WIDE_INT var_size
; /* # bytes that variables take up */
6544 HOST_WIDE_INT args_size
; /* # bytes that outgoing arguments take up */
6545 HOST_WIDE_INT extra_size
; /* # extra bytes */
6546 HOST_WIDE_INT gp_reg_rounded
; /* # bytes needed to store gp after rounding */
6547 HOST_WIDE_INT gp_reg_size
; /* # bytes needed to store gp regs */
6548 HOST_WIDE_INT fp_reg_size
; /* # bytes needed to store fp regs */
6549 long mask
; /* mask of saved gp registers */
6550 long fmask
; /* mask of saved fp registers */
6557 extra_size
= MIPS_STACK_ALIGN (((TARGET_ABICALLS
) ? UNITS_PER_WORD
: 0));
6558 var_size
= MIPS_STACK_ALIGN (size
);
6559 args_size
= MIPS_STACK_ALIGN (current_function_outgoing_args_size
);
6561 /* The MIPS 3.0 linker does not like functions that dynamically
6562 allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it
6563 looks like we are trying to create a second frame pointer to the
6564 function, so allocate some stack space to make it happy. */
6566 if (args_size
== 0 && current_function_calls_alloca
)
6567 args_size
= 4 * UNITS_PER_WORD
;
6569 total_size
= var_size
+ args_size
+ extra_size
;
6570 return_type
= DECL_RESULT (current_function_decl
);
6572 /* Calculate space needed for gp registers. */
6573 for (regno
= GP_REG_FIRST
; regno
<= GP_REG_LAST
; regno
++)
6575 /* $18 is a special case on the mips16. It may be used to call
6576 a function which returns a floating point value, but it is
6577 marked in call_used_regs. $31 is also a special case. When
6578 not using -mentry, it will be used to copy a return value
6579 into the floating point registers if the return value is
6581 if (MUST_SAVE_REGISTER (regno
)
6583 && regno
== GP_REG_FIRST
+ 18
6584 && regs_ever_live
[regno
])
6586 && regno
== GP_REG_FIRST
+ 31
6587 && mips16_hard_float
6589 && ! aggregate_value_p (return_type
)
6590 && GET_MODE_CLASS (DECL_MODE (return_type
)) == MODE_FLOAT
6591 && GET_MODE_SIZE (DECL_MODE (return_type
)) <= UNITS_PER_FPVALUE
))
6593 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6594 mask
|= 1L << (regno
- GP_REG_FIRST
);
6596 /* The entry and exit pseudo instructions can not save $17
6597 without also saving $16. */
6599 && regno
== GP_REG_FIRST
+ 17
6600 && ! MUST_SAVE_REGISTER (GP_REG_FIRST
+ 16))
6602 gp_reg_size
+= UNITS_PER_WORD
;
6608 /* We need to restore these for the handler. */
6609 if (current_function_calls_eh_return
)
6614 regno
= EH_RETURN_DATA_REGNO (i
);
6615 if (regno
== INVALID_REGNUM
)
6617 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6618 mask
|= 1L << (regno
- GP_REG_FIRST
);
6622 /* This loop must iterate over the same space as its companion in
6623 save_restore_insns. */
6624 for (regno
= (FP_REG_LAST
- FP_INC
+ 1);
6625 regno
>= FP_REG_FIRST
;
6628 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
6630 fp_reg_size
+= FP_INC
* UNITS_PER_FPREG
;
6631 fmask
|= ((1 << FP_INC
) - 1) << (regno
- FP_REG_FIRST
);
6635 gp_reg_rounded
= MIPS_STACK_ALIGN (gp_reg_size
);
6636 total_size
+= gp_reg_rounded
+ MIPS_STACK_ALIGN (fp_reg_size
);
6638 /* The gp reg is caller saved in the 32 bit ABI, so there is no need
6639 for leaf routines (total_size == extra_size) to save the gp reg.
6640 The gp reg is callee saved in the 64 bit ABI, so all routines must
6641 save the gp reg. This is not a leaf routine if -p, because of the
6643 if (total_size
== extra_size
6644 && (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
|| mips_abi
== ABI_EABI
)
6645 && ! current_function_profile
)
6646 total_size
= extra_size
= 0;
6647 else if (TARGET_ABICALLS
)
6649 /* Add the context-pointer to the saved registers. */
6650 gp_reg_size
+= UNITS_PER_WORD
;
6651 mask
|= 1L << (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
);
6652 total_size
-= gp_reg_rounded
;
6653 gp_reg_rounded
= MIPS_STACK_ALIGN (gp_reg_size
);
6654 total_size
+= gp_reg_rounded
;
6657 /* Add in space reserved on the stack by the callee for storing arguments
6658 passed in registers. */
6659 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
6660 total_size
+= MIPS_STACK_ALIGN (current_function_pretend_args_size
);
6662 /* The entry pseudo instruction will allocate 32 bytes on the stack. */
6663 if (mips_entry
&& total_size
> 0 && total_size
< 32)
6666 /* Save other computed information. */
6667 current_frame_info
.total_size
= total_size
;
6668 current_frame_info
.var_size
= var_size
;
6669 current_frame_info
.args_size
= args_size
;
6670 current_frame_info
.extra_size
= extra_size
;
6671 current_frame_info
.gp_reg_size
= gp_reg_size
;
6672 current_frame_info
.fp_reg_size
= fp_reg_size
;
6673 current_frame_info
.mask
= mask
;
6674 current_frame_info
.fmask
= fmask
;
6675 current_frame_info
.initialized
= reload_completed
;
6676 current_frame_info
.num_gp
= gp_reg_size
/ UNITS_PER_WORD
;
6677 current_frame_info
.num_fp
= fp_reg_size
/ (FP_INC
* UNITS_PER_FPREG
);
6681 unsigned long offset
;
6683 /* When using mips_entry, the registers are always saved at the
6684 top of the stack. */
6686 offset
= (args_size
+ extra_size
+ var_size
6687 + gp_reg_size
- GET_MODE_SIZE (gpr_mode
));
6689 offset
= total_size
- GET_MODE_SIZE (gpr_mode
);
6691 current_frame_info
.gp_sp_offset
= offset
;
6692 current_frame_info
.gp_save_offset
= offset
- total_size
;
6696 current_frame_info
.gp_sp_offset
= 0;
6697 current_frame_info
.gp_save_offset
= 0;
6702 unsigned long offset
= (args_size
+ extra_size
+ var_size
6703 + gp_reg_rounded
+ fp_reg_size
6704 - FP_INC
* UNITS_PER_FPREG
);
6705 current_frame_info
.fp_sp_offset
= offset
;
6706 current_frame_info
.fp_save_offset
= offset
- total_size
;
6710 current_frame_info
.fp_sp_offset
= 0;
6711 current_frame_info
.fp_save_offset
= 0;
6714 /* Ok, we're done. */
6718 /* Common code to emit the insns (or to write the instructions to a file)
6719 to save/restore registers.
6721 Other parts of the code assume that MIPS_TEMP1_REGNUM (aka large_reg)
6722 is not modified within save_restore_insns. */
6724 #define BITSET_P(VALUE,BIT) (((VALUE) & (1L << (BIT))) != 0)
6726 /* Emit instructions to load the value (SP + OFFSET) into MIPS_TEMP2_REGNUM
6727 and return an rtl expression for the register.
6729 This function is a subroutine of save_restore_insns. It is used when
6730 OFFSET is too large to add in a single instruction. */
6733 mips_add_large_offset_to_sp (offset
)
6734 HOST_WIDE_INT offset
;
6736 rtx reg
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6737 rtx offset_rtx
= GEN_INT (offset
);
6739 emit_move_insn (reg
, offset_rtx
);
6740 if (Pmode
== DImode
)
6741 emit_insn (gen_adddi3 (reg
, reg
, stack_pointer_rtx
));
6743 emit_insn (gen_addsi3 (reg
, reg
, stack_pointer_rtx
));
6747 /* Make INSN frame related and note that it performs the frame-related
6748 operation DWARF_PATTERN. */
6751 mips_annotate_frame_insn (insn
, dwarf_pattern
)
6752 rtx insn
, dwarf_pattern
;
6754 RTX_FRAME_RELATED_P (insn
) = 1;
6755 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
6760 /* Return a frame-related rtx that stores register REGNO at (SP + OFFSET).
6761 The expression should only be used to store single registers. */
6764 mips_frame_set (mode
, regno
, offset
)
6765 enum machine_mode mode
;
6769 rtx address
= plus_constant (stack_pointer_rtx
, offset
);
6770 rtx set
= gen_rtx_SET (mode
,
6771 gen_rtx_MEM (mode
, address
),
6772 gen_rtx_REG (mode
, regno
));
6773 RTX_FRAME_RELATED_P (set
) = 1;
6778 /* Emit a move instruction that stores REG in MEM. Make the instruction
6779 frame related and note that it stores REG at (SP + OFFSET). This
6780 function may be asked to store an FPR pair. */
6783 mips_emit_frame_related_store (mem
, reg
, offset
)
6786 HOST_WIDE_INT offset
;
6790 if (GET_MODE (reg
) == DFmode
&& ! TARGET_FLOAT64
)
6792 /* Two registers are being stored, so the frame-related expression
6793 must be a PARALLEL rtx with one SET for each register. The
6794 higher numbered register is stored in the lower address on
6795 big-endian targets. */
6796 int regno1
= TARGET_BIG_ENDIAN
? REGNO (reg
) + 1 : REGNO (reg
);
6797 int regno2
= TARGET_BIG_ENDIAN
? REGNO (reg
) : REGNO (reg
) + 1;
6798 rtx set1
= mips_frame_set (SFmode
, regno1
, offset
);
6799 rtx set2
= mips_frame_set (SFmode
, regno2
, offset
+ UNITS_PER_FPREG
);
6800 dwarf_expr
= gen_rtx_PARALLEL (VOIDmode
, gen_rtvec (2, set1
, set2
));
6803 dwarf_expr
= mips_frame_set (GET_MODE (reg
), REGNO (reg
), offset
);
6805 mips_annotate_frame_insn (emit_move_insn (mem
, reg
), dwarf_expr
);
6809 save_restore_insns (store_p
, large_reg
, large_offset
)
6810 int store_p
; /* true if this is prologue */
6811 rtx large_reg
; /* register holding large offset constant or NULL */
6812 long large_offset
; /* large constant offset value */
6814 long mask
= current_frame_info
.mask
;
6815 long fmask
= current_frame_info
.fmask
;
6816 long real_mask
= mask
;
6819 HOST_WIDE_INT base_offset
;
6820 HOST_WIDE_INT gp_offset
;
6821 HOST_WIDE_INT fp_offset
;
6822 HOST_WIDE_INT end_offset
;
6825 if (frame_pointer_needed
6826 && ! BITSET_P (mask
, HARD_FRAME_POINTER_REGNUM
- GP_REG_FIRST
))
6829 /* Do not restore GP under certain conditions. */
6832 && (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
))
6833 mask
&= ~(1L << (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
));
6835 if (mask
== 0 && fmask
== 0)
6838 /* Save registers starting from high to low. The debuggers prefer at least
6839 the return register be stored at func+4, and also it allows us not to
6840 need a nop in the epilog if at least one register is reloaded in
6841 addition to return address. */
6843 /* Save GP registers if needed. */
6846 /* Pick which pointer to use as a base register. For small frames, just
6847 use the stack pointer. Otherwise, use a temporary register. Save 2
6848 cycles if the save area is near the end of a large frame, by reusing
6849 the constant created in the prologue/epilogue to adjust the stack
6852 gp_offset
= current_frame_info
.gp_sp_offset
;
6854 = gp_offset
- (current_frame_info
.gp_reg_size
6855 - GET_MODE_SIZE (gpr_mode
));
6857 if (gp_offset
< 0 || end_offset
< 0)
6859 ("gp_offset (%ld) or end_offset (%ld) is less than zero",
6860 (long) gp_offset
, (long) end_offset
);
6862 /* If we see a large frame in mips16 mode, we save the registers
6863 before adjusting the stack pointer, and load them afterward. */
6864 else if (TARGET_MIPS16
&& large_offset
> 32767)
6865 base_reg_rtx
= stack_pointer_rtx
, base_offset
= large_offset
;
6867 else if (gp_offset
< 32768)
6868 base_reg_rtx
= stack_pointer_rtx
, base_offset
= 0;
6870 else if (large_reg
!= 0
6871 && (unsigned HOST_WIDE_INT
) (large_offset
- gp_offset
) < 32768
6872 && (unsigned HOST_WIDE_INT
) (large_offset
- end_offset
) < 32768)
6874 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6875 base_offset
= large_offset
;
6876 if (Pmode
== DImode
)
6877 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, large_reg
,
6878 stack_pointer_rtx
));
6880 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, large_reg
,
6881 stack_pointer_rtx
));
6885 base_offset
= gp_offset
;
6886 base_reg_rtx
= mips_add_large_offset_to_sp (base_offset
);
6889 /* When we restore the registers in MIPS16 mode, then if we are
6890 using a frame pointer, and this is not a large frame, the
6891 current stack pointer will be offset by
6892 current_function_outgoing_args_size. Doing it this way lets
6893 us avoid offsetting the frame pointer before copying it into
6894 the stack pointer; there is no instruction to set the stack
6895 pointer to the sum of a register and a constant. */
6898 && frame_pointer_needed
6899 && large_offset
<= 32767)
6900 base_offset
+= current_function_outgoing_args_size
;
6902 for (regno
= GP_REG_LAST
; regno
>= GP_REG_FIRST
; regno
--)
6904 if (BITSET_P (mask
, regno
- GP_REG_FIRST
))
6908 = gen_rtx (MEM
, gpr_mode
,
6909 gen_rtx (PLUS
, Pmode
, base_reg_rtx
,
6910 GEN_INT (gp_offset
- base_offset
)));
6912 if (! current_function_calls_eh_return
)
6913 RTX_UNCHANGING_P (mem_rtx
) = 1;
6915 /* The mips16 does not have an instruction to load
6916 $31, so we load $7 instead, and work things out
6917 in mips_expand_epilogue. */
6918 if (TARGET_MIPS16
&& ! store_p
&& regno
== GP_REG_FIRST
+ 31)
6919 reg_rtx
= gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 7);
6920 /* The mips16 sometimes needs to save $18. */
6921 else if (TARGET_MIPS16
6922 && regno
!= GP_REG_FIRST
+ 31
6923 && ! M16_REG_P (regno
))
6926 reg_rtx
= gen_rtx (REG
, gpr_mode
, 6);
6929 reg_rtx
= gen_rtx (REG
, gpr_mode
, 3);
6930 emit_move_insn (reg_rtx
,
6931 gen_rtx (REG
, gpr_mode
, regno
));
6935 reg_rtx
= gen_rtx (REG
, gpr_mode
, regno
);
6938 mips_emit_frame_related_store (mem_rtx
, reg_rtx
, gp_offset
);
6941 emit_move_insn (reg_rtx
, mem_rtx
);
6943 && regno
!= GP_REG_FIRST
+ 31
6944 && ! M16_REG_P (regno
))
6945 emit_move_insn (gen_rtx (REG
, gpr_mode
, regno
),
6949 /* If the restore is being supressed, still take into account
6950 the offset at which it is stored. */
6951 if (BITSET_P (real_mask
, regno
- GP_REG_FIRST
))
6952 gp_offset
-= GET_MODE_SIZE (gpr_mode
);
6956 base_reg_rtx
= 0, base_offset
= 0;
6958 /* Save floating point registers if needed. */
6961 /* Pick which pointer to use as a base register. */
6962 fp_offset
= current_frame_info
.fp_sp_offset
;
6963 end_offset
= fp_offset
- (current_frame_info
.fp_reg_size
6964 - UNITS_PER_FPVALUE
);
6966 if (fp_offset
< 0 || end_offset
< 0)
6968 ("fp_offset (%ld) or end_offset (%ld) is less than zero",
6969 (long) fp_offset
, (long) end_offset
);
6971 else if (fp_offset
< 32768)
6972 base_reg_rtx
= stack_pointer_rtx
, base_offset
= 0;
6974 else if (base_reg_rtx
!= 0
6975 && (unsigned HOST_WIDE_INT
) (base_offset
- fp_offset
) < 32768
6976 && (unsigned HOST_WIDE_INT
) (base_offset
- end_offset
) < 32768)
6977 ; /* already set up for gp registers above */
6979 else if (large_reg
!= 0
6980 && (unsigned HOST_WIDE_INT
) (large_offset
- fp_offset
) < 32768
6981 && (unsigned HOST_WIDE_INT
) (large_offset
- end_offset
) < 32768)
6983 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6984 base_offset
= large_offset
;
6985 if (Pmode
== DImode
)
6986 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, large_reg
,
6987 stack_pointer_rtx
));
6989 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, large_reg
,
6990 stack_pointer_rtx
));
6994 base_offset
= fp_offset
;
6995 base_reg_rtx
= mips_add_large_offset_to_sp (fp_offset
);
6998 /* This loop must iterate over the same space as its companion in
6999 compute_frame_size. */
7000 for (regno
= (FP_REG_LAST
- FP_INC
+ 1);
7001 regno
>= FP_REG_FIRST
;
7003 if (BITSET_P (fmask
, regno
- FP_REG_FIRST
))
7005 enum machine_mode sz
= TARGET_SINGLE_FLOAT
? SFmode
: DFmode
;
7006 rtx reg_rtx
= gen_rtx (REG
, sz
, regno
);
7007 rtx mem_rtx
= gen_rtx (MEM
, sz
,
7008 gen_rtx (PLUS
, Pmode
, base_reg_rtx
,
7011 if (! current_function_calls_eh_return
)
7012 RTX_UNCHANGING_P (mem_rtx
) = 1;
7015 mips_emit_frame_related_store (mem_rtx
, reg_rtx
, fp_offset
);
7017 emit_move_insn (reg_rtx
, mem_rtx
);
7019 fp_offset
-= UNITS_PER_FPVALUE
;
7024 /* Set up the stack and frame (if desired) for the function. */
7027 mips_output_function_prologue (file
, size
)
7029 HOST_WIDE_INT size ATTRIBUTE_UNUSED
;
7031 #ifndef FUNCTION_NAME_ALREADY_DECLARED
7034 HOST_WIDE_INT tsize
= current_frame_info
.total_size
;
7036 ASM_OUTPUT_SOURCE_FILENAME (file
, DECL_SOURCE_FILE (current_function_decl
));
7038 #ifdef SDB_DEBUGGING_INFO
7039 if (debug_info_level
!= DINFO_LEVEL_TERSE
&& write_symbols
== SDB_DEBUG
)
7040 ASM_OUTPUT_SOURCE_LINE (file
, DECL_SOURCE_LINE (current_function_decl
));
7043 /* In mips16 mode, we may need to generate a 32 bit to handle
7044 floating point arguments. The linker will arrange for any 32 bit
7045 functions to call this stub, which will then jump to the 16 bit
7047 if (TARGET_MIPS16
&& !TARGET_SOFT_FLOAT
7048 && current_function_args_info
.fp_code
!= 0)
7049 build_mips16_function_stub (file
);
7051 inside_function
= 1;
7053 #ifndef FUNCTION_NAME_ALREADY_DECLARED
7054 /* Get the function name the same way that toplev.c does before calling
7055 assemble_start_function. This is needed so that the name used here
7056 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
7057 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
7059 if (!flag_inhibit_size_directive
)
7061 fputs ("\t.ent\t", file
);
7062 assemble_name (file
, fnname
);
7066 assemble_name (file
, fnname
);
7067 fputs (":\n", file
);
7070 if (!flag_inhibit_size_directive
)
7072 /* .frame FRAMEREG, FRAMESIZE, RETREG */
7074 "\t.frame\t%s,%ld,%s\t\t# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
7075 (reg_names
[(frame_pointer_needed
)
7076 ? HARD_FRAME_POINTER_REGNUM
: STACK_POINTER_REGNUM
]),
7077 ((frame_pointer_needed
&& TARGET_MIPS16
)
7078 ? ((long) tsize
- current_function_outgoing_args_size
)
7080 reg_names
[GP_REG_FIRST
+ 31],
7081 current_frame_info
.var_size
,
7082 current_frame_info
.num_gp
,
7083 current_frame_info
.num_fp
,
7084 current_function_outgoing_args_size
,
7085 current_frame_info
.extra_size
);
7087 /* .mask MASK, GPOFFSET; .fmask FPOFFSET */
7088 fprintf (file
, "\t.mask\t0x%08lx,%ld\n\t.fmask\t0x%08lx,%ld\n",
7089 current_frame_info
.mask
,
7090 current_frame_info
.gp_save_offset
,
7091 current_frame_info
.fmask
,
7092 current_frame_info
.fp_save_offset
);
7095 OLD_SP == *FRAMEREG + FRAMESIZE => can find old_sp from nominated FP reg.
7096 HIGHEST_GP_SAVED == *FRAMEREG + FRAMESIZE + GPOFFSET => can find saved regs. */
7099 if (mips_entry
&& ! mips_can_use_return_insn ())
7101 int save16
= BITSET_P (current_frame_info
.mask
, 16);
7102 int save17
= BITSET_P (current_frame_info
.mask
, 17);
7103 int save31
= BITSET_P (current_frame_info
.mask
, 31);
7107 /* Look through the initial insns to see if any of them store
7108 the function parameters into the incoming parameter storage
7109 area. If they do, we delete the insn, and save the register
7110 using the entry pseudo-instruction instead. We don't try to
7111 look past a label, jump, or call. */
7112 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
7114 rtx note
, set
, src
, dest
, base
, offset
;
7117 if (GET_CODE (insn
) == CODE_LABEL
7118 || GET_CODE (insn
) == JUMP_INSN
7119 || GET_CODE (insn
) == CALL_INSN
)
7121 if (GET_CODE (insn
) != INSN
)
7123 set
= PATTERN (insn
);
7124 if (GET_CODE (set
) != SET
)
7127 /* An insn storing a function parameter will still have a
7128 REG_EQUIV note on it mentioning the argument pointer. */
7129 note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
);
7130 if (note
== NULL_RTX
)
7132 if (! reg_mentioned_p (arg_pointer_rtx
, XEXP (note
, 0)))
7135 src
= SET_SRC (set
);
7136 if (GET_CODE (src
) != REG
7137 || REGNO (src
) < GP_REG_FIRST
+ 4
7138 || REGNO (src
) > GP_REG_FIRST
+ 7)
7141 dest
= SET_DEST (set
);
7142 if (GET_CODE (dest
) != MEM
)
7144 if (GET_MODE_SIZE (GET_MODE (dest
)) == (unsigned) UNITS_PER_WORD
)
7146 else if (GET_MODE_SIZE (GET_MODE (dest
)) == (unsigned)2 * UNITS_PER_WORD
7147 && REGNO (src
) < GP_REG_FIRST
+ 7)
7151 offset
= const0_rtx
;
7152 base
= eliminate_constant_term (XEXP (dest
, 0), &offset
);
7153 if (GET_CODE (base
) != REG
7154 || GET_CODE (offset
) != CONST_INT
)
7156 if (REGNO (base
) == (unsigned) STACK_POINTER_REGNUM
7157 && INTVAL (offset
) == tsize
+ (REGNO (src
) - 4) * UNITS_PER_WORD
)
7159 else if (REGNO (base
) == (unsigned) HARD_FRAME_POINTER_REGNUM
7162 + (REGNO (src
) - 4) * UNITS_PER_WORD
7163 - current_function_outgoing_args_size
)))
7168 /* This insn stores a parameter onto the stack, in the same
7169 location where the entry pseudo-instruction will put it.
7170 Delete the insn, and arrange to tell the entry
7171 instruction to save the register. */
7172 PUT_CODE (insn
, NOTE
);
7173 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
7174 NOTE_SOURCE_FILE (insn
) = 0;
7176 hireg
= (REGNO (src
)
7177 + HARD_REGNO_NREGS (REGNO (src
), GET_MODE (dest
))
7179 if (hireg
> savearg
)
7183 /* If this is a varargs function, we need to save all the
7184 registers onto the stack anyhow. */
7185 if (current_function_stdarg
|| current_function_varargs
)
7186 savearg
= GP_REG_FIRST
+ 7;
7188 fprintf (file
, "\tentry\t");
7191 if (savearg
== GP_REG_FIRST
+ 4)
7192 fprintf (file
, "%s", reg_names
[savearg
]);
7194 fprintf (file
, "%s-%s", reg_names
[GP_REG_FIRST
+ 4],
7195 reg_names
[savearg
]);
7197 if (save16
|| save17
)
7200 fprintf (file
, ",");
7201 fprintf (file
, "%s", reg_names
[GP_REG_FIRST
+ 16]);
7203 fprintf (file
, "-%s", reg_names
[GP_REG_FIRST
+ 17]);
7207 if (savearg
> 0 || save16
|| save17
)
7208 fprintf (file
, ",");
7209 fprintf (file
, "%s", reg_names
[GP_REG_FIRST
+ 31]);
7211 fprintf (file
, "\n");
7214 if (TARGET_ABICALLS
&& (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
))
7216 const char *const sp_str
= reg_names
[STACK_POINTER_REGNUM
];
7218 fprintf (file
, "\t.set\tnoreorder\n\t.cpload\t%s\n\t.set\treorder\n",
7219 reg_names
[PIC_FUNCTION_ADDR_REGNUM
]);
7222 fprintf (file
, "\t%s\t%s,%s,%ld\n",
7223 (Pmode
== DImode
? "dsubu" : "subu"),
7224 sp_str
, sp_str
, (long) tsize
);
7225 fprintf (file
, "\t.cprestore %ld\n", current_frame_info
.args_size
);
7228 if (dwarf2out_do_frame ())
7229 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM
, tsize
);
7233 /* Expand the prologue into a bunch of separate insns. */
7236 mips_expand_prologue ()
7239 HOST_WIDE_INT tsize
;
7241 int last_arg_is_vararg_marker
= 0;
7242 tree fndecl
= current_function_decl
;
7243 tree fntype
= TREE_TYPE (fndecl
);
7244 tree fnargs
= DECL_ARGUMENTS (fndecl
);
7249 CUMULATIVE_ARGS args_so_far
;
7250 rtx reg_18_save
= NULL_RTX
;
7251 int store_args_on_stack
= (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
7252 && (! mips_entry
|| mips_can_use_return_insn ());
7254 /* If struct value address is treated as the first argument, make it so. */
7255 if (aggregate_value_p (DECL_RESULT (fndecl
))
7256 && ! current_function_returns_pcc_struct
7257 && struct_value_incoming_rtx
== 0)
7259 tree type
= build_pointer_type (fntype
);
7260 tree function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
7262 DECL_ARG_TYPE (function_result_decl
) = type
;
7263 TREE_CHAIN (function_result_decl
) = fnargs
;
7264 fnargs
= function_result_decl
;
7267 /* For arguments passed in registers, find the register number
7268 of the first argument in the variable part of the argument list,
7269 otherwise GP_ARG_LAST+1. Note also if the last argument is
7270 the varargs special argument, and treat it as part of the
7273 This is only needed if store_args_on_stack is true. */
7275 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
7276 regno
= GP_ARG_FIRST
;
7278 for (cur_arg
= fnargs
; cur_arg
!= 0; cur_arg
= next_arg
)
7280 tree passed_type
= DECL_ARG_TYPE (cur_arg
);
7281 enum machine_mode passed_mode
= TYPE_MODE (passed_type
);
7284 if (TREE_ADDRESSABLE (passed_type
))
7286 passed_type
= build_pointer_type (passed_type
);
7287 passed_mode
= Pmode
;
7290 entry_parm
= FUNCTION_ARG (args_so_far
, passed_mode
, passed_type
, 1);
7292 FUNCTION_ARG_ADVANCE (args_so_far
, passed_mode
, passed_type
, 1);
7293 next_arg
= TREE_CHAIN (cur_arg
);
7295 if (entry_parm
&& store_args_on_stack
)
7298 && DECL_NAME (cur_arg
)
7299 && ((0 == strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
7300 "__builtin_va_alist"))
7301 || (0 == strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
7304 last_arg_is_vararg_marker
= 1;
7305 if (GET_CODE (entry_parm
) == REG
)
7306 regno
= REGNO (entry_parm
);
7308 regno
= GP_ARG_LAST
+ 1;
7315 if (GET_CODE (entry_parm
) != REG
)
7318 /* passed in a register, so will get homed automatically */
7319 if (GET_MODE (entry_parm
) == BLKmode
)
7320 words
= (int_size_in_bytes (passed_type
) + 3) / 4;
7322 words
= (GET_MODE_SIZE (GET_MODE (entry_parm
)) + 3) / 4;
7324 regno
= REGNO (entry_parm
) + words
- 1;
7329 regno
= GP_ARG_LAST
+1;
7334 /* In order to pass small structures by value in registers compatibly with
7335 the MIPS compiler, we need to shift the value into the high part of the
7336 register. Function_arg has encoded a PARALLEL rtx, holding a vector of
7337 adjustments to be made as the next_arg_reg variable, so we split up the
7338 insns, and emit them separately. */
7340 next_arg_reg
= FUNCTION_ARG (args_so_far
, VOIDmode
, void_type_node
, 1);
7341 if (next_arg_reg
!= 0 && GET_CODE (next_arg_reg
) == PARALLEL
)
7343 rtvec adjust
= XVEC (next_arg_reg
, 0);
7344 int num
= GET_NUM_ELEM (adjust
);
7346 for (i
= 0; i
< num
; i
++)
7350 pattern
= RTVEC_ELT (adjust
, i
);
7351 if (GET_CODE (pattern
) != SET
7352 || GET_CODE (SET_SRC (pattern
)) != ASHIFT
)
7353 abort_with_insn (pattern
, "insn is not a shift");
7354 PUT_CODE (SET_SRC (pattern
), ASHIFTRT
);
7356 insn
= emit_insn (pattern
);
7358 /* Global life information isn't valid at this point, so we
7359 can't check whether these shifts are actually used. Mark
7360 them MAYBE_DEAD so that flow2 will remove them, and not
7361 complain about dead code in the prologue. */
7362 REG_NOTES(insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7367 tsize
= compute_frame_size (get_frame_size ());
7369 /* If this function is a varargs function, store any registers that
7370 would normally hold arguments ($4 - $7) on the stack. */
7371 if (store_args_on_stack
7372 && ((TYPE_ARG_TYPES (fntype
) != 0
7373 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
7375 || last_arg_is_vararg_marker
))
7377 int offset
= (regno
- GP_ARG_FIRST
) * UNITS_PER_WORD
;
7378 rtx ptr
= stack_pointer_rtx
;
7380 /* If we are doing svr4-abi, sp has already been decremented by tsize. */
7381 if (TARGET_ABICALLS
)
7384 for (; regno
<= GP_ARG_LAST
; regno
++)
7387 ptr
= gen_rtx (PLUS
, Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
7388 emit_move_insn (gen_rtx (MEM
, gpr_mode
, ptr
),
7389 gen_rtx (REG
, gpr_mode
, regno
));
7391 offset
+= GET_MODE_SIZE (gpr_mode
);
7395 /* If we are using the entry pseudo instruction, it will
7396 automatically subtract 32 from the stack pointer, so we don't
7397 need to. The entry pseudo instruction is emitted by
7398 function_prologue. */
7399 if (mips_entry
&& ! mips_can_use_return_insn ())
7401 if (tsize
> 0 && tsize
<= 32 && frame_pointer_needed
)
7405 /* If we are using a frame pointer with a small stack frame,
7406 we need to initialize it here since it won't be done
7408 if (TARGET_MIPS16
&& current_function_outgoing_args_size
!= 0)
7410 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7411 if (Pmode
== DImode
)
7412 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7416 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7420 else if (Pmode
== DImode
)
7421 insn
= emit_insn (gen_movdi (hard_frame_pointer_rtx
,
7422 stack_pointer_rtx
));
7424 insn
= emit_insn (gen_movsi (hard_frame_pointer_rtx
,
7425 stack_pointer_rtx
));
7427 RTX_FRAME_RELATED_P (insn
) = 1;
7430 /* We may need to save $18, if it is used to call a function
7431 which may return a floating point value. Set up a sequence
7432 of instructions to do so. Later on we emit them at the right
7434 if (TARGET_MIPS16
&& BITSET_P (current_frame_info
.mask
, 18))
7436 rtx reg_rtx
= gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 3);
7437 long gp_offset
, base_offset
;
7439 gp_offset
= current_frame_info
.gp_sp_offset
;
7440 if (BITSET_P (current_frame_info
.mask
, 16))
7441 gp_offset
-= UNITS_PER_WORD
;
7442 if (BITSET_P (current_frame_info
.mask
, 17))
7443 gp_offset
-= UNITS_PER_WORD
;
7444 if (BITSET_P (current_frame_info
.mask
, 31))
7445 gp_offset
-= UNITS_PER_WORD
;
7447 base_offset
= tsize
;
7451 emit_move_insn (reg_rtx
,
7452 gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 18));
7453 emit_move_insn (gen_rtx (MEM
, gpr_mode
,
7454 gen_rtx (PLUS
, Pmode
, stack_pointer_rtx
,
7458 reg_18_save
= gen_sequence ();
7467 if (reg_18_save
!= NULL_RTX
)
7468 emit_insn (reg_18_save
);
7474 rtx tsize_rtx
= GEN_INT (tsize
);
7476 /* If we are doing svr4-abi, sp move is done by
7477 function_prologue. In mips16 mode with a large frame, we
7478 save the registers before adjusting the stack. */
7479 if ((!TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7480 && (!TARGET_MIPS16
|| tsize
<= 32767))
7482 rtx adjustment_rtx
, insn
, dwarf_pattern
;
7486 adjustment_rtx
= gen_rtx (REG
, Pmode
, MIPS_TEMP1_REGNUM
);
7487 emit_move_insn (adjustment_rtx
, tsize_rtx
);
7490 adjustment_rtx
= tsize_rtx
;
7492 if (Pmode
== DImode
)
7493 insn
= emit_insn (gen_subdi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7496 insn
= emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7499 dwarf_pattern
= gen_rtx_SET (Pmode
, stack_pointer_rtx
,
7500 plus_constant (stack_pointer_rtx
,
7503 mips_annotate_frame_insn (insn
, dwarf_pattern
);
7507 save_restore_insns (1, tmp_rtx
, tsize
);
7508 else if (reg_18_save
!= NULL_RTX
)
7509 emit_insn (reg_18_save
);
7511 if ((!TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7517 if (!frame_pointer_needed
)
7520 reg_rtx
= gen_rtx (REG
, Pmode
, 3);
7521 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7522 emit_move_insn (reg_rtx
, tsize_rtx
);
7523 if (Pmode
== DImode
)
7524 emit_insn (gen_subdi3 (hard_frame_pointer_rtx
,
7525 hard_frame_pointer_rtx
,
7528 emit_insn (gen_subsi3 (hard_frame_pointer_rtx
,
7529 hard_frame_pointer_rtx
,
7531 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
7534 if (frame_pointer_needed
)
7538 /* On the mips16, we encourage the use of unextended
7539 instructions when using the frame pointer by pointing the
7540 frame pointer ahead of the argument space allocated on
7542 if ((! TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7546 /* In this case, we have already copied the stack
7547 pointer into the frame pointer, above. We need only
7548 adjust for the outgoing argument size. */
7549 if (current_function_outgoing_args_size
!= 0)
7551 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7552 if (Pmode
== DImode
)
7553 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7554 hard_frame_pointer_rtx
,
7557 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7558 hard_frame_pointer_rtx
,
7562 else if (TARGET_MIPS16
&& current_function_outgoing_args_size
!= 0)
7564 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7565 if (Pmode
== DImode
)
7566 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7570 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7574 else if (Pmode
== DImode
)
7575 insn
= emit_insn (gen_movdi (hard_frame_pointer_rtx
,
7576 stack_pointer_rtx
));
7578 insn
= emit_insn (gen_movsi (hard_frame_pointer_rtx
,
7579 stack_pointer_rtx
));
7582 RTX_FRAME_RELATED_P (insn
) = 1;
7585 if (TARGET_ABICALLS
&& (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7586 emit_insn (gen_loadgp (XEXP (DECL_RTL (current_function_decl
), 0),
7587 gen_rtx_REG (DImode
, 25)));
7590 /* If we are profiling, make sure no instructions are scheduled before
7591 the call to mcount. */
7593 if (current_function_profile
)
7594 emit_insn (gen_blockage ());
7597 /* Do any necessary cleanup after a function to restore stack, frame,
7600 #define RA_MASK BITMASK_HIGH /* 1 << 31 */
7601 #define PIC_OFFSET_TABLE_MASK (1 << (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
7604 mips_output_function_epilogue (file
, size
)
7605 FILE *file ATTRIBUTE_UNUSED
;
7606 HOST_WIDE_INT size ATTRIBUTE_UNUSED
;
7608 const char *fnname
= ""; /* FIXME: Correct initialisation? */
7610 #ifndef FUNCTION_NAME_ALREADY_DECLARED
7611 /* Get the function name the same way that toplev.c does before calling
7612 assemble_start_function. This is needed so that the name used here
7613 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
7614 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
7616 if (!flag_inhibit_size_directive
)
7618 fputs ("\t.end\t", file
);
7619 assemble_name (file
, fnname
);
7626 int num_gp_regs
= current_frame_info
.gp_reg_size
/ 4;
7627 int num_fp_regs
= current_frame_info
.fp_reg_size
/ 8;
7628 int num_regs
= num_gp_regs
+ num_fp_regs
;
7629 const char *name
= fnname
;
7634 dslots_load_total
+= num_regs
;
7637 "%-20s fp=%c leaf=%c alloca=%c setjmp=%c stack=%4ld arg=%3d reg=%2d/%d delay=%3d/%3dL %3d/%3dJ refs=%3d/%3d/%3d",
7638 name
, frame_pointer_needed
? 'y' : 'n',
7639 (current_frame_info
.mask
& RA_MASK
) != 0 ? 'n' : 'y',
7640 current_function_calls_alloca
? 'y' : 'n',
7641 current_function_calls_setjmp
? 'y' : 'n',
7642 current_frame_info
.total_size
,
7643 current_function_outgoing_args_size
, num_gp_regs
, num_fp_regs
,
7644 dslots_load_total
, dslots_load_filled
,
7645 dslots_jump_total
, dslots_jump_filled
,
7646 num_refs
[0], num_refs
[1], num_refs
[2]);
7648 if (HALF_PIC_NUMBER_PTRS
> prev_half_pic_ptrs
)
7651 " half-pic=%3d", HALF_PIC_NUMBER_PTRS
- prev_half_pic_ptrs
);
7652 prev_half_pic_ptrs
= HALF_PIC_NUMBER_PTRS
;
7655 if (HALF_PIC_NUMBER_REFS
> prev_half_pic_refs
)
7658 " pic-ref=%3d", HALF_PIC_NUMBER_REFS
- prev_half_pic_refs
);
7659 prev_half_pic_refs
= HALF_PIC_NUMBER_REFS
;
7662 fputc ('\n', stderr
);
7665 /* Reset state info for each function. */
7666 inside_function
= 0;
7667 ignore_line_number
= 0;
7668 dslots_load_total
= 0;
7669 dslots_jump_total
= 0;
7670 dslots_load_filled
= 0;
7671 dslots_jump_filled
= 0;
7677 current_frame_info
= zero_frame_info
;
7679 while (string_constants
!= NULL
)
7681 struct string_constant
*next
;
7683 next
= string_constants
->next
;
7684 free (string_constants
);
7685 string_constants
= next
;
7688 /* Restore the output file if optimizing the GP (optimizing the GP causes
7689 the text to be diverted to a tempfile, so that data decls come before
7690 references to the data). */
7691 if (TARGET_FILE_SWITCHING
)
7693 asm_out_file
= asm_out_data_file
;
7698 /* Expand the epilogue into a bunch of separate insns. */
7701 mips_expand_epilogue ()
7703 HOST_WIDE_INT tsize
= current_frame_info
.total_size
;
7704 rtx tsize_rtx
= GEN_INT (tsize
);
7705 rtx tmp_rtx
= (rtx
)0;
7707 if (mips_can_use_return_insn ())
7709 emit_insn (gen_return ());
7713 if (mips_entry
&& ! mips_can_use_return_insn ())
7716 if (tsize
> 32767 && ! TARGET_MIPS16
)
7718 tmp_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP1_REGNUM
);
7719 emit_move_insn (tmp_rtx
, tsize_rtx
);
7720 tsize_rtx
= tmp_rtx
;
7725 long orig_tsize
= tsize
;
7727 if (frame_pointer_needed
)
7729 emit_insn (gen_blockage ());
7731 /* On the mips16, the frame pointer is offset from the stack
7732 pointer by current_function_outgoing_args_size. We
7733 account for that by changing tsize. Note that this can
7734 actually make tsize negative. */
7737 tsize
-= current_function_outgoing_args_size
;
7739 /* If we have a large frame, it's easier to add to $6
7740 than to $sp, since the mips16 has no instruction to
7741 add a register to $sp. */
7742 if (orig_tsize
> 32767)
7744 rtx g6_rtx
= gen_rtx (REG
, Pmode
, GP_REG_FIRST
+ 6);
7746 emit_move_insn (g6_rtx
, GEN_INT (tsize
));
7747 if (Pmode
== DImode
)
7748 emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7749 hard_frame_pointer_rtx
,
7752 emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7753 hard_frame_pointer_rtx
,
7758 if (tsize
&& tsize
!= orig_tsize
)
7759 tsize_rtx
= GEN_INT (tsize
);
7762 if (Pmode
== DImode
)
7763 emit_insn (gen_movdi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
7765 emit_insn (gen_movsi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
7768 /* The GP/PIC register is implicitly used by all SYMBOL_REFs, so if we
7769 are going to restore it, then we must emit a blockage insn to
7770 prevent the scheduler from moving the restore out of the epilogue. */
7771 else if (TARGET_ABICALLS
&& mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
7772 && (current_frame_info
.mask
7773 & (1L << (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
))))
7774 emit_insn (gen_blockage ());
7776 save_restore_insns (0, tmp_rtx
, orig_tsize
);
7778 /* In mips16 mode with a large frame, we adjust the stack
7779 pointer before restoring the registers. In this case, we
7780 should always be using a frame pointer, so everything should
7781 have been handled above. */
7782 if (tsize
> 32767 && TARGET_MIPS16
)
7785 if (current_function_calls_eh_return
)
7787 rtx eh_ofs
= EH_RETURN_STACKADJ_RTX
;
7788 if (Pmode
== DImode
)
7789 emit_insn (gen_adddi3 (eh_ofs
, eh_ofs
, tsize_rtx
));
7791 emit_insn (gen_addsi3 (eh_ofs
, eh_ofs
, tsize_rtx
));
7795 emit_insn (gen_blockage ());
7797 if (tsize
!= 0 || current_function_calls_eh_return
)
7801 if (Pmode
== DImode
)
7802 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7805 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7810 /* We need to work around not being able to add a register
7811 to the stack pointer directly. Use register $6 as an
7812 intermediate step. */
7814 rtx g6_rtx
= gen_rtx (REG
, Pmode
, GP_REG_FIRST
+ 6);
7816 if (Pmode
== DImode
)
7818 emit_insn (gen_movdi (g6_rtx
, stack_pointer_rtx
));
7819 emit_insn (gen_adddi3 (g6_rtx
, g6_rtx
, tsize_rtx
));
7820 emit_insn (gen_movdi (stack_pointer_rtx
, g6_rtx
));
7824 emit_insn (gen_movsi (g6_rtx
, stack_pointer_rtx
));
7825 emit_insn (gen_addsi3 (g6_rtx
, g6_rtx
, tsize_rtx
));
7826 emit_insn (gen_movsi (stack_pointer_rtx
, g6_rtx
));
7833 /* The mips16 loads the return address into $7, not $31. */
7834 if (TARGET_MIPS16
&& (current_frame_info
.mask
& RA_MASK
) != 0)
7835 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
7836 GP_REG_FIRST
+ 7)));
7838 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
7839 GP_REG_FIRST
+ 31)));
7842 /* Return nonzero if this function is known to have a null epilogue.
7843 This allows the optimizer to omit jumps to jumps if no stack
7847 mips_can_use_return_insn ()
7851 if (! reload_completed
)
7854 if (regs_ever_live
[31] || current_function_profile
)
7857 return_type
= DECL_RESULT (current_function_decl
);
7859 /* In mips16 mode, a function which returns a floating point value
7860 needs to arrange to copy the return value into the floating point
7863 && mips16_hard_float
7864 && ! aggregate_value_p (return_type
)
7865 && GET_MODE_CLASS (DECL_MODE (return_type
)) == MODE_FLOAT
7866 && GET_MODE_SIZE (DECL_MODE (return_type
)) <= UNITS_PER_FPVALUE
)
7869 if (current_frame_info
.initialized
)
7870 return current_frame_info
.total_size
== 0;
7872 return compute_frame_size (get_frame_size ()) == 0;
7875 /* Returns non-zero if X contains a SYMBOL_REF. */
7878 symbolic_expression_p (x
)
7881 if (GET_CODE (x
) == SYMBOL_REF
)
7884 if (GET_CODE (x
) == CONST
)
7885 return symbolic_expression_p (XEXP (x
, 0));
7887 if (GET_RTX_CLASS (GET_CODE (x
)) == '1')
7888 return symbolic_expression_p (XEXP (x
, 0));
7890 if (GET_RTX_CLASS (GET_CODE (x
)) == 'c'
7891 || GET_RTX_CLASS (GET_CODE (x
)) == '2')
7892 return (symbolic_expression_p (XEXP (x
, 0))
7893 || symbolic_expression_p (XEXP (x
, 1)));
7898 /* Choose the section to use for the constant rtx expression X that has
7902 mips_select_rtx_section (mode
, x
, align
)
7903 enum machine_mode mode
;
7905 unsigned HOST_WIDE_INT align
;
7909 /* In mips16 mode, the constant table always goes in the same section
7910 as the function, so that constants can be loaded using PC relative
7912 function_section (current_function_decl
);
7914 else if (TARGET_EMBEDDED_DATA
)
7916 /* For embedded applications, always put constants in read-only data,
7917 in order to reduce RAM usage. */
7918 mergeable_constant_section (mode
, align
, 0);
7922 /* For hosted applications, always put constants in small data if
7923 possible, as this gives the best performance. */
7924 /* ??? Consider using mergable small data sections. */
7926 if (GET_MODE_SIZE (mode
) <= (unsigned) mips_section_threshold
7927 && mips_section_threshold
> 0)
7928 SMALL_DATA_SECTION ();
7929 else if (flag_pic
&& symbolic_expression_p (x
))
7931 if (targetm
.have_named_sections
)
7932 named_section (NULL_TREE
, ".data.rel.ro", 3);
7937 mergeable_constant_section (mode
, align
, 0);
7941 /* Choose the section to use for DECL. RELOC is true if its value contains
7942 any relocatable expression.
7944 Some of the logic used here needs to be replicated in
7945 mips_encode_section_info so that references to these symbols are
7946 done correctly. Specifically, at least all symbols assigned here
7947 to rom (.text and/or .rodata) must not be referenced via
7948 mips_encode_section_info with %gprel, as the rom might be too far
7951 If you need to make a change here, you probably should check
7952 mips_encode_section_info to see if it needs a similar change.
7954 ??? This would be fixed by implementing targetm.is_small_data_p. */
7957 mips_select_section (decl
, reloc
, align
)
7960 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
7962 int size
= int_size_in_bytes (TREE_TYPE (decl
));
7964 if ((TARGET_EMBEDDED_PIC
|| TARGET_MIPS16
)
7965 && TREE_CODE (decl
) == STRING_CST
7966 && !flag_writable_strings
)
7967 /* For embedded position independent code, put constant strings in the
7968 text section, because the data section is limited to 64K in size.
7969 For mips16 code, put strings in the text section so that a PC
7970 relative load instruction can be used to get their address. */
7972 else if (TARGET_EMBEDDED_DATA
)
7974 /* For embedded applications, always put an object in read-only data
7975 if possible, in order to reduce RAM usage. */
7977 if (((TREE_CODE (decl
) == VAR_DECL
7978 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
7979 && DECL_INITIAL (decl
)
7980 && (DECL_INITIAL (decl
) == error_mark_node
7981 || TREE_CONSTANT (DECL_INITIAL (decl
))))
7982 /* Deal with calls from output_constant_def_contents. */
7983 || (TREE_CODE (decl
) != VAR_DECL
7984 && (TREE_CODE (decl
) != STRING_CST
7985 || !flag_writable_strings
)))
7986 && ! (flag_pic
&& reloc
))
7987 readonly_data_section ();
7988 else if (size
> 0 && size
<= mips_section_threshold
)
7989 SMALL_DATA_SECTION ();
7995 /* For hosted applications, always put an object in small data if
7996 possible, as this gives the best performance. */
7998 if (size
> 0 && size
<= mips_section_threshold
)
7999 SMALL_DATA_SECTION ();
8000 else if (((TREE_CODE (decl
) == VAR_DECL
8001 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
8002 && DECL_INITIAL (decl
)
8003 && (DECL_INITIAL (decl
) == error_mark_node
8004 || TREE_CONSTANT (DECL_INITIAL (decl
))))
8005 /* Deal with calls from output_constant_def_contents. */
8006 || (TREE_CODE (decl
) != VAR_DECL
8007 && (TREE_CODE (decl
) != STRING_CST
8008 || !flag_writable_strings
)))
8009 && ! (flag_pic
&& reloc
))
8010 readonly_data_section ();
8016 /* When optimizing for the $gp pointer, SYMBOL_REF_FLAG is set for all
8019 When generating embedded PIC code, SYMBOL_REF_FLAG is set for
8020 symbols which are not in the .text section.
8022 When generating mips16 code, SYMBOL_REF_FLAG is set for string
8023 constants which are put in the .text section. We also record the
8024 total length of all such strings; this total is used to decide
8025 whether we need to split the constant table, and need not be
8028 When not mips16 code nor embedded PIC, if a symbol is in a
8029 gp addresable section, SYMBOL_REF_FLAG is set prevent gcc from
8030 splitting the reference so that gas can generate a gp relative
8033 When TARGET_EMBEDDED_DATA is set, we assume that all const
8034 variables will be stored in ROM, which is too far from %gp to use
8035 %gprel addressing. Note that (1) we include "extern const"
8036 variables in this, which mips_select_section doesn't, and (2) we
8037 can't always tell if they're really const (they might be const C++
8038 objects with non-const constructors), so we err on the side of
8039 caution and won't use %gprel anyway (otherwise we'd have to defer
8040 this decision to the linker/loader). The handling of extern consts
8041 is why the DECL_INITIAL macros differ from mips_select_section. */
8044 mips_encode_section_info (decl
, first
)
8050 if (first
&& TREE_CODE (decl
) == STRING_CST
8051 && ! flag_writable_strings
8052 /* If this string is from a function, and the function will
8053 go in a gnu linkonce section, then we can't directly
8054 access the string. This gets an assembler error
8055 "unsupported PC relative reference to different section".
8056 If we modify SELECT_SECTION to put it in function_section
8057 instead of text_section, it still fails because
8058 DECL_SECTION_NAME isn't set until assemble_start_function.
8059 If we fix that, it still fails because strings are shared
8060 among multiple functions, and we have cross section
8061 references again. We force it to work by putting string
8062 addresses in the constant pool and indirecting. */
8063 && (! current_function_decl
8064 || ! DECL_ONE_ONLY (current_function_decl
)))
8066 SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (decl
), 0)) = 1;
8067 mips_string_length
+= TREE_STRING_LENGTH (decl
);
8071 if (TARGET_EMBEDDED_DATA
8072 && (TREE_CODE (decl
) == VAR_DECL
8073 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
))
8074 && (!DECL_INITIAL (decl
)
8075 || TREE_CONSTANT (DECL_INITIAL (decl
))))
8077 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl
), 0)) = 0;
8080 else if (TARGET_EMBEDDED_PIC
)
8082 if (TREE_CODE (decl
) == VAR_DECL
)
8083 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl
), 0)) = 1;
8084 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
8085 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl
), 0)) = 0;
8086 else if (TREE_CODE (decl
) == STRING_CST
8087 && ! flag_writable_strings
)
8088 SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (decl
), 0)) = 0;
8090 SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (decl
), 0)) = 1;
8093 else if (TREE_CODE (decl
) == VAR_DECL
8094 && DECL_SECTION_NAME (decl
) != NULL_TREE
8095 && (0 == strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
8097 || 0 == strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
8100 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl
), 0)) = 1;
8103 /* We can not perform GP optimizations on variables which are in
8104 specific sections, except for .sdata and .sbss which are
8106 else if (TARGET_GP_OPT
&& TREE_CODE (decl
) == VAR_DECL
8107 && DECL_SECTION_NAME (decl
) == NULL_TREE
8108 && ! (TARGET_MIPS16
&& TREE_PUBLIC (decl
)
8109 && (DECL_COMMON (decl
)
8110 || DECL_ONE_ONLY (decl
)
8111 || DECL_WEAK (decl
))))
8113 int size
= int_size_in_bytes (TREE_TYPE (decl
));
8115 if (size
> 0 && size
<= mips_section_threshold
)
8116 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl
), 0)) = 1;
8119 else if (HALF_PIC_P ())
8122 HALF_PIC_ENCODE (decl
);
8126 /* Return register to use for a function return value with VALTYPE for
8127 function FUNC. MODE is used instead of VALTYPE for LIBCALLs. */
8130 mips_function_value (valtype
, func
, mode
)
8132 tree func ATTRIBUTE_UNUSED
;
8133 enum machine_mode mode
;
8135 int reg
= GP_RETURN
;
8136 enum mode_class mclass
;
8141 mode
= TYPE_MODE (valtype
);
8142 unsignedp
= TREE_UNSIGNED (valtype
);
8144 /* Since we define PROMOTE_FUNCTION_RETURN, we must promote
8145 the mode just as PROMOTE_MODE does. */
8146 mode
= promote_mode (valtype
, mode
, &unsignedp
, 1);
8148 mclass
= GET_MODE_CLASS (mode
);
8150 if (mclass
== MODE_FLOAT
&& GET_MODE_SIZE (mode
) <= UNITS_PER_FPVALUE
)
8153 else if (mclass
== MODE_COMPLEX_FLOAT
8154 && GET_MODE_SIZE (mode
) <= UNITS_PER_FPVALUE
* 2)
8156 enum machine_mode cmode
= GET_MODE_INNER (mode
);
8158 return gen_rtx_PARALLEL
8161 gen_rtx_EXPR_LIST (VOIDmode
,
8162 gen_rtx_REG (cmode
, FP_RETURN
),
8164 gen_rtx_EXPR_LIST (VOIDmode
,
8165 gen_rtx_REG (cmode
, FP_RETURN
+ FP_INC
),
8166 GEN_INT (GET_MODE_SIZE (cmode
)))));
8169 else if (valtype
&& TREE_CODE (valtype
) == RECORD_TYPE
8170 && mips_abi
!= ABI_32
8171 && mips_abi
!= ABI_O64
8172 && mips_abi
!= ABI_EABI
)
8174 /* A struct with only one or two floating point fields is returned in
8175 the floating point registers. */
8176 tree field
, fields
[2];
8179 for (i
= 0, field
= TYPE_FIELDS (valtype
); field
;
8180 field
= TREE_CHAIN (field
))
8182 if (TREE_CODE (field
) != FIELD_DECL
)
8185 if (TREE_CODE (TREE_TYPE (field
)) != REAL_TYPE
|| i
>= 2)
8188 fields
[i
++] = field
;
8191 /* Must check i, so that we reject structures with no elements. */
8196 /* The structure has DImode, but we don't allow DImode values
8197 in FP registers, so we use a PARALLEL even though it isn't
8198 strictly necessary. */
8199 enum machine_mode field_mode
= TYPE_MODE (TREE_TYPE (fields
[0]));
8201 return gen_rtx_PARALLEL
8204 gen_rtx_EXPR_LIST (VOIDmode
,
8205 gen_rtx_REG (field_mode
,
8212 enum machine_mode first_mode
8213 = TYPE_MODE (TREE_TYPE (fields
[0]));
8214 enum machine_mode second_mode
8215 = TYPE_MODE (TREE_TYPE (fields
[1]));
8216 HOST_WIDE_INT first_offset
= int_byte_position (fields
[0]);
8217 HOST_WIDE_INT second_offset
= int_byte_position (fields
[1]);
8219 return gen_rtx_PARALLEL
8222 gen_rtx_EXPR_LIST (VOIDmode
,
8223 gen_rtx_REG (first_mode
,
8225 GEN_INT (first_offset
)),
8226 gen_rtx_EXPR_LIST (VOIDmode
,
8227 gen_rtx_REG (second_mode
,
8229 GEN_INT (second_offset
))));
8234 return gen_rtx_REG (mode
, reg
);
8237 /* The implementation of FUNCTION_ARG_PASS_BY_REFERENCE. Return
8238 nonzero when an argument must be passed by reference. */
8241 function_arg_pass_by_reference (cum
, mode
, type
, named
)
8242 const CUMULATIVE_ARGS
*cum
;
8243 enum machine_mode mode
;
8245 int named ATTRIBUTE_UNUSED
;
8249 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
8252 /* We must pass by reference if we would be both passing in registers
8253 and the stack. This is because any subsequent partial arg would be
8254 handled incorrectly in this case.
8256 ??? This is really a kludge. We should either fix GCC so that such
8257 a situation causes an abort and then do something in the MIPS port
8258 to prevent it, or add code to function.c to properly handle the case. */
8259 /* ??? cum can be NULL when called from mips_va_arg. The problem handled
8260 here hopefully is not relevant to mips_va_arg. */
8261 if (cum
&& MUST_PASS_IN_STACK (mode
, type
)
8262 && mips_abi
!= ABI_MEABI
8263 && FUNCTION_ARG (*cum
, mode
, type
, named
) != 0)
8266 /* Otherwise, we only do this if EABI is selected. */
8267 if (mips_abi
!= ABI_EABI
)
8270 /* ??? How should SCmode be handled? */
8271 if (type
== NULL_TREE
|| mode
== DImode
|| mode
== DFmode
)
8274 size
= int_size_in_bytes (type
);
8275 return size
== -1 || size
> UNITS_PER_WORD
;
8278 /* This function returns the register class required for a secondary
8279 register when copying between one of the registers in CLASS, and X,
8280 using MODE. If IN_P is nonzero, the copy is going from X to the
8281 register, otherwise the register is the source. A return value of
8282 NO_REGS means that no secondary register is required. */
8285 mips_secondary_reload_class (class, mode
, x
, in_p
)
8286 enum reg_class
class;
8287 enum machine_mode mode
;
8291 enum reg_class gr_regs
= TARGET_MIPS16
? M16_REGS
: GR_REGS
;
8295 if (GET_CODE (x
) == SIGN_EXTEND
)
8301 /* We may be called with reg_renumber NULL from regclass.
8302 ??? This is probably a bug. */
8304 regno
= true_regnum (x
);
8307 while (GET_CODE (x
) == SUBREG
)
8309 off
+= subreg_regno_offset (REGNO (SUBREG_REG (x
)),
8310 GET_MODE (SUBREG_REG (x
)),
8316 if (GET_CODE (x
) == REG
)
8317 regno
= REGNO (x
) + off
;
8321 else if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
8322 regno
= true_regnum (x
);
8324 gp_reg_p
= TARGET_MIPS16
? M16_REG_P (regno
) : GP_REG_P (regno
);
8326 /* We always require a general register when copying anything to
8327 HILO_REGNUM, except when copying an SImode value from HILO_REGNUM
8328 to a general register, or when copying from register 0. */
8329 if (class == HILO_REG
&& regno
!= GP_REG_FIRST
+ 0)
8332 && GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (SImode
))
8333 ? NO_REGS
: gr_regs
);
8334 else if (regno
== HILO_REGNUM
)
8337 && GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (SImode
))
8338 ? NO_REGS
: gr_regs
);
8340 /* Copying from HI or LO to anywhere other than a general register
8341 requires a general register. */
8342 if (class == HI_REG
|| class == LO_REG
|| class == MD_REGS
)
8344 if (TARGET_MIPS16
&& in_p
)
8346 /* We can't really copy to HI or LO at all in mips16 mode. */
8349 return gp_reg_p
? NO_REGS
: gr_regs
;
8351 if (MD_REG_P (regno
))
8353 if (TARGET_MIPS16
&& ! in_p
)
8355 /* We can't really copy to HI or LO at all in mips16 mode. */
8358 return class == gr_regs
? NO_REGS
: gr_regs
;
8361 /* We can only copy a value to a condition code register from a
8362 floating point register, and even then we require a scratch
8363 floating point register. We can only copy a value out of a
8364 condition code register into a general register. */
8365 if (class == ST_REGS
)
8369 return GP_REG_P (regno
) ? NO_REGS
: GR_REGS
;
8371 if (ST_REG_P (regno
))
8375 return class == GR_REGS
? NO_REGS
: GR_REGS
;
8378 /* In mips16 mode, going between memory and anything but M16_REGS
8379 requires an M16_REG. */
8382 if (class != M16_REGS
&& class != M16_NA_REGS
)
8390 /* The stack pointer isn't a valid operand to an add instruction,
8391 so we need to load it into M16_REGS first. This can happen as
8392 a result of register elimination and form_sum converting
8393 (plus reg (plus SP CONST)) to (plus (plus reg SP) CONST). We
8394 need an extra register if the dest is the same as the other
8395 register. In that case, we can't fix the problem by loading SP
8396 into the dest first. */
8397 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == REG
8398 && GET_CODE (XEXP (x
, 1)) == REG
8399 && (XEXP (x
, 0) == stack_pointer_rtx
8400 || XEXP (x
, 1) == stack_pointer_rtx
))
8401 return (class == M16_REGS
? M16_NA_REGS
: M16_REGS
);
8403 if (class == M16_REGS
|| class == M16_NA_REGS
)
8412 /* This function returns the maximum number of consecutive registers
8413 needed to represent mode MODE in registers of class CLASS. */
8416 mips_class_max_nregs (class, mode
)
8417 enum reg_class
class;
8418 enum machine_mode mode
;
8420 if (class == FP_REGS
)
8423 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
8426 /* For each mips16 function which refers to GP relative symbols, we
8427 use a pseudo register, initialized at the start of the function, to
8428 hold the $gp value. */
8431 mips16_gp_pseudo_reg ()
8433 if (cfun
->machine
->mips16_gp_pseudo_rtx
== NULL_RTX
)
8438 cfun
->machine
->mips16_gp_pseudo_rtx
= gen_reg_rtx (Pmode
);
8439 RTX_UNCHANGING_P (cfun
->machine
->mips16_gp_pseudo_rtx
) = 1;
8441 /* We want to initialize this to a value which gcc will believe
8443 const_gp
= gen_rtx (CONST
, Pmode
,
8444 gen_rtx (REG
, Pmode
, GP_REG_FIRST
+ 28));
8447 emit_move_insn (cfun
->machine
->mips16_gp_pseudo_rtx
,
8449 insn
= gen_sequence ();
8452 push_topmost_sequence ();
8453 /* We need to emit the initialization after the FUNCTION_BEG
8454 note, so that it will be integrated. */
8455 for (scan
= get_insns (); scan
!= NULL_RTX
; scan
= NEXT_INSN (scan
))
8456 if (GET_CODE (scan
) == NOTE
8457 && NOTE_LINE_NUMBER (scan
) == NOTE_INSN_FUNCTION_BEG
)
8459 if (scan
== NULL_RTX
)
8460 scan
= get_insns ();
8461 insn
= emit_insn_after (insn
, scan
);
8462 pop_topmost_sequence ();
8465 return cfun
->machine
->mips16_gp_pseudo_rtx
;
8468 /* Return an RTX which represents the signed 16 bit offset from the
8469 $gp register for the given symbol. This is only used on the
8473 mips16_gp_offset (sym
)
8478 if (GET_CODE (sym
) != SYMBOL_REF
8479 || ! SYMBOL_REF_FLAG (sym
))
8482 /* We use a special identifier to represent the value of the gp
8484 gp
= get_identifier ("__mips16_gp_value");
8486 return gen_rtx (CONST
, Pmode
,
8487 gen_rtx (MINUS
, Pmode
, sym
,
8488 gen_rtx (SYMBOL_REF
, Pmode
,
8489 IDENTIFIER_POINTER (gp
))));
8492 /* Return nonzero if the given RTX represents a signed 16 bit offset
8493 from the $gp register. */
8496 mips16_gp_offset_p (x
)
8499 if (GET_CODE (x
) == CONST
)
8502 /* It's OK to add a small integer value to a gp offset. */
8503 if (GET_CODE (x
) == PLUS
)
8505 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
8506 && SMALL_INT (XEXP (x
, 1)))
8507 return mips16_gp_offset_p (XEXP (x
, 0));
8508 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
8509 && SMALL_INT (XEXP (x
, 0)))
8510 return mips16_gp_offset_p (XEXP (x
, 1));
8514 /* Make sure it is in the form SYM - __mips16_gp_value. */
8515 return (GET_CODE (x
) == MINUS
8516 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
8517 && SYMBOL_REF_FLAG (XEXP (x
, 0))
8518 && GET_CODE (XEXP (x
, 1)) == SYMBOL_REF
8519 && strcmp (XSTR (XEXP (x
, 1), 0), "__mips16_gp_value") == 0);
8522 /* Output a GP offset. We don't want to print the subtraction of
8523 __mips16_gp_value; it is implicitly represented by the %gprel which
8524 should have been printed by the caller. */
8527 mips16_output_gp_offset (file
, x
)
8531 if (GET_CODE (x
) == CONST
)
8534 if (GET_CODE (x
) == PLUS
)
8536 mips16_output_gp_offset (file
, XEXP (x
, 0));
8538 mips16_output_gp_offset (file
, XEXP (x
, 1));
8542 if (GET_CODE (x
) == MINUS
8543 && GET_CODE (XEXP (x
, 1)) == SYMBOL_REF
8544 && strcmp (XSTR (XEXP (x
, 1), 0), "__mips16_gp_value") == 0)
8546 mips16_output_gp_offset (file
, XEXP (x
, 0));
8550 output_addr_const (file
, x
);
8553 /* Return nonzero if a constant should not be output until after the
8554 function. This is true of most string constants, so that we can
8555 use a more efficient PC relative reference. However, a static
8556 inline function may never call assemble_function_end to write out
8557 the constant pool, so don't try to postpone the constant in that
8560 ??? It's really a bug that a static inline function can put stuff
8561 in the constant pool even if the function itself is not output.
8563 We record which string constants we've seen, so that we know which
8564 ones might use the more efficient reference. */
8567 mips16_constant_after_function_p (x
)
8570 if (TREE_CODE (x
) == STRING_CST
8571 && ! flag_writable_strings
8572 && current_function_decl
!= 0
8573 && ! DECL_DEFER_OUTPUT (current_function_decl
)
8574 && ! (DECL_INLINE (current_function_decl
)
8575 && ((! TREE_PUBLIC (current_function_decl
)
8576 && ! TREE_ADDRESSABLE (current_function_decl
)
8577 && ! flag_keep_inline_functions
)
8578 || DECL_EXTERNAL (current_function_decl
))))
8580 struct string_constant
*n
;
8582 n
= (struct string_constant
*) xmalloc (sizeof *n
);
8583 n
->label
= XSTR (XEXP (TREE_CST_RTL (x
), 0), 0);
8584 n
->next
= string_constants
;
8585 string_constants
= n
;
8593 /* Validate a constant for the mips16. This rejects general symbolic
8594 addresses, which must be loaded from memory. If ADDR is nonzero,
8595 this should reject anything which is not a legal address. If
8596 ADDEND is nonzero, this is being added to something else. */
8599 mips16_constant (x
, mode
, addr
, addend
)
8601 enum machine_mode mode
;
8605 while (GET_CODE (x
) == CONST
)
8608 switch (GET_CODE (x
))
8614 return (mips16_constant (XEXP (x
, 0), mode
, addr
, 1)
8615 && mips16_constant (XEXP (x
, 1), mode
, addr
, 1));
8618 if (addr
&& GET_MODE_SIZE (mode
) != 4 && GET_MODE_SIZE (mode
) != 8)
8620 if (CONSTANT_POOL_ADDRESS_P (x
))
8623 /* If we aren't looking for a memory address, we can accept a GP
8624 relative symbol, which will have SYMBOL_REF_FLAG set; movsi
8625 knows how to handle this. We can always accept a string
8626 constant, which is the other case in which SYMBOL_REF_FLAG
8630 && SYMBOL_REF_FLAG (x
)
8631 && mode
== (enum machine_mode
) Pmode
)
8634 /* We can accept a string constant, which will have
8635 SYMBOL_REF_FLAG set but must be recognized by name to
8636 distinguish from a GP accessible symbol. The name of a
8637 string constant will have been generated by
8638 ASM_GENERATE_INTERNAL_LABEL as called by output_constant_def. */
8639 if (SYMBOL_REF_FLAG (x
))
8641 const char *name
= XSTR (x
, 0);
8643 return (name
[0] == '*'
8644 && strncmp (name
+ 1, LOCAL_LABEL_PREFIX
,
8645 sizeof LOCAL_LABEL_PREFIX
- 1) == 0);
8651 if (addr
&& GET_MODE_SIZE (mode
) != 4 && GET_MODE_SIZE (mode
) != 8)
8656 if (addr
&& ! addend
)
8658 return INTVAL (x
) > - 0x10000 && INTVAL (x
) <= 0xffff;
8661 /* We need to treat $gp as a legitimate constant, because
8662 mips16_gp_pseudo_reg assumes that. */
8663 return REGNO (x
) == GP_REG_FIRST
+ 28;
8667 /* Write out code to move floating point arguments in or out of
8668 general registers. Output the instructions to FILE. FP_CODE is
8669 the code describing which arguments are present (see the comment at
8670 the definition of CUMULATIVE_ARGS in mips.h). FROM_FP_P is non-zero if
8671 we are copying from the floating point registers. */
8674 mips16_fp_args (file
, fp_code
, from_fp_p
)
8683 /* This code only works for the original 32 bit ABI and the O64 ABI. */
8684 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
8691 gparg
= GP_ARG_FIRST
;
8692 fparg
= FP_ARG_FIRST
;
8693 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
8697 if ((fparg
& 1) != 0)
8699 fprintf (file
, "\t%s\t%s,%s\n", s
,
8700 reg_names
[gparg
], reg_names
[fparg
]);
8702 else if ((f
& 3) == 2)
8705 fprintf (file
, "\td%s\t%s,%s\n", s
,
8706 reg_names
[gparg
], reg_names
[fparg
]);
8709 if ((fparg
& 1) != 0)
8711 if (TARGET_BIG_ENDIAN
)
8712 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
8713 reg_names
[gparg
], reg_names
[fparg
+ 1], s
,
8714 reg_names
[gparg
+ 1], reg_names
[fparg
]);
8716 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
8717 reg_names
[gparg
], reg_names
[fparg
], s
,
8718 reg_names
[gparg
+ 1], reg_names
[fparg
+ 1]);
8731 /* Build a mips16 function stub. This is used for functions which
8732 take aruments in the floating point registers. It is 32 bit code
8733 that moves the floating point args into the general registers, and
8734 then jumps to the 16 bit code. */
8737 build_mips16_function_stub (file
)
8741 char *secname
, *stubname
;
8742 tree stubid
, stubdecl
;
8746 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
8747 secname
= (char *) alloca (strlen (fnname
) + 20);
8748 sprintf (secname
, ".mips16.fn.%s", fnname
);
8749 stubname
= (char *) alloca (strlen (fnname
) + 20);
8750 sprintf (stubname
, "__fn_stub_%s", fnname
);
8751 stubid
= get_identifier (stubname
);
8752 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
8753 build_function_type (void_type_node
, NULL_TREE
));
8754 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
8756 fprintf (file
, "\t# Stub function for %s (", current_function_name
);
8758 for (f
= (unsigned int) current_function_args_info
.fp_code
; f
!= 0; f
>>= 2)
8760 fprintf (file
, "%s%s",
8761 need_comma
? ", " : "",
8762 (f
& 3) == 1 ? "float" : "double");
8765 fprintf (file
, ")\n");
8767 fprintf (file
, "\t.set\tnomips16\n");
8768 function_section (stubdecl
);
8769 ASM_OUTPUT_ALIGN (file
, floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
));
8771 /* ??? If FUNCTION_NAME_ALREADY_DECLARED is defined, then we are
8772 within a .ent, and we can not emit another .ent. */
8773 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8774 fputs ("\t.ent\t", file
);
8775 assemble_name (file
, stubname
);
8779 assemble_name (file
, stubname
);
8780 fputs (":\n", file
);
8782 /* We don't want the assembler to insert any nops here. */
8783 fprintf (file
, "\t.set\tnoreorder\n");
8785 mips16_fp_args (file
, current_function_args_info
.fp_code
, 1);
8787 fprintf (asm_out_file
, "\t.set\tnoat\n");
8788 fprintf (asm_out_file
, "\tla\t%s,", reg_names
[GP_REG_FIRST
+ 1]);
8789 assemble_name (file
, fnname
);
8790 fprintf (file
, "\n");
8791 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
8792 fprintf (asm_out_file
, "\t.set\tat\n");
8794 /* Unfortunately, we can't fill the jump delay slot. We can't fill
8795 with one of the mfc1 instructions, because the result is not
8796 available for one instruction, so if the very first instruction
8797 in the function refers to the register, it will see the wrong
8799 fprintf (file
, "\tnop\n");
8801 fprintf (file
, "\t.set\treorder\n");
8803 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8804 fputs ("\t.end\t", file
);
8805 assemble_name (file
, stubname
);
8809 fprintf (file
, "\t.set\tmips16\n");
8811 function_section (current_function_decl
);
8814 /* We keep a list of functions for which we have already built stubs
8815 in build_mips16_call_stub. */
8819 struct mips16_stub
*next
;
8824 static struct mips16_stub
*mips16_stubs
;
8826 /* Build a call stub for a mips16 call. A stub is needed if we are
8827 passing any floating point values which should go into the floating
8828 point registers. If we are, and the call turns out to be to a 32
8829 bit function, the stub will be used to move the values into the
8830 floating point registers before calling the 32 bit function. The
8831 linker will magically adjust the function call to either the 16 bit
8832 function or the 32 bit stub, depending upon where the function call
8833 is actually defined.
8835 Similarly, we need a stub if the return value might come back in a
8836 floating point register.
8838 RETVAL, FNMEM, and ARG_SIZE are the values passed to the call insn
8839 (RETVAL is NULL if this is call rather than call_value). FP_CODE
8840 is the code built by function_arg. This function returns a nonzero
8841 value if it builds the call instruction itself. */
8844 build_mips16_call_stub (retval
, fnmem
, arg_size
, fp_code
)
8853 char *secname
, *stubname
;
8854 struct mips16_stub
*l
;
8855 tree stubid
, stubdecl
;
8859 /* We don't need to do anything if we aren't in mips16 mode, or if
8860 we were invoked with the -msoft-float option. */
8861 if (! TARGET_MIPS16
|| ! mips16_hard_float
)
8864 /* Figure out whether the value might come back in a floating point
8866 fpret
= (retval
!= 0
8867 && GET_MODE_CLASS (GET_MODE (retval
)) == MODE_FLOAT
8868 && GET_MODE_SIZE (GET_MODE (retval
)) <= UNITS_PER_FPVALUE
);
8870 /* We don't need to do anything if there were no floating point
8871 arguments and the value will not be returned in a floating point
8873 if (fp_code
== 0 && ! fpret
)
8876 if (GET_CODE (fnmem
) != MEM
)
8878 fn
= XEXP (fnmem
, 0);
8880 /* We don't need to do anything if this is a call to a special
8881 mips16 support function. */
8882 if (GET_CODE (fn
) == SYMBOL_REF
8883 && strncmp (XSTR (fn
, 0), "__mips16_", 9) == 0)
8886 /* This code will only work for o32 and o64 abis. The other ABI's
8887 require more sophisticated support. */
8888 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
8891 /* We can only handle SFmode and DFmode floating point return
8893 if (fpret
&& GET_MODE (retval
) != SFmode
&& GET_MODE (retval
) != DFmode
)
8896 /* If we're calling via a function pointer, then we must always call
8897 via a stub. There are magic stubs provided in libgcc.a for each
8898 of the required cases. Each of them expects the function address
8899 to arrive in register $2. */
8901 if (GET_CODE (fn
) != SYMBOL_REF
)
8905 rtx stub_fn
, stub_mem
, insn
;
8907 /* ??? If this code is modified to support other ABI's, we need
8908 to handle PARALLEL return values here. */
8910 sprintf (buf
, "__mips16_call_stub_%s%d",
8912 ? (GET_MODE (retval
) == SFmode
? "sf_" : "df_")
8915 id
= get_identifier (buf
);
8916 stub_fn
= gen_rtx (SYMBOL_REF
, Pmode
, IDENTIFIER_POINTER (id
));
8917 stub_mem
= gen_rtx (MEM
, Pmode
, stub_fn
);
8919 emit_move_insn (gen_rtx (REG
, Pmode
, 2), fn
);
8921 if (retval
== NULL_RTX
)
8922 insn
= gen_call_internal0 (stub_mem
, arg_size
,
8923 gen_rtx (REG
, SImode
,
8924 GP_REG_FIRST
+ 31));
8926 insn
= gen_call_value_internal0 (retval
, stub_mem
, arg_size
,
8927 gen_rtx (REG
, SImode
,
8928 GP_REG_FIRST
+ 31));
8929 insn
= emit_call_insn (insn
);
8931 /* Put the register usage information on the CALL. */
8932 if (GET_CODE (insn
) != CALL_INSN
)
8934 CALL_INSN_FUNCTION_USAGE (insn
) =
8935 gen_rtx (EXPR_LIST
, VOIDmode
,
8936 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, Pmode
, 2)),
8937 CALL_INSN_FUNCTION_USAGE (insn
));
8939 /* If we are handling a floating point return value, we need to
8940 save $18 in the function prologue. Putting a note on the
8941 call will mean that regs_ever_live[$18] will be true if the
8942 call is not eliminated, and we can check that in the prologue
8945 CALL_INSN_FUNCTION_USAGE (insn
) =
8946 gen_rtx (EXPR_LIST
, VOIDmode
,
8947 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
8948 CALL_INSN_FUNCTION_USAGE (insn
));
8950 /* Return 1 to tell the caller that we've generated the call
8955 /* We know the function we are going to call. If we have already
8956 built a stub, we don't need to do anything further. */
8958 fnname
= XSTR (fn
, 0);
8959 for (l
= mips16_stubs
; l
!= NULL
; l
= l
->next
)
8960 if (strcmp (l
->name
, fnname
) == 0)
8965 /* Build a special purpose stub. When the linker sees a
8966 function call in mips16 code, it will check where the target
8967 is defined. If the target is a 32 bit call, the linker will
8968 search for the section defined here. It can tell which
8969 symbol this section is associated with by looking at the
8970 relocation information (the name is unreliable, since this
8971 might be a static function). If such a section is found, the
8972 linker will redirect the call to the start of the magic
8975 If the function does not return a floating point value, the
8976 special stub section is named
8979 If the function does return a floating point value, the stub
8981 .mips16.call.fp.FNNAME
8984 secname
= (char *) alloca (strlen (fnname
) + 40);
8985 sprintf (secname
, ".mips16.call.%s%s",
8988 stubname
= (char *) alloca (strlen (fnname
) + 20);
8989 sprintf (stubname
, "__call_stub_%s%s",
8992 stubid
= get_identifier (stubname
);
8993 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
8994 build_function_type (void_type_node
, NULL_TREE
));
8995 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
8997 fprintf (asm_out_file
, "\t# Stub function to call %s%s (",
8999 ? (GET_MODE (retval
) == SFmode
? "float " : "double ")
9003 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
9005 fprintf (asm_out_file
, "%s%s",
9006 need_comma
? ", " : "",
9007 (f
& 3) == 1 ? "float" : "double");
9010 fprintf (asm_out_file
, ")\n");
9012 fprintf (asm_out_file
, "\t.set\tnomips16\n");
9013 assemble_start_function (stubdecl
, stubname
);
9015 #ifndef FUNCTION_NAME_ALREADY_DECLARED
9016 fputs ("\t.ent\t", asm_out_file
);
9017 assemble_name (asm_out_file
, stubname
);
9018 fputs ("\n", asm_out_file
);
9020 assemble_name (asm_out_file
, stubname
);
9021 fputs (":\n", asm_out_file
);
9024 /* We build the stub code by hand. That's the only way we can
9025 do it, since we can't generate 32 bit code during a 16 bit
9028 /* We don't want the assembler to insert any nops here. */
9029 fprintf (asm_out_file
, "\t.set\tnoreorder\n");
9031 mips16_fp_args (asm_out_file
, fp_code
, 0);
9035 fprintf (asm_out_file
, "\t.set\tnoat\n");
9036 fprintf (asm_out_file
, "\tla\t%s,%s\n", reg_names
[GP_REG_FIRST
+ 1],
9038 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
9039 fprintf (asm_out_file
, "\t.set\tat\n");
9040 /* Unfortunately, we can't fill the jump delay slot. We
9041 can't fill with one of the mtc1 instructions, because the
9042 result is not available for one instruction, so if the
9043 very first instruction in the function refers to the
9044 register, it will see the wrong value. */
9045 fprintf (asm_out_file
, "\tnop\n");
9049 fprintf (asm_out_file
, "\tmove\t%s,%s\n",
9050 reg_names
[GP_REG_FIRST
+ 18], reg_names
[GP_REG_FIRST
+ 31]);
9051 fprintf (asm_out_file
, "\tjal\t%s\n", fnname
);
9052 /* As above, we can't fill the delay slot. */
9053 fprintf (asm_out_file
, "\tnop\n");
9054 if (GET_MODE (retval
) == SFmode
)
9055 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
9056 reg_names
[GP_REG_FIRST
+ 2], reg_names
[FP_REG_FIRST
+ 0]);
9059 if (TARGET_BIG_ENDIAN
)
9061 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
9062 reg_names
[GP_REG_FIRST
+ 2],
9063 reg_names
[FP_REG_FIRST
+ 1]);
9064 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
9065 reg_names
[GP_REG_FIRST
+ 3],
9066 reg_names
[FP_REG_FIRST
+ 0]);
9070 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
9071 reg_names
[GP_REG_FIRST
+ 2],
9072 reg_names
[FP_REG_FIRST
+ 0]);
9073 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
9074 reg_names
[GP_REG_FIRST
+ 3],
9075 reg_names
[FP_REG_FIRST
+ 1]);
9078 fprintf (asm_out_file
, "\tj\t%s\n", reg_names
[GP_REG_FIRST
+ 18]);
9079 /* As above, we can't fill the delay slot. */
9080 fprintf (asm_out_file
, "\tnop\n");
9083 fprintf (asm_out_file
, "\t.set\treorder\n");
9085 #ifdef ASM_DECLARE_FUNCTION_SIZE
9086 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, stubname
, stubdecl
);
9089 #ifndef FUNCTION_NAME_ALREADY_DECLARED
9090 fputs ("\t.end\t", asm_out_file
);
9091 assemble_name (asm_out_file
, stubname
);
9092 fputs ("\n", asm_out_file
);
9095 fprintf (asm_out_file
, "\t.set\tmips16\n");
9097 /* Record this stub. */
9098 l
= (struct mips16_stub
*) xmalloc (sizeof *l
);
9099 l
->name
= xstrdup (fnname
);
9101 l
->next
= mips16_stubs
;
9105 /* If we expect a floating point return value, but we've built a
9106 stub which does not expect one, then we're in trouble. We can't
9107 use the existing stub, because it won't handle the floating point
9108 value. We can't build a new stub, because the linker won't know
9109 which stub to use for the various calls in this object file.
9110 Fortunately, this case is illegal, since it means that a function
9111 was declared in two different ways in a single compilation. */
9112 if (fpret
&& ! l
->fpret
)
9113 error ("can not handle inconsistent calls to `%s'", fnname
);
9115 /* If we are calling a stub which handles a floating point return
9116 value, we need to arrange to save $18 in the prologue. We do
9117 this by marking the function call as using the register. The
9118 prologue will later see that it is used, and emit code to save
9125 if (retval
== NULL_RTX
)
9126 insn
= gen_call_internal0 (fnmem
, arg_size
,
9127 gen_rtx (REG
, SImode
,
9128 GP_REG_FIRST
+ 31));
9130 insn
= gen_call_value_internal0 (retval
, fnmem
, arg_size
,
9131 gen_rtx (REG
, SImode
,
9132 GP_REG_FIRST
+ 31));
9133 insn
= emit_call_insn (insn
);
9135 if (GET_CODE (insn
) != CALL_INSN
)
9138 CALL_INSN_FUNCTION_USAGE (insn
) =
9139 gen_rtx (EXPR_LIST
, VOIDmode
,
9140 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
9141 CALL_INSN_FUNCTION_USAGE (insn
));
9143 /* Return 1 to tell the caller that we've generated the call
9148 /* Return 0 to let the caller generate the call insn. */
9152 /* This function looks through the code for a function, and tries to
9153 optimize the usage of the $gp register. We arrange to copy $gp
9154 into a pseudo-register, and then let gcc's normal reload handling
9155 deal with the pseudo-register. Unfortunately, if reload choose to
9156 put the pseudo-register into a call-clobbered register, it will
9157 emit saves and restores for that register around any function
9158 calls. We don't need the saves, and it's faster to copy $gp than
9159 to do an actual restore. ??? This still means that we waste a
9162 This is an optimization, and the code which gcc has actually
9163 generated is correct, so we do not need to catch all cases. */
9166 mips16_optimize_gp (first
)
9169 rtx gpcopy
, slot
, insn
;
9171 /* Look through the instructions. Set GPCOPY to the register which
9172 holds a copy of $gp. Set SLOT to the stack slot where it is
9173 saved. If we find an instruction which sets GPCOPY to anything
9174 other than $gp or SLOT, then we can't use it. If we find an
9175 instruction which sets SLOT to anything other than GPCOPY, we
9180 for (insn
= first
; insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
9184 if (! INSN_P (insn
))
9187 set
= PATTERN (insn
);
9189 /* We know that all references to memory will be inside a SET,
9190 because there is no other way to access memory on the mips16.
9191 We don't have to worry about a PARALLEL here, because the
9192 mips.md file will never generate them for memory references. */
9193 if (GET_CODE (set
) != SET
)
9196 if (gpcopy
== NULL_RTX
9197 && GET_CODE (SET_SRC (set
)) == CONST
9198 && GET_CODE (XEXP (SET_SRC (set
), 0)) == REG
9199 && REGNO (XEXP (SET_SRC (set
), 0)) == GP_REG_FIRST
+ 28
9200 && GET_CODE (SET_DEST (set
)) == REG
9201 && GET_MODE (SET_DEST (set
)) == (unsigned) Pmode
)
9202 gpcopy
= SET_DEST (set
);
9203 else if (slot
== NULL_RTX
9204 && gpcopy
!= NULL_RTX
9205 && GET_CODE (SET_DEST (set
)) == MEM
9206 && GET_CODE (SET_SRC (set
)) == REG
9207 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
)
9208 && GET_MODE (SET_DEST (set
)) == (unsigned) Pmode
)
9212 offset
= const0_rtx
;
9213 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
9214 if (GET_CODE (base
) == REG
9215 && (REGNO (base
) == STACK_POINTER_REGNUM
9216 || REGNO (base
) == FRAME_POINTER_REGNUM
))
9217 slot
= SET_DEST (set
);
9219 else if (gpcopy
!= NULL_RTX
9220 && (GET_CODE (SET_DEST (set
)) == REG
9221 || GET_CODE (SET_DEST (set
)) == SUBREG
)
9222 && reg_overlap_mentioned_p (SET_DEST (set
), gpcopy
)
9223 && (GET_CODE (SET_DEST (set
)) != REG
9224 || REGNO (SET_DEST (set
)) != REGNO (gpcopy
)
9225 || GET_MODE (SET_DEST (set
)) != (unsigned) Pmode
9226 || ((GET_CODE (SET_SRC (set
)) != CONST
9227 || GET_CODE (XEXP (SET_SRC (set
), 0)) != REG
9228 || (REGNO (XEXP (SET_SRC (set
), 0))
9229 != GP_REG_FIRST
+ 28))
9230 && ! rtx_equal_p (SET_SRC (set
), slot
))))
9232 else if (slot
!= NULL_RTX
9233 && GET_CODE (SET_DEST (set
)) == MEM
9234 && rtx_equal_p (SET_DEST (set
), slot
)
9235 && (GET_CODE (SET_SRC (set
)) != REG
9236 || REGNO (SET_SRC (set
)) != REGNO (gpcopy
)))
9240 /* If we couldn't find a unique value for GPCOPY or SLOT, then try a
9241 different optimization. Any time we find a copy of $28 into a
9242 register, followed by an add of a symbol_ref to that register, we
9243 convert it to load the value from the constant table instead.
9244 The copy and add will take six bytes, just as the load and
9245 constant table entry will take six bytes. However, it is
9246 possible that the constant table entry will be shared.
9248 This could be a peephole optimization, but I don't know if the
9249 peephole code can call force_const_mem.
9251 Using the same register for the copy of $28 and the add of the
9252 symbol_ref is actually pretty likely, since the add instruction
9253 requires the destination and the first addend to be the same
9256 if (insn
!= NULL_RTX
|| gpcopy
== NULL_RTX
|| slot
== NULL_RTX
)
9260 /* This optimization is only reasonable if the constant table
9261 entries are only 4 bytes. */
9262 if (Pmode
!= SImode
)
9265 for (insn
= first
; insn
!= NULL_RTX
; insn
= next
)
9272 next
= NEXT_INSN (next
);
9274 while (next
!= NULL_RTX
9275 && (GET_CODE (next
) == NOTE
9276 || (GET_CODE (next
) == INSN
9277 && (GET_CODE (PATTERN (next
)) == USE
9278 || GET_CODE (PATTERN (next
)) == CLOBBER
))));
9280 if (next
== NULL_RTX
)
9283 if (! INSN_P (insn
))
9286 if (! INSN_P (next
))
9289 set1
= PATTERN (insn
);
9290 if (GET_CODE (set1
) != SET
)
9292 set2
= PATTERN (next
);
9293 if (GET_CODE (set2
) != SET
)
9296 if (GET_CODE (SET_DEST (set1
)) == REG
9297 && GET_CODE (SET_SRC (set1
)) == CONST
9298 && GET_CODE (XEXP (SET_SRC (set1
), 0)) == REG
9299 && REGNO (XEXP (SET_SRC (set1
), 0)) == GP_REG_FIRST
+ 28
9300 && rtx_equal_p (SET_DEST (set1
), SET_DEST (set2
))
9301 && GET_CODE (SET_SRC (set2
)) == PLUS
9302 && rtx_equal_p (SET_DEST (set1
), XEXP (SET_SRC (set2
), 0))
9303 && mips16_gp_offset_p (XEXP (SET_SRC (set2
), 1))
9304 && GET_CODE (XEXP (XEXP (SET_SRC (set2
), 1), 0)) == MINUS
)
9308 /* We've found a case we can change to load from the
9311 sym
= XEXP (XEXP (XEXP (SET_SRC (set2
), 1), 0), 0);
9312 if (GET_CODE (sym
) != SYMBOL_REF
)
9314 emit_insn_after (gen_rtx (SET
, VOIDmode
, SET_DEST (set1
),
9315 force_const_mem (Pmode
, sym
)),
9318 PUT_CODE (insn
, NOTE
);
9319 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
9320 NOTE_SOURCE_FILE (insn
) = 0;
9322 PUT_CODE (next
, NOTE
);
9323 NOTE_LINE_NUMBER (next
) = NOTE_INSN_DELETED
;
9324 NOTE_SOURCE_FILE (next
) = 0;
9331 /* We can safely remove all assignments to SLOT from GPCOPY, and
9332 replace all assignments from SLOT to GPCOPY with assignments from
9335 for (insn
= first
; insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
9339 if (! INSN_P (insn
))
9342 set
= PATTERN (insn
);
9343 if (GET_CODE (set
) != SET
9344 || GET_MODE (SET_DEST (set
)) != (unsigned) Pmode
)
9347 if (GET_CODE (SET_DEST (set
)) == MEM
9348 && rtx_equal_p (SET_DEST (set
), slot
)
9349 && GET_CODE (SET_SRC (set
)) == REG
9350 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
))
9352 PUT_CODE (insn
, NOTE
);
9353 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
9354 NOTE_SOURCE_FILE (insn
) = 0;
9356 else if (GET_CODE (SET_DEST (set
)) == REG
9357 && REGNO (SET_DEST (set
)) == REGNO (gpcopy
)
9358 && GET_CODE (SET_SRC (set
)) == MEM
9359 && rtx_equal_p (SET_SRC (set
), slot
))
9361 emit_insn_after (gen_rtx (SET
, Pmode
, SET_DEST (set
),
9362 gen_rtx (CONST
, Pmode
,
9363 gen_rtx (REG
, Pmode
,
9364 GP_REG_FIRST
+ 28))),
9366 PUT_CODE (insn
, NOTE
);
9367 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
9368 NOTE_SOURCE_FILE (insn
) = 0;
9373 /* We keep a list of constants we which we have to add to internal
9374 constant tables in the middle of large functions. */
9378 struct constant
*next
;
9381 enum machine_mode mode
;
9384 /* Add a constant to the list in *PCONSTANTS. */
9387 add_constant (pconstants
, val
, mode
)
9388 struct constant
**pconstants
;
9390 enum machine_mode mode
;
9394 for (c
= *pconstants
; c
!= NULL
; c
= c
->next
)
9395 if (mode
== c
->mode
&& rtx_equal_p (val
, c
->value
))
9398 c
= (struct constant
*) xmalloc (sizeof *c
);
9401 c
->label
= gen_label_rtx ();
9402 c
->next
= *pconstants
;
9407 /* Dump out the constants in CONSTANTS after INSN. */
9410 dump_constants (constants
, insn
)
9411 struct constant
*constants
;
9422 struct constant
*next
;
9424 switch (GET_MODE_SIZE (c
->mode
))
9431 insn
= emit_insn_after (gen_align_2 (), insn
);
9436 insn
= emit_insn_after (gen_align_4 (), insn
);
9441 insn
= emit_insn_after (gen_align_8 (), insn
);
9446 insn
= emit_label_after (c
->label
, insn
);
9451 r
= gen_consttable_qi (c
->value
);
9454 r
= gen_consttable_hi (c
->value
);
9457 r
= gen_consttable_si (c
->value
);
9460 r
= gen_consttable_sf (c
->value
);
9463 r
= gen_consttable_di (c
->value
);
9466 r
= gen_consttable_df (c
->value
);
9472 insn
= emit_insn_after (r
, insn
);
9479 emit_barrier_after (insn
);
9482 /* Find the symbol in an address expression. */
9485 mips_find_symbol (addr
)
9488 if (GET_CODE (addr
) == MEM
)
9489 addr
= XEXP (addr
, 0);
9490 while (GET_CODE (addr
) == CONST
)
9491 addr
= XEXP (addr
, 0);
9492 if (GET_CODE (addr
) == SYMBOL_REF
|| GET_CODE (addr
) == LABEL_REF
)
9494 if (GET_CODE (addr
) == PLUS
)
9498 l1
= mips_find_symbol (XEXP (addr
, 0));
9499 l2
= mips_find_symbol (XEXP (addr
, 1));
9500 if (l1
!= NULL_RTX
&& l2
== NULL_RTX
)
9502 else if (l1
== NULL_RTX
&& l2
!= NULL_RTX
)
9508 /* Exported to toplev.c.
9510 Do a final pass over the function, just before delayed branch
9514 machine_dependent_reorg (first
)
9517 int insns_len
, max_internal_pool_size
, pool_size
, addr
, first_constant_ref
;
9519 struct constant
*constants
;
9521 if (! TARGET_MIPS16
)
9524 /* If $gp is used, try to remove stores, and replace loads with
9527 mips16_optimize_gp (first
);
9529 /* Scan the function looking for PC relative loads which may be out
9530 of range. All such loads will either be from the constant table,
9531 or be getting the address of a constant string. If the size of
9532 the function plus the size of the constant table is less than
9533 0x8000, then all loads are in range. */
9536 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9538 insns_len
+= get_attr_length (insn
);
9540 /* ??? We put switch tables in .text, but we don't define
9541 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
9542 compute their lengths correctly. */
9543 if (GET_CODE (insn
) == JUMP_INSN
)
9547 body
= PATTERN (insn
);
9548 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
9549 insns_len
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
9550 * GET_MODE_SIZE (GET_MODE (body
)));
9551 insns_len
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
9555 /* Store the original value of insns_len in current_frame_info, so
9556 that simple_memory_operand can look at it. */
9557 current_frame_info
.insns_len
= insns_len
;
9559 pool_size
= get_pool_size ();
9560 if (insns_len
+ pool_size
+ mips_string_length
< 0x8000)
9563 /* Loop over the insns and figure out what the maximum internal pool
9565 max_internal_pool_size
= 0;
9566 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9568 if (GET_CODE (insn
) == INSN
9569 && GET_CODE (PATTERN (insn
)) == SET
)
9573 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
9574 if (src
== NULL_RTX
)
9576 if (CONSTANT_POOL_ADDRESS_P (src
))
9577 max_internal_pool_size
+= GET_MODE_SIZE (get_pool_mode (src
));
9578 else if (SYMBOL_REF_FLAG (src
))
9579 max_internal_pool_size
+= GET_MODE_SIZE (Pmode
);
9585 first_constant_ref
= -1;
9587 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9589 if (GET_CODE (insn
) == INSN
9590 && GET_CODE (PATTERN (insn
)) == SET
)
9593 enum machine_mode mode
= VOIDmode
;
9596 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
9597 if (src
!= NULL_RTX
&& CONSTANT_POOL_ADDRESS_P (src
))
9599 /* ??? This is very conservative, which means that we
9600 will generate too many copies of the constant table.
9601 The only solution would seem to be some form of
9603 if (((insns_len
- addr
)
9604 + max_internal_pool_size
9605 + get_pool_offset (src
))
9608 val
= get_pool_constant (src
);
9609 mode
= get_pool_mode (src
);
9611 max_internal_pool_size
-= GET_MODE_SIZE (get_pool_mode (src
));
9613 else if (src
!= NULL_RTX
&& SYMBOL_REF_FLAG (src
))
9615 /* Including all of mips_string_length is conservative,
9616 and so is including all of max_internal_pool_size. */
9617 if (((insns_len
- addr
)
9618 + max_internal_pool_size
9620 + mips_string_length
)
9626 max_internal_pool_size
-= Pmode
;
9629 if (val
!= NULL_RTX
)
9633 /* This PC relative load is out of range. ??? In the
9634 case of a string constant, we are only guessing that
9635 it is range, since we don't know the offset of a
9636 particular string constant. */
9638 lab
= add_constant (&constants
, val
, mode
);
9639 newsrc
= gen_rtx (MEM
, mode
,
9640 gen_rtx (LABEL_REF
, VOIDmode
, lab
));
9641 RTX_UNCHANGING_P (newsrc
) = 1;
9642 PATTERN (insn
) = gen_rtx (SET
, VOIDmode
,
9643 SET_DEST (PATTERN (insn
)),
9645 INSN_CODE (insn
) = -1;
9647 if (first_constant_ref
< 0)
9648 first_constant_ref
= addr
;
9652 addr
+= get_attr_length (insn
);
9654 /* ??? We put switch tables in .text, but we don't define
9655 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
9656 compute their lengths correctly. */
9657 if (GET_CODE (insn
) == JUMP_INSN
)
9661 body
= PATTERN (insn
);
9662 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
9663 addr
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
9664 * GET_MODE_SIZE (GET_MODE (body
)));
9665 addr
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
9668 if (GET_CODE (insn
) == BARRIER
)
9670 /* Output any constants we have accumulated. Note that we
9671 don't need to change ADDR, since its only use is
9672 subtraction from INSNS_LEN, and both would be changed by
9674 ??? If the instructions up to the next barrier reuse a
9675 constant, it would often be better to continue
9677 if (constants
!= NULL
)
9678 dump_constants (constants
, insn
);
9680 first_constant_ref
= -1;
9683 if (constants
!= NULL
9684 && (NEXT_INSN (insn
) == NULL
9685 || (first_constant_ref
>= 0
9686 && (((addr
- first_constant_ref
)
9687 + 2 /* for alignment */
9688 + 2 /* for a short jump insn */
9692 /* If we haven't had a barrier within 0x8000 bytes of a
9693 constant reference or we are at the end of the function,
9694 emit a barrier now. */
9696 rtx label
, jump
, barrier
;
9698 label
= gen_label_rtx ();
9699 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
9700 JUMP_LABEL (jump
) = label
;
9701 LABEL_NUSES (label
) = 1;
9702 barrier
= emit_barrier_after (jump
);
9703 emit_label_after (label
, barrier
);
9704 first_constant_ref
= -1;
9708 /* ??? If we output all references to a constant in internal
9709 constants table, we don't need to output the constant in the real
9710 constant table, but we have no way to prevent that. */
9713 /* Return nonzero if X is a SIGN or ZERO extend operator. */
9715 extend_operator (x
, mode
)
9717 enum machine_mode mode ATTRIBUTE_UNUSED
;
9719 enum rtx_code code
= GET_CODE (x
);
9720 return code
== SIGN_EXTEND
|| code
== ZERO_EXTEND
;
9723 /* Accept any operator that can be used to shift the high half of the
9724 input value to the lower half, suitable for truncation. The
9725 remainder (the lower half of the input, and the upper half of the
9726 output) will be discarded. */
9728 highpart_shift_operator (x
, mode
)
9730 enum machine_mode mode ATTRIBUTE_UNUSED
;
9732 enum rtx_code code
= GET_CODE (x
);
9733 return (code
== LSHIFTRT
9739 /* Return a number assessing the cost of moving a register in class
9740 FROM to class TO. The classes are expressed using the enumeration
9741 values such as `GENERAL_REGS'. A value of 2 is the default; other
9742 values are interpreted relative to that.
9744 It is not required that the cost always equal 2 when FROM is the
9745 same as TO; on some machines it is expensive to move between
9746 registers if they are not general registers.
9748 If reload sees an insn consisting of a single `set' between two
9749 hard registers, and if `REGISTER_MOVE_COST' applied to their
9750 classes returns a value of 2, reload does not check to ensure that
9751 the constraints of the insn are met. Setting a cost of other than
9752 2 will allow reload to verify that the constraints are met. You
9753 should do this if the `movM' pattern's constraints do not allow
9756 ??? We make make the cost of moving from HI/LO/HILO/MD into general
9757 registers the same as for one of moving general registers to
9758 HI/LO/HILO/MD for TARGET_MIPS16 in order to prevent allocating a
9759 pseudo to HI/LO/HILO/MD. This might hurt optimizations though, it
9760 isn't clear if it is wise. And it might not work in all cases. We
9761 could solve the DImode LO reg problem by using a multiply, just
9762 like reload_{in,out}si. We could solve the SImode/HImode HI reg
9763 problem by using divide instructions. divu puts the remainder in
9764 the HI reg, so doing a divide by -1 will move the value in the HI
9765 reg for all values except -1. We could handle that case by using a
9766 signed divide, e.g. -1 / 2 (or maybe 1 / -2?). We'd have to emit
9767 a compare/branch to test the input value to see which instruction
9768 we need to use. This gets pretty messy, but it is feasible. */
9771 mips_register_move_cost (mode
, to
, from
)
9772 enum machine_mode mode ATTRIBUTE_UNUSED
;
9773 enum reg_class to
, from
;
9775 if (from
== M16_REGS
&& GR_REG_CLASS_P (to
))
9777 else if (from
== M16_NA_REGS
&& GR_REG_CLASS_P (to
))
9779 else if (GR_REG_CLASS_P (from
))
9783 else if (to
== M16_NA_REGS
)
9785 else if (GR_REG_CLASS_P (to
))
9792 else if (to
== FP_REGS
)
9794 else if (to
== HI_REG
|| to
== LO_REG
|| to
== MD_REGS
9802 else if (COP_REG_CLASS_P (to
))
9806 } /* GR_REG_CLASS_P (from) */
9807 else if (from
== FP_REGS
)
9809 if (GR_REG_CLASS_P (to
))
9811 else if (to
== FP_REGS
)
9813 else if (to
== ST_REGS
)
9815 } /* from == FP_REGS */
9816 else if (from
== HI_REG
|| from
== LO_REG
|| from
== MD_REGS
9817 || from
== HILO_REG
)
9819 if (GR_REG_CLASS_P (to
))
9826 } /* from == HI_REG, etc. */
9827 else if (from
== ST_REGS
&& GR_REG_CLASS_P (to
))
9829 else if (COP_REG_CLASS_P (from
))
9832 } /* COP_REG_CLASS_P (from) */
9839 /* Return the length of INSN. LENGTH is the initial length computed by
9840 attributes in the machine-description file. */
9843 mips_adjust_insn_length (insn
, length
)
9847 /* A unconditional jump has an unfilled delay slot if it is not part
9848 of a sequence. A conditional jump normally has a delay slot, but
9849 does not on MIPS16. */
9850 if (simplejump_p (insn
)
9851 || (!TARGET_MIPS16
&& (GET_CODE (insn
) == JUMP_INSN
9852 || GET_CODE (insn
) == CALL_INSN
)))
9855 /* All MIPS16 instructions are a measly two bytes. */
9862 /* Output assembly instructions to peform a conditional branch.
9864 INSN is the branch instruction. OPERANDS[0] is the condition.
9865 OPERANDS[1] is the target of the branch. OPERANDS[2] is the target
9866 of the first operand to the condition. If TWO_OPERANDS_P is
9867 non-zero the comparison takes two operands; OPERANDS[3] will be the
9870 If INVERTED_P is non-zero we are to branch if the condition does
9871 not hold. If FLOAT_P is non-zero this is a floating-point comparison.
9873 LENGTH is the length (in bytes) of the sequence we are to generate.
9874 That tells us whether to generate a simple conditional branch, or a
9875 reversed conditional branch around a `jr' instruction. */
9877 mips_output_conditional_branch (insn
,
9890 static char buffer
[200];
9891 /* The kind of comparison we are doing. */
9892 enum rtx_code code
= GET_CODE (operands
[0]);
9893 /* Non-zero if the opcode for the comparison needs a `z' indicating
9894 that it is a comparision against zero. */
9896 /* A string to use in the assembly output to represent the first
9898 const char *op1
= "%z2";
9899 /* A string to use in the assembly output to represent the second
9900 operand. Use the hard-wired zero register if there's no second
9902 const char *op2
= (two_operands_p
? ",%z3" : ",%.");
9903 /* The operand-printing string for the comparison. */
9904 const char *const comp
= (float_p
? "%F0" : "%C0");
9905 /* The operand-printing string for the inverted comparison. */
9906 const char *const inverted_comp
= (float_p
? "%W0" : "%N0");
9908 /* The MIPS processors (for levels of the ISA at least two), have
9909 "likely" variants of each branch instruction. These instructions
9910 annul the instruction in the delay slot if the branch is not
9912 mips_branch_likely
= (final_sequence
&& INSN_ANNULLED_BRANCH_P (insn
));
9914 if (!two_operands_p
)
9916 /* To compute whether than A > B, for example, we normally
9917 subtract B from A and then look at the sign bit. But, if we
9918 are doing an unsigned comparison, and B is zero, we don't
9919 have to do the subtraction. Instead, we can just check to
9920 see if A is non-zero. Thus, we change the CODE here to
9921 reflect the simpler comparison operation. */
9933 /* A condition which will always be true. */
9939 /* A condition which will always be false. */
9945 /* Not a special case. */
9950 /* Relative comparisons are always done against zero. But
9951 equality comparisons are done between two operands, and therefore
9952 do not require a `z' in the assembly language output. */
9953 need_z_p
= (!float_p
&& code
!= EQ
&& code
!= NE
);
9954 /* For comparisons against zero, the zero is not provided
9959 /* Begin by terminating the buffer. That way we can always use
9960 strcat to add to it. */
9967 /* Just a simple conditional branch. */
9969 sprintf (buffer
, "%%*b%s%%?\t%%Z2%%1",
9970 inverted_p
? inverted_comp
: comp
);
9972 sprintf (buffer
, "%%*b%s%s%%?\t%s%s,%%1",
9973 inverted_p
? inverted_comp
: comp
,
9974 need_z_p
? "z" : "",
9982 /* Generate a reversed conditional branch around ` j'
9997 rtx target
= gen_label_rtx ();
9999 output_asm_insn ("%(%<", 0);
10000 orig_target
= operands
[1];
10001 operands
[1] = target
;
10002 /* Generate the reversed comparison. This takes four
10005 sprintf (buffer
, "%%*b%s\t%%Z2%%1",
10006 inverted_p
? comp
: inverted_comp
);
10008 sprintf (buffer
, "%%*b%s%s\t%s%s,%%1",
10009 inverted_p
? comp
: inverted_comp
,
10010 need_z_p
? "z" : "",
10013 output_asm_insn (buffer
, operands
);
10014 operands
[1] = orig_target
;
10016 output_asm_insn ("nop\n\tj\t%1", operands
);
10019 output_asm_insn ("nop", 0);
10022 /* Output delay slot instruction. */
10023 rtx insn
= final_sequence
;
10024 final_scan_insn (XVECEXP (insn
, 0, 1), asm_out_file
,
10026 INSN_DELETED_P (XVECEXP (insn
, 0, 1)) = 1;
10028 output_asm_insn ("%>%)", 0);
10029 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "L",
10030 CODE_LABEL_NUMBER (target
));
10034 /* We do not currently use this code. It handles jumps to
10035 arbitrary locations, using `jr', even across a 256MB boundary.
10036 We could add a -mhuge switch, and then use this code instead of
10037 the `j' alternative above when -mhuge was used. */
10042 /* Generate a reversed conditional branch around a `jr'
10056 Not pretty, but allows a conditional branch anywhere in the
10057 32-bit address space. If the original branch is annulled,
10058 then the instruction in the delay slot should be executed
10059 only if the branch is taken. The la instruction is really
10060 a macro which will usually take eight bytes, but sometimes
10061 takes only four, if the instruction to which we're jumping
10062 gets its own entry in the global pointer table, which will
10063 happen if its a case label. The assembler will then
10064 generate only a four-byte sequence, rather than eight, and
10065 there seems to be no way to tell it not to. Thus, we can't
10066 just use a `.+x' addressing form; we don't know what value
10069 So, we resort to using the explicit relocation syntax
10070 available in the assembler and do:
10072 lw $at,%got_page(target)($gp)
10073 daddiu $at,$at,%got_ofst(target)
10075 That way, this always takes up eight bytes, and we can use
10076 the `.+x' form. Of course, these explicit machinations
10077 with relocation will not work with old assemblers. Then
10078 again, neither do out-of-range branches, so we haven't lost
10081 /* The target of the reversed branch. */
10082 const char *const target
10083 = ((mips_branch_likely
|| length
== 20) ? ".+20" : ".+16");
10084 const char *at_register
= mips_reg_names
[ASSEMBLER_SCRATCH_REGNUM
];
10085 const char *gp_register
= mips_reg_names
[PIC_OFFSET_TABLE_REGNUM
];
10088 strcpy (buffer
, "%(%<%[");
10089 c
= strchr (buffer
, '\0');
10090 /* Generate the reversed comparision. This takes four
10093 sprintf (c
, "%%*b%s\t%%Z2%s",
10094 inverted_p
? comp
: inverted_comp
,
10097 sprintf (c
, "%%*b%s%s\t%s%s,%s",
10098 inverted_p
? comp
: inverted_comp
,
10099 need_z_p
? "z" : "",
10103 c
= strchr (buffer
, '\0');
10104 /* Generate the load-address, and jump. This takes twelve
10105 bytes, for a total of 16. */
10107 "\n\tlw\t%s,%%%%got_page(%%1)(%s)\n\tdaddiu\t%s,%s,%%%%got_ofst(%%1)\n\tjr\t%s",
10114 /* The delay slot was unfilled. Since we're inside
10115 .noreorder, the assembler will not fill in the NOP for
10116 us, so we must do it ourselves. */
10117 strcat (buffer
, "\n\tnop");
10118 strcat (buffer
, "%]%>%)");
10131 /* Called to register all of our global variables with the garbage
10135 mips_add_gc_roots ()
10137 ggc_add_rtx_root (&mips_load_reg
, 1);
10138 ggc_add_rtx_root (&mips_load_reg2
, 1);
10139 ggc_add_rtx_root (&mips_load_reg3
, 1);
10140 ggc_add_rtx_root (&mips_load_reg4
, 1);
10141 ggc_add_rtx_root (branch_cmp
, ARRAY_SIZE (branch_cmp
));
10144 static enum processor_type
10145 mips_parse_cpu (cpu_string
)
10146 const char *cpu_string
;
10148 const char *p
= cpu_string
;
10150 enum processor_type cpu
;
10151 int warn_upper_case
= 0;
10153 /* We need to cope with the various "vr" prefixes for the NEC 4300
10154 and 4100 processors. */
10155 if (*p
== 'v' || *p
== 'V')
10158 warn_upper_case
= 1;
10162 if (*p
== 'r' || *p
== 'R')
10165 warn_upper_case
= 1;
10169 if (warn_upper_case
)
10170 warning ("the cpu name must be lower case");
10172 /* Since there is no difference between a R2000 and R3000 in
10173 terms of the scheduler, we collapse them into just an R3000. */
10175 cpu
= PROCESSOR_DEFAULT
;
10179 if (!strcmp (p
, "2000") || !strcmp (p
, "2k") || !strcmp (p
, "2K"))
10180 cpu
= PROCESSOR_R3000
;
10181 else if (!strcmp (p
, "20kc") || !strcmp (p
, "20Kc") )
10182 cpu
= PROCESSOR_R20KC
;
10186 if (!strcmp (p
, "3000") || !strcmp (p
, "3k") || !strcmp (p
, "3K"))
10187 cpu
= PROCESSOR_R3000
;
10188 else if (!strcmp (p
, "3900"))
10189 cpu
= PROCESSOR_R3900
;
10193 if (!strcmp (p
, "4000") || !strcmp (p
, "4k") || !strcmp (p
, "4K"))
10194 cpu
= PROCESSOR_R4000
;
10195 /* The vr4100 is a non-FP ISA III processor with some extra
10197 else if (!strcmp (p
, "4100"))
10198 cpu
= PROCESSOR_R4100
;
10199 /* The vr4300 is a standard ISA III processor, but with a different
10201 else if (!strcmp (p
, "4300"))
10202 cpu
= PROCESSOR_R4300
;
10203 /* The r4400 is exactly the same as the r4000 from the compiler's
10205 else if (!strcmp (p
, "4400"))
10206 cpu
= PROCESSOR_R4000
;
10207 else if (!strcmp (p
, "4600"))
10208 cpu
= PROCESSOR_R4600
;
10209 else if (!strcmp (p
, "4650"))
10210 cpu
= PROCESSOR_R4650
;
10211 /* The 4kc and 4kp processor cores are the same for
10212 scheduling purposes; they both implement the MIPS32
10213 ISA and only differ in their memory management
10215 else if (!strcmp (p
, "4kc") || !strcmp (p
, "4Kc")
10216 || !strcmp (p
, "4kp") || !strcmp (p
, "4Kp") )
10217 cpu
= PROCESSOR_R4KC
;
10221 if (!strcmp (p
, "5000") || !strcmp (p
, "5k") || !strcmp (p
, "5K"))
10222 cpu
= PROCESSOR_R5000
;
10223 else if (!strcmp (p
, "5kc") || !strcmp (p
, "5Kc") )
10224 cpu
= PROCESSOR_R5KC
;
10228 if (!strcmp (p
, "6000") || !strcmp (p
, "6k") || !strcmp (p
, "6K"))
10229 cpu
= PROCESSOR_R6000
;
10233 if (!strcmp (p
, "8000"))
10234 cpu
= PROCESSOR_R8000
;
10238 if (!strcmp (p
, "orion"))
10239 cpu
= PROCESSOR_R4600
;
10244 && cpu
!= PROCESSOR_R4300
10245 && cpu
!= PROCESSOR_R4100
10246 && cpu
!= PROCESSOR_R5000
)
10247 cpu
= PROCESSOR_DEFAULT
;
10252 /* Adjust the cost of INSN based on the relationship between INSN that
10253 is dependent on DEP_INSN through the dependence LINK. The default
10254 is to make no adjustment to COST.
10256 On the MIPS, ignore the cost of anti- and output-dependencies. */
10258 mips_adjust_cost (insn
, link
, dep
, cost
)
10259 rtx insn ATTRIBUTE_UNUSED
;
10261 rtx dep ATTRIBUTE_UNUSED
;
10264 if (REG_NOTE_KIND (link
) != 0)
10265 return 0; /* Anti or output dependence. */
10269 /* ??? This could be replaced with the default elf version if
10270 TARGET_IS_SMALL_DATA_P is set properly. */
10273 mips_unique_section (decl
, reloc
)
10277 int len
, size
, sec
;
10278 const char *name
, *prefix
;
10280 static const char *const prefixes
[4][2] = {
10281 { ".text.", ".gnu.linkonce.t." },
10282 { ".rodata.", ".gnu.linkonce.r." },
10283 { ".data.", ".gnu.linkonce.d." },
10284 { ".sdata.", ".gnu.linkonce.s." }
10287 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
10288 size
= int_size_in_bytes (TREE_TYPE (decl
));
10289 STRIP_NAME_ENCODING (name
, name
);
10291 /* Determine the base section we are interested in:
10292 0=text, 1=rodata, 2=data, 3=sdata, [4=bss]. */
10293 if (TREE_CODE (decl
) == FUNCTION_DECL
)
10295 else if (DECL_INITIAL (decl
) == 0
10296 || DECL_INITIAL (decl
) == error_mark_node
)
10298 else if ((TARGET_EMBEDDED_PIC
|| TARGET_MIPS16
)
10299 && TREE_CODE (decl
) == STRING_CST
10300 && !flag_writable_strings
)
10302 /* For embedded position independent code, put constant
10303 strings in the text section, because the data section
10304 is limited to 64K in size. For mips16 code, put
10305 strings in the text section so that a PC relative load
10306 instruction can be used to get their address. */
10309 else if (TARGET_EMBEDDED_DATA
)
10311 /* For embedded applications, always put an object in
10312 read-only data if possible, in order to reduce RAM
10315 if (DECL_READONLY_SECTION (decl
, reloc
))
10317 else if (size
> 0 && size
<= mips_section_threshold
)
10324 /* For hosted applications, always put an object in
10325 small data if possible, as this gives the best
10328 if (size
> 0 && size
<= mips_section_threshold
)
10330 else if (DECL_READONLY_SECTION (decl
, reloc
))
10336 prefix
= prefixes
[sec
][DECL_ONE_ONLY (decl
)];
10337 len
= strlen (name
) + strlen (prefix
);
10338 string
= alloca (len
+ 1);
10339 sprintf (string
, "%s%s", prefix
, name
);
10341 DECL_SECTION_NAME (decl
) = build_string (len
, string
);
10345 mips_hard_regno_nregs (regno
, mode
)
10347 enum machine_mode mode
;
10349 if (! FP_REG_P (regno
))
10350 return ((GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
);
10352 return ((GET_MODE_SIZE (mode
) + UNITS_PER_FPREG
- 1) / UNITS_PER_FPREG
);
10356 mips_return_in_memory (type
)
10359 /* Under the old (i.e., 32 and O64 ABIs) all BLKmode objects are
10360 returned in memory. Under the new (N32 and 64-bit MIPS ABIs) small
10361 structures are returned in a register. Objects with varying size
10362 must still be returned in memory, of course. */
10364 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
10365 return (TYPE_MODE (type
) == BLKmode
);
10367 return ((int_size_in_bytes (type
) > (2 * UNITS_PER_WORD
))
10368 || (int_size_in_bytes (type
) == -1));
10378 case PROCESSOR_R3000
:
10391 #ifdef TARGET_IRIX6
10392 /* Output assembly to switch to section NAME with attribute FLAGS. */
10395 iris6_asm_named_section_1 (name
, flags
, align
)
10397 unsigned int flags
;
10398 unsigned int align
;
10400 unsigned int sh_type
, sh_flags
, sh_entsize
;
10403 if (!(flags
& SECTION_DEBUG
))
10404 sh_flags
|= 2; /* SHF_ALLOC */
10405 if (flags
& SECTION_WRITE
)
10406 sh_flags
|= 1; /* SHF_WRITE */
10407 if (flags
& SECTION_CODE
)
10408 sh_flags
|= 4; /* SHF_EXECINSTR */
10409 if (flags
& SECTION_SMALL
)
10410 sh_flags
|= 0x10000000; /* SHF_MIPS_GPREL */
10411 if (strcmp (name
, ".debug_frame") == 0)
10412 sh_flags
|= 0x08000000; /* SHF_MIPS_NOSTRIP */
10413 if (flags
& SECTION_DEBUG
)
10414 sh_type
= 0x7000001e; /* SHT_MIPS_DWARF */
10415 else if (flags
& SECTION_BSS
)
10416 sh_type
= 8; /* SHT_NOBITS */
10418 sh_type
= 1; /* SHT_PROGBITS */
10420 if (flags
& SECTION_CODE
)
10425 fprintf (asm_out_file
, "\t.section %s,%#x,%#x,%u,%u\n",
10426 name
, sh_type
, sh_flags
, sh_entsize
, align
);
10430 iris6_asm_named_section (name
, flags
)
10432 unsigned int flags
;
10434 if (TARGET_FILE_SWITCHING
&& (flags
& SECTION_CODE
))
10435 asm_out_file
= asm_out_text_file
;
10436 iris6_asm_named_section_1 (name
, flags
, 0);
10439 /* In addition to emitting a .align directive, record the maximum
10440 alignment requested for the current section. */
10442 struct iris_section_align_entry
10446 unsigned int flags
;
10449 static htab_t iris_section_align_htab
;
10450 static FILE *iris_orig_asm_out_file
;
10453 iris_section_align_entry_eq (p1
, p2
)
10457 const struct iris_section_align_entry
*old
= p1
;
10458 const char *new = p2
;
10460 return strcmp (old
->name
, new) == 0;
10464 iris_section_align_entry_hash (p
)
10467 const struct iris_section_align_entry
*old
= p
;
10468 return htab_hash_string (old
->name
);
10472 iris6_asm_output_align (file
, log
)
10476 const char *section
= current_section_name ();
10477 struct iris_section_align_entry
**slot
, *entry
;
10482 slot
= (struct iris_section_align_entry
**)
10483 htab_find_slot_with_hash (iris_section_align_htab
, section
,
10484 htab_hash_string (section
), INSERT
);
10488 entry
= (struct iris_section_align_entry
*)
10489 xmalloc (sizeof (struct iris_section_align_entry
));
10491 entry
->name
= section
;
10493 entry
->flags
= current_section_flags ();
10495 else if (entry
->log
< log
)
10498 fprintf (file
, "\t.align\t%u\n", log
);
10501 /* The Iris assembler does not record alignment from .align directives,
10502 but takes it from the first .section directive seen. Play yet more
10503 file switching games so that we can emit a .section directive at the
10504 beginning of the file with the proper alignment attached. */
10507 iris6_asm_file_start (stream
)
10510 mips_asm_file_start (stream
);
10512 iris_orig_asm_out_file
= asm_out_file
;
10513 stream
= tmpfile ();
10514 asm_out_file
= stream
;
10515 asm_out_data_file
= stream
;
10516 if (! TARGET_FILE_SWITCHING
)
10517 asm_out_text_file
= stream
;
10519 iris_section_align_htab
= htab_create (31, iris_section_align_entry_hash
,
10520 iris_section_align_entry_eq
, NULL
);
10524 iris6_section_align_1 (slot
, data
)
10526 void *data ATTRIBUTE_UNUSED
;
10528 const struct iris_section_align_entry
*entry
10529 = *(const struct iris_section_align_entry
**) slot
;
10531 iris6_asm_named_section_1 (entry
->name
, entry
->flags
, 1 << entry
->log
);
10536 iris6_asm_file_end (stream
)
10539 /* Emit section directives with the proper alignment at the top of the
10540 real output file. */
10541 asm_out_file
= iris_orig_asm_out_file
;
10542 htab_traverse (iris_section_align_htab
, iris6_section_align_1
, NULL
);
10544 /* Copy the data emitted to the temp file to the real output file. */
10545 copy_file_data (asm_out_file
, stream
);
10547 mips_asm_file_end (stream
);
10549 #endif /* TARGET_IRIX6 */