Skip to content

Commit

Permalink
Add support for trivial methods (#46)
Browse files Browse the repository at this point in the history
Trivial methods are special cases of well-known patterns where we avoid
the need for a frame.

Currently supported are:
 - methods that return a literal
 - methods that return a global
 - methods that read a field (getter)
 - methods that write a field (setter)


https://rebench.dev/SOMpp/compare/f2e87f82f240732ba0f8dd2bdea489c33edcb713..4d147afeb4e27fb698ff1b89ac6a106b3c0381f7
median -1% (min. -46%, max. 14%)

The implementation uses a `VMTrivial` method and subclasses.

Tests now have a common superclass `TestWithParsing` when they use the
parser.
  • Loading branch information
smarr authored Aug 6, 2024
2 parents f2e87f8 + 505d4ec commit 4ba47cf
Show file tree
Hide file tree
Showing 37 changed files with 1,508 additions and 405 deletions.
20 changes: 20 additions & 0 deletions SOM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
0A3A3CB31A5D5476004CB03B /* PrimitiveLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F52032B0FA6624C00E75857 /* PrimitiveLoader.cpp */; };
0A5A7E912C5D45A00011C783 /* VMSafePrimitive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E902C5D45A00011C783 /* VMSafePrimitive.cpp */; };
0A5A7E922C5D45A00011C783 /* VMSafePrimitive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E902C5D45A00011C783 /* VMSafePrimitive.cpp */; };
0A5A7E962C60F5BB0011C783 /* VMTrivialMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E952C60F5BB0011C783 /* VMTrivialMethod.cpp */; };
0A5A7E972C60F5BB0011C783 /* VMTrivialMethod.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E952C60F5BB0011C783 /* VMTrivialMethod.cpp */; };
0A5A7E9A2C617E400011C783 /* TrivialMethodTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E992C617E400011C783 /* TrivialMethodTest.cpp */; };
0A5A7E9D2C617EE00011C783 /* TestWithParsing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A5A7E9C2C617EE00011C783 /* TestWithParsing.cpp */; };
0A67EA7519ACD43A00830E3B /* CloneObjectsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A67EA7019ACD43A00830E3B /* CloneObjectsTest.cpp */; };
0A67EA7619ACD43A00830E3B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A67EA7119ACD43A00830E3B /* main.cpp */; };
0A67EA7819ACD43A00830E3B /* WalkObjectsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0A67EA7319ACD43A00830E3B /* WalkObjectsTest.cpp */; };
Expand Down Expand Up @@ -225,6 +229,12 @@
0A5A7E8F2C5D30390011C783 /* VMSafePrimitive.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMSafePrimitive.h; sourceTree = "<group>"; };
0A5A7E902C5D45A00011C783 /* VMSafePrimitive.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VMSafePrimitive.cpp; sourceTree = "<group>"; };
0A5A7E932C5DA9A90011C783 /* Primitives.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Primitives.h; sourceTree = "<group>"; };
0A5A7E942C602E8C0011C783 /* VMTrivialMethod.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMTrivialMethod.h; sourceTree = "<group>"; };
0A5A7E952C60F5BB0011C783 /* VMTrivialMethod.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VMTrivialMethod.cpp; sourceTree = "<group>"; };
0A5A7E982C617E2B0011C783 /* TrivialMethodTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TrivialMethodTest.h; path = unitTests/TrivialMethodTest.h; sourceTree = "<group>"; };
0A5A7E992C617E400011C783 /* TrivialMethodTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = TrivialMethodTest.cpp; path = unitTests/TrivialMethodTest.cpp; sourceTree = "<group>"; };
0A5A7E9B2C617EC70011C783 /* TestWithParsing.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TestWithParsing.h; path = unitTests/TestWithParsing.h; sourceTree = "<group>"; };
0A5A7E9C2C617EE00011C783 /* TestWithParsing.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = TestWithParsing.cpp; path = unitTests/TestWithParsing.cpp; sourceTree = "<group>"; };
0A67EA6719ACD37200830E3B /* unittests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = unittests; sourceTree = BUILT_PRODUCTS_DIR; };
0A67EA7019ACD43A00830E3B /* CloneObjectsTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CloneObjectsTest.cpp; path = unitTests/CloneObjectsTest.cpp; sourceTree = "<group>"; };
0A67EA7119ACD43A00830E3B /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = unitTests/main.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -449,6 +459,10 @@
0A67EA7419ACD43A00830E3B /* WriteBarrierTest.cpp */,
0A1C98562C3DD87300735850 /* unitTests/BytecodeGenerationTest.h */,
0A1C98572C3DD88500735850 /* unitTests/BytecodeGenerationTest.cpp */,
0A5A7E982C617E2B0011C783 /* TrivialMethodTest.h */,
0A5A7E992C617E400011C783 /* TrivialMethodTest.cpp */,
0A5A7E9B2C617EC70011C783 /* TestWithParsing.h */,
0A5A7E9C2C617EE00011C783 /* TestWithParsing.cpp */,
);
name = unittests;
sourceTree = "<group>";
Expand Down Expand Up @@ -671,6 +685,8 @@
3F5203580FA6624C00E75857 /* VMSymbol.h */,
0A5A7E8F2C5D30390011C783 /* VMSafePrimitive.h */,
0A5A7E902C5D45A00011C783 /* VMSafePrimitive.cpp */,
0A5A7E942C602E8C0011C783 /* VMTrivialMethod.h */,
0A5A7E952C60F5BB0011C783 /* VMTrivialMethod.cpp */,
);
path = vmobjects;
sourceTree = "<group>";
Expand Down Expand Up @@ -881,6 +897,7 @@
0A1886DD1832BCC800A2CBCA /* ClassGenerationContext.cpp in Sources */,
0A3A3C941A5D546D004CB03B /* Class.cpp in Sources */,
0A1C98672C4D340300735850 /* Symbols.cpp in Sources */,
0A5A7E962C60F5BB0011C783 /* VMTrivialMethod.cpp in Sources */,
0A18870B1832C0E400A2CBCA /* AbstractObject.cpp in Sources */,
0AB80AD82C394806006B6419 /* Globals.cpp in Sources */,
0A3A3C991A5D546D004CB03B /* Primitive.cpp in Sources */,
Expand Down Expand Up @@ -946,10 +963,12 @@
0A3A3CA31A5D546D004CB03B /* Class.cpp in Sources */,
0A67EA9019ACD83200830E3B /* Lexer.cpp in Sources */,
0AB80AD92C394806006B6419 /* Globals.cpp in Sources */,
0A5A7E9D2C617EE00011C783 /* TestWithParsing.cpp in Sources */,
0A3A3CA71A5D546D004CB03B /* Object.cpp in Sources */,
0A3A3CB21A5D5476004CB03B /* PrimitiveContainer.cpp in Sources */,
0A1C98582C3DD88500735850 /* unitTests/BytecodeGenerationTest.cpp in Sources */,
0A1C986F2C4F1D3900735850 /* debug.cpp in Sources */,
0A5A7E9A2C617E400011C783 /* TrivialMethodTest.cpp in Sources */,
0A67EA8419ACD74800830E3B /* VMFrame.cpp in Sources */,
0A67EA7D19ACD74800830E3B /* Signature.cpp in Sources */,
0A67EA7E19ACD74800830E3B /* VMArray.cpp in Sources */,
Expand Down Expand Up @@ -997,6 +1016,7 @@
0A1C986C2C4D363A00735850 /* LogAllocation.cpp in Sources */,
0A67EA9319ACD83200830E3B /* SourcecodeCompiler.cpp in Sources */,
0A1C98682C4D340300735850 /* Symbols.cpp in Sources */,
0A5A7E972C60F5BB0011C783 /* VMTrivialMethod.cpp in Sources */,
0AB80AD42C392B78006B6419 /* Print.cpp in Sources */,
0A3A3CA41A5D546D004CB03B /* Double.cpp in Sources */,
0A1C98772C5526AD00735850 /* DebugCopyingCollector.cpp in Sources */,
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void EmitPUSHFIELD(MethodGenerationContext& mgenc, VMSymbol* field) {
}
}

void EmitPUSHBLOCK(MethodGenerationContext& mgenc, VMMethod* block) {
void EmitPUSHBLOCK(MethodGenerationContext& mgenc, VMInvokable* block) {
const int8_t idx = mgenc.AddLiteralIfAbsent(block);
Emit2(mgenc, BC_PUSH_BLOCK, idx, 1);
}
Expand Down Expand Up @@ -322,8 +322,7 @@ size_t Emit3WithDummy(MethodGenerationContext& mgenc, uint8_t bytecode,
return index;
}

void EmitPushFieldWithIndex(MethodGenerationContext& mgenc, uint8_t fieldIdx,
uint8_t ctxLevel) {
void EmitPushFieldWithIndex(MethodGenerationContext& mgenc, uint8_t fieldIdx) {
// if (ctxLevel == 0) {
if (fieldIdx == 0) {
Emit1(mgenc, BC_PUSH_FIELD_0, 1);
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/BytecodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void EmitDUP(MethodGenerationContext& mgenc);
void EmitPUSHLOCAL(MethodGenerationContext& mgenc, long idx, int ctx);
void EmitPUSHARGUMENT(MethodGenerationContext& mgenc, long idx, int ctx);
void EmitPUSHFIELD(MethodGenerationContext& mgenc, VMSymbol* field);
void EmitPUSHBLOCK(MethodGenerationContext& mgenc, VMMethod* block);
void EmitPUSHBLOCK(MethodGenerationContext& mgenc, VMInvokable* block);
void EmitPUSHCONSTANT(MethodGenerationContext& mgenc, vm_oop_t cst);
void EmitPUSHCONSTANT(MethodGenerationContext& mgenc, uint8_t literalIndex);
void EmitPUSHCONSTANTString(MethodGenerationContext& mgenc, VMString* str);
Expand All @@ -71,7 +71,6 @@ void EmitJumpBackwardWithOffset(MethodGenerationContext& mgenc,
size_t Emit3WithDummy(MethodGenerationContext& mgenc, uint8_t bytecode,
size_t stackEffect);

void EmitPushFieldWithIndex(MethodGenerationContext& mgenc, uint8_t fieldIdx,
uint8_t ctxLevel);
void EmitPushFieldWithIndex(MethodGenerationContext& mgenc, uint8_t fieldIdx);
void EmitPopFieldWithIndex(MethodGenerationContext& mgenc, uint8_t fieldIdx,
uint8_t ctxLevel);
Loading

0 comments on commit 4ba47cf

Please sign in to comment.