This is an archive of the discontinued LLVM Phabricator instance.

[flang] add hlfir.null to implement NULL()
ClosedPublic

Authored by jeanPerier on Jan 5 2023, 1:54 AM.

Details

Summary

In HLFIR, the address of a Fortran entity in lowering must be defined
by an operation that has the FortranVariableOpInterface (it is a sanity
requirement to ensure that the mlir::Value propagated in certain places
of lowering can be reasoned about).
fir.zero_bits does not have this interface and it makes little sense to
add it since it can "zero initialize" more types than just addresses.

Creating an hlfir.declare for null addresses is a bit too much (what
would be the name), and it would be noisy in the IR.

Instead add a small hlfir.null operation whose codegen is simply a
replacement by fir.zero_bits.

It may also later help dealing with the NULL(MOLD) cases in a nicer
way (the current lowering of this uses special handling it).

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 5 2023, 1:54 AM
jeanPerier requested review of this revision.Jan 5 2023, 1:54 AM
PeteSteinfeld accepted this revision.Jan 5 2023, 7:18 AM

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Jan 5 2023, 7:18 AM
vzakhari accepted this revision.Jan 5 2023, 8:17 AM
vdonaldson added inline comments.Jan 5 2023, 9:08 AM
flang/include/flang/Optimizer/HLFIR/HLFIROps.td
469

This formatting looks a little odd.

vdonaldson accepted this revision.Jan 5 2023, 9:08 AM

Remove extra space caught by Val.

This revision was automatically updated to reflect the committed changes.