[flang-commits] [flang] [flang][hlfir] Extend InlineHLFIRCopy to inline copy_out with copy-back (PR #179096)
via flang-commits
flang-commits at lists.llvm.org
Sun Feb 1 02:23:19 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- flang/lib/Optimizer/Passes/Pipelines.cpp flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp
index ab3944fcd..ddb489fa1 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/InlineHLFIRCopy.cpp
@@ -54,36 +54,34 @@ static void inlineCopyOut(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value tempBox, mlir::Value wasCopied,
mlir::Value copyBackDest, mlir::Value shape,
mlir::Type sequenceType) {
- builder.genIfOp(loc, {}, wasCopied, /*withElseRegion=*/false)
- .genThen([&]() {
- mlir::Value box = fir::LoadOp::create(builder, loc, tempBox);
-
- // If we need to copy back, generate the copy loop
- if (copyBackDest) {
- hlfir::Entity temp{box};
- hlfir::Entity dest{copyBackDest};
- llvm::SmallVector<mlir::Value> extents =
- hlfir::getIndexExtents(loc, builder, shape);
- hlfir::LoopNest loopNest =
- hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true,
- /*workshare=*/false, /*couldVectorize=*/false);
- builder.setInsertionPointToStart(loopNest.body);
- hlfir::Entity tempElem = hlfir::getElementAt(
- loc, builder, temp, loopNest.oneBasedIndices);
- tempElem = hlfir::loadTrivialScalar(loc, builder, tempElem);
- hlfir::Entity destElem = hlfir::getElementAt(
- loc, builder, dest, loopNest.oneBasedIndices);
- hlfir::AssignOp::create(builder, loc, tempElem, destElem);
- builder.setInsertionPointAfter(loopNest.outerOp);
- }
-
- // Free the temporary
- mlir::Value addr = fir::BoxAddrOp::create(builder, loc, box);
- auto heapType = fir::HeapType::get(sequenceType);
- mlir::Value heapAddr =
- fir::ConvertOp::create(builder, loc, heapType, addr);
- fir::FreeMemOp::create(builder, loc, heapAddr);
- });
+ builder.genIfOp(loc, {}, wasCopied, /*withElseRegion=*/false).genThen([&]() {
+ mlir::Value box = fir::LoadOp::create(builder, loc, tempBox);
+
+ // If we need to copy back, generate the copy loop
+ if (copyBackDest) {
+ hlfir::Entity temp{box};
+ hlfir::Entity dest{copyBackDest};
+ llvm::SmallVector<mlir::Value> extents =
+ hlfir::getIndexExtents(loc, builder, shape);
+ hlfir::LoopNest loopNest =
+ hlfir::genLoopNest(loc, builder, extents, /*isUnordered=*/true,
+ /*workshare=*/false, /*couldVectorize=*/false);
+ builder.setInsertionPointToStart(loopNest.body);
+ hlfir::Entity tempElem =
+ hlfir::getElementAt(loc, builder, temp, loopNest.oneBasedIndices);
+ tempElem = hlfir::loadTrivialScalar(loc, builder, tempElem);
+ hlfir::Entity destElem =
+ hlfir::getElementAt(loc, builder, dest, loopNest.oneBasedIndices);
+ hlfir::AssignOp::create(builder, loc, tempElem, destElem);
+ builder.setInsertionPointAfter(loopNest.outerOp);
+ }
+
+ // Free the temporary
+ mlir::Value addr = fir::BoxAddrOp::create(builder, loc, box);
+ auto heapType = fir::HeapType::get(sequenceType);
+ mlir::Value heapAddr = fir::ConvertOp::create(builder, loc, heapType, addr);
+ fir::FreeMemOp::create(builder, loc, heapAddr);
+ });
}
// Note: We don't have a separate InlineCopyOutConversion pattern.
@@ -125,8 +123,7 @@ InlineCopyInConversion::matchAndRewrite(hlfir::CopyInOp copyIn,
mlir::Value copyBackDest;
if (mlir::Value destVar = copyOut.getVar()) {
hlfir::Entity destEntity{destVar};
- destEntity =
- hlfir::derefPointersAndAllocatables(loc, builder, destEntity);
+ destEntity = hlfir::derefPointersAndAllocatables(loc, builder, destEntity);
copyBackDest = destEntity;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/179096
More information about the flang-commits
mailing list