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

[FIRRTL] Fix unnecessarily repeated calls to setType in LowerTypes. #643

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

mikeurbach
Copy link
Contributor

The previous implementation would call setType to update the module's
type attribute after each new argument was added. This constant
updating of the attribute was needed because getNumFuncArguments used
the attribute, and getNumFuncArguments was called by core MLIR logic
throughout this pass.

By updating getNumFuncArguments to just return the current number of
entry block arguments, we are able to update the type attribute once
at the end of the pass.

This is part of #615.

The previous implementation would call setType to update the module's
type attribute after each new argument was added. This constant
updating of the attribute was needed because getNumFuncArguments used
the attribute, and getNumFuncArguments was called by core MLIR logic
throughout this pass.

By updating getNumFuncArguments to just return the current number of
entry block arguments, we are able to update the type attribute once
at the end of the pass.
@mikeurbach
Copy link
Contributor Author

CPU flame graphs seem the best way to showcase the performance gain. This was tested using the same test case as reported in #615.

Before:

After:

Note that the calls to Builder::getFunctionType and FunctionLike::setType are no longer prominent in the flame graph. On my machine, this reduced the time firtool spent in LowerTypes (according to -pass-timing) from ~60% to ~50%.

@mikeurbach
Copy link
Contributor Author

@lattner the change in LowerTypes.cpp seems "obvious" to me, but I am less sure about the change in FIRRTLStructure.td. Do you mind taking a look? The tests pass, so I don't think anything relied on the previous behavior.

@lattner
Copy link
Collaborator

lattner commented Feb 23, 2021

This looks great to me!

@lattner
Copy link
Collaborator

lattner commented Feb 23, 2021

and yes, going to bb args should be faster than going through getType() which has to dig it out of an attribute.

@mikeurbach
Copy link
Contributor Author

Thanks for the review!

@mikeurbach mikeurbach merged commit 5f3bf8f into main Feb 23, 2021
@mikeurbach mikeurbach deleted the lower-types-perf branch February 23, 2021 00:43
@seldridge
Copy link
Member

newplot
newplot(1)

The nightly performance tests seem to agree that this helped. 👍

@lattner
Copy link
Collaborator

lattner commented Feb 23, 2021

Great progress, but still more to do ;-)

@mikeurbach
Copy link
Contributor Author

Yep, I will share a PR today that should clean up the remaining performance issues (spoiler: it also has to do with too many setAttr calls).

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.

3 participants