aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-02-02 21:55:20 +0000
committerMichael Williamson <mike@zwobble.org>2024-02-02 22:08:35 +0000
commit26092973fe989c6b6ff16d6713c32d76603458a1 (patch)
tree598b2c506962cf7e1c2e5af1b97098c23f645586 /src/main/java
parent11758c5da6ee5ff0ecc747810c9ea12a4fa1bf8b (diff)
Reduce size of GC object header
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java2
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ScalarRuntimeType.java29
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java14
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java16
4 files changed, 45 insertions, 16 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
index 104080be..859d79ab 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/codegen/PatioToLlvm.java
@@ -189,7 +189,7 @@ public class PatioToLlvm {
context.target()
)),
true,
- true,
+ false,
true
));
}
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ScalarRuntimeType.java b/src/main/java/org/shedlang/compiler/shidtopatio/ScalarRuntimeType.java
new file mode 100644
index 00000000..27a8dd4b
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ScalarRuntimeType.java
@@ -0,0 +1,29 @@
+package org.shedlang.compiler.shidtopatio;
+
+import org.shedlang.compiler.patio.types.PatioDataLayout;
+import org.shedlang.compiler.patio.types.PatioDataLayouts;
+
+import java.util.List;
+
+public class ScalarRuntimeType implements RuntimeType {
+ public static final ScalarRuntimeType INSTANCE = new ScalarRuntimeType();
+
+ private ScalarRuntimeType() {
+ }
+
+ @Override
+ public PatioDataLayout layout() {
+ // TODO: separate out runtime type from the info needed by RTTI
+ return PatioDataLayouts.struct(List.of());
+ }
+
+ @Override
+ public List<Integer> gcChildrenOffset() {
+ return List.of();
+ }
+
+ @Override
+ public int gcChildrenCount() {
+ return 0;
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
index dd187acc..04644052 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
@@ -42,12 +42,18 @@ public record ShidToPatioContext(
var effectTags = generateEffectTags(typeInfos);
var runtimeTypeTags = P.<RuntimeType, Integer>orderedPMap();
- return new GlobalContext(
+ var context = new GlobalContext(
typeInfos,
structTags,
effectTags,
runtimeTypeTags
);
+
+ // Ensure that scalars have tag of 0: this is relied on in the
+ // runtime (for instance, when allocating ints and strings).
+ context = context.addRuntimeTypeTag(ScalarRuntimeType.INSTANCE);
+
+ return context;
}
@CheckReturnValue
@@ -116,12 +122,12 @@ public record ShidToPatioContext(
}
@CheckReturnValue
- private GlobalContext addRuntimeTypeTag(RuntimeType runtimeType, Integer tag) {
+ private GlobalContext addRuntimeTypeTag(RuntimeType runtimeType) {
return new GlobalContext(
this.typeInfos,
this.structTags,
this.effectTags,
- this.runtimeTypeTags.plus(runtimeType, tag)
+ this.runtimeTypeTags.plus(runtimeType, this.runtimeTypeTags.size())
);
}
@@ -129,7 +135,7 @@ public record ShidToPatioContext(
public Result<Integer> runtimeTypeTag(RuntimeType runtimeType) {
var globalContext = this.runtimeTypeTags.containsKey(runtimeType)
? this
- : this.addRuntimeTypeTag(runtimeType, this.runtimeTypeTags.size());
+ : this.addRuntimeTypeTag(runtimeType);
return globalContext.toResult(globalContext.runtimeTypeTags.get(runtimeType));
}
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java
index 4d62f082..dff665f9 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java
@@ -7,7 +7,6 @@ import org.shedlang.compiler.patio.instructions.PatioMemoryStore;
import org.shedlang.compiler.patio.operands.*;
import org.shedlang.compiler.patio.types.*;
import org.shedlang.compiler.patio.values.PatioDataPtrValueNull;
-import org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf;
import org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.sources.Sources;
@@ -25,9 +24,8 @@ public class ShidToPatioGc {
return PatioDataLayouts.struct(List.of(
PatioDataLayouts.struct(List.of(
PatioDataLayouts.DATA_PTR, // next
- PatioDataLayouts.INT, // mark
- PatioDataLayouts.INT32, // children offset
- PatioDataLayouts.INT32 // children count
+ PatioDataLayouts.INT32, // mark
+ PatioDataLayouts.INT32 // runtime type tag
)),
valueLayout
));
@@ -47,8 +45,7 @@ public class ShidToPatioGc {
PatioDataValues.struct(List.of(
PatioDataValues.int_(0),
// Static values are always marked: see gc.c
- PatioDataValues.int_(0b110),
- PatioDataValues.int32(0),
+ PatioDataValues.int32(0b110),
PatioDataValues.int32(0)
)),
value
@@ -131,8 +128,7 @@ public class ShidToPatioGc {
"shed__runtime__gc_alloc",
List.of(
PatioLocal.param("size", PatioTypes.INT),
- PatioLocal.param("children_offset", PatioTypes.INT32),
- PatioLocal.param("children_count", PatioTypes.INT32)
+ PatioLocal.param("runtime_type_tag", PatioTypes.INT32)
),
PatioTypes.DATA_PTR,
Sources.RUNTIME
@@ -156,12 +152,10 @@ public class ShidToPatioGc {
var size = new PatioIntConst(new PatioIntValueByteSizeOf(layout));
- var offset = new PatioInt32Const(new PatioIntValueByteOffsetOf(layout, childrenOffset));
-
context = context.addInstruction(new PatioCall(
Optional.of(destination),
ALLOC.name(),
- List.of(size, offset, PatioInt32Const.of(childrenCount)),
+ List.of(size, PatioInt32Const.of(runtimeTypeTag)),
source
));