changeset 14822:39daeb102dce

Baseline compiler emitPrologue.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 19 Mar 2014 17:07:22 +0100
parents 71ec7648c56c
children 9fbc1a798558
files graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/BaselineLIRGenerator.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGeneratorCommon.java
diffstat 4 files changed, 80 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java	Wed Mar 19 15:26:44 2014 +0100
+++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineCompiler.java	Wed Mar 19 17:07:22 2014 +0100
@@ -106,19 +106,24 @@
         } finally {
             filter.remove();
         }
-        // emitLIR
+        // begin fake cfg
         LIRBlock b = new LIRBlock(0);
         LIRBlock[] blocks = new LIRBlock[1];
         blocks[0] = b;
 
-        AbstractControlFlowGraph<?> cfg = new LIRControlFlowGraph(blocks, null);
+        AbstractControlFlowGraph<?> cfg = new LIRControlFlowGraph(blocks, new Loop[0]);
+
         BlocksToDoubles blockProbabilities = new BlocksToDoubles(blocks.length);
         blockProbabilities.put(b, 1);
+        // end fake cfg
 
+        // emitLIR
         List<? extends AbstractBlock<?>> linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, b, blockProbabilities);
         List<? extends AbstractBlock<?>> codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, b, blockProbabilities);
         LIR lir = new LIR(cfg, linearScanOrder, codeEmittingOrder);
+
         LIRGenerationResult lirGenRes = null;
+
         try (Scope ds = Debug.scope("BackEnd", lir)) {
             FrameMap frameMap = backend.newFrameMap();
             TargetDescription target = backend.getTarget();
@@ -127,7 +132,9 @@
             LIRGenerator lirGen = backend.newLIRGenerator(null, cc, lirGenRes);
 
             try (Scope s = Debug.scope("LIRGen", lirGen)) {
-                lirGen.doBlock(b);
+                for (AbstractBlock<?> block : linearScanOrder) {
+                    lirGen.doBlock(block, method);
+                }
                 // lirGen.beforeRegisterAllocation();
 
                 Debug.dump(lir, "After LIR generation");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/BaselineLIRGenerator.java	Wed Mar 19 17:07:22 2014 +0100
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 2014, 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.gen;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.nodes.cfg.*;
+
+public interface BaselineLIRGenerator {
+
+    void doBlock(AbstractBlock<?> block, ResolvedJavaMethod method);
+
+}
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Wed Mar 19 15:26:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java	Wed Mar 19 17:07:22 2014 +0100
@@ -29,6 +29,7 @@
 import static com.oracle.graal.nodes.ConstantNode.*;
 import static com.oracle.graal.phases.GraalOptions.*;
 
+import java.lang.reflect.*;
 import java.util.*;
 import java.util.Map.Entry;
 
@@ -57,7 +58,7 @@
 /**
  * This class traverses the HIR instructions and generates LIR instructions from them.
  */
-public abstract class LIRGenerator implements LIRGeneratorTool, LIRTypeTool, LIRGeneratorCommon, NodeBasedLIRGenerator {
+public abstract class LIRGenerator implements LIRGeneratorTool, LIRTypeTool, LIRGeneratorCommon, NodeBasedLIRGenerator, BaselineLIRGenerator {
 
     public static class Options {
         // @formatter:off
@@ -441,8 +442,16 @@
     /**
      * For Baseline compilation
      */
-    public void doBlock(AbstractBlock<?> block) {
+    public void doBlock(AbstractBlock<?> block, ResolvedJavaMethod method) {
         doBlockStart(block);
+
+        if (block == res.getLIR().getControlFlowGraph().getStartBlock()) {
+            assert block.getPredecessorCount() == 0;
+            emitPrologue(method);
+        } else {
+            assert block.getPredecessorCount() > 0;
+        }
+
         // add instruction
         emitAdd(Constant.forLong(42), Constant.forLong(73));
         doBlockEnd(block);
@@ -563,6 +572,33 @@
         }
     }
 
+    protected void emitPrologue(ResolvedJavaMethod method) {
+        CallingConvention incomingArguments = getCallingConvention();
+
+        Value[] params = new Value[incomingArguments.getArgumentCount()];
+        for (int i = 0; i < params.length; i++) {
+            params[i] = toStackKind(incomingArguments.getArgument(i));
+            if (ValueUtil.isStackSlot(params[i])) {
+                StackSlot slot = ValueUtil.asStackSlot(params[i]);
+                if (slot.isInCallerFrame() && !res.getLIR().hasArgInCallerFrame()) {
+                    res.getLIR().setHasArgInCallerFrame();
+                }
+            }
+        }
+
+        emitIncomingValues(params);
+
+        Signature sig = method.getSignature();
+        boolean isStatic = Modifier.isStatic(method.getModifiers());
+
+        for (int i = 0; i < sig.getParameterCount(!isStatic); i++) {
+            Value paramValue = params[i];
+            assert paramValue.getKind() == sig.getParameterKind(i).getStackKind();
+            // TODO setResult(param, emitMove(paramValue));
+            emitMove(paramValue);
+        }
+    }
+
     public void emitIncomingValues(Value[] params) {
         ((LabelOp) res.getLIR().getLIRforBlock(currentBlock).get(0)).setIncomingValues(params);
     }
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGeneratorCommon.java	Wed Mar 19 15:26:44 2014 +0100
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGeneratorCommon.java	Wed Mar 19 17:07:22 2014 +0100
@@ -4,7 +4,6 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.nodes.calc.*;
-import com.oracle.graal.nodes.cfg.*;
 import com.oracle.graal.nodes.type.*;
 
 public interface LIRGeneratorCommon {
@@ -51,8 +50,6 @@
 
     Value loadNonConst(Value value);
 
-    void doBlock(AbstractBlock<?> block);
-
     /**
      * Gets the ABI specific operand used to return a value of a given kind from a method.
      *