Skip to content

Commit 14ad799

Browse files
apinski-quicpinskia
authored andcommitted
varasm: Redo mergeable section support [PR121438]
We increased the switch conversion array decl alignment for better mergeability but it turns out that we increase the alignment on targets which don't support mergeable sections (e.g. NVPTX). Also after the fix for PR 121394, it becomes obvious that we can place any sized into the mergeable section instead of increasing the alignment. This implements that and now also fixes PR 121438 as we don't need to increase the alignment for the mergeable decls that were being created by the C++ front-end. Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/121438 PR middle-end/121444 gcc/ChangeLog: * output.h (MAX_ALIGN_MERGABLE): Rename to ... (MAX_MERGEABLE_BITSIZE): This. * tree-switch-conversion.cc (switch_conversion::build_one_array): Don't increase the alignment. * varasm.cc (mergeable_string_section): Use MAX_MERGEABLE_BITSIZE instead of MAX_ALIGN_MERGABLE. Also replace `/ 8` with `/ BITS_PER_UNIT`. (mergeable_constant_section): Select the mergeable section based on the bitsize rather than the alignment. Make sure the align is less than the entity size. Signed-off-by: Andrew Pinski <[email protected]>
1 parent 405f45a commit 14ad799

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

gcc/output.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ extern GTY(()) section *bss_noswitch_section;
545545
extern GTY(()) section *in_section;
546546
extern GTY(()) bool in_cold_section_p;
547547

548-
/* MAX bit alignment for mergable sections. */
549-
#define MAX_ALIGN_MERGABLE 256
548+
/* MAX size for mergeable sections in bits. */
549+
#define MAX_MERGEABLE_BITSIZE 256
550550

551551
extern section *get_unnamed_section (unsigned int, void (*) (const char *),
552552
const char *);

gcc/tree-switch-conversion.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
5555
#include "hwint.h"
5656
#include "internal-fn.h"
5757
#include "diagnostic-core.h"
58-
#include "output.h"
5958

6059
/* ??? For lang_hooks.types.type_for_mode, but is there a word_mode
6160
type in the GIMPLE type system that is language-independent? */
@@ -1031,19 +1030,10 @@ switch_conversion::build_one_array (int num, tree arr_index_type,
10311030
TREE_CONSTANT (decl) = 1;
10321031
TREE_READONLY (decl) = 1;
10331032
DECL_IGNORED_P (decl) = 1;
1034-
/* The decl is mergable since we don't take the address ever and
1033+
/* The decl is mergeable since we don't take the address ever and
10351034
just reading from it. */
10361035
DECL_MERGEABLE (decl) = 1;
10371036

1038-
/* Increase the alignments as needed. */
1039-
if (tree_to_uhwi (DECL_SIZE (decl)) > DECL_ALIGN (decl))
1040-
{
1041-
unsigned HOST_WIDE_INT s = tree_to_uhwi (DECL_SIZE (decl));
1042-
/* Only support up to the max supported for merging. */
1043-
if (s <= MAX_ALIGN_MERGABLE)
1044-
SET_DECL_ALIGN (decl, HOST_WIDE_INT_1U << ceil_log2 (s));
1045-
}
1046-
10471037
if (offloading_function_p (cfun->decl))
10481038
DECL_ATTRIBUTES (decl)
10491039
= tree_cons (get_identifier ("omp declare target"), NULL_TREE,

gcc/varasm.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
871871
if (HAVE_GAS_SHF_MERGE && flag_merge_constants
872872
&& TREE_CODE (decl) == STRING_CST
873873
&& TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
874-
&& align <= MAX_ALIGN_MERGABLE
874+
&& align <= MAX_MERGEABLE_BITSIZE
875875
&& (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
876876
&& TREE_STRING_LENGTH (decl) == len)
877877
{
@@ -885,7 +885,7 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
885885

886886
mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
887887
modesize = GET_MODE_BITSIZE (mode);
888-
if (modesize >= 8 && modesize <= MAX_ALIGN_MERGABLE
888+
if (modesize >= 8 && modesize <= MAX_MERGEABLE_BITSIZE
889889
&& (modesize & (modesize - 1)) == 0)
890890
{
891891
if (align < modesize)
@@ -906,8 +906,8 @@ mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
906906
if (i == len - unit || (unit == 1 && i == len))
907907
{
908908
sprintf (name, "%s.str%d.%d", prefix,
909-
modesize / 8, (int) (align / 8));
910-
flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
909+
modesize / BITS_PER_UNIT, (int) (align / BITS_PER_UNIT));
910+
flags |= (modesize / BITS_PER_UNIT) | SECTION_MERGE | SECTION_STRINGS;
911911
return get_section (name, flags, NULL);
912912
}
913913
}
@@ -923,17 +923,19 @@ mergeable_constant_section (unsigned HOST_WIDE_INT size_bits,
923923
unsigned HOST_WIDE_INT align,
924924
unsigned int flags)
925925
{
926+
unsigned HOST_WIDE_INT newsize;
927+
newsize = HOST_WIDE_INT_1U << ceil_log2 (size_bits);
926928
if (HAVE_GAS_SHF_MERGE && flag_merge_constants
927-
&& size_bits <= align
929+
&& newsize <= MAX_MERGEABLE_BITSIZE
928930
&& align >= 8
929-
&& align <= MAX_ALIGN_MERGABLE
931+
&& align <= newsize
930932
&& (align & (align - 1)) == 0)
931933
{
932934
const char *prefix = function_mergeable_rodata_prefix ();
933935
char *name = (char *) alloca (strlen (prefix) + 30);
934936

935-
sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
936-
flags |= (align / 8) | SECTION_MERGE;
937+
sprintf (name, "%s.cst%d", prefix, (int) (newsize / BITS_PER_UNIT));
938+
flags |= (newsize / BITS_PER_UNIT) | SECTION_MERGE;
937939
return get_section (name, flags, NULL);
938940
}
939941
return readonly_data_section;

0 commit comments

Comments
 (0)