summaryrefslogtreecommitdiff
path: root/test/gtest
diff options
context:
space:
mode:
authorAshley Nelson <nashley@google.com>2023-10-17 17:12:26 -0700
committerGitHub <noreply@github.com>2023-10-18 00:12:26 +0000
commitf45207e02f3f703ef96b23957538a935856cf874 (patch)
treec4820119a1e6fc1588c92a405753c40f8eec7ed0 /test/gtest
parent1be114f36d6a4d48dec69a070de0d66a729918e6 (diff)
downloadbinaryen-f45207e02f3f703ef96b23957538a935856cf874.tar.gz
binaryen-f45207e02f3f703ef96b23957538a935856cf874.tar.bz2
binaryen-f45207e02f3f703ef96b23957538a935856cf874.zip
[Outlining] Filter Local Set (#6018)
Adds a general purpose walker named FilterStringifyWalker, intended to walk control flow and take note of whether any of the expressions satisfy the condition. Also includes an << overload for SuffixTree::RepeatedSubstring to make debugging easier.
Diffstat (limited to 'test/gtest')
-rw-r--r--test/gtest/stringify.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/gtest/stringify.cpp b/test/gtest/stringify.cpp
index 14f5009e1..5b5e650e6 100644
--- a/test/gtest/stringify.cpp
+++ b/test/gtest/stringify.cpp
@@ -295,7 +295,7 @@ TEST_F(StringifyTest, DedupeSubstrings) {
auto hashString = hashStringifyModule(&wasm);
std::vector<SuffixTree::RepeatedSubstring> substrings =
repeatSubstrings(hashString);
- auto result = StringifyProcessor::dedupe(substrings);
+ auto result = StringifyProcessor::dedupe(std::move(substrings));
EXPECT_EQ(
result,
@@ -305,3 +305,44 @@ TEST_F(StringifyTest, DedupeSubstrings) {
// 10, 11, 6 appears at idx 23 and again at 34
SuffixTree::RepeatedSubstring{3u, (std::vector<unsigned>{23, 34})}}));
}
+
+TEST_F(StringifyTest, FilterLocalSets) {
+ static auto localSetModuleText = R"wasm(
+ (module
+ (func $a (result i32)
+ (local $x i32)
+ (local.set $x
+ (i32.const 1)
+ )
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (func $b (result i32)
+ (local $x i32)
+ (local.set $x
+ (i32.const 1)
+ )
+ (i32.const 5)
+ (i32.const 0)
+ (i32.const 1)
+ )
+ )
+ )wasm";
+ Module wasm;
+ parseWast(wasm, localSetModuleText);
+ HashStringifyWalker stringify = HashStringifyWalker();
+ stringify.walkModule(&wasm);
+ auto substrings = repeatSubstrings(stringify.hashString);
+ auto result = StringifyProcessor::dedupe(std::move(substrings));
+
+ result = StringifyProcessor::filter(
+ std::move(substrings), stringify.exprs, [](const Expression* curr) {
+ return curr->is<LocalSet>();
+ });
+
+ EXPECT_EQ(
+ result,
+ (std::vector<SuffixTree::RepeatedSubstring>{
+ // sequence i32.const 0, i32.const 1 appears at idx 6 and again at 16
+ SuffixTree::RepeatedSubstring{2u, (std::vector<unsigned>{6, 16})}}));
+}