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

Assembler: merge adjacent basic blocks #1454

Merged
merged 28 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4eed616
add failing test
plafer Aug 14, 2024
6284166
chore: Remove old mentions "span" instead of "basic block"
plafer Aug 14, 2024
5e903d1
feat(assembler): merge contiguous basic blocks
plafer Aug 14, 2024
e3bcda6
chore: fix tests that didn't assume merging
plafer Aug 14, 2024
bbb4313
Changelog
plafer Aug 14, 2024
8d3a98b
fix falcon test
plafer Aug 14, 2024
f0fff24
fix integration tests
plafer Aug 16, 2024
dceb4c5
disable exec_iter test
plafer Aug 16, 2024
aaf0212
feat: implement dead code elimination
plafer Aug 15, 2024
7113e23
make `compute_live_ids` iterative
plafer Aug 19, 2024
244aaee
comment nit
plafer Aug 19, 2024
b4d82c6
comment nit
plafer Aug 19, 2024
a642adc
move dead code elimination code to MastForest
plafer Aug 19, 2024
78953e6
Merge remote-tracking branch 'origin/next' into plafer-1429-merge-adj…
plafer Aug 19, 2024
2c7095d
Move contiguous block merging to `MastForestBuilder`
plafer Aug 19, 2024
aefaa5f
Move `join_mast_node_ids` in `MastForestBuilder`
plafer Aug 19, 2024
a71c792
Replace "dead code elimination" with removal of unused basic blocks only
plafer Aug 19, 2024
8c8ef39
Rename `MastForestBuilder::prune_and_build` to `build`
plafer Aug 20, 2024
18d26da
rename `join_nodes()`
plafer Aug 20, 2024
ba9e864
check for procedure roots in `get_nodes_to_remove`
plafer Aug 20, 2024
0c7635f
MastNodeId: Remove conversion from u32
plafer Aug 20, 2024
b64e6e3
rename variable `pruned_nodes`
plafer Aug 20, 2024
0f7beae
update comment
plafer Aug 20, 2024
dcd8922
rename var `pruned_nodes` in other context
plafer Aug 20, 2024
c652420
clarify docstring for `MastForest::remove_nodes`
plafer Aug 20, 2024
622ce45
add stdlib compilation benchmark
plafer Aug 20, 2024
d8f664c
Rename all `mast_node_ids` -> `node_ids`
plafer Aug 20, 2024
df15c30
rename stdlib benchmark group
plafer Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## 0.11.0 (TBD)
- Assembler: Merge contiguous basic blocks (#1454)

#### Enhancements

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions assembly/src/assembler/basic_block_builder.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use alloc::{borrow::Borrow, string::ToString, vec::Vec};

use vm_core::{mast::MastNodeId, AdviceInjector, AssemblyOp, Operation};
use vm_core::{mast::MastNodeId, AdviceInjector, AssemblyOp, Decorator, Operation};

use super::{
mast_forest_builder::MastForestBuilder, BodyWrapper, Decorator, DecoratorList, ProcedureContext,
};
use super::{mast_forest_builder::MastForestBuilder, BodyWrapper, DecoratorList, ProcedureContext};
use crate::{ast::Instruction, AssemblyError, Span};

// BASIC BLOCK BUILDER
// ================================================================================================

/// A helper struct for constructing SPAN blocks while compiling procedure bodies.
/// A helper struct for constructing basic blocks while compiling procedure bodies.
///
/// Operations and decorators can be added to a span builder via various `add_*()` and `push_*()`
/// methods, and then SPAN blocks can be extracted from the builder via `extract_*()` methods.
/// Operations and decorators can be added to a basic block builder via various `add_*()` and
/// `push_*()` methods, and then basic blocks can be extracted from the builder via `extract_*()`
/// methods.
///
/// The same span builder can be used to construct many blocks. It is expected that when the last
/// SPAN block in a procedure's body is constructed `extract_final_span_into()` will be used.
/// The same basic block builder can be used to construct many blocks. It is expected that when the
/// last basic block in a procedure's body is constructed [`Self::try_into_basic_block`] will be
/// used.
#[derive(Default)]
pub struct BasicBlockBuilder {
plafer marked this conversation as resolved.
Show resolved Hide resolved
ops: Vec<Operation>,
Expand All @@ -27,11 +27,11 @@ pub struct BasicBlockBuilder {

/// Constructors
impl BasicBlockBuilder {
/// Returns a new [SpanBuilder] instantiated with the specified optional wrapper.
/// Returns a new [`BasicBlockBuilder`] instantiated with the specified optional wrapper.
///
/// If the wrapper is provided, the prologue of the wrapper is immediately appended to the
/// vector of span operations. The epilogue of the wrapper is appended to the list of
/// operations upon consumption of the builder via `extract_final_span_into()` method.
/// vector of span operations. The epilogue of the wrapper is appended to the list of operations
/// upon consumption of the builder via the [`Self::try_into_basic_block`] method.
pub(super) fn new(wrapper: Option<BodyWrapper>) -> Self {
match wrapper {
Some(wrapper) => Self {
Expand All @@ -47,12 +47,12 @@ impl BasicBlockBuilder {

/// Operations
impl BasicBlockBuilder {
/// Adds the specified operation to the list of span operations.
/// Adds the specified operation to the list of basic block operations.
pub fn push_op(&mut self, op: Operation) {
self.ops.push(op);
}

/// Adds the specified sequence of operations to the list of span operations.
/// Adds the specified sequence of operations to the list of basic block operations.
pub fn push_ops<I, O>(&mut self, ops: I)
where
I: IntoIterator<Item = O>,
Expand All @@ -61,7 +61,7 @@ impl BasicBlockBuilder {
self.ops.extend(ops.into_iter().map(|o| *o.borrow()));
}

/// Adds the specified operation n times to the list of span operations.
/// Adds the specified operation n times to the list of basic block operations.
pub fn push_op_many(&mut self, op: Operation, n: usize) {
let new_len = self.ops.len() + n;
self.ops.resize(new_len, op);
Expand All @@ -70,17 +70,17 @@ impl BasicBlockBuilder {

/// Decorators
impl BasicBlockBuilder {
/// Add the specified decorator to the list of span decorators.
/// Add the specified decorator to the list of basic block decorators.
pub fn push_decorator(&mut self, decorator: Decorator) {
self.decorators.push((self.ops.len(), decorator));
}

/// Adds the specified advice injector to the list of span decorators.
/// Adds the specified advice injector to the list of basic block decorators.
pub fn push_advice_injector(&mut self, injector: AdviceInjector) {
self.push_decorator(Decorator::Advice(injector));
}

/// Adds an AsmOp decorator to the list of span decorators.
/// Adds an AsmOp decorator to the list of basic block decorators.
///
/// This indicates that the provided instruction should be tracked and the cycle count for
/// this instruction will be computed when the call to set_instruction_cycle_count() is made.
Expand Down
Loading
Loading