Skip to content

Commit

Permalink
JIT: Use state using evidence(-ish)
Browse files Browse the repository at this point in the history
For now, just use the evidence in Allocate. This requires the smallest
change in the actual jit implementation.
TODO We should evaluate what's the best implementation strategy here.
  • Loading branch information
marzipankaiser committed Oct 17, 2023
1 parent 3138482 commit 3080244
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ object PrettyPrinter extends ParenPrettyPrinter {
"init" -> toDoc(init),
"region" -> toDoc(region)
))
case AllocateAt(out, tpe, init, evidence) => jsonObjectSmall(ListMap("op" -> "\"AllocateAt\"",
"out" -> toDoc(out),
"type" -> toDoc(tpe),
"init" -> toDoc(init),
"evidence" -> toDoc(evidence)
))
case Load(out, tpe, ref) => jsonObjectSmall(ListMap("op" -> "\"Load\"",
"out" -> toDoc(out),
"type" -> toDoc(tpe),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ object Transformer {
emit(Add(out, transformArgument(l).id, transformArgument(r).id))
emitInlined(restBlock)
}
case machine.NewStack(name, region, frame, rest) => {
case machine.NewStack(name, frame, rest) => {
val (closesOver, _, target) = transformClosure(frame, "/r");
val (_, RegList(outs), restBlock) = transformInline(machine.Clause(List(name, region), rest));
val region_ignored = machine.Variable("__ignored__", machine.Type.Negative("__Region__"))
val (_, RegList(outs), restBlock) = transformInline(machine.Clause(List(name, region_ignored), rest));
val List(out, regReg) = outs(RegisterType.Ptr) : @unchecked
emit(NewStack(out, regReg, target, closesOver));
emitInlined(restBlock)
Expand All @@ -206,21 +207,21 @@ object Transformer {
emit(ShiftDyn(out, transformArgument(n).id));
emitInlined(block)
}
case machine.Allocate(name, init, mRegion, rest) =>
val (_, RegList(outs), block) = transformInline(machine.Clause(List(name, mRegion), rest));
case machine.Allocate(name, init, mEvidence, rest) =>
val (_, RegList(outs), block) = transformInline(machine.Clause(List(name), rest));
val tpe = transform(init.tpe)
val out = outs(RegisterType.Ptr).head
val region = transformArgument(mRegion).id // outs(RegisterType.Ptr).last
emit(Allocate(out, tpe.registerType, transformArgument(init).id, region))
val evidence = transformArgument(mEvidence).id // outs(RegisterType.Ptr).last
emit(AllocateAt(out, tpe.registerType, transformArgument(init).id, evidence))
emitInlined(block)
case machine.Load(name, ref, rest) =>
case machine.Load(name, ref, _, rest) =>
val (_, RegList(outs), block) = transformInline(machine.Clause(List(name), rest));
val Type.Reference(tpe) = transform(ref.tpe) : @unchecked
assert(tpe == transform(name.tpe))
val out = outs(tpe.registerType).head
emit(Load(out, tpe.registerType, transformArgument(ref).id))
emitInlined(block)
case machine.Store(ref, value, rest) =>
case machine.Store(ref, value, _, rest) =>
val Type.Reference(tpe) = transform(ref.tpe) : @unchecked
assert(tpe == transform(value.tpe))
emit(Store(transformArgument(ref).id, tpe.registerType, transformArgument(value).id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ case class Copy(tpe: RegisterType, from: Register, to: Register) extends Instruc
case class Drop(tpe: RegisterType, reg: Register) extends Instruction
case class Swap(tpe: RegisterType, a: Register, b: Register) extends Instruction
case class Allocate(out: Register, tpe: RegisterType, init: Register, region: Register) extends Instruction
case class AllocateAt(out: Register, tpe: RegisterType, init: Register, evidence: Register) extends Instruction
case class Load(out: Register, tpe: RegisterType, ref: Register) extends Instruction
case class Store(ref: Register, tpe: RegisterType, value: Register) extends Instruction

Expand Down

0 comments on commit 3080244

Please sign in to comment.