This is an archive of the discontinued LLVM Phabricator instance.

[Flang][RFC] Adding extension intrinsics
ClosedPublic

Authored by kkwli0 on Feb 13 2023, 2:23 PM.

Details

Summary

This RFC is for adding extension builtins to flang. The approach is to make use of the existing intrinsic module mechanism (i.e. __fortran_builtins.f90) to add the platforms specific builtins (e.g. fmsub builtin supported for PPC platform). The framework here is to add an intrinsic module (__fortran_ppc_intrinsics.f90) that the __Fortran_PPC_intrinsics.mod is implicitly "USEd" in every compilation.

This work is still WIP (e.g. no platform specific checking). Please comment. Thanks.

Diff Detail

Event Timeline

kkwli0 created this revision.Feb 13 2023, 2:23 PM
kkwli0 requested review of this revision.Feb 13 2023, 2:23 PM
klausler added inline comments.Feb 13 2023, 2:59 PM
flang/lib/Evaluate/intrinsics.cpp
917 ↗(On Diff #497108)

I still am not sure whether you need to have intrinsic table entries for these. If you declare these names via Fortran INTERFACE blocks or PROCEDURE statements in a built-in module, all of the dummy argument and result information will be completely specified there, and doesn't need to be redundantly specified here. These tables are for intrinsics in the standard Fortran language, because those intrinsics usually cannot be completely specified in Fortran itself, like I believe yours can be.

flang/lib/Semantics/semantics.cpp
475

If extBuiltinsScope is only ever going to hold these PPC intrinsics, please give it a less generic name, like ppcBuiltinsScope, so that it's more clear to the code reader what's going on here.

flang/module/__fortran_ppc_builtins.f90
1 ↗(On Diff #497108)

Please update the first lines of these comment blocks when you copy & paste them into new files.

flang/module/__ppc_intrinsics.f90
1 ↗(On Diff #497108)

Same here.

kkwli0 marked an inline comment as done.Feb 15 2023, 7:39 AM
kkwli0 added inline comments.
flang/lib/Evaluate/intrinsics.cpp
917 ↗(On Diff #497108)

Thanks for the review. I think I can see the benefit of having the interface in the intrinsic module. However, I am not sure if it will push the error checking in the Lowering stage (IntrinsicCall.cpp).

flang/lib/Semantics/semantics.cpp
475

If extBuiltinsScope is only ever going to hold these PPC intrinsics, please give it a less generic name, like ppcBuiltinsScope, so that it's more clear to the code reader what's going on here.

Sure. I will change it to ppcBuiltinsScope. My original idea is that this field can take some other builtin table.

flang/module/__fortran_ppc_builtins.f90
1 ↗(On Diff #497108)

Oops. Will fix it.

kkwli0 updated this revision to Diff 497679.Feb 15 2023, 7:57 AM

I update the patch that puts the interfaces in the module for further discussion. Thanks.

This is looking pretty good.

flang/include/flang/Semantics/semantics.h
282

As with the line above, please put the module name into the comment.

flang/lib/Evaluate/intrinsics.cpp
2354 ↗(On Diff #497679)

Is this still needed here in intrinsics processing?

3168 ↗(On Diff #497679)

Is this also still needed here in intrinsics processing?

flang/module/__fortran_ppc_intrinsics.f90
10

Is this a complete list of the PPC vector intrinsics, or are there more to come?

39

Do you want to also undefined SPECIFICS_R and PRIVATE_R? Or just leave all three macros defined at the end of the source file.

klausler added inline comments.Feb 15 2023, 8:46 AM
flang/module/__fortran_ppc_intrinsics.f90
13

The module might be more clear if it had a blanket PRIVATE statement and then a PUBLIC:: that exposed only the names of the generics.

Instead of explicit INTERFACE blocks for all of the functions, you could define two with ABSTRACT INTERFACE and then use simple PROCEDURE(interface name) statements in the generic interfaces. Maybe then you wouldn't even need any macros.

kkwli0 marked 6 inline comments as done.Feb 17 2023, 9:26 AM
kkwli0 added inline comments.
flang/include/flang/Semantics/semantics.h
282

Will do.

flang/lib/Evaluate/intrinsics.cpp
2354 ↗(On Diff #497679)

Yes, the ppcBuiltinsScope_ is no longer needed.

3168 ↗(On Diff #497679)

Will remove it.

flang/module/__fortran_ppc_intrinsics.f90
10

No, there are more for PPC non-vector and a lot more for vector intrinsics.

13

Yeah, I agree that this is a cleaner approach. However, for the non-vector PPC intrinsics, there are some variants in terms of number of arguments, types of arguments and also the argument keywords. I will try to group some of them to make use of the abstract interface and procedure statement.

39

I will undef if the macros stay.

Both of the continuous integration builds are failing on this patch; please resolve them before asking for final approval.

kkwli0 updated this revision to Diff 498424.Feb 17 2023, 10:01 AM
kkwli0 marked 6 inline comments as done.

The change includes:

  • address review comments
    • use abstract interface in __Fortran_PPC_intrinsics module
    • remove an unnecessary member
    • rename a member name to be less generic
  • add arch check
  • fix format
klausler added inline comments.Feb 17 2023, 10:12 AM
flang/module/__fortran_ppc_intrinsics.f90
24

These procedure statements can appear in the generic interface.

kkwli0 added inline comments.Feb 17 2023, 11:51 AM
flang/module/__fortran_ppc_intrinsics.f90
24

It doesn't work. For the procedure-stmt in interface-specification, the standard only allows:
[ MODULE ] PROCEDURE [ :: ] specific-procedure-list

kkwli0 updated this revision to Diff 498522.Feb 17 2023, 4:25 PM

Fix pre-commit build failures

klausler accepted this revision.Feb 17 2023, 4:35 PM

Well done, and thanks!

This revision is now accepted and ready to land.Feb 17 2023, 4:35 PM
This revision was automatically updated to reflect the committed changes.
kkwli0 edited the summary of this revision. (Show Details)Feb 18 2023, 8:58 AM

Well done, and thanks!

Thanks a lot for the review.