[flang-commits] [flang] f9e5579 - [flang][OpenMP] Convert unique clauses in ClauseProcessor (#81622)
via flang-commits
flang-commits at lists.llvm.org
Thu Mar 14 15:24:43 PDT 2024
Author: Krzysztof Parzyszek
Date: 2024-03-14T17:24:40-05:00
New Revision: f9e557961e993d9b9b4e4782d345cbb2c87e9361
URL: https://github.com/llvm/llvm-project/commit/f9e557961e993d9b9b4e4782d345cbb2c87e9361
DIFF: https://github.com/llvm/llvm-project/commit/f9e557961e993d9b9b4e4782d345cbb2c87e9361.diff
LOG: [flang][OpenMP] Convert unique clauses in ClauseProcessor (#81622)
Temporarily rename old clause list to `clauses2`, old clause iterator to
`ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects, modify
all handlers to operate on 'omp::clause::xyz` equivalents.
[Clause representation 2/6]
Added:
Modified:
flang/lib/Lower/OpenMP/ClauseProcessor.cpp
flang/lib/Lower/OpenMP/ClauseProcessor.h
flang/lib/Lower/OpenMP/Clauses.cpp
flang/lib/Lower/OpenMP/Clauses.h
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index a41f8312a28c9e..9987cd73fc7670 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "ClauseProcessor.h"
+#include "Clauses.h"
#include "flang/Lower/PFTBuilder.h"
#include "flang/Parser/tools.h"
@@ -30,64 +31,55 @@ static void checkMapType(mlir::Location location, mlir::Type type) {
}
static mlir::omp::ScheduleModifier
-translateScheduleModifier(const Fortran::parser::OmpScheduleModifierType &m) {
- switch (m.v) {
- case Fortran::parser::OmpScheduleModifierType::ModType::Monotonic:
+translateScheduleModifier(const omp::clause::Schedule::ModType &m) {
+ switch (m) {
+ case omp::clause::Schedule::ModType::Monotonic:
return mlir::omp::ScheduleModifier::monotonic;
- case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
+ case omp::clause::Schedule::ModType::Nonmonotonic:
return mlir::omp::ScheduleModifier::nonmonotonic;
- case Fortran::parser::OmpScheduleModifierType::ModType::Simd:
+ case omp::clause::Schedule::ModType::Simd:
return mlir::omp::ScheduleModifier::simd;
}
return mlir::omp::ScheduleModifier::none;
}
static mlir::omp::ScheduleModifier
-getScheduleModifier(const Fortran::parser::OmpScheduleClause &x) {
- const auto &modifier =
- std::get<std::optional<Fortran::parser::OmpScheduleModifier>>(x.t);
+getScheduleModifier(const omp::clause::Schedule &clause) {
+ using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
+ const auto &modifier = std::get<std::optional<ScheduleModifier>>(clause.t);
// The input may have the modifier any order, so we look for one that isn't
// SIMD. If modifier is not set at all, fall down to the bottom and return
// "none".
if (modifier) {
- const auto &modType1 =
- std::get<Fortran::parser::OmpScheduleModifier::Modifier1>(modifier->t);
- if (modType1.v.v ==
- Fortran::parser::OmpScheduleModifierType::ModType::Simd) {
- const auto &modType2 = std::get<
- std::optional<Fortran::parser::OmpScheduleModifier::Modifier2>>(
- modifier->t);
- if (modType2 &&
- modType2->v.v !=
- Fortran::parser::OmpScheduleModifierType::ModType::Simd)
- return translateScheduleModifier(modType2->v);
-
+ using ModType = omp::clause::Schedule::ModType;
+ const auto &modType1 = std::get<ModType>(modifier->t);
+ if (modType1 == ModType::Simd) {
+ const auto &modType2 = std::get<std::optional<ModType>>(modifier->t);
+ if (modType2 && *modType2 != ModType::Simd)
+ return translateScheduleModifier(*modType2);
return mlir::omp::ScheduleModifier::none;
}
- return translateScheduleModifier(modType1.v);
+ return translateScheduleModifier(modType1);
}
return mlir::omp::ScheduleModifier::none;
}
static mlir::omp::ScheduleModifier
-getSimdModifier(const Fortran::parser::OmpScheduleClause &x) {
- const auto &modifier =
- std::get<std::optional<Fortran::parser::OmpScheduleModifier>>(x.t);
+getSimdModifier(const omp::clause::Schedule &clause) {
+ using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
+ const auto &modifier = std::get<std::optional<ScheduleModifier>>(clause.t);
// Either of the two possible modifiers in the input can be the SIMD modifier,
// so look in either one, and return simd if we find one. Not found = return
// "none".
if (modifier) {
- const auto &modType1 =
- std::get<Fortran::parser::OmpScheduleModifier::Modifier1>(modifier->t);
- if (modType1.v.v == Fortran::parser::OmpScheduleModifierType::ModType::Simd)
+ using ModType = omp::clause::Schedule::ModType;
+ const auto &modType1 = std::get<ModType>(modifier->t);
+ if (modType1 == ModType::Simd)
return mlir::omp::ScheduleModifier::simd;
- const auto &modType2 = std::get<
- std::optional<Fortran::parser::OmpScheduleModifier::Modifier2>>(
- modifier->t);
- if (modType2 && modType2->v.v ==
- Fortran::parser::OmpScheduleModifierType::ModType::Simd)
+ const auto &modType2 = std::get<std::optional<ModType>>(modifier->t);
+ if (modType2 && *modType2 == ModType::Simd)
return mlir::omp::ScheduleModifier::simd;
}
return mlir::omp::ScheduleModifier::none;
@@ -141,21 +133,21 @@ genAllocateClause(Fortran::lower::AbstractConverter &converter,
genObjectList(ompObjectList, converter, allocateOperands);
}
-static mlir::omp::ClauseProcBindKindAttr genProcBindKindAttr(
- fir::FirOpBuilder &firOpBuilder,
- const Fortran::parser::OmpClause::ProcBind *procBindClause) {
+static mlir::omp::ClauseProcBindKindAttr
+genProcBindKindAttr(fir::FirOpBuilder &firOpBuilder,
+ const omp::clause::ProcBind &clause) {
mlir::omp::ClauseProcBindKind procBindKind;
- switch (procBindClause->v.v) {
- case Fortran::parser::OmpProcBindClause::Type::Master:
+ switch (clause.v) {
+ case omp::clause::ProcBind::Type::Master:
procBindKind = mlir::omp::ClauseProcBindKind::Master;
break;
- case Fortran::parser::OmpProcBindClause::Type::Close:
+ case omp::clause::ProcBind::Type::Close:
procBindKind = mlir::omp::ClauseProcBindKind::Close;
break;
- case Fortran::parser::OmpProcBindClause::Type::Spread:
+ case omp::clause::ProcBind::Type::Spread:
procBindKind = mlir::omp::ClauseProcBindKind::Spread;
break;
- case Fortran::parser::OmpProcBindClause::Type::Primary:
+ case omp::clause::ProcBind::Type::Primary:
procBindKind = mlir::omp::ClauseProcBindKind::Primary;
break;
}
@@ -253,9 +245,8 @@ bool ClauseProcessor::processCollapse(
}
std::int64_t collapseValue = 1l;
- if (auto *collapseClause = findUniqueClause<ClauseTy::Collapse>()) {
- const auto *expr = Fortran::semantics::GetExpr(collapseClause->v);
- collapseValue = Fortran::evaluate::ToInt64(*expr).value();
+ if (auto *clause = findUniqueClause<omp::clause::Collapse>()) {
+ collapseValue = Fortran::evaluate::ToInt64(clause->v).value();
found = true;
}
@@ -294,19 +285,19 @@ bool ClauseProcessor::processCollapse(
}
bool ClauseProcessor::processDefault() const {
- if (auto *defaultClause = findUniqueClause<ClauseTy::Default>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Default>()) {
// Private, Firstprivate, Shared, None
- switch (defaultClause->v.v) {
- case Fortran::parser::OmpDefaultClause::Type::Shared:
- case Fortran::parser::OmpDefaultClause::Type::None:
+ switch (clause->v) {
+ case omp::clause::Default::Type::Shared:
+ case omp::clause::Default::Type::None:
// Default clause with shared or none do not require any handling since
// Shared is the default behavior in the IR and None is only required
// for semantic checks.
break;
- case Fortran::parser::OmpDefaultClause::Type::Private:
+ case omp::clause::Default::Type::Private:
// TODO Support default(private)
break;
- case Fortran::parser::OmpDefaultClause::Type::Firstprivate:
+ case omp::clause::Default::Type::Firstprivate:
// TODO Support default(firstprivate)
break;
}
@@ -318,20 +309,17 @@ bool ClauseProcessor::processDefault() const {
bool ClauseProcessor::processDevice(Fortran::lower::StatementContext &stmtCtx,
mlir::Value &result) const {
const Fortran::parser::CharBlock *source = nullptr;
- if (auto *deviceClause = findUniqueClause<ClauseTy::Device>(&source)) {
+ if (auto *clause = findUniqueClause<omp::clause::Device>(&source)) {
mlir::Location clauseLocation = converter.genLocation(*source);
- if (auto deviceModifier = std::get<
- std::optional<Fortran::parser::OmpDeviceClause::DeviceModifier>>(
- deviceClause->v.t)) {
- if (deviceModifier ==
- Fortran::parser::OmpDeviceClause::DeviceModifier::Ancestor) {
+ if (auto deviceModifier =
+ std::get<std::optional<omp::clause::Device::DeviceModifier>>(
+ clause->t)) {
+ if (deviceModifier == omp::clause::Device::DeviceModifier::Ancestor) {
TODO(clauseLocation, "OMPD_target Device Modifier Ancestor");
}
}
- if (const auto *deviceExpr = Fortran::semantics::GetExpr(
- std::get<Fortran::parser::ScalarIntExpr>(deviceClause->v.t))) {
- result = fir::getBase(converter.genExprValue(*deviceExpr, stmtCtx));
- }
+ const auto &deviceExpr = std::get<omp::SomeExpr>(clause->t);
+ result = fir::getBase(converter.genExprValue(deviceExpr, stmtCtx));
return true;
}
return false;
@@ -339,16 +327,16 @@ bool ClauseProcessor::processDevice(Fortran::lower::StatementContext &stmtCtx,
bool ClauseProcessor::processDeviceType(
mlir::omp::DeclareTargetDeviceType &result) const {
- if (auto *deviceTypeClause = findUniqueClause<ClauseTy::DeviceType>()) {
+ if (auto *clause = findUniqueClause<omp::clause::DeviceType>()) {
// Case: declare target ... device_type(any | host | nohost)
- switch (deviceTypeClause->v.v) {
- case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+ switch (clause->v) {
+ case omp::clause::DeviceType::Type::Nohost:
result = mlir::omp::DeclareTargetDeviceType::nohost;
break;
- case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+ case omp::clause::DeviceType::Type::Host:
result = mlir::omp::DeclareTargetDeviceType::host;
break;
- case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+ case omp::clause::DeviceType::Type::Any:
result = mlir::omp::DeclareTargetDeviceType::any;
break;
}
@@ -360,12 +348,12 @@ bool ClauseProcessor::processDeviceType(
bool ClauseProcessor::processFinal(Fortran::lower::StatementContext &stmtCtx,
mlir::Value &result) const {
const Fortran::parser::CharBlock *source = nullptr;
- if (auto *finalClause = findUniqueClause<ClauseTy::Final>(&source)) {
+ if (auto *clause = findUniqueClause<omp::clause::Final>(&source)) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
mlir::Location clauseLocation = converter.genLocation(*source);
- mlir::Value finalVal = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(finalClause->v), stmtCtx));
+ mlir::Value finalVal =
+ fir::getBase(converter.genExprValue(clause->v, stmtCtx));
result = firOpBuilder.createConvert(clauseLocation,
firOpBuilder.getI1Type(), finalVal);
return true;
@@ -374,10 +362,9 @@ bool ClauseProcessor::processFinal(Fortran::lower::StatementContext &stmtCtx,
}
bool ClauseProcessor::processHint(mlir::IntegerAttr &result) const {
- if (auto *hintClause = findUniqueClause<ClauseTy::Hint>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Hint>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- const auto *expr = Fortran::semantics::GetExpr(hintClause->v);
- int64_t hintValue = *Fortran::evaluate::ToInt64(*expr);
+ int64_t hintValue = *Fortran::evaluate::ToInt64(clause->v);
result = firOpBuilder.getI64IntegerAttr(hintValue);
return true;
}
@@ -385,20 +372,19 @@ bool ClauseProcessor::processHint(mlir::IntegerAttr &result) const {
}
bool ClauseProcessor::processMergeable(mlir::UnitAttr &result) const {
- return markClauseOccurrence<ClauseTy::Mergeable>(result);
+ return markClauseOccurrence<omp::clause::Mergeable>(result);
}
bool ClauseProcessor::processNowait(mlir::UnitAttr &result) const {
- return markClauseOccurrence<ClauseTy::Nowait>(result);
+ return markClauseOccurrence<omp::clause::Nowait>(result);
}
bool ClauseProcessor::processNumTeams(Fortran::lower::StatementContext &stmtCtx,
mlir::Value &result) const {
// TODO Get lower and upper bounds for num_teams when parser is updated to
// accept both.
- if (auto *numTeamsClause = findUniqueClause<ClauseTy::NumTeams>()) {
- result = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(numTeamsClause->v), stmtCtx));
+ if (auto *clause = findUniqueClause<omp::clause::NumTeams>()) {
+ result = fir::getBase(converter.genExprValue(clause->v, stmtCtx));
return true;
}
return false;
@@ -406,23 +392,20 @@ bool ClauseProcessor::processNumTeams(Fortran::lower::StatementContext &stmtCtx,
bool ClauseProcessor::processNumThreads(
Fortran::lower::StatementContext &stmtCtx, mlir::Value &result) const {
- if (auto *numThreadsClause = findUniqueClause<ClauseTy::NumThreads>()) {
+ if (auto *clause = findUniqueClause<omp::clause::NumThreads>()) {
// OMPIRBuilder expects `NUM_THREADS` clause as a `Value`.
- result = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(numThreadsClause->v), stmtCtx));
+ result = fir::getBase(converter.genExprValue(clause->v, stmtCtx));
return true;
}
return false;
}
bool ClauseProcessor::processOrdered(mlir::IntegerAttr &result) const {
- if (auto *orderedClause = findUniqueClause<ClauseTy::Ordered>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Ordered>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
int64_t orderedClauseValue = 0l;
- if (orderedClause->v.has_value()) {
- const auto *expr = Fortran::semantics::GetExpr(orderedClause->v);
- orderedClauseValue = *Fortran::evaluate::ToInt64(*expr);
- }
+ if (clause->v.has_value())
+ orderedClauseValue = *Fortran::evaluate::ToInt64(*clause->v);
result = firOpBuilder.getI64IntegerAttr(orderedClauseValue);
return true;
}
@@ -431,9 +414,8 @@ bool ClauseProcessor::processOrdered(mlir::IntegerAttr &result) const {
bool ClauseProcessor::processPriority(Fortran::lower::StatementContext &stmtCtx,
mlir::Value &result) const {
- if (auto *priorityClause = findUniqueClause<ClauseTy::Priority>()) {
- result = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(priorityClause->v), stmtCtx));
+ if (auto *clause = findUniqueClause<omp::clause::Priority>()) {
+ result = fir::getBase(converter.genExprValue(clause->v, stmtCtx));
return true;
}
return false;
@@ -441,20 +423,19 @@ bool ClauseProcessor::processPriority(Fortran::lower::StatementContext &stmtCtx,
bool ClauseProcessor::processProcBind(
mlir::omp::ClauseProcBindKindAttr &result) const {
- if (auto *procBindClause = findUniqueClause<ClauseTy::ProcBind>()) {
+ if (auto *clause = findUniqueClause<omp::clause::ProcBind>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- result = genProcBindKindAttr(firOpBuilder, procBindClause);
+ result = genProcBindKindAttr(firOpBuilder, *clause);
return true;
}
return false;
}
bool ClauseProcessor::processSafelen(mlir::IntegerAttr &result) const {
- if (auto *safelenClause = findUniqueClause<ClauseTy::Safelen>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Safelen>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- const auto *expr = Fortran::semantics::GetExpr(safelenClause->v);
const std::optional<std::int64_t> safelenVal =
- Fortran::evaluate::ToInt64(*expr);
+ Fortran::evaluate::ToInt64(clause->v);
result = firOpBuilder.getI64IntegerAttr(*safelenVal);
return true;
}
@@ -465,41 +446,38 @@ bool ClauseProcessor::processSchedule(
mlir::omp::ClauseScheduleKindAttr &valAttr,
mlir::omp::ScheduleModifierAttr &modifierAttr,
mlir::UnitAttr &simdModifierAttr) const {
- if (auto *scheduleClause = findUniqueClause<ClauseTy::Schedule>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Schedule>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
mlir::MLIRContext *context = firOpBuilder.getContext();
- const Fortran::parser::OmpScheduleClause &scheduleType = scheduleClause->v;
- const auto &scheduleClauseKind =
- std::get<Fortran::parser::OmpScheduleClause::ScheduleType>(
- scheduleType.t);
+ const auto &scheduleType =
+ std::get<omp::clause::Schedule::ScheduleType>(clause->t);
mlir::omp::ClauseScheduleKind scheduleKind;
- switch (scheduleClauseKind) {
- case Fortran::parser::OmpScheduleClause::ScheduleType::Static:
+ switch (scheduleType) {
+ case omp::clause::Schedule::ScheduleType::Static:
scheduleKind = mlir::omp::ClauseScheduleKind::Static;
break;
- case Fortran::parser::OmpScheduleClause::ScheduleType::Dynamic:
+ case omp::clause::Schedule::ScheduleType::Dynamic:
scheduleKind = mlir::omp::ClauseScheduleKind::Dynamic;
break;
- case Fortran::parser::OmpScheduleClause::ScheduleType::Guided:
+ case omp::clause::Schedule::ScheduleType::Guided:
scheduleKind = mlir::omp::ClauseScheduleKind::Guided;
break;
- case Fortran::parser::OmpScheduleClause::ScheduleType::Auto:
+ case omp::clause::Schedule::ScheduleType::Auto:
scheduleKind = mlir::omp::ClauseScheduleKind::Auto;
break;
- case Fortran::parser::OmpScheduleClause::ScheduleType::Runtime:
+ case omp::clause::Schedule::ScheduleType::Runtime:
scheduleKind = mlir::omp::ClauseScheduleKind::Runtime;
break;
}
- mlir::omp::ScheduleModifier scheduleModifier =
- getScheduleModifier(scheduleClause->v);
+ mlir::omp::ScheduleModifier scheduleModifier = getScheduleModifier(*clause);
if (scheduleModifier != mlir::omp::ScheduleModifier::none)
modifierAttr =
mlir::omp::ScheduleModifierAttr::get(context, scheduleModifier);
- if (getSimdModifier(scheduleClause->v) != mlir::omp::ScheduleModifier::none)
+ if (getSimdModifier(*clause) != mlir::omp::ScheduleModifier::none)
simdModifierAttr = firOpBuilder.getUnitAttr();
valAttr = mlir::omp::ClauseScheduleKindAttr::get(context, scheduleKind);
@@ -510,25 +488,19 @@ bool ClauseProcessor::processSchedule(
bool ClauseProcessor::processScheduleChunk(
Fortran::lower::StatementContext &stmtCtx, mlir::Value &result) const {
- if (auto *scheduleClause = findUniqueClause<ClauseTy::Schedule>()) {
- if (const auto &chunkExpr =
- std::get<std::optional<Fortran::parser::ScalarIntExpr>>(
- scheduleClause->v.t)) {
- if (const auto *expr = Fortran::semantics::GetExpr(*chunkExpr)) {
- result = fir::getBase(converter.genExprValue(*expr, stmtCtx));
- }
- }
+ if (auto *clause = findUniqueClause<omp::clause::Schedule>()) {
+ if (const auto &chunkExpr = std::get<omp::MaybeExpr>(clause->t))
+ result = fir::getBase(converter.genExprValue(*chunkExpr, stmtCtx));
return true;
}
return false;
}
bool ClauseProcessor::processSimdlen(mlir::IntegerAttr &result) const {
- if (auto *simdlenClause = findUniqueClause<ClauseTy::Simdlen>()) {
+ if (auto *clause = findUniqueClause<omp::clause::Simdlen>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- const auto *expr = Fortran::semantics::GetExpr(simdlenClause->v);
const std::optional<std::int64_t> simdlenVal =
- Fortran::evaluate::ToInt64(*expr);
+ Fortran::evaluate::ToInt64(clause->v);
result = firOpBuilder.getI64IntegerAttr(*simdlenVal);
return true;
}
@@ -537,16 +509,15 @@ bool ClauseProcessor::processSimdlen(mlir::IntegerAttr &result) const {
bool ClauseProcessor::processThreadLimit(
Fortran::lower::StatementContext &stmtCtx, mlir::Value &result) const {
- if (auto *threadLmtClause = findUniqueClause<ClauseTy::ThreadLimit>()) {
- result = fir::getBase(converter.genExprValue(
- *Fortran::semantics::GetExpr(threadLmtClause->v), stmtCtx));
+ if (auto *clause = findUniqueClause<omp::clause::ThreadLimit>()) {
+ result = fir::getBase(converter.genExprValue(clause->v, stmtCtx));
return true;
}
return false;
}
bool ClauseProcessor::processUntied(mlir::UnitAttr &result) const {
- return markClauseOccurrence<ClauseTy::Untied>(result);
+ return markClauseOccurrence<omp::clause::Untied>(result);
}
//===----------------------------------------------------------------------===//
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index 11aff0be25053d..c87fc30c88bb93 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -12,6 +12,7 @@
#ifndef FORTRAN_LOWER_CLAUASEPROCESSOR_H
#define FORTRAN_LOWER_CLAUASEPROCESSOR_H
+#include "Clauses.h"
#include "DirectivesCommon.h"
#include "ReductionProcessor.h"
#include "Utils.h"
@@ -51,7 +52,8 @@ class ClauseProcessor {
ClauseProcessor(Fortran::lower::AbstractConverter &converter,
Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &clauses)
- : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
+ : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+ clauses(makeList(clauses, semaCtx)) {}
// 'Unique' clauses: They can appear at most once in the clause list.
bool
@@ -155,11 +157,15 @@ class ClauseProcessor {
llvm::omp::Directive directive) const;
private:
- using ClauseIterator = std::list<ClauseTy>::const_iterator;
+ using ClauseIterator = List<Clause>::const_iterator;
+ using ClauseIterator2 = std::list<ClauseTy>::const_iterator;
/// Utility to find a clause within a range in the clause list.
template <typename T>
static ClauseIterator findClause(ClauseIterator begin, ClauseIterator end);
+ template <typename T>
+ static ClauseIterator2 findClause2(ClauseIterator2 begin,
+ ClauseIterator2 end);
/// Return the first instance of the given clause found in the clause list or
/// `nullptr` if not present. If more than one instance is expected, use
@@ -181,7 +187,8 @@ class ClauseProcessor {
Fortran::lower::AbstractConverter &converter;
Fortran::semantics::SemanticsContext &semaCtx;
- const Fortran::parser::OmpClauseList &clauses;
+ const Fortran::parser::OmpClauseList &clauses2;
+ List<Clause> clauses;
};
template <typename T>
@@ -248,7 +255,7 @@ void ClauseProcessor::processTODO(mlir::Location currentLocation,
" construct");
};
- for (ClauseIterator it = clauses.v.begin(); it != clauses.v.end(); ++it)
+ for (ClauseIterator2 it = clauses2.v.begin(); it != clauses2.v.end(); ++it)
(checkUnhandledClause(std::get_if<Ts>(&it->u)), ...);
}
@@ -263,11 +270,22 @@ ClauseProcessor::findClause(ClauseIterator begin, ClauseIterator end) {
return end;
}
+template <typename T>
+ClauseProcessor::ClauseIterator2
+ClauseProcessor::findClause2(ClauseIterator2 begin, ClauseIterator2 end) {
+ for (ClauseIterator2 it = begin; it != end; ++it) {
+ if (std::get_if<T>(&it->u))
+ return it;
+ }
+
+ return end;
+}
+
template <typename T>
const T *ClauseProcessor::findUniqueClause(
const Fortran::parser::CharBlock **source) const {
- ClauseIterator it = findClause<T>(clauses.v.begin(), clauses.v.end());
- if (it != clauses.v.end()) {
+ ClauseIterator it = findClause<T>(clauses.begin(), clauses.end());
+ if (it != clauses.end()) {
if (source)
*source = &it->source;
return &std::get<T>(it->u);
@@ -280,9 +298,9 @@ bool ClauseProcessor::findRepeatableClause(
std::function<void(const T *, const Fortran::parser::CharBlock &source)>
callbackFn) const {
bool found = false;
- ClauseIterator nextIt, endIt = clauses.v.end();
- for (ClauseIterator it = clauses.v.begin(); it != endIt; it = nextIt) {
- nextIt = findClause<T>(it, endIt);
+ ClauseIterator2 nextIt, endIt = clauses2.v.end();
+ for (ClauseIterator2 it = clauses2.v.begin(); it != endIt; it = nextIt) {
+ nextIt = findClause2<T>(it, endIt);
if (nextIt != endIt) {
callbackFn(&std::get<T>(nextIt->u), nextIt->source);
diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp
index 50ac4f2097ea8b..a807814d0229d7 100644
--- a/flang/lib/Lower/OpenMP/Clauses.cpp
+++ b/flang/lib/Lower/OpenMP/Clauses.cpp
@@ -42,7 +42,7 @@ static llvm::omp::Clause getClauseId(const Fortran::parser::OmpClause &clause) {
clause.u);
}
-namespace omp {
+namespace Fortran::lower::omp {
using SymbolWithDesignator = std::tuple<semantics::Symbol *, MaybeExpr>;
struct SymbolAndDesignatorExtractor {
@@ -725,10 +725,10 @@ Clause makeClause(const Fortran::parser::OmpClause &cls,
cls.u);
}
-omp::List<Clause> makeList(const parser::OmpClauseList &clauses,
- semantics::SemanticsContext &semaCtx) {
+List<Clause> makeList(const parser::OmpClauseList &clauses,
+ semantics::SemanticsContext &semaCtx) {
return makeList(clauses.v, [&](const parser::OmpClause &s) {
return makeClause(s, semaCtx);
});
}
-} // namespace omp
+} // namespace Fortran::lower::omp
diff --git a/flang/lib/Lower/OpenMP/Clauses.h b/flang/lib/Lower/OpenMP/Clauses.h
index 586875036cb376..fdf45ec21e8e65 100644
--- a/flang/lib/Lower/OpenMP/Clauses.h
+++ b/flang/lib/Lower/OpenMP/Clauses.h
@@ -22,7 +22,7 @@
#include <type_traits>
#include <utility>
-namespace omp {
+namespace Fortran::lower::omp {
using namespace Fortran;
using SomeType = evaluate::SomeType;
using SomeExpr = semantics::SomeExpr;
@@ -33,13 +33,14 @@ using SymReference = SomeExpr;
template <typename T>
using List = tomp::ListT<T>;
-} // namespace omp
+} // namespace Fortran::lower::omp
namespace tomp {
template <>
-struct ObjectT<omp::SymIdent, omp::SymReference> {
- using IdType = omp::SymIdent;
- using ExprType = omp::SymReference;
+struct ObjectT<Fortran::lower::omp::SymIdent,
+ Fortran::lower::omp::SymReference> {
+ using IdType = Fortran::lower::omp::SymIdent;
+ using ExprType = Fortran::lower::omp::SymReference;
const IdType &id() const { return symbol; }
const std::optional<ExprType> &ref() const { return designator; }
@@ -49,7 +50,7 @@ struct ObjectT<omp::SymIdent, omp::SymReference> {
};
} // namespace tomp
-namespace omp {
+namespace Fortran::lower::omp {
using Object = tomp::ObjectT<SymIdent, SymReference>;
using ObjectList = tomp::ObjectListT<SymIdent, SymReference>;
@@ -200,6 +201,6 @@ Clause makeClause(const Fortran::parser::OmpClause &cls,
List<Clause> makeList(const parser::OmpClauseList &clauses,
semantics::SemanticsContext &semaCtx);
-} // namespace omp
+} // namespace Fortran::lower::omp
#endif // FORTRAN_LOWER_OPENMP_CLAUSES_H
More information about the flang-commits
mailing list