Skip to content

Commit 58f18e1

Browse files
Some small changes
1 parent 2f5c1f9 commit 58f18e1

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

src/passes/DeadStoreElimination.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ struct ComparingLocalGraph : public LocalGraph {
110110
// One implementation of Logic can handle globals, another memory, and another
111111
// GC, etc., implementing the various hooks appropriately.
112112
struct Logic {
113-
Function* func;
114-
115-
Logic(Function* func, PassOptions& passOptions, Module& wasm) : func(func) {}
116-
117113
//============================================================================
118114
// Hooks to identify relevant things to include in the analysis.
119115
//============================================================================
@@ -228,13 +224,14 @@ struct DeadStoreCFG
228224
PassOptions& passOptions;
229225
LogicType logic;
230226

231-
DeadStoreCFG(Module& wasm, Function* func, PassOptions& passOptions)
232-
: func(func), passOptions(passOptions), logic(func, passOptions, wasm) {
227+
DeadStoreCFG(Module& wasm,
228+
Function* func,
229+
PassOptions& passOptions,
230+
LogicType logic)
231+
: func(func), passOptions(passOptions), logic(std::move(logic)) {
233232
this->setModule(&wasm);
234233
}
235234

236-
~DeadStoreCFG() {}
237-
238235
void visitExpression(Expression* curr) {
239236
if (!this->currBasicBlock) {
240237
return;
@@ -420,13 +417,12 @@ struct ComparingLogic : public Logic {
420417
ComparingLocalGraph localGraph;
421418

422419
ComparingLogic(Function* func, PassOptions& passOptions, Module& wasm)
423-
: Logic(func, passOptions, wasm), localGraph(func, passOptions, wasm) {}
420+
: localGraph(func, passOptions, wasm) {}
424421
};
425422

426423
// Optimize module globals: GlobalSet/GlobalGet.
427424
struct GlobalLogic : public Logic {
428-
GlobalLogic(Function* func, PassOptions& passOptions, Module& wasm)
429-
: Logic(func, passOptions, wasm) {}
425+
GlobalLogic(Function* func, PassOptions& passOptions, Module& wasm) {}
430426

431427
bool isStore(Expression* curr) { return curr->is<GlobalSet>(); }
432428

@@ -513,6 +509,9 @@ struct GCLogic : public ComparingLogic {
513509

514510
// Check whether two GC operations may alias memory.
515511
template<typename U, typename V> bool mayAlias(U* u, V* v) {
512+
static_assert(std::is_same_v<U, StructGet> || std::is_same_v<U, StructSet>);
513+
static_assert(std::is_same_v<V, StructGet> || std::is_same_v<V, StructSet>);
514+
516515
// If one of the inputs is unreachable, it does not execute, and so there
517516
// cannot be aliasing.
518517
auto uType = u->ref->type;
@@ -582,11 +581,19 @@ struct LocalDeadStoreElimination
582581

583582
void doWalkFunction(Function* func) {
584583
// Optimize globals.
585-
DeadStoreCFG<GlobalLogic>(*getModule(), func, getPassOptions()).optimize();
584+
DeadStoreCFG<GlobalLogic>(*getModule(),
585+
func,
586+
getPassOptions(),
587+
GlobalLogic(func, getPassOptions(), *getModule()))
588+
.optimize();
586589

587590
// Optimize GC heap.
588591
if (getModule()->features.hasGC()) {
589-
DeadStoreCFG<GCLogic>(*getModule(), func, getPassOptions()).optimize();
592+
DeadStoreCFG<GCLogic>(*getModule(),
593+
func,
594+
getPassOptions(),
595+
GCLogic(func, getPassOptions(), *getModule()))
596+
.optimize();
590597
}
591598
}
592599
};

test/lit/passes/ldse.wast

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
;; CHECK: (global $global$1 (mut i32) (i32.const 0))
2020
(global $global$1 (mut i32) (i32.const 0))
2121

22-
;; CHECK: (func $simple-param (type $3) (param $x (ref $A))
22+
;; CHECK: (func $simple-param (type $2) (param $x (ref $A))
2323
;; CHECK-NEXT: (block
2424
;; CHECK-NEXT: (drop
2525
;; CHECK-NEXT: (local.get $x)
@@ -59,7 +59,7 @@
5959
)
6060
)
6161

62-
;; CHECK: (func $simple-local (type $1)
62+
;; CHECK: (func $simple-local (type $3)
6363
;; CHECK-NEXT: (local $x (ref null $A))
6464
;; CHECK-NEXT: (block
6565
;; CHECK-NEXT: (drop
@@ -100,7 +100,7 @@
100100
)
101101
)
102102

103-
;; CHECK: (func $simple-reaching-trap (type $1)
103+
;; CHECK: (func $simple-reaching-trap (type $3)
104104
;; CHECK-NEXT: (local $x (ref null $A))
105105
;; CHECK-NEXT: (block
106106
;; CHECK-NEXT: (drop
@@ -169,7 +169,7 @@
169169
)
170170
)
171171

172-
;; CHECK: (func $simple-fallthrough (type $3) (param $x (ref $A))
172+
;; CHECK: (func $simple-fallthrough (type $2) (param $x (ref $A))
173173
;; CHECK-NEXT: (block
174174
;; CHECK-NEXT: (drop
175175
;; CHECK-NEXT: (block (result (ref $A))
@@ -210,7 +210,7 @@
210210
(unreachable)
211211
)
212212

213-
;; CHECK: (func $ref-changes (type $3) (param $x (ref $A))
213+
;; CHECK: (func $ref-changes (type $2) (param $x (ref $A))
214214
;; CHECK-NEXT: (struct.set $A 0
215215
;; CHECK-NEXT: (local.get $x)
216216
;; CHECK-NEXT: (i32.const 10)
@@ -276,7 +276,7 @@
276276
)
277277
)
278278

279-
;; CHECK: (func $simple-use (type $3) (param $x (ref $A))
279+
;; CHECK: (func $simple-use (type $2) (param $x (ref $A))
280280
;; CHECK-NEXT: (block
281281
;; CHECK-NEXT: (drop
282282
;; CHECK-NEXT: (local.get $x)
@@ -566,11 +566,11 @@
566566
)
567567
)
568568

569-
;; CHECK: (func $foo (type $1)
569+
;; CHECK: (func $foo (type $3)
570570
;; CHECK-NEXT: )
571571
(func $foo)
572572

573-
;; CHECK: (func $call (type $3) (param $x (ref $A))
573+
;; CHECK: (func $call (type $2) (param $x (ref $A))
574574
;; CHECK-NEXT: (struct.set $A 0
575575
;; CHECK-NEXT: (local.get $x)
576576
;; CHECK-NEXT: (i32.const 10)
@@ -594,7 +594,7 @@
594594
)
595595
)
596596

597-
;; CHECK: (func $through-branches (type $3) (param $x (ref $A))
597+
;; CHECK: (func $through-branches (type $2) (param $x (ref $A))
598598
;; CHECK-NEXT: (block
599599
;; CHECK-NEXT: (drop
600600
;; CHECK-NEXT: (local.get $x)
@@ -638,7 +638,7 @@
638638
)
639639
)
640640

641-
;; CHECK: (func $just-one-branch-trample (type $3) (param $x (ref $A))
641+
;; CHECK: (func $just-one-branch-trample (type $2) (param $x (ref $A))
642642
;; CHECK-NEXT: (struct.set $A 0
643643
;; CHECK-NEXT: (local.get $x)
644644
;; CHECK-NEXT: (i32.const 10)
@@ -675,7 +675,7 @@
675675
)
676676
)
677677

678-
;; CHECK: (func $two-branch-trample (type $3) (param $x (ref $A))
678+
;; CHECK: (func $two-branch-trample (type $2) (param $x (ref $A))
679679
;; CHECK-NEXT: (block
680680
;; CHECK-NEXT: (drop
681681
;; CHECK-NEXT: (local.get $x)
@@ -722,7 +722,7 @@
722722
)
723723
)
724724

725-
;; CHECK: (func $just-one-branch-bad (type $3) (param $x (ref $A))
725+
;; CHECK: (func $just-one-branch-bad (type $2) (param $x (ref $A))
726726
;; CHECK-NEXT: (struct.set $A 0
727727
;; CHECK-NEXT: (local.get $x)
728728
;; CHECK-NEXT: (i32.const 10)
@@ -761,7 +761,7 @@
761761
)
762762
)
763763

764-
;; CHECK: (func $simple-in-branches (type $3) (param $x (ref $A))
764+
;; CHECK: (func $simple-in-branches (type $2) (param $x (ref $A))
765765
;; CHECK-NEXT: (if
766766
;; CHECK-NEXT: (i32.const 1)
767767
;; CHECK-NEXT: (then
@@ -970,15 +970,15 @@
970970
)
971971
)
972972

973-
;; CHECK: (func $no-basic-blocks (type $1)
973+
;; CHECK: (func $no-basic-blocks (type $3)
974974
;; CHECK-NEXT: (unreachable)
975975
;; CHECK-NEXT: )
976976
(func $no-basic-blocks
977977
;; Check we don't crash on a function with no basic blocks at all.
978978
(unreachable)
979979
)
980980

981-
;; CHECK: (func $global (type $1)
981+
;; CHECK: (func $global (type $3)
982982
;; CHECK-NEXT: (drop
983983
;; CHECK-NEXT: (i32.const 10)
984984
;; CHECK-NEXT: )
@@ -1004,7 +1004,7 @@
10041004
)
10051005
)
10061006

1007-
;; CHECK: (func $global-trap (type $1)
1007+
;; CHECK: (func $global-trap (type $3)
10081008
;; CHECK-NEXT: (global.set $global$0
10091009
;; CHECK-NEXT: (i32.const 10)
10101010
;; CHECK-NEXT: )
@@ -1035,7 +1035,7 @@
10351035
)
10361036
)
10371037

1038-
;; CHECK: (func $gc-unreachable (type $3) (param $x (ref $A))
1038+
;; CHECK: (func $gc-unreachable (type $2) (param $x (ref $A))
10391039
;; CHECK-NEXT: (struct.set $A 0
10401040
;; CHECK-NEXT: (local.get $x)
10411041
;; CHECK-NEXT: (loop $loop

0 commit comments

Comments
 (0)