changeset 22312:baa6dc00fd5c

Refactoring of the SSA_LIR options.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 23 Jul 2015 15:59:59 +0200
parents 6fd6cf960c72
children 2c87ecb88c81 bcbb9745d795
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64SuitesProvider.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/LIRGenerationPhase.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSALinearScanEliminateSpillMovePhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/PreAllocationOptimizationStage.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ssa/SSADestructionPhase.java
diffstat 8 files changed, 103 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64SuitesProvider.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64SuitesProvider.java	Thu Jul 23 15:59:59 2015 +0200
@@ -22,7 +22,8 @@
  */
 package com.oracle.graal.compiler.amd64;
 
-import com.oracle.graal.compiler.common.*;
+import static com.oracle.graal.compiler.common.BackendOptions.*;
+
 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
 import com.oracle.graal.java.*;
 import com.oracle.graal.lir.amd64.phases.*;
@@ -37,7 +38,7 @@
     @Override
     public LIRSuites createLIRSuites() {
         LIRSuites lirSuites = super.createLIRSuites();
-        if (StackMoveOptimizationPhase.Options.LIROptStackMoveOptimizer.getValue() && GraalOptions.SSA_LIR.getValue()) {
+        if (StackMoveOptimizationPhase.Options.LIROptStackMoveOptimizer.getValue() && ShouldOptimizeStackToStackMoves.getValue()) {
             /* Note: this phase must be inserted <b>after</b> RedundantMoveElimination */
             lirSuites.getPostAllocationOptimizationStage().appendPhase(new StackMoveOptimizationPhase());
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java	Thu Jul 23 15:59:59 2015 +0200
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.common;
+
+import static com.oracle.graal.compiler.common.BackendOptions.UserOptions.*;
+import static com.oracle.graal.compiler.common.GraalOptions.*;
+import jdk.internal.jvmci.options.*;
+import jdk.internal.jvmci.options.DerivedOptionValue.*;
+
+/**
+ * Options to control the backend configuration.
+ */
+public final class BackendOptions {
+
+    public static class UserOptions {
+        // @formatter:off
+        @Option(help = "Destruct SSA LIR eagerly (before other LIR phases).", type = OptionType.Debug)
+        public static final OptionValue<Boolean> LIREagerSSADestruction = new OptionValue<>(false);
+        // @formatter:on
+    }
+
+    /* Create SSA LIR during LIR generation. */
+    public static final DerivedOptionValue<Boolean> ConstructionSSAlirDuringLirBuilding = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
+        private static final long serialVersionUID = 7657622005438210681L;
+
+        public Boolean get() {
+            return SSA_LIR.getValue();
+        }
+    });
+
+    public enum LSRAVariant {
+        NONSSA_LSAR,
+        SSA_LSRA
+    }
+
+    public static final DerivedOptionValue<LSRAVariant> LinearScanVariant = new DerivedOptionValue<>(new OptionSupplier<LSRAVariant>() {
+        private static final long serialVersionUID = 364925071685235153L;
+
+        public LSRAVariant get() {
+            if (SSA_LIR.getValue() && !LIREagerSSADestruction.getValue()) {
+                return LSRAVariant.SSA_LSRA;
+            }
+            return LSRAVariant.NONSSA_LSAR;
+        }
+    });
+
+    /* Does the backend emit stack to stack moves?. */
+    public static final DerivedOptionValue<Boolean> ShouldOptimizeStackToStackMoves = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
+        private static final long serialVersionUID = 2366072840509944317L;
+
+        public Boolean get() {
+            switch (LinearScanVariant.getValue()) {
+                case SSA_LSRA:
+                    return true;
+            }
+            return false;
+        }
+    });
+}
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/LIRGenerationPhase.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/LIRGenerationPhase.java	Thu Jul 23 15:59:59 2015 +0200
@@ -22,7 +22,7 @@
  */
 package com.oracle.graal.compiler;
 
