Skip to content

Commit ef8de68

Browse files
[MLIR][DebugInfo] Enable the use of DILocalVariable DIFlags (#100190)
This patch enables the use of flags for local variables in debug info. They were defaulted as always zero, but allowing them is pretty trivial.
1 parent 4f516aa commit ef8de68

File tree

9 files changed

+20
-18
lines changed

9 files changed

+20
-18
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
129129
auto localVarAttr = mlir::LLVM::DILocalVariableAttr::get(
130130
context, scopeAttr, mlir::StringAttr::get(context, result.second.name),
131131
fileAttr, getLineFromLoc(declOp.getLoc()), argNo, /* alignInBits*/ 0,
132-
tyAttr);
132+
tyAttr, mlir::LLVM::DIFlags::Zero);
133133
declOp->setLoc(builder.getFusedLoc({declOp->getLoc()}, localVarAttr));
134134
}
135135

mlir/include/mlir-c/Dialect/LLVM.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(
309309
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
310310
MlirContext ctx, MlirAttribute scope, MlirAttribute name,
311311
MlirAttribute diFile, unsigned int line, unsigned int arg,
312-
unsigned int alignInBits, MlirAttribute diType);
312+
unsigned int alignInBits, MlirAttribute diType, int64_t flags);
313313

314314
/// Creates a LLVM DISubprogramAttr attribute.
315315
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

+4-3
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,18 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
532532
OptionalParameter<"unsigned">:$line,
533533
OptionalParameter<"unsigned">:$arg,
534534
OptionalParameter<"unsigned">:$alignInBits,
535-
OptionalParameter<"DITypeAttr">:$type
535+
OptionalParameter<"DITypeAttr">:$type,
536+
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags
536537
);
537538
let builders = [
538539
AttrBuilderWithInferredContext<(ins
539540
"DIScopeAttr":$scope, "StringRef":$name, "DIFileAttr":$file,
540541
"unsigned":$line, "unsigned":$arg, "unsigned":$alignInBits,
541-
"DITypeAttr":$type
542+
"DITypeAttr":$type, "DIFlags":$flags
542543
), [{
543544
MLIRContext *ctx = scope.getContext();
544545
return $_get(ctx, scope, StringAttr::get(ctx, name), file, line,
545-
arg, alignInBits, type);
546+
arg, alignInBits, type, flags);
546547
}]>
547548
];
548549
let assemblyFormat = "`<` struct(params) `>`";

mlir/lib/CAPI/Dialect/LLVM.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,14 @@ MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
266266
cast<DIFileAttr>(unwrap(file)), discriminator));
267267
}
268268

269-
MlirAttribute
270-
mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope,
271-
MlirAttribute name, MlirAttribute diFile,
272-
unsigned int line, unsigned int arg,
273-
unsigned int alignInBits, MlirAttribute diType) {
269+
MlirAttribute mlirLLVMDILocalVariableAttrGet(
270+
MlirContext ctx, MlirAttribute scope, MlirAttribute name,
271+
MlirAttribute diFile, unsigned int line, unsigned int arg,
272+
unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
274273
return wrap(DILocalVariableAttr::get(
275274
unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
276275
cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
277-
arg, alignInBits, cast<DITypeAttr>(unwrap(diType))));
276+
arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
278277
}
279278

280279
MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,

mlir/lib/Target/LLVMIR/DebugImporter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ DILocalVariableAttr DebugImporter::translateImpl(llvm::DILocalVariable *node) {
180180
return DILocalVariableAttr::get(
181181
context, scope, getStringAttrOrNull(node->getRawName()),
182182
translate(node->getFile()), node->getLine(), node->getArg(),
183-
node->getAlignInBits(), translate(node->getType()));
183+
node->getAlignInBits(), translate(node->getType()),
184+
symbolizeDIFlags(node->getFlags()).value_or(DIFlags::Zero));
184185
}
185186

186187
DIVariableAttr DebugImporter::translateImpl(llvm::DIVariable *node) {

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ DebugTranslation::translateImpl(DILocalVariableAttr attr) {
228228
return llvm::DILocalVariable::get(
229229
llvmCtx, translate(attr.getScope()), getMDStringOrNull(attr.getName()),
230230
translate(attr.getFile()), attr.getLine(), translate(attr.getType()),
231-
attr.getArg(),
232-
/*Flags=*/llvm::DINode::FlagZero, attr.getAlignInBits(),
231+
attr.getArg(), static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
232+
attr.getAlignInBits(),
233233
/*Annotations=*/nullptr);
234234
}
235235

mlir/test/CAPI/llvm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static void testDebugInfoAttributes(MlirContext ctx) {
294294

295295
// CHECK: #llvm.di_local_variable<{{.*}}>
296296
MlirAttribute local_var = mlirLLVMDILocalVariableAttrGet(
297-
ctx, compile_unit, foo, file, 1, 0, 8, di_type);
297+
ctx, compile_unit, foo, file, 1, 0, 8, di_type, 0);
298298
mlirAttributeDump(local_var);
299299
// CHECK: #llvm.di_derived_type<{{.*}}>
300300
// CHECK-NOT: dwarfAddressSpace

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ define void @string_type(ptr %arg1) {
781781
!6 = !DIStringType(name: "character(*)", stringLength: !4, size: 32, align: 8, stringLengthExpression: !8, stringLocationExpression: !7)
782782
!7 = !DIExpression(DW_OP_push_object_address, DW_OP_deref)
783783
!8 = !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8)
784-
!9 = !DILocalVariable(scope: !5, name: "str", file: !2, type: !6);
784+
!9 = !DILocalVariable(scope: !5, name: "str", file: !2, type: !6, flags: 64);
785785
!10 = !DILocation(line: 1, column: 2, scope: !5)
786786

787787
; CHECK: #[[VAR:.+]] = #llvm.di_local_variable<{{.*}}name = "string_size"{{.*}}>
@@ -791,3 +791,4 @@ define void @string_type(ptr %arg1) {
791791
; CHECK-SAME: stringLength = #[[VAR]]
792792
; CHECK-SAME: stringLengthExp = <[DW_OP_push_object_address, DW_OP_plus_uconst(8)]>
793793
; CHECK-SAME: stringLocationExp = <[DW_OP_push_object_address, DW_OP_deref]>>
794+
; CHECK: #di_local_variable1 = #llvm.di_local_variable<scope = #di_subprogram, name = "str", file = #di_file, type = #di_string_type, flags = Artificial>

mlir/test/Target/LLVMIR/llvmir-debug.mlir

+2-2
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ llvm.func @subranges(%arg: !llvm.ptr) {
603603
file = #file, isOptimized = false, emissionKind = Full>
604604
#sp = #llvm.di_subprogram<compileUnit = #cu, scope = #file, name = "test",
605605
file = #file, subprogramFlags = Definition>
606-
#var = #llvm.di_local_variable<scope = #sp, name = "string_size", type = #bt>
606+
#var = #llvm.di_local_variable<scope = #sp, name = "string_size", type = #bt, flags = Artificial>
607607
#ty = #llvm.di_string_type<tag = DW_TAG_string_type, name = "character(*)",
608608
sizeInBits = 32, alignInBits = 8, stringLength = #var,
609609
stringLengthExp = <[DW_OP_push_object_address, DW_OP_plus_uconst(8)]>,
@@ -620,4 +620,4 @@ llvm.func @string_ty(%arg0: !llvm.ptr) {
620620
#loc2 = loc(fused<#sp>[#loc1])
621621

622622
// CHECK-DAG: !DIStringType(name: "character(*)", stringLength: ![[VAR:[0-9]+]], stringLengthExpression: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8), stringLocationExpression: !DIExpression(DW_OP_push_object_address, DW_OP_deref), size: 32, align: 8)
623-
// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "string_size"{{.*}})
623+
// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "string_size"{{.*}} flags: DIFlagArtificial)

0 commit comments

Comments
 (0)