OLD | NEW |
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 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 wasm::WasmCodePosition position) { | 1990 wasm::WasmCodePosition position) { |
1991 DCHECK_NULL(args[0]); | 1991 DCHECK_NULL(args[0]); |
1992 | 1992 |
1993 // Add code object as constant. | 1993 // Add code object as constant. |
1994 args[0] = HeapConstant(module_->GetImportCode(index)); | 1994 args[0] = HeapConstant(module_->GetImportCode(index)); |
1995 wasm::FunctionSig* sig = module_->GetImportSignature(index); | 1995 wasm::FunctionSig* sig = module_->GetImportSignature(index); |
1996 | 1996 |
1997 return BuildWasmCall(sig, args, position); | 1997 return BuildWasmCall(sig, args, position); |
1998 } | 1998 } |
1999 | 1999 |
2000 Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, | 2000 Node* WasmGraphBuilder::CallIndirect(uint32_t entry_index, uint32_t table_index, |
| 2001 Node** args, |
2001 wasm::WasmCodePosition position) { | 2002 wasm::WasmCodePosition position) { |
2002 DCHECK_NOT_NULL(args[0]); | 2003 DCHECK_NOT_NULL(args[0]); |
2003 DCHECK(module_ && module_->instance); | 2004 DCHECK(module_ && module_->instance); |
2004 | 2005 |
2005 MachineOperatorBuilder* machine = jsgraph()->machine(); | 2006 MachineOperatorBuilder* machine = jsgraph()->machine(); |
2006 | 2007 |
2007 // Compute the code object by loading it from the function table. | 2008 // Compute the code object by loading it from the function table. |
2008 Node* key = args[0]; | 2009 Node* key = args[0]; |
2009 | 2010 |
2010 // Assume only one table for now. | |
2011 DCHECK_LE(module_->instance->function_tables.size(), 1u); | |
2012 // Bounds check the index. | 2011 // Bounds check the index. |
2013 uint32_t table_size = | 2012 uint32_t table_size = module_->IsValidTable(table_index) |
2014 module_->IsValidTable(0) ? module_->GetTable(0)->max_size : 0; | 2013 ? module_->GetTable(table_index)->max_size |
| 2014 : 0; |
2015 if (table_size > 0) { | 2015 if (table_size > 0) { |
2016 // Bounds check against the table size. | 2016 // Bounds check against the table size. |
2017 Node* size = Uint32Constant(table_size); | 2017 Node* size = Uint32Constant(table_size); |
2018 Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); | 2018 Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, size); |
2019 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); | 2019 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, in_bounds, position); |
2020 } else { | 2020 } else { |
2021 // No function table. Generate a trap and return a constant. | 2021 // No function table. Generate a trap and return a constant. |
2022 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, Int32Constant(0), position); | 2022 trap_->AddTrapIfFalse(wasm::kTrapFuncInvalid, Int32Constant(0), position); |
2023 return trap_->GetTrapValue(module_->GetSignature(index)); | 2023 return trap_->GetTrapValue(module_->GetSignature(entry_index)); |
2024 } | 2024 } |
2025 Node* table = FunctionTable(0); | 2025 Node* table = FunctionTable(table_index); |
2026 | 2026 |
2027 // Load signature from the table and check. | 2027 // Load signature from the table. |
2028 // The table is a FixedArray; signatures are encoded as SMIs. | 2028 // The table is a FixedArray; signatures are encoded as SMIs. |
2029 // [sig1, sig2, sig3, ...., code1, code2, code3 ...] | 2029 // [sig1, sig2, sig3, ...., code1, code2, code3 ...] |
2030 ElementAccess access = AccessBuilder::ForFixedArrayElement(); | 2030 ElementAccess access = AccessBuilder::ForFixedArrayElement(); |
2031 const int fixed_offset = access.header_size - access.tag(); | 2031 const int fixed_offset = access.header_size - access.tag(); |
2032 { | |
2033 Node* load_sig = graph()->NewNode( | |
2034 machine->Load(MachineType::AnyTagged()), table, | |
2035 graph()->NewNode(machine->Int32Add(), | |
2036 graph()->NewNode(machine->Word32Shl(), key, | |
2037 Int32Constant(kPointerSizeLog2)), | |
2038 Int32Constant(fixed_offset)), | |
2039 *effect_, *control_); | |
2040 Node* sig_match = | |
2041 graph()->NewNode(machine->Word32Equal(), | |
2042 BuildChangeSmiToInt32(load_sig), Int32Constant(index)); | |
2043 trap_->AddTrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position); | |
2044 } | |
2045 | 2032 |
2046 // Load code object from the table. | 2033 // Load code object from the table. |
2047 uint32_t offset = fixed_offset + kPointerSize * table_size; | 2034 uint32_t offset = fixed_offset + kPointerSize * table_size; |
2048 Node* load_code = graph()->NewNode( | 2035 Node* load_code = graph()->NewNode( |
2049 machine->Load(MachineType::AnyTagged()), table, | 2036 machine->Load(MachineType::AnyTagged()), table, |
2050 graph()->NewNode(machine->Int32Add(), | 2037 graph()->NewNode(machine->Int32Add(), |
2051 graph()->NewNode(machine->Word32Shl(), key, | 2038 graph()->NewNode(machine->Word32Shl(), key, |
2052 Int32Constant(kPointerSizeLog2)), | 2039 Int32Constant(kPointerSizeLog2)), |
2053 Uint32Constant(offset)), | 2040 Uint32Constant(offset)), |
2054 *effect_, *control_); | 2041 *effect_, *control_); |
2055 | 2042 |
2056 args[0] = load_code; | 2043 args[0] = load_code; |
2057 wasm::FunctionSig* sig = module_->GetSignature(index); | 2044 wasm::FunctionSig* sig = module_->GetSignature(entry_index); |
2058 return BuildWasmCall(sig, args, position); | 2045 return BuildWasmCall(sig, args, position); |
2059 } | 2046 } |
2060 | 2047 |
2061 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { | 2048 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { |
2062 // Implement Rol by Ror since TurboFan does not have Rol opcode. | 2049 // Implement Rol by Ror since TurboFan does not have Rol opcode. |
2063 // TODO(weiliang): support Word32Rol opcode in TurboFan. | 2050 // TODO(weiliang): support Word32Rol opcode in TurboFan. |
2064 Int32Matcher m(right); | 2051 Int32Matcher m(right); |
2065 if (m.HasValue()) { | 2052 if (m.HasValue()) { |
2066 return Binop(wasm::kExprI32Ror, left, | 2053 return Binop(wasm::kExprI32Ror, left, |
2067 jsgraph()->Int32Constant(32 - m.Value())); | 2054 jsgraph()->Int32Constant(32 - m.Value())); |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 function_->code_start_offset), | 3311 function_->code_start_offset), |
3325 compile_ms); | 3312 compile_ms); |
3326 } | 3313 } |
3327 | 3314 |
3328 return code; | 3315 return code; |
3329 } | 3316 } |
3330 | 3317 |
3331 } // namespace compiler | 3318 } // namespace compiler |
3332 } // namespace internal | 3319 } // namespace internal |
3333 } // namespace v8 | 3320 } // namespace v8 |
OLD | NEW |