1// RUN: mlir-translate -test-spirv-roundtrip-debug -mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s 2 3spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> { 4 // CHECK: loc({{".*debug.mlir"}}:5:3) 5 spv.globalVariable @var0 bind(0, 1) : !spv.ptr<f32, Input> 6 spv.func @arithmetic(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) "None" { 7 // CHECK: loc({{".*debug.mlir"}}:8:10) 8 %0 = spv.FAdd %arg0, %arg1 : vector<4xf32> 9 // CHECK: loc({{".*debug.mlir"}}:10:10) 10 %1 = spv.FNegate %arg0 : vector<4xf32> 11 spv.Return 12 } 13 14 spv.func @atomic(%ptr: !spv.ptr<i32, Workgroup>, %value: i32, %comparator: i32) "None" { 15 // CHECK: loc({{".*debug.mlir"}}:16:10) 16 %1 = spv.AtomicAnd "Device" "None" %ptr, %value : !spv.ptr<i32, Workgroup> 17 spv.Return 18 } 19 20 spv.func @bitwiser(%arg0 : i32, %arg1 : i32) "None" { 21 // CHECK: loc({{".*debug.mlir"}}:22:10) 22 %0 = spv.BitwiseAnd %arg0, %arg1 : i32 23 spv.Return 24 } 25 26 spv.func @convert(%arg0 : f32) "None" { 27 // CHECK: loc({{".*debug.mlir"}}:28:10) 28 %0 = spv.ConvertFToU %arg0 : f32 to i32 29 spv.Return 30 } 31 32 spv.func @composite(%arg0 : !spv.struct<(f32, !spv.struct<(!spv.array<4xf32>, f32)>)>, %arg1: !spv.array<4xf32>, %arg2 : f32, %arg3 : f32) "None" { 33 // CHECK: loc({{".*debug.mlir"}}:34:10) 34 %0 = spv.CompositeInsert %arg1, %arg0[1 : i32, 0 : i32] : !spv.array<4xf32> into !spv.struct<(f32, !spv.struct<(!spv.array<4xf32>, f32)>)> 35 // CHECK: loc({{".*debug.mlir"}}:36:10) 36 %1 = spv.CompositeConstruct %arg2, %arg3 : vector<2xf32> 37 spv.Return 38 } 39 40 spv.func @group_non_uniform(%val: f32) "None" { 41 // CHECK: loc({{".*debug.mlir"}}:42:10) 42 %0 = spv.GroupNonUniformFAdd "Workgroup" "Reduce" %val : f32 43 spv.Return 44 } 45 46 spv.func @local_var() "None" { 47 %zero = spv.constant 0: i32 48 // CHECK: loc({{".*debug.mlir"}}:49:12) 49 %var = spv.Variable init(%zero) : !spv.ptr<i32, Function> 50 spv.Return 51 } 52 53 spv.func @logical(%arg0: i32, %arg1: i32) "None" { 54 // CHECK: loc({{".*debug.mlir"}}:55:10) 55 %0 = spv.IEqual %arg0, %arg1 : i32 56 spv.Return 57 } 58 59 spv.func @memory_accesses(%arg0 : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, StorageBuffer>, %arg1 : i32, %arg2 : i32) "None" { 60 // CHECK: loc({{".*debug.mlir"}}:61:10) 61 %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, StorageBuffer>, i32, i32 62 // CHECK: loc({{".*debug.mlir"}}:63:10) 63 %3 = spv.Load "StorageBuffer" %2 : f32 64 // CHECK: loc({{.*debug.mlir"}}:65:5) 65 spv.Store "StorageBuffer" %2, %3 : f32 66 // CHECK: loc({{".*debug.mlir"}}:67:5) 67 spv.Return 68 } 69 70 spv.func @loop(%count : i32) -> () "None" { 71 %zero = spv.constant 0: i32 72 %one = spv.constant 1: i32 73 %ivar = spv.Variable init(%zero) : !spv.ptr<i32, Function> 74 %jvar = spv.Variable init(%zero) : !spv.ptr<i32, Function> 75 spv.loop { 76 // CHECK: loc({{".*debug.mlir"}}:75:5) 77 spv.Branch ^header 78 ^header: 79 %ival0 = spv.Load "Function" %ivar : i32 80 %icmp = spv.SLessThan %ival0, %count : i32 81 // CHECK: loc({{".*debug.mlir"}}:75:5) 82 spv.BranchConditional %icmp, ^body, ^merge 83 ^body: 84 spv.Store "Function" %jvar, %zero : i32 85 spv.loop { 86 // CHECK: loc({{".*debug.mlir"}}:85:7) 87 spv.Branch ^header 88 ^header: 89 %jval0 = spv.Load "Function" %jvar : i32 90 %jcmp = spv.SLessThan %jval0, %count : i32 91 // CHECK: loc({{".*debug.mlir"}}:85:7) 92 spv.BranchConditional %jcmp, ^body, ^merge 93 ^body: 94 // CHECK: loc({{".*debug.mlir"}}:95:9) 95 spv.Branch ^continue 96 ^continue: 97 %jval1 = spv.Load "Function" %jvar : i32 98 %add = spv.IAdd %jval1, %one : i32 99 spv.Store "Function" %jvar, %add : i32 100 // CHECK: loc({{".*debug.mlir"}}:101:9) 101 spv.Branch ^header 102 ^merge: 103 // CHECK: loc({{".*debug.mlir"}}:85:7) 104 spv.mlir.merge 105 // CHECK: loc({{".*debug.mlir"}}:85:7) 106 } 107 // CHECK: loc({{".*debug.mlir"}}:108:7) 108 spv.Branch ^continue 109 ^continue: 110 %ival1 = spv.Load "Function" %ivar : i32 111 %add = spv.IAdd %ival1, %one : i32 112 spv.Store "Function" %ivar, %add : i32 113 // CHECK: loc({{".*debug.mlir"}}:114:7) 114 spv.Branch ^header 115 ^merge: 116 // CHECK: loc({{".*debug.mlir"}}:75:5) 117 spv.mlir.merge 118 // CHECK: loc({{".*debug.mlir"}}:75:5) 119 } 120 spv.Return 121 } 122 123 spv.func @selection(%cond: i1) -> () "None" { 124 %zero = spv.constant 0: i32 125 %one = spv.constant 1: i32 126 %two = spv.constant 2: i32 127 %var = spv.Variable init(%zero) : !spv.ptr<i32, Function> 128 spv.selection { 129 // CHECK: loc({{".*debug.mlir"}}:128:5) 130 spv.BranchConditional %cond [5, 10], ^then, ^else 131 ^then: 132 spv.Store "Function" %var, %one : i32 133 // CHECK: loc({{".*debug.mlir"}}:134:7) 134 spv.Branch ^merge 135 ^else: 136 spv.Store "Function" %var, %two : i32 137 // CHECK: loc({{".*debug.mlir"}}:138:7) 138 spv.Branch ^merge 139 ^merge: 140 // CHECK: loc({{".*debug.mlir"}}:128:5) 141 spv.mlir.merge 142 // CHECK: loc({{".*debug.mlir"}}:128:5) 143 } 144 spv.Return 145 } 146} 147