diff options
author | Chung-Ju Wu <jasonwucj@gmail.com> | 2018-04-22 08:19:38 +0000 |
---|---|---|
committer | Chung-Ju Wu <jasonwucj@gcc.gnu.org> | 2018-04-22 08:19:38 +0000 |
commit | 79498ad8ba53725b8429deeb9eb81c66bc0c496d (patch) | |
tree | 30cf7d8656f4f4789dbb8fb4a882260c15432d3b | |
parent | 50256c75f49088898f6820944077e49202cac2da (diff) | |
download | gcc-79498ad8ba53725b8429deeb9eb81c66bc0c496d.zip gcc-79498ad8ba53725b8429deeb9eb81c66bc0c496d.tar.gz gcc-79498ad8ba53725b8429deeb9eb81c66bc0c496d.tar.bz2 |
[NDS32] Implement DATA_ALIGNMENT, LOCAL_ALIGNMENT and TARGET_CONSTANT_ALIGNMENT.
gcc/
* config/nds32/nds32-protos.h (nds32_data_alignment,
nds32_local_alignment): Declare.
* config/nds32/nds32.c (nds32_data_alignment, nds32_constant_alignment,
nds32_local_alignment): New functions.
(TARGET_CONSTANT_ALIGNMENT): Define.
* config/nds32/nds32.h (DATA_ALIGNMENT, LOCAL_ALIGNMENT): Define.
From-SVN: r259548
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/config/nds32/nds32-protos.h | 2 | ||||
-rw-r--r-- | gcc/config/nds32/nds32.c | 60 | ||||
-rw-r--r-- | gcc/config/nds32/nds32.h | 6 |
4 files changed, 77 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f71edd5..7c6fb76 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2018-04-22 Chung-Ju Wu <jasonwucj@gmail.com> + * config/nds32/nds32-protos.h (nds32_data_alignment, + nds32_local_alignment): Declare. + * config/nds32/nds32.c (nds32_data_alignment, nds32_constant_alignment, + nds32_local_alignment): New functions. + (TARGET_CONSTANT_ALIGNMENT): Define. + * config/nds32/nds32.h (DATA_ALIGNMENT, LOCAL_ALIGNMENT): Define. + +2018-04-22 Chung-Ju Wu <jasonwucj@gmail.com> + * config/nds32/nds32.c (TARGET_HARD_REGNO_MODE_OK): Move to the bottom of file. (TARGET_MODES_TIEABLE_P): Likewise. diff --git a/gcc/config/nds32/nds32-protos.h b/gcc/config/nds32/nds32-protos.h index b7522f1..2dce97e 100644 --- a/gcc/config/nds32/nds32-protos.h +++ b/gcc/config/nds32/nds32-protos.h @@ -223,6 +223,8 @@ extern int nds32_can_use_return_insn (void); /* Auxiliary functions to decide output alignment or not. */ extern int nds32_target_alignment (rtx_insn *); +extern unsigned int nds32_data_alignment (tree, unsigned int); +extern unsigned int nds32_local_alignment (tree, unsigned int); /* Auxiliary functions to expand builtin functions. */ diff --git a/gcc/config/nds32/nds32.c b/gcc/config/nds32/nds32.c index 76a72a8..a0012c0 100644 --- a/gcc/config/nds32/nds32.c +++ b/gcc/config/nds32/nds32.c @@ -4812,6 +4812,63 @@ nds32_target_alignment (rtx_insn *label) return 2; } +/* Return alignment for data. */ +unsigned int +nds32_data_alignment (tree data, + unsigned int basic_align) +{ + if ((basic_align < BITS_PER_WORD) + && (TREE_CODE (data) == ARRAY_TYPE + || TREE_CODE (data) == UNION_TYPE + || TREE_CODE (data) == RECORD_TYPE)) + return BITS_PER_WORD; + else + return basic_align; +} + +/* Return alignment for constant value. */ +static HOST_WIDE_INT +nds32_constant_alignment (const_tree constant, + HOST_WIDE_INT basic_align) +{ + /* Make string literal and constant for constructor to word align. */ + if (((TREE_CODE (constant) == STRING_CST + || TREE_CODE (constant) == CONSTRUCTOR + || TREE_CODE (constant) == UNION_TYPE + || TREE_CODE (constant) == RECORD_TYPE + || TREE_CODE (constant) == ARRAY_TYPE) + && basic_align < BITS_PER_WORD)) + return BITS_PER_WORD; + else + return basic_align; +} + +/* Return alignment for local variable. */ +unsigned int +nds32_local_alignment (tree local ATTRIBUTE_UNUSED, + unsigned int basic_align) +{ + bool at_least_align_to_word = false; + /* Make local array, struct and union at least align to word for make + sure it can unroll memcpy when initialize by constant. */ + switch (TREE_CODE (local)) + { + case ARRAY_TYPE: + case RECORD_TYPE: + case UNION_TYPE: + at_least_align_to_word = true; + break; + default: + at_least_align_to_word = false; + break; + } + if (at_least_align_to_word + && (basic_align < BITS_PER_WORD)) + return BITS_PER_WORD; + else + return basic_align; +} + bool nds32_split_double_word_load_store_p(rtx *operands, bool load_p) { @@ -4865,6 +4922,9 @@ nds32_use_blocks_for_constant_p (machine_mode mode, #undef TARGET_EXPAND_TO_RTL_HOOK #define TARGET_EXPAND_TO_RTL_HOOK nds32_expand_to_rtl_hook +#undef TARGET_CONSTANT_ALIGNMENT +#define TARGET_CONSTANT_ALIGNMENT nds32_constant_alignment + /* Layout of Source Language Data Types. */ diff --git a/gcc/config/nds32/nds32.h b/gcc/config/nds32/nds32.h index 9d673d5..6c2f1f8 100644 --- a/gcc/config/nds32/nds32.h +++ b/gcc/config/nds32/nds32.h @@ -688,6 +688,12 @@ enum nds32_builtins #define BIGGEST_ALIGNMENT 64 +#define DATA_ALIGNMENT(constant, basic_align) \ + nds32_data_alignment (constant, basic_align) + +#define LOCAL_ALIGNMENT(type, basic_align) \ + nds32_local_alignment (type, basic_align) + #define EMPTY_FIELD_BOUNDARY 32 #define STRUCTURE_SIZE_BOUNDARY 8 |