diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -8561,6 +8561,7 @@ child_range used_children() { return child_range(child_iterator(), child_iterator()); } + const_child_range used_children() const { return const_child_range(const_child_iterator(), const_child_iterator()); } @@ -8570,17 +8571,6 @@ } }; -/// This represents 'when' clause in the '#pragma omp ...' directive -/// -/// \code -/// #pragma omp metadirective when(user={condition(N<10)} : parallel for) \ -/// when(user={condition(N> 10)}: parallel)\ -/// \endcode -/// In this example directive '#pragma omp metadirective' has two 'when' -/// clauses with user defined conditions. - - - /// This class implements a simple visitor for OMPClause /// subclasses. @@ -8623,31 +8613,7 @@ template class ConstOMPClauseVisitor : public OMPClauseVisitorBase {}; - - -/* -class OMPClausePrinter final : public OMPClauseVisitor { - raw_ostream &OS; - const PrintingPolicy &Policy; - - /// Process clauses with list of variables. - template void VisitOMPClauseList(T *Node, char StartSym); - /// Process motion clauses. - template void VisitOMPMotionClause(T *Node); - -public: - OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy) - : OS(OS), Policy(Policy) {} - - // void VisitOMPWhenClause(OMPWhenClause *Node); - -#define GEN_CLANG_CLAUSE_CLASS -#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S); -#include "llvm/Frontend/OpenMP/OMP.inc" -}; - -*/ - + struct OMPTraitProperty { llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid; diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -5476,7 +5476,6 @@ Stmt *AssociatedStmt, Stmt *IfStmt); static OMPMetaDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); - Stmt *getIfStmt() const { return IfStmt; } static bool classof(const Stmt *T) { diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3286,12 +3286,15 @@ const llvm::function_ref & Callback, bool AllowScopeSpecifier); + /// Parses declarative or executable directive. /// /// \param StmtCtx The context in which we're parsing the directive. + /// StmtResult ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx); /// Parse clause for metadirective + /// /// \param Dkind Kind of current directive /// \param CKind Kind of current clause /// diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10683,10 +10683,16 @@ OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); - StmtResult ActOnOpenMPExecutableMetaDirective( // This might be needed later + + /// Called on '\#pragma omp metadirective' after parsing + /// + /// + /// \returns Statement for metadirective + StmtResult ActOnOpenMPExecutableMetaDirective( OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); + /// Called on well-formed '\#pragma omp parallel' after parsing /// of the associated statement. StmtResult ActOnOpenMPParallelDirective(ArrayRef Clauses, @@ -11132,7 +11138,6 @@ SourceLocation LParenLoc, SourceLocation EndLoc); /// Called on well-formed 'when' clause. - /// Abid OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, OpenMPDirectiveKind DKind, StmtResult Directive, SourceLocation StartLoc, diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -1609,7 +1609,6 @@ // OpenMP clauses printing methods //===----------------------------------------------------------------------===// - void OMPClausePrinter::VisitOMPWhenClause(OMPWhenClause *Node) { if (Node->getTI().Sets.size() == 0) { @@ -1671,7 +1670,6 @@ OS << ")}"; break; } - default: break; } diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -655,18 +655,13 @@ void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S, bool ForceNoStmt) { - - OMPClausePrinter Printer(OS, Policy); ArrayRef Clauses = S->clauses(); - for (auto *Clause : Clauses){ - + for (auto *Clause : Clauses){ if (Clause && !Clause->isImplicit()) { OS << ' '; - Printer.Visit(Clause); - + Printer.Visit(Clause); if (dyn_cast(S)){ - OMPWhenClause *c = dyn_cast(Clause); if (c!=NULL){ if (c->getDKind() != llvm::omp::OMPD_unknown){ @@ -683,8 +678,7 @@ PrintStmt(S->getRawStmt()); } -void StmtPrinter::VisitOMPMetaDirective(OMPMetaDirective *Node) { - +void StmtPrinter::VisitOMPMetaDirective(OMPMetaDirective *Node) { Indent() << "#pragma omp metadirective"; PrintOMPExecutableDirective(Node); } diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2431,7 +2431,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { // need to check about the following - static bool ReadDirectiveWithinMetadirective = false; // what is this? + static bool ReadDirectiveWithinMetadirective = false; if (!ReadDirectiveWithinMetadirective) assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) && "Not an OpenMP directive!"); @@ -2553,7 +2553,7 @@ ParseScope OMPDirectiveScope(this, ScopeFlags); Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); - while(Tok.isNot(tok::annot_pragma_openmp_end)){ + while(Tok.isNot(tok::annot_pragma_openmp_end)){ OpenMPClauseKind CKind = Tok.isAnnotation() ? OMPC_unknown @@ -3101,7 +3101,6 @@ ErrorFound = true; WrongDirective = true; } - // Check if clause is not allowed if (CKind == OMPC_unknown) { Diag(Tok, diag::err_omp_unexpected_clause) @@ -3109,9 +3108,8 @@ ErrorFound = true; WrongDirective = true; } - - if (CKind == OMPC_default || CKind == OMPC_when) { + if (CKind == OMPC_default || CKind == OMPC_when) { SourceLocation Loc = ConsumeToken(); SourceLocation DelimLoc; // Parse '('. @@ -3122,6 +3120,7 @@ return nullptr; OMPTraitInfo &TI = Actions.getASTContext().getNewOMPTraitInfo(); + if (CKind == OMPC_when) { // parse and get condition expression to pass to the When clause parseOMPContextSelectors(Loc, TI); @@ -3156,46 +3155,41 @@ int paren = 0; - while (Tok.isNot(tok::r_paren) || paren != 0) { - if (Tok.is(tok::l_paren)) + while (Tok.isNot(tok::r_paren) || paren != 0) { + if (Tok.is(tok::l_paren)) paren++; - if (Tok.is(tok::r_paren)) + if (Tok.is(tok::r_paren)) paren--; - OpenMPClauseKind CKind = Tok.isAnnotation() + OpenMPClauseKind CKind = Tok.isAnnotation() ? OMPC_unknown : getOpenMPClauseKind(PP.getSpelling(Tok)); - if (CKind == OMPC_unknown && + if (CKind == OMPC_unknown && !isAllowedClauseForDirective(DirKind, CKind, getLangOpts().OpenMP)) { Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind); ErrorFound = true; WrongDirective = true; - } + } - Actions.StartOpenMPClause(CKind); + Actions.StartOpenMPClause(CKind); - OMPClause *Clause = ParseOpenMPClause( + OMPClause *Clause = ParseOpenMPClause( DirKind, CKind, !FirstClauses[(unsigned)CKind].getInt()); - FirstClauses[(unsigned)CKind].setInt(true); - if (Clause) { + FirstClauses[(unsigned)CKind].setInt(true); + if (Clause) { FirstClauses[(unsigned)CKind].setPointer(Clause); Clauses.push_back(Clause); - } - - // Skip ',' if any. - if (Tok.is(tok::comma)) + } + // Skip ',' if any. + if (Tok.is(tok::comma)) ConsumeToken(); - Actions.EndOpenMPClause(); - - + Actions.EndOpenMPClause(); } - Actions.ActOnOpenMPRegionStart(DirKind, getCurScope()); ParsingOpenMPDirectiveRAII NormalScope(*this, /*Value=*/false); - /* Get Stmt and revert back */ TentativeParsingAction TPA(*this); while (Tok.isNot(tok::annot_pragma_openmp_end)) { @@ -3214,17 +3208,14 @@ AssociatedStmt = (Sema::CompoundScopeRAII(Actions), AStmt); AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); - + Directive = Actions.ActOnOpenMPExecutableDirective( DirKind, DirName, OMPD_unknown, llvm::makeArrayRef(Clauses), AssociatedStmt.get(), Loc, Tok.getLocation()); - - + Actions.EndOpenMPDSABlock(Directive.get()); OMPDirectiveScope.Exit(); - } - // Parse ')' T.consumeClose(); @@ -3238,12 +3229,10 @@ Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind); } - + return ErrorFound ? nullptr : Clause; } - - /// Parsing of OpenMP clauses. /// /// clause: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3931,7 +3931,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { switch (DKind) { - case OMPD_metadirective: // added + case OMPD_metadirective: case OMPD_parallel: case OMPD_parallel_for: case OMPD_parallel_for_simd: @@ -4341,7 +4341,6 @@ case OMPD_declare_variant: case OMPD_begin_declare_variant: case OMPD_end_declare_variant: - //case OMPD_metadirective: //llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: default: @@ -4523,8 +4522,7 @@ } StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, - ArrayRef Clauses) { - + ArrayRef Clauses) { handleDeclareVariantConstructTrait(DSAStack, DSAStack->getCurrentDirective(), /* ScopeEntry */ false); if (DSAStack->getCurrentDirective() == OMPD_atomic || @@ -5977,7 +5975,6 @@ llvm::SmallVector AllowedNameModifiers; switch (Kind) { - case OMPD_metadirective: Res = ActOnOpenMPMetaDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); @@ -7361,18 +7358,15 @@ AppendArgs.size(), SR); FD->addAttr(NewAttr); } -/// StmtResult Sema::ActOnOpenMPMetaDirective(ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, - SourceLocation EndLoc) { - + SourceLocation EndLoc) { if (!AStmt) return StmtError(); auto *CS = cast(AStmt); - // CS->getCapturedDecl()->setNothrow(); StmtResult IfStmt = StmtError(); @@ -7441,7 +7435,7 @@ break; } } - } //// + } if (WhenCondExpr == NULL) { if (ElseStmt != NULL) { @@ -7469,12 +7463,9 @@ } return OMPMetaDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, - IfStmt.get()); - + IfStmt.get()); } - -/// StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, @@ -14970,8 +14961,6 @@ return std::string(Out.str()); } -/// ActOnOpenMPWheClause --- Abid - OMPClause * Sema::ActOnOpenMPWhenClause(OMPTraitInfo &TI, OpenMPDirectiveKind DKind, StmtResult Directive, SourceLocation StartLoc, @@ -14980,9 +14969,6 @@ OMPWhenClause(TI, DKind, Directive.get(), StartLoc, LParenLoc, EndLoc); } - - - OMPClause *Sema::ActOnOpenMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -4793,7 +4793,6 @@ Captures, CaptureInits, CD, RD); CD->setBody(Res->getCapturedStmt()); - RD->completeDefinition(); return Res; diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPContext.h b/llvm/include/llvm/Frontend/OpenMP/OMPContext.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPContext.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPContext.h @@ -197,7 +197,6 @@ const SmallVectorImpl &VMIs, const OMPContext &Ctx, SmallVector> &A); -// new-- } // namespace omp template <> struct DenseMapInfo { diff --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp b/llvm/lib/Frontend/OpenMP/OMPContext.cpp --- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -19,7 +19,6 @@ #include "llvm/ADT/Triple.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" - #include #define DEBUG_TYPE "openmp-ir-builder" @@ -340,53 +339,36 @@ return Score; } -/// /// Takes \p VMI and \p Ctx and sort the /// scores using \p A void llvm::omp::getArrayVariantMatchForContext(const SmallVectorImpl &VMIs, const OMPContext &Ctx, SmallVector> &A){ - - //APInt BestScore(64, 0); - APInt Score (64, 0); - llvm::DenseMap m; - - /*for (unsigned u = 0, e = VMIs.size(); u < e; ++u) { - const VariantMatchInfo &VMI = VMIs[u]; - SmallVector ConstructMatches; - APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches); - m.insert({u, Score}); - } - - */ - - for (unsigned u = 0, e = VMIs.size(); u < e; ++u) { - const VariantMatchInfo &VMI = VMIs[u]; - - SmallVector ConstructMatches; - // If the variant is not applicable its not the best. - if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches, + APInt Score (64, 0); + llvm::DenseMap m; + + for (unsigned u = 0, e = VMIs.size(); u < e; ++u) { + const VariantMatchInfo &VMI = VMIs[u]; + + SmallVector ConstructMatches; + // If the variant is not applicable its not the best. + if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches, /* DeviceSetOnly */ false)){ - Score = 0; - m.insert({u, Score}); - continue; - } + Score = 0; + m.insert({u, Score}); + continue;} - // Check if its clearly not the best. - Score = getVariantMatchScore(VMI, Ctx, ConstructMatches); + // Check if its clearly not the best. + Score = getVariantMatchScore(VMI, Ctx, ConstructMatches); m.insert({u, Score}); - } + } - for (auto& it : m) - A.push_back(it); + for (auto& it : m) A.push_back(it); - std::sort(A.begin(), A.end(), [] (std::pair&a, + std::sort(A.begin(), A.end(), [] (std::pair&a, std::pair&b){ - return a.second.ugt(b.second); - }); + return a.second.ugt(b.second);}); } - - int llvm::omp::getBestVariantMatchForContext( const SmallVectorImpl &VMIs, const OMPContext &Ctx) {