-import static com.oracle.graal.compiler.common.GraalOptions.*;
+import static com.oracle.graal.compiler.common.BackendOptions.*;
 
 import java.util.*;
 
@@ -64,7 +64,7 @@
             emitBlock(nodeLirBuilder, lirGenRes, (Block) b, graph, schedule.getBlockToNodesMap());
         }
         context.lirGen.beforeRegisterAllocation();
-        assert !SSA_LIR.getValue() || SSAUtils.verifySSAForm(lirGenRes.getLIR());
+        assert !ConstructionSSAlirDuringLirBuilding.getValue() || SSAUtils.verifySSAForm(lirGenRes.getLIR());
     }
 
     private static void emitBlock(NodeLIRBuilderTool nodeLirGen, LIRGenerationResult lirGenRes, Block b, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java	Thu Jul 23 15:59:59 2015 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.compiler.gen;
 
+import static com.oracle.graal.compiler.common.BackendOptions.*;
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 import static com.oracle.graal.lir.LIR.*;
 import static jdk.internal.jvmci.code.ValueUtil.*;
@@ -267,7 +268,7 @@
                 emitPrologue(graph);
             } else {
                 assert block.getPredecessorCount() > 0;
-                if (SSA_LIR.getValue()) {
+                if (ConstructionSSAlirDuringLirBuilding.getValue()) {
                     // create phi-in value array
                     AbstractBeginNode begin = block.getBeginNode();
                     if (begin instanceof AbstractMergeNode) {
@@ -428,7 +429,7 @@
     public void visitEndNode(AbstractEndNode end) {
         AbstractMergeNode merge = end.merge();
         JumpOp jump = newJumpOp(getLIRBlock(merge));
-        if (SSA_LIR.getValue()) {
+        if (ConstructionSSAlirDuringLirBuilding.getValue()) {
             jump.setOutgoingValues(createPhiOut(merge, end));
         } else {
             moveToPhi(merge, end);
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java	Thu Jul 23 15:59:59 2015 +0200
@@ -22,40 +22,34 @@
  */
 package com.oracle.graal.lir.alloc.lsra;
 
-import static com.oracle.graal.compiler.common.GraalOptions.*;
+import static com.oracle.graal.compiler.common.BackendOptions.*;
 
 import java.util.*;
 
 import jdk.internal.jvmci.code.*;
-import jdk.internal.jvmci.options.*;
-import jdk.internal.jvmci.options.DerivedOptionValue.*;
+import jdk.internal.jvmci.common.*;
 
 import com.oracle.graal.compiler.common.alloc.*;
 import com.oracle.graal.compiler.common.cfg.*;
 import com.oracle.graal.lir.gen.*;
 import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory;
 import com.oracle.graal.lir.phases.*;
-import com.oracle.graal.lir.ssa.*;
 
 public final class LinearScanPhase extends AllocationPhase {
 
-    public static final DerivedOptionValue<Boolean> SSA_LSRA = new DerivedOptionValue<>(new OptionSupplier<Boolean>() {
-
-        private static final long serialVersionUID = 9115795480259228194L;
-
-        public Boolean get() {
-            return SSA_LIR.getValue() && !SSADestructionPhase.Options.LIREagerSSADestruction.getValue();
-        }
-    });
-
     @Override
     protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, SpillMoveFactory spillMoveFactory,
                     RegisterAllocationConfig registerAllocationConfig) {
         final LinearScan allocator;
-        if (LinearScanPhase.SSA_LSRA.getValue()) {
-            allocator = new SSALinearScan(target, lirGenRes, spillMoveFactory, registerAllocationConfig, linearScanOrder);
-        } else {
-            allocator = new LinearScan(target, lirGenRes, spillMoveFactory, registerAllocationConfig, linearScanOrder);
+        switch (LinearScanVariant.getValue()) {
+            case SSA_LSRA:
+                allocator = new SSALinearScan(target, lirGenRes, spillMoveFactory, registerAllocationConfig, linearScanOrder);
+                break;
+            case NONSSA_LSAR:
+                allocator = new LinearScan(target, lirGenRes, spillMoveFactory, registerAllocationConfig, linearScanOrder);
+                break;
+            default:
+                throw JVMCIError.shouldNotReachHere();
         }
         allocator.allocate(target, lirGenRes, codeEmittingOrder, linearScanOrder, spillMoveFactory, registerAllocationConfig);
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSALinearScanEliminateSpillMovePhase.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/SSALinearScanEliminateSpillMovePhase.java	Thu Jul 23 15:59:59 2015 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.lir.alloc.lsra;
 
+import static com.oracle.graal.compiler.common.BackendOptions.*;
 import static com.oracle.graal.lir.LIRValueUtil.*;
 import static jdk.internal.jvmci.code.ValueUtil.*;
 import com.oracle.graal.debug.*;
@@ -45,7 +46,7 @@
 
     @Override
     protected boolean canEliminateSpillMove(AbstractBlockBase<?> block, MoveOp move) {
-        assert isVariable(move.getResult()) || LinearScanPhase.SSA_LSRA.getValue() : "Move should not be produced in a non-SSA compilation: " + move;
+        assert isVariable(move.getResult()) || LinearScanVariant.getValue() == LSRAVariant.SSA_LSRA : "Move should not be produced in a non-SSA compilation: " + move;
 
         if (super.canEliminateSpillMove(block, move)) {
             // SSA Linear Scan might introduce moves to stack slots
@@ -60,9 +61,7 @@
     }
 
     private boolean isPhiResolutionMove(AbstractBlockBase<?> block, MoveOp move, Interval toInterval) {
-        if (!LinearScanPhase.SSA_LSRA.getValue()) {
-            return false;
-        }
+        assert LinearScanVariant.getValue() == LSRAVariant.SSA_LSRA;
         if (!toInterval.isSplitParent()) {
             return false;
         }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/PreAllocationOptimizationStage.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/phases/PreAllocationOptimizationStage.java	Thu Jul 23 15:59:59 2015 +0200
@@ -24,13 +24,14 @@
 
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 
+import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.lir.constopt.*;
 import com.oracle.graal.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext;
 import com.oracle.graal.lir.ssa.*;
 
 public class PreAllocationOptimizationStage extends LIRPhaseSuite<PreAllocationOptimizationContext> {
     public PreAllocationOptimizationStage() {
-        if (SSA_LIR.getValue() && SSADestructionPhase.Options.LIREagerSSADestruction.getValue()) {
+        if (SSA_LIR.getValue() && BackendOptions.UserOptions.LIREagerSSADestruction.getValue()) {
             appendPhase(new SSADestructionPhase());
         }
         if (ConstantLoadOptimization.Options.LIROptConstantLoadOptimization.getValue()) {
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ssa/SSADestructionPhase.java	Wed Jul 15 14:20:12 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/ssa/SSADestructionPhase.java	Thu Jul 23 15:59:59 2015 +0200
@@ -25,7 +25,6 @@
 import java.util.*;
 
 import jdk.internal.jvmci.code.*;
-import jdk.internal.jvmci.options.*;
 
 import com.oracle.graal.compiler.common.cfg.*;
 import com.oracle.graal.lir.*;
@@ -34,13 +33,6 @@
 
 public final class SSADestructionPhase extends PreAllocationOptimizationPhase {
 
-    public static class Options {
-        // @formatter:off
-        @Option(help = "Destruct SSA LIR eagerly (before other LIR phases).", type = OptionType.Debug)
-        public static final OptionValue<Boolean> LIREagerSSADestruction = new OptionValue<>(false);
-        // @formatter:on
-    }
-
     @Override
     protected <B extends AbstractBlockBase<B>> void run(TargetDescription target, LIRGenerationResult lirGenRes, List<B> codeEmittingOrder, List<B> linearScanOrder, LIRGeneratorTool lirGen) {
         LIR lir = lirGenRes.getLIR();