Commit c62bb3e2 authored by titzer@chromium.org's avatar titzer@chromium.org

Now with more checkings! Skip the CallFunctionStub when the callee function...

Now with more checkings! Skip the CallFunctionStub when the callee function can be statically determined.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/696223002

Cr-Commit-Position: refs/heads/master@{#25062}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25062 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 498920f9
...@@ -35,8 +35,9 @@ struct ArmLinkageHelperTraits { ...@@ -35,8 +35,9 @@ struct ArmLinkageHelperTraits {
typedef LinkageHelper<ArmLinkageHelperTraits> LH; typedef LinkageHelper<ArmLinkageHelperTraits> LH;
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) { CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
return LH::GetJSCallDescriptor(zone, parameter_count); CallDescriptor::Flags flags) {
return LH::GetJSCallDescriptor(zone, parameter_count, flags);
} }
......
...@@ -35,8 +35,9 @@ struct Arm64LinkageHelperTraits { ...@@ -35,8 +35,9 @@ struct Arm64LinkageHelperTraits {
typedef LinkageHelper<Arm64LinkageHelperTraits> LH; typedef LinkageHelper<Arm64LinkageHelperTraits> LH;
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) { CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
return LH::GetJSCallDescriptor(zone, parameter_count); CallDescriptor::Flags flags) {
return LH::GetJSCallDescriptor(zone, parameter_count, flags);
} }
......
...@@ -30,8 +30,9 @@ struct IA32LinkageHelperTraits { ...@@ -30,8 +30,9 @@ struct IA32LinkageHelperTraits {
typedef LinkageHelper<IA32LinkageHelperTraits> LH; typedef LinkageHelper<IA32LinkageHelperTraits> LH;
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) { CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
return LH::GetJSCallDescriptor(zone, parameter_count); CallDescriptor::Flags flags) {
return LH::GetJSCallDescriptor(zone, parameter_count, flags);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "src/compiler/js-generic-lowering.h" #include "src/compiler/js-generic-lowering.h"
#include "src/compiler/machine-operator.h" #include "src/compiler/machine-operator.h"
#include "src/compiler/node-aux-data-inl.h" #include "src/compiler/node-aux-data-inl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
#include "src/unique.h" #include "src/unique.h"
...@@ -405,9 +406,51 @@ void JSGenericLowering::LowerJSCallConstruct(Node* node) { ...@@ -405,9 +406,51 @@ void JSGenericLowering::LowerJSCallConstruct(Node* node) {
} }
bool JSGenericLowering::TryLowerDirectJSCall(Node* node) {
// Lower to a direct call to a constant JSFunction if legal.
const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
int arg_count = static_cast<int>(p.arity() - 2);
// Check the function is a constant and is really a JSFunction.
HeapObjectMatcher<Object> function_const(node->InputAt(0));
if (!function_const.HasValue()) return false; // not a constant.
Handle<Object> func = function_const.Value().handle();
if (!func->IsJSFunction()) return false; // not a function.
Handle<JSFunction> function = Handle<JSFunction>::cast(func);
if (arg_count != function->shared()->formal_parameter_count()) return false;
// Check the receiver doesn't need to be wrapped.
Node* receiver = node->InputAt(1);
if (!NodeProperties::IsTyped(receiver)) return false;
Type* ok_receiver = Type::Union(Type::Undefined(), Type::Receiver(), zone());
if (!NodeProperties::GetBounds(receiver).upper->Is(ok_receiver)) return false;
int index = NodeProperties::FirstContextIndex(node);
// TODO(titzer): total hack to share function context constants.
// Remove this when the JSGraph canonicalizes heap constants.
Node* context = node->InputAt(index);
HeapObjectMatcher<Context> context_const(context);
if (!context_const.HasValue() ||
*(context_const.Value().handle()) != function->context()) {
context = jsgraph()->HeapConstant(Handle<Context>(function->context()));
}
node->ReplaceInput(index, context);
CallDescriptor* desc = linkage()->GetJSCallDescriptor(
1 + arg_count, jsgraph()->zone(), FlagsForNode(node));
PatchOperator(node, common()->Call(desc));
return true;
}
void JSGenericLowering::LowerJSCallFunction(Node* node) { void JSGenericLowering::LowerJSCallFunction(Node* node) {
// Fast case: call function directly.
if (TryLowerDirectJSCall(node)) return;
// General case: CallFunctionStub.
const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
CallFunctionStub stub(isolate(), static_cast<int>(p.arity() - 2), p.flags()); int arg_count = static_cast<int>(p.arity() - 2);
CallFunctionStub stub(isolate(), arg_count, p.flags());
CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
CallDescriptor* desc = linkage()->GetStubCallDescriptor( CallDescriptor* desc = linkage()->GetStubCallDescriptor(
d, static_cast<int>(p.arity() - 1), FlagsForNode(node)); d, static_cast<int>(p.arity() - 1), FlagsForNode(node));
......
...@@ -66,6 +66,8 @@ class JSGenericLowering : public Reducer { ...@@ -66,6 +66,8 @@ class JSGenericLowering : public Reducer {
CompilationInfo* info_; CompilationInfo* info_;
JSGraph* jsgraph_; JSGraph* jsgraph_;
Linkage* linkage_; Linkage* linkage_;
bool TryLowerDirectJSCall(Node* node);
}; };
} // namespace compiler } // namespace compiler
......
...@@ -28,8 +28,8 @@ class LinkageHelper { ...@@ -28,8 +28,8 @@ class LinkageHelper {
} }
// TODO(turbofan): cache call descriptors for JSFunction calls. // TODO(turbofan): cache call descriptors for JSFunction calls.
static CallDescriptor* GetJSCallDescriptor(Zone* zone, static CallDescriptor* GetJSCallDescriptor(Zone* zone, int js_parameter_count,
int js_parameter_count) { CallDescriptor::Flags flags) {
const size_t return_count = 1; const size_t return_count = 1;
const size_t context_count = 1; const size_t context_count = 1;
const size_t parameter_count = js_parameter_count + context_count; const size_t parameter_count = js_parameter_count + context_count;
...@@ -56,16 +56,17 @@ class LinkageHelper { ...@@ -56,16 +56,17 @@ class LinkageHelper {
// The target for JS function calls is the JSFunction object. // The target for JS function calls is the JSFunction object.
MachineType target_type = kMachAnyTagged; MachineType target_type = kMachAnyTagged;
LinkageLocation target_loc = regloc(LinkageTraits::JSCallFunctionReg()); LinkageLocation target_loc = regloc(LinkageTraits::JSCallFunctionReg());
return new (zone) CallDescriptor(CallDescriptor::kCallJSFunction, // kind return new (zone) CallDescriptor( // --
target_type, // target MachineType CallDescriptor::kCallJSFunction, // kind
target_loc, // target location target_type, // target MachineType
types.Build(), // machine_sig target_loc, // target location
locations.Build(), // location_sig types.Build(), // machine_sig
js_parameter_count, // js_parameter_count locations.Build(), // location_sig
Operator::kNoProperties, // properties js_parameter_count, // js_parameter_count
kNoCalleeSaved, // callee-saved Operator::kNoProperties, // properties
CallDescriptor::kNeedsFrameState, // flags kNoCalleeSaved, // callee-saved
"js-call"); flags, // flags
"js-call");
} }
...@@ -116,16 +117,17 @@ class LinkageHelper { ...@@ -116,16 +117,17 @@ class LinkageHelper {
// The target for runtime calls is a code object. // The target for runtime calls is a code object.
MachineType target_type = kMachAnyTagged; MachineType target_type = kMachAnyTagged;
LinkageLocation target_loc = LinkageLocation::AnyRegister(); LinkageLocation target_loc = LinkageLocation::AnyRegister();
return new (zone) CallDescriptor(CallDescriptor::kCallCodeObject, // kind return new (zone) CallDescriptor( // --
target_type, // target MachineType CallDescriptor::kCallCodeObject, // kind
target_loc, // target location target_type, // target MachineType
types.Build(), // machine_sig target_loc, // target location
locations.Build(), // location_sig types.Build(), // machine_sig
js_parameter_count, // js_parameter_count locations.Build(), // location_sig
properties, // properties js_parameter_count, // js_parameter_count
kNoCalleeSaved, // callee-saved properties, // properties
flags, // flags kNoCalleeSaved, // callee-saved
function->name); // debug name flags, // flags
function->name); // debug name
} }
...@@ -169,16 +171,17 @@ class LinkageHelper { ...@@ -169,16 +171,17 @@ class LinkageHelper {
// The target for stub calls is a code object. // The target for stub calls is a code object.
MachineType target_type = kMachAnyTagged; MachineType target_type = kMachAnyTagged;
LinkageLocation target_loc = LinkageLocation::AnyRegister(); LinkageLocation target_loc = LinkageLocation::AnyRegister();
return new (zone) CallDescriptor(CallDescriptor::kCallCodeObject, // kind return new (zone) CallDescriptor( // --
target_type, // target MachineType CallDescriptor::kCallCodeObject, // kind
target_loc, // target location target_type, // target MachineType
types.Build(), // machine_sig target_loc, // target location
locations.Build(), // location_sig types.Build(), // machine_sig
js_parameter_count, // js_parameter_count locations.Build(), // location_sig
Operator::kNoProperties, // properties js_parameter_count, // js_parameter_count
kNoCalleeSaved, // callee-saved registers Operator::kNoProperties, // properties
flags, // flags kNoCalleeSaved, // callee-saved registers
descriptor.DebugName(zone->isolate())); flags, // flags
descriptor.DebugName(zone->isolate()));
} }
static CallDescriptor* GetSimplifiedCDescriptor(Zone* zone, static CallDescriptor* GetSimplifiedCDescriptor(Zone* zone,
...@@ -201,15 +204,16 @@ class LinkageHelper { ...@@ -201,15 +204,16 @@ class LinkageHelper {
// The target for C calls is always an address (i.e. machine pointer). // The target for C calls is always an address (i.e. machine pointer).
MachineType target_type = kMachPtr; MachineType target_type = kMachPtr;
LinkageLocation target_loc = LinkageLocation::AnyRegister(); LinkageLocation target_loc = LinkageLocation::AnyRegister();
return new (zone) CallDescriptor(CallDescriptor::kCallAddress, // kind return new (zone) CallDescriptor( // --
target_type, // target MachineType CallDescriptor::kCallAddress, // kind
target_loc, // target location target_type, // target MachineType
msig, // machine_sig target_loc, // target location
locations.Build(), // location_sig msig, // machine_sig
0, // js_parameter_count locations.Build(), // location_sig
Operator::kNoProperties, // properties 0, // js_parameter_count
LinkageTraits::CCalleeSaveRegisters(), Operator::kNoProperties, // properties
CallDescriptor::kNoFlags, "c-call"); LinkageTraits::CCalleeSaveRegisters(), CallDescriptor::kNoFlags,
"c-call");
} }
static LinkageLocation regloc(Register reg) { static LinkageLocation regloc(Register reg) {
......
...@@ -42,13 +42,15 @@ CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) { ...@@ -42,13 +42,15 @@ CallDescriptor* Linkage::ComputeIncoming(Zone* zone, CompilationInfo* info) {
if (info->function() != NULL) { if (info->function() != NULL) {
// If we already have the function literal, use the number of parameters // If we already have the function literal, use the number of parameters
// plus the receiver. // plus the receiver.
return GetJSCallDescriptor(1 + info->function()->parameter_count(), zone); return GetJSCallDescriptor(1 + info->function()->parameter_count(), zone,
CallDescriptor::kNoFlags);
} }
if (!info->closure().is_null()) { if (!info->closure().is_null()) {
// If we are compiling a JS function, use a JS call descriptor, // If we are compiling a JS function, use a JS call descriptor,
// plus the receiver. // plus the receiver.
SharedFunctionInfo* shared = info->closure()->shared(); SharedFunctionInfo* shared = info->closure()->shared();
return GetJSCallDescriptor(1 + shared->formal_parameter_count(), zone); return GetJSCallDescriptor(1 + shared->formal_parameter_count(), zone,
CallDescriptor::kNoFlags);
} }
if (info->code_stub() != NULL) { if (info->code_stub() != NULL) {
// Use the code stub interface descriptor. // Use the code stub interface descriptor.
...@@ -88,8 +90,9 @@ FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame, ...@@ -88,8 +90,9 @@ FrameOffset Linkage::GetFrameOffset(int spill_slot, Frame* frame,
} }
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count) const { CallDescriptor* Linkage::GetJSCallDescriptor(
return GetJSCallDescriptor(parameter_count, zone_); int parameter_count, CallDescriptor::Flags flags) const {
return GetJSCallDescriptor(parameter_count, zone_, flags);
} }
......
...@@ -174,8 +174,10 @@ class Linkage : public ZoneObject { ...@@ -174,8 +174,10 @@ class Linkage : public ZoneObject {
// The call descriptor for this compilation unit describes the locations // The call descriptor for this compilation unit describes the locations
// of incoming parameters and the outgoing return value(s). // of incoming parameters and the outgoing return value(s).
CallDescriptor* GetIncomingDescriptor() const { return incoming_; } CallDescriptor* GetIncomingDescriptor() const { return incoming_; }
CallDescriptor* GetJSCallDescriptor(int parameter_count) const; CallDescriptor* GetJSCallDescriptor(int parameter_count,
static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone); CallDescriptor::Flags flags) const;
static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone,
CallDescriptor::Flags flags);
CallDescriptor* GetRuntimeCallDescriptor( CallDescriptor* GetRuntimeCallDescriptor(
Runtime::FunctionId function, int parameter_count, Runtime::FunctionId function, int parameter_count,
Operator::Properties properties) const; Operator::Properties properties) const;
......
...@@ -35,8 +35,9 @@ struct MipsLinkageHelperTraits { ...@@ -35,8 +35,9 @@ struct MipsLinkageHelperTraits {
typedef LinkageHelper<MipsLinkageHelperTraits> LH; typedef LinkageHelper<MipsLinkageHelperTraits> LH;
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) { CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
return LH::GetJSCallDescriptor(zone, parameter_count); CallDescriptor::Flags flags) {
return LH::GetJSCallDescriptor(zone, parameter_count, flags);
} }
......
...@@ -99,7 +99,8 @@ Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver, ...@@ -99,7 +99,8 @@ Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver,
Node* RawMachineAssembler::CallJS0(Node* function, Node* receiver, Node* RawMachineAssembler::CallJS0(Node* function, Node* receiver,
Node* context, Node* frame_state) { Node* context, Node* frame_state) {
CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(1, zone()); CallDescriptor* descriptor =
Linkage::GetJSCallDescriptor(1, zone(), CallDescriptor::kNeedsFrameState);
Node* call = graph()->NewNode(common()->Call(descriptor), function, receiver, Node* call = graph()->NewNode(common()->Call(descriptor), function, receiver,
context, frame_state); context, frame_state);
schedule()->AddNode(CurrentBlock(), call); schedule()->AddNode(CurrentBlock(), call);
......
...@@ -49,8 +49,9 @@ struct X64LinkageHelperTraits { ...@@ -49,8 +49,9 @@ struct X64LinkageHelperTraits {
typedef LinkageHelper<X64LinkageHelperTraits> LH; typedef LinkageHelper<X64LinkageHelperTraits> LH;
CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone) { CallDescriptor* Linkage::GetJSCallDescriptor(int parameter_count, Zone* zone,
return LH::GetJSCallDescriptor(zone, parameter_count); CallDescriptor::Flags flags) {
return LH::GetJSCallDescriptor(zone, parameter_count, flags);
} }
......
...@@ -90,7 +90,8 @@ TEST(TestLinkageJSCall) { ...@@ -90,7 +90,8 @@ TEST(TestLinkageJSCall) {
Linkage linkage(info.zone(), &info); Linkage linkage(info.zone(), &info);
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
CallDescriptor* descriptor = linkage.GetJSCallDescriptor(i); CallDescriptor* descriptor =
linkage.GetJSCallDescriptor(i, CallDescriptor::kNoFlags);
CHECK_NE(NULL, descriptor); CHECK_NE(NULL, descriptor);
CHECK_EQ(i, descriptor->JSParameterCount()); CHECK_EQ(i, descriptor->JSParameterCount());
CHECK_EQ(1, descriptor->ReturnCount()); CHECK_EQ(1, descriptor->ReturnCount());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment