This is an archive of the discontinued LLVM Phabricator instance.

[flang] add hlfir.product operation
ClosedPublic

Authored by jacob-crawley on Apr 5 2023, 8:50 AM.

Details

Summary

Adds a HLFIR operation for the PRODUCT intrinsic according to
the design set out in flang/doc/HighLevelFIR.md

Since the PRODUCT intrinsic is essentially identical to SUM
in terms of its arguments and result characteristics in the
Fortran Standard, the operation definition and subsequent
tests also take the same form.

Diff Detail

Event Timeline

jacob-crawley created this revision.Apr 5 2023, 8:50 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 5 2023, 8:50 AM
jacob-crawley requested review of this revision.Apr 5 2023, 8:50 AM

Note - I am away on annual leave until April 13th from today so you will likely not receive any replies until then

Other than my comment about sharing the verifier logic, looks good.

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
496

This looks very similar to SumOp::verify. Could you try to share this in a:

template<typename ReductionOp>
static mlir::LogicalResult verifyReductionOp(ReductionOp reductionOp) {
 //...
 mlir::Value array = reductionOp.getArray();
  // ...
  reductionOp.emitWarning("MASK must be conformable to ARRAY")
}

An alternative would be to use an operation interface for reduction operation, but it seems a bit overkill at that point.

flang/test/HLFIR/product.fir
241

Nit: missing new line here.

tblah added a comment.Apr 12 2023, 3:01 AM

Good work on this! +1 from me, but please address Jean's comments.

Thanks for the reviews

Changes:

  • Following Jean's suggestion, the shared logic in the verify functions for Sum and Product has been moved into a new template function verifyReductionOp
  • fixes to review nits
jacob-crawley marked 2 inline comments as done.Apr 13 2023, 8:31 AM

Looks good, thanks. There is a build-bot failure, I am not sure it is related to your patch, but you should probably rebase the patch to verify this.

Rebasing to pass build-bot tests

jeanPerier accepted this revision.Apr 14 2023, 6:33 AM
This revision is now accepted and ready to land.Apr 14 2023, 6:33 AM