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