This patch adds support for selecting which functions are lowered to LLVM IR from MLIR depending on declare target information and whether host or device code is being generated.
The approach proposed by this patch is to perform the filtering in two stages:
- An MLIR transformation pass, which is added to the Flang translation flow before the VerifierPass. The functions that are kept are those that match the OpenMP processor (host or device) the compiler invocation is targeting, according to the presence of the -fopenmp-is-device compiler option and declare target information. All functions contaning an omp.target are also kept, regardless of the declare target information of the function, due to the need for keeping target regions visible for both host and device compilation.
- A filtering step during translation to LLVM IR, which is peformed for those functions that were kept because of the presence of a target region inside. If the targeted OpenMP processor does not match the declare target information of the function, then it is removed from the LLVM IR after its contents have been processed and translated. Since they should only contain an omp.target operation which, in turn, should have been outlined into another LLVM function, the wrapper can be deleted at that point.
The change in convertOneFunction is intrusive. Code here must not be aware of the OpenMP attributes.