Skip to content

Commit

Permalink
Compute Ir machine-level offsets in MachProgram
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Apr 9, 2024
1 parent f46374a commit 38cefa0
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 53 deletions.
3 changes: 0 additions & 3 deletions aeneas/src/arm64/Arm64Backend.v3
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Arm64Target extends Target {
def configureProgram(prog: Program) {
prog.ERROR.unimplemented();
}
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
prog.ERROR.unimplemented();
}
def addRoots(compiler: Compiler, prog: Program) {
prog.ERROR.unimplemented();
}
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/ir/Ir.v3
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IrClass extends IrItem {
def methods: Array<IrMethod>; // method dispatch table, #0 = constructor
var minClassId: int;
var maxClassId: int;
var machSize: int;
var machSize: int = -1;
var boxing: Boxing;

new(ctype, typeArgs, parent, fields, methods) { }
Expand Down
4 changes: 0 additions & 4 deletions aeneas/src/ir/Normalization.v3
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@ class ReachabilityNormalizer(config: NormalizerConfig, ra: ReachabilityAnalyzer)
rf.norm = norms;
}
}
if (ra.compiler.target != null) {
var start = if(rc.parent != null, rc.parent.normFields.length);
ra.compiler.target.computeFieldOffsets(ra.prog, fields, start);
}
rc.normFields = fields.extract();
}
private def normRecordAsArray(rc: RaClass, oldRecord: Record, array: Array<Val>) {
Expand Down
45 changes: 20 additions & 25 deletions aeneas/src/mach/MachProgram.v3
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,27 @@ class MachProgram extends TargetProgram {
}
numMethods = methods.length;
}
def computeFieldOffsets(p: Program, b: Vector<IrField>, start: int) {
def processIrClass(ic: IrClass) {
if (ic.machSize >= 0) return;
var t = ic.ctype;
if (V3.isComponent(t)) return processComponent(ic);
if (ic.parent != null) processIrClass(ic.parent);
var mlayout = MachLayout.new(this);
if (start == 0) { // add type tag as first field
var start = 0;
if (ic.parent != null) {
mlayout.size = ic.parent.machSize;
start = ic.parent.fields.length;
} else {
mlayout.addType(tagType);
} else { // skip to end of previous fields
var last = b[start - 1];
mlayout.size = last.machOffset + sizeOf(last.fieldType);
}
var b = ic.fields;
for (i = start; i < b.length; i++) {
var f = b[i];
f.machOffset = mlayout.addType(f.fieldType);
}
}
def processIrClass(ic: IrClass) {
var t = ic.ctype;
if (V3.isComponent(t)) return processComponent(ic);
// compute size of heap objects if necessary
if (ic.minClassId < 0) return;
if (!Facts.isLive(ic)) return;
if (ic.fields.length == 0) {
// no fields
ic.machSize = data.addrAlign.alignUp(sizeOf(tagType));
} else {
// find field at maximum offset; assume no overlapping fields
var maxf = ic.fields[0];
for (f in ic.fields) if (f.machOffset > maxf.machOffset) maxf = f;
ic.machSize = data.addrAlign.alignUp(maxf.machOffset + sizeOf(maxf.fieldType));
}
ic.machSize = mlayout.size;
// create GC maps for object if necessary
if (runtime != null && runtime.gc != null) runtime.gc.recordTypeRefMap(ic);
if (runtime != null && runtime.gc != null && Facts.isLive(ic)) runtime.gc.recordTypeRefMap(ic);
}
def processComponent(ic: IrClass) {
// queue component record for processing
Expand Down Expand Up @@ -243,9 +234,13 @@ class MachProgram extends TargetProgram {
return ar.headerSize;
}
def getObjectSize(t: Type, r: Record) -> int {
if (V3.isClass(t)) return prog.ir.getIrClass(t).machSize; // return the size of the object
if (V3.isArray(t)) return data.addrAlign.alignUp(arrayRep(t).getObjectSize(r)); // return the size of the header only
return unexpectedType(t, 0);
var size: int;
match (t) {
x: ClassType => size = prog.ir.getIrClass(t).machSize;
x: ArrayType => size = arrayRep(t).getObjectSize(r);
_ => return unexpectedType(t, 0);
}
return data.addrAlign.alignUp(size);
}
def alignTo(i: int, a: int) -> int {
// XXX: use masks for powers of two
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/mach/MachRtGcTables.v3
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MachRtGcTables(mach: MachProgram, rt: MachRuntime) {
}
def recordTypeRefMap(ic: IrClass) {
// compute the reference map for a given IrClass
var slots = ic.machSize / mach.refSize;
var slots = (ic.machSize + mach.refSize - 1) / mach.refSize;
refMapBuilder.beginRefMap(slots, 32); // XXX: 32-bit centric; use 16-bit maps on 16-bit targets
var mutable: List<int>;
for (f in ic.fields) {
Expand Down
6 changes: 0 additions & 6 deletions aeneas/src/main/Compiler.v3
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,6 @@ class Target(name: string) {
def configureProgram(prog: Program) { }
def emit(compiler: Compiler, prog: Program) { }
def addRoots(compiler: Compiler, prog: Program) { }
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
// XXX: is this the best place for computing field offsets?
for (i = start; i < b.length; i++) {
b[i].machOffset = i;
}
}
def verifyMain(main: VstMethod, error: (FileRange, string) -> void) {
if (!typedMain) return;
var ftype = main.getType();
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/main/Version.v3
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

// Updated by VCS scripts. DO NOT EDIT.
component Version {
def version: string = "III-7.1711";
def version: string = "III-7.1712";
var buildData: string;
}
3 changes: 0 additions & 3 deletions aeneas/src/os/Linux.v3
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class LinuxTarget extends Target {
prog.typeEnv.add(linuxComponent);
prog.typeEnv.add(rt.typeCon); // installs "CiRuntime" component (for RiRuntime code)
}
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
getRuntime(prog).mach.computeFieldOffsets(prog, b, start);
}
def addRoots(compiler: Compiler, prog: Program) {
getRuntime(prog).addRoots();
}
Expand Down
3 changes: 0 additions & 3 deletions aeneas/src/wasm/WasmTarget.v3
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ class WasmTarget extends Target {
}
return buf;
}
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
getRuntime(prog).mach.computeFieldOffsets(prog, b, start);
}
def addRoots(compiler: Compiler, prog: Program) {
getRuntime(prog).addRoots();
}
Expand Down
3 changes: 0 additions & 3 deletions aeneas/src/x86-64/X86_64Darwin.v3
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ class X86_64DarwinTarget extends Target {
DarwinModule.install(prog, true); // installs "Darwin" component
prog.typeEnv.add(rt.typeCon); // installs "CiRuntime" component (for RiRuntime code)
}
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
getRuntime(prog).mach.computeFieldOffsets(prog, b, start);
}
def addRoots(compiler: Compiler, prog: Program) {
getRuntime(prog).addRoots();
}
Expand Down
3 changes: 0 additions & 3 deletions aeneas/src/x86/X86Darwin.v3
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class X86DarwinTarget extends Target {
DarwinModule.install(prog, false); // installs "Darwin" component
prog.typeEnv.add(rt.typeCon); // installs "CiRuntime" component (for RiRuntime code)
}
def computeFieldOffsets(prog: Program, b: Vector<IrField>, start: int) {
getRuntime(prog).mach.computeFieldOffsets(prog, b, start);
}
def addRoots(compiler: Compiler, prog: Program) {
getRuntime(prog).addRoots();
}
Expand Down

0 comments on commit 38cefa0

Please sign in to comment.