[Mlir-commits] [mlir] [MLIR] Add DIExpression to LLVM dialect (PR #72462)

Billy Zhu llvmlistbot at llvm.org
Wed Nov 15 23:33:34 PST 2023


https://github.com/zyx-billy updated https://github.com/llvm/llvm-project/pull/72462

>From f21323173d015325ea8ae7d7bdd8e68a88e126f8 Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Wed, 15 Nov 2023 13:59:20 -0800
Subject: [PATCH 1/2] add DIExpression to llvm dialect

---
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td       | 11 +++++++
 .../mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td   | 20 +++++++++----
 mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp |  6 ++--
 mlir/lib/Target/LLVMIR/ModuleImport.cpp       | 16 +++++-----
 mlir/test/Dialect/LLVMIR/debuginfo.mlir       | 12 ++++----
 mlir/test/Dialect/LLVMIR/inlining.mlir        |  8 ++---
 mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir | 30 +++++++++----------
 mlir/test/Target/LLVMIR/Import/debug-info.ll  |  8 ++---
 .../Target/LLVMIR/Import/import-failure.ll    |  3 --
 mlir/test/Target/LLVMIR/llvmir-debug.mlir     | 20 ++++++-------
 .../test/mlir-translate/import-diagnostics.ll |  2 +-
 11 files changed, 78 insertions(+), 58 deletions(-)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 0d9af88157a8ae1..6dc2c26221e5cd6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -261,6 +261,17 @@ def LLVM_DITagParameter : LLVM_DIParameter<
   "tag", /*default=*/"", "Tag"
 >;
 
+//===----------------------------------------------------------------------===//
+// DIExpressionAttr
+//===----------------------------------------------------------------------===//
+
+// TODO: Implement custom printer/parser for elements so that operators are
+// dumped in textual form.
+def LLVM_DIExpressionAttr : ArrayOfAttr<LLVM_Dialect, "DIExpression",
+                                          "di_expr", "uint64_t"> {
+  let assemblyFormat = "`<` `[` (`]` `>`) : ($value^ `]` `>`)?";
+}
+
 //===----------------------------------------------------------------------===//
 // DINullTypeAttr
 //===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index 1123466b7a75e3f..b59826b9b2c9383 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -538,7 +538,7 @@ class LLVM_DbgIntrOp<string name, string argName, list<Trait> traits = []>
         llvm::MetadataAsValue::get(ctx,
             llvm::ValueAsMetadata::get(moduleTranslation.lookupValue(opInst.getOperand(0)))),
         llvm::MetadataAsValue::get(ctx, moduleTranslation.translateDebugInfo($varInfo)),
-        llvm::MetadataAsValue::get(ctx, llvm::DIExpression::get(ctx, std::nullopt)),
+        llvm::MetadataAsValue::get(ctx, llvm::DIExpression::get(ctx, $locationExpr)),
       });
   }];
   let mlirBuilder = [{
@@ -548,7 +548,7 @@ class LLVM_DbgIntrOp<string name, string argName, list<Trait> traits = []>
     return success();
   }];
   let assemblyFormat = [{
-    qualified($varInfo) `=` $}] # argName #
+    qualified($varInfo) qualified($locationExpr) `=` $}] # argName #
       [{ `:` qualified(type($}] # argName # [{)) attr-dict
   }];
 }
