[flang-commits] [flang] flang][debug] Run AddDebugInfo before TargetRewrite. (PR #114418)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Nov 4 06:03:29 PST 2024


https://github.com/abidh updated https://github.com/llvm/llvm-project/pull/114418

>From 0fba70e8a4c1d619e74116be891bd9129379a0de Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Wed, 30 Oct 2024 18:02:42 +0000
Subject: [PATCH 1/3] [flang][debug] Run AddDebugInfo before TargetRewrite.

This help us generate debug info that better represents the actual
Fortran source code.

Fixes #108711.
---
 flang/lib/Optimizer/Passes/Pipelines.cpp       | 2 +-
 flang/test/Driver/mlir-debug-pass-pipeline.f90 | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 3c139f7e93405c..113225df991364 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -264,10 +264,10 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
   addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt);
   fir::addCodeGenRewritePass(
       pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
+  fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
   fir::addTargetRewritePass(pm);
   fir::addCompilerGeneratedNamesConversionPass(pm);
   fir::addExternalNameConversionPass(pm, config.Underscoring);
-  fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
 
   if (config.VScaleMin != 0)
     pm.addPass(fir::createVScaleAttr({{config.VScaleMin, config.VScaleMax}}));
diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index e44f4e62a7148b..277f4795670a58 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -111,10 +111,10 @@
 
 ! ALL-NEXT: CodeGenRewrite
 ! ALL-NEXT:   (S) 0 num-dce'd - Number of operations eliminated
+! DEBUG-NEXT: AddDebugInfo
+! NO-DEBUG-NOT: AddDebugInfo
 ! ALL-NEXT: TargetRewrite
 ! ALL-NEXT: CompilerGeneratedNamesConversion
 ! ALL-NEXT: ExternalNameConversion
-! DEBUG-NEXT: AddDebugInfo
-! NO-DEBUG-NOT: AddDebugInfo
 ! ALL: FIRToLLVMLowering
 ! ALL-NOT: LLVMIRLoweringPass

>From 017a8956014fd479a949ba380e6523b1e9cdd4cd Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Thu, 31 Oct 2024 15:40:12 +0000
Subject: [PATCH 2/3] Add test.

---
 flang/test/Integration/debug-complex-2.f90 | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 flang/test/Integration/debug-complex-2.f90

diff --git a/flang/test/Integration/debug-complex-2.f90 b/flang/test/Integration/debug-complex-2.f90
new file mode 100644
index 00000000000000..c5f46d7b270b64
--- /dev/null
+++ b/flang/test/Integration/debug-complex-2.f90
@@ -0,0 +1,12 @@
+! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck  %s
+
+! Test that complex return type is correctly represented in debug.
+complex function fn(a)
+    complex, intent(in) :: a
+    fn = a
+end function
+
+! CHECK-DAG: ![[CMPLX:.*]] = !DIBasicType(name: "complex", size: 64, encoding: DW_ATE_complex_float)
+! CHECK-DAG: ![[SR_TY:.*]] = !DISubroutineType(cc: DW_CC_normal, types: ![[TYPES:.*]])
+! CHECK-DAG: ![[TYPES]] = !{![[CMPLX]], ![[CMPLX]]}
+! CHECK-DAG: !DISubprogram(name: "fn"{{.*}}type: ![[SR_TY]]{{.*}})

>From a1d78e4b73e7237182c065bf5da9ab448fe0b923 Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Mon, 4 Nov 2024 13:41:54 +0000
Subject: [PATCH 3/3] Run ExternalNameConversion pass before AddDebugInfo.

This helps us generate the correct linkage name.
---
 flang/lib/Optimizer/Passes/Pipelines.cpp               |  2 +-
 flang/test/Driver/mlir-debug-pass-pipeline.f90         |  2 +-
 flang/test/Driver/mlir-pass-pipeline.f90               |  2 +-
 flang/test/Integration/debug-external-linkage-name.f90 | 10 ++++++++++
 4 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Integration/debug-external-linkage-name.f90

diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 113225df991364..a9144079915912 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -264,10 +264,10 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
   addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt);
   fir::addCodeGenRewritePass(
       pm, (config.DebugInfo != llvm::codegenoptions::NoDebugInfo));
+  fir::addExternalNameConversionPass(pm, config.Underscoring);
   fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
   fir::addTargetRewritePass(pm);
   fir::addCompilerGeneratedNamesConversionPass(pm);
-  fir::addExternalNameConversionPass(pm, config.Underscoring);
 
   if (config.VScaleMin != 0)
     pm.addPass(fir::createVScaleAttr({{config.VScaleMin, config.VScaleMax}}));
diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index 277f4795670a58..ab5ddedf5fc180 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -111,10 +111,10 @@
 
 ! ALL-NEXT: CodeGenRewrite
 ! ALL-NEXT:   (S) 0 num-dce'd - Number of operations eliminated
+! ALL-NEXT: ExternalNameConversion
 ! DEBUG-NEXT: AddDebugInfo
 ! NO-DEBUG-NOT: AddDebugInfo
 ! ALL-NEXT: TargetRewrite
 ! ALL-NEXT: CompilerGeneratedNamesConversion
-! ALL-NEXT: ExternalNameConversion
 ! ALL: FIRToLLVMLowering
 ! ALL-NOT: LLVMIRLoweringPass
diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index 6c2829d3cc5c57..7d57135c5fee37 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -120,8 +120,8 @@
 
 ! ALL-NEXT: CodeGenRewrite
 ! ALL-NEXT:   (S) 0 num-dce'd - Number of operations eliminated
+! ALL-NEXT: ExternalNameConversion
 ! ALL-NEXT: TargetRewrite
 ! ALL-NEXT: CompilerGeneratedNamesConversion
-! ALL-NEXT: ExternalNameConversion
 ! ALL-NEXT: FIRToLLVMLowering
 ! ALL-NOT: LLVMIRLoweringPass
diff --git a/flang/test/Integration/debug-external-linkage-name.f90 b/flang/test/Integration/debug-external-linkage-name.f90
new file mode 100644
index 00000000000000..c7fdf846b7dd3a
--- /dev/null
+++ b/flang/test/Integration/debug-external-linkage-name.f90
@@ -0,0 +1,10 @@
+! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck  %s
+
+! Test that correct linkage name is generated in the debug info.
+subroutine sub(a)
+  integer :: a
+  return a+1
+end
+
+!CHECK: !DISubprogram(name: "sub", linkageName: "sub_"{{.*}})
+



More information about the flang-commits mailing list