Bug 1584758 - Use BytecodeLocation and BytecodeIterator in IonBuilder::analyzeNewLoopTypes. r=mgaudet

Replaced uses of `jsbytecode*` and `pcToOffset` in `IonBuilder::analyzeNewLoopTypes` with bytecode abstraction classes
`BytecodeLocation` and `BytecodeIterator`.

Differential Revision: https://phabricator.services.mozilla.com/D47855

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Adam Holm 2019-10-11 00:43:30 +00:00
parent e5eee2cbe0
commit 71af6eb79b
3 changed files with 39 additions and 23 deletions

View File

@ -22,6 +22,8 @@
#include "jit/Lowering.h"
#include "jit/MIRGraph.h"
#include "vm/ArgumentsObject.h"
#include "vm/BytecodeIterator.h"
#include "vm/BytecodeLocation.h"
#include "vm/BytecodeUtil.h"
#include "vm/EnvironmentObject.h"
#include "vm/Instrumentation.h"
@ -33,6 +35,8 @@
#include "gc/Nursery-inl.h"
#include "jit/CompileInfo-inl.h"
#include "jit/shared/Lowering-shared-inl.h"
#include "vm/BytecodeIterator-inl.h"
#include "vm/BytecodeLocation-inl.h"
#include "vm/BytecodeUtil-inl.h"
#include "vm/EnvironmentObject-inl.h"
#include "vm/JSScript-inl.h"
@ -626,49 +630,54 @@ AbortReasonOr<Ok> IonBuilder::analyzeNewLoopTypes(
}
}
// Get the start and end pc of this loop.
jsbytecode* start = loopEntryBlock->stopPc();
start += GetBytecodeLength(start);
jsbytecode* end = loopEntry->loopStopPc();
// Get the start and end bytecode locations of this loop.
BytecodeLocation start(script_, loopEntryBlock->stopPc());
start = start.next();
BytecodeLocation end(script_, loopEntry->loopStopPc());
// Iterate the bytecode quickly to seed possible types in the loopheader.
jsbytecode* last = nullptr;
jsbytecode* earlier = nullptr;
for (jsbytecode* pc = start; pc != end;
earlier = last, last = pc, pc += GetBytecodeLength(pc)) {
BytecodeLocation last = start;
BytecodeLocation earlier = last;
for (auto it : BytecodeLocationRange(start, end)) {
// Keeping track of previous BytecodeLocation values
earlier = last;
last = it;
uint32_t slot;
if (*pc == JSOP_SETLOCAL) {
slot = info().localSlot(GET_LOCALNO(pc));
} else if (*pc == JSOP_SETARG) {
slot = info().argSlotUnchecked(GET_ARGNO(pc));
if (it.is(JSOP_SETLOCAL)) {
slot = info().localSlot(it.local());
} else if (it.is(JSOP_SETARG)) {
slot = info().argSlotUnchecked(it.arg());
} else {
continue;
}
if (slot >= info().firstStackSlot()) {
continue;
}
if (!last) {
if (!last.isValid(script_)) {
continue;
}
MPhi* phi = entry->getSlot(slot)->toPhi();
if (*last == JSOP_POS || *last == JSOP_TONUMERIC) {
if (last.is(JSOP_POS) || last.is(JSOP_TONUMERIC)) {
last = earlier;
}
if (BytecodeOpHasTypeSet(JSOp(*last))) {
TemporaryTypeSet* typeSet = bytecodeTypes(last);
if (last.opHasTypeSet()) {
TemporaryTypeSet* typeSet = bytecodeTypes(last.toRawBytecode());
if (!typeSet->empty()) {
MIRType type = typeSet->getKnownMIRType();
if (!phi->addBackedgeType(alloc(), type, typeSet)) {
return abort(AbortReason::Alloc);
}
}
} else if (*last == JSOP_GETLOCAL || *last == JSOP_GETARG) {
uint32_t slot = (*last == JSOP_GETLOCAL)
? info().localSlot(GET_LOCALNO(last))
: info().argSlotUnchecked(GET_ARGNO(last));
} else if (last.is(JSOP_GETLOCAL) || last.is(JSOP_GETARG)) {
uint32_t slot = (last.is(JSOP_GETLOCAL))
? info().localSlot(last.local())
: info().argSlotUnchecked(last.arg());
if (slot < info().firstStackSlot()) {
MPhi* otherPhi = entry->getSlot(slot)->toPhi();
if (otherPhi->hasBackedgeType()) {
@ -680,7 +689,7 @@ AbortReasonOr<Ok> IonBuilder::analyzeNewLoopTypes(
}
} else {
MIRType type = MIRType::None;
switch (*last) {
switch (last.getOp()) {
case JSOP_VOID:
case JSOP_UNDEFINED:
type = MIRType::Undefined;
@ -746,7 +755,7 @@ AbortReasonOr<Ok> IonBuilder::analyzeNewLoopTypes(
case JSOP_NEG:
case JSOP_INC:
case JSOP_DEC:
type = inspector->expectedResultType(last);
type = inspector->expectedResultType(last.toRawBytecode());
break;
case JSOP_BIGINT:
type = MIRType::BigInt;

View File

@ -10,6 +10,7 @@
#include "vm/BytecodeIterator.h"
#include "vm/JSScript.h"
namespace js {
inline BytecodeIterator::BytecodeIterator(const JSScript* script)

View File

@ -35,7 +35,6 @@ class BytecodeLocation {
#ifdef DEBUG
const JSScript* debugOnlyScript_;
#endif
// Construct a new BytecodeLocation, while borrowing scriptIdentity
// from some other BytecodeLocation.
BytecodeLocation(const BytecodeLocation& loc, RawBytecode pc)
@ -49,6 +48,9 @@ class BytecodeLocation {
}
public:
// Disallow the creation of an uninitialized location.
BytecodeLocation() = delete;
BytecodeLocation(const JSScript* script, RawBytecode pc)
: rawBytecode_(pc)
#ifdef DEBUG
@ -132,6 +134,10 @@ class BytecodeLocation {
uint32_t icIndex() const { return GET_ICINDEX(rawBytecode_); }
uint32_t local() const { return GET_LOCALNO(rawBytecode_); }
uint16_t arg() const { return GET_ARGNO(rawBytecode_); }
bool isEqualityOp() const { return IsEqualityOp(getOp()); }
bool isStrictEqualityOp() const {