Commit 3864b09a authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Cleanup function import signature caching.

This simplifies the double-indirection used for the signature cache in
function imports and also reduces the memory its memory footprint. Also
switch to use the local zone as an underlying storage.

R=rossberg@chromium.org
BUG=v8:6127

Change-Id: I8bc6cf13f2ce9ffa02485e76b7e36f389c9e02e5
Reviewed-on: https://chromium-review.googlesource.com/483443Reviewed-by: 's avatarAndreas Rossberg <rossberg@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44768}
parent e863286b
......@@ -550,8 +550,9 @@ bool AsmJsParser::ValidateModuleVarImport(VarInfo* info,
return true;
}
info->kind = VarKind::kImportedFunction;
function_import_info_.resize(function_import_info_.size() + 1);
info->import = &function_import_info_.back();
info->import =
new (zone()->New(sizeof(FunctionImportInfo))) FunctionImportInfo(
{nullptr, 0, WasmModuleBuilder::SignatureMap(zone())});
// TODO(bradnelson): Refactor memory management here.
// AsmModuleBuilder should really own import names.
info->import->function_name = zone()->NewArray<char>(import_name.size());
......@@ -2162,16 +2163,16 @@ AsmType* AsmJsParser::ValidateCall() {
}
DCHECK(function_info->import != nullptr);
// TODO(bradnelson): Factor out.
uint32_t cache_index = function_info->import->cache.FindOrInsert(sig);
uint32_t index;
if (cache_index >= function_info->import->cache_index.size()) {
auto it = function_info->import->cache.find(sig);
if (it != function_info->import->cache.end()) {
index = it->second;
} else {
index = module_builder_->AddImport(
function_info->import->function_name,
static_cast<uint32_t>(function_info->import->function_name_size),
sig);
function_info->import->cache_index.push_back(index);
} else {
index = function_info->import->cache_index[cache_index];
function_info->import->cache[sig] = index;
}
current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos);
current_function_builder_->Emit(kExprCallFunction);
......
......@@ -5,14 +5,12 @@
#ifndef V8_ASMJS_ASM_PARSER_H_
#define V8_ASMJS_ASM_PARSER_H_
#include <list>
#include <string>
#include <vector>
#include "src/asmjs/asm-scanner.h"
#include "src/asmjs/asm-typer.h"
#include "src/asmjs/asm-types.h"
#include "src/wasm/signature-map.h"
#include "src/wasm/wasm-module-builder.h"
#include "src/zone/zone-containers.h"
......@@ -61,8 +59,7 @@ class AsmJsParser {
struct FunctionImportInfo {
char* function_name;
size_t function_name_size;
SignatureMap cache;
std::vector<uint32_t> cache_index;
WasmModuleBuilder::SignatureMap cache;
};
struct VarInfo {
......@@ -100,9 +97,8 @@ class AsmJsParser {
WasmModuleBuilder* module_builder_;
WasmFunctionBuilder* current_function_builder_;
AsmType* return_type_;
std::uintptr_t stack_limit_;
uintptr_t stack_limit_;
AsmTyper::StdlibSet stdlib_uses_;
std::list<FunctionImportInfo> function_import_info_;
ZoneVector<VarInfo> global_var_info_;
ZoneVector<VarInfo> local_var_info_;
......
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