-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[flang] Fixed repacking for TARGET and INTENT(OUT) #131972
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 1 commit
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -916,10 +916,7 @@ needDeallocationOrFinalization(const Fortran::lower::pft::Variable &var) { | |
| /// point 7. | ||
| /// Must be nonpointer, nonallocatable, INTENT (OUT) dummy argument. | ||
| static bool | ||
| needDummyIntentoutFinalization(const Fortran::lower::pft::Variable &var) { | ||
| if (!var.hasSymbol()) | ||
| return false; | ||
| const Fortran::semantics::Symbol &sym = var.getSymbol(); | ||
| needDummyIntentoutFinalization(const Fortran::semantics::Symbol &sym) { | ||
| if (!Fortran::semantics::IsDummy(sym) || | ||
| !Fortran::semantics::IsIntentOut(sym) || | ||
| Fortran::semantics::IsAllocatable(sym) || | ||
|
|
@@ -938,6 +935,16 @@ needDummyIntentoutFinalization(const Fortran::lower::pft::Variable &var) { | |
| return hasFinalization(sym) || hasAllocatableDirectComponent(sym); | ||
| } | ||
|
|
||
| /// Check whether a variable needs the be finalized according to clause 7.5.6.3 | ||
| /// point 7. | ||
| /// Must be nonpointer, nonallocatable, INTENT (OUT) dummy argument. | ||
| static bool | ||
| needDummyIntentoutFinalization(const Fortran::lower::pft::Variable &var) { | ||
| if (!var.hasSymbol()) | ||
| return false; | ||
| return needDummyIntentoutFinalization(var.getSymbol()); | ||
| } | ||
|
|
||
| /// Call default initialization runtime routine to initialize \p var. | ||
| static void finalizeAtRuntime(Fortran::lower::AbstractConverter &converter, | ||
| const Fortran::lower::pft::Variable &var, | ||
|
|
@@ -1011,10 +1018,16 @@ static void deallocateIntentOut(Fortran::lower::AbstractConverter &converter, | |
|
|
||
| static bool needsRepack(Fortran::lower::AbstractConverter &converter, | ||
| const Fortran::semantics::Symbol &sym) { | ||
| const auto &attrs = sym.attrs(); | ||
| if (!converter.getLoweringOptions().getRepackArrays() || | ||
| !converter.isRegisteredDummySymbol(sym) || | ||
| !Fortran::semantics::IsAssumedShape(sym) || | ||
| Fortran::evaluate::IsSimplyContiguous(sym, converter.getFoldingContext())) | ||
| Fortran::evaluate::IsSimplyContiguous(sym, | ||
| converter.getFoldingContext()) || | ||
| // TARGET dummy may be accessed indirectly, so it is unsafe | ||
| // to repack it. Some compilers provide options to override | ||
| // this. | ||
| attrs.test(Fortran::semantics::Attr::TARGET)) | ||
|
||
| return false; | ||
|
|
||
| return true; | ||
|
|
@@ -2613,8 +2626,12 @@ Fortran::lower::genPackArray(Fortran::lower::AbstractConverter &converter, | |
| bool stackAlloc = opts.getStackArrays(); | ||
| // 1D arrays must always use 'whole' mode. | ||
| bool isInnermostMode = !opts.getRepackArraysWhole() && sym.Rank() > 1; | ||
| // Avoid copy-in for 'intent(out)' variables. | ||
| bool noCopy = Fortran::semantics::IsIntentOut(sym); | ||
| // Avoid copy-in for 'intent(out)' variable, unless this is a dummy | ||
| // argument with INTENT(OUT) that needs finalization on entry | ||
| // to the subprogram. The finalization routine may read the initial | ||
| // value of the array. | ||
| bool noCopy = Fortran::semantics::IsIntentOut(sym) && | ||
| !needDummyIntentoutFinalization(sym); | ||
| auto boxType = mlir::cast<fir::BaseBoxType>(fir::getBase(exv).getType()); | ||
| mlir::Type elementType = boxType.unwrapInnerType(); | ||
| llvm::SmallVector<mlir::Value> elidedLenParams = | ||
|
|
||
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,31 @@ | ||
| ! RUN: bbc -emit-hlfir -frepack-arrays %s -o - -I nowhere | FileCheck --check-prefixes=CHECK %s | ||
|
|
||
| ! Check that the original array is copied on entry to the subroutine | ||
| ! before it is being finalized, otherwise the finalization routine | ||
| ! may read the uninitialized temporary. | ||
| ! Verify that fir.pack_array does not have no_copy attribute. | ||
|
|
||
| module m | ||
| type t | ||
| contains | ||
| final :: my_final | ||
| end type t | ||
| interface | ||
| subroutine my_final(x) | ||
| type(t) :: x(:) | ||
| end subroutine my_final | ||
| end interface | ||
| contains | ||
| ! CHECK-LABEL: func.func @_QMmPtest( | ||
| ! CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.class<!fir.array<?x!fir.type<_QMmTt>>> {fir.bindc_name = "x"}) { | ||
| subroutine test(x) | ||
| class(t), intent(out) :: x(:) | ||
| ! CHECK: %[[VAL_2:.*]] = fir.pack_array %[[VAL_0]] heap whole : (!fir.class<!fir.array<?x!fir.type<_QMmTt>>>) -> !fir.class<!fir.array<?x!fir.type<_QMmTt>>> | ||
| ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] | ||
| ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]]#1 | ||
| ! CHECK: fir.call @_FortranADestroy(%[[VAL_4]]) fastmath<contract> : (!fir.box<none>) -> () | ||
| ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_3]]#1 | ||
| ! CHECK: fir.call @_FortranAInitialize(%[[VAL_7]] | ||
| ! CHECK: fir.unpack_array %[[VAL_2]] to %[[VAL_0]] heap : !fir.class<!fir.array<?x!fir.type<_QMmTt>>> | ||
| end subroutine test | ||
| end module m |
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,10 @@ | ||
| ! RUN: bbc -emit-hlfir -frepack-arrays %s -o - -I nowhere | FileCheck --check-prefixes=CHECK %s | ||
|
|
||
| ! Check that there is no repacking for TARGET dummy argument. | ||
|
|
||
| ! CHECK-LABEL: func.func @_QPtest( | ||
| ! CHECK-NOT: fir.pack_array | ||
| ! CHECK-NOT: fir.unpack_array | ||
| subroutine test(x) | ||
| integer, target :: x(:) | ||
| end subroutine test |
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.
Uh oh!
There was an error while loading. Please reload this page.