< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/alloc/lsra/LinearScanEliminateSpillMovePhase.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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.alloc.lsra;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.isRegister;
  26 import static org.graalvm.compiler.core.common.GraalOptions.DetailedAsserts;
  27 import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
  28 import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
  29 import static org.graalvm.compiler.lir.phases.LIRPhase.Options.LIROptimization;
  30 
  31 import java.util.ArrayList;
  32 
  33 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;

  34 import org.graalvm.compiler.debug.DebugContext;
  35 import org.graalvm.compiler.debug.Indent;
  36 import org.graalvm.compiler.lir.LIRInsertionBuffer;
  37 import org.graalvm.compiler.lir.LIRInstruction;
  38 import org.graalvm.compiler.lir.StandardOp.LoadConstantOp;
  39 import org.graalvm.compiler.lir.StandardOp.MoveOp;
  40 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  41 import org.graalvm.compiler.lir.alloc.lsra.Interval.SpillState;
  42 import org.graalvm.compiler.lir.alloc.lsra.LinearScan.IntervalPredicate;
  43 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  44 import org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext;
  45 import org.graalvm.compiler.options.NestedBooleanOptionKey;
  46 import org.graalvm.compiler.options.Option;
  47 import org.graalvm.compiler.options.OptionKey;
  48 import org.graalvm.compiler.options.OptionType;
  49 
  50 import jdk.vm.ci.code.TargetDescription;
  51 import jdk.vm.ci.meta.AllocatableValue;
  52 
  53 public class LinearScanEliminateSpillMovePhase extends LinearScanAllocationPhase {


  82      * @return the index of the first instruction that is of interest for
  83      *         {@link #eliminateSpillMoves}
  84      */
  85     protected int firstInstructionOfInterest() {
  86         // skip the first because it is always a label
  87         return 1;
  88     }
  89 
  90     // called once before assignment of register numbers
  91     @SuppressWarnings("try")
  92     void eliminateSpillMoves(LIRGenerationResult res) {
  93         DebugContext debug = allocator.getDebug();
  94         try (Indent indent = debug.logAndIndent("Eliminating unnecessary spill moves")) {
  95 
  96             /*
  97              * collect all intervals that must be stored after their definition. The list is sorted
  98              * by Interval.spillDefinitionPos.
  99              */
 100             Interval interval;
 101             interval = allocator.createUnhandledLists(mustStoreAtDefinition, null).getLeft();
 102             if (DetailedAsserts.getValue(allocator.getOptions())) {
 103                 checkIntervals(debug, interval);
 104             }
 105 
 106             LIRInsertionBuffer insertionBuffer = new LIRInsertionBuffer();
 107             for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
 108                 try (Indent indent1 = debug.logAndIndent("Handle %s", block)) {
 109                     ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
 110                     int numInst = instructions.size();
 111 
 112                     // iterate all instructions of the block.
 113                     for (int j = firstInstructionOfInterest(); j < numInst; j++) {
 114                         LIRInstruction op = instructions.get(j);
 115                         int opId = op.id();
 116 
 117                         if (opId == -1) {
 118                             MoveOp move = MoveOp.asMoveOp(op);
 119                             /*
 120                              * Remove move from register to stack if the stack slot is guaranteed to
 121                              * be correct. Only moves that have been inserted by LinearScan can be
 122                              * removed.




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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.alloc.lsra;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.isRegister;

  26 import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
  27 import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
  28 import static org.graalvm.compiler.lir.phases.LIRPhase.Options.LIROptimization;
  29 
  30 import java.util.ArrayList;
  31 
  32 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  33 import org.graalvm.compiler.debug.Assertions;
  34 import org.graalvm.compiler.debug.DebugContext;
  35 import org.graalvm.compiler.debug.Indent;
  36 import org.graalvm.compiler.lir.LIRInsertionBuffer;
  37 import org.graalvm.compiler.lir.LIRInstruction;
  38 import org.graalvm.compiler.lir.StandardOp.LoadConstantOp;
  39 import org.graalvm.compiler.lir.StandardOp.MoveOp;
  40 import org.graalvm.compiler.lir.StandardOp.ValueMoveOp;
  41 import org.graalvm.compiler.lir.alloc.lsra.Interval.SpillState;
  42 import org.graalvm.compiler.lir.alloc.lsra.LinearScan.IntervalPredicate;
  43 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  44 import org.graalvm.compiler.lir.phases.AllocationPhase.AllocationContext;
  45 import org.graalvm.compiler.options.NestedBooleanOptionKey;
  46 import org.graalvm.compiler.options.Option;
  47 import org.graalvm.compiler.options.OptionKey;
  48 import org.graalvm.compiler.options.OptionType;
  49 
  50 import jdk.vm.ci.code.TargetDescription;
  51 import jdk.vm.ci.meta.AllocatableValue;
  52 
  53 public class LinearScanEliminateSpillMovePhase extends LinearScanAllocationPhase {


  82      * @return the index of the first instruction that is of interest for
  83      *         {@link #eliminateSpillMoves}
  84      */
  85     protected int firstInstructionOfInterest() {
  86         // skip the first because it is always a label
  87         return 1;
  88     }
  89 
  90     // called once before assignment of register numbers
  91     @SuppressWarnings("try")
  92     void eliminateSpillMoves(LIRGenerationResult res) {
  93         DebugContext debug = allocator.getDebug();
  94         try (Indent indent = debug.logAndIndent("Eliminating unnecessary spill moves")) {
  95 
  96             /*
  97              * collect all intervals that must be stored after their definition. The list is sorted
  98              * by Interval.spillDefinitionPos.
  99              */
 100             Interval interval;
 101             interval = allocator.createUnhandledLists(mustStoreAtDefinition, null).getLeft();
 102             if (Assertions.detailedAssertionsEnabled(allocator.getOptions())) {
 103                 checkIntervals(debug, interval);
 104             }
 105 
 106             LIRInsertionBuffer insertionBuffer = new LIRInsertionBuffer();
 107             for (AbstractBlockBase<?> block : allocator.sortedBlocks()) {
 108                 try (Indent indent1 = debug.logAndIndent("Handle %s", block)) {
 109                     ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(block);
 110                     int numInst = instructions.size();
 111 
 112                     // iterate all instructions of the block.
 113                     for (int j = firstInstructionOfInterest(); j < numInst; j++) {
 114                         LIRInstruction op = instructions.get(j);
 115                         int opId = op.id();
 116 
 117                         if (opId == -1) {
 118                             MoveOp move = MoveOp.asMoveOp(op);
 119                             /*
 120                              * Remove move from register to stack if the stack slot is guaranteed to
 121                              * be correct. Only moves that have been inserted by LinearScan can be
 122                              * removed.


< prev index next >