[clang] [clang][OpenMP] Simplify check for repeated clauses (PR #93611)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 13:50:26 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
The `FirstClauses` is a vector of pointer-bool pairs, and the pointer part of the pair is never used. Replace the vector with std::bitset, and rename it to `SeenClauses` to make the purpose of it a bit clearer.
---
Full diff: https://github.com/llvm/llvm-project/pull/93611.diff
1 Files Affected:
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+19-30)
``````````diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e959dd6378f46..02fccd3c413fb 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -28,6 +28,7 @@
#include "llvm/ADT/UniqueVector.h"
#include "llvm/Frontend/OpenMP/OMPAssume.h"
#include "llvm/Frontend/OpenMP/OMPContext.h"
+#include <bitset>
#include <optional>
using namespace clang;
@@ -1646,19 +1647,17 @@ bool Parser::parseOMPDeclareVariantMatchClause(SourceLocation Loc,
void Parser::ParseOpenMPClauses(OpenMPDirectiveKind DKind,
SmallVectorImpl<OMPClause *> &Clauses,
SourceLocation Loc) {
- SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
- llvm::omp::Clause_enumSize + 1>
- FirstClauses(llvm::omp::Clause_enumSize + 1);
+ std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
OpenMPClauseKind CKind = Tok.isAnnotation()
? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.OpenMP().StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(
- DKind, CKind, !FirstClauses[unsigned(CKind)].getInt());
+ DKind, CKind, !SeenClauses[unsigned(CKind)]);
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch);
- FirstClauses[unsigned(CKind)].setInt(true);
+ SeenClauses[unsigned(CKind)] = true;
if (Clause != nullptr)
Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) {
@@ -2114,19 +2113,17 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
/*AllowScopeSpecifier=*/true)) {
SmallVector<OMPClause *, 1> Clauses;
if (Tok.isNot(tok::annot_pragma_openmp_end)) {
- SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
- llvm::omp::Clause_enumSize + 1>
- FirstClauses(llvm::omp::Clause_enumSize + 1);
+ std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
OpenMPClauseKind CKind =
Tok.isAnnotation() ? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.OpenMP().StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(
- OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
+ OMPD_allocate, CKind, !SeenClauses[unsigned(CKind)]);
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch);
- FirstClauses[unsigned(CKind)].setInt(true);
+ SeenClauses[unsigned(CKind)] = true;
if (Clause != nullptr)
Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) {
@@ -2150,9 +2147,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
case OMPD_requires: {
SourceLocation StartLoc = ConsumeToken();
SmallVector<OMPClause *, 5> Clauses;
- SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
- llvm::omp::Clause_enumSize + 1>
- FirstClauses(llvm::omp::Clause_enumSize + 1);
+ std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
if (Tok.is(tok::annot_pragma_openmp_end)) {
Diag(Tok, diag::err_omp_expected_clause)
<< getOpenMPDirectiveName(OMPD_requires);
@@ -2164,10 +2159,10 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
: getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.OpenMP().StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(
- OMPD_requires, CKind, !FirstClauses[unsigned(CKind)].getInt());
+ OMPD_requires, CKind, !SeenClauses[unsigned(CKind)]);
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch);
- FirstClauses[unsigned(CKind)].setInt(true);
+ SeenClauses[unsigned(CKind)] = true;
if (Clause != nullptr)
Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) {
@@ -2510,9 +2505,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
ParsingOpenMPDirectiveRAII DirScope(*this);
ParenBraceBracketBalancer BalancerRAIIObj(*this);
SmallVector<OMPClause *, 5> Clauses;
- SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
- llvm::omp::Clause_enumSize + 1>
- FirstClauses(llvm::omp::Clause_enumSize + 1);
+ std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope;
SourceLocation Loc = ReadDirectiveWithinMetadirective
@@ -2717,19 +2710,17 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
/*AllowScopeSpecifier=*/false)) {
SmallVector<OMPClause *, 1> Clauses;
if (Tok.isNot(tok::annot_pragma_openmp_end)) {
- SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
- llvm::omp::Clause_enumSize + 1>
- FirstClauses(llvm::omp::Clause_enumSize + 1);
+ std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
while (Tok.isNot(tok::annot_pragma_openmp_end)) {
OpenMPClauseKind CKind =
Tok.isAnnotation() ? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.OpenMP().StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(
- OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
+ OMPD_allocate, CKind, !SeenClauses[unsigned(CKind)]);
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch);
- FirstClauses[unsigned(CKind)].setInt(true);
+ SeenClauses[unsigned(CKind)] = true;
if (Clause != nullptr)
Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) {
@@ -2927,12 +2918,10 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
Actions.OpenMP().StartOpenMPClause(CKind);
HasImplicitClause = false;
OMPClause *Clause = ParseOpenMPClause(
- DKind, CKind, !FirstClauses[unsigned(CKind)].getInt());
- FirstClauses[unsigned(CKind)].setInt(true);
- if (Clause) {
- FirstClauses[unsigned(CKind)].setPointer(Clause);
+ DKind, CKind, !SeenClauses[unsigned(CKind)]);
+ SeenClauses[unsigned(CKind)] = true;
+ if (Clause)
Clauses.push_back(Clause);
- }
// Skip ',' if any.
if (Tok.is(tok::comma))
@@ -2948,7 +2937,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
// If the depend or doacross clause is specified, the ordered construct
// is a stand-alone directive.
for (auto CK : {OMPC_depend, OMPC_doacross}) {
- if (FirstClauses[unsigned(CK)].getInt()) {
+ if (SeenClauses[unsigned(CK)]) {
if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
ParsedStmtContext()) {
Diag(Loc, diag::err_omp_immediate_directive)
@@ -2960,7 +2949,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
}
}
- if (DKind == OMPD_tile && !FirstClauses[unsigned(OMPC_sizes)].getInt()) {
+ if (DKind == OMPD_tile && !SeenClauses[unsigned(OMPC_sizes)]) {
Diag(Loc, diag::err_omp_required_clause)
<< getOpenMPDirectiveName(OMPD_tile) << "sizes";
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/93611
More information about the cfe-commits
mailing list