Skip to content

Commit

Permalink
Merge pull request mozilla#31 from bytecodealliance/pbl-predict-return
Browse files Browse the repository at this point in the history
pbl: Specialize PREDICT_NEXT for ReturnFromIC
  • Loading branch information
cfallin authored Oct 6, 2023
2 parents 5317de5 + 602295f commit 951c9e7
Showing 1 changed file with 44 additions and 30 deletions.
74 changes: 44 additions & 30 deletions js/src/vm/PortableBaselineInterpret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
goto cacheop_##name; \
}

#define PREDICT_RETURN() \
if (icregs.cacheIRReader.peekOp() == CacheOp::ReturnFromIC) { \
TRACE_PRINTF("stub successful, predicted return\n"); \
return ICInterpretOpResult::Return; \
}

CacheOp cacheop;

DISPATCH_CACHEOP();
Expand Down Expand Up @@ -790,6 +796,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
JSClass* clasp = reinterpret_cast<JSClass*>(
cstub->stubInfo()->getStubRawWord(cstub, claspOffset));
icregs.icResult = BooleanValue(obj->getClass() == clasp).asRawBits();
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1210,7 +1217,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
reinterpret_cast<uintptr_t>(nobj) + offset);
Value val = Value::fromRawBits(icregs.icVals[rhsId.id()]);
slot->set(val);
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1226,7 +1233,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
size_t dynSlot = offset / sizeof(Value);
size_t slot = dynSlot + nobj->numFixedSlots();
slots[dynSlot].set(nobj, HeapSlot::Slot, slot, val);
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1244,6 +1251,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
GCPtr<Value>* slot = reinterpret_cast<GCPtr<Value>*>(
reinterpret_cast<uintptr_t>(obj) + offset);
slot->init(rhs);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1263,6 +1271,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
size_t dynSlot = offset / sizeof(Value);
size_t slot = dynSlot + nobj->numFixedSlots();
slots[dynSlot].init(nobj, HeapSlot::Slot, slot, rhs);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1290,6 +1299,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
size_t dynSlot = offset / sizeof(Value);
size_t slot = dynSlot + nobj->numFixedSlots();
slots[dynSlot].init(nobj, HeapSlot::Slot, slot, rhs);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1311,7 +1321,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
Value val = Value::fromRawBits(icregs.icVals[rhsId.id()]);
slot->set(nobj, HeapSlot::Element, index + elems->numShiftedElements(),
val);
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1353,6 +1363,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,

nobj->initDenseElement(index, rhs);
}
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1376,14 +1387,15 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
aobj->setLength(initLength + 1);
aobj->initDenseElement(initLength, rhs);
icregs.icResult = Int32Value(initLength + 1).asRawBits();
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(IsObjectResult) {
ValOperandId inputId = icregs.cacheIRReader.valOperandId();
Value val = Value::fromRawBits(icregs.icVals[inputId.id()]);
icregs.icResult = BooleanValue(val.isObject()).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1534,6 +1546,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
}
}

PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1550,7 +1563,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
"slot %" PRIx64 "\n",
nobj, int(offsetOffset), int(offset), slot, slot->asRawBits());
icregs.icResult = slot->asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1562,7 +1575,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
reinterpret_cast<NativeObject*>(icregs.icVals[objId.id()]);
HeapSlot* slots = nobj->getSlotsUnchecked();
icregs.icResult = slots[offset / sizeof(Value)].get().asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1582,7 +1595,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC;
}
icregs.icResult = val.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1596,7 +1609,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC;
}
icregs.icResult = Int32Value(length).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1671,7 +1684,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
}
}
icregs.icResult = StringValue(result).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -1699,7 +1712,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
result = Int32Value(c);
}
icregs.icResult = result.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1711,7 +1724,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC;
}
icregs.icResult = Int32Value(length).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1720,7 +1733,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
icregs.icResult =
ObjectValue(*reinterpret_cast<JSObject*>(icregs.icVals[objId.id()]))
.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1729,6 +1742,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
icregs.icResult =
StringValue(reinterpret_cast<JSString*>(icregs.icVals[strId.id()]))
.asRawBits();
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1737,14 +1751,14 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
icregs.icResult =
SymbolValue(reinterpret_cast<JS::Symbol*>(icregs.icVals[symId.id()]))
.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(LoadInt32Result) {
Int32OperandId valId = icregs.cacheIRReader.int32OperandId();
icregs.icResult = Int32Value(icregs.icVals[valId.id()]).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1755,7 +1769,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
val = DoubleValue(val.toInt32());
}
icregs.icResult = val.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1764,14 +1778,14 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
icregs.icResult =
BigIntValue(reinterpret_cast<JS::BigInt*>(icregs.icVals[valId.id()]))
.asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(LoadBooleanResult) {
bool val = icregs.cacheIRReader.readBool();
icregs.icResult = BooleanValue(val).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1789,7 +1803,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
JSString* str = reinterpret_cast<JSString*>(
cstub->stubInfo()->getStubRawWord(cstub, strOffset));
icregs.icResult = StringValue(str).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1805,7 +1819,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC; \
} \
icregs.icResult = Int32Value(int32_t(result)).asRawBits(); \
PREDICT_NEXT(ReturnFromIC); \
PREDICT_RETURN(); \
DISPATCH_CACHEOP(); \
}

Expand Down Expand Up @@ -1872,7 +1886,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
}

icregs.icResult = Int32Value(int32_t(result)).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1884,15 +1898,15 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC;
}
icregs.icResult = Int32Value(int32_t(value)).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(LoadInt32TruthyResult) {
ValOperandId inputId = icregs.cacheIRReader.valOperandId();
int32_t val = int32_t(icregs.icVals[inputId.id()]);
icregs.icResult = BooleanValue(val != 0).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1901,7 +1915,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
JSString* str =
reinterpret_cast<JSLinearString*>(icregs.icVals[strId.id()]);
icregs.icResult = BooleanValue(str->length() > 0).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1913,21 +1927,21 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
return ICInterpretOpResult::NextIC;
}
icregs.icResult = BooleanValue(!cls->emulatesUndefined()).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(LoadValueResult) {
uint32_t valOffset = icregs.cacheIRReader.stubOffset();
icregs.icResult = cstub->stubInfo()->getStubRawInt64(cstub, valOffset);
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

CACHEOP_CASE(LoadOperandResult) {
ValOperandId inputId = icregs.cacheIRReader.valOperandId();
icregs.icResult = icregs.icVals[inputId.id()];
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand All @@ -1947,7 +1961,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
} else {
return ICInterpretOpResult::NextIC;
}
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -2004,7 +2018,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
}
icregs.icResult = BooleanValue(result).asRawBits();
}
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -2042,7 +2056,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
MOZ_CRASH("Unexpected opcode");
}
icregs.icResult = BooleanValue(result).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down Expand Up @@ -2077,7 +2091,7 @@ ICInterpretOps(BaselineFrame* frame, VMFrameManager& frameMgr, State& state,
MOZ_CRASH("bad opcode");
}
icregs.icResult = BooleanValue(result).asRawBits();
PREDICT_NEXT(ReturnFromIC);
PREDICT_RETURN();
DISPATCH_CACHEOP();
}

Expand Down

0 comments on commit 951c9e7

Please sign in to comment.