Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: src/compiler/wasm-compiler.cc

Issue 2731523005: [wasm] Lazy compilation for asm.js (Closed)
Patch Set: [wasm] Lazy compilation for asm.js Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/x64/builtins-x64.cc ('k') | src/counters.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index b14e0844fc413a402e43e19f7ffb894e8dcc7469..b276bb40bc64591d964a9fd26782bbb841e3252b 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -180,7 +180,8 @@ class WasmTrapHelper : public ZoneObject {
Builtins::Name GetBuiltinIdForTrap(wasm::TrapReason reason) {
bool in_cctest =
- !builder_->module_ || builder_->module_->instance->context.is_null();
+ !builder_->module_ || (builder_->module_->instance &&
+ builder_->module_->instance->context.is_null());
if (in_cctest) {
// We use Builtins::builtin_count as a marker to tell the code generator
// to generate a call to a testing c-function instead of a runtime
@@ -487,7 +488,8 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position,
Node** effect, Node** control) {
if (FLAG_wasm_no_stack_checks) return;
// We do not generate stack checks for cctests.
- if (!module_ || module_->instance->context.is_null()) return;
+ if (!module_ || (module_->instance && module_->instance->context.is_null()))
+ return;
if (effect == nullptr) effect = effect_;
if (control == nullptr) control = control_;
@@ -1796,6 +1798,11 @@ Node* WasmGraphBuilder::BuildFloatToIntConversionInstruction(
}
Node* WasmGraphBuilder::GrowMemory(Node* input) {
+ // GrowMemory will not be called from asm.js, hence we cannot be in
+ // lazy-compilation mode, hence the instance will be set.
+ DCHECK_NOT_NULL(module_);
+ DCHECK_NOT_NULL(module_->instance);
+
Diamond check_input_range(
graph(), jsgraph()->common(),
graph()->NewNode(jsgraph()->machine()->Uint32LessThanOrEqual(), input,
@@ -2286,7 +2293,9 @@ Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args, Node*** rets,
DCHECK_NULL(args[0]);
// Add code object as constant.
- Handle<Code> code = module_->GetFunctionCode(index);
+ Handle<Code> code = module_->instance
+ ? module_->GetFunctionCode(index)
+ : jsgraph()->isolate()->builtins()->Illegal();
DCHECK(!code.is_null());
args[0] = HeapConstant(code);
wasm::FunctionSig* sig = module_->GetFunctionSignature(index);
@@ -2298,7 +2307,7 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args,
Node*** rets,
wasm::WasmCodePosition position) {
DCHECK_NOT_NULL(args[0]);
- DCHECK(module_ && module_->instance);
+ DCHECK_NOT_NULL(module_);
// Assume only one table for now.
uint32_t table_index = 0;
@@ -3043,22 +3052,28 @@ void WasmGraphBuilder::BuildWasmInterpreterEntry(
}
Node* WasmGraphBuilder::MemBuffer(uint32_t offset) {
- DCHECK(module_ && module_->instance);
+ DCHECK_NOT_NULL(module_);
+ uintptr_t mem_start = reinterpret_cast<uintptr_t>(
+ module_->instance ? module_->instance->mem_start : nullptr);
if (offset == 0) {
if (!mem_buffer_) {
mem_buffer_ = jsgraph()->RelocatableIntPtrConstant(
- reinterpret_cast<uintptr_t>(module_->instance->mem_start),
- RelocInfo::WASM_MEMORY_REFERENCE);
+ mem_start, RelocInfo::WASM_MEMORY_REFERENCE);
}
return mem_buffer_;
} else {
return jsgraph()->RelocatableIntPtrConstant(
- reinterpret_cast<uintptr_t>(module_->instance->mem_start + offset),
- RelocInfo::WASM_MEMORY_REFERENCE);
+ mem_start + offset, RelocInfo::WASM_MEMORY_REFERENCE);
}
}
Node* WasmGraphBuilder::CurrentMemoryPages() {
+ // CurrentMemoryPages will not be called from asm.js, hence we cannot be in
+ // lazy-compilation mode, hence the instance will be set.
+ DCHECK_EQ(wasm::kWasmOrigin, module_->module->origin);
+ DCHECK_NOT_NULL(module_);
+ DCHECK_NOT_NULL(module_->instance);
+
Runtime::FunctionId function_id = Runtime::kWasmMemorySize;
const Runtime::Function* function = Runtime::FunctionForId(function_id);
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
@@ -3092,11 +3107,14 @@ Node* WasmGraphBuilder::MemSize() {
void WasmGraphBuilder::EnsureFunctionTableNodes() {
if (function_tables_.size() > 0) return;
- size_t tables_size = module_->instance->function_tables.size();
- DCHECK(tables_size == module_->instance->signature_tables.size());
+ size_t tables_size = module_->module->function_tables.size();
+ if (module_->instance) {
+ DCHECK_EQ(tables_size, module_->instance->function_tables.size());
+ DCHECK_EQ(tables_size, module_->instance->signature_tables.size());
+ }
for (size_t i = 0; i < tables_size; ++i) {
- auto function_handle = module_->instance->function_tables[i];
- auto signature_handle = module_->instance->signature_tables[i];
+ auto function_handle = module_->GetFunctionTableObj(i);
+ auto signature_handle = module_->GetSignatureTableObj(i);
DCHECK(!function_handle.is_null() && !signature_handle.is_null());
function_tables_.push_back(HeapConstant(function_handle));
signature_tables_.push_back(HeapConstant(signature_handle));
@@ -3110,10 +3128,12 @@ void WasmGraphBuilder::EnsureFunctionTableNodes() {
Node* WasmGraphBuilder::GetGlobal(uint32_t index) {
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index));
+ byte* globals_start =
+ module_->instance ? module_->instance->globals_start : nullptr;
+ uintptr_t global_addr = reinterpret_cast<uintptr_t>(
+ globals_start + module_->module->globals[index].offset);
Node* addr = jsgraph()->RelocatableIntPtrConstant(
- reinterpret_cast<uintptr_t>(module_->instance->globals_start +
- module_->module->globals[index].offset),
- RelocInfo::WASM_GLOBAL_REFERENCE);
+ global_addr, RelocInfo::WASM_GLOBAL_REFERENCE);
const Operator* op = jsgraph()->machine()->Load(mem_type);
Node* node = graph()->NewNode(op, addr, jsgraph()->Int32Constant(0), *effect_,
*control_);
@@ -3124,8 +3144,10 @@ Node* WasmGraphBuilder::GetGlobal(uint32_t index) {
Node* WasmGraphBuilder::SetGlobal(uint32_t index, Node* val) {
MachineType mem_type =
wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index));
+ byte* globals_start =
+ module_->instance ? module_->instance->globals_start : 0;
Node* addr = jsgraph()->RelocatableIntPtrConstant(
- reinterpret_cast<uintptr_t>(module_->instance->globals_start +
+ reinterpret_cast<uintptr_t>(globals_start +
module_->module->globals[index].offset),
RelocInfo::WASM_GLOBAL_REFERENCE);
const Operator* op = jsgraph()->machine()->Store(
« no previous file with comments | « src/builtins/x64/builtins-x64.cc ('k') | src/counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698