Skip to content
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

Function call CSE pass #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

arrangabriel
Copy link
Collaborator

Adds a pass that hoists repeated function calls with equivalent arguments in and between equations into new equations, so they are only computed once.

@arrangabriel
Copy link
Collaborator Author

It would be nice if you could take a look @mscuttari and see what you think.

As you asked it does not currently handle equations with induction variables.

Additionally I was unsure whether calls in the initial equations had to be handled differently, so for not they are ignored.

There is also just one test. I read the page on filecheck tests for mlir, and they mention that one should try to make the tests as isolated as possible. I tried to do that for the one I have made, so please let me know if something can be improved about that. I'll add some more before finishing the PR.

Copy link
Member

@mscuttari mscuttari left a comment

Choose a reason for hiding this comment

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

I've left some comments about possible code improvements. Some of them are mostly stylistic, others a little bit less.

lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
@mscuttari mscuttari linked an issue Oct 14, 2024 that may be closed by this pull request
@arrangabriel arrangabriel force-pushed the arrangabriel/function-cse branch 5 times, most recently from 1990b4d to a7398f8 Compare October 17, 2024 16:22
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
lib/Dialect/BaseModelica/Transforms/CallCSE.cpp Outdated Show resolved Hide resolved
@arrangabriel arrangabriel marked this pull request as ready for review October 21, 2024 10:55
@arrangabriel arrangabriel requested a review from a team as a code owner October 21, 2024 10:55
Copy link
Member

@mscuttari mscuttari left a comment

Choose a reason for hiding this comment

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

LGTM. Perform the last fix and squash your commits into one ("Add calls CSE pass"). I will then merge.

for (EquationInstanceOp equationOp : dynamicEquationOps) {
EquationTemplateOp templateOp = equationOp.getTemplate();
if (!templateOp.getInductionVariables().empty() ||
llvm::is_contained(templateOps, templateOp)) {
Copy link
Member

Choose a reason for hiding this comment

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

This is O(n^2). It would be better to check for already visited templates by using a set, while at the same time keeping the vector for deterministic output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'll fix it

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.

CSE to avoid repeated pure function calls with the same argument
2 participants