1- use std:: collections:: { BTreeSet , HashMap } ;
1+ use std:: collections:: HashMap ;
22
33use std:: fmt:: Display ;
44use std:: hash:: Hash ;
@@ -10,7 +10,6 @@ use crate::bus_map::OpenVmBusType;
1010use crate :: extraction_utils:: { get_air_metrics, AirWidthsDiff , OriginalAirs , OriginalVmConfig } ;
1111use crate :: instruction_formatter:: openvm_instruction_formatter;
1212use crate :: memory_bus_interaction:: OpenVmMemoryBusInteraction ;
13- use crate :: opcode:: branch_opcodes_bigint_set;
1413use crate :: powdr_extension:: chip:: PowdrAir ;
1514use crate :: utils:: UnsupportedOpenVmReferenceError ;
1615use crate :: OriginalCompiledProgram ;
@@ -27,7 +26,7 @@ use openvm_stark_sdk::p3_baby_bear::BabyBear;
2726use powdr_autoprecompiles:: adapter:: {
2827 Adapter , AdapterApc , AdapterApcWithStats , AdapterVmConfig , ApcWithStats , PgoAdapter ,
2928} ;
30- use powdr_autoprecompiles:: blocks:: { collect_basic_blocks , BasicBlock , Instruction , Program } ;
29+ use powdr_autoprecompiles:: blocks:: { BasicBlock , Instruction , Program } ;
3130use powdr_autoprecompiles:: evaluation:: { evaluate_apc, EvaluationResult } ;
3231use powdr_autoprecompiles:: expression:: try_convert;
3332use powdr_autoprecompiles:: pgo:: { ApcCandidateJsonExport , Candidate , KnapsackItem } ;
@@ -78,7 +77,7 @@ impl<'a> Adapter for BabyBearOpenVmApcAdapter<'a> {
7877
7978/// A newtype wrapper around `OpenVmProgram` to implement the `Program` trait.
8079/// This is necessary because we cannot implement a foreign trait for a foreign type.
81- pub struct Prog < ' a , F > ( & ' a OpenVmProgram < F > ) ;
80+ pub struct Prog < ' a , F > ( pub & ' a OpenVmProgram < F > ) ;
8281
8382impl < ' a , F > From < & ' a OpenVmProgram < F > > for Prog < ' a , F > {
8483 fn from ( program : & ' a OpenVmProgram < F > ) -> Self {
@@ -140,30 +139,20 @@ impl<'a, F: PrimeField32> Program<Instr<F>> for Prog<'a, F> {
140139}
141140
142141pub fn customize < ' a , P : PgoAdapter < Adapter = BabyBearOpenVmApcAdapter < ' a > > > (
143- OriginalCompiledProgram {
144- exe,
145- vm_config,
146- elf,
147- } : OriginalCompiledProgram ,
142+ original_program : OriginalCompiledProgram ,
148143 config : PowdrConfig ,
149144 pgo : P ,
150145) -> CompiledProgram {
151- let labels = elf. text_labels ( ) ;
152- let debug_info = elf. debug_info ( ) ;
153- let original_config = OriginalVmConfig :: new ( vm_config. clone ( ) ) ;
146+ let original_config = OriginalVmConfig :: new ( original_program. vm_config . clone ( ) ) ;
154147 let airs = original_config. airs ( config. degree_bound . identities ) . expect ( "Failed to convert the AIR of an OpenVM instruction, even after filtering by the blacklist!" ) ;
155148 let bus_map = original_config. bus_map ( ) ;
156149
157- let jumpdest_set = add_extra_targets (
158- & exe. program ,
159- labels. clone ( ) ,
160- exe. program . pc_base ,
161- DEFAULT_PC_STEP ,
162- ) ;
163-
164- let program = Prog ( & exe. program ) ;
165-
166- let range_tuple_checker_sizes = vm_config. sdk . rv32m . unwrap ( ) . range_tuple_checker_sizes ;
150+ let range_tuple_checker_sizes = original_program
151+ . vm_config
152+ . sdk
153+ . rv32m
154+ . unwrap ( )
155+ . range_tuple_checker_sizes ;
167156 let vm_config = VmConfig {
168157 instruction_handler : & airs,
169158 bus_interaction_handler : OpenVmBusInteractionHandler :: new (
@@ -173,13 +162,9 @@ pub fn customize<'a, P: PgoAdapter<Adapter = BabyBearOpenVmApcAdapter<'a>>>(
173162 bus_map : bus_map. clone ( ) ,
174163 } ;
175164
176- // Convert the jump destinations to u64 for compatibility with the `collect_basic_blocks` function.
177- let jumpdest_set = jumpdest_set
178- . iter ( )
179- . map ( |& x| x as u64 )
180- . collect :: < BTreeSet < _ > > ( ) ;
181-
182- let blocks = collect_basic_blocks :: < BabyBearOpenVmApcAdapter > ( & program, & jumpdest_set, & airs) ;
165+ let blocks = original_program. collect_basic_blocks ( config. degree_bound . identities ) ;
166+ let exe = original_program. exe ;
167+ let debug_info = original_program. elf . debug_info ( ) ;
183168 tracing:: info!(
184169 "Got {} basic blocks from `collect_basic_blocks`" ,
185170 blocks. len( )
@@ -264,36 +249,6 @@ pub fn customize<'a, P: PgoAdapter<Adapter = BabyBearOpenVmApcAdapter<'a>>>(
264249 }
265250}
266251
267- /// Besides the base RISCV-V branching instructions, the bigint extension adds two more branching
268- /// instruction classes over BranchEqual and BranchLessThan.
269- /// Those instructions have the form <INSTR rs0 rs1 target_offset ...>, where target_offset is the
270- /// relative jump we're interested in.
271- /// This means that for a given program address A containing the instruction above,
272- /// we add A + target_offset as a target as well.
273- fn add_extra_targets < F : PrimeField32 > (
274- program : & OpenVmProgram < F > ,
275- mut labels : BTreeSet < u32 > ,
276- base_pc : u32 ,
277- pc_step : u32 ,
278- ) -> BTreeSet < u32 > {
279- let branch_opcodes_bigint = branch_opcodes_bigint_set ( ) ;
280- let new_labels = program
281- . instructions_and_debug_infos
282- . iter ( )
283- . enumerate ( )
284- . filter_map ( |( i, instr) | {
285- let instr = instr. as_ref ( ) . unwrap ( ) . 0 . clone ( ) ;
286- let adjusted_pc = base_pc + ( i as u32 ) * pc_step;
287- let op = instr. opcode ;
288- branch_opcodes_bigint
289- . contains ( & op)
290- . then_some ( adjusted_pc + instr. c . as_canonical_u32 ( ) )
291- } ) ;
292- labels. extend ( new_labels) ;
293-
294- labels
295- }
296-
297252pub fn openvm_bus_interaction_to_powdr < F : PrimeField32 > (
298253 interaction : & SymbolicInteraction < F > ,
299254 columns : & [ Arc < String > ] ,
0 commit comments