[Mlir-commits] [mlir] [mlir][OpenMP] inscan reduction modifier and scan op mlir support (PR #114737)

Anchu Rajendran S llvmlistbot at llvm.org
Fri Dec 6 11:25:12 PST 2024


================
@@ -1560,6 +1560,26 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
   let hasVerifier = 1;
 }
 
+def ScanOp : OpenMP_Op<"scan", [
----------------
anchuraj wrote:

Great question. There are a few facts to be considered here. For Simplicity, i will consider body of for-loop as 
```
{
  <pre scan block> b1;
  scan
  <post scan block> b2;
} 
```
- As per the definition of scan,  `b1` or `b2` can be input or scan phase based on `exclusive` or `inclusive` clause used with the directive
- My first attempt was to define this structure in parsing, however I failed  `<structured sequence> scan <structured sequence>` was making the grammar ambiguous. I digged into clang and saw that the blocks are not associated with the directive (scan is a stand-alone directive). Its the llvm lowering that separated the two blocks. When lowered, the body of the for loop before scan is emitted as first basic block and after scan is emitted as another basic block. On encountering scan, these blocks are treated as input or scan phase based on clauses that scan has. Since there are only two blocks and as scan directive always appear in loops with `inscan` reduction modifier, dealing it while lowering would be simple.
- When parsing does not separate it easily, representing it as an MLIR op will be very complicated to do in frontend and would result in code that is not much reusable if we go with that representation. 

These are why the current representation is chosen.

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


More information about the Mlir-commits mailing list