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

Gheorghe-Teodor Bercea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 14:12:18 PST 2022


doru1004 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());
----------------
ABataev wrote:
> 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;
> ```
I will rewrite this.


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