[llvm] [flang-rt] Optimise ShallowCopy and elemental copies in Assign (PR #140569)

Slava Zakharin via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 14:09:01 PDT 2025


================
@@ -437,6 +437,43 @@ 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 RANK1=true variant can be used
+// safely and that Advance() is not called more times than the number of
+// elements in the Descriptor allows for.
+template <bool RANK1 = false> class DescriptorIterator {
+private:
+  const Descriptor &descriptor;
+  SubscriptValue subscripts[maxRank];
+  std::size_t elementOffset = 0;
+
+public:
+  DescriptorIterator(const Descriptor &descriptor) : descriptor(descriptor) {
+    descriptor.GetLowerBounds(subscripts);
+    if constexpr (RANK1) {
+      elementOffset = descriptor.SubscriptByteOffset(0, subscripts[0]);
+    }
+  };
+
+  template <typename A> A *Get() {
----------------
vzakhari wrote:

```suggestion
  template <typename A> RT_API_ATTRS A *Get() {
```

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


More information about the llvm-commits mailing list