-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION #131628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Leporacanthicus
wants to merge
12
commits into
llvm:main
from
Leporacanthicus:omp-reduction-add-details
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a75db6e
[flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION
Leporacanthicus ee4f705
Fix review comments
Leporacanthicus 3f926bd
Use stringswitch and spell details correctly
Leporacanthicus d0b5e5c
Add support for user defined operators in declare reduction
Leporacanthicus 38bdc0f
Fix nit comments and add simple bad operator test
Leporacanthicus 0afc359
Fix error messages to be more consistent
Leporacanthicus 1b08d9c
add missed test change
Leporacanthicus 17a400b
Improve support for metadirective + declare reduction
Leporacanthicus 93f8179
Fix Klausler reported review comments
Leporacanthicus ce6ca8f
Fix some semantics issues
Leporacanthicus 4739878
[Flang][OpenMP] Fix review comment failed examples
Leporacanthicus c4e01f6
Fix review comments
Leporacanthicus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#include "check-omp-structure.h" | ||
#include "definable.h" | ||
#include "resolve-names-utils.h" | ||
#include "flang/Evaluate/check-expression.h" | ||
#include "flang/Evaluate/expression.h" | ||
#include "flang/Evaluate/type.h" | ||
|
@@ -3390,6 +3391,17 @@ bool OmpStructureChecker::CheckReductionOperator( | |
break; | ||
} | ||
} | ||
// User-defined operators are OK if there has been a declared reduction | ||
// for that. We mangle those names to store the user details. | ||
if (const auto *definedOp{std::get_if<parser::DefinedOpName>(&dOpr.u)}) { | ||
std::string mangled = MangleDefinedOperator(definedOp->v.symbol->name()); | ||
const Scope &scope = definedOp->v.symbol->owner(); | ||
if (const Symbol *symbol = scope.FindSymbol(mangled)) { | ||
if (symbol->detailsIf<UserReductionDetails>()) { | ||
return true; | ||
} | ||
} | ||
} | ||
context_.Say(source, "Invalid reduction operator in %s clause."_err_en_US, | ||
parser::ToUpperCaseLetters(getClauseName(clauseId).str())); | ||
return false; | ||
|
@@ -3403,8 +3415,7 @@ bool OmpStructureChecker::CheckReductionOperator( | |
valid = | ||
llvm::is_contained({"max", "min", "iand", "ior", "ieor"}, realName); | ||
if (!valid) { | ||
auto *misc{name->symbol->detailsIf<MiscDetails>()}; | ||
valid = misc && misc->kind() == MiscDetails::Kind::ConstructName; | ||
valid = name->symbol->detailsIf<UserReductionDetails>(); | ||
} | ||
} | ||
if (!valid) { | ||
|
@@ -3485,8 +3496,20 @@ void OmpStructureChecker::CheckReductionObjects( | |
} | ||
} | ||
|
||
static bool CheckSymbolSupportsType(const Scope &scope, | ||
const parser::CharBlock &name, const DeclTypeSpec &type) { | ||
if (const auto *symbol{scope.FindSymbol(name)}) { | ||
if (const auto *reductionDetails{ | ||
symbol->detailsIf<UserReductionDetails>()}) { | ||
return reductionDetails->SupportsType(type); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
static bool IsReductionAllowedForType( | ||
const parser::OmpReductionIdentifier &ident, const DeclTypeSpec &type) { | ||
const parser::OmpReductionIdentifier &ident, const DeclTypeSpec &type, | ||
const Scope &scope, SemanticsContext &context) { | ||
auto isLogical{[](const DeclTypeSpec &type) -> bool { | ||
return type.category() == DeclTypeSpec::Logical; | ||
}}; | ||
|
@@ -3506,27 +3529,39 @@ static bool IsReductionAllowedForType( | |
case parser::DefinedOperator::IntrinsicOperator::Multiply: | ||
case parser::DefinedOperator::IntrinsicOperator::Add: | ||
case parser::DefinedOperator::IntrinsicOperator::Subtract: | ||
return type.IsNumeric(TypeCategory::Integer) || | ||
if (type.IsNumeric(TypeCategory::Integer) || | ||
type.IsNumeric(TypeCategory::Real) || | ||
type.IsNumeric(TypeCategory::Complex); | ||
type.IsNumeric(TypeCategory::Complex)) | ||
return true; | ||
break; | ||
|
||
case parser::DefinedOperator::IntrinsicOperator::AND: | ||
case parser::DefinedOperator::IntrinsicOperator::OR: | ||
case parser::DefinedOperator::IntrinsicOperator::EQV: | ||
case parser::DefinedOperator::IntrinsicOperator::NEQV: | ||
return isLogical(type); | ||
if (isLogical(type)) { | ||
return true; | ||
} | ||
break; | ||
|
||
// Reduction identifier is not in OMP5.2 Table 5.2 | ||
default: | ||
DIE("This should have been caught in CheckIntrinsicOperator"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
parser::CharBlock name{MakeNameFromOperator(*intrinsicOp, context)}; | ||
return CheckSymbolSupportsType(scope, name, type); | ||
} else if (const auto *definedOp{ | ||
std::get_if<parser::DefinedOpName>(&dOpr.u)}) { | ||
return CheckSymbolSupportsType( | ||
scope, MangleDefinedOperator(definedOp->v.symbol->name()), type); | ||
} | ||
DIE("Intrinsic Operator not found - parsing gone wrong?"); | ||
}}; | ||
|
||
auto checkDesignator{[&](const parser::ProcedureDesignator &procD) { | ||
const parser::Name *name{std::get_if<parser::Name>(&procD.u)}; | ||
CHECK(name && name->symbol); | ||
if (name && name->symbol) { | ||
const SourceName &realName{name->symbol->GetUltimate().name()}; | ||
// OMP5.2: The type [...] of a list item that appears in a | ||
|
@@ -3535,18 +3570,35 @@ static bool IsReductionAllowedForType( | |
// IAND: arguments must be integers: F2023 16.9.100 | ||
// IEOR: arguments must be integers: F2023 16.9.106 | ||
// IOR: arguments must be integers: F2023 16.9.111 | ||
return type.IsNumeric(TypeCategory::Integer); | ||
if (type.IsNumeric(TypeCategory::Integer)) { | ||
return true; | ||
} | ||
} else if (realName == "max" || realName == "min") { | ||
// MAX: arguments must be integer, real, or character: | ||
// F2023 16.9.135 | ||
// MIN: arguments must be integer, real, or character: | ||
// F2023 16.9.141 | ||
return type.IsNumeric(TypeCategory::Integer) || | ||
type.IsNumeric(TypeCategory::Real) || isCharacter(type); | ||
if (type.IsNumeric(TypeCategory::Integer) || | ||
type.IsNumeric(TypeCategory::Real) || isCharacter(type)) { | ||
return true; | ||
} | ||
} | ||
|
||
// If we get here, it may be a user declared reduction, so check | ||
// if the symbol has UserReductionDetails, and if so, the type is | ||
// supported. | ||
if (const auto *reductionDetails{ | ||
name->symbol->detailsIf<UserReductionDetails>()}) { | ||
return reductionDetails->SupportsType(type); | ||
} | ||
|
||
// We also need to check for mangled names (max, min, iand, ieor and ior) | ||
// and then check if the type is there. | ||
parser::CharBlock mangledName{MangleSpecialFunctions(name->source)}; | ||
return CheckSymbolSupportsType(scope, mangledName, type); | ||
} | ||
// TODO: user defined reduction operators. Just allow everything for now. | ||
return true; | ||
// Everything else is "not matching type". | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this used to be an assert, and when changing to die, I didn't remove the line below. |
||
}}; | ||
|
||
return common::visit( | ||
|
@@ -3561,7 +3613,8 @@ void OmpStructureChecker::CheckReductionObjectTypes( | |
|
||
for (auto &[symbol, source] : symbols) { | ||
if (auto *type{symbol->GetType()}) { | ||
if (!IsReductionAllowedForType(ident, *type)) { | ||
const auto &scope{context_.FindScope(symbol->name())}; | ||
if (!IsReductionAllowedForType(ident, *type, scope, context_)) { | ||
context_.Say(source, | ||
"The type of '%s' is incompatible with the reduction operator."_err_en_US, | ||
symbol->name()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the same change required for the isLogical check below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.