Commit a326691c authored by svenpanne's avatar svenpanne Committed by Commit bot

JavaScript stubs have access to their calling convention and minor key now.

First steps only, the TurboFan compilation is still triggered from C++ land.

Includes some simplifications/cleanups, too.

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

Cr-Commit-Position: refs/heads/master@{#28581}
parent eeb2d17b
...@@ -477,17 +477,31 @@ Handle<JSFunction> GetFunction(Isolate* isolate, const char* name) { ...@@ -477,17 +477,31 @@ Handle<JSFunction> GetFunction(Isolate* isolate, const char* name) {
Handle<JSFunction> function = Handle<JSFunction>::cast(fun.ToHandleChecked()); Handle<JSFunction> function = Handle<JSFunction>::cast(fun.ToHandleChecked());
DCHECK(!function->IsUndefined() && DCHECK(!function->IsUndefined() &&
"JavaScript implementation of stub not found"); "JavaScript implementation of stub not found");
// Just to make sure nobody calls this...
function->set_code(isolate->builtins()->builtin(Builtins::kIllegal));
return function; return function;
} }
} // namespace } // namespace
Handle<Code> TurboFanCodeStub::GenerateCode() { Handle<Code> TurboFanCodeStub::GenerateCode() {
// Get the outer ("stub generator") function.
const char* name = CodeStub::MajorName(MajorKey(), false);
Handle<JSFunction> outer = GetFunction(isolate(), name);
DCHECK_EQ(2, outer->shared()->length());
// Invoke the outer function to get the stub itself.
Factory* factory = isolate()->factory();
Handle<Object> call_conv = factory->InternalizeUtf8String(name);
Handle<Object> minor_key = factory->NewNumber(MinorKey());
Handle<Object> args[] = {call_conv, minor_key};
MaybeHandle<Object> result = Execution::Call(
isolate(), outer, factory->undefined_value(), 2, args, false);
Handle<JSFunction> inner = Handle<JSFunction>::cast(result.ToHandleChecked());
// Just to make sure nobody calls this...
inner->set_code(isolate()->builtins()->builtin(Builtins::kIllegal));
Zone zone; Zone zone;
// Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair. // Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair.
ParseInfo parse_info(&zone, GetFunction(isolate(), GetFunctionName())); ParseInfo parse_info(&zone, inner);
CompilationInfo info(&parse_info); CompilationInfo info(&parse_info);
info.SetStub(this); info.SetStub(this);
return info.GenerateCodeStub(); return info.GenerateCodeStub();
......
...@@ -355,11 +355,6 @@ struct FakeStubForTesting : public CodeStub { ...@@ -355,11 +355,6 @@ struct FakeStubForTesting : public CodeStub {
Handle<Code> GenerateCode() override; \ Handle<Code> GenerateCode() override; \
DEFINE_CODE_STUB(NAME, SUPER) DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
public: \
const char* GetFunctionName() const override { return #NAME "_STUB"; } \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \ #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
public: \ public: \
Handle<Code> GenerateCode() override; \ Handle<Code> GenerateCode() override; \
...@@ -533,8 +528,6 @@ class TurboFanCodeStub : public CodeStub { ...@@ -533,8 +528,6 @@ class TurboFanCodeStub : public CodeStub {
Code::StubType GetStubType() const override { return Code::FAST; } Code::StubType GetStubType() const override { return Code::FAST; }
virtual const char* GetFunctionName() const = 0;
protected: protected:
explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {} explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
...@@ -615,7 +608,7 @@ class MathFloorStub : public TurboFanCodeStub { ...@@ -615,7 +608,7 @@ class MathFloorStub : public TurboFanCodeStub {
int GetStackParameterCount() const override { return 1; } int GetStackParameterCount() const override { return 1; }
DEFINE_CALL_INTERFACE_DESCRIPTOR(MathRoundVariant); DEFINE_CALL_INTERFACE_DESCRIPTOR(MathRoundVariant);
DEFINE_TURBOFAN_CODE_STUB(MathFloor, TurboFanCodeStub); DEFINE_CODE_STUB(MathFloor, TurboFanCodeStub);
}; };
...@@ -628,7 +621,7 @@ class StringLengthTFStub : public TurboFanCodeStub { ...@@ -628,7 +621,7 @@ class StringLengthTFStub : public TurboFanCodeStub {
ExtraICState GetExtraICState() const override { return Code::LOAD_IC; } ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector); DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
DEFINE_TURBOFAN_CODE_STUB(StringLengthTF, TurboFanCodeStub); DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
}; };
...@@ -671,7 +664,7 @@ class StringAddTFStub : public TurboFanCodeStub { ...@@ -671,7 +664,7 @@ class StringAddTFStub : public TurboFanCodeStub {
void PrintBaseName(std::ostream& os) const override; // NOLINT void PrintBaseName(std::ostream& os) const override; // NOLINT
DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd); DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
DEFINE_TURBOFAN_CODE_STUB(StringAddTF, TurboFanCodeStub); DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
}; };
......
...@@ -64,9 +64,9 @@ var TO_NUMBER; ...@@ -64,9 +64,9 @@ var TO_NUMBER;
var TO_STRING; var TO_STRING;
var TO_NAME; var TO_NAME;
var StringLengthTF_STUB; var StringLengthTFStub;
var StringAddTF_STUB; var StringAddTFStub;
var MathFloor_STUB; var MathFloorStub;
var $defaultNumber; var $defaultNumber;
var $defaultString; var $defaultString;
...@@ -767,35 +767,44 @@ TO_NAME = function TO_NAME() { ...@@ -767,35 +767,44 @@ TO_NAME = function TO_NAME() {
----------------------------------------------- -----------------------------------------------
*/ */
StringLengthTF_STUB = function StringLengthTF_STUB(receiver, name, i, v) { StringLengthTFStub = function StringLengthTFStub(call_conv, minor_key) {
// i and v are dummy parameters mandated by the InterfaceDescriptor, var stub = function(receiver, name, i, v) {
// (LoadWithVectorDescriptor). // i and v are dummy parameters mandated by the InterfaceDescriptor,
return %_StringGetLength(%_JSValueGetValue(receiver)); // (LoadWithVectorDescriptor).
} return %_StringGetLength(%_JSValueGetValue(receiver));
}
StringAddTF_STUB = function StringAddTF_STUB(left, right) { return stub;
return %StringAdd(left, right);
} }
MathFloor_STUB = function MathFloor_STUB(f, i, v) { StringAddTFStub = function StringAddTFStub(call_conv, minor_key) {
// |f| is calling function's JSFunction var stub = function(left, right) {
// |i| is TypeFeedbackVector slot # of callee's CallIC for Math.floor call return %StringAdd(left, right);
// |v| is the value to floor
var r = %_MathFloor(+v);
if (%_IsMinusZero(r)) {
// Collect type feedback when the result of the floor is -0. This is
// accomplished by storing a sentinel in the second, "extra"
// TypeFeedbackVector slot corresponding to the Math.floor CallIC call in
// the caller's TypeVector.
%_FixedArraySet(%_GetTypeFeedbackVector(f), ((i|0)+1)|0, 1);
return -0;
} }
// Return integers in smi range as smis. return stub;
var trunc = r|0; }
if (trunc === r) {
return trunc; MathFloorStub = function MathFloorStub(call_conv, minor_key) {
var stub = function(f, i, v) {
// |f| is calling function's JSFunction
// |i| is TypeFeedbackVector slot # of callee's CallIC for Math.floor call
// |v| is the value to floor
var r = %_MathFloor(+v);
if (%_IsMinusZero(r)) {
// Collect type feedback when the result of the floor is -0. This is
// accomplished by storing a sentinel in the second, "extra"
// TypeFeedbackVector slot corresponding to the Math.floor CallIC call in
// the caller's TypeVector.
%_FixedArraySet(%_GetTypeFeedbackVector(f), ((i|0)+1)|0, 1);
return -0;
}
// Return integers in smi range as smis.
var trunc = r|0;
if (trunc === r) {
return trunc;
}
return r;
} }
return r; return stub;
} }
......
...@@ -36,16 +36,17 @@ const kFirstSlotExtraTypeFeedbackIndex = 5; ...@@ -36,16 +36,17 @@ const kFirstSlotExtraTypeFeedbackIndex = 5;
} }
// Execute the function once to make sure it has a type feedback vector. // Execute the function once to make sure it has a type feedback vector.
floorFunc(5); floorFunc(5);
var stub = builtins.MathFloorStub("MathFloorStub", 0);
assertTrue(kExtraTypeFeedbackMinusZeroSentinel !== assertTrue(kExtraTypeFeedbackMinusZeroSentinel !==
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc), %FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex)); kFirstSlotExtraTypeFeedbackIndex));
assertEquals(5.0, builtins.MathFloor_STUB(floorFunc, 4, 5.5)); assertEquals(5.0, stub(floorFunc, 4, 5.5));
assertTrue(kExtraTypeFeedbackMinusZeroSentinel !== assertTrue(kExtraTypeFeedbackMinusZeroSentinel !==
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc), %FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex)); kFirstSlotExtraTypeFeedbackIndex));
// Executing floor such that it returns -0 should set the proper sentinel in // Executing floor such that it returns -0 should set the proper sentinel in
// the feedback vector. // the feedback vector.
assertEquals(-Infinity, 1/builtins.MathFloor_STUB(floorFunc, 4, -0)); assertEquals(-Infinity, 1/stub(floorFunc, 4, -0));
assertEquals(kExtraTypeFeedbackMinusZeroSentinel, assertEquals(kExtraTypeFeedbackMinusZeroSentinel,
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc), %FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex)); kFirstSlotExtraTypeFeedbackIndex));
......
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