Commit 36ae442e authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Correctly increment the func_index for streaming compilation

The `num_functions_` counter got incremented at the exit of
`ProcessFunctionBody`, and for some exits it did not get incremented
at all. This was incorrect, it has to get incremented for each call to
`ProcessFunctionBody`. With this CL, `num_functions_` gets called at
the beginning of the function.

R=clemensb@chromium.org

Bug: v8:12852
Change-Id: I554916a7217533234a82ba397c301b926ce86b99
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3811587
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82259}
parent 30f0847c
......@@ -2898,14 +2898,16 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
void AsyncStreamingProcessor::ProcessFunctionBody(
base::Vector<const uint8_t> bytes, uint32_t offset) {
TRACE_STREAMING("Process function body %d ...\n", num_functions_);
uint32_t func_index =
decoder_.module()->num_imported_functions + num_functions_;
++num_functions_;
// In case of {prefix_cache_hit} we still need the function body to be
// decoded. Otherwise a later cache miss cannot be handled.
decoder_.DecodeFunctionBody(
num_functions_, static_cast<uint32_t>(bytes.length()), offset, false);
decoder_.DecodeFunctionBody(func_index, static_cast<uint32_t>(bytes.length()),
offset, false);
if (prefix_cache_hit_) {
// Don't compile yet if we might have a cache hit.
++num_functions_;
return;
}
......@@ -2919,8 +2921,6 @@ void AsyncStreamingProcessor::ProcessFunctionBody(
const WasmModule* module = decoder_.module();
auto enabled_features = job_->enabled_features_;
uint32_t func_index =
num_functions_ + decoder_.module()->num_imported_functions;
DCHECK_EQ(module->origin, kWasmOrigin);
const bool lazy_module = job_->wasm_lazy_compilation_;
CompileStrategy strategy =
......@@ -2944,7 +2944,6 @@ void AsyncStreamingProcessor::ProcessFunctionBody(
auto* compilation_state = Impl(job_->native_module_->compilation_state());
compilation_state->AddCompilationUnit(compilation_unit_builder_.get(),
func_index);
++num_functions_;
}
void AsyncStreamingProcessor::CommitCompilationUnits() {
......
......@@ -1139,8 +1139,9 @@ class ModuleDecoderTemplate : public Decoder {
std::vector<std::pair<uint32_t, uint32_t>> inst_traces;
for (uint32_t i = 0; ok() && i < functions_count; ++i) {
int function_index = module_->num_imported_functions + i;
tracer_.Description("function #");
tracer_.FunctionName(module_->num_imported_functions + i);
tracer_.FunctionName(function_index);
tracer_.NextLine();
const byte* pos = pc();
uint32_t size = consume_u32v("body size", tracer_);
......@@ -1154,7 +1155,7 @@ class ModuleDecoderTemplate : public Decoder {
uint32_t offset = pc_offset();
consume_bytes(size, "function body");
if (failed()) break;
DecodeFunctionBody(i, size, offset, verify_functions);
DecodeFunctionBody(function_index, size, offset, verify_functions);
// Now that the function has been decoded, we can compute module offsets.
for (; inst_traces_it != this->inst_traces_.end() &&
......@@ -1199,8 +1200,7 @@ class ModuleDecoderTemplate : public Decoder {
void DecodeFunctionBody(uint32_t index, uint32_t length, uint32_t offset,
bool verify_functions) {
WasmFunction* function =
&module_->functions[index + module_->num_imported_functions];
WasmFunction* function = &module_->functions[index];
function->code = {offset, length};
tracer_.FunctionBody(function, pc_ - (pc_offset() - offset));
if (verify_functions) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment