[PR testsuite/116860] Testsuite adjustment for recently added tests
[official-gcc.git] / gcc / config / loongarch / loongarch.h
blob42a38a44efeb81d617afb918c93ca39dbebfa834
1 /* Definitions of target machine for GNU compiler. LoongArch version.
2 Copyright (C) 2021-2025 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"
25 #include "config/loongarch/loongarch-evolution.h"
27 #define SWITCHABLE_TARGET 1
29 #define REGISTER_TARGET_PRAGMAS() loongarch_register_pragmas ()
31 #define TARGET_SUPPORTS_WIDE_INT 1
33 /* Macros to silence warnings about numbers being signed in traditional
34 C and unsigned in ISO C when compiled on 32-bit hosts. */
36 #define BITMASK_HIGH (((unsigned long) 1) << 31) /* 0x80000000 */
38 /* Run-time compilation parameters selecting different hardware subsets. */
40 /* Target CPU builtins. */
41 #define TARGET_CPU_CPP_BUILTINS() loongarch_cpu_cpp_builtins (pfile)
43 /* Default target_flags if no switches are specified. */
45 #ifdef IN_LIBGCC2
46 #undef TARGET_64BIT
47 /* Make this compile time constant for libgcc2. */
48 #ifdef __loongarch64
49 #define TARGET_64BIT 1
50 #else
51 #define TARGET_64BIT 0
52 #endif
53 #endif /* IN_LIBGCC2 */
55 #define TARGET_LIBGCC_SDATA_SECTION ".sdata"
57 /* This definition replaces the formerly used 'm' constraint with a
58 different constraint letter in order to avoid changing semantics of
59 the 'm' constraint when accepting new address formats in
60 TARGET_LEGITIMATE_ADDRESS_P. The constraint letter defined here
61 must not be used in insn definitions or inline assemblies. */
62 #define TARGET_MEM_CONSTRAINT 'w'
64 /* Tell collect what flags to pass to nm. */
65 #ifndef NM_FLAGS
66 #define NM_FLAGS "-Bn"
67 #endif
69 /* Registers may have a prefix which can be ignored when matching
70 user asm and register definitions. */
71 #ifndef REGISTER_PREFIX
72 #define REGISTER_PREFIX "$"
73 #endif
75 /* Local compiler-generated symbols must have a prefix that the assembler
76 understands. */
78 #define LOCAL_LABEL_PREFIX "."
80 /* By default on the loongarch, external symbols do not have an underscore
81 prepended. */
83 #define USER_LABEL_PREFIX ""
85 #ifndef PREFERRED_DEBUGGING_TYPE
86 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
87 #endif
89 /* The size of DWARF addresses should be the same as the size of symbols
90 in the target file format. */
91 #define DWARF2_ADDR_SIZE (TARGET_64BIT ? 8 : 4)
93 /* By default, turn on GDB extensions. */
94 #define DEFAULT_GDB_EXTENSIONS 1
96 /* By default, produce dwarf version 2 format debugging output in response
97 to the ā€˜-gā€™ option. */
98 #define DWARF2_DEBUGGING_INFO 1
100 /* The mapping from gcc register number to DWARF 2 CFA column number. */
101 #define DWARF_FRAME_REGNUM(REGNO) loongarch_dwarf_regno[REGNO]
103 /* The DWARF 2 CFA column which tracks the return address. */
104 #define DWARF_FRAME_RETURN_COLUMN RETURN_ADDR_REGNUM
106 /* Before the prologue, RA lives in r1. */
107 #define INCOMING_RETURN_ADDR_RTX gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)
109 /* Describe how we implement __builtin_eh_return. */
110 #define EH_RETURN_DATA_REGNO(N) \
111 ((N) < (4) ? (N) + GP_ARG_FIRST : INVALID_REGNUM)
113 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, GP_ARG_FIRST + 4)
115 #define EH_USES(N) loongarch_eh_uses (N)
117 /* Offsets recorded in opcodes are a multiple of this alignment factor.
118 The default for this in 64-bit mode is 8, which causes problems with
119 SFmode register saves. */
120 #define DWARF_CIE_DATA_ALIGNMENT -4
122 /* Target machine storage layout. */
124 #define BITS_BIG_ENDIAN 0
125 #define BYTES_BIG_ENDIAN 0
126 #define WORDS_BIG_ENDIAN 0
128 #define MAX_BITS_PER_WORD 64
130 /* Width of a word, in units (bytes). */
131 #define UNITS_PER_WORD (TARGET_64BIT ? 8 : 4)
132 #ifndef IN_LIBGCC2
133 #define MIN_UNITS_PER_WORD 4
134 #endif
136 /* Width of a LSX vector register in bytes. */
137 #define UNITS_PER_LSX_REG 16
138 /* Width of a LSX vector register in bits. */
139 #define BITS_PER_LSX_REG (UNITS_PER_LSX_REG * BITS_PER_UNIT)
141 /* Width of a LASX vector register in bytes. */
142 #define UNITS_PER_LASX_REG 32
143 /* Width of a LASX vector register in bits. */
144 #define BITS_PER_LASX_REG (UNITS_PER_LASX_REG * BITS_PER_UNIT)
146 /* The largest size of value that can be held in floating-point
147 registers and moved with a single instruction. */
148 #define UNITS_PER_HWFPVALUE \
149 (TARGET_SOFT_FLOAT ? 0 : UNITS_PER_FP_REG)
151 /* The number of bytes in a double. */
152 #define UNITS_PER_DOUBLE (TYPE_PRECISION (double_type_node) / BITS_PER_UNIT)
154 /* Set the sizes of the core types. */
155 #define SHORT_TYPE_SIZE 16
156 #define INT_TYPE_SIZE 32
157 #define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32)
158 #define LONG_LONG_TYPE_SIZE 64
160 /* LONG_DOUBLE_TYPE_SIZE get poisoned, so add LA_ prefix. */
161 #define LA_LONG_DOUBLE_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
163 /* Define the sizes of fixed-point types. */
164 #define SHORT_FRACT_TYPE_SIZE 8
165 #define FRACT_TYPE_SIZE 16
166 #define LONG_FRACT_TYPE_SIZE 32
167 #define LONG_LONG_FRACT_TYPE_SIZE 64
169 #define SHORT_ACCUM_TYPE_SIZE 16
170 #define ACCUM_TYPE_SIZE 32
171 #define LONG_ACCUM_TYPE_SIZE 64
172 #define LONG_LONG_ACCUM_TYPE_SIZE (TARGET_64BIT ? 128 : 64)
174 /* long double is not a fixed mode, but the idea is that, if we
175 support long double, we also want a 128-bit integer type. */
176 #define MAX_FIXED_MODE_SIZE LA_LONG_DOUBLE_TYPE_SIZE
178 /* Width in bits of a pointer. */
179 #ifndef POINTER_SIZE
180 #define POINTER_SIZE (TARGET_64BIT ? 64 : 32)
181 #endif
183 /* Allocation boundary (in *bits*) for storing arguments in argument list. */
184 #define PARM_BOUNDARY BITS_PER_WORD
186 /* Allocation boundary (in *bits*) for the code of a function. */
187 #define FUNCTION_BOUNDARY 32
189 /* Alignment of field after `int : 0' in a structure. */
190 #define EMPTY_FIELD_BOUNDARY 32
192 /* Number of bits which any structure or union's size must be a multiple of.
193 Each structure or union's size is rounded up to a multiple of this. */
194 #define STRUCTURE_SIZE_BOUNDARY 8
196 /* There is no point aligning anything to a rounder boundary than
197 LA_LONG_DOUBLE_TYPE_SIZE, unless under LSX/LASX the bigggest alignment is
198 BITS_PER_LSX_REG/BITS_PER_LASX_REG/.. */
199 #define BIGGEST_ALIGNMENT \
200 (ISA_HAS_LASX? BITS_PER_LASX_REG \
201 : (ISA_HAS_LSX ? BITS_PER_LSX_REG : LA_LONG_DOUBLE_TYPE_SIZE))
203 /* All accesses must be aligned. */
204 #define STRICT_ALIGNMENT (TARGET_STRICT_ALIGN)
206 /* Define this if you wish to imitate the way many other C compilers
207 handle alignment of bitfields and the structures that contain
208 them.
210 The behavior is that the type written for a bit-field (`int',
211 `short', or other integer type) imposes an alignment for the
212 entire structure, as if the structure really did contain an
213 ordinary field of that type. In addition, the bit-field is placed
214 within the structure so that it would fit within such a field,
215 not crossing a boundary for it.
217 Thus, on most machines, a bit-field whose type is written as `int'
218 would not cross a four-byte boundary, and would force four-byte
219 alignment for the whole structure. (The alignment used may not
220 be four bytes; it is controlled by the other alignment
221 parameters.)
223 If the macro is defined, its definition should be a C expression;
224 a nonzero value for the expression enables this behavior. */
226 #define PCC_BITFIELD_TYPE_MATTERS 1
228 /* If defined, a C expression to compute the alignment for a static
229 variable. TYPE is the data type, and ALIGN is the alignment that
230 the object would ordinarily have. The value of this macro is used
231 instead of that alignment to align the object.
233 If this macro is not defined, then ALIGN is used.
235 One use of this macro is to increase alignment of medium-size
236 data to make it all fit in fewer cache lines. Another is to
237 cause character arrays to be word-aligned so that `strcpy' calls
238 that copy constants to character arrays can be done inline. */
240 #undef DATA_ALIGNMENT
241 #define DATA_ALIGNMENT(TYPE, ALIGN) \
242 ((((ALIGN) < BITS_PER_WORD) \
243 && (TREE_CODE (TYPE) == ARRAY_TYPE \
244 || TREE_CODE (TYPE) == UNION_TYPE \
245 || TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
247 /* We need this for the same reason as DATA_ALIGNMENT, namely to cause
248 character arrays to be word-aligned so that `strcpy' calls that copy
249 constants to character arrays can be done inline, and 'strcmp' can be
250 optimised to use word loads. */
251 #define LOCAL_ALIGNMENT(TYPE, ALIGN) DATA_ALIGNMENT (TYPE, ALIGN)
253 /* Define if operations between registers always perform the operation
254 on the full register even if a narrower mode is specified. */
255 #define WORD_REGISTER_OPERATIONS 1
257 /* When in 64-bit mode, move insns will sign extend SImode and FCCmode
258 moves. All other references are zero extended. */
259 #define LOAD_EXTEND_OP(MODE) \
260 (TARGET_64BIT && ((MODE) == SImode || (MODE) == FCCmode) ? SIGN_EXTEND \
261 : ZERO_EXTEND)
263 /* Define this macro if it is advisable to hold scalars in registers
264 in a wider mode than that declared by the program. In such cases,
265 the value is constrained to be within the bounds of the declared
266 type, but kept valid in the wider mode. The signedness of the
267 extension may differ from that of the type. */
269 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
270 if (GET_MODE_CLASS (MODE) == MODE_INT \
271 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
273 if ((MODE) == SImode) \
274 (UNSIGNEDP) = 0; \
275 (MODE) = Pmode; \
278 /* Pmode is always the same as ptr_mode, but not always the same as word_mode.
279 Extensions of pointers to word_mode must be signed. */
280 #define POINTERS_EXTEND_UNSIGNED false
282 /* Define if loading short immediate values into registers sign extends. */
283 #define SHORT_IMMEDIATES_SIGN_EXTEND 1
285 /* The clz.{w/d}, ctz.{w/d} instructions have the natural values at 0. */
287 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
288 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
289 #define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
290 ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2)
292 /* Standard register usage. */
294 /* Number of hardware registers. We have:
296 - 32 integer registers
297 - 32 floating point registers
298 - 8 condition code registers
299 - 2 fake registers:
300 - ARG_POINTER_REGNUM
301 - FRAME_POINTER_REGNUM
304 #define FIRST_PSEUDO_REGISTER 74
306 /* zero, tp, sp and x are fixed. */
307 #define FIXED_REGISTERS \
308 { /* General registers. */ \
309 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
310 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
311 /* Floating-point registers. */ \
312 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
313 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
314 /* Others. */ \
315 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}
317 /* The call RTLs themselves clobber ra. */
318 #define CALL_USED_REGISTERS \
319 { /* General registers. */ \
320 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
321 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
322 /* Floating-point registers. */ \
323 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
324 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, \
325 /* Others. */ \
326 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
328 /* Internal macros to classify a register number as to whether it's a
329 general purpose register, a floating point register, or a status
330 register. */
332 #define GP_REG_FIRST 0
333 #define GP_REG_LAST 31
334 #define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1)
336 #define FP_REG_FIRST 32
337 #define FP_REG_LAST 63
338 #define FP_REG_NUM (FP_REG_LAST - FP_REG_FIRST + 1)
339 #define LSX_REG_FIRST FP_REG_FIRST
340 #define LSX_REG_LAST FP_REG_LAST
341 #define LSX_REG_NUM FP_REG_NUM
343 #define LASX_REG_FIRST FP_REG_FIRST
344 #define LASX_REG_LAST FP_REG_LAST
345 #define LASX_REG_NUM FP_REG_NUM
347 /* The DWARF 2 CFA column which tracks the return address from a
348 signal handler context. This means that to maintain backwards
349 compatibility, no hard register can be assigned this column if it
350 would need to be handled by the DWARF unwinder. */
351 #define DWARF_ALT_FRAME_RETURN_COLUMN 72
353 #define FCC_REG_FIRST 64
354 #define FCC_REG_LAST 71
355 #define FCC_REG_NUM (FCC_REG_LAST - FCC_REG_FIRST + 1)
357 #define GP_REG_P(REGNO) \
358 ((unsigned int) ((int) (REGNO) - GP_REG_FIRST) < GP_REG_NUM)
359 #define FP_REG_P(REGNO) \
360 ((unsigned int) ((int) (REGNO) - FP_REG_FIRST) < FP_REG_NUM)
361 #define FCC_REG_P(REGNO) \
362 ((unsigned int) ((int) (REGNO) - FCC_REG_FIRST) < FCC_REG_NUM)
363 #define LSX_REG_P(REGNO) \
364 ((unsigned int) ((int) (REGNO) - LSX_REG_FIRST) < LSX_REG_NUM)
365 #define LASX_REG_P(REGNO) \
366 ((unsigned int) ((int) (REGNO) - LASX_REG_FIRST) < LASX_REG_NUM)
368 #define FP_REG_RTX_P(X) (REG_P (X) && FP_REG_P (REGNO (X)))
369 #define LSX_REG_RTX_P(X) (REG_P (X) && LSX_REG_P (REGNO (X)))
370 #define LASX_REG_RTX_P(X) (REG_P (X) && LASX_REG_P (REGNO (X)))
372 /* Select a register mode required for caller save of hard regno REGNO. */
373 #define HARD_REGNO_CALLER_SAVE_MODE(REGNO, NREGS, MODE) \
374 loongarch_hard_regno_caller_save_mode (REGNO, NREGS, MODE)
376 /* Register to use for pushing function arguments. */
377 #define STACK_POINTER_REGNUM (GP_REG_FIRST + 3)
379 /* These two registers don't really exist: they get eliminated to either
380 the stack or hard frame pointer. */
381 #define ARG_POINTER_REGNUM 72
382 #define FRAME_POINTER_REGNUM 73
384 #define HARD_FRAME_POINTER_REGNUM (GP_REG_FIRST + 22)
386 #define HARD_FRAME_POINTER_IS_FRAME_POINTER 0
387 #define HARD_FRAME_POINTER_IS_ARG_POINTER 0
389 /* Register in which static-chain is passed to a function. */
390 #define STATIC_CHAIN_REGNUM (GP_REG_FIRST + 20) /* $t8 */
392 #define GP_TEMP_FIRST (GP_REG_FIRST + 12)
393 #define LARCH_PROLOGUE_TEMP_REGNUM (GP_TEMP_FIRST + 1)
394 #define LARCH_PROLOGUE_TEMP2_REGNUM (GP_TEMP_FIRST)
395 #define LARCH_PROLOGUE_TEMP3_REGNUM (GP_TEMP_FIRST + 2)
396 #define LARCH_EPILOGUE_TEMP_REGNUM (GP_TEMP_FIRST)
398 #define CALLEE_SAVED_REG_NUMBER(REGNO) \
399 ((REGNO) >= 22 && (REGNO) <= 31 ? (REGNO) - 22 : -1)
401 #define LARCH_PROLOGUE_TEMP(MODE) \
402 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP_REGNUM)
403 #define LARCH_PROLOGUE_TEMP2(MODE) \
404 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP2_REGNUM)
405 #define LARCH_PROLOGUE_TEMP3(MODE) \
406 gen_rtx_REG (MODE, LARCH_PROLOGUE_TEMP3_REGNUM)
407 #define LARCH_EPILOGUE_TEMP(MODE) \
408 gen_rtx_REG (MODE, LARCH_EPILOGUE_TEMP_REGNUM)
410 /* Define this macro if it is as good or better to call a constant
411 function address than to call an address kept in a register. */
412 #define NO_FUNCTION_CSE 1
414 #define THREAD_POINTER_REGNUM (GP_REG_FIRST + 2)
416 /* Define the classes of registers for register constraints in the
417 machine description. Also define ranges of constants.
419 One of the classes must always be named ALL_REGS and include all hard regs.
420 If there is more than one class, another class must be named NO_REGS
421 and contain no registers.
423 The name GENERAL_REGS must be the name of a class (or an alias for
424 another name such as ALL_REGS). This is the class of registers
425 that is allowed by "r" in a register constraint.
426 Also, registers outside this class are allocated only when
427 instructions express preferences for them.
429 The classes must be numbered in nondecreasing order; that is,
430 a larger-numbered class must never be contained completely
431 in a smaller-numbered class.
433 For any two classes, it is very desirable that there be another
434 class that represents their union. */
436 enum reg_class
438 NO_REGS, /* no registers in set */
439 SIBCALL_REGS, /* registers used by indirect sibcalls */
440 JIRL_REGS, /* registers used by indirect calls */
441 CSR_REGS, /* integer registers except for $r0 and $r1 for lcsr. */
442 GR_REGS, /* integer registers */
443 FP_REGS, /* floating point registers */
444 FCC_REGS, /* status registers (fp status) */
445 FRAME_REGS, /* arg pointer and frame pointer */
446 ALL_REGS, /* all registers */
447 LIM_REG_CLASSES /* max value + 1 */
450 #define N_REG_CLASSES (int) LIM_REG_CLASSES
452 #define GENERAL_REGS GR_REGS
454 /* An initializer containing the names of the register classes as C
455 string constants. These names are used in writing some of the
456 debugging dumps. */
458 #define REG_CLASS_NAMES \
460 "NO_REGS", \
461 "SIBCALL_REGS", \
462 "JIRL_REGS", \
463 "CSR_REGS", \
464 "GR_REGS", \
465 "FP_REGS", \
466 "FCC_REGS", \
467 "FRAME_REGS", \
468 "ALL_REGS" \
471 /* An initializer containing the contents of the register classes,
472 as integers which are bit masks. The Nth integer specifies the
473 contents of class N. The way the integer MASK is interpreted is
474 that register R is in the class if `MASK & (1 << R)' is 1.
476 When the machine has more than 32 registers, an integer does not
477 suffice. Then the integers are replaced by sub-initializers,
478 braced groupings containing several integers. Each
479 sub-initializer must be suitable as an initializer for the type
480 `HARD_REG_SET' which is defined in `hard-reg-set.h'. */
482 #define REG_CLASS_CONTENTS \
484 { 0x00000000, 0x00000000, 0x00000000 }, /* NO_REGS */ \
485 { 0x001fd000, 0x00000000, 0x00000000 }, /* SIBCALL_REGS */ \
486 { 0xff9ffff0, 0x00000000, 0x00000000 }, /* JIRL_REGS */ \
487 { 0xfffffffc, 0x00000000, 0x00000000 }, /* CSR_REGS */ \
488 { 0xffffffff, 0x00000000, 0x00000000 }, /* GR_REGS */ \
489 { 0x00000000, 0xffffffff, 0x00000000 }, /* FP_REGS */ \
490 { 0x00000000, 0x00000000, 0x000000ff }, /* FCC_REGS */ \
491 { 0x00000000, 0x00000000, 0x00000300 }, /* FRAME_REGS */ \
492 { 0xffffffff, 0xffffffff, 0x000003ff } /* ALL_REGS */ \
495 /* A C expression whose value is a register class containing hard
496 register REGNO. In general there is more that one such class;
497 choose a class which is "minimal", meaning that no smaller class
498 also contains the register. */
500 #define REGNO_REG_CLASS(REGNO) loongarch_regno_to_class[(REGNO)]
502 /* A macro whose definition is the name of the class to which a
503 valid base register must belong. A base register is one used in
504 an address which is the register value plus a displacement. */
506 #define BASE_REG_CLASS (GR_REGS)
508 /* A macro whose definition is the name of the class to which a
509 valid index register must belong. An index register is one used
510 in an address where its value is either multiplied by a scale
511 factor or added to another register (as well as added to a
512 displacement). */
514 #define INDEX_REG_CLASS GR_REGS
516 /* We generally want to put call-clobbered registers ahead of
517 call-saved ones. (IRA expects this.) */
519 #define REG_ALLOC_ORDER \
520 { /* Call-clobbered GPRs. */ \
521 12, 13, 14, 15, 16, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 1, \
522 /* Call-saved GPRs. */ \
523 23, 24, 25, 26, 27, 28, 29, 30, 31, \
524 /* GPRs that can never be exposed to the register allocator. */ \
525 0, 2, 3, 21, 22, \
526 /* Call-clobbered FPRs. */ \
527 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, \
528 48, 49, 50, 51,52, 53, 54, 55, \
529 56, 57, 58, 59, 60, 61, 62, 63, \
530 /* None of the remaining classes have defined call-saved \
531 registers. */ \
532 64, 65, 66, 67, 68, 69, 70, 71, 72, 73}
534 #define IMM_BITS 12
535 #define IMM_REACH (HOST_WIDE_INT_1 << IMM_BITS)
536 #define HWIT_1U HOST_WIDE_INT_1U
538 /* True if VALUE is an unsigned 6-bit number. */
540 #define UIMM6_OPERAND(VALUE) (((VALUE) & ~(unsigned HOST_WIDE_INT) 0x3f) == 0)
542 /* True if VALUE is a signed 10-bit number. */
544 #define IMM10_OPERAND(VALUE) ((unsigned HOST_WIDE_INT) (VALUE) + 0x200 < 0x400)
546 /* True if VALUE is a signed 12-bit number. */
548 #define IMM12_OPERAND(VALUE) \
549 ((unsigned HOST_WIDE_INT) (VALUE) + IMM_REACH / 2 < IMM_REACH)
551 /* True if VALUE is a signed 13-bit number. */
553 #define IMM13_OPERAND(VALUE) \
554 ((unsigned HOST_WIDE_INT) (VALUE) + 0x1000 < 0x2000)
556 /* True if VALUE is a signed 16-bit number. */
558 #define IMM16_OPERAND(VALUE) \
559 ((unsigned HOST_WIDE_INT) (VALUE) + 0x8000 < 0x10000)
561 /* True if VALUE is an unsigned 12-bit number. */
563 #define IMM12_OPERAND_UNSIGNED(VALUE) \
564 (((VALUE) & ~(unsigned HOST_WIDE_INT) (IMM_REACH - 1)) == 0)
566 /* True if VALUE can be loaded into a register using LU12I. */
568 #define LU12I_OPERAND(VALUE) \
569 (((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) == ((HWIT_1U << 31) - IMM_REACH) \
570 || ((VALUE) | ((HWIT_1U << 31) - IMM_REACH)) + IMM_REACH == 0)
572 /* True if VALUE can be loaded into a register using LU32I. */
574 #define LU32I_OPERAND(VALUE) \
575 (((VALUE) | (((HWIT_1U << 19) - 1) << 32)) == (((HWIT_1U << 19) - 1) << 32) \
576 || ((VALUE) | (((HWIT_1U << 19) - 1) << 32)) + (HWIT_1U << 32) == 0)
578 /* True if VALUE can be loaded into a register using LU52I. */
580 #define HWIT_UC_0xFFF HOST_WIDE_INT_UC(0xfff)
581 #define LU52I_OPERAND(VALUE) \
582 (((VALUE) | (HWIT_UC_0xFFF << 52)) == (HWIT_UC_0xFFF << 52))
584 /* Return a value X with the low 12 bits clear, and such that
585 VALUE - X is a signed 12-bit value. */
587 #define CONST_HIGH_PART(VALUE) (((VALUE) + (IMM_REACH / 2)) & ~(IMM_REACH - 1))
589 #define CONST_LOW_PART(VALUE) ((VALUE) - CONST_HIGH_PART (VALUE))
591 /* True if VALUE can be added onto a register with one addu16i.d
592 instruction. */
594 #define ADDU16I_OPERAND(VALUE) \
595 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
596 && IMM16_OPERAND ((HOST_WIDE_INT) (VALUE) / 65536)))
598 /* True if VALUE can be added onto a register with two addi.{d/w}
599 instructions, but not one addi.{d/w} instruction. */
600 #define DUAL_IMM12_OPERAND(VALUE) \
601 (IN_RANGE ((VALUE), -4096, 4094) && !IMM12_OPERAND (VALUE))
603 /* True if VALUE can be added onto a register with two addu16i.d
604 instruction, but not one addu16i.d instruction. */
605 #define DUAL_ADDU16I_OPERAND(VALUE) \
606 (TARGET_64BIT && (((VALUE) & 0xffff) == 0 \
607 && !ADDU16I_OPERAND (VALUE) \
608 && IN_RANGE ((VALUE) / 65536, -0x10000, 0xfffe)))
610 #define IMM12_INT(X) IMM12_OPERAND (INTVAL (X))
611 #define IMM12_INT_UNSIGNED(X) IMM12_OPERAND_UNSIGNED (INTVAL (X))
612 #define LU12I_INT(X) LU12I_OPERAND (INTVAL (X))
613 #define LU32I_INT(X) LU32I_OPERAND (INTVAL (X))
614 #define LU52I_INT(X) LU52I_OPERAND (INTVAL (X))
615 #define LARCH_12BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -2048, 2047))
616 #define LARCH_9BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -256, 255))
617 #define LARCH_16BIT_OFFSET_P(OFFSET) (IN_RANGE (OFFSET, -32768, 32767))
618 #define LARCH_SHIFT_2_OFFSET_P(OFFSET) (((OFFSET) & 0x3) == 0)
620 /* Return the maximum number of consecutive registers
621 needed to represent mode MODE in a register of class CLASS. */
623 #define CLASS_MAX_NREGS(CLASS, MODE) loongarch_class_max_nregs (CLASS, MODE)
625 /* Stack layout; function entry, exit and calling. */
627 #define STACK_GROWS_DOWNWARD 1
629 #define FRAME_GROWS_DOWNWARD 1
631 #define RETURN_ADDR_RTX loongarch_return_addr
633 /* Similarly, don't use the least-significant bit to tell pointers to
634 code from vtable index. */
636 #define TARGET_PTRMEMFUNC_VBIT_LOCATION ptrmemfunc_vbit_in_delta
638 #define ELIMINABLE_REGS \
640 {ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
641 {ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
642 {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
643 {FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM}, \
646 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
647 (OFFSET) = loongarch_initial_elimination_offset ((FROM), (TO))
649 /* Allocate stack space for arguments at the beginning of each function. */
650 #define ACCUMULATE_OUTGOING_ARGS 1
652 /* The argument pointer always points to the first argument. */
653 #define FIRST_PARM_OFFSET(FNDECL) 0
655 #define REG_PARM_STACK_SPACE(FNDECL) 0
657 /* Define this if it is the responsibility of the caller to
658 allocate the area reserved for arguments passed in registers.
659 If `ACCUMULATE_OUTGOING_ARGS' is also defined, the only effect
660 of this macro is to determine whether the space is included in
661 `crtl->outgoing_args_size'. */
662 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
664 #define STACK_BOUNDARY (TARGET_ABI_LP64 ? 128 : 64)
666 /* This value controls how many pages we manually unroll the loop for when
667 generating stack clash probes. */
668 #define STACK_CLASH_MAX_UNROLL_PAGES 4
670 /* Symbolic macros for the registers used to return integer and floating
671 point values. */
673 #define GP_RETURN (GP_REG_FIRST + 4)
674 #define FP_RETURN ((TARGET_SOFT_FLOAT_ABI) ? GP_RETURN : (FP_REG_FIRST + 0))
676 #define MAX_ARGS_IN_REGISTERS 8
678 /* Symbolic macros for the first/last argument registers. */
680 #define GP_ARG_FIRST (GP_REG_FIRST + 4)
681 #define GP_ARG_LAST (GP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
682 #define FP_ARG_FIRST (FP_REG_FIRST + 0)
683 #define FP_ARG_LAST (FP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
685 /* True if MODE is vector and supported in a LSX vector register. */
686 #define LSX_SUPPORTED_MODE_P(MODE) \
687 (ISA_HAS_LSX \
688 && GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
689 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
690 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
692 #define LASX_SUPPORTED_MODE_P(MODE) \
693 (ISA_HAS_LASX \
694 && (GET_MODE_SIZE (MODE) == UNITS_PER_LSX_REG \
695 ||GET_MODE_SIZE (MODE) == UNITS_PER_LASX_REG) \
696 && (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
697 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT))
699 #define RECIP_MASK_NONE 0x00
700 #define RECIP_MASK_DIV 0x01
701 #define RECIP_MASK_SQRT 0x02
702 #define RECIP_MASK_RSQRT 0x04
703 #define RECIP_MASK_VEC_DIV 0x08
704 #define RECIP_MASK_VEC_SQRT 0x10
705 #define RECIP_MASK_VEC_RSQRT 0x20
706 #define RECIP_MASK_ALL (RECIP_MASK_DIV | RECIP_MASK_SQRT \
707 | RECIP_MASK_RSQRT | RECIP_MASK_VEC_SQRT \
708 | RECIP_MASK_VEC_DIV | RECIP_MASK_VEC_RSQRT)
710 #define TARGET_RECIP_DIV \
711 ((recip_mask & RECIP_MASK_DIV) != 0 && ISA_HAS_FRECIPE)
712 #define TARGET_RECIP_SQRT \
713 ((recip_mask & RECIP_MASK_SQRT) != 0 && ISA_HAS_FRECIPE)
714 #define TARGET_RECIP_RSQRT \
715 ((recip_mask & RECIP_MASK_RSQRT) != 0 && ISA_HAS_FRECIPE)
716 #define TARGET_RECIP_VEC_DIV \
717 ((recip_mask & RECIP_MASK_VEC_DIV) != 0 && ISA_HAS_FRECIPE)
718 #define TARGET_RECIP_VEC_SQRT \
719 ((recip_mask & RECIP_MASK_VEC_SQRT) != 0 && ISA_HAS_FRECIPE)
720 #define TARGET_RECIP_VEC_RSQRT \
721 ((recip_mask & RECIP_MASK_VEC_RSQRT) != 0 && ISA_HAS_FRECIPE)
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)