Skip to content

Commit 36f9b09

Browse files
PR updates
1 parent 5efb807 commit 36f9b09

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

src/passes/GlobalEffects.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,30 @@ struct FuncInfo {
4848
std::unordered_set<HeapType> indirectCalledTypes;
4949
};
5050

51+
/*
52+
Only funcs that are 'addressed' may be the target of an indirect call. A
53+
function is addressed if:
54+
- It appears in a ref.func expression
55+
- It appears in an `elem declare` statement (note that we already ignore `elem`
56+
statements in our IR, but we check separately for funcs that appear in
57+
`ref.func`).
58+
- It's exported, because it may flow back to us as a reference.
59+
- It's imported, which implies it is `elem declare`d.
60+
61+
If a function doesn't meet any of these criteria, it can't be the target of
62+
an indirect call and we don't need to include its effects in indirect calls.
63+
*/
5164
std::unordered_set<Function*> getAddressedFuncs(Module& module) {
52-
struct AddressedFuncsWalker
53-
: PostWalker<AddressedFuncsWalker,
54-
UnifiedExpressionVisitor<AddressedFuncsWalker>> {
65+
struct AddressedFuncsWalker : PostWalker<AddressedFuncsWalker> {
5566
const Module& module;
5667
std::unordered_set<Function*>& addressedFuncs;
5768

5869
AddressedFuncsWalker(const Module& module,
5970
std::unordered_set<Function*>& addressedFuncs)
6071
: module(module), addressedFuncs(addressedFuncs) {}
6172

62-
void visitExpression(Expression* curr) {
63-
if (auto* refFunc = curr->dynCast<RefFunc>()) {
64-
addressedFuncs.insert(module.getFunction(refFunc->func));
65-
}
73+
void visitRefFunc(RefFunc* refFunc) {
74+
addressedFuncs.insert(module.getFunction(refFunc->func));
6675
}
6776
};
6877

@@ -80,9 +89,6 @@ std::unordered_set<Function*> getAddressedFuncs(Module& module) {
8089
continue;
8190
}
8291

83-
// TODO: internal or external? I think internal
84-
// This might be why we failed to lookup the function earlier
85-
// Maybe we can use Function* after all
8692
addressedFuncs.insert(module.getFunction(*export_->getInternalName()));
8793
}
8894

@@ -199,7 +205,7 @@ using CallGraph =
199205

200206
CallGraph buildCallGraph(const Module& module,
201207
const std::map<Function*, FuncInfo>& funcInfos,
202-
const std::unordered_set<Function*> addressedFuncs,
208+
const std::unordered_set<Function*>& addressedFuncs,
203209
bool closedWorld) {
204210
CallGraph callGraph;
205211
if (!closedWorld) {

0 commit comments

Comments
 (0)