Skip to content

Commit

Permalink
Update disas tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jan 14, 2025
1 parent bb9172d commit ae25083
Show file tree
Hide file tree
Showing 166 changed files with 1,009 additions and 1,013 deletions.
29 changes: 12 additions & 17 deletions tests/disas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ impl Test {
let mut config = self.opts.config(None)?;
config.target(&self.config.target)?;
match self.config.test {
TestKind::Clif | TestKind::Optimize => {
TestKind::Clif => {
config.emit_clif(tempdir.path());
config.cranelift_opt_level(OptLevel::None);
}
TestKind::Optimize => {
config.emit_clif(tempdir.path());
}
TestKind::Compile => {}
Expand All @@ -204,6 +208,11 @@ impl Test {
{
let entry = entry.context("failed to iterate over tempdir")?;
let path = entry.path();
if let Some(name) = path.file_name().and_then(|s| s.to_str()) {
if !name.starts_with("wasm_func_") {
continue;
}
}
let clif = std::fs::read_to_string(&path)
.with_context(|| format!("failed to read clif file {path:?}"))?;
clifs.push(clif);
Expand Down Expand Up @@ -243,6 +252,7 @@ impl Test {
_ => unreachable!(),
};
flags.set("opt_level", opt_level)?;
flags.set("preserve_frame_pointers", "true")?;
for (key, val) in self.opts.codegen.cranelift.iter() {
let key = &key.replace("-", "_");
let target_res = match val {
Expand Down Expand Up @@ -283,14 +293,7 @@ fn assert_output(
for mut func in funcs {
match kind {
TestKind::Compile | TestKind::Winch => unreachable!(),
TestKind::Optimize => {
let mut ctx = cranelift_codegen::Context::for_function(func.clone());
ctx.optimize(isa, &mut Default::default())
.map_err(|e| codegen_error_to_anyhow_error(&ctx.func, e))?;
ctx.func.dfg.resolve_all_aliases();
writeln!(&mut actual, "{}", ctx.func.display()).unwrap();
}
TestKind::Clif => {
TestKind::Optimize | TestKind::Clif => {
func.dfg.resolve_all_aliases();
writeln!(&mut actual, "{}", func.display()).unwrap();
}
Expand Down Expand Up @@ -526,11 +529,3 @@ fn assert_or_bless_output(path: &Path, wat: &str, actual: &str) -> Result<()> {
.header("expected", "actual")
)
}

fn codegen_error_to_anyhow_error(
func: &cranelift_codegen::ir::Function,
err: cranelift_codegen::CodegenError,
) -> anyhow::Error {
let s = cranelift_codegen::print_errors::pretty_error(func, err);
anyhow::anyhow!("{}", s)
}
10 changes: 5 additions & 5 deletions tests/disas/basic-wat-test.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: i32):
;; @0021 v5 = uextend.i64 v2
;; @0021 v6 = global_value.i64 gv5
;; @0021 v6 = load.i64 notrap aligned readonly checked v0+96
;; @0021 v7 = iadd v6, v5
;; @0021 v8 = load.i32 little heap v7
;; @0026 v9 = uextend.i64 v3
;; @0026 v10 = global_value.i64 gv5
;; @0026 v10 = load.i64 notrap aligned readonly checked v0+96
;; @0026 v11 = iadd v10, v9
;; @0026 v12 = load.i32 little heap v11
;; @0029 v13 = iadd v8, v12
;; @002a jump block1(v13)
;; @002a jump block1
;;
;; block1(v4: i32):
;; @002a return v4
;; block1:
;; @002a return v13
;; }
72 changes: 36 additions & 36 deletions tests/disas/br_table.wat
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@
;; @0025 br_table v7, block8, [block5, block6, block7] ; v7 = 0
;;
;; block5:
;; @0025 jump block4(v6) ; v6 = 42
;; @0025 jump block4
;;
;; block6:
;; @0025 jump block3(v6) ; v6 = 42
;; @0025 jump block3
;;
;; block7:
;; @0025 jump block2(v6) ; v6 = 42
;; @0025 jump block2
;;
;; block8:
;; @0025 jump block1(v6) ; v6 = 42
;; @0025 jump block1
;;
;; block4(v5: i32):
;; @002c jump block3(v5)
;; block4:
;; @002c jump block3
;;
;; block3(v4: i32):
;; @002d jump block2(v4)
;; block3:
;; @002d jump block2
;;
;; block2(v3: i32):
;; @002e jump block1(v3)
;; block2:
;; @002e jump block1
;;
;; block1(v2: i32):
;; @002e return v2
;; block1:
;; @002e return v6 ; v6 = 42
;; }
;;
;; function u0:1(i64 vmctx, i64) -> i32 tail {
Expand All @@ -79,28 +79,28 @@
;; @003b br_table v7, block8, [block5, block6, block7] ; v7 = 0
;;
;; block5:
;; @003b jump block1(v6) ; v6 = 42
;; @003b jump block1
;;
;; block6:
;; @003b jump block2(v6) ; v6 = 42
;; @003b jump block2
;;
;; block7:
;; @003b jump block3(v6) ; v6 = 42
;; @003b jump block3
;;
;; block8:
;; @003b jump block4(v6) ; v6 = 42
;; @003b jump block4
;;
;; block4(v5: i32):
;; @0042 jump block3(v5)
;; block4:
;; @0042 jump block3
;;
;; block3(v4: i32):
;; @0043 jump block2(v4)
;; block3:
;; @0043 jump block2
;;
;; block2(v3: i32):
;; @0044 jump block1(v3)
;; block2:
;; @0044 jump block1
;;
;; block1(v2: i32):
;; @0044 return v2
;; block1:
;; @0044 return v6 ; v6 = 42
;; }
;;
;; function u0:2(i64 vmctx, i64) -> i32 tail {
Expand All @@ -115,16 +115,16 @@
;; @004d br_table v5, block4, [block3, block3, block4] ; v5 = 0
;;
;; block3:
;; @004d jump block2(v4) ; v4 = 42
;; @004d jump block2
;;
;; block4:
;; @004d jump block1(v4) ; v4 = 42
;; @004d jump block1
;;
;; block2(v3: i32):
;; @0054 jump block1(v3)
;; block2:
;; @0054 jump block1
;;
;; block1(v2: i32):
;; @0054 return v2
;; block1:
;; @0054 return v4 ; v4 = 42
;; }
;;
;; function u0:3(i64 vmctx, i64) -> i32 tail {
Expand All @@ -139,14 +139,14 @@
;; @005d br_table v5, block4, [block3, block3, block4] ; v5 = 0
;;
;; block3:
;; @005d jump block1(v4) ; v4 = 42
;; @005d jump block1
;;
;; block4:
;; @005d jump block2(v4) ; v4 = 42
;; @005d jump block2
;;
;; block2(v3: i32):
;; @0064 jump block1(v3)
;; block2:
;; @0064 jump block1
;;
;; block1(v2: i32):
;; @0064 return v2
;; block1:
;; @0064 return v4 ; v4 = 42
;; }
6 changes: 3 additions & 3 deletions tests/disas/call-simd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
;; @004f v6 = bitcast.i32x4 little v3
;; @004f v7 = iadd v5, v6
;; @0052 v8 = bitcast.i8x16 little v7
;; @0052 jump block1(v8)
;; @0052 jump block1
;;
;; block1(v4: i8x16):
;; @0052 return v4
;; block1:
;; @0052 return v8
;; }
6 changes: 3 additions & 3 deletions tests/disas/call.wat
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
;;
;; block0(v0: i64, v1: i64):
;; @002b v3 = iconst.i32 1
;; @002d jump block1(v3) ; v3 = 1
;; @002d jump block1
;;
;; block1(v2: i32):
;; @002d return v2
;; block1:
;; @002d return v3 ; v3 = 1
;; }
8 changes: 4 additions & 4 deletions tests/disas/f32-load.wat
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
;;
;; block0(v0: i64, v1: i64, v2: i32):
;; @002e v4 = uextend.i64 v2
;; @002e v5 = global_value.i64 gv5
;; @002e v5 = load.i64 notrap aligned readonly checked v0+96
;; @002e v6 = iadd v5, v4
;; @002e v7 = load.f32 little heap v6
;; @0031 jump block1(v7)
;; @0031 jump block1
;;
;; block1(v3: f32):
;; @0031 return v3
;; block1:
;; @0031 return v7
;; }
2 changes: 1 addition & 1 deletion tests/disas/f32-store.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: f32):
;; @0031 v4 = uextend.i64 v2
;; @0031 v5 = global_value.i64 gv5
;; @0031 v5 = load.i64 notrap aligned readonly checked v0+96
;; @0031 v6 = iadd v5, v4
;; @0031 store little heap v3, v6
;; @0034 jump block1
Expand Down
8 changes: 4 additions & 4 deletions tests/disas/f64-load.wat
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
;;
;; block0(v0: i64, v1: i64, v2: i32):
;; @002e v4 = uextend.i64 v2
;; @002e v5 = global_value.i64 gv5
;; @002e v5 = load.i64 notrap aligned readonly checked v0+96
;; @002e v6 = iadd v5, v4
;; @002e v7 = load.f64 little heap v6
;; @0031 jump block1(v7)
;; @0031 jump block1
;;
;; block1(v3: f64):
;; @0031 return v3
;; block1:
;; @0031 return v7
;; }
2 changes: 1 addition & 1 deletion tests/disas/f64-store.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
;;
;; block0(v0: i64, v1: i64, v2: i32, v3: f64):
;; @0031 v4 = uextend.i64 v2
;; @0031 v5 = global_value.i64 gv5
;; @0031 v5 = load.i64 notrap aligned readonly checked v0+96
;; @0031 v6 = iadd v5, v4
;; @0031 store little heap v3, v6
;; @0034 jump block1
Expand Down
12 changes: 6 additions & 6 deletions tests/disas/fac-multi-value.wat
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64):
;; @0040 jump block1(v2, v2)
;; @0040 jump block1
;;
;; block1(v3: i64, v4: i64):
;; @0040 return v3, v4
;; block1:
;; @0040 return v2, v2
;; }
;;
;; function u0:1(i64 vmctx, i64, i64, i64) -> i64, i64, i64 tail {
Expand All @@ -40,10 +40,10 @@
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i64, v3: i64):
;; @0049 jump block1(v2, v3, v2)
;; @0049 jump block1
;;
;; block1(v4: i64, v5: i64, v6: i64):
;; @0049 return v4, v5, v6
;; block1:
;; @0049 return v2, v3, v2
;; }
;;
;; function u0:2(i64 vmctx, i64, i64) -> i64 tail {
Expand Down
2 changes: 1 addition & 1 deletion tests/disas/fibonacci.wat
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
;; block2:
;; @0056 v16 = iconst.i32 0
;; @005a v17 = uextend.i64 v16 ; v16 = 0
;; @005a v18 = global_value.i64 gv5
;; @005a v18 = load.i64 notrap aligned readonly checked v0+96
;; @005a v19 = iadd v18, v17
;; @005a store.i32 little heap v11, v19
;; @005d jump block1
Expand Down
10 changes: 5 additions & 5 deletions tests/disas/fixed-size-memory.wat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
;; @0041 v5 = iconst.i64 0x0001_0000
;; @0041 v6 = icmp uge v4, v5 ; v5 = 0x0001_0000
;; @0041 trapnz v6, heap_oob
;; @0041 v7 = global_value.i64 gv5
;; @0041 v7 = load.i64 notrap aligned checked v0+96
;; @0041 v8 = iadd v7, v4
;; @0041 istore8 little heap v3, v8
;; @0044 jump block1
Expand All @@ -57,11 +57,11 @@
;; @0049 v5 = iconst.i64 0x0001_0000
;; @0049 v6 = icmp uge v4, v5 ; v5 = 0x0001_0000
;; @0049 trapnz v6, heap_oob
;; @0049 v7 = global_value.i64 gv5
;; @0049 v7 = load.i64 notrap aligned checked v0+96
;; @0049 v8 = iadd v7, v4
;; @0049 v9 = uload8.i32 little heap v8
;; @004c jump block1(v9)
;; @004c jump block1
;;
;; block1(v3: i32):
;; @004c return v3
;; block1:
;; @004c return v9
;; }
5 changes: 2 additions & 3 deletions tests/disas/globals.wat
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
;; block0(v0: i64, v1: i64):
;; @0027 v2 = iconst.i32 0
;; @0029 v3 = iconst.i32 0
;; @002b v4 = global_value.i64 gv3
;; @002b v5 = load.i32 notrap aligned table v4+112
;; @002b v5 = load.i32 notrap aligned table v0+112
;; @002d v6 = uextend.i64 v3 ; v3 = 0
;; @002d v7 = global_value.i64 gv5
;; @002d v7 = load.i64 notrap aligned readonly checked v0+96
;; @002d v8 = iadd v7, v6
;; @002d store little heap v5, v8
;; @0030 jump block1
Expand Down
8 changes: 4 additions & 4 deletions tests/disas/i32-load.wat
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
;;
;; block0(v0: i64, v1: i64, v2: i32):
;; @002e v4 = uextend.i64 v2
;; @002e v5 = global_value.i64 gv5
;; @002e v5 = load.i64 notrap aligned readonly checked v0+96
;; @002e v6 = iadd v5, v4
;; @002e v7 = load.i32 little heap v6
;; @0031 jump block1(v7)
;; @0031 jump block1
;;
;; block1(v3: i32):
;; @0031 return v3
;; block1:
;; @0031 return v7
;; }
8 changes: 4 additions & 4 deletions tests/disas/i32-load16-s.wat
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
;;
;; block0(v0: i64, v1: i64, v2: i32):
;; @0032 v4 = uextend.i64 v2
;; @0032 v5 = global_value.i64 gv5
;; @0032 v5 = load.i64 notrap aligned readonly checked v0+96
;; @0032 v6 = iadd v5, v4
;; @0032 v7 = sload16.i32 little heap v6
;; @0035 jump block1(v7)
;; @0035 jump block1
;;
;; block1(v3: i32):
;; @0035 return v3
;; block1:
;; @0035 return v7
;; }
Loading

0 comments on commit ae25083

Please sign in to comment.