https://gcc.gnu.org/g:16dda95e39fa04e5ab43486a980e8866ee12efd7

commit r15-3718-g16dda95e39fa04e5ab43486a980e8866ee12efd7
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Sep 19 17:53:27 2024 +0200

    dwarf2asm: Use constexpr for eh_data_format_name initialization for C++14
    
    Similarly to the previous patch, dwarf2asm.cc had
    HAVE_DESIGNATED_INITIALIZERS support, and as fallback a huge switch.
    The switch from what I can see is expanded as a jump table with 256
    label pointers and code at those labels then loads addresses of
    string literals.
    The following patch instead uses a table with 256 const char * pointers,
    NULL for ICE, non-NULL for returning something, similarly to the
    HAVE_DESIGNATED_INITIALIZERS case.
    
    2024-09-19  Jakub Jelinek  <ja...@redhat.com>
    
            * dwarf2asm.cc (eh_data_format_name): Use constexpr initialization
            of format_names table for C++14 instead of a large switch.

Diff:
---
 gcc/dwarf2asm.cc | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2asm.cc b/gcc/dwarf2asm.cc
index 6c835bafbc46..72e831af99ed 100644
--- a/gcc/dwarf2asm.cc
+++ b/gcc/dwarf2asm.cc
@@ -488,14 +488,22 @@ eh_data_format_name (int format)
 {
 #if HAVE_DESIGNATED_INITIALIZERS
 #define S(p, v)                [p] = v,
+#elif __cpp_constexpr >= 201304L
+#define S(p, v)                names[p] = v;
 #else
 #define S(p, v)                case p: return v;
 #endif
 
 #if HAVE_DESIGNATED_INITIALIZERS
   __extension__ static const char * const format_names[256] = {
+#elif __cpp_constexpr >= 201304L
+  static constexpr struct format_names_s {
+    const char *names[256];
+    constexpr format_names_s () : names {}
+    {
 #else
-  switch (format) {
+  switch (format)
+    {
 #endif
 
   S(DW_EH_PE_absptr, "absolute")
@@ -635,8 +643,15 @@ eh_data_format_name (int format)
   gcc_assert (format >= 0 && format < 0x100 && format_names[format]);
 
   return format_names[format];
+#elif __cpp_constexpr >= 201304L
+    }
+  } format_names;
+
+  gcc_assert (format >= 0 && format < 0x100 && format_names.names[format]);
+
+  return format_names.names[format];
 #else
-  }
+    }
   gcc_unreachable ();
 #endif
 }

Reply via email to