Skip to content

[MLIR][DebugInfo] Enable the use of DILocalVariable DIFlags #100190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
auto localVarAttr = mlir::LLVM::DILocalVariableAttr::get(
context, scopeAttr, mlir::StringAttr::get(context, result.second.name),
fileAttr, getLineFromLoc(declOp.getLoc()), argNo, /* alignInBits*/ 0,
tyAttr);
tyAttr, mlir::LLVM::DIFlags::Zero);
declOp->setLoc(builder.getFusedLoc({declOp->getLoc()}, localVarAttr));
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir-c/Dialect/LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
MlirContext ctx, MlirAttribute scope, MlirAttribute name,
MlirAttribute diFile, unsigned int line, unsigned int arg,
unsigned int alignInBits, MlirAttribute diType);
unsigned int alignInBits, MlirAttribute diType, int64_t flags);

/// Creates a LLVM DISubprogramAttr attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
Expand Down
7 changes: 4 additions & 3 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,18 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
OptionalParameter<"unsigned">:$line,
OptionalParameter<"unsigned">:$arg,
OptionalParameter<"unsigned">:$alignInBits,
OptionalParameter<"DITypeAttr">:$type
OptionalParameter<"DITypeAttr">:$type,
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags
);
let builders = [
AttrBuilderWithInferredContext<(ins
"DIScopeAttr":$scope, "StringRef":$name, "DIFileAttr":$file,
"unsigned":$line, "unsigned":$arg, "unsigned":$alignInBits,
"DITypeAttr":$type
"DITypeAttr":$type, "DIFlags":$flags
), [{
MLIRContext *ctx = scope.getContext();
return $_get(ctx, scope, StringAttr::get(ctx, name), file, line,
arg, alignInBits, type);
arg, alignInBits, type, flags);
}]>
];
let assemblyFormat = "`<` struct(params) `>`";
Expand Down
11 changes: 5 additions & 6 deletions mlir/lib/CAPI/Dialect/LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,14 @@ MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
cast<DIFileAttr>(unwrap(file)), discriminator));
}

MlirAttribute
mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope,
MlirAttribute name, MlirAttribute diFile,
unsigned int line, unsigned int arg,
unsigned int alignInBits, MlirAttribute diType) {
MlirAttribute mlirLLVMDILocalVariableAttrGet(
MlirContext ctx, MlirAttribute scope, MlirAttribute name,
MlirAttribute diFile, unsigned int line, unsigned int arg,
unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
return wrap(DILocalVariableAttr::get(
unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
arg, alignInBits, cast<DITypeAttr>(unwrap(diType))));
arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
}

MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Target/LLVMIR/DebugImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ DILocalVariableAttr DebugImporter::translateImpl(llvm::DILocalVariable *node) {
return DILocalVariableAttr::get(
context, scope, getStringAttrOrNull(node->getRawName()),
translate(node->getFile()), node->getLine(), node->getArg(),
node->getAlignInBits(), translate(node->getType()));
node->getAlignInBits(), translate(node->getType()),
symbolizeDIFlags(node->getFlags()).value_or(DIFlags::Zero));
}

DIVariableAttr DebugImporter::translateImpl(llvm::DIVariable *node) {
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Target/LLVMIR/DebugTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ DebugTranslation::translateImpl(DILocalVariableAttr attr) {
return llvm::DILocalVariable::get(
llvmCtx, translate(attr.getScope()), getMDStringOrNull(attr.getName()),
translate(attr.getFile()), attr.getLine(), translate(attr.getType()),
attr.getArg(),
/*Flags=*/llvm::DINode::FlagZero, attr.getAlignInBits(),
attr.getArg(), static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
attr.getAlignInBits(),
/*Annotations=*/nullptr);
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/test/CAPI/llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static void testDebugInfoAttributes(MlirContext ctx) {

// CHECK: #llvm.di_local_variable<{{.*}}>
MlirAttribute local_var = mlirLLVMDILocalVariableAttrGet(
ctx, compile_unit, foo, file, 1, 0, 8, di_type);
ctx, compile_unit, foo, file, 1, 0, 8, di_type, 0);
mlirAttributeDump(local_var);
// CHECK: #llvm.di_derived_type<{{.*}}>
// CHECK-NOT: dwarfAddressSpace
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/Target/LLVMIR/Import/debug-info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ define void @string_type(ptr %arg1) {
!6 = !DIStringType(name: "character(*)", stringLength: !4, size: 32, align: 8, stringLengthExpression: !8, stringLocationExpression: !7)
!7 = !DIExpression(DW_OP_push_object_address, DW_OP_deref)
!8 = !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 8)
!9 = !DILocalVariable(scope: !5, name: "str", file: !2, type: !6);
!9 = !DILocalVariable(scope: !5, name: "str", file: !2, type: !6, flags: 64);
!10 = !DILocation(line: 1, column: 2, scope: !5)

; CHECK: #[[VAR:.+]] = #llvm.di_local_variable<{{.*}}name = "string_size"{{.*}}>
Expand All @@ -791,3 +791,4 @@ define void @string_type(ptr %arg1) {
; CHECK-SAME: stringLength = #[[VAR]]
; CHECK-SAME: stringLengthExp = <[DW_OP_push_object_address, DW_OP_plus_uconst(8)]>
; CHECK-SAME: stringLocationExp = <[DW_OP_push_object_address, DW_OP_deref]>>
; CHECK: #di_local_variable1 = #llvm.di_local_variable<scope = #di_subprogram, name = "str", file = #di_file, type = #di_string_type, flags = Artificial>
4 changes: 2 additions & 2 deletions mlir/test/Target/LLVMIR/llvmir-debug.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ llvm.func @subranges(%arg: !llvm.ptr) {
file = #file, isOptimized = false, emissionKind = Full>
#sp = #llvm.di_subprogram<compileUnit = #cu, scope = #file, name = "test",
file = #file, subprogramFlags = Definition>
#var = #llvm.di_local_variable<scope = #sp, name = "string_size", type = #bt>
#var = #llvm.di_local_variable<scope = #sp, name = "string_size", type = #bt, flags = Artificial>
#ty = #llvm.di_string_type<tag = DW_TAG_string_type, name = "character(*)",
sizeInBits = 32, alignInBits = 8, stringLength = #var,
stringLengthExp = <[DW_OP_push_object_address, DW_OP_plus_uconst(8)]>,
Expand All @@ -620,4 +620,4 @@ llvm.func @string_ty(%arg0: !llvm.ptr) {
#loc2 = loc(fused<#sp>[#loc1])

// 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)
// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "string_size"{{.*}})
// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "string_size"{{.*}} flags: DIFlagArtificial)
Loading