-
Notifications
You must be signed in to change notification settings - Fork 14k
[flang][OpenMP][NFC] Refactor to avoid global variable #144493
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
base: main
Are you sure you want to change the base?
Conversation
I was really hoping this would also work for `hostEvalInfo` but unfortunately that needed to be shared to a greater degree. The same technique should work for that but it would need that class to be made public and then the state kept between calls to `genOpenMP*Construct`, which felt like more trouble than it was worth. I'm open to abandoning this patch if solving one global variable doesn't feel worth this much churn. Making these changes I was wondering if we should implement this file with one big class to wrap up all the state passed to every function. Any thoughts?
6e3b475
to
29ccef7
Compare
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.
Thank you Tom for taking a stab at this issue. In my opinion, we should probably take this opportunity to address it for both hostEvalInfo
and sectionsStack
in a slightly more generic way.
I think you're referring to this yourself in the "FIXME" comment you added for hostEvalInfo
, but in my opinion it would be the AbstractConverter
class the one that should hold a stack of generic information and provide basic facilities to introduce, query and remove objects from it. That way, we can produce information on parent constructs that can then be queried by their children, which would address the current need for any global variables here.
The ModuleTranslation::StackFrame
and related classes and methods in MLIR to LLVM IR translation seem to define an applicable pattern we could use here as well. Not sure if there's a good way of refactoring and reusing these same classes both here and in MLIR, but my feeling is that the worst-case scenario of mirroring that approach in Flang lowering wouldn't introduce so much code duplication that it could be an issue.
What do you think about that alternative?
Okay if you are happy for I think something like What would you think about sharing all of the context for these calls in one big class (probably kept internal to this translation unit). For example, // Instead of having loads of these
static mlir::omp::SomethingOp genSomethingOp(lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx, ...);
// Wrap it all in a class to store the common parameters
class OmpLowering {
public:
...
void genOMP(const parser::OpenMPSomethingConstruct &construct);
private:
mlir::omp::SomethingOp
genSomethingOp(lower::pft::Evaluation &eval, mlir::Location loc, const ConstructQueue &queue, ConstructQueue::const_iterator item);
lower::AbstractConverter &converter;
semantics::SemanticsContext &semaCtx;
...
}; My hope here is to make it a smaller change next time the interface to all of these functions needs to change. I guess a StackFrame could go in here. |
I think that's a very good idea. Both |
Oh you want to put the stack in AbstractConverter. Yes that could avoid most of the churn in this PR. LGTM. Do you want me to do it or are you already working on it? |
That's what I got from Segio's suggestion (correct me if I am wrong @skatrak). So we would have something like
Not working on that atm. |
Yes, that's what I meant to say. We would have an
That would be a separate patch in my opinion, but I think it would certainly be quite helpful regardless of how we deal with the context, since we're sharing quite a big chunk of state between many helper functions through arguments. |
I was really hoping this would also work for
hostEvalInfo
but unfortunately that needed to be shared to a greater degree.The same technique should work for that but it would need that class to be made public and then the state kept between calls to
genOpenMP*Construct
, which felt like more trouble than it was worth.I'm open to abandoning this patch if solving one global variable doesn't feel worth this much churn.
Making these changes I was wondering if we should implement this file with one big class to wrap up all the state passed to every function. Any thoughts?