[llvm] [flang-rt] Optimise ShallowCopy and use it in CopyInAssign (PR #140569)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 04:44:20 PDT 2025


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 HEAD~1 HEAD --extensions cpp,h -- flang-rt/include/flang-rt/runtime/descriptor.h flang-rt/include/flang-rt/runtime/tools.h flang-rt/lib/runtime/assign.cpp flang-rt/lib/runtime/tools.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang-rt/lib/runtime/tools.cpp b/flang-rt/lib/runtime/tools.cpp
index ee62761da..694864dbb 100644
--- a/flang-rt/lib/runtime/tools.cpp
+++ b/flang-rt/lib/runtime/tools.cpp
@@ -194,20 +194,21 @@ RT_API_ATTRS void ShallowCopyInner(const Descriptor &to, const Descriptor &from,
 // Most arrays are much closer to rank-1 than to maxRank.
 // Doing the recursion upwards instead of downwards puts the more common
 // cases earlier in the if-chain and has a tangible impact on performance.
-template <typename P, int RANK>
-struct ShallowCopyRankSpecialize {
-  static bool execute(const Descriptor &to, const Descriptor &from, bool toIsContiguous, bool fromIsContiguous) {
+template <typename P, int RANK> struct ShallowCopyRankSpecialize {
+  static bool execute(const Descriptor &to, const Descriptor &from,
+      bool toIsContiguous, bool fromIsContiguous) {
     if (to.rank() == RANK && from.rank() == RANK) {
       ShallowCopyInner<P, RANK>(to, from, toIsContiguous, fromIsContiguous);
       return true;
     }
-    return ShallowCopyRankSpecialize<P, RANK+1>::execute(to, from, toIsContiguous, fromIsContiguous);
+    return ShallowCopyRankSpecialize<P, RANK + 1>::execute(
+        to, from, toIsContiguous, fromIsContiguous);
   }
 };
 
-template<typename P>
-struct ShallowCopyRankSpecialize<P, maxRank+1> {
-  static bool execute(const Descriptor &to, const Descriptor &from, bool toIsContiguous, bool fromIsContiguous) {
+template <typename P> struct ShallowCopyRankSpecialize<P, maxRank + 1> {
+  static bool execute(const Descriptor &to, const Descriptor &from,
+      bool toIsContiguous, bool fromIsContiguous) {
     return false;
   }
 };
@@ -217,7 +218,8 @@ template <typename P>
 RT_API_ATTRS void ShallowCopyRank(const Descriptor &to, const Descriptor &from,
     bool toIsContiguous, bool fromIsContiguous) {
   // Try to call a specialised ShallowCopy variant from rank-1 up to maxRank
-  bool specialized = ShallowCopyRankSpecialize<P, 1>::execute(to, from, toIsContiguous, fromIsContiguous);
+  bool specialized = ShallowCopyRankSpecialize<P, 1>::execute(
+      to, from, toIsContiguous, fromIsContiguous);
   if (!specialized) {
     ShallowCopyInner<P>(to, from, toIsContiguous, fromIsContiguous);
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/140569


More information about the llvm-commits mailing list