From b81349b3de37d38e00d3adff3b893b1f6e9c6fb8 Mon Sep 17 00:00:00 2001 From: Travis Fisher Date: Wed, 10 Apr 2019 22:22:17 -0400 Subject: [PATCH] make StatementInfos map control flow block objects instead of labelRef's (~5% compiler speedup) --- .../kickc/model/LiveRangeVariablesEffective.java | 3 +-- .../kickc/model/statements/StatementInfos.java | 10 +++++----- .../dk/camelot64/kickc/passes/PassNStatementInfos.java | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/model/LiveRangeVariablesEffective.java b/src/main/java/dk/camelot64/kickc/model/LiveRangeVariablesEffective.java index 063d2af7b..70566cf77 100644 --- a/src/main/java/dk/camelot64/kickc/model/LiveRangeVariablesEffective.java +++ b/src/main/java/dk/camelot64/kickc/model/LiveRangeVariablesEffective.java @@ -276,9 +276,8 @@ public class LiveRangeVariablesEffective { * @return All variables effectively alive at the statement on the call-path */ public Collection getEffectiveAliveAtStmt(CallPath callPath) { - LinkedHashSet effectiveAlive = new LinkedHashSet<>(); // Add alive at call - effectiveAlive.addAll(callPath.getAlive()); + LinkedHashSet effectiveAlive = new LinkedHashSet<>(callPath.getAlive()); // Clear out any variables referenced in the method effectiveAlive.removeAll(referencedInProcedure); // Add alive at statement diff --git a/src/main/java/dk/camelot64/kickc/model/statements/StatementInfos.java b/src/main/java/dk/camelot64/kickc/model/statements/StatementInfos.java index b13d7cbc0..53572d2f2 100644 --- a/src/main/java/dk/camelot64/kickc/model/statements/StatementInfos.java +++ b/src/main/java/dk/camelot64/kickc/model/statements/StatementInfos.java @@ -14,12 +14,12 @@ public class StatementInfos { private ControlFlowGraph graph; /** Maps statement index to block label. */ - private Map stmtBlocks; + private Map stmtBlocks; /** Maps statement index to statement. */ private Map stmtIdx; - public StatementInfos(Program program, Map stmtBlocks, Map stmtIdx) { + public StatementInfos(Program program, Map stmtBlocks, Map stmtIdx) { this.graph = program.getGraph(); this.stmtBlocks = stmtBlocks; this.stmtIdx = stmtIdx; @@ -32,7 +32,7 @@ public class StatementInfos { * @return The block label */ public LabelRef getBlockRef(Integer stmtIdx) { - return stmtBlocks.get(stmtIdx); + return stmtBlocks.get(stmtIdx).getLabel(); } /** @@ -42,7 +42,7 @@ public class StatementInfos { * @return The block label */ public LabelRef getBlockRef(Statement stmt) { - return stmtBlocks.get(stmt.getIndex()); + return stmtBlocks.get(stmt.getIndex()).getLabel(); } /** @@ -52,7 +52,7 @@ public class StatementInfos { * @return The containing block */ public ControlFlowBlock getBlock(Statement stmt) { - return graph.getBlock(getBlockRef(stmt)); + return stmtBlocks.get(stmt.getIndex()); } /** diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNStatementInfos.java b/src/main/java/dk/camelot64/kickc/passes/PassNStatementInfos.java index e9e115400..224719d9f 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNStatementInfos.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNStatementInfos.java @@ -24,11 +24,11 @@ public class PassNStatementInfos extends Pass2SsaOptimization { */ @Override public boolean step() { - LinkedHashMap stmtBlocks = new LinkedHashMap<>(); + LinkedHashMap stmtBlocks = new LinkedHashMap<>(); LinkedHashMap stmtIdx = new LinkedHashMap<>(); for(ControlFlowBlock block : getProgram().getGraph().getAllBlocks()) { for(Statement statement : block.getStatements()) { - stmtBlocks.put(statement.getIndex(), block.getLabel()); + stmtBlocks.put(statement.getIndex(), block); stmtIdx.put(statement.getIndex(), statement); } }