diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/stringify.cpp | 32 | ||||
-rw-r--r-- | test/lit/help/wasm-opt.test | 2 | ||||
-rw-r--r-- | test/lit/help/wasm2js.test | 2 | ||||
-rw-r--r-- | test/lit/passes/outlining.wast | 108 |
4 files changed, 118 insertions, 26 deletions
diff --git a/test/gtest/stringify.cpp b/test/gtest/stringify.cpp index 8e854ee4b..59b7db6e1 100644 --- a/test/gtest/stringify.cpp +++ b/test/gtest/stringify.cpp @@ -250,29 +250,11 @@ TEST_F(StringifyTest, Stringify) { })); } -std::vector<SuffixTree::RepeatedSubstring> -repeatSubstrings(std::vector<uint32_t> hashString) { - SuffixTree st(hashString); - std::vector<SuffixTree::RepeatedSubstring> substrings(st.begin(), st.end()); - std::sort( - substrings.begin(), - substrings.end(), - [](SuffixTree::RepeatedSubstring a, SuffixTree::RepeatedSubstring b) { - size_t aWeight = a.Length * a.StartIndices.size(); - size_t bWeight = b.Length * b.StartIndices.size(); - if (aWeight == bWeight) { - return a.StartIndices[0] < b.StartIndices[0]; - } - return aWeight > bWeight; - }); - return substrings; -} - TEST_F(StringifyTest, Substrings) { Module wasm; parseWast(wasm, dupModuleText); auto hashString = hashStringifyModule(&wasm); - auto substrings = repeatSubstrings(hashString); + auto substrings = StringifyProcessor::repeatSubstrings(hashString); EXPECT_EQ( substrings, @@ -294,7 +276,7 @@ TEST_F(StringifyTest, DedupeSubstrings) { parseWast(wasm, dupModuleText); auto hashString = hashStringifyModule(&wasm); std::vector<SuffixTree::RepeatedSubstring> substrings = - repeatSubstrings(hashString); + StringifyProcessor::repeatSubstrings(hashString); auto result = StringifyProcessor::dedupe(substrings); EXPECT_EQ( @@ -332,10 +314,9 @@ TEST_F(StringifyTest, FilterLocalSets) { parseWast(wasm, localSetModuleText); HashStringifyWalker stringify = HashStringifyWalker(); stringify.walkModule(&wasm); - auto substrings = repeatSubstrings(stringify.hashString); - auto result = StringifyProcessor::dedupe(substrings); - - result = StringifyProcessor::filterLocalSets(substrings, stringify.exprs); + auto substrings = StringifyProcessor::repeatSubstrings(stringify.hashString); + auto result = + StringifyProcessor::filterLocalSets(substrings, stringify.exprs); EXPECT_EQ( result, @@ -375,8 +356,7 @@ TEST_F(StringifyTest, FilterBranches) { parseWast(wasm, branchesModuleText); HashStringifyWalker stringify = HashStringifyWalker(); stringify.walkModule(&wasm); - - auto substrings = repeatSubstrings(stringify.hashString); + auto substrings = StringifyProcessor::repeatSubstrings(stringify.hashString); auto result = StringifyProcessor::filterBranches(substrings, stringify.exprs); EXPECT_EQ( diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index 95d25cc61..b18c312ff 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -317,6 +317,8 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --optimize-stack-ir optimize Stack IR ;; CHECK-NEXT: +;; CHECK-NEXT: --outlining outline instructions +;; CHECK-NEXT: ;; CHECK-NEXT: --pick-load-signs pick load signs based on their ;; CHECK-NEXT: uses ;; CHECK-NEXT: diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index d3df47eb6..129374049 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -276,6 +276,8 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --optimize-stack-ir optimize Stack IR ;; CHECK-NEXT: +;; CHECK-NEXT: --outlining outline instructions +;; CHECK-NEXT: ;; CHECK-NEXT: --pick-load-signs pick load signs based on their ;; CHECK-NEXT: uses ;; CHECK-NEXT: diff --git a/test/lit/passes/outlining.wast b/test/lit/passes/outlining.wast new file mode 100644 index 000000000..d62570c11 --- /dev/null +++ b/test/lit/passes/outlining.wast @@ -0,0 +1,108 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: foreach %s %t wasm-opt --outlining -S -o - | filecheck %s + +;; TODO: Add a test that creates an outlined function with a sequence at beginning +;; TODO: Add a test that creates an outlined function with one return value +;; TODO: Add a test that creates an outlined function that no arguments +;; TODO: Add a test that creates an outlined function that returns multiple values +;; TODO: Add a test that makes sure we filter localSets correctly +;; TODO: Add a test that makes sure we filter localGets correctly +;; TODO: Add a test that makes sure we filter branches correctly +;; TODO: Add a test that makes sure we filter globals correctly +;; TODO: Add a test that fails to outline a single control flow that repeats + + +(module + ;; CHECK: (type $0 (func (result i32))) + + ;; CHECK: (type $1 (func (param i32))) + + ;; CHECK: (func $a (result i32) + ;; CHECK-NEXT: (call $outline$ + ;; CHECK-NEXT: (i32.const 7) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (i32.const 4) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $a (result i32) + (drop (i32.const 7)) + (drop (i32.const 1)) + (drop (i32.const 2)) + (return (i32.const 4)) + ) + ;; CHECK: (func $b (result i32) + ;; CHECK-NEXT: (call $outline$ + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (i32.const 5) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $b (result i32) + (drop (i32.const 0)) + (drop (i32.const 1)) + (drop (i32.const 2)) + (return (i32.const 5)) + ) +) + +;; Tests that outlining occurs properly when the sequence is at the end of a function. + +;; CHECK: (func $outline$ (param $0 i32) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (local.get $0) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (i32.const 1) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (i32.const 2) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +(module + ;; CHECK: (type $0 (func)) + + ;; CHECK: (type $1 (func (param i32))) + + ;; CHECK: (func $a + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.const 7) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (call $outline$ + ;; CHECK-NEXT: (i32.const 4) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $a + (drop (i32.const 7)) + (drop (i32.const 4)) + (drop (i32.const 1)) + (drop (i32.const 2)) + ) + ;; CHECK: (func $b + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (call $outline$ + ;; CHECK-NEXT: (i32.const 5) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $b + (drop (i32.const 0)) + (drop (i32.const 5)) + (drop (i32.const 1)) + (drop (i32.const 2)) + ) +) +;; CHECK: (func $outline$ (param $0 i32) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (local.get $0) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (i32.const 1) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (i32.const 2) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) |