@@ -556,13 +556,21 @@ class LLVM_DbgIntrOp<string name, string argName, list<Trait> traits = []>
 def LLVM_DbgDeclareOp : LLVM_DbgIntrOp<"dbg.declare", "addr",
     [DeclareOpInterfaceMethods<PromotableOpInterface>]> {
   let summary = "Describes how the address relates to a source language variable.";
-  let arguments = (ins LLVM_AnyPointer:$addr, LLVM_DILocalVariableAttr:$varInfo);
+  let arguments = (ins
+    LLVM_AnyPointer:$addr,
+    LLVM_DILocalVariableAttr:$varInfo,
+    LLVM_DIExpressionAttr:$locationExpr
+  );
 }
 
 def LLVM_DbgValueOp : LLVM_DbgIntrOp<"dbg.value", "value",
     [DeclareOpInterfaceMethods<PromotableOpInterface>]> {
   let summary = "Describes how the value relates to a source language variable.";
-  let arguments = (ins LLVM_Type:$value, LLVM_DILocalVariableAttr:$varInfo);
+  let arguments = (ins
+    LLVM_Type:$value,
+    LLVM_DILocalVariableAttr:$varInfo,
+    LLVM_DIExpressionAttr:$locationExpr
+  );
 }
 
 def LLVM_DbgLabelOp : LLVM_IntrOp<"dbg.label", [], [], [], 0> {
@@ -660,8 +668,8 @@ class LLVM_VecReductionI<string mnem>
 // LLVM vector reduction over a single vector, with an initial value,
 // and with permission to reassociate the reduction operations.
 class LLVM_VecReductionAccBase<string mnem, Type element>
-    : LLVM_OneResultIntrOp</*mnem=*/"vector.reduce." # mnem, 
-                           /*overloadedResults=*/[], 
+    : LLVM_OneResultIntrOp</*mnem=*/"vector.reduce." # mnem,
+                           /*overloadedResults=*/[],
                            /*overloadedOperands=*/[1],
                            /*traits=*/[Pure, SameOperandsAndResultElementType],
                            /*equiresFastmath=*/1>,
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
index cc2a917e58f6394..43349a26ad11276 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
@@ -46,7 +46,8 @@ void LLVM::AllocaOp::handleBlockArgument(const MemorySlot &slot,
   for (Operation *user : getOperation()->getUsers())
     if (auto declareOp = llvm::dyn_cast<LLVM::DbgDeclareOp>(user))
       rewriter.create<LLVM::DbgValueOp>(declareOp.getLoc(), argument,
-                                        declareOp.getVarInfo());
+                                        declareOp.getVarInfo(),
+                                        declareOp.getLocationExpr());
 }
 
 void LLVM::AllocaOp::handlePromotionComplete(const MemorySlot &slot,
@@ -174,7 +175,8 @@ DeletionKind LLVM::StoreOp::removeBlockingUses(
   for (Operation *user : slot.ptr.getUsers())
     if (auto declareOp = dyn_cast<LLVM::DbgDeclareOp>(user))
       rewriter.create<LLVM::DbgValueOp>(declareOp->getLoc(), getValue(),
-                                        declareOp.getVarInfo());
+                                        declareOp.getVarInfo(),
+                                        declareOp.getLocationExpr());
   return DeletionKind::Delete;
 }
 
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 75e806650f3117e..d9e039e75e9ef24 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -1819,9 +1819,9 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
       emitWarning(loc) << "dropped intrinsic: " << diag(*dbgIntr);
     return success();
   };
-  // Drop debug intrinsics with a non-empty debug expression.
-  // TODO: Support debug intrinsics that evaluate a debug expression.
-  if (dbgIntr->hasArgList() || dbgIntr->getExpression()->getNumElements() != 0)
+  // Drop debug intrinsics with arg lists.
+  // TODO: Support debug intrinsics that have arg lists.
+  if (dbgIntr->hasArgList())
     return emitUnsupportedWarning();
   // Kill locations can have metadata nodes as location operand. This
   // cannot be converted to poison as the type cannot be reconstructed.
@@ -1855,15 +1855,17 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
   }
   DILocalVariableAttr localVariableAttr =
       matchLocalVariableAttr(dbgIntr->getArgOperand(1));
+  auto locationExprAttr =
+      DIExpressionAttr::get(context, dbgIntr->getExpression()->getElements());
   Operation *op =
       llvm::TypeSwitch<llvm::DbgVariableIntrinsic *, Operation *>(dbgIntr)
           .Case([&](llvm::DbgDeclareInst *) {
-            return builder.create<LLVM::DbgDeclareOp>(loc, *argOperand,
-                                                      localVariableAttr);
+            return builder.create<LLVM::DbgDeclareOp>(
+                loc, *argOperand, localVariableAttr, locationExprAttr);
           })
           .Case([&](llvm::DbgValueInst *) {
-            return builder.create<LLVM::DbgValueOp>(loc, *argOperand,
-                                                    localVariableAttr);
+            return builder.create<LLVM::DbgValueOp>(
+                loc, *argOperand, localVariableAttr, locationExprAttr);
           });
   mapNoResultOp(dbgIntr, op);
   setNonDebugMetadataAttrs(dbgIntr, op);
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index 5f7b1acff6bbe92..b0a6273f45f9efa 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -155,17 +155,17 @@ llvm.func @addr(%arg: i64) {
   %allocCount = llvm.mlir.constant(1 : i32) : i32
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
 
-  // CHECK: llvm.intr.dbg.declare #[[VAR0]] = %[[ALLOC]]
-  llvm.intr.dbg.declare #var0 = %alloc : !llvm.ptr
+  // CHECK: llvm.intr.dbg.value #[[VAR0]] #llvm.di_expr<[]> = %[[ALLOC]]
+  llvm.intr.dbg.value #var0 #llvm.di_expr<[]> = %alloc : !llvm.ptr
   llvm.return
 }
 
 // CHECK: llvm.func @value(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32)
 llvm.func @value(%arg1: i32, %arg2: i32) {
-  // CHECK: llvm.intr.dbg.value #[[VAR1]] = %[[ARG1]]
-  llvm.intr.dbg.value #var1 = %arg1 : i32
-  // CHECK: llvm.intr.dbg.value #[[VAR2]] = %[[ARG2]]
-  llvm.intr.dbg.value #var2 = %arg2 : i32
+  // CHECK: llvm.intr.dbg.value #[[VAR1]] #llvm.di_expr<[2, 4096, 0, 4]> = %[[ARG1]]
+  llvm.intr.dbg.value #var1 #llvm.di_expr<[2, 4096, 0, 4]> = %arg1 : i32
+  // CHECK: llvm.intr.dbg.value #[[VAR2]] #llvm.di_expr<[]> = %[[ARG2]]
+  llvm.intr.dbg.value #var2 #llvm.di_expr<[]> = %arg2 : i32
   // CHECK: llvm.intr.dbg.label #[[LABEL1]]
   llvm.intr.dbg.label #label1
   // CHECK: llvm.intr.dbg.label #[[LABEL2]]
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index b684be1f9626b1c..4f78f8b73b7102f 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -10,8 +10,8 @@ func.func @inner_func_inlinable(%ptr : !llvm.ptr) -> i32 {
   %stack = llvm.intr.stacksave : !llvm.ptr
   llvm.store %0, %ptr { alignment = 8 } : i32, !llvm.ptr
   %1 = llvm.load %ptr { alignment = 8 } : !llvm.ptr -> i32
-  llvm.intr.dbg.value #variable = %0 : i32
-  llvm.intr.dbg.declare #variableAddr = %ptr : !llvm.ptr
+  llvm.intr.dbg.value #variable #llvm.di_expr<[]> = %0 : i32
+  llvm.intr.dbg.declare #variableAddr #llvm.di_expr<[]> = %ptr : !llvm.ptr
   llvm.intr.dbg.label #label
   %byte = llvm.mlir.constant(43 : i8) : i8
   %true = llvm.mlir.constant(1 : i1) : i1
@@ -38,8 +38,8 @@ func.func @inner_func_inlinable(%ptr : !llvm.ptr) -> i32 {
 // CHECK: %[[STACK:.+]] = llvm.intr.stacksave
 // CHECK: llvm.store %[[CST]], %[[PTR]]
 // CHECK: %[[RES:.+]] = llvm.load %[[PTR]]
-// CHECK: llvm.intr.dbg.value #{{.+}} = %[[CST]]
-// CHECK: llvm.intr.dbg.declare #{{.+}} = %[[PTR]]
+// CHECK: llvm.intr.dbg.value #{{.+}} #llvm.di_expr<[]> = %[[CST]]
+// CHECK: llvm.intr.dbg.declare #{{.+}} #llvm.di_expr<[]> = %[[PTR]]
 // CHECK: llvm.intr.dbg.label #{{.+}}
 // CHECK: "llvm.intr.memset"(%[[PTR]]
 // CHECK: "llvm.intr.memmove"(%[[PTR]], %[[PTR]]
diff --git a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
index bb96256f3af28f0..1b2fabdba3c2cb5 100644
--- a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
@@ -19,8 +19,8 @@ llvm.func @basic_store_load(%arg0: i64) -> i64 {
   // CHECK-NOT: llvm.store
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[LOADED:.*]] : i64
+  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[LOADED:.*]] : i64
   // CHECK-NOT: llvm.intr.dbg.value
   // CHECK-NOT: llvm.intr.dbg.declare
   // CHECK-NOT: llvm.store
@@ -36,17 +36,17 @@ llvm.func @block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
   // CHECK-NOT: = llvm.alloca
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
   llvm.cond_br %arg1, ^bb1, ^bb2
 // CHECK: ^{{.*}}:
 ^bb1:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[ARG0]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[ARG0]]
   // CHECK-NOT: llvm.intr.dbg.value
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   llvm.br ^bb2
 // CHECK: ^{{.*}}(%[[BLOCKARG:.*]]: i64):
 ^bb2:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG]]
   %2 = llvm.load %1 {alignment = 4 : i64} : !llvm.ptr -> i64
   llvm.return %2 : i64
 }
@@ -58,20 +58,20 @@ llvm.func @double_block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
   // CHECK-NOT: = llvm.alloca
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
   llvm.cond_br %arg1, ^bb1, ^bb2
 // CHECK: ^{{.*}}(%[[BLOCKARG1:.*]]: i64):
 ^bb1:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG1]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG1]]
   %2 = llvm.load %1 {alignment = 4 : i64} : !llvm.ptr -> i64
   llvm.call @use(%2) : (i64) -> ()
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[ARG0]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[ARG0]]
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   llvm.br ^bb2
   // CHECK-NOT: llvm.intr.dbg.value
 // CHECK: ^{{.*}}(%[[BLOCKARG2:.*]]: i64):
 ^bb2:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG2]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG2]]
   llvm.br ^bb1
 }
 
@@ -79,12 +79,12 @@ llvm.func @double_block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
 // CHECK: %[[UNDEF:.*]] = llvm.mlir.undef
 // CHECK-NOT: = llvm.alloca
 // CHECK-NOT: llvm.intr.dbg.declare
-// CHECK: llvm.intr.dbg.value #{{.*}} = %[[UNDEF]]
+// CHECK: llvm.intr.dbg.value #{{.*}} #llvm.di_expr<[]> = %[[UNDEF]]
 llvm.func @always_drop_promoted_declare() {
   %0 = llvm.mlir.constant(1 : i32) : i32
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
-  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
-  llvm.intr.dbg.value #di_local_variable = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
   llvm.return
 }
 
@@ -95,13 +95,13 @@ llvm.func @keep_dbg_if_not_promoted() {
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: = llvm.alloca
   // CHECK-NOT: llvm.intr.dbg.declare
-  // CHECK: llvm.intr.dbg.declare #[[$VAR]] = %[[ALLOCA]]
+  // CHECK: llvm.intr.dbg.declare #[[$VAR]] #llvm.di_expr<[]> = %[[ALLOCA]]
   // CHECK-NOT: = llvm.alloca
   // CHECK-NOT: llvm.intr.dbg.declare
   // CHECK: llvm.call @use_ptr(%[[ALLOCA]])
-  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
   %2 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
-  llvm.intr.dbg.declare #di_local_variable_2 = %2 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable_2 #llvm.di_expr<[]> = %2 : !llvm.ptr
   llvm.call @use_ptr(%1) : (!llvm.ptr) -> ()
   llvm.return
 }
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index 08e60deb699d8d1..f76d333b6eba6e4 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -256,9 +256,9 @@ source_filename = "debug-info.ll"
 ; CHECK-SAME:  %[[ARG0:[a-zA-Z0-9]+]]
 ; CHECK-SAME:  %[[ARG1:[a-zA-Z0-9]+]]
 define void @intrinsic(i64 %0, ptr %1) {
-  ; CHECK: llvm.intr.dbg.declare #[[$VAR1]] = %[[ARG1]] : !llvm.ptr loc(#[[LOC1:.+]])
-  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] = %[[ARG0]] : i64 loc(#[[LOC0:.+]])
-  call void @llvm.dbg.value(metadata i64 %0, metadata !5, metadata !DIExpression()), !dbg !7
+  ; CHECK: llvm.intr.dbg.declare #[[$VAR1]] #llvm.di_expr<[]> = %[[ARG1]] : !llvm.ptr loc(#[[LOC1:.+]])
+  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] #llvm.di_expr<[4096, 0, 8]> = %[[ARG0]] : i64 loc(#[[LOC0:.+]])
+  call void @llvm.dbg.value(metadata i64 %0, metadata !5, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 8)), !dbg !7
   call void @llvm.dbg.declare(metadata ptr %1, metadata !6, metadata !DIExpression()), !dbg !9
   ; CHECK: llvm.intr.dbg.label #[[$LABEL]] loc(#[[LOC1:.+]])
   call void @llvm.dbg.label(metadata !10), !dbg !9
@@ -324,7 +324,7 @@ define void @class_method() {
 ; CHECK-LABEL: @class_field
 ; CHECK-SAME:  %[[ARG0:[a-zA-Z0-9]+]]
 define void @class_field(ptr %arg1) {
-  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] = %[[ARG0]] : !llvm.ptr
+  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] #llvm.di_expr<[]> = %[[ARG0]] : !llvm.ptr
   call void @llvm.dbg.value(metadata ptr %arg1, metadata !7, metadata !DIExpression()), !dbg !9
   ret void
 }
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index 19837072f676376..09621346656636f 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -61,14 +61,11 @@ define void @unhandled_intrinsic() gc "example" {
 
 declare void @llvm.dbg.value(metadata, metadata, metadata)
 
-; CHECK:      import-failure.ll
-; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata i64 %arg1, metadata !3, metadata !DIExpression(DW_OP_plus_uconst, 42, DW_OP_stack_value)), !dbg !5
 ; CHECK:      import-failure.ll
 ; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5
 ; CHECK:      import-failure.ll
 ; CHECK-SAME: warning: dropped intrinsic: call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5
 define void @dropped_instruction(i64 %arg1) {
-  call void @llvm.dbg.value(metadata i64 %arg1, metadata !3, metadata !DIExpression(DW_OP_plus_uconst, 42, DW_OP_stack_value)), !dbg !5
   call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value)), !dbg !5
   call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5
   ret void
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index ea962c66cb8eff9..89d98ad33cc6d7d 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -74,7 +74,7 @@ llvm.func @func_no_debug() {
 #variableAddr = #llvm.di_local_variable<scope = #blockScope, name = "alloc">
 #noNameVariable = #llvm.di_local_variable<scope = #blockScope>
 #module = #llvm.di_module<
-  file = #file, scope = #file, name = "module", 
+  file = #file, scope = #file, name = "module",
   configMacros = "bar", includePath = "/",
   apinotes = "/", line = 42, isDecl = true
 >
@@ -92,11 +92,11 @@ llvm.func @func_with_debug(%arg: i64) {
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
 
   // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression())
-  // CHECK: call void @llvm.dbg.declare(metadata ptr %[[ALLOC]], metadata ![[ADDR_LOC:[0-9]+]], metadata !DIExpression())
+  // CHECK: call void @llvm.dbg.declare(metadata ptr %[[ALLOC]], metadata ![[ADDR_LOC:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 8))
   // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[NO_NAME_VAR:[0-9]+]], metadata !DIExpression())
-  llvm.intr.dbg.value #variable = %arg : i64
-  llvm.intr.dbg.declare #variableAddr = %alloc : !llvm.ptr
-  llvm.intr.dbg.value #noNameVariable= %arg : i64
+  llvm.intr.dbg.value #variable #llvm.di_expr<[]> = %arg : i64
+  llvm.intr.dbg.declare #variableAddr #llvm.di_expr<[4096, 0, 8]> = %alloc : !llvm.ptr
+  llvm.intr.dbg.value #noNameVariable #llvm.di_expr<[]> = %arg : i64
 
   // CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
   llvm.call @func_no_debug() : () -> () loc(callsite("mysource.cc":3:4 at "mysource.cc":5:6))
@@ -190,9 +190,9 @@ llvm.func @empty_types() {
 // CHECK-SAME: i32 %[[ARG:.*]]) !dbg ![[OUTER_FUNC:[0-9]+]]
 llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) {
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC0:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC0:.*]]
-  llvm.intr.dbg.value #di_local_variable0 = %arg0 : i32 loc(fused<#di_subprogram>[#loc0])
+  llvm.intr.dbg.value #di_local_variable0 #llvm.di_expr<[]> = %arg0 : i32 loc(fused<#di_subprogram>[#loc0])
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC1:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC1:.*]]
-  llvm.intr.dbg.value #di_local_variable1 = %arg0 : i32 loc(fused<#di_lexical_block_file>[#loc1])
+  llvm.intr.dbg.value #di_local_variable1 #llvm.di_expr<[]> = %arg0 : i32 loc(fused<#di_lexical_block_file>[#loc1])
   // CHECK: call void @llvm.dbg.label(metadata ![[LABEL:[0-9]+]]), !dbg ![[DBG_LOC1:.*]]
   llvm.intr.dbg.label #di_label loc(fused<#di_lexical_block_file>[#loc1])
   llvm.return %arg0 : i32
@@ -225,7 +225,7 @@ llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) {
 // CHECK-SAME: i32 %[[ARG:.*]])
 llvm.func @func_without_subprogram(%0 : i32) {
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC0:.*]]
-  llvm.intr.dbg.value #di_local_variable = %0 : i32 loc(fused<#di_subprogram>[#loc])
+  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %0 : i32 loc(fused<#di_subprogram>[#loc])
   llvm.return
 }
 
@@ -256,9 +256,9 @@ llvm.func @dbg_intrinsics_with_no_location(%arg0: i32) -> (i32) {
   %allocCount = llvm.mlir.constant(1 : i32) : i32
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
   // CHECK-NOT: @llvm.dbg.value
-  llvm.intr.dbg.value #di_local_variable = %arg0 : i32
+  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %arg0 : i32
   // CHECK-NOT: @llvm.dbg.declare
-  llvm.intr.dbg.declare #declared_var = %alloc : !llvm.ptr
+  llvm.intr.dbg.declare #declared_var #llvm.di_expr<[]> = %alloc : !llvm.ptr
   // CHECK-NOT: @llvm.dbg.label
   llvm.intr.dbg.label #di_label
   llvm.return %arg0 : i32
diff --git a/mlir/test/mlir-translate/import-diagnostics.ll b/mlir/test/mlir-translate/import-diagnostics.ll
index dd72f07745b4ba9..acf45eb1c7c5dd5 100644
--- a/mlir/test/mlir-translate/import-diagnostics.ll
+++ b/mlir/test/mlir-translate/import-diagnostics.ll
@@ -37,7 +37,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata)
 ; DEFAULT-NOT: warning:
 ; EXPENSIVE:   warning:
 define void @dropped_instruction(i64 %arg1) {
-  call void @llvm.dbg.value(metadata i64 %arg1, metadata !3, metadata !DIExpression(DW_OP_plus_uconst, 42, DW_OP_stack_value)), !dbg !5
+  call void @llvm.dbg.value(metadata !DIArgList(i64 %arg1, i64 undef), metadata !3, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !5
   ret void
 }
 

>From a7af0a69796558a5e8eab522862bffffda43a746 Mon Sep 17 00:00:00 2001
From: Billy Zhu <billyzhu at modular.com>
Date: Wed, 15 Nov 2023 23:31:12 -0800
Subject: [PATCH 2/2] make locationExpr optional

---
 .../mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td   |  6 ++--
 mlir/test/Dialect/LLVMIR/debuginfo.mlir       |  8 ++---
 mlir/test/Dialect/LLVMIR/inlining.mlir        |  8 ++---
 mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir | 30 +++++++++----------
 mlir/test/Target/LLVMIR/Import/debug-info.ll  |  4 +--
 mlir/test/Target/LLVMIR/llvmir-debug.mlir     | 16 +++++-----
 6 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index b59826b9b2c9383..1d6936ed6c2bf0f 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -548,7 +548,7 @@ class LLVM_DbgIntrOp<string name, string argName, list<Trait> traits = []>
     return success();
   }];
   let assemblyFormat = [{
-    qualified($varInfo) qualified($locationExpr) `=` $}] # argName #
+    qualified($varInfo) (qualified($locationExpr)^)? `=` $}] # argName #
       [{ `:` qualified(type($}] # argName # [{)) attr-dict
   }];
 }
@@ -559,7 +559,7 @@ def LLVM_DbgDeclareOp : LLVM_DbgIntrOp<"dbg.declare", "addr",
   let arguments = (ins
     LLVM_AnyPointer:$addr,
     LLVM_DILocalVariableAttr:$varInfo,
-    LLVM_DIExpressionAttr:$locationExpr
+    DefaultValuedAttr<LLVM_DIExpressionAttr, "std::nullopt">:$locationExpr
   );
 }
 
@@ -569,7 +569,7 @@ def LLVM_DbgValueOp : LLVM_DbgIntrOp<"dbg.value", "value",
   let arguments = (ins
     LLVM_Type:$value,
     LLVM_DILocalVariableAttr:$varInfo,
-    LLVM_DIExpressionAttr:$locationExpr
+    DefaultValuedAttr<LLVM_DIExpressionAttr, "std::nullopt">:$locationExpr
   );
 }
 
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index b0a6273f45f9efa..b5f98b75e509397 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -155,8 +155,8 @@ llvm.func @addr(%arg: i64) {
   %allocCount = llvm.mlir.constant(1 : i32) : i32
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
 
-  // CHECK: llvm.intr.dbg.value #[[VAR0]] #llvm.di_expr<[]> = %[[ALLOC]]
-  llvm.intr.dbg.value #var0 #llvm.di_expr<[]> = %alloc : !llvm.ptr
+  // CHECK: llvm.intr.dbg.value #[[VAR0]] = %[[ALLOC]]
+  llvm.intr.dbg.value #var0 = %alloc : !llvm.ptr
   llvm.return
 }
 
@@ -164,8 +164,8 @@ llvm.func @addr(%arg: i64) {
 llvm.func @value(%arg1: i32, %arg2: i32) {
   // CHECK: llvm.intr.dbg.value #[[VAR1]] #llvm.di_expr<[2, 4096, 0, 4]> = %[[ARG1]]
   llvm.intr.dbg.value #var1 #llvm.di_expr<[2, 4096, 0, 4]> = %arg1 : i32
-  // CHECK: llvm.intr.dbg.value #[[VAR2]] #llvm.di_expr<[]> = %[[ARG2]]
-  llvm.intr.dbg.value #var2 #llvm.di_expr<[]> = %arg2 : i32
+  // CHECK: llvm.intr.dbg.value #[[VAR2]] = %[[ARG2]]
+  llvm.intr.dbg.value #var2 = %arg2 : i32
   // CHECK: llvm.intr.dbg.label #[[LABEL1]]
   llvm.intr.dbg.label #label1
   // CHECK: llvm.intr.dbg.label #[[LABEL2]]
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index 4f78f8b73b7102f..b684be1f9626b1c 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -10,8 +10,8 @@ func.func @inner_func_inlinable(%ptr : !llvm.ptr) -> i32 {
   %stack = llvm.intr.stacksave : !llvm.ptr
   llvm.store %0, %ptr { alignment = 8 } : i32, !llvm.ptr
   %1 = llvm.load %ptr { alignment = 8 } : !llvm.ptr -> i32
-  llvm.intr.dbg.value #variable #llvm.di_expr<[]> = %0 : i32
-  llvm.intr.dbg.declare #variableAddr #llvm.di_expr<[]> = %ptr : !llvm.ptr
+  llvm.intr.dbg.value #variable = %0 : i32
+  llvm.intr.dbg.declare #variableAddr = %ptr : !llvm.ptr
   llvm.intr.dbg.label #label
   %byte = llvm.mlir.constant(43 : i8) : i8
   %true = llvm.mlir.constant(1 : i1) : i1
@@ -38,8 +38,8 @@ func.func @inner_func_inlinable(%ptr : !llvm.ptr) -> i32 {
 // CHECK: %[[STACK:.+]] = llvm.intr.stacksave
 // CHECK: llvm.store %[[CST]], %[[PTR]]
 // CHECK: %[[RES:.+]] = llvm.load %[[PTR]]
-// CHECK: llvm.intr.dbg.value #{{.+}} #llvm.di_expr<[]> = %[[CST]]
-// CHECK: llvm.intr.dbg.declare #{{.+}} #llvm.di_expr<[]> = %[[PTR]]
+// CHECK: llvm.intr.dbg.value #{{.+}} = %[[CST]]
+// CHECK: llvm.intr.dbg.declare #{{.+}} = %[[PTR]]
 // CHECK: llvm.intr.dbg.label #{{.+}}
 // CHECK: "llvm.intr.memset"(%[[PTR]]
 // CHECK: "llvm.intr.memmove"(%[[PTR]], %[[PTR]]
diff --git a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
index 1b2fabdba3c2cb5..bb96256f3af28f0 100644
--- a/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/mem2reg-dbginfo.mlir
@@ -19,8 +19,8 @@ llvm.func @basic_store_load(%arg0: i64) -> i64 {
   // CHECK-NOT: llvm.store
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[LOADED:.*]] : i64
+  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[LOADED:.*]] : i64
   // CHECK-NOT: llvm.intr.dbg.value
   // CHECK-NOT: llvm.intr.dbg.declare
   // CHECK-NOT: llvm.store
@@ -36,17 +36,17 @@ llvm.func @block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
   // CHECK-NOT: = llvm.alloca
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
   llvm.cond_br %arg1, ^bb1, ^bb2
 // CHECK: ^{{.*}}:
 ^bb1:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[ARG0]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[ARG0]]
   // CHECK-NOT: llvm.intr.dbg.value
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   llvm.br ^bb2
 // CHECK: ^{{.*}}(%[[BLOCKARG:.*]]: i64):
 ^bb2:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG]]
   %2 = llvm.load %1 {alignment = 4 : i64} : !llvm.ptr -> i64
   llvm.return %2 : i64
 }
