-
Notifications
You must be signed in to change notification settings - Fork 123
Temporary register analysis #3330
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
base: main
Are you sure you want to change the base?
Conversation
openvm/src/tmp_register_analysis.rs
Outdated
| let opcode = instruction.opcode.as_usize(); | ||
|
|
||
| if opcode == OPCODE_JALR { | ||
| // For JALR, we don't know the target statically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can if the previous instruction was AUIPC: https://github.com/powdr-labs/powdr/blob/main/riscv-elf/src/rv64.rs#L211
| } | ||
|
|
||
| if BRANCH_OPCODES_BIGINT.contains(&opcode) || BRANCH_OPCODES.contains(&opcode) { | ||
| // All other branch instructions conditionally add `c` to the current PC, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other as opposed to JALR?
| 0 => (vec![], vec![]), | ||
| // PHANTOM | ||
| 1 => { | ||
| // TODO: Not sure what should happen here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/powdr-labs/openvm/blob/main/crates/vm/src/arch/segment.rs#L272
Here it doesn't seem to read/write registers. Would need to check other occurrences
| .map(|block| (block.start_pc, register_access_types(block))) | ||
| .collect::<BTreeMap<_, _>>(); | ||
| let block_ids = register_access_types.keys().copied().collect::<Vec<_>>(); | ||
| for i in 0.. { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intuitively it feels like there's a cubic way of doing the entire search, similar to Floyd-Warshall, but I haven't actually tried to prove that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't remember Floyd-Warshall rn, but noting that this runs 13 times in practice on the simple "guest" example. Worst case, this runs as many times as there are basic blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
28 now after 20ee691
| for (r, succ) in successor_access_types.iter().enumerate() { | ||
| let current = register_access_types.get(block_id).unwrap()[r]; | ||
| if current == RegisterAccessType::Unused && *succ != RegisterAccessType::Unused { | ||
| // Unused becomes whatever the successor is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true?:
For reg r, if in the current block its state is Write, and in the successor it's Read, we shouldn't change it because we can still use that information to potentially prune searches starting at the predecessors of the current block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but that's what the code does, no? It only updates the current block if the state is Unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we want is:
- Among the successors, read > write > unused
- The current block is only updated with the succor state if the current state is unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, actually no! I think this is a bug. we should not set the current block to write if any successor is still unknown!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha my first comment "is this true?" was referring to whether my understanding was correcf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, actually no! I think this is a bug. we should not set the current block to write if any successor is still unknown!
Yea agree with this, that's what I was trying to figure out
31343bb to
19df4cc
Compare
Following an idea from this doc, checks whether registers (1) written to before being read in a basic block and (2) also written to before read in all possible future basic blocks. If this is the case, the autoprecompile can skip changing their value.
cargo test -r guest_prove_simple -- --nocapture