diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp --- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertLaunchFuncToLLVMCalls.cpp @@ -126,7 +126,7 @@ /// Encodes the SPIR-V module's symbolic name into the name of the entry point /// function. static LogicalResult encodeKernelName(spirv::ModuleOp module) { - StringRef spvModuleName = *module.getSymName(); + StringRef spvModuleName = module.getSymName().value_or(kSPIRVModule); // We already know that the module contains exactly one entry point function // based on `getKernelGlobalVariables()` call. Update this function's name // to: diff --git a/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir --- a/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir +++ b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt --lower-host-to-llvm %s | FileCheck %s +// RUN: mlir-opt --lower-host-to-llvm %s -split-input-file | FileCheck %s module attributes {gpu.container_module, spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits>} { @@ -45,3 +45,35 @@ return } } + +// ----- + +// Check using a specified sym_name attribute. +module { + spirv.module Logical GLSL450 attributes { sym_name = "spirv.sym" } { + // CHECK: spirv.func @spirv.sym_bar + // CHECK: spirv.EntryPoint "GLCompute" @spirv.sym_bar + // CHECK: spirv.ExecutionMode @spirv.sym_bar "LocalSize", 1, 1, 1 + spirv.func @bar() "None" { + spirv.Return + } + spirv.EntryPoint "GLCompute" @bar + spirv.ExecutionMode @bar "LocalSize", 1, 1, 1 + } +} + +// ----- + +// Check using the default sym_name attribute. +module { + spirv.module Logical GLSL450 { + // CHECK: spirv.func @__spv___bar + // CHECK: spirv.EntryPoint "GLCompute" @__spv___bar + // CHECK: spirv.ExecutionMode @__spv___bar "LocalSize", 1, 1, 1 + spirv.func @bar() "None" { + spirv.Return + } + spirv.EntryPoint "GLCompute" @bar + spirv.ExecutionMode @bar "LocalSize", 1, 1, 1 + } +}