This adds lowering support to Flang for OpenMP Declare Target
tagged functions and subroutines, it currently supports only the
to and device_type clauses. Although, it is very likely the current
infrastructure is easily extendable to link (findFuncAndVarSyms
should work with ease), this has yet to be tested with global
data, but this will be a future extension of this work.
This patch adds an attribute which contains data
provided to the device_type clause (any | host | nohost) and
marks MLIR FuncOps with this attribute where neccesary.
An additional pass is added to Flang which marks functions used
within declare target functions as declare target with their
callers device_type (or a combination if they are marked
multiple times). This is a form of implicit capture, this appears
to occur within Clang (albeit in a different way) and from my
current reading and understanding of the specification is described
there as well. However, perhaps this is not the right way to go
about this. Unfortunately the Fir.CallOps within
FIR make the current form of the pass a
little difficult to generalise to an OpenMP dialect pass
within the MLIR infrastructure as it would add Flang
dependencies to the MLIR project.
This also adds omp-declare-target.f90 and attr.mlir as tests to test
the attribute and the current lowering support.
The idea is that this attribute can be picked up by amendOperation or
similar infrastructure later during lowering of the LLVM Dialect +
OpenMP dialect to LLVM-IR and have specialised lowering based
on the contained device_type clause.
Naive filtering/removal of declare target functions was attempted
within the initial lowering inside of the new handleDeclareTarget
function based on the omp.is_device attribute tied to the
module. However, this cannot be done at this stage as the
function itself may contain a target region that has yet to be
lowered. However, I believe this filtering could be done after
the initial module lowering with a supplementary pass similar
to the one added within this patch. But I have yet to investigate
this direction.