@@ -58,20 +58,20 @@ llvm.func @double_block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
   // CHECK-NOT: = llvm.alloca
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: llvm.intr.dbg.declare
-  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
   llvm.cond_br %arg1, ^bb1, ^bb2
 // CHECK: ^{{.*}}(%[[BLOCKARG1:.*]]: i64):
 ^bb1:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG1]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG1]]
   %2 = llvm.load %1 {alignment = 4 : i64} : !llvm.ptr -> i64
   llvm.call @use(%2) : (i64) -> ()
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[ARG0]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[ARG0]]
   llvm.store %arg0, %1 {alignment = 4 : i64} : i64, !llvm.ptr
   llvm.br ^bb2
   // CHECK-NOT: llvm.intr.dbg.value
 // CHECK: ^{{.*}}(%[[BLOCKARG2:.*]]: i64):
 ^bb2:
-  // CHECK: llvm.intr.dbg.value #[[$VAR]] #llvm.di_expr<[]> = %[[BLOCKARG2]]
+  // CHECK: llvm.intr.dbg.value #[[$VAR]] = %[[BLOCKARG2]]
   llvm.br ^bb1
 }
 
@@ -79,12 +79,12 @@ llvm.func @double_block_argument_value(%arg0: i64, %arg1: i1) -> i64 {
 // CHECK: %[[UNDEF:.*]] = llvm.mlir.undef
 // CHECK-NOT: = llvm.alloca
 // CHECK-NOT: llvm.intr.dbg.declare
-// CHECK: llvm.intr.dbg.value #{{.*}} #llvm.di_expr<[]> = %[[UNDEF]]
+// CHECK: llvm.intr.dbg.value #{{.*}} = %[[UNDEF]]
 llvm.func @always_drop_promoted_declare() {
   %0 = llvm.mlir.constant(1 : i32) : i32
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
-  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
-  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
+  llvm.intr.dbg.value #di_local_variable = %1 : !llvm.ptr
   llvm.return
 }
 
@@ -95,13 +95,13 @@ llvm.func @keep_dbg_if_not_promoted() {
   %1 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
   // CHECK-NOT: = llvm.alloca
   // CHECK-NOT: llvm.intr.dbg.declare
-  // CHECK: llvm.intr.dbg.declare #[[$VAR]] #llvm.di_expr<[]> = %[[ALLOCA]]
+  // CHECK: llvm.intr.dbg.declare #[[$VAR]] = %[[ALLOCA]]
   // CHECK-NOT: = llvm.alloca
   // CHECK-NOT: llvm.intr.dbg.declare
   // CHECK: llvm.call @use_ptr(%[[ALLOCA]])
-  llvm.intr.dbg.declare #di_local_variable #llvm.di_expr<[]> = %1 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable = %1 : !llvm.ptr
   %2 = llvm.alloca %0 x i64 {alignment = 8 : i64} : (i32) -> !llvm.ptr
-  llvm.intr.dbg.declare #di_local_variable_2 #llvm.di_expr<[]> = %2 : !llvm.ptr
+  llvm.intr.dbg.declare #di_local_variable_2 = %2 : !llvm.ptr
   llvm.call @use_ptr(%1) : (!llvm.ptr) -> ()
   llvm.return
 }
diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll
index f76d333b6eba6e4..51445f25dc400f0 100644
--- a/mlir/test/Target/LLVMIR/Import/debug-info.ll
+++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll
@@ -256,7 +256,7 @@ source_filename = "debug-info.ll"
 ; CHECK-SAME:  %[[ARG0:[a-zA-Z0-9]+]]
 ; CHECK-SAME:  %[[ARG1:[a-zA-Z0-9]+]]
 define void @intrinsic(i64 %0, ptr %1) {
-  ; CHECK: llvm.intr.dbg.declare #[[$VAR1]] #llvm.di_expr<[]> = %[[ARG1]] : !llvm.ptr loc(#[[LOC1:.+]])
+  ; CHECK: llvm.intr.dbg.declare #[[$VAR1]] = %[[ARG1]] : !llvm.ptr loc(#[[LOC1:.+]])
   ; CHECK: llvm.intr.dbg.value #[[$VAR0]] #llvm.di_expr<[4096, 0, 8]> = %[[ARG0]] : i64 loc(#[[LOC0:.+]])
   call void @llvm.dbg.value(metadata i64 %0, metadata !5, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 8)), !dbg !7
   call void @llvm.dbg.declare(metadata ptr %1, metadata !6, metadata !DIExpression()), !dbg !9
@@ -324,7 +324,7 @@ define void @class_method() {
 ; CHECK-LABEL: @class_field
 ; CHECK-SAME:  %[[ARG0:[a-zA-Z0-9]+]]
 define void @class_field(ptr %arg1) {
-  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] #llvm.di_expr<[]> = %[[ARG0]] : !llvm.ptr
+  ; CHECK: llvm.intr.dbg.value #[[$VAR0]] = %[[ARG0]] : !llvm.ptr
   call void @llvm.dbg.value(metadata ptr %arg1, metadata !7, metadata !DIExpression()), !dbg !9
   ret void
 }
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 89d98ad33cc6d7d..e088374ec0eb8e1 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -91,12 +91,12 @@ llvm.func @func_with_debug(%arg: i64) {
   %allocCount = llvm.mlir.constant(1 : i32) : i32
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
 
-  // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression())
+  // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 8, 8))
   // CHECK: call void @llvm.dbg.declare(metadata ptr %[[ALLOC]], metadata ![[ADDR_LOC:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 8))
   // CHECK: call void @llvm.dbg.value(metadata i64 %[[ARG]], metadata ![[NO_NAME_VAR:[0-9]+]], metadata !DIExpression())
-  llvm.intr.dbg.value #variable #llvm.di_expr<[]> = %arg : i64
+  llvm.intr.dbg.value #variable #llvm.di_expr<[4096, 8, 8]> = %arg : i64
   llvm.intr.dbg.declare #variableAddr #llvm.di_expr<[4096, 0, 8]> = %alloc : !llvm.ptr
-  llvm.intr.dbg.value #noNameVariable #llvm.di_expr<[]> = %arg : i64
+  llvm.intr.dbg.value #noNameVariable = %arg : i64
 
   // CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
   llvm.call @func_no_debug() : () -> () loc(callsite("mysource.cc":3:4 at "mysource.cc":5:6))
@@ -190,9 +190,9 @@ llvm.func @empty_types() {
 // CHECK-SAME: i32 %[[ARG:.*]]) !dbg ![[OUTER_FUNC:[0-9]+]]
 llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) {
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC0:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC0:.*]]
-  llvm.intr.dbg.value #di_local_variable0 #llvm.di_expr<[]> = %arg0 : i32 loc(fused<#di_subprogram>[#loc0])
+  llvm.intr.dbg.value #di_local_variable0 = %arg0 : i32 loc(fused<#di_subprogram>[#loc0])
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC1:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC1:.*]]
-  llvm.intr.dbg.value #di_local_variable1 #llvm.di_expr<[]> = %arg0 : i32 loc(fused<#di_lexical_block_file>[#loc1])
+  llvm.intr.dbg.value #di_local_variable1 = %arg0 : i32 loc(fused<#di_lexical_block_file>[#loc1])
   // CHECK: call void @llvm.dbg.label(metadata ![[LABEL:[0-9]+]]), !dbg ![[DBG_LOC1:.*]]
   llvm.intr.dbg.label #di_label loc(fused<#di_lexical_block_file>[#loc1])
   llvm.return %arg0 : i32
@@ -225,7 +225,7 @@ llvm.func @func_with_inlined_dbg_value(%arg0: i32) -> (i32) {
 // CHECK-SAME: i32 %[[ARG:.*]])
 llvm.func @func_without_subprogram(%0 : i32) {
   // CHECK: call void @llvm.dbg.value(metadata i32 %[[ARG]], metadata ![[VAR_LOC:[0-9]+]], metadata !DIExpression()), !dbg ![[DBG_LOC0:.*]]
-  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %0 : i32 loc(fused<#di_subprogram>[#loc])
+  llvm.intr.dbg.value #di_local_variable = %0 : i32 loc(fused<#di_subprogram>[#loc])
   llvm.return
 }
 
@@ -256,9 +256,9 @@ llvm.func @dbg_intrinsics_with_no_location(%arg0: i32) -> (i32) {
   %allocCount = llvm.mlir.constant(1 : i32) : i32
   %alloc = llvm.alloca %allocCount x i64 : (i32) -> !llvm.ptr
   // CHECK-NOT: @llvm.dbg.value
-  llvm.intr.dbg.value #di_local_variable #llvm.di_expr<[]> = %arg0 : i32
+  llvm.intr.dbg.value #di_local_variable = %arg0 : i32
   // CHECK-NOT: @llvm.dbg.declare
-  llvm.intr.dbg.declare #declared_var #llvm.di_expr<[]> = %alloc : !llvm.ptr
+  llvm.intr.dbg.declare #declared_var = %alloc : !llvm.ptr
   // CHECK-NOT: @llvm.dbg.label
   llvm.intr.dbg.label #di_label
   llvm.return %arg0 : i32



More information about the Mlir-commits mailing list