Skip to content

Commit 86d784c

Browse files
committed
Bug 1991402 - Part 17: Make {PackedArray,Arguments}SliceResult shared CacheIR instructions. r=jandem
Use `AutoCallVM` to implement both instructions in `CacheIRCompiler`. `AutoCallVM` can't be used together with `FailurePath`, so we have to move the packed array guard into a separate instruction. Differential Revision: https://phabricator.services.mozilla.com/D266773
1 parent 5109899 commit 86d784c

File tree

6 files changed

+77
-94
lines changed

6 files changed

+77
-94
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,21 @@ function testStringAt() {
3838
}
3939
}
4040
testStringAt();
41+
42+
function testArraySlice() {
43+
Object.defineProperty(Array.prototype, "sliced", {get: Array.prototype.slice});
44+
45+
for (var i = 0; i < 100; ++i) {
46+
assertEq([1, 2].sliced.length, 2);
47+
}
48+
}
49+
testArraySlice();
50+
51+
function testArraySliceArguments() {
52+
Object.defineProperty(arguments, "sliced", {get: Array.prototype.slice});
53+
54+
for (var i = 0; i < 100; ++i) {
55+
assertEq(arguments.sliced.length, 0);
56+
}
57+
}
58+
testArraySliceArguments();

js/src/jit/BaselineCacheIRCompiler.cpp

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,85 +1107,6 @@ bool BaselineCacheIRCompiler::emitArrayJoinResult(ObjOperandId objId,
11071107
return true;
11081108
}
11091109

1110-
bool BaselineCacheIRCompiler::emitPackedArraySliceResult(
1111-
uint32_t templateObjectOffset, ObjOperandId arrayId, Int32OperandId beginId,
1112-
Int32OperandId endId) {
1113-
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
1114-
1115-
AutoOutputRegister output(*this);
1116-
AutoScratchRegisterMaybeOutput scratch1(allocator, masm, output);
1117-
AutoScratchRegisterMaybeOutputType scratch2(allocator, masm, output);
1118-
1119-
Register array = allocator.useRegister(masm, arrayId);
1120-
Register begin = allocator.useRegister(masm, beginId);
1121-
Register end = allocator.useRegister(masm, endId);
1122-
1123-
FailurePath* failure;
1124-
if (!addFailurePath(&failure)) {
1125-
return false;
1126-
}
1127-
1128-
masm.branchArrayIsNotPacked(array, scratch1, scratch2, failure->label());
1129-
1130-
allocator.discardStack(masm);
1131-
1132-
AutoStubFrame stubFrame(*this);
1133-
stubFrame.enter(masm, scratch1);
1134-
1135-
// Don't attempt to pre-allocate the object, instead always use the slow
1136-
// path.
1137-
ImmPtr result(nullptr);
1138-
1139-
masm.Push(result);
1140-
masm.Push(end);
1141-
masm.Push(begin);
1142-
masm.Push(array);
1143-
1144-
using Fn =
1145-
JSObject* (*)(JSContext*, HandleObject, int32_t, int32_t, HandleObject);
1146-
callVM<Fn, ArraySliceDense>(masm);
1147-
1148-
stubFrame.leave(masm);
1149-
1150-
masm.tagValue(JSVAL_TYPE_OBJECT, ReturnReg, output.valueReg());
1151-
return true;
1152-
}
1153-
1154-
bool BaselineCacheIRCompiler::emitArgumentsSliceResult(
1155-
uint32_t templateObjectOffset, ObjOperandId argsId, Int32OperandId beginId,
1156-
Int32OperandId endId) {
1157-
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
1158-
1159-
AutoOutputRegister output(*this);
1160-
AutoScratchRegisterMaybeOutput scratch(allocator, masm, output);
1161-
1162-
Register args = allocator.useRegister(masm, argsId);
1163-
Register begin = allocator.useRegister(masm, beginId);
1164-
Register end = allocator.useRegister(masm, endId);
1165-
1166-
allocator.discardStack(masm);
1167-
1168-
AutoStubFrame stubFrame(*this);
1169-
stubFrame.enter(masm, scratch);
1170-
1171-
// Don't attempt to pre-allocate the object, instead always use the slow path.
1172-
ImmPtr result(nullptr);
1173-
1174-
masm.Push(result);
1175-
masm.Push(end);
1176-
masm.Push(begin);
1177-
masm.Push(args);
1178-
1179-
using Fn =
1180-
JSObject* (*)(JSContext*, HandleObject, int32_t, int32_t, HandleObject);
1181-
callVM<Fn, ArgumentsSliceDense>(masm);
1182-
1183-
stubFrame.leave(masm);
1184-
1185-
masm.tagValue(JSVAL_TYPE_OBJECT, ReturnReg, output.valueReg());
1186-
return true;
1187-
}
1188-
11891110
bool BaselineCacheIRCompiler::emitIsArrayResult(ValOperandId inputId) {
11901111
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
11911112

js/src/jit/CacheIR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,6 +6804,7 @@ AttachDecision InlinableNativeIRGenerator::tryAttachArraySlice() {
68046804
if (isPackedArray) {
68056805
emitOptimisticClassGuard(objId, &thisval_.toObject(),
68066806
GuardClassKind::Array);
6807+
writer.guardArrayIsPacked(objId);
68076808
} else {
68086809
auto* args = &thisval_.toObject().as<ArgumentsObject>();
68096810

js/src/jit/CacheIRCompiler.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7334,6 +7334,62 @@ bool CacheIRCompiler::emitArrayPush(ObjOperandId objId, ValOperandId rhsId) {
73347334
return true;
73357335
}
73367336

7337+
bool CacheIRCompiler::emitPackedArraySliceResult(uint32_t templateObjectOffset,
7338+
ObjOperandId arrayId,
7339+
Int32OperandId beginId,
7340+
Int32OperandId endId) {
7341+
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
7342+
7343+
AutoCallVM callvm(masm, this, allocator);
7344+
7345+
Register array = allocator.useRegister(masm, arrayId);
7346+
Register begin = allocator.useRegister(masm, beginId);
7347+
Register end = allocator.useRegister(masm, endId);
7348+
7349+
callvm.prepare();
7350+
7351+
// Don't attempt to pre-allocate the object, instead always use the slow path.
7352+
ImmPtr result(nullptr);
7353+
7354+
masm.Push(result);
7355+
masm.Push(end);
7356+
masm.Push(begin);
7357+
masm.Push(array);
7358+
7359+
using Fn =
7360+
JSObject* (*)(JSContext*, HandleObject, int32_t, int32_t, HandleObject);
7361+
callvm.call<Fn, ArraySliceDense>();
7362+
return true;
7363+
}
7364+
7365+
bool CacheIRCompiler::emitArgumentsSliceResult(uint32_t templateObjectOffset,
7366+
ObjOperandId argsId,
7367+
Int32OperandId beginId,
7368+
Int32OperandId endId) {
7369+
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
7370+
7371+
AutoCallVM callvm(masm, this, allocator);
7372+
7373+
Register args = allocator.useRegister(masm, argsId);
7374+
Register begin = allocator.useRegister(masm, beginId);
7375+
Register end = allocator.useRegister(masm, endId);
7376+
7377+
callvm.prepare();
7378+
7379+
// Don't attempt to pre-allocate the object, instead always use the slow path.
7380+
ImmPtr result(nullptr);
7381+
7382+
masm.Push(result);
7383+
masm.Push(end);
7384+
masm.Push(begin);
7385+
masm.Push(args);
7386+
7387+
using Fn =
7388+
JSObject* (*)(JSContext*, HandleObject, int32_t, int32_t, HandleObject);
7389+
callvm.call<Fn, ArgumentsSliceDense>();
7390+
return true;
7391+
}
7392+
73377393
bool CacheIRCompiler::emitStoreTypedArrayElement(ObjOperandId objId,
73387394
Scalar::Type elementType,
73397395
IntPtrOperandId indexId,

js/src/jit/CacheIROps.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@
12041204
array: ObjId
12051205

12061206
- name: PackedArraySliceResult
1207-
shared: false
1207+
shared: true
12081208
transpile: true
12091209
cost_estimate: 5
12101210
args:
@@ -1214,7 +1214,7 @@
12141214
end: Int32Id
12151215

12161216
- name: ArgumentsSliceResult
1217-
shared: false
1217+
shared: true
12181218
transpile: true
12191219
cost_estimate: 5
12201220
args:

js/src/jit/IonCacheIRCompiler.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,19 +2335,6 @@ bool IonCacheIRCompiler::emitArrayJoinResult(ObjOperandId objId,
23352335
MOZ_CRASH("Call ICs not used in ion");
23362336
}
23372337

2338-
bool IonCacheIRCompiler::emitPackedArraySliceResult(
2339-
uint32_t templateObjectOffset, ObjOperandId arrayId, Int32OperandId beginId,
2340-
Int32OperandId endId) {
2341-
MOZ_CRASH("Call ICs not used in ion");
2342-
}
2343-
2344-
bool IonCacheIRCompiler::emitArgumentsSliceResult(uint32_t templateObjectOffset,
2345-
ObjOperandId argsId,
2346-
Int32OperandId beginId,
2347-
Int32OperandId endId) {
2348-
MOZ_CRASH("Call ICs not used in ion");
2349-
}
2350-
23512338
bool IonCacheIRCompiler::emitIsArrayResult(ValOperandId inputId) {
23522339
MOZ_CRASH("Call ICs not used in ion");
23532340
}

0 commit comments

Comments
 (0)