[Mlir-commits] [mlir] [mlir][spirv] Add spirv validation for module.mlir target test (PR #153227)

Igor Wodiany llvmlistbot at llvm.org
Thu Aug 14 00:37:01 PDT 2025


https://github.com/IgWod-IMG updated https://github.com/llvm/llvm-project/pull/153227

>From db6e00e691402f665c92400340ae013aca9da5aa Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Tue, 12 Aug 2025 15:13:31 +0000
Subject: [PATCH 1/3] [mlir][spirv] Add spirv validation for modules.mlir

Creating this patch as an example on using the new
`mlir-translate` flag. Eventually all the tests will
be updated to validate SPIR-V modules.
---
 mlir/test/Target/SPIRV/module.mlir | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/mlir/test/Target/SPIRV/module.mlir b/mlir/test/Target/SPIRV/module.mlir
index dcdcab8097e41..e610001a3a71f 100644
--- a/mlir/test/Target/SPIRV/module.mlir
+++ b/mlir/test/Target/SPIRV/module.mlir
@@ -1,21 +1,29 @@
-// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s
+// RUN: mlir-translate --no-implicit-module --test-spirv-roundtrip --split-input-file %s | FileCheck %s
+
+// REQUIRES: shell
+// RUN: %if spirv-tools %{ rm -rf %t %}
+// RUN: %if spirv-tools %{ mkdir %t && mlir-translate --no-implicit-module --serialize-spirv \ %}
+// RUN: %if spirv-tools %{ --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s \ %}
+// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} bash -c 'spirv-val {}' %}
 
 // CHECK:      spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
 // CHECK-NEXT:   spirv.func @foo() "Inline" {
 // CHECK-NEXT:     spirv.Return
 // CHECK-NEXT:   }
+// CHECK-NEXT:   spirv.EntryPoint "Vertex" @foo
 // CHECK-NEXT: }
 
 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
   spirv.func @foo() -> () "Inline" {
      spirv.Return
   }
+  spirv.EntryPoint "Vertex" @foo
 }
 
 // -----
 
 // CHECK: v1.5
-spirv.module Logical GLSL450 requires #spirv.vce<v1.5, [Shader], []> {
+spirv.module Logical GLSL450 requires #spirv.vce<v1.5, [Shader, Linkage], []> {
 }
 
 // -----
@@ -26,13 +34,13 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.6, [Shader, Linkage], []> {
 
 // -----
 
-// CHECK: [Shader, Float16]
-spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Float16], []> {
+// CHECK: [Shader, Float16, Linkage]
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Float16, Linkage], []> {
 }
 
 // -----
 
 // CHECK: [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]
-spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]> {
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]> {
 }
 

>From 63fd639c5d84bf38837d00e4165b23326fb2bf3a Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Wed, 13 Aug 2025 14:44:15 +0000
Subject: [PATCH 2/3] Simplify xargs

---
 mlir/test/Target/SPIRV/module.mlir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/Target/SPIRV/module.mlir b/mlir/test/Target/SPIRV/module.mlir
index e610001a3a71f..91156e1ad4486 100644
--- a/mlir/test/Target/SPIRV/module.mlir
+++ b/mlir/test/Target/SPIRV/module.mlir
@@ -4,7 +4,7 @@
 // RUN: %if spirv-tools %{ rm -rf %t %}
 // RUN: %if spirv-tools %{ mkdir %t && mlir-translate --no-implicit-module --serialize-spirv \ %}
 // RUN: %if spirv-tools %{ --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s \ %}
-// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} bash -c 'spirv-val {}' %}
+// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} spirv-val {} %}
 
 // CHECK:      spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
 // CHECK-NEXT:   spirv.func @foo() "Inline" {

>From e4decc3fae99f3881ba857cc187b841fe907705e Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Wed, 13 Aug 2025 16:16:39 +0000
Subject: [PATCH 3/3] Address feedback

---
 mlir/test/Target/SPIRV/module.mlir | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/test/Target/SPIRV/module.mlir b/mlir/test/Target/SPIRV/module.mlir
index 91156e1ad4486..d4000dfa53810 100644
--- a/mlir/test/Target/SPIRV/module.mlir
+++ b/mlir/test/Target/SPIRV/module.mlir
@@ -2,9 +2,9 @@
 
 // REQUIRES: shell
 // RUN: %if spirv-tools %{ rm -rf %t %}
-// RUN: %if spirv-tools %{ mkdir %t && mlir-translate --no-implicit-module --serialize-spirv \ %}
-// RUN: %if spirv-tools %{ --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s \ %}
-// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} spirv-val {} %}
+// RUN: %if spirv-tools %{ mkdir %t %}
+// RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
+// RUN: %if spirv-tools %{ ls %t/module*.spv | xargs -I{} spirv-val {} %}
 
 // CHECK:      spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
 // CHECK-NEXT:   spirv.func @foo() "Inline" {



More information about the Mlir-commits mailing list