From 692f432d6ae7f14d36b37a36173b47b0b74dbec8 Mon Sep 17 00:00:00 2001 From: SrGaabriel Date: Sun, 8 Sep 2024 22:19:30 -0300 Subject: [PATCH] optimization: ignore unused pure calls --- .../session/SeleneDragonCompilingSession.kt | 6 +++++- bard/output/ll/signatures.json | 2 +- bard/output/output.exe | Bin 123392 -> 123392 bytes build.gradle.kts | 8 -------- stdlib/src/collections.sn | 4 +++- stdlib/src/io.sn | 4 +--- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/backend/llvm/src/commonMain/kotlin/session/SeleneDragonCompilingSession.kt b/backend/llvm/src/commonMain/kotlin/session/SeleneDragonCompilingSession.kt index 85b8b5e..c302db8 100644 --- a/backend/llvm/src/commonMain/kotlin/session/SeleneDragonCompilingSession.kt +++ b/backend/llvm/src/commonMain/kotlin/session/SeleneDragonCompilingSession.kt @@ -115,6 +115,10 @@ class SeleneDragonCompilingSession( return intrinsics.onCall(context) } val pure = !signature.modifiers.contains(Modifiers.IMPURE) + val ignoreResult = statement || signature.returnType == SeleneType.Void + if (pure && ignoreResult) { + return NullMemory + } val call = if (signature.module != compilerModule.name) { @@ -132,7 +136,7 @@ class SeleneDragonCompilingSession( pure = pure ) } - if (statement || signature.returnType == SeleneType.Void) { + if (ignoreResult) { call.ignore() return NullMemory } diff --git a/bard/output/ll/signatures.json b/bard/output/ll/signatures.json index 3331069..39fa170 100644 --- a/bard/output/ll/signatures.json +++ b/bard/output/ll/signatures.json @@ -1 +1 @@ -{"functions":[{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"test","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":["IMPURE"]}]} \ No newline at end of file +{"functions":[{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"test","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":["IMPURE"]}]} \ No newline at end of file diff --git a/bard/output/output.exe b/bard/output/output.exe index 4ecffab44e2b1a09db771fb7ee70f37415b85422..9c73f056b6655b07bf6670355da19da6d254fad2 100644 GIT binary patch delta 27 icmZoT!rpL%eZmi>>pqRYw*F$|ng?WUXPeLX%LxFv*9_GF delta 27 icmZoT!rpL%eZmhWcBjT)TYoWf%>%Nwv(0Dx