-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Add debug information for module variables. #91582
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eecff7b
[flang] Add initial implementation of module variables.
abidh e87df98
Handled review comments.
abidh be8a2ba
Remove a redundant include file.
abidh e90d49a
Addressed review comments.
abidh e837cab
Process variable only if full debug info is requested.
abidh 94aecb0
Replace 'hasInitializationBody' with 'isInitialized'.
abidh 3487f18
Handle review comments.
abidh 5d5c73c
Fix clang-format issues.
abidh c509126
Handle review comments.
abidh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s | ||
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -o - | FileCheck --check-prefix=LINEONLY %s | ||
|
||
! CHECK-DAG: ![[FILE:.*]] = !DIFile(filename: {{.*}}debug-module-2.f90{{.*}}) | ||
! CHECK-DAG: ![[FILE2:.*]] = !DIFile(filename: {{.*}}debug-module-2.f90{{.*}}) | ||
! CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}file: ![[FILE]]{{.*}} globals: ![[GLOBALS:.*]]) | ||
! CHECK-DAG: ![[MOD:.*]] = !DIModule(scope: ![[CU]], name: "helper", file: ![[FILE]]{{.*}}) | ||
! CHECK-DAG: ![[R4:.*]] = !DIBasicType(name: "real", size: 32, encoding: DW_ATE_float) | ||
! CHECK-DAG: ![[I4:.*]] = !DIBasicType(name: "integer", size: 32, encoding: DW_ATE_signed) | ||
module helper | ||
! CHECK-DAG: ![[GLR:.*]] = distinct !DIGlobalVariable(name: "glr", linkageName: "_QMhelperEglr", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+2]], type: ![[R4]], isLocal: false, isDefinition: true) | ||
! CHECK-DAG: ![[GLRX:.*]] = !DIGlobalVariableExpression(var: ![[GLR]], expr: !DIExpression()) | ||
real glr | ||
|
||
! CHECK-DAG: ![[GLI:.*]] = distinct !DIGlobalVariable(name: "gli", linkageName: "_QMhelperEgli", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+2]], type: ![[I4]], isLocal: false, isDefinition: true) | ||
! CHECK-DAG: ![[GLIX:.*]] = !DIGlobalVariableExpression(var: ![[GLI]], expr: !DIExpression()) | ||
integer gli | ||
|
||
contains | ||
!CHECK-DAG: !DISubprogram(name: "test", linkageName: "_QMhelperPtest", scope: ![[MOD]], file: ![[FILE2]], line: [[@LINE+1]]{{.*}}unit: ![[CU]]) | ||
subroutine test() | ||
glr = 12.34 | ||
gli = 67 | ||
|
||
end subroutine | ||
end module helper | ||
|
||
program test | ||
use helper | ||
implicit none | ||
|
||
glr = 3.14 | ||
gli = 2 | ||
call test() | ||
|
||
end program test | ||
|
||
! CHECK-DAG: ![[GLOBALS]] = !{![[GLIX]], ![[GLRX]]} | ||
! LINEONLY-NOT: DIGlobalVariable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s | ||
|
||
|
||
module attributes {} { | ||
fir.global @_QMhelperEgli : i32 { | ||
%0 = fir.zero_bits i32 | ||
fir.has_value %0 : i32 | ||
} loc(#loc1) | ||
fir.global @_QMhelperEglr : f32 { | ||
%0 = fir.zero_bits f32 | ||
fir.has_value %0 : f32 | ||
} loc(#loc2) | ||
func.func @_QMhelperPtest() { | ||
%c67_i32 = arith.constant 67 : i32 | ||
%cst = arith.constant 1.234000e+01 : f32 | ||
%0 = fir.address_of(@_QMhelperEgli) : !fir.ref<i32> | ||
%1 = fir.address_of(@_QMhelperEglr) : !fir.ref<f32> | ||
fir.store %cst to %1 : !fir.ref<f32> | ||
fir.store %c67_i32 to %0 : !fir.ref<i32> | ||
return | ||
} loc(#loc3) | ||
} | ||
#loc1 = loc("test.f90":12:11) | ||
#loc2 = loc("test.f90":15:8) | ||
#loc3 = loc("test.f90":20:5) | ||
|
||
// CHECK-DAG: #[[I4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed> | ||
// CHECK-DAG: #[[R4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float> | ||
// CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<{{.*}}> | ||
// CHECK-DAG: #[[MOD:.*]] = #llvm.di_module<{{.*}}scope = #[[CU]], name = "helper"{{.*}}> | ||
// CHECK-DAG: #[[LOC1:.*]] = loc("{{.*}}test.f90":12{{.*}}) | ||
// CHECK-DAG: #[[GLI:.*]] = #llvm.di_global_variable<scope = #[[MOD]], name = "gli", linkageName = "_QMhelperEgli"{{.*}}line = 12, type = #[[I4]], isDefined = true> | ||
// CHECK-DAG: #[[LOC2:.*]] = loc("{{.*}}test.f90":15{{.*}}) | ||
// CHECK-DAG: #[[GLR:.*]] = #llvm.di_global_variable<scope = #[[MOD]], name = "glr", linkageName = "_QMhelperEglr"{{.*}}line = 15, type = #[[R4]], isDefined = true> | ||
// CHECK-DAG: #[[LOC3:.*]] = loc("{{.*}}test.f90":20{{.*}}) | ||
// CHECK-DAG: #[[TEST:.*]] = #llvm.di_subprogram<{{.*}}compileUnit = #[[CU]], scope = #[[MOD]], name = "test", linkageName = "_QMhelperPtest"{{.*}}line = 20, scopeLine = 20{{.*}}> | ||
// CHECK-DAG: loc(fused<#[[GLI]]>[#[[LOC1]]]) | ||
// CHECK-DAG: loc(fused<#[[GLR]]>[#[[LOC2]]]) | ||
// CHECK-DAG: loc(fused<#[[TEST]]>[#[[LOC3]]]) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" --mlir-print-debuginfo %s | FileCheck %s | ||
|
||
module { | ||
fir.global @_QMhelperEgli : i32 { | ||
%0 = fir.zero_bits i32 | ||
fir.has_value %0 : i32 | ||
} loc(#loc3) | ||
fir.global @_QMhelperEglr : f32 { | ||
%0 = fir.zero_bits f32 | ||
fir.has_value %0 : f32 | ||
} loc(#loc4) | ||
} | ||
#di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 32, encoding = DW_ATE_signed> | ||
#di_basic_type1 = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float> | ||
|
||
#di_file = #llvm.di_file<"test.f90" in ""> | ||
#di_subroutine_type = #llvm.di_subroutine_type<callingConvention = DW_CC_normal> | ||
|
||
#di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang version 19.0.0 (/home/haqadeer/work/llvm-project/flang 5d5c73cad421bdca6e43e1cc10704ff160f1a33e)", isOptimized = false, emissionKind = Full> | ||
#di_module = #llvm.di_module<file = #di_file, scope = #di_compile_unit, name = "helper", line = 11> | ||
#di_global_variable = #llvm.di_global_variable<scope = #di_module, name = "gli", linkageName = "_QMhelperEgli", file = #di_file, line = 12, type = #di_basic_type, isDefined = true> | ||
#di_global_variable1 = #llvm.di_global_variable<scope = #di_module, name = "glr", linkageName = "_QMhelperEglr", file = #di_file, line = 15, type = #di_basic_type1, isDefined = true> | ||
|
||
#loc1 = loc("test.f90":12:11) | ||
#loc2 = loc("test.f90":15:8) | ||
#loc3 = loc(fused<#di_global_variable>[#loc1]) | ||
#loc4 = loc(fused<#di_global_variable1>[#loc2]) | ||
|
||
|
||
// CHECK-DAG: #[[GLI:.*]] = #llvm.di_global_variable<{{.*}}name = "gli", linkageName = "_QMhelperEgli"{{.*}}> | ||
// CHECK-DAG: #[[GLR:.*]] = #llvm.di_global_variable<{{.*}}name = "glr", linkageName = "_QMhelperEglr"{{.*}}> | ||
// CHECK-DAG: #[[GLIE:.*]] = #llvm.di_global_variable_expression<var = #[[GLI]]> | ||
// CHECK-DAG: #[[GLRE:.*]] = #llvm.di_global_variable_expression<var = #[[GLR]]> | ||
// CHECK-DAG: llvm.mlir.global{{.*}}@_QMhelperEgli() {{{.*}}dbg_expr = #[[GLIE]]} | ||
// CHECK-DAG: llvm.mlir.global{{.*}}@_QMhelperEglr() {{{.*}}dbg_expr = #[[GLRE]]} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this mean that if a module variable or subroutine is not used we will not have the information that the module is used via a USE statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In debugger, one should be able to evaluate module variables using module::var syntax even in functions where the module is not used (using
use
keyword). For functions where it is used, evaluation without module:: should work too (once we have implemented the imported module functionality).I also tried multi file examples where module is defined in one file and used in others. In such cases, compilers (e.g. gfortran, classic flang) generate a module entry in both the compile units. To differentiate, they set decl attribute to true in files where it is just used. I have tried to follow the similar approach. I found that GlobalOp::hasInitializationBody() gave me this information. It was true in compile unit where the module was actually defined and false where it was just used.