Skip to content

Commit 6ce310d

Browse files
committed
[mlir][llvm] Handle debug record import edge cases
This commit enables the direct import of debug records by default and fixes issues with two edge cases: - Detect early on if the address operand is an argument list (calling getAddress() for argument lists asserts) - Use getAddress() to check if the address operand is null, which means the address operand is an empty metadata node, which currently is not supported. This is a follow-up to: #167812
1 parent eb65517 commit 6ce310d

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

mlir/include/mlir/Target/LLVMIR/ModuleImport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class ModuleImport {
358358
/// used by these operations.
359359
std::tuple<DILocalVariableAttr, DIExpressionAttr, Value>
360360
processDebugOpArgumentsAndInsertionPt(
361-
Location loc, bool hasArgList, bool isKillLocation,
361+
Location loc,
362362
llvm::function_ref<FailureOr<Value>()> convertArgOperandToValue,
363363
llvm::Value *address,
364364
llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> variable,

mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void registerFromLLVMIRTranslation() {
7979

8080
// Now that the translation supports importing debug records directly,
8181
// make it the default, but allow the user to override to old behavior.
82-
if (!convertDebugRecToIntrinsics)
82+
if (convertDebugRecToIntrinsics)
8383
llvmModule->convertFromNewDbgValues();
8484

8585
return translateLLVMIRToModule(

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,10 +3047,12 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
30473047
return success();
30483048
}
30493049

3050-
/// Checks if a kill location holds metadata instead of an SSA value.
3051-
static bool isMetadataKillLocation(bool isKillLocation, llvm::Value *value) {
3052-
if (!isKillLocation)
3050+
/// Checks if `dbgIntr` is a kill location that holds metadata instead of an SSA
3051+
/// value.
3052+
static bool isMetadataKillLocation(llvm::DbgVariableIntrinsic *dbgIntr) {
3053+
if (!dbgIntr->isKillLocation())
30533054
return false;
3055+
llvm::Value *value = dbgIntr->getArgOperand(0);
30543056
auto *nodeAsVal = dyn_cast<llvm::MetadataAsValue>(value);
30553057
if (!nodeAsVal)
30563058
return false;
@@ -3095,23 +3097,13 @@ static LogicalResult setDebugIntrinsicBuilderInsertionPoint(
30953097

30963098
std::tuple<DILocalVariableAttr, DIExpressionAttr, Value>
30973099
ModuleImport::processDebugOpArgumentsAndInsertionPt(
3098-
Location loc, bool hasArgList, bool isKillLocation,
3100+
Location loc,
30993101
llvm::function_ref<FailureOr<Value>()> convertArgOperandToValue,
31003102
llvm::Value *address,
31013103
llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> variable,
31023104
llvm::DIExpression *expression, DominanceInfo &domInfo) {
3103-
// Drop debug intrinsics with arg lists.
3104-
// TODO: Support debug intrinsics that have arg lists.
3105-
if (hasArgList)
3106-
return {};
3107-
// Kill locations can have metadata nodes as location operand. This
3108-
// cannot be converted to poison as the type cannot be reconstructed.
3109-
// TODO: find a way to support this case.
3110-
if (isMetadataKillLocation(isKillLocation, address))
3111-
return {};
3112-
// Drop debug intrinsics if the associated variable information cannot be
3113-
// translated due to cyclic debug metadata.
3114-
// TODO: Support cyclic debug metadata.
3105+
// Drop debug intrinsics if the associated debug information cannot be
3106+
// translated due to an unsupported construct.
31153107
DILocalVariableAttr localVarAttr = matchLocalVariableAttr(variable);
31163108
if (!localVarAttr)
31173109
return {};
@@ -3144,10 +3136,21 @@ ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
31443136
return convertMetadataValue(dbgIntr->getArgOperand(0));
31453137
};
31463138

3139+
// Drop debug intrinsics with an argument list.
3140+
// TODO: Support this case.
3141+
if (dbgIntr->hasArgList())
3142+
return emitUnsupportedWarning();
3143+
3144+
// Drop debug intrinsics with kill locations that have metadata nodes as
3145+
// location operand, which cannot be converted to poison as the type cannot be
3146+
// reconstructed.
3147+
// TODO: Support this case.
3148+
if (isMetadataKillLocation(dbgIntr))
3149+
return emitUnsupportedWarning();
3150+
31473151
auto [localVariableAttr, locationExprAttr, locVal] =
31483152
processDebugOpArgumentsAndInsertionPt(
3149-
loc, dbgIntr->hasArgList(), dbgIntr->isKillLocation(),
3150-
convertArgOperandToValue, dbgIntr->getArgOperand(0),
3153+
loc, convertArgOperandToValue, dbgIntr->getArgOperand(0),
31513154
dbgIntr->getArgOperand(1), dbgIntr->getExpression(), domInfo);
31523155

31533156
if (!localVariableAttr)
@@ -3203,11 +3206,21 @@ LogicalResult ModuleImport::processDebugRecord(llvm::DbgRecord &debugRecord,
32033206
return failure();
32043207
};
32053208

3209+
// Drop debug records with an argument list.
3210+
// TODO: Support this case.
3211+
if (dbgVar->hasArgList())
3212+
return emitUnsupportedWarning();
3213+
3214+
// Drop kill location debug records with a null address operand, which cannot
3215+
// be converted to poison as the type cannot be reconstructed.
3216+
// TODO: Support this case.
3217+
if (!dbgVar->getAddress())
3218+
return emitUnsupportedWarning();
3219+
32063220
auto [localVariableAttr, locationExprAttr, locVal] =
32073221
processDebugOpArgumentsAndInsertionPt(
3208-
loc, dbgVar->hasArgList(), dbgVar->isKillLocation(),
3209-
convertArgOperandToValue, dbgVar->getAddress(), dbgVar->getVariable(),
3210-
dbgVar->getExpression(), domInfo);
3222+
loc, convertArgOperandToValue, dbgVar->getAddress(),
3223+
dbgVar->getVariable(), dbgVar->getExpression(), domInfo);
32113224

32123225
if (!localVariableAttr)
32133226
return emitUnsupportedWarning();

mlir/test/Target/LLVMIR/Import/debug-info.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: mlir-translate -import-llvm -mlir-print-debuginfo -split-input-file %s | FileCheck %s
1+
; RUN: mlir-translate -import-llvm -convert-debug-rec-to-intrinsics -mlir-print-debuginfo -split-input-file %s | FileCheck %s
22

33
; CHECK: #[[$UNKNOWN_LOC:.+]] = loc(unknown)
44

mlir/test/Target/LLVMIR/Import/import-failure.ll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
; RUN: not mlir-translate -import-llvm -emit-expensive-warnings -split-input-file %s 2>&1 -o /dev/null | FileCheck %s
22

3-
; Check that debug intrinsics with an unsupported argument are dropped.
4-
5-
declare void @llvm.dbg.value(metadata, metadata, metadata)
3+
; Check that debug records with an unsupported argument are dropped.
64

75
; CHECK: import-failure.ll
8-
; CHECK-SAME: warning: dropped intrinsic: tail call void @llvm.dbg.value(metadata !DIArgList(i64 %{{.*}}, 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))
6+
; CHECK-SAME: warning: unhandled debug record #dbg_value(!DIArgList(i64 %{{.*}}, i64 undef), !{{.*}}, !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), !{{.*}})
97
; CHECK: import-failure.ll
10-
; CHECK-SAME: warning: dropped intrinsic: tail call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression())
8+
; CHECK-SAME: warning: unhandled debug record #dbg_value(!{{.*}}, !{{.*}}, !DIExpression(), !{{.*}})
119
define void @unsupported_argument(i64 %arg1) {
12-
tail 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
13-
tail call void @llvm.dbg.value(metadata !6, metadata !3, metadata !DIExpression()), !dbg !5
10+
#dbg_value(!DIArgList(i64 %arg1, i64 undef), !3, !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), !5)
11+
#dbg_value(!6, !3, !DIExpression(), !5)
1412
ret void
1513
}
1614

0 commit comments

Comments
 (0)