Skip to content

Commit 50dec54

Browse files
committed
[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`
1 parent 18669b1 commit 50dec54

File tree

10 files changed

+28
-28
lines changed

10 files changed

+28
-28
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,12 @@ enum class ArgPassingKind {
14221422
CanNeverPassInRegs
14231423
};
14241424

1425+
enum class OMPDeclareReductionInitKind {
1426+
Call, // Initialized by function call.
1427+
Direct, // omp_priv(<expr>)
1428+
Copy // omp_priv = <expr>
1429+
};
1430+
14251431
/// DeclContext - This is used only as base class of specific decl types that
14261432
/// can act as declaration contexts. These decls are (only the top classes
14271433
/// that directly derive from DeclContext are mentioned, not their subclasses):

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,7 @@ class OMPThreadPrivateDecl final : public OMPDeclarativeDirective<Decl> {
171171
class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
172172
// This class stores some data in DeclContext::OMPDeclareReductionDeclBits
173173
// to save some space. Use the provided accessors to access it.
174-
public:
175-
enum InitKind {
176-
CallInit, // Initialized by function call.
177-
DirectInit, // omp_priv(<expr>)
178-
CopyInit // omp_priv = <expr>
179-
};
180174

181-
private:
182175
friend class ASTDeclReader;
183176
/// Combiner for declare reduction construct.
184177
Expr *Combiner = nullptr;
@@ -239,8 +232,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
239232
Expr *getInitializer() { return Initializer; }
240233
const Expr *getInitializer() const { return Initializer; }
241234
/// Get initializer kind.
242-
InitKind getInitializerKind() const {
243-
return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind);
235+
OMPDeclareReductionInitKind getInitializerKind() const {
236+
return static_cast<OMPDeclareReductionInitKind>(
237+
OMPDeclareReductionDeclBits.InitializerKind);
244238
}
245239
/// Get Orig variable of the initializer.
246240
Expr *getInitOrig() { return Orig; }
@@ -249,9 +243,9 @@ class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
249243
Expr *getInitPriv() { return Priv; }
250244
const Expr *getInitPriv() const { return Priv; }
251245
/// Set initializer expression for the declare reduction construct.
252-
void setInitializer(Expr *E, InitKind IK) {
246+
void setInitializer(Expr *E, OMPDeclareReductionInitKind IK) {
253247
Initializer = E;
254-
OMPDeclareReductionDeclBits.InitializerKind = IK;
248+
OMPDeclareReductionDeclBits.InitializerKind = llvm::to_underlying(IK);
255249
}
256250
/// Set initializer Orig and Priv vars.
257251
void setInitializerData(Expr *OrigE, Expr *PrivE) {

clang/lib/AST/DeclOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ OMPDeclareReductionDecl::OMPDeclareReductionDecl(
104104
QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
105105
: ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
106106
PrevDeclInScope(PrevDeclInScope) {
107-
setInitializer(nullptr, CallInit);
107+
setInitializer(nullptr, OMPDeclareReductionInitKind::Call);
108108
}
109109

110110
void OMPDeclareReductionDecl::anchor() {}

clang/lib/AST/DeclPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,17 +1866,17 @@ void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
18661866
if (auto *Init = D->getInitializer()) {
18671867
Out << " initializer(";
18681868
switch (D->getInitializerKind()) {
1869-
case OMPDeclareReductionDecl::DirectInit:
1869+
case OMPDeclareReductionInitKind::Direct:
18701870
Out << "omp_priv(";
18711871
break;
1872-
case OMPDeclareReductionDecl::CopyInit:
1872+
case OMPDeclareReductionInitKind::Copy:
18731873
Out << "omp_priv = ";
18741874
break;
1875-
case OMPDeclareReductionDecl::CallInit:
1875+
case OMPDeclareReductionInitKind::Call:
18761876
break;
18771877
}
18781878
Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1879-
if (D->getInitializerKind() == OMPDeclareReductionDecl::DirectInit)
1879+
if (D->getInitializerKind() == OMPDeclareReductionInitKind::Direct)
18801880
Out << ")";
18811881
Out << ")";
18821882
}

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,13 +2078,13 @@ void TextNodeDumper::VisitOMPDeclareReductionDecl(
20782078
OS << " initializer";
20792079
dumpPointer(Initializer);
20802080
switch (D->getInitializerKind()) {
2081-
case OMPDeclareReductionDecl::DirectInit:
2081+
case OMPDeclareReductionInitKind::Direct:
20822082
OS << " omp_priv = ";
20832083
break;
2084-
case OMPDeclareReductionDecl::CopyInit:
2084+
case OMPDeclareReductionInitKind::Copy:
20852085
OS << " omp_priv ()";
20862086
break;
2087-
case OMPDeclareReductionDecl::CallInit:
2087+
case OMPDeclareReductionInitKind::Call:
20882088
break;
20892089
}
20902090
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ void CGOpenMPRuntime::emitUserDefinedReduction(
11331133
if (const Expr *Init = D->getInitializer()) {
11341134
Initializer = emitCombinerOrInitializer(
11351135
CGM, D->getType(),
1136-
D->getInitializerKind() == OMPDeclareReductionDecl::CallInit ? Init
1136+
D->getInitializerKind() == OMPDeclareReductionInitKind::Call ? Init
11371137
: nullptr,
11381138
cast<VarDecl>(cast<DeclRefExpr>(D->getInitOrig())->getDecl()),
11391139
cast<VarDecl>(cast<DeclRefExpr>(D->getInitPriv())->getDecl()),

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22611,12 +22611,12 @@ void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer,
2261122611
PopFunctionScopeInfo();
2261222612

2261322613
if (Initializer != nullptr) {
22614-
DRD->setInitializer(Initializer, OMPDeclareReductionDecl::CallInit);
22614+
DRD->setInitializer(Initializer, OMPDeclareReductionInitKind::Call);
2261522615
} else if (OmpPrivParm->hasInit()) {
2261622616
DRD->setInitializer(OmpPrivParm->getInit(),
2261722617
OmpPrivParm->isDirectInit()
22618-
? OMPDeclareReductionDecl::DirectInit
22619-
: OMPDeclareReductionDecl::CopyInit);
22618+
? OMPDeclareReductionInitKind::Direct
22619+
: OMPDeclareReductionInitKind::Copy);
2262022620
} else {
2262122621
DRD->setInvalidDecl();
2262222622
}

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,7 +3627,7 @@ Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl(
36273627
SemaRef.CurrentInstantiationScope->InstantiatedLocal(
36283628
cast<DeclRefExpr>(D->getInitPriv())->getDecl(),
36293629
cast<DeclRefExpr>(NewDRD->getInitPriv())->getDecl());
3630-
if (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit) {
3630+
if (D->getInitializerKind() == OMPDeclareReductionInitKind::Call) {
36313631
SubstInitializer = SemaRef.SubstExpr(Init, TemplateArgs).get();
36323632
} else {
36333633
auto *OldPrivParm =
@@ -3642,9 +3642,9 @@ Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl(
36423642
}
36433643
IsCorrect = IsCorrect && SubstCombiner &&
36443644
(!Init ||
3645-
(D->getInitializerKind() == OMPDeclareReductionDecl::CallInit &&
3645+
(D->getInitializerKind() == OMPDeclareReductionInitKind::Call &&
36463646
SubstInitializer) ||
3647-
(D->getInitializerKind() != OMPDeclareReductionDecl::CallInit &&
3647+
(D->getInitializerKind() != OMPDeclareReductionInitKind::Call &&
36483648
!SubstInitializer));
36493649

36503650
(void)SemaRef.ActOnOpenMPDeclareReductionDirectiveEnd(

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3005,7 +3005,7 @@ void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
30053005
Expr *Priv = Record.readExpr();
30063006
D->setInitializerData(Orig, Priv);
30073007
Expr *Init = Record.readExpr();
3008-
auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt());
3008+
auto IK = static_cast<OMPDeclareReductionInitKind>(Record.readInt());
30093009
D->setInitializer(Init, IK);
30103010
D->PrevDeclInScope = readDeclID();
30113011
}

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
19721972
Record.AddStmt(D->getInitOrig());
19731973
Record.AddStmt(D->getInitPriv());
19741974
Record.AddStmt(D->getInitializer());
1975-
Record.push_back(D->getInitializerKind());
1975+
Record.push_back(llvm::to_underlying(D->getInitializerKind()));
19761976
Record.AddDeclRef(D->getPrevDeclInScope());
19771977
Code = serialization::DECL_OMP_DECLARE_REDUCTION;
19781978
}

0 commit comments

Comments
 (0)