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

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

Issue 2295743002: [wasm] Refactor BuildWasmToJSWrapper to clearly separate direct calls from Call-codestub calls (Closed)
Patch Set: Created 4 years, 4 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 | « no previous file | no next file » | 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 30c545ec515bb07c2459b52b11dc25d3e1fcedd9..28d7a846f6d5d19614182862960a58f783f11e55 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -2548,18 +2548,14 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
*control_ = start;
Node** args = Buffer(wasm_count + 7);
- // The default context of the target.
- Handle<Context> target_context = isolate->native_context();
+ Node* call;
+ bool direct_call = false;
- // Optimization: check if the target is a JSFunction with the right arity so
- // that we can call it directly.
- bool call_direct = false;
- int pos = 0;
if (target->IsJSFunction()) {
Handle<JSFunction> function = Handle<JSFunction>::cast(target);
if (function->shared()->internal_formal_parameter_count() == wasm_count) {
- call_direct = true;
-
+ direct_call = true;
+ int pos = 0;
args[pos++] = jsgraph()->Constant(target); // target callable.
// Receiver.
if (is_sloppy(function->shared()->language_mode()) &&
@@ -2574,13 +2570,32 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
desc = Linkage::GetJSCallDescriptor(
graph()->zone(), false, wasm_count + 1, CallDescriptor::kNoFlags);
- // For a direct call we have to use the context of the JSFunction.
- target_context = handle(function->context());
+ // Convert WASM numbers to JS values.
titzer 2016/09/01 14:35:17 Is it possible to factor this loop out with its ca
ahaas 2016/09/01 17:17:52 Done.
+ int param_index = 0;
+ for (int i = 0; i < wasm_count; ++i) {
+ Node* param = graph()->NewNode(
+ jsgraph()->common()->Parameter(param_index++), start);
+ args[pos++] = ToJS(param, sig->GetParam(i));
+ if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kAstI64) {
+ // On 32 bit platforms we have to skip the high word of int64
+ // parameters.
+ param_index++;
+ }
+ }
+
+ args[pos++] = jsgraph()->UndefinedConstant(); // new target
+ args[pos++] = jsgraph()->Int32Constant(wasm_count); // argument count
+ args[pos++] = HeapConstant(handle(function->context()));
+ args[pos++] = *effect_;
+ args[pos++] = *control_;
+
+ call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
}
}
// We cannot call the target directly, we have to use the Call builtin.
- if (!call_direct) {
+ if (!direct_call) {
+ int pos = 0;
Callable callable = CodeFactory::Call(isolate);
args[pos++] = jsgraph()->HeapConstant(callable.code());
args[pos++] = jsgraph()->Constant(target); // target callable
@@ -2591,30 +2606,31 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
desc = Linkage::GetStubCallDescriptor(isolate, graph()->zone(),
callable.descriptor(), wasm_count + 1,
CallDescriptor::kNoFlags);
- }
- // Convert WASM numbers to JS values.
- int param_index = 0;
- for (int i = 0; i < wasm_count; ++i) {
- Node* param =
- graph()->NewNode(jsgraph()->common()->Parameter(param_index++), start);
- args[pos++] = ToJS(param, sig->GetParam(i));
- if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kAstI64) {
- // On 32 bit platforms we have to skip the high word of int64 parameters.
- param_index++;
+ // Convert WASM numbers to JS values.
+ int param_index = 0;
+ for (int i = 0; i < wasm_count; ++i) {
+ Node* param = graph()->NewNode(
+ jsgraph()->common()->Parameter(param_index++), start);
+ args[pos++] = ToJS(param, sig->GetParam(i));
+ if (jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kAstI64) {
+ // On 32 bit platforms we have to skip the high word of int64
+ // parameters.
+ param_index++;
+ }
}
- }
-
- if (call_direct) {
- args[pos++] = jsgraph()->UndefinedConstant(); // new target
- args[pos++] = jsgraph()->Int32Constant(wasm_count); // argument count
- }
- args[pos++] = HeapConstant(target_context);
- args[pos++] = *effect_;
- args[pos++] = *control_;
+ // The native_context is sufficient here, because all kind of callables
+ // which depend on the context provide their own context. The context here
+ // is only needed if the target is a constructor to throw a TypeError, if
+ // the target is a native function, or if the target is a callable JSObject,
+ // which can only be constructed by the runtime.
+ args[pos++] = HeapConstant(isolate->native_context());
+ args[pos++] = *effect_;
+ args[pos++] = *control_;
- Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
+ call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
+ }
// Convert the return value back.
Node* ret;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698