[OPENMP50]Simplify processing of context selector scores.
If the context selector score was not specified, its value must be set
to 0. Simplify the processing of unspecified scores + save memory in
attribute representation.
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 514457d..b48c52d 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11044,41 +11044,11 @@
}
static bool greaterCtxScore(ASTContext &Ctx, const Expr *LHS, const Expr *RHS) {
- // If both scores are unknown, choose the very first one.
- if (!LHS && !RHS)
- return true;
- // If only one is known, return this one.
- if (LHS && !RHS)
- return true;
- if (!LHS && RHS)
- return false;
llvm::APSInt LHSVal = LHS->EvaluateKnownConstInt(Ctx);
llvm::APSInt RHSVal = RHS->EvaluateKnownConstInt(Ctx);
return llvm::APSInt::compareValues(LHSVal, RHSVal) >= 0;
}
-namespace {
-/// Comparator for the priority queue for context selector.
-class OMPDeclareVariantAttrComparer
- : public std::greater<const OMPDeclareVariantAttr *> {
-private:
- ASTContext &Ctx;
-
-public:
- OMPDeclareVariantAttrComparer(ASTContext &Ctx) : Ctx(Ctx) {}
- bool operator()(const OMPDeclareVariantAttr *LHS,
- const OMPDeclareVariantAttr *RHS) const {
- const Expr *LHSExpr = nullptr;
- const Expr *RHSExpr = nullptr;
- if (LHS->getCtxScore() == OMPDeclareVariantAttr::ScoreSpecified)
- LHSExpr = LHS->getScore();
- if (RHS->getCtxScore() == OMPDeclareVariantAttr::ScoreSpecified)
- RHSExpr = RHS->getScore();
- return greaterCtxScore(Ctx, LHSExpr, RHSExpr);
- }
-};
-} // anonymous namespace
-
/// Finds the variant function that matches current context with its context
/// selector.
static const FunctionDecl *getDeclareVariantFunction(ASTContext &Ctx,
@@ -11088,13 +11058,7 @@
// Iterate through all DeclareVariant attributes and check context selectors.
auto &&Comparer = [&Ctx](const OMPDeclareVariantAttr *LHS,
const OMPDeclareVariantAttr *RHS) {
- const Expr *LHSExpr = nullptr;
- const Expr *RHSExpr = nullptr;
- if (LHS->getCtxScore() == OMPDeclareVariantAttr::ScoreSpecified)
- LHSExpr = LHS->getScore();
- if (RHS->getCtxScore() == OMPDeclareVariantAttr::ScoreSpecified)
- RHSExpr = RHS->getScore();
- return greaterCtxScore(Ctx, LHSExpr, RHSExpr);
+ return greaterCtxScore(Ctx, LHS->getScore(), RHS->getScore());
};
const OMPDeclareVariantAttr *TopMostAttr = nullptr;
for (const auto *A : FD->specific_attrs<OMPDeclareVariantAttr>()) {
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 816e888..e59b83d 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -800,13 +800,8 @@
SmallString<16> Buffer;
StringRef SelectorName =
P.getPreprocessor().getSpelling(P.getCurToken(), Buffer);
- OMPDeclareVariantAttr::ScoreType ScoreKind =
- OMPDeclareVariantAttr::ScoreUnknown;
- (void)OMPDeclareVariantAttr::ConvertStrToScoreType(SelectorName, ScoreKind);
- if (ScoreKind == OMPDeclareVariantAttr::ScoreUnknown)
+ if (!SelectorName.equals("score"))
return ScoreExpr;
- assert(ScoreKind == OMPDeclareVariantAttr::ScoreSpecified &&
- "Expected \"score\" clause.");
(void)P.ConsumeToken();
SourceLocation RLoc;
ScoreExpr = P.ParseOpenMPParensExpr(SelectorName, RLoc);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 9055eff..7ed582f 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5197,9 +5197,7 @@
Data.Ctx == OMPDeclareVariantAttr::CtxUnknown)
return;
Expr *Score = nullptr;
- OMPDeclareVariantAttr::ScoreType ST = OMPDeclareVariantAttr::ScoreUnknown;
if (Data.CtxScore.isUsable()) {
- ST = OMPDeclareVariantAttr::ScoreSpecified;
Score = Data.CtxScore.get();
if (!Score->isTypeDependent() && !Score->isValueDependent() &&
!Score->isInstantiationDependent() &&
@@ -5209,9 +5207,11 @@
if (ICE.isInvalid())
return;
}
+ } else {
+ Score = ActOnIntegerConstant(SourceLocation(), 0).get();
}
auto *NewAttr = OMPDeclareVariantAttr::CreateImplicit(
- Context, VariantRef, Score, Data.CtxSet, ST, Data.Ctx,
+ Context, VariantRef, Score, Data.CtxSet, Data.Ctx,
Data.ImplVendors.begin(), Data.ImplVendors.size(), SR);
FD->addAttr(NewAttr);
}