[llvm] [OpenMP] [IR Builder] Changes to Support Scan Operation (PR #136035)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 13 14:45:04 PDT 2025


================
@@ -2631,6 +2716,41 @@ class OpenMPIRBuilder {
                                              FinalizeCallbackTy FiniCB,
                                              Value *Filter);
 
+  /// This function performs the scan reduction of the values updated in
+  /// the input phase. The reduction logic needs to be emitted between input
+  /// and scan loop returned by `CreateCanonicalScanLoops`. The following
+  /// is the code that is generated, `buffer` and `span` are expected to be
+  /// populated before executing the generated code.
+  ///
+  ///  for (int k = 0; k != ceil(log2(span)); ++k) {
+  ///    i=pow(2,k)
+  ///    for (size cnt = last_iter; cnt >= i; --cnt)
+  ///      buffer[cnt] op= buffer[cnt-i];
+  ///  }
+  /// \param Loc The insert and source location description.
+  /// \param ReductionInfos Array type containing the ReductionOps.
+  ///
+  /// \returns The insertion position *after* the masked.
+  InsertPointOrErrorTy emitScanReduction(
+      const LocationDescription &Loc,
+      SmallVector<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos);
----------------
Meinersbur wrote:

```suggestion
      ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos);
```
If passing non-modified lists, use `ArrayRef` (`SmallVectorImpl` if elements are added withing the call, `MutableArrayRef` the number of elements stays the same)

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


More information about the llvm-commits mailing list