Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,28 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
currContinuation->resumeInfo.push_back(entry);
}

// Rvalue reference overload to avoid unnecessary copies when the entry
// is about to be destroyed.
void pushResumeEntry(Literals&& entry, const char* what) {
auto currContinuation = getCurrContinuationOrNull();
if (!currContinuation) {
return;
}
#if WASM_INTERPRETER_DEBUG
std::cout << indent() << "push resume entry [" << what << "]: " << entry
<< "\n";
#endif
currContinuation->resumeInfo.push_back(std::move(entry));
}

// Fetch an entry as we resume. Instructions call this as we rewind.
Literals popResumeEntry(const char* what) {
#if WASM_INTERPRETER_DEBUG
std::cout << indent() << "pop resume entry [" << what << "]:\n";
#endif
auto currContinuation = getCurrContinuation();
assert(!currContinuation->resumeInfo.empty());
auto entry = currContinuation->resumeInfo.back();
auto entry = std::move(currContinuation->resumeInfo.back());
currContinuation->resumeInfo.pop_back();
#if WASM_INTERPRETER_DEBUG
std::cout << indent() << " => " << entry << "\n";
Expand Down Expand Up @@ -618,8 +632,7 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
auto& values = valueStack.back();
auto num = values.size();
while (!values.empty()) {
// TODO: std::move, &elsewhere?
pushResumeEntry(values.back(), "child value");
pushResumeEntry(std::move(values.back()), "child value");
values.pop_back();
}
pushResumeEntry({Literal(int32_t(num))}, "num executed children");
Expand Down Expand Up @@ -687,7 +700,7 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
// in the block.
entry.push_back(Literal(uint32_t(stack.size())));
entry.push_back(Literal(uint32_t(blockIndex)));
pushResumeEntry(entry, "block");
pushResumeEntry(std::move(entry), "block");
};
Index blockIndex = 0;
if (isResuming()) {
Expand Down Expand Up @@ -4779,7 +4792,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
// callFunction() will read it. Then call into the other module. This
// sets this up as if we called into the proper module in the first
// place.
self()->pushResumeEntry(entry, "function-target");
self()->pushResumeEntry(std::move(entry), "function-target");
return data->doCall(arguments);
}

Expand Down Expand Up @@ -4843,7 +4856,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
if (flow.suspendTag) {
// Save the local state.
for (auto& local : scope.locals) {
self()->pushResumeEntry(local, "function-local");
self()->pushResumeEntry(std::move(local), "function-local");
}

// Save the function we called (in the case of a return call, this is
Expand Down