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

Yusuke MINATO via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 21:54:04 PDT 2025


================
@@ -437,6 +437,64 @@ class Descriptor {
 };
 static_assert(sizeof(Descriptor) == sizeof(ISO::CFI_cdesc_t));
 
+// Lightweight iterator-like API to simplify specialising Descriptor indexing
+// in cases where it can improve application performance. On account of the
+// purpose of this API being performance optimisation, it is up to the user to
+// do all the necessary checks to make sure the specialised variants can be used
+// safely and that Advance() is not called more times than the number of
+// elements in the Descriptor allows for.
+// Default RANK=-1 supports aray descriptors of any rank up to maxRank.
+template <int RANK = -1> class DescriptorIterator {
+private:
+  const Descriptor &descriptor;
+  SubscriptValue subscripts[maxRank];
+  std::size_t elementOffset = 0;
+
+public:
+  RT_API_ATTRS DescriptorIterator(const Descriptor &descriptor)
+      : descriptor(descriptor) {
+    // We do not need the subscripts to iterate over a rank-1 array
+    if constexpr (RANK != 1) {
+      descriptor.GetLowerBounds(subscripts);
+    }
+  };
+
+  template <typename A> RT_API_ATTRS A *Get() {
+    std::size_t offset = 0;
----------------
yus3710-fj wrote:

```suggestion
    std::size_t offset{0};
```

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


More information about the llvm-commits mailing list