[Mlir-commits] [mlir] b5973d2 - [mlir][spirv] Handle debuginfo for variables.
Denis Khalikov
llvmlistbot at llvm.org
Fri May 8 08:11:20 PDT 2020
Author: Denis Khalikov
Date: 2020-05-08T18:10:18+03:00
New Revision: b5973d20b388ab7aa7590757177454e17fb2e59b
URL: https://github.com/llvm/llvm-project/commit/b5973d20b388ab7aa7590757177454e17fb2e59b
DIFF: https://github.com/llvm/llvm-project/commit/b5973d20b388ab7aa7590757177454e17fb2e59b.diff
LOG: [mlir][spirv] Handle debuginfo for variables.
Summary:
Handle debuginfo for spv.Variable and spv.globalVariable during
(de)serialization.
Differential Revision: https://reviews.llvm.org/D79566
Added:
Modified:
mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
mlir/test/Dialect/SPIRV/Serialization/debug.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
index b46e17a8c6ab..490367e71ef1 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Deserializer.cpp
@@ -1024,8 +1024,9 @@ LogicalResult Deserializer::processGlobalVariable(ArrayRef<uint32_t> operands) {
"OpVariable instruction, only ")
<< wordIndex << " of " << operands.size() << " processed";
}
+ auto loc = createFileLineColLoc(opBuilder);
auto varOp = opBuilder.create<spirv::GlobalVariableOp>(
- 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
index a553778938a9..a2e8d3368125 100644
--- a/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
+++ b/mlir/lib/Dialect/SPIRV/Serialization/Serializer.cpp
@@ -852,6 +852,7 @@ LogicalResult Serializer::processVariableOp(spirv::VariableOp op) {
}
operands.push_back(argID);
}
+ emitDebugLine(functionHeader, op.getLoc());
encodeInstructionInto(functionHeader, spirv::Opcode::OpVariable, operands);
for (auto attr : op.getAttrs()) {
if (llvm::any_of(elidedAttrs,
@@ -914,6 +915,7 @@ Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
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
index 83fcca7dd0fb..fe7c365a037b 100644
--- 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<v1.0, [Shader], []> {
+ // CHECK: loc({{".*debug.mlir"}}:5:3)
+ spv.globalVariable @var0 bind(0, 1) : !spv.ptr<f32, Input>
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<i32, Workgroup>, %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<i32, Workgroup>
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, !spv.struct<!spv.array<4xf32>, 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, !spv.struct<!spv.array<4xf32>, f32>>
// CHECK: loc({{".*debug.mlir"}}:34:10)
+ %0 = spv.CompositeInsert %arg1, %arg0[1 : i32, 0 : i32] : !spv.array<4xf32> into !spv.struct<f32, !spv.struct<!spv.array<4xf32>, 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<i32, Function>
+ 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<!spv.array<4x!spv.array<4xf32>>, 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<!spv.array<4x!spv.array<4xf32>>, 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
}
}
More information about the Mlir-commits
mailing list