From 8e4f6b00556baf4835dc81e7858b484323b0db22 Mon Sep 17 00:00:00 2001 From: jasonwucj Date: Tue, 13 Jan 2015 05:59:03 +0000 Subject: [PATCH] [NDS32] Implement TARGET_ENCODE_SECTION_INFO to store specific flag in symbol_ref rtx. gcc/ * config/nds32/nds32.h (NDS32_SYMBOL_FLAG_RODATA): Define our own target-specific symbol_ref flag. (NDS32_SYMBOL_REF_RODATA_P): Define it to check if the symbol_ref resides in rodata section. * config/nds32/nds32.c (TARGET_ENCODE_SECTION_INFO): Define. (nds32_encode_section_info): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219514 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 +++++++++ gcc/config/nds32/nds32.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gcc/config/nds32/nds32.h | 8 ++++++++ 3 files changed, 59 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 047af3d..6166c08 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2015-01-13 Chung-Ju Wu + * config/nds32/nds32.h (NDS32_SYMBOL_FLAG_RODATA): Define our own + target-specific symbol_ref flag. + (NDS32_SYMBOL_REF_RODATA_P): Define it to check if the symbol_ref + resides in rodata section. + * config/nds32/nds32.c (TARGET_ENCODE_SECTION_INFO): Define. + (nds32_encode_section_info): New function. + +2015-01-13 Chung-Ju Wu + * config/nds32/nds32.md (call): Use pseudo instruction bal which clobbers TA_REGNUM if large code model is specified. (call_register): Likewise. diff --git a/gcc/config/nds32/nds32.c b/gcc/config/nds32/nds32.c index 91e797e..5128bfa 100644 --- a/gcc/config/nds32/nds32.c +++ b/gcc/config/nds32/nds32.c @@ -2107,6 +2107,45 @@ nds32_address_cost (rtx address, } +/* Dividing the Output into Sections (Texts, Data, . . . ). */ + +/* If references to a symbol or a constant must be treated differently + depending on something about the variable or function named by the symbol + (such as what section it is in), we use this hook to store flags + in symbol_ref rtx. */ +static void +nds32_encode_section_info (tree decl, rtx rtl, int new_decl_p) +{ + default_encode_section_info (decl, rtl, new_decl_p); + + /* For the memory rtx, if it references to rodata section, we can store + NDS32_SYMBOL_FLAG_RODATA flag into symbol_ref rtx so that the + nds32_legitimate_address_p() can determine how to treat such symbol_ref + based on -mcmodel=X and this information. */ + if (MEM_P (rtl) && MEM_READONLY_P (rtl)) + { + rtx addr = XEXP (rtl, 0); + + if (GET_CODE (addr) == SYMBOL_REF) + { + /* For (mem (symbol_ref X)) case. */ + SYMBOL_REF_FLAGS (addr) |= NDS32_SYMBOL_FLAG_RODATA; + } + else if (GET_CODE (addr) == CONST + && GET_CODE (XEXP (addr, 0)) == PLUS) + { + /* For (mem (const (plus (symbol_ref X) (const_int N)))) case. */ + rtx plus_op = XEXP (addr, 0); + rtx op0 = XEXP (plus_op, 0); + rtx op1 = XEXP (plus_op, 1); + + if (GET_CODE (op0) == SYMBOL_REF && CONST_INT_P (op1)) + SYMBOL_REF_FLAGS (op0) |= NDS32_SYMBOL_FLAG_RODATA; + } + } +} + + /* Defining the Output Assembler Language. */ /* -- The Overall Framework of an Assembler File. */ @@ -3669,6 +3708,9 @@ nds32_target_alignment (rtx label) /* Dividing the Output into Sections (Texts, Data, . . . ). */ +#undef TARGET_ENCODE_SECTION_INFO +#define TARGET_ENCODE_SECTION_INFO nds32_encode_section_info + /* Position Independent Code. */ diff --git a/gcc/config/nds32/nds32.h b/gcc/config/nds32/nds32.h index ac6cf42..e3362b6 100644 --- a/gcc/config/nds32/nds32.h +++ b/gcc/config/nds32/nds32.h @@ -24,6 +24,14 @@ /* The following are auxiliary macros or structure declarations that are used all over the nds32.c and nds32.h. */ +/* Use SYMBOL_FLAG_MACH_DEP to define our own symbol_ref flag. + It is used in nds32_encode_section_info() to store flag in symbol_ref + in case the symbol should be placed in .rodata section. + So that we can check it in nds32_legitimate_address_p(). */ +#define NDS32_SYMBOL_FLAG_RODATA \ + (SYMBOL_FLAG_MACH_DEP << 0) +#define NDS32_SYMBOL_REF_RODATA_P(x) \ + ((SYMBOL_REF_FLAGS (x) & NDS32_SYMBOL_FLAG_RODATA) != 0) /* Computing the Length of an Insn. */ #define ADJUST_INSN_LENGTH(INSN, LENGTH) \ -- 2.7.4