Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Guard ops for fixed and dynamic slot values #30

Open
wants to merge 2 commits into
base: memory-model
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 108 additions & 12 deletions notes/cacheir.cachet
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ enum OperandLocationKind {
Uninitialized,
PayloadReg,
ValueReg,
Constant,
}

struct OperandLocation;

impl OperandLocation {
fn kind(loc: OperandLocation) -> OperandLocationKind;
fn kind(loc: OperandLocation) -> OperandLocationKind;

fn newUninitialized() -> OperandLocation {
let loc = (unsafe { OperandLocation::newUninitializedUnchecked() });
Expand All @@ -22,7 +23,7 @@ impl OperandLocation {
unsafe fn newUninitializedUnchecked() -> OperandLocation;

fn setValueReg(out loc: OperandLocation, valueReg: ValueReg) {
(unsafe { OperandLocation::setValueRegUnchecked(out loc, valueReg) });
(unsafe { OperandLocation::setValueRegUnchecked(out loc, valueReg) });
assume OperandLocation::kind(loc) == OperandLocationKind::ValueReg;
assume (unsafe { OperandLocation::getValueRegUnchecked(loc) } ) == valueReg;
}
Expand All @@ -37,8 +38,16 @@ impl OperandLocation {

unsafe fn getValueRegUnchecked(loc: OperandLocation) -> ValueReg;

fn getConstant(loc: OperandLocation) -> Value {
assert OperandLocation::kind(loc) == OperandLocationKind::Constant;
let val = (unsafe { OperandLocation::getConstantUnchecked(loc) });
val
}

unsafe fn getConstantUnchecked(loc: OperandLocation) -> Value;

fn setPayloadReg(out loc: OperandLocation, reg: Reg, type: ValueType) {
(unsafe { OperandLocation::setPayloadRegUnchecked(out loc, reg, type) });
(unsafe { OperandLocation::setPayloadRegUnchecked(out loc, reg, type) });
assume OperandLocation::kind(loc) == OperandLocationKind::PayloadReg;
assume (unsafe { OperandLocation::getPayloadRegUnchecked(loc) } ) == reg;
assume (unsafe { OperandLocation::getPayloadTypeUnchecked(loc) } ) == type;
Expand All @@ -65,6 +74,7 @@ impl OperandLocation {

struct OperandId;

// Corresponds to a ValOperandId
struct ValueId <: OperandId;

impl ValueId {
Expand Down Expand Up @@ -105,13 +115,13 @@ impl TypedId {
typedId
}

unsafe fn fromValueIdUnchecked(valueId: ValueId, type: ValueType) -> TypedId;
unsafe fn fromValueIdUnchecked(valueId: ValueId, type: ValueType) -> TypedId;

fn toValueId(typedId: TypedId) -> ValueId {
assert TypedId::isValueId(typedId);
let type = TypedId::type(typedId);
let valueId = (unsafe { TypedId::toValueIdUnchecked(typedId) });
assume (unsafe { TypedId::fromValueIdUnchecked(valueId, type) }) == typedId;
assume (unsafe { TypedId::fromValueIdUnchecked(valueId, type) }) == typedId;
valueId
}

Expand Down Expand Up @@ -355,7 +365,7 @@ ir CacheIR emits MASM {
op GuardClass(objId: ObjectId, kind: GuardClassKind) {
let objReg = CacheIR::useObjectReg(objId);
let scratchReg = CacheIR::allocateReg();

CacheIR::addFailurePath(out label failure);

if kind == GuardClassKind::JSFunction {
Expand Down Expand Up @@ -467,6 +477,53 @@ ir CacheIR emits MASM {
CacheIR::releaseReg(scratchReg);
}

op GuardFixedSlotValue(objId: ObjectId,
offsetOffset: Int32Field,
valOffset: ValueField) {
let obj = CacheIR::useObjectReg(objId);
let offset = CacheIR::allocateReg();
let scratchVal = CacheIR::allocateValueReg();

CacheIR::addFailurePath(out label failure);

CacheIR::emitLoadInt32StubField(offsetOffset, offset);
CacheIR::emitLoadValueStubField(valOffset, scratchVal);

let slotVal = BaseIndex::new(obj, offset, Scale::TimesOne, 0_u32);
emit MASM::BranchTestValue(
Condition::NotEqual, slotVal, scratchVal, failure
);

CacheIR::releaseReg(offset);
CacheIR::releaseValueReg(scratchVal);
}

op GuardDynamicSlotValue(objId: ObjectId,
offsetOffset: Int32Field,
valOffset: ValueField) {
let obj = CacheIR::useObjectReg(objId);
let objSlots = CacheIR::allocateReg();
let offset = CacheIR::allocateReg();
let scratchVal = CacheIR::allocateValueReg();

CacheIR::addFailurePath(out label failure);

let objOffsetAddr = Address::new(obj, NativeObject::offsetOfSlots as Int32);
emit MASM::LoadPtrAddress(objOffsetAddr, objSlots);

CacheIR::emitLoadInt32StubField(offsetOffset, offset);
CacheIR::emitLoadValueStubField(valOffset, scratchVal);

let slotVal = BaseIndex::new(objSlots, offset, Scale::TimesOne, 0_u32);
emit MASM::BranchTestValue(
Condition::NotEqual, slotVal, scratchVal, failure
);

CacheIR::releaseReg(objSlots);
CacheIR::releaseReg(offset);
CacheIR::releaseValueReg(scratchVal);
}

op GuardToString(valueId: ValueId) {
let valueReg = CacheIR::useValueReg(valueId);

Expand Down Expand Up @@ -660,6 +717,11 @@ ir CacheIR emits MASM {
emit MASM::MoveValueImm(value, CacheIR::outputReg);
}

op LoadUndefinedResult() {
let value = Value::getUndefined();
emit MASM::MoveValueImm(value, CacheIR::outputReg);
}

op LoadBigIntResult(bigIntId: BigIntId) {
let bigIntReg = CacheIR::useBigIntReg(bigIntId);
emit MASM::TagValue(ValueType::BigInt, bigIntReg, CacheIR::outputReg);
Expand Down Expand Up @@ -701,6 +763,16 @@ ir CacheIR emits MASM {
bind done;
}

op StoreFixedSlot(objId: ObjectId, offsetOffset: Int32Field, ValueId) {
let obj = CacheIR::useObjectReg(objId);
let offset = readInt32Field(offsetOffset);
let val = CacheIR::useConstantOrReg(objId);
let scratch = CacheIR::allocateReg();

let slot = Address::new(obj, offset);
emit MASM::GuardedCallPreBarrier(slot, MIRType::Value)
}

op Int32AddResult(lhsId: Int32Id, rhsId: Int32Id) {
let lhsReg = CacheIR::useInt32Reg(lhsId);
let rhsReg = CacheIR::useInt32Reg(rhsId);
Expand Down Expand Up @@ -823,7 +895,7 @@ ir CacheIR emits MASM {

emit MASM::TagValue(ValueType::Int32, scratchReg, CacheIR::outputReg);

CacheIR::releaseReg(scratchReg);
CacheIR::releaseReg(scratchReg);
}

op Int32BitOrResult(lhsId: Int32Id, rhsId: Int32Id) {
Expand Down Expand Up @@ -893,7 +965,7 @@ ir CacheIR emits MASM {
let scratchReg = CacheIR::allocateReg();

CacheIR::addFailurePath(out label failure);

emit MASM::Mov(lhsReg, scratchReg);
emit MASM::FlexibleRshift32(rhsReg, scratchReg);
emit MASM::BranchTest32(Condition::Signed, scratchReg, scratchReg, failure);
Expand Down Expand Up @@ -997,7 +1069,7 @@ ir CacheIR emits MASM {
let valueId = id as ValueId;
CacheIR::defineValueReg(valueId)
}

#[refined]
fn defineBooleanReg(id: BooleanId) -> Reg {
let typedId = TypedId::fromBooleanId(id);
Expand All @@ -1015,7 +1087,7 @@ ir CacheIR emits MASM {
let typedId = TypedId::fromSymbolId(id);
CacheIR::defineReg(typedId)
}

#[refined]
fn defineBigIntReg(id: BigIntId) -> Reg {
let typedId = TypedId::fromBigIntId(id);
Expand All @@ -1027,7 +1099,7 @@ ir CacheIR emits MASM {

#[refined]
fn useReg(id: TypedId) emits MASM -> Reg {
let operandId = id as OperandId;
let operandId = id as OperandId;
let location = CacheIR::getOperandLocation(operandId);
let locationKind = OperandLocation::kind(location);

Expand All @@ -1050,7 +1122,7 @@ ir CacheIR emits MASM {

#[refined]
fn useValueReg(valueId: ValueId) emits MASM -> ValueReg {
let operandId = valueId as OperandId;
let operandId = valueId as OperandId;
let location = CacheIR::getOperandLocation(operandId);
let locationKind = OperandLocation::kind(location);

Expand All @@ -1076,6 +1148,25 @@ ir CacheIR emits MASM {
CacheIR::useReg(typedId)
}

fn useConstantOrReg(id: ValueId) -> ConstantOrReg {
let operandId = id as OperandId;
let location = CacheIR::getOperandLocation(operandId);
let locationKind = OperandLocation::kind(location);

if locationKind == OperandLocationKind::Constant {
let c = OperandLocation::getConstant(location);
return ConstantOrReg::fromValue(c);
} else if locationKind == OperandLocationKind::PayloadReg {
let r = OperandLocation::getValueReg(location);
return ConstantOrReg::fromValueReg(r);
} else {
assert false;
}

// TODO: unecessary fallthrough?
return ConstantOrReg::fromValueReg(CacheIR::useValueReg(id));
}

#[refined]
fn useInt32Reg(id: Int32Id) emits MASM -> Reg {
let typedId = TypedId::fromInt32Id(id);
Expand Down Expand Up @@ -1119,6 +1210,11 @@ ir CacheIR emits MASM {
emit MASM::Move32Imm32(CacheIR::readInt32Field(int32Field), dstReg);
}

#[refined]
fn emitLoadValueStubField(valueField: ValueField, dstReg: ValueReg) emits MASM {
emit MASM::MoveValueImm(CacheIR::readValueField(valueField), dstReg);
}

#[refined]
fn emitLoadObjectStubField(objectField: ObjectField, dstReg: Reg) emits MASM {
emit MASM::MovePtrImmGCPtrObject(CacheIR::readObjectField(objectField), dstReg);
Expand Down
36 changes: 36 additions & 0 deletions notes/js.cachet
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ enum ValueType {
Unknown,
}

enum MIRType {
Undefined,
Null,
Boolean,
Int32,
Int64,
IntPtr,
Double,
Float32,
String,
Symbol,
BigInt,
Simd128,
Object,
MagicOptimizedOut,
MagicHole,
MagicIsConstructing,
MagicUninitializedLexical,
Value,
None,
Slots,
Elements,
Pointer,
RefOrNull,
StackResults,
Shape,
}

struct Value;

impl Value {
Expand Down Expand Up @@ -260,6 +288,14 @@ impl Value {
Value::typeOf(value) == ValueType::Null
}

fn getUndefined() -> Value {
let value = (unsafe { Value::getUndefinedUnchecked() });
assume Value::isUndefined(value);
value
}

unsafe fn getUndefinedUnchecked() -> Value;

fn isUndefined(value: Value) -> Bool {
Value::typeOf(value) == ValueType::Undefined
}
Expand Down
Loading