Skip to content

Commit e4d014f

Browse files
authored
Remove replaced imports in LegalizeJSInterface (#1657)
This pass was replacing all the uses of certain imports but wasn't bothering to delete the old ones.
1 parent f109f3c commit e4d014f

8 files changed

+131
-145
lines changed

src/passes/LegalizeJSInterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ struct LegalizeJSInterface : public Pass {
7272
}
7373
}
7474
if (illegalToLegal.size() > 0) {
75+
for (auto& pair : illegalToLegal) {
76+
module->removeImport(pair.first);
77+
}
78+
7579
for (auto* im : newImports) {
7680
module->addImport(im);
7781
}

test/i64-setTempRet0.fromasm.clamp.no-opts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
(import "env" "table" (table 0 0 anyfunc))
66
(import "env" "memoryBase" (global $memoryBase i32))
77
(import "env" "tableBase" (global $tableBase i32))
8-
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
98
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
109
(global $tempRet0 (mut i32) (i32.const 0))
1110
(export "illegalResult" (func $legalstub$illegalResult))
1211
(export "imports" (func $imports))
13-
(func $illegalResult (; 2 ;) (result i64)
12+
(func $illegalResult (; 1 ;) (result i64)
1413
(return
1514
(i64.const 8589934593)
1615
)
1716
)
18-
(func $imports (; 3 ;) (result i32)
17+
(func $imports (; 2 ;) (result i32)
1918
(return
2019
(i32.wrap/i64
2120
(call $legalfunc$illegalImportResult)
2221
)
2322
)
2423
)
25-
(func $legalstub$illegalResult (; 4 ;) (result i32)
24+
(func $legalstub$illegalResult (; 3 ;) (result i32)
2625
(local $0 i64)
2726
(set_local $0
2827
(call $illegalResult)
@@ -39,7 +38,7 @@
3938
(get_local $0)
4039
)
4140
)
42-
(func $legalfunc$illegalImportResult (; 5 ;) (result i64)
41+
(func $legalfunc$illegalImportResult (; 4 ;) (result i64)
4342
(i64.or
4443
(i64.extend_u/i32
4544
(call $legalimport$illegalImportResult)

test/i64-setTempRet0.fromasm.imprecise.no-opts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
(import "env" "table" (table 0 0 anyfunc))
66
(import "env" "memoryBase" (global $memoryBase i32))
77
(import "env" "tableBase" (global $tableBase i32))
8-
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
98
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
109
(global $tempRet0 (mut i32) (i32.const 0))
1110
(export "illegalResult" (func $legalstub$illegalResult))
1211
(export "imports" (func $imports))
13-
(func $illegalResult (; 2 ;) (result i64)
12+
(func $illegalResult (; 1 ;) (result i64)
1413
(return
1514
(i64.const 8589934593)
1615
)
1716
)
18-
(func $imports (; 3 ;) (result i32)
17+
(func $imports (; 2 ;) (result i32)
1918
(return
2019
(i32.wrap/i64
2120
(call $legalfunc$illegalImportResult)
2221
)
2322
)
2423
)
25-
(func $legalstub$illegalResult (; 4 ;) (result i32)
24+
(func $legalstub$illegalResult (; 3 ;) (result i32)
2625
(local $0 i64)
2726
(set_local $0
2827
(call $illegalResult)
@@ -39,7 +38,7 @@
3938
(get_local $0)
4039
)
4140
)
42-
(func $legalfunc$illegalImportResult (; 5 ;) (result i64)
41+
(func $legalfunc$illegalImportResult (; 4 ;) (result i64)
4342
(i64.or
4443
(i64.extend_u/i32
4544
(call $legalimport$illegalImportResult)

test/i64-setTempRet0.fromasm.no-opts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
(import "env" "table" (table 0 0 anyfunc))
66
(import "env" "memoryBase" (global $memoryBase i32))
77
(import "env" "tableBase" (global $tableBase i32))
8-
(import "env" "illegalImportResult" (func $illegalImportResult (result i64)))
98
(import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32)))
109
(global $tempRet0 (mut i32) (i32.const 0))
1110
(export "illegalResult" (func $legalstub$illegalResult))
1211
(export "imports" (func $imports))
13-
(func $illegalResult (; 2 ;) (result i64)
12+
(func $illegalResult (; 1 ;) (result i64)
1413
(return
1514
(i64.const 8589934593)
1615
)
1716
)
18-
(func $imports (; 3 ;) (result i32)
17+
(func $imports (; 2 ;) (result i32)
1918
(return
2019
(i32.wrap/i64
2120
(call $legalfunc$illegalImportResult)
2221
)
2322
)
2423
)
25-
(func $legalstub$illegalResult (; 4 ;) (result i32)
24+
(func $legalstub$illegalResult (; 3 ;) (result i32)
2625
(local $0 i64)
2726
(set_local $0
2827
(call $illegalResult)
@@ -39,7 +38,7 @@
3938
(get_local $0)
4039
)
4140
)
42-
(func $legalfunc$illegalImportResult (; 5 ;) (result i64)
41+
(func $legalfunc$illegalImportResult (; 4 ;) (result i64)
4342
(i64.or
4443
(i64.extend_u/i32
4544
(call $legalimport$illegalImportResult)

test/lld/duplicate_imports.wast.out

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
(type $legaltype$invoke_ffd (func (param i32 f64 f64) (result f64)))
1111
(type $legaltype$invoke_ffd2 (func (param i32 f64 f64) (result f64)))
1212
(import "env" "puts" (func $puts1 (param i32) (result i32)))
13-
(import "env" "puts" (func $puts2 (param i64) (result i32)))
14-
(import "env" "invoke_ffd" (func $invoke_ffd (param i32 f32 f64) (result f32)))
15-
(import "env" "invoke_ffd" (func $invoke_ffd2 (param i32 f64 f64) (result f32)))
1613
(import "env" "puts" (func $legalimport$puts2 (param i32 i32) (result i32)))
1714
(import "env" "invoke_ffd" (func $legalimport$invoke_ffd (param i32 f64 f64) (result f64)))
1815
(import "env" "invoke_ffd" (func $legalimport$invoke_ffd2 (param i32 f64 f64) (result f64)))
@@ -31,18 +28,18 @@
3128
(export "stackAlloc" (func $stackAlloc))
3229
(export "stackRestore" (func $stackRestore))
3330
(export "__growWasmMemory" (func $__growWasmMemory))
34-
(func $main (; 7 ;) (type $1) (result i32)
31+
(func $main (; 4 ;) (type $1) (result i32)
3532
(drop
3633
(call $puts1
3734
(i32.const 568)
3835
)
3936
)
4037
(i32.const 0)
4138
)
42-
(func $__wasm_call_ctors (; 8 ;) (type $2)
39+
(func $__wasm_call_ctors (; 5 ;) (type $2)
4340
(nop)
4441
)
45-
(func $legalfunc$puts2 (; 9 ;) (param $0 i64) (result i32)
42+
(func $legalfunc$puts2 (; 6 ;) (param $0 i64) (result i32)
4643
(call $legalimport$puts2
4744
(i32.wrap/i64
4845
(get_local $0)
@@ -55,7 +52,7 @@
5552
)
5653
)
5754
)
58-
(func $legalfunc$invoke_ffd (; 10 ;) (param $0 i32) (param $1 f32) (param $2 f64) (result f32)
55+
(func $legalfunc$invoke_ffd (; 7 ;) (param $0 i32) (param $1 f32) (param $2 f64) (result f32)
5956
(f32.demote/f64
6057
(call $legalimport$invoke_ffd
6158
(get_local $0)
@@ -66,7 +63,7 @@
6663
)
6764
)
6865
)
69-
(func $legalfunc$invoke_ffd2 (; 11 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f32)
66+
(func $legalfunc$invoke_ffd2 (; 8 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f32)
7067
(f32.demote/f64
7168
(call $legalimport$invoke_ffd2
7269
(get_local $0)
@@ -75,10 +72,10 @@
7572
)
7673
)
7774
)
78-
(func $stackSave (; 12 ;) (result i32)
75+
(func $stackSave (; 9 ;) (result i32)
7976
(get_global $global$0)
8077
)
81-
(func $stackAlloc (; 13 ;) (param $0 i32) (result i32)
78+
(func $stackAlloc (; 10 ;) (param $0 i32) (result i32)
8279
(local $1 i32)
8380
(set_global $global$0
8481
(tee_local $1
@@ -93,12 +90,12 @@
9390
)
9491
(get_local $1)
9592
)
96-
(func $stackRestore (; 14 ;) (param $0 i32)
93+
(func $stackRestore (; 11 ;) (param $0 i32)
9794
(set_global $global$0
9895
(get_local $0)
9996
)
10097
)
101-
(func $__growWasmMemory (; 15 ;) (param $newSize i32) (result i32)
98+
(func $__growWasmMemory (; 12 ;) (param $newSize i32) (result i32)
10299
(grow_memory
103100
(get_local $newSize)
104101
)

0 commit comments

Comments
 (0)