changeset 22165:9a2015b7afab

Introduce SpillMoveFactoryBase.
author Josef Eisl <josef.eisl@jku.at>
date Tue, 07 Jul 2015 15:45:49 +0200
parents 62827991cf80
children 72fa6c115a9b
files graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/SpillMoveFactoryBase.java
diffstat 4 files changed, 126 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Tue Jul 07 15:08:50 2015 +0200
+++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java	Tue Jul 07 15:45:49 2015 +0200
@@ -96,15 +96,15 @@
         }
     }
 
-    private class AMD64SpillMoveFactory implements LIRGeneratorTool.SpillMoveFactory {
+    private class AMD64SpillMoveFactory extends SpillMoveFactoryBase {
 
         @Override
-        public LIRInstruction createMove(AllocatableValue result, Value input) {
+        protected LIRInstruction createMoveIntern(AllocatableValue result, Value input) {
             return AMD64LIRGenerator.this.createMove(result, input);
         }
 
         @Override
-        public LIRInstruction createStackMove(AllocatableValue result, Value input) {
+        protected LIRInstruction createStackMoveIntern(AllocatableValue result, Value input) {
             return AMD64LIRGenerator.this.createStackMove(result, input);
         }
 
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Tue Jul 07 15:08:50 2015 +0200
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Tue Jul 07 15:45:49 2015 +0200
@@ -75,15 +75,15 @@
     private Variable constantTableBase;
     private SPARCLoadConstantTableBaseOp loadConstantTableBaseOp;
 
-    private class SPARCSpillMoveFactory implements LIRGeneratorTool.SpillMoveFactory {
+    private class SPARCSpillMoveFactory extends SpillMoveFactoryBase {
 
         @Override
-        public LIRInstruction createMove(AllocatableValue result, Value input) {
+        protected LIRInstruction createMoveIntern(AllocatableValue result, Value input) {
             return SPARCLIRGenerator.this.createMove(result, input);
         }
 
         @Override
-        public LIRInstruction createStackMove(AllocatableValue result, Value input) {
+        protected LIRInstruction createStackMoveIntern(AllocatableValue result, Value input) {
             return SPARCLIRGenerator.this.createStackMove(result, input);
         }
     }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Tue Jul 07 15:08:50 2015 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Tue Jul 07 15:45:49 2015 +0200
@@ -30,7 +30,6 @@
 import com.oracle.graal.compiler.common.cfg.*;
 import com.oracle.graal.compiler.common.spi.*;
 import com.oracle.graal.lir.*;
-import com.oracle.graal.lir.StandardOp.StackMove;
 
 public interface LIRGeneratorTool extends ArithmeticLIRGenerator, BenchmarkCounterFactory {
 
@@ -38,9 +37,7 @@
 
         LIRInstruction createMove(AllocatableValue result, Value input);
 
-        default LIRInstruction createStackMove(AllocatableValue result, Value input) {
-            return new StackMove(result, input);
-        }
+        LIRInstruction createStackMove(AllocatableValue result, Value input);
     }
 
     public abstract class BlockScope implements AutoCloseable {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/SpillMoveFactoryBase.java	Tue Jul 07 15:45:49 2015 +0200
@@ -0,0 +1,119 @@
+/*
+ * 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.lir.gen;
+
+import static com.oracle.graal.lir.LIRValueUtil.*;
+
+import java.util.*;
+
+import jdk.internal.jvmci.meta.*;
+
+import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.LIRInstruction.OperandFlag;
+import com.oracle.graal.lir.LIRInstruction.OperandMode;
+import com.oracle.graal.lir.StandardOp.StackMove;
+import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory;
+
+/**
+ * Base class for {@link SpillMoveFactory} that checks that the instructions created adhere to the
+ * contract of {@link SpillMoveFactory}.
+ */
+public abstract class SpillMoveFactoryBase implements SpillMoveFactory {
+
+    public final LIRInstruction createMove(AllocatableValue result, Value input) {
+        LIRInstruction inst = createMoveIntern(result, input);
+        assert checkResult(inst, result, input);
+        return inst;
+    }
+
+    public final LIRInstruction createStackMove(AllocatableValue result, Value input) {
+        LIRInstruction inst = createStackMoveIntern(result, input);
+        assert checkResult(inst, result, input);
+        return inst;
+    }
+
+    protected abstract LIRInstruction createMoveIntern(AllocatableValue result, Value input);
+
+    protected LIRInstruction createStackMoveIntern(AllocatableValue result, Value input) {
+        return new StackMove(result, input);
+    }
+
+    /** Closure for {@link SpillMoveFactoryBase#checkResult}. */
+    @SuppressWarnings("unused")
+    private static class CheckClosure {
+
+        private final AllocatableValue result;
+        private final Value input;
+
+        private int tempCount = 0;
+        private int aliveCount = 0;
+        private int stateCount = 0;
+        private int inputCount = 0;
+        private int outputCount = 0;
+
+        CheckClosure(AllocatableValue result, Value input) {
+            this.result = result;
+            this.input = input;
+        }
+
+        void tempProc(LIRInstruction op, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+            assert false : String.format("SpillMoveFactory: Instruction %s is not allowed to contain operand %s of mode %s", op, value, mode);
+            tempCount++;
+        }
+
+        void stateProc(LIRInstruction op, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+            assert false : String.format("SpillMoveFactory: Instruction %s is not allowed to contain operand %s of mode %s", op, value, mode);
+            stateCount++;
+        }
+
+        void aliveProc(LIRInstruction op, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+            assert !isVariable(value) && flags.contains(OperandFlag.UNINITIALIZED) : String.format("SpillMoveFactory: Instruction %s is not allowed to contain operand %s of mode %s", op, value, mode);
+            aliveCount++;
+        }
+
+        void inputProc(LIRInstruction op, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+            assert value.equals(input) : String.format("SpillMoveFactory: Instruction %s can only have %s as input, got %s", op, input, value);
+            inputCount++;
+        }
+
+        void outputProc(LIRInstruction op, Value value, OperandMode mode, EnumSet<OperandFlag> flags) {
+            assert value.equals(result) : String.format("SpillMoveFactory: Instruction %s can only have %s as input, got %s", op, input, value);
+            outputCount++;
+        }
+    }
+
+    /** Checks that the instructions adheres to the contract of {@link SpillMoveFactory}. */
+    private static boolean checkResult(LIRInstruction inst, AllocatableValue result, Value input) {
+
+        SpillMoveFactoryBase.CheckClosure c = new CheckClosure(result, input);
+        inst.visitEachInput(c::inputProc);
+        inst.visitEachOutput(c::outputProc);
+        inst.visitEachAlive(c::aliveProc);
+        inst.visitEachTemp(c::tempProc);
+        inst.visitEachState(c::stateProc);
+
+        assert c.outputCount >= 1 : "no output produced" + inst;
+        assert c.stateCount == 0 : "SpillMoveFactory: instruction must not have a state: " + inst;
+        return true;
+    }
+}