[Openmp-commits] [PATCH] D77252: [OpenMP] Try to find an existing base for `omp begin/end declare variant`

Mike Rice via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Apr 4 18:06:13 PDT 2020


mikerice added a comment.

I just moved your lookup code and tried to get the same info from the declarator.  The function looks like this:

  FunctionDecl *
  Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S,
                                                                  Declarator &D) {
    IdentifierInfo *BaseII = D.getIdentifier();
    LookupResult Lookup(*this, DeclarationName(BaseII), D.getIdentifierLoc(),
                        LookupOrdinaryName);
    LookupParsedName(Lookup, S, &D.getCXXScopeSpec());
  
    TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
    QualType FType = TInfo->getType();
  
    bool IsConstexpr = D.getDeclSpec().getConstexprSpecifier() == CSK_constexpr;
    bool IsConsteval = D.getDeclSpec().getConstexprSpecifier() == CSK_consteval;
  
    FunctionDecl *BaseFD = nullptr;
    for (auto *Candidate : Lookup) {
      auto *UDecl = dyn_cast<FunctionDecl>(Candidate->getUnderlyingDecl());
      if (!UDecl)
        continue;
  
      // Don't specialize constexpr/consteval functions with
      // non-constexpr/consteval functions.
      if (UDecl->isConstexpr() && !IsConstexpr)
        continue;
      if (UDecl->isConsteval() && !IsConsteval)
        continue;
  
      QualType NewType = Context.mergeFunctionTypes(
          FType, UDecl->getType(), /* OfBlockPointer */ false,
          /* Unqualified */ false, /* AllowCXX */ true);
      if (NewType.isNull())
        continue;
  
      // Found a base!
      BaseFD = UDecl;
      break;
    }
    if (!BaseFD) {
      BaseFD = cast<FunctionDecl>(ActOnDeclarator(S, D));
      BaseFD->setImplicit(true);
    }
    OMPDeclareVariantScope &DVScope = OMPDeclareVariantScopes.back();
    std::string MangledName;
    MangledName += D.getIdentifier()->getName();
    MangledName += getOpenMPVariantManglingSeparatorStr();
    MangledName += DVScope.NameSuffix;
    IdentifierInfo &VariantII = Context.Idents.get(MangledName);
  
    VariantII.setMangledOpenMPVariantName(true);
    D.SetIdentifier(&VariantII, D.getBeginLoc());
    return BaseFD;
  }

I just tried a few tests so I didn't spend too much time verifying it.  I'll see if I can get the test your suggest running.

I'm not sure I have any better ideas on how to correctly pick the base function.  This seems like a reasonable first attempt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77252





More information about the Openmp-commits mailing list