This is an archive of the discontinued LLVM Phabricator instance.

[Flang][MLIR][OpenMP] Improve device-only function filtering
ClosedPublic

Authored by skatrak on Jul 20 2023, 5:46 AM.

Details

Summary

This patch improves the implementation of a recent function filtering workaround to address problems uncovered by D154247.

In particular, the problem was related to the removal of functions called from within target regions. Since target regions have to remain until LLVM IR is generated, removing these functions from MLIR results in undefined references any time there are calls to them in a target region. This patch modifies the MLIR function filtering pass to make these functions "external" rather than removing them. This way, the processing and lowering of MLIR functions that will eventually be discarded is still prevented, but no calls to undefined functions remain either.

Additionally, the approach of just filtering host-only functions during device compilation, and not filtering device-only functions during host compilation, is maintained. This is because code generation for device-only functions is required for host fallback to work.

Depends on D156988

Diff Detail

Event Timeline

skatrak created this revision.Jul 20 2023, 5:46 AM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
skatrak requested review of this revision.Jul 20 2023, 5:46 AM
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
1064–1068 ↗(On Diff #542462)

This part has to come in a separate patch.

skatrak updated this revision to Diff 546806.Aug 3 2023, 4:54 AM

Update patch after splitting some work into D156988.

skatrak edited the summary of this revision. (Show Details)Aug 3 2023, 4:55 AM

Looks OK to me. @agozillon or @jsjodin can accept the patch if they agree.

jsjodin accepted this revision.Aug 9 2023, 8:09 AM

This looks good to me.

flang/include/flang/Optimizer/Transforms/Passes.td
322

Nit: I think we should say "target device" instead of "device" if it is visible to the user.

This revision is now accepted and ready to land.Aug 9 2023, 8:09 AM
agozillon accepted this revision.Aug 9 2023, 8:09 AM

LGTM, great job. You can wait on @jsjodin to review as well if you wish to have another set of eyes on the patch though!

skatrak updated this revision to Diff 548658.Aug 9 2023, 9:58 AM
skatrak marked an inline comment as done.

Rebase and address review comment.

Thank you all for giving this a look. I'll land it tomorrow.