Skip to content

Commit 01198f8

Browse files
Finish?
1 parent 7d1b989 commit 01198f8

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/passes/GlobalEffects.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
// Function::effects; see more details there.
2020
//
2121

22+
#include "ir/table-utils.h"
2223
#include "ir/subtypes.h"
2324
#include "ir/effects.h"
2425
#include "ir/module-utils.h"
2526
#include "pass.h"
27+
#include "ir/element-utils.h"
2628
#include "support/unique_deferring_queue.h"
2729
#include "wasm.h"
2830

@@ -194,6 +196,20 @@ struct GenerateGlobalEffects : public Pass {
194196
std::unordered_map<CallGraphNode, std::unordered_set<CallGraphNode>> callers;
195197

196198
std::unordered_set<HeapType> allIndirectCalledTypes;
199+
200+
std::unordered_set<Name> funcsWithAddress;
201+
202+
auto refFuncs = TableUtils::getFunctionsNeedingElemDeclare(*module);
203+
funcsWithAddress.insert(refFuncs.begin(), refFuncs.end());
204+
ElementUtils::iterAllElementFunctionNames(module, [&funcsWithAddress](Name name) { funcsWithAddress.insert(name); });
205+
for (const auto& export_ : module->exports) {
206+
if (export_->kind == ExternalKind::Function) {
207+
// This exported function might flow back to us even in a closed world,
208+
// so it's essentially addressed.
209+
funcsWithAddress.insert(export_->name);
210+
}
211+
}
212+
197213
for (const auto& [func, info] : funcInfos) {
198214
// Name -> Name for direct calls
199215
for (const auto& callee : info.calledFunctions) {
@@ -206,7 +222,9 @@ struct GenerateGlobalEffects : public Pass {
206222
}
207223

208224
// Name -> HeapType for function types
209-
callers[func->name].insert(func->type.getHeapType());
225+
if (funcsWithAddress.contains(func->name)) {
226+
callers[func->name].insert(func->type.getHeapType());
227+
}
210228

211229
allIndirectCalledTypes.insert(func->type.getHeapType());
212230
}
@@ -218,6 +236,7 @@ struct GenerateGlobalEffects : public Pass {
218236
// A subtype is a 'callee' of its supertype. Supertypes need to inherit effects from their subtypes
219237
// See the example in (TODO)
220238
callers[sub].insert(type);
239+
// callers[type].insert(sub);
221240
return true;
222241
});
223242
}

test/lit/passes/global-effects-closed-world.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
;; CHECK: (func $A (type $ttt) (param $0 i64)
207207
;; CHECK-NEXT: (call $B)
208208
;; CHECK-NEXT: )
209-
(func $A (param i64)
209+
(func $A (export "A") (param i64)
210210
(call $B)
211211
;; (call_ref $ttt (ref.func $u))
212212
)
@@ -224,7 +224,7 @@
224224
)
225225

226226
;; CHECK: (func $foo (type $6)
227-
;; CHECK-NEXT: (nop)
227+
;; CHECK-NEXT: (call $C)
228228
;; CHECK-NEXT: )
229229
(func $foo
230230
(call $C)

0 commit comments

Comments
 (0)