[flang-commits] [flang] 49dfbd1 - flang][debug] Run AddDebugInfo before TargetRewrite. (#114418)
via flang-commits
flang-commits at lists.llvm.org
Tue Nov 5 03:42:21 PST 2024
Author: Abid Qadeer
Date: 2024-11-05T11:42:18Z
New Revision: 49dfbd13ad846080eb00d71b076549c501f8f240
URL: https://github.com/llvm/llvm-project/commit/49dfbd13ad846080eb00d71b076549c501f8f240
DIFF: https://github.com/llvm/llvm-project/commit/49dfbd13ad846080eb00d71b076549c501f8f240.diff
LOG: flang][debug] Run AddDebugInfo before TargetRewrite. (#114418)
This help us generate debug info that better represents the actual
Fortran source code. It was briefly discussed
[here](https://github.com/llvm/llvm-project/pull/113917#pullrequestreview-2401339038).
Fixes #108711.
Added:
flang/test/Integration/debug-complex-2.f90
flang/test/Integration/debug-external-linkage-name.f90
Modified:
flang/lib/Optimizer/Passes/Pipelines.cpp
flang/test/Driver/mlir-debug-pass-pipeline.f90
flang/test/Driver/mlir-pass-pipeline.f90
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 3c139f7e93405c..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::addTargetRewritePass(pm);
- fir::addCompilerGeneratedNamesConversionPass(pm);
fir::addExternalNameConversionPass(pm, config.Underscoring);
fir::createDebugPasses(pm, config.DebugInfo, config.OptLevel, inputFilename);
+ fir::addTargetRewritePass(pm);
+ fir::addCompilerGeneratedNamesConversionPass(pm);
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..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: TargetRewrite
-! ALL-NEXT: CompilerGeneratedNamesConversion
! ALL-NEXT: ExternalNameConversion
! DEBUG-NEXT: AddDebugInfo
! NO-DEBUG-NOT: AddDebugInfo
+! ALL-NEXT: TargetRewrite
+! ALL-NEXT: CompilerGeneratedNamesConversion
! 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-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]]{{.*}})
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