[flang-commits] [flang] [flang][OpenMP] Support lowering of metadirective (part 1) (PR #193664)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Jun 1 04:08:23 PDT 2026


================
@@ -4638,11 +4586,224 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
   // support the case of threadprivate variable declared in module.
 }
 
+namespace {
+struct TargetOMPContext final : public llvm::omp::OMPContext {
+  TargetOMPContext(mlir::ModuleOp module,
+                   llvm::ArrayRef<llvm::omp::TraitProperty> constructTraits)
+      // DeviceNum is set to -1 (unknown) because the
+      // target_device={device_num()} selector is not yet supported. OMPContext
+      // uses DeviceNum > -1 to activate target_device traits from the offload
+      // triple; without a concrete device number those traits are left
+      // inactive.
----------------
abidh wrote:

The last line of the comment is not entirely accurate. Looking at `OMPContext::OMPContext` in OMPContext.cpp with `DeviceNum` == -1 (the else-branch), `OMPContext` does set target_device_* traits but from the host triple, not the offload triple. I think the TODO guard in `makeVariantMatchInfo` prevents that path to be taken but it will need handling when that TODO is removed.

https://github.com/llvm/llvm-project/pull/193664


More information about the flang-commits mailing list