Skip to content

[flang][openmp]Add UserReductionDetails and use in DECLARE REDUCTION #140066

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

tblah
Copy link
Contributor

@tblah tblah commented May 15, 2025

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.

@tblah
Copy link
Contributor Author

tblah commented May 15, 2025

This is a continuation of @Leporacanthicus's work in #131628.

@tblah tblah force-pushed the ecclescake/omp-reduction-add-details branch from c4e01f6 to c5f9768 Compare May 19, 2025 17:11
@tblah
Copy link
Contributor Author

tblah commented May 21, 2025

ping for review

Comment on lines 293 to 295
// Store (and get a reference to the stored string) for mangled names
// used for OpenMP DECLARE REDUCTION.
std::string &StoreUserReductionName(const std::string &name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping we could get this to work without the requirement for a string storage like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SaveTempName is used elsewhere for saving mangled names so I'm not adding any new confusion here. There's currently no code removing any strings that are added via that helper so the lifetime should be okay.

void OmpVisitor::ProcessReductionSpecifier(
const parser::OmpReductionSpecifier &spec,
const std::optional<parser::OmpClauseList> &clauses) {
const std::optional<parser::OmpClauseList> &clauses,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this function looks a bit hacky.
Ideally we shouldn't have random parser::Name not attached to the parse-tree and floating symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tblah tblah force-pushed the ecclescake/omp-reduction-add-details branch from bb650c5 to 9a7d1ab Compare June 4, 2025 14:54
Copy link

github-actions bot commented Jun 4, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@NimishMishra NimishMishra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. But please wait for another approval


UserReductionDetails() = default;

void AddType(const DeclTypeSpec &type) { typeList_.push_back(&type); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (feel free to ignore): emplace_back may be preferable for non-trivial types in std::vector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ignored here (because it is just adding a pointer). But the other one does benefit from emplace_back to construct the variant in place. Thanks

return CheckSymbolSupportsType(
scope, MangleDefinedOperator(definedOp->v.symbol->name()), type);
}
DIE("Intrinsic Operator not found - parsing gone wrong?");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should this be DIE or a semantic error that sources the offending source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll replace this with unreachable to make it clearer

@kiranchandramohan
Copy link
Contributor

Could you check the format complaints again?

Leporacanthicus and others added 18 commits June 5, 2025 11:10
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.
* Add two more tests (multiple operator-based declarations and re-using
  symbol already declared.
* Add a few comments.
* Fix up logical results.
Also print the reduction declaration in the module file.

Fix trivial typo.

Add/modify tests to cover all the new things, including fixing
the duplicated typo in the test...
Also rebase, as the branch was quite a way behind. Small conflict
was resolved.
Add code to better handle operators in parsing and semantics.
Add a function to set the the scope when processign assignments,
which caused a crash in "check for pure functions".

Add three new tests and amend existing tests to cover a pure function.
tblah added 3 commits June 5, 2025 11:10
I had to rebase to reproduce the test failure
@tblah tblah force-pushed the ecclescake/omp-reduction-add-details branch from ea6901d to d12203c Compare June 5, 2025 11:21
@tblah tblah requested a review from kiranchandramohan June 5, 2025 15:06
Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will probably have to revisit when we implement the lowering.

Please check whether the reported issues error out properly now.
#141306
#119960
#97241
#92832
#66453
#57219

LG.

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 referene.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Decls are pointers, so do not use a referene.
// Decls are pointers, so do not use a reference.

name = std::get_if<parser::Name>(&procDes->u);
// This shouldn't be a procedure component: this is the name of the
// reduction being declared.
assert(name && "ProcedureDesignator contained ProcComponentRef");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the CHECK macro?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants