Skip to content

Commit 6094080

Browse files
authored
[clang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139115)
The OpenMP version is stored in language options in ASTContext. If the context is not available, use the fallback version. RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
1 parent 4b29ee4 commit 6094080

File tree

8 files changed

+212
-123
lines changed

8 files changed

+212
-123
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9475,15 +9475,17 @@ class ConstOMPClauseVisitor :
94759475
class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
94769476
raw_ostream &OS;
94779477
const PrintingPolicy &Policy;
9478+
unsigned Version;
94789479

94799480
/// Process clauses with list of variables.
94809481
template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
94819482
/// Process motion clauses.
94829483
template <typename T> void VisitOMPMotionClause(T *Node);
94839484

94849485
public:
9485-
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
9486-
: OS(OS), Policy(Policy) {}
9486+
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy,
9487+
unsigned OpenMPVersion)
9488+
: OS(OS), Policy(Policy), Version(OpenMPVersion) {}
94879489

94889490
#define GEN_CLANG_CLAUSE_CLASS
94899491
#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);

clang/lib/AST/DeclPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
18271827
Out << ")";
18281828
}
18291829
if (!D->clauselist_empty()) {
1830-
OMPClausePrinter Printer(Out, Policy);
1830+
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
18311831
for (OMPClause *C : D->clauselists()) {
18321832
Out << " ";
18331833
Printer.Visit(C);
@@ -1838,7 +1838,7 @@ void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
18381838
void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
18391839
Out << "#pragma omp requires ";
18401840
if (!D->clauselist_empty()) {
1841-
OMPClausePrinter Printer(Out, Policy);
1841+
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
18421842
for (auto I = D->clauselist_begin(), E = D->clauselist_end(); I != E; ++I)
18431843
Printer.Visit(*I);
18441844
}
@@ -1891,7 +1891,7 @@ void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
18911891
Out << D->getVarName();
18921892
Out << ")";
18931893
if (!D->clauselist_empty()) {
1894-
OMPClausePrinter Printer(Out, Policy);
1894+
OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
18951895
for (auto *C : D->clauselists()) {
18961896
Out << " ";
18971897
Printer.Visit(C);

clang/lib/AST/OpenMPClause.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ OMPThreadLimitClause *OMPThreadLimitClause::CreateEmpty(const ASTContext &C,
18211821
void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) {
18221822
OS << "if(";
18231823
if (Node->getNameModifier() != OMPD_unknown)
1824-
OS << getOpenMPDirectiveName(Node->getNameModifier()) << ": ";
1824+
OS << getOpenMPDirectiveName(Node->getNameModifier(), Version) << ": ";
18251825
Node->getCondition()->printPretty(OS, nullptr, Policy, 0);
18261826
OS << ")";
18271827
}
@@ -2049,7 +2049,7 @@ void OMPClausePrinter::VisitOMPAbsentClause(OMPAbsentClause *Node) {
20492049
for (auto &D : Node->getDirectiveKinds()) {
20502050
if (!First)
20512051
OS << ", ";
2052-
OS << getOpenMPDirectiveName(D);
2052+
OS << getOpenMPDirectiveName(D, Version);
20532053
First = false;
20542054
}
20552055
OS << ")";
@@ -2067,7 +2067,7 @@ void OMPClausePrinter::VisitOMPContainsClause(OMPContainsClause *Node) {
20672067
for (auto &D : Node->getDirectiveKinds()) {
20682068
if (!First)
20692069
OS << ", ";
2070-
OS << getOpenMPDirectiveName(D);
2070+
OS << getOpenMPDirectiveName(D, Version);
20712071
First = false;
20722072
}
20732073
OS << ")";

clang/lib/AST/StmtPrinter.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,9 @@ void StmtPrinter::VisitOMPCanonicalLoop(OMPCanonicalLoop *Node) {
737737

738738
void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S,
739739
bool ForceNoStmt) {
740-
OMPClausePrinter Printer(OS, Policy);
740+
unsigned OpenMPVersion =
741+
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
742+
OMPClausePrinter Printer(OS, Policy, OpenMPVersion);
741743
ArrayRef<OMPClause *> Clauses = S->clauses();
742744
for (auto *Clause : Clauses)
743745
if (Clause && !Clause->isImplicit()) {
@@ -964,14 +966,18 @@ void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) {
964966

965967
void StmtPrinter::VisitOMPCancellationPointDirective(
966968
OMPCancellationPointDirective *Node) {
969+
unsigned OpenMPVersion =
970+
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
967971
Indent() << "#pragma omp cancellation point "
968-
<< getOpenMPDirectiveName(Node->getCancelRegion());
972+
<< getOpenMPDirectiveName(Node->getCancelRegion(), OpenMPVersion);
969973
PrintOMPExecutableDirective(Node);
970974
}
971975

972976
void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) {
977+
unsigned OpenMPVersion =
978+
Context ? Context->getLangOpts().OpenMP : llvm::omp::FallbackVersion;
973979
Indent() << "#pragma omp cancel "
974-
<< getOpenMPDirectiveName(Node->getCancelRegion());
980+
<< getOpenMPDirectiveName(Node->getCancelRegion(), OpenMPVersion);
975981
PrintOMPExecutableDirective(Node);
976982
}
977983

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,8 @@ void clang::getOpenMPCaptureRegions(
850850
case OMPD_master:
851851
return false;
852852
default:
853-
llvm::errs() << getOpenMPDirectiveName(LKind) << '\n';
853+
llvm::errs() << getOpenMPDirectiveName(LKind, llvm::omp::FallbackVersion)
854+
<< '\n';
854855
llvm_unreachable("Unexpected directive");
855856
}
856857
return false;

0 commit comments

Comments
 (0)