[Flang] Add missing dependency to AddDebugInfo pass (#139099)

The `AddDebugInfo` pass currently has a dependency on the `DLTI` MLIR
dialect caused by a call to the `fir::support::getOrSetMLIRDataLayout()`
utility function.

This dependency is not captured in the pass definition. This patch adds
the dependency and simplifies several unit tests that had to explicitly
use the `DLTI` dialect to prevent the missing dependency from causing
compiler failures.
This commit is contained in:
Sergio Afonso 2025-05-09 12:19:53 +01:00 committed by GitHub
parent 187a83f86c
commit 4923cffc1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 31 additions and 29 deletions

View File

@ -210,7 +210,8 @@ def AddDebugInfo : Pass<"add-debug-info", "mlir::ModuleOp"> {
}];
let constructor = "::fir::createAddDebugInfoPass()";
let dependentDialects = [
"fir::FIROpsDialect", "mlir::func::FuncDialect", "mlir::LLVM::LLVMDialect"
"fir::FIROpsDialect", "mlir::func::FuncDialect", "mlir::LLVM::LLVMDialect",
"mlir::DLTIDialect"
];
let options = [
Option<"debugLevel", "debug-level",

View File

@ -23,6 +23,7 @@
#include "flang/Optimizer/Support/InternalNames.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "flang/Support/Version.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Matchers.h"

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s -o - | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @test(%arg0: !fir.ref<!fir.char<1,?>> {fir.bindc_name = "str"}, %arg1: i64) {
%0 = fir.emboxchar %arg0, %arg1 : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
%1 = fir.undefined !fir.dscope

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s -o - | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QMhelperPmod_sub(%arg0: !fir.ref<i32> {fir.bindc_name = "a"} ) {
return
} loc(#loc1)

View File

@ -1,7 +1,7 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @_QFPff() {
%c1 = arith.constant 1 : index
%c0 = arith.constant 0 : index

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QFPfn(%arg0: !fir.box<!fir.array<*:i32>> ) {
%1 = fir.undefined !fir.dscope
%2 = fircg.ext_declare %arg0 dummy_scope %1 {uniq_name = "_QFFfnEx"} : (!fir.box<!fir.array<*:i32>>, !fir.dscope) -> !fir.box<!fir.array<*:i32>> loc(#loc2)

View File

@ -2,7 +2,7 @@
// Test assumed shape array with variable lower bound.
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @_QFPfn(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) attributes {} {
%c23_i32 = arith.constant 23 : i32
%c6_i32 = arith.constant 6 : i32

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QMhelperPfn(%arg0: !fir.ref<!fir.array<5x?xi32>> {fir.bindc_name = "a1"}, %arg1: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "a2"}, %arg2: !fir.ref<!fir.array<2x?xi32>> {fir.bindc_name = "a3"}) {
%c5 = arith.constant 5 : index
%c1 = arith.constant 1 : index

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @_QMhelperEstr1 : !fir.char<1,40> {
%0 = fir.zero_bits !fir.char<1,40>
fir.has_value %0 : !fir.char<1,40>

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.type_info @_QTtest_type nofinal : !fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}> dispatch_table {
fir.dt_entry "test_proc", @_QPtest_proc
} loc(#loc1)

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @__BLNK__ {alignment = 4 : i64} : tuple<i32, !fir.array<8xi8>> {} loc(#loc1)
fir.global @a_ {alignment = 4 : i64} : tuple<i32, !fir.array<8xi8>> {} loc(#loc2)
func.func @f1() {

View File

@ -3,7 +3,7 @@
// check conversion of complex type of different size. Both fir and mlir
// variants are checked.
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @test1(%x : complex<f32>) -> complex<f64> {
%1 = fir.convert %x : (complex<f32>) -> complex<f64>
return %1 : complex<f64>

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @_QMmEvar : !fir.type<_QMmTt1{elm:!fir.array<5xi32>,elm2:!fir.array<5x8xi32>}> {} loc(#loc1)
fir.type_info @_QMmTt1 noinit nodestroy nofinal : !fir.type<_QMmTt1{elm:!fir.array<5xi32>,elm2:!fir.array<5x8xi32>}> component_info {
fir.dt_component "elm" lbs [2]

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global linkonce_odr @_QFEXnXxcx constant target : !fir.char<1,3> {
%0 = fir.string_lit "xcx"(3) : !fir.char<1,3>
fir.has_value %0 : !fir.char<1,3>

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QQmain() attributes {fir.bindc_name = "mn"} {
%c7 = arith.constant 7 : index
%c8 = arith.constant 8 : index

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QQmain() attributes {fir.bindc_name = "mn"} {
%0 = fir.alloca i32 {bindc_name = "i4", uniq_name = "_QFEi4"}
%1 = fircg.ext_declare %0 {uniq_name = "_QFEi4"} : (!fir.ref<i32>) -> !fir.ref<i32>

View File

@ -1,7 +1,7 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @_QMfooEv1 : i32 {
%0 = fir.zero_bits i32
fir.has_value %0 : i32

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @str(%arg0: index) -> i32 loc(#loc1)
}
#loc1 = loc("test.f90":5:1)

View File

@ -3,7 +3,7 @@
// REQUIRES: system-linux
// Test that there are no changes to a function with existed fused loc debug
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QPs1() {
return loc(#loc1)
} loc(#loc2)

View File

@ -3,7 +3,7 @@
// REQUIRES: system-linux
// Test for included functions that have a different debug location than the current file
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QPsinc() {
return loc(#loc2)
} loc(#loc1)

View File

@ -4,7 +4,7 @@
// Test that there is only one FileAttribute generated for multiple functions
// in the same file.
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QPs1() {
return loc(#loc2)
} loc(#loc1)

View File

@ -3,7 +3,7 @@
// RUN: fir-opt --add-debug-info="debug-level=LineTablesOnly" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=LINETABLE
// RUN: fir-opt --add-debug-info="is-optimized=true" --mlir-print-debuginfo %s | FileCheck %s --check-prefix=OPT
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QPsb() {
return loc(#loc_sb)
} loc(#loc_sb)

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @_QQmain() attributes {fir.bindc_name = "mn"} {
%0 = fir.alloca i32 {bindc_name = "i4", uniq_name = "_QFEi4"}
%1 = fircg.ext_declare %0 {uniq_name = "_QFEi4"} : (!fir.ref<i32>) -> !fir.ref<i32> loc(#loc1)

View File

@ -1,7 +1,7 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @_QMhelperEgli : i32 {
%0 = fir.zero_bits i32
fir.has_value %0 : i32

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
fir.global @_QMhelperEpar : !fir.box<!fir.ptr<!fir.array<?x?xf32>>> {
%0 = fir.zero_bits !fir.ptr<!fir.array<?x?xf32>>
%c0 = arith.constant 0 : index

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @_FortranAioBeginExternalListOutput(i8) -> !fir.ref<i8> loc(#loc1)
}
#loc1 = loc("test.f90":5:1)

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @fn1(!fir.ref<tuple<f64, f64>>)
func.func private @_FortranAioOutputDerivedType(!fir.ref<tuple<>>)
}

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @foo_(%arg0: !fir.ref<!fir.array<?x?xi32>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}, %arg2: !fir.ref<i32> {fir.bindc_name = "m"}, %arg3: !fir.ref<i32> {fir.bindc_name = "p"}) attributes {fir.internal_name = "_QPfoo"} {
%c5_i32 = arith.constant 5 : i32
%c6_i32 = arith.constant 6 : i32

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s -o - | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func @foo(%arg0: !fir.ref<!fir.char<1,?>> {fir.bindc_name = "str1"} , %arg1: !fir.ref<i64> {fir.bindc_name = "len1"} loc("/home/haqadeer/work/fortran/t1/../str.f90":1:1), %arg2: i64) {
%0 = fir.emboxchar %arg0, %arg2 : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
%c4_i32 = arith.constant 4 : i32

View File

@ -1,6 +1,6 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
module {
func.func private @foo1(%arg0: !fir.vector<20:bf16>)
// CHECK-DAG: #[[F16:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 16, encoding = DW_ATE_float>
// CHECK-DAG: #llvm.di_composite_type<tag = DW_TAG_array_type, name = "vector real (20)", baseType = #[[F16]], flags = Vector, sizeInBits = 320, elements = #llvm.di_subrange<count = 20 : i64>>