We don't need every mkoffload runtime setting to use it's own constructor.
There was only two committed, but I have more uses for this soon.  In theory,
we could also use this setup to choose not to register the kernel with libgomp.

The behaviour is not changed, just the generated code structure.

gcc/ChangeLog:

        * config/gcn/mkoffload.cc (process_asm): Replace "configure_stack_size"
        constructor with a new regular function, "mkoffload_setup".
        (process_obj): Call mkoffload_setup from the "init" constructor.
---
 gcc/config/gcn/mkoffload.cc | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index b284ff422ee..222adb2cd41 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -661,18 +661,25 @@ process_asm (FILE *in, FILE *out, FILE *cfile)
     }
   fprintf (cfile, "\n};\n\n");
 
+  /* Start a mkoffload_setup function to hold zero-or-more setup actions.  */
+  fprintf (cfile,
+          "static void\n"
+          "mkoffload_setup (void)\n"
+          "{");
+
   /* Set the stack size if the user configured a value.  */
   if (gcn_stack_size)
     fprintf (cfile,
-            "static __attribute__((constructor))\n"
-            "void configure_stack_size (void)\n"
-            "{\n"
+            "\n"
+            "  /* Pass through the -mstack-size compile-time option.  */\n"
             "  const char *val = getenv (\"GCN_STACK_SIZE\");\n"
             "  if (!val || val[0] == '\\0')\n"
-            "    setenv (\"GCN_STACK_SIZE\", \"%d\", true);\n"
-            "}\n\n",
+            "    setenv (\"GCN_STACK_SIZE\", \"%d\", true);\n",
             gcn_stack_size);
 
+  /* End of mkoffload_setup function.  */
+  fprintf (cfile, "}\n\n");
+
   obstack_free (&fns_os, NULL);
   for (i = 0; i < dims_count; i++)
     free (dims[i].name);
@@ -737,6 +744,7 @@ process_obj (const char *fname_in, FILE *cfile, uint32_t 
omp_requires)
 
   fprintf (cfile, "static __attribute__((constructor)) void init (void)\n"
           "{\n"
+          "  mkoffload_setup ();\n"
           "  GOMP_offload_register_ver (%#x, __OFFLOAD_TABLE__,"
           " %d/*GCN*/, &gcn_data);\n"
           "};\n",
-- 
2.51.0

Reply via email to