-
Notifications
You must be signed in to change notification settings - Fork 997
revise defer to use heap allocations when running a variable number of times #745
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
Conversation
|
Any action happening on this PR? |
|
It needs some major changes and I do not have time to implement them right now. |
|
Understood. Can just let it hang out until ready to land, then. |
|
Alright, I updated the strategy to use a BFS to scan backwards. A defer will be stack-allocated unless there exists a path from the defer's block to itself. The only situation in which this would be slow that I can think of is something along the lines of: If a defer is in the entry block then the loop should only run once. |
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.
The algorithm looks sound, although it looks quadratic on crafted inputs. So except for a minor nit, this looks good to me.
Meanwhile I've been thinking about this problem, and I think there is a way to do this in linear or polynomial time (if the result is cached per function). The algorithm (in pseudocode) to calculate all blocks that are in a loop:
blocks := fn.DomPreorder()
inLoop := make([]bool, len(blocks))
for block in blocks:
if block has predecessor that has not yet been seen:
mark inLoop from block to predecessor
optimization: continue from the predecessor (which comes later)
The idea is to walk from the first to the last block in DomPreorder, and if a block has a predecessor that has not been seen yet there must be a loop and all blocks from the checked block up to (and including) that predecessor are marked as in a loop.
The checked block may also be in a loop (directly jumping back to itself) so should not be marked as seen until the predecessors are checked.
This assumes of course that blocks in DomPreorder are ordered as is common in structural programming, I'm not sure whether this is always the case.
|
Kicking the Windows build again... |
|
Great! Thank you for working on this! |
No description provided.