Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Reconstruct locations of the original source variable #698

Merged
merged 1 commit into from
May 9, 2019

Conversation

yurydelendik
Copy link
Collaborator

@yurydelendik yurydelendik commented Mar 6, 2019

  • attaches ValueLabel to every values that store the (wasm) variable value
  • use Liveness object to recover and group ranges for particular label
  • visualization of the results

TODO:

  • optimize build_value_labels_ranges algorithmic complexity
  • refactor visualization
  • fix range to start from top of EBB
  • better label indexing

Example:
https://gist.github.com/yurydelendik/46e12a65afc63d866b8482915dfe286b#file-fib2-wasm

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 20, 2019

Could you please add cranelift-frontend support for this, so every use_var for a specific variable will get the same ValueLabel?

cc bjorn3/rustc_codegen_cranelift#166.

@yurydelendik
Copy link
Collaborator Author

yurydelendik commented Mar 20, 2019

Could you please add

  • cranelift-frontend support ... so every use_var for a specific variable will get the same ValueLabel

@yurydelendik yurydelendik force-pushed the get-val-labels branch 2 times, most recently from acc17cf to 346ebe6 Compare March 27, 2019 22:02
@yurydelendik yurydelendik changed the title [WIP] Reconstruct locations of the original source variable Reconstruct locations of the original source variable Mar 28, 2019
@yurydelendik yurydelendik marked this pull request as ready for review March 28, 2019 22:42
/// Marked with a label value.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct ValueLabel(u32);
entity_impl!(ValueLabel, "val");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to use Variable instead of defining a new index type? In the code below, it always has the same value as the Variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to extend ValueLabel to be used for global or stack operands as well.

state.push1(builder.use_var(Variable::with_u32(local_index)))
state.push1(builder.use_var(Variable::with_u32(local_index)));
let label = ValueLabel::from_u32(local_index);
builder.set_val_label(state.peek1(), label);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing peek1 here to pull the Value back off the stack, can you just save the return value from use_var and use that instead? And ditto for TeeLocal below.

Also, if we switch from ValueLabel to just using Variable per my comment above, we could actually move this code into FunctionBuilder::use_var and def_var, which would make this functionality available to non-wasm users of Cranelift as well.

Also, I'm concerned about the overhead of doing set_val_label, which can do HashMap and Vec insertions, since GetLocal and SetLocal are some of the most frequent wasm opcodes. Do you know if this is significant right now? If it is, and if we make the other changes, one option would be to give FunctionBuilder a flag indicating whether it should collect debug info or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I can add a flag to not collect this info

@@ -127,6 +128,12 @@ fn declare_wasm_parameters(builder: &mut FunctionBuilder, entry_block: Ebb) -> u
let param_value = builder.ebb_params(entry_block)[i];
builder.def_var(local, param_value);
}
if param_type.purpose == ir::ArgumentPurpose::VMContext {
// Tracking vmctx as 0xffff_fffe label.
const VMCTX_LABEL: u32 = 0xffff_fffe;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this may complicate my suggestion above. Would it be possible to make cranelift-wasm declare an extra variable for this? It knows how many locals it has, so it can use that to compute the index one greater than the greatest local. That would also eliminate a magic-number dependency.

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@sunfishcode
Copy link
Member

Unfortunately, a lot of tests are now failing with "thread 'worker #0' panicked at 'Code layout must be computed first', cranelift-codegen/src/ir/function.rs:190:9". Could you take a look?

@yurydelendik yurydelendik force-pushed the get-val-labels branch 3 times, most recently from ad8e48c to 2e193c0 Compare April 16, 2019 23:18
@sunfishcode
Copy link
Member

Looks good, thanks!

@sunfishcode sunfishcode merged commit cb7fcce into bytecodealliance:master May 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants