Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
Add regalloc2-tool#148
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| [workspace] | ||
| members = ["regalloc2-tool"] | ||
| [package] | ||
| name = "regalloc2" | ||
| version = "0.9.1" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [package] | ||
| name = "regalloc2-tool" | ||
| authors = [ | ||
| "Chris Fallin <chris@cfallin.org>", | ||
| "Mozilla SpiderMonkey Developers", | ||
| ] | ||
| version = "0.0.0" | ||
| edition = "2021" | ||
| publish = false | ||
| license = "Apache-2.0 WITH LLVM-exception" | ||
| description = "Tool for testing regalloc2" | ||
| repository = "https://github.com/bytecodealliance/regalloc2" | ||
| [dependencies] | ||
| bincode = "1.3.3" | ||
| clap = { version = "4.3.11", features = ["derive"] } | ||
| pretty_env_logger = "0.5.0" | ||
| regalloc2 = { path = "..", features = ["trace-log", "enable-serde"] } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use std::path::PathBuf; | ||
| use clap::Parser; | ||
| use regalloc2::{ | ||
| checker::Checker, serialize::SerializableFunction, Block, Edit, Function, InstOrEdit, Output, | ||
| RegallocOptions, | ||
| }; | ||
| #[derive(Parser)] | ||
| /// Tool for testing regalloc2. | ||
| struct Args { | ||
| /// Print the input function and the result of register allocation. | ||
| #[clap(short = 'v')] | ||
| verbose: bool, | ||
| /// Input file containing a bincode-encoded SerializedFunction. | ||
| input: PathBuf, | ||
| } | ||
| fn main() { | ||
| pretty_env_logger::init(); | ||
| let args = Args::parse(); | ||
| let input = std::fs::read(&args.input).expect("could not read input file"); | ||
| let function: SerializableFunction = | ||
| bincode::deserialize(&input).expect("could not deserialize input file"); | ||
| if args.verbose { | ||
| println!("Input function: {function:?}"); | ||
| } | ||
| let options = RegallocOptions { | ||
| verbose_log: true, | ||
| validate_ssa: true, | ||
| }; | ||
| let output = match regalloc2::run(&function, function.machine_env(), &options) { | ||
| Ok(output) => output, | ||
| Err(e) => { | ||
| panic!("Register allocation failed: {e:#?}"); | ||
| } | ||
| }; | ||
| if args.verbose { | ||
| print_output(&function, &output); | ||
| } | ||
| let mut checker = Checker::new(&function, function.machine_env()); | ||
| checker.prepare(&output); | ||
| if let Err(e) = checker.run() { | ||
| panic!("Regsiter allocation checker failed: {e:#?}"); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Regsiter/Register/ ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. | ||
| } | ||
| } | ||
| fn print_output(func: &SerializableFunction, output: &Output) { | ||
| print!("Register allocation result: {{\n"); | ||
| for i in 0..func.num_blocks() { | ||
| let block = Block::new(i); | ||
| let succs = func | ||
| .block_succs(block) | ||
| .iter() | ||
| .map(|b| b.index()) | ||
| .collect::<Vec<_>>(); | ||
| let preds = func | ||
| .block_preds(block) | ||
| .iter() | ||
| .map(|b| b.index()) | ||
| .collect::<Vec<_>>(); | ||
| print!(" block{}: # succs:{:?} preds:{:?}\n", i, succs, preds); | ||
| for inst_or_edit in output.block_insts_and_edits(func, block) { | ||
| match inst_or_edit { | ||
| InstOrEdit::Inst(inst) => { | ||
| let op = if func.is_ret(inst) { | ||
| "ret" | ||
| } else if func.is_branch(inst) { | ||
| "branch" | ||
| } else { | ||
| "op" | ||
| }; | ||
| let ops: Vec<_> = func | ||
| .inst_operands(inst) | ||
| .iter() | ||
| .zip(output.inst_allocs(inst)) | ||
| .map(|(op, alloc)| format!("{op} => {alloc}")) | ||
| .collect(); | ||
| let ops = ops.join(", "); | ||
| print!(" inst{}: {op} {ops}\n", inst.index(),); | ||
| } | ||
| InstOrEdit::Edit(Edit::Move { from, to }) => { | ||
| print!(" edit: move {to} <- {from}\n"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| print!("}}\n"); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.