This is an archive of the discontinued LLVM Phabricator instance.

[mlir] support reductions in SCF to OpenMP conversion
ClosedPublic

Authored by ftynse on Aug 5 2021, 3:01 AM.

Details

Summary

OpenMP reductions need a neutral element, so we match some known reduction
kinds (integer add/mul/or/and/xor, float add/mul, integer and float min/max) to
define the neutral element and the atomic version when possible to express
using atomicrmw (everything except float mul). The SCF-to-OpenMP pass becomes a
module pass because it now needs to introduce new symbols for reduction
declarations in the module.

Diff Detail

Event Timeline

ftynse created this revision.Aug 5 2021, 3:01 AM
ftynse requested review of this revision.Aug 5 2021, 3:01 AM
ftynse updated this revision to Diff 364409.Aug 5 2021, 4:06 AM

Fix cmake

ftynse updated this revision to Diff 370268.Sep 2 2021, 7:39 AM

Rebase.

chelini added inline comments.Sep 3 2021, 5:28 AM
mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
63

opreations -> operations

97

is -> if

184

please add assert message

232

I would move this below the if

233

Should not this be an assert instead? if I am not mistaken ReduceOp has a single block.

275

I would explicitly set isMin to false.

354

"cannot be an LLVM" -> "is not an LLVM"

ftynse updated this revision to Diff 370565.Sep 3 2021, 6:14 AM
ftynse marked 7 inline comments as done.

Address review.

mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp
275

It is unset on purpose to indicate that the further call (matchSelectReduction) will set it. The compiler will likely complain if it is ever used without being initialized, but will not complain if it is initialized to the wrong value.

chelini accepted this revision.Sep 9 2021, 3:00 AM

Thanks, looks good to me.

This revision is now accepted and ready to land.Sep 9 2021, 3:00 AM
This revision was automatically updated to reflect the committed changes.