Chromium Code Reviews| 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 "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
| 8 | 8 |
| 9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 Node** buf = Realloc(effects, count, count + 1); | 354 Node** buf = Realloc(effects, count, count + 1); |
| 355 buf[count] = control; | 355 buf[count] = control; |
| 356 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, | 356 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, |
| 357 buf); | 357 buf); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Node* WasmGraphBuilder::NumberConstant(int32_t value) { | 360 Node* WasmGraphBuilder::NumberConstant(int32_t value) { |
| 361 return jsgraph()->Constant(value); | 361 return jsgraph()->Constant(value); |
| 362 } | 362 } |
| 363 | 363 |
| 364 Node* WasmGraphBuilder::Uint32Constant(uint32_t value) { | |
| 365 return jsgraph()->Uint32Constant(value); | |
| 366 } | |
| 367 | |
| 364 Node* WasmGraphBuilder::Int32Constant(int32_t value) { | 368 Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
| 365 return jsgraph()->Int32Constant(value); | 369 return jsgraph()->Int32Constant(value); |
| 366 } | 370 } |
| 367 | 371 |
| 368 Node* WasmGraphBuilder::Int64Constant(int64_t value) { | 372 Node* WasmGraphBuilder::Int64Constant(int64_t value) { |
| 369 return jsgraph()->Int64Constant(value); | 373 return jsgraph()->Int64Constant(value); |
| 370 } | 374 } |
| 371 | 375 |
| 372 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, | 376 Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left, Node* right, |
| 373 wasm::WasmCodePosition position) { | 377 wasm::WasmCodePosition position) { |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2087 graph()->NewNode(machine->Word32Shl(), key, | 2091 graph()->NewNode(machine->Word32Shl(), key, |
| 2088 Int32Constant(kPointerSizeLog2)), | 2092 Int32Constant(kPointerSizeLog2)), |
| 2089 Int32Constant(offset)), | 2093 Int32Constant(offset)), |
| 2090 *effect_, *control_); | 2094 *effect_, *control_); |
| 2091 | 2095 |
| 2092 args[0] = load_code; | 2096 args[0] = load_code; |
| 2093 wasm::FunctionSig* sig = module_->GetSignature(index); | 2097 wasm::FunctionSig* sig = module_->GetSignature(index); |
| 2094 return BuildWasmCall(sig, args, position); | 2098 return BuildWasmCall(sig, args, position); |
| 2095 } | 2099 } |
| 2096 | 2100 |
| 2101 Node* WasmGraphBuilder::JITSingleFunction(Node* base, Node* length, Node* index, | |
| 2102 uint32_t sig_index, | |
|
Mircea Trofin
2016/07/12 02:49:12
looks like base, length, index, and sig are all no
John
2016/07/13 19:56:59
Const-correctness is good, but it seems this modul
ritesht
2016/07/13 23:58:44
Done.
ritesht
2016/07/13 23:58:44
Acknowledged.
| |
| 2103 wasm::FunctionSig* sig) { | |
| 2104 Runtime::FunctionId f = Runtime::kJITSingleFunction; | |
| 2105 const Runtime::Function* fun = Runtime::FunctionForId(f); | |
| 2106 // CEntryStubConstant nodes have to be created and cached in the main | |
| 2107 // thread. At the moment this is only done for CEntryStubConstant(1). | |
| 2108 DCHECK_EQ(1, fun->result_size); | |
| 2109 uint32_t return_count = static_cast<uint32_t>(sig->return_count()); | |
| 2110 uint32_t parameter_count = static_cast<uint32_t>(sig->parameter_count()); | |
| 2111 | |
| 2112 uint32_t inputs_size = 13 + return_count + parameter_count; | |
|
Mircea Trofin
2016/07/12 02:49:12
what's 13? (is there a constant or should you defi
ritesht
2016/07/13 23:58:44
Done.
| |
| 2113 Node** inputs = Buffer(inputs_size); | |
| 2114 inputs[0] = jsgraph()->CEntryStubConstant(fun->result_size); // C entry | |
|
Mircea Trofin
2016/07/12 02:49:12
remove comment ("// C entry"), doesn't add info.
ritesht
2016/07/13 23:58:45
Done.
| |
| 2115 inputs[1] = BuildChangeUint32ToSmi(base); | |
| 2116 inputs[2] = BuildChangeUint32ToSmi(length); | |
| 2117 inputs[3] = BuildChangeUint32ToSmi(index); | |
| 2118 inputs[4] = BuildChangeIntPtrToSmi(MemBuffer(0)); | |
| 2119 inputs[5] = FunctionTable(); | |
| 2120 inputs[6] = Uint32Constant(sig_index); | |
| 2121 inputs[7] = BuildChangeUint32ToSmi(Uint32Constant(return_count)); | |
| 2122 | |
| 2123 // Pass in parameters and return types in to the runtime function | |
| 2124 // to allow it to regenerate signature | |
| 2125 for (uint32_t i = 0; i < return_count; i++) { | |
|
Mircea Trofin
2016/07/12 02:49:12
++i
ritesht
2016/07/13 23:58:44
Done.
| |
| 2126 inputs[i + 8] = BuildChangeUint32ToSmi( | |
| 2127 Uint32Constant(static_cast<int>(sig->GetReturn(i)))); | |
| 2128 } | |
| 2129 | |
| 2130 for (uint32_t i = 0; i < parameter_count; i++) { | |
|
Mircea Trofin
2016/07/12 02:49:12
++i
ritesht
2016/07/13 23:58:44
Done.
| |
| 2131 inputs[i + 8 + return_count] = BuildChangeUint32ToSmi( | |
| 2132 Uint32Constant(static_cast<int>(sig->GetParam(i)))); | |
| 2133 } | |
| 2134 | |
| 2135 const uint32_t args_offset = 8 + return_count + parameter_count; | |
|
Mircea Trofin
2016/07/12 02:49:12
could you define constants for all these indices (
ritesht
2016/07/13 23:58:44
Done.
| |
| 2136 inputs[args_offset] = jsgraph()->ExternalConstant( | |
| 2137 ExternalReference(f, jsgraph()->isolate())); // ref | |
| 2138 inputs[args_offset + 1] = jsgraph()->Int32Constant(args_offset - 1); // arity | |
| 2139 inputs[args_offset + 2] = | |
| 2140 HeapConstant(module_->instance->context); // context | |
| 2141 inputs[args_offset + 3] = *effect_; | |
| 2142 inputs[args_offset + 4] = *control_; | |
| 2143 | |
| 2144 // Use the module context to call the runtime. | |
| 2145 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | |
|
John
2016/07/13 19:56:59
I would probably use auto* here, but auto isn't us
ritesht
2016/07/13 23:58:44
Acknowledged.
| |
| 2146 jsgraph()->zone(), f, args_offset - 1, Operator::kNoProperties, | |
| 2147 CallDescriptor::kNoFlags); | |
| 2148 | |
| 2149 Node* node = | |
| 2150 graph()->NewNode(jsgraph()->common()->Call(desc), inputs_size, inputs); | |
| 2151 *control_ = node; | |
| 2152 *effect_ = node; | |
| 2153 return node; | |
| 2154 } | |
| 2155 | |
| 2097 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { | 2156 Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { |
| 2098 // Implement Rol by Ror since TurboFan does not have Rol opcode. | 2157 // Implement Rol by Ror since TurboFan does not have Rol opcode. |
| 2099 // TODO(weiliang): support Word32Rol opcode in TurboFan. | 2158 // TODO(weiliang): support Word32Rol opcode in TurboFan. |
| 2100 Int32Matcher m(right); | 2159 Int32Matcher m(right); |
| 2101 if (m.HasValue()) { | 2160 if (m.HasValue()) { |
| 2102 return Binop(wasm::kExprI32Ror, left, | 2161 return Binop(wasm::kExprI32Ror, left, |
| 2103 jsgraph()->Int32Constant(32 - m.Value())); | 2162 jsgraph()->Int32Constant(32 - m.Value())); |
| 2104 } else { | 2163 } else { |
| 2105 return Binop(wasm::kExprI32Ror, left, | 2164 return Binop(wasm::kExprI32Ror, left, |
| 2106 Binop(wasm::kExprI32Sub, jsgraph()->Int32Constant(32), right)); | 2165 Binop(wasm::kExprI32Sub, jsgraph()->Int32Constant(32), right)); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2410 case wasm::kAstStmt: | 2469 case wasm::kAstStmt: |
| 2411 num = jsgraph()->Int32Constant(0); | 2470 num = jsgraph()->Int32Constant(0); |
| 2412 break; | 2471 break; |
| 2413 default: | 2472 default: |
| 2414 UNREACHABLE(); | 2473 UNREACHABLE(); |
| 2415 return nullptr; | 2474 return nullptr; |
| 2416 } | 2475 } |
| 2417 return num; | 2476 return num; |
| 2418 } | 2477 } |
| 2419 | 2478 |
| 2479 Node* WasmGraphBuilder::BuildChangeIntPtrToSmi(Node* value) { | |
|
Mircea Trofin
2016/07/12 02:49:12
"value" is const?
ritesht
2016/07/13 23:58:44
Removed function. No longer needed.
| |
| 2480 return graph()->NewNode(jsgraph()->machine()->WordShl(), value, | |
| 2481 BuildSmiShiftBitsConstant()); | |
| 2482 } | |
| 2483 | |
| 2420 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { | 2484 Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { |
| 2421 if (jsgraph()->machine()->Is64()) { | 2485 if (jsgraph()->machine()->Is64()) { |
| 2422 value = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), value); | 2486 value = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), value); |
| 2423 } | 2487 } |
| 2424 return graph()->NewNode(jsgraph()->machine()->WordShl(), value, | 2488 return graph()->NewNode(jsgraph()->machine()->WordShl(), value, |
| 2425 BuildSmiShiftBitsConstant()); | 2489 BuildSmiShiftBitsConstant()); |
| 2426 } | 2490 } |
| 2427 | 2491 |
| 2428 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { | 2492 Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { |
| 2429 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, | 2493 value = graph()->NewNode(jsgraph()->machine()->WordSar(), value, |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3464 function_->code_start_offset), | 3528 function_->code_start_offset), |
| 3465 compile_ms); | 3529 compile_ms); |
| 3466 } | 3530 } |
| 3467 | 3531 |
| 3468 return code; | 3532 return code; |
| 3469 } | 3533 } |
| 3470 | 3534 |
| 3471 } // namespace compiler | 3535 } // namespace compiler |
| 3472 } // namespace internal | 3536 } // namespace internal |
| 3473 } // namespace v8 | 3537 } // namespace v8 |
| OLD | NEW |