From 748edce6b831a453831bf8d8688fdbae68d44e14 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 21 Aug 2019 18:04:56 -0700 Subject: [PATCH] Remove the wrapping function in SPIR-V (de)serialization Previously Module and Function are builtinn constructs in MLIR. Due to the structural requirements we must wrap the SPIR-V module inside a Function inside a Module. Now the requirement is lifted and we can remove the wrapping function! :) PiperOrigin-RevId: 264736051 --- .../SPIRV/Serialization/ConvertFromBinary.cpp | 21 +- .../SPIRV/Serialization/ConvertToBinary.cpp | 20 +- .../SPIRV/Serialization/access_chain.mlir | 21 +- .../SPIRV/Serialization/array_stride.mlir | 15 +- .../Dialect/SPIRV/Serialization/bin_ops.mlir | 243 +++++++------ .../Dialect/SPIRV/Serialization/constant.mlir | 329 +++++++++--------- .../Dialect/SPIRV/Serialization/entry.mlir | 19 +- .../SPIRV/Serialization/entry_interface.mlir | 27 +- .../SPIRV/Serialization/execution_mode.mlir | 17 +- .../SPIRV/Serialization/load_store.mlir | 15 +- .../SPIRV/Serialization/minimal-module.mlir | 10 +- .../SPIRV/Serialization/spec_constant.mlir | 42 +-- .../Dialect/SPIRV/Serialization/struct.mlir | 29 +- .../SPIRV/Serialization/terminator.mlir | 30 +- .../Serialization/variable_reference.mlir | 21 +- .../SPIRV/Serialization/variables.mlir | 24 +- .../SPIRV/Serialization/variables_init.mlir | 15 +- 17 files changed, 411 insertions(+), 487 deletions(-) diff --git a/mlir/lib/Dialect/SPIRV/Serialization/ConvertFromBinary.cpp b/mlir/lib/Dialect/SPIRV/Serialization/ConvertFromBinary.cpp index cda56e27b1aa..66b178b6480a 100644 --- a/mlir/lib/Dialect/SPIRV/Serialization/ConvertFromBinary.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/ConvertFromBinary.cpp @@ -33,19 +33,6 @@ using namespace mlir; -// Adds a one-block function named as `spirv_module` to `module` and returns the -// block. The created block will be terminated by `std.return`. -Block *createOneBlockFunction(Builder builder, ModuleOp module) { - auto fnType = builder.getFunctionType(/*inputs=*/{}, /*results=*/{}); - auto fn = FuncOp::create(builder.getUnknownLoc(), "spirv_module", fnType); - module.push_back(fn); - - auto *block = fn.addEntryBlock(); - OpBuilder(block).create(builder.getUnknownLoc()); - - return block; -} - // Deserializes the SPIR-V binary module stored in the file named as // `inputFilename` and returns a module containing the SPIR-V module. OwningModuleRef deserializeModule(llvm::StringRef inputFilename, @@ -75,15 +62,9 @@ OwningModuleRef deserializeModule(llvm::StringRef inputFilename, if (!spirvModule) return {}; - // TODO(antiagainst): due to the restriction of the current translation - // infrastructure, we must return a MLIR module here. So we are wrapping the - // converted SPIR-V ModuleOp inside a MLIR module. This should be changed to - // return the SPIR-V ModuleOp directly after module and function are migrated - // to be general ops. OwningModuleRef module(ModuleOp::create( FileLineColLoc::get(inputFilename, /*line=*/0, /*column=*/0, context))); - Block *block = createOneBlockFunction(builder, module.get()); - block->push_front(spirvModule->getOperation()); + module->getBody()->push_front(spirvModule->getOperation()); return module; } diff --git a/mlir/lib/Dialect/SPIRV/Serialization/ConvertToBinary.cpp b/mlir/lib/Dialect/SPIRV/Serialization/ConvertToBinary.cpp index 5e8c663e2109..8267e6b70b65 100644 --- a/mlir/lib/Dialect/SPIRV/Serialization/ConvertToBinary.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/ConvertToBinary.cpp @@ -40,22 +40,12 @@ LogicalResult serializeModule(ModuleOp module, StringRef outputFilename) { bool done = false; auto result = failure(); - // TODO(antiagainst): we are checking there is only one SPIR-V ModuleOp in - // this module and serialize it. This is due to the restriction of the current - // translation infrastructure; we must take in a MLIR module here. So we are - // wrapping the SPIR-V ModuleOp inside a MLIR module. This should be changed - // to take in the SPIR-V ModuleOp directly after module and function are - // migrated to be general ops. - for (auto fn : module.getOps()) { - fn.walk([&](spirv::ModuleOp spirvModule) { - if (done) { - spirvModule.emitError("found more than one 'spv.module' op"); - return; - } + for (auto spirvModule : module.getOps()) { + if (done) + return spirvModule.emitError("found more than one 'spv.module' op"); - done = true; - result = spirv::serialize(spirvModule, binary); - }); + done = true; + result = spirv::serialize(spirvModule, binary); } if (failed(result)) diff --git a/mlir/test/Dialect/SPIRV/Serialization/access_chain.mlir b/mlir/test/Dialect/SPIRV/Serialization/access_chain.mlir index 3602b62524db..e2172f6e1007 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/access_chain.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/access_chain.mlir @@ -1,15 +1,12 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @foo() { - spv.module "Logical" "VulkanKHR" { - func @access_chain(%arg0 : !spv.ptr>, Function>, - %arg1 : i32, %arg2 : i32) { - // CHECK: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}] : !spv.ptr>, Function> - // CHECK-NEXT: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spv.ptr>, Function> - %1 = spv.AccessChain %arg0[%arg1] : !spv.ptr>, Function> - %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr>, Function> - spv.Return - } +spv.module "Logical" "VulkanKHR" { + func @access_chain(%arg0 : !spv.ptr>, Function>, + %arg1 : i32, %arg2 : i32) { + // CHECK: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}] : !spv.ptr>, Function> + // CHECK-NEXT: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spv.ptr>, Function> + %1 = spv.AccessChain %arg0[%arg1] : !spv.ptr>, Function> + %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr>, Function> + spv.Return } - return -} \ No newline at end of file +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/array_stride.mlir b/mlir/test/Dialect/SPIRV/Serialization/array_stride.mlir index b7229e80ffd4..fa76c8a4c445 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/array_stride.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/array_stride.mlir @@ -1,13 +1,10 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirvmodule() { - spv.module "Logical" "VulkanKHR" { - func @array_stride(%arg0 : !spv.ptr [128]>, StorageBuffer>, - %arg1 : i32, %arg2 : i32) { - // CHECK: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spv.ptr [128]>, StorageBuffer> - %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr [128]>, StorageBuffer> - spv.Return - } +spv.module "Logical" "VulkanKHR" { + func @array_stride(%arg0 : !spv.ptr [128]>, StorageBuffer>, + %arg1 : i32, %arg2 : i32) { + // CHECK: {{%.*}} = spv.AccessChain {{%.*}}[{{%.*}}, {{%.*}}] : !spv.ptr [128]>, StorageBuffer> + %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr [128]>, StorageBuffer> + spv.Return } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/bin_ops.mlir b/mlir/test/Dialect/SPIRV/Serialization/bin_ops.mlir index dc0f36389c1f..891d9fd142a1 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/bin_ops.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/bin_ops.mlir @@ -1,127 +1,124 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_bin_ops() -> () { - spv.module "Logical" "VulkanKHR" { - func @fmul(%arg0 : f32, %arg1 : f32) { - // CHECK: {{%.*}}= spv.FMul {{%.*}}, {{%.*}} : f32 - %0 = spv.FMul %arg0, %arg1 : f32 - spv.Return - } - func @fadd(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { - // CHECK: {{%.*}} = spv.FAdd {{%.*}}, {{%.*}} : vector<4xf32> - %0 = spv.FAdd %arg0, %arg1 : vector<4xf32> - spv.Return - } - func @fdiv(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { - // CHECK: {{%.*}} = spv.FDiv {{%.*}}, {{%.*}} : vector<4xf32> - %0 = spv.FDiv %arg0, %arg1 : vector<4xf32> - spv.Return - } - func @fmod(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { - // CHECK: {{%.*}} = spv.FMod {{%.*}}, {{%.*}} : vector<4xf32> - %0 = spv.FMod %arg0, %arg1 : vector<4xf32> - spv.Return - } - func @fsub(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { - // CHECK: {{%.*}} = spv.FSub {{%.*}}, {{%.*}} : vector<4xf32> - %0 = spv.FSub %arg0, %arg1 : vector<4xf32> - spv.Return - } - func @frem(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { - // CHECK: {{%.*}} = spv.FRem {{%.*}}, {{%.*}} : vector<4xf32> - %0 = spv.FRem %arg0, %arg1 : vector<4xf32> - spv.Return - } - func @iadd(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.IAdd {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.IAdd %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @isub(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.ISub {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.ISub %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @imul(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.IMul {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.IMul %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @udiv(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.UDiv {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.UDiv %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @umod(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.UMod {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.UMod %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @sdiv(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.SDiv {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.SDiv %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @smod(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.SMod {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.SMod %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @srem(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { - // CHECK: {{%.*}} = spv.SRem {{%.*}}, {{%.*}} : vector<4xi32> - %0 = spv.SRem %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @iequal_scalar(%arg0: i32, %arg1: i32) { - // CHECK: {{.*}} = spv.IEqual {{.*}}, {{.*}} : i32 - %0 = spv.IEqual %arg0, %arg1 : i32 - spv.Return - } - func @inotequal_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.INotEqual {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.INotEqual %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @sgt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.SGreaterThan {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.SGreaterThan %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @sge_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.SGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.SGreaterThanEqual %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @slt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.SLessThan {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.SLessThan %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @slte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.SLessThanEqual {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.SLessThanEqual %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @ugt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.UGreaterThan {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.UGreaterThan %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @ugte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.UGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.UGreaterThanEqual %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @ult_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.ULessThan {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.ULessThan %arg0, %arg1 : vector<4xi32> - spv.Return - } - func @ulte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { - // CHECK: {{.*}} = spv.ULessThanEqual {{.*}}, {{.*}} : vector<4xi32> - %0 = spv.ULessThanEqual %arg0, %arg1 : vector<4xi32> - spv.Return - } +spv.module "Logical" "VulkanKHR" { + func @fmul(%arg0 : f32, %arg1 : f32) { + // CHECK: {{%.*}}= spv.FMul {{%.*}}, {{%.*}} : f32 + %0 = spv.FMul %arg0, %arg1 : f32 + spv.Return + } + func @fadd(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { + // CHECK: {{%.*}} = spv.FAdd {{%.*}}, {{%.*}} : vector<4xf32> + %0 = spv.FAdd %arg0, %arg1 : vector<4xf32> + spv.Return + } + func @fdiv(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { + // CHECK: {{%.*}} = spv.FDiv {{%.*}}, {{%.*}} : vector<4xf32> + %0 = spv.FDiv %arg0, %arg1 : vector<4xf32> + spv.Return + } + func @fmod(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { + // CHECK: {{%.*}} = spv.FMod {{%.*}}, {{%.*}} : vector<4xf32> + %0 = spv.FMod %arg0, %arg1 : vector<4xf32> + spv.Return + } + func @fsub(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { + // CHECK: {{%.*}} = spv.FSub {{%.*}}, {{%.*}} : vector<4xf32> + %0 = spv.FSub %arg0, %arg1 : vector<4xf32> + spv.Return + } + func @frem(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) { + // CHECK: {{%.*}} = spv.FRem {{%.*}}, {{%.*}} : vector<4xf32> + %0 = spv.FRem %arg0, %arg1 : vector<4xf32> + spv.Return + } + func @iadd(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.IAdd {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.IAdd %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @isub(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.ISub {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.ISub %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @imul(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.IMul {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.IMul %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @udiv(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.UDiv {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.UDiv %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @umod(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.UMod {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.UMod %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @sdiv(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.SDiv {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.SDiv %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @smod(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.SMod {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.SMod %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @srem(%arg0 : vector<4xi32>, %arg1 : vector<4xi32>) { + // CHECK: {{%.*}} = spv.SRem {{%.*}}, {{%.*}} : vector<4xi32> + %0 = spv.SRem %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @iequal_scalar(%arg0: i32, %arg1: i32) { + // CHECK: {{.*}} = spv.IEqual {{.*}}, {{.*}} : i32 + %0 = spv.IEqual %arg0, %arg1 : i32 + spv.Return + } + func @inotequal_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.INotEqual {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.INotEqual %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @sgt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.SGreaterThan {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.SGreaterThan %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @sge_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.SGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.SGreaterThanEqual %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @slt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.SLessThan {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.SLessThan %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @slte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.SLessThanEqual {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.SLessThanEqual %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @ugt_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.UGreaterThan {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.UGreaterThan %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @ugte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.UGreaterThanEqual {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.UGreaterThanEqual %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @ult_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.ULessThan {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.ULessThan %arg0, %arg1 : vector<4xi32> + spv.Return + } + func @ulte_vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) { + // CHECK: {{.*}} = spv.ULessThanEqual {{.*}}, {{.*}} : vector<4xi32> + %0 = spv.ULessThanEqual %arg0, %arg1 : vector<4xi32> + spv.Return } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/constant.mlir b/mlir/test/Dialect/SPIRV/Serialization/constant.mlir index ff422ca04906..3c34b0c31db0 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/constant.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/constant.mlir @@ -1,171 +1,168 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_module() -> () { - spv.module "Logical" "GLSL450" { - // CHECK-LABEL: @bool_const - func @bool_const() -> () { - // CHECK: spv.constant true - %0 = spv.constant true - // CHECK: spv.constant false - %1 = spv.constant false +spv.module "Logical" "GLSL450" { + // CHECK-LABEL: @bool_const + func @bool_const() -> () { + // CHECK: spv.constant true + %0 = spv.constant true + // CHECK: spv.constant false + %1 = spv.constant false - %2 = spv.Variable init(%0): !spv.ptr - %3 = spv.Variable init(%1): !spv.ptr - spv.Return - } - - // CHECK-LABEL: @i32_const - func @i32_const() -> () { - // CHECK: spv.constant 0 : i32 - %0 = spv.constant 0 : i32 - // CHECK: spv.constant 10 : i32 - %1 = spv.constant 10 : i32 - // CHECK: spv.constant -5 : i32 - %2 = spv.constant -5 : i32 - - %3 = spv.IAdd %0, %1 : i32 - %4 = spv.IAdd %2, %3 : i32 - spv.Return - } - - // CHECK-LABEL: @i64_const - func @i64_const() -> () { - // CHECK: spv.constant 4294967296 : i64 - %0 = spv.constant 4294967296 : i64 // 2^32 - // CHECK: spv.constant -4294967296 : i64 - %1 = spv.constant -4294967296 : i64 // -2^32 - // CHECK: spv.constant 9223372036854775807 : i64 - %2 = spv.constant 9223372036854775807 : i64 // 2^63 - 1 - // CHECK: spv.constant -9223372036854775808 : i64 - %3 = spv.constant -9223372036854775808 : i64 // -2^63 - - %4 = spv.IAdd %0, %1 : i64 - %5 = spv.IAdd %2, %3 : i64 - spv.Return - } - - // CHECK-LABEL: @i16_const - func @i16_const() -> () { - // CHECK: spv.constant -32768 : i16 - %0 = spv.constant -32768 : i16 // -2^15 - // CHECK: spv.constant 32767 : i16 - %1 = spv.constant 32767 : i16 // 2^15 - 1 - - %2 = spv.IAdd %0, %1 : i16 - spv.Return - } - - // CHECK-LABEL: @float_const - func @float_const() -> () { - // CHECK: spv.constant 0.000000e+00 : f32 - %0 = spv.constant 0. : f32 - // CHECK: spv.constant 1.000000e+00 : f32 - %1 = spv.constant 1. : f32 - // CHECK: spv.constant -0.000000e+00 : f32 - %2 = spv.constant -0. : f32 - // CHECK: spv.constant -1.000000e+00 : f32 - %3 = spv.constant -1. : f32 - // CHECK: spv.constant 7.500000e-01 : f32 - %4 = spv.constant 0.75 : f32 - // CHECK: spv.constant -2.500000e-01 : f32 - %5 = spv.constant -0.25 : f32 - - %6 = spv.FAdd %0, %1 : f32 - %7 = spv.FAdd %2, %3 : f32 - %8 = spv.FAdd %4, %5 : f32 - spv.Return - } - - // CHECK-LABEL: @double_const - func @double_const() -> () { - // TODO(antiagainst): test range boundary values - // CHECK: spv.constant 1.024000e+03 : f64 - %0 = spv.constant 1024. : f64 - // CHECK: spv.constant -1.024000e+03 : f64 - %1 = spv.constant -1024. : f64 - - %2 = spv.FAdd %0, %1 : f64 - spv.Return - } - - // CHECK-LABEL: @half_const - func @half_const() -> () { - // CHECK: spv.constant 5.120000e+02 : f16 - %0 = spv.constant 512. : f16 - // CHECK: spv.constant -5.120000e+02 : f16 - %1 = spv.constant -512. : f16 - - %2 = spv.FAdd %0, %1 : f16 - spv.Return - } - - // CHECK-LABEL: @bool_vector_const - func @bool_vector_const() -> () { - // CHECK: spv.constant dense : vector<2xi1> - %0 = spv.constant dense : vector<2xi1> - // CHECK: spv.constant dense<[true, true, true]> : vector<3xi1> - %1 = spv.constant dense : vector<3xi1> - // CHECK: spv.constant dense<[false, true]> : vector<2xi1> - %2 = spv.constant dense<[false, true]> : vector<2xi1> - - %3 = spv.Variable init(%0): !spv.ptr, Function> - %4 = spv.Variable init(%1): !spv.ptr, Function> - %5 = spv.Variable init(%2): !spv.ptr, Function> - spv.Return - } - - // CHECK-LABEL: @int_vector_const - func @int_vector_const() -> () { - // CHECK: spv.constant dense<0> : vector<3xi32> - %0 = spv.constant dense<0> : vector<3xi32> - // CHECK: spv.constant dense<1> : vector<3xi32> - %1 = spv.constant dense<1> : vector<3xi32> - // CHECK: spv.constant dense<[2, -3, 4]> : vector<3xi32> - %2 = spv.constant dense<[2, -3, 4]> : vector<3xi32> - - %3 = spv.IAdd %0, %1 : vector<3xi32> - %4 = spv.IAdd %2, %3 : vector<3xi32> - spv.Return - } - - // CHECK-LABEL: @fp_vector_const - func @fp_vector_const() -> () { - // CHECK: spv.constant dense<0.000000e+00> : vector<4xf32> - %0 = spv.constant dense<0.> : vector<4xf32> - // CHECK: spv.constant dense<-1.500000e+01> : vector<4xf32> - %1 = spv.constant dense<-15.> : vector<4xf32> - // CHECK: spv.constant dense<[7.500000e-01, -2.500000e-01, 1.000000e+01, 4.200000e+01]> : vector<4xf32> - %2 = spv.constant dense<[0.75, -0.25, 10., 42.]> : vector<4xf32> - - %3 = spv.FAdd %0, %1 : vector<4xf32> - %4 = spv.FAdd %2, %3 : vector<4xf32> - spv.Return - } - - // CHECK-LABEL: @array_const - func @array_const() -> (!spv.array<2 x vector<2xf32>>) { - // CHECK: spv.constant [dense<3.000000e+00> : vector<2xf32>, dense<[4.000000e+00, 5.000000e+00]> : vector<2xf32>] : !spv.array<2 x vector<2xf32>> - %0 = spv.constant [dense<3.0> : vector<2xf32>, dense<[4., 5.]> : vector<2xf32>] : !spv.array<2 x vector<2xf32>> - - spv.ReturnValue %0 : !spv.array<2 x vector<2xf32>> - } - - // CHECK-LABEL: @ignore_not_used_const - func @ignore_not_used_const() -> () { - %0 = spv.constant false - // CHECK-NEXT: spv.Return - spv.Return - } - - // CHECK-LABEL: @materialize_const_at_each_use - func @materialize_const_at_each_use() -> (i32) { - // CHECK: %[[USE1:.*]] = spv.constant 42 : i32 - // CHECK: %[[USE2:.*]] = spv.constant 42 : i32 - // CHECK: spv.IAdd %[[USE1]], %[[USE2]] - %0 = spv.constant 42 : i32 - %1 = spv.IAdd %0, %0 : i32 - spv.ReturnValue %1 : i32 - } + %2 = spv.Variable init(%0): !spv.ptr + %3 = spv.Variable init(%1): !spv.ptr + spv.Return + } + + // CHECK-LABEL: @i32_const + func @i32_const() -> () { + // CHECK: spv.constant 0 : i32 + %0 = spv.constant 0 : i32 + // CHECK: spv.constant 10 : i32 + %1 = spv.constant 10 : i32 + // CHECK: spv.constant -5 : i32 + %2 = spv.constant -5 : i32 + + %3 = spv.IAdd %0, %1 : i32 + %4 = spv.IAdd %2, %3 : i32 + spv.Return + } + + // CHECK-LABEL: @i64_const + func @i64_const() -> () { + // CHECK: spv.constant 4294967296 : i64 + %0 = spv.constant 4294967296 : i64 // 2^32 + // CHECK: spv.constant -4294967296 : i64 + %1 = spv.constant -4294967296 : i64 // -2^32 + // CHECK: spv.constant 9223372036854775807 : i64 + %2 = spv.constant 9223372036854775807 : i64 // 2^63 - 1 + // CHECK: spv.constant -9223372036854775808 : i64 + %3 = spv.constant -9223372036854775808 : i64 // -2^63 + + %4 = spv.IAdd %0, %1 : i64 + %5 = spv.IAdd %2, %3 : i64 + spv.Return + } + + // CHECK-LABEL: @i16_const + func @i16_const() -> () { + // CHECK: spv.constant -32768 : i16 + %0 = spv.constant -32768 : i16 // -2^15 + // CHECK: spv.constant 32767 : i16 + %1 = spv.constant 32767 : i16 // 2^15 - 1 + + %2 = spv.IAdd %0, %1 : i16 + spv.Return + } + + // CHECK-LABEL: @float_const + func @float_const() -> () { + // CHECK: spv.constant 0.000000e+00 : f32 + %0 = spv.constant 0. : f32 + // CHECK: spv.constant 1.000000e+00 : f32 + %1 = spv.constant 1. : f32 + // CHECK: spv.constant -0.000000e+00 : f32 + %2 = spv.constant -0. : f32 + // CHECK: spv.constant -1.000000e+00 : f32 + %3 = spv.constant -1. : f32 + // CHECK: spv.constant 7.500000e-01 : f32 + %4 = spv.constant 0.75 : f32 + // CHECK: spv.constant -2.500000e-01 : f32 + %5 = spv.constant -0.25 : f32 + + %6 = spv.FAdd %0, %1 : f32 + %7 = spv.FAdd %2, %3 : f32 + %8 = spv.FAdd %4, %5 : f32 + spv.Return + } + + // CHECK-LABEL: @double_const + func @double_const() -> () { + // TODO(antiagainst): test range boundary values + // CHECK: spv.constant 1.024000e+03 : f64 + %0 = spv.constant 1024. : f64 + // CHECK: spv.constant -1.024000e+03 : f64 + %1 = spv.constant -1024. : f64 + + %2 = spv.FAdd %0, %1 : f64 + spv.Return + } + + // CHECK-LABEL: @half_const + func @half_const() -> () { + // CHECK: spv.constant 5.120000e+02 : f16 + %0 = spv.constant 512. : f16 + // CHECK: spv.constant -5.120000e+02 : f16 + %1 = spv.constant -512. : f16 + + %2 = spv.FAdd %0, %1 : f16 + spv.Return + } + + // CHECK-LABEL: @bool_vector_const + func @bool_vector_const() -> () { + // CHECK: spv.constant dense : vector<2xi1> + %0 = spv.constant dense : vector<2xi1> + // CHECK: spv.constant dense<[true, true, true]> : vector<3xi1> + %1 = spv.constant dense : vector<3xi1> + // CHECK: spv.constant dense<[false, true]> : vector<2xi1> + %2 = spv.constant dense<[false, true]> : vector<2xi1> + + %3 = spv.Variable init(%0): !spv.ptr, Function> + %4 = spv.Variable init(%1): !spv.ptr, Function> + %5 = spv.Variable init(%2): !spv.ptr, Function> + spv.Return + } + + // CHECK-LABEL: @int_vector_const + func @int_vector_const() -> () { + // CHECK: spv.constant dense<0> : vector<3xi32> + %0 = spv.constant dense<0> : vector<3xi32> + // CHECK: spv.constant dense<1> : vector<3xi32> + %1 = spv.constant dense<1> : vector<3xi32> + // CHECK: spv.constant dense<[2, -3, 4]> : vector<3xi32> + %2 = spv.constant dense<[2, -3, 4]> : vector<3xi32> + + %3 = spv.IAdd %0, %1 : vector<3xi32> + %4 = spv.IAdd %2, %3 : vector<3xi32> + spv.Return + } + + // CHECK-LABEL: @fp_vector_const + func @fp_vector_const() -> () { + // CHECK: spv.constant dense<0.000000e+00> : vector<4xf32> + %0 = spv.constant dense<0.> : vector<4xf32> + // CHECK: spv.constant dense<-1.500000e+01> : vector<4xf32> + %1 = spv.constant dense<-15.> : vector<4xf32> + // CHECK: spv.constant dense<[7.500000e-01, -2.500000e-01, 1.000000e+01, 4.200000e+01]> : vector<4xf32> + %2 = spv.constant dense<[0.75, -0.25, 10., 42.]> : vector<4xf32> + + %3 = spv.FAdd %0, %1 : vector<4xf32> + %4 = spv.FAdd %2, %3 : vector<4xf32> + spv.Return + } + + // CHECK-LABEL: @array_const + func @array_const() -> (!spv.array<2 x vector<2xf32>>) { + // CHECK: spv.constant [dense<3.000000e+00> : vector<2xf32>, dense<[4.000000e+00, 5.000000e+00]> : vector<2xf32>] : !spv.array<2 x vector<2xf32>> + %0 = spv.constant [dense<3.0> : vector<2xf32>, dense<[4., 5.]> : vector<2xf32>] : !spv.array<2 x vector<2xf32>> + + spv.ReturnValue %0 : !spv.array<2 x vector<2xf32>> + } + + // CHECK-LABEL: @ignore_not_used_const + func @ignore_not_used_const() -> () { + %0 = spv.constant false + // CHECK-NEXT: spv.Return + spv.Return + } + + // CHECK-LABEL: @materialize_const_at_each_use + func @materialize_const_at_each_use() -> (i32) { + // CHECK: %[[USE1:.*]] = spv.constant 42 : i32 + // CHECK: %[[USE2:.*]] = spv.constant 42 : i32 + // CHECK: spv.IAdd %[[USE1]], %[[USE2]] + %0 = spv.constant 42 : i32 + %1 = spv.IAdd %0, %0 : i32 + spv.ReturnValue %1 : i32 } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/entry.mlir b/mlir/test/Dialect/SPIRV/Serialization/entry.mlir index c6093a9715ae..cd48e209886f 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/entry.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/entry.mlir @@ -1,14 +1,11 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_loadstore() -> () { - spv.module "Logical" "VulkanKHR" { - func @noop() -> () { - spv.Return - } - // CHECK: spv.EntryPoint "GLCompute" @noop - // CHECK-NEXT: spv.ExecutionMode @noop "ContractionOff" - spv.EntryPoint "GLCompute" @noop - spv.ExecutionMode @noop "ContractionOff" +spv.module "Logical" "VulkanKHR" { + func @noop() -> () { + spv.Return } - return -} \ No newline at end of file + // CHECK: spv.EntryPoint "GLCompute" @noop + // CHECK-NEXT: spv.ExecutionMode @noop "ContractionOff" + spv.EntryPoint "GLCompute" @noop + spv.ExecutionMode @noop "ContractionOff" +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/entry_interface.mlir b/mlir/test/Dialect/SPIRV/Serialization/entry_interface.mlir index d22b4e4ceb24..1c8488f85184 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/entry_interface.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/entry_interface.mlir @@ -1,18 +1,15 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_loadstore() -> () { - spv.module "Logical" "VulkanKHR" { - // CHECK: spv.globalVariable @var2 : !spv.ptr - // CHECK-NEXT: spv.globalVariable @var3 : !spv.ptr - // CHECK-NEXT: func @noop({{%.*}}: !spv.ptr, {{%.*}}: !spv.ptr) - // CHECK: spv.EntryPoint "GLCompute" @noop, @var2, @var3 - spv.globalVariable @var2 : !spv.ptr - spv.globalVariable @var3 : !spv.ptr - func @noop(%arg0 : !spv.ptr, %arg1 : !spv.ptr) -> () { - spv.Return - } - spv.EntryPoint "GLCompute" @noop, @var2, @var3 - spv.ExecutionMode @noop "ContractionOff" +spv.module "Logical" "VulkanKHR" { + // CHECK: spv.globalVariable @var2 : !spv.ptr + // CHECK-NEXT: spv.globalVariable @var3 : !spv.ptr + // CHECK-NEXT: func @noop({{%.*}}: !spv.ptr, {{%.*}}: !spv.ptr) + // CHECK: spv.EntryPoint "GLCompute" @noop, @var2, @var3 + spv.globalVariable @var2 : !spv.ptr + spv.globalVariable @var3 : !spv.ptr + func @noop(%arg0 : !spv.ptr, %arg1 : !spv.ptr) -> () { + spv.Return } - return -} \ No newline at end of file + spv.EntryPoint "GLCompute" @noop, @var2, @var3 + spv.ExecutionMode @noop "ContractionOff" +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/execution_mode.mlir b/mlir/test/Dialect/SPIRV/Serialization/execution_mode.mlir index 173bb436d1e6..b8bd23095ced 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/execution_mode.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/execution_mode.mlir @@ -1,13 +1,10 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_loadstore() -> () { - spv.module "Logical" "VulkanKHR" { - func @foo() -> () { - spv.Return - } - spv.EntryPoint "GLCompute" @foo - // CHECK: spv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5 - spv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5 +spv.module "Logical" "VulkanKHR" { + func @foo() -> () { + spv.Return } - return -} \ No newline at end of file + spv.EntryPoint "GLCompute" @foo + // CHECK: spv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5 + spv.ExecutionMode @foo "LocalSizeHint", 3, 4, 5 +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/load_store.mlir b/mlir/test/Dialect/SPIRV/Serialization/load_store.mlir index a6d66c744dcb..07ec6da34291 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/load_store.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/load_store.mlir @@ -4,13 +4,10 @@ // CHECK-NEXT: [[VALUE:%.*]] = spv.Load "Input" [[ARG1]] : f32 // CHECK-NEXT: spv.Store "Output" [[ARG2]], [[VALUE]] : f32 -func @spirv_loadstore() -> () { - spv.module "Logical" "VulkanKHR" { - func @load_store(%arg0 : !spv.ptr, %arg1 : !spv.ptr) { - %1 = spv.Load "Input" %arg0 : f32 - spv.Store "Output" %arg1, %1 : f32 - spv.Return - } +spv.module "Logical" "VulkanKHR" { + func @load_store(%arg0 : !spv.ptr, %arg1 : !spv.ptr) { + %1 = spv.Load "Input" %arg0 : f32 + spv.Store "Output" %arg1, %1 : f32 + spv.Return } - return -} \ No newline at end of file +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/minimal-module.mlir b/mlir/test/Dialect/SPIRV/Serialization/minimal-module.mlir index 54b176273d3b..8754a67cb2c3 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/minimal-module.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/minimal-module.mlir @@ -1,17 +1,13 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -// CHECK-LABEL: func @spirv_module // CHECK: spv.module "Logical" "VulkanKHR" { // CHECK-NEXT: func @foo() { // CHECK-NEXT: spv.Return // CHECK-NEXT: } // CHECK-NEXT: } attributes {major_version = 1 : i32, minor_version = 0 : i32} -func @spirv_module() -> () { - spv.module "Logical" "VulkanKHR" { - func @foo() -> () { - spv.Return - } +spv.module "Logical" "VulkanKHR" { + func @foo() -> () { + spv.Return } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/spec_constant.mlir b/mlir/test/Dialect/SPIRV/Serialization/spec_constant.mlir index f40b48b72f67..24bf65d3f204 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/spec_constant.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/spec_constant.mlir @@ -1,31 +1,27 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_module() -> () { - spv.module "Logical" "GLSL450" { - // CHECK: spv.specConstant @sc_true = true - spv.specConstant @sc_true = true - // CHECK: spv.specConstant @sc_false = false - spv.specConstant @sc_false = false +spv.module "Logical" "GLSL450" { + // CHECK: spv.specConstant @sc_true = true + spv.specConstant @sc_true = true + // CHECK: spv.specConstant @sc_false = false + spv.specConstant @sc_false = false - // CHECK: spv.specConstant @sc_int = -5 : i32 - spv.specConstant @sc_int = -5 : i32 + // CHECK: spv.specConstant @sc_int = -5 : i32 + spv.specConstant @sc_int = -5 : i32 - // CHECK: spv.specConstant @sc_float = 1.000000e+00 : f32 - spv.specConstant @sc_float = 1. : f32 + // CHECK: spv.specConstant @sc_float = 1.000000e+00 : f32 + spv.specConstant @sc_float = 1. : f32 - // CHECK-LABEL: @use - func @use() -> (i32) { - // We materialize a `spv._reference_of` op at every use of a - // specialization constant in the deserializer. So two ops here. - // CHECK: %[[USE1:.*]] = spv._reference_of @sc_int : i32 - // CHECK: %[[USE2:.*]] = spv._reference_of @sc_int : i32 - // CHECK: spv.IAdd %[[USE1]], %[[USE2]] + // CHECK-LABEL: @use + func @use() -> (i32) { + // We materialize a `spv._reference_of` op at every use of a + // specialization constant in the deserializer. So two ops here. + // CHECK: %[[USE1:.*]] = spv._reference_of @sc_int : i32 + // CHECK: %[[USE2:.*]] = spv._reference_of @sc_int : i32 + // CHECK: spv.IAdd %[[USE1]], %[[USE2]] - %0 = spv._reference_of @sc_int : i32 - %1 = spv.IAdd %0, %0 : i32 - spv.ReturnValue %1 : i32 - } + %0 = spv._reference_of @sc_int : i32 + %1 = spv.IAdd %0, %0 : i32 + spv.ReturnValue %1 : i32 } - return } - diff --git a/mlir/test/Dialect/SPIRV/Serialization/struct.mlir b/mlir/test/Dialect/SPIRV/Serialization/struct.mlir index ac885fba2391..98481e142c3d 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/struct.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/struct.mlir @@ -1,24 +1,21 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirvmodule() -> () { - spv.module "Logical" "VulkanKHR" { - // CHECK: !spv.ptr [0]>, Input> - spv.globalVariable @var0 bind(0, 1) : !spv.ptr [0]>, Input> +spv.module "Logical" "VulkanKHR" { + // CHECK: !spv.ptr [0]>, Input> + spv.globalVariable @var0 bind(0, 1) : !spv.ptr [0]>, Input> - // CHECK: !spv.ptr [4]> [4]>, Input> - spv.globalVariable @var1 bind(0, 2) : !spv.ptr [4]> [4]>, Input> + // CHECK: !spv.ptr [4]> [4]>, Input> + spv.globalVariable @var1 bind(0, 2) : !spv.ptr [4]> [4]>, Input> - // CHECK: !spv.ptr, StorageBuffer> - spv.globalVariable @var2 : !spv.ptr, StorageBuffer> + // CHECK: !spv.ptr, StorageBuffer> + spv.globalVariable @var2 : !spv.ptr, StorageBuffer> - // CHECK: !spv.ptr [0]> [4]> [0]>, StorageBuffer> - spv.globalVariable @var3 : !spv.ptr [0]> [4]> [0]>, StorageBuffer> + // CHECK: !spv.ptr [0]> [4]> [0]>, StorageBuffer> + spv.globalVariable @var3 : !spv.ptr [0]> [4]> [0]>, StorageBuffer> - // CHECK: !spv.ptr [0]>, Input>, - // CHECK-SAME: !spv.ptr [0]>, Output> - func @kernel_1(%arg0: !spv.ptr [0]>, Input>, %arg1: !spv.ptr [0]>, Output>) -> () { - spv.Return - } + // CHECK: !spv.ptr [0]>, Input>, + // CHECK-SAME: !spv.ptr [0]>, Output> + func @kernel_1(%arg0: !spv.ptr [0]>, Input>, %arg1: !spv.ptr [0]>, Output>) -> () { + spv.Return } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/terminator.mlir b/mlir/test/Dialect/SPIRV/Serialization/terminator.mlir index 35d2f972b555..679ac087c360 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/terminator.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/terminator.mlir @@ -1,21 +1,17 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_terminator() -> () { - spv.module "Logical" "GLSL450" { - // CHECK-LABEL: @ret - func @ret() -> () { - // CHECK: spv.Return - spv.Return - } - - // CHECK-LABEL: @ret_val - func @ret_val() -> (i32) { - %0 = spv.Variable : !spv.ptr - %1 = spv.Load "Function" %0 : i32 - // CHECK: spv.ReturnValue {{.*}} : i32 - spv.ReturnValue %1 : i32 - } +spv.module "Logical" "GLSL450" { + // CHECK-LABEL: @ret + func @ret() -> () { + // CHECK: spv.Return + spv.Return } - return -} + // CHECK-LABEL: @ret_val + func @ret_val() -> (i32) { + %0 = spv.Variable : !spv.ptr + %1 = spv.Load "Function" %0 : i32 + // CHECK: spv.ReturnValue {{.*}} : i32 + spv.ReturnValue %1 : i32 + } +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/variable_reference.mlir b/mlir/test/Dialect/SPIRV/Serialization/variable_reference.mlir index 971bbfae70fe..544197632bf8 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/variable_reference.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/variable_reference.mlir @@ -1,16 +1,13 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_global_vars() -> () { - spv.module "Logical" "VulkanKHR" { - spv.globalVariable @globalInvocationID built_in("GlobalInvocationId") : !spv.ptr, Input> - func @foo() { - // CHECK: %[[ADDR:.*]] = spv._address_of @globalInvocationID : !spv.ptr, Input> - %0 = spv._address_of @globalInvocationID : !spv.ptr, Input> - %1 = spv.constant 0: i32 - // CHECK: spv.AccessChain %[[ADDR]] - %2 = spv.AccessChain %0[%1] : !spv.ptr, Input> - spv.Return - } +spv.module "Logical" "VulkanKHR" { + spv.globalVariable @globalInvocationID built_in("GlobalInvocationId") : !spv.ptr, Input> + func @foo() { + // CHECK: %[[ADDR:.*]] = spv._address_of @globalInvocationID : !spv.ptr, Input> + %0 = spv._address_of @globalInvocationID : !spv.ptr, Input> + %1 = spv.constant 0: i32 + // CHECK: spv.AccessChain %[[ADDR]] + %2 = spv.AccessChain %0[%1] : !spv.ptr, Input> + spv.Return } - return } diff --git a/mlir/test/Dialect/SPIRV/Serialization/variables.mlir b/mlir/test/Dialect/SPIRV/Serialization/variables.mlir index f9c572d9be71..d87b944b93d4 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/variables.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/variables.mlir @@ -1,15 +1,13 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -// CHECK: spv.globalVariable @var0 bind(1, 0) : !spv.ptr -// CHECK-NEXT: spv.globalVariable @var1 bind(0, 1) : !spv.ptr -// CHECK-NEXT: spv.globalVariable @var2 built_in("GlobalInvocationId") : !spv.ptr, Input> -// CHECK-NEXT: spv.globalVariable @var3 built_in("GlobalInvocationId") : !spv.ptr, Input> -func @spirv_variables() -> () { - spv.module "Logical" "VulkanKHR" { - spv.globalVariable @var0 bind(1, 0) : !spv.ptr - spv.globalVariable @var1 bind(0, 1) : !spv.ptr - spv.globalVariable @var2 {built_in = "GlobalInvocationId"} : !spv.ptr, Input> - spv.globalVariable @var3 built_in("GlobalInvocationId") : !spv.ptr, Input> - } - return -} \ No newline at end of file +// CHECK: spv.globalVariable @var0 bind(1, 0) : !spv.ptr +// CHECK-NEXT: spv.globalVariable @var1 bind(0, 1) : !spv.ptr +// CHECK-NEXT: spv.globalVariable @var2 built_in("GlobalInvocationId") : !spv.ptr, Input> +// CHECK-NEXT: spv.globalVariable @var3 built_in("GlobalInvocationId") : !spv.ptr, Input> + +spv.module "Logical" "VulkanKHR" { + spv.globalVariable @var0 bind(1, 0) : !spv.ptr + spv.globalVariable @var1 bind(0, 1) : !spv.ptr + spv.globalVariable @var2 {built_in = "GlobalInvocationId"} : !spv.ptr, Input> + spv.globalVariable @var3 built_in("GlobalInvocationId") : !spv.ptr, Input> +} diff --git a/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir b/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir index b08d46e1b0d9..7432d482ff49 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/variables_init.mlir @@ -1,11 +1,8 @@ // RUN: mlir-translate -serialize-spirv %s | mlir-translate -deserialize-spirv | FileCheck %s -func @spirv_variables() -> () { - spv.module "Logical" "VulkanKHR" { - // CHECK: spv.globalVariable @var1 : !spv.ptr - // CHECK-NEXT: spv.globalVariable @var2 initializer(@var1) bind(1, 0) : !spv.ptr - spv.globalVariable @var1 : !spv.ptr - spv.globalVariable @var2 initializer(@var1) bind(1, 0) : !spv.ptr - } - return -} \ No newline at end of file +spv.module "Logical" "VulkanKHR" { + // CHECK: spv.globalVariable @var1 : !spv.ptr + // CHECK-NEXT: spv.globalVariable @var2 initializer(@var1) bind(1, 0) : !spv.ptr + spv.globalVariable @var1 : !spv.ptr + spv.globalVariable @var2 initializer(@var1) bind(1, 0) : !spv.ptr +}