Skip to content

Commit

Permalink
Bug 1641708 - Support IsCallable in CacheIR r=jandem
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed May 29, 2020
1 parent 4d2666f commit 834a3ba
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
29 changes: 28 additions & 1 deletion js/src/jit/CacheIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5009,7 +5009,7 @@ AttachDecision CallIRGenerator::tryAttachArrayIsArray(HandleFunction callee) {
// Initialize the input operand.
Int32OperandId argcId(writer.setInputOperandId(0));

// Guard callee is the 'isArray' intrinsic native function.
// Guard callee is the 'isArray' native function.
emitNativeCalleeGuard(callee);

// Check if the argument is an Array and return result.
Expand Down Expand Up @@ -5170,6 +5170,31 @@ AttachDecision CallIRGenerator::tryAttachIsObject(HandleFunction callee) {
return AttachDecision::Attach;
}

AttachDecision CallIRGenerator::tryAttachIsCallable(HandleFunction callee) {
// Need a single argument.
if (argc_ != 1) {
return AttachDecision::NoAction;
}

// Initialize the input operand.
Int32OperandId argcId(writer.setInputOperandId(0));

// Guard callee is the 'IsCallable' intrinsic native function.
emitNativeCalleeGuard(callee);

// Check if the argument is callable and return result.
ValOperandId argId = writer.loadArgumentFixedSlot(ArgumentKind::Arg0, argc_);
writer.isCallableResult(argId);

// This stub does not need to be monitored, because it always
// returns a boolean.
writer.returnFromIC();
cacheIRStubKind_ = BaselineCacheIRStubKind::Regular;

trackAttached("IsCallable");
return AttachDecision::Attach;
}

AttachDecision CallIRGenerator::tryAttachStringChar(HandleFunction callee,
StringChar kind) {
// Need one argument.
Expand Down Expand Up @@ -5608,6 +5633,8 @@ AttachDecision CallIRGenerator::tryAttachInlinableNative(
return tryAttachToInteger(callee);
case InlinableNative::IntrinsicIsObject:
return tryAttachIsObject(callee);
case InlinableNative::IntrinsicIsCallable:
return tryAttachIsCallable(callee);

// String natives.
case InlinableNative::StringCharCodeAt:
Expand Down
1 change: 1 addition & 0 deletions js/src/jit/CacheIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ class MOZ_RAII CallIRGenerator : public IRGenerator {
AttachDecision tryAttachToObject(HandleFunction callee);
AttachDecision tryAttachToInteger(HandleFunction callee);
AttachDecision tryAttachIsObject(HandleFunction callee);
AttachDecision tryAttachIsCallable(HandleFunction callee);
AttachDecision tryAttachStringChar(HandleFunction callee, StringChar kind);
AttachDecision tryAttachStringCharCodeAt(HandleFunction callee);
AttachDecision tryAttachStringCharAt(HandleFunction callee);
Expand Down
43 changes: 43 additions & 0 deletions js/src/jit/CacheIRCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3708,6 +3708,49 @@ bool CacheIRCompiler::emitIsObjectResult(ValOperandId inputId) {
return true;
}

bool CacheIRCompiler::emitIsCallableResult(ValOperandId inputId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);

AutoOutputRegister output(*this);
AutoScratchRegister scratch1(allocator, masm);
AutoScratchRegisterMaybeOutput scratch2(allocator, masm, output);

ValueOperand val = allocator.useValueRegister(masm, inputId);

Label isObject, done;
masm.branchTestObject(Assembler::Equal, val, &isObject);
// Primitives are never callable.
masm.move32(Imm32(0), scratch2);
masm.jump(&done);

masm.bind(&isObject);
masm.unboxObject(val, scratch1);

Label isProxy;
masm.isCallable(scratch1, scratch2, &isProxy);
masm.jump(&done);

masm.bind(&isProxy);
{
LiveRegisterSet volatileRegs(GeneralRegisterSet::Volatile(),
liveVolatileFloatRegs());
masm.PushRegsInMask(volatileRegs);

masm.setupUnalignedABICall(scratch2);
masm.passABIArg(scratch1);
masm.callWithABI(JS_FUNC_TO_DATA_PTR(void*, ObjectIsCallable));
masm.storeCallBoolResult(scratch2);

LiveRegisterSet ignore;
ignore.add(scratch2);
masm.PopRegsInMaskIgnore(volatileRegs, ignore);
}

masm.bind(&done);
EmitStoreResult(masm, scratch2, JSVAL_TYPE_BOOLEAN, output);
return true;
}

bool CacheIRCompiler::emitMathAbsInt32Result(Int32OperandId inputId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);

Expand Down
6 changes: 6 additions & 0 deletions js/src/jit/CacheIROps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@
args:
input: ValId

- name: IsCallableResult
shared: true
transpile: false
args:
input: ValId

- name: MathAbsInt32Result
shared: true
transpile: true
Expand Down

0 comments on commit 834a3ba

Please sign in to comment.