xref: /llvm-project/mlir/test/Dialect/SPIRV/Linking/ModuleCombiner/basic.mlir (revision 4f4cd963a6e820b50514706a1a3faed3a05779a2)
1// RUN: mlir-opt -test-spirv-module-combiner -split-input-file -verify-diagnostics %s | FileCheck %s
2
3// Combine modules without the same symbols
4
5// CHECK:      module {
6// CHECK-NEXT:   spirv.module Logical GLSL450 {
7// CHECK-NEXT:     spirv.SpecConstant @m1_sc
8// CHECK-NEXT:     spirv.GlobalVariable @m1_gv bind(1, 0)
9// CHECK-NEXT:     spirv.func @no_op
10// CHECK-NEXT:       spirv.Return
11// CHECK-NEXT:     }
12// CHECK-NEXT:     spirv.EntryPoint "GLCompute" @no_op
13// CHECK-NEXT:     spirv.ExecutionMode @no_op "LocalSize", 32, 1, 1
14
15// CHECK-NEXT:     spirv.SpecConstant @m2_sc
16// CHECK-NEXT:     spirv.GlobalVariable @m2_gv bind(0, 1)
17// CHECK-NEXT:     spirv.func @variable_init_spec_constant
18// CHECK-NEXT:       spirv.mlir.referenceof @m2_sc
19// CHECK-NEXT:       spirv.Variable init
20// CHECK-NEXT:       spirv.Return
21// CHECK-NEXT:     }
22// CHECK-NEXT:   }
23// CHECK-NEXT: }
24
25module {
26spirv.module Logical GLSL450 {
27  spirv.SpecConstant @m1_sc = 42.42 : f32
28  spirv.GlobalVariable @m1_gv bind(1, 0): !spirv.ptr<f32, Input>
29  spirv.func @no_op() -> () "None" {
30    spirv.Return
31  }
32  spirv.EntryPoint "GLCompute" @no_op
33  spirv.ExecutionMode @no_op "LocalSize", 32, 1, 1
34}
35
36spirv.module Logical GLSL450 {
37  spirv.SpecConstant @m2_sc = 42 : i32
38  spirv.GlobalVariable @m2_gv bind(0, 1): !spirv.ptr<f32, Input>
39  spirv.func @variable_init_spec_constant() -> () "None" {
40    %0 = spirv.mlir.referenceof @m2_sc : i32
41    %1 = spirv.Variable init(%0) : !spirv.ptr<i32, Function>
42    spirv.Return
43  }
44}
45}
46
47// -----
48
49module {
50spirv.module Physical64 GLSL450 {
51}
52
53// expected-error @+1 {{input modules differ in addressing model, memory model, and/or VCE triple}}
54spirv.module Logical GLSL450 {
55}
56}
57
58// -----
59
60module {
61spirv.module Logical Simple {
62}
63
64// expected-error @+1 {{input modules differ in addressing model, memory model, and/or VCE triple}}
65spirv.module Logical GLSL450 {
66}
67}
68
69// -----
70
71module {
72spirv.module Logical GLSL450 {
73}
74
75// expected-error @+1 {{input modules differ in addressing model, memory model, and/or VCE triple}}
76spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_storage_buffer_storage_class]> {
77}
78}
79
80// -----
81
82// No spir-v modules to combine.
83module {
84  func.func @foo(%arg0: i32) -> i32 {
85    return %arg0 : i32
86  }
87}
88