Skip to content

Commit e4587f4

Browse files
committed
Bug 1991402 - Part 19: Make (Specialized)BindFunctionResult shared CacheIR instructions. r=jandem
Inlined GetProp ICs don't have additional arguments we need to load from the stack, so we don't have to load anything from the stub frame. Differential Revision: https://phabricator.services.mozilla.com/D266775
1 parent 02d5755 commit e4587f4

File tree

5 files changed

+93
-93
lines changed

5 files changed

+93
-93
lines changed

js/src/jit-test/tests/cacheir/inlinable-native-accessor-6.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ function testArrayJoin() {
6666
}
6767
}
6868
testArrayJoin();
69+
70+
function testFunctionBind() {
71+
Object.defineProperty(Function.prototype, "bound", {get: Function.prototype.bind});
72+
73+
for (var i = 0; i < 100; ++i) {
74+
// |SpecializedBindFunctionResult| CacheIROp.
75+
assertEq(function(){ return i; }.bound(), i);
76+
77+
// |BindFunctionResult| CacheIROp.
78+
var r = Math.random.bound();
79+
assertEq(0 <= r && r < 1, true);
80+
}
81+
}
82+
testFunctionBind();

js/src/jit/BaselineCacheIRCompiler.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,86 +4093,6 @@ bool BaselineCacheIRCompiler::emitNewFunctionCloneResult(
40934093
return true;
40944094
}
40954095

4096-
bool BaselineCacheIRCompiler::emitBindFunctionResult(
4097-
ObjOperandId targetId, uint32_t argc, uint32_t templateObjectOffset) {
4098-
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
4099-
4100-
AutoOutputRegister output(*this);
4101-
AutoScratchRegister scratch(allocator, masm);
4102-
4103-
Register target = allocator.useRegister(masm, targetId);
4104-
4105-
allocator.discardStack(masm);
4106-
4107-
AutoStubFrame stubFrame(*this);
4108-
stubFrame.enter(masm, scratch);
4109-
4110-
// Push the arguments in reverse order.
4111-
for (uint32_t i = 0; i < argc; i++) {
4112-
Address argAddress(FramePointer,
4113-
BaselineStubFrameLayout::Size() + i * sizeof(Value));
4114-
masm.pushValue(argAddress);
4115-
}
4116-
masm.moveStackPtrTo(scratch.get());
4117-
4118-
masm.Push(ImmWord(0)); // nullptr for maybeBound
4119-
masm.Push(Imm32(argc));
4120-
masm.Push(scratch);
4121-
masm.Push(target);
4122-
4123-
using Fn = BoundFunctionObject* (*)(JSContext*, Handle<JSObject*>, Value*,
4124-
uint32_t, Handle<BoundFunctionObject*>);
4125-
callVM<Fn, BoundFunctionObject::functionBindImpl>(masm);
4126-
4127-
stubFrame.leave(masm);
4128-
masm.storeCallPointerResult(scratch);
4129-
4130-
masm.tagValue(JSVAL_TYPE_OBJECT, scratch, output.valueReg());
4131-
return true;
4132-
}
4133-
4134-
bool BaselineCacheIRCompiler::emitSpecializedBindFunctionResult(
4135-
ObjOperandId targetId, uint32_t argc, uint32_t templateObjectOffset) {
4136-
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
4137-
4138-
AutoOutputRegister output(*this);
4139-
AutoScratchRegisterMaybeOutput scratch1(allocator, masm);
4140-
AutoScratchRegister scratch2(allocator, masm);
4141-
4142-
Register target = allocator.useRegister(masm, targetId);
4143-
4144-
StubFieldOffset objectField(templateObjectOffset, StubField::Type::JSObject);
4145-
emitLoadStubField(objectField, scratch2);
4146-
4147-
allocator.discardStack(masm);
4148-
4149-
AutoStubFrame stubFrame(*this);
4150-
stubFrame.enter(masm, scratch1);
4151-
4152-
// Push the arguments in reverse order.
4153-
for (uint32_t i = 0; i < argc; i++) {
4154-
Address argAddress(FramePointer,
4155-
BaselineStubFrameLayout::Size() + i * sizeof(Value));
4156-
masm.pushValue(argAddress);
4157-
}
4158-
masm.moveStackPtrTo(scratch1.get());
4159-
4160-
masm.Push(scratch2);
4161-
masm.Push(Imm32(argc));
4162-
masm.Push(scratch1);
4163-
masm.Push(target);
4164-
4165-
using Fn = BoundFunctionObject* (*)(JSContext*, Handle<JSObject*>, Value*,
4166-
uint32_t, Handle<BoundFunctionObject*>);
4167-
callVM<Fn, BoundFunctionObject::functionBindSpecializedBaseline>(masm);
4168-
4169-
stubFrame.leave(masm);
4170-
masm.storeCallPointerResult(scratch1);
4171-
4172-
masm.tagValue(JSVAL_TYPE_OBJECT, scratch1, output.valueReg());
4173-
return true;
4174-
}
4175-
41764096
bool BaselineCacheIRCompiler::emitCloseIterScriptedResult(
41774097
ObjOperandId iterId, ObjOperandId calleeId, CompletionKind kind,
41784098
uint32_t calleeNargs) {

js/src/jit/CacheIRCompiler.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4548,6 +4548,79 @@ bool CacheIRCompiler::emitLoadFunctionNameResult(ObjOperandId objId) {
45484548
return true;
45494549
}
45504550

4551+
bool CacheIRCompiler::emitBindFunctionResult(ObjOperandId targetId,
4552+
uint32_t argc,
4553+
uint32_t templateObjectOffset) {
4554+
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
4555+
4556+
AutoCallVM callvm(masm, this, allocator);
4557+
AutoScratchRegisterMaybeOutput scratch(allocator, masm, callvm.output());
4558+
4559+
Register target = allocator.useRegister(masm, targetId);
4560+
4561+
callvm.prepare();
4562+
4563+
if (isBaseline()) {
4564+
// Push the arguments in reverse order.
4565+
for (uint32_t i = 0; i < argc; i++) {
4566+
Address argAddress(FramePointer,
4567+
BaselineStubFrameLayout::Size() + i * sizeof(Value));
4568+
masm.pushValue(argAddress);
4569+
}
4570+
} else {
4571+
MOZ_ASSERT(argc == 0, "Call ICs not used in ion");
4572+
}
4573+
masm.moveStackPtrTo(scratch.get());
4574+
4575+
masm.Push(ImmWord(0)); // nullptr for maybeBound
4576+
masm.Push(Imm32(argc));
4577+
masm.Push(scratch);
4578+
masm.Push(target);
4579+
4580+
using Fn = BoundFunctionObject* (*)(JSContext*, Handle<JSObject*>, Value*,
4581+
uint32_t, Handle<BoundFunctionObject*>);
4582+
callvm.call<Fn, BoundFunctionObject::functionBindImpl>();
4583+
return true;
4584+
}
4585+
4586+
bool CacheIRCompiler::emitSpecializedBindFunctionResult(
4587+
ObjOperandId targetId, uint32_t argc, uint32_t templateObjectOffset) {
4588+
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
4589+
4590+
AutoCallVM callvm(masm, this, allocator);
4591+
AutoScratchRegisterMaybeOutput scratch1(allocator, masm, callvm.output());
4592+
AutoScratchRegister scratch2(allocator, masm);
4593+
4594+
Register target = allocator.useRegister(masm, targetId);
4595+
4596+
StubFieldOffset objectField(templateObjectOffset, StubField::Type::JSObject);
4597+
emitLoadStubField(objectField, scratch2);
4598+
4599+
callvm.prepare();
4600+
4601+
if (isBaseline()) {
4602+
// Push the arguments in reverse order.
4603+
for (uint32_t i = 0; i < argc; i++) {
4604+
Address argAddress(FramePointer,
4605+
BaselineStubFrameLayout::Size() + i * sizeof(Value));
4606+
masm.pushValue(argAddress);
4607+
}
4608+
} else {
4609+
MOZ_ASSERT(argc == 0, "Call ICs not used in ion");
4610+
}
4611+
masm.moveStackPtrTo(scratch1.get());
4612+
4613+
masm.Push(scratch2);
4614+
masm.Push(Imm32(argc));
4615+
masm.Push(scratch1);
4616+
masm.Push(target);
4617+
4618+
using Fn = BoundFunctionObject* (*)(JSContext*, Handle<JSObject*>, Value*,
4619+
uint32_t, Handle<BoundFunctionObject*>);
4620+
callvm.call<Fn, BoundFunctionObject::functionBindSpecializedBaseline>();
4621+
return true;
4622+
}
4623+
45514624
bool CacheIRCompiler::emitLinearizeForCharAccess(StringOperandId strId,
45524625
Int32OperandId indexId,
45534626
StringOperandId resultId) {
@@ -12027,6 +12100,10 @@ template <>
1202712100
struct ReturnTypeToJSValueType<SetObject*> {
1202812101
static constexpr JSValueType result = JSVAL_TYPE_OBJECT;
1202912102
};
12103+
template <>
12104+
struct ReturnTypeToJSValueType<BoundFunctionObject*> {
12105+
static constexpr JSValueType result = JSVAL_TYPE_OBJECT;
12106+
};
1203012107

1203112108
template <typename Fn>
1203212109
void AutoCallVM::storeResult() {

js/src/jit/CacheIROps.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@
22542254
thisShape: ShapeField
22552255

22562256
- name: BindFunctionResult
2257-
shared: false
2257+
shared: true
22582258
transpile: true
22592259
cost_estimate: 5
22602260
args:
@@ -2263,7 +2263,7 @@
22632263
templateObject: ObjectField
22642264

22652265
- name: SpecializedBindFunctionResult
2266-
shared: false
2266+
shared: true
22672267
transpile: true
22682268
cost_estimate: 4
22692269
args:

js/src/jit/IonCacheIRCompiler.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,17 +2308,6 @@ bool IonCacheIRCompiler::emitCallInlinedFunction(ObjOperandId calleeId,
23082308
MOZ_CRASH("Call ICs not used in ion");
23092309
}
23102310

2311-
bool IonCacheIRCompiler::emitBindFunctionResult(ObjOperandId targetId,
2312-
uint32_t argc,
2313-
uint32_t templateObjectOffset) {
2314-
MOZ_CRASH("Call ICs not used in ion");
2315-
}
2316-
2317-
bool IonCacheIRCompiler::emitSpecializedBindFunctionResult(
2318-
ObjOperandId targetId, uint32_t argc, uint32_t templateObjectOffset) {
2319-
MOZ_CRASH("Call ICs not used in ion");
2320-
}
2321-
23222311
bool IonCacheIRCompiler::emitLoadArgumentFixedSlot(ValOperandId resultId,
23232312
uint8_t slotIndex) {
23242313
MOZ_CRASH("Call ICs not used in ion");

0 commit comments

Comments
 (0)