<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp, branch users/mingmingl-llvm/spr/sdpglobalvariable</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[flang][debug] Improve check for global variable detection. (#118326)</title>
<updated>2025-02-04T13:17:14+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2025-02-04T13:17:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=7ece824b6fa943bf20162d8d653d6e5cd0722a6e'/>
<id>7ece824b6fa943bf20162d8d653d6e5cd0722a6e</id>
<content type='text'>
When a global variable is used in the OpenMP target region, it is passed
as an argument to the function that implements target region. But the
`DeclareOp` for this incarnation still have the original name of the
variable. As some of our checks to decide if a variable is global or nor
are based on the name, this can result in a local variable being treated
as global. This PR hardens the check a bit. We now also check that
memory ref is actually an `AddrOfOp` before looking at the name.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When a global variable is used in the OpenMP target region, it is passed
as an argument to the function that implements target region. But the
`DeclareOp` for this incarnation still have the original name of the
variable. As some of our checks to decide if a variable is global or nor
are based on the name, this can result in a local variable being treated
as global. This PR hardens the check a bit. We now also check that
memory ref is actually an `AddrOfOp` before looking at the name.</pre>
</div>
</content>
</entry>
<entry>
<title>[Flang][MLIR] Extend DataLayout utilities to have basic GPU Module support (#123149)</title>
<updated>2025-01-30T16:31:50+00:00</updated>
<author>
<name>agozillon</name>
<email>Andrew.Gozillon@amd.com</email>
</author>
<published>2025-01-30T16:31:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=4186805060bb06dc3362707d45e6f0f826208a8f'/>
<id>4186805060bb06dc3362707d45e6f0f826208a8f</id>
<content type='text'>
As there is now certain areas where we now have the possibility of
having either a ModuleOp or GPUModuleOp and both of these modules can
have DataLayout's and we may require utilising the DataLayout utilities
in these areas I've taken the liberty of trying to extend them for use
with both.

Those with more knowledge of how they wish the GPUModuleOp's to interact
with their parent ModuleOp's DataLayout may have further alterations
they wish to make in the future, but for the moment, it'll simply
utilise the basic data layout construction which I believe combines
parent and child datalayouts from the ModuleOp and GPUModuleOp. If there
is no GPUModuleOp DataLayout it should default to the parent ModuleOp.

It's worth noting there is some weirdness if you have two module
operations defining builtin dialect DataLayout Entries, it appears the
combinatorial functionality for DataLayouts doesn't support the merging
of these.

This behaviour is useful for areas like:
https://github.com/llvm/llvm-project/pull/119585/files#diff-19fc4bcb38829d085e25d601d344bbd85bf7ef749ca359e348f4a7c750eae89dR1412
where we have a crossroads between the two different module operations.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As there is now certain areas where we now have the possibility of
having either a ModuleOp or GPUModuleOp and both of these modules can
have DataLayout's and we may require utilising the DataLayout utilities
in these areas I've taken the liberty of trying to extend them for use
with both.

Those with more knowledge of how they wish the GPUModuleOp's to interact
with their parent ModuleOp's DataLayout may have further alterations
they wish to make in the future, but for the moment, it'll simply
utilise the basic data layout construction which I believe combines
parent and child datalayouts from the ModuleOp and GPUModuleOp. If there
is no GPUModuleOp DataLayout it should default to the parent ModuleOp.

It's worth noting there is some weirdness if you have two module
operations defining builtin dialect DataLayout Entries, it appears the
combinatorial functionality for DataLayouts doesn't support the merging
of these.

This behaviour is useful for areas like:
https://github.com/llvm/llvm-project/pull/119585/files#diff-19fc4bcb38829d085e25d601d344bbd85bf7ef749ca359e348f4a7c750eae89dR1412
where we have a crossroads between the two different module operations.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Add support for common blocks. (#112398)</title>
<updated>2025-01-28T12:54:15+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2025-01-28T12:54:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=afa4681ce443e88a5f196b808300fe3c133e96fd'/>
<id>afa4681ce443e88a5f196b808300fe3c133e96fd</id>
<content type='text'>
This PR adds debug support for common block in flang. As variable which
are part of a common block don't have a special marker to recognize
them, we use the following check to find them.

%0 = fir.address_of(@a)
%1 = fir.convert %0
%2 = fir.coordinate_of %1, %c0
%3 = fir.convert %2
%4 = fircg.ext_declare %3

If the memref of a fircg.ext_declare points to a fir.coordinate_of and
that in turn points to an fir.address_of (ignoring immediate
fir.convert) then we assume that it is a common block variable. The
fir.address_of gives us the global symbol which is the storage for
common block and fir.coordinate_of provides the offset in this storage.

The debug hierarchy looks like as

subroutine f3
  integer :: x, y
  common /a/ x, y
end subroutine

@a_ = global { ... } { ... }, !dbg !26, !dbg !28

!23 = !DISubprogram(name: "f3"...)
!24 = !DICommonBlock(scope: !23, name: "a", ...)
!25 = !DIGlobalVariable(name: "x", scope: !24 ...)
!26 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!27 = !DIGlobalVariable(name: "y", scope: !24 ...)
!28 = !DIGlobalVariableExpression(var: !27, expr:
!DIExpression(DW_OP_plus_uconst, 4))

This required following changes:

1. Instead of using DIGlobalVariableAttr in the FusedLoc of GlobalOp, we
use DIGlobalVariableExpressionAttr. This allows us the generate the
DIExpression where we have the information.

2. Previously, only one DIGlobalVariableExpressionAttr could be linked
to one global op. I recently removed this restriction in mlir. To make
use of it, we add an ArrayAttr to the FusedLoc of a GlobalOp. This
allows us to pass multiple DIGlobalVariableExpressionAttr.

3. I was depending on the name of global for the name of the common
block. The name gets a '_' appended. I could not find a utility function
in flang to remove it so I have to brute force it.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This PR adds debug support for common block in flang. As variable which
are part of a common block don't have a special marker to recognize
them, we use the following check to find them.

%0 = fir.address_of(@a)
%1 = fir.convert %0
%2 = fir.coordinate_of %1, %c0
%3 = fir.convert %2
%4 = fircg.ext_declare %3

If the memref of a fircg.ext_declare points to a fir.coordinate_of and
that in turn points to an fir.address_of (ignoring immediate
fir.convert) then we assume that it is a common block variable. The
fir.address_of gives us the global symbol which is the storage for
common block and fir.coordinate_of provides the offset in this storage.

The debug hierarchy looks like as

subroutine f3
  integer :: x, y
  common /a/ x, y
end subroutine

@a_ = global { ... } { ... }, !dbg !26, !dbg !28

!23 = !DISubprogram(name: "f3"...)
!24 = !DICommonBlock(scope: !23, name: "a", ...)
!25 = !DIGlobalVariable(name: "x", scope: !24 ...)
!26 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression())
!27 = !DIGlobalVariable(name: "y", scope: !24 ...)
!28 = !DIGlobalVariableExpression(var: !27, expr:
!DIExpression(DW_OP_plus_uconst, 4))

This required following changes:

1. Instead of using DIGlobalVariableAttr in the FusedLoc of GlobalOp, we
use DIGlobalVariableExpressionAttr. This allows us the generate the
DIExpression where we have the information.

2. Previously, only one DIGlobalVariableExpressionAttr could be linked
to one global op. I recently removed this restriction in mlir. To make
use of it, we add an ArrayAttr to the FusedLoc of a GlobalOp. This
allows us to pass multiple DIGlobalVariableExpressionAttr.

3. I was depending on the name of global for the name of the common
block. The name gets a '_' appended. I could not find a utility function
in flang to remove it so I have to brute force it.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Fix issue with argument numbering. (#120726)</title>
<updated>2025-01-03T19:41:48+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2025-01-03T19:41:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f7420a9dff6d09715042b60c9e26a40a1b2a3147'/>
<id>f7420a9dff6d09715042b60c9e26a40a1b2a3147</id>
<content type='text'>
Currently fir::isDummyArgument is being used to check if a DeclareOp
represents a dummy argument. The argument passed to the function is
declOp.getMemref(). This bypasses the code in isDummyArgument that
checks for dummy_scope because the `Value` returned by the getMemref()
may not have DeclareOp as its defining op.

This bypassing mean that sometime a variable will be marked as argument
when it should not. This happened in this case where same arg was being
used for 2 different result variables with use of `entry` in the
function.

The solution is to check directly if the declOp has a dummy_scope. If
yes, we know this is dummy argument. We can now check if the memref
points to the BlockArgument and use its number. This will still miss
arguments where memref does not directly point to a BlockArgument but
that is missed currently too. Note that we can still evaluate those
variable in debugger. It is just that they are not marked as arguments.

Fixes #116525.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently fir::isDummyArgument is being used to check if a DeclareOp
represents a dummy argument. The argument passed to the function is
declOp.getMemref(). This bypasses the code in isDummyArgument that
checks for dummy_scope because the `Value` returned by the getMemref()
may not have DeclareOp as its defining op.

This bypassing mean that sometime a variable will be marked as argument
when it should not. This happened in this case where same arg was being
used for 2 different result variables with use of `entry` in the
function.

The solution is to check directly if the declOp has a dummy_scope. If
yes, we know this is dummy argument. We can now check if the memref
points to the BlockArgument and use its number. This will still miss
arguments where memref does not directly point to a BlockArgument but
that is missed currently too. Note that we can still evaluate those
variable in debugger. It is just that they are not marked as arguments.

Fixes #116525.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Don't generate debug for compiler-generated variables (#112423)</title>
<updated>2024-10-21T10:27:34+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2024-10-21T10:27:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=95b4128c6a87e9b894aa75524e63be147cca790b'/>
<id>95b4128c6a87e9b894aa75524e63be147cca790b</id>
<content type='text'>
Flang generates many globals to handle derived types. There was a check
in debug info to filter them based on the information that their names
start with a period. This changed since PR#104859 where 'X' is being
used instead of '.'.

This PR fixes this issue by also adding 'X' in that list. As user
variables gets lower cased by the NameUniquer, there is no risk that
those will be filtered out. I added a test for that to be sure.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Flang generates many globals to handle derived types. There was a check
in debug info to filter them based on the information that their names
start with a period. This changed since PR#104859 where 'X' is being
used instead of '.'.

This PR fixes this issue by also adding 'X' in that list. As user
variables gets lower cased by the NameUniquer, there is no risk that
those will be filtered out. I added a test for that to be sure.</pre>
</div>
</content>
</entry>
<entry>
<title>[mlir][debuginfo] Add support for subprogram annotations (#110946)</title>
<updated>2024-10-07T21:51:08+00:00</updated>
<author>
<name>Walter Erquinigo</name>
<email>a20012251@gmail.com</email>
</author>
<published>2024-10-07T21:51:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=2918e779a9545a66c0031b03b3af5bf4d8517cec'/>
<id>2918e779a9545a66c0031b03b3af5bf4d8517cec</id>
<content type='text'>
LLVM already supports `DW_TAG_LLVM_annotation` entries for subprograms,
but this hasn't been surfaced to the LLVM dialect.
I'm doing the minimal amount of work to support string-based
annotations, which is useful for attaching metadata to
functions, which is useful for debuggers to offer features beyond basic
DWARF.
As LLVM already supports this, this patch is not controversial.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
LLVM already supports `DW_TAG_LLVM_annotation` entries for subprograms,
but this hasn't been surfaced to the LLVM dialect.
I'm doing the minimal amount of work to support string-based
annotations, which is useful for attaching metadata to
functions, which is useful for debuggers to offer features beyond basic
DWARF.
As LLVM already supports this, this patch is not controversial.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] set DW_AT_main_subprogram for fortran main function (#111350)</title>
<updated>2024-10-07T12:59:41+00:00</updated>
<author>
<name>Tom Eccles</name>
<email>tom.eccles@arm.com</email>
</author>
<published>2024-10-07T12:59:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=91d6e77d8b4ad6dbbbfa5b6788f44d3ab6757707'/>
<id>91d6e77d8b4ad6dbbbfa5b6788f44d3ab6757707</id>
<content type='text'>
Requested here
https://github.com/llvm/llvm-project/pull/111022#issuecomment-2396287781</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Requested here
https://github.com/llvm/llvm-project/pull/111022#issuecomment-2396287781</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Use PROGRAM name for main function name (#111022)</title>
<updated>2024-10-04T09:46:58+00:00</updated>
<author>
<name>Tom Eccles</name>
<email>tom.eccles@arm.com</email>
</author>
<published>2024-10-04T09:46:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=f6f4c177ef03ecd027d884af2cd3caf3ccafcfd1'/>
<id>f6f4c177ef03ecd027d884af2cd3caf3ccafcfd1</id>
<content type='text'>
For example, in

        PROGRAM test_program
          ...
        END PROGRAM

This allows a user to break on the main function with `break
test_program`. This matches what classic flang and gfortran do.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For example, in

        PROGRAM test_program
          ...
        END PROGRAM

This allows a user to break on the main function with `break
test_program`. This matches what classic flang and gfortran do.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Generate correct subroutine type. (#108605)</title>
<updated>2024-09-17T10:07:23+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2024-09-17T10:07:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b6f72fc1e202c749333bd5b8ecb879d661af16b6'/>
<id>b6f72fc1e202c749333bd5b8ecb879d661af16b6</id>
<content type='text'>
We pass a list of types when creating a subroutine type. The first one
is supposed to be return type and the rest are the argument types. A
subroutine does not have a return type so an argument type could be
confused as a return type. To fix this, if there is no return type, we
generate a null type as a place holder.

Fixes #108564.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We pass a list of types when creating a subroutine type. The first one
is supposed to be return type and the rest are the argument types. A
subroutine does not have a return type so an argument type could be
confused as a return type. To fix this, if there is no return type, we
generate a null type as a place holder.

Fixes #108564.</pre>
</div>
</content>
</entry>
<entry>
<title>[flang][debug] Handle 'used' module. (#107626)</title>
<updated>2024-09-11T08:31:53+00:00</updated>
<author>
<name>Abid Qadeer</name>
<email>haqadeer@amd.com</email>
</author>
<published>2024-09-11T08:31:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=db64e69fa250ea3a8d7a761220a7922fbdad0f2c'/>
<id>db64e69fa250ea3a8d7a761220a7922fbdad0f2c</id>
<content type='text'>
As described in #98883, we have to qualify a module variable name in
debugger to get its value. This PR tries to remove this limitation.
    
LLVM provides `DIImportedEntity` to handle such cases but the PR is made
more complicated due to the following 2 issues.
    
1. The MLIR attributes are readonly and we have a circular dependency
here. This has to be handled using the recursive interface provided by
the MLIR. This requires us to first create a place holder
`DISubprogramAttr` which is used in creating `DIImportedEntityAttr`.
Later another `DISubprogramAttr` is created which replaces the place
holder.
    
2. The flang IR does not provide any information about the 'used' module
so this has to be extracted by doing a pass over the
`DeclareOp` in the function. This presents certain limitation as 'only'
and module variable renaming may not be handled properly.
    
Due to the change in `DISubprogramAttr`, some tests also needed to be
adjusted.
    
Fixes #98883.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As described in #98883, we have to qualify a module variable name in
debugger to get its value. This PR tries to remove this limitation.
    
LLVM provides `DIImportedEntity` to handle such cases but the PR is made
more complicated due to the following 2 issues.
    
1. The MLIR attributes are readonly and we have a circular dependency
here. This has to be handled using the recursive interface provided by
the MLIR. This requires us to first create a place holder
`DISubprogramAttr` which is used in creating `DIImportedEntityAttr`.
Later another `DISubprogramAttr` is created which replaces the place
holder.
    
2. The flang IR does not provide any information about the 'used' module
so this has to be extracted by doing a pass over the
`DeclareOp` in the function. This presents certain limitation as 'only'
and module variable renaming may not be handled properly.
    
Due to the change in `DISubprogramAttr`, some tests also needed to be
adjusted.
    
Fixes #98883.</pre>
</div>
</content>
</entry>
</feed>
