Skip to content

Commit 0994588

Browse files
authored
Remove f32 legalization from LegalizeJSInterface (#2052)
As well as i64 splitting this pass was also converting f32 to f64 at the wasm boundry. However it appears this is not actually useful and makes somethings (such as dynamic linking) harder.
1 parent c3ed0f1 commit 0994588

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+489
-1266
lines changed

src/passes/LegalizeJSInterface.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
// across modules, we still want to legalize dynCalls so JS can call into the
3030
// table even to a signature that is not legal.
3131
//
32-
// This pass also legalizes according to asm.js FFI rules, which
33-
// disallow f32s. TODO: an option to not do that, if it matters?
34-
//
3532

3633
#include <utility>
3734
#include "wasm.h"
@@ -124,9 +121,9 @@ struct LegalizeJSInterface : public Pass {
124121
template<typename T>
125122
bool isIllegal(T* t) {
126123
for (auto param : t->params) {
127-
if (param == i64 || param == f32) return true;
124+
if (param == i64) return true;
128125
}
129-
return t->result == i64 || t->result == f32;
126+
return t->result == i64;
130127
}
131128

132129
// Check if an export should be legalized.
@@ -158,9 +155,6 @@ struct LegalizeJSInterface : public Pass {
158155
call->operands.push_back(I64Utilities::recreateI64(builder, legal->params.size(), legal->params.size() + 1));
159156
legal->params.push_back(i32);
160157
legal->params.push_back(i32);
161-
} else if (param == f32) {
162-
call->operands.push_back(builder.makeUnary(DemoteFloat64, builder.makeGetLocal(legal->params.size(), f64)));
163-
legal->params.push_back(f64);
164158
} else {
165159
call->operands.push_back(builder.makeGetLocal(legal->params.size(), param));
166160
legal->params.push_back(param);
@@ -177,9 +171,6 @@ struct LegalizeJSInterface : public Pass {
177171
block->list.push_back(I64Utilities::getI64Low(builder, index));
178172
block->finalize();
179173
legal->body = block;
180-
} else if (func->result == f32) {
181-
legal->result = f64;
182-
legal->body = builder.makeUnary(PromoteFloat32, call);
183174
} else {
184175
legal->result = func->result;
185176
legal->body = call;
@@ -216,9 +207,6 @@ struct LegalizeJSInterface : public Pass {
216207
call->operands.push_back(I64Utilities::getI64High(builder, func->params.size()));
217208
type->params.push_back(i32);
218209
type->params.push_back(i32);
219-
} else if (param == f32) {
220-
call->operands.push_back(builder.makeUnary(PromoteFloat32, builder.makeGetLocal(func->params.size(), f32)));
221-
type->params.push_back(f64);
222210
} else {
223211
call->operands.push_back(builder.makeGetLocal(func->params.size(), param));
224212
type->params.push_back(param);
@@ -232,10 +220,6 @@ struct LegalizeJSInterface : public Pass {
232220
Expression* get = builder.makeCall(f->name, {}, call->type);
233221
func->body = I64Utilities::recreateI64(builder, call, get);
234222
type->result = i32;
235-
} else if (imFunctionType->result == f32) {
236-
call->type = f64;
237-
func->body = builder.makeUnary(DemoteFloat64, call);
238-
type->result = f64;
239223
} else {
240224
call->type = imFunctionType->result;
241225
func->body = call;

src/wasm/wasm-emscripten.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ Function* EmscriptenGlueGenerator::generateAssignGOTEntriesFunction() {
241241
} else {
242242
ImportInfo info(wasm);
243243
f = info.getImportedFunction(ENV, g->base);
244+
if (!f) {
245+
Fatal() << "GOT.func entry with no import/export: " << g->base;
246+
}
244247
}
245248

246249
Name getter((std::string("fp$") + g->base.c_str() + std::string("$") + getSig(f)).c_str());

test/lld/duplicate_imports.wast.out

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
(type $FUNCSIG$fifd (func (param i32 f32 f64) (result f32)))
88
(type $FUNCSIG$fidd (func (param i32 f64 f64) (result f32)))
99
(type $legaltype$puts2 (func (param i32 i32) (result i32)))
10-
(type $legaltype$invoke_ffd (func (param i32 f64 f64) (result f64)))
11-
(type $legaltype$invoke_ffd2 (func (param i32 f64 f64) (result f64)))
1210
(import "env" "puts" (func $puts1 (param i32) (result i32)))
11+
(import "env" "invoke_ffd" (func $invoke_ffd (param i32 f32 f64) (result f32)))
12+
(import "env" "invoke_ffd" (func $invoke_ffd2 (param i32 f64 f64) (result f32)))
1313
(import "env" "puts" (func $legalimport$puts2 (param i32 i32) (result i32)))
14-
(import "env" "invoke_ffd" (func $legalimport$invoke_ffd (param i32 f64 f64) (result f64)))
15-
(import "env" "invoke_ffd" (func $legalimport$invoke_ffd2 (param i32 f64 f64) (result f64)))
1614
(memory $0 2)
1715
(data (i32.const 568) "Hello, world\00")
1816
(table $0 1 1 funcref)
@@ -80,26 +78,6 @@
8078
)
8179
)
8280
)
83-
(func $legalfunc$invoke_ffd (; 11 ;) (param $0 i32) (param $1 f32) (param $2 f64) (result f32)
84-
(f32.demote_f64
85-
(call $legalimport$invoke_ffd
86-
(local.get $0)
87-
(f64.promote_f32
88-
(local.get $1)
89-
)
90-
(local.get $2)
91-
)
92-
)
93-
)
94-
(func $legalfunc$invoke_ffd2 (; 12 ;) (param $0 i32) (param $1 f64) (param $2 f64) (result f32)
95-
(f32.demote_f64
96-
(call $legalimport$invoke_ffd2
97-
(local.get $0)
98-
(local.get $1)
99-
(local.get $2)
100-
)
101-
)
102-
)
10381
)
10482
(;
10583
--BEGIN METADATA --

test/min.fromasm

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,38 @@
33
(data (global.get $__memory_base) "min.asm.js")
44
(import "env" "__memory_base" (global $__memory_base i32))
55
(global $M (mut i32) (i32.const 0))
6-
(export "floats" (func $legalstub$floats))
6+
(export "floats" (func $floats))
77
(export "getTempRet0" (func $ub))
8-
(export "neg" (func $legalstub$neg))
9-
(export "bitcasts" (func $legalstub$bitcasts))
8+
(export "neg" (func $neg))
9+
(export "bitcasts" (func $bitcasts))
1010
(export "ctzzzz" (func $ctzzzz))
11-
(func $ctzzzz (; 0 ;) (; has Stack IR ;) (result i32)
12-
(i32.const 2)
13-
)
14-
(func $ub (; 1 ;) (; has Stack IR ;) (result i32)
15-
(drop
16-
(call $ub)
17-
)
18-
(global.get $M)
19-
)
20-
(func $legalstub$floats (; 2 ;) (; has Stack IR ;) (param $0 f64) (result f64)
21-
(f64.promote_f32
22-
(f32.add
23-
(f32.const 0)
24-
(f32.demote_f64
25-
(local.get $0)
26-
)
27-
)
11+
(func $floats (; 0 ;) (; has Stack IR ;) (param $0 f32) (result f32)
12+
(f32.add
13+
(f32.const 0)
14+
(local.get $0)
2815
)
2916
)
30-
(func $legalstub$neg (; 3 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f64)
17+
(func $neg (; 1 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f32)
3118
(i32.store
3219
(local.get $0)
3320
(local.get $1)
3421
)
35-
(f64.promote_f32
36-
(f32.neg
37-
(f32.load
38-
(local.get $0)
39-
)
22+
(f32.neg
23+
(f32.load
24+
(local.get $0)
4025
)
4126
)
4227
)
43-
(func $legalstub$bitcasts (; 4 ;) (; has Stack IR ;) (param $0 i32) (param $1 f64)
28+
(func $bitcasts (; 2 ;) (; has Stack IR ;) (param $0 i32) (param $1 f32)
4429
(nop)
4530
)
31+
(func $ctzzzz (; 3 ;) (; has Stack IR ;) (result i32)
32+
(i32.const 2)
33+
)
34+
(func $ub (; 4 ;) (; has Stack IR ;) (result i32)
35+
(drop
36+
(call $ub)
37+
)
38+
(global.get $M)
39+
)
4640
)

test/min.fromasm.clamp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,38 @@
33
(data (global.get $__memory_base) "min.asm.js")
44
(import "env" "__memory_base" (global $__memory_base i32))
55
(global $M (mut i32) (i32.const 0))
6-
(export "floats" (func $legalstub$floats))
6+
(export "floats" (func $floats))
77
(export "getTempRet0" (func $ub))
8-
(export "neg" (func $legalstub$neg))
9-
(export "bitcasts" (func $legalstub$bitcasts))
8+
(export "neg" (func $neg))
9+
(export "bitcasts" (func $bitcasts))
1010
(export "ctzzzz" (func $ctzzzz))
11-
(func $ctzzzz (; 0 ;) (; has Stack IR ;) (result i32)
12-
(i32.const 2)
13-
)
14-
(func $ub (; 1 ;) (; has Stack IR ;) (result i32)
15-
(drop
16-
(call $ub)
17-
)
18-
(global.get $M)
19-
)
20-
(func $legalstub$floats (; 2 ;) (; has Stack IR ;) (param $0 f64) (result f64)
21-
(f64.promote_f32
22-
(f32.add
23-
(f32.const 0)
24-
(f32.demote_f64
25-
(local.get $0)
26-
)
27-
)
11+
(func $floats (; 0 ;) (; has Stack IR ;) (param $0 f32) (result f32)
12+
(f32.add
13+
(f32.const 0)
14+
(local.get $0)
2815
)
2916
)
30-
(func $legalstub$neg (; 3 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f64)
17+
(func $neg (; 1 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f32)
3118
(i32.store
3219
(local.get $0)
3320
(local.get $1)
3421
)
35-
(f64.promote_f32
36-
(f32.neg
37-
(f32.load
38-
(local.get $0)
39-
)
22+
(f32.neg
23+
(f32.load
24+
(local.get $0)
4025
)
4126
)
4227
)
43-
(func $legalstub$bitcasts (; 4 ;) (; has Stack IR ;) (param $0 i32) (param $1 f64)
28+
(func $bitcasts (; 2 ;) (; has Stack IR ;) (param $0 i32) (param $1 f32)
4429
(nop)
4530
)
31+
(func $ctzzzz (; 3 ;) (; has Stack IR ;) (result i32)
32+
(i32.const 2)
33+
)
34+
(func $ub (; 4 ;) (; has Stack IR ;) (result i32)
35+
(drop
36+
(call $ub)
37+
)
38+
(global.get $M)
39+
)
4640
)

test/min.fromasm.clamp.no-opts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
(import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32))
77
(global $tDP (mut i32) (global.get $tDP$asm2wasm$import))
88
(global $M (mut i32) (i32.const 0))
9-
(export "floats" (func $legalstub$floats))
9+
(export "floats" (func $floats))
1010
(export "getTempRet0" (func $ub))
11-
(export "neg" (func $legalstub$neg))
12-
(export "bitcasts" (func $legalstub$bitcasts))
11+
(export "neg" (func $neg))
12+
(export "bitcasts" (func $bitcasts))
1313
(export "ctzzzz" (func $ctzzzz))
1414
(func $floats (; 0 ;) (param $f f32) (result f32)
1515
(local $t f32)
@@ -73,29 +73,4 @@
7373
(global.get $M)
7474
)
7575
)
76-
(func $legalstub$floats (; 5 ;) (param $0 f64) (result f64)
77-
(f64.promote_f32
78-
(call $floats
79-
(f32.demote_f64
80-
(local.get $0)
81-
)
82-
)
83-
)
84-
)
85-
(func $legalstub$neg (; 6 ;) (param $0 i32) (param $1 i32) (result f64)
86-
(f64.promote_f32
87-
(call $neg
88-
(local.get $0)
89-
(local.get $1)
90-
)
91-
)
92-
)
93-
(func $legalstub$bitcasts (; 7 ;) (param $0 i32) (param $1 f64)
94-
(call $bitcasts
95-
(local.get $0)
96-
(f32.demote_f64
97-
(local.get $1)
98-
)
99-
)
100-
)
10176
)

test/min.fromasm.imprecise

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
(module
22
(import "env" "memory" (memory $memory 256 256))
33
(global $M (mut i32) (i32.const 0))
4-
(export "floats" (func $legalstub$floats))
4+
(export "floats" (func $floats))
55
(export "getTempRet0" (func $ub))
6-
(export "neg" (func $legalstub$neg))
7-
(export "bitcasts" (func $legalstub$bitcasts))
6+
(export "neg" (func $neg))
7+
(export "bitcasts" (func $bitcasts))
88
(export "ctzzzz" (func $ctzzzz))
9-
(func $ctzzzz (; 0 ;) (; has Stack IR ;) (result i32)
10-
(i32.const 2)
11-
)
12-
(func $ub (; 1 ;) (; has Stack IR ;) (result i32)
13-
(drop
14-
(call $ub)
15-
)
16-
(global.get $M)
17-
)
18-
(func $legalstub$floats (; 2 ;) (; has Stack IR ;) (param $0 f64) (result f64)
19-
(f64.promote_f32
20-
(f32.add
21-
(f32.const 0)
22-
(f32.demote_f64
23-
(local.get $0)
24-
)
25-
)
9+
(func $floats (; 0 ;) (; has Stack IR ;) (param $0 f32) (result f32)
10+
(f32.add
11+
(f32.const 0)
12+
(local.get $0)
2613
)
2714
)
28-
(func $legalstub$neg (; 3 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f64)
15+
(func $neg (; 1 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result f32)
2916
(i32.store
3017
(local.get $0)
3118
(local.get $1)
3219
)
33-
(f64.promote_f32
34-
(f32.neg
35-
(f32.load
36-
(local.get $0)
37-
)
20+
(f32.neg
21+
(f32.load
22+
(local.get $0)
3823
)
3924
)
4025
)
41-
(func $legalstub$bitcasts (; 4 ;) (; has Stack IR ;) (param $0 i32) (param $1 f64)
26+
(func $bitcasts (; 2 ;) (; has Stack IR ;) (param $0 i32) (param $1 f32)
4227
(nop)
4328
)
29+
(func $ctzzzz (; 3 ;) (; has Stack IR ;) (result i32)
30+
(i32.const 2)
31+
)
32+
(func $ub (; 4 ;) (; has Stack IR ;) (result i32)
33+
(drop
34+
(call $ub)
35+
)
36+
(global.get $M)
37+
)
4438
)

0 commit comments

Comments
 (0)