This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] lower hlfir.product into fir runtime call
ClosedPublic

Authored by jacob-crawley on May 2 2023, 4:02 AM.

Details

Summary

The shared code for lowering the sum and product operations in
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp have
been moved into a new class HlfirReductionIntrinsicConverion.

Depends on: D148719

Diff Detail

Event Timeline

jacob-crawley created this revision.May 2 2023, 4:02 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 2 2023, 4:02 AM
jacob-crawley requested review of this revision.May 2 2023, 4:02 AM
tblah added inline comments.May 2 2023, 4:46 AM
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
180

There may be other reduction intrinsics added in the future, so I would still check std::is_same_v<OP, hflfir::ProductOp>. If it is neither you could return mlir::failure().

This if statement can be constexpr https://stackoverflow.com/questions/43434491/difference-between-if-constexpr-vs-if

Thanks for the review,

Added a case to check for hlfir::ProductOp and return mlir::failure()
if the class in HlfirReductionIntrinsicConversion matches neither
product or sum

jacob-crawley marked an inline comment as done.May 2 2023, 6:29 AM

Thanks looks good

flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
212

To save even more lines, you could maybe define "convertReductionIntrinsic" as a public "matchAndRewrite" directly, and used: using SumOpConversion = HlfirReductionIntrinsicConversion<hlfir::SumOp>; here.

Thanks for that tip,

the "convertReductionIntrinsic" method has been altered to a public
"matchAndRewrite" method meaning the OpConversion classes for product
and sum can be refactored to a single line each.

jacob-crawley marked an inline comment as done.May 2 2023, 8:27 AM
jeanPerier accepted this revision.May 3 2023, 12:04 AM

Thanks, LGTM

This revision is now accepted and ready to land.May 3 2023, 12:04 AM