Add Block::to_vector - #9384
Open
abadams wants to merge 1 commit into
Open
Conversation
Adds a helper that unpacks a Stmt into the sequence of non-Block Stmts it runs, and uses it in the places that were doing this ad-hoc: LoopCarry (which had its own recursive block_to_vector), Prefetch (which had a recursive traverse_block template), AsyncProducers, RemoveUndef, and StmtToHTML. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9384 +/- ##
==========================================
+ Coverage 70.03% 70.11% +0.07%
==========================================
Files 261 261
Lines 79223 79190 -33
Branches 19312 19305 -7
==========================================
+ Hits 55487 55524 +37
+ Misses 17923 17893 -30
+ Partials 5813 5773 -40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mcourteaux
reviewed
Aug 25, 2026
|
|
||
| std::vector<Stmt> Block::to_vector(const Stmt &s) { | ||
| std::vector<Stmt> result; | ||
| // Blocks are right-leaning: 'first' is never itself a Block. |
Contributor
There was a problem hiding this comment.
Not through a Block::make indeed. But someone could just set first and rest manually. An assert wouldn't hurt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocks are guaranteed to be right-leaning, but several places were unpacking a Block tree into a vector of non-Block Stmts by hand, some of them recursively. This adds a single helper:
It's a static taking a Stmt rather than a member on Block, because every call site starts from a Stmt that may or may not be a Block, and that makes it a true inverse of
Block::make(const std::vector<Stmt> &).Call sites converted:
LoopCarryhad its own recursiveblock_to_vectorpair; deleted.Prefetchhad a recursivetraverse_blocktemplate; deleted.HoistPrefetches::visit(Block)now collects into two vectors and concatenates.AsyncProducers, both inmake_producer_consumerand inExpandAcquireNodes::visit(Block).RemoveUndef::visit(Block). It no longer shares an unchanged suffix when something did change, but still returnsopuntouched when nothing changed, and still returns an undefined Stmt when everything was removed.StmtToHTML::print_block_stmt.Left alone are the places that walk a block chain conditionally or partially rather than unpacking it:
Simplify_Stmts,CodeGen_LLVM's leading-assert collection,LICM,Profiling,InjectHostDevBufferCopies, andSerialization.test_correctness passes locally apart from the known LLVM 23 sve2 failure in simd_op_check.