Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index e7508c26ddffe32340289b2ed64342fb4d809590..5024bff198436437c11ed08f6a4512384f906214 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -361,6 +361,10 @@ Node* WasmGraphBuilder::NumberConstant(int32_t value) { |
return jsgraph()->Constant(value); |
} |
+Node* WasmGraphBuilder::Uint32Constant(uint32_t value) { |
+ return jsgraph()->Uint32Constant(value); |
+} |
+ |
Node* WasmGraphBuilder::Int32Constant(int32_t value) { |
return jsgraph()->Int32Constant(value); |
} |
@@ -2094,6 +2098,61 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t index, Node** args, |
return BuildWasmCall(sig, args, position); |
} |
+Node* WasmGraphBuilder::JITSingleFunction(Node* base, Node* length, Node* index, |
+ 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.
|
+ wasm::FunctionSig* sig) { |
+ Runtime::FunctionId f = Runtime::kJITSingleFunction; |
+ const Runtime::Function* fun = Runtime::FunctionForId(f); |
+ // CEntryStubConstant nodes have to be created and cached in the main |
+ // thread. At the moment this is only done for CEntryStubConstant(1). |
+ DCHECK_EQ(1, fun->result_size); |
+ uint32_t return_count = static_cast<uint32_t>(sig->return_count()); |
+ uint32_t parameter_count = static_cast<uint32_t>(sig->parameter_count()); |
+ |
+ 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.
|
+ Node** inputs = Buffer(inputs_size); |
+ 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.
|
+ inputs[1] = BuildChangeUint32ToSmi(base); |
+ inputs[2] = BuildChangeUint32ToSmi(length); |
+ inputs[3] = BuildChangeUint32ToSmi(index); |
+ inputs[4] = BuildChangeIntPtrToSmi(MemBuffer(0)); |
+ inputs[5] = FunctionTable(); |
+ inputs[6] = Uint32Constant(sig_index); |
+ inputs[7] = BuildChangeUint32ToSmi(Uint32Constant(return_count)); |
+ |
+ // Pass in parameters and return types in to the runtime function |
+ // to allow it to regenerate signature |
+ 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.
|
+ inputs[i + 8] = BuildChangeUint32ToSmi( |
+ Uint32Constant(static_cast<int>(sig->GetReturn(i)))); |
+ } |
+ |
+ 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.
|
+ inputs[i + 8 + return_count] = BuildChangeUint32ToSmi( |
+ Uint32Constant(static_cast<int>(sig->GetParam(i)))); |
+ } |
+ |
+ 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.
|
+ inputs[args_offset] = jsgraph()->ExternalConstant( |
+ ExternalReference(f, jsgraph()->isolate())); // ref |
+ inputs[args_offset + 1] = jsgraph()->Int32Constant(args_offset - 1); // arity |
+ inputs[args_offset + 2] = |
+ HeapConstant(module_->instance->context); // context |
+ inputs[args_offset + 3] = *effect_; |
+ inputs[args_offset + 4] = *control_; |
+ |
+ // Use the module context to call the runtime. |
+ 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.
|
+ jsgraph()->zone(), f, args_offset - 1, Operator::kNoProperties, |
+ CallDescriptor::kNoFlags); |
+ |
+ Node* node = |
+ graph()->NewNode(jsgraph()->common()->Call(desc), inputs_size, inputs); |
+ *control_ = node; |
+ *effect_ = node; |
+ return node; |
+} |
+ |
Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) { |
// Implement Rol by Ror since TurboFan does not have Rol opcode. |
// TODO(weiliang): support Word32Rol opcode in TurboFan. |
@@ -2417,6 +2476,11 @@ Node* WasmGraphBuilder::FromJS(Node* node, Node* context, |
return num; |
} |
+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.
|
+ return graph()->NewNode(jsgraph()->machine()->WordShl(), value, |
+ BuildSmiShiftBitsConstant()); |
+} |
+ |
Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { |
if (jsgraph()->machine()->Is64()) { |
value = graph()->NewNode(jsgraph()->machine()->ChangeInt32ToInt64(), value); |