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

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2627543003: [wasm] Prerequisites for WebAssembly Table.Grow (Closed)
Patch Set: Rename update function Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 }; 341 };
342 342
343 WasmGraphBuilder::WasmGraphBuilder( 343 WasmGraphBuilder::WasmGraphBuilder(
344 wasm::ModuleEnv* module_env, Zone* zone, JSGraph* jsgraph, 344 wasm::ModuleEnv* module_env, Zone* zone, JSGraph* jsgraph,
345 wasm::FunctionSig* sig, 345 wasm::FunctionSig* sig,
346 compiler::SourcePositionTable* source_position_table) 346 compiler::SourcePositionTable* source_position_table)
347 : zone_(zone), 347 : zone_(zone),
348 jsgraph_(jsgraph), 348 jsgraph_(jsgraph),
349 module_(module_env), 349 module_(module_env),
350 signature_tables_(zone),
350 function_tables_(zone), 351 function_tables_(zone),
351 function_table_sizes_(zone), 352 function_table_sizes_(zone),
352 cur_buffer_(def_buffer_), 353 cur_buffer_(def_buffer_),
353 cur_bufsize_(kDefaultBufferSize), 354 cur_bufsize_(kDefaultBufferSize),
354 trap_(new (zone) WasmTrapHelper(this)), 355 trap_(new (zone) WasmTrapHelper(this)),
355 sig_(sig), 356 sig_(sig),
356 source_position_table_(source_position_table) { 357 source_position_table_(source_position_table) {
357 for (size_t i = 0; i < sig->parameter_count(); i++) { 358 for (size_t i = 0; i < sig->parameter_count(); i++) {
358 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; 359 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true;
359 } 360 }
(...skipping 1938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2298 2299
2299 EnsureFunctionTableNodes(); 2300 EnsureFunctionTableNodes();
2300 MachineOperatorBuilder* machine = jsgraph()->machine(); 2301 MachineOperatorBuilder* machine = jsgraph()->machine();
2301 Node* key = args[0]; 2302 Node* key = args[0];
2302 2303
2303 // Bounds check against the table size. 2304 // Bounds check against the table size.
2304 Node* size = function_table_sizes_[table_index]; 2305 Node* size = function_table_sizes_[table_index];
2305 Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); 2306 Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size);
2306 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); 2307 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position);
2307 Node* table = function_tables_[table_index]; 2308 Node* table = function_tables_[table_index];
2309 Node* signatures = signature_tables_[table_index];
2308 2310
2309 // Load signature from the table and check. 2311 // Load signature from the table and check.
2310 // The table is a FixedArray; signatures are encoded as SMIs. 2312 // The table is a FixedArray; signatures are encoded as SMIs.
2311 // [sig1, sig2, sig3, ...., code1, code2, code3 ...] 2313 // [sig1, sig2, sig3, ...., code1, code2, code3 ...]
2312 ElementAccess access = AccessBuilder::ForFixedArrayElement(); 2314 ElementAccess access = AccessBuilder::ForFixedArrayElement();
2313 const int fixed_offset = access.header_size - access.tag(); 2315 const int fixed_offset = access.header_size - access.tag();
2314 { 2316 {
2315 Node* load_sig = graph()->NewNode( 2317 Node* load_sig = graph()->NewNode(
2316 machine->Load(MachineType::AnyTagged()), table, 2318 machine->Load(MachineType::AnyTagged()), signatures,
2317 graph()->NewNode(machine->Int32Add(), 2319 graph()->NewNode(machine->Int32Add(),
2318 graph()->NewNode(machine->Word32Shl(), key, 2320 graph()->NewNode(machine->Word32Shl(), key,
2319 Int32Constant(kPointerSizeLog2)), 2321 Int32Constant(kPointerSizeLog2)),
2320 Int32Constant(fixed_offset)), 2322 Int32Constant(fixed_offset)),
2321 *effect_, *control_); 2323 *effect_, *control_);
2322 auto map = const_cast<wasm::SignatureMap&>( 2324 auto map = const_cast<wasm::SignatureMap&>(
2323 module_->module->function_tables[0].map); 2325 module_->module->function_tables[0].map);
2324 Node* sig_match = graph()->NewNode( 2326 Node* sig_match = graph()->NewNode(
2325 machine->WordEqual(), load_sig, 2327 machine->WordEqual(), load_sig,
2326 jsgraph()->SmiConstant(static_cast<int>(map.FindOrInsert(sig)))); 2328 jsgraph()->SmiConstant(static_cast<int>(map.FindOrInsert(sig))));
2327 trap_->AddTrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position); 2329 trap_->AddTrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
2328 } 2330 }
2329 2331
2330 // Load code object from the table. 2332 // Load code object from the table.
2331 uint32_t table_size = module_->module->function_tables[table_index].min_size;
2332 uint32_t offset = fixed_offset + kPointerSize * table_size;
2333 Node* load_code = graph()->NewNode( 2333 Node* load_code = graph()->NewNode(
2334 machine->Load(MachineType::AnyTagged()), table, 2334 machine->Load(MachineType::AnyTagged()), table,
2335 graph()->NewNode(machine->Int32Add(), 2335 graph()->NewNode(machine->Int32Add(),
2336 graph()->NewNode(machine->Word32Shl(), key, 2336 graph()->NewNode(machine->Word32Shl(), key,
2337 Int32Constant(kPointerSizeLog2)), 2337 Int32Constant(kPointerSizeLog2)),
2338 Uint32Constant(offset)), 2338 Uint32Constant(fixed_offset)),
2339 *effect_, *control_); 2339 *effect_, *control_);
2340 2340
2341 args[0] = load_code; 2341 args[0] = load_code;
2342 return BuildWasmCall(sig, args, rets, position); 2342 return BuildWasmCall(sig, args, rets, position);
2343 } 2343 }
2344 2344
2345 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { 2345 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) {
2346 // Implement Rol by Ror since TurboFan does not have Rol opcode. 2346 // Implement Rol by Ror since TurboFan does not have Rol opcode.
2347 // TODO(weiliang): support Word32Rol opcode in TurboFan. 2347 // TODO(weiliang): support Word32Rol opcode in TurboFan.
2348 Int32Matcher m(right); 2348 Int32Matcher m(right);
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2960 size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2961 return mem_size_; 2961 return mem_size_;
2962 } else { 2962 } else {
2963 return jsgraph()->RelocatableInt32Constant( 2963 return jsgraph()->RelocatableInt32Constant(
2964 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 2964 size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
2965 } 2965 }
2966 } 2966 }
2967 2967
2968 void WasmGraphBuilder::EnsureFunctionTableNodes() { 2968 void WasmGraphBuilder::EnsureFunctionTableNodes() {
2969 if (function_tables_.size() > 0) return; 2969 if (function_tables_.size() > 0) return;
2970 for (size_t i = 0; i < module_->instance->function_tables.size(); ++i) { 2970 size_t tables_size = module_->instance->function_tables.size();
2971 auto handle = module_->instance->function_tables[i]; 2971 DCHECK(tables_size == module_->instance->signature_tables.size());
2972 DCHECK(!handle.is_null()); 2972 for (size_t i = 0; i < tables_size; ++i) {
2973 function_tables_.push_back(HeapConstant(handle)); 2973 auto function_handle = module_->instance->function_tables[i];
2974 auto signature_handle = module_->instance->signature_tables[i];
2975 DCHECK(!function_handle.is_null() && !signature_handle.is_null());
2976 function_tables_.push_back(HeapConstant(function_handle));
2977 signature_tables_.push_back(HeapConstant(signature_handle));
2974 uint32_t table_size = module_->module->function_tables[i].min_size; 2978 uint32_t table_size = module_->module->function_tables[i].min_size;
2975 function_table_sizes_.push_back(Uint32Constant(table_size)); 2979 function_table_sizes_.push_back(jsgraph()->RelocatableInt32Constant(
2980 static_cast<uint32_t>(table_size),
2981 RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE));
2976 } 2982 }
2977 } 2983 }
2978 2984
2979 Node* WasmGraphBuilder::GetGlobal(uint32_t index) { 2985 Node* WasmGraphBuilder::GetGlobal(uint32_t index) {
2980 MachineType mem_type = 2986 MachineType mem_type =
2981 wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index)); 2987 wasm::WasmOpcodes::MachineTypeFor(module_->GetGlobalType(index));
2982 Node* addr = jsgraph()->RelocatableIntPtrConstant( 2988 Node* addr = jsgraph()->RelocatableIntPtrConstant(
2983 reinterpret_cast<uintptr_t>(module_->instance->globals_start + 2989 reinterpret_cast<uintptr_t>(module_->instance->globals_start +
2984 module_->module->globals[index].offset), 2990 module_->module->globals[index].offset),
2985 RelocInfo::WASM_GLOBAL_REFERENCE); 2991 RelocInfo::WASM_GLOBAL_REFERENCE);
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
3686 Smi::FromInt(instruction.instr_offset)); 3692 Smi::FromInt(instruction.instr_offset));
3687 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, 3693 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset,
3688 Smi::FromInt(instruction.landing_offset)); 3694 Smi::FromInt(instruction.landing_offset));
3689 } 3695 }
3690 return fn_protected; 3696 return fn_protected;
3691 } 3697 }
3692 3698
3693 } // namespace compiler 3699 } // namespace compiler
3694 } // namespace internal 3700 } // namespace internal
3695 } // namespace v8 3701 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698