This adds lowering support to Flang for OpenMP Declare Target
tagged functions, subroutines and global data in the form of
GlobalOps.
This patch adds an attribute which contains data
provided to the device_type clause (any | host | nohost) and
what I've currently called the "capture" clause which is the
To (Enter) and Link clauses. This attribute is then applied
to functions, subroutines and global data (which are
represented as builtin.FuncOp's and fir.GlobalOp's in
MLIR).
An additional semantic analysis pass is added to Flang
which adds functions used within declare target functions
to the original declare target specifier, effectively marking
them as declare target, with the same clauses as their
parent/caller. 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.
This also adds several tests testing current global data, functions and
subroutine 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 attribute data. This can be seen in:
https://reviews.llvm.org/D149368 which lowers GlobalOp's marked
with a declare target attribute to LLVM-IR.
Filtering of functions/global data that is deemed unneccesary for a
module is currently not done in this patch. The approach currently is
to do this later in the pipeline during the lowering to LLVM-IR as shown
for functions here: https://reviews.llvm.org/D147641 Global data can
likely be done similarly.
This patch has the following related patches on-going:
Function filtering: https://reviews.llvm.org/D147641
Initial lowering of declare target to LLVM-IR for global data: https://reviews.llvm.org/D149368
Movement of OMP IR Builder functionality for lowering declare target data: https://reviews.llvm.org/D149162
Loading in of host module data to properly populate device metadata for declare target: https://reviews.llvm.org/D148370
With these four patches and this patch, initial support for declare target will exist for Flang+OpenMP, however,
further testing and extension for all edge cases will be required and something I will continue to work on. Frontend
semantic analysis support also needs a little look into as well, there's a lot of cases where things compile without
error when they shouldn't and vice versa still. But these patches should yield some initial support.
It might be preferable to use llvm::SmallVector<Fortran::semantics::Symbol, 0> here, according to this: https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h.