1 /* Subroutines for insn-output.c for MIPS
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 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"
54 #include "target-def.h"
57 #define STAB_CODE_TYPE enum __stab_debug_code
59 #define STAB_CODE_TYPE int
62 extern tree lookup_name
PARAMS ((tree
));
64 /* Enumeration for all of the relational tests, so that we can build
65 arrays indexed by the test type, and not worry about the order
84 static enum internal_test map_test_to_internal_test
PARAMS ((enum rtx_code
));
85 static int mips16_simple_memory_operand
PARAMS ((rtx
, rtx
,
87 static int m16_check_op
PARAMS ((rtx
, int, int, int));
88 static void block_move_loop
PARAMS ((rtx
, rtx
,
92 static void block_move_call
PARAMS ((rtx
, rtx
, rtx
));
93 static FILE *mips_make_temp_file
PARAMS ((void));
94 static void save_restore_insns
PARAMS ((int, rtx
,
96 static void mips16_output_gp_offset
PARAMS ((FILE *, rtx
));
97 static void mips16_fp_args
PARAMS ((FILE *, int, int));
98 static void build_mips16_function_stub
PARAMS ((FILE *));
99 static void mips16_optimize_gp
PARAMS ((rtx
));
100 static rtx add_constant
PARAMS ((struct constant
**,
103 static void dump_constants
PARAMS ((struct constant
*,
105 static rtx mips_find_symbol
PARAMS ((rtx
));
106 static void abort_with_insn
PARAMS ((rtx
, const char *))
108 static int symbolic_expression_p
PARAMS ((rtx
));
109 static void mips_add_gc_roots
PARAMS ((void));
110 static void mips_output_function_epilogue
PARAMS ((FILE *, HOST_WIDE_INT
));
111 static void mips_output_function_prologue
PARAMS ((FILE *, HOST_WIDE_INT
));
112 static enum processor_type mips_parse_cpu
PARAMS ((const char *));
114 /* Global variables for machine-dependent things. */
116 /* Threshold for data being put into the small data/bss area, instead
117 of the normal data area (references to the small data/bss area take
118 1 instruction, and use the global pointer, references to the normal
119 data area takes 2 instructions). */
120 int mips_section_threshold
= -1;
122 /* Count the number of .file directives, so that .loc is up to date. */
123 int num_source_filenames
= 0;
125 /* Count the number of sdb related labels are generated (to find block
126 start and end boundaries). */
127 int sdb_label_count
= 0;
129 /* Next label # for each statement for Silicon Graphics IRIS systems. */
132 /* Non-zero if inside of a function, because the stupid MIPS asm can't
133 handle .files inside of functions. */
134 int inside_function
= 0;
136 /* Files to separate the text and the data output, so that all of the data
137 can be emitted before the text, which will mean that the assembler will
138 generate smaller code, based on the global pointer. */
139 FILE *asm_out_data_file
;
140 FILE *asm_out_text_file
;
142 /* Linked list of all externals that are to be emitted when optimizing
143 for the global pointer if they haven't been declared by the end of
144 the program with an appropriate .comm or initialization. */
148 struct extern_list
*next
; /* next external */
149 const char *name
; /* name of the external */
150 int size
; /* size in bytes */
153 /* Name of the file containing the current function. */
154 const char *current_function_file
= "";
156 /* Warning given that Mips ECOFF can't support changing files
157 within a function. */
158 int file_in_function_warning
= FALSE
;
160 /* Whether to suppress issuing .loc's because the user attempted
161 to change the filename within a function. */
162 int ignore_line_number
= FALSE
;
164 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
170 /* The next branch instruction is a branch likely, not branch normal. */
171 int mips_branch_likely
;
173 /* Count of delay slots and how many are filled. */
174 int dslots_load_total
;
175 int dslots_load_filled
;
176 int dslots_jump_total
;
177 int dslots_jump_filled
;
179 /* # of nops needed by previous insn */
180 int dslots_number_nops
;
182 /* Number of 1/2/3 word references to data items (ie, not jal's). */
185 /* registers to check for load delay */
186 rtx mips_load_reg
, mips_load_reg2
, mips_load_reg3
, mips_load_reg4
;
188 /* Cached operands, and operator to compare for use in set/branch/trap
189 on condition codes. */
192 /* what type of branch to use */
193 enum cmp_type branch_type
;
195 /* Number of previously seen half-pic pointers and references. */
196 static int prev_half_pic_ptrs
= 0;
197 static int prev_half_pic_refs
= 0;
199 /* The target cpu for code generation. */
200 enum processor_type mips_arch
;
202 /* The target cpu for optimization and scheduling. */
203 enum processor_type mips_tune
;
205 /* Historical option for code generation and scheduling. */
206 enum processor_type mips_cpu
;
208 /* which instruction set architecture to use. */
211 #ifdef MIPS_ABI_DEFAULT
212 /* Which ABI to use. This is defined to a constant in mips.h if the target
213 doesn't support multiple ABIs. */
217 /* Strings to hold which cpu and instruction set architecture to use. */
218 const char *mips_cpu_string
; /* for -mcpu=<xxx> */
219 const char *mips_arch_string
; /* for -march=<xxx> */
220 const char *mips_tune_string
; /* for -mtune=<xxx> */
221 const char *mips_isa_string
; /* for -mips{1,2,3,4} */
222 const char *mips_abi_string
; /* for -mabi={32,n32,64,eabi} */
224 /* Whether we are generating mips16 code. This is a synonym for
225 TARGET_MIPS16, and exists for use as an attribute. */
228 /* This variable is set by -mno-mips16. We only care whether
229 -mno-mips16 appears or not, and using a string in this fashion is
230 just a way to avoid using up another bit in target_flags. */
231 const char *mips_no_mips16_string
;
233 /* This is only used to determine if an type size setting option was
234 explicitly specified (-mlong64, -mint64, -mlong32). The specs
235 set this option if such an option is used. */
236 const char *mips_explicit_type_size_string
;
238 /* Whether we are generating mips16 hard float code. In mips16 mode
239 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
240 -msoft-float was not specified by the user, which means that we
241 should arrange to call mips32 hard floating point code. */
242 int mips16_hard_float
;
244 /* This variable is set by -mentry. We only care whether -mentry
245 appears or not, and using a string in this fashion is just a way to
246 avoid using up another bit in target_flags. */
247 const char *mips_entry_string
;
249 /* Whether we should entry and exit pseudo-ops in mips16 mode. */
252 /* If TRUE, we split addresses into their high and low parts in the RTL. */
253 int mips_split_addresses
;
255 /* Generating calls to position independent functions? */
256 enum mips_abicalls_type mips_abicalls
;
258 /* High and low marks for floating point values which we will accept
259 as legitimate constants for LEGITIMATE_CONSTANT_P. These are
260 initialized in override_options. */
261 REAL_VALUE_TYPE dfhigh
, dflow
, sfhigh
, sflow
;
263 /* Mode used for saving/restoring general purpose registers. */
264 static enum machine_mode gpr_mode
;
266 /* Array giving truth value on whether or not a given hard register
267 can support a given mode. */
268 char mips_hard_regno_mode_ok
[(int)MAX_MACHINE_MODE
][FIRST_PSEUDO_REGISTER
];
270 /* Current frame information calculated by compute_frame_size. */
271 struct mips_frame_info current_frame_info
;
273 /* Zero structure to initialize current_frame_info. */
274 struct mips_frame_info zero_frame_info
;
276 /* Temporary filename used to buffer .text until end of program
278 static char *temp_filename
;
280 /* Pseudo-reg holding the address of the current function when
281 generating embedded PIC code. Created by LEGITIMIZE_ADDRESS, used
282 by mips_finalize_pic if it was created. */
283 rtx embedded_pic_fnaddr_rtx
;
285 /* The length of all strings seen when compiling for the mips16. This
286 is used to tell how many strings are in the constant pool, so that
287 we can see if we may have an overflow. This is reset each time the
288 constant pool is output. */
289 int mips_string_length
;
291 /* Pseudo-reg holding the value of $28 in a mips16 function which
292 refers to GP relative global variables. */
293 rtx mips16_gp_pseudo_rtx
;
295 /* In mips16 mode, we build a list of all the string constants we see
296 in a particular function. */
298 struct string_constant
300 struct string_constant
*next
;
304 static struct string_constant
*string_constants
;
306 /* List of all MIPS punctuation characters used by print_operand. */
307 char mips_print_operand_punct
[256];
309 /* Map GCC register number to debugger register number. */
310 int mips_dbx_regno
[FIRST_PSEUDO_REGISTER
];
312 /* Buffer to use to enclose a load/store operation with %{ %} to
313 turn on .set volatile. */
314 static char volatile_buffer
[60];
316 /* Hardware names for the registers. If -mrnames is used, this
317 will be overwritten with mips_sw_reg_names. */
319 char mips_reg_names
[][8] =
321 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
322 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
323 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
324 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
325 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
326 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
327 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
328 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
329 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
330 "$fcc5","$fcc6","$fcc7","$rap"
333 /* Mips software names for the registers, used to overwrite the
334 mips_reg_names array. */
336 char mips_sw_reg_names
[][8] =
338 "$zero","$at", "$v0", "$v1", "$a0", "$a1", "$a2", "$a3",
339 "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
340 "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7",
341 "$t8", "$t9", "$k0", "$k1", "$gp", "$sp", "$fp", "$ra",
342 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
343 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
344 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
345 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
346 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
347 "$fcc5","$fcc6","$fcc7","$rap"
350 /* Map hard register number to register class */
351 enum reg_class mips_regno_to_class
[] =
353 GR_REGS
, GR_REGS
, M16_NA_REGS
, M16_NA_REGS
,
354 M16_REGS
, M16_REGS
, M16_REGS
, M16_REGS
,
355 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
356 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
357 M16_NA_REGS
, M16_NA_REGS
, GR_REGS
, GR_REGS
,
358 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
359 T_REG
, GR_REGS
, GR_REGS
, GR_REGS
,
360 GR_REGS
, GR_REGS
, GR_REGS
, GR_REGS
,
361 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
362 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
363 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
364 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
365 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
366 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
367 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
368 FP_REGS
, FP_REGS
, FP_REGS
, FP_REGS
,
369 HI_REG
, LO_REG
, HILO_REG
, ST_REGS
,
370 ST_REGS
, ST_REGS
, ST_REGS
, ST_REGS
,
371 ST_REGS
, ST_REGS
, ST_REGS
, GR_REGS
374 /* Map register constraint character to register class. */
375 enum reg_class mips_char_to_class
[256] =
377 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
378 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
379 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
380 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
381 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
382 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
383 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
384 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
385 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
386 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
387 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
388 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
389 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
390 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
391 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
392 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
393 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
394 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
395 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
396 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
397 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
398 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
399 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
400 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
401 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
402 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
403 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
404 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
405 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
406 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
407 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
408 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
409 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
410 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
411 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
412 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
413 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
414 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
415 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
416 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
417 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
418 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
419 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
420 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
421 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
422 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
423 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
424 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
425 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
426 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
427 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
428 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
429 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
430 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
431 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
432 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
433 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
434 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
435 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
436 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
437 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
438 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
439 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
440 NO_REGS
, NO_REGS
, NO_REGS
, NO_REGS
,
443 /* Initialize the GCC target structure. */
444 #undef TARGET_ASM_FUNCTION_PROLOGUE
445 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
446 #undef TARGET_ASM_FUNCTION_EPILOGUE
447 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
449 struct gcc_target target
= TARGET_INITIALIZER
;
451 /* Return truth value of whether OP can be used as an operands
452 where a register or 16 bit unsigned integer is needed. */
455 uns_arith_operand (op
, mode
)
457 enum machine_mode mode
;
459 if (GET_CODE (op
) == CONST_INT
&& SMALL_INT_UNSIGNED (op
))
462 return register_operand (op
, mode
);
465 /* Return truth value of whether OP can be used as an operands
466 where a 16 bit integer is needed */
469 arith_operand (op
, mode
)
471 enum machine_mode mode
;
473 if (GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
))
476 /* On the mips16, a GP relative value is a signed 16 bit offset. */
477 if (TARGET_MIPS16
&& GET_CODE (op
) == CONST
&& mips16_gp_offset_p (op
))
480 return register_operand (op
, mode
);
483 /* Return truth value of whether OP can be used as an operand in a two
484 address arithmetic insn (such as set 123456,%o4) of mode MODE. */
487 arith32_operand (op
, mode
)
489 enum machine_mode mode
;
491 if (GET_CODE (op
) == CONST_INT
)
494 return register_operand (op
, mode
);
497 /* Return truth value of whether OP is a integer which fits in 16 bits */
502 enum machine_mode mode ATTRIBUTE_UNUSED
;
504 return (GET_CODE (op
) == CONST_INT
&& SMALL_INT (op
));
507 /* Return truth value of whether OP is a 32 bit integer which is too big to
508 be loaded with one instruction. */
513 enum machine_mode mode ATTRIBUTE_UNUSED
;
517 if (GET_CODE (op
) != CONST_INT
)
522 /* ior reg,$r0,value */
523 if ((value
& ~ ((HOST_WIDE_INT
) 0x0000ffff)) == 0)
526 /* subu reg,$r0,value */
527 if (((unsigned HOST_WIDE_INT
) (value
+ 32768)) <= 32767)
530 /* lui reg,value>>16 */
531 if ((value
& 0x0000ffff) == 0)
537 /* Return truth value of whether OP is a register or the constant 0.
538 In mips16 mode, we only accept a register, since the mips16 does
542 reg_or_0_operand (op
, mode
)
544 enum machine_mode mode
;
546 switch (GET_CODE (op
))
551 return INTVAL (op
) == 0;
556 return op
== CONST0_RTX (mode
);
560 return register_operand (op
, mode
);
569 /* Return truth value of whether OP is a register or the constant 0,
570 even in mips16 mode. */
573 true_reg_or_0_operand (op
, mode
)
575 enum machine_mode mode
;
577 switch (GET_CODE (op
))
580 return INTVAL (op
) == 0;
583 return op
== CONST0_RTX (mode
);
587 return register_operand (op
, mode
);
596 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant. */
599 mips_const_double_ok (op
, mode
)
601 enum machine_mode mode
;
605 if (GET_CODE (op
) != CONST_DOUBLE
)
608 if (mode
== VOIDmode
)
611 if (mode
!= SFmode
&& mode
!= DFmode
)
614 if (op
== CONST0_RTX (mode
))
617 /* ??? li.s does not work right with SGI's Irix 6 assembler. */
618 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
&& mips_abi
!= ABI_EABI
)
621 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
623 if (REAL_VALUE_ISNAN (d
))
626 if (REAL_VALUE_NEGATIVE (d
))
627 d
= REAL_VALUE_NEGATE (d
);
631 if (REAL_VALUES_LESS (d
, dfhigh
)
632 && REAL_VALUES_LESS (dflow
, d
))
637 if (REAL_VALUES_LESS (d
, sfhigh
)
638 && REAL_VALUES_LESS (sflow
, d
))
645 /* Accept the floating point constant 1 in the appropriate mode. */
648 const_float_1_operand (op
, mode
)
650 enum machine_mode mode
;
653 static REAL_VALUE_TYPE onedf
;
654 static REAL_VALUE_TYPE onesf
;
655 static int one_initialized
;
657 if (GET_CODE (op
) != CONST_DOUBLE
658 || mode
!= GET_MODE (op
)
659 || (mode
!= DFmode
&& mode
!= SFmode
))
662 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
664 /* We only initialize these values if we need them, since we will
665 never get called unless mips_isa >= 4. */
666 if (! one_initialized
)
668 onedf
= REAL_VALUE_ATOF ("1.0", DFmode
);
669 onesf
= REAL_VALUE_ATOF ("1.0", SFmode
);
674 return REAL_VALUES_EQUAL (d
, onedf
);
676 return REAL_VALUES_EQUAL (d
, onesf
);
679 /* Return true if a memory load or store of REG plus OFFSET in MODE
680 can be represented in a single word on the mips16. */
683 mips16_simple_memory_operand (reg
, offset
, mode
)
686 enum machine_mode mode
;
693 /* We can't tell, because we don't know how the value will
694 eventually be accessed. Returning 0 here does no great
695 harm; it just prevents some possible instruction scheduling. */
699 size
= GET_MODE_SIZE (mode
);
701 if (INTVAL (offset
) % size
!= 0)
703 if (REGNO (reg
) == STACK_POINTER_REGNUM
&& GET_MODE_SIZE (mode
) == 4)
707 if (INTVAL (offset
) >= 0 && INTVAL (offset
) < (HOST_WIDE_INT
)(off
* size
))
712 /* Return truth value if a memory operand fits in a single instruction
713 (ie, register + small offset). */
716 simple_memory_operand (op
, mode
)
718 enum machine_mode mode
;
720 rtx addr
, plus0
, plus1
;
722 /* Eliminate non-memory operations */
723 if (GET_CODE (op
) != MEM
)
726 /* dword operations really put out 2 instructions, so eliminate them. */
727 /* ??? This isn't strictly correct. It is OK to accept multiword modes
728 here, since the length attributes are being set correctly, but only
729 if the address is offsettable. LO_SUM is not offsettable. */
730 if (GET_MODE_SIZE (GET_MODE (op
)) > (unsigned) UNITS_PER_WORD
)
733 /* Decode the address now. */
735 switch (GET_CODE (addr
))
744 return SMALL_INT (addr
);
747 plus0
= XEXP (addr
, 0);
748 plus1
= XEXP (addr
, 1);
749 if (GET_CODE (plus0
) == REG
750 && GET_CODE (plus1
) == CONST_INT
&& SMALL_INT (plus1
)
752 || mips16_simple_memory_operand (plus0
, plus1
, mode
)))
755 else if (GET_CODE (plus1
) == REG
756 && GET_CODE (plus0
) == CONST_INT
&& SMALL_INT (plus0
)
758 || mips16_simple_memory_operand (plus1
, plus0
, mode
)))
765 /* We used to allow small symbol refs here (ie, stuff in .sdata
766 or .sbss), but this causes some bugs in G++. Also, it won't
767 interfere if the MIPS linker rewrites the store instruction
768 because the function is PIC. */
770 case LABEL_REF
: /* never gp relative */
774 /* If -G 0, we can never have a GP relative memory operation.
775 Also, save some time if not optimizing. */
780 rtx offset
= const0_rtx
;
781 addr
= eliminate_constant_term (XEXP (addr
, 0), &offset
);
782 if (GET_CODE (op
) != SYMBOL_REF
)
785 /* let's be paranoid.... */
786 if (! SMALL_INT (offset
))
793 return SYMBOL_REF_FLAG (addr
);
796 /* This SYMBOL_REF case is for the mips16. If the above case is
797 reenabled, this one should be merged in. */
799 /* References to the constant pool on the mips16 use a small
800 offset if the function is small. The only time we care about
801 getting this right is during delayed branch scheduling, so
802 don't need to check until then. The machine_dependent_reorg
803 function will set the total length of the instructions used
804 in the function in current_frame_info. If that is small
805 enough, we know for sure that this is a small offset. It
806 would be better if we could take into account the location of
807 the instruction within the function, but we can't, because we
808 don't know where we are. */
810 && CONSTANT_POOL_ADDRESS_P (addr
)
811 && current_frame_info
.insns_len
> 0)
815 size
= current_frame_info
.insns_len
+ get_pool_size ();
816 if (GET_MODE_SIZE (mode
) == 4)
817 return size
< 4 * 0x100;
818 else if (GET_MODE_SIZE (mode
) == 8)
819 return size
< 8 * 0x20;
833 /* Return nonzero for a memory address that can be used to load or store
837 double_memory_operand (op
, mode
)
839 enum machine_mode mode
;
843 if (GET_CODE (op
) != MEM
844 || ! memory_operand (op
, mode
))
846 /* During reload, we accept a pseudo register if it has an
847 appropriate memory address. If we don't do this, we will
848 wind up reloading into a register, and then reloading that
849 register from memory, when we could just reload directly from
851 if (reload_in_progress
852 && GET_CODE (op
) == REG
853 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
854 && reg_renumber
[REGNO (op
)] < 0
855 && reg_equiv_mem
[REGNO (op
)] != 0
856 && double_memory_operand (reg_equiv_mem
[REGNO (op
)], mode
))
859 /* All reloaded addresses are valid in TARGET_64BIT mode. This is
860 the same test performed for 'm' in find_reloads. */
862 if (reload_in_progress
864 && (GET_CODE (op
) == MEM
865 || (GET_CODE (op
) == REG
866 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
867 && reg_renumber
[REGNO (op
)] < 0)))
870 if (reload_in_progress
872 && GET_CODE (op
) == MEM
)
878 /* During reload on the mips16, we accept a large offset
879 from the frame pointer or the stack pointer. This large
880 address will get reloaded anyhow. */
881 if (GET_CODE (addr
) == PLUS
882 && GET_CODE (XEXP (addr
, 0)) == REG
883 && (REGNO (XEXP (addr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
884 || REGNO (XEXP (addr
, 0)) == STACK_POINTER_REGNUM
)
885 && ((GET_CODE (XEXP (addr
, 1)) == CONST_INT
886 && ! SMALL_INT (XEXP (addr
, 1)))
887 || (GET_CODE (XEXP (addr
, 1)) == SYMBOL_REF
888 && CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 1)))))
891 /* Similarly, we accept a case where the memory address is
892 itself on the stack, and will be reloaded. */
893 if (GET_CODE (addr
) == MEM
)
897 maddr
= XEXP (addr
, 0);
898 if (GET_CODE (maddr
) == PLUS
899 && GET_CODE (XEXP (maddr
, 0)) == REG
900 && (REGNO (XEXP (maddr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
901 || REGNO (XEXP (maddr
, 0)) == STACK_POINTER_REGNUM
)
902 && ((GET_CODE (XEXP (maddr
, 1)) == CONST_INT
903 && ! SMALL_INT (XEXP (maddr
, 1)))
904 || (GET_CODE (XEXP (maddr
, 1)) == SYMBOL_REF
905 && CONSTANT_POOL_ADDRESS_P (XEXP (maddr
, 1)))))
909 /* We also accept the same case when we have a 16 bit signed
910 offset mixed in as well. The large address will get
911 reloaded, and the 16 bit offset will be OK. */
912 if (GET_CODE (addr
) == PLUS
913 && GET_CODE (XEXP (addr
, 0)) == MEM
914 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
915 && SMALL_INT (XEXP (addr
, 1)))
917 addr
= XEXP (XEXP (addr
, 0), 0);
918 if (GET_CODE (addr
) == PLUS
919 && GET_CODE (XEXP (addr
, 0)) == REG
920 && (REGNO (XEXP (addr
, 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM
921 || REGNO (XEXP (addr
, 0)) == STACK_POINTER_REGNUM
)
922 && ((GET_CODE (XEXP (addr
, 1)) == CONST_INT
923 && ! SMALL_INT (XEXP (addr
, 1)))
924 || (GET_CODE (XEXP (addr
, 1)) == SYMBOL_REF
925 && CONSTANT_POOL_ADDRESS_P (XEXP (addr
, 1)))))
935 /* In this case we can use an instruction like sd. */
939 /* Make sure that 4 added to the address is a valid memory address.
940 This essentially just checks for overflow in an added constant. */
944 if (CONSTANT_ADDRESS_P (addr
))
947 return memory_address_p ((GET_MODE_CLASS (mode
) == MODE_INT
949 plus_constant (addr
, 4));
952 /* Return nonzero if the code of this rtx pattern is EQ or NE. */
955 equality_op (op
, mode
)
957 enum machine_mode mode
;
959 if (mode
!= GET_MODE (op
))
962 return GET_CODE (op
) == EQ
|| GET_CODE (op
) == NE
;
965 /* Return nonzero if the code is a relational operations (EQ, LE, etc.) */
970 enum machine_mode mode
;
972 if (mode
!= GET_MODE (op
))
975 return GET_RTX_CLASS (GET_CODE (op
)) == '<';
978 /* Return nonzero if the code is a relational operation suitable for a
979 conditional trap instructuion (only EQ, NE, LT, LTU, GE, GEU).
980 We need this in the insn that expands `trap_if' in order to prevent
981 combine from erroneously altering the condition. */
984 trap_cmp_op (op
, mode
)
986 enum machine_mode mode
;
988 if (mode
!= GET_MODE (op
))
991 switch (GET_CODE (op
))
1006 /* Return nonzero if the operand is either the PC or a label_ref. */
1009 pc_or_label_operand (op
, mode
)
1011 enum machine_mode mode ATTRIBUTE_UNUSED
;
1016 if (GET_CODE (op
) == LABEL_REF
)
1022 /* Test for a valid operand for a call instruction.
1023 Don't allow the arg pointer register or virtual regs
1024 since they may change into reg + const, which the patterns
1025 can't handle yet. */
1028 call_insn_operand (op
, mode
)
1030 enum machine_mode mode ATTRIBUTE_UNUSED
;
1032 return (CONSTANT_ADDRESS_P (op
)
1033 || (GET_CODE (op
) == REG
&& op
!= arg_pointer_rtx
1034 && ! (REGNO (op
) >= FIRST_PSEUDO_REGISTER
1035 && REGNO (op
) <= LAST_VIRTUAL_REGISTER
)));
1038 /* Return nonzero if OPERAND is valid as a source operand for a move
1042 move_operand (op
, mode
)
1044 enum machine_mode mode
;
1046 /* Accept any general operand after reload has started; doing so
1047 avoids losing if reload does an in-place replacement of a register
1048 with a SYMBOL_REF or CONST. */
1049 return (general_operand (op
, mode
)
1050 && (! (mips_split_addresses
&& mips_check_split (op
, mode
))
1051 || reload_in_progress
|| reload_completed
)
1053 && GET_CODE (op
) == SYMBOL_REF
1054 && ! mips16_constant (op
, mode
, 1, 0)));
1057 /* Return nonzero if OPERAND is valid as a source operand for movdi.
1058 This accepts not only general_operand, but also sign extended
1059 constants and registers. We need to accept sign extended constants
1060 in case a sign extended register which is used in an expression,
1061 and is equivalent to a constant, is spilled. */
1064 movdi_operand (op
, mode
)
1066 enum machine_mode mode
;
1070 && GET_CODE (op
) == SIGN_EXTEND
1071 && GET_MODE (op
) == DImode
1072 && (GET_MODE (XEXP (op
, 0)) == SImode
1073 || (GET_CODE (XEXP (op
, 0)) == CONST_INT
1074 && GET_MODE (XEXP (op
, 0)) == VOIDmode
))
1075 && (register_operand (XEXP (op
, 0), SImode
)
1076 || immediate_operand (XEXP (op
, 0), SImode
)))
1079 return (general_operand (op
, mode
)
1081 && GET_CODE (op
) == SYMBOL_REF
1082 && ! mips16_constant (op
, mode
, 1, 0)));
1085 /* Like register_operand, but when in 64 bit mode also accept a sign
1086 extend of a 32 bit register, since the value is known to be already
1090 se_register_operand (op
, mode
)
1092 enum machine_mode mode
;
1096 && GET_CODE (op
) == SIGN_EXTEND
1097 && GET_MODE (op
) == DImode
1098 && GET_MODE (XEXP (op
, 0)) == SImode
1099 && register_operand (XEXP (op
, 0), SImode
))
1102 return register_operand (op
, mode
);
1105 /* Like reg_or_0_operand, but when in 64 bit mode also accept a sign
1106 extend of a 32 bit register, since the value is known to be already
1110 se_reg_or_0_operand (op
, mode
)
1112 enum machine_mode mode
;
1116 && GET_CODE (op
) == SIGN_EXTEND
1117 && GET_MODE (op
) == DImode
1118 && GET_MODE (XEXP (op
, 0)) == SImode
1119 && register_operand (XEXP (op
, 0), SImode
))
1122 return reg_or_0_operand (op
, mode
);
1125 /* Like uns_arith_operand, but when in 64 bit mode also accept a sign
1126 extend of a 32 bit register, since the value is known to be already
1130 se_uns_arith_operand (op
, mode
)
1132 enum machine_mode mode
;
1136 && GET_CODE (op
) == SIGN_EXTEND
1137 && GET_MODE (op
) == DImode
1138 && GET_MODE (XEXP (op
, 0)) == SImode
1139 && register_operand (XEXP (op
, 0), SImode
))
1142 return uns_arith_operand (op
, mode
);
1145 /* Like arith_operand, but when in 64 bit mode also accept a sign
1146 extend of a 32 bit register, since the value is known to be already
1150 se_arith_operand (op
, mode
)
1152 enum machine_mode mode
;
1156 && GET_CODE (op
) == SIGN_EXTEND
1157 && GET_MODE (op
) == DImode
1158 && GET_MODE (XEXP (op
, 0)) == SImode
1159 && register_operand (XEXP (op
, 0), SImode
))
1162 return arith_operand (op
, mode
);
1165 /* Like nonmemory_operand, but when in 64 bit mode also accept a sign
1166 extend of a 32 bit register, since the value is known to be already
1170 se_nonmemory_operand (op
, mode
)
1172 enum machine_mode mode
;
1176 && GET_CODE (op
) == SIGN_EXTEND
1177 && GET_MODE (op
) == DImode
1178 && GET_MODE (XEXP (op
, 0)) == SImode
1179 && register_operand (XEXP (op
, 0), SImode
))
1182 return nonmemory_operand (op
, mode
);
1185 /* Like nonimmediate_operand, but when in 64 bit mode also accept a
1186 sign extend of a 32 bit register, since the value is known to be
1187 already sign extended. */
1190 se_nonimmediate_operand (op
, mode
)
1192 enum machine_mode mode
;
1196 && GET_CODE (op
) == SIGN_EXTEND
1197 && GET_MODE (op
) == DImode
1198 && GET_MODE (XEXP (op
, 0)) == SImode
1199 && register_operand (XEXP (op
, 0), SImode
))
1202 return nonimmediate_operand (op
, mode
);
1205 /* Accept any operand that can appear in a mips16 constant table
1206 instruction. We can't use any of the standard operand functions
1207 because for these instructions we accept values that are not
1208 accepted by LEGITIMATE_CONSTANT, such as arbitrary SYMBOL_REFs. */
1211 consttable_operand (op
, mode
)
1213 enum machine_mode mode ATTRIBUTE_UNUSED
;
1215 return CONSTANT_P (op
);
1218 /* Return nonzero if we split the address into high and low parts. */
1220 /* ??? We should also handle reg+array somewhere. We get four
1221 instructions currently, lui %hi/addui %lo/addui reg/lw. Better is
1222 lui %hi/addui reg/lw %lo. Fixing GO_IF_LEGITIMATE_ADDRESS to accept
1223 (plus (reg) (symbol_ref)) doesn't work because the SYMBOL_REF is broken
1224 out of the address, then we have 4 instructions to combine. Perhaps
1225 add a 3->2 define_split for combine. */
1227 /* ??? We could also split a CONST_INT here if it is a large_int().
1228 However, it doesn't seem to be very useful to have %hi(constant).
1229 We would be better off by doing the masking ourselves and then putting
1230 the explicit high part of the constant in the RTL. This will give better
1231 optimization. Also, %hi(constant) needs assembler changes to work.
1232 There is already a define_split that does this. */
1235 mips_check_split (address
, mode
)
1237 enum machine_mode mode
;
1239 /* ??? This is the same check used in simple_memory_operand.
1240 We use it here because LO_SUM is not offsettable. */
1241 if (GET_MODE_SIZE (mode
) > (unsigned) UNITS_PER_WORD
)
1244 if ((GET_CODE (address
) == SYMBOL_REF
&& ! SYMBOL_REF_FLAG (address
))
1245 || (GET_CODE (address
) == CONST
1246 && GET_CODE (XEXP (XEXP (address
, 0), 0)) == SYMBOL_REF
1247 && ! SYMBOL_REF_FLAG (XEXP (XEXP (address
, 0), 0)))
1248 || GET_CODE (address
) == LABEL_REF
)
1254 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1257 mips_reg_mode_ok_for_base_p (reg
, mode
, strict
)
1259 enum machine_mode mode
;
1263 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg
), mode
)
1264 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg
), mode
));
1267 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1268 returns a nonzero value if XINSN is a legitimate address for a
1269 memory operand of the indicated MODE. STRICT is non-zero if this
1270 function is called during reload. */
1273 mips_legitimate_address_p (mode
, xinsn
, strict
)
1274 enum machine_mode mode
;
1278 if (TARGET_DEBUG_B_MODE
)
1280 GO_PRINTF2 ("\n========== GO_IF_LEGITIMATE_ADDRESS, %sstrict\n",
1281 strict
? "" : "not ");
1282 GO_DEBUG_RTX (xinsn
);
1285 /* Check for constant before stripping off SUBREG, so that we don't
1286 accept (subreg (const_int)) which will fail to reload. */
1287 if (CONSTANT_ADDRESS_P (xinsn
)
1288 && ! (mips_split_addresses
&& mips_check_split (xinsn
, mode
))
1289 && (! TARGET_MIPS16
|| mips16_constant (xinsn
, mode
, 1, 0)))
1292 while (GET_CODE (xinsn
) == SUBREG
)
1293 xinsn
= SUBREG_REG (xinsn
);
1295 /* The mips16 can only use the stack pointer as a base register when
1296 loading SImode or DImode values. */
1297 if (GET_CODE (xinsn
) == REG
1298 && mips_reg_mode_ok_for_base_p (xinsn
, mode
, strict
))
1301 if (GET_CODE (xinsn
) == LO_SUM
&& mips_split_addresses
)
1303 register rtx xlow0
= XEXP (xinsn
, 0);
1304 register rtx xlow1
= XEXP (xinsn
, 1);
1306 while (GET_CODE (xlow0
) == SUBREG
)
1307 xlow0
= SUBREG_REG (xlow0
);
1308 if (GET_CODE (xlow0
) == REG
1309 && mips_reg_mode_ok_for_base_p (xlow0
, mode
, strict
)
1310 && mips_check_split (xlow1
, mode
))
1314 if (GET_CODE (xinsn
) == PLUS
)
1316 register rtx xplus0
= XEXP (xinsn
, 0);
1317 register rtx xplus1
= XEXP (xinsn
, 1);
1318 register enum rtx_code code0
;
1319 register enum rtx_code code1
;
1321 while (GET_CODE (xplus0
) == SUBREG
)
1322 xplus0
= SUBREG_REG (xplus0
);
1323 code0
= GET_CODE (xplus0
);
1325 while (GET_CODE (xplus1
) == SUBREG
)
1326 xplus1
= SUBREG_REG (xplus1
);
1327 code1
= GET_CODE (xplus1
);
1329 /* The mips16 can only use the stack pointer as a base register
1330 when loading SImode or DImode values. */
1332 && mips_reg_mode_ok_for_base_p (xplus0
, mode
, strict
))
1334 if (code1
== CONST_INT
&& SMALL_INT (xplus1
))
1337 /* On the mips16, we represent GP relative offsets in RTL.
1338 These are 16 bit signed values, and can serve as register
1341 && mips16_gp_offset_p (xplus1
))
1344 /* For some code sequences, you actually get better code by
1345 pretending that the MIPS supports an address mode of a
1346 constant address + a register, even though the real
1347 machine doesn't support it. This is because the
1348 assembler can use $r1 to load just the high 16 bits, add
1349 in the register, and fold the low 16 bits into the memory
1350 reference, whereas the compiler generates a 4 instruction
1351 sequence. On the other hand, CSE is not as effective.
1352 It would be a win to generate the lui directly, but the
1353 MIPS assembler does not have syntax to generate the
1354 appropriate relocation. */
1356 /* Also accept CONST_INT addresses here, so no else. */
1357 /* Reject combining an embedded PIC text segment reference
1358 with a register. That requires an additional
1360 /* ??? Reject combining an address with a register for the MIPS
1361 64 bit ABI, because the SGI assembler can not handle this. */
1362 if (!TARGET_DEBUG_A_MODE
1363 && (mips_abi
== ABI_32
1364 || mips_abi
== ABI_O64
1365 || mips_abi
== ABI_EABI
)
1366 && CONSTANT_ADDRESS_P (xplus1
)
1367 && ! mips_split_addresses
1368 && (!TARGET_EMBEDDED_PIC
1370 || GET_CODE (XEXP (xplus1
, 0)) != MINUS
)
1371 /* When assembling for machines with 64 bit registers,
1372 the assembler will not sign-extend the constant "foo"
1373 in "la x, foo(x)" */
1374 && (!TARGET_64BIT
|| (INTVAL (xplus1
) > 0))
1380 if (TARGET_DEBUG_B_MODE
)
1381 GO_PRINTF ("Not a legitimate address\n");
1383 /* The address was not legitimate. */
1388 /* We need a lot of little routines to check constant values on the
1389 mips16. These are used to figure out how long the instruction will
1390 be. It would be much better to do this using constraints, but
1391 there aren't nearly enough letters available. */
1394 m16_check_op (op
, low
, high
, mask
)
1400 return (GET_CODE (op
) == CONST_INT
1401 && INTVAL (op
) >= low
1402 && INTVAL (op
) <= high
1403 && (INTVAL (op
) & mask
) == 0);
1407 m16_uimm3_b (op
, mode
)
1409 enum machine_mode mode ATTRIBUTE_UNUSED
;
1411 return m16_check_op (op
, 0x1, 0x8, 0);
1415 m16_simm4_1 (op
, mode
)
1417 enum machine_mode mode ATTRIBUTE_UNUSED
;
1419 return m16_check_op (op
, - 0x8, 0x7, 0);
1423 m16_nsimm4_1 (op
, mode
)
1425 enum machine_mode mode ATTRIBUTE_UNUSED
;
1427 return m16_check_op (op
, - 0x7, 0x8, 0);
1431 m16_simm5_1 (op
, mode
)
1433 enum machine_mode mode ATTRIBUTE_UNUSED
;
1435 return m16_check_op (op
, - 0x10, 0xf, 0);
1439 m16_nsimm5_1 (op
, mode
)
1441 enum machine_mode mode ATTRIBUTE_UNUSED
;
1443 return m16_check_op (op
, - 0xf, 0x10, 0);
1447 m16_uimm5_4 (op
, mode
)
1449 enum machine_mode mode ATTRIBUTE_UNUSED
;
1451 return m16_check_op (op
, (- 0x10) << 2, 0xf << 2, 3);
1455 m16_nuimm5_4 (op
, mode
)
1457 enum machine_mode mode ATTRIBUTE_UNUSED
;
1459 return m16_check_op (op
, (- 0xf) << 2, 0x10 << 2, 3);
1463 m16_simm8_1 (op
, mode
)
1465 enum machine_mode mode ATTRIBUTE_UNUSED
;
1467 return m16_check_op (op
, - 0x80, 0x7f, 0);
1471 m16_nsimm8_1 (op
, mode
)
1473 enum machine_mode mode ATTRIBUTE_UNUSED
;
1475 return m16_check_op (op
, - 0x7f, 0x80, 0);
1479 m16_uimm8_1 (op
, mode
)
1481 enum machine_mode mode ATTRIBUTE_UNUSED
;
1483 return m16_check_op (op
, 0x0, 0xff, 0);
1487 m16_nuimm8_1 (op
, mode
)
1489 enum machine_mode mode ATTRIBUTE_UNUSED
;
1491 return m16_check_op (op
, - 0xff, 0x0, 0);
1495 m16_uimm8_m1_1 (op
, mode
)
1497 enum machine_mode mode ATTRIBUTE_UNUSED
;
1499 return m16_check_op (op
, - 0x1, 0xfe, 0);
1503 m16_uimm8_4 (op
, mode
)
1505 enum machine_mode mode ATTRIBUTE_UNUSED
;
1507 return m16_check_op (op
, 0x0, 0xff << 2, 3);
1511 m16_nuimm8_4 (op
, mode
)
1513 enum machine_mode mode ATTRIBUTE_UNUSED
;
1515 return m16_check_op (op
, (- 0xff) << 2, 0x0, 3);
1519 m16_simm8_8 (op
, mode
)
1521 enum machine_mode mode ATTRIBUTE_UNUSED
;
1523 return m16_check_op (op
, (- 0x80) << 3, 0x7f << 3, 7);
1527 m16_nsimm8_8 (op
, mode
)
1529 enum machine_mode mode ATTRIBUTE_UNUSED
;
1531 return m16_check_op (op
, (- 0x7f) << 3, 0x80 << 3, 7);
1534 /* References to the string table on the mips16 only use a small
1535 offset if the function is small. See the comment in the SYMBOL_REF
1536 case in simple_memory_operand. We can't check for LABEL_REF here,
1537 because the offset is always large if the label is before the
1538 referencing instruction. */
1541 m16_usym8_4 (op
, mode
)
1543 enum machine_mode mode ATTRIBUTE_UNUSED
;
1545 if (GET_CODE (op
) == SYMBOL_REF
1546 && SYMBOL_REF_FLAG (op
)
1547 && current_frame_info
.insns_len
> 0
1548 && XSTR (op
, 0)[0] == '*'
1549 && strncmp (XSTR (op
, 0) + 1, LOCAL_LABEL_PREFIX
,
1550 sizeof LOCAL_LABEL_PREFIX
- 1) == 0
1551 && (current_frame_info
.insns_len
+ get_pool_size () + mips_string_length
1554 struct string_constant
*l
;
1556 /* Make sure this symbol is on thelist of string constants to be
1557 output for this function. It is possible that it has already
1558 been output, in which case this requires a large offset. */
1559 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
1560 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
1568 m16_usym5_4 (op
, mode
)
1570 enum machine_mode mode ATTRIBUTE_UNUSED
;
1572 if (GET_CODE (op
) == SYMBOL_REF
1573 && SYMBOL_REF_FLAG (op
)
1574 && current_frame_info
.insns_len
> 0
1575 && XSTR (op
, 0)[0] == '*'
1576 && strncmp (XSTR (op
, 0) + 1, LOCAL_LABEL_PREFIX
,
1577 sizeof LOCAL_LABEL_PREFIX
- 1) == 0
1578 && (current_frame_info
.insns_len
+ get_pool_size () + mips_string_length
1581 struct string_constant
*l
;
1583 /* Make sure this symbol is on thelist of string constants to be
1584 output for this function. It is possible that it has already
1585 been output, in which case this requires a large offset. */
1586 for (l
= string_constants
; l
!= NULL
; l
= l
->next
)
1587 if (strcmp (l
->label
, XSTR (op
, 0)) == 0)
1594 /* Returns an operand string for the given instruction's delay slot,
1595 after updating filled delay slot statistics.
1597 We assume that operands[0] is the target register that is set.
1599 In order to check the next insn, most of this functionality is moved
1600 to FINAL_PRESCAN_INSN, and we just set the global variables that
1603 /* ??? This function no longer does anything useful, because final_prescan_insn
1604 now will never emit a nop. */
1607 mips_fill_delay_slot (ret
, type
, operands
, cur_insn
)
1608 const char *ret
; /* normal string to return */
1609 enum delay_type type
; /* type of delay */
1610 rtx operands
[]; /* operands to use */
1611 rtx cur_insn
; /* current insn */
1613 register rtx set_reg
;
1614 register enum machine_mode mode
;
1615 register rtx next_insn
= cur_insn
? NEXT_INSN (cur_insn
) : NULL_RTX
;
1616 register int num_nops
;
1618 if (type
== DELAY_LOAD
|| type
== DELAY_FCMP
)
1621 else if (type
== DELAY_HILO
)
1627 /* Make sure that we don't put nop's after labels. */
1628 next_insn
= NEXT_INSN (cur_insn
);
1629 while (next_insn
!= 0 && GET_CODE (next_insn
) == NOTE
)
1630 next_insn
= NEXT_INSN (next_insn
);
1632 dslots_load_total
+= num_nops
;
1633 if (TARGET_DEBUG_F_MODE
1635 || type
== DELAY_NONE
1639 || GET_CODE (next_insn
) == CODE_LABEL
1640 || (set_reg
= operands
[0]) == 0)
1642 dslots_number_nops
= 0;
1650 set_reg
= operands
[0];
1654 while (GET_CODE (set_reg
) == SUBREG
)
1655 set_reg
= SUBREG_REG (set_reg
);
1657 mode
= GET_MODE (set_reg
);
1658 dslots_number_nops
= num_nops
;
1659 mips_load_reg
= set_reg
;
1660 if (GET_MODE_SIZE (mode
)
1661 > (unsigned) (FP_REG_P (REGNO (set_reg
)) ? UNITS_PER_FPREG
: UNITS_PER_WORD
))
1662 mips_load_reg2
= gen_rtx_REG (SImode
, REGNO (set_reg
) + 1);
1666 if (type
== DELAY_HILO
)
1668 mips_load_reg3
= gen_rtx_REG (SImode
, MD_REG_FIRST
);
1669 mips_load_reg4
= gen_rtx_REG (SImode
, MD_REG_FIRST
+1);
1681 /* Determine whether a memory reference takes one (based off of the GP
1682 pointer), two (normal), or three (label + reg) instructions, and bump the
1683 appropriate counter for -mstats. */
1686 mips_count_memory_refs (op
, num
)
1692 rtx addr
, plus0
, plus1
;
1693 enum rtx_code code0
, code1
;
1696 if (TARGET_DEBUG_B_MODE
)
1698 fprintf (stderr
, "\n========== mips_count_memory_refs:\n");
1702 /* Skip MEM if passed, otherwise handle movsi of address. */
1703 addr
= (GET_CODE (op
) != MEM
) ? op
: XEXP (op
, 0);
1705 /* Loop, going through the address RTL. */
1709 switch (GET_CODE (addr
))
1717 plus0
= XEXP (addr
, 0);
1718 plus1
= XEXP (addr
, 1);
1719 code0
= GET_CODE (plus0
);
1720 code1
= GET_CODE (plus1
);
1730 if (code0
== CONST_INT
)
1745 if (code1
== CONST_INT
)
1752 if (code0
== SYMBOL_REF
|| code0
== LABEL_REF
|| code0
== CONST
)
1759 if (code1
== SYMBOL_REF
|| code1
== LABEL_REF
|| code1
== CONST
)
1769 n_words
= 2; /* always 2 words */
1773 addr
= XEXP (addr
, 0);
1778 n_words
= SYMBOL_REF_FLAG (addr
) ? 1 : 2;
1790 n_words
+= additional
;
1794 num_refs
[n_words
-1] += num
;
1798 /* Return RTL for the offset from the current function to the argument.
1800 ??? Which argument is this? */
1803 embedded_pic_offset (x
)
1806 if (embedded_pic_fnaddr_rtx
== NULL
)
1810 embedded_pic_fnaddr_rtx
= gen_reg_rtx (Pmode
);
1812 /* Output code at function start to initialize the pseudo-reg. */
1813 /* ??? We used to do this in FINALIZE_PIC, but that does not work for
1814 inline functions, because it is called after RTL for the function
1815 has been copied. The pseudo-reg in embedded_pic_fnaddr_rtx however
1816 does not get copied, and ends up not matching the rest of the RTL.
1817 This solution works, but means that we get unnecessary code to
1818 initialize this value every time a function is inlined into another
1821 emit_insn (gen_get_fnaddr (embedded_pic_fnaddr_rtx
,
1822 XEXP (DECL_RTL (current_function_decl
), 0)));
1823 seq
= gen_sequence ();
1825 push_topmost_sequence ();
1826 emit_insn_after (seq
, get_insns ());
1827 pop_topmost_sequence ();
1831 gen_rtx_CONST (Pmode
,
1832 gen_rtx_MINUS (Pmode
, x
,
1833 XEXP (DECL_RTL (current_function_decl
), 0)));
1836 /* Return the appropriate instructions to move one operand to another. */
1839 mips_move_1word (operands
, insn
, unsignedp
)
1844 const char *ret
= 0;
1845 rtx op0
= operands
[0];
1846 rtx op1
= operands
[1];
1847 enum rtx_code code0
= GET_CODE (op0
);
1848 enum rtx_code code1
= GET_CODE (op1
);
1849 enum machine_mode mode
= GET_MODE (op0
);
1850 int subreg_offset0
= 0;
1851 int subreg_offset1
= 0;
1852 enum delay_type delay
= DELAY_NONE
;
1854 while (code0
== SUBREG
)
1856 subreg_offset0
+= subreg_regno_offset (REGNO (SUBREG_REG (op0
)),
1857 GET_MODE (SUBREG_REG (op0
)),
1860 op0
= SUBREG_REG (op0
);
1861 code0
= GET_CODE (op0
);
1864 while (code1
== SUBREG
)
1866 subreg_offset1
+= subreg_regno_offset (REGNO (SUBREG_REG (op1
)),
1867 GET_MODE (SUBREG_REG (op1
)),
1870 op1
= SUBREG_REG (op1
);
1871 code1
= GET_CODE (op1
);
1874 /* For our purposes, a condition code mode is the same as SImode. */
1880 int regno0
= REGNO (op0
) + subreg_offset0
;
1884 int regno1
= REGNO (op1
) + subreg_offset1
;
1886 /* Just in case, don't do anything for assigning a register
1887 to itself, unless we are filling a delay slot. */
1888 if (regno0
== regno1
&& set_nomacro
== 0)
1891 else if (GP_REG_P (regno0
))
1893 if (GP_REG_P (regno1
))
1894 ret
= "move\t%0,%1";
1896 else if (MD_REG_P (regno1
))
1899 if (regno1
!= HILO_REGNUM
)
1905 else if (ST_REG_P (regno1
) && ISA_HAS_8CC
)
1906 ret
= "li\t%0,1\n\tmovf\t%0,%.,%1";
1911 if (FP_REG_P (regno1
))
1912 ret
= "mfc1\t%0,%1";
1914 else if (regno1
== FPSW_REGNUM
&& ! ISA_HAS_8CC
)
1915 ret
= "cfc1\t%0,$31";
1919 else if (FP_REG_P (regno0
))
1921 if (GP_REG_P (regno1
))
1924 ret
= "mtc1\t%1,%0";
1927 if (FP_REG_P (regno1
))
1928 ret
= "mov.s\t%0,%1";
1931 else if (MD_REG_P (regno0
))
1933 if (GP_REG_P (regno1
))
1936 if (regno0
!= HILO_REGNUM
&& ! TARGET_MIPS16
)
1941 else if (regno0
== FPSW_REGNUM
&& ! ISA_HAS_8CC
)
1943 if (GP_REG_P (regno1
))
1946 ret
= "ctc1\t%0,$31";
1951 else if (code1
== MEM
)
1956 mips_count_memory_refs (op1
, 1);
1958 if (GP_REG_P (regno0
))
1960 /* For loads, use the mode of the memory item, instead of the
1961 target, so zero/sign extend can use this code as well. */
1962 switch (GET_MODE (op1
))
1971 ret
= ((unsignedp
&& TARGET_64BIT
)
1976 ret
= (unsignedp
) ? "lhu\t%0,%1" : "lh\t%0,%1";
1979 ret
= (unsignedp
) ? "lbu\t%0,%1" : "lb\t%0,%1";
1984 else if (FP_REG_P (regno0
) && (mode
== SImode
|| mode
== SFmode
))
1987 if (ret
!= (char *)0 && MEM_VOLATILE_P (op1
))
1989 size_t i
= strlen (ret
);
1990 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
1993 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
1994 ret
= volatile_buffer
;
1998 else if (code1
== CONST_INT
1999 || (code1
== CONST_DOUBLE
2000 && GET_MODE (op1
) == VOIDmode
))
2002 if (code1
== CONST_DOUBLE
)
2004 /* This can happen when storing constants into long long
2005 bitfields. Just store the least significant word of
2007 operands
[1] = op1
= GEN_INT (CONST_DOUBLE_LOW (op1
));
2010 if (INTVAL (op1
) == 0 && ! TARGET_MIPS16
)
2012 if (GP_REG_P (regno0
))
2013 ret
= "move\t%0,%z1";
2015 else if (FP_REG_P (regno0
))
2018 ret
= "mtc1\t%z1,%0";
2021 else if (MD_REG_P (regno0
))
2028 else if (GP_REG_P (regno0
))
2030 /* Don't use X format, because that will give out of
2031 range numbers for 64 bit host and 32 bit target. */
2032 if (! TARGET_MIPS16
)
2033 ret
= "li\t%0,%1\t\t\t# %X1";
2036 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2038 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2039 ret
= "li\t%0,%n1\n\tneg\t%0";
2044 else if (code1
== CONST_DOUBLE
&& mode
== SFmode
)
2046 if (op1
== CONST0_RTX (SFmode
))
2048 if (GP_REG_P (regno0
))
2049 ret
= "move\t%0,%.";
2051 else if (FP_REG_P (regno0
))
2054 ret
= "mtc1\t%.,%0";
2061 ret
= "li.s\t%0,%1";
2065 else if (code1
== LABEL_REF
)
2068 mips_count_memory_refs (op1
, 1);
2073 else if (code1
== SYMBOL_REF
|| code1
== CONST
)
2075 if (HALF_PIC_P () && CONSTANT_P (op1
) && HALF_PIC_ADDRESS_P (op1
))
2077 rtx offset
= const0_rtx
;
2079 if (GET_CODE (op1
) == CONST
)
2080 op1
= eliminate_constant_term (XEXP (op1
, 0), &offset
);
2082 if (GET_CODE (op1
) == SYMBOL_REF
)
2084 operands
[2] = HALF_PIC_PTR (op1
);
2087 mips_count_memory_refs (operands
[2], 1);
2089 if (INTVAL (offset
) == 0)
2092 ret
= (unsignedp
&& TARGET_64BIT
2098 dslots_load_total
++;
2099 operands
[3] = offset
;
2100 if (unsignedp
&& TARGET_64BIT
)
2101 ret
= (SMALL_INT (offset
)
2102 ? "lwu\t%0,%2%#\n\tadd\t%0,%0,%3"
2103 : "lwu\t%0,%2%#\n\t%[li\t%@,%3\n\tadd\t%0,%0,%@%]");
2105 ret
= (SMALL_INT (offset
)
2106 ? "lw\t%0,%2%#\n\tadd\t%0,%0,%3"
2107 : "lw\t%0,%2%#\n\t%[li\t%@,%3\n\tadd\t%0,%0,%@%]");
2111 else if (TARGET_MIPS16
2113 && GET_CODE (XEXP (op1
, 0)) == REG
2114 && REGNO (XEXP (op1
, 0)) == GP_REG_FIRST
+ 28)
2116 /* This case arises on the mips16; see
2117 mips16_gp_pseudo_reg. */
2118 ret
= "move\t%0,%+";
2120 else if (TARGET_MIPS16
2121 && code1
== SYMBOL_REF
2122 && SYMBOL_REF_FLAG (op1
)
2123 && (XSTR (op1
, 0)[0] != '*'
2124 || strncmp (XSTR (op1
, 0) + 1,
2126 sizeof LOCAL_LABEL_PREFIX
- 1) != 0))
2128 /* This can occur when reloading the address of a GP
2129 relative symbol on the mips16. */
2130 ret
= "move\t%0,%+\n\taddu\t%0,%%gprel(%a1)";
2135 mips_count_memory_refs (op1
, 1);
2141 else if (code1
== PLUS
)
2143 rtx add_op0
= XEXP (op1
, 0);
2144 rtx add_op1
= XEXP (op1
, 1);
2146 if (GET_CODE (XEXP (op1
, 1)) == REG
2147 && GET_CODE (XEXP (op1
, 0)) == CONST_INT
)
2148 add_op0
= XEXP (op1
, 1), add_op1
= XEXP (op1
, 0);
2150 operands
[2] = add_op0
;
2151 operands
[3] = add_op1
;
2152 ret
= "add%:\t%0,%2,%3";
2155 else if (code1
== HIGH
)
2157 operands
[1] = XEXP (op1
, 0);
2158 ret
= "lui\t%0,%%hi(%1)";
2162 else if (code0
== MEM
)
2165 mips_count_memory_refs (op0
, 1);
2169 int regno1
= REGNO (op1
) + subreg_offset1
;
2171 if (GP_REG_P (regno1
))
2175 case SFmode
: ret
= "sw\t%1,%0"; break;
2176 case SImode
: ret
= "sw\t%1,%0"; break;
2177 case HImode
: ret
= "sh\t%1,%0"; break;
2178 case QImode
: ret
= "sb\t%1,%0"; break;
2183 else if (FP_REG_P (regno1
) && (mode
== SImode
|| mode
== SFmode
))
2187 else if (code1
== CONST_INT
&& INTVAL (op1
) == 0)
2191 case SFmode
: ret
= "sw\t%z1,%0"; break;
2192 case SImode
: ret
= "sw\t%z1,%0"; break;
2193 case HImode
: ret
= "sh\t%z1,%0"; break;
2194 case QImode
: ret
= "sb\t%z1,%0"; break;
2199 else if (code1
== CONST_DOUBLE
&& op1
== CONST0_RTX (mode
))
2203 case SFmode
: ret
= "sw\t%.,%0"; break;
2204 case SImode
: ret
= "sw\t%.,%0"; break;
2205 case HImode
: ret
= "sh\t%.,%0"; break;
2206 case QImode
: ret
= "sb\t%.,%0"; break;
2211 if (ret
!= 0 && MEM_VOLATILE_P (op0
))
2213 size_t i
= strlen (ret
);
2215 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2218 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2219 ret
= volatile_buffer
;
2225 abort_with_insn (insn
, "Bad move");
2229 if (delay
!= DELAY_NONE
)
2230 return mips_fill_delay_slot (ret
, delay
, operands
, insn
);
2236 /* Return the appropriate instructions to move 2 words */
2239 mips_move_2words (operands
, insn
)
2243 const char *ret
= 0;
2244 rtx op0
= operands
[0];
2245 rtx op1
= operands
[1];
2246 enum rtx_code code0
= GET_CODE (operands
[0]);
2247 enum rtx_code code1
= GET_CODE (operands
[1]);
2248 int subreg_offset0
= 0;
2249 int subreg_offset1
= 0;
2250 enum delay_type delay
= DELAY_NONE
;
2252 while (code0
== SUBREG
)
2254 subreg_offset0
+= subreg_regno_offset (REGNO (SUBREG_REG (op0
)),
2255 GET_MODE (SUBREG_REG (op0
)),
2258 op0
= SUBREG_REG (op0
);
2259 code0
= GET_CODE (op0
);
2262 if (code1
== SIGN_EXTEND
)
2264 op1
= XEXP (op1
, 0);
2265 code1
= GET_CODE (op1
);
2268 while (code1
== SUBREG
)
2270 subreg_offset1
+= subreg_regno_offset (REGNO (SUBREG_REG (op1
)),
2271 GET_MODE (SUBREG_REG (op1
)),
2274 op1
= SUBREG_REG (op1
);
2275 code1
= GET_CODE (op1
);
2279 if (GET_CODE (operands
[1]) == SIGN_EXTEND
2281 && code1
!= CONST_INT
2282 /* The following three can happen as the result of a questionable
2284 && code1
!= LABEL_REF
2285 && code1
!= SYMBOL_REF
2291 int regno0
= REGNO (op0
) + subreg_offset0
;
2295 int regno1
= REGNO (op1
) + subreg_offset1
;
2297 /* Just in case, don't do anything for assigning a register
2298 to itself, unless we are filling a delay slot. */
2299 if (regno0
== regno1
&& set_nomacro
== 0)
2302 else if (FP_REG_P (regno0
))
2304 if (FP_REG_P (regno1
))
2305 ret
= "mov.d\t%0,%1";
2313 abort_with_insn (insn
, "Bad move");
2315 #ifdef TARGET_FP_CALL_32
2316 if (FP_CALL_GP_REG_P (regno1
))
2317 ret
= "dsll\t%1,32\n\tor\t%1,%D1\n\tdmtc1\t%1,%0";
2320 ret
= "dmtc1\t%1,%0";
2323 ret
= "mtc1\t%L1,%0\n\tmtc1\t%M1,%D0";
2327 else if (FP_REG_P (regno1
))
2333 abort_with_insn (insn
, "Bad move");
2335 #ifdef TARGET_FP_CALL_32
2336 if (FP_CALL_GP_REG_P (regno0
))
2337 ret
= "dmfc1\t%0,%1\n\tmfc1\t%D0,%1\n\tdsrl\t%0,32";
2340 ret
= "dmfc1\t%0,%1";
2343 ret
= "mfc1\t%L0,%1\n\tmfc1\t%M0,%D1";
2346 else if (MD_REG_P (regno0
) && GP_REG_P (regno1
) && !TARGET_MIPS16
)
2351 if (regno0
!= HILO_REGNUM
)
2353 else if (regno1
== 0)
2354 ret
= "mtlo\t%.\n\tmthi\t%.";
2357 ret
= "mthi\t%M1\n\tmtlo\t%L1";
2360 else if (GP_REG_P (regno0
) && MD_REG_P (regno1
))
2365 if (regno1
!= HILO_REGNUM
)
2369 ret
= "mfhi\t%M0\n\tmflo\t%L0";
2372 else if (TARGET_64BIT
)
2373 ret
= "move\t%0,%1";
2375 else if (regno0
!= (regno1
+1))
2376 ret
= "move\t%0,%1\n\tmove\t%D0,%D1";
2379 ret
= "move\t%D0,%D1\n\tmove\t%0,%1";
2382 else if (code1
== CONST_DOUBLE
)
2384 /* Move zero from $0 unless !TARGET_64BIT and recipient
2385 is 64-bit fp reg, in which case generate a constant. */
2386 if (op1
!= CONST0_RTX (GET_MODE (op1
))
2387 || (TARGET_FLOAT64
&& !TARGET_64BIT
&& FP_REG_P (regno0
)))
2389 if (GET_MODE (op1
) == DFmode
)
2393 #ifdef TARGET_FP_CALL_32
2394 if (FP_CALL_GP_REG_P (regno0
))
2396 if (TARGET_FLOAT64
&& !TARGET_64BIT
)
2398 split_double (op1
, operands
+ 2, operands
+ 3);
2399 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2402 ret
= "li.d\t%0,%1\n\tdsll\t%D0,%0,32\n\tdsrl\t%D0,32\n\tdsrl\t%0,32";
2406 /* GNU as emits 64-bit code for li.d if the ISA is 3
2407 or higher. For !TARGET_64BIT && gp registers we
2408 need to avoid this by using two li instructions
2410 if (ISA_HAS_64BIT_REGS
2412 && ! FP_REG_P (regno0
))
2414 split_double (op1
, operands
+ 2, operands
+ 3);
2415 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2418 ret
= "li.d\t%0,%1";
2421 else if (TARGET_64BIT
)
2423 if (! TARGET_MIPS16
)
2429 split_double (op1
, operands
+ 2, operands
+ 3);
2430 ret
= "li\t%0,%2\n\tli\t%D0,%3";
2436 if (GP_REG_P (regno0
))
2438 #ifdef TARGET_FP_CALL_32
2439 && ! FP_CALL_GP_REG_P (regno0
)
2442 : "move\t%0,%.\n\tmove\t%D0,%.");
2444 else if (FP_REG_P (regno0
))
2449 : "mtc1\t%.,%0\n\tmtc1\t%.,%D0");
2454 else if (code1
== CONST_INT
&& INTVAL (op1
) == 0 && ! TARGET_MIPS16
)
2456 if (GP_REG_P (regno0
))
2459 : "move\t%0,%.\n\tmove\t%D0,%.");
2461 else if (FP_REG_P (regno0
))
2468 : "mtc1\t%.,%0\n\tmtc1\t%.,%D0"));
2470 else if (MD_REG_P (regno0
))
2473 ret
= (regno0
== HILO_REGNUM
2474 ? "mtlo\t%.\n\tmthi\t%."
2479 else if (code1
== CONST_INT
&& GET_MODE (op0
) == DImode
2480 && GP_REG_P (regno0
))
2486 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2488 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2489 ret
= "li\t%0,%n1\n\tneg\t%0";
2491 else if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2492 ret
= "li\t%0,%1\t\t# %X1";
2493 else if (HOST_BITS_PER_WIDE_INT
< 64)
2494 /* We can't use 'X' for negative numbers, because then we won't
2495 get the right value for the upper 32 bits. */
2496 ret
= (INTVAL (op1
) < 0
2497 ? "dli\t%0,%1\t\t\t# %X1"
2498 : "dli\t%0,%X1\t\t# %1");
2500 /* We must use 'X', because otherwise LONG_MIN will print as
2501 a number that the assembler won't accept. */
2502 ret
= "dli\t%0,%X1\t\t# %1";
2504 else if (HOST_BITS_PER_WIDE_INT
< 64)
2506 operands
[2] = GEN_INT (INTVAL (operands
[1]) >= 0 ? 0 : -1);
2509 if (INTVAL (op1
) >= 0 && INTVAL (op1
) <= 0xffff)
2510 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2511 else if (INTVAL (op1
) < 0 && INTVAL (op1
) >= -0xffff)
2513 operands
[2] = GEN_INT (1);
2514 ret
= "li\t%M0,%2\n\tneg\t%M0\n\tli\t%L0,%n1\n\tneg\t%L0";
2518 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2522 /* We use multiple shifts here, to avoid warnings about out
2523 of range shifts on 32 bit hosts. */
2524 operands
[2] = GEN_INT (INTVAL (operands
[1]) >> 16 >> 16);
2526 = GEN_INT (INTVAL (operands
[1]) << 16 << 16 >> 16 >> 16);
2527 ret
= "li\t%M0,%2\n\tli\t%L0,%1";
2531 else if (code1
== MEM
)
2536 mips_count_memory_refs (op1
, 2);
2538 if (FP_REG_P (regno0
))
2541 else if (TARGET_64BIT
)
2544 #ifdef TARGET_FP_CALL_32
2545 if (FP_CALL_GP_REG_P (regno0
))
2546 ret
= (double_memory_operand (op1
, GET_MODE (op1
))
2547 ? "lwu\t%0,%1\n\tlwu\t%D0,4+%1"
2548 : "ld\t%0,%1\n\tdsll\t%D0,%0,32\n\tdsrl\t%D0,32\n\tdsrl\t%0,32");
2554 else if (double_memory_operand (op1
, GET_MODE (op1
)))
2556 operands
[2] = adjust_address (op1
, SImode
, 4);
2557 ret
= (reg_mentioned_p (op0
, op1
)
2558 ? "lw\t%D0,%2\n\tlw\t%0,%1"
2559 : "lw\t%0,%1\n\tlw\t%D0,%2");
2562 if (ret
!= 0 && MEM_VOLATILE_P (op1
))
2564 size_t i
= strlen (ret
);
2566 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2569 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2570 ret
= volatile_buffer
;
2574 else if (code1
== LABEL_REF
)
2577 mips_count_memory_refs (op1
, 2);
2579 if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2580 /* We deliberately remove the 'a' from '%1', so that we don't
2581 have to add SIGN_EXTEND support to print_operand_address.
2582 print_operand will just call print_operand_address in this
2583 case, so there is no problem. */
2586 ret
= "dla\t%0,%a1";
2588 else if (code1
== SYMBOL_REF
|| code1
== CONST
)
2592 && GET_CODE (XEXP (op1
, 0)) == REG
2593 && REGNO (XEXP (op1
, 0)) == GP_REG_FIRST
+ 28)
2595 /* This case arises on the mips16; see
2596 mips16_gp_pseudo_reg. */
2597 ret
= "move\t%0,%+";
2599 else if (TARGET_MIPS16
2600 && code1
== SYMBOL_REF
2601 && SYMBOL_REF_FLAG (op1
)
2602 && (XSTR (op1
, 0)[0] != '*'
2603 || strncmp (XSTR (op1
, 0) + 1,
2605 sizeof LOCAL_LABEL_PREFIX
- 1) != 0))
2607 /* This can occur when reloading the address of a GP
2608 relative symbol on the mips16. */
2609 ret
= "move\t%0,%+\n\taddu\t%0,%%gprel(%a1)";
2614 mips_count_memory_refs (op1
, 2);
2616 if (GET_CODE (operands
[1]) == SIGN_EXTEND
)
2617 /* We deliberately remove the 'a' from '%1', so that we don't
2618 have to add SIGN_EXTEND support to print_operand_address.
2619 print_operand will just call print_operand_address in this
2620 case, so there is no problem. */
2623 ret
= "dla\t%0,%a1";
2628 else if (code0
== MEM
)
2632 int regno1
= REGNO (op1
) + subreg_offset1
;
2634 if (FP_REG_P (regno1
))
2637 else if (TARGET_64BIT
)
2640 #ifdef TARGET_FP_CALL_32
2641 if (FP_CALL_GP_REG_P (regno1
))
2642 ret
= "dsll\t%1,32\n\tor\t%1,%D1\n\tsd\t%1,%0";
2648 else if (double_memory_operand (op0
, GET_MODE (op0
)))
2650 operands
[2] = adjust_address (op0
, SImode
, 4);
2651 ret
= "sw\t%1,%0\n\tsw\t%D1,%2";
2655 else if (((code1
== CONST_INT
&& INTVAL (op1
) == 0)
2656 || (code1
== CONST_DOUBLE
2657 && op1
== CONST0_RTX (GET_MODE (op1
))))
2659 || double_memory_operand (op0
, GET_MODE (op0
))))
2665 operands
[2] = adjust_address (op0
, SImode
, 4);
2666 ret
= "sw\t%.,%0\n\tsw\t%.,%2";
2671 mips_count_memory_refs (op0
, 2);
2673 if (ret
!= 0 && MEM_VOLATILE_P (op0
))
2675 size_t i
= strlen (ret
);
2677 if (i
> sizeof (volatile_buffer
) - sizeof ("%{%}"))
2680 sprintf (volatile_buffer
, "%%{%s%%}", ret
);
2681 ret
= volatile_buffer
;
2687 abort_with_insn (insn
, "Bad move");
2691 if (delay
!= DELAY_NONE
)
2692 return mips_fill_delay_slot (ret
, delay
, operands
, insn
);
2697 /* Provide the costs of an addressing mode that contains ADDR.
2698 If ADDR is not a valid address, its cost is irrelevant. */
2701 mips_address_cost (addr
)
2704 switch (GET_CODE (addr
))
2714 rtx offset
= const0_rtx
;
2715 addr
= eliminate_constant_term (XEXP (addr
, 0), &offset
);
2716 if (GET_CODE (addr
) == LABEL_REF
)
2719 if (GET_CODE (addr
) != SYMBOL_REF
)
2722 if (! SMALL_INT (offset
))
2726 /* ... fall through ... */
2729 return SYMBOL_REF_FLAG (addr
) ? 1 : 2;
2733 register rtx plus0
= XEXP (addr
, 0);
2734 register rtx plus1
= XEXP (addr
, 1);
2736 if (GET_CODE (plus0
) != REG
&& GET_CODE (plus1
) == REG
)
2737 plus0
= XEXP (addr
, 1), plus1
= XEXP (addr
, 0);
2739 if (GET_CODE (plus0
) != REG
)
2742 switch (GET_CODE (plus1
))
2745 return SMALL_INT (plus1
) ? 1 : 2;
2752 return mips_address_cost (plus1
) + 1;
2766 /* Return nonzero if X is an address which needs a temporary register when
2767 reloaded while generating PIC code. */
2770 pic_address_needs_scratch (x
)
2773 /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */
2774 if (GET_CODE (x
) == CONST
&& GET_CODE (XEXP (x
, 0)) == PLUS
2775 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
2776 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2777 && ! SMALL_INT (XEXP (XEXP (x
, 0), 1)))
2783 /* Make normal rtx_code into something we can index from an array */
2785 static enum internal_test
2786 map_test_to_internal_test (test_code
)
2787 enum rtx_code test_code
;
2789 enum internal_test test
= ITEST_MAX
;
2793 case EQ
: test
= ITEST_EQ
; break;
2794 case NE
: test
= ITEST_NE
; break;
2795 case GT
: test
= ITEST_GT
; break;
2796 case GE
: test
= ITEST_GE
; break;
2797 case LT
: test
= ITEST_LT
; break;
2798 case LE
: test
= ITEST_LE
; break;
2799 case GTU
: test
= ITEST_GTU
; break;
2800 case GEU
: test
= ITEST_GEU
; break;
2801 case LTU
: test
= ITEST_LTU
; break;
2802 case LEU
: test
= ITEST_LEU
; break;
2810 /* Generate the code to compare two integer values. The return value is:
2811 (reg:SI xx) The pseudo register the comparison is in
2812 0 No register, generate a simple branch.
2814 ??? This is called with result nonzero by the Scond patterns in
2815 mips.md. These patterns are called with a target in the mode of
2816 the Scond instruction pattern. Since this must be a constant, we
2817 must use SImode. This means that if RESULT is non-zero, it will
2818 always be an SImode register, even if TARGET_64BIT is true. We
2819 cope with this by calling convert_move rather than emit_move_insn.
2820 This will sometimes lead to an unnecessary extension of the result;
2832 gen_int_relational (test_code
, result
, cmp0
, cmp1
, p_invert
)
2833 enum rtx_code test_code
; /* relational test (EQ, etc) */
2834 rtx result
; /* result to store comp. or 0 if branch */
2835 rtx cmp0
; /* first operand to compare */
2836 rtx cmp1
; /* second operand to compare */
2837 int *p_invert
; /* NULL or ptr to hold whether branch needs */
2838 /* to reverse its test */
2842 enum rtx_code test_code
; /* code to use in instruction (LT vs. LTU) */
2843 int const_low
; /* low bound of constant we can accept */
2844 int const_high
; /* high bound of constant we can accept */
2845 int const_add
; /* constant to add (convert LE -> LT) */
2846 int reverse_regs
; /* reverse registers in test */
2847 int invert_const
; /* != 0 if invert value if cmp1 is constant */
2848 int invert_reg
; /* != 0 if invert value if cmp1 is register */
2849 int unsignedp
; /* != 0 for unsigned comparisons. */
2852 static struct cmp_info info
[ (int)ITEST_MAX
] = {
2854 { XOR
, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
2855 { XOR
, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
2856 { LT
, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
2857 { LT
, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
2858 { LT
, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
2859 { LT
, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
2860 { LTU
, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
2861 { LTU
, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
2862 { LTU
, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
2863 { LTU
, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
2866 enum internal_test test
;
2867 enum machine_mode mode
;
2868 struct cmp_info
*p_info
;
2875 test
= map_test_to_internal_test (test_code
);
2876 if (test
== ITEST_MAX
)
2879 p_info
= &info
[(int) test
];
2880 eqne_p
= (p_info
->test_code
== XOR
);
2882 mode
= GET_MODE (cmp0
);
2883 if (mode
== VOIDmode
)
2884 mode
= GET_MODE (cmp1
);
2886 /* Eliminate simple branches */
2887 branch_p
= (result
== 0);
2890 if (GET_CODE (cmp0
) == REG
|| GET_CODE (cmp0
) == SUBREG
)
2892 /* Comparisons against zero are simple branches */
2893 if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0
2894 && (! TARGET_MIPS16
|| eqne_p
))
2897 /* Test for beq/bne. */
2898 if (eqne_p
&& ! TARGET_MIPS16
)
2902 /* allocate a pseudo to calculate the value in. */
2903 result
= gen_reg_rtx (mode
);
2906 /* Make sure we can handle any constants given to us. */
2907 if (GET_CODE (cmp0
) == CONST_INT
)
2908 cmp0
= force_reg (mode
, cmp0
);
2910 if (GET_CODE (cmp1
) == CONST_INT
)
2912 HOST_WIDE_INT value
= INTVAL (cmp1
);
2914 if (value
< p_info
->const_low
2915 || value
> p_info
->const_high
2916 /* ??? Why? And why wasn't the similar code below modified too? */
2918 && HOST_BITS_PER_WIDE_INT
< 64
2919 && p_info
->const_add
!= 0
2920 && ((p_info
->unsignedp
2921 ? ((unsigned HOST_WIDE_INT
) (value
+ p_info
->const_add
)
2922 > (unsigned HOST_WIDE_INT
) INTVAL (cmp1
))
2923 : (value
+ p_info
->const_add
) > INTVAL (cmp1
))
2924 != (p_info
->const_add
> 0))))
2925 cmp1
= force_reg (mode
, cmp1
);
2928 /* See if we need to invert the result. */
2929 invert
= (GET_CODE (cmp1
) == CONST_INT
2930 ? p_info
->invert_const
: p_info
->invert_reg
);
2932 if (p_invert
!= (int *)0)
2938 /* Comparison to constants, may involve adding 1 to change a LT into LE.
2939 Comparison between two registers, may involve switching operands. */
2940 if (GET_CODE (cmp1
) == CONST_INT
)
2942 if (p_info
->const_add
!= 0)
2944 HOST_WIDE_INT
new = INTVAL (cmp1
) + p_info
->const_add
;
2946 /* If modification of cmp1 caused overflow,
2947 we would get the wrong answer if we follow the usual path;
2948 thus, x > 0xffffffffU would turn into x > 0U. */
2949 if ((p_info
->unsignedp
2950 ? (unsigned HOST_WIDE_INT
) new >
2951 (unsigned HOST_WIDE_INT
) INTVAL (cmp1
)
2952 : new > INTVAL (cmp1
))
2953 != (p_info
->const_add
> 0))
2955 /* This test is always true, but if INVERT is true then
2956 the result of the test needs to be inverted so 0 should
2957 be returned instead. */
2958 emit_move_insn (result
, invert
? const0_rtx
: const_true_rtx
);
2962 cmp1
= GEN_INT (new);
2966 else if (p_info
->reverse_regs
)
2973 if (test
== ITEST_NE
&& GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0)
2977 reg
= (invert
|| eqne_p
) ? gen_reg_rtx (mode
) : result
;
2978 convert_move (reg
, gen_rtx (p_info
->test_code
, mode
, cmp0
, cmp1
), 0);
2981 if (test
== ITEST_NE
)
2983 if (! TARGET_MIPS16
)
2985 convert_move (result
, gen_rtx (GTU
, mode
, reg
, const0_rtx
), 0);
2990 reg2
= invert
? gen_reg_rtx (mode
) : result
;
2991 convert_move (reg2
, gen_rtx (LTU
, mode
, reg
, const1_rtx
), 0);
2996 else if (test
== ITEST_EQ
)
2998 reg2
= invert
? gen_reg_rtx (mode
) : result
;
2999 convert_move (reg2
, gen_rtx_LTU (mode
, reg
, const1_rtx
), 0);
3007 if (! TARGET_MIPS16
)
3011 /* The value is in $24. Copy it to another register, so
3012 that reload doesn't think it needs to store the $24 and
3013 the input to the XOR in the same location. */
3014 reg2
= gen_reg_rtx (mode
);
3015 emit_move_insn (reg2
, reg
);
3017 one
= force_reg (mode
, const1_rtx
);
3019 convert_move (result
, gen_rtx (XOR
, mode
, reg
, one
), 0);
3025 /* Emit the common code for doing conditional branches.
3026 operand[0] is the label to jump to.
3027 The comparison operands are saved away by cmp{si,di,sf,df}. */
3030 gen_conditional_branch (operands
, test_code
)
3032 enum rtx_code test_code
;
3034 enum cmp_type type
= branch_type
;
3035 rtx cmp0
= branch_cmp
[0];
3036 rtx cmp1
= branch_cmp
[1];
3037 enum machine_mode mode
;
3046 mode
= type
== CMP_SI
? SImode
: DImode
;
3048 reg
= gen_int_relational (test_code
, NULL_RTX
, cmp0
, cmp1
, &invert
);
3056 else if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) != 0)
3057 /* We don't want to build a comparison against a non-zero
3059 cmp1
= force_reg (mode
, cmp1
);
3066 reg
= gen_rtx_REG (CCmode
, FPSW_REGNUM
);
3068 reg
= gen_reg_rtx (CCmode
);
3070 /* For cmp0 != cmp1, build cmp0 == cmp1, and test for result ==
3071 0 in the instruction built below. The MIPS FPU handles
3072 inequality testing by testing for equality and looking for a
3074 emit_insn (gen_rtx_SET (VOIDmode
, reg
,
3075 gen_rtx (test_code
== NE
? EQ
: test_code
,
3076 CCmode
, cmp0
, cmp1
)));
3078 test_code
= test_code
== NE
? EQ
: NE
;
3086 abort_with_insn (gen_rtx (test_code
, VOIDmode
, cmp0
, cmp1
), "bad test");
3089 /* Generate the branch. */
3091 label1
= gen_rtx_LABEL_REF (VOIDmode
, operands
[0]);
3100 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
,
3101 gen_rtx_IF_THEN_ELSE (VOIDmode
,
3102 gen_rtx (test_code
, mode
,
3107 /* Emit the common code for conditional moves. OPERANDS is the array
3108 of operands passed to the conditional move defined_expand. */
3111 gen_conditional_move (operands
)
3114 rtx op0
= branch_cmp
[0];
3115 rtx op1
= branch_cmp
[1];
3116 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3117 enum rtx_code cmp_code
= GET_CODE (operands
[1]);
3118 enum rtx_code move_code
= NE
;
3119 enum machine_mode op_mode
= GET_MODE (operands
[0]);
3120 enum machine_mode cmp_mode
;
3123 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
3142 op0
= force_reg (mode
, branch_cmp
[1]);
3143 op1
= branch_cmp
[0];
3147 op0
= force_reg (mode
, branch_cmp
[1]);
3148 op1
= branch_cmp
[0];
3159 op0
= force_reg (mode
, branch_cmp
[1]);
3160 op1
= branch_cmp
[0];
3164 op0
= force_reg (mode
, branch_cmp
[1]);
3165 op1
= branch_cmp
[0];
3172 else if (cmp_code
== NE
)
3173 cmp_code
= EQ
, move_code
= EQ
;
3175 if (mode
== SImode
|| mode
== DImode
)
3177 else if (mode
== SFmode
|| mode
== DFmode
)
3182 cmp_reg
= gen_reg_rtx (cmp_mode
);
3183 emit_insn (gen_rtx_SET (cmp_mode
, cmp_reg
,
3184 gen_rtx (cmp_code
, cmp_mode
, op0
, op1
)));
3186 emit_insn (gen_rtx_SET (op_mode
, operands
[0],
3187 gen_rtx_IF_THEN_ELSE (op_mode
,
3188 gen_rtx (move_code
, VOIDmode
,
3190 CONST0_RTX (SImode
)),
3191 operands
[2], operands
[3])));
3194 /* Emit the common code for conditional moves. OPERANDS is the array
3195 of operands passed to the conditional move defined_expand. */
3198 mips_gen_conditional_trap (operands
)
3202 enum rtx_code cmp_code
= GET_CODE (operands
[0]);
3203 enum machine_mode mode
= GET_MODE (branch_cmp
[0]);
3205 /* MIPS conditional trap machine instructions don't have GT or LE
3206 flavors, so we must invert the comparison and convert to LT and
3207 GE, respectively. */
3210 case GT
: cmp_code
= LT
; break;
3211 case LE
: cmp_code
= GE
; break;
3212 case GTU
: cmp_code
= LTU
; break;
3213 case LEU
: cmp_code
= GEU
; break;
3216 if (cmp_code
== GET_CODE (operands
[0]))
3218 op0
= force_reg (mode
, branch_cmp
[0]);
3219 op1
= branch_cmp
[1];
3223 op0
= force_reg (mode
, branch_cmp
[1]);
3224 op1
= branch_cmp
[0];
3226 if (GET_CODE (op1
) == CONST_INT
&& ! SMALL_INT (op1
))
3227 op1
= force_reg (mode
, op1
);
3229 emit_insn (gen_rtx_TRAP_IF (VOIDmode
,
3230 gen_rtx (cmp_code
, GET_MODE (operands
[0]), op0
, op1
),
3234 /* Write a loop to move a constant number of bytes.
3235 Generate load/stores as follows:
3241 temp<last> = src[MAX_MOVE_REGS-1];
3245 dest[MAX_MOVE_REGS-1] = temp<last>;
3246 src += MAX_MOVE_REGS;
3247 dest += MAX_MOVE_REGS;
3248 } while (src != final);
3250 This way, no NOP's are needed, and only MAX_MOVE_REGS+3 temp
3251 registers are needed.
3253 Aligned moves move MAX_MOVE_REGS*4 bytes every (2*MAX_MOVE_REGS)+3
3254 cycles, unaligned moves move MAX_MOVE_REGS*4 bytes every
3255 (4*MAX_MOVE_REGS)+3 cycles, assuming no cache misses. */
3257 #define MAX_MOVE_REGS 4
3258 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3261 block_move_loop (dest_reg
, src_reg
, bytes
, align
, orig_dest
, orig_src
)
3262 rtx dest_reg
; /* register holding destination address */
3263 rtx src_reg
; /* register holding source address */
3264 unsigned int bytes
; /* # bytes to move */
3265 int align
; /* alignment */
3266 rtx orig_dest
; /* original dest */
3267 rtx orig_src
; /* original source for making a reg note */
3269 rtx dest_mem
= replace_equiv_address (orig_dest
, dest_reg
);
3270 rtx src_mem
= replace_equiv_address (orig_src
, src_reg
);
3271 rtx align_rtx
= GEN_INT (align
);
3277 if (bytes
< (unsigned)2 * MAX_MOVE_BYTES
)
3280 leftover
= bytes
% MAX_MOVE_BYTES
;
3283 label
= gen_label_rtx ();
3284 final_src
= gen_reg_rtx (Pmode
);
3285 bytes_rtx
= GEN_INT (bytes
);
3289 if (Pmode
== DImode
)
3291 emit_insn (gen_movdi (final_src
, bytes_rtx
));
3292 emit_insn (gen_adddi3 (final_src
, final_src
, src_reg
));
3296 emit_insn (gen_movsi (final_src
, bytes_rtx
));
3297 emit_insn (gen_addsi3 (final_src
, final_src
, src_reg
));
3302 if (Pmode
== DImode
)
3303 emit_insn (gen_adddi3 (final_src
, src_reg
, bytes_rtx
));
3305 emit_insn (gen_addsi3 (final_src
, src_reg
, bytes_rtx
));
3310 bytes_rtx
= GEN_INT (MAX_MOVE_BYTES
);
3311 emit_insn (gen_movstrsi_internal (dest_mem
, src_mem
, bytes_rtx
, align_rtx
));
3313 if (Pmode
== DImode
)
3315 emit_insn (gen_adddi3 (src_reg
, src_reg
, bytes_rtx
));
3316 emit_insn (gen_adddi3 (dest_reg
, dest_reg
, bytes_rtx
));
3317 emit_insn (gen_cmpdi (src_reg
, final_src
));
3321 emit_insn (gen_addsi3 (src_reg
, src_reg
, bytes_rtx
));
3322 emit_insn (gen_addsi3 (dest_reg
, dest_reg
, bytes_rtx
));
3323 emit_insn (gen_cmpsi (src_reg
, final_src
));
3326 emit_jump_insn (gen_bne (label
));
3329 emit_insn (gen_movstrsi_internal (dest_mem
, src_mem
, GEN_INT (leftover
),
3333 /* Use a library function to move some bytes. */
3336 block_move_call (dest_reg
, src_reg
, bytes_rtx
)
3341 /* We want to pass the size as Pmode, which will normally be SImode
3342 but will be DImode if we are using 64 bit longs and pointers. */
3343 if (GET_MODE (bytes_rtx
) != VOIDmode
3344 && GET_MODE (bytes_rtx
) != (unsigned) Pmode
)
3345 bytes_rtx
= convert_to_mode (Pmode
, bytes_rtx
, 1);
3347 #ifdef TARGET_MEM_FUNCTIONS
3348 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "memcpy"), 0,
3349 VOIDmode
, 3, dest_reg
, Pmode
, src_reg
, Pmode
,
3350 convert_to_mode (TYPE_MODE (sizetype
), bytes_rtx
,
3351 TREE_UNSIGNED (sizetype
)),
3352 TYPE_MODE (sizetype
));
3354 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, "bcopy"), 0,
3355 VOIDmode
, 3, src_reg
, Pmode
, dest_reg
, Pmode
,
3356 convert_to_mode (TYPE_MODE (integer_type_node
), bytes_rtx
,
3357 TREE_UNSIGNED (integer_type_node
)),
3358 TYPE_MODE (integer_type_node
));
3362 /* Expand string/block move operations.
3364 operands[0] is the pointer to the destination.
3365 operands[1] is the pointer to the source.
3366 operands[2] is the number of bytes to move.
3367 operands[3] is the alignment. */
3370 expand_block_move (operands
)
3373 rtx bytes_rtx
= operands
[2];
3374 rtx align_rtx
= operands
[3];
3375 int constp
= GET_CODE (bytes_rtx
) == CONST_INT
;
3376 unsigned HOST_WIDE_INT bytes
= constp
? INTVAL (bytes_rtx
) : 0;
3377 unsigned int align
= INTVAL (align_rtx
);
3378 rtx orig_src
= operands
[1];
3379 rtx orig_dest
= operands
[0];
3383 if (constp
&& bytes
== 0)
3386 if (align
> (unsigned) UNITS_PER_WORD
)
3387 align
= UNITS_PER_WORD
;
3389 /* Move the address into scratch registers. */
3390 dest_reg
= copy_addr_to_reg (XEXP (orig_dest
, 0));
3391 src_reg
= copy_addr_to_reg (XEXP (orig_src
, 0));
3394 block_move_call (dest_reg
, src_reg
, bytes_rtx
);
3396 else if (constp
&& bytes
<= (unsigned)2 * MAX_MOVE_BYTES
3397 && align
== (unsigned) UNITS_PER_WORD
)
3398 move_by_pieces (orig_dest
, orig_src
, bytes
, align
* BITS_PER_WORD
);
3400 else if (constp
&& bytes
<= (unsigned)2 * MAX_MOVE_BYTES
)
3401 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest
,
3403 replace_equiv_address (orig_src
,
3405 bytes_rtx
, align_rtx
));
3407 else if (constp
&& align
>= (unsigned) UNITS_PER_WORD
&& optimize
)
3408 block_move_loop (dest_reg
, src_reg
, bytes
, align
, orig_dest
, orig_src
);
3410 else if (constp
&& optimize
)
3412 /* If the alignment is not word aligned, generate a test at
3413 runtime, to see whether things wound up aligned, and we
3414 can use the faster lw/sw instead ulw/usw. */
3416 rtx temp
= gen_reg_rtx (Pmode
);
3417 rtx aligned_label
= gen_label_rtx ();
3418 rtx join_label
= gen_label_rtx ();
3419 int leftover
= bytes
% MAX_MOVE_BYTES
;
3423 if (Pmode
== DImode
)
3425 emit_insn (gen_iordi3 (temp
, src_reg
, dest_reg
));
3426 emit_insn (gen_anddi3 (temp
, temp
, GEN_INT (UNITS_PER_WORD
- 1)));
3427 emit_insn (gen_cmpdi (temp
, const0_rtx
));
3431 emit_insn (gen_iorsi3 (temp
, src_reg
, dest_reg
));
3432 emit_insn (gen_andsi3 (temp
, temp
, GEN_INT (UNITS_PER_WORD
- 1)));
3433 emit_insn (gen_cmpsi (temp
, const0_rtx
));
3436 emit_jump_insn (gen_beq (aligned_label
));
3438 /* Unaligned loop. */
3439 block_move_loop (dest_reg
, src_reg
, bytes
, 1, orig_dest
, orig_src
);
3440 emit_jump_insn (gen_jump (join_label
));
3444 emit_label (aligned_label
);
3445 block_move_loop (dest_reg
, src_reg
, bytes
, UNITS_PER_WORD
, orig_dest
,
3447 emit_label (join_label
);
3449 /* Bytes at the end of the loop. */
3451 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest
,
3453 replace_equiv_address (orig_src
,
3460 block_move_call (dest_reg
, src_reg
, bytes_rtx
);
3463 /* Emit load/stores for a small constant block_move.
3465 operands[0] is the memory address of the destination.
3466 operands[1] is the memory address of the source.
3467 operands[2] is the number of bytes to move.
3468 operands[3] is the alignment.
3469 operands[4] is a temp register.
3470 operands[5] is a temp register.
3472 operands[3+num_regs] is the last temp register.
3474 The block move type can be one of the following:
3475 BLOCK_MOVE_NORMAL Do all of the block move.
3476 BLOCK_MOVE_NOT_LAST Do all but the last store.
3477 BLOCK_MOVE_LAST Do just the last store. */
3480 output_block_move (insn
, operands
, num_regs
, move_type
)
3484 enum block_move_type move_type
;
3486 rtx dest_reg
= XEXP (operands
[0], 0);
3487 rtx src_reg
= XEXP (operands
[1], 0);
3488 HOST_WIDE_INT bytes
= INTVAL (operands
[2]);
3489 int align
= INTVAL (operands
[3]);
3492 int use_lwl_lwr
= 0;
3493 int last_operand
= num_regs
+ 4;
3499 const char *load
; /* load insn without nop */
3500 const char *load_nop
; /* load insn with trailing nop */
3501 const char *store
; /* store insn */
3502 const char *final
; /* if last_store used: NULL or swr */
3503 const char *last_store
; /* last store instruction */
3504 int offset
; /* current offset */
3505 enum machine_mode mode
; /* mode to use on (MEM) */
3508 /* ??? Detect a bug in GCC, where it can give us a register
3509 the same as one of the addressing registers and reduce
3510 the number of registers available. */
3511 for (i
= 4; i
< last_operand
&& safe_regs
< (int) ARRAY_SIZE (xoperands
); i
++)
3512 if (! reg_mentioned_p (operands
[i
], operands
[0])
3513 && ! reg_mentioned_p (operands
[i
], operands
[1]))
3514 xoperands
[safe_regs
++] = operands
[i
];
3516 if (safe_regs
< last_operand
)
3518 xoperands
[0] = operands
[0];
3519 xoperands
[1] = operands
[1];
3520 xoperands
[2] = operands
[2];
3521 xoperands
[3] = operands
[3];
3522 return output_block_move (insn
, xoperands
, safe_regs
- 4, move_type
);
3525 /* If we are given global or static addresses, and we would be
3526 emitting a few instructions, try to save time by using a
3527 temporary register for the pointer. */
3528 /* ??? The SGI Irix6 assembler fails when a SYMBOL_REF is used in
3529 an ldl/ldr instruction pair. We play it safe, and always move
3530 constant addresses into registers when generating N32/N64 code, just
3531 in case we might emit an unaligned load instruction. */
3532 if (num_regs
> 2 && (bytes
> 2 * align
|| move_type
!= BLOCK_MOVE_NORMAL
3533 || mips_abi
== ABI_N32
|| mips_abi
== ABI_64
))
3535 if (CONSTANT_P (src_reg
))
3538 mips_count_memory_refs (operands
[1], 1);
3540 src_reg
= operands
[3 + num_regs
--];
3541 if (move_type
!= BLOCK_MOVE_LAST
)
3543 xoperands
[1] = operands
[1];
3544 xoperands
[0] = src_reg
;
3545 if (Pmode
== DImode
)
3546 output_asm_insn ("dla\t%0,%1", xoperands
);
3548 output_asm_insn ("la\t%0,%1", xoperands
);
3552 if (CONSTANT_P (dest_reg
))
3555 mips_count_memory_refs (operands
[0], 1);
3557 dest_reg
= operands
[3 + num_regs
--];
3558 if (move_type
!= BLOCK_MOVE_LAST
)
3560 xoperands
[1] = operands
[0];
3561 xoperands
[0] = dest_reg
;
3562 if (Pmode
== DImode
)
3563 output_asm_insn ("dla\t%0,%1", xoperands
);
3565 output_asm_insn ("la\t%0,%1", xoperands
);
3570 /* ??? We really shouldn't get any LO_SUM addresses here, because they
3571 are not offsettable, however, offsettable_address_p says they are
3572 offsettable. I think this is a bug in offsettable_address_p.
3573 For expediency, we fix this by just loading the address into a register
3574 if we happen to get one. */
3576 if (GET_CODE (src_reg
) == LO_SUM
)
3578 src_reg
= operands
[3 + num_regs
--];
3579 if (move_type
!= BLOCK_MOVE_LAST
)
3581 xoperands
[2] = XEXP (XEXP (operands
[1], 0), 1);
3582 xoperands
[1] = XEXP (XEXP (operands
[1], 0), 0);
3583 xoperands
[0] = src_reg
;
3584 if (Pmode
== DImode
)
3585 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands
);
3587 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands
);
3591 if (GET_CODE (dest_reg
) == LO_SUM
)
3593 dest_reg
= operands
[3 + num_regs
--];
3594 if (move_type
!= BLOCK_MOVE_LAST
)
3596 xoperands
[2] = XEXP (XEXP (operands
[0], 0), 1);
3597 xoperands
[1] = XEXP (XEXP (operands
[0], 0), 0);
3598 xoperands
[0] = dest_reg
;
3599 if (Pmode
== DImode
)
3600 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands
);
3602 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands
);
3606 if (num_regs
> (int) ARRAY_SIZE (load_store
))
3607 num_regs
= ARRAY_SIZE (load_store
);
3609 else if (num_regs
< 1)
3610 abort_with_insn (insn
,
3611 "Cannot do block move, not enough scratch registers");
3615 load_store
[num
].offset
= offset
;
3617 if (TARGET_64BIT
&& bytes
>= 8 && align
>= 8)
3619 load_store
[num
].load
= "ld\t%0,%1";
3620 load_store
[num
].load_nop
= "ld\t%0,%1%#";
3621 load_store
[num
].store
= "sd\t%0,%1";
3622 load_store
[num
].last_store
= "sd\t%0,%1";
3623 load_store
[num
].final
= 0;
3624 load_store
[num
].mode
= DImode
;
3629 /* ??? Fails because of a MIPS assembler bug? */
3630 else if (TARGET_64BIT
&& bytes
>= 8 && ! TARGET_MIPS16
)
3632 if (BYTES_BIG_ENDIAN
)
3634 load_store
[num
].load
= "ldl\t%0,%1\n\tldr\t%0,%2";
3635 load_store
[num
].load_nop
= "ldl\t%0,%1\n\tldr\t%0,%2%#";
3636 load_store
[num
].store
= "sdl\t%0,%1\n\tsdr\t%0,%2";
3637 load_store
[num
].last_store
= "sdr\t%0,%2";
3638 load_store
[num
].final
= "sdl\t%0,%1";
3642 load_store
[num
].load
= "ldl\t%0,%2\n\tldr\t%0,%1";
3643 load_store
[num
].load_nop
= "ldl\t%0,%2\n\tldr\t%0,%1%#";
3644 load_store
[num
].store
= "sdl\t%0,%2\n\tsdr\t%0,%1";
3645 load_store
[num
].last_store
= "sdr\t%0,%1";
3646 load_store
[num
].final
= "sdl\t%0,%2";
3649 load_store
[num
].mode
= DImode
;
3655 else if (bytes
>= 4 && align
>= 4)
3657 load_store
[num
].load
= "lw\t%0,%1";
3658 load_store
[num
].load_nop
= "lw\t%0,%1%#";
3659 load_store
[num
].store
= "sw\t%0,%1";
3660 load_store
[num
].last_store
= "sw\t%0,%1";
3661 load_store
[num
].final
= 0;
3662 load_store
[num
].mode
= SImode
;
3667 else if (bytes
>= 4 && ! TARGET_MIPS16
)
3669 if (BYTES_BIG_ENDIAN
)
3671 load_store
[num
].load
= "lwl\t%0,%1\n\tlwr\t%0,%2";
3672 load_store
[num
].load_nop
= "lwl\t%0,%1\n\tlwr\t%0,%2%#";
3673 load_store
[num
].store
= "swl\t%0,%1\n\tswr\t%0,%2";
3674 load_store
[num
].last_store
= "swr\t%0,%2";
3675 load_store
[num
].final
= "swl\t%0,%1";
3679 load_store
[num
].load
= "lwl\t%0,%2\n\tlwr\t%0,%1";
3680 load_store
[num
].load_nop
= "lwl\t%0,%2\n\tlwr\t%0,%1%#";
3681 load_store
[num
].store
= "swl\t%0,%2\n\tswr\t%0,%1";
3682 load_store
[num
].last_store
= "swr\t%0,%1";
3683 load_store
[num
].final
= "swl\t%0,%2";
3686 load_store
[num
].mode
= SImode
;
3692 else if (bytes
>= 2 && align
>= 2)
3694 load_store
[num
].load
= "lh\t%0,%1";
3695 load_store
[num
].load_nop
= "lh\t%0,%1%#";
3696 load_store
[num
].store
= "sh\t%0,%1";
3697 load_store
[num
].last_store
= "sh\t%0,%1";
3698 load_store
[num
].final
= 0;
3699 load_store
[num
].mode
= HImode
;
3705 load_store
[num
].load
= "lb\t%0,%1";
3706 load_store
[num
].load_nop
= "lb\t%0,%1%#";
3707 load_store
[num
].store
= "sb\t%0,%1";
3708 load_store
[num
].last_store
= "sb\t%0,%1";
3709 load_store
[num
].final
= 0;
3710 load_store
[num
].mode
= QImode
;
3715 if (TARGET_STATS
&& move_type
!= BLOCK_MOVE_LAST
)
3717 dslots_load_total
++;
3718 dslots_load_filled
++;
3720 if (CONSTANT_P (src_reg
))
3721 mips_count_memory_refs (src_reg
, 1);
3723 if (CONSTANT_P (dest_reg
))
3724 mips_count_memory_refs (dest_reg
, 1);
3727 /* Emit load/stores now if we have run out of registers or are
3728 at the end of the move. */
3730 if (++num
== num_regs
|| bytes
== 0)
3732 /* If only load/store, we need a NOP after the load. */
3735 load_store
[0].load
= load_store
[0].load_nop
;
3736 if (TARGET_STATS
&& move_type
!= BLOCK_MOVE_LAST
)
3737 dslots_load_filled
--;
3740 if (move_type
!= BLOCK_MOVE_LAST
)
3742 for (i
= 0; i
< num
; i
++)
3746 if (!operands
[i
+ 4])
3749 if (GET_MODE (operands
[i
+ 4]) != load_store
[i
].mode
)
3750 operands
[i
+ 4] = gen_rtx_REG (load_store
[i
].mode
,
3751 REGNO (operands
[i
+ 4]));
3753 offset
= load_store
[i
].offset
;
3754 xoperands
[0] = operands
[i
+ 4];
3755 xoperands
[1] = gen_rtx_MEM (load_store
[i
].mode
,
3756 plus_constant (src_reg
, offset
));
3761 = GET_MODE_SIZE (load_store
[i
].mode
) - 1;
3763 xoperands
[2] = gen_rtx_MEM (load_store
[i
].mode
,
3764 plus_constant (src_reg
,
3769 output_asm_insn (load_store
[i
].load
, xoperands
);
3773 for (i
= 0; i
< num
; i
++)
3775 int last_p
= (i
== num
-1 && bytes
== 0);
3776 int offset
= load_store
[i
].offset
;
3778 xoperands
[0] = operands
[i
+ 4];
3779 xoperands
[1] = gen_rtx_MEM (load_store
[i
].mode
,
3780 plus_constant (dest_reg
, offset
));
3785 int extra_offset
= GET_MODE_SIZE (load_store
[i
].mode
) - 1;
3786 xoperands
[2] = gen_rtx_MEM (load_store
[i
].mode
,
3787 plus_constant (dest_reg
,
3792 if (move_type
== BLOCK_MOVE_NORMAL
)
3793 output_asm_insn (load_store
[i
].store
, xoperands
);
3795 else if (move_type
== BLOCK_MOVE_NOT_LAST
)
3798 output_asm_insn (load_store
[i
].store
, xoperands
);
3800 else if (load_store
[i
].final
!= 0)
3801 output_asm_insn (load_store
[i
].final
, xoperands
);
3805 output_asm_insn (load_store
[i
].last_store
, xoperands
);
3808 num
= 0; /* reset load_store */
3816 /* Argument support functions. */
3818 /* Initialize CUMULATIVE_ARGS for a function. */
3821 init_cumulative_args (cum
, fntype
, libname
)
3822 CUMULATIVE_ARGS
*cum
; /* argument info to initialize */
3823 tree fntype
; /* tree ptr for function decl */
3824 rtx libname ATTRIBUTE_UNUSED
; /* SYMBOL_REF of library name or 0 */
3826 static CUMULATIVE_ARGS zero_cum
;
3827 tree param
, next_param
;
3829 if (TARGET_DEBUG_E_MODE
)
3832 "\ninit_cumulative_args, fntype = 0x%.8lx", (long)fntype
);
3835 fputc ('\n', stderr
);
3839 tree ret_type
= TREE_TYPE (fntype
);
3840 fprintf (stderr
, ", fntype code = %s, ret code = %s\n",
3841 tree_code_name
[(int)TREE_CODE (fntype
)],
3842 tree_code_name
[(int)TREE_CODE (ret_type
)]);
3848 /* Determine if this function has variable arguments. This is
3849 indicated by the last argument being 'void_type_mode' if there
3850 are no variable arguments. The standard MIPS calling sequence
3851 passes all arguments in the general purpose registers in this case. */
3853 for (param
= fntype
? TYPE_ARG_TYPES (fntype
) : 0;
3854 param
!= 0; param
= next_param
)
3856 next_param
= TREE_CHAIN (param
);
3857 if (next_param
== 0 && TREE_VALUE (param
) != void_type_node
)
3858 cum
->gp_reg_found
= 1;
3862 /* Advance the argument to the next argument position. */
3865 function_arg_advance (cum
, mode
, type
, named
)
3866 CUMULATIVE_ARGS
*cum
; /* current arg information */
3867 enum machine_mode mode
; /* current arg mode */
3868 tree type
; /* type of the argument or 0 if lib support */
3869 int named
; /* whether or not the argument was named */
3871 if (TARGET_DEBUG_E_MODE
)
3874 "function_adv({gp reg found = %d, arg # = %2d, words = %2d}, %4s, ",
3875 cum
->gp_reg_found
, cum
->arg_number
, cum
->arg_words
,
3876 GET_MODE_NAME (mode
));
3877 fprintf (stderr
, HOST_PTR_PRINTF
, (const PTR
) type
);
3878 fprintf (stderr
, ", %d )\n\n", named
);
3888 if (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
3889 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
3892 cum
->gp_reg_found
= 1;
3893 cum
->arg_words
+= ((GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1)
3898 cum
->gp_reg_found
= 1;
3899 cum
->arg_words
+= ((int_size_in_bytes (type
) + UNITS_PER_WORD
- 1)
3904 if (mips_abi
== ABI_EABI
&& ! TARGET_SOFT_FLOAT
)
3905 cum
->fp_arg_words
++;
3908 if (! cum
->gp_reg_found
&& cum
->arg_number
<= 2)
3909 cum
->fp_code
+= 1 << ((cum
->arg_number
- 1) * 2);
3913 if (mips_abi
== ABI_EABI
&& ! TARGET_SOFT_FLOAT
&& ! TARGET_SINGLE_FLOAT
)
3914 cum
->fp_arg_words
+= (TARGET_64BIT
? 1 : 2);
3916 cum
->arg_words
+= (TARGET_64BIT
? 1 : 2);
3917 if (! cum
->gp_reg_found
&& ! TARGET_SINGLE_FLOAT
&& cum
->arg_number
<= 2)
3918 cum
->fp_code
+= 2 << ((cum
->arg_number
- 1) * 2);
3922 cum
->gp_reg_found
= 1;
3923 cum
->arg_words
+= (TARGET_64BIT
? 1 : 2);
3929 cum
->gp_reg_found
= 1;
3935 /* Return an RTL expression containing the register for the given mode,
3936 or 0 if the argument is to be passed on the stack. */
3939 function_arg (cum
, mode
, type
, named
)
3940 CUMULATIVE_ARGS
*cum
; /* current arg information */
3941 enum machine_mode mode
; /* current arg mode */
3942 tree type
; /* type of the argument or 0 if lib support */
3943 int named
; /* != 0 for normal args, == 0 for ... args */
3948 unsigned int *arg_words
= &cum
->arg_words
;
3949 int struct_p
= (type
!= 0
3950 && (TREE_CODE (type
) == RECORD_TYPE
3951 || TREE_CODE (type
) == UNION_TYPE
3952 || TREE_CODE (type
) == QUAL_UNION_TYPE
));
3954 if (TARGET_DEBUG_E_MODE
)
3957 "function_arg( {gp reg found = %d, arg # = %2d, words = %2d}, %4s, ",
3958 cum
->gp_reg_found
, cum
->arg_number
, cum
->arg_words
,
3959 GET_MODE_NAME (mode
));
3960 fprintf (stderr
, HOST_PTR_PRINTF
, (const PTR
) type
);
3961 fprintf (stderr
, ", %d ) = ", named
);
3965 cum
->last_arg_fp
= 0;
3969 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
3971 if (cum
->gp_reg_found
|| cum
->arg_number
>= 2 || TARGET_SOFT_FLOAT
)
3972 regbase
= GP_ARG_FIRST
;
3975 regbase
= FP_ARG_FIRST
;
3977 /* If the first arg was a float in a floating point register,
3978 then set bias to align this float arg properly. */
3979 if (cum
->arg_words
== 1)
3983 else if (mips_abi
== ABI_EABI
&& ! TARGET_SOFT_FLOAT
)
3986 cum
->fp_arg_words
+= cum
->fp_arg_words
& 1;
3987 cum
->last_arg_fp
= 1;
3988 arg_words
= &cum
->fp_arg_words
;
3989 regbase
= FP_ARG_FIRST
;
3992 regbase
= (TARGET_SOFT_FLOAT
|| ! named
? GP_ARG_FIRST
: FP_ARG_FIRST
);
3998 if (mips_abi
== ABI_EABI
3999 && ! TARGET_SOFT_FLOAT
&& ! TARGET_SINGLE_FLOAT
)
4000 cum
->fp_arg_words
+= cum
->fp_arg_words
& 1;
4002 cum
->arg_words
+= cum
->arg_words
& 1;
4005 if (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
4006 regbase
= ((cum
->gp_reg_found
4007 || TARGET_SOFT_FLOAT
|| TARGET_SINGLE_FLOAT
4008 || cum
->arg_number
>= 2)
4009 ? GP_ARG_FIRST
: FP_ARG_FIRST
);
4010 else if (mips_abi
== ABI_EABI
4011 && ! TARGET_SOFT_FLOAT
&& ! TARGET_SINGLE_FLOAT
)
4013 cum
->last_arg_fp
= 1;
4014 arg_words
= &cum
->fp_arg_words
;
4015 regbase
= FP_ARG_FIRST
;
4018 regbase
= (TARGET_SOFT_FLOAT
|| TARGET_SINGLE_FLOAT
|| ! named
4019 ? GP_ARG_FIRST
: FP_ARG_FIRST
);
4023 if (GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
4024 && GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
4027 /* Drops through. */
4029 if (type
!= NULL_TREE
&& TYPE_ALIGN (type
) > (unsigned) BITS_PER_WORD
4030 && ! TARGET_64BIT
&& mips_abi
!= ABI_EABI
)
4031 cum
->arg_words
+= (cum
->arg_words
& 1);
4032 regbase
= GP_ARG_FIRST
;
4039 regbase
= GP_ARG_FIRST
;
4044 cum
->arg_words
+= (cum
->arg_words
& 1);
4045 regbase
= GP_ARG_FIRST
;
4048 if (*arg_words
>= (unsigned) MAX_ARGS_IN_REGISTERS
)
4050 if (TARGET_DEBUG_E_MODE
)
4051 fprintf (stderr
, "<stack>%s\n", struct_p
? ", [struct]" : "");
4060 if (! type
|| TREE_CODE (type
) != RECORD_TYPE
|| mips_abi
== ABI_32
4061 || mips_abi
== ABI_EABI
|| mips_abi
== ABI_O64
|| ! named
4062 || ! TYPE_SIZE_UNIT (type
)
4063 || ! host_integerp (TYPE_SIZE_UNIT (type
), 1))
4064 ret
= gen_rtx_REG (mode
, regbase
+ *arg_words
+ bias
);
4067 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
4068 structure contains a double in its entirety, then that 64 bit
4069 chunk is passed in a floating point register. */
4072 /* First check to see if there is any such field. */
4073 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
4074 if (TREE_CODE (field
) == FIELD_DECL
4075 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
4076 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
4077 && host_integerp (bit_position (field
), 0)
4078 && int_bit_position (field
) % BITS_PER_WORD
== 0)
4081 /* If the whole struct fits a DFmode register,
4082 we don't need the PARALLEL. */
4083 if (! field
|| mode
== DFmode
)
4084 ret
= gen_rtx_REG (mode
, regbase
+ *arg_words
+ bias
);
4087 /* Now handle the special case by returning a PARALLEL
4088 indicating where each 64 bit chunk goes. */
4089 unsigned int chunks
;
4090 HOST_WIDE_INT bitpos
;
4094 /* ??? If this is a packed structure, then the last hunk won't
4098 = tree_low_cst (TYPE_SIZE_UNIT (type
), 1) / UNITS_PER_WORD
;
4099 if (chunks
+ *arg_words
+ bias
> (unsigned) MAX_ARGS_IN_REGISTERS
)
4100 chunks
= MAX_ARGS_IN_REGISTERS
- *arg_words
- bias
;
4102 /* assign_parms checks the mode of ENTRY_PARM, so we must
4103 use the actual mode here. */
4104 ret
= gen_rtx_PARALLEL (mode
, rtvec_alloc (chunks
));
4107 regno
= regbase
+ *arg_words
+ bias
;
4108 field
= TYPE_FIELDS (type
);
4109 for (i
= 0; i
< chunks
; i
++)
4113 for (; field
; field
= TREE_CHAIN (field
))
4114 if (TREE_CODE (field
) == FIELD_DECL
4115 && int_bit_position (field
) >= bitpos
)
4119 && int_bit_position (field
) == bitpos
4120 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
4121 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
)
4122 reg
= gen_rtx_REG (DFmode
,
4123 regno
+ FP_ARG_FIRST
- GP_ARG_FIRST
);
4125 reg
= gen_rtx_REG (word_mode
, regno
);
4128 = gen_rtx_EXPR_LIST (VOIDmode
, reg
,
4129 GEN_INT (bitpos
/ BITS_PER_UNIT
));
4137 if (TARGET_DEBUG_E_MODE
)
4138 fprintf (stderr
, "%s%s\n", reg_names
[regbase
+ *arg_words
+ bias
],
4139 struct_p
? ", [struct]" : "");
4141 /* The following is a hack in order to pass 1 byte structures
4142 the same way that the MIPS compiler does (namely by passing
4143 the structure in the high byte or half word of the register).
4144 This also makes varargs work. If we have such a structure,
4145 we save the adjustment RTL, and the call define expands will
4146 emit them. For the VOIDmode argument (argument after the
4147 last real argument), pass back a parallel vector holding each
4148 of the adjustments. */
4150 /* ??? function_arg can be called more than once for each argument.
4151 As a result, we compute more adjustments than we need here.
4152 See the CUMULATIVE_ARGS definition in mips.h. */
4154 /* ??? This scheme requires everything smaller than the word size to
4155 shifted to the left, but when TARGET_64BIT and ! TARGET_INT64,
4156 that would mean every int needs to be shifted left, which is very
4157 inefficient. Let's not carry this compatibility to the 64 bit
4158 calling convention for now. */
4160 if (struct_p
&& int_size_in_bytes (type
) < UNITS_PER_WORD
4161 && ! TARGET_64BIT
&& mips_abi
!= ABI_EABI
)
4163 rtx amount
= GEN_INT (BITS_PER_WORD
4164 - int_size_in_bytes (type
) * BITS_PER_UNIT
);
4165 rtx reg
= gen_rtx_REG (word_mode
, regbase
+ *arg_words
+ bias
);
4168 cum
->adjust
[cum
->num_adjusts
++] = gen_ashldi3 (reg
, reg
, amount
);
4170 cum
->adjust
[cum
->num_adjusts
++] = gen_ashlsi3 (reg
, reg
, amount
);
4174 /* We will be called with a mode of VOIDmode after the last argument
4175 has been seen. Whatever we return will be passed to the call
4176 insn. If we need any shifts for small structures, return them in
4177 a PARALLEL; in that case, stuff the mips16 fp_code in as the
4178 mode. Otherwise, if we have need a mips16 fp_code, return a REG
4179 with the code stored as the mode. */
4180 if (mode
== VOIDmode
)
4182 if (cum
->num_adjusts
> 0)
4183 ret
= gen_rtx (PARALLEL
, (enum machine_mode
) cum
->fp_code
,
4184 gen_rtvec_v (cum
->num_adjusts
, cum
->adjust
));
4185 else if (TARGET_MIPS16
&& cum
->fp_code
!= 0)
4186 ret
= gen_rtx (REG
, (enum machine_mode
) cum
->fp_code
, 0);
4193 function_arg_partial_nregs (cum
, mode
, type
, named
)
4194 CUMULATIVE_ARGS
*cum
; /* current arg information */
4195 enum machine_mode mode
; /* current arg mode */
4196 tree type
; /* type of the argument or 0 if lib support */
4197 int named ATTRIBUTE_UNUSED
;/* != 0 for normal args, == 0 for ... args */
4199 if ((mode
== BLKmode
4200 || GET_MODE_CLASS (mode
) != MODE_COMPLEX_INT
4201 || GET_MODE_CLASS (mode
) != MODE_COMPLEX_FLOAT
)
4202 && cum
->arg_words
< (unsigned) MAX_ARGS_IN_REGISTERS
4203 && mips_abi
!= ABI_EABI
)
4206 if (mode
== BLKmode
)
4207 words
= ((int_size_in_bytes (type
) + UNITS_PER_WORD
- 1)
4210 words
= (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
4212 if (words
+ cum
->arg_words
<= (unsigned) MAX_ARGS_IN_REGISTERS
)
4213 return 0; /* structure fits in registers */
4215 if (TARGET_DEBUG_E_MODE
)
4216 fprintf (stderr
, "function_arg_partial_nregs = %d\n",
4217 MAX_ARGS_IN_REGISTERS
- cum
->arg_words
);
4219 return MAX_ARGS_IN_REGISTERS
- cum
->arg_words
;
4222 else if (mode
== DImode
4223 && cum
->arg_words
== MAX_ARGS_IN_REGISTERS
- (unsigned)1
4224 && ! TARGET_64BIT
&& mips_abi
!= ABI_EABI
)
4226 if (TARGET_DEBUG_E_MODE
)
4227 fprintf (stderr
, "function_arg_partial_nregs = 1\n");
4235 /* Create the va_list data type.
4236 We keep 3 pointers, and two offsets.
4237 Two pointers are to the overflow area, which starts at the CFA.
4238 One of these is constant, for addressing into the GPR save area below it.
4239 The other is advanced up the stack through the overflow region.
4240 The third pointer is to the GPR save area. Since the FPR save area
4241 is just below it, we can address FPR slots off this pointer.
4242 We also keep two one-byte offsets, which are to be subtracted from the
4243 constant pointers to yield addresses in the GPR and FPR save areas.
4244 These are downcounted as float or non-float arguments are used,
4245 and when they get to zero, the argument must be obtained from the
4247 If TARGET_SOFT_FLOAT or TARGET_SINGLE_FLOAT, then no FPR save area exists,
4248 and a single pointer is enough. It's started at the GPR save area,
4249 and is advanced, period.
4250 Note that the GPR save area is not constant size, due to optimization
4251 in the prologue. Hence, we can't use a design with two pointers
4252 and two offsets, although we could have designed this with two pointers
4253 and three offsets. */
4257 mips_build_va_list ()
4259 if (mips_abi
== ABI_EABI
&& !TARGET_SOFT_FLOAT
&& !TARGET_SINGLE_FLOAT
)
4261 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
, record
;
4263 record
= make_node (RECORD_TYPE
);
4265 f_ovfl
= build_decl (FIELD_DECL
, get_identifier ("__overflow_argptr"),
4267 f_gtop
= build_decl (FIELD_DECL
, get_identifier ("__gpr_top"),
4269 f_ftop
= build_decl (FIELD_DECL
, get_identifier ("__fpr_top"),
4271 f_goff
= build_decl (FIELD_DECL
, get_identifier ("__gpr_offset"),
4272 unsigned_char_type_node
);
4273 f_foff
= build_decl (FIELD_DECL
, get_identifier ("__fpr_offset"),
4274 unsigned_char_type_node
);
4277 DECL_FIELD_CONTEXT (f_ovfl
) = record
;
4278 DECL_FIELD_CONTEXT (f_gtop
) = record
;
4279 DECL_FIELD_CONTEXT (f_ftop
) = record
;
4280 DECL_FIELD_CONTEXT (f_goff
) = record
;
4281 DECL_FIELD_CONTEXT (f_foff
) = record
;
4283 TYPE_FIELDS (record
) = f_ovfl
;
4284 TREE_CHAIN (f_ovfl
) = f_gtop
;
4285 TREE_CHAIN (f_gtop
) = f_ftop
;
4286 TREE_CHAIN (f_ftop
) = f_goff
;
4287 TREE_CHAIN (f_goff
) = f_foff
;
4289 layout_type (record
);
4293 return ptr_type_node
;
4296 /* Implement va_start. stdarg_p is 0 if implementing
4297 __builtin_varargs_va_start, 1 if implementing __builtin_stdarg_va_start.
4298 Note that this routine isn't called when compiling e.g. "_vfprintf_r".
4299 (It doesn't have "...", so it inherits the pointers of its caller.) */
4302 mips_va_start (stdarg_p
, valist
, nextarg
)
4310 /* Find out how many non-float named formals */
4311 int_arg_words
= current_function_args_info
.arg_words
;
4313 if (mips_abi
== ABI_EABI
)
4315 int gpr_save_area_size
;
4316 /* Note UNITS_PER_WORD is 4 bytes or 8, depending on TARGET_64BIT. */
4317 if (int_arg_words
< 8 )
4318 /* Adjust for the prologue's economy measure */
4319 gpr_save_area_size
= (8 - int_arg_words
) * UNITS_PER_WORD
;
4321 gpr_save_area_size
= 0;
4323 if (!TARGET_SOFT_FLOAT
&& !TARGET_SINGLE_FLOAT
)
4325 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4326 tree ovfl
, gtop
, ftop
, goff
, foff
;
4328 int float_formals
, fpr_offset
, size_excess
, floats_passed_in_regs
;
4329 int fpr_save_offset
;
4331 float_formals
= current_function_args_info
.fp_arg_words
;
4332 /* If mips2, the number of formals is half the reported # of words */
4335 floats_passed_in_regs
= (TARGET_64BIT
? 8 : 4);
4337 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4338 f_gtop
= TREE_CHAIN (f_ovfl
);
4339 f_ftop
= TREE_CHAIN (f_gtop
);
4340 f_goff
= TREE_CHAIN (f_ftop
);
4341 f_foff
= TREE_CHAIN (f_goff
);
4343 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4344 gtop
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4345 ftop
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4346 goff
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4347 foff
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4349 /* Emit code setting a pointer into the overflow (shared-stack) area.
4350 If there were more than 8 non-float formals, or more than 8
4351 float formals, then this pointer isn't to the base of the area.
4352 In that case, it must point to where the first vararg is. */
4354 if (float_formals
> floats_passed_in_regs
)
4355 size_excess
+= (float_formals
-floats_passed_in_regs
) * 8;
4356 if (int_arg_words
> 8)
4357 size_excess
+= (int_arg_words
-8) * UNITS_PER_WORD
;
4359 /* FIXME: for mips2, the above size_excess can be wrong. Because the
4360 overflow stack holds mixed size items, there can be alignments,
4361 so that an 8 byte double following a 4 byte int will be on an
4362 8 byte boundary. This means that the above calculation should
4363 take into account the exact sequence of floats and non-floats
4364 which make up the excess. That calculation should be rolled
4365 into the code which sets the current_function_args_info struct.
4366 The above then reduces to a fetch from that struct. */
4369 t
= make_tree (TREE_TYPE (ovfl
), virtual_incoming_args_rtx
);
4371 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), t
,
4372 build_int_2 (size_excess
, 0));
4373 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4374 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4376 /* Emit code setting a ptr to the base of the overflow area. */
4377 t
= make_tree (TREE_TYPE (gtop
), virtual_incoming_args_rtx
);
4378 t
= build (MODIFY_EXPR
, TREE_TYPE (gtop
), gtop
, t
);
4379 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4381 /* Emit code setting a pointer to the GPR save area.
4382 More precisely, a pointer to off-the-end of the FPR save area.
4383 If mips4, this is gpr_save_area_size below the overflow area.
4384 If mips2, also round down to an 8-byte boundary, since the FPR
4385 save area is 8-byte aligned, and GPR is 4-byte-aligned.
4386 Therefore there can be a 4-byte gap between the save areas. */
4387 gprv
= make_tree (TREE_TYPE (ftop
), virtual_incoming_args_rtx
);
4388 fpr_save_offset
= gpr_save_area_size
;
4391 if (fpr_save_offset
& 7)
4392 fpr_save_offset
+= 4;
4394 if (fpr_save_offset
)
4395 gprv
= build (PLUS_EXPR
, TREE_TYPE (ftop
), gprv
,
4396 build_int_2 (-fpr_save_offset
,-1));
4397 t
= build (MODIFY_EXPR
, TREE_TYPE (ftop
), ftop
, gprv
);
4398 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4400 /* Emit code initting an offset to the size of the GPR save area */
4401 t
= build (MODIFY_EXPR
, TREE_TYPE (goff
), goff
,
4402 build_int_2 (gpr_save_area_size
,0));
4403 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4405 /* Emit code initting an offset from ftop to the first float
4406 vararg. This varies in size, since any float
4407 varargs are put in the FPR save area after the formals.
4408 Note it's 8 bytes/formal regardless of TARGET_64BIT.
4409 However, mips2 stores 4 GPRs, mips4 stores 8 GPRs.
4410 If there are 8 or more float formals, init to zero.
4411 (In fact, the formals aren't stored in the bottom of the
4412 FPR save area: they are elsewhere, and the size of the FPR
4413 save area is economized by the prologue. But this code doesn't
4414 care. This design is unaffected by that fact.) */
4415 if (float_formals
>= floats_passed_in_regs
)
4418 fpr_offset
= (floats_passed_in_regs
- float_formals
) * 8;
4419 t
= build (MODIFY_EXPR
, TREE_TYPE (foff
), foff
,
4420 build_int_2 (fpr_offset
,0));
4421 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4425 /* TARGET_SOFT_FLOAT or TARGET_SINGLE_FLOAT */
4427 /* Everything is in the GPR save area, or in the overflow
4428 area which is contiguous with it. */
4430 int offset
= -gpr_save_area_size
;
4431 if (gpr_save_area_size
== 0)
4432 offset
= (stdarg_p
? 0 : -UNITS_PER_WORD
);
4433 nextarg
= plus_constant (nextarg
, offset
);
4434 std_expand_builtin_va_start (1, valist
, nextarg
);
4446 /* ??? This had been conditional on
4447 _MIPS_SIM == _MIPS_SIM_ABI64 || _MIPS_SIM == _MIPS_SIM_NABI32
4448 and both iris5.h and iris6.h define _MIPS_SIM. */
4449 if (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
)
4450 ofs
= (int_arg_words
>= 8 ? -UNITS_PER_WORD
: 0);
4452 ofs
= -UNITS_PER_WORD
;
4455 nextarg
= plus_constant (nextarg
, ofs
);
4456 std_expand_builtin_va_start (1, valist
, nextarg
);
4460 /* Implement va_arg. */
4463 mips_va_arg (valist
, type
)
4466 HOST_WIDE_INT size
, rsize
;
4470 size
= int_size_in_bytes (type
);
4471 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
4473 if (mips_abi
== ABI_EABI
)
4476 rtx r
, lab_over
= NULL_RTX
, lab_false
;
4477 tree f_ovfl
, f_gtop
, f_ftop
, f_goff
, f_foff
;
4478 tree ovfl
, gtop
, ftop
, goff
, foff
;
4481 = function_arg_pass_by_reference (NULL
, TYPE_MODE (type
), type
, 0);
4484 size
= POINTER_SIZE
/ BITS_PER_UNIT
;
4485 rsize
= UNITS_PER_WORD
;
4488 addr_rtx
= gen_reg_rtx (Pmode
);
4490 if (TARGET_SOFT_FLOAT
|| TARGET_SINGLE_FLOAT
)
4492 /* Case of all args in a merged stack. No need to check bounds,
4493 just advance valist along the stack. */
4498 && TYPE_ALIGN (type
) > (unsigned) BITS_PER_WORD
)
4500 t
= build (PLUS_EXPR
, TREE_TYPE (gpr
), gpr
,
4501 build_int_2 (2*UNITS_PER_WORD
- 1, 0));
4502 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
,
4503 build_int_2 (-2*UNITS_PER_WORD
, -1));
4504 t
= build (MODIFY_EXPR
, TREE_TYPE (gpr
), gpr
, t
);
4505 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4508 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (gpr
), gpr
,
4510 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4512 emit_move_insn (addr_rtx
, r
);
4514 /* flush the POSTINCREMENT */
4519 r
= gen_rtx_MEM (Pmode
, addr_rtx
);
4520 MEM_ALIAS_SET (r
) = get_varargs_alias_set ();
4521 emit_move_insn (addr_rtx
, r
);
4525 if (BYTES_BIG_ENDIAN
&& rsize
!= size
)
4526 addr_rtx
= plus_constant (addr_rtx
, rsize
- size
);
4531 /* Not a simple merged stack. Need ptrs and indexes left by va_start. */
4533 f_ovfl
= TYPE_FIELDS (va_list_type_node
);
4534 f_gtop
= TREE_CHAIN (f_ovfl
);
4535 f_ftop
= TREE_CHAIN (f_gtop
);
4536 f_goff
= TREE_CHAIN (f_ftop
);
4537 f_foff
= TREE_CHAIN (f_goff
);
4539 ovfl
= build (COMPONENT_REF
, TREE_TYPE (f_ovfl
), valist
, f_ovfl
);
4540 gtop
= build (COMPONENT_REF
, TREE_TYPE (f_gtop
), valist
, f_gtop
);
4541 ftop
= build (COMPONENT_REF
, TREE_TYPE (f_ftop
), valist
, f_ftop
);
4542 goff
= build (COMPONENT_REF
, TREE_TYPE (f_goff
), valist
, f_goff
);
4543 foff
= build (COMPONENT_REF
, TREE_TYPE (f_foff
), valist
, f_foff
);
4545 lab_false
= gen_label_rtx ();
4546 lab_over
= gen_label_rtx ();
4548 if (TREE_CODE (type
) == REAL_TYPE
)
4551 /* Emit code to branch if foff == 0. */
4552 r
= expand_expr (foff
, NULL_RTX
, TYPE_MODE (TREE_TYPE (foff
)),
4554 emit_cmp_and_jump_insns (r
, const0_rtx
, EQ
,
4555 const1_rtx
, GET_MODE (r
), 1, 1, lab_false
);
4557 /* Emit code for addr_rtx = ftop - foff */
4558 t
= build (MINUS_EXPR
, TREE_TYPE (ftop
), ftop
, foff
);
4559 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4561 emit_move_insn (addr_rtx
, r
);
4563 /* Emit code for foff-=8.
4564 Advances the offset up FPR save area by one double */
4565 t
= build (MINUS_EXPR
, TREE_TYPE (foff
), foff
, build_int_2 (8, 0));
4566 t
= build (MODIFY_EXPR
, TREE_TYPE (foff
), foff
, t
);
4567 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4570 emit_jump (lab_over
);
4572 emit_label (lab_false
);
4576 /* For mips2, the overflow area contains mixed size items.
4577 If a 4-byte int is followed by an 8-byte float, then
4578 natural alignment causes a 4 byte gap.
4579 So, dynamically adjust ovfl up to a multiple of 8. */
4580 t
= build (BIT_AND_EXPR
, TREE_TYPE (ovfl
), ovfl
,
4581 build_int_2 (7, 0));
4582 t
= build (PLUS_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4583 t
= build (MODIFY_EXPR
, TREE_TYPE (ovfl
), ovfl
, t
);
4584 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4587 /* Emit code for addr_rtx = the ovfl pointer into overflow area.
4588 Regardless of mips2, postincrement the ovfl pointer by 8. */
4589 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE(ovfl
), ovfl
,
4591 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4593 emit_move_insn (addr_rtx
, r
);
4596 emit_label (lab_over
);
4605 && TREE_CODE (type
) == INTEGER_TYPE
4606 && TYPE_PRECISION (type
) == 64)
4608 /* In mips2, int takes 32 bits of the GPR save area, but
4609 longlong takes an aligned 64 bits. So, emit code
4610 to zero the low order bits of goff, thus aligning
4611 the later calculation of (gtop-goff) upwards. */
4612 t
= build (BIT_AND_EXPR
, TREE_TYPE (goff
), goff
,
4613 build_int_2 (-8, -1));
4614 t
= build (MODIFY_EXPR
, TREE_TYPE (goff
), goff
, t
);
4615 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4618 /* Emit code to branch if goff == 0. */
4619 r
= expand_expr (goff
, NULL_RTX
, TYPE_MODE (TREE_TYPE (goff
)),
4621 emit_cmp_and_jump_insns (r
, const0_rtx
, EQ
,
4622 const1_rtx
, GET_MODE (r
), 1, 1, lab_false
);
4624 /* Emit code for addr_rtx = gtop - goff. */
4625 t
= build (MINUS_EXPR
, TREE_TYPE (gtop
), gtop
, goff
);
4626 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4628 emit_move_insn (addr_rtx
, r
);
4630 /* Note that mips2 int is 32 bit, but mips2 longlong is 64. */
4631 if (! TARGET_64BIT
&& TYPE_PRECISION (type
) == 64)
4634 step_size
= UNITS_PER_WORD
;
4636 /* Emit code for goff = goff - step_size.
4637 Advances the offset up GPR save area over the item. */
4638 t
= build (MINUS_EXPR
, TREE_TYPE (goff
), goff
,
4639 build_int_2 (step_size
, 0));
4640 t
= build (MODIFY_EXPR
, TREE_TYPE (goff
), goff
, t
);
4641 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4644 emit_jump (lab_over
);
4646 emit_label (lab_false
);
4648 /* Emit code for addr_rtx -> overflow area, postinc by step_size */
4649 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE(ovfl
), ovfl
,
4650 size_int (step_size
));
4651 r
= expand_expr (t
, addr_rtx
, Pmode
, EXPAND_NORMAL
);
4653 emit_move_insn (addr_rtx
, r
);
4656 emit_label (lab_over
);
4660 r
= gen_rtx_MEM (Pmode
, addr_rtx
);
4661 MEM_ALIAS_SET (r
) = get_varargs_alias_set ();
4662 emit_move_insn (addr_rtx
, r
);
4666 if (BYTES_BIG_ENDIAN
&& rsize
!= size
)
4667 addr_rtx
= plus_constant (addr_rtx
, rsize
- size
);
4677 /* ??? The original va-mips.h did always align, despite the fact
4678 that alignments <= UNITS_PER_WORD are preserved by the va_arg
4679 increment mechanism. */
4683 else if (TYPE_ALIGN (type
) > 32)
4688 t
= build (PLUS_EXPR
, TREE_TYPE (valist
), valist
,
4689 build_int_2 (align
- 1, 0));
4690 t
= build (BIT_AND_EXPR
, TREE_TYPE (t
), t
, build_int_2 (-align
, -1));
4691 t
= build (MODIFY_EXPR
, TREE_TYPE (valist
), valist
, t
);
4692 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4694 /* Everything past the alignment is standard. */
4695 return std_expand_builtin_va_arg (valist
, type
);
4699 /* Abort after printing out a specific insn. */
4702 abort_with_insn (insn
, reason
)
4711 /* Set up the threshold for data to go into the small data area, instead
4712 of the normal data area, and detect any conflicts in the switches. */
4717 register int i
, start
;
4719 register enum machine_mode mode
;
4721 mips_section_threshold
= g_switch_set
? g_switch_value
: MIPS_DEFAULT_GVALUE
;
4723 if (mips_section_threshold
<= 0)
4724 target_flags
&= ~MASK_GPOPT
;
4726 target_flags
|= MASK_GPOPT
;
4728 /* If both single-float and soft-float are set, then clear the one that
4729 was set by TARGET_DEFAULT, leaving the one that was set by the
4730 user. We assume here that the specs prevent both being set by the
4732 #ifdef TARGET_DEFAULT
4733 if (TARGET_SINGLE_FLOAT
&& TARGET_SOFT_FLOAT
)
4734 target_flags
&= ~((TARGET_DEFAULT
) & (MASK_SOFT_FLOAT
| MASK_SINGLE_FLOAT
));
4737 /* Get the architectural level. */
4738 if (mips_isa_string
== 0)
4739 mips_isa
= MIPS_ISA_DEFAULT
;
4741 else if (ISDIGIT (*mips_isa_string
))
4743 mips_isa
= atoi (mips_isa_string
);
4746 /* -mno-mips16 overrides -mips16. */
4747 if (mips_no_mips16_string
== NULL
)
4749 target_flags
|= MASK_MIPS16
;
4753 mips_isa
= MIPS_ISA_DEFAULT
;
4757 mips_isa
= MIPS_ISA_DEFAULT
;
4760 else if (mips_isa
< 1 || mips_isa
> 4)
4762 error ("-mips%d not supported", mips_isa
);
4769 error ("bad value (%s) for -mips switch", mips_isa_string
);
4773 #ifdef MIPS_ABI_DEFAULT
4774 /* Get the ABI to use. */
4775 if (mips_abi_string
== (char *) 0)
4776 mips_abi
= MIPS_ABI_DEFAULT
;
4777 else if (! strcmp (mips_abi_string
, "32"))
4779 else if (! strcmp (mips_abi_string
, "o64"))
4781 else if (! strcmp (mips_abi_string
, "n32"))
4783 else if (! strcmp (mips_abi_string
, "64"))
4785 else if (! strcmp (mips_abi_string
, "eabi"))
4786 mips_abi
= ABI_EABI
;
4788 error ("bad value (%s) for -mabi= switch", mips_abi_string
);
4790 /* A specified ISA defaults the ABI if it was not specified. */
4791 if (mips_abi_string
== 0 && mips_isa_string
4792 && mips_abi
!= ABI_EABI
&& mips_abi
!= ABI_O64
)
4794 if (! ISA_HAS_64BIT_REGS
)
4800 /* A specified ABI defaults the ISA if it was not specified. */
4801 else if (mips_isa_string
== 0 && mips_abi_string
4802 && mips_abi
!= ABI_EABI
&& mips_abi
!= ABI_O64
)
4804 if (mips_abi
== ABI_32
)
4806 else if (mips_abi
== ABI_N32
)
4812 /* If both ABI and ISA were specified, check for conflicts. */
4813 else if (mips_isa_string
&& mips_abi_string
)
4815 if ((! ISA_HAS_64BIT_REGS
&& (mips_abi
== ABI_N32
|| mips_abi
== ABI_64
4816 || mips_abi
== ABI_O64
))
4817 || (ISA_HAS_64BIT_REGS
&& mips_abi
== ABI_32
))
4818 error ("-mabi=%s does not support -mips%d", mips_abi_string
, mips_isa
);
4821 /* Override TARGET_DEFAULT if necessary. */
4822 if (mips_abi
== ABI_32
)
4823 target_flags
&= ~ (MASK_FLOAT64
|MASK_64BIT
);
4825 /* If no type size setting options (-mlong64,-mint64,-mlong32) were used
4826 then set the type sizes. In the EABI in 64 bit mode, longs and
4827 pointers are 64 bits. Likewise for the SGI Irix6 N64 ABI. */
4828 if (mips_explicit_type_size_string
== NULL
4829 && ((mips_abi
== ABI_EABI
&& TARGET_64BIT
)
4830 || mips_abi
== ABI_64
))
4831 target_flags
|= MASK_LONG64
;
4833 /* ??? This doesn't work yet, so don't let people try to use it. */
4834 if (mips_abi
== ABI_32
)
4835 error ("The -mabi=32 support does not work yet.");
4838 if (mips_abi_string
)
4839 error ("This target does not support the -mabi switch.");
4842 #ifdef MIPS_CPU_STRING_DEFAULT
4843 /* ??? There is a minor inconsistency here. If the user specifies an ISA
4844 greater than that supported by the default processor, then the user gets
4845 an error. Normally, the compiler will just default to the base level cpu
4846 for the indicated isa. */
4847 if (mips_arch_string
== 0)
4848 mips_arch_string
= MIPS_CPU_STRING_DEFAULT
;
4849 if (mips_tune_string
== 0)
4850 mips_tune_string
= MIPS_CPU_STRING_DEFAULT
;
4853 /* Identify the processor type. */
4855 if (mips_cpu_string
!= 0)
4857 mips_cpu
= mips_parse_cpu (mips_cpu_string
);
4858 if (mips_cpu
== PROCESSOR_DEFAULT
)
4860 error ("bad value (%s) for -mcpu= switch", mips_arch_string
);
4861 mips_cpu_string
= "default";
4863 mips_arch
= mips_cpu
;
4864 mips_tune
= mips_cpu
;
4867 if (mips_arch_string
== 0
4868 || ! strcmp (mips_arch_string
, "default")
4869 || ! strcmp (mips_arch_string
, "DEFAULT"))
4874 mips_arch_string
= "3000";
4875 mips_arch
= PROCESSOR_R3000
;
4878 mips_arch_string
= "6000";
4879 mips_arch
= PROCESSOR_R6000
;
4882 mips_arch_string
= "4000";
4883 mips_arch
= PROCESSOR_R4000
;
4886 mips_arch_string
= "8000";
4887 mips_arch
= PROCESSOR_R8000
;
4893 mips_arch
= mips_parse_cpu (mips_arch_string
);
4894 if (mips_arch
== PROCESSOR_DEFAULT
)
4896 error ("bad value (%s) for -march= switch", mips_arch_string
);
4897 mips_arch_string
= "default";
4900 if (mips_tune_string
== 0
4901 || ! strcmp (mips_tune_string
, "default")
4902 || ! strcmp (mips_tune_string
, "DEFAULT"))
4904 if (mips_arch
!= PROCESSOR_DEFAULT
)
4905 mips_tune
== mips_arch
;
4910 mips_tune_string
= "3000";
4911 mips_tune
= PROCESSOR_R3000
;
4914 mips_tune_string
= "6000";
4915 mips_tune
= PROCESSOR_R6000
;
4918 mips_tune_string
= "4000";
4919 mips_tune
= PROCESSOR_R4000
;
4922 mips_tune_string
= "8000";
4923 mips_tune
= PROCESSOR_R8000
;
4930 mips_tune
= mips_parse_cpu (mips_tune_string
);
4931 if (mips_tune
== PROCESSOR_DEFAULT
)
4933 error ("bad value (%s) for -mtune= switch", mips_tune_string
);
4934 mips_tune_string
= "default";
4938 /* Handle processor configuration based on architecture. */
4939 if (TARGET_MIPS4100
|| TARGET_MIPS3900
)
4940 target_flags
|= MASK_SOFT_FLOAT
;
4943 if ((mips_arch
== PROCESSOR_R3000
&& (mips_isa
!= 1))
4944 || (mips_arch
== PROCESSOR_R6000
&& mips_isa
!= 1 && mips_isa
!= 2)
4945 || ((mips_arch
== PROCESSOR_R4000
4946 || mips_arch
== PROCESSOR_R4100
4947 || mips_arch
== PROCESSOR_R4300
4948 || mips_arch
== PROCESSOR_R4600
4949 || mips_arch
== PROCESSOR_R4650
)
4950 && mips_isa
!= 1 && mips_isa
!= 2 && mips_isa
!= 3))
4951 error ("-march=%s does not support -mips%d", mips_arch_string
, mips_isa
);
4953 /* make sure sizes of ints/longs/etc. are ok */
4954 if (! ISA_HAS_64BIT_REGS
)
4958 error ("-mips%d does not support 64 bit fp registers", mips_isa
);
4959 target_flags
&= ~ MASK_FLOAT64
;
4962 else if (TARGET_64BIT
)
4964 error ("-mips%d does not support 64 bit gp registers", mips_isa
);
4965 target_flags
&= ~MASK_64BIT
;
4969 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
4970 flag_pcc_struct_return
= 0;
4972 /* Tell halfpic.c that we have half-pic code if we do. */
4973 if (TARGET_HALF_PIC
)
4976 /* -fpic (-KPIC) is the default when TARGET_ABICALLS is defined. We need
4977 to set flag_pic so that the LEGITIMATE_PIC_OPERAND_P macro will work. */
4978 /* ??? -non_shared turns off pic code generation, but this is not
4980 if (TARGET_ABICALLS
)
4982 mips_abicalls
= MIPS_ABICALLS_YES
;
4984 if (mips_section_threshold
> 0)
4985 warning ("-G is incompatible with PIC code which is the default");
4988 mips_abicalls
= MIPS_ABICALLS_NO
;
4990 /* -membedded-pic is a form of PIC code suitable for embedded
4991 systems. All calls are made using PC relative addressing, and
4992 all data is addressed using the $gp register. This requires gas,
4993 which does most of the work, and GNU ld, which automatically
4994 expands PC relative calls which are out of range into a longer
4995 instruction sequence. All gcc really does differently is
4996 generate a different sequence for a switch. */
4997 if (TARGET_EMBEDDED_PIC
)
5000 if (TARGET_ABICALLS
)
5001 warning ("-membedded-pic and -mabicalls are incompatible");
5004 warning ("-G and -membedded-pic are incompatible");
5006 /* Setting mips_section_threshold is not required, because gas
5007 will force everything to be GP addressable anyhow, but
5008 setting it will cause gcc to make better estimates of the
5009 number of instructions required to access a particular data
5011 mips_section_threshold
= 0x7fffffff;
5014 /* This optimization requires a linker that can support a R_MIPS_LO16
5015 relocation which is not immediately preceded by a R_MIPS_HI16 relocation.
5016 GNU ld has this support, but not all other MIPS linkers do, so we enable
5017 this optimization only if the user requests it, or if GNU ld is the
5018 standard linker for this configuration. */
5019 /* ??? This does not work when target addresses are DImode.
5020 This is because we are missing DImode high/lo_sum patterns. */
5021 if (TARGET_GAS
&& ! TARGET_MIPS16
&& TARGET_SPLIT_ADDRESSES
&& optimize
&& ! flag_pic
5023 mips_split_addresses
= 1;
5025 mips_split_addresses
= 0;
5027 /* -mrnames says to use the MIPS software convention for register
5028 names instead of the hardware names (ie, $a0 instead of $4).
5029 We do this by switching the names in mips_reg_names, which the
5030 reg_names points into via the REGISTER_NAMES macro. */
5032 if (TARGET_NAME_REGS
)
5033 memcpy (mips_reg_names
, mips_sw_reg_names
, sizeof (mips_reg_names
));
5035 /* When compiling for the mips16, we can not use floating point. We
5036 record the original hard float value in mips16_hard_float. */
5039 if (TARGET_SOFT_FLOAT
)
5040 mips16_hard_float
= 0;
5042 mips16_hard_float
= 1;
5043 target_flags
|= MASK_SOFT_FLOAT
;
5045 /* Don't run the scheduler before reload, since it tends to
5046 increase register pressure. */
5047 flag_schedule_insns
= 0;
5050 /* We put -mentry in TARGET_OPTIONS rather than TARGET_SWITCHES only
5051 to avoid using up another bit in target_flags. */
5052 if (mips_entry_string
!= NULL
)
5054 if (*mips_entry_string
!= '\0')
5055 error ("Invalid option `entry%s'", mips_entry_string
);
5057 if (! TARGET_MIPS16
)
5058 warning ("-mentry is only meaningful with -mips-16");
5063 /* We copy TARGET_MIPS16 into the mips16 global variable, so that
5064 attributes can access it. */
5070 /* Initialize the high and low values for legitimate floating point
5071 constants. Rather than trying to get the accuracy down to the
5072 last bit, just use approximate ranges. */
5073 dfhigh
= REAL_VALUE_ATOF ("1.0e300", DFmode
);
5074 dflow
= REAL_VALUE_ATOF ("1.0e-300", DFmode
);
5075 sfhigh
= REAL_VALUE_ATOF ("1.0e38", SFmode
);
5076 sflow
= REAL_VALUE_ATOF ("1.0e-38", SFmode
);
5078 mips_print_operand_punct
['?'] = 1;
5079 mips_print_operand_punct
['#'] = 1;
5080 mips_print_operand_punct
['&'] = 1;
5081 mips_print_operand_punct
['!'] = 1;
5082 mips_print_operand_punct
['*'] = 1;
5083 mips_print_operand_punct
['@'] = 1;
5084 mips_print_operand_punct
['.'] = 1;
5085 mips_print_operand_punct
['('] = 1;
5086 mips_print_operand_punct
[')'] = 1;
5087 mips_print_operand_punct
['['] = 1;
5088 mips_print_operand_punct
[']'] = 1;
5089 mips_print_operand_punct
['<'] = 1;
5090 mips_print_operand_punct
['>'] = 1;
5091 mips_print_operand_punct
['{'] = 1;
5092 mips_print_operand_punct
['}'] = 1;
5093 mips_print_operand_punct
['^'] = 1;
5094 mips_print_operand_punct
['$'] = 1;
5095 mips_print_operand_punct
['+'] = 1;
5096 mips_print_operand_punct
['~'] = 1;
5098 mips_char_to_class
['d'] = TARGET_MIPS16
? M16_REGS
: GR_REGS
;
5099 mips_char_to_class
['e'] = M16_NA_REGS
;
5100 mips_char_to_class
['t'] = T_REG
;
5101 mips_char_to_class
['f'] = (TARGET_HARD_FLOAT
? FP_REGS
: NO_REGS
);
5102 mips_char_to_class
['h'] = HI_REG
;
5103 mips_char_to_class
['l'] = LO_REG
;
5104 mips_char_to_class
['a'] = HILO_REG
;
5105 mips_char_to_class
['x'] = MD_REGS
;
5106 mips_char_to_class
['b'] = ALL_REGS
;
5107 mips_char_to_class
['y'] = GR_REGS
;
5108 mips_char_to_class
['z'] = ST_REGS
;
5110 /* Set up array to map GCC register number to debug register number.
5111 Ignore the special purpose register numbers. */
5113 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5114 mips_dbx_regno
[i
] = -1;
5116 start
= GP_DBX_FIRST
- GP_REG_FIRST
;
5117 for (i
= GP_REG_FIRST
; i
<= GP_REG_LAST
; i
++)
5118 mips_dbx_regno
[i
] = i
+ start
;
5120 start
= FP_DBX_FIRST
- FP_REG_FIRST
;
5121 for (i
= FP_REG_FIRST
; i
<= FP_REG_LAST
; i
++)
5122 mips_dbx_regno
[i
] = i
+ start
;
5124 /* Set up array giving whether a given register can hold a given mode.
5125 At present, restrict ints from being in FP registers, because reload
5126 is a little enthusiastic about storing extra values in FP registers,
5127 and this is not good for things like OS kernels. Also, due to the
5128 mandatory delay, it is as fast to load from cached memory as to move
5129 from the FP register. */
5131 for (mode
= VOIDmode
;
5132 mode
!= MAX_MACHINE_MODE
;
5133 mode
= (enum machine_mode
) ((int)mode
+ 1))
5135 register int size
= GET_MODE_SIZE (mode
);
5136 register enum mode_class
class = GET_MODE_CLASS (mode
);
5138 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
5145 temp
= (regno
== FPSW_REGNUM
);
5147 temp
= (ST_REG_P (regno
) || GP_REG_P (regno
)
5148 || FP_REG_P (regno
));
5151 else if (GP_REG_P (regno
))
5152 temp
= ((regno
& 1) == 0 || size
<= UNITS_PER_WORD
);
5154 else if (FP_REG_P (regno
))
5155 temp
= ((TARGET_FLOAT64
|| ((regno
& 1) == 0))
5156 && (class == MODE_FLOAT
5157 || class == MODE_COMPLEX_FLOAT
5158 || (TARGET_DEBUG_H_MODE
&& class == MODE_INT
))
5159 && (! TARGET_SINGLE_FLOAT
|| size
<= 4));
5161 else if (MD_REG_P (regno
))
5162 temp
= (class == MODE_INT
5163 && (size
<= UNITS_PER_WORD
5164 || (regno
== MD_REG_FIRST
5165 && size
== 2 * UNITS_PER_WORD
)));
5170 mips_hard_regno_mode_ok
[(int)mode
][regno
] = temp
;
5174 /* Save GPR registers in word_mode sized hunks. word_mode hasn't been
5175 initialized yet, so we can't use that here. */
5176 gpr_mode
= TARGET_64BIT
? DImode
: SImode
;
5178 /* Provide default values for align_* for 64-bit targets. */
5179 if (TARGET_64BIT
&& !TARGET_MIPS16
)
5181 if (align_loops
== 0)
5183 if (align_jumps
== 0)
5185 if (align_functions
== 0)
5186 align_functions
= 8;
5189 /* Register global variables with the garbage collector. */
5190 mips_add_gc_roots ();
5193 /* On the mips16, we want to allocate $24 (T_REG) before other
5194 registers for instructions for which it is possible. This helps
5195 avoid shuffling registers around in order to set up for an xor,
5196 encouraging the compiler to use a cmp instead. */
5199 mips_order_regs_for_local_alloc ()
5203 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
5204 reg_alloc_order
[i
] = i
;
5208 /* It really doesn't matter where we put register 0, since it is
5209 a fixed register anyhow. */
5210 reg_alloc_order
[0] = 24;
5211 reg_alloc_order
[24] = 0;
5216 /* The MIPS debug format wants all automatic variables and arguments
5217 to be in terms of the virtual frame pointer (stack pointer before
5218 any adjustment in the function), while the MIPS 3.0 linker wants
5219 the frame pointer to be the stack pointer after the initial
5220 adjustment. So, we do the adjustment here. The arg pointer (which
5221 is eliminated) points to the virtual frame pointer, while the frame
5222 pointer (which may be eliminated) points to the stack pointer after
5223 the initial adjustments. */
5226 mips_debugger_offset (addr
, offset
)
5228 HOST_WIDE_INT offset
;
5230 rtx offset2
= const0_rtx
;
5231 rtx reg
= eliminate_constant_term (addr
, &offset2
);
5234 offset
= INTVAL (offset2
);
5236 if (reg
== stack_pointer_rtx
|| reg
== frame_pointer_rtx
5237 || reg
== hard_frame_pointer_rtx
)
5239 HOST_WIDE_INT frame_size
= (!current_frame_info
.initialized
)
5240 ? compute_frame_size (get_frame_size ())
5241 : current_frame_info
.total_size
;
5243 /* MIPS16 frame is smaller */
5244 if (frame_pointer_needed
&& TARGET_MIPS16
)
5245 frame_size
-= current_function_outgoing_args_size
;
5247 offset
= offset
- frame_size
;
5250 /* sdbout_parms does not want this to crash for unrecognized cases. */
5252 else if (reg
!= arg_pointer_rtx
)
5253 abort_with_insn (addr
, "mips_debugger_offset called with non stack/frame/arg pointer.");
5259 /* A C compound statement to output to stdio stream STREAM the
5260 assembler syntax for an instruction operand X. X is an RTL
5263 CODE is a value that can be used to specify one of several ways
5264 of printing the operand. It is used when identical operands
5265 must be printed differently depending on the context. CODE
5266 comes from the `%' specification that was used to request
5267 printing of the operand. If the specification was just `%DIGIT'
5268 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
5269 is the ASCII code for LTR.
5271 If X is a register, this macro should print the register's name.
5272 The names can be found in an array `reg_names' whose type is
5273 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
5275 When the machine description has a specification `%PUNCT' (a `%'
5276 followed by a punctuation character), this macro is called with
5277 a null pointer for X and the punctuation character for CODE.
5279 The MIPS specific codes are:
5281 'X' X is CONST_INT, prints 32 bits in hexadecimal format = "0x%08x",
5282 'x' X is CONST_INT, prints 16 bits in hexadecimal format = "0x%04x",
5283 'd' output integer constant in decimal,
5284 'z' if the operand is 0, use $0 instead of normal operand.
5285 'D' print second register of double-word register operand.
5286 'L' print low-order register of double-word register operand.
5287 'M' print high-order register of double-word register operand.
5288 'C' print part of opcode for a branch condition.
5289 'F' print part of opcode for a floating-point branch condition.
5290 'N' print part of opcode for a branch condition, inverted.
5291 'W' print part of opcode for a floating-point branch condition, inverted.
5292 'S' X is CODE_LABEL, print with prefix of "LS" (for embedded switch).
5293 'B' print 'z' for EQ, 'n' for NE
5294 'b' print 'n' for EQ, 'z' for NE
5295 'T' print 'f' for EQ, 't' for NE
5296 't' print 't' for EQ, 'f' for NE
5297 'Z' print register and a comma, but print nothing for $fcc0
5298 '(' Turn on .set noreorder
5299 ')' Turn on .set reorder
5300 '[' Turn on .set noat
5302 '<' Turn on .set nomacro
5303 '>' Turn on .set macro
5304 '{' Turn on .set volatile (not GAS)
5305 '}' Turn on .set novolatile (not GAS)
5306 '&' Turn on .set noreorder if filling delay slots
5307 '*' Turn on both .set noreorder and .set nomacro if filling delay slots
5308 '!' Turn on .set nomacro if filling delay slots
5309 '#' Print nop if in a .set noreorder section.
5310 '?' Print 'l' if we are to use a branch likely instead of normal branch.
5311 '@' Print the name of the assembler temporary register (at or $1).
5312 '.' Print the name of the register with a hard-wired zero (zero or $0).
5313 '^' Print the name of the pic call-through register (t9 or $25).
5314 '$' Print the name of the stack pointer register (sp or $29).
5315 '+' Print the name of the gp register (gp or $28).
5316 '~' Output an branch alignment to LABEL_ALIGN(NULL). */
5319 print_operand (file
, op
, letter
)
5320 FILE *file
; /* file to write to */
5321 rtx op
; /* operand to print */
5322 int letter
; /* %<letter> or 0 */
5324 register enum rtx_code code
;
5326 if (PRINT_OPERAND_PUNCT_VALID_P (letter
))
5331 if (mips_branch_likely
)
5336 fputs (reg_names
[GP_REG_FIRST
+ 1], file
);
5340 fputs (reg_names
[PIC_FUNCTION_ADDR_REGNUM
], file
);
5344 fputs (reg_names
[GP_REG_FIRST
+ 0], file
);
5348 fputs (reg_names
[STACK_POINTER_REGNUM
], file
);
5352 fputs (reg_names
[GP_REG_FIRST
+ 28], file
);
5356 if (final_sequence
!= 0 && set_noreorder
++ == 0)
5357 fputs (".set\tnoreorder\n\t", file
);
5361 if (final_sequence
!= 0)
5363 if (set_noreorder
++ == 0)
5364 fputs (".set\tnoreorder\n\t", file
);
5366 if (set_nomacro
++ == 0)
5367 fputs (".set\tnomacro\n\t", file
);
5372 if (final_sequence
!= 0 && set_nomacro
++ == 0)
5373 fputs ("\n\t.set\tnomacro", file
);
5377 if (set_noreorder
!= 0)
5378 fputs ("\n\tnop", file
);
5379 else if (TARGET_STATS
)
5380 fputs ("\n\t#nop", file
);
5385 if (set_noreorder
++ == 0)
5386 fputs (".set\tnoreorder\n\t", file
);
5390 if (set_noreorder
== 0)
5391 error ("internal error: %%) found without a %%( in assembler pattern");
5393 else if (--set_noreorder
== 0)
5394 fputs ("\n\t.set\treorder", file
);
5399 if (set_noat
++ == 0)
5400 fputs (".set\tnoat\n\t", file
);
5405 error ("internal error: %%] found without a %%[ in assembler pattern");
5406 else if (--set_noat
== 0)
5407 fputs ("\n\t.set\tat", file
);
5412 if (set_nomacro
++ == 0)
5413 fputs (".set\tnomacro\n\t", file
);
5417 if (set_nomacro
== 0)
5418 error ("internal error: %%> found without a %%< in assembler pattern");
5419 else if (--set_nomacro
== 0)
5420 fputs ("\n\t.set\tmacro", file
);
5425 if (set_volatile
++ == 0)
5426 fprintf (file
, "%s.set\tvolatile\n\t", TARGET_MIPS_AS
? "" : "#");
5430 if (set_volatile
== 0)
5431 error ("internal error: %%} found without a %%{ in assembler pattern");
5432 else if (--set_volatile
== 0)
5433 fprintf (file
, "\n\t%s.set\tnovolatile", (TARGET_MIPS_AS
) ? "" : "#");
5439 if (align_labels_log
> 0)
5440 ASM_OUTPUT_ALIGN (file
, align_labels_log
);
5445 error ("PRINT_OPERAND: Unknown punctuation '%c'", letter
);
5454 error ("PRINT_OPERAND null pointer");
5458 code
= GET_CODE (op
);
5460 if (code
== SIGN_EXTEND
)
5461 op
= XEXP (op
, 0), code
= GET_CODE (op
);
5466 case EQ
: fputs ("eq", file
); break;
5467 case NE
: fputs ("ne", file
); break;
5468 case GT
: fputs ("gt", file
); break;
5469 case GE
: fputs ("ge", file
); break;
5470 case LT
: fputs ("lt", file
); break;
5471 case LE
: fputs ("le", file
); break;
5472 case GTU
: fputs ("gtu", file
); break;
5473 case GEU
: fputs ("geu", file
); break;
5474 case LTU
: fputs ("ltu", file
); break;
5475 case LEU
: fputs ("leu", file
); break;
5477 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%C");
5480 else if (letter
== 'N')
5483 case EQ
: fputs ("ne", file
); break;
5484 case NE
: fputs ("eq", file
); break;
5485 case GT
: fputs ("le", file
); break;
5486 case GE
: fputs ("lt", file
); break;
5487 case LT
: fputs ("ge", file
); break;
5488 case LE
: fputs ("gt", file
); break;
5489 case GTU
: fputs ("leu", file
); break;
5490 case GEU
: fputs ("ltu", file
); break;
5491 case LTU
: fputs ("geu", file
); break;
5492 case LEU
: fputs ("gtu", file
); break;
5494 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%N");
5497 else if (letter
== 'F')
5500 case EQ
: fputs ("c1f", file
); break;
5501 case NE
: fputs ("c1t", file
); break;
5503 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%F");
5506 else if (letter
== 'W')
5509 case EQ
: fputs ("c1t", file
); break;
5510 case NE
: fputs ("c1f", file
); break;
5512 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%W");
5515 else if (letter
== 'S')
5519 ASM_GENERATE_INTERNAL_LABEL (buffer
, "LS", CODE_LABEL_NUMBER (op
));
5520 assemble_name (file
, buffer
);
5523 else if (letter
== 'Z')
5525 register int regnum
;
5530 regnum
= REGNO (op
);
5531 if (! ST_REG_P (regnum
))
5534 if (regnum
!= ST_REG_FIRST
)
5535 fprintf (file
, "%s,", reg_names
[regnum
]);
5538 else if (code
== REG
|| code
== SUBREG
)
5540 register int regnum
;
5543 regnum
= REGNO (op
);
5545 regnum
= true_regnum (op
);
5547 if ((letter
== 'M' && ! WORDS_BIG_ENDIAN
)
5548 || (letter
== 'L' && WORDS_BIG_ENDIAN
)
5552 fprintf (file
, "%s", reg_names
[regnum
]);
5555 else if (code
== MEM
)
5556 output_address (XEXP (op
, 0));
5558 else if (code
== CONST_DOUBLE
5559 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_FLOAT
)
5564 REAL_VALUE_FROM_CONST_DOUBLE (d
, op
);
5565 REAL_VALUE_TO_DECIMAL (d
, "%.20e", s
);
5569 else if (letter
== 'x' && GET_CODE (op
) == CONST_INT
)
5570 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, 0xffff & INTVAL(op
));
5572 else if (letter
== 'X' && GET_CODE(op
) == CONST_INT
)
5573 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (op
));
5575 else if (letter
== 'd' && GET_CODE(op
) == CONST_INT
)
5576 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, (INTVAL(op
)));
5578 else if (letter
== 'z' && GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 0)
5579 fputs (reg_names
[GP_REG_FIRST
], file
);
5581 else if (letter
== 'd' || letter
== 'x' || letter
== 'X')
5582 output_operand_lossage ("invalid use of %%d, %%x, or %%X");
5584 else if (letter
== 'B')
5585 fputs (code
== EQ
? "z" : "n", file
);
5586 else if (letter
== 'b')
5587 fputs (code
== EQ
? "n" : "z", file
);
5588 else if (letter
== 'T')
5589 fputs (code
== EQ
? "f" : "t", file
);
5590 else if (letter
== 't')
5591 fputs (code
== EQ
? "t" : "f", file
);
5593 else if (code
== CONST
&& GET_CODE (XEXP (op
, 0)) == REG
)
5595 /* This case arises on the mips16; see mips16_gp_pseudo_reg. */
5596 print_operand (file
, XEXP (op
, 0), letter
);
5599 else if (TARGET_MIPS16
&& code
== CONST
&& mips16_gp_offset_p (op
))
5601 fputs ("%gprel(", file
);
5602 mips16_output_gp_offset (file
, op
);
5607 output_addr_const (file
, op
);
5610 /* A C compound statement to output to stdio stream STREAM the
5611 assembler syntax for an instruction operand that is a memory
5612 reference whose address is ADDR. ADDR is an RTL expression.
5614 On some machines, the syntax for a symbolic address depends on
5615 the section that the address refers to. On these machines,
5616 define the macro `ENCODE_SECTION_INFO' to store the information
5617 into the `symbol_ref', and then check for it here. */
5620 print_operand_address (file
, addr
)
5625 error ("PRINT_OPERAND_ADDRESS, null pointer");
5628 switch (GET_CODE (addr
))
5631 if (! TARGET_MIPS16
&& REGNO (addr
) == ARG_POINTER_REGNUM
)
5632 abort_with_insn (addr
, "Arg pointer not eliminated.");
5634 fprintf (file
, "0(%s)", reg_names
[REGNO (addr
)]);
5639 register rtx arg0
= XEXP (addr
, 0);
5640 register rtx arg1
= XEXP (addr
, 1);
5642 if (! mips_split_addresses
)
5643 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, Spurious LO_SUM.");
5645 if (GET_CODE (arg0
) != REG
)
5646 abort_with_insn (addr
,
5647 "PRINT_OPERAND_ADDRESS, LO_SUM with #1 not REG.");
5649 fprintf (file
, "%%lo(");
5650 print_operand_address (file
, arg1
);
5651 fprintf (file
, ")(%s)", reg_names
[REGNO (arg0
)]);
5657 register rtx reg
= 0;
5658 register rtx offset
= 0;
5659 register rtx arg0
= XEXP (addr
, 0);
5660 register rtx arg1
= XEXP (addr
, 1);
5662 if (GET_CODE (arg0
) == REG
)
5666 if (GET_CODE (offset
) == REG
)
5667 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, 2 regs");
5670 else if (GET_CODE (arg1
) == REG
)
5671 reg
= arg1
, offset
= arg0
;
5672 else if (CONSTANT_P (arg0
) && CONSTANT_P (arg1
))
5674 output_addr_const (file
, addr
);
5678 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, no regs");
5680 if (! CONSTANT_P (offset
))
5681 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #2");
5683 if (REGNO (reg
) == ARG_POINTER_REGNUM
)
5684 abort_with_insn (addr
, "Arg pointer not eliminated.");
5687 && GET_CODE (offset
) == CONST
5688 && mips16_gp_offset_p (offset
))
5690 fputs ("%gprel(", file
);
5691 mips16_output_gp_offset (file
, offset
);
5695 output_addr_const (file
, offset
);
5696 fprintf (file
, "(%s)", reg_names
[REGNO (reg
)]);
5704 output_addr_const (file
, addr
);
5708 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #1");
5714 /* If optimizing for the global pointer, keep track of all of the externs, so
5715 that at the end of the file, we can emit the appropriate .extern
5716 declaration for them, before writing out the text section. We assume all
5717 names passed to us are in the permanent obstack, so they will be valid at
5718 the end of the compilation.
5720 If we have -G 0, or the extern size is unknown, or the object is in a user
5721 specified section that is not .sbss/.sdata, don't bother emitting the
5722 .externs. In the case of user specified sections this behaviour is
5723 required as otherwise GAS will think the object lives in .sbss/.sdata. */
5726 mips_output_external (file
, decl
, name
)
5727 FILE *file ATTRIBUTE_UNUSED
;
5731 register struct extern_list
*p
;
5736 && TREE_CODE (decl
) != FUNCTION_DECL
5737 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
5738 && ((section_name
= DECL_SECTION_NAME (decl
)) == NULL
5739 || strcmp (TREE_STRING_POINTER (section_name
), ".sbss") == 0
5740 || strcmp (TREE_STRING_POINTER (section_name
), ".sdata") == 0))
5742 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
5743 p
->next
= extern_head
;
5749 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
5750 if (TREE_CODE (decl
) == FUNCTION_DECL
5751 /* ??? Don't include alloca, since gcc will always expand it
5752 inline. If we don't do this, the C++ library fails to build. */
5753 && strcmp (name
, "alloca")
5754 /* ??? Don't include __builtin_next_arg, because then gcc will not
5755 bootstrap under Irix 5.1. */
5756 && strcmp (name
, "__builtin_next_arg"))
5758 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
5759 p
->next
= extern_head
;
5769 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
5771 mips_output_external_libcall (file
, name
)
5775 register struct extern_list
*p
;
5777 p
= (struct extern_list
*) permalloc (sizeof (struct extern_list
));
5778 p
->next
= extern_head
;
5787 /* Compute a string to use as a temporary file name. */
5790 mips_make_temp_file ()
5794 temp_filename
= make_temp_file (0);
5795 stream
= fopen (temp_filename
, "w+");
5797 fatal_io_error ("can't open %s", temp_filename
);
5801 /* Emit a new filename to a stream. If this is MIPS ECOFF, watch out
5802 for .file's that start within a function. If we are smuggling stabs, try to
5803 put out a MIPS ECOFF file and a stab. */
5806 mips_output_filename (stream
, name
)
5810 static int first_time
= 1;
5811 char ltext_label_name
[100];
5817 current_function_file
= name
;
5818 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
5819 /* This tells mips-tfile that stabs will follow. */
5820 if (!TARGET_GAS
&& write_symbols
== DBX_DEBUG
)
5821 fprintf (stream
, "\t#@stabs\n");
5824 else if (write_symbols
== DBX_DEBUG
)
5826 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name
, "Ltext", 0);
5827 fprintf (stream
, "%s", ASM_STABS_OP
);
5828 output_quoted_string (stream
, name
);
5829 fprintf (stream
, ",%d,0,0,%s\n", N_SOL
, <ext_label_name
[1]);
5832 else if (name
!= current_function_file
5833 && strcmp (name
, current_function_file
) != 0)
5835 if (inside_function
&& !TARGET_GAS
)
5837 if (!file_in_function_warning
)
5839 file_in_function_warning
= 1;
5840 ignore_line_number
= 1;
5841 warning ("MIPS ECOFF format does not allow changing filenames within functions with #line");
5847 current_function_file
= name
;
5848 ASM_OUTPUT_FILENAME (stream
, num_source_filenames
, name
);
5853 /* Emit a linenumber. For encapsulated stabs, we need to put out a stab
5854 as well as a .loc, since it is possible that MIPS ECOFF might not be
5855 able to represent the location for inlines that come from a different
5859 mips_output_lineno (stream
, line
)
5863 if (write_symbols
== DBX_DEBUG
)
5866 fprintf (stream
, "%sLM%d:\n%s%d,0,%d,%sLM%d\n",
5867 LOCAL_LABEL_PREFIX
, sym_lineno
, ASM_STABN_OP
, N_SLINE
, line
,
5868 LOCAL_LABEL_PREFIX
, sym_lineno
);
5873 fprintf (stream
, "\n\t%s.loc\t%d %d\n",
5874 (ignore_line_number
) ? "#" : "",
5875 num_source_filenames
, line
);
5877 LABEL_AFTER_LOC (stream
);
5881 /* Output an ASCII string, in a space-saving way. */
5884 mips_output_ascii (stream
, string_param
, len
)
5886 const char *string_param
;
5891 register const unsigned char *string
=
5892 (const unsigned char *)string_param
;
5894 fprintf (stream
, "\t.ascii\t\"");
5895 for (i
= 0; i
< len
; i
++)
5897 register int c
= string
[i
];
5903 putc ('\\', stream
);
5908 case TARGET_NEWLINE
:
5909 fputs ("\\n", stream
);
5911 && (((c
= string
[i
+1]) >= '\040' && c
<= '~')
5912 || c
== TARGET_TAB
))
5913 cur_pos
= 32767; /* break right here */
5919 fputs ("\\t", stream
);
5924 fputs ("\\f", stream
);
5929 fputs ("\\b", stream
);
5934 fputs ("\\r", stream
);
5939 if (c
>= ' ' && c
< 0177)
5946 fprintf (stream
, "\\%03o", c
);
5951 if (cur_pos
> 72 && i
+1 < len
)
5954 fprintf (stream
, "\"\n\t.ascii\t\"");
5957 fprintf (stream
, "\"\n");
5960 /* If defined, a C statement to be executed just prior to the output of
5961 assembler code for INSN, to modify the extracted operands so they will be
5964 Here the argument OPVEC is the vector containing the operands extracted
5965 from INSN, and NOPERANDS is the number of elements of the vector which
5966 contain meaningful data for this insn. The contents of this vector are
5967 what will be used to convert the insn template into assembler code, so you
5968 can change the assembler output by changing the contents of the vector.
5970 We use it to check if the current insn needs a nop in front of it because
5971 of load delays, and also to update the delay slot statistics. */
5973 /* ??? There is no real need for this function, because it never actually
5974 emits a NOP anymore. */
5977 final_prescan_insn (insn
, opvec
, noperands
)
5979 rtx opvec
[] ATTRIBUTE_UNUSED
;
5980 int noperands ATTRIBUTE_UNUSED
;
5982 if (dslots_number_nops
> 0)
5984 rtx pattern
= PATTERN (insn
);
5985 int length
= get_attr_length (insn
);
5987 /* Do we need to emit a NOP? */
5989 || (mips_load_reg
!= 0 && reg_mentioned_p (mips_load_reg
, pattern
))
5990 || (mips_load_reg2
!= 0 && reg_mentioned_p (mips_load_reg2
, pattern
))
5991 || (mips_load_reg3
!= 0 && reg_mentioned_p (mips_load_reg3
, pattern
))
5992 || (mips_load_reg4
!= 0
5993 && reg_mentioned_p (mips_load_reg4
, pattern
)))
5994 fputs ("\t#nop\n", asm_out_file
);
5997 dslots_load_filled
++;
5999 while (--dslots_number_nops
> 0)
6000 fputs ("\t#nop\n", asm_out_file
);
6009 && (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == CALL_INSN
))
6010 dslots_jump_total
++;
6013 /* Output at beginning of assembler file.
6015 If we are optimizing to use the global pointer, create a temporary file to
6016 hold all of the text stuff, and write it out to the end. This is needed
6017 because the MIPS assembler is evidently one pass, and if it hasn't seen the
6018 relevant .comm/.lcomm/.extern/.sdata declaration when the code is
6019 processed, it generates a two instruction sequence. */
6022 mips_asm_file_start (stream
)
6025 ASM_OUTPUT_SOURCE_FILENAME (stream
, main_input_filename
);
6027 /* Versions of the MIPS assembler before 2.20 generate errors if a branch
6028 inside of a .set noreorder section jumps to a label outside of the .set
6029 noreorder section. Revision 2.20 just set nobopt silently rather than
6032 if (TARGET_MIPS_AS
&& optimize
&& flag_delayed_branch
)
6033 fprintf (stream
, "\t.set\tnobopt\n");
6035 /* Generate the pseudo ops that System V.4 wants. */
6036 #ifndef ABICALLS_ASM_OP
6037 #define ABICALLS_ASM_OP "\t.abicalls"
6039 if (TARGET_ABICALLS
)
6040 /* ??? but do not want this (or want pic0) if -non-shared? */
6041 fprintf (stream
, "%s\n", ABICALLS_ASM_OP
);
6044 fprintf (stream
, "\t.set\tmips16\n");
6046 /* Start a section, so that the first .popsection directive is guaranteed
6047 to have a previously defined section to pop back to. */
6048 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
&& mips_abi
!= ABI_EABI
)
6049 fprintf (stream
, "\t.section\t.text\n");
6051 /* This code exists so that we can put all externs before all symbol
6052 references. This is necessary for the MIPS assembler's global pointer
6053 optimizations to work. */
6054 if (TARGET_FILE_SWITCHING
&& ! TARGET_MIPS16
)
6056 asm_out_data_file
= stream
;
6057 asm_out_text_file
= mips_make_temp_file ();
6061 asm_out_data_file
= asm_out_text_file
= stream
;
6063 if (flag_verbose_asm
)
6064 fprintf (stream
, "\n%s -G value = %d, Arch = %s, ISA = %d\n",
6066 mips_section_threshold
, mips_arch_string
, mips_isa
);
6069 /* If we are optimizing the global pointer, emit the text section now and any
6070 small externs which did not have .comm, etc that are needed. Also, give a
6071 warning if the data area is more than 32K and -pic because 3 instructions
6072 are needed to reference the data pointers. */
6075 mips_asm_file_end (file
)
6080 struct extern_list
*p
;
6085 HALF_PIC_FINISH (file
);
6092 for (p
= extern_head
; p
!= 0; p
= p
->next
)
6094 name_tree
= get_identifier (p
->name
);
6096 /* Positively ensure only one .extern for any given symbol. */
6097 if (! TREE_ASM_WRITTEN (name_tree
))
6099 TREE_ASM_WRITTEN (name_tree
) = 1;
6100 #ifdef ASM_OUTPUT_UNDEF_FUNCTION
6102 ASM_OUTPUT_UNDEF_FUNCTION (file
, p
->name
);
6106 fputs ("\t.extern\t", file
);
6107 assemble_name (file
, p
->name
);
6108 fprintf (file
, ", %d\n", p
->size
);
6114 if (TARGET_FILE_SWITCHING
&& ! TARGET_MIPS16
)
6116 fprintf (file
, "\n\t.text\n");
6117 rewind (asm_out_text_file
);
6118 if (ferror (asm_out_text_file
))
6119 fatal_io_error ("can't rewind %s", temp_filename
);
6121 while ((len
= fread (buffer
, 1, sizeof (buffer
), asm_out_text_file
)) > 0)
6122 if ((int) fwrite (buffer
, 1, len
, file
) != len
)
6123 fatal_io_error ("can't write to %s", asm_file_name
);
6126 fatal_io_error ("can't read from %s", temp_filename
);
6128 if (fclose (asm_out_text_file
) != 0)
6129 fatal_io_error ("can't close %s", temp_filename
);
6131 unlink (temp_filename
);
6132 free (temp_filename
);
6136 /* Emit either a label, .comm, or .lcomm directive, and mark that the symbol
6137 is used, so that we don't emit an .extern for it in mips_asm_file_end. */
6140 mips_declare_object (stream
, name
, init_string
, final_string
, size
)
6143 const char *init_string
;
6144 const char *final_string
;
6147 fputs (init_string
, stream
); /* "", "\t.comm\t", or "\t.lcomm\t" */
6148 assemble_name (stream
, name
);
6149 fprintf (stream
, final_string
, size
); /* ":\n", ",%u\n", ",%u\n" */
6153 tree name_tree
= get_identifier (name
);
6154 TREE_ASM_WRITTEN (name_tree
) = 1;
6158 /* Output a double precision value to the assembler. If both the
6159 host and target are IEEE, emit the values in hex. */
6162 mips_output_double (stream
, value
)
6164 REAL_VALUE_TYPE value
;
6166 #ifdef REAL_VALUE_TO_TARGET_DOUBLE
6168 REAL_VALUE_TO_TARGET_DOUBLE (value
, value_long
);
6170 fprintf (stream
, "\t.word\t0x%08lx\t\t# %.20g\n\t.word\t0x%08lx\n",
6171 value_long
[0], value
, value_long
[1]);
6173 fprintf (stream
, "\t.double\t%.20g\n", value
);
6177 /* Output a single precision value to the assembler. If both the
6178 host and target are IEEE, emit the values in hex. */
6181 mips_output_float (stream
, value
)
6183 REAL_VALUE_TYPE value
;
6185 #ifdef REAL_VALUE_TO_TARGET_SINGLE
6187 REAL_VALUE_TO_TARGET_SINGLE (value
, value_long
);
6189 fprintf (stream
, "\t.word\t0x%08lx\t\t# %.12g (float)\n", value_long
, value
);
6191 fprintf (stream
, "\t.float\t%.12g\n", value
);
6195 /* Return the bytes needed to compute the frame pointer from the current
6198 Mips stack frames look like:
6200 Before call After call
6201 +-----------------------+ +-----------------------+
6204 | caller's temps. | | caller's temps. |
6206 +-----------------------+ +-----------------------+
6208 | arguments on stack. | | arguments on stack. |
6210 +-----------------------+ +-----------------------+
6211 | 4 words to save | | 4 words to save |
6212 | arguments passed | | arguments passed |
6213 | in registers, even | | in registers, even |
6214 SP->| if not passed. | VFP->| if not passed. |
6215 +-----------------------+ +-----------------------+
6217 | fp register save |
6219 +-----------------------+
6221 | gp register save |
6223 +-----------------------+
6227 +-----------------------+
6229 | alloca allocations |
6231 +-----------------------+
6233 | GP save for V.4 abi |
6235 +-----------------------+
6237 | arguments on stack |
6239 +-----------------------+
6241 | arguments passed |
6242 | in registers, even |
6243 low SP->| if not passed. |
6244 memory +-----------------------+
6249 compute_frame_size (size
)
6250 HOST_WIDE_INT size
; /* # of var. bytes allocated */
6253 HOST_WIDE_INT total_size
; /* # bytes that the entire frame takes up */
6254 HOST_WIDE_INT var_size
; /* # bytes that variables take up */
6255 HOST_WIDE_INT args_size
; /* # bytes that outgoing arguments take up */
6256 HOST_WIDE_INT extra_size
; /* # extra bytes */
6257 HOST_WIDE_INT gp_reg_rounded
; /* # bytes needed to store gp after rounding */
6258 HOST_WIDE_INT gp_reg_size
; /* # bytes needed to store gp regs */
6259 HOST_WIDE_INT fp_reg_size
; /* # bytes needed to store fp regs */
6260 long mask
; /* mask of saved gp registers */
6261 long fmask
; /* mask of saved fp registers */
6262 int fp_inc
; /* 1 or 2 depending on the size of fp regs */
6263 long fp_bits
; /* bitmask to use for each fp register */
6269 extra_size
= MIPS_STACK_ALIGN (((TARGET_ABICALLS
) ? UNITS_PER_WORD
: 0));
6270 var_size
= MIPS_STACK_ALIGN (size
);
6271 args_size
= MIPS_STACK_ALIGN (current_function_outgoing_args_size
);
6273 /* The MIPS 3.0 linker does not like functions that dynamically
6274 allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it
6275 looks like we are trying to create a second frame pointer to the
6276 function, so allocate some stack space to make it happy. */
6278 if (args_size
== 0 && current_function_calls_alloca
)
6279 args_size
= 4 * UNITS_PER_WORD
;
6281 total_size
= var_size
+ args_size
+ extra_size
;
6283 /* Calculate space needed for gp registers. */
6284 for (regno
= GP_REG_FIRST
; regno
<= GP_REG_LAST
; regno
++)
6286 /* $18 is a special case on the mips16. It may be used to call
6287 a function which returns a floating point value, but it is
6288 marked in call_used_regs. $31 is also a special case. When
6289 not using -mentry, it will be used to copy a return value
6290 into the floating point registers if the return value is
6292 if (MUST_SAVE_REGISTER (regno
)
6294 && regno
== GP_REG_FIRST
+ 18
6295 && regs_ever_live
[regno
])
6297 && regno
== GP_REG_FIRST
+ 31
6298 && mips16_hard_float
6300 && ! aggregate_value_p (DECL_RESULT (current_function_decl
))
6301 && (GET_MODE_CLASS (DECL_MODE (DECL_RESULT (current_function_decl
)))
6303 && (! TARGET_SINGLE_FLOAT
6304 || (GET_MODE_SIZE (DECL_MODE (DECL_RESULT (current_function_decl
)))
6307 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6308 mask
|= 1L << (regno
- GP_REG_FIRST
);
6310 /* The entry and exit pseudo instructions can not save $17
6311 without also saving $16. */
6313 && regno
== GP_REG_FIRST
+ 17
6314 && ! MUST_SAVE_REGISTER (GP_REG_FIRST
+ 16))
6316 gp_reg_size
+= UNITS_PER_WORD
;
6322 /* We need to restore these for the handler. */
6323 if (current_function_calls_eh_return
)
6328 regno
= EH_RETURN_DATA_REGNO (i
);
6329 if (regno
== INVALID_REGNUM
)
6331 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
6332 mask
|= 1L << (regno
- GP_REG_FIRST
);
6336 /* Calculate space needed for fp registers. */
6337 if (TARGET_FLOAT64
|| TARGET_SINGLE_FLOAT
)
6348 /* This loop must iterate over the same space as its companion in
6349 save_restore_regs. */
6350 for (regno
= (FP_REG_LAST
- fp_inc
+ 1);
6351 regno
>= FP_REG_FIRST
;
6354 if (regs_ever_live
[regno
] && !call_used_regs
[regno
])
6356 fp_reg_size
+= fp_inc
* UNITS_PER_FPREG
;
6357 fmask
|= fp_bits
<< (regno
- FP_REG_FIRST
);
6361 gp_reg_rounded
= MIPS_STACK_ALIGN (gp_reg_size
);
6362 total_size
+= gp_reg_rounded
+ MIPS_STACK_ALIGN (fp_reg_size
);
6364 /* The gp reg is caller saved in the 32 bit ABI, so there is no need
6365 for leaf routines (total_size == extra_size) to save the gp reg.
6366 The gp reg is callee saved in the 64 bit ABI, so all routines must
6367 save the gp reg. This is not a leaf routine if -p, because of the
6369 if (total_size
== extra_size
6370 && (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
|| mips_abi
== ABI_EABI
)
6372 total_size
= extra_size
= 0;
6373 else if (TARGET_ABICALLS
)
6375 /* Add the context-pointer to the saved registers. */
6376 gp_reg_size
+= UNITS_PER_WORD
;
6377 mask
|= 1L << (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
);
6378 total_size
-= gp_reg_rounded
;
6379 gp_reg_rounded
= MIPS_STACK_ALIGN (gp_reg_size
);
6380 total_size
+= gp_reg_rounded
;
6383 /* Add in space reserved on the stack by the callee for storing arguments
6384 passed in registers. */
6385 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
6386 total_size
+= MIPS_STACK_ALIGN (current_function_pretend_args_size
);
6388 /* The entry pseudo instruction will allocate 32 bytes on the stack. */
6389 if (mips_entry
&& total_size
> 0 && total_size
< 32)
6392 /* Save other computed information. */
6393 current_frame_info
.total_size
= total_size
;
6394 current_frame_info
.var_size
= var_size
;
6395 current_frame_info
.args_size
= args_size
;
6396 current_frame_info
.extra_size
= extra_size
;
6397 current_frame_info
.gp_reg_size
= gp_reg_size
;
6398 current_frame_info
.fp_reg_size
= fp_reg_size
;
6399 current_frame_info
.mask
= mask
;
6400 current_frame_info
.fmask
= fmask
;
6401 current_frame_info
.initialized
= reload_completed
;
6402 current_frame_info
.num_gp
= gp_reg_size
/ UNITS_PER_WORD
;
6403 current_frame_info
.num_fp
= fp_reg_size
/ (fp_inc
* UNITS_PER_FPREG
);
6407 unsigned long offset
;
6409 /* When using mips_entry, the registers are always saved at the
6410 top of the stack. */
6412 offset
= (args_size
+ extra_size
+ var_size
6413 + gp_reg_size
- GET_MODE_SIZE (gpr_mode
));
6415 offset
= total_size
- GET_MODE_SIZE (gpr_mode
);
6417 current_frame_info
.gp_sp_offset
= offset
;
6418 current_frame_info
.gp_save_offset
= offset
- total_size
;
6422 current_frame_info
.gp_sp_offset
= 0;
6423 current_frame_info
.gp_save_offset
= 0;
6428 unsigned long offset
= (args_size
+ extra_size
+ var_size
6429 + gp_reg_rounded
+ fp_reg_size
6430 - fp_inc
* UNITS_PER_FPREG
);
6431 current_frame_info
.fp_sp_offset
= offset
;
6432 current_frame_info
.fp_save_offset
= offset
- total_size
;
6436 current_frame_info
.fp_sp_offset
= 0;
6437 current_frame_info
.fp_save_offset
= 0;
6440 /* Ok, we're done. */
6444 /* Common code to emit the insns (or to write the instructions to a file)
6445 to save/restore registers.
6447 Other parts of the code assume that MIPS_TEMP1_REGNUM (aka large_reg)
6448 is not modified within save_restore_insns. */
6450 #define BITSET_P(VALUE,BIT) (((VALUE) & (1L << (BIT))) != 0)
6453 save_restore_insns (store_p
, large_reg
, large_offset
, file
)
6454 int store_p
; /* true if this is prologue */
6455 rtx large_reg
; /* register holding large offset constant or NULL */
6456 long large_offset
; /* large constant offset value */
6457 FILE *file
; /* file to write instructions instead of making RTL */
6459 long mask
= current_frame_info
.mask
;
6460 long fmask
= current_frame_info
.fmask
;
6463 HOST_WIDE_INT base_offset
;
6464 HOST_WIDE_INT gp_offset
;
6465 HOST_WIDE_INT fp_offset
;
6466 HOST_WIDE_INT end_offset
;
6469 if (frame_pointer_needed
6470 && ! BITSET_P (mask
, HARD_FRAME_POINTER_REGNUM
- GP_REG_FIRST
))
6473 if (mask
== 0 && fmask
== 0)
6476 /* Save registers starting from high to low. The debuggers prefer at least
6477 the return register be stored at func+4, and also it allows us not to
6478 need a nop in the epilog if at least one register is reloaded in
6479 addition to return address. */
6481 /* Save GP registers if needed. */
6484 /* Pick which pointer to use as a base register. For small frames, just
6485 use the stack pointer. Otherwise, use a temporary register. Save 2
6486 cycles if the save area is near the end of a large frame, by reusing
6487 the constant created in the prologue/epilogue to adjust the stack
6490 gp_offset
= current_frame_info
.gp_sp_offset
;
6492 = gp_offset
- (current_frame_info
.gp_reg_size
6493 - GET_MODE_SIZE (gpr_mode
));
6495 if (gp_offset
< 0 || end_offset
< 0)
6497 ("gp_offset (%ld) or end_offset (%ld) is less than zero.",
6498 (long) gp_offset
, (long) end_offset
);
6500 /* If we see a large frame in mips16 mode, we save the registers
6501 before adjusting the stack pointer, and load them afterward. */
6502 else if (TARGET_MIPS16
&& large_offset
> 32767)
6503 base_reg_rtx
= stack_pointer_rtx
, base_offset
= large_offset
;
6505 else if (gp_offset
< 32768)
6506 base_reg_rtx
= stack_pointer_rtx
, base_offset
= 0;
6508 else if (large_reg
!= 0
6509 && (unsigned HOST_WIDE_INT
) (large_offset
- gp_offset
) < 32768
6510 && (unsigned HOST_WIDE_INT
) (large_offset
- end_offset
) < 32768)
6512 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6513 base_offset
= large_offset
;
6516 if (Pmode
== DImode
)
6517 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, large_reg
,
6518 stack_pointer_rtx
));
6520 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, large_reg
,
6521 stack_pointer_rtx
));
6523 RTX_FRAME_RELATED_P (insn
) = 1;
6526 fprintf (file
, "\t%s\t%s,%s,%s\n",
6527 Pmode
== DImode
? "daddu" : "addu",
6528 reg_names
[MIPS_TEMP2_REGNUM
],
6529 reg_names
[REGNO (large_reg
)],
6530 reg_names
[STACK_POINTER_REGNUM
]);
6535 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6536 base_offset
= gp_offset
;
6539 rtx gp_offset_rtx
= GEN_INT (gp_offset
);
6541 /* Instruction splitting doesn't preserve the RTX_FRAME_RELATED_P
6542 bit, so make sure that we don't emit anything that can be
6544 /* ??? There is no DImode ori immediate pattern, so we can only
6545 do this for 32 bit code. */
6546 if (large_int (gp_offset_rtx
, GET_MODE (gp_offset_rtx
))
6547 && GET_MODE (base_reg_rtx
) == SImode
)
6549 insn
= emit_move_insn (base_reg_rtx
,
6550 GEN_INT (gp_offset
& BITMASK_UPPER16
));
6552 RTX_FRAME_RELATED_P (insn
) = 1;
6554 = emit_insn (gen_iorsi3 (base_reg_rtx
, base_reg_rtx
,
6556 & BITMASK_LOWER16
)));
6558 RTX_FRAME_RELATED_P (insn
) = 1;
6562 insn
= emit_move_insn (base_reg_rtx
, gp_offset_rtx
);
6564 RTX_FRAME_RELATED_P (insn
) = 1;
6567 if (Pmode
== DImode
)
6568 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, base_reg_rtx
,
6569 stack_pointer_rtx
));
6571 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, base_reg_rtx
,
6572 stack_pointer_rtx
));
6574 RTX_FRAME_RELATED_P (insn
) = 1;
6578 fprintf (file
, "\tli\t%s,0x%.08lx\t# ",
6579 reg_names
[MIPS_TEMP2_REGNUM
], (long) base_offset
);
6580 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, base_offset
);
6581 fprintf (file
, "\n\t%s\t%s,%s,%s\n",
6582 Pmode
== DImode
? "daddu" : "addu",
6583 reg_names
[MIPS_TEMP2_REGNUM
],
6584 reg_names
[MIPS_TEMP2_REGNUM
],
6585 reg_names
[STACK_POINTER_REGNUM
]);
6589 /* When we restore the registers in MIPS16 mode, then if we are
6590 using a frame pointer, and this is not a large frame, the
6591 current stack pointer will be offset by
6592 current_function_outgoing_args_size. Doing it this way lets
6593 us avoid offsetting the frame pointer before copying it into
6594 the stack pointer; there is no instruction to set the stack
6595 pointer to the sum of a register and a constant. */
6598 && frame_pointer_needed
6599 && large_offset
<= 32767)
6600 base_offset
+= current_function_outgoing_args_size
;
6602 for (regno
= GP_REG_LAST
; regno
>= GP_REG_FIRST
; regno
--)
6603 if (BITSET_P (mask
, regno
- GP_REG_FIRST
))
6609 = gen_rtx (MEM
, gpr_mode
,
6610 gen_rtx (PLUS
, Pmode
, base_reg_rtx
,
6611 GEN_INT (gp_offset
- base_offset
)));
6613 RTX_UNCHANGING_P (mem_rtx
) = 1;
6615 /* The mips16 does not have an instruction to load
6616 $31, so we load $7 instead, and work things out
6618 if (TARGET_MIPS16
&& ! store_p
&& regno
== GP_REG_FIRST
+ 31)
6619 reg_rtx
= gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 7);
6620 /* The mips16 sometimes needs to save $18. */
6621 else if (TARGET_MIPS16
6622 && regno
!= GP_REG_FIRST
+ 31
6623 && ! M16_REG_P (regno
))
6626 reg_rtx
= gen_rtx (REG
, gpr_mode
, 6);
6629 reg_rtx
= gen_rtx (REG
, gpr_mode
, 3);
6630 emit_move_insn (reg_rtx
,
6631 gen_rtx (REG
, gpr_mode
, regno
));
6635 reg_rtx
= gen_rtx (REG
, gpr_mode
, regno
);
6639 insn
= emit_move_insn (mem_rtx
, reg_rtx
);
6640 RTX_FRAME_RELATED_P (insn
) = 1;
6642 else if (!TARGET_ABICALLS
6643 || (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
6644 || regno
!= (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
))
6646 emit_move_insn (reg_rtx
, mem_rtx
);
6648 && regno
!= GP_REG_FIRST
+ 31
6649 && ! M16_REG_P (regno
))
6650 emit_move_insn (gen_rtx (REG
, gpr_mode
, regno
),
6656 if (store_p
|| !TARGET_ABICALLS
6657 || (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
6658 || regno
!= (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
))
6662 /* The mips16 does not have an instruction to
6663 load $31, so we load $7 instead, and work
6664 things out in the caller. */
6665 if (TARGET_MIPS16
&& ! store_p
&& r
== GP_REG_FIRST
+ 31)
6666 r
= GP_REG_FIRST
+ 7;
6667 /* The mips16 sometimes needs to save $18. */
6669 && regno
!= GP_REG_FIRST
+ 31
6670 && ! M16_REG_P (regno
))
6673 r
= GP_REG_FIRST
+ 6;
6676 r
= GP_REG_FIRST
+ 3;
6677 fprintf (file
, "\tmove\t%s,%s\n",
6678 reg_names
[r
], reg_names
[regno
]);
6681 fprintf (file
, "\t%s\t%s,",
6683 ? (store_p
) ? "sd" : "ld"
6684 : (store_p
) ? "sw" : "lw"),
6686 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
6687 gp_offset
- base_offset
);
6688 fprintf (file
, "(%s)\n", reg_names
[REGNO(base_reg_rtx
)]);
6691 && regno
!= GP_REG_FIRST
+ 31
6692 && ! M16_REG_P (regno
))
6693 fprintf (file
, "\tmove\t%s,%s\n",
6694 reg_names
[regno
], reg_names
[r
]);
6698 gp_offset
-= GET_MODE_SIZE (gpr_mode
);
6702 base_reg_rtx
= 0, base_offset
= 0;
6704 /* Save floating point registers if needed. */
6707 int fp_inc
= (TARGET_FLOAT64
|| TARGET_SINGLE_FLOAT
) ? 1 : 2;
6708 int fp_size
= fp_inc
* UNITS_PER_FPREG
;
6710 /* Pick which pointer to use as a base register. */
6711 fp_offset
= current_frame_info
.fp_sp_offset
;
6712 end_offset
= fp_offset
- (current_frame_info
.fp_reg_size
- fp_size
);
6714 if (fp_offset
< 0 || end_offset
< 0)
6716 ("fp_offset (%ld) or end_offset (%ld) is less than zero.",
6717 (long) fp_offset
, (long) end_offset
);
6719 else if (fp_offset
< 32768)
6720 base_reg_rtx
= stack_pointer_rtx
, base_offset
= 0;
6722 else if (base_reg_rtx
!= 0
6723 && (unsigned HOST_WIDE_INT
) (base_offset
- fp_offset
) < 32768
6724 && (unsigned HOST_WIDE_INT
) (base_offset
- end_offset
) < 32768)
6725 ; /* already set up for gp registers above */
6727 else if (large_reg
!= 0
6728 && (unsigned HOST_WIDE_INT
) (large_offset
- fp_offset
) < 32768
6729 && (unsigned HOST_WIDE_INT
) (large_offset
- end_offset
) < 32768)
6731 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6732 base_offset
= large_offset
;
6735 if (Pmode
== DImode
)
6736 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, large_reg
,
6737 stack_pointer_rtx
));
6739 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, large_reg
,
6740 stack_pointer_rtx
));
6742 RTX_FRAME_RELATED_P (insn
) = 1;
6746 fprintf (file
, "\t%s\t%s,%s,%s\n",
6747 Pmode
== DImode
? "daddu" : "addu",
6748 reg_names
[MIPS_TEMP2_REGNUM
],
6749 reg_names
[REGNO (large_reg
)],
6750 reg_names
[STACK_POINTER_REGNUM
]);
6755 base_reg_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP2_REGNUM
);
6756 base_offset
= fp_offset
;
6759 rtx fp_offset_rtx
= GEN_INT (fp_offset
);
6761 /* Instruction splitting doesn't preserve the RTX_FRAME_RELATED_P
6762 bit, so make sure that we don't emit anything that can be
6764 /* ??? There is no DImode ori immediate pattern, so we can only
6765 do this for 32 bit code. */
6766 if (large_int (fp_offset_rtx
, GET_MODE (fp_offset_rtx
))
6767 && GET_MODE (base_reg_rtx
) == SImode
)
6769 insn
= emit_move_insn (base_reg_rtx
,
6770 GEN_INT (fp_offset
& BITMASK_UPPER16
));
6772 RTX_FRAME_RELATED_P (insn
) = 1;
6773 insn
= emit_insn (gen_iorsi3 (base_reg_rtx
, base_reg_rtx
,
6775 & BITMASK_LOWER16
)));
6777 RTX_FRAME_RELATED_P (insn
) = 1;
6781 insn
= emit_move_insn (base_reg_rtx
, fp_offset_rtx
);
6783 RTX_FRAME_RELATED_P (insn
) = 1;
6787 RTX_FRAME_RELATED_P (insn
) = 1;
6788 if (Pmode
== DImode
)
6789 insn
= emit_insn (gen_adddi3 (base_reg_rtx
, base_reg_rtx
,
6790 stack_pointer_rtx
));
6792 insn
= emit_insn (gen_addsi3 (base_reg_rtx
, base_reg_rtx
,
6793 stack_pointer_rtx
));
6795 RTX_FRAME_RELATED_P (insn
) = 1;
6799 fprintf (file
, "\tli\t%s,0x%.08lx\t# ",
6800 reg_names
[MIPS_TEMP2_REGNUM
], (long) base_offset
);
6801 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, base_offset
);
6802 fprintf (file
, "\n\t%s\t%s,%s,%s\n",
6803 Pmode
== DImode
? "daddu" : "addu",
6804 reg_names
[MIPS_TEMP2_REGNUM
],
6805 reg_names
[MIPS_TEMP2_REGNUM
],
6806 reg_names
[STACK_POINTER_REGNUM
]);
6810 /* This loop must iterate over the same space as its companion in
6811 compute_frame_size. */
6812 for (regno
= (FP_REG_LAST
- fp_inc
+ 1);
6813 regno
>= FP_REG_FIRST
;
6815 if (BITSET_P (fmask
, regno
- FP_REG_FIRST
))
6819 enum machine_mode sz
6820 = TARGET_SINGLE_FLOAT
? SFmode
: DFmode
;
6821 rtx reg_rtx
= gen_rtx (REG
, sz
, regno
);
6822 rtx mem_rtx
= gen_rtx (MEM
, sz
,
6823 gen_rtx (PLUS
, Pmode
, base_reg_rtx
,
6826 RTX_UNCHANGING_P (mem_rtx
) = 1;
6830 insn
= emit_move_insn (mem_rtx
, reg_rtx
);
6831 RTX_FRAME_RELATED_P (insn
) = 1;
6834 emit_move_insn (reg_rtx
, mem_rtx
);
6838 fprintf (file
, "\t%s\t%s,",
6839 (TARGET_SINGLE_FLOAT
6840 ? (store_p
? "s.s" : "l.s")
6841 : (store_p
? "s.d" : "l.d")),
6843 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
,
6844 fp_offset
- base_offset
);
6845 fprintf (file
, "(%s)\n", reg_names
[REGNO(base_reg_rtx
)]);
6848 fp_offset
-= fp_size
;
6853 /* Set up the stack and frame (if desired) for the function. */
6856 mips_output_function_prologue (file
, size
)
6858 HOST_WIDE_INT size ATTRIBUTE_UNUSED
;
6860 #ifndef FUNCTION_NAME_ALREADY_DECLARED
6863 long tsize
= current_frame_info
.total_size
;
6865 ASM_OUTPUT_SOURCE_FILENAME (file
, DECL_SOURCE_FILE (current_function_decl
));
6867 #ifdef SDB_DEBUGGING_INFO
6868 if (debug_info_level
!= DINFO_LEVEL_TERSE
&& write_symbols
== SDB_DEBUG
)
6869 ASM_OUTPUT_SOURCE_LINE (file
, DECL_SOURCE_LINE (current_function_decl
));
6872 /* In mips16 mode, we may need to generate a 32 bit to handle
6873 floating point arguments. The linker will arrange for any 32 bit
6874 functions to call this stub, which will then jump to the 16 bit
6876 if (TARGET_MIPS16
&& !TARGET_SOFT_FLOAT
6877 && current_function_args_info
.fp_code
!= 0)
6878 build_mips16_function_stub (file
);
6880 inside_function
= 1;
6882 #ifndef FUNCTION_NAME_ALREADY_DECLARED
6883 /* Get the function name the same way that toplev.c does before calling
6884 assemble_start_function. This is needed so that the name used here
6885 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
6886 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
6888 if (!flag_inhibit_size_directive
)
6890 fputs ("\t.ent\t", file
);
6891 assemble_name (file
, fnname
);
6895 assemble_name (file
, fnname
);
6896 fputs (":\n", file
);
6899 if (!flag_inhibit_size_directive
)
6901 /* .frame FRAMEREG, FRAMESIZE, RETREG */
6903 "\t.frame\t%s,%ld,%s\t\t# vars= %ld, regs= %d/%d, args= %d, extra= %ld\n",
6904 (reg_names
[(frame_pointer_needed
)
6905 ? HARD_FRAME_POINTER_REGNUM
: STACK_POINTER_REGNUM
]),
6906 ((frame_pointer_needed
&& TARGET_MIPS16
)
6907 ? (tsize
- current_function_outgoing_args_size
)
6909 reg_names
[31 + GP_REG_FIRST
],
6910 current_frame_info
.var_size
,
6911 current_frame_info
.num_gp
,
6912 current_frame_info
.num_fp
,
6913 current_function_outgoing_args_size
,
6914 current_frame_info
.extra_size
);
6916 /* .mask MASK, GPOFFSET; .fmask FPOFFSET */
6917 fprintf (file
, "\t.mask\t0x%08lx,%ld\n\t.fmask\t0x%08lx,%ld\n",
6918 current_frame_info
.mask
,
6919 current_frame_info
.gp_save_offset
,
6920 current_frame_info
.fmask
,
6921 current_frame_info
.fp_save_offset
);
6924 OLD_SP == *FRAMEREG + FRAMESIZE => can find old_sp from nominated FP reg.
6925 HIGHEST_GP_SAVED == *FRAMEREG + FRAMESIZE + GPOFFSET => can find saved regs. */
6928 if (mips_entry
&& ! mips_can_use_return_insn ())
6930 int save16
= BITSET_P (current_frame_info
.mask
, 16);
6931 int save17
= BITSET_P (current_frame_info
.mask
, 17);
6932 int save31
= BITSET_P (current_frame_info
.mask
, 31);
6936 /* Look through the initial insns to see if any of them store
6937 the function parameters into the incoming parameter storage
6938 area. If they do, we delete the insn, and save the register
6939 using the entry pseudo-instruction instead. We don't try to
6940 look past a label, jump, or call. */
6941 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
6943 rtx note
, set
, src
, dest
, base
, offset
;
6946 if (GET_CODE (insn
) == CODE_LABEL
6947 || GET_CODE (insn
) == JUMP_INSN
6948 || GET_CODE (insn
) == CALL_INSN
)
6950 if (GET_CODE (insn
) != INSN
)
6952 set
= PATTERN (insn
);
6953 if (GET_CODE (set
) != SET
)
6956 /* An insn storing a function parameter will still have a
6957 REG_EQUIV note on it mentioning the argument pointer. */
6958 note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
);
6959 if (note
== NULL_RTX
)
6961 if (! reg_mentioned_p (arg_pointer_rtx
, XEXP (note
, 0)))
6964 src
= SET_SRC (set
);
6965 if (GET_CODE (src
) != REG
6966 || REGNO (src
) < GP_REG_FIRST
+ 4
6967 || REGNO (src
) > GP_REG_FIRST
+ 7)
6970 dest
= SET_DEST (set
);
6971 if (GET_CODE (dest
) != MEM
)
6973 if (GET_MODE_SIZE (GET_MODE (dest
)) == (unsigned) UNITS_PER_WORD
)
6975 else if (GET_MODE_SIZE (GET_MODE (dest
)) == (unsigned)2 * UNITS_PER_WORD
6976 && REGNO (src
) < GP_REG_FIRST
+ 7)
6980 offset
= const0_rtx
;
6981 base
= eliminate_constant_term (XEXP (dest
, 0), &offset
);
6982 if (GET_CODE (base
) != REG
6983 || GET_CODE (offset
) != CONST_INT
)
6985 if (REGNO (base
) == (unsigned) STACK_POINTER_REGNUM
6986 && (unsigned HOST_WIDE_INT
) INTVAL (offset
)
6987 == tsize
+ (REGNO (src
) - 4) * UNITS_PER_WORD
)
6989 else if (REGNO (base
) == (unsigned) HARD_FRAME_POINTER_REGNUM
6990 && ((unsigned HOST_WIDE_INT
) INTVAL (offset
)
6992 + (REGNO (src
) - 4) * UNITS_PER_WORD
6993 - current_function_outgoing_args_size
)))
6998 /* This insn stores a parameter onto the stack, in the same
6999 location where the entry pseudo-instruction will put it.
7000 Delete the insn, and arrange to tell the entry
7001 instruction to save the register. */
7002 PUT_CODE (insn
, NOTE
);
7003 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
7004 NOTE_SOURCE_FILE (insn
) = 0;
7006 hireg
= (REGNO (src
)
7007 + HARD_REGNO_NREGS (REGNO (src
), GET_MODE (dest
))
7009 if (hireg
> savearg
)
7013 /* If this is a varargs function, we need to save all the
7014 registers onto the stack anyhow. */
7015 if (current_function_stdarg
|| current_function_varargs
)
7016 savearg
= GP_REG_FIRST
+ 7;
7018 fprintf (file
, "\tentry\t");
7021 if (savearg
== GP_REG_FIRST
+ 4)
7022 fprintf (file
, "%s", reg_names
[savearg
]);
7024 fprintf (file
, "%s-%s", reg_names
[GP_REG_FIRST
+ 4],
7025 reg_names
[savearg
]);
7027 if (save16
|| save17
)
7030 fprintf (file
, ",");
7031 fprintf (file
, "%s", reg_names
[GP_REG_FIRST
+ 16]);
7033 fprintf (file
, "-%s", reg_names
[GP_REG_FIRST
+ 17]);
7037 if (savearg
> 0 || save16
|| save17
)
7038 fprintf (file
, ",");
7039 fprintf (file
, "%s", reg_names
[GP_REG_FIRST
+ 31]);
7041 fprintf (file
, "\n");
7044 if (TARGET_ABICALLS
&& (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
))
7046 const char *const sp_str
= reg_names
[STACK_POINTER_REGNUM
];
7048 fprintf (file
, "\t.set\tnoreorder\n\t.cpload\t%s\n\t.set\treorder\n",
7049 reg_names
[PIC_FUNCTION_ADDR_REGNUM
]);
7052 fprintf (file
, "\t%s\t%s,%s,%ld\n",
7053 (Pmode
== DImode
? "dsubu" : "subu"),
7054 sp_str
, sp_str
, tsize
);
7055 fprintf (file
, "\t.cprestore %ld\n", current_frame_info
.args_size
);
7058 if (dwarf2out_do_frame ())
7059 dwarf2out_def_cfa ("", STACK_POINTER_REGNUM
, tsize
);
7063 /* Expand the prologue into a bunch of separate insns. */
7066 mips_expand_prologue ()
7069 HOST_WIDE_INT tsize
;
7071 int last_arg_is_vararg_marker
= 0;
7072 tree fndecl
= current_function_decl
;
7073 tree fntype
= TREE_TYPE (fndecl
);
7074 tree fnargs
= DECL_ARGUMENTS (fndecl
);
7079 CUMULATIVE_ARGS args_so_far
;
7080 rtx reg_18_save
= NULL_RTX
;
7081 int store_args_on_stack
= (mips_abi
== ABI_32
|| mips_abi
== ABI_O64
)
7082 && (! mips_entry
|| mips_can_use_return_insn ());
7084 /* If struct value address is treated as the first argument, make it so. */
7085 if (aggregate_value_p (DECL_RESULT (fndecl
))
7086 && ! current_function_returns_pcc_struct
7087 && struct_value_incoming_rtx
== 0)
7089 tree type
= build_pointer_type (fntype
);
7090 tree function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
7092 DECL_ARG_TYPE (function_result_decl
) = type
;
7093 TREE_CHAIN (function_result_decl
) = fnargs
;
7094 fnargs
= function_result_decl
;
7097 /* For arguments passed in registers, find the register number
7098 of the first argument in the variable part of the argument list,
7099 otherwise GP_ARG_LAST+1. Note also if the last argument is
7100 the varargs special argument, and treat it as part of the
7103 This is only needed if store_args_on_stack is true. */
7105 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
7106 regno
= GP_ARG_FIRST
;
7108 for (cur_arg
= fnargs
; cur_arg
!= 0; cur_arg
= next_arg
)
7110 tree passed_type
= DECL_ARG_TYPE (cur_arg
);
7111 enum machine_mode passed_mode
= TYPE_MODE (passed_type
);
7114 if (TREE_ADDRESSABLE (passed_type
))
7116 passed_type
= build_pointer_type (passed_type
);
7117 passed_mode
= Pmode
;
7120 entry_parm
= FUNCTION_ARG (args_so_far
, passed_mode
, passed_type
, 1);
7122 FUNCTION_ARG_ADVANCE (args_so_far
, passed_mode
, passed_type
, 1);
7123 next_arg
= TREE_CHAIN (cur_arg
);
7125 if (entry_parm
&& store_args_on_stack
)
7128 && DECL_NAME (cur_arg
)
7129 && ((0 == strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
7130 "__builtin_va_alist"))
7131 || (0 == strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
7134 last_arg_is_vararg_marker
= 1;
7141 if (GET_CODE (entry_parm
) != REG
)
7144 /* passed in a register, so will get homed automatically */
7145 if (GET_MODE (entry_parm
) == BLKmode
)
7146 words
= (int_size_in_bytes (passed_type
) + 3) / 4;
7148 words
= (GET_MODE_SIZE (GET_MODE (entry_parm
)) + 3) / 4;
7150 regno
= REGNO (entry_parm
) + words
- 1;
7155 regno
= GP_ARG_LAST
+1;
7160 /* In order to pass small structures by value in registers compatibly with
7161 the MIPS compiler, we need to shift the value into the high part of the
7162 register. Function_arg has encoded a PARALLEL rtx, holding a vector of
7163 adjustments to be made as the next_arg_reg variable, so we split up the
7164 insns, and emit them separately. */
7166 next_arg_reg
= FUNCTION_ARG (args_so_far
, VOIDmode
, void_type_node
, 1);
7167 if (next_arg_reg
!= 0 && GET_CODE (next_arg_reg
) == PARALLEL
)
7169 rtvec adjust
= XVEC (next_arg_reg
, 0);
7170 int num
= GET_NUM_ELEM (adjust
);
7172 for (i
= 0; i
< num
; i
++)
7176 pattern
= RTVEC_ELT (adjust
, i
);
7177 if (GET_CODE (pattern
) != SET
7178 || GET_CODE (SET_SRC (pattern
)) != ASHIFT
)
7179 abort_with_insn (pattern
, "Insn is not a shift");
7180 PUT_CODE (SET_SRC (pattern
), ASHIFTRT
);
7182 insn
= emit_insn (pattern
);
7184 /* Global life information isn't valid at this point, so we
7185 can't check whether these shifts are actually used. Mark
7186 them MAYBE_DEAD so that flow2 will remove them, and not
7187 complain about dead code in the prologue. */
7188 REG_NOTES(insn
) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD
, NULL_RTX
,
7193 tsize
= compute_frame_size (get_frame_size ());
7195 /* If this function is a varargs function, store any registers that
7196 would normally hold arguments ($4 - $7) on the stack. */
7197 if (store_args_on_stack
7198 && ((TYPE_ARG_TYPES (fntype
) != 0
7199 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
7201 || last_arg_is_vararg_marker
))
7203 int offset
= (regno
- GP_ARG_FIRST
) * UNITS_PER_WORD
;
7204 rtx ptr
= stack_pointer_rtx
;
7206 /* If we are doing svr4-abi, sp has already been decremented by tsize. */
7207 if (TARGET_ABICALLS
)
7210 for (; regno
<= GP_ARG_LAST
; regno
++)
7213 ptr
= gen_rtx (PLUS
, Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
7214 emit_move_insn (gen_rtx (MEM
, gpr_mode
, ptr
),
7215 gen_rtx (REG
, gpr_mode
, regno
));
7217 offset
+= GET_MODE_SIZE (gpr_mode
);
7221 /* If we are using the entry pseudo instruction, it will
7222 automatically subtract 32 from the stack pointer, so we don't
7223 need to. The entry pseudo instruction is emitted by
7224 function_prologue. */
7225 if (mips_entry
&& ! mips_can_use_return_insn ())
7227 if (tsize
> 0 && tsize
<= 32 && frame_pointer_needed
)
7231 /* If we are using a frame pointer with a small stack frame,
7232 we need to initialize it here since it won't be done
7234 if (TARGET_MIPS16
&& current_function_outgoing_args_size
!= 0)
7236 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7237 if (Pmode
== DImode
)
7238 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7242 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7246 else if (Pmode
== DImode
)
7247 insn
= emit_insn (gen_movdi (hard_frame_pointer_rtx
,
7248 stack_pointer_rtx
));
7250 insn
= emit_insn (gen_movsi (hard_frame_pointer_rtx
,
7251 stack_pointer_rtx
));
7253 RTX_FRAME_RELATED_P (insn
) = 1;
7256 /* We may need to save $18, if it is used to call a function
7257 which may return a floating point value. Set up a sequence
7258 of instructions to do so. Later on we emit them at the right
7260 if (TARGET_MIPS16
&& BITSET_P (current_frame_info
.mask
, 18))
7262 rtx reg_rtx
= gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 3);
7263 long gp_offset
, base_offset
;
7265 gp_offset
= current_frame_info
.gp_sp_offset
;
7266 if (BITSET_P (current_frame_info
.mask
, 16))
7267 gp_offset
-= UNITS_PER_WORD
;
7268 if (BITSET_P (current_frame_info
.mask
, 17))
7269 gp_offset
-= UNITS_PER_WORD
;
7270 if (BITSET_P (current_frame_info
.mask
, 31))
7271 gp_offset
-= UNITS_PER_WORD
;
7273 base_offset
= tsize
;
7277 emit_move_insn (reg_rtx
,
7278 gen_rtx (REG
, gpr_mode
, GP_REG_FIRST
+ 18));
7279 emit_move_insn (gen_rtx (MEM
, gpr_mode
,
7280 gen_rtx (PLUS
, Pmode
, stack_pointer_rtx
,
7284 reg_18_save
= gen_sequence ();
7293 if (reg_18_save
!= NULL_RTX
)
7294 emit_insn (reg_18_save
);
7300 rtx tsize_rtx
= GEN_INT (tsize
);
7302 /* If we are doing svr4-abi, sp move is done by
7303 function_prologue. In mips16 mode with a large frame, we
7304 save the registers before adjusting the stack. */
7305 if ((!TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7306 && (!TARGET_MIPS16
|| tsize
<= 32767))
7312 tmp_rtx
= gen_rtx (REG
, Pmode
, MIPS_TEMP1_REGNUM
);
7314 /* Instruction splitting doesn't preserve the RTX_FRAME_RELATED_P
7315 bit, so make sure that we don't emit anything that can be
7317 /* ??? There is no DImode ori immediate pattern, so we can only
7318 do this for 32 bit code. */
7319 if (large_int (tsize_rtx
, GET_MODE (tsize_rtx
))
7320 && GET_MODE (tmp_rtx
) == SImode
)
7322 insn
= emit_move_insn (tmp_rtx
,
7323 GEN_INT (tsize
& BITMASK_UPPER16
));
7324 RTX_FRAME_RELATED_P (insn
) = 1;
7325 insn
= emit_insn (gen_iorsi3 (tmp_rtx
, tmp_rtx
,
7327 & BITMASK_LOWER16
)));
7328 RTX_FRAME_RELATED_P (insn
) = 1;
7332 insn
= emit_move_insn (tmp_rtx
, tsize_rtx
);
7333 RTX_FRAME_RELATED_P (insn
) = 1;
7336 tsize_rtx
= tmp_rtx
;
7339 if (Pmode
== DImode
)
7340 insn
= emit_insn (gen_subdi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7343 insn
= emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7346 RTX_FRAME_RELATED_P (insn
) = 1;
7350 save_restore_insns (1, tmp_rtx
, tsize
, (FILE *)0);
7351 else if (reg_18_save
!= NULL_RTX
)
7352 emit_insn (reg_18_save
);
7354 if ((!TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7360 if (!frame_pointer_needed
)
7363 reg_rtx
= gen_rtx (REG
, Pmode
, 3);
7364 emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
);
7365 emit_move_insn (reg_rtx
, tsize_rtx
);
7366 if (Pmode
== DImode
)
7367 emit_insn (gen_subdi3 (hard_frame_pointer_rtx
,
7368 hard_frame_pointer_rtx
,
7371 emit_insn (gen_subsi3 (hard_frame_pointer_rtx
,
7372 hard_frame_pointer_rtx
,
7374 emit_move_insn (stack_pointer_rtx
, hard_frame_pointer_rtx
);
7377 if (frame_pointer_needed
)
7381 /* On the mips16, we encourage the use of unextended
7382 instructions when using the frame pointer by pointing the
7383 frame pointer ahead of the argument space allocated on
7385 if ((! TARGET_ABICALLS
|| (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7389 /* In this case, we have already copied the stack
7390 pointer into the frame pointer, above. We need only
7391 adjust for the outgoing argument size. */
7392 if (current_function_outgoing_args_size
!= 0)
7394 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7395 if (Pmode
== DImode
)
7396 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7397 hard_frame_pointer_rtx
,
7400 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7401 hard_frame_pointer_rtx
,
7405 else if (TARGET_MIPS16
&& current_function_outgoing_args_size
!= 0)
7407 rtx incr
= GEN_INT (current_function_outgoing_args_size
);
7408 if (Pmode
== DImode
)
7409 insn
= emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7413 insn
= emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7417 else if (Pmode
== DImode
)
7418 insn
= emit_insn (gen_movdi (hard_frame_pointer_rtx
,
7419 stack_pointer_rtx
));
7421 insn
= emit_insn (gen_movsi (hard_frame_pointer_rtx
,
7422 stack_pointer_rtx
));
7425 RTX_FRAME_RELATED_P (insn
) = 1;
7428 if (TARGET_ABICALLS
&& (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
))
7429 emit_insn (gen_loadgp (XEXP (DECL_RTL (current_function_decl
), 0),
7430 gen_rtx_REG (DImode
, 25)));
7433 /* If we are profiling, make sure no instructions are scheduled before
7434 the call to mcount. */
7436 if (profile_flag
|| profile_block_flag
)
7437 emit_insn (gen_blockage ());
7440 /* Do any necessary cleanup after a function to restore stack, frame,
7443 #define RA_MASK BITMASK_HIGH /* 1 << 31 */
7444 #define PIC_OFFSET_TABLE_MASK (1 << (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
7447 mips_output_function_epilogue (file
, size
)
7448 FILE *file ATTRIBUTE_UNUSED
;
7449 HOST_WIDE_INT size ATTRIBUTE_UNUSED
;
7451 const char *fnname
= ""; /* FIXME: Correct initialisation? */
7453 #ifndef FUNCTION_NAME_ALREADY_DECLARED
7454 /* Get the function name the same way that toplev.c does before calling
7455 assemble_start_function. This is needed so that the name used here
7456 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
7457 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
7459 if (!flag_inhibit_size_directive
)
7461 fputs ("\t.end\t", file
);
7462 assemble_name (file
, fnname
);
7469 int num_gp_regs
= current_frame_info
.gp_reg_size
/ 4;
7470 int num_fp_regs
= current_frame_info
.fp_reg_size
/ 8;
7471 int num_regs
= num_gp_regs
+ num_fp_regs
;
7472 const char *name
= fnname
;
7477 dslots_load_total
+= num_regs
;
7480 "%-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",
7481 name
, frame_pointer_needed
? 'y' : 'n',
7482 (current_frame_info
.mask
& RA_MASK
) != 0 ? 'n' : 'y',
7483 current_function_calls_alloca
? 'y' : 'n',
7484 current_function_calls_setjmp
? 'y' : 'n',
7485 current_frame_info
.total_size
,
7486 current_function_outgoing_args_size
, num_gp_regs
, num_fp_regs
,
7487 dslots_load_total
, dslots_load_filled
,
7488 dslots_jump_total
, dslots_jump_filled
,
7489 num_refs
[0], num_refs
[1], num_refs
[2]);
7491 if (HALF_PIC_NUMBER_PTRS
> prev_half_pic_ptrs
)
7494 " half-pic=%3d", HALF_PIC_NUMBER_PTRS
- prev_half_pic_ptrs
);
7495 prev_half_pic_ptrs
= HALF_PIC_NUMBER_PTRS
;
7498 if (HALF_PIC_NUMBER_REFS
> prev_half_pic_refs
)
7501 " pic-ref=%3d", HALF_PIC_NUMBER_REFS
- prev_half_pic_refs
);
7502 prev_half_pic_refs
= HALF_PIC_NUMBER_REFS
;
7505 fputc ('\n', stderr
);
7508 /* Reset state info for each function. */
7509 inside_function
= 0;
7510 ignore_line_number
= 0;
7511 dslots_load_total
= 0;
7512 dslots_jump_total
= 0;
7513 dslots_load_filled
= 0;
7514 dslots_jump_filled
= 0;
7520 current_frame_info
= zero_frame_info
;
7522 while (string_constants
!= NULL
)
7524 struct string_constant
*next
;
7526 next
= string_constants
->next
;
7527 free (string_constants
);
7528 string_constants
= next
;
7531 /* Restore the output file if optimizing the GP (optimizing the GP causes
7532 the text to be diverted to a tempfile, so that data decls come before
7533 references to the data). */
7535 if (TARGET_GP_OPT
&& ! TARGET_MIPS16
&& ! TARGET_GAS
)
7536 asm_out_file
= asm_out_data_file
;
7539 /* Expand the epilogue into a bunch of separate insns. */
7542 mips_expand_epilogue ()
7544 HOST_WIDE_INT tsize
= current_frame_info
.total_size
;
7545 rtx tsize_rtx
= GEN_INT (tsize
);
7546 rtx tmp_rtx
= (rtx
)0;
7548 if (mips_can_use_return_insn ())
7550 emit_insn (gen_return ());
7554 if (mips_entry
&& ! mips_can_use_return_insn ())
7557 if (tsize
> 32767 && ! TARGET_MIPS16
)
7559 tmp_rtx
= gen_rtx_REG (Pmode
, MIPS_TEMP1_REGNUM
);
7560 emit_move_insn (tmp_rtx
, tsize_rtx
);
7561 tsize_rtx
= tmp_rtx
;
7566 long orig_tsize
= tsize
;
7568 if (frame_pointer_needed
)
7570 emit_insn (gen_blockage ());
7572 /* On the mips16, the frame pointer is offset from the stack
7573 pointer by current_function_outgoing_args_size. We
7574 account for that by changing tsize. Note that this can
7575 actually make tsize negative. */
7578 tsize
-= current_function_outgoing_args_size
;
7580 /* If we have a large frame, it's easier to add to $17
7581 than to $sp, since the mips16 has no instruction to
7582 add a register to $sp. */
7583 if (orig_tsize
> 32767)
7585 rtx g6_rtx
= gen_rtx (REG
, Pmode
, GP_REG_FIRST
+ 6);
7587 emit_move_insn (g6_rtx
, GEN_INT (tsize
));
7588 if (Pmode
== DImode
)
7589 emit_insn (gen_adddi3 (hard_frame_pointer_rtx
,
7590 hard_frame_pointer_rtx
,
7593 emit_insn (gen_addsi3 (hard_frame_pointer_rtx
,
7594 hard_frame_pointer_rtx
,
7599 if (tsize
&& tsize
!= orig_tsize
)
7600 tsize_rtx
= GEN_INT (tsize
);
7603 if (Pmode
== DImode
)
7604 emit_insn (gen_movdi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
7606 emit_insn (gen_movsi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
7609 /* The GP/PIC register is implicitly used by all SYMBOL_REFs, so if we
7610 are going to restore it, then we must emit a blockage insn to
7611 prevent the scheduler from moving the restore out of the epilogue. */
7612 else if (TARGET_ABICALLS
&& mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
7613 && (current_frame_info
.mask
7614 & (1L << (PIC_OFFSET_TABLE_REGNUM
- GP_REG_FIRST
))))
7615 emit_insn (gen_blockage ());
7617 save_restore_insns (0, tmp_rtx
, orig_tsize
, (FILE *)0);
7619 /* In mips16 mode with a large frame, we adjust the stack
7620 pointer before restoring the registers. In this case, we
7621 should always be using a frame pointer, so everything should
7622 have been handled above. */
7623 if (tsize
> 32767 && TARGET_MIPS16
)
7626 if (current_function_calls_eh_return
)
7628 rtx eh_ofs
= EH_RETURN_STACKADJ_RTX
;
7629 if (Pmode
== DImode
)
7630 emit_insn (gen_adddi3 (eh_ofs
, eh_ofs
, tsize_rtx
));
7632 emit_insn (gen_addsi3 (eh_ofs
, eh_ofs
, tsize_rtx
));
7636 emit_insn (gen_blockage ());
7638 if (tsize
!= 0 || current_function_calls_eh_return
)
7640 if (Pmode
== DImode
)
7641 emit_insn (gen_adddi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7644 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
7649 /* The mips16 loads the return address into $7, not $31. */
7650 if (TARGET_MIPS16
&& (current_frame_info
.mask
& RA_MASK
) != 0)
7651 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
7652 GP_REG_FIRST
+ 7)));
7654 emit_jump_insn (gen_return_internal (gen_rtx (REG
, Pmode
,
7655 GP_REG_FIRST
+ 31)));
7658 /* Return nonzero if this function is known to have a null epilogue.
7659 This allows the optimizer to omit jumps to jumps if no stack
7663 mips_can_use_return_insn ()
7665 if (! reload_completed
)
7668 if (regs_ever_live
[31] || profile_flag
)
7671 /* In mips16 mode, a function which returns a floating point value
7672 needs to arrange to copy the return value into the floating point
7675 && mips16_hard_float
7676 && ! aggregate_value_p (DECL_RESULT (current_function_decl
))
7677 && (GET_MODE_CLASS (DECL_MODE (DECL_RESULT (current_function_decl
)))
7679 && (! TARGET_SINGLE_FLOAT
7680 || (GET_MODE_SIZE (DECL_MODE (DECL_RESULT (current_function_decl
)))
7684 if (current_frame_info
.initialized
)
7685 return current_frame_info
.total_size
== 0;
7687 return compute_frame_size (get_frame_size ()) == 0;
7690 /* Returns non-zero if X contains a SYMBOL_REF. */
7693 symbolic_expression_p (x
)
7696 if (GET_CODE (x
) == SYMBOL_REF
)
7699 if (GET_CODE (x
) == CONST
)
7700 return symbolic_expression_p (XEXP (x
, 0));
7702 if (GET_RTX_CLASS (GET_CODE (x
)) == '1')
7703 return symbolic_expression_p (XEXP (x
, 0));
7705 if (GET_RTX_CLASS (GET_CODE (x
)) == 'c'
7706 || GET_RTX_CLASS (GET_CODE (x
)) == '2')
7707 return (symbolic_expression_p (XEXP (x
, 0))
7708 || symbolic_expression_p (XEXP (x
, 1)));
7713 /* Choose the section to use for the constant rtx expression X that has
7717 mips_select_rtx_section (mode
, x
)
7718 enum machine_mode mode
;
7719 rtx x ATTRIBUTE_UNUSED
;
7723 /* In mips16 mode, the constant table always goes in the same section
7724 as the function, so that constants can be loaded using PC relative
7726 function_section (current_function_decl
);
7728 else if (TARGET_EMBEDDED_DATA
)
7730 /* For embedded applications, always put constants in read-only data,
7731 in order to reduce RAM usage. */
7732 READONLY_DATA_SECTION ();
7736 /* For hosted applications, always put constants in small data if
7737 possible, as this gives the best performance. */
7739 if (GET_MODE_SIZE (mode
) <= (unsigned) mips_section_threshold
7740 && mips_section_threshold
> 0)
7741 SMALL_DATA_SECTION ();
7742 else if (flag_pic
&& symbolic_expression_p (x
))
7743 /* Any expression involving a SYMBOL_REF might need a run-time
7744 relocation. (The symbol might be defined in a shared
7745 library loaded at an unexpected base address.) So, we must
7746 put such expressions in the data segment (which is
7747 writable), rather than the text segment (which is
7751 READONLY_DATA_SECTION ();
7755 /* Choose the section to use for DECL. RELOC is true if its value contains
7756 any relocatable expression.
7758 Some of the logic used here needs to be replicated in
7759 ENCODE_SECTION_INFO in mips.h so that references to these symbols
7760 are done correctly. Specifically, at least all symbols assigned
7761 here to rom (.text and/or .rodata) must not be referenced via
7762 ENCODE_SECTION_INFO with %gprel, as the rom might be too far away.
7764 If you need to make a change here, you probably should check
7765 ENCODE_SECTION_INFO to see if it needs a similar change. */
7768 mips_select_section (decl
, reloc
)
7772 int size
= int_size_in_bytes (TREE_TYPE (decl
));
7774 if ((TARGET_EMBEDDED_PIC
|| TARGET_MIPS16
)
7775 && TREE_CODE (decl
) == STRING_CST
7776 && !flag_writable_strings
)
7777 /* For embedded position independent code, put constant strings in the
7778 text section, because the data section is limited to 64K in size.
7779 For mips16 code, put strings in the text section so that a PC
7780 relative load instruction can be used to get their address. */
7782 else if (TARGET_EMBEDDED_DATA
)
7784 /* For embedded applications, always put an object in read-only data
7785 if possible, in order to reduce RAM usage. */
7787 if (((TREE_CODE (decl
) == VAR_DECL
7788 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
7789 && DECL_INITIAL (decl
)
7790 && (DECL_INITIAL (decl
) == error_mark_node
7791 || TREE_CONSTANT (DECL_INITIAL (decl
))))
7792 /* Deal with calls from output_constant_def_contents. */
7793 || (TREE_CODE (decl
) != VAR_DECL
7794 && (TREE_CODE (decl
) != STRING_CST
7795 || !flag_writable_strings
)))
7796 && ! (flag_pic
&& reloc
))
7797 READONLY_DATA_SECTION ();
7798 else if (size
> 0 && size
<= mips_section_threshold
)
7799 SMALL_DATA_SECTION ();
7805 /* For hosted applications, always put an object in small data if
7806 possible, as this gives the best performance. */
7808 if (size
> 0 && size
<= mips_section_threshold
)
7809 SMALL_DATA_SECTION ();
7810 else if (((TREE_CODE (decl
) == VAR_DECL
7811 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
7812 && DECL_INITIAL (decl
)
7813 && (DECL_INITIAL (decl
) == error_mark_node
7814 || TREE_CONSTANT (DECL_INITIAL (decl
))))
7815 /* Deal with calls from output_constant_def_contents. */
7816 || (TREE_CODE (decl
) != VAR_DECL
7817 && (TREE_CODE (decl
) != STRING_CST
7818 || !flag_writable_strings
)))
7819 && ! (flag_pic
&& reloc
))
7820 READONLY_DATA_SECTION ();
7826 #ifdef MIPS_ABI_DEFAULT
7828 /* Support functions for the 64 bit ABI. */
7830 /* Return register to use for a function return value with VALTYPE for function
7834 mips_function_value (valtype
, func
)
7836 tree func ATTRIBUTE_UNUSED
;
7838 int reg
= GP_RETURN
;
7839 enum machine_mode mode
= TYPE_MODE (valtype
);
7840 enum mode_class mclass
= GET_MODE_CLASS (mode
);
7841 int unsignedp
= TREE_UNSIGNED (valtype
);
7843 /* Since we define PROMOTE_FUNCTION_RETURN, we must promote the mode
7844 just as PROMOTE_MODE does. */
7845 mode
= promote_mode (valtype
, mode
, &unsignedp
, 1);
7847 /* ??? How should we return complex float? */
7848 if (mclass
== MODE_FLOAT
|| mclass
== MODE_COMPLEX_FLOAT
)
7850 if (TARGET_SINGLE_FLOAT
7851 && (mclass
== MODE_FLOAT
7852 ? GET_MODE_SIZE (mode
) > 4 : GET_MODE_SIZE (mode
) / 2 > 4))
7858 else if (TREE_CODE (valtype
) == RECORD_TYPE
7859 && mips_abi
!= ABI_32
7860 && mips_abi
!= ABI_O64
7861 && mips_abi
!= ABI_EABI
)
7863 /* A struct with only one or two floating point fields is returned in
7864 the floating point registers. */
7865 tree field
, fields
[2];
7868 for (i
= 0, field
= TYPE_FIELDS (valtype
); field
;
7869 field
= TREE_CHAIN (field
))
7871 if (TREE_CODE (field
) != FIELD_DECL
)
7874 if (TREE_CODE (TREE_TYPE (field
)) != REAL_TYPE
|| i
>= 2)
7877 fields
[i
++] = field
;
7880 /* Must check i, so that we reject structures with no elements. */
7885 /* The structure has DImode, but we don't allow DImode values
7886 in FP registers, so we use a PARALLEL even though it isn't
7887 strictly necessary. */
7888 enum machine_mode field_mode
= TYPE_MODE (TREE_TYPE (fields
[0]));
7890 return gen_rtx_PARALLEL
7893 gen_rtx_EXPR_LIST (VOIDmode
,
7894 gen_rtx_REG (field_mode
,
7901 enum machine_mode first_mode
7902 = TYPE_MODE (TREE_TYPE (fields
[0]));
7903 enum machine_mode second_mode
7904 = TYPE_MODE (TREE_TYPE (fields
[1]));
7905 HOST_WIDE_INT first_offset
= int_byte_position (fields
[0]);
7906 HOST_WIDE_INT second_offset
= int_byte_position (fields
[1]);
7908 return gen_rtx_PARALLEL
7911 gen_rtx_EXPR_LIST (VOIDmode
,
7912 gen_rtx_REG (first_mode
,
7914 GEN_INT (first_offset
)),
7915 gen_rtx_EXPR_LIST (VOIDmode
,
7916 gen_rtx_REG (second_mode
,
7918 GEN_INT (second_offset
))));
7923 return gen_rtx_REG (mode
, reg
);
7927 /* The implementation of FUNCTION_ARG_PASS_BY_REFERENCE. Return
7928 nonzero when an argument must be passed by reference. */
7931 function_arg_pass_by_reference (cum
, mode
, type
, named
)
7932 CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
;
7933 enum machine_mode mode
;
7935 int named ATTRIBUTE_UNUSED
;
7939 /* We must pass by reference if we would be both passing in registers
7940 and the stack. This is because any subsequent partial arg would be
7941 handled incorrectly in this case.
7943 ??? This is really a kludge. We should either fix GCC so that such
7944 a situation causes an abort and then do something in the MIPS port
7945 to prevent it, or add code to function.c to properly handle the case. */
7946 /* ??? cum can be NULL when called from mips_va_arg. The problem handled
7947 here hopefully is not relevant to mips_va_arg. */
7948 if (cum
&& MUST_PASS_IN_STACK (mode
, type
))
7950 /* Don't pass the actual CUM to FUNCTION_ARG, because we would
7951 get double copies of any offsets generated for small structs
7952 passed in registers. */
7953 CUMULATIVE_ARGS temp
;
7955 if (FUNCTION_ARG (temp
, mode
, type
, named
) != 0)
7959 /* Otherwise, we only do this if EABI is selected. */
7960 if (mips_abi
!= ABI_EABI
)
7963 /* ??? How should SCmode be handled? */
7964 if (type
== NULL_TREE
|| mode
== DImode
|| mode
== DFmode
)
7967 size
= int_size_in_bytes (type
);
7968 return size
== -1 || size
> UNITS_PER_WORD
;
7971 /* This function returns the register class required for a secondary
7972 register when copying between one of the registers in CLASS, and X,
7973 using MODE. If IN_P is nonzero, the copy is going from X to the
7974 register, otherwise the register is the source. A return value of
7975 NO_REGS means that no secondary register is required. */
7978 mips_secondary_reload_class (class, mode
, x
, in_p
)
7979 enum reg_class
class;
7980 enum machine_mode mode
;
7984 enum reg_class gr_regs
= TARGET_MIPS16
? M16_REGS
: GR_REGS
;
7988 if (GET_CODE (x
) == SIGN_EXTEND
)
7994 /* We may be called with reg_renumber NULL from regclass.
7995 ??? This is probably a bug. */
7997 regno
= true_regnum (x
);
8000 while (GET_CODE (x
) == SUBREG
)
8002 off
+= subreg_regno_offset (REGNO (SUBREG_REG (x
)),
8003 GET_MODE (SUBREG_REG (x
)),
8009 if (GET_CODE (x
) == REG
)
8010 regno
= REGNO (x
) + off
;
8014 else if (GET_CODE (x
) == REG
|| GET_CODE (x
) == SUBREG
)
8015 regno
= true_regnum (x
);
8017 gp_reg_p
= TARGET_MIPS16
? M16_REG_P (regno
) : GP_REG_P (regno
);
8019 /* We always require a general register when copying anything to
8020 HILO_REGNUM, except when copying an SImode value from HILO_REGNUM
8021 to a general register, or when copying from register 0. */
8022 if (class == HILO_REG
&& regno
!= GP_REG_FIRST
+ 0)
8025 && GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (SImode
))
8026 ? NO_REGS
: gr_regs
);
8027 else if (regno
== HILO_REGNUM
)
8030 && GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (SImode
))
8031 ? NO_REGS
: gr_regs
);
8033 /* Copying from HI or LO to anywhere other than a general register
8034 requires a general register. */
8035 if (class == HI_REG
|| class == LO_REG
|| class == MD_REGS
)
8037 if (TARGET_MIPS16
&& in_p
)
8039 /* We can't really copy to HI or LO at all in mips16 mode. */
8042 return gp_reg_p
? NO_REGS
: gr_regs
;
8044 if (MD_REG_P (regno
))
8046 if (TARGET_MIPS16
&& ! in_p
)
8048 /* We can't really copy to HI or LO at all in mips16 mode. */
8051 return class == gr_regs
? NO_REGS
: gr_regs
;
8054 /* We can only copy a value to a condition code register from a
8055 floating point register, and even then we require a scratch
8056 floating point register. We can only copy a value out of a
8057 condition code register into a general register. */
8058 if (class == ST_REGS
)
8062 return GP_REG_P (regno
) ? NO_REGS
: GR_REGS
;
8064 if (ST_REG_P (regno
))
8068 return class == GR_REGS
? NO_REGS
: GR_REGS
;
8071 /* In mips16 mode, going between memory and anything but M16_REGS
8072 requires an M16_REG. */
8075 if (class != M16_REGS
&& class != M16_NA_REGS
)
8083 /* The stack pointer isn't a valid operand to an add instruction,
8084 so we need to load it into M16_REGS first. This can happen as
8085 a result of register elimination and form_sum converting
8086 (plus reg (plus SP CONST)) to (plus (plus reg SP) CONST). We
8087 need an extra register if the dest is the same as the other
8088 register. In that case, we can't fix the problem by loading SP
8089 into the dest first. */
8090 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == REG
8091 && GET_CODE (XEXP (x
, 1)) == REG
8092 && (XEXP (x
, 0) == stack_pointer_rtx
8093 || XEXP (x
, 1) == stack_pointer_rtx
))
8094 return (class == M16_REGS
? M16_NA_REGS
: M16_REGS
);
8096 if (class == M16_REGS
|| class == M16_NA_REGS
)
8105 /* For each mips16 function which refers to GP relative symbols, we
8106 use a pseudo register, initialized at the start of the function, to
8107 hold the $gp value. */
8110 mips16_gp_pseudo_reg ()
8112 if (mips16_gp_pseudo_rtx
== NULL_RTX
)
8117 mips16_gp_pseudo_rtx
= gen_reg_rtx (Pmode
);
8118 RTX_UNCHANGING_P (mips16_gp_pseudo_rtx
) = 1;
8120 /* We want to initialize this to a value which gcc will believe
8122 const_gp
= gen_rtx (CONST
, Pmode
,
8123 gen_rtx (REG
, Pmode
, GP_REG_FIRST
+ 28));
8126 emit_move_insn (mips16_gp_pseudo_rtx
, const_gp
);
8127 insn
= gen_sequence ();
8130 push_topmost_sequence ();
8131 /* We need to emit the initialization after the FUNCTION_BEG
8132 note, so that it will be integrated. */
8133 for (scan
= get_insns (); scan
!= NULL_RTX
; scan
= NEXT_INSN (scan
))
8134 if (GET_CODE (scan
) == NOTE
8135 && NOTE_LINE_NUMBER (scan
) == NOTE_INSN_FUNCTION_BEG
)
8137 if (scan
== NULL_RTX
)
8138 scan
= get_insns ();
8139 insn
= emit_insn_after (insn
, scan
);
8140 pop_topmost_sequence ();
8143 return mips16_gp_pseudo_rtx
;
8146 /* Return an RTX which represents the signed 16 bit offset from the
8147 $gp register for the given symbol. This is only used on the
8151 mips16_gp_offset (sym
)
8156 if (GET_CODE (sym
) != SYMBOL_REF
8157 || ! SYMBOL_REF_FLAG (sym
))
8160 /* We use a special identifier to represent the value of the gp
8162 gp
= get_identifier ("__mips16_gp_value");
8164 return gen_rtx (CONST
, Pmode
,
8165 gen_rtx (MINUS
, Pmode
, sym
,
8166 gen_rtx (SYMBOL_REF
, Pmode
,
8167 IDENTIFIER_POINTER (gp
))));
8170 /* Return nonzero if the given RTX represents a signed 16 bit offset
8171 from the $gp register. */
8174 mips16_gp_offset_p (x
)
8177 if (GET_CODE (x
) == CONST
)
8180 /* It's OK to add a small integer value to a gp offset. */
8181 if (GET_CODE (x
) == PLUS
)
8183 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
8184 && SMALL_INT (XEXP (x
, 1)))
8185 return mips16_gp_offset_p (XEXP (x
, 0));
8186 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
8187 && SMALL_INT (XEXP (x
, 0)))
8188 return mips16_gp_offset_p (XEXP (x
, 1));
8192 /* Make sure it is in the form SYM - __mips16_gp_value. */
8193 return (GET_CODE (x
) == MINUS
8194 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
8195 && SYMBOL_REF_FLAG (XEXP (x
, 0))
8196 && GET_CODE (XEXP (x
, 1)) == SYMBOL_REF
8197 && strcmp (XSTR (XEXP (x
, 1), 0), "__mips16_gp_value") == 0);
8200 /* Output a GP offset. We don't want to print the subtraction of
8201 __mips16_gp_value; it is implicitly represented by the %gprel which
8202 should have been printed by the caller. */
8205 mips16_output_gp_offset (file
, x
)
8209 if (GET_CODE (x
) == CONST
)
8212 if (GET_CODE (x
) == PLUS
)
8214 mips16_output_gp_offset (file
, XEXP (x
, 0));
8216 mips16_output_gp_offset (file
, XEXP (x
, 1));
8220 if (GET_CODE (x
) == MINUS
8221 && GET_CODE (XEXP (x
, 1)) == SYMBOL_REF
8222 && strcmp (XSTR (XEXP (x
, 1), 0), "__mips16_gp_value") == 0)
8224 mips16_output_gp_offset (file
, XEXP (x
, 0));
8228 output_addr_const (file
, x
);
8231 /* Return nonzero if a constant should not be output until after the
8232 function. This is true of most string constants, so that we can
8233 use a more efficient PC relative reference. However, a static
8234 inline function may never call assemble_function_end to write out
8235 the constant pool, so don't try to postpone the constant in that
8238 ??? It's really a bug that a static inline function can put stuff
8239 in the constant pool even if the function itself is not output.
8241 We record which string constants we've seen, so that we know which
8242 ones might use the more efficient reference. */
8245 mips16_constant_after_function_p (x
)
8248 if (TREE_CODE (x
) == STRING_CST
8249 && ! flag_writable_strings
8250 && current_function_decl
!= 0
8251 && ! DECL_DEFER_OUTPUT (current_function_decl
)
8252 && ! (DECL_INLINE (current_function_decl
)
8253 && ((! TREE_PUBLIC (current_function_decl
)
8254 && ! TREE_ADDRESSABLE (current_function_decl
)
8255 && ! flag_keep_inline_functions
)
8256 || DECL_EXTERNAL (current_function_decl
))))
8258 struct string_constant
*n
;
8260 n
= (struct string_constant
*) xmalloc (sizeof *n
);
8261 n
->label
= XSTR (XEXP (TREE_CST_RTL (x
), 0), 0);
8262 n
->next
= string_constants
;
8263 string_constants
= n
;
8271 /* Validate a constant for the mips16. This rejects general symbolic
8272 addresses, which must be loaded from memory. If ADDR is nonzero,
8273 this should reject anything which is not a legal address. If
8274 ADDEND is nonzero, this is being added to something else. */
8277 mips16_constant (x
, mode
, addr
, addend
)
8279 enum machine_mode mode
;
8283 while (GET_CODE (x
) == CONST
)
8286 switch (GET_CODE (x
))
8292 return (mips16_constant (XEXP (x
, 0), mode
, addr
, 1)
8293 && mips16_constant (XEXP (x
, 1), mode
, addr
, 1));
8296 if (addr
&& GET_MODE_SIZE (mode
) != 4 && GET_MODE_SIZE (mode
) != 8)
8298 if (CONSTANT_POOL_ADDRESS_P (x
))
8301 /* If we aren't looking for a memory address, we can accept a GP
8302 relative symbol, which will have SYMBOL_REF_FLAG set; movsi
8303 knows how to handle this. We can always accept a string
8304 constant, which is the other case in which SYMBOL_REF_FLAG
8308 && SYMBOL_REF_FLAG (x
)
8309 && mode
== (enum machine_mode
) Pmode
)
8312 /* We can accept a string constant, which will have
8313 SYMBOL_REF_FLAG set but must be recognized by name to
8314 distinguish from a GP accessible symbol. The name of a
8315 string constant will have been generated by
8316 ASM_GENERATE_INTERNAL_LABEL as called by output_constant_def. */
8317 if (SYMBOL_REF_FLAG (x
))
8319 const char *name
= XSTR (x
, 0);
8321 return (name
[0] == '*'
8322 && strncmp (name
+ 1, LOCAL_LABEL_PREFIX
,
8323 sizeof LOCAL_LABEL_PREFIX
- 1) == 0);
8329 if (addr
&& GET_MODE_SIZE (mode
) != 4 && GET_MODE_SIZE (mode
) != 8)
8334 if (addr
&& ! addend
)
8336 return INTVAL (x
) > - 0x10000 && INTVAL (x
) <= 0xffff;
8339 /* We need to treat $gp as a legitimate constant, because
8340 mips16_gp_pseudo_reg assumes that. */
8341 return REGNO (x
) == GP_REG_FIRST
+ 28;
8345 /* Write out code to move floating point arguments in or out of
8346 general registers. Output the instructions to FILE. FP_CODE is
8347 the code describing which arguments are present (see the comment at
8348 the definition of CUMULATIVE_ARGS in mips.h). FROM_FP_P is non-zero if
8349 we are copying from the floating point registers. */
8352 mips16_fp_args (file
, fp_code
, from_fp_p
)
8361 /* This code only works for the original 32 bit ABI and the O64 ABI. */
8362 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
8369 gparg
= GP_ARG_FIRST
;
8370 fparg
= FP_ARG_FIRST
;
8371 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
8375 if ((fparg
& 1) != 0)
8377 fprintf (file
, "\t%s\t%s,%s\n", s
,
8378 reg_names
[gparg
], reg_names
[fparg
]);
8380 else if ((f
& 3) == 2)
8383 fprintf (file
, "\td%s\t%s,%s\n", s
,
8384 reg_names
[gparg
], reg_names
[fparg
]);
8387 if ((fparg
& 1) != 0)
8389 if (TARGET_BIG_ENDIAN
)
8390 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
8391 reg_names
[gparg
], reg_names
[fparg
+ 1], s
,
8392 reg_names
[gparg
+ 1], reg_names
[fparg
]);
8394 fprintf (file
, "\t%s\t%s,%s\n\t%s\t%s,%s\n", s
,
8395 reg_names
[gparg
], reg_names
[fparg
], s
,
8396 reg_names
[gparg
+ 1], reg_names
[fparg
+ 1]);
8409 /* Build a mips16 function stub. This is used for functions which
8410 take aruments in the floating point registers. It is 32 bit code
8411 that moves the floating point args into the general registers, and
8412 then jumps to the 16 bit code. */
8415 build_mips16_function_stub (file
)
8419 char *secname
, *stubname
;
8420 tree stubid
, stubdecl
;
8424 fnname
= XSTR (XEXP (DECL_RTL (current_function_decl
), 0), 0);
8425 secname
= (char *) alloca (strlen (fnname
) + 20);
8426 sprintf (secname
, ".mips16.fn.%s", fnname
);
8427 stubname
= (char *) alloca (strlen (fnname
) + 20);
8428 sprintf (stubname
, "__fn_stub_%s", fnname
);
8429 stubid
= get_identifier (stubname
);
8430 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
8431 build_function_type (void_type_node
, NULL_TREE
));
8432 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
8434 fprintf (file
, "\t# Stub function for %s (", current_function_name
);
8436 for (f
= (unsigned int) current_function_args_info
.fp_code
; f
!= 0; f
>>= 2)
8438 fprintf (file
, "%s%s",
8439 need_comma
? ", " : "",
8440 (f
& 3) == 1 ? "float" : "double");
8443 fprintf (file
, ")\n");
8445 fprintf (file
, "\t.set\tnomips16\n");
8446 function_section (stubdecl
);
8447 ASM_OUTPUT_ALIGN (file
, floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
));
8449 /* ??? If FUNCTION_NAME_ALREADY_DECLARED is defined, then we are
8450 within a .ent, and we can not emit another .ent. */
8451 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8452 fputs ("\t.ent\t", file
);
8453 assemble_name (file
, stubname
);
8457 assemble_name (file
, stubname
);
8458 fputs (":\n", file
);
8460 /* We don't want the assembler to insert any nops here. */
8461 fprintf (file
, "\t.set\tnoreorder\n");
8463 mips16_fp_args (file
, current_function_args_info
.fp_code
, 1);
8465 fprintf (asm_out_file
, "\t.set\tnoat\n");
8466 fprintf (asm_out_file
, "\tla\t%s,", reg_names
[GP_REG_FIRST
+ 1]);
8467 assemble_name (file
, fnname
);
8468 fprintf (file
, "\n");
8469 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
8470 fprintf (asm_out_file
, "\t.set\tat\n");
8472 /* Unfortunately, we can't fill the jump delay slot. We can't fill
8473 with one of the mfc1 instructions, because the result is not
8474 available for one instruction, so if the very first instruction
8475 in the function refers to the register, it will see the wrong
8477 fprintf (file
, "\tnop\n");
8479 fprintf (file
, "\t.set\treorder\n");
8481 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8482 fputs ("\t.end\t", file
);
8483 assemble_name (file
, stubname
);
8487 fprintf (file
, "\t.set\tmips16\n");
8489 function_section (current_function_decl
);
8492 /* We keep a list of functions for which we have already built stubs
8493 in build_mips16_call_stub. */
8497 struct mips16_stub
*next
;
8502 static struct mips16_stub
*mips16_stubs
;
8504 /* Build a call stub for a mips16 call. A stub is needed if we are
8505 passing any floating point values which should go into the floating
8506 point registers. If we are, and the call turns out to be to a 32
8507 bit function, the stub will be used to move the values into the
8508 floating point registers before calling the 32 bit function. The
8509 linker will magically adjust the function call to either the 16 bit
8510 function or the 32 bit stub, depending upon where the function call
8511 is actually defined.
8513 Similarly, we need a stub if the return value might come back in a
8514 floating point register.
8516 RETVAL, FNMEM, and ARG_SIZE are the values passed to the call insn
8517 (RETVAL is NULL if this is call rather than call_value). FP_CODE
8518 is the code built by function_arg. This function returns a nonzero
8519 value if it builds the call instruction itself. */
8522 build_mips16_call_stub (retval
, fnmem
, arg_size
, fp_code
)
8531 char *secname
, *stubname
;
8532 struct mips16_stub
*l
;
8533 tree stubid
, stubdecl
;
8537 /* We don't need to do anything if we aren't in mips16 mode, or if
8538 we were invoked with the -msoft-float option. */
8539 if (! TARGET_MIPS16
|| ! mips16_hard_float
)
8542 /* Figure out whether the value might come back in a floating point
8544 fpret
= (retval
!= 0
8545 && GET_MODE_CLASS (GET_MODE (retval
)) == MODE_FLOAT
8546 && (! TARGET_SINGLE_FLOAT
8547 || GET_MODE_SIZE (GET_MODE (retval
)) <= 4));
8549 /* We don't need to do anything if there were no floating point
8550 arguments and the value will not be returned in a floating point
8552 if (fp_code
== 0 && ! fpret
)
8555 if (GET_CODE (fnmem
) != MEM
)
8557 fn
= XEXP (fnmem
, 0);
8559 /* We don't need to do anything if this is a call to a special
8560 mips16 support function. */
8561 if (GET_CODE (fn
) == SYMBOL_REF
8562 && strncmp (XSTR (fn
, 0), "__mips16_", 9) == 0)
8565 /* This code will only work for o32 and o64 abis. The other ABI's
8566 require more sophisticated support. */
8567 if (mips_abi
!= ABI_32
&& mips_abi
!= ABI_O64
)
8570 /* We can only handle SFmode and DFmode floating point return
8572 if (fpret
&& GET_MODE (retval
) != SFmode
&& GET_MODE (retval
) != DFmode
)
8575 /* If we're calling via a function pointer, then we must always call
8576 via a stub. There are magic stubs provided in libgcc.a for each
8577 of the required cases. Each of them expects the function address
8578 to arrive in register $2. */
8580 if (GET_CODE (fn
) != SYMBOL_REF
)
8584 rtx stub_fn
, stub_mem
, insn
;
8586 /* ??? If this code is modified to support other ABI's, we need
8587 to handle PARALLEL return values here. */
8589 sprintf (buf
, "__mips16_call_stub_%s%d",
8591 ? (GET_MODE (retval
) == SFmode
? "sf_" : "df_")
8594 id
= get_identifier (buf
);
8595 stub_fn
= gen_rtx (SYMBOL_REF
, Pmode
, IDENTIFIER_POINTER (id
));
8596 stub_mem
= gen_rtx (MEM
, Pmode
, stub_fn
);
8598 emit_move_insn (gen_rtx (REG
, Pmode
, 2), fn
);
8600 if (retval
== NULL_RTX
)
8601 insn
= gen_call_internal0 (stub_mem
, arg_size
,
8602 gen_rtx (REG
, SImode
,
8603 GP_REG_FIRST
+ 31));
8605 insn
= gen_call_value_internal0 (retval
, stub_mem
, arg_size
,
8606 gen_rtx (REG
, SImode
,
8607 GP_REG_FIRST
+ 31));
8608 insn
= emit_call_insn (insn
);
8610 /* Put the register usage information on the CALL. */
8611 if (GET_CODE (insn
) != CALL_INSN
)
8613 CALL_INSN_FUNCTION_USAGE (insn
) =
8614 gen_rtx (EXPR_LIST
, VOIDmode
,
8615 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, Pmode
, 2)),
8616 CALL_INSN_FUNCTION_USAGE (insn
));
8618 /* If we are handling a floating point return value, we need to
8619 save $18 in the function prologue. Putting a note on the
8620 call will mean that regs_ever_live[$18] will be true if the
8621 call is not eliminated, and we can check that in the prologue
8624 CALL_INSN_FUNCTION_USAGE (insn
) =
8625 gen_rtx (EXPR_LIST
, VOIDmode
,
8626 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
8627 CALL_INSN_FUNCTION_USAGE (insn
));
8629 /* Return 1 to tell the caller that we've generated the call
8634 /* We know the function we are going to call. If we have already
8635 built a stub, we don't need to do anything further. */
8637 fnname
= XSTR (fn
, 0);
8638 for (l
= mips16_stubs
; l
!= NULL
; l
= l
->next
)
8639 if (strcmp (l
->name
, fnname
) == 0)
8644 /* Build a special purpose stub. When the linker sees a
8645 function call in mips16 code, it will check where the target
8646 is defined. If the target is a 32 bit call, the linker will
8647 search for the section defined here. It can tell which
8648 symbol this section is associated with by looking at the
8649 relocation information (the name is unreliable, since this
8650 might be a static function). If such a section is found, the
8651 linker will redirect the call to the start of the magic
8654 If the function does not return a floating point value, the
8655 special stub section is named
8658 If the function does return a floating point value, the stub
8660 .mips16.call.fp.FNNAME
8663 secname
= (char *) alloca (strlen (fnname
) + 40);
8664 sprintf (secname
, ".mips16.call.%s%s",
8667 stubname
= (char *) alloca (strlen (fnname
) + 20);
8668 sprintf (stubname
, "__call_stub_%s%s",
8671 stubid
= get_identifier (stubname
);
8672 stubdecl
= build_decl (FUNCTION_DECL
, stubid
,
8673 build_function_type (void_type_node
, NULL_TREE
));
8674 DECL_SECTION_NAME (stubdecl
) = build_string (strlen (secname
), secname
);
8676 fprintf (asm_out_file
, "\t# Stub function to call %s%s (",
8678 ? (GET_MODE (retval
) == SFmode
? "float " : "double ")
8682 for (f
= (unsigned int) fp_code
; f
!= 0; f
>>= 2)
8684 fprintf (asm_out_file
, "%s%s",
8685 need_comma
? ", " : "",
8686 (f
& 3) == 1 ? "float" : "double");
8689 fprintf (asm_out_file
, ")\n");
8691 fprintf (asm_out_file
, "\t.set\tnomips16\n");
8692 assemble_start_function (stubdecl
, stubname
);
8694 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8695 fputs ("\t.ent\t", asm_out_file
);
8696 assemble_name (asm_out_file
, stubname
);
8697 fputs ("\n", asm_out_file
);
8699 assemble_name (asm_out_file
, stubname
);
8700 fputs (":\n", asm_out_file
);
8703 /* We build the stub code by hand. That's the only way we can
8704 do it, since we can't generate 32 bit code during a 16 bit
8707 /* We don't want the assembler to insert any nops here. */
8708 fprintf (asm_out_file
, "\t.set\tnoreorder\n");
8710 mips16_fp_args (asm_out_file
, fp_code
, 0);
8714 fprintf (asm_out_file
, "\t.set\tnoat\n");
8715 fprintf (asm_out_file
, "\tla\t%s,%s\n", reg_names
[GP_REG_FIRST
+ 1],
8717 fprintf (asm_out_file
, "\tjr\t%s\n", reg_names
[GP_REG_FIRST
+ 1]);
8718 fprintf (asm_out_file
, "\t.set\tat\n");
8719 /* Unfortunately, we can't fill the jump delay slot. We
8720 can't fill with one of the mtc1 instructions, because the
8721 result is not available for one instruction, so if the
8722 very first instruction in the function refers to the
8723 register, it will see the wrong value. */
8724 fprintf (asm_out_file
, "\tnop\n");
8728 fprintf (asm_out_file
, "\tmove\t%s,%s\n",
8729 reg_names
[GP_REG_FIRST
+ 18], reg_names
[GP_REG_FIRST
+ 31]);
8730 fprintf (asm_out_file
, "\tjal\t%s\n", fnname
);
8731 /* As above, we can't fill the delay slot. */
8732 fprintf (asm_out_file
, "\tnop\n");
8733 if (GET_MODE (retval
) == SFmode
)
8734 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
8735 reg_names
[GP_REG_FIRST
+ 2], reg_names
[FP_REG_FIRST
+ 0]);
8738 if (TARGET_BIG_ENDIAN
)
8740 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
8741 reg_names
[GP_REG_FIRST
+ 2],
8742 reg_names
[FP_REG_FIRST
+ 1]);
8743 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
8744 reg_names
[GP_REG_FIRST
+ 3],
8745 reg_names
[FP_REG_FIRST
+ 0]);
8749 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
8750 reg_names
[GP_REG_FIRST
+ 2],
8751 reg_names
[FP_REG_FIRST
+ 0]);
8752 fprintf (asm_out_file
, "\tmfc1\t%s,%s\n",
8753 reg_names
[GP_REG_FIRST
+ 3],
8754 reg_names
[FP_REG_FIRST
+ 1]);
8757 fprintf (asm_out_file
, "\tj\t%s\n", reg_names
[GP_REG_FIRST
+ 18]);
8758 /* As above, we can't fill the delay slot. */
8759 fprintf (asm_out_file
, "\tnop\n");
8762 fprintf (asm_out_file
, "\t.set\treorder\n");
8764 #ifdef ASM_DECLARE_FUNCTION_SIZE
8765 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, stubname
, stubdecl
);
8768 #ifndef FUNCTION_NAME_ALREADY_DECLARED
8769 fputs ("\t.end\t", asm_out_file
);
8770 assemble_name (asm_out_file
, stubname
);
8771 fputs ("\n", asm_out_file
);
8774 fprintf (asm_out_file
, "\t.set\tmips16\n");
8776 /* Record this stub. */
8777 l
= (struct mips16_stub
*) xmalloc (sizeof *l
);
8778 l
->name
= xstrdup (fnname
);
8780 l
->next
= mips16_stubs
;
8784 /* If we expect a floating point return value, but we've built a
8785 stub which does not expect one, then we're in trouble. We can't
8786 use the existing stub, because it won't handle the floating point
8787 value. We can't build a new stub, because the linker won't know
8788 which stub to use for the various calls in this object file.
8789 Fortunately, this case is illegal, since it means that a function
8790 was declared in two different ways in a single compilation. */
8791 if (fpret
&& ! l
->fpret
)
8792 error ("can not handle inconsistent calls to `%s'", fnname
);
8794 /* If we are calling a stub which handles a floating point return
8795 value, we need to arrange to save $18 in the prologue. We do
8796 this by marking the function call as using the register. The
8797 prologue will later see that it is used, and emit code to save
8804 if (retval
== NULL_RTX
)
8805 insn
= gen_call_internal0 (fnmem
, arg_size
,
8806 gen_rtx (REG
, SImode
,
8807 GP_REG_FIRST
+ 31));
8809 insn
= gen_call_value_internal0 (retval
, fnmem
, arg_size
,
8810 gen_rtx (REG
, SImode
,
8811 GP_REG_FIRST
+ 31));
8812 insn
= emit_call_insn (insn
);
8814 if (GET_CODE (insn
) != CALL_INSN
)
8817 CALL_INSN_FUNCTION_USAGE (insn
) =
8818 gen_rtx (EXPR_LIST
, VOIDmode
,
8819 gen_rtx (USE
, VOIDmode
, gen_rtx (REG
, word_mode
, 18)),
8820 CALL_INSN_FUNCTION_USAGE (insn
));
8822 /* Return 1 to tell the caller that we've generated the call
8827 /* Return 0 to let the caller generate the call insn. */
8831 /* This function looks through the code for a function, and tries to
8832 optimize the usage of the $gp register. We arrange to copy $gp
8833 into a pseudo-register, and then let gcc's normal reload handling
8834 deal with the pseudo-register. Unfortunately, if reload choose to
8835 put the pseudo-register into a call-clobbered register, it will
8836 emit saves and restores for that register around any function
8837 calls. We don't need the saves, and it's faster to copy $gp than
8838 to do an actual restore. ??? This still means that we waste a
8841 This is an optimization, and the code which gcc has actually
8842 generated is correct, so we do not need to catch all cases. */
8845 mips16_optimize_gp (first
)
8848 rtx gpcopy
, slot
, insn
;
8850 /* Look through the instructions. Set GPCOPY to the register which
8851 holds a copy of $gp. Set SLOT to the stack slot where it is
8852 saved. If we find an instruction which sets GPCOPY to anything
8853 other than $gp or SLOT, then we can't use it. If we find an
8854 instruction which sets SLOT to anything other than GPCOPY, we
8859 for (insn
= first
; insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
8863 if (! INSN_P (insn
))
8866 set
= PATTERN (insn
);
8868 /* We know that all references to memory will be inside a SET,
8869 because there is no other way to access memory on the mips16.
8870 We don't have to worry about a PARALLEL here, because the
8871 mips.md file will never generate them for memory references. */
8872 if (GET_CODE (set
) != SET
)
8875 if (gpcopy
== NULL_RTX
8876 && GET_CODE (SET_SRC (set
)) == CONST
8877 && GET_CODE (XEXP (SET_SRC (set
), 0)) == REG
8878 && REGNO (XEXP (SET_SRC (set
), 0)) == GP_REG_FIRST
+ 28
8879 && GET_CODE (SET_DEST (set
)) == REG
8880 && GET_MODE (SET_DEST (set
)) == (unsigned) Pmode
)
8881 gpcopy
= SET_DEST (set
);
8882 else if (slot
== NULL_RTX
8883 && gpcopy
!= NULL_RTX
8884 && GET_CODE (SET_DEST (set
)) == MEM
8885 && GET_CODE (SET_SRC (set
)) == REG
8886 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
)
8887 && GET_MODE (SET_DEST (set
)) == (unsigned) Pmode
)
8891 offset
= const0_rtx
;
8892 base
= eliminate_constant_term (XEXP (SET_DEST (set
), 0), &offset
);
8893 if (GET_CODE (base
) == REG
8894 && (REGNO (base
) == STACK_POINTER_REGNUM
8895 || REGNO (base
) == FRAME_POINTER_REGNUM
))
8896 slot
= SET_DEST (set
);
8898 else if (gpcopy
!= NULL_RTX
8899 && (GET_CODE (SET_DEST (set
)) == REG
8900 || GET_CODE (SET_DEST (set
)) == SUBREG
)
8901 && reg_overlap_mentioned_p (SET_DEST (set
), gpcopy
)
8902 && (GET_CODE (SET_DEST (set
)) != REG
8903 || REGNO (SET_DEST (set
)) != REGNO (gpcopy
)
8904 || GET_MODE (SET_DEST (set
)) != (unsigned) Pmode
8905 || ((GET_CODE (SET_SRC (set
)) != CONST
8906 || GET_CODE (XEXP (SET_SRC (set
), 0)) != REG
8907 || (REGNO (XEXP (SET_SRC (set
), 0))
8908 != GP_REG_FIRST
+ 28))
8909 && ! rtx_equal_p (SET_SRC (set
), slot
))))
8911 else if (slot
!= NULL_RTX
8912 && GET_CODE (SET_DEST (set
)) == MEM
8913 && rtx_equal_p (SET_DEST (set
), slot
)
8914 && (GET_CODE (SET_SRC (set
)) != REG
8915 || REGNO (SET_SRC (set
)) != REGNO (gpcopy
)))
8919 /* If we couldn't find a unique value for GPCOPY or SLOT, then try a
8920 different optimization. Any time we find a copy of $28 into a
8921 register, followed by an add of a symbol_ref to that register, we
8922 convert it to load the value from the constant table instead.
8923 The copy and add will take six bytes, just as the load and
8924 constant table entry will take six bytes. However, it is
8925 possible that the constant table entry will be shared.
8927 This could be a peephole optimization, but I don't know if the
8928 peephole code can call force_const_mem.
8930 Using the same register for the copy of $28 and the add of the
8931 symbol_ref is actually pretty likely, since the add instruction
8932 requires the destination and the first addend to be the same
8935 if (insn
!= NULL_RTX
|| gpcopy
== NULL_RTX
|| slot
== NULL_RTX
)
8939 /* This optimization is only reasonable if the constant table
8940 entries are only 4 bytes. */
8941 if (Pmode
!= SImode
)
8944 for (insn
= first
; insn
!= NULL_RTX
; insn
= next
)
8951 next
= NEXT_INSN (next
);
8953 while (next
!= NULL_RTX
8954 && (GET_CODE (next
) == NOTE
8955 || (GET_CODE (next
) == INSN
8956 && (GET_CODE (PATTERN (next
)) == USE
8957 || GET_CODE (PATTERN (next
)) == CLOBBER
))));
8959 if (next
== NULL_RTX
)
8962 if (! INSN_P (insn
))
8965 if (! INSN_P (next
))
8968 set1
= PATTERN (insn
);
8969 if (GET_CODE (set1
) != SET
)
8971 set2
= PATTERN (next
);
8972 if (GET_CODE (set2
) != SET
)
8975 if (GET_CODE (SET_DEST (set1
)) == REG
8976 && GET_CODE (SET_SRC (set1
)) == CONST
8977 && GET_CODE (XEXP (SET_SRC (set1
), 0)) == REG
8978 && REGNO (XEXP (SET_SRC (set1
), 0)) == GP_REG_FIRST
+ 28
8979 && rtx_equal_p (SET_DEST (set1
), SET_DEST (set2
))
8980 && GET_CODE (SET_SRC (set2
)) == PLUS
8981 && rtx_equal_p (SET_DEST (set1
), XEXP (SET_SRC (set2
), 0))
8982 && mips16_gp_offset_p (XEXP (SET_SRC (set2
), 1))
8983 && GET_CODE (XEXP (XEXP (SET_SRC (set2
), 1), 0)) == MINUS
)
8987 /* We've found a case we can change to load from the
8990 sym
= XEXP (XEXP (XEXP (SET_SRC (set2
), 1), 0), 0);
8991 if (GET_CODE (sym
) != SYMBOL_REF
)
8993 emit_insn_after (gen_rtx (SET
, VOIDmode
, SET_DEST (set1
),
8994 force_const_mem (Pmode
, sym
)),
8997 PUT_CODE (insn
, NOTE
);
8998 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
8999 NOTE_SOURCE_FILE (insn
) = 0;
9001 PUT_CODE (next
, NOTE
);
9002 NOTE_LINE_NUMBER (next
) = NOTE_INSN_DELETED
;
9003 NOTE_SOURCE_FILE (next
) = 0;
9010 /* We can safely remove all assignments to SLOT from GPCOPY, and
9011 replace all assignments from SLOT to GPCOPY with assignments from
9014 for (insn
= first
; insn
!= NULL_RTX
; insn
= next_active_insn (insn
))
9018 if (! INSN_P (insn
))
9021 set
= PATTERN (insn
);
9022 if (GET_CODE (set
) != SET
9023 || GET_MODE (SET_DEST (set
)) != (unsigned) Pmode
)
9026 if (GET_CODE (SET_DEST (set
)) == MEM
9027 && rtx_equal_p (SET_DEST (set
), slot
)
9028 && GET_CODE (SET_SRC (set
)) == REG
9029 && REGNO (SET_SRC (set
)) == REGNO (gpcopy
))
9031 PUT_CODE (insn
, NOTE
);
9032 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
9033 NOTE_SOURCE_FILE (insn
) = 0;
9035 else if (GET_CODE (SET_DEST (set
)) == REG
9036 && REGNO (SET_DEST (set
)) == REGNO (gpcopy
)
9037 && GET_CODE (SET_SRC (set
)) == MEM
9038 && rtx_equal_p (SET_SRC (set
), slot
))
9040 emit_insn_after (gen_rtx (SET
, Pmode
, SET_DEST (set
),
9041 gen_rtx (CONST
, Pmode
,
9042 gen_rtx (REG
, Pmode
,
9043 GP_REG_FIRST
+ 28))),
9045 PUT_CODE (insn
, NOTE
);
9046 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
9047 NOTE_SOURCE_FILE (insn
) = 0;
9052 /* We keep a list of constants we which we have to add to internal
9053 constant tables in the middle of large functions. */
9057 struct constant
*next
;
9060 enum machine_mode mode
;
9063 /* Add a constant to the list in *PCONSTANTS. */
9066 add_constant (pconstants
, val
, mode
)
9067 struct constant
**pconstants
;
9069 enum machine_mode mode
;
9073 for (c
= *pconstants
; c
!= NULL
; c
= c
->next
)
9074 if (mode
== c
->mode
&& rtx_equal_p (val
, c
->value
))
9077 c
= (struct constant
*) xmalloc (sizeof *c
);
9080 c
->label
= gen_label_rtx ();
9081 c
->next
= *pconstants
;
9086 /* Dump out the constants in CONSTANTS after INSN. */
9089 dump_constants (constants
, insn
)
9090 struct constant
*constants
;
9101 struct constant
*next
;
9103 switch (GET_MODE_SIZE (c
->mode
))
9110 insn
= emit_insn_after (gen_align_2 (), insn
);
9115 insn
= emit_insn_after (gen_align_4 (), insn
);
9120 insn
= emit_insn_after (gen_align_8 (), insn
);
9125 insn
= emit_label_after (c
->label
, insn
);
9130 r
= gen_consttable_qi (c
->value
);
9133 r
= gen_consttable_hi (c
->value
);
9136 r
= gen_consttable_si (c
->value
);
9139 r
= gen_consttable_sf (c
->value
);
9142 r
= gen_consttable_di (c
->value
);
9145 r
= gen_consttable_df (c
->value
);
9151 insn
= emit_insn_after (r
, insn
);
9158 emit_barrier_after (insn
);
9161 /* Find the symbol in an address expression. */
9164 mips_find_symbol (addr
)
9167 if (GET_CODE (addr
) == MEM
)
9168 addr
= XEXP (addr
, 0);
9169 while (GET_CODE (addr
) == CONST
)
9170 addr
= XEXP (addr
, 0);
9171 if (GET_CODE (addr
) == SYMBOL_REF
|| GET_CODE (addr
) == LABEL_REF
)
9173 if (GET_CODE (addr
) == PLUS
)
9177 l1
= mips_find_symbol (XEXP (addr
, 0));
9178 l2
= mips_find_symbol (XEXP (addr
, 1));
9179 if (l1
!= NULL_RTX
&& l2
== NULL_RTX
)
9181 else if (l1
== NULL_RTX
&& l2
!= NULL_RTX
)
9187 /* Exported to toplev.c.
9189 Do a final pass over the function, just before delayed branch
9193 machine_dependent_reorg (first
)
9196 int insns_len
, max_internal_pool_size
, pool_size
, addr
, first_constant_ref
;
9198 struct constant
*constants
;
9200 if (! TARGET_MIPS16
)
9203 /* If $gp is used, try to remove stores, and replace loads with
9206 mips16_optimize_gp (first
);
9208 /* Scan the function looking for PC relative loads which may be out
9209 of range. All such loads will either be from the constant table,
9210 or be getting the address of a constant string. If the size of
9211 the function plus the size of the constant table is less than
9212 0x8000, then all loads are in range. */
9215 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9217 insns_len
+= get_attr_length (insn
);
9219 /* ??? We put switch tables in .text, but we don't define
9220 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
9221 compute their lengths correctly. */
9222 if (GET_CODE (insn
) == JUMP_INSN
)
9226 body
= PATTERN (insn
);
9227 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
9228 insns_len
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
9229 * GET_MODE_SIZE (GET_MODE (body
)));
9230 insns_len
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
9234 /* Store the original value of insns_len in current_frame_info, so
9235 that simple_memory_operand can look at it. */
9236 current_frame_info
.insns_len
= insns_len
;
9238 pool_size
= get_pool_size ();
9239 if (insns_len
+ pool_size
+ mips_string_length
< 0x8000)
9242 /* Loop over the insns and figure out what the maximum internal pool
9244 max_internal_pool_size
= 0;
9245 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9247 if (GET_CODE (insn
) == INSN
9248 && GET_CODE (PATTERN (insn
)) == SET
)
9252 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
9253 if (src
== NULL_RTX
)
9255 if (CONSTANT_POOL_ADDRESS_P (src
))
9256 max_internal_pool_size
+= GET_MODE_SIZE (get_pool_mode (src
));
9257 else if (SYMBOL_REF_FLAG (src
))
9258 max_internal_pool_size
+= GET_MODE_SIZE (Pmode
);
9264 first_constant_ref
= -1;
9266 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
9268 if (GET_CODE (insn
) == INSN
9269 && GET_CODE (PATTERN (insn
)) == SET
)
9272 enum machine_mode mode
= VOIDmode
;
9275 src
= mips_find_symbol (SET_SRC (PATTERN (insn
)));
9276 if (src
!= NULL_RTX
&& CONSTANT_POOL_ADDRESS_P (src
))
9278 /* ??? This is very conservative, which means that we
9279 will generate too many copies of the constant table.
9280 The only solution would seem to be some form of
9282 if (((insns_len
- addr
)
9283 + max_internal_pool_size
9284 + get_pool_offset (src
))
9287 val
= get_pool_constant (src
);
9288 mode
= get_pool_mode (src
);
9290 max_internal_pool_size
-= GET_MODE_SIZE (get_pool_mode (src
));
9292 else if (src
!= NULL_RTX
&& SYMBOL_REF_FLAG (src
))
9294 /* Including all of mips_string_length is conservative,
9295 and so is including all of max_internal_pool_size. */
9296 if (((insns_len
- addr
)
9297 + max_internal_pool_size
9299 + mips_string_length
)
9305 max_internal_pool_size
-= Pmode
;
9308 if (val
!= NULL_RTX
)
9312 /* This PC relative load is out of range. ??? In the
9313 case of a string constant, we are only guessing that
9314 it is range, since we don't know the offset of a
9315 particular string constant. */
9317 lab
= add_constant (&constants
, val
, mode
);
9318 newsrc
= gen_rtx (MEM
, mode
,
9319 gen_rtx (LABEL_REF
, VOIDmode
, lab
));
9320 RTX_UNCHANGING_P (newsrc
) = 1;
9321 PATTERN (insn
) = gen_rtx (SET
, VOIDmode
,
9322 SET_DEST (PATTERN (insn
)),
9324 INSN_CODE (insn
) = -1;
9326 if (first_constant_ref
< 0)
9327 first_constant_ref
= addr
;
9331 addr
+= get_attr_length (insn
);
9333 /* ??? We put switch tables in .text, but we don't define
9334 JUMP_TABLES_IN_TEXT_SECTION, so get_attr_length will not
9335 compute their lengths correctly. */
9336 if (GET_CODE (insn
) == JUMP_INSN
)
9340 body
= PATTERN (insn
);
9341 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
9342 addr
+= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
9343 * GET_MODE_SIZE (GET_MODE (body
)));
9344 addr
+= GET_MODE_SIZE (GET_MODE (body
)) - 1;
9347 if (GET_CODE (insn
) == BARRIER
)
9349 /* Output any constants we have accumulated. Note that we
9350 don't need to change ADDR, since its only use is
9351 subtraction from INSNS_LEN, and both would be changed by
9353 ??? If the instructions up to the next barrier reuse a
9354 constant, it would often be better to continue
9356 if (constants
!= NULL
)
9357 dump_constants (constants
, insn
);
9359 first_constant_ref
= -1;
9362 if (constants
!= NULL
9363 && (NEXT_INSN (insn
) == NULL
9364 || (first_constant_ref
>= 0
9365 && (((addr
- first_constant_ref
)
9366 + 2 /* for alignment */
9367 + 2 /* for a short jump insn */
9371 /* If we haven't had a barrier within 0x8000 bytes of a
9372 constant reference or we are at the end of the function,
9373 emit a barrier now. */
9375 rtx label
, jump
, barrier
;
9377 label
= gen_label_rtx ();
9378 jump
= emit_jump_insn_after (gen_jump (label
), insn
);
9379 JUMP_LABEL (jump
) = label
;
9380 LABEL_NUSES (label
) = 1;
9381 barrier
= emit_barrier_after (jump
);
9382 emit_label_after (label
, barrier
);
9383 first_constant_ref
= -1;
9387 /* ??? If we output all references to a constant in internal
9388 constants table, we don't need to output the constant in the real
9389 constant table, but we have no way to prevent that. */
9392 /* Return nonzero if X is a SIGN or ZERO extend operator. */
9394 extend_operator (x
, mode
)
9396 enum machine_mode mode ATTRIBUTE_UNUSED
;
9398 enum rtx_code code
= GET_CODE (x
);
9399 return code
== SIGN_EXTEND
|| code
== ZERO_EXTEND
;
9402 /* Accept any operator that can be used to shift the high half of the
9403 input value to the lower half, suitable for truncation. The
9404 remainder (the lower half of the input, and the upper half of the
9405 output) will be discarded. */
9407 highpart_shift_operator (x
, mode
)
9409 enum machine_mode mode ATTRIBUTE_UNUSED
;
9411 enum rtx_code code
= GET_CODE (x
);
9412 return (code
== LSHIFTRT
9418 /* Return the length of INSN. LENGTH is the initial length computed by
9419 attributes in the machine-description file. */
9422 mips_adjust_insn_length (insn
, length
)
9426 /* A unconditional jump has an unfilled delay slot if it is not part
9427 of a sequence. A conditional jump normally has a delay slot, but
9428 does not on MIPS16. */
9429 if (simplejump_p (insn
)
9430 || (!TARGET_MIPS16
&& (GET_CODE (insn
) == JUMP_INSN
9431 || GET_CODE (insn
) == CALL_INSN
)))
9434 /* All MIPS16 instructions are a measly two bytes. */
9441 /* Output assembly instructions to peform a conditional branch.
9443 INSN is the branch instruction. OPERANDS[0] is the condition.
9444 OPERANDS[1] is the target of the branch. OPERANDS[2] is the target
9445 of the first operand to the condition. If TWO_OPERANDS_P is
9446 non-zero the comparison takes two operands; OPERANDS[3] will be the
9449 If INVERTED_P is non-zero we are to branch if the condition does
9450 not hold. If FLOAT_P is non-zero this is a floating-point comparison.
9452 LENGTH is the length (in bytes) of the sequence we are to generate.
9453 That tells us whether to generate a simple conditional branch, or a
9454 reversed conditional branch around a `jr' instruction. */
9456 mips_output_conditional_branch (insn
,
9469 static char buffer
[200];
9470 /* The kind of comparison we are doing. */
9471 enum rtx_code code
= GET_CODE (operands
[0]);
9472 /* Non-zero if the opcode for the comparison needs a `z' indicating
9473 that it is a comparision against zero. */
9475 /* A string to use in the assembly output to represent the first
9477 const char *op1
= "%z2";
9478 /* A string to use in the assembly output to represent the second
9479 operand. Use the hard-wired zero register if there's no second
9481 const char *op2
= (two_operands_p
? ",%z3" : ",%.");
9482 /* The operand-printing string for the comparison. */
9483 const char *comp
= (float_p
? "%F0" : "%C0");
9484 /* The operand-printing string for the inverted comparison. */
9485 const char *inverted_comp
= (float_p
? "%W0" : "%N0");
9487 /* The MIPS processors (for levels of the ISA at least two), have
9488 "likely" variants of each branch instruction. These instructions
9489 annul the instruction in the delay slot if the branch is not
9491 mips_branch_likely
= (final_sequence
&& INSN_ANNULLED_BRANCH_P (insn
));
9493 if (!two_operands_p
)
9495 /* To compute whether than A > B, for example, we normally
9496 subtract B from A and then look at the sign bit. But, if we
9497 are doing an unsigned comparison, and B is zero, we don't
9498 have to do the subtraction. Instead, we can just check to
9499 see if A is non-zero. Thus, we change the CODE here to
9500 reflect the simpler comparison operation. */
9512 /* A condition which will always be true. */
9518 /* A condition which will always be false. */
9524 /* Not a special case. */
9529 /* Relative comparisons are always done against zero. But
9530 equality comparisons are done between two operands, and therefore
9531 do not require a `z' in the assembly language output. */
9532 need_z_p
= (!float_p
&& code
!= EQ
&& code
!= NE
);
9533 /* For comparisons against zero, the zero is not provided
9538 /* Begin by terminating the buffer. That way we can always use
9539 strcat to add to it. */
9546 /* Just a simple conditional branch. */
9548 sprintf (buffer
, "%%*b%s%%?\t%%Z2%%1",
9549 inverted_p
? inverted_comp
: comp
);
9551 sprintf (buffer
, "%%*b%s%s%%?\t%s%s,%%1",
9552 inverted_p
? inverted_comp
: comp
,
9553 need_z_p
? "z" : "",
9561 /* Generate a reversed conditional branch around ` j'
9573 Because we have to jump four bytes *past* the following
9574 instruction if this branch was annulled, we can't just use
9575 a label, as in the picture above; there's no way to put the
9576 label after the next instruction, as the assembler does not
9577 accept `.L+4' as the target of a branch. (We can't just
9578 wait until the next instruction is output; it might be a
9579 macro and take up more than four bytes. Once again, we see
9580 why we want to eliminate macros.)
9582 If the branch is annulled, we jump four more bytes that we
9583 would otherwise; that way we skip the annulled instruction
9584 in the delay slot. */
9587 = ((mips_branch_likely
|| length
== 16) ? ".+16" : ".+12");
9590 strcpy (buffer
, "%(%<");
9591 c
= strchr (buffer
, '\0');
9592 /* Generate the reversed comparision. This takes four
9595 sprintf (c
, "%%*b%s\t%%Z2%s",
9596 inverted_p
? comp
: inverted_comp
,
9599 sprintf (c
, "%%*b%s%s\t%s%s,%s",
9600 inverted_p
? comp
: inverted_comp
,
9601 need_z_p
? "z" : "",
9605 strcat (c
, "\n\tnop\n\tj\t%1");
9607 /* The delay slot was unfilled. Since we're inside
9608 .noreorder, the assembler will not fill in the NOP for
9609 us, so we must do it ourselves. */
9610 strcat (buffer
, "\n\tnop");
9611 strcat (buffer
, "%>%)");
9615 /* We do not currently use this code. It handles jumps to
9616 arbitrary locations, using `jr', even across a 256MB boundary.
9617 We could add a -mhuge switch, and then use this code instead of
9618 the `j' alternative above when -mhuge was used. */
9623 /* Generate a reversed conditional branch around a `jr'
9637 Not pretty, but allows a conditional branch anywhere in the
9638 32-bit address space. If the original branch is annulled,
9639 then the instruction in the delay slot should be executed
9640 only if the branch is taken. The la instruction is really
9641 a macro which will usually take eight bytes, but sometimes
9642 takes only four, if the instruction to which we're jumping
9643 gets its own entry in the global pointer table, which will
9644 happen if its a case label. The assembler will then
9645 generate only a four-byte sequence, rather than eight, and
9646 there seems to be no way to tell it not to. Thus, we can't
9647 just use a `.+x' addressing form; we don't know what value
9650 So, we resort to using the explicit relocation syntax
9651 available in the assembler and do:
9653 lw $at,%got_page(target)($gp)
9654 daddiu $at,$at,%got_ofst(target)
9656 That way, this always takes up eight bytes, and we can use
9657 the `.+x' form. Of course, these explicit machinations
9658 with relocation will not work with old assemblers. Then
9659 again, neither do out-of-range branches, so we haven't lost
9662 /* The target of the reversed branch. */
9664 = ((mips_branch_likely
|| length
== 20) ? ".+20" : ".+16");
9665 const char *at_register
= mips_reg_names
[ASSEMBLER_SCRATCH_REGNUM
];
9666 const char *gp_register
= mips_reg_names
[PIC_OFFSET_TABLE_REGNUM
];
9669 strcpy (buffer
, "%(%<%[");
9670 c
= strchr (buffer
, '\0');
9671 /* Generate the reversed comparision. This takes four
9674 sprintf (c
, "%%*b%s\t%%Z2%s",
9675 inverted_p
? comp
: inverted_comp
,
9678 sprintf (c
, "%%*b%s%s\t%s%s,%s",
9679 inverted_p
? comp
: inverted_comp
,
9680 need_z_p
? "z" : "",
9684 c
= strchr (buffer
, '\0');
9685 /* Generate the load-address, and jump. This takes twelve
9686 bytes, for a total of 16. */
9688 "\n\tlw\t%s,%%%%got_page(%%1)(%s)\n\tdaddiu\t%s,%s,%%%%got_ofst(%%1)\n\tjr\t%s",
9695 /* The delay slot was unfilled. Since we're inside
9696 .noreorder, the assembler will not fill in the NOP for
9697 us, so we must do it ourselves. */
9698 strcat (buffer
, "\n\tnop");
9699 strcat (buffer
, "%]%>%)");
9712 /* Called to register all of our global variables with the garbage
9716 mips_add_gc_roots ()
9718 ggc_add_rtx_root (&mips_load_reg
, 1);
9719 ggc_add_rtx_root (&mips_load_reg2
, 1);
9720 ggc_add_rtx_root (&mips_load_reg3
, 1);
9721 ggc_add_rtx_root (&mips_load_reg4
, 1);
9722 ggc_add_rtx_root (branch_cmp
, sizeof (branch_cmp
) / sizeof (rtx
));
9723 ggc_add_rtx_root (&embedded_pic_fnaddr_rtx
, 1);
9724 ggc_add_rtx_root (&mips16_gp_pseudo_rtx
, 1);
9727 static enum processor_type
9728 mips_parse_cpu (cpu_string
)
9729 const char *cpu_string
;
9731 const char *p
= cpu_string
;
9733 enum processor_type cpu
;
9735 /* We need to cope with the various "vr" prefixes for the NEC 4300
9736 and 4100 processors. */
9737 if (*p
== 'v' || *p
== 'V')
9740 if (*p
== 'r' || *p
== 'R')
9743 /* Since there is no difference between a R2000 and R3000 in
9744 terms of the scheduler, we collapse them into just an R3000. */
9746 cpu
= PROCESSOR_DEFAULT
;
9750 if (!strcmp (p
, "2000") || !strcmp (p
, "2k") || !strcmp (p
, "2K"))
9751 cpu
= PROCESSOR_R3000
;
9755 if (!strcmp (p
, "3000") || !strcmp (p
, "3k") || !strcmp (p
, "3K"))
9756 cpu
= PROCESSOR_R3000
;
9757 else if (!strcmp (p
, "3900"))
9758 cpu
= PROCESSOR_R3900
;
9762 if (!strcmp (p
, "4000") || !strcmp (p
, "4k") || !strcmp (p
, "4K"))
9763 cpu
= PROCESSOR_R4000
;
9764 /* The vr4100 is a non-FP ISA III processor with some extra
9766 else if (!strcmp (p
, "4100"))
9767 cpu
= PROCESSOR_R4100
;
9768 /* The vr4300 is a standard ISA III processor, but with a different
9770 else if (!strcmp (p
, "4300"))
9771 cpu
= PROCESSOR_R4300
;
9772 /* The r4400 is exactly the same as the r4000 from the compiler's
9774 else if (!strcmp (p
, "4400"))
9775 cpu
= PROCESSOR_R4000
;
9776 else if (!strcmp (p
, "4600"))
9777 cpu
= PROCESSOR_R4600
;
9778 else if (!strcmp (p
, "4650"))
9779 cpu
= PROCESSOR_R4650
;
9783 if (!strcmp (p
, "5000") || !strcmp (p
, "5k") || !strcmp (p
, "5K"))
9784 cpu
= PROCESSOR_R5000
;
9788 if (!strcmp (p
, "6000") || !strcmp (p
, "6k") || !strcmp (p
, "6K"))
9789 cpu
= PROCESSOR_R6000
;
9793 if (!strcmp (p
, "8000"))
9794 cpu
= PROCESSOR_R8000
;
9798 if (!strcmp (p
, "orion"))
9799 cpu
= PROCESSOR_R4600
;
9804 && cpu
!= PROCESSOR_R4300
9805 && cpu
!= PROCESSOR_R4100
9806 && cpu
!= PROCESSOR_R5000
)
9807 cpu
= PROCESSOR_DEFAULT
;