From fb77d7629d6228cb0c48c126916937bc36e8b324 Mon Sep 17 00:00:00 2001 From: Flight_Control Date: Wed, 29 Mar 2023 07:00:14 +0200 Subject: [PATCH 1/4] - Optimized the speed of the compilation by reducing the zp coalesce to only zeropage allocated registers. - All mem[x] type allocated memory or registers is ignored. (cherry picked from commit 783bd398190b55b0ccea2be937b50eb185bf51bb) --- .../java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java index c229e98fe..64d60f35f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java @@ -143,6 +143,10 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { // Check the both registers have the same type if(!register1.getType().equals(register2.getType())) return false; + if(register1.toString().startsWith("mem")) + return false; + if(register2.toString().startsWith("mem")) + return false; // Check the both registers have the same size if(register1.getBytes() != register2.getBytes()) return false; From 7e5b2caa3783072b2c2b62b26d1d643f7014eca3 Mon Sep 17 00:00:00 2001 From: Flight_Control Date: Sat, 1 Apr 2023 07:00:58 +0200 Subject: [PATCH 2/4] Optimized logic for speed --- .../java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java index 64d60f35f..29163d077 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java @@ -143,9 +143,7 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { // Check the both registers have the same type if(!register1.getType().equals(register2.getType())) return false; - if(register1.toString().startsWith("mem")) - return false; - if(register2.toString().startsWith("mem")) + if(register1.getType() == Registers.RegisterType.MAIN_MEM) return false; // Check the both registers have the same size if(register1.getBytes() != register2.getBytes()) From ca791df458272a3f90e56c22c4942860afab3b49 Mon Sep 17 00:00:00 2001 From: Flight_Control Date: Thu, 20 Apr 2023 10:47:41 +0200 Subject: [PATCH 3/4] - Coalesce optimization option implemented: - nocoalesce: disables coalesce completely. - Removed the coalesce testing if both classes were equal, as this does not make any sense ... --- .../java/dk/camelot64/kickc/Compiler.java | 24 +++++++++++++------ src/main/java/dk/camelot64/kickc/KickC.java | 8 +++++++ .../kickc/passes/Pass4MemoryCoalesce.java | 3 --- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index cc8b197cd..edb7f84f2 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -31,7 +31,10 @@ public class Compiler { private int upliftCombinations = 100; /** Enable the zero-page coalesce pass. It takes a lot of time, but limits the zero page usage significantly. */ - private boolean enableZeroPageCoalasce = false; + private boolean enableZeroPageCoalesce = false; + + /** Disables coalesce completely, which reduces compile time significantly. */ + private boolean disableCoalesce = false; /** Disable the entire register uplift. This will create significantly less optimized ASM since registers are not utilized. */ private boolean disableUplift = false; @@ -81,7 +84,11 @@ public class Compiler { } public void enableZeroPageCoalesce() { - this.enableZeroPageCoalasce = true; + this.enableZeroPageCoalesce = true; + } + + public void disableCoalesce() { + this.disableCoalesce = true; } void enableLoopHeadConstant() { @@ -712,12 +719,15 @@ public class Compiler { // Register coalesce on assignment (saving bytes & cycles) new Pass4MemoryCoalesceAssignment(program).coalesce(); - // Register coalesce on call graph (saving ZP) - new Pass4MemoryCoalesceCallGraph(program).coalesce(); + // Coalesce can be completely disabled for compilation speed reasons during programming and testing. + if(!disableCoalesce) { + // Register coalesce on call graph (saving ZP) + new Pass4MemoryCoalesceCallGraph(program).coalesce(); - if(enableZeroPageCoalasce) { - // Register coalesce using exhaustive search (saving even more ZP - but slow) - new Pass4MemoryCoalesceExhaustive(program).coalesce(); + if (enableZeroPageCoalesce) { + // Register coalesce using exhaustive search (saving even more ZP - but slow) + new Pass4MemoryCoalesceExhaustive(program).coalesce(); + } } new Pass4RegistersFinalize(program).allocate(true, true); new Pass4AssertZeropageAllocation(program).check(); diff --git a/src/main/java/dk/camelot64/kickc/KickC.java b/src/main/java/dk/camelot64/kickc/KickC.java index e79bf722c..5202df9de 100644 --- a/src/main/java/dk/camelot64/kickc/KickC.java +++ b/src/main/java/dk/camelot64/kickc/KickC.java @@ -96,6 +96,12 @@ public class KickC implements Callable { @CommandLine.Option(names = {"-Ocoalesce"}, description = "Optimization Option. Enables zero-page coalesce pass which limits zero-page usage significantly, but takes a lot of compile time.") private boolean optimizeZeroPageCoalesce = false; + @CommandLine.Option(names = {"-Ofastcoalesce"}, description = "Optimization Option. Enables zero-page only coalesce, which reduces compile time significantly, but with less coalesce optimimzation.") + private boolean optimizeFastCoalesce = false; + + @CommandLine.Option(names = {"-Onocoalesce"}, description = "Optimization Option. Disables coalesce completely, which reduces compile time significantly.") + private boolean optimizeNoCoalesce = false; + @CommandLine.Option(names = {"-Oloophead"}, description = "Optimization Option. Enabled experimental loop-head constant pass which identifies loops where the condition is constant on the first iteration.") private boolean optimizeLoopHeadConstant = false; @@ -319,6 +325,8 @@ public class KickC implements Callable { if(optimizeZeroPageCoalesce) compiler.enableZeroPageCoalesce(); + if(optimizeNoCoalesce) + compiler.disableCoalesce(); if(optimizeLoopHeadConstant) compiler.enableLoopHeadConstant(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java index 29163d077..65974bb6f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java @@ -140,9 +140,6 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { // Check the both registers are in memory if(!register1.isMem() || !register2.isMem()) return false; - // Check the both registers have the same type - if(!register1.getType().equals(register2.getType())) - return false; if(register1.getType() == Registers.RegisterType.MAIN_MEM) return false; // Check the both registers have the same size From ccf880e617a1eb39896ee0d89a3cfeb693f394c3 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 24 Apr 2023 07:52:42 +0200 Subject: [PATCH 4/4] Merged master into branch. Rolled back main mem only coalesce. --- src/main/java/dk/camelot64/kickc/KickC.java | 3 --- .../java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/KickC.java b/src/main/java/dk/camelot64/kickc/KickC.java index 5202df9de..53528d19e 100644 --- a/src/main/java/dk/camelot64/kickc/KickC.java +++ b/src/main/java/dk/camelot64/kickc/KickC.java @@ -96,9 +96,6 @@ public class KickC implements Callable { @CommandLine.Option(names = {"-Ocoalesce"}, description = "Optimization Option. Enables zero-page coalesce pass which limits zero-page usage significantly, but takes a lot of compile time.") private boolean optimizeZeroPageCoalesce = false; - @CommandLine.Option(names = {"-Ofastcoalesce"}, description = "Optimization Option. Enables zero-page only coalesce, which reduces compile time significantly, but with less coalesce optimimzation.") - private boolean optimizeFastCoalesce = false; - @CommandLine.Option(names = {"-Onocoalesce"}, description = "Optimization Option. Disables coalesce completely, which reduces compile time significantly.") private boolean optimizeNoCoalesce = false; diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java index 7e26193d8..03c531702 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4MemoryCoalesce.java @@ -156,7 +156,8 @@ public abstract class Pass4MemoryCoalesce extends Pass2Base { // Check the both registers are in memory if(!register1.isMem() || !register2.isMem()) return false; - if(register1.getType() == Registers.RegisterType.MAIN_MEM) + // Check the both registers have the same type + if(!register1.getType().equals(register2.getType())) return false; // Check the both registers have the same size if(register1.getBytes() != register2.getBytes())