[PATCH] D140155: [Clang][OpenMP] Allow host call to nohost function with host variant

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 13:48:41 PST 2022


ABataev added inline comments.


================
Comment at: clang/lib/Sema/SemaOpenMP.cpp:2697-2706
+      for (OMPDeclareVariantAttr *A :
+           Callee->specific_attrs<OMPDeclareVariantAttr>()) {
+        auto *DeclRefVariant = cast<DeclRefExpr>(A->getVariantFuncRef());
+        auto *VariantFD = cast<FunctionDecl>(DeclRefVariant->getDecl());
+        Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
+            OMPDeclareTargetDeclAttr::getDeviceType(
+                VariantFD->getMostRecentDecl());
----------------
It is recommended to implement such loops as functions/lauto &ambdas:
```
auto HasHostAttr = []() {
  for (const OMPDeclareVariantAttr *A :
    Callee->specific_attrs<OMPDeclareVariantAttr>()) {
    auto *DeclRefVariant = cast<DeclRefExpr>(A->getVariantFuncRef());
    auto *VariantFD = cast<FunctionDecl>(DeclRefVariant->getDecl());
    Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
        OMPDeclareTargetDeclAttr::getDeviceType(
            VariantFD->getMostRecentDecl());
    if (!DevTy || *DevTy == OMPDeclareTargetDeclAttr::DT_Host)
      return true;
  }
  return false;
};
if (HasHostAttr())
  return;
```


================
Comment at: clang/lib/Sema/SemaOpenMP.cpp:2703
+            OMPDeclareTargetDeclAttr::getDeviceType(
+                VariantFD->getMostRecentDecl());
+        if (!DevTy || *DevTy == OMPDeclareTargetDeclAttr::DT_Host)
----------------
Why the most recent decl?


================
Comment at: clang/lib/Sema/SemaOpenMP.cpp:2704
+                VariantFD->getMostRecentDecl());
+        if (!DevTy || *DevTy == OMPDeclareTargetDeclAttr::DT_Host)
+          HasHostFunctionVariant = true;
----------------
Isuppose it must be `DevTy && *DevTy == OMPDeclareTargetDeclAttr::DT_Host`, no?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140155/new/

https://reviews.llvm.org/D140155



More information about the cfe-commits mailing list