Skip to content

Commit 273d7d1

Browse files
authored
Refactor pass pipeline for better precompute globals (AssemblyScript#2154)
1 parent eddf08c commit 273d7d1

File tree

84 files changed

+19736
-19517
lines changed

Some content is hidden

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

84 files changed

+19736
-19517
lines changed

src/module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,17 +2306,18 @@ export class Module {
23062306
if (optimizeLevel >= 2) {
23072307
passes.push("once-reduction");
23082308
passes.push("inlining");
2309+
passes.push("simplify-globals-optimizing");
23092310
}
23102311
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
23112312
passes.push("rse");
23122313
passes.push("vacuum");
23132314
passes.push("ssa-nomerge");
2314-
passes.push("simplify-globals-optimizing");
23152315
passes.push("local-cse");
23162316
passes.push("remove-unused-brs");
23172317
passes.push("remove-unused-names");
23182318
passes.push("merge-blocks");
23192319
passes.push("precompute-propagate");
2320+
passes.push("simplify-globals-optimizing");
23202321
}
23212322
if (optimizeLevel >= 3) {
23222323
passes.push("simplify-locals-nostructure");
@@ -2339,13 +2340,12 @@ export class Module {
23392340
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
23402341
passes.push("inlining");
23412342
passes.push("precompute-propagate");
2343+
passes.push("simplify-globals-optimizing");
23422344
} else {
23432345
passes.push("precompute");
23442346
}
23452347
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
23462348
passes.push("pick-load-signs");
2347-
passes.push("simplify-globals-optimizing");
2348-
passes.push("simplify-globals-optimizing");
23492349
}
23502350
passes.push("simplify-locals-notee-nostructure");
23512351
passes.push("vacuum");
@@ -2412,6 +2412,7 @@ export class Module {
24122412
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
24132413
passes.push("precompute-propagate");
24142414
passes.push("simplify-globals-optimizing");
2415+
passes.push("simplify-globals-optimizing");
24152416
} else {
24162417
passes.push("precompute");
24172418
}

tests/compiler/call-super.optimized.wat

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@
595595
(local $0 i32)
596596
(local $1 i32)
597597
memory.size
598-
local.tee $0
598+
local.tee $1
599599
i32.const 0
600600
i32.le_s
601601
if (result i32)
602602
i32.const 1
603-
local.get $0
603+
local.get $1
604604
i32.sub
605605
memory.grow
606606
i32.const 0
@@ -618,26 +618,26 @@
618618
i32.const 0
619619
i32.store
620620
loop $for-loop|0
621-
local.get $1
621+
local.get $0
622622
i32.const 23
623623
i32.lt_u
624624
if
625-
local.get $1
625+
local.get $0
626626
i32.const 2
627627
i32.shl
628628
i32.const 17984
629629
i32.add
630630
i32.const 0
631631
i32.store offset=4
632632
i32.const 0
633-
local.set $0
633+
local.set $1
634634
loop $for-loop|1
635-
local.get $0
635+
local.get $1
636636
i32.const 16
637637
i32.lt_u
638638
if
639-
local.get $0
640639
local.get $1
640+
local.get $0
641641
i32.const 4
642642
i32.shl
643643
i32.add
@@ -647,17 +647,17 @@
647647
i32.add
648648
i32.const 0
649649
i32.store offset=96
650-
local.get $0
650+
local.get $1
651651
i32.const 1
652652
i32.add
653-
local.set $0
653+
local.set $1
654654
br $for-loop|1
655655
end
656656
end
657-
local.get $1
657+
local.get $0
658658
i32.const 1
659659
i32.add
660-
local.set $1
660+
local.set $0
661661
br $for-loop|0
662662
end
663663
end
@@ -1666,7 +1666,7 @@
16661666
i32.const 2
16671667
i32.store offset=4
16681668
global.get $~lib/memory/__stack_pointer
1669-
global.get $~lib/memory/__stack_pointer
1669+
local.tee $2
16701670
i32.const 4
16711671
i32.sub
16721672
global.set $~lib/memory/__stack_pointer
@@ -1706,6 +1706,7 @@
17061706
i32.const 4
17071707
i32.add
17081708
global.set $~lib/memory/__stack_pointer
1709+
local.get $2
17091710
local.get $0
17101711
i32.store
17111712
local.get $0
@@ -1804,7 +1805,7 @@
18041805
i32.const 2
18051806
i32.store offset=4
18061807
global.get $~lib/memory/__stack_pointer
1807-
global.get $~lib/memory/__stack_pointer
1808+
local.tee $2
18081809
i32.const 4
18091810
i32.sub
18101811
global.set $~lib/memory/__stack_pointer
@@ -1832,6 +1833,7 @@
18321833
i32.const 4
18331834
i32.add
18341835
global.set $~lib/memory/__stack_pointer
1836+
local.get $2
18351837
local.get $0
18361838
i32.store
18371839
local.get $0
@@ -1927,7 +1929,7 @@
19271929
local.tee $0
19281930
i32.store
19291931
global.get $~lib/memory/__stack_pointer
1930-
global.get $~lib/memory/__stack_pointer
1932+
local.tee $2
19311933
i32.const 4
19321934
i32.sub
19331935
global.set $~lib/memory/__stack_pointer
@@ -1967,6 +1969,7 @@
19671969
i32.const 4
19681970
i32.add
19691971
global.set $~lib/memory/__stack_pointer
1972+
local.get $2
19701973
local.get $0
19711974
i32.store
19721975
local.get $0
@@ -2038,7 +2041,7 @@
20382041
local.tee $0
20392042
i32.store
20402043
global.get $~lib/memory/__stack_pointer
2041-
global.get $~lib/memory/__stack_pointer
2044+
local.tee $2
20422045
i32.const 4
20432046
i32.sub
20442047
global.set $~lib/memory/__stack_pointer
@@ -2066,6 +2069,7 @@
20662069
i32.const 4
20672070
i32.add
20682071
global.set $~lib/memory/__stack_pointer
2072+
local.get $2
20692073
local.get $0
20702074
i32.store
20712075
local.get $0
@@ -2137,7 +2141,7 @@
21372141
local.tee $0
21382142
i32.store
21392143
global.get $~lib/memory/__stack_pointer
2140-
global.get $~lib/memory/__stack_pointer
2144+
local.tee $2
21412145
i32.const 4
21422146
i32.sub
21432147
global.set $~lib/memory/__stack_pointer
@@ -2165,6 +2169,7 @@
21652169
i32.const 4
21662170
i32.add
21672171
global.set $~lib/memory/__stack_pointer
2172+
local.get $2
21682173
local.get $0
21692174
i32.store
21702175
local.get $0
@@ -2223,19 +2228,19 @@
22232228
local.get $0
22242229
i32.const 20
22252230
i32.sub
2226-
local.tee $0
2231+
local.tee $1
22272232
i32.load offset=4
22282233
i32.const 3
22292234
i32.and
22302235
i32.eq
22312236
if
22322237
global.get $~lib/rt/itcms/iter
2233-
local.get $0
2238+
local.get $1
22342239
i32.eq
22352240
if
2236-
local.get $0
2241+
local.get $1
22372242
i32.load offset=8
2238-
local.tee $1
2243+
local.tee $0
22392244
i32.eqz
22402245
if
22412246
i32.const 0
@@ -2245,22 +2250,22 @@
22452250
call $~lib/builtins/abort
22462251
unreachable
22472252
end
2248-
local.get $1
2253+
local.get $0
22492254
global.set $~lib/rt/itcms/iter
22502255
end
22512256
block $__inlined_func$~lib/rt/itcms/Object#unlink
2252-
local.get $0
2257+
local.get $1
22532258
i32.load offset=4
22542259
i32.const -4
22552260
i32.and
2256-
local.tee $1
2261+
local.tee $0
22572262
i32.eqz
22582263
if
22592264
i32.const 0
2260-
local.get $0
2265+
local.get $1
22612266
i32.const 17980
22622267
i32.lt_u
2263-
local.get $0
2268+
local.get $1
22642269
i32.load offset=8
22652270
select
22662271
i32.eqz
@@ -2274,7 +2279,7 @@
22742279
end
22752280
br $__inlined_func$~lib/rt/itcms/Object#unlink
22762281
end
2277-
local.get $0
2282+
local.get $1
22782283
i32.load offset=8
22792284
local.tee $2
22802285
i32.eqz
@@ -2286,31 +2291,31 @@
22862291
call $~lib/builtins/abort
22872292
unreachable
22882293
end
2289-
local.get $1
2294+
local.get $0
22902295
local.get $2
22912296
i32.store offset=8
22922297
local.get $2
22932298
local.get $2
22942299
i32.load offset=4
22952300
i32.const 3
22962301
i32.and
2297-
local.get $1
2302+
local.get $0
22982303
i32.or
22992304
i32.store offset=4
23002305
end
23012306
global.get $~lib/rt/itcms/toSpace
23022307
local.set $2
2303-
local.get $0
2308+
local.get $1
23042309
i32.load offset=12
2305-
local.tee $1
2310+
local.tee $0
23062311
i32.const 1
23072312
i32.le_u
23082313
if (result i32)
23092314
i32.const 1
23102315
else
23112316
i32.const 1488
23122317
i32.load
2313-
local.get $1
2318+
local.get $0
23142319
i32.lt_u
23152320
if
23162321
i32.const 1296
@@ -2320,7 +2325,7 @@
23202325
call $~lib/builtins/abort
23212326
unreachable
23222327
end
2323-
local.get $1
2328+
local.get $0
23242329
i32.const 3
23252330
i32.shl
23262331
i32.const 1492
@@ -2338,25 +2343,25 @@
23382343
local.set $3
23392344
local.get $2
23402345
i32.load offset=8
2341-
local.set $1
2342-
local.get $0
2346+
local.set $0
2347+
local.get $1
23432348
local.get $2
23442349
local.get $3
23452350
i32.or
23462351
i32.store offset=4
2347-
local.get $0
23482352
local.get $1
2353+
local.get $0
23492354
i32.store offset=8
2350-
local.get $1
2351-
local.get $1
2355+
local.get $0
2356+
local.get $0
23522357
i32.load offset=4
23532358
i32.const 3
23542359
i32.and
2355-
local.get $0
2360+
local.get $1
23562361
i32.or
23572362
i32.store offset=4
23582363
local.get $2
2359-
local.get $0
2364+
local.get $1
23602365
i32.store offset=8
23612366
global.get $~lib/rt/itcms/visitCount
23622367
i32.const 1

0 commit comments

Comments
 (0)