Skip to content

Commit

Permalink
[Flang][OpenMP] Lower host_eval clauses during target lowering
Browse files Browse the repository at this point in the history
Previously, the approach taken to deal with host-evaluated clauses for
operations nested inside of `omp.target` was to use the
`HostClausesInsertionGuard`. This class moved the MLIR insertion point outside
the `omp.target` operation, so that clause lowering would produce code to be
evaluated in the host device.

However, this approach resulted in the use of MLIR values defined only inside
of the target region outside of it. Then, some fix-up work was performed to
replace these uses with the equivalent values outside, which had to consider
multiple corner cases based on the types and the origin of these values.

This patch replaces that approach with another in which these host-evaluated
clauses are lowered as part of the processing of `omp.target` clauses, so the
created MLIR operations are correct from the beginning, without the need for a
fix-up pass.

For that, evaluations related to a target construct are analyzed and processed
independently of the established lowering process, also checking nested
evaluations for the code patterns for which `host_eval` operands have to be
introduced for the `omp.target` operation under construction. If one of these
patterns is found, the relevant clauses are evaluated and stored in a global
structure.

This global structure is checked and used when lowering clauses for operations
that can potentially be evaluated in the host, rather than immediately prior to
that operation. If it has already been evaluated in the host, the corresponding
`omp.target` region block argument is passed as an operand to that operation.
Otherwise, it is evaluated as usual.

This patch also updates the MLIR to LLVM IR translation pass to make sure
default values are properly processed regardless of whether it's host or device
compilation.
  • Loading branch information
skatrak committed Nov 15, 2024
1 parent b635d6e commit 98f2560
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 638 deletions.
Loading

0 comments on commit 98f2560

Please sign in to comment.