]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
amdgcn: Consolidate mkoffload setup constructors
authorAndrew Stubbs <ams@baylibre.com>
Tue, 11 Nov 2025 15:04:09 +0000 (15:04 +0000)
committerAndrew Stubbs <ams@baylibre.com>
Tue, 11 Nov 2025 15:32:20 +0000 (15:32 +0000)
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

index b284ff422ee73a5024e237f55b5796b4e1182f37..222adb2cd41d3ce5fb8094769feccd4cea442fa4 100644 (file)
@@ -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",