aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/mod-file.cpp
diff options
context:
space:
mode:
authorTom Eccles <tom.eccles@arm.com>2025-06-09 11:17:03 +0100
committerGitHub <noreply@github.com>2025-06-09 11:17:03 +0100
commitce603a0f16209bd7eb2bd378d6a3f13fe52a1063 (patch)
tree7771e392cefd69db40927d99930d89a45ccccc9b /flang/lib/Semantics/mod-file.cpp
parente4447e1273616a8732e332168a53a6ac5c8798e2 (diff)
downloadllvm-ce603a0f16209bd7eb2bd378d6a3f13fe52a1063.zip
llvm-ce603a0f16209bd7eb2bd378d6a3f13fe52a1063.tar.gz
llvm-ce603a0f16209bd7eb2bd378d6a3f13fe52a1063.tar.bz2
[flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION (#140066)
This adds another puzzle piece for the support of OpenMP DECLARE REDUCTION functionality. This adds support for operators with derived types, as well as declaring multiple different types with the same name or operator. A new detail class for UserReductionDetials is introduced to hold the list of types supported for a given reduction declaration. Tests for parsing and symbol generation added. Declare reduction is still not supported to lowering, it will generate a "Not yet implemented" fatal error. Fixes #141306 Fixes #97241 Fixes #92832 Fixes #66453 --------- Co-authored-by: Mats Petersson <mats.petersson@arm.com>
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r--flang/lib/Semantics/mod-file.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index a1ec956..a726418 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -894,6 +894,7 @@ void ModFileWriter::PutEntity(llvm::raw_ostream &os, const Symbol &symbol) {
[&](const ObjectEntityDetails &) { PutObjectEntity(os, symbol); },
[&](const ProcEntityDetails &) { PutProcEntity(os, symbol); },
[&](const TypeParamDetails &) { PutTypeParam(os, symbol); },
+ [&](const UserReductionDetails &) { PutUserReduction(os, symbol); },
[&](const auto &) {
common::die("PutEntity: unexpected details: %s",
DetailsToString(symbol.details()).c_str());
@@ -1043,6 +1044,28 @@ void ModFileWriter::PutTypeParam(llvm::raw_ostream &os, const Symbol &symbol) {
os << '\n';
}
+void ModFileWriter::PutUserReduction(
+ llvm::raw_ostream &os, const Symbol &symbol) {
+ const auto &details{symbol.get<UserReductionDetails>()};
+ // The module content for a OpenMP Declare Reduction is the OpenMP
+ // declaration. There may be multiple declarations.
+ // Decls are pointers, so do not use a reference.
+ for (const auto decl : details.GetDeclList()) {
+ common::visit( //
+ common::visitors{//
+ [&](const parser::OpenMPDeclareReductionConstruct *d) {
+ Unparse(os, *d, context_.langOptions());
+ },
+ [&](const parser::OmpMetadirectiveDirective *m) {
+ Unparse(os, *m, context_.langOptions());
+ },
+ [&](const auto &) {
+ DIE("Unknown OpenMP DECLARE REDUCTION content");
+ }},
+ decl);
+ }
+}
+
void PutInit(llvm::raw_ostream &os, const Symbol &symbol, const MaybeExpr &init,
const parser::Expr *unanalyzed, SemanticsContext &context) {
if (IsNamedConstant(symbol) || symbol.owner().IsDerivedType()) {