Skip to content

Commit 3e5a10a

Browse files
Gemini WIP
1 parent 36ee3a5 commit 3e5a10a

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/ir/effects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ class EffectAnalyzer {
757757
}
758758
}
759759
void visitCallIndirect(CallIndirect* curr) {
760-
auto* table = getModule()->getTable(curr->table);
760+
auto* table = parent.module.getTable(curr->table);
761761
if (!Type::isSubType(Type(curr->heapType, Nullability::Nullable), table->type)) {
762762
parent.trap = true;
763763
return;

src/ir/type-updating.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,25 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) {
324324
for (auto& tag : wasm.tags) {
325325
tag->type = updater.getNew(tag->type);
326326
}
327+
328+
// Update type effects.
329+
std::unordered_map<HeapType, std::shared_ptr<const EffectAnalyzer>>
330+
newTypeEffects;
331+
for (auto& [oldType, effects] : wasm.typeEffects) {
332+
if (!effects) {
333+
continue;
334+
}
335+
auto newType = updater.getNew(oldType);
336+
auto& targetEffects = newTypeEffects[newType];
337+
if (!targetEffects) {
338+
targetEffects = effects;
339+
} else {
340+
auto merged = std::make_shared<EffectAnalyzer>(*targetEffects);
341+
merged->mergeIn(*effects);
342+
targetEffects = merged;
343+
}
344+
}
345+
wasm.typeEffects = std::move(newTypeEffects);
327346
}
328347

329348
void GlobalTypeRewriter::mapTypeNamesAndIndices(const TypeMap& oldToNewTypes) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
;; RUN: foreach %s %t wasm-opt --all-features --closed-world --generate-global-effects --minimize-rec-groups --vacuum --ignore-implicit-traps -S -o - | filecheck %s
3+
4+
(module
5+
(rec (type $A (func (result i32))))
6+
(rec (type $B (func (result i32))))
7+
(table 2 2 funcref)
8+
(elem (i32.const 0) $pure_A)
9+
(elem (i32.const 1) $pure_B)
10+
11+
;; CHECK: (func $pure_A (type $A) (result i32)
12+
;; CHECK-NEXT: (unreachable)
13+
;; CHECK-NEXT: )
14+
(func $pure_A (type $A)
15+
(unreachable)
16+
)
17+
;; CHECK: (func $pure_B (type $A) (result i32)
18+
;; CHECK-NEXT: (i32.const 0)
19+
;; CHECK-NEXT: )
20+
(func $pure_B (type $B)
21+
(i32.const 0)
22+
)
23+
24+
;; CHECK: (func $test (type $1) (param $idx i32)
25+
;; CHECK-NEXT: (drop
26+
;; CHECK-NEXT: (call_indirect $0 (type $A)
27+
;; CHECK-NEXT: (local.get $idx)
28+
;; CHECK-NEXT: )
29+
;; CHECK-NEXT: )
30+
;; CHECK-NEXT: (drop
31+
;; CHECK-NEXT: (call_indirect $0 (type $A)
32+
;; CHECK-NEXT: (local.get $idx)
33+
;; CHECK-NEXT: )
34+
;; CHECK-NEXT: )
35+
;; CHECK-NEXT: )
36+
(func $test (export "test") (param $idx i32)
37+
(drop
38+
(call_indirect (type $B) (local.get $idx))
39+
)
40+
(drop
41+
(call_indirect (type $A) (local.get $idx))
42+
)
43+
)
44+
)

0 commit comments

Comments
 (0)