This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpenMP]Support for modifiers in workshare loops
ClosedPublic

Authored by Leporacanthicus on Oct 4 2021, 6:11 AM.

Details

Summary

Pass the modifiers from the Flang parser to FIR/MLIR workshare
loop operation.

Not yet supporting the SIMD modifier, which is a bit more work
than just adding it to the list of modifiers, so will go in a
separate patch.

This adds a new field to the WsLoopOp.

Also add test for dynamic WSLoop, checking that dynamic schedule calls
the init and next functions as expected.

Diff Detail

Event Timeline

Leporacanthicus created this revision.Oct 4 2021, 6:11 AM
Leporacanthicus requested review of this revision.Oct 4 2021, 6:11 AM
Meinersbur added a comment.EditedOct 4 2021, 3:13 PM

What are your plans to support the simd directive? Does schedule_modifiers() also become a list? A flags enum? Or do you split schedule_modifiers() into separate attributes such as monotonicity_schedule_modifier() and simd_schedule_modifier()?

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
256

Parameters should be SmallVectorImpl to not force the caller to a specific small-size. Same theoretically also applies to SmallString (SmallVectorTempl<char>) but that doesn't work with type arguments. (but it would for SmallString<8> &schedule).

It's a static function anyway, so treat this as a nitpicking.

What are your plans to support the simd directive? Does schedule_modifiers() also become a list? A flags enum? Or do you split schedule_modifiers() into separate attributes such as mononoicity_schedule_modifier() and simd_schedule_modifier()?

Yes, it's in D111051 (linked to this one as "Child Revision"). The reviews are "backwards" because of my inability to use Arcanist - it decided that I only wanted to upload ONE of the two patches. Both of these patches already in fir-dev, I'm submitting them to llvm/main to make sure they don't accidentally get lost when fir-dev is catching up with llvm/main.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
256

I'll take a look at this - I think there's quite a bit of "potential for improvement" here, and I'll see if it's better to do a whole other "clean things up" patch.

ftynse requested changes to this revision.Oct 6 2021, 1:16 AM

Thanks! A couple of minor comments from me.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
229

Nit: there's only one attribute that can be present, so I would use singular for the name.

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
280

The case with more modifiers is not handled.

936

Could we omit the "none" modifier in the format as, I believe, it is the default? This will avoid the change in most tests below.

This revision now requires changes to proceed.Oct 6 2021, 1:16 AM
clementval added inline comments.
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
139

I think @kiranchandramohan added a way to have this coming directly from the OMP.td file.

Leporacanthicus marked 3 inline comments as done.

Updating according to review comments

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
256

Fixed.

280

It is "handled" in the sense that it gives an error below for "expected parenthesis". The only valid case is for further modifiers is SIMD, which is covered in the next patch.

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
139

This was introduced as part of https://reviews.llvm.org/D84347.

If you can define ClauseVal entries in llvm/include/llvm/Frontend/OpenMP/OMP.td then these entries will be autogenerated. Example for proc_bind given below.

def OMP_PROC_BIND_master : ClauseVal<"master",2,1> {}
def OMP_PROC_BIND_close : ClauseVal<"close",3,1> {}
def OMP_PROC_BIND_spread : ClauseVal<"spread",4,1> {}
def OMP_PROC_BIND_default : ClauseVal<"default",5,0> {}
def OMP_PROC_BIND_unknown : ClauseVal<"unknown",6,0> { let isDefault = 1; }
def OMPC_ProcBind : Clause<"proc_bind"> {
  let clangClass = "OMPProcBindClause";
  let flangClass = "OmpProcBindClause";
  let enumClauseValue = "ProcBindKind";
  let allowedClauseValues = [
    OMP_PROC_BIND_master,
    OMP_PROC_BIND_close,
    OMP_PROC_BIND_spread,
    OMP_PROC_BIND_default,
    OMP_PROC_BIND_unknown
  ];
}
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
139

But a schedule modifier is not a clause on its own - it's part of the ScheduleClause - I first implemented it as a SheduleModifierClause, but I was told that it isn't a clause.

ftynse accepted this revision.Oct 18 2021, 6:52 AM
This revision is now accepted and ready to land.Oct 18 2021, 6:52 AM

Rebase to latest llvm/main