[flang-commits] [flang] [flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION (PR #131628)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Wed May 7 10:21:57 PDT 2025
================
@@ -1752,14 +1761,91 @@ void OmpVisitor::ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
PopScope();
}
+parser::CharBlock MakeNameFromOperator(
+ const parser::DefinedOperator::IntrinsicOperator &op,
+ SemanticsContext &context) {
+ switch (op) {
+ case parser::DefinedOperator::IntrinsicOperator::Multiply:
+ return parser::CharBlock{"op.*", 4};
+ case parser::DefinedOperator::IntrinsicOperator::Add:
+ return parser::CharBlock{"op.+", 4};
+ case parser::DefinedOperator::IntrinsicOperator::Subtract:
+ return parser::CharBlock{"op.-", 4};
+
+ case parser::DefinedOperator::IntrinsicOperator::AND:
+ return parser::CharBlock{"op.AND", 6};
+ case parser::DefinedOperator::IntrinsicOperator::OR:
+ return parser::CharBlock{"op.OR", 6};
+ case parser::DefinedOperator::IntrinsicOperator::EQV:
+ return parser::CharBlock{"op.EQV", 7};
+ case parser::DefinedOperator::IntrinsicOperator::NEQV:
+ return parser::CharBlock{"op.NEQV", 8};
+
+ default:
+ context.Say("Unsupported operator in DECLARE REDUCTION"_err_en_US);
+ return parser::CharBlock{"op.?", 4};
+ }
+}
+
+parser::CharBlock MangleSpecialFunctions(const parser::CharBlock &name) {
+ return llvm::StringSwitch<parser::CharBlock>(name.ToString())
+ .Case("max", {"op.max", 6})
+ .Case("min", {"op.min", 6})
+ .Case("iand", {"op.iand", 7})
+ .Case("ior", {"op.ior", 6})
+ .Case("ieor", {"op.ieor", 7})
+ .Default(name);
+}
+
+std::string MangleDefinedOperator(const parser::CharBlock &name) {
+ CHECK(name[0] == '.' && name[name.size() - 1] == '.');
+ return "op" + name.ToString();
+}
+
+template <typename T>
void OmpVisitor::ProcessReductionSpecifier(
const parser::OmpReductionSpecifier &spec,
- const std::optional<parser::OmpClauseList> &clauses) {
+ const std::optional<parser::OmpClauseList> &clauses,
+ const T &wholeOmpConstruct) {
+ const parser::Name *name{nullptr};
+ parser::Name mangledName;
+ UserReductionDetails reductionDetailsTemp;
const auto &id{std::get<parser::OmpReductionIdentifier>(spec.t)};
if (auto procDes{std::get_if<parser::ProcedureDesignator>(&id.u)}) {
- if (auto *name{std::get_if<parser::Name>(&procDes->u)}) {
- name->symbol =
- &MakeSymbol(*name, MiscDetails{MiscDetails::Kind::ConstructName});
+ name = std::get_if<parser::Name>(&procDes->u);
+ if (name) {
+ mangledName.source = MangleSpecialFunctions(name->source);
+ }
+
+ } else {
+ const auto &defOp{std::get<parser::DefinedOperator>(id.u)};
+ if (const auto definedOp{std::get_if<parser::DefinedOpName>(&defOp.u)}) {
+ name = &definedOp->v;
+ mangledName.source = parser::CharBlock{context().StoreUserReductionName(
+ MangleDefinedOperator(definedOp->v.source))};
+ } else {
+ mangledName.source = MakeNameFromOperator(
+ std::get<parser::DefinedOperator::IntrinsicOperator>(defOp.u),
+ context());
+ name = &mangledName;
+ }
+ }
+
+ // Use reductionDetailsTemp if we can't find the symbol (this is
+ // the first, or only, instance with this name). The details then
+ // gets stored in the symbol when it's created.
+ UserReductionDetails *reductionDetails{&reductionDetailsTemp};
+ Symbol *symbol{FindSymbol(mangledName)};
+ if (symbol) {
+ // If we found a symbol, we append the type info to the
+ // existing reductionDetails.
+ reductionDetails = symbol->detailsIf<UserReductionDetails>();
+
+ if (!reductionDetails) {
+ context().Say(name->source,
----------------
kparzysz wrote:
The "source" argument to Say must point to somewhere within the cooked sources. It's used to locate the line number and for underlining of the problematic fragment. I'm not sure if that's guaranteed here, since some names are created within this function.
https://github.com/llvm/llvm-project/pull/131628
More information about the flang-commits
mailing list