Skip to content

Consistent detection of invoke_ functions in PostEmscripten.cpp #2619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/passes/PostEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ namespace wasm {

namespace {

static bool isInvoke(Name name) { return name.startsWith("invoke_"); }
static bool isInvoke(Function* F) {
return F->imported() && F->module == ENV && F->base.startsWith("invoke_");
}

struct OptimizeCalls : public WalkerPass<PostWalker<OptimizeCalls>> {
bool isFunctionParallel() override { return true; }
Expand Down Expand Up @@ -123,7 +125,7 @@ struct PostEmscripten : public Pass {
// First, check if this code even uses invokes.
bool hasInvokes = false;
for (auto& imp : module->functions) {
if (imp->imported() && imp->module == ENV && isInvoke(imp->base)) {
if (isInvoke(imp.get())) {
hasInvokes = true;
}
}
Expand Down Expand Up @@ -169,7 +171,8 @@ struct PostEmscripten : public Pass {
: map(map), flatTable(flatTable) {}

void visitCall(Call* curr) {
if (isInvoke(curr->target)) {
auto* target = getModule()->getFunction(curr->target);
if (isInvoke(target)) {
// The first operand is the function pointer index, which must be
// constant if we are to optimize it statically.
if (auto* index = curr->operands[0]->dynCast<Const>()) {
Expand Down