diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp --- a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp @@ -1024,8 +1024,9 @@ "OpVariable instruction, only ") << wordIndex << " of " << operands.size() << " processed"; } + auto loc = createFileLineColLoc(opBuilder); auto varOp = opBuilder.create( - unknownLoc, TypeAttr::get(type), opBuilder.getStringAttr(variableName), + loc, TypeAttr::get(type), opBuilder.getStringAttr(variableName), initializer); // Decorations. diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp --- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp @@ -852,6 +852,7 @@ } operands.push_back(argID); } + emitDebugLine(functionHeader, op.getLoc()); encodeInstructionInto(functionHeader, spirv::getOpcode(), operands); for (auto attr : op.getAttrs()) { @@ -915,6 +916,7 @@ elidedAttrs.push_back("initializer"); } + emitDebugLine(typesGlobalValues, varOp.getLoc()); if (failed(encodeInstructionInto(typesGlobalValues, spirv::Opcode::OpVariable, operands))) { elidedAttrs.push_back("initializer"); diff --git a/mlir/test/Dialect/SPIRV/Serialization/debug.mlir b/mlir/test/Dialect/SPIRV/Serialization/debug.mlir --- a/mlir/test/Dialect/SPIRV/Serialization/debug.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/debug.mlir @@ -1,60 +1,69 @@ // RUN: mlir-translate -test-spirv-roundtrip-debug -mlir-print-debuginfo %s | FileCheck %s spv.module Logical GLSL450 requires #spv.vce { + // CHECK: loc({{".*debug.mlir"}}:5:3) + spv.globalVariable @var0 bind(0, 1) : !spv.ptr spv.func @arithmetic(%arg0 : vector<4xf32>, %arg1 : vector<4xf32>) "None" { - // CHECK: loc({{".*debug.mlir"}}:6:10) - %0 = spv.FAdd %arg0, %arg1 : vector<4xf32> // CHECK: loc({{".*debug.mlir"}}:8:10) + %0 = spv.FAdd %arg0, %arg1 : vector<4xf32> + // CHECK: loc({{".*debug.mlir"}}:10:10) %1 = spv.FNegate %arg0 : vector<4xf32> spv.Return } spv.func @atomic(%ptr: !spv.ptr, %value: i32, %comparator: i32) "None" { - // CHECK: loc({{".*debug.mlir"}}:14:10) + // CHECK: loc({{".*debug.mlir"}}:16:10) %1 = spv.AtomicAnd "Device" "None" %ptr, %value : !spv.ptr spv.Return } spv.func @bitwiser(%arg0 : i32, %arg1 : i32) "None" { - // CHECK: loc({{".*debug.mlir"}}:20:10) + // CHECK: loc({{".*debug.mlir"}}:22:10) %0 = spv.BitwiseAnd %arg0, %arg1 : i32 spv.Return } spv.func @convert(%arg0 : f32) "None" { - // CHECK: loc({{".*debug.mlir"}}:26:10) + // CHECK: loc({{".*debug.mlir"}}:28:10) %0 = spv.ConvertFToU %arg0 : f32 to i32 spv.Return } spv.func @composite(%arg0 : !spv.struct, f32>>, %arg1: !spv.array<4xf32>, %arg2 : f32, %arg3 : f32) "None" { - // CHECK: loc({{".*debug.mlir"}}:32:10) - %0 = spv.CompositeInsert %arg1, %arg0[1 : i32, 0 : i32] : !spv.array<4xf32> into !spv.struct, f32>> // CHECK: loc({{".*debug.mlir"}}:34:10) + %0 = spv.CompositeInsert %arg1, %arg0[1 : i32, 0 : i32] : !spv.array<4xf32> into !spv.struct, f32>> + // CHECK: loc({{".*debug.mlir"}}:36:10) %1 = spv.CompositeConstruct %arg2, %arg3 : vector<2xf32> spv.Return } spv.func @group_non_uniform(%val: f32) "None" { - // CHECK: loc({{".*debug.mlir"}}:40:10) + // CHECK: loc({{".*debug.mlir"}}:42:10) %0 = spv.GroupNonUniformFAdd "Workgroup" "Reduce" %val : f32 spv.Return } + spv.func @local_var() "None" { + %zero = spv.constant 0: i32 + // CHECK: loc({{".*debug.mlir"}}:49:12) + %var = spv.Variable init(%zero) : !spv.ptr + spv.Return + } + spv.func @logical(%arg0: i32, %arg1: i32) "None" { - // CHECK: loc({{".*debug.mlir"}}:46:10) + // CHECK: loc({{".*debug.mlir"}}:55:10) %0 = spv.IEqual %arg0, %arg1 : i32 spv.Return } spv.func @memory_accesses(%arg0 : !spv.ptr>, StorageBuffer>, %arg1 : i32, %arg2 : i32) "None" { - // CHECK: loc({{".*debug.mlir"}}:52:10) + // CHECK: loc({{".*debug.mlir"}}:61:10) %2 = spv.AccessChain %arg0[%arg1, %arg2] : !spv.ptr>, StorageBuffer> - // CHECK: loc({{".*debug.mlir"}}:54:10) + // CHECK: loc({{".*debug.mlir"}}:63:10) %3 = spv.Load "StorageBuffer" %2 : f32 - // CHECK: loc({{.*debug.mlir"}}:56:5) + // CHECK: loc({{.*debug.mlir"}}:65:5) spv.Store "StorageBuffer" %2, %3 : f32 - // CHECK: loc({{".*debug.mlir"}}:58:5) + // CHECK: loc({{".*debug.mlir"}}:67:5) spv.Return } }