< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/RedundantMoveElimination.java

Print this page




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.lir;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.isRegister;
  26 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Arrays;
  30 import java.util.Collections;
  31 import java.util.EnumSet;
  32 

  33 import org.graalvm.compiler.core.common.LIRKind;
  34 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  35 import org.graalvm.compiler.debug.CounterKey;
  36 import org.graalvm.compiler.debug.DebugContext;
  37 import org.graalvm.compiler.debug.Indent;
  38 import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
  39 import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
  40 import org.graalvm.compiler.lir.StandardOp.MoveOp;
  41 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  42 import org.graalvm.compiler.lir.framemap.FrameMap;
  43 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  44 import org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase;
  45 import org.graalvm.util.EconomicMap;
  46 import org.graalvm.util.Equivalence;
  47 
  48 import jdk.vm.ci.code.Register;
  49 import jdk.vm.ci.code.RegisterArray;
  50 import jdk.vm.ci.code.RegisterValue;
  51 import jdk.vm.ci.code.StackSlot;
  52 import jdk.vm.ci.code.TargetDescription;


 121         int numRegs;
 122 
 123         private final FrameMap frameMap;
 124 
 125         /*
 126          * Pseudo value for a not yet assigned location.
 127          */
 128         static final int INIT_VALUE = 0;
 129 
 130         Optimization(FrameMap frameMap) {
 131             this.frameMap = frameMap;
 132         }
 133 
 134         /**
 135          * The main method doing the elimination of redundant moves.
 136          */
 137         @SuppressWarnings("try")
 138         private void doOptimize(LIR lir) {
 139             DebugContext debug = lir.getDebug();
 140             try (Indent indent = debug.logAndIndent("eliminate redundant moves")) {
 141 
 142                 callerSaveRegs = frameMap.getRegisterConfig().getCallerSaveRegisters();
 143 
 144                 initBlockData(lir);
 145 
 146                 // Compute a table of the registers which are eligible for move optimization.
 147                 // Unallocatable registers should never be optimized.
 148                 eligibleRegs = new int[numRegs];
 149                 Arrays.fill(eligibleRegs, -1);
 150                 for (Register reg : frameMap.getRegisterConfig().getAllocatableRegisters()) {
 151                     if (reg.number < numRegs) {
 152                         eligibleRegs[reg.number] = reg.number;
 153                     }
 154                 }
 155 
 156                 if (!solveDataFlow(lir)) {
 157                     return;
 158                 }
 159 
 160                 eliminateMoves(lir);
 161             }
 162         }
 163 
 164         /**
 165          * The maximum number of locations * blocks. This is a complexity limit for the inner loop
 166          * in {@link #mergeState} (assuming a small number of iterations in {@link #solveDataFlow}.
 167          */
 168         private static final int COMPLEXITY_LIMIT = 30000;
 169 
 170         private void initBlockData(LIR lir) {




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.lir;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.isRegister;
  26 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Arrays;
  30 import java.util.Collections;
  31 import java.util.EnumSet;
  32 
  33 import jdk.vm.ci.code.RegisterConfig;
  34 import org.graalvm.compiler.core.common.LIRKind;
  35 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  36 import org.graalvm.compiler.debug.CounterKey;
  37 import org.graalvm.compiler.debug.DebugContext;
  38 import org.graalvm.compiler.debug.Indent;
  39 import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
  40 import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
  41 import org.graalvm.compiler.lir.StandardOp.MoveOp;
  42 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  43 import org.graalvm.compiler.lir.framemap.FrameMap;
  44 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  45 import org.graalvm.compiler.lir.phases.PostAllocationOptimizationPhase;
  46 import org.graalvm.util.EconomicMap;
  47 import org.graalvm.util.Equivalence;
  48 
  49 import jdk.vm.ci.code.Register;
  50 import jdk.vm.ci.code.RegisterArray;
  51 import jdk.vm.ci.code.RegisterValue;
  52 import jdk.vm.ci.code.StackSlot;
  53 import jdk.vm.ci.code.TargetDescription;


 122         int numRegs;
 123 
 124         private final FrameMap frameMap;
 125 
 126         /*
 127          * Pseudo value for a not yet assigned location.
 128          */
 129         static final int INIT_VALUE = 0;
 130 
 131         Optimization(FrameMap frameMap) {
 132             this.frameMap = frameMap;
 133         }
 134 
 135         /**
 136          * The main method doing the elimination of redundant moves.
 137          */
 138         @SuppressWarnings("try")
 139         private void doOptimize(LIR lir) {
 140             DebugContext debug = lir.getDebug();
 141             try (Indent indent = debug.logAndIndent("eliminate redundant moves")) {
 142                 RegisterConfig registerConfig = frameMap.getRegisterConfig();
 143                 callerSaveRegs = registerConfig.getCallerSaveRegisters();
 144 
 145                 initBlockData(lir);
 146 
 147                 // Compute a table of the registers which are eligible for move optimization.
 148                 // Unallocatable registers should never be optimized.
 149                 eligibleRegs = new int[numRegs];
 150                 Arrays.fill(eligibleRegs, -1);
 151                 for (Register reg : registerConfig.getAllocatableRegisters()) {
 152                     if (reg.number < numRegs) {
 153                         eligibleRegs[reg.number] = reg.number;
 154                     }
 155                 }
 156 
 157                 if (!solveDataFlow(lir)) {
 158                     return;
 159                 }
 160 
 161                 eliminateMoves(lir);
 162             }
 163         }
 164 
 165         /**
 166          * The maximum number of locations * blocks. This is a complexity limit for the inner loop
 167          * in {@link #mergeState} (assuming a small number of iterations in {@link #solveDataFlow}.
 168          */
 169         private static final int COMPLEXITY_LIMIT = 30000;
 170 
 171         private void initBlockData(LIR lir) {


< prev index next >