# HG changeset patch # User Josef Eisl # Date 1436533851 -7200 # Node ID ca38f84b17fc7a45f70795b7463f7d3f891646e2 # Parent 5522e8ffa5f57e9aa61f0e678bcdf179966d0bc7 RedundantMoveElimination: use stack offset as index for stackIndices. diff -r 5522e8ffa5f5 -r ca38f84b17fc graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java Fri Jul 10 18:06:37 2015 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/RedundantMoveElimination.java Fri Jul 10 15:10:51 2015 +0200 @@ -47,8 +47,8 @@ @Override protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, BenchmarkCounterFactory counterFactory) { - Optimization redundantMoveElimination = new Optimization(); - redundantMoveElimination.doOptimize(lirGenRes.getLIR(), lirGenRes.getFrameMap()); + Optimization redundantMoveElimination = new Optimization(lirGenRes.getFrameMap()); + redundantMoveElimination.doOptimize(lirGenRes.getLIR()); } /** @@ -99,28 +99,34 @@ int[] eligibleRegs; /** - * A map from the {@link StackSlot} to an index into the state. StackSlots of different - * kinds that map to the same location will map to the same index. + * A map from the {@link StackSlot} {@link #getOffset offset} to an index into the state. + * StackSlots of different kinds that map to the same location will map to the same index. */ - Map stackIndices = CollectionsFactory.newMap(); + Map stackIndices = CollectionsFactory.newMap(); int numRegs; + private final FrameMap frameMap; + /* * Pseudo value for a not yet assigned location. */ static final int INIT_VALUE = 0; + public Optimization(FrameMap frameMap) { + this.frameMap = frameMap; + } + /** * The main method doing the elimination of redundant moves. */ - private void doOptimize(LIR lir, FrameMap frameMap) { + private void doOptimize(LIR lir) { try (Indent indent = Debug.logAndIndent("eliminate redundant moves")) { callerSaveRegs = frameMap.getRegisterConfig().getCallerSaveRegisters(); - initBlockData(lir, frameMap); + initBlockData(lir); // Compute a table of the registers which are eligible for move optimization. // Unallocatable registers should never be optimized. @@ -146,7 +152,7 @@ */ private static final int COMPLEXITY_LIMIT = 30000; - private void initBlockData(LIR lir, FrameMap frameMap) { + private void initBlockData(LIR lir) { List> blocks = lir.linearScanOrder(); numRegs = 0; @@ -157,7 +163,6 @@ * Search for relevant locations which can be optimized. These are register or stack * slots which occur as destinations of move instructions. */ - Map offsetToIndex = CollectionsFactory.newMap(); for (AbstractBlockBase block : blocks) { List instructions = lir.getLIRforBlock(block); for (LIRInstruction op : instructions) { @@ -170,12 +175,9 @@ } } else if (isStackSlot(dest)) { StackSlot stackSlot = (StackSlot) dest; - if (!stackIndices.containsKey(stackSlot) && offsetToIndex.size() < maxStackLocations) { - Integer offset = stackSlot.getOffset(frameMap.totalFrameSize()); - if (!offsetToIndex.containsKey(offset)) { - offsetToIndex.put(offset, offsetToIndex.size()); - } - stackIndices.put(stackSlot, offsetToIndex.get(offset)); + Integer offset = getOffset(stackSlot); + if (!stackIndices.containsKey(offset) && stackIndices.size() < maxStackLocations) { + stackIndices.put(offset, stackIndices.size()); } } } @@ -193,6 +195,10 @@ } } + private int getOffset(StackSlot stackSlot) { + return stackSlot.getOffset(frameMap.totalFrameSize()); + } + /** * Calculates the entry and exit states for all basic blocks. * @@ -489,7 +495,7 @@ } if (isStackSlot(location)) { StackSlot slot = (StackSlot) location; - Integer index = stackIndices.get(slot); + Integer index = stackIndices.get(getOffset(slot)); if (index != null) { return index.intValue() + numRegs; }