[WebGPU] Preserve executable export names (#25195)

WebGPU renames shader entry points to names like `d0`, but also changes
the original executable export names. This breaks runtime lookup by the
original dispatch name.

Keep the export name separate from the shader entry point, following the
same approach as #24889 for CUDA by `weimin023`.

A simple add model compiles before the fix but fails to load with:
`NOT_FOUND; no function named 'add_dispatch_0_elementwise_4_f32' in
executable`

After the fix, it loads and returns the expected result.

---------

Signed-off-by: anutosh491 <andersonbhat491@gmail.com>
diff --git a/compiler/plugins/target/WebGPUSPIRV/WebGPUSPIRVTarget.cpp b/compiler/plugins/target/WebGPUSPIRV/WebGPUSPIRVTarget.cpp
index b0ac676..ce10da0 100644
--- a/compiler/plugins/target/WebGPUSPIRV/WebGPUSPIRVTarget.cpp
+++ b/compiler/plugins/target/WebGPUSPIRV/WebGPUSPIRVTarget.cpp
@@ -146,7 +146,8 @@
 
     // The schema expects each shader module to have entry points named "dN",
     // where N is the entry point ordinal. For each executable entry point op,
-    // rename the entry point symbol using that convention.
+    // rename the shader symbol using that convention. Keep the HAL export
+    // name unchanged because runtime function lookups use it.
     auto exportOps = llvm::to_vector(variantOp.getExportOps());
     SymbolTableCollection symbolTable;
     SymbolUserMap symbolUsers(symbolTable, variantOp);
@@ -166,7 +167,6 @@
           mlir::StringAttr::get(variantOp->getContext(), symbolName);
 
       symbolUsers.replaceAllUsesWith(entryPointFunc, nameAttr);
-      exportOp.setName(symbolName); // Same symbol reference? Not in table?
       SymbolTable::setSymbolName(entryPointFunc, symbolName);
     }
 
@@ -233,7 +233,9 @@
       }
       int64_t ordinal = ordinalAttr.getInt();
 
-      auto entryPointRef = builder.createString(exportOp.getName());
+      auto entryPointRef =
+          builder.createString(llvm::formatv("d{}", ordinal).str());
+      auto exportNameRef = builder.createString(exportOp.getName());
 
       iree_hal_webgpu_WorkgroupSize_t workgroupSize = {0};
       if (auto workgroupSizeAttr = exportOp.getWorkgroupSize()) {
@@ -266,6 +268,7 @@
       // TODO(#7824): Support multiple shader modules per executable.
       iree_hal_webgpu_ExportDef_shader_module_ordinal_add(builder, 0);
       iree_hal_webgpu_ExportDef_entry_point_add(builder, entryPointRef);
+      iree_hal_webgpu_ExportDef_name_add(builder, exportNameRef);
       iree_hal_webgpu_ExportDef_workgroup_size_add(builder, &workgroupSize);
       iree_hal_webgpu_ExportDef_constant_count_add(builder, constantCount);
       iree_hal_webgpu_ExportDef_binding_flags_add(builder, bindingFlagsRef);
diff --git a/runtime/src/iree/hal/drivers/webgpu/webgpu_executable.c b/runtime/src/iree/hal/drivers/webgpu/webgpu_executable.c
index 351fa96..f3fc433 100644
--- a/runtime/src/iree/hal/drivers/webgpu/webgpu_executable.c
+++ b/runtime/src/iree/hal/drivers/webgpu/webgpu_executable.c
@@ -54,6 +54,18 @@
   return (iree_hal_webgpu_executable_t*)base_value;
 }
 
+static iree_string_view_t iree_hal_webgpu_executable_export_name(
+    iree_hal_webgpu_ExportDef_table_t export_def) {
+  flatbuffers_string_t name = iree_hal_webgpu_ExportDef_name_get(export_def);
+  if (!name || flatbuffers_string_len(name) == 0) {
+    name = iree_hal_webgpu_ExportDef_entry_point_get(export_def);
+  }
+  if (!name) {
+    return iree_string_view_empty();
+  }
+  return iree_make_string_view(name, flatbuffers_string_len(name));
+}
+
 static iree_status_t iree_hal_webgpu_executable_calculate_name_storage_size(
     iree_hal_webgpu_ExportDef_vec_t exports_vec, iree_host_size_t export_count,
     iree_host_size_t* out_name_storage_size) {
@@ -61,16 +73,13 @@
   for (iree_host_size_t i = 0; i < export_count; ++i) {
     iree_hal_webgpu_ExportDef_table_t export_def =
         iree_hal_webgpu_ExportDef_vec_at(exports_vec, i);
-    flatbuffers_string_t entry_point =
-        iree_hal_webgpu_ExportDef_entry_point_get(export_def);
-    iree_host_size_t entry_point_length =
-        entry_point ? flatbuffers_string_len(entry_point) : 0;
-    if (entry_point_length == 0) {
+    iree_string_view_t name =
+        iree_hal_webgpu_executable_export_name(export_def);
+    if (iree_string_view_is_empty(name)) {
       return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
-                              "exports[%" PRIhsz "] has no entry point name",
-                              i);
+                              "exports[%" PRIhsz "] has no export name", i);
     }
-    if (!iree_host_size_checked_add(name_storage_size, entry_point_length + 1,
+    if (!iree_host_size_checked_add(name_storage_size, name.size + 1,
                                     &name_storage_size)) {
       return iree_make_status(IREE_STATUS_RESOURCE_EXHAUSTED,
                               "WebGPU executable export name storage exceeds "
@@ -119,11 +128,11 @@
                             "exports[%" PRIhsz "] has no entry point name",
                             export_ordinal);
   }
-  memcpy(*inout_name_storage, entry_point, entry_point_length);
-  (*inout_name_storage)[entry_point_length] = '\0';
-  out_entry->name =
-      iree_make_string_view(*inout_name_storage, entry_point_length);
-  *inout_name_storage += entry_point_length + 1;
+  iree_string_view_t name = iree_hal_webgpu_executable_export_name(export_def);
+  memcpy(*inout_name_storage, name.data, name.size);
+  (*inout_name_storage)[name.size] = '\0';
+  out_entry->name = iree_make_string_view(*inout_name_storage, name.size);
+  *inout_name_storage += name.size + 1;
 
   uint32_t constant_count =
       iree_hal_webgpu_ExportDef_constant_count_get(export_def);
@@ -163,8 +172,8 @@
   out_entry->pipeline_handle =
       iree_hal_webgpu_import_device_create_compute_pipeline(
           device_handle, /*layout_handle=*/0, (uintptr_t)wgsl_source,
-          (uint32_t)wgsl_source_length, (uintptr_t)out_entry->name.data,
-          (uint32_t)out_entry->name.size);
+          (uint32_t)wgsl_source_length, (uintptr_t)entry_point,
+          (uint32_t)entry_point_length);
   if (out_entry->pipeline_handle == 0) {
     return iree_make_status(
         IREE_STATUS_INTERNAL,
diff --git a/runtime/src/iree/schemas/webgpu_executable_def.fbs b/runtime/src/iree/schemas/webgpu_executable_def.fbs
index a9ed183..7be19ef 100644
--- a/runtime/src/iree/schemas/webgpu_executable_def.fbs
+++ b/runtime/src/iree/schemas/webgpu_executable_def.fbs
@@ -56,6 +56,10 @@
 
   // Optional debug information related to the export.
   debug_info:iree.hal.debug.ExportDef;
+
+  // Canonical hal.executable.export name used by runtime function lookup.
+  // The WGSL entry point may have a different name (for example, "d0").
+  name:string;
 }
 
 table ExecutableDef {