Skip to content

Commit

Permalink
chore: remove unused Loop opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Jan 11, 2025
1 parent 7e00bd1 commit aa16a1d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 91 deletions.
49 changes: 0 additions & 49 deletions extensions/native/compiler/src/asm/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,6 @@ impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> AsmCo
};
zip_for_compiler.for_each(move |_, builder| builder.build(block), debug_info);
}
DslIr::Loop(block) => {
let loop_compiler = LoopCompiler { compiler: self };
loop_compiler.compile(move |builder| builder.build(block), debug_info);
}
DslIr::AssertEqV(lhs, rhs) => {
// If lhs != rhs, execute TRAP
self.assert(lhs.fp(), ValueOrConst::Val(rhs.fp()), false, debug_info)
Expand Down Expand Up @@ -1050,51 +1046,6 @@ impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> ForCo
}
}

struct LoopCompiler<'a, F: Field, EF> {
compiler: &'a mut AsmCompiler<F, EF>,
}

impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> LoopCompiler<'_, F, EF> {
fn compile(
self,
compile_body: impl FnOnce(&mut AsmCompiler<F, EF>),
debug_info: Option<DebugInfo>,
) {
// Initialize a break label for this loop.
let break_label = self.compiler.new_break_label();
self.compiler.break_label = Some(break_label);

// Loop block.
self.compiler.basic_block();
let loop_label = self.compiler.block_label();

compile_body(self.compiler);
self.compiler
.push(AsmInstruction::j(loop_label), debug_info.clone());

// After loop block.
self.compiler.basic_block();
let after_loop_label = self.compiler.block_label();
self.compiler
.break_label_map
.insert(break_label, after_loop_label);

// Replace break instructions with a jump to the after loop block.
for block in self.compiler.contains_break.iter() {
for instruction in self.compiler.basic_blocks[block.as_canonical_u32() as usize]
.0
.iter_mut()
{
if let AsmInstruction::Break(l) = instruction {
if *l == break_label {
*instruction = AsmInstruction::j(after_loop_label);
}
}
}
}
}
}

// Ext compiler logic.
impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> AsmCompiler<F, EF> {
fn assign_exti(&mut self, dst: i32, imm: EF, debug_info: Option<DebugInfo>) {
Expand Down
12 changes: 0 additions & 12 deletions extensions/native/compiler/src/ir/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,18 +423,6 @@ impl<C: Config> Builder<C> {
}
}

/// Evaluate a block of operations repeatedly (until a break).
pub fn do_loop(&mut self, mut f: impl FnMut(&mut Builder<C>) -> Result<(), BreakLoop>) {
let mut loop_body_builder = self.create_sub_builder();

f(&mut loop_body_builder).expect("should not be break issues in dynamic loop");

let loop_instructions = loop_body_builder.operations;

let op = DslIr::Loop(loop_instructions);
self.operations.push(op);
}

/// Break out of a loop.
pub fn break_loop(&mut self) -> Result<(), BreakLoop> {
if self.flags.disable_break {
Expand Down
2 changes: 0 additions & 2 deletions extensions/native/compiler/src/ir/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ pub enum DslIr<C: Config> {
TracedVec<DslIr<C>>,
),

/// Executes an indefinite loop.
Loop(TracedVec<DslIr<C>>),
/// Executes an equal conditional branch with the parameters (lhs var, rhs var, then body, else body).
IfEq(
Var<C::N>,
Expand Down
28 changes: 0 additions & 28 deletions extensions/native/compiler/tests/loops.rs

This file was deleted.

0 comments on commit aa16a1d

Please sign in to comment.