Skip to content

Commit

Permalink
Rename PutOwn bytecode instructions to DefineOwn
Browse files Browse the repository at this point in the history
Summary: Name the store instructions more accurately.

Reviewed By: neildhar

Differential Revision: D67061814

fbshipit-source-id: 94f1c797f7e1a700f22946e1b499fce0e920a08a
  • Loading branch information
fbmal7 authored and facebook-github-bot committed Dec 13, 2024
1 parent 791cc2d commit 696b483
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 78 deletions.
10 changes: 5 additions & 5 deletions include/hermes/BCGen/HBC/BytecodeList.def
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ DEFINE_OPCODE_1(NewObject, Reg8)
DEFINE_OPCODE_2(NewObjectWithParent, Reg8, Reg8)

/// Create an array from a static list of values, as for var=[1,2,3].
/// Any non-constant elements can be set afterwards with PutOwnByIndex.
/// Any non-constant elements can be set afterwards with DefineOwnByIndex.
/// Arg1 is the destination.
/// Arg2 is a preallocation size hint.
/// Arg3 is the number of static elements.
Expand Down Expand Up @@ -411,8 +411,8 @@ ASSERT_MONOTONE_INCREASING(
/// enumerable. This is used (potentially in conjunction with
/// NewArrayWithBuffer) for arr=[foo,bar] initializations.
/// Arg1[Arg3] = Arg2;
DEFINE_OPCODE_3(PutOwnByIndex, Reg8, Reg8, UInt8)
DEFINE_OPCODE_3(PutOwnByIndexL, Reg8, Reg8, UInt32)
DEFINE_OPCODE_3(DefineOwnByIndex, Reg8, Reg8, UInt8)
DEFINE_OPCODE_3(DefineOwnByIndexL, Reg8, Reg8, UInt32)

/// Set an own property identified by value.
/// Arg1 is the destination object.
Expand All @@ -421,7 +421,7 @@ DEFINE_OPCODE_3(PutOwnByIndexL, Reg8, Reg8, UInt32)
/// Arg4 : bool -> enumerable. If true, the property is created as enumerable,
/// non-enumerable otherwise.
/// Arg1[Arg3] = Arg2;
DEFINE_OPCODE_4(PutOwnByVal, Reg8, Reg8, Reg8, UInt8)
DEFINE_OPCODE_4(DefineOwnByVal, Reg8, Reg8, Reg8, UInt8)

/// Get a property by value. Constants string values should instead use GetById.
/// Arg1 = Arg2[Arg3]
Expand Down Expand Up @@ -449,7 +449,7 @@ DEFINE_OPCODE_4(DelByVal, Reg8, Reg8, Reg8, UInt8)
/// Arg3 is the getter closure or undefined
/// Arg4 is the setter closure or undefined
/// Arg5 : boolean - if true, the property will be enumerable.
DEFINE_OPCODE_5(PutOwnGetterSetterByVal, Reg8, Reg8, Reg8, Reg8, UInt8)
DEFINE_OPCODE_5(DefineOwnGetterSetterByVal, Reg8, Reg8, Reg8, Reg8, UInt8)

/// Get the list of properties from an object to implement for..in loop.
/// Returns Arg1, which is the register that holds array of properties.
Expand Down
4 changes: 2 additions & 2 deletions include/hermes/VM/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ class Interpreter {
PinnedHermesValue *frameRegs,
const inst::Inst *ip);

static ExecutionStatus casePutOwnByVal(
static ExecutionStatus caseDefineOwnByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip);

static ExecutionStatus casePutOwnGetterSetterByVal(
static ExecutionStatus caseDefineOwnGetterSetterByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip);
Expand Down
15 changes: 8 additions & 7 deletions lib/BCGen/HBC/ISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,15 @@ void HBCISel::generateDefineOwnPropertyInst(

// If the property is a LiteralNumber, the property is enumerable, and it is a
// valid array index, it is coming from an array initialization and we will
// emit it as PutByIndex.
// emit it as DefineOwnByIndex.
auto *numProp = llvh::dyn_cast<LiteralNumber>(prop);
if (numProp && isEnumerable) {
if (auto arrayIndex = numProp->convertToArrayIndex()) {
uint32_t index = arrayIndex.getValue();
if (index <= UINT8_MAX) {
BCFGen_->emitPutOwnByIndex(objReg, valueReg, index);
BCFGen_->emitDefineOwnByIndex(objReg, valueReg, index);
} else {
BCFGen_->emitPutOwnByIndexL(objReg, valueReg, index);
BCFGen_->emitDefineOwnByIndexL(objReg, valueReg, index);
}

return;
Expand All @@ -928,7 +928,8 @@ void HBCISel::generateDefineOwnPropertyInst(

// It is a register operand.
auto propReg = encodeValue(Inst->getProperty());
BCFGen_->emitPutOwnByVal(objReg, valueReg, propReg, Inst->getIsEnumerable());
BCFGen_->emitDefineOwnByVal(
objReg, valueReg, propReg, Inst->getIsEnumerable());
}

void HBCISel::generateDefineNewOwnPropertyInst(
Expand All @@ -945,9 +946,9 @@ void HBCISel::generateDefineNewOwnPropertyInst(
"No way to generate non-enumerable indexed DefineNewOwnPropertyInst.");
uint32_t index = *numProp->convertToArrayIndex();
if (index <= UINT8_MAX) {
BCFGen_->emitPutOwnByIndex(objReg, valueReg, index);
BCFGen_->emitDefineOwnByIndex(objReg, valueReg, index);
} else {
BCFGen_->emitPutOwnByIndexL(objReg, valueReg, index);
BCFGen_->emitDefineOwnByIndexL(objReg, valueReg, index);
}
return;
}
Expand Down Expand Up @@ -977,7 +978,7 @@ void HBCISel::generateDefineOwnGetterSetterInst(
BasicBlock *next) {
auto objReg = encodeValue(Inst->getObject());
auto ident = encodeValue(Inst->getProperty());
BCFGen_->emitPutOwnGetterSetterByVal(
BCFGen_->emitDefineOwnGetterSetterByVal(
objReg,
ident,
encodeValue(Inst->getStoredGetter()),
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool LoadConstants::operandMustBeLiteral(Instruction *Inst, unsigned opIndex) {

// If the propery is a LiteralNumber, the property is enumerable, and it
// is a valid array index, it is coming from an array initialization and
// we will emit it as PutByIndex.
// we will emit it as DefineOwnByIndex.
if (auto *LN = llvh::dyn_cast<LiteralNumber>(Inst->getOperand(opIndex))) {
if (SOP->getIsEnumerable() && LN->convertToArrayIndex().hasValue())
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/SH/LoadConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool operandMustBeLiteral(Instruction *Inst, unsigned opIndex) {

// If the propery is a LiteralNumber, the property is enumerable, and it
// is a valid array index, it is coming from an array initialization and
// we will emit it as PutByIndex.
// we will emit it as DefineOwnByIndex.
if (auto *LN = llvh::dyn_cast<LiteralNumber>(Inst->getOperand(opIndex))) {
if (SOP->getIsEnumerable() && LN->convertToArrayIndex().hasValue())
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/SH/SH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ class InstrGen {

// If the property is a LiteralNumber, the property is enumerable, and it is
// a valid array index, it is coming from an array initialization and we
// will emit it as PutByIndex.
// will emit it as DefineOwnByIndex.
auto *numProp = llvh::dyn_cast<LiteralNumber>(prop);
if (numProp && isEnumerable) {
if (auto arrayIndex = numProp->convertToArrayIndex()) {
Expand Down
28 changes: 14 additions & 14 deletions lib/VM/Interpreter-slowpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,53 @@ ExecutionStatus Interpreter::caseDirectEval(
return ExecutionStatus::RETURNED;
}

ExecutionStatus Interpreter::casePutOwnByVal(
ExecutionStatus Interpreter::caseDefineOwnByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const Inst *ip) {
return JSObject::defineOwnComputed(
Handle<JSObject>::vmcast(&O1REG(PutOwnByVal)),
Handle<JSObject>::vmcast(&O1REG(DefineOwnByVal)),
runtime,
Handle<>(&O3REG(PutOwnByVal)),
ip->iPutOwnByVal.op4
Handle<>(&O3REG(DefineOwnByVal)),
ip->iDefineOwnByVal.op4
? DefinePropertyFlags::getDefaultNewPropertyFlags()
: DefinePropertyFlags::getNewNonEnumerableFlags(),
Handle<>(&O2REG(PutOwnByVal)),
Handle<>(&O2REG(DefineOwnByVal)),
PropOpFlags().plusThrowOnError())
.getStatus();
}

ExecutionStatus Interpreter::casePutOwnGetterSetterByVal(
ExecutionStatus Interpreter::caseDefineOwnGetterSetterByVal(
Runtime &runtime,
PinnedHermesValue *frameRegs,
const inst::Inst *ip) {
DefinePropertyFlags dpFlags{};
dpFlags.setConfigurable = 1;
dpFlags.configurable = 1;
dpFlags.setEnumerable = 1;
dpFlags.enumerable = ip->iPutOwnGetterSetterByVal.op5;
dpFlags.enumerable = ip->iDefineOwnGetterSetterByVal.op5;

MutableHandle<Callable> getter(runtime);
MutableHandle<Callable> setter(runtime);
if (LLVM_LIKELY(!O3REG(PutOwnGetterSetterByVal).isUndefined())) {
if (LLVM_LIKELY(!O3REG(DefineOwnGetterSetterByVal).isUndefined())) {
dpFlags.setGetter = 1;
getter = vmcast<Callable>(O3REG(PutOwnGetterSetterByVal));
getter = vmcast<Callable>(O3REG(DefineOwnGetterSetterByVal));
}
if (LLVM_LIKELY(!O4REG(PutOwnGetterSetterByVal).isUndefined())) {
if (LLVM_LIKELY(!O4REG(DefineOwnGetterSetterByVal).isUndefined())) {
dpFlags.setSetter = 1;
setter = vmcast<Callable>(O4REG(PutOwnGetterSetterByVal));
setter = vmcast<Callable>(O4REG(DefineOwnGetterSetterByVal));
}
assert(
(dpFlags.setSetter || dpFlags.setGetter) &&
"No accessor set in PutOwnGetterSetterByVal");
"No accessor set in DefineOwnGetterSetterByVal");

auto accessor = runtime.makeHandle<PropertyAccessor>(
PropertyAccessor::create(runtime, getter, setter));

return JSObject::defineOwnComputed(
Handle<JSObject>::vmcast(&O1REG(PutOwnGetterSetterByVal)),
Handle<JSObject>::vmcast(&O1REG(DefineOwnGetterSetterByVal)),
runtime,
Handle<>(&O2REG(PutOwnGetterSetterByVal)),
Handle<>(&O2REG(DefineOwnGetterSetterByVal)),
dpFlags,
accessor)
.getStatus();
Expand Down
24 changes: 12 additions & 12 deletions lib/VM/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2648,23 +2648,23 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH;
}

CASE(PutOwnByIndexL) {
nextIP = NEXTINST(PutOwnByIndexL);
idVal = ip->iPutOwnByIndexL.op3;
goto putOwnByIndex;
CASE(DefineOwnByIndexL) {
nextIP = NEXTINST(DefineOwnByIndexL);
idVal = ip->iDefineOwnByIndexL.op3;
goto DefineOwnByIndex;
}
CASE(PutOwnByIndex) {
nextIP = NEXTINST(PutOwnByIndex);
idVal = ip->iPutOwnByIndex.op3;
CASE(DefineOwnByIndex) {
nextIP = NEXTINST(DefineOwnByIndex);
idVal = ip->iDefineOwnByIndex.op3;
}
putOwnByIndex: {
DefineOwnByIndex: {
tmpHandle = HermesValue::encodeTrustedNumberValue(idVal);
CAPTURE_IP(JSObject::defineOwnComputedPrimitive(
Handle<JSObject>::vmcast(&O1REG(PutOwnByIndex)),
Handle<JSObject>::vmcast(&O1REG(DefineOwnByIndex)),
runtime,
tmpHandle,
DefinePropertyFlags::getDefaultNewPropertyFlags(),
Handle<>(&O2REG(PutOwnByIndex)),
Handle<>(&O2REG(DefineOwnByIndex)),
PropOpFlags().plusThrowOnError()));
gcScope.flushToSmallCount(KEEP_HANDLES);
tmpHandle.clear();
Expand Down Expand Up @@ -3641,8 +3641,8 @@ CallResult<HermesValue> Interpreter::interpretFunction(
DISPATCH;
}

CASE_OUTOFLINE(PutOwnByVal);
CASE_OUTOFLINE(PutOwnGetterSetterByVal);
CASE_OUTOFLINE(DefineOwnByVal);
CASE_OUTOFLINE(DefineOwnGetterSetterByVal);
CASE_OUTOFLINE(DirectEval);

CASE_OUTOFLINE(IteratorBegin);
Expand Down
25 changes: 13 additions & 12 deletions lib/VM/JIT/arm64/JIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,24 +687,25 @@ inline void JITContext::Compiler::emitGetByIndex(
em_.getByIndex(FR(inst->op1), FR(inst->op2), inst->op3);
}

inline void JITContext::Compiler::emitPutOwnByIndex(
const inst::PutOwnByIndexInst *inst) {
em_.putOwnByIndex(FR(inst->op1), FR(inst->op2), inst->op3);
inline void JITContext::Compiler::emitDefineOwnByIndex(
const inst::DefineOwnByIndexInst *inst) {
em_.defineOwnByIndex(FR(inst->op1), FR(inst->op2), inst->op3);
}

inline void JITContext::Compiler::emitPutOwnByIndexL(
const inst::PutOwnByIndexLInst *inst) {
em_.putOwnByIndex(FR(inst->op1), FR(inst->op2), inst->op3);
inline void JITContext::Compiler::emitDefineOwnByIndexL(
const inst::DefineOwnByIndexLInst *inst) {
em_.defineOwnByIndex(FR(inst->op1), FR(inst->op2), inst->op3);
}

inline void JITContext::Compiler::emitPutOwnByVal(
const inst::PutOwnByValInst *inst) {
em_.putOwnByVal(FR(inst->op1), FR(inst->op2), FR(inst->op3), (bool)inst->op4);
inline void JITContext::Compiler::emitDefineOwnByVal(
const inst::DefineOwnByValInst *inst) {
em_.defineOwnByVal(
FR(inst->op1), FR(inst->op2), FR(inst->op3), (bool)inst->op4);
}

inline void JITContext::Compiler::emitPutOwnGetterSetterByVal(
const inst::PutOwnGetterSetterByValInst *inst) {
em_.putOwnGetterSetterByVal(
inline void JITContext::Compiler::emitDefineOwnGetterSetterByVal(
const inst::DefineOwnGetterSetterByValInst *inst) {
em_.defineOwnGetterSetterByVal(
FR(inst->op1),
FR(inst->op2),
FR(inst->op3),
Expand Down
14 changes: 9 additions & 5 deletions lib/VM/JIT/arm64/JitEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3722,7 +3722,7 @@ asmjit::Label Emitter::newPrefLabel(const char *pref, size_t index) {
return a.newNamedLabel(buf);
}

void Emitter::putOwnByIndex(FR frTarget, FR frValue, uint32_t key) {
void Emitter::defineOwnByIndex(FR frTarget, FR frValue, uint32_t key) {
comment(
"// putOwnByIdx r%u, r%u, %u", frTarget.index(), frValue.index(), key);

Expand All @@ -3741,9 +3741,13 @@ void Emitter::putOwnByIndex(FR frTarget, FR frValue, uint32_t key) {
_sh_ljs_put_own_by_index);
}

void Emitter::putOwnByVal(FR frTarget, FR frValue, FR frKey, bool enumerable) {
void Emitter::defineOwnByVal(
FR frTarget,
FR frValue,
FR frKey,
bool enumerable) {
comment(
"// PutOwnByVal r%u, r%u, r%u",
"// DefineOwnByVal r%u, r%u, r%u",
frTarget.index(),
frValue.index(),
frKey.index());
Expand Down Expand Up @@ -3773,14 +3777,14 @@ void Emitter::putOwnByVal(FR frTarget, FR frValue, FR frKey, bool enumerable) {
}
}

void Emitter::putOwnGetterSetterByVal(
void Emitter::defineOwnGetterSetterByVal(
FR frTarget,
FR frKey,
FR frGetter,
FR frSetter,
bool enumerable) {
comment(
"// PutOwnGetterSetterByVal r%u, r%u, r%u, r%u, %d",
"// DefineOwnGetterSetterByVal r%u, r%u, r%u, r%u, %d",
frTarget.index(),
frKey.index(),
frGetter.index(),
Expand Down
6 changes: 3 additions & 3 deletions lib/VM/JIT/arm64/JitEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,9 @@ class Emitter {
"tryPutByIdStrict",
_sh_ljs_try_put_by_id_strict_rjs);

void putOwnByIndex(FR frTarget, FR frValue, uint32_t key);
void putOwnByVal(FR frTarget, FR frValue, FR frKey, bool enumerable);
void putOwnGetterSetterByVal(
void defineOwnByIndex(FR frTarget, FR frValue, uint32_t key);
void defineOwnByVal(FR frTarget, FR frValue, FR frKey, bool enumerable);
void defineOwnGetterSetterByVal(
FR frTarget,
FR frKey,
FR frGetter,
Expand Down
2 changes: 1 addition & 1 deletion lib/VM/StaticH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ extern "C" void _sh_ljs_put_own_getter_setter_by_val(
}
assert(
(dpFlags.setSetter || dpFlags.setGetter) &&
"No accessor set in PutOwnGetterSetterByVal");
"No accessor set in DefineOwnGetterSetterByVal");

auto res =
PropertyAccessor::create(runtime, getterCallable, setterCallable);
Expand Down
6 changes: 3 additions & 3 deletions test/BCGen/HBC/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ var z = [{}];
//CHECK-NEXT: DeclareGlobalVar "z"
//CHECK-NEXT: NewArrayWithBuffer r3, 6, 4, 0
//CHECK-NEXT: LoadConstUndefined r2
//CHECK-NEXT: PutOwnByIndex r3, r2, 4
//CHECK-NEXT: DefineOwnByIndex r3, r2, 4
//CHECK-NEXT: LoadConstNull r1
//CHECK-NEXT: PutOwnByIndex r3, r1, 5
//CHECK-NEXT: DefineOwnByIndex r3, r1, 5
//CHECK-NEXT: GetGlobalObject r5
//CHECK-NEXT: PutByIdLoose r5, r3, 1, "x"
//CHECK-NEXT: NewArrayWithBuffer r3, 5, 3, 11
Expand All @@ -48,6 +48,6 @@ var z = [{}];
//CHECK-NEXT: PutByIdLoose r5, r3, 3, "y"
//CHECK-NEXT: NewArray r3, 1
//CHECK-NEXT: NewObject r4
//CHECK-NEXT: PutOwnByIndex r3, r4, 0
//CHECK-NEXT: DefineOwnByIndex r3, r4, 0
//CHECK-NEXT: PutByIdLoose r5, r3, 4, "z"
//CHECK-NEXT: Ret r2
6 changes: 3 additions & 3 deletions test/BCGen/HBC/gettersetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ var obj = {
// CHECK-NEXT: CreateClosure r4, r1, Function<get b>
// CHECK-NEXT: CreateClosure r3, r1, Function<set b>
// CHECK-NEXT: LoadConstString r2, "b"
// CHECK-NEXT: PutOwnGetterSetterByVal r5, r2, r4, r3, 1
// CHECK-NEXT: DefineOwnGetterSetterByVal r5, r2, r4, r3, 1
// CHECK-NEXT: CreateClosure r3, r1, Function<get c>
// CHECK-NEXT: LoadConstUndefined r0
// CHECK-NEXT: LoadConstString r2, "c"
// CHECK-NEXT: PutOwnGetterSetterByVal r5, r2, r3, r0, 1
// CHECK-NEXT: DefineOwnGetterSetterByVal r5, r2, r3, r0, 1
// CHECK-NEXT: CreateClosure r2, r1, Function<set d>
// CHECK-NEXT: LoadConstString r1, "d"
// CHECK-NEXT: PutOwnGetterSetterByVal r5, r1, r0, r2, 1
// CHECK-NEXT: DefineOwnGetterSetterByVal r5, r1, r0, r2, 1
// CHECK-NEXT: GetGlobalObject r1
// CHECK-NEXT: PutByIdLoose r1, r5, 1, "obj"
// CHECK-NEXT: Ret r0
Expand Down
Loading

0 comments on commit 696b483

Please sign in to comment.