comparison gcc/config/riscv/riscv.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Definition of RISC-V target for GNU compiler. 1 /* Definition of RISC-V target for GNU compiler.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc. 2 Copyright (C) 2011-2018 Free Software Foundation, Inc.
3 Contributed by Andrew Waterman (andrew@sifive.com). 3 Contributed by Andrew Waterman (andrew@sifive.com).
4 Based on MIPS target for GNU compiler. 4 Based on MIPS target for GNU compiler.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
100 100
101 /* The `Q' extension is not yet supported. */ 101 /* The `Q' extension is not yet supported. */
102 #define UNITS_PER_FP_REG (TARGET_DOUBLE_FLOAT ? 8 : 4) 102 #define UNITS_PER_FP_REG (TARGET_DOUBLE_FLOAT ? 8 : 4)
103 103
104 /* The largest type that can be passed in floating-point registers. */ 104 /* The largest type that can be passed in floating-point registers. */
105 #define UNITS_PER_FP_ARG \ 105 #define UNITS_PER_FP_ARG \
106 (riscv_abi == ABI_ILP32 || riscv_abi == ABI_LP64 ? 0 : \ 106 ((riscv_abi == ABI_ILP32 || riscv_abi == ABI_ILP32E \
107 riscv_abi == ABI_ILP32F || riscv_abi == ABI_LP64F ? 4 : 8) \ 107 || riscv_abi == ABI_LP64) \
108 ? 0 \
109 : ((riscv_abi == ABI_ILP32F || riscv_abi == ABI_LP64F) ? 4 : 8))
108 110
109 /* Set the sizes of the core types. */ 111 /* Set the sizes of the core types. */
110 #define SHORT_TYPE_SIZE 16 112 #define SHORT_TYPE_SIZE 16
111 #define INT_TYPE_SIZE 32 113 #define INT_TYPE_SIZE 32
112 #define LONG_LONG_TYPE_SIZE 64 114 #define LONG_LONG_TYPE_SIZE 64
121 #define PARM_BOUNDARY BITS_PER_WORD 123 #define PARM_BOUNDARY BITS_PER_WORD
122 124
123 /* Allocation boundary (in *bits*) for the code of a function. */ 125 /* Allocation boundary (in *bits*) for the code of a function. */
124 #define FUNCTION_BOUNDARY (TARGET_RVC ? 16 : 32) 126 #define FUNCTION_BOUNDARY (TARGET_RVC ? 16 : 32)
125 127
128 /* The smallest supported stack boundary the calling convention supports. */
129 #define STACK_BOUNDARY \
130 (riscv_abi == ABI_ILP32E ? BITS_PER_WORD : 2 * BITS_PER_WORD)
131
132 /* The ABI stack alignment. */
133 #define ABI_STACK_BOUNDARY (riscv_abi == ABI_ILP32E ? BITS_PER_WORD : 128)
134
126 /* There is no point aligning anything to a rounder boundary than this. */ 135 /* There is no point aligning anything to a rounder boundary than this. */
127 #define BIGGEST_ALIGNMENT 128 136 #define BIGGEST_ALIGNMENT 128
128 137
129 /* The user-level ISA permits unaligned accesses, but they are not required 138 /* The user-level ISA permits unaligned accesses, but they are not required
130 of the privileged architecture. */ 139 of the privileged architecture. */
149 158
150 If the macro is defined, its definition should be a C expression; 159 If the macro is defined, its definition should be a C expression;
151 a nonzero value for the expression enables this behavior. */ 160 a nonzero value for the expression enables this behavior. */
152 161
153 #define PCC_BITFIELD_TYPE_MATTERS 1 162 #define PCC_BITFIELD_TYPE_MATTERS 1
163
164 /* An integer expression for the size in bits of the largest integer machine
165 mode that should actually be used. We allow pairs of registers. */
166 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (TARGET_64BIT ? TImode : DImode)
154 167
155 /* If defined, a C expression to compute the alignment for a static 168 /* If defined, a C expression to compute the alignment for a static
156 variable. TYPE is the data type, and ALIGN is the alignment that 169 variable. TYPE is the data type, and ALIGN is the alignment that
157 the object would ordinarily have. The value of this macro is used 170 the object would ordinarily have. The value of this macro is used
158 instead of that alignment to align the object. 171 instead of that alignment to align the object.
231 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
232 /* Others. */ \ 245 /* Others. */ \
233 1, 1 \ 246 1, 1 \
234 } 247 }
235 248
236 /* a0-a7, t0-a6, fa0-fa7, and ft0-ft11 are volatile across calls. 249 /* a0-a7, t0-t6, fa0-fa7, and ft0-ft11 are volatile across calls.
237 The call RTLs themselves clobber ra. */ 250 The call RTLs themselves clobber ra. */
238 251
239 #define CALL_USED_REGISTERS \ 252 #define CALL_USED_REGISTERS \
240 { /* General registers. */ \ 253 { /* General registers. */ \
241 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, \ 254 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, \
248 } 261 }
249 262
250 /* Internal macros to classify an ISA register's type. */ 263 /* Internal macros to classify an ISA register's type. */
251 264
252 #define GP_REG_FIRST 0 265 #define GP_REG_FIRST 0
253 #define GP_REG_LAST 31 266 #define GP_REG_LAST (TARGET_RVE ? 15 : 31)
254 #define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1) 267 #define GP_REG_NUM (GP_REG_LAST - GP_REG_FIRST + 1)
255 268
256 #define FP_REG_FIRST 32 269 #define FP_REG_FIRST 32
257 #define FP_REG_LAST 63 270 #define FP_REG_LAST 63
258 #define FP_REG_NUM (FP_REG_LAST - FP_REG_FIRST + 1) 271 #define FP_REG_NUM (FP_REG_LAST - FP_REG_FIRST + 1)
470 If `ACCUMULATE_OUTGOING_ARGS' is also defined, the only effect 483 If `ACCUMULATE_OUTGOING_ARGS' is also defined, the only effect
471 of this macro is to determine whether the space is included in 484 of this macro is to determine whether the space is included in
472 `crtl->outgoing_args_size'. */ 485 `crtl->outgoing_args_size'. */
473 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1 486 #define OUTGOING_REG_PARM_STACK_SPACE(FNTYPE) 1
474 487
475 #define STACK_BOUNDARY 128 488 #define PREFERRED_STACK_BOUNDARY riscv_stack_boundary
476 489
477 /* Symbolic macros for the registers used to return integer and floating 490 /* Symbolic macros for the registers used to return integer and floating
478 point values. */ 491 point values. */
479 492
480 #define GP_RETURN GP_ARG_FIRST 493 #define GP_RETURN GP_ARG_FIRST
481 #define FP_RETURN (UNITS_PER_FP_ARG == 0 ? GP_RETURN : FP_ARG_FIRST) 494 #define FP_RETURN (UNITS_PER_FP_ARG == 0 ? GP_RETURN : FP_ARG_FIRST)
482 495
483 #define MAX_ARGS_IN_REGISTERS 8 496 #define MAX_ARGS_IN_REGISTERS (riscv_abi == ABI_ILP32E ? 6 : 8)
484 497
485 /* Symbolic macros for the first/last argument registers. */ 498 /* Symbolic macros for the first/last argument registers. */
486 499
487 #define GP_ARG_FIRST (GP_REG_FIRST + 10) 500 #define GP_ARG_FIRST (GP_REG_FIRST + 10)
488 #define GP_ARG_LAST (GP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1) 501 #define GP_ARG_LAST (GP_ARG_FIRST + MAX_ARGS_IN_REGISTERS - 1)
501 riscv_function_value (VALTYPE, FUNC, VOIDmode) 514 riscv_function_value (VALTYPE, FUNC, VOIDmode)
502 515
503 #define FUNCTION_VALUE_REGNO_P(N) ((N) == GP_RETURN || (N) == FP_RETURN) 516 #define FUNCTION_VALUE_REGNO_P(N) ((N) == GP_RETURN || (N) == FP_RETURN)
504 517
505 /* 1 if N is a possible register number for function argument passing. 518 /* 1 if N is a possible register number for function argument passing.
506 We have no FP argument registers when soft-float. When FP registers 519 We have no FP argument registers when soft-float. */
507 are 32 bits, we can't directly reference the odd numbered ones. */
508 520
509 /* Accept arguments in a0-a7, and in fa0-fa7 if permitted by the ABI. */ 521 /* Accept arguments in a0-a7, and in fa0-fa7 if permitted by the ABI. */
510 #define FUNCTION_ARG_REGNO_P(N) \ 522 #define FUNCTION_ARG_REGNO_P(N) \
511 (IN_RANGE ((N), GP_ARG_FIRST, GP_ARG_LAST) \ 523 (IN_RANGE ((N), GP_ARG_FIRST, GP_ARG_LAST) \
512 || (UNITS_PER_FP_ARG && IN_RANGE ((N), FP_ARG_FIRST, FP_ARG_LAST))) 524 || (UNITS_PER_FP_ARG && IN_RANGE ((N), FP_ARG_FIRST, FP_ARG_LAST)))
524 For a library call, FNTYPE is 0. */ 536 For a library call, FNTYPE is 0. */
525 537
526 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \ 538 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT, N_NAMED_ARGS) \
527 memset (&(CUM), 0, sizeof (CUM)) 539 memset (&(CUM), 0, sizeof (CUM))
528 540
529 #define EPILOGUE_USES(REGNO) ((REGNO) == RETURN_ADDR_REGNUM) 541 #define EPILOGUE_USES(REGNO) riscv_epilogue_uses (REGNO)
530 542
531 /* ABI requires 16-byte alignment, even on RV32. */ 543 /* Align based on stack boundary, which might have been set by the user. */
532 #define RISCV_STACK_ALIGN(LOC) (((LOC) + 15) & -16) 544 #define RISCV_STACK_ALIGN(LOC) \
545 (((LOC) + ((PREFERRED_STACK_BOUNDARY/8)-1)) & -(PREFERRED_STACK_BOUNDARY/8))
533 546
534 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function, 547 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
535 the stack pointer does not matter. The value is tested only in 548 the stack pointer does not matter. The value is tested only in
536 functions that have frame pointers. 549 functions that have frame pointers.
537 No definition is equivalent to always zero. */ 550 No definition is equivalent to always zero. */
583 (CONSTANT_P (X) && memory_address_p (SImode, X)) 596 (CONSTANT_P (X) && memory_address_p (SImode, X))
584 597
585 /* This handles the magic '..CURRENT_FUNCTION' symbol, which means 598 /* This handles the magic '..CURRENT_FUNCTION' symbol, which means
586 'the start of the function that this code is output in'. */ 599 'the start of the function that this code is output in'. */
587 600
588 #define ASM_OUTPUT_LABELREF(FILE,NAME) \ 601 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
589 if (strcmp (NAME, "..CURRENT_FUNCTION") == 0) \ 602 do { \
590 asm_fprintf ((FILE), "%U%s", \ 603 if (strcmp (NAME, "..CURRENT_FUNCTION") == 0) \
591 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \ 604 asm_fprintf ((FILE), "%U%s", \
592 else \ 605 XSTR (XEXP (DECL_RTL (current_function_decl), \
593 asm_fprintf ((FILE), "%U%s", (NAME)) 606 0), 0)); \
607 else \
608 asm_fprintf ((FILE), "%U%s", (NAME)); \
609 } while (0)
594 610
595 #define JUMP_TABLES_IN_TEXT_SECTION 0 611 #define JUMP_TABLES_IN_TEXT_SECTION 0
596 #define CASE_VECTOR_MODE SImode 612 #define CASE_VECTOR_MODE SImode
597 #define CASE_VECTOR_PC_RELATIVE (riscv_cmodel != CM_MEDLOW) 613 #define CASE_VECTOR_PC_RELATIVE (riscv_cmodel != CM_MEDLOW)
598 614
613 #define DEFAULT_SIGNED_CHAR 0 629 #define DEFAULT_SIGNED_CHAR 0
614 630
615 #define MOVE_MAX UNITS_PER_WORD 631 #define MOVE_MAX UNITS_PER_WORD
616 #define MAX_MOVE_MAX 8 632 #define MAX_MOVE_MAX 8
617 633
618 #define SLOW_BYTE_ACCESS 0 634 /* The SPARC port says:
619 635 Nonzero if access to memory by bytes is slow and undesirable.
620 #define SHIFT_COUNT_TRUNCATED 1 636 For RISC chips, it means that access to memory by bytes is no
637 better than access by words when possible, so grab a whole word
638 and maybe make use of that. */
639 #define SLOW_BYTE_ACCESS 1
640
641 /* Using SHIFT_COUNT_TRUNCATED is discouraged, so we handle this with patterns
642 in the md file instead. */
643 #define SHIFT_COUNT_TRUNCATED 0
621 644
622 /* Specify the machine mode that pointers have. 645 /* Specify the machine mode that pointers have.
623 After generation of rtl, the compiler makes no further distinction 646 After generation of rtl, the compiler makes no further distinction
624 between pointers and any other objects of this machine mode. */ 647 between pointers and any other objects of this machine mode. */
625 648
801 #define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int") 824 #define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")
802 825
803 #undef PTRDIFF_TYPE 826 #undef PTRDIFF_TYPE
804 #define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "int") 827 #define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "int")
805 828
829 /* The maximum number of bytes copied by one iteration of a movmemsi loop. */
830
831 #define RISCV_MAX_MOVE_BYTES_PER_LOOP_ITER (UNITS_PER_WORD * 4)
832
833 /* The maximum number of bytes that can be copied by a straight-line
834 movmemsi implementation. */
835
836 #define RISCV_MAX_MOVE_BYTES_STRAIGHT (RISCV_MAX_MOVE_BYTES_PER_LOOP_ITER * 3)
837
806 /* If a memory-to-memory move would take MOVE_RATIO or more simple 838 /* If a memory-to-memory move would take MOVE_RATIO or more simple
807 move-instruction pairs, we will do a movmem or libcall instead. */ 839 move-instruction pairs, we will do a movmem or libcall instead.
808 840 Do not use move_by_pieces at all when strict alignment is not
809 #define MOVE_RATIO(speed) (CLEAR_RATIO (speed) / 2) 841 in effect but the target has slow unaligned accesses; in this
842 case, movmem or libcall is more efficient. */
843
844 #define MOVE_RATIO(speed) \
845 (!STRICT_ALIGNMENT && riscv_slow_unaligned_access_p ? 1 : \
846 (speed) ? RISCV_MAX_MOVE_BYTES_PER_LOOP_ITER / UNITS_PER_WORD : \
847 CLEAR_RATIO (speed) / 2)
810 848
811 /* For CLEAR_RATIO, when optimizing for size, give a better estimate 849 /* For CLEAR_RATIO, when optimizing for size, give a better estimate
812 of the length of a memset call, but use the default otherwise. */ 850 of the length of a memset call, but use the default otherwise. */
813 851
814 #define CLEAR_RATIO(speed) ((speed) ? 16 : 6) 852 #define CLEAR_RATIO(speed) ((speed) ? 16 : 6)
819 857
820 #define SET_RATIO(speed) (CLEAR_RATIO (speed) - ((speed) ? 0 : 2)) 858 #define SET_RATIO(speed) (CLEAR_RATIO (speed) - ((speed) ? 0 : 2))
821 859
822 #ifndef USED_FOR_TARGET 860 #ifndef USED_FOR_TARGET
823 extern const enum reg_class riscv_regno_to_class[]; 861 extern const enum reg_class riscv_regno_to_class[];
862 extern bool riscv_slow_unaligned_access_p;
863 extern unsigned riscv_stack_boundary;
824 #endif 864 #endif
825 865
826 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \ 866 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
827 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) 867 (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
828 868
830 "%{march=rv32*:32}" \ 870 "%{march=rv32*:32}" \
831 "%{march=rv64*:64}" \ 871 "%{march=rv64*:64}" \
832 872
833 #define ABI_SPEC \ 873 #define ABI_SPEC \
834 "%{mabi=ilp32:ilp32}" \ 874 "%{mabi=ilp32:ilp32}" \
875 "%{mabi=ilp32e:ilp32e}" \
835 "%{mabi=ilp32f:ilp32f}" \ 876 "%{mabi=ilp32f:ilp32f}" \
836 "%{mabi=ilp32d:ilp32d}" \ 877 "%{mabi=ilp32d:ilp32d}" \
837 "%{mabi=lp64:lp64}" \ 878 "%{mabi=lp64:lp64}" \
838 "%{mabi=lp64f:lp64f}" \ 879 "%{mabi=lp64f:lp64f}" \
839 "%{mabi=lp64d:lp64d}" \ 880 "%{mabi=lp64d:lp64d}" \
853 #define OPCODE_ADDI 0x13 894 #define OPCODE_ADDI 0x13
854 #define SHIFT_RD 7 895 #define SHIFT_RD 7
855 #define SHIFT_RS1 15 896 #define SHIFT_RS1 15
856 #define SHIFT_IMM 20 897 #define SHIFT_IMM 20
857 #define IMM_BITS 12 898 #define IMM_BITS 12
899 #define C_SxSP_BITS 6
858 900
859 #define IMM_REACH (1LL << IMM_BITS) 901 #define IMM_REACH (1LL << IMM_BITS)
860 #define CONST_HIGH_PART(VALUE) (((VALUE) + (IMM_REACH/2)) & ~(IMM_REACH-1)) 902 #define CONST_HIGH_PART(VALUE) (((VALUE) + (IMM_REACH/2)) & ~(IMM_REACH-1))
861 #define CONST_LOW_PART(VALUE) ((VALUE) - CONST_HIGH_PART (VALUE)) 903 #define CONST_LOW_PART(VALUE) ((VALUE) - CONST_HIGH_PART (VALUE))
862 904
905 #define SWSP_REACH (4LL << C_SxSP_BITS)
906 #define SDSP_REACH (8LL << C_SxSP_BITS)
907
863 #endif /* ! GCC_RISCV_H */ 908 #endif /* ! GCC_RISCV_H */