Skip to content

Commit a68f35a

Browse files
committed
[flang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139131)
The OpenMP version is stored in LangOptions in SemanticsContext. Use the fallback version where SemanticsContext is unavailable (mostly in case of debug dumps). RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507 Reland with a fix for build break in f18-parse-demo.
1 parent dbe5613 commit a68f35a

File tree

16 files changed

+102
-58
lines changed

16 files changed

+102
-58
lines changed

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ void OpenMPCounterVisitor::Post(const OmpScheduleClause::Kind &c) {
267267
"type=" + std::string{OmpScheduleClause::EnumToString(c)} + ";";
268268
}
269269
void OpenMPCounterVisitor::Post(const OmpDirectiveNameModifier &c) {
270-
clauseDetails +=
271-
"name_modifier=" + llvm::omp::getOpenMPDirectiveName(c.v).str() + ";";
270+
clauseDetails += "name_modifier=" +
271+
llvm::omp::getOpenMPDirectiveName(c.v, llvm::omp::FallbackVersion).str() +
272+
";";
272273
}
273274
void OpenMPCounterVisitor::Post(const OmpClause &c) {
274275
PostClauseCommon(normalize_clause_name(c.source.ToString()));

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "flang/Common/idioms.h"
1818
#include "flang/Common/indirection.h"
1919
#include "flang/Support/Fortran.h"
20+
#include "llvm/Frontend/OpenMP/OMP.h"
2021
#include "llvm/Support/raw_ostream.h"
2122
#include <string>
2223
#include <type_traits>
@@ -545,8 +546,8 @@ class ParseTreeDumper {
545546
NODE(parser, OmpBeginSectionsDirective)
546547
NODE(parser, OmpBlockDirective)
547548
static std::string GetNodeName(const llvm::omp::Directive &x) {
548-
return llvm::Twine(
549-
"llvm::omp::Directive = ", llvm::omp::getOpenMPDirectiveName(x))
549+
return llvm::Twine("llvm::omp::Directive = ",
550+
llvm::omp::getOpenMPDirectiveName(x, llvm::omp::FallbackVersion))
550551
.str();
551552
}
552553
NODE(parser, OmpClause)

flang/include/flang/Parser/unparse.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace llvm {
1818
class raw_ostream;
1919
}
2020

21+
namespace Fortran::common {
22+
class LangOptions;
23+
}
24+
2125
namespace Fortran::evaluate {
2226
struct GenericExprWrapper;
2327
struct GenericAssignmentWrapper;
@@ -47,15 +51,18 @@ struct AnalyzedObjectsAsFortran {
4751
// Converts parsed program (or fragment) to out as Fortran.
4852
template <typename A>
4953
void Unparse(llvm::raw_ostream &out, const A &root,
50-
Encoding encoding = Encoding::UTF_8, bool capitalizeKeywords = true,
51-
bool backslashEscapes = true, preStatementType *preStatement = nullptr,
54+
const common::LangOptions &langOpts, Encoding encoding = Encoding::UTF_8,
55+
bool capitalizeKeywords = true, bool backslashEscapes = true,
56+
preStatementType *preStatement = nullptr,
5257
AnalyzedObjectsAsFortran * = nullptr);
5358

5459
extern template void Unparse(llvm::raw_ostream &out, const Program &program,
55-
Encoding encoding, bool capitalizeKeywords, bool backslashEscapes,
60+
const common::LangOptions &langOpts, Encoding encoding,
61+
bool capitalizeKeywords, bool backslashEscapes,
5662
preStatementType *preStatement, AnalyzedObjectsAsFortran *);
5763
extern template void Unparse(llvm::raw_ostream &out, const Expr &expr,
58-
Encoding encoding, bool capitalizeKeywords, bool backslashEscapes,
64+
const common::LangOptions &langOpts, Encoding encoding,
65+
bool capitalizeKeywords, bool backslashEscapes,
5966
preStatementType *preStatement, AnalyzedObjectsAsFortran *);
6067
} // namespace Fortran::parser
6168

flang/include/flang/Semantics/unparse-with-symbols.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ namespace llvm {
1616
class raw_ostream;
1717
}
1818

19+
namespace Fortran::common {
20+
class LangOptions;
21+
}
22+
1923
namespace Fortran::parser {
2024
struct Program;
2125
}
2226

2327
namespace Fortran::semantics {
2428
class SemanticsContext;
2529
void UnparseWithSymbols(llvm::raw_ostream &, const parser::Program &,
30+
const common::LangOptions &,
2631
parser::Encoding encoding = parser::Encoding::UTF_8);
2732
void UnparseWithModules(llvm::raw_ostream &, SemanticsContext &,
2833
const parser::Program &,

flang/lib/Frontend/ParserActions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void debugUnparseNoSema(CompilerInstance &ci, llvm::raw_ostream &out) {
119119
auto &parseTree{ci.getParsing().parseTree()};
120120

121121
// TODO: Options should come from CompilerInvocation
122-
Unparse(out, *parseTree,
122+
Unparse(out, *parseTree, ci.getInvocation().getLangOpts(),
123123
/*encoding=*/parser::Encoding::UTF_8,
124124
/*capitalizeKeywords=*/true, /*backslashEscapes=*/false,
125125
/*preStatement=*/nullptr,
@@ -131,6 +131,7 @@ void debugUnparseWithSymbols(CompilerInstance &ci) {
131131
auto &parseTree{*ci.getParsing().parseTree()};
132132

133133
semantics::UnparseWithSymbols(llvm::outs(), parseTree,
134+
ci.getInvocation().getLangOpts(),
134135
/*encoding=*/parser::Encoding::UTF_8);
135136
}
136137

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ void ClauseProcessor::processTODO(mlir::Location currentLocation,
200200
auto checkUnhandledClause = [&](llvm::omp::Clause id, const auto *x) {
201201
if (!x)
202202
return;
203+
unsigned version = semaCtx.langOptions().OpenMPVersion;
203204
TODO(currentLocation,
204205
"Unhandled clause " + llvm::omp::getOpenMPClauseName(id).upper() +
205-
" in " + llvm::omp::getOpenMPDirectiveName(directive).upper() +
206+
" in " +
207+
llvm::omp::getOpenMPDirectiveName(directive, version).upper() +
206208
" construct");
207209
};
208210

flang/lib/Lower/OpenMP/Decomposer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct ConstructDecomposition {
7070
namespace Fortran::lower::omp {
7171
LLVM_DUMP_METHOD llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
7272
const UnitConstruct &uc) {
73-
os << llvm::omp::getOpenMPDirectiveName(uc.id);
73+
os << llvm::omp::getOpenMPDirectiveName(uc.id, llvm::omp::FallbackVersion);
7474
for (auto [index, clause] : llvm::enumerate(uc.clauses)) {
7575
os << (index == 0 ? '\t' : ' ');
7676
os << llvm::omp::getOpenMPClauseName(clause.id);

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,9 +3754,11 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
37543754
item);
37553755
break;
37563756
case llvm::omp::Directive::OMPD_tile:
3757-
case llvm::omp::Directive::OMPD_unroll:
3757+
case llvm::omp::Directive::OMPD_unroll: {
3758+
unsigned version = semaCtx.langOptions().OpenMPVersion;
37583759
TODO(loc, "Unhandled loop directive (" +
3759-
llvm::omp::getOpenMPDirectiveName(dir) + ")");
3760+
llvm::omp::getOpenMPDirectiveName(dir, version) + ")");
3761+
}
37603762
// case llvm::omp::Directive::OMPD_workdistribute:
37613763
case llvm::omp::Directive::OMPD_workshare:
37623764
newOp = genWorkshareOp(converter, symTable, stmtCtx, semaCtx, eval, loc,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ OmpDirectiveNameParser::directives() const {
125125
void OmpDirectiveNameParser::initTokens(NameWithId *table) const {
126126
for (size_t i{0}, e{llvm::omp::Directive_enumSize}; i != e; ++i) {
127127
auto id{static_cast<llvm::omp::Directive>(i)};
128-
llvm::StringRef name{llvm::omp::getOpenMPDirectiveName(id)};
128+
llvm::StringRef name{
129+
llvm::omp::getOpenMPDirectiveName(id, llvm::omp::FallbackVersion)};
129130
table[i] = std::make_pair(name.str(), id);
130131
}
131132
// Sort the table with respect to the directive name length in a descending

flang/lib/Parser/parse-tree.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flang/Common/indirection.h"
1212
#include "flang/Parser/tools.h"
1313
#include "flang/Parser/user-state.h"
14+
#include "llvm/Frontend/OpenMP/OMP.h"
1415
#include "llvm/Support/raw_ostream.h"
1516
#include <algorithm>
1617

@@ -305,7 +306,9 @@ std::string OmpTraitSelectorName::ToString() const {
305306
return std::string(EnumToString(v));
306307
},
307308
[&](llvm::omp::Directive d) {
308-
return llvm::omp::getOpenMPDirectiveName(d).str();
309+
return llvm::omp::getOpenMPDirectiveName(
310+
d, llvm::omp::FallbackVersion)
311+
.str();
309312
},
310313
[&](const std::string &s) { //
311314
return s;

0 commit comments

Comments
 (0)