RISC-V: Put jump table in text for large code model

Large code model assume the data or rodata may put far away from
text section.  So we need to put jump table in text section for
large code model.

gcc/ChangeLog:

	* config/riscv/riscv.h (JUMP_TABLES_IN_TEXT_SECTION): Check if
	large code model.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/jump-table-large-code-model.c: New test.
This commit is contained in:
Kito Cheng 2025-04-14 16:03:07 +08:00
parent 45a708d7bf
commit 1d9e02bb7e
2 changed files with 25 additions and 1 deletions

View file

@ -888,7 +888,7 @@ extern enum riscv_cc get_riscv_cc (const rtx use);
#define ASM_OUTPUT_OPCODE(STREAM, PTR) \
(PTR) = riscv_asm_output_opcode(STREAM, PTR)
#define JUMP_TABLES_IN_TEXT_SECTION 0
#define JUMP_TABLES_IN_TEXT_SECTION (riscv_cmodel == CM_LARGE)
#define CASE_VECTOR_MODE SImode
#define CASE_VECTOR_PC_RELATIVE (riscv_cmodel != CM_MEDLOW)

View file

@ -0,0 +1,24 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gc -mabi=lp64 -mcmodel=large" } */
int foo(int x, int y)
{
switch(x){
case 0:
return 123 + y;
case 1:
return 456 + y;
case 2:
return 789 - y;
case 3:
return 12 * y;
case 4:
return 13 % y;
case 5:
return 11 *y;
}
return 0;
}
/* { dg-final { scan-assembler-not "\.section \.rodata" } } */