This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix printing of constc and parsing of #fir.real
ClosedPublic

Authored by rovka on Nov 17 2021, 5:07 AM.

Details

Summary

Printing and parsing of constc didn't agree with each other. This patch
treats the parsing of constc as the final word and fixes the printing
accordingly.

More concretely, this patch prints the RealAttrs that make up the
ConstcOp directly instead of casting to mlir::FloatAttr (which blows
up). It also fixes parseFirRealAttr to invoke APFloat's method for
getting the size of a floating point type instead of computing it as
8 * kind (which blows up for BFloat, with kind == 3 and size == 16).

Kudos to Kiran Chandramohan <kiran.chandramohan@arm.com> for noticing
that we were missing tests for constc in fir-ops.fir.

Diff Detail

Event Timeline

rovka created this revision.Nov 17 2021, 5:07 AM
rovka requested review of this revision.Nov 17 2021, 5:07 AM

This is great. LGTM. Please wait for an approval from @schweitz.

This revision is now accepted and ready to land.Nov 18 2021, 1:58 PM
schweitz added a comment.EditedNov 18 2021, 2:10 PM

Thanks for cleaning this up. We had some convoluted workarounds to support precisions more than double in the early days of MLIR.

flang/lib/Optimizer/Dialect/FIRAttr.cpp
167

LLVM convention is to prefer = for these.

This revision was automatically updated to reflect the committed changes.