[flang][OpenMP] Avoid early returns, NFC (#117231)
Frontend code is generally nested. Follow-up to https://github.com/llvm/llvm-project/pull/116658.
This commit is contained in:
committed by
GitHub
parent
e79cd24676
commit
1a08b15589
@@ -163,6 +163,16 @@ std::optional<ResultTy> maybeApplyToV(FuncTy &&func, const ArgTy *arg) {
|
||||
return func(arg->v);
|
||||
}
|
||||
|
||||
template <
|
||||
typename FuncTy, //
|
||||
typename ArgTy, //
|
||||
typename ResultTy = std::invoke_result_t<FuncTy, typename ArgTy::Value>>
|
||||
std::optional<ResultTy> maybeApplyToV(FuncTy &&func, const ArgTy *arg) {
|
||||
if (!arg)
|
||||
return std::nullopt;
|
||||
return std::move(func(arg->v));
|
||||
}
|
||||
|
||||
std::optional<Object> getBaseObject(const Object &object,
|
||||
semantics::SemanticsContext &semaCtx);
|
||||
|
||||
|
||||
@@ -2865,45 +2865,41 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
|
||||
|
||||
bool OmpStructureChecker::CheckReductionOperators(
|
||||
const parser::OmpClause::Reduction &x) {
|
||||
auto &modifiers{OmpGetModifiers(x.v)};
|
||||
const auto *definedOp{
|
||||
OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)};
|
||||
if (!definedOp) {
|
||||
return false;
|
||||
}
|
||||
bool ok = false;
|
||||
common::visit(
|
||||
common::visitors{
|
||||
[&](const parser::DefinedOperator &dOpr) {
|
||||
if (const auto *intrinsicOp{
|
||||
std::get_if<parser::DefinedOperator::IntrinsicOperator>(
|
||||
&dOpr.u)}) {
|
||||
ok = CheckIntrinsicOperator(*intrinsicOp);
|
||||
} else {
|
||||
context_.Say(GetContext().clauseSource,
|
||||
"Invalid reduction operator in REDUCTION clause."_err_en_US,
|
||||
ContextDirectiveAsFortran());
|
||||
}
|
||||
},
|
||||
[&](const parser::ProcedureDesignator &procD) {
|
||||
const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
|
||||
if (name && name->symbol) {
|
||||
const SourceName &realName{name->symbol->GetUltimate().name()};
|
||||
if (realName == "max" || realName == "min" ||
|
||||
realName == "iand" || realName == "ior" ||
|
||||
realName == "ieor") {
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
context_.Say(GetContext().clauseSource,
|
||||
"Invalid reduction identifier in REDUCTION "
|
||||
"clause."_err_en_US,
|
||||
ContextDirectiveAsFortran());
|
||||
}
|
||||
},
|
||||
},
|
||||
definedOp->u);
|
||||
auto &modifiers{OmpGetModifiers(x.v)};
|
||||
if (const auto *ident{
|
||||
OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)}) {
|
||||
|
||||
auto visitOperator{[&](const parser::DefinedOperator &dOpr) {
|
||||
if (const auto *intrinsicOp{
|
||||
std::get_if<parser::DefinedOperator::IntrinsicOperator>(
|
||||
&dOpr.u)}) {
|
||||
ok = CheckIntrinsicOperator(*intrinsicOp);
|
||||
} else {
|
||||
context_.Say(GetContext().clauseSource,
|
||||
"Invalid reduction operator in REDUCTION clause."_err_en_US,
|
||||
ContextDirectiveAsFortran());
|
||||
}
|
||||
}};
|
||||
|
||||
auto visitDesignator{[&](const parser::ProcedureDesignator &procD) {
|
||||
const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
|
||||
if (name && name->symbol) {
|
||||
const SourceName &realName{name->symbol->GetUltimate().name()};
|
||||
if (realName == "max" || realName == "min" || realName == "iand" ||
|
||||
realName == "ior" || realName == "ieor") {
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
context_.Say(GetContext().clauseSource,
|
||||
"Invalid reduction identifier in REDUCTION "
|
||||
"clause."_err_en_US,
|
||||
ContextDirectiveAsFortran());
|
||||
}
|
||||
}};
|
||||
common::visit(common::visitors{visitOperator, visitDesignator}, ident->u);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -522,49 +522,47 @@ public:
|
||||
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
|
||||
ResolveOmpObjectList(objList, Symbol::Flag::OmpReduction);
|
||||
|
||||
auto &modifiers{OmpGetModifiers(x.v)};
|
||||
if (!modifiers) {
|
||||
return false;
|
||||
}
|
||||
if (auto &modifiers{OmpGetModifiers(x.v)}) {
|
||||
auto createDummyProcSymbol = [&](const parser::Name *name) {
|
||||
// If name resolution failed, create a dummy symbol
|
||||
const auto namePair{currScope().try_emplace(
|
||||
name->source, Attrs{}, ProcEntityDetails{})};
|
||||
auto &newSymbol{*namePair.first->second};
|
||||
if (context_.intrinsics().IsIntrinsic(name->ToString())) {
|
||||
newSymbol.attrs().set(Attr::INTRINSIC);
|
||||
}
|
||||
name->symbol = &newSymbol;
|
||||
};
|
||||
|
||||
auto createDummyProcSymbol = [&](const parser::Name *name) {
|
||||
// If name resolution failed, create a dummy symbol
|
||||
const auto namePair{
|
||||
currScope().try_emplace(name->source, Attrs{}, ProcEntityDetails{})};
|
||||
auto &newSymbol{*namePair.first->second};
|
||||
if (context_.intrinsics().IsIntrinsic(name->ToString())) {
|
||||
newSymbol.attrs().set(Attr::INTRINSIC);
|
||||
}
|
||||
name->symbol = &newSymbol;
|
||||
};
|
||||
|
||||
for (auto &mod : *modifiers) {
|
||||
if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
|
||||
continue;
|
||||
}
|
||||
auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
|
||||
if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
|
||||
if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
|
||||
if (!name->symbol) {
|
||||
if (!ResolveName(name)) {
|
||||
createDummyProcSymbol(name);
|
||||
for (auto &mod : *modifiers) {
|
||||
if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
|
||||
continue;
|
||||
}
|
||||
auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
|
||||
if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
|
||||
if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
|
||||
if (!name->symbol) {
|
||||
if (!ResolveName(name)) {
|
||||
createDummyProcSymbol(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auto *procRef{parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
|
||||
if (!procRef->v.thing.component.symbol) {
|
||||
if (!ResolveName(&procRef->v.thing.component)) {
|
||||
createDummyProcSymbol(&procRef->v.thing.component);
|
||||
if (auto *procRef{
|
||||
parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
|
||||
if (!procRef->v.thing.component.symbol) {
|
||||
if (!ResolveName(&procRef->v.thing.component)) {
|
||||
createDummyProcSymbol(&procRef->v.thing.component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using ReductionModifier = parser::OmpReductionModifier;
|
||||
if (auto *maybeModifier{
|
||||
OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
|
||||
if (maybeModifier->v == ReductionModifier::Value::Inscan) {
|
||||
ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
|
||||
using ReductionModifier = parser::OmpReductionModifier;
|
||||
if (auto *maybeModifier{
|
||||
OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
|
||||
if (maybeModifier->v == ReductionModifier::Value::Inscan) {
|
||||
ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user