diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp index 1ddbcc958633c8..577d37cc34b962 100644 --- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp +++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp @@ -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)); } diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h index 902b45444d6c4e..631b5646183204 100644 --- a/mlir/include/mlir-c/Dialect/LLVM.h +++ b/mlir/include/mlir-c/Dialect/LLVM.h @@ -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( diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td index aefc02bce40fb0..695a962bcab9b9 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td @@ -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) `>`"; diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp index 754c94511524db..03e2f2be2156af 100644 --- a/mlir/lib/CAPI/Dialect/LLVM.cpp +++ b/mlir/lib/CAPI/Dialect/LLVM.cpp @@ -266,15 +266,14 @@ MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, cast(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(unwrap(scope)), cast(unwrap(name)), cast(unwrap(diFile)), line, - arg, alignInBits, cast(unwrap(diType)))); + arg, alignInBits, cast(unwrap(diType)), DIFlags(flags))); } MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp index f104b72209c391..1817c1271b43ee 100644 --- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp +++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp @@ -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) { diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp index 35800e993d89d3..95b37e47d04612 100644 --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -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(attr.getFlags()), + attr.getAlignInBits(), /*Annotations=*/nullptr); } diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c index 082ddc53e6282a..d3054aa6a0d93d 100644 --- a/mlir/test/CAPI/llvm.c +++ b/mlir/test/CAPI/llvm.c @@ -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 diff --git a/mlir/test/Target/LLVMIR/Import/debug-info.ll b/mlir/test/Target/LLVMIR/Import/debug-info.ll index a194ecbf2eb204..03c3855a9a324c 100644 --- a/mlir/test/Target/LLVMIR/Import/debug-info.ll +++ b/mlir/test/Target/LLVMIR/Import/debug-info.ll @@ -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"{{.*}}> @@ -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 diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir index f89ef5af87f4b7..1a9a8561de00dc 100644 --- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir @@ -603,7 +603,7 @@ llvm.func @subranges(%arg: !llvm.ptr) { file = #file, isOptimized = false, emissionKind = Full> #sp = #llvm.di_subprogram -#var = #llvm.di_local_variable +#var = #llvm.di_local_variable #ty = #llvm.di_string_type, @@ -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)