Skip to content

Commit

Permalink
Improve precomputation of static instanceof (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 21, 2019
1 parent 1fd20a8 commit 070d67f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 655 deletions.
22 changes: 14 additions & 8 deletions src/module.ts
Expand Up @@ -1106,10 +1106,16 @@ export class Module {
var func = this.addTemporaryFunction(type, null, expr);
var names = this.cachedPrecomputeNames;
if (!names) {
this.cachedPrecomputeNames = names = allocI32Array([ this.allocStringCached("precompute") ]);
this.cachedPrecomputeNames = names = allocI32Array([
this.allocStringCached("vacuum"),
this.allocStringCached("precompute")
]);
}
_BinaryenFunctionRunPasses(func, this.ref, names, 1);
_BinaryenFunctionRunPasses(func, this.ref, names, 2);
expr = _BinaryenFunctionGetBody(func);
if (_BinaryenExpressionGetId(expr) == ExpressionId.Return) {
expr = _BinaryenReturnGetValue(expr);
}
this.removeTemporaryFunction();

// reset optimize levels to previous
Expand Down Expand Up @@ -1194,7 +1200,7 @@ export class Module {
var nested1: ExpressionRef,
nested2: ExpressionRef;

switch (_BinaryenExpressionGetId(expr)) {
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.Const: {
switch (_BinaryenExpressionGetType(expr)) {
case NativeType.I32: {
Expand Down Expand Up @@ -1562,12 +1568,12 @@ export class Relooper {
}

// export function hasSideEffects(expr: ExpressionRef): bool {
// switch (_BinaryenExpressionGetId(expr = getPtr(expr))) {
// case ExpressionId.GetLocal:
// case ExpressionId.GetGlobal:
// // TODO: there's more
// switch (_BinaryenExpressionGetId(expr)) {
// case ExpressionId.LocalGet:
// case ExpressionId.GlobalGet:
// case ExpressionId.Const:
// case ExpressionId.Nop:
// case ExpressionId.Unreachable: {
// case ExpressionId.Nop: {
// return false;
// }
// case ExpressionId.Block: {
Expand Down
44 changes: 4 additions & 40 deletions tests/compiler/instanceof.untouched.wat
Expand Up @@ -19,56 +19,20 @@
(export "memory" (memory $0))
(start $start)
(func $instanceof/isI32<i32> (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
drop
i32.const 1
if
i32.const 1
return
else
i32.const 0
return
end
unreachable
return
)
(func $instanceof/isI32<f64> (; 2 ;) (type $FUNCSIG$id) (param $0 f64) (result i32)
local.get $0
drop
i32.const 0
if
i32.const 1
return
else
i32.const 0
return
end
unreachable
return
)
(func $instanceof/isI32<u32> (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
drop
i32.const 0
if
i32.const 1
return
else
i32.const 0
return
end
unreachable
return
)
(func $instanceof/isI32<u16> (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
drop
i32.const 0
if
i32.const 1
return
else
i32.const 0
return
end
unreachable
return
)
(func $~lib/rt/stub/__retain (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
Expand Down

0 comments on commit 070d67f

Please sign in to comment.