LoongArch: Allow s9 as a register alias
[official-gcc.git] / gcc / config / loongarch / loongarch.h
blobbf2351f0968fc741a8bee4c018e680995567a9bf
1 /* Definitions of target machine for GNU compiler. LoongArch version.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 Contributed by Loongson Ltd.
4 Based on MIPS and RISC-V target for GNU compiler.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* LoongArch external variables defined in loongarch.cc. */
24 #include "config/loongarch/loongarch-opts.h"
26 #define TARGET_SUPPORTS_WIDE_INT 1
28 /* Macros to silence warnings about numbers being signed in traditional
29 C and unsigned in ISO C when compiled on 32-bit hosts. */
31 #define BITMASK_HIGH (((unsigned long) 1) << 31) /* 0x80000000 */
33 /* Run-time compilation parameters selecting different hardware subsets. */
35 /* Target CPU builtins. */
36 #define TARGET_CPU_CPP_BUILTINS() loongarch_cpu_cpp_builtins (pfile)
38 /* Default target_flags if no switches are specified. */
40 #ifdef IN_LIBGCC2
41 #undef TARGET_64BIT
42 /* Make this compile time constant for libgcc2. */
43 #ifdef __loongarch64
44 #define TARGET_64BIT 1
45 #else
46 #define TARGET_64BIT 0
47 #endif
48 #endif /* IN_LIBGCC2 */
50 #define TARGET_LIBGCC_SDATA_SECTION ".sdata"
52 /* This definition replaces the formerly used 'm' constraint with a
53 different constraint letter in order to avoid changing semantics of
54 the 'm' constraint when accepting new address formats in
55 TARGET_LEGITIMATE_ADDRESS_P. The constraint letter defined here
56 must not be used in insn definitions or inline assemblies. */
57 #define TARGET_MEM_CONSTRAINT 'w'
59 /* Tell collect what flags to pass to nm. */
60 #ifndef NM_FLAGS
61 #define NM_FLAGS "-Bn"
62 #endif
64 /* Registers may have a prefix which can be ignored when matching
65 user asm and register definitions. */
66 #ifndef REGISTER_PREFIX
67 #define REGISTER_PREFIX "$"
68 #endif
70 /* Local compiler-generated symbols must have a prefix that the assembler
71 understands. */
73 #define LOCAL_LABEL_PREFIX "."
75 /* By default on the loongarch, external symbols do not have an underscore
76 prepended. */
78 #define USER_LABEL_PREFIX ""
80 #ifndef PREFERRED_DEBUGGING_TYPE
81 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
82 #endif
84 /* The size of DWARF addresses should be the same as the size of symbols
85 in the target file format. */
86 #define DWARF2_ADDR_SIZE (TARGET_64BIT ? 8 : 4)
88 /* By default, turn on GDB extensions. */
89 #define DEFAULT_GDB_EXTENSIONS 1
91 /* By default, produce dwarf version 2 format debugging output in response
92 to the ā€˜-gā€™ option. */
93 #define DWARF2_DEBUGGING_INFO 1
95 /* The mapping from gcc register number to DWARF 2 CFA column number. */
96 #define DWARF_FRAME_REGNUM(REGNO) loongarch_dwarf_regno[REGNO]
98 /* The DWARF 2 CFA column which tracks the return address. */
99 #define DWARF_FRAME_RETURN_COLUMN RETURN_ADDR_REGNUM
101 /* Before the prologue, RA lives in r1. */
102 #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)
104 /* Describe how we implement __builtin_eh_return. */
105 #define EH_RETURN_DATA_REGNO(N) \
106 ((N) < (4) ? (N) + GP_ARG_FIRST : INVALID_REGNUM)
108 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, GP_ARG_FIRST + 4)
110 #define EH_USES(N) loongarch_eh_uses (N)
112 /* Offsets recorded in opcodes are a multiple of this alignment factor.
113 The default for this in 64-bit mode is 8, which causes problems with
114 SFmode register saves. */
115 #define DWARF_CIE_DATA_ALIGNMENT -4
117 /* Target machine storage layout. */
119 #define BITS_BIG_ENDIAN 0
120 #define BYTES_BIG_ENDIAN 0
121 #define WORDS_BIG_ENDIAN 0
123 #define MAX_BITS_PER_WORD 64
125 /* Width of a word, in units (bytes). */
126 #define UNITS_PER_WORD (TARGET_64BIT ? 8 : 4)
127 #ifndef IN_LIBGCC2
128 #define MIN_UNITS_PER_WORD 4
129 #endif
131 /* Width of a LSX vector register in bytes. */
132 #define UNITS_PER_LSX_REG 16
133 /* Width of a LSX vector register in bits. */
134 #define BITS_PER_LSX_REG (UNITS_PER_LSX_REG * BITS_PER_UNIT)
136 /* Width of a LASX vector register in bytes. */
137 #define UNITS_PER_LASX_REG 32
138 /* Width of a LASX vector register in bits. */
139 #define BITS_PER_LASX_REG (UNITS_PER_LASX_REG * BITS_PER_UNIT)
141 /* For LARCH, width of a floating point register. */
142 #define UNITS_PER_FPREG (TARGET_DOUBLE_FLOAT ? 8 : 4)
144 /* The largest size of value that can be held in floating-point
145 registers and moved with a single instruction. */
146 #define UNITS_PER_HWFPVALUE \
147 (TARGET_SOFT_FLOAT ? 0 : UNITS_PER_FPREG)
149 /* The largest size of value that can be held in floating-point
150 registers. */
151 #define UNITS_PER_FPVALUE \
152 (TARGET_SOFT_FLOAT ? 0 \
153 : TARGET_SINGLE_FLOAT ? UNITS_PER_FPREG \
154 : LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
156 /* The number of bytes in a double. */
157 #define UNITS_PER_DOUBLE (TYPE_PRECISION (double_type_node) / BITS_PER_UNIT)
159 /* Set the sizes of the core types. */
160 #define SHORT_TYPE_SIZE 16
161 #define INT_TYPE_SIZE 32
162 #define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32)
163 #define LONG_LONG_TYPE_SIZE 64
165 #define FLOAT_TYPE_SIZE 32
166 #define DOUBLE_TYPE_SIZE 64
167 #define LONG_DOUBLE_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
169 /* Define the sizes of fixed-point types. */
170 #define SHORT_FRACT_TYPE_SIZE 8
171 #define FRACT_TYPE_SIZE 16
172 #define LONG_FRACT_TYPE_SIZE 32
173 #define LONG_LONG_FRACT_TYPE_SIZE 64
175 #define SHORT_ACCUM_TYPE_SIZE 16
176 #define ACCUM_TYPE_SIZE 32
177 #define LONG_ACCUM_TYPE_SIZE 64
178 #define LONG_LONG_ACCUM_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
180 /* long double is not a fixed mode, but the idea is that, if we
181 support long double, we also want a 128-bit integer type. */
182 #define MAX_FIXED_MODE_SIZE LONG_DOUBLE_TYPE_SIZE
184 /* Width in bits of a pointer. */
185 #ifndef POINTER_SIZE
186 #define POINTER_SIZE (TARGET_64BIT ? 64 : 32)
187 #endif
189 /* Allocation boundary (in *bits*) for storing arguments in argument list. */
190 #define PARM_BOUNDARY BITS_PER_WORD
192 /* Allocation boundary (in *bits*) for the code of a function. */
193 #define FUNCTION_BOUNDARY 32
195 /* Alignment of field after `int : 0' in a structure. */
196 #define EMPTY_FIELD_BOUNDARY 32
198 /* Number of bits which any structure or union's size must be a multiple of.
199 Each structure or union's size is rounded up to a multiple of this. */
200 #define STRUCTURE_SIZE_BOUNDARY 8
202 /* There is no point aligning anything to a rounder boundary than
203 LONG_DOUBLE_TYPE_SIZE, unless under LSX/LASX the bigggest alignment is
204 BITS_PER_LSX_REG/BITS_PER_LASX_REG/.. */
205 #define BIGGEST_ALIGNMENT \
206 (ISA_HAS_LASX? BITS_PER_LASX_REG \
207 : (ISA_HAS_LSX ? BITS_PER_LSX_REG : LONG_DOUBLE_TYPE_SIZE))
209 /* All accesses must be aligned. */
210 #define STRICT_ALIGNMENT (TARGET_STRICT_ALIGN)
212 /* Define this if you wish to imitate the way many other C compilers
213 handle alignment of bitfields and the structures that contain
214 them.
216 The behavior is that the type written for a bit-field (`int',
217 `short', or other integer type) imposes an alignment for the
218 entire structure, as if the structure really did contain an
219 ordinary field of that type. In addition, the bit-field is placed
220 within the structure so that it would fit within such a field,
221 not crossing a boundary for it.
223 Thus, on most machines, a bit-field whose type is written as `int'
224 would not cross a four-byte boundary, and would force four-byte
225 alignment for the whole structure. (The alignment used may not
226 be four bytes; it is controlled by the other alignment
227 parameters.)
229 If the macro is defined, its definition should be a C expression;
230 a nonzero value for the expression enables this behavior. */
232 #define PCC_BITFIELD_TYPE_MATTERS 1
234 /* If defined, a C expression to compute the alignment for a static
235 variable. TYPE is the data type, and ALIGN is the alignment that
236 the object would ordinarily have. The value of this macro is used
237 instead of that alignment to align the object.
239 If this macro is not defined, then ALIGN is used.
241 One use of this macro is to increase alignment of medium-size
242 data to make it all fit in fewer cache lines. Another is to
243 cause character arrays to be word-aligned so that `strcpy' calls
244 that copy constants to character arrays can be done inline. */
246 #undef DATA_ALIGNMENT
247 #define DATA_ALIGNMENT(TYPE, ALIGN) \
248 ((((ALIGN) < BITS_PER_WORD) \
249 && (TREE_CODE (TYPE) == ARRAY_TYPE \
250 || TREE_CODE (TYPE) == UNION_TYPE \
251 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
253 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
254 character arrays to be word-aligned so that `strcpy' calls that copy
255 constants to character arrays can be done inline, and 'strcmp' can be
256 optimised to use word loads. */
257 #define LOCAL_ALIGNMENT(TYPE, ALIGN) DATA_ALIGNMENT (TYPE, ALIGN)
259 /* Define if operations between registers always perform the operation
260 on the full register even if a narrower mode is specified. */
261 #define WORD_REGISTER_OPERATIONS 1
263 /* When in 64-bit mode, move insns will sign extend SImode and FCCmode
264 moves. All other references are zero extended. */
265 #define LOAD_EXTEND_OP(MODE) \
266 (TARGET_64BIT && ((MODE) == SImode || (MODE) == FCCmode) ? SIGN_EXTEND \
267 : ZERO_EXTEND)
269 /* Define this macro if it is advisable to hold scalars in registers
270 in a wider mode than that declared by the program. In such cases,
271 the value is constrained to be within the bounds of the declared
272 type, but kept valid in the wider mode. The signedness of the
273 extension may differ from that of the type. */
275 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
276 if (GET_MODE_CLASS (MODE) == MODE_INT \
277 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
279 if ((MODE) == SImode) \
280 (UNSIGNEDP) = 0; \
281 (MODE) = Pmode; \
284 /* Pmode is always the same as ptr_mode, but not always the same as word_mode.
285 Extensions of pointers to word_mode must be signed. */
286 #define POINTERS_EXTEND_UNSIGNED false
288 /* Define if loading short immediate values into registers sign extends. */
289 #define SHORT_IMMEDIATES_SIGN_EXTEND 1
291 /* The clz.{w/d}, ctz.{w/d} instructions have the natural values at 0. */
293 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
294 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
295 #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
296 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
298 /* Standard register usage. */
300 /* Number of hardware registers. We have:
302 - 32 integer registers
303 - 32 floating point registers
304 - 8 condition code registers
305 - 2 fake registers:
306 - ARG_POINTER_REGNUM
307 - FRAME_POINTER_REGNUM
310 #define FIRST_PSEUDO_REGISTER 74
312 /* zero, tp, sp and x are fixed. */
313 #define FIXED_REGISTERS \
314 { /* General registers. */ \
315 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
316 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
317 /* Floating-point registers. */ \
318 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
319 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
320 /* Others. */ \
321 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}
323 /* The call RTLs themselves clobber ra. */
324 #define CALL_USED_REGISTERS \
325 { /* General registers. */ \
326 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
327 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
328 /* Floating-point registers. */ \
329 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
330 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, \
331 /* Others. */ \
332 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
334 /* Internal macros to classify a register number as to whether it's a
335 general purpose register, a floating point register, or a status
336 register. */
338 #define GP_REG_FIRST 0
339 #define GP_REG_LAST 31
340 #define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1)
342 #define FP_REG_FIRST 32
343 #define FP_REG_LAST 63
344 #define FP_REG_NUM (FP_REG_LAST - FP_REG_FIRST + 1)
345 #define LSX_REG_FIRST FP_REG_FIRST
346 #define LSX_REG_LAST FP_REG_LAST
347 #define LSX_REG_NUM FP_REG_NUM
349 #define LASX_REG_FIRST FP_REG_FIRST
350 #define LASX_REG_LAST FP_REG_LAST
351 #define LASX_REG_NUM FP_REG_NUM
353 /* The DWARF 2 CFA column which tracks the return address from a
354 signal handler context. This means that to maintain backwards
355 compatibility, no hard register can be assigned this column if it
356 would need to be handled by the DWARF unwinder. */
357 #define DWARF_ALT_FRAME_RETURN_COLUMN 72
359 #define FCC_REG_FIRST 64
360 #define FCC_REG_LAST 71
361 #define FCC_REG_NUM (FCC_REG_LAST - FCC_REG_FIRST + 1)
363 #define GP_REG_P(REGNO) \
364 ((unsigned int) ((int) (REGNO) - GP_REG_FIRST) < GP_REG_NUM)
365 #define FP_REG_P(REGNO) \
366 ((unsigned int) ((int) (REGNO) - FP_REG_FIRST) < FP_REG_NUM)
367 #define FCC_REG_P(REGNO) \
368 ((unsigned int) ((int) (REGNO) - FCC_REG_FIRST) < FCC_REG_NUM)
369 #define LSX_REG_P(REGNO) \
370 ((unsigned int) ((int) (REGNO) - LSX_REG_FIRST) < LSX_REG_NUM)
371 #define LASX_REG_P(REGNO) \
372 ((unsigned int) ((int) (REGNO) - LASX_REG_FIRST) < LASX_REG_NUM)
374 #define FP_REG_RTX_P(X) (REG_P (X) && FP_REG_P (REGNO (X)))
375 #define LSX_REG_RTX_P(X) (REG_P (X) && LSX_REG_P (REGNO (X)))
376 #define LASX_REG_RTX_P(X) (REG_P (X) && LASX_REG_P (REGNO (X)))
378 /* Select a register mode required for caller save of hard regno REGNO. */
379 #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
380 loongarch_hard_regno_caller_save_mode (REGNO, NREGS, MODE)
382 /* Register to use for pushing function arguments. */
383 #define STACK_POINTER_REGNUM (GP_REG_FIRST + 3)
385 /* These two registers don't really exist: they get eliminated to either
386 the stack or hard frame pointer. */
387 #define ARG_POINTER_REGNUM 72
388 #define FRAME_POINTER_REGNUM 73
390 #define HARD_FRAME_POINTER_REGNUM (GP_REG_FIRST + 22)
392 #define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
393 #define HARD_FRAME_POINTER_IS_ARG_POINTER 0
395 /* Register in which static-chain is passed to a function. */
396 #define STATIC_CHAIN_REGNUM (GP_REG_FIRST + 20) /* $t8 */
398 #define GP_TEMP_FIRST (GP_REG_FIRST + 12)
399 #define LARCH_PROLOGUE_TEMP_REGNUM (GP_TEMP_FIRST + 1)
400 #define LARCH_PROLOGUE_TEMP2_REGNUM (GP_TEMP_FIRST)
401 #define LARCH_PROLOGUE_TEMP3_REGNUM (GP_TEMP_FIRST + 2)
402 #define LARCH_EPILOGUE_TEMP_REGNUM (GP_TEMP_FIRST)
404 #define CALLEE_SAVED_REG_NUMBER(REGNO) \
405 ((REGNO) >= 22 && (REGNO) <= 31 ? (REGNO) - 22 : -1)
407 #define LARCH_PROLOGUE_TEMP(MODE) \
408 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP_REGNUM)
409 #define LARCH_PROLOGUE_TEMP2(MODE) \
410 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP2_REGNUM)
411 #define LARCH_PROLOGUE_TEMP3(MODE) \
412 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP3_REGNUM)
413 #define LARCH_EPILOGUE_TEMP(MODE) \
414 gen_rtx_REG (MODE, LARCH_EPILOGUE_TEMP_REGNUM)
416 /* Define this macro if it is as good or better to call a constant
417 function address than to call an address kept in a register. */
418 #define NO_FUNCTION_CSE 1
420 #define THREAD_POINTER_REGNUM (GP_REG_FIRST + 2)
422 /* Define the classes of registers for register constraints in the
423 machine description. Also define ranges of constants.
425 One of the classes must always be named ALL_REGS and include all hard regs.
426 If there is more than one class, another class must be named NO_REGS
427 and contain no registers.
429 The name GENERAL_REGS must be the name of a class (or an alias for
430 another name such as ALL_REGS). This is the class of registers
431 that is allowed by "r" in a register constraint.
432 Also, registers outside this class are allocated only when
433 instructions express preferences for them.
435 The classes must be numbered in nondecreasing order; that is,
436 a larger-numbered class must never be contained completely
437 in a smaller-numbered class.
439 For any two classes, it is very desirable that there be another
440 class that represents their union. */
442 enum reg_class
444 NO_REGS, /* no registers in set */
445 SIBCALL_REGS, /* registers used by indirect sibcalls */
446 JIRL_REGS, /* registers used by indirect calls */
447 CSR_REGS, /* integer registers except for $r0 and $r1 for lcsr. */
448 GR_REGS, /* integer registers */
449 FP_REGS, /* floating point registers */
450 FCC_REGS, /* status registers (fp status) */
451 FRAME_REGS, /* arg pointer and frame pointer */
452 ALL_REGS, /* all registers */
453 LIM_REG_CLASSES /* max value + 1 */
456 #define N_REG_CLASSES (int) LIM_REG_CLASSES
458 #define GENERAL_REGS GR_REGS
460 /* An initializer containing the names of the register classes as C
461 string constants. These names are used in writing some of the
462 debugging dumps. */
464 #define REG_CLASS_NAMES \
466 "NO_REGS", \
467 "SIBCALL_REGS", \
468 "JIRL_REGS", \
469 "CSR_REGS", \
470 "GR_REGS", \
471 "FP_REGS", \
472 "FCC_REGS", \
473 "FRAME_REGS", \
474 "ALL_REGS" \
477 /* An initializer containing the contents of the register classes,
478 as integers which are bit masks. The Nth integer specifies the
479 contents of class N. The way the integer MASK is interpreted is
480 that register R is in the class if `MASK & (1 << R)' is 1.
482 When the machine has more than 32 registers, an integer does not
483 suffice. Then the integers are replaced by sub-initializers,
484 braced groupings containing several integers. Each
485 sub-initializer must be suitable as an initializer for the type
486 `HARD_REG_SET' which is defined in `hard-reg-set.h'. */
488 #define REG_CLASS_CONTENTS \
490 { 0x00000000, 0x00000000, 0x00000000 }, /* NO_REGS */ \
491 { 0x001fd000, 0x00000000, 0x00000000 }, /* SIBCALL_REGS */ \
492 { 0xff9ffff0, 0x00000000, 0x00000000 }, /* JIRL_REGS */ \
493 { 0xfffffffc, 0x00000000, 0x00000000 }, /* CSR_REGS */ \
494 { 0xffffffff, 0x00000000, 0x00000000 }, /* GR_REGS */ \
495 { 0x00000000, 0xffffffff, 0x00000000 }, /* FP_REGS */ \
496 { 0x00000000, 0x00000000, 0x000000ff }, /* FCC_REGS */ \
497 { 0x00000000, 0x00000000, 0x00000300 }, /* FRAME_REGS */ \
498 { 0xffffffff, 0xffffffff, 0x000003ff } /* ALL_REGS */ \
501 /* A C expression whose value is a register class containing hard
502 register REGNO. In general there is more that one such class;
503 choose a class which is "minimal", meaning that no smaller class
504 also contains the register. */
506 #define REGNO_REG_CLASS(REGNO) loongarch_regno_to_class[(REGNO)]
508 /* A macro whose definition is the name of the class to which a
509 valid base register must belong. A base register is one used in
510 an address which is the register value plus a displacement. */
512 #define BASE_REG_CLASS (GR_REGS)
514 /* A macro whose definition is the name of the class to which a
515 valid index register must belong. An index register is one used
516 in an address where its value is either multiplied by a scale
517 factor or added to another register (as well as added to a
518 displacement). */
520 #define INDEX_REG_CLASS GR_REGS
522 /* We generally want to put call-clobbered registers ahead of
523 call-saved ones. (IRA expects this.) */
525 #define REG_ALLOC_ORDER \
526 { /* Call-clobbered GPRs. */ \
527 12, 13, 14, 15, 16, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 1, \
528 /* Call-saved GPRs. */ \
529 23, 24, 25, 26, 27, 28, 29, 30, 31, \
530 /* GPRs that can never be exposed to the register allocator. */ \
531 0, 2, 3, 21, 22, \
532 /* Call-clobbered FPRs. */ \
533 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, \
534 48, 49, 50, 51,52, 53, 54, 55, \
535 56, 57, 58, 59, 60, 61, 62, 63, \
536 /* None of the remaining classes have defined call-saved \
537 registers. */ \
538 64, 65, 66, 67, 68, 69, 70, 71, 72, 73}
540 #define IMM_BITS 12
541 #define IMM_REACH (HOST_WIDE_INT_1 << IMM_BITS)
542 #define HWIT_1U HOST_WIDE_INT_1U
544 /* True if VALUE is an unsigned 6-bit number. */
546 #define UIMM6_OPERAND(VALUE) (((VALUE) & ~(unsigned HOST_WIDE_INT) 0x3f) == 0)
548 /* True if VALUE is a signed 10-bit number. */
550 #define IMM10_OPERAND(VALUE) ((unsigned HOST_WIDE_INT) (VALUE) + 0x200 < 0x400)
552 /* True if VALUE is a signed 12-bit number. */
554 #define IMM12_OPERAND(VALUE) \
555 ((unsigned HOST_WIDE_INT) (VALUE) + IMM_REACH / 2 < IMM_REACH)
557 /* True if VALUE is a signed 13-bit number. */
559 #define IMM13_OPERAND(VALUE) \
560 ((unsigned HOST_WIDE_INT) (VALUE) + 0x1000 < 0x2000)
562 /* True if VALUE is a signed 16-bit number. */
564 #define IMM16_OPERAND(VALUE) \
565 ((unsigned HOST_WIDE_INT) (VALUE) + 0x8000 < 0x10000)
567 /* True if VALUE is an unsigned 12-bit number. */
569 #define IMM12_OPERAND_UNSIGNED(VALUE) \
570 (((VALUE) & ~(unsigned HOST_WIDE_INT) (IMM_REACH - 1)) == 0)
572 /* True if VALUE can be loaded into a register using LU12I. */
574 #define LU12I_OPERAND(VALUE) \
575 (((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) == ((HWIT_1U << 31) - IMM_REACH) \
576 || ((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) + IMM_REACH == 0)
578 /* True if VALUE can be loaded into a register using LU32I. */
580 #define LU32I_OPERAND(VALUE) \
581 (((VALUE) | (((HWIT_1U << 19) - 1) << 32)) == (((HWIT_1U << 19) - 1) << 32) \
582 || ((VALUE) | (((HWIT_1U << 19) - 1) << 32)) + (HWIT_1U << 32) == 0)
584 /* True if VALUE can be loaded into a register using LU52I. */
586 #define HWIT_UC_0xFFF HOST_WIDE_INT_UC(0xfff)
587 #define LU52I_OPERAND(VALUE) \
588 (((VALUE) | (HWIT_UC_0xFFF << 52)) == (HWIT_UC_0xFFF << 52))
590 /* Return a value X with the low 12 bits clear, and such that
591 VALUE - X is a signed 12-bit value. */
593 #define CONST_HIGH_PART(VALUE) (((VALUE) + (IMM_REACH / 2)) & ~(IMM_REACH - 1))
595 #define CONST_LOW_PART(VALUE) ((VALUE) - CONST_HIGH_PART (VALUE))
597 /* True if VALUE can be added onto a register with one addu16i.d
598 instruction. */
600 #define ADDU16I_OPERAND(VALUE) \
601 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
602 && IMM16_OPERAND ((HOST_WIDE_INT) (VALUE) / 65536)))
604 /* True if VALUE can be added onto a register with two addi.{d/w}
605 instructions, but not one addi.{d/w} instruction. */
606 #define DUAL_IMM12_OPERAND(VALUE) \
607 (IN_RANGE ((VALUE), -4096, 4094) && !IMM12_OPERAND (VALUE))
609 /* True if VALUE can be added onto a register with two addu16i.d
610 instruction, but not one addu16i.d instruction. */
611 #define DUAL_ADDU16I_OPERAND(VALUE) \
612 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
613 && !ADDU16I_OPERAND (VALUE) \
614 && IN_RANGE ((VALUE) / 65536, -0x10000, 0xfffe)))
616 #define IMM12_INT(X) IMM12_OPERAND (INTVAL (X))
617 #define IMM12_INT_UNSIGNED(X) IMM12_OPERAND_UNSIGNED (INTVAL (X))
618 #define LU12I_INT(X) LU12I_OPERAND (INTVAL (X))
619 #define LU32I_INT(X) LU32I_OPERAND (INTVAL (X))
620 #define LU52I_INT(X) LU52I_OPERAND (INTVAL (X))
621 #define LARCH_12BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -2048, 2047))
622 #define LARCH_9BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -256, 255))
623 #define LARCH_16BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -32768, 32767))
624 #define LARCH_SHIFT_2_OFFSET_P(OFFSET) (((OFFSET) & 0x3) == 0)
626 /* Return the maximum number of consecutive registers
627 needed to represent mode MODE in a register of class CLASS. */
629 #define CLASS_MAX_NREGS(CLASS, MODE) loongarch_class_max_nregs (CLASS, MODE)
631 /* Stack layout; function entry, exit and calling. */
633 #define STACK_GROWS_DOWNWARD 1
635 #define FRAME_GROWS_DOWNWARD 1
637 #define RETURN_ADDR_RTX loongarch_return_addr
639 /* Similarly, don't use the least-significant bit to tell pointers to
640 code from vtable index. */
642 #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_delta
644 #define ELIMINABLE_REGS \
646 {ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
647 {ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
648 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
649 {FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
652 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
653 (OFFSET) = loongarch_initial_elimination_offset ((FROM), (TO))
655 /* Allocate stack space for arguments at the beginning of each function. */
656 #define ACCUMULATE_OUTGOING_ARGS 1
658 /* The argument pointer always points to the first argument. */
659 #define FIRST_PARM_OFFSET(FNDECL) 0
661 #define REG_PARM_STACK_SPACE(FNDECL) 0
663 /* Define this if it is the responsibility of the caller to
664 allocate the area reserved for arguments passed in registers.
665 If `ACCUMULATE_OUTGOING_ARGS' is also defined, the only effect
666 of this macro is to determine whether the space is included in
667 `crtl->outgoing_args_size'. */
668 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
670 #define STACK_BOUNDARY (TARGET_ABI_LP64 ? 128 : 64)
672 /* This value controls how many pages we manually unroll the loop for when
673 generating stack clash probes. */
674 #define STACK_CLASH_MAX_UNROLL_PAGES 4
676 /* Symbolic macros for the registers used to return integer and floating
677 point values. */
679 #define GP_RETURN (GP_REG_FIRST + 4)
680 #define FP_RETURN ((TARGET_SOFT_FLOAT_ABI) ? GP_RETURN : (FP_REG_FIRST + 0))
682 #define MAX_ARGS_IN_REGISTERS 8
684 /* Symbolic macros for the first/last argument registers. */
686 #define GP_ARG_FIRST (GP_REG_FIRST + 4)
687 #define GP_ARG_LAST (GP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
688 #define FP_ARG_FIRST (FP_REG_FIRST + 0)
689 #define FP_ARG_LAST (FP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
691 /* True if MODE is vector and supported in a LSX vector register. */
692 #define LSX_SUPPORTED_MODE_P(MODE) \
693 (ISA_HAS_LSX \
694 && GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
695 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
696 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
698 #define LASX_SUPPORTED_MODE_P(MODE) \
699 (ISA_HAS_LASX \
700 && (GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
701 ||GET_MODE_SIZE (MODE) == UNITS_PER_LASX_REG) \
702 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
703 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
705 #define RECIP_MASK_NONE 0x00
706 #define RECIP_MASK_DIV 0x01
707 #define RECIP_MASK_SQRT 0x02
708 #define RECIP_MASK_RSQRT 0x04
709 #define RECIP_MASK_VEC_DIV 0x08
710 #define RECIP_MASK_VEC_SQRT 0x10
711 #define RECIP_MASK_VEC_RSQRT 0x20
712 #define RECIP_MASK_ALL (RECIP_MASK_DIV | RECIP_MASK_SQRT \
713 | RECIP_MASK_RSQRT | RECIP_MASK_VEC_SQRT \
714 | RECIP_MASK_VEC_DIV | RECIP_MASK_VEC_RSQRT)
716 #define TARGET_RECIP_DIV ((recip_mask & RECIP_MASK_DIV) != 0 || TARGET_uARCH_LA664)
717 #define TARGET_RECIP_SQRT ((recip_mask & RECIP_MASK_SQRT) != 0 || TARGET_uARCH_LA664)
718 #define TARGET_RECIP_RSQRT ((recip_mask & RECIP_MASK_RSQRT) != 0 || TARGET_uARCH_LA664)
719 #define TARGET_RECIP_VEC_DIV ((recip_mask & RECIP_MASK_VEC_DIV) != 0 || TARGET_uARCH_LA664)
720 #define TARGET_RECIP_VEC_SQRT ((recip_mask & RECIP_MASK_VEC_SQRT) != 0 || TARGET_uARCH_LA664)
721 #define TARGET_RECIP_VEC_RSQRT ((recip_mask & RECIP_MASK_VEC_RSQRT) != 0 || TARGET_uARCH_LA664)
723 /* 1 if N is a possible register number for function argument passing.
724 We have no FP argument registers when soft-float. */
726 /* Accept arguments in a0-a7, and in fa0-fa7 if permitted by the ABI. */
727 #define FUNCTION_ARG_REGNO_P(N) \
728 (IN_RANGE ((N), GP_ARG_FIRST, GP_ARG_LAST) \
729 || (UNITS_PER_FP_ARG && IN_RANGE ((N), FP_ARG_FIRST, FP_ARG_LAST)))
731 typedef struct {
732 /* Number of integer registers used so far, up to MAX_ARGS_IN_REGISTERS. */
733 unsigned int num_gprs;
735 /* Number of floating-point registers used so far, likewise. */
736 unsigned int num_fprs;
738 } CUMULATIVE_ARGS;
740 /* Initialize a variable CUM of type CUMULATIVE_ARGS
741 for a call to a function whose data type is FNTYPE.
742 For a library call, FNTYPE is 0. */
744 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
745 memset (&(CUM), 0, sizeof (CUM))
747 #define EPILOGUE_USES(REGNO) loongarch_epilogue_uses (REGNO)
749 /* Treat LOC as a byte offset from the stack pointer and round it up
750 to the next fully-aligned offset. */
751 #define LARCH_STACK_ALIGN(LOC) \
752 (TARGET_ABI_LP64 ? ROUND_UP ((LOC), 16) : ROUND_UP ((LOC), 8))
754 #define MCOUNT_NAME "_mcount"
756 /* Emit rtl for profiling. Output assembler code to FILE
757 to call "_mcount" for profiling a function entry. */
758 #define PROFILE_HOOK(LABEL) \
760 rtx fun, ra; \
761 ra = get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM); \
762 fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
763 emit_library_call (fun, LCT_NORMAL, VOIDmode, ra, Pmode); \
766 /* All the work done in PROFILE_HOOK, but still required. */
767 #define FUNCTION_PROFILER(STREAM, LABELNO) do { } while (0)
769 #define NO_PROFILE_COUNTERS 1
771 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
772 the stack pointer does not matter. The value is tested only in
773 functions that have frame pointers.
774 No definition is equivalent to always zero. */
776 #define EXIT_IGNORE_STACK 1
778 /* Trampolines are a block of code followed by two pointers. */
780 #define TRAMPOLINE_CODE_SIZE 16
781 #define TRAMPOLINE_SIZE \
782 ((Pmode == SImode) ? TRAMPOLINE_CODE_SIZE \
783 : (TRAMPOLINE_CODE_SIZE + POINTER_SIZE * 2))
784 #define TRAMPOLINE_ALIGNMENT POINTER_SIZE
786 /* loongarch_trampoline_init calls this library function to flush
787 program and data caches. */
789 #ifndef CACHE_FLUSH_FUNC
790 #define CACHE_FLUSH_FUNC "_flush_cache"
791 #endif
793 /* Addressing modes, and classification of registers for them. */
795 #define REGNO_OK_FOR_INDEX_P(REGNO) \
796 loongarch_regno_mode_ok_for_base_p (REGNO, VOIDmode, 1)
798 #define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) \
799 loongarch_regno_mode_ok_for_base_p (REGNO, MODE, 1)
801 /* Maximum number of registers that can appear in a valid memory address. */
803 #define MAX_REGS_PER_ADDRESS 2
805 /* Check for constness inline but use loongarch_legitimate_address_p
806 to check whether a constant really is an address. */
808 #define CONSTANT_ADDRESS_P(X) (CONSTANT_P (X) && memory_address_p (SImode, X))
810 /* This handles the magic '..CURRENT_FUNCTION' symbol, which means
811 'the start of the function that this code is output in'. */
813 #define ASM_OUTPUT_LABELREF(FILE, NAME) \
814 do \
816 if (strcmp (NAME, "..CURRENT_FUNCTION") == 0) \
817 asm_fprintf ((FILE), "%U%s", \
818 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \
819 else \
820 asm_fprintf ((FILE), "%U%s", (NAME)); \
822 while (0)
824 #define CASE_VECTOR_MODE Pmode
826 #define CASE_VECTOR_SHORTEN_MODE(MIN, MAX, BODY) Pmode
828 /* Define this as 1 if `char' should by default be signed; else as 0. */
829 #ifndef DEFAULT_SIGNED_CHAR
830 #define DEFAULT_SIGNED_CHAR 1
831 #endif
833 /* The SPARC port says:
834 The maximum number of bytes that a single instruction
835 can move quickly between memory and registers or between
836 two memory locations. */
837 #define MOVE_MAX UNITS_PER_WORD
838 #define MAX_MOVE_MAX 8
840 /* The SPARC port says:
841 Nonzero if access to memory by bytes is slow and undesirable.
842 For RISC chips, it means that access to memory by bytes is no
843 better than access by words when possible, so grab a whole word
844 and maybe make use of that. */
845 #define SLOW_BYTE_ACCESS 1
847 /* Standard LoongArch integer shifts truncate the shift amount to the
848 width of the shifted operand. */
849 #define SHIFT_COUNT_TRUNCATED 1
851 /* Specify the machine mode that pointers have.
852 After generation of rtl, the compiler makes no further distinction
853 between pointers and any other objects of this machine mode. */
855 #ifndef Pmode
856 #define Pmode (TARGET_64BIT ? DImode : SImode)
857 #endif
859 /* Give call MEMs SImode since it is the "most permissive" mode
860 for both 32-bit and 64-bit targets. */
862 #define FUNCTION_MODE SImode
864 /* We allocate $fcc registers by hand and can't cope with moves of
865 CCmode registers to and from pseudos (or memory). */
866 #define AVOID_CCMODE_COPIES
868 /* A C expression for the cost of a branch instruction. A value of
869 1 is the default; other values are interpreted relative to that. */
871 #define BRANCH_COST(speed_p, predictable_p) la_branch_cost
872 #define LOGICAL_OP_NON_SHORT_CIRCUIT 0
874 /* Return the asm template for a conditional branch instruction.
875 OPCODE is the opcode's mnemonic and OPERANDS is the asm template for
876 its operands. */
877 #define LARCH_BRANCH(OPCODE, OPERANDS) OPCODE "\t" OPERANDS
879 /* Control the assembler format that we output. */
881 /* Output to assembler file text saying following lines
882 may contain character constants, extra white space, comments, etc. */
884 #ifndef ASM_APP_ON
885 #define ASM_APP_ON " #APP\n"
886 #endif
888 /* Output to assembler file text saying following lines
889 no longer contain unusual constructs. */
891 #ifndef ASM_APP_OFF
892 #define ASM_APP_OFF " #NO_APP\n"
893 #endif
895 #define REGISTER_NAMES \
896 { "$r0", "$r1", "$r2", "$r3", "$r4", "$r5", "$r6", "$r7", \
897 "$r8", "$r9", "$r10", "$r11", "$r12", "$r13", "$r14", "$r15", \
898 "$r16", "$r17", "$r18", "$r19", "$r20", "$r21", "$r22", "$r23", \
899 "$r24", "$r25", "$r26", "$r27", "$r28", "$r29", "$r30", "$r31", \
900 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", \
901 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", \
902 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", \
903 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", \
904 "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4","$fcc5","$fcc6","$fcc7", \
905 "$arg", "$frame"}
907 /* This macro defines additional names for hard registers. */
909 #define ADDITIONAL_REGISTER_NAMES \
911 { "zero", 0 + GP_REG_FIRST }, \
912 { "ra", 1 + GP_REG_FIRST }, \
913 { "tp", 2 + GP_REG_FIRST }, \
914 { "sp", 3 + GP_REG_FIRST }, \
915 { "a0", 4 + GP_REG_FIRST }, \
916 { "a1", 5 + GP_REG_FIRST }, \
917 { "a2", 6 + GP_REG_FIRST }, \
918 { "a3", 7 + GP_REG_FIRST }, \
919 { "a4", 8 + GP_REG_FIRST }, \
920 { "a5", 9 + GP_REG_FIRST }, \
921 { "a6", 10 + GP_REG_FIRST }, \
922 { "a7", 11 + GP_REG_FIRST }, \
923 { "t0", 12 + GP_REG_FIRST }, \
924 { "t1", 13 + GP_REG_FIRST }, \
925 { "t2", 14 + GP_REG_FIRST }, \
926 { "t3", 15 + GP_REG_FIRST }, \
927 { "t4", 16 + GP_REG_FIRST }, \
928 { "t5", 17 + GP_REG_FIRST }, \
929 { "t6", 18 + GP_REG_FIRST }, \
930 { "t7", 19 + GP_REG_FIRST }, \
931 { "t8", 20 + GP_REG_FIRST }, \
932 { "x", 21 + GP_REG_FIRST }, \
933 { "fp", 22 + GP_REG_FIRST }, \
934 { "s9", 22 + GP_REG_FIRST }, \
935 { "s0", 23 + GP_REG_FIRST }, \
936 { "s1", 24 + GP_REG_FIRST }, \
937 { "s2", 25 + GP_REG_FIRST }, \
938 { "s3", 26 + GP_REG_FIRST }, \
939 { "s4", 27 + GP_REG_FIRST }, \
940 { "s5", 28 + GP_REG_FIRST }, \
941 { "s6", 29 + GP_REG_FIRST }, \
942 { "s7", 30 + GP_REG_FIRST }, \
943 { "s8", 31 + GP_REG_FIRST }, \
944 { "v0", 4 + GP_REG_FIRST }, \
945 { "v1", 5 + GP_REG_FIRST }, \
946 { "vr0", 0 + FP_REG_FIRST }, \
947 { "vr1", 1 + FP_REG_FIRST }, \
948 { "vr2", 2 + FP_REG_FIRST }, \
949 { "vr3", 3 + FP_REG_FIRST }, \
950 { "vr4", 4 + FP_REG_FIRST }, \
951 { "vr5", 5 + FP_REG_FIRST }, \
952 { "vr6", 6 + FP_REG_FIRST }, \
953 { "vr7", 7 + FP_REG_FIRST }, \
954 { "vr8", 8 + FP_REG_FIRST }, \
955 { "vr9", 9 + FP_REG_FIRST }, \
956 { "vr10", 10 + FP_REG_FIRST }, \
957 { "vr11", 11 + FP_REG_FIRST }, \
958 { "vr12", 12 + FP_REG_FIRST }, \
959 { "vr13", 13 + FP_REG_FIRST }, \
960 { "vr14", 14 + FP_REG_FIRST }, \
961 { "vr15", 15 + FP_REG_FIRST }, \
962 { "vr16", 16 + FP_REG_FIRST }, \
963 { "vr17", 17 + FP_REG_FIRST }, \
964 { "vr18", 18 + FP_REG_FIRST }, \
965 { "vr19", 19 + FP_REG_FIRST }, \
966 { "vr20", 20 + FP_REG_FIRST }, \
967 { "vr21", 21 + FP_REG_FIRST }, \
968 { "vr22", 22 + FP_REG_FIRST }, \
969 { "vr23", 23 + FP_REG_FIRST }, \
970 { "vr24", 24 + FP_REG_FIRST }, \
971 { "vr25", 25 + FP_REG_FIRST }, \
972 { "vr26", 26 + FP_REG_FIRST }, \
973 { "vr27", 27 + FP_REG_FIRST }, \
974 { "vr28", 28 + FP_REG_FIRST }, \
975 { "vr29", 29 + FP_REG_FIRST }, \
976 { "vr30", 30 + FP_REG_FIRST }, \
977 { "vr31", 31 + FP_REG_FIRST }, \
978 { "xr0", 0 + FP_REG_FIRST }, \
979 { "xr1", 1 + FP_REG_FIRST }, \
980 { "xr2", 2 + FP_REG_FIRST }, \
981 { "xr3", 3 + FP_REG_FIRST }, \
982 { "xr4", 4 + FP_REG_FIRST }, \
983 { "xr5", 5 + FP_REG_FIRST }, \
984 { "xr6", 6 + FP_REG_FIRST }, \
985 { "xr7", 7 + FP_REG_FIRST }, \
986 { "xr8", 8 + FP_REG_FIRST }, \
987 { "xr9", 9 + FP_REG_FIRST }, \
988 { "xr10", 10 + FP_REG_FIRST }, \
989 { "xr11", 11 + FP_REG_FIRST }, \
990 { "xr12", 12 + FP_REG_FIRST }, \
991 { "xr13", 13 + FP_REG_FIRST }, \
992 { "xr14", 14 + FP_REG_FIRST }, \
993 { "xr15", 15 + FP_REG_FIRST }, \
994 { "xr16", 16 + FP_REG_FIRST }, \
995 { "xr17", 17 + FP_REG_FIRST }, \
996 { "xr18", 18 + FP_REG_FIRST }, \
997 { "xr19", 19 + FP_REG_FIRST }, \
998 { "xr20", 20 + FP_REG_FIRST }, \
999 { "xr21", 21 + FP_REG_FIRST }, \
1000 { "xr22", 22 + FP_REG_FIRST }, \
1001 { "xr23", 23 + FP_REG_FIRST }, \
1002 { "xr24", 24 + FP_REG_FIRST }, \
1003 { "xr25", 25 + FP_REG_FIRST }, \
1004 { "xr26", 26 + FP_REG_FIRST }, \
1005 { "xr27", 27 + FP_REG_FIRST }, \
1006 { "xr28", 28 + FP_REG_FIRST }, \
1007 { "xr29", 29 + FP_REG_FIRST }, \
1008 { "xr30", 30 + FP_REG_FIRST }, \
1009 { "xr31", 31 + FP_REG_FIRST } \
1012 /* Globalizing directive for a label. */
1013 #define GLOBAL_ASM_OP "\t.globl\t"
1015 /* This says how to output an external. It would be possible not to
1016 output anything and let undefined symbol become external. However
1017 the assembler uses length information on externals to allocate in
1018 data/sdata bss/sbss, thereby saving exec time. */
1020 #undef ASM_OUTPUT_EXTERNAL
1021 #define ASM_OUTPUT_EXTERNAL(STREAM, DECL, NAME) \
1022 loongarch_output_external (STREAM, DECL, NAME)
1024 /* This is how to store into the string LABEL
1025 the symbol_ref name of an internal numbered label where
1026 PREFIX is the class of label and NUM is the number within the class.
1027 This is suitable for output with `assemble_name'. */
1029 #undef ASM_GENERATE_INTERNAL_LABEL
1030 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
1031 sprintf ((LABEL), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long) (NUM))
1033 /* Print debug labels as "foo = ." rather than "foo:" because they should
1034 represent a byte pointer rather than an ISA-encoded address. This is
1035 particularly important for code like:
1037 $LFBxxx = .
1038 .cfi_startproc
1040 .section .gcc_except_table,...
1042 .uleb128 foo-$LFBxxx
1044 The .uleb128 requies $LFBxxx to match the FDE start address, which is
1045 likewise a byte pointer rather than an ISA-encoded address.
1047 At the time of writing, this hook is not used for the function end
1048 label:
1050 $LFExxx:
1051 .end foo
1055 #define ASM_OUTPUT_DEBUG_LABEL(FILE, PREFIX, NUM) \
1056 fprintf (FILE, "%s%s%d = .\n", LOCAL_LABEL_PREFIX, PREFIX, NUM)
1058 /* This is how to output an element of a case-vector that is absolute. */
1060 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
1061 fprintf (STREAM, "\t%s\t%sL%d\n", ptr_mode == DImode ? ".dword" : ".word", \
1062 LOCAL_LABEL_PREFIX, VALUE)
1064 /* This is how to output an element of a case-vector. */
1066 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL) \
1067 do \
1069 fprintf (STREAM, "\t%s\t%sL%d-%sL%d\n", \
1070 ptr_mode == DImode ? ".dword" : ".word", LOCAL_LABEL_PREFIX, \
1071 VALUE, LOCAL_LABEL_PREFIX, REL); \
1073 while (0)
1075 #define JUMP_TABLES_IN_TEXT_SECTION 0
1077 /* This is how to output an assembler line
1078 that says to advance the location counter
1079 to a multiple of 2**LOG bytes. */
1081 #define ASM_OUTPUT_ALIGN(STREAM, LOG) fprintf (STREAM, "\t.align\t%d\n", (LOG))
1083 /* This is how to output an assembler line to advance the location
1084 counter by SIZE bytes. */
1086 #undef ASM_OUTPUT_SKIP
1087 #define ASM_OUTPUT_SKIP(STREAM, SIZE) \
1088 fprintf (STREAM, "\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n", (SIZE))
1090 /* This is how to output a string. */
1091 #undef ASM_OUTPUT_ASCII
1092 #define ASM_OUTPUT_ASCII loongarch_output_ascii
1094 /* Define the strings to put out for each section in the object file. */
1095 #define TEXT_SECTION_ASM_OP "\t.text" /* instructions */
1096 #define DATA_SECTION_ASM_OP "\t.data" /* large data */
1098 #undef READONLY_DATA_SECTION_ASM_OP
1099 #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata" /* read-only data */
1101 #define ASM_OUTPUT_REG_PUSH(STREAM, REGNO) \
1102 do \
1104 fprintf (STREAM, "\t%s\t%s,%s,-8\n\t%s\t%s,%s,0\n", \
1105 TARGET_64BIT ? "addi.d" : "addi.w", \
1106 reg_names[STACK_POINTER_REGNUM], \
1107 reg_names[STACK_POINTER_REGNUM], \
1108 TARGET_64BIT ? "st.d" : "st.w", reg_names[REGNO], \
1109 reg_names[STACK_POINTER_REGNUM]); \
1111 while (0)
1113 #define ASM_OUTPUT_REG_POP(STREAM, REGNO) \
1114 do \
1116 fprintf (STREAM, "\t%s\t%s,%s,0\n\t%s\t%s,%s,8\n", \
1117 TARGET_64BIT ? "ld.d" : "ld.w", reg_names[REGNO], \
1118 reg_names[STACK_POINTER_REGNUM], \
1119 TARGET_64BIT ? "addi.d" : "addi.w", \
1120 reg_names[STACK_POINTER_REGNUM], \
1121 reg_names[STACK_POINTER_REGNUM]); \
1123 while (0)
1125 /* How to start an assembler comment.
1126 The leading space is important (the loongarch native assembler requires it).
1128 #ifndef ASM_COMMENT_START
1129 #define ASM_COMMENT_START " #"
1130 #endif
1132 #undef SIZE_TYPE
1133 #define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")
1135 #undef PTRDIFF_TYPE
1136 #define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "int")
1138 /* The maximum number of bytes that can be copied by one iteration of
1139 a cpymemsi loop; see loongarch_block_move_loop. */
1140 #define LARCH_MAX_MOVE_OPS_PER_LOOP_ITER 4
1142 /* The maximum number of bytes that can be copied by a straight-line
1143 implementation of cpymemsi; see loongarch_block_move_straight. We want
1144 to make sure that any loop-based implementation will iterate at
1145 least twice. */
1146 #define LARCH_MAX_MOVE_OPS_STRAIGHT (LARCH_MAX_MOVE_OPS_PER_LOOP_ITER * 2)
1148 #define LARCH_MAX_MOVE_PER_INSN \
1149 (ISA_HAS_LASX ? 32 : (ISA_HAS_LSX ? 16 : UNITS_PER_WORD))
1151 /* The base cost of a memcpy call, for MOVE_RATIO and friends. These
1152 values were determined experimentally by benchmarking with CSiBE.
1154 #define LARCH_CALL_RATIO 6
1156 /* Any loop-based implementation of cpymemsi will have at least
1157 LARCH_MAX_MOVE_OPS_PER_LOOP_ITER memory-to-memory
1158 moves, so allow individual copies of fewer elements.
1160 When cpymemsi is not available, use a value approximating
1161 the length of a memcpy call sequence, so that move_by_pieces
1162 will generate inline code if it is shorter than a function call.
1163 Since move_by_pieces_ninsns counts memory-to-memory moves, but
1164 we'll have to generate a load/store pair for each, halve the
1165 value of LARCH_CALL_RATIO to take that into account. */
1167 #define MOVE_RATIO(speed) \
1168 (HAVE_cpymemsi ? LARCH_MAX_MOVE_OPS_PER_LOOP_ITER : CLEAR_RATIO (speed) / 2)
1170 /* For CLEAR_RATIO, when optimizing for size, give a better estimate
1171 of the length of a memset call, but use the default otherwise. */
1173 #define CLEAR_RATIO(speed) ((speed) ? 15 : LARCH_CALL_RATIO)
1175 /* This is similar to CLEAR_RATIO, but for a non-zero constant, so when
1176 optimizing for size adjust the ratio to account for the overhead of
1177 loading the constant and replicating it across the word. */
1179 #define SET_RATIO(speed) ((speed) ? 15 : LARCH_CALL_RATIO - 2)
1181 #ifndef USED_FOR_TARGET
1182 extern const enum reg_class loongarch_regno_to_class[];
1183 extern int loongarch_dwarf_regno[];
1185 /* Information about a function's frame layout. */
1186 struct GTY (()) loongarch_frame_info
1188 /* The size of the frame in bytes. */
1189 HOST_WIDE_INT total_size;
1191 /* Bit X is set if the function saves or restores GPR X. */
1192 unsigned int mask;
1194 /* Likewise FPR X. */
1195 unsigned int fmask;
1197 /* How much the GPR save/restore routines adjust sp (or 0 if unused). */
1198 unsigned save_libcall_adjustment;
1200 /* Offsets of fixed-point and floating-point save areas from frame
1201 bottom. */
1202 HOST_WIDE_INT gp_sp_offset;
1203 HOST_WIDE_INT fp_sp_offset;
1205 /* Offset of virtual frame pointer from stack pointer/frame bottom. */
1206 HOST_WIDE_INT frame_pointer_offset;
1208 /* Offset of hard frame pointer from stack pointer/frame bottom. */
1209 HOST_WIDE_INT hard_frame_pointer_offset;
1211 /* The offset of arg_pointer_rtx from the bottom of the frame. */
1212 HOST_WIDE_INT arg_pointer_offset;
1215 struct GTY (()) machine_function
1217 /* The next floating-point condition-code register to allocate
1218 for 8CC targets, relative to FCC_REG_FIRST. */
1219 unsigned int next_fcc;
1221 /* The number of extra stack bytes taken up by register varargs.
1222 This area is allocated by the callee at the very top of the frame. */
1223 int varargs_size;
1225 /* The current frame information, calculated by loongarch_compute_frame_info.
1227 struct loongarch_frame_info frame;
1229 bool reg_is_wrapped_separately[FIRST_PSEUDO_REGISTER];
1231 #endif
1233 #ifdef HAVE_AS_EH_FRAME_PCREL_ENCODING_SUPPORT
1234 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
1235 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
1236 #else
1237 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
1238 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_absptr)
1239 #endif
1241 /* Do emit .note.GNU-stack by default. */
1242 #ifndef NEED_INDICATE_EXEC_STACK
1243 #define NEED_INDICATE_EXEC_STACK 1
1244 #endif
1246 /* The `Q' extension is not yet supported. */
1247 /* TODO: according to march. */
1248 #define UNITS_PER_FP_REG (TARGET_DOUBLE_FLOAT ? 8 : 4)
1250 /* The largest type that can be passed in floating-point registers. */
1251 /* TODO: according to mabi. */
1252 #define UNITS_PER_FP_ARG \
1253 (TARGET_HARD_FLOAT_ABI ? (TARGET_DOUBLE_FLOAT_ABI ? 8 : 4) : 0)
1255 #define FUNCTION_VALUE_REGNO_P(N) ((N) == GP_RETURN || (N) == FP_RETURN)
1257 /* LoongArch maintains ICache/DCache coherency by hardware,
1258 we just need "ibar" to avoid instruction hazard here. */
1259 #undef CLEAR_INSN_CACHE
1260 #define CLEAR_INSN_CACHE(beg, end) __builtin_loongarch_ibar (0)
1262 #define TARGET_EXPLICIT_RELOCS \
1263 (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)