Skip to content

Update binaryen & other deps #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a2efc69
init
MaxGraey Sep 10, 2021
4a38ac4
add extra optimize globals
MaxGraey Sep 10, 2021
26879cd
refactor
MaxGraey Sep 10, 2021
11a147c
Merge branch 'main' into update-binaryen
MaxGraey Sep 10, 2021
239a9a0
Merge branch 'main' into update-binaryen
MaxGraey Sep 11, 2021
3c6e167
update
MaxGraey Sep 11, 2021
9cc6c3f
Merge branch 'main' into update-binaryen
MaxGraey Sep 14, 2021
cabd405
update
MaxGraey Sep 14, 2021
e382f03
Merge branch 'main' into update-binaryen
MaxGraey Sep 15, 2021
ace69ef
update
MaxGraey Sep 15, 2021
46b3618
update
MaxGraey Sep 16, 2021
1776a59
update
MaxGraey Sep 17, 2021
84085dc
update
MaxGraey Sep 18, 2021
9f5752b
add extra ssa-nomerge
MaxGraey Sep 20, 2021
bebcc54
better
MaxGraey Sep 20, 2021
80cc26a
add reorder-locals
MaxGraey Sep 20, 2021
bdfbe8d
Revert "add reorder-locals"
MaxGraey Sep 20, 2021
070985b
add simplify-locals
MaxGraey Sep 20, 2021
786d1b3
better
MaxGraey Sep 20, 2021
8764c99
remove merge-blocks
MaxGraey Sep 20, 2021
93502c4
add merge-block earlier
MaxGraey Sep 20, 2021
54dc7dc
better
MaxGraey Sep 20, 2021
436e57b
update
MaxGraey Sep 21, 2021
ec9f31f
update
MaxGraey Sep 23, 2021
459cce6
add vacuum after simplify-locals-notee-nostructure
MaxGraey Sep 23, 2021
01cf56a
better
MaxGraey Sep 23, 2021
96a4344
do later
MaxGraey Sep 23, 2021
a138412
update
MaxGraey Sep 24, 2021
f54dce1
update
MaxGraey Sep 25, 2021
db620bc
one more simplify-globals-optimizing
MaxGraey Sep 25, 2021
3fc740e
add late rse
MaxGraey Sep 25, 2021
25ebef6
update
MaxGraey Sep 30, 2021
68f070c
update. Add TableGet operation
MaxGraey Oct 2, 2021
8629f1f
update
MaxGraey Oct 5, 2021
3bbff0c
update
MaxGraey Oct 6, 2021
5c26848
update binaryen. Add table_get, table_set and table_size
MaxGraey Oct 10, 2021
94fb972
update
MaxGraey Oct 13, 2021
7237f9d
update
MaxGraey Oct 14, 2021
7c56cc1
now simplify some hardcoded opts
MaxGraey Oct 14, 2021
0645cb9
update. Add table_grow operation
MaxGraey Oct 19, 2021
c059eae
refactor
MaxGraey Oct 19, 2021
2deba58
update
MaxGraey Oct 20, 2021
0ac8a4f
update webpack and other deps
MaxGraey Oct 20, 2021
c391804
fix webpack builds on node 17
MaxGraey Oct 20, 2021
668282d
fix?
MaxGraey Oct 20, 2021
ae06241
revert
MaxGraey Oct 20, 2021
a83f149
fix?
MaxGraey Oct 20, 2021
7aabff7
fix?
MaxGraey Oct 20, 2021
ce0b88f
Merge branch 'main' into update-binaryen
MaxGraey Oct 23, 2021
db8d5c1
update
MaxGraey Oct 23, 2021
f10c108
update
MaxGraey Oct 23, 2021
b8e65ef
fix audit
MaxGraey Oct 23, 2021
bb0212f
move rse earlier
MaxGraey Oct 25, 2021
99c95de
add local-subtyping pass for GC
MaxGraey Oct 26, 2021
eea18d2
update
MaxGraey Oct 27, 2021
482dde4
refactor
MaxGraey Oct 27, 2021
a7895b6
bump
MaxGraey Oct 30, 2021
83a2cdf
chang ^ to ~ for ts dep
MaxGraey Oct 30, 2021
44a5ff9
update webpack to latest
MaxGraey Oct 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
567 changes: 295 additions & 272 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "101.0.0-nightly.20210904",
"binaryen": "102.0.0-nightly.20211028",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"source-map-support": "^0.5.20",
"ts-node": "^6.2.0"
},
"devDependencies": {
"@types/node": "^15.6.1",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"@types/node": "^16.11.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"diff": "^5.0.0",
"eslint": "^7.15.0",
"glob": "^7.1.6",
"eslint": "^7.32.0",
"glob": "^7.2.0",
"physical-cpu-count": "^2.0.0",
"source-map-support": "^0.5.19",
"ts-loader": "^9.2.2",
"ts-loader": "^9.2.6",
"ts-node": "^6.2.0",
"typescript": "~4.2.4",
"webpack": "^5.59.1",
"typescript": "^4.4.4",
"webpack": "^5.61.0",
"webpack-cli": "^4.9.1"
},
"type": "commonjs",
Expand Down
26 changes: 26 additions & 0 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,32 @@ export declare function _BinaryenRefEqSetLeft(expr: ExpressionRef, leftExpr: Exp
export declare function _BinaryenRefEqGetRight(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenRefEqSetRight(expr: ExpressionRef, rightExpr: ExpressionRef): void;

export declare function _BinaryenTableGet(module: ModuleRef, name: StringRef, index: ExpressionRef, type: TypeRef): ExpressionRef;
export declare function _BinaryenTableGetGetTable(expr: ExpressionRef): StringRef;
export declare function _BinaryenTableGetSetTable(expr: ExpressionRef, table: StringRef): void;
export declare function _BinaryenTableGetGetIndex(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableGetSetIndex(expr: ExpressionRef, index: ExpressionRef): void;

export declare function _BinaryenTableSet(module: ModuleRef, name: StringRef, index: ExpressionRef, value: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableSetGetTable(expr: ExpressionRef): StringRef;
export declare function _BinaryenTableSetSetTable(expr: ExpressionRef, table: StringRef): void;
export declare function _BinaryenTableSetGetIndex(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableSetSetIndex(expr: ExpressionRef, index: ExpressionRef): void;
export declare function _BinaryenTableSetGetValue(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableSetSetValue(expr: ExpressionRef, value: ExpressionRef): void;

export declare function _BinaryenTableSize(module: ModuleRef, name: StringRef): ExpressionRef;
export declare function _BinaryenTableSizeGetTable(expr: ExpressionRef): StringRef;
export declare function _BinaryenTableSizeSetTable(expr: ExpressionRef, table: StringRef): void;

export declare function _BinaryenTableGrow(module: ModuleRef, name: StringRef, value: ExpressionRef, delta: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableGrowGetTable(expr: ExpressionRef): StringRef;
export declare function _BinaryenTableGrowSetTable(expr: ExpressionRef, table: StringRef): void;
export declare function _BinaryenTableGrowGetValue(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableGrowSetValue(expr: ExpressionRef, value: ExpressionRef): void;
export declare function _BinaryenTableGrowGetDelta(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTableGrowSetDelta(expr: ExpressionRef, delta: ExpressionRef): void;

export declare function _BinaryenTry(module: ModuleRef, name: StringRef, bodyExpr: ExpressionRef, catchTags: ArrayRef<StringRef>, numCatchTags: Index, catchBodies: ArrayRef<ExpressionRef>, numCatchBodies: Index, delegateTarget: StringRef): ExpressionRef;
export declare function _BinaryenTryGetName(expr: ExpressionRef): StringRef;
export declare function _BinaryenTrySetName(expr: ExpressionRef, name: StringRef): void;
Expand Down
119 changes: 81 additions & 38 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export enum FeatureFlags {
GC = 1024 /* _BinaryenFeatureGC */,
Memory64 = 2048 /* _BinaryenFeatureMemory64 */,
TypedFunctionReferences = 4096 /* _BinaryenFeatureTypedFunctionReferences */,
All = 16383 /* _BinaryenFeatureAll */
RelaxedSIMD = 16384 /* _BinaryenFeatureRelaxedSIMD */,
All = 32767 /* _BinaryenFeatureAll */
}

/** Binaryen expression id constants. */
Expand Down Expand Up @@ -126,28 +127,33 @@ export enum ExpressionId {
RefIs = 42 /* _BinaryenRefIsId */,
RefFunc = 43 /* _BinaryenRefFuncId */,
RefEq = 44 /* _BinaryenRefEqId */,
Try = 45 /* _BinaryenTryId */,
Throw = 46 /* _BinaryenThrowId */,
Rethrow = 47 /* _BinaryenRethrowId */,
TupleMake = 48 /* _BinaryenTupleMakeId */,
TupleExtract = 49 /* _BinaryenTupleExtractId */,
I31New = 50 /* _BinaryenI31NewId */,
I31Get = 51 /* _BinaryenI31GetId */,
CallRef = 52 /* _BinaryenCallRefId */,
RefTest = 53 /* _BinaryenRefTestId */,
RefCast = 54 /* _BinaryenRefCastId */,
BrOn = 55 /* _BinaryenBrOnId */,
RttCanon = 56 /* _BinaryenRttCanonId */,
RttSub = 57 /* _BinaryenRttSubId */,
StructNew = 58 /* _BinaryenStructNewId */,
StructGet = 59 /* _BinaryenStructGetId */,
StructSet = 60 /* _BinaryenStructSetId */,
ArrayNew = 61 /* _BinaryenArrayNewId */,
ArrayGet = 62 /* _BinaryenArrayGetId */,
ArraySet = 63 /* _BinaryenArraySetId */,
ArrayLen = 64 /* _BinaryenArrayLenId */,
ArrayCopy = 65 /* _BinaryenArrayCopyId */,
RefAs = 66 /* _BinaryenRefAsId */
TableGet = 45 /* _BinaryenTableGetId */,
TableSet = 46 /* _BinaryenTableSetId */,
TableSize = 47 /* _BinaryenTableSizeId */,
TableGrow = 48 /* _BinaryenTableGrowId */,
Try = 49 /* _BinaryenTryId */,
Throw = 50 /* _BinaryenThrowId */,
Rethrow = 51 /* _BinaryenRethrowId */,
TupleMake = 52 /* _BinaryenTupleMakeId */,
TupleExtract = 53 /* _BinaryenTupleExtractId */,
I31New = 54 /* _BinaryenI31NewId */,
I31Get = 55 /* _BinaryenI31GetId */,
CallRef = 56 /* _BinaryenCallRefId */,
RefTest = 57 /* _BinaryenRefTestId */,
RefCast = 58 /* _BinaryenRefCastId */,
BrOn = 59 /* _BinaryenBrOnId */,
RttCanon = 60 /* _BinaryenRttCanonId */,
RttSub = 61 /* _BinaryenRttSubId */,
StructNew = 62 /* _BinaryenStructNewId */,
StructGet = 63 /* _BinaryenStructGetId */,
StructSet = 64 /* _BinaryenStructSetId */,
ArrayNew = 65 /* _BinaryenArrayNewId */,
ArrayInit = 66 /* _BinaryenArrayInitId */,
ArrayGet = 67 /* _BinaryenArrayGetId */,
ArraySet = 68 /* _BinaryenArraySetId */,
ArrayLen = 69 /* _BinaryenArrayLenId */,
ArrayCopy = 70 /* _BinaryenArrayCopyId */,
RefAs = 71 /* _BinaryenRefAsId */
}

/** Binaryen external kind constants. */
Expand Down Expand Up @@ -1239,6 +1245,16 @@ export class Module {
return binaryen._BinaryenMemoryGrow(this.ref, delta);
}

table_size(name: string): ExpressionRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenTableSize(this.ref, cStr);
}

table_grow(name: string, delta: ExpressionRef, value: ExpressionRef = 0): ExpressionRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenTableGrow(this.ref, cStr, value, delta);
}

local_get(
index: i32,
type: TypeRef
Expand Down Expand Up @@ -1276,6 +1292,15 @@ export class Module {
return binaryen._BinaryenGlobalGet(this.ref, cStr, type);
}

table_get(
name: string,
index: ExpressionRef,
type: TypeRef
): ExpressionRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenTableGet(this.ref, cStr, index, type);
}

load(
bytes: Index,
signed: bool,
Expand Down Expand Up @@ -1380,6 +1405,15 @@ export class Module {
return binaryen._BinaryenGlobalSet(this.ref, cStr, value);
}

table_set(
name: string,
index: ExpressionRef,
value: ExpressionRef
): ExpressionRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenTableSet(this.ref, cStr, index, value);
}

block(
label: string | null,
children: ExpressionRef[],
Expand Down Expand Up @@ -2267,13 +2301,15 @@ export class Module {
passes.push("local-cse");
passes.push("remove-unused-brs");
passes.push("remove-unused-names");
passes.push("merge-blocks");
passes.push("precompute-propagate");
}
if (optimizeLevel >= 3) {
passes.push("simplify-locals-nostructure");
passes.push("flatten");
passes.push("vacuum");
passes.push("simplify-locals-notee-nostructure");
passes.push("vacuum");
passes.push("licm");
passes.push("merge-locals");
passes.push("reorder-locals");
Expand All @@ -2295,6 +2331,7 @@ export class Module {
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("pick-load-signs");
passes.push("simplify-globals-optimizing");
passes.push("simplify-globals-optimizing");
}
passes.push("simplify-locals-notee-nostructure");
passes.push("vacuum");
Expand All @@ -2307,25 +2344,24 @@ export class Module {
passes.push("coalesce-locals");
passes.push("reorder-locals");
passes.push("vacuum");

if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("rse");
passes.push("vacuum");
}
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("merge-locals");
passes.push("vacuum");
}
passes.push("vacuum");
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("simplify-globals-optimizing");
passes.push("simplify-globals-optimizing");
}
passes.push("merge-blocks");
passes.push("remove-unused-brs");
passes.push("remove-unused-names");
passes.push("merge-blocks");
if (optimizeLevel >= 3) {
passes.push("optimize-instructions");
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("rse");
passes.push("vacuum");
}

// --- PassRunner::addDefaultGlobalOptimizationPostPasses ---

Expand Down Expand Up @@ -2353,8 +2389,10 @@ export class Module {
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("code-folding");
}
if (optimizeLevel > 1 && (this.getFeatures() & FeatureFlags.GC) != 0) {
if (optimizeLevel >= 2 && (this.getFeatures() & FeatureFlags.GC) != 0) {
passes.push("heap2local");
passes.push("merge-locals");
passes.push("local-subtyping");
}
// precompute works best after global optimizations
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
Expand All @@ -2367,6 +2405,7 @@ export class Module {
passes.push("dae-optimizing"); // reduce arity
passes.push("inlining-optimizing"); // and inline if possible
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("ssa-nomerge");
passes.push("rse");
// move code on early return (after CFG cleanup)
passes.push("code-pushing");
Expand All @@ -2390,8 +2429,10 @@ export class Module {

passes.push("inlining");
passes.push("precompute-propagate");
passes.push("rse");
passes.push("vacuum");

passes.push("ssa-nomerge");
passes.push("simplify-locals");
passes.push("coalesce-locals");
}
passes.push("remove-unused-brs");
Expand Down Expand Up @@ -2963,12 +3004,14 @@ export enum SideEffects {
WritesGlobal = 32 /* _BinaryenSideEffectWritesGlobal */,
ReadsMemory = 64 /* _BinaryenSideEffectReadsMemory */,
WritesMemory = 128 /* _BinaryenSideEffectWritesMemory */,
ImplicitTrap = 256 /* _BinaryenSideEffectImplicitTrap */,
IsAtomic = 512 /* _BinaryenSideEffectIsAtomic */,
Throws = 1024 /* _BinaryenSideEffectThrows */,
DanglingPop = 2048 /* _BinaryenSideEffectDanglingPop */,
TrapsNeverHappen = 4096 /* _BinaryenSideEffectTrapsNeverHappen */,
Any = 8191 /* _BinaryenSideEffectAny */
ReadsTable = 256 /* _BinaryenSideEffectReadsTable */,
WritesTable = 512 /* _BinaryenSideEffectWritesTable */,
ImplicitTrap = 1024 /* _BinaryenSideEffectImplicitTrap */,
IsAtomic = 2048 /* _BinaryenSideEffectIsAtomic */,
Throws = 4096 /* _BinaryenSideEffectThrows */,
DanglingPop = 8192 /* _BinaryenSideEffectDanglingPop */,
TrapsNeverHappen = 16384 /* _BinaryenSideEffectTrapsNeverHappen */,
Any = 32767 /* _BinaryenSideEffectAny */
}

export function getSideEffects(expr: ExpressionRef, module: ModuleRef): SideEffects {
Expand Down
3 changes: 1 addition & 2 deletions std/assembly/util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ export function isSpace(c: u32): bool {
if (c < 0x1680) { // < <LS> (1)
// <SP>, <TAB>, <LF>, <VT>, <FF>, <CR> and <NBSP>
// (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0
// @ts-ignore: cast
return ((c | 0x80) == 0xA0) | (c - 0x09 <= 0x0D - 0x09);
return ((c | 0x80) == 0xA0) || (c - 0x09 <= 0x0D - 0x09);
}
if (c - 0x2000 <= 0x200A - 0x2000) return true;
switch (c) {
Expand Down
3 changes: 1 addition & 2 deletions std/assembly/util/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,5 @@ function loadHex(src: usize, offset: usize): u32 {

// @ts-ignore: decorator
@inline function isHex(ch: u32): bool {
// @ts-ignore
return (ch - CharCode._0 < 10) | ((ch | 32) - CharCode.a < 6);
return (ch - CharCode._0 < 10) || ((ch | 32) - CharCode.a < 6);
}
31 changes: 15 additions & 16 deletions tests/compiler/NonNullable.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
i32.load offset=16
i32.const 1
i32.shr_u
local.tee $2
local.tee $3
local.get $1
i32.const 20
i32.sub
Expand All @@ -59,32 +59,31 @@
end
block $__inlined_func$~lib/util/string/compareImpl (result i32)
local.get $0
local.tee $3
local.tee $2
i32.const 7
i32.and
local.get $1
i32.const 7
i32.and
i32.or
i32.const 1
local.get $2
i32.eqz
local.get $3
local.tee $0
i32.const 4
i32.ge_u
select
i32.eqz
i32.and
if
loop $do-loop|0
local.get $3
local.get $2
i64.load
local.get $1
i64.load
i64.eq
if
local.get $3
local.get $2
i32.const 8
i32.add
local.set $3
local.set $2
local.get $1
i32.const 8
i32.add
Expand All @@ -101,29 +100,29 @@
end
loop $while-continue|1
local.get $0
local.tee $2
local.tee $3
i32.const 1
i32.sub
local.set $0
local.get $2
local.get $3
if
local.get $3
local.get $2
i32.load16_u
local.tee $2
local.tee $3
local.get $1
i32.load16_u
local.tee $4
i32.ne
if
local.get $2
local.get $3
local.get $4
i32.sub
br $__inlined_func$~lib/util/string/compareImpl
end
local.get $3
local.get $2
i32.const 2
i32.add
local.set $3
local.set $2
local.get $1
i32.const 2
i32.add
Expand Down
Loading