summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/SimplifyGlobals.cpp14
-rw-r--r--test/lit/passes/simplify-globals-prefer_earlier.wast53
-rw-r--r--test/passes/simplify-globals-optimizing_all-features.txt4
-rw-r--r--test/passes/simplify-globals_all-features.txt4
4 files changed, 67 insertions, 8 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp
index e411adf55..02e685ca7 100644
--- a/src/passes/SimplifyGlobals.cpp
+++ b/src/passes/SimplifyGlobals.cpp
@@ -505,7 +505,11 @@ struct SimplifyGlobals : public Pass {
map[ex->value].exported = true;
}
}
- GlobalUseScanner(&map).run(getPassRunner(), module);
+
+ GlobalUseScanner scanner(&map);
+ scanner.run(getPassRunner(), module);
+ scanner.runOnModuleCode(getPassRunner(), module);
+
// We now know which are immutable in practice.
for (auto& global : module->globals) {
auto& info = map[global->name];
@@ -601,8 +605,8 @@ struct SimplifyGlobals : public Pass {
}
void preferEarlierImports() {
- // Optimize uses of immutable globals, prefer the earlier import when
- // there is a copy.
+ // Optimize uses of immutable globals, prefer the earlier one when there is
+ // a copy.
NameNameMap copiedParentMap;
for (auto& global : module->globals) {
auto child = global->name;
@@ -626,7 +630,9 @@ struct SimplifyGlobals : public Pass {
}
}
// Apply to the gets.
- GlobalUseModifier(&copiedParentMap).run(getPassRunner(), module);
+ GlobalUseModifier modifier(&copiedParentMap);
+ modifier.run(getPassRunner(), module);
+ modifier.runOnModuleCode(getPassRunner(), module);
}
}
diff --git a/test/lit/passes/simplify-globals-prefer_earlier.wast b/test/lit/passes/simplify-globals-prefer_earlier.wast
new file mode 100644
index 000000000..4d8b17abb
--- /dev/null
+++ b/test/lit/passes/simplify-globals-prefer_earlier.wast
@@ -0,0 +1,53 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.
+
+;; RUN: foreach %s %t wasm-opt -all --simplify-globals -S -o - | filecheck %s
+
+;; When a global is copied into another, prefer the earlier one in later gets.
+;;
+;; The global.gets in the definitions of $global2,3,4 should all point to
+;; $global1, as should the gets in the function below.
+(module
+ ;; CHECK: (type $0 (func))
+
+ ;; CHECK: (import "a" "b" (global $global1 i32))
+ (import "a" "b" (global $global1 i32))
+
+ ;; CHECK: (global $global2 i32 (global.get $global1))
+ (global $global2 i32 (global.get $global1))
+
+ ;; CHECK: (global $global3 i32 (global.get $global1))
+ (global $global3 i32 (global.get $global2))
+
+ ;; CHECK: (global $global4 i32 (global.get $global1))
+ (global $global4 i32 (global.get $global3))
+
+ ;; CHECK: (func $simple (type $0)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $simple
+ (drop
+ (global.get $global1)
+ )
+ (drop
+ (global.get $global2)
+ )
+ (drop
+ (global.get $global3)
+ )
+ (drop
+ (global.get $global4)
+ )
+ )
+)
diff --git a/test/passes/simplify-globals-optimizing_all-features.txt b/test/passes/simplify-globals-optimizing_all-features.txt
index 1ffd2a2b3..72c0620a6 100644
--- a/test/passes/simplify-globals-optimizing_all-features.txt
+++ b/test/passes/simplify-globals-optimizing_all-features.txt
@@ -15,8 +15,8 @@
(type $0 (func))
(import "env" "global-1" (global $g1 i32))
(global $g2 i32 (global.get $g1))
- (global $g3 i32 (global.get $g2))
- (global $g4 i32 (global.get $g3))
+ (global $g3 i32 (global.get $g1))
+ (global $g4 i32 (global.get $g1))
(func $foo (type $0)
(drop
(global.get $g1)
diff --git a/test/passes/simplify-globals_all-features.txt b/test/passes/simplify-globals_all-features.txt
index 3273148e1..e885b3cfe 100644
--- a/test/passes/simplify-globals_all-features.txt
+++ b/test/passes/simplify-globals_all-features.txt
@@ -15,8 +15,8 @@
(type $0 (func))
(import "env" "global-1" (global $g1 i32))
(global $g2 i32 (global.get $g1))
- (global $g3 i32 (global.get $g2))
- (global $g4 i32 (global.get $g3))
+ (global $g3 i32 (global.get $g1))
+ (global $g4 i32 (global.get $g1))
(func $foo (type $0)
(drop
(global.get $g1)