-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] handle fir.call in AliasAnalysis::getModRef #117164
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
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ add_flang_library(FIRAnalysis | |
|
||
DEPENDS | ||
FIRDialect | ||
FIRSupport | ||
HLFIRDialect | ||
MLIRIR | ||
MLIROpenMPDialect | ||
|
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,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Add attributes hook in an HLFIR code to test fir.call ModRef effects | ||
with the test-fir-alias-analysis-modref pass. | ||
|
||
This will insert mod ref test hook: | ||
- to any fir.call to a function which name starts with "test_effect_" | ||
- to any hlfir.declare for variable which name starts with "test_var_" | ||
""" | ||
|
||
import sys | ||
import re | ||
|
||
for line in sys.stdin: | ||
line = re.sub( | ||
r"(fir.call @_\w*P)(test_effect_\w*)(\(.*) : ", | ||
r'\1\2\3 {test.ptr ="\2"} : ', | ||
line, | ||
) | ||
line = re.sub( | ||
r'(hlfir.declare .*uniq_name =.*E)(test_var_\w*)"', | ||
r'\1\2", test.ptr ="\2"', | ||
line, | ||
) | ||
sys.stdout.write(line) |
45 changes: 45 additions & 0 deletions
45
flang/test/Analysis/AliasAnalysis/modref-call-after-inlining.fir
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,45 @@ | ||
// RUN: fir-opt -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis-modref))' \ | ||
// RUN: --mlir-disable-threading %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
// Test fir.call modref with internal procedures after the host function has been inlined in | ||
// some other function. This checks that the last hlfir.declare "internal_assoc" flags that | ||
// marks a variable that was captured is still considered even though there is no such flags | ||
// on the declare at the top of the chain. | ||
// | ||
// In other words, in the following Fortran example, "x" should be considered | ||
// modified by "call internal_proc" after "call inline_me" was inlined into | ||
// "test". | ||
// | ||
// subroutine test() | ||
// real :: x(10) | ||
// call inline_me(x) | ||
// end subroutine | ||
// | ||
// subroutine inline_me(x) | ||
// real :: x(10) | ||
// call internal_proc() | ||
// contains | ||
// subroutine internal_proc() | ||
// call some_external(x) | ||
// end subroutine | ||
// end subroutine | ||
|
||
func.func @_QPtest() { | ||
%c0_i32 = arith.constant 0 : i32 | ||
%c10 = arith.constant 10 : index | ||
%0 = fir.alloca !fir.array<10xf32> {bindc_name = "x", uniq_name = "_QFtestEx"} | ||
%1 = fir.shape %c10 : (index) -> !fir.shape<1> | ||
%2:2 = hlfir.declare %0(%1) {uniq_name = "_QFtestEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>) | ||
%3 = fir.dummy_scope : !fir.dscope | ||
%4:2 = hlfir.declare %2#1(%1) dummy_scope %3 {test.ptr = "x", fortran_attrs = #fir.var_attrs<internal_assoc>, uniq_name = "_QFinline_meEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>) | ||
%5 = fir.alloca tuple<!fir.box<!fir.array<10xf32>>> | ||
%6 = fir.coordinate_of %5, %c0_i32 : (!fir.ref<tuple<!fir.box<!fir.array<10xf32>>>>, i32) -> !fir.ref<!fir.box<!fir.array<10xf32>>> | ||
%7 = fir.embox %4#1(%1) : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<10xf32>> | ||
fir.store %7 to %6 : !fir.ref<!fir.box<!fir.array<10xf32>>> | ||
fir.call @_QFinline_mePinternal_proc(%5) {test.ptr="internal_proc"} : (!fir.ref<tuple<!fir.box<!fir.array<10xf32>>>>) -> () | ||
return | ||
} | ||
func.func private @_QFinline_mePinternal_proc(!fir.ref<tuple<!fir.box<!fir.array<10xf32>>>> {fir.host_assoc}) attributes {fir.host_symbol = @_QPinline_me} | ||
|
||
// CHECK-LABEL: Testing : "_QPtest" | ||
// CHECK: internal_proc -> x#0: ModRef |
Oops, something went wrong.
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.
I believe lookups in an
mlir::SymbolTable
are constant time. Constructing a SymbolTable is linear, but perhaps one could be re-used from a calling context. Orfir::AliasAnalysis
could have aLazySymbolTable
(AbstractResult.cpp
).It is fine by me to leave this as a TODO in this PR and only attempt this if the optimization turns out to be useful on some real code.
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.
Makes some sense to me. The only limitation I see here is that any changes to the ModuleOp symbols (name change/new functions) would not propagate to it, so fir::AliasAnalysis users would have to ensure they do not modify symbols during the lifetime of the AliasAnalysis object (or to somehow update the symbol table too).
I am planning to chase the moduleOp lookups at some point and try to think of a way to keep and maintain symbol tables in the pipeline.
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.
That sounds great!