Author: Vlad Serebrennikov Date: 2023-11-01T12:40:13+03:00 New Revision: 50dec541f328a251c2830421f354e4439e635def
URL: https://github.com/llvm/llvm-project/commit/50dec541f328a251c2830421f354e4439e635def DIFF: https://github.com/llvm/llvm-project/commit/50dec541f328a251c2830421f354e4439e635def.diff LOG: [clang][NFC] Refactor `OMPDeclareReductionDecl::InitKind` This patch moves `OMPDeclareReductionDecl::InitKind` to DeclBase.h, so that it's complete at the point where corresponding bit-field is declared. This patch also converts it to scoped enum named `OMPDeclareReductionInitKind` Added: Modified: clang/include/clang/AST/DeclBase.h clang/include/clang/AST/DeclOpenMP.h clang/lib/AST/DeclOpenMP.cpp clang/lib/AST/DeclPrinter.cpp clang/lib/AST/TextNodeDumper.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriterDecl.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index ba6dadd7d3563c3..7b743edf9452526 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -1422,6 +1422,12 @@ enum class ArgPassingKind { CanNeverPassInRegs }; +enum class OMPDeclareReductionInitKind { + Call, // Initialized by function call. + Direct, // omp_priv(<expr>) + Copy // omp_priv = <expr> +}; + /// DeclContext - This is used only as base class of specific decl types that /// can act as declaration contexts. These decls are (only the top classes /// that directly derive from DeclContext are mentioned, not their subclasses): diff --git a/clang/include/clang/AST/DeclOpenMP.h b/clang/include/clang/AST/DeclOpenMP.h index dd63a4f5d680cf5..2bbd159f59a3536 100644 --- a/clang/include/clang/AST/DeclOpenMP.h +++ b/clang/include/clang/AST/DeclOpenMP.h @@ -171,14 +171,7 @@ class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> { class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext { // This class stores some data in DeclContext::OMPDeclareReductionDeclBits // to save some space. Use the provided accessors to access it. -public: - enum InitKind { - CallInit, // Initialized by function call. - DirectInit, // omp_priv(<expr>) - CopyInit // omp_priv = <expr> - }; -private: friend class ASTDeclReader; /// Combiner for declare reduction construct. Expr *Combiner = nullptr; @@ -239,8 +232,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext { Expr *getInitializer() { return Initializer; } const Expr *getInitializer() const { return Initializer; } /// Get initializer kind. - InitKind getInitializerKind() const { - return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind); + OMPDeclareReductionInitKind getInitializerKind() const { + return static_cast<OMPDeclareReductionInitKind>( + OMPDeclareReductionDeclBits.InitializerKind); } /// Get Orig variable of the initializer. Expr *getInitOrig() { return Orig; } @@ -249,9 +243,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext { Expr *getInitPriv() { return Priv; } const Expr *getInitPriv() const { return Priv; } /// Set initializer expression for the declare reduction construct. - void setInitializer(Expr *E, InitKind IK) { + void setInitializer(Expr *E, OMPDeclareReductionInitKind IK) { Initializer = E; - OMPDeclareReductionDeclBits.InitializerKind = IK; + OMPDeclareReductionDeclBits.InitializerKind = llvm::to_underlying(IK); } /// Set initializer Orig and Priv vars. void setInitializerData(Expr *OrigE, Expr *PrivE) { diff --git a/clang/lib/AST/DeclOpenMP.cpp b/clang/lib/AST/DeclOpenMP.cpp index e29fc564fd34ac5..ac5780f82dbbb23 100644 --- a/clang/lib/AST/DeclOpenMP.cpp +++ b/clang/lib/AST/DeclOpenMP.cpp @@ -104,7 +104,7 @@ OMPDeclareReductionDecl::OMPDeclareReductionDecl( QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope) : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr), PrevDeclInScope(PrevDeclInScope) { - setInitializer(nullptr, CallInit); + setInitializer(nullptr, OMPDeclareReductionInitKind::Call); } void OMPDeclareReductionDecl::anchor() {} diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index daa219b43c4e6cf..98fba958064a106 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1866,17 +1866,17 @@ void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { if (auto *Init = D->getInitializer()) { Out << " initializer("; switch (D->getInitializerKind()) { - case OMPDeclareReductionDecl::DirectInit: + case OMPDeclareReductionInitKind::Direct: Out << "omp_priv("; break; - case OMPDeclareReductionDecl::CopyInit: + case OMPDeclareReductionInitKind::Copy: Out << "omp_priv = "; break; - case OMPDeclareReductionDecl::CallInit: + case OMPDeclareReductionInitKind::Call: break; } Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context); - if (D->getInitializerKind() == OMPDeclareReductionDecl::DirectInit) + if (D->getInitializerKind() == OMPDeclareReductionInitKind::Direct) Out << ")"; Out << ")"; } diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index 89951b384f12849..bbdfd4523c8200c 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -2078,13 +2078,13 @@ void TextNodeDumper::VisitOMPDeclareReductionDecl( OS << " initializer"; dumpPointer(Initializer); switch (D->getInitializerKind()) { - case OMPDeclareReductionDecl::DirectInit: + case OMPDeclareReductionInitKind::Direct: OS << " omp_priv = "; break; - case OMPDeclareReductionDecl::CopyInit: + case OMPDeclareReductionInitKind::Copy: OS << " omp_priv ()"; break; - case OMPDeclareReductionDecl::CallInit: + case OMPDeclareReductionInitKind::Call: break; } } diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 01786774aad6b41..34c9c02884ec555 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1133,7 +1133,7 @@ void CGOpenMPRuntime::emitUserDefinedReduction( if (const Expr *Init = D->getInitializer()) { Initializer = emitCombinerOrInitializer( CGM, D->getType(), - D->getInitializerKind() == OMPDeclareReductionDecl::CallInit ? Init + D->getInitializerKind() == OMPDeclareReductionInitKind::Call ? Init : nullptr, cast<VarDecl>(cast<DeclRefExpr>(D->getInitOrig())->getDecl()), cast<VarDecl>(cast<DeclRefExpr>(D->getInitPriv())->getDecl()), diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 29b2c7531f4b535..1bd34f73e5f7e00 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -22611,12 +22611,12 @@ void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, PopFunctionScopeInfo(); if (Initializer != nullptr) { - DRD->setInitializer(Initializer, OMPDeclareReductionDecl::CallInit); + DRD->setInitializer(Initializer, OMPDeclareReductionInitKind::Call); } else if (OmpPrivParm->hasInit()) { DRD->setInitializer(OmpPrivParm->getInit(), OmpPrivParm->isDirectInit() - ? OMPDeclareReductionDecl::DirectInit - : OMPDeclareReductionDecl::CopyInit); + ? OMPDeclareReductionInitKind::Direct + : OMPDeclareReductionInitKind::Copy); } else { DRD->setInvalidDecl(); } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 78a7892a35a320b..11d4c83dba77d96 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3627,7 +3627,7 @@ Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl( SemaRef.CurrentInstantiationScope->InstantiatedLocal( cast<DeclRefExpr>(D->getInitPriv())->getDecl(), cast<DeclRefExpr>(NewDRD->getInitPriv())->getDecl()); - if (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit) { + if (D->getInitializerKind() == OMPDeclareReductionInitKind::Call) { SubstInitializer = SemaRef.SubstExpr(Init, TemplateArgs).get(); } else { auto *OldPrivParm = @@ -3642,9 +3642,9 @@ Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl( } IsCorrect = IsCorrect && SubstCombiner && (!Init || - (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit && + (D->getInitializerKind() == OMPDeclareReductionInitKind::Call && SubstInitializer) || - (D->getInitializerKind() != OMPDeclareReductionDecl::CallInit && + (D->getInitializerKind() != OMPDeclareReductionInitKind::Call && !SubstInitializer)); (void)SemaRef.ActOnOpenMPDeclareReductionDirectiveEnd( diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 470a648098e2ed9..94a678e0c416404 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3005,7 +3005,7 @@ void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { Expr *Priv = Record.readExpr(); D->setInitializerData(Orig, Priv); Expr *Init = Record.readExpr(); - auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()); + auto IK = static_cast<OMPDeclareReductionInitKind>(Record.readInt()); D->setInitializer(Init, IK); D->PrevDeclInScope = readDeclID(); } diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 7f6a23cf6b8c10d..a91fde561d23aa2 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1972,7 +1972,7 @@ void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { Record.AddStmt(D->getInitOrig()); Record.AddStmt(D->getInitPriv()); Record.AddStmt(D->getInitializer()); - Record.push_back(D->getInitializerKind()); + Record.push_back(llvm::to_underlying(D->getInitializerKind())); Record.AddDeclRef(D->getPrevDeclInScope()); Code = serialization::DECL_OMP_DECLARE_REDUCTION; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits