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

loop analysis simplification #9613

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

Conversation

KGrewal1
Copy link
Contributor

Some small simplifications I saw when looking through the loop analysis code, mostly regarding using inbuilt iterator method for greater simplicity

@KGrewal1 KGrewal1 requested a review from a team as a code owner November 15, 2024 14:22
@KGrewal1 KGrewal1 requested review from cfallin and removed request for a team November 15, 2024 14:22
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Nov 15, 2024
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. A few thoughts below. I think there may be some aspect of subjective taste here; but I'm not a huge fan of very large iterator chain expressions, because they take a lot of "mental type-inference" to understand intermediate steps and how the chain works, and they're harder to modify and maintain over time. They're not a huge amount worse than explicit for-loops, but here they don't really seem better either; so I'm not sure I see the "simplification" aspect. Happy to hear your thoughts though.

inst: pred_inst, ..
}| domtree.dominates(block, pred_inst, layout),
)
})
Copy link
Member

Choose a reason for hiding this comment

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

This iterator chain is a little too convoluted to be easily readable, IMHO. One thing that might help is to pull out an is_loop_header helper?

It might also be nice to have a method on the domtree that returns an RPO iterator directly (impl Iterator... in return is fine). Then we could do something like:

for &block in domtree.cfg_rpo().filter(|&block| is_loop_header(cfg, domtree, block)) { ... }

cranelift/codegen/src/loop_analysis.rs Show resolved Hide resolved
@@ -190,6 +190,19 @@ impl LoopAnalysis {
self.valid = false;
}

// Determines if a block dominates any predecessor
// and thus is a loop header
fn check_loop_header(
Copy link
Member

Choose a reason for hiding this comment

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

Let's call this is_loop_header (check doesn't tell me anything about what it returns; usually implies an invariant check or something like that instead). And the doc-comment should end with a period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was going to use is_loop_header but already in use by another function - check was best synonym but not ideal

cranelift/codegen/src/loop_analysis.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/loop_analysis.rs Show resolved Hide resolved
@github-actions github-actions bot added the cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants