# HG changeset patch # User Josef Eisl # Date 1398242395 -7200 # Node ID 71cdf5518dab1e464d7ecb6c99f3a298c9caa511 # Parent cc0dde80d6df4efc4d994b2bd09fe141f8bfb0e1 Use LIRGeneratorTool in NodeLIRBuilder. diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java Wed Apr 23 09:57:00 2014 +0200 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64MemoryPeephole.java Wed Apr 23 10:39:55 2014 +0200 @@ -77,7 +77,7 @@ } protected Kind getMemoryKind(Access access) { - return (Kind) gen.getLIRGenerator().getPlatformKind(access.asNode().stamp()); + return (Kind) gen.getLIRGeneratorTool().getPlatformKind(access.asNode().stamp()); } protected AMD64AddressValue makeAddress(Access access) { @@ -94,7 +94,7 @@ } } ensureEvaluated(other); - return gen.getLIRGenerator().emitBinaryMemory(op, getMemoryKind(access), gen.getLIRGeneratorTool().asAllocatable(gen.operand(other)), makeAddress(access), getState(access)); + return gen.getLIRGeneratorTool().emitBinaryMemory(op, getMemoryKind(access), gen.getLIRGeneratorTool().asAllocatable(gen.operand(other)), makeAddress(access), getState(access)); } /** @@ -128,7 +128,7 @@ AMD64AddressValue address = makeAddress(access); LIRFrameState state = getState(access); evaluateDeferred(); - return gen.getLIRGenerator().emitConvert2MemoryOp(kind, op, address, state); + return gen.getLIRGeneratorTool().emitConvert2MemoryOp(kind, op, address, state); } @Override @@ -252,7 +252,7 @@ @Override public Value emitReinterpretMemory(Stamp stamp, Access access) { - PlatformKind to = gen.getLIRGenerator().getPlatformKind(stamp); + PlatformKind to = gen.getLIRGeneratorTool().getPlatformKind(stamp); Kind from = getMemoryKind(access); assert to != from : "should have been eliminated"; @@ -370,7 +370,7 @@ memoryKind = Kind.Char; } evaluateDeferred(); - return gen.getLIRGenerator().emitZeroExtendMemory(memoryKind, toBits, makeAddress(access), getState(access)); + return gen.getLIRGeneratorTool().emitZeroExtendMemory(memoryKind, toBits, makeAddress(access), getState(access)); } public boolean emitIfMemory(IfNode x, Access access) { @@ -463,7 +463,7 @@ } } ensureEvaluated(other); - gen.getLIRGenerator().emitCompareMemoryConOp(kind, makeAddress(access), constant, getState(access)); + gen.getLIRGeneratorTool().emitCompareMemoryConOp(kind, makeAddress(access), constant, getState(access)); mirrored = uncast(right) == access; } else { if (kind == Kind.Object) { @@ -473,7 +473,7 @@ } evaluateDeferred(); - gen.getLIRGenerator().emitCompareRegMemoryOp(kind, gen.operand(other), makeAddress(access), getState(access)); + gen.getLIRGeneratorTool().emitCompareRegMemoryOp(kind, gen.operand(other), makeAddress(access), getState(access)); mirrored = uncast(left) == access; } diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Wed Apr 23 09:57:00 2014 +0200 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64NodeLIRBuilder.java Wed Apr 23 10:39:55 2014 +0200 @@ -108,7 +108,7 @@ } @Override - public AMD64LIRGenerator getLIRGenerator() { + public AMD64LIRGenerator getLIRGeneratorTool() { return (AMD64LIRGenerator) gen; } } diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java Wed Apr 23 09:57:00 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java Wed Apr 23 10:39:55 2014 +0200 @@ -58,7 +58,7 @@ private final NodeMap nodeOperands; private final DebugInfoBuilder debugInfoBuilder; - protected final LIRGenerator gen; + protected final LIRGeneratorTool gen; private ValueNode currentInstruction; private ValueNode lastInstructionPrinted; // Debugging only @@ -725,11 +725,7 @@ } @Override - public LIRGenerator getLIRGeneratorTool() { - return gen; - } - - public LIRGenerator getLIRGenerator() { + public LIRGeneratorTool getLIRGeneratorTool() { return gen; } } diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/PhiResolver.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/PhiResolver.java Wed Apr 23 09:57:00 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/PhiResolver.java Wed Apr 23 10:39:55 2014 +0200 @@ -34,18 +34,18 @@ /** * Converts {@link ValuePhiNode} instructions into moves. - * + * * Resolves cycles: - * + * *
- * 
+ *
  *  r1 := r2  becomes  temp := r1
  *  r2 := r1           r1 := r2
  *                     r2 := temp
  * 
- * + * * and orders moves: - * + * *
  *  r2 := r3  becomes  r1 := r2
  *  r1 := r2           r2 := r3
@@ -104,7 +104,7 @@
         }
     }
 
-    private final LIRGenerator gen;
+    private final LIRGeneratorTool gen;
 
     /**
      * The operand loop header phi for the operand currently being process in {@link #dispose()}.
@@ -121,7 +121,7 @@
      */
     private final HashMap operandToNodeMap = new HashMap<>();
 
-    public PhiResolver(LIRGenerator gen) {
+    public PhiResolver(LIRGeneratorTool gen) {
         this.gen = gen;
         temp = ILLEGAL;
     }
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMemoryPeephole.java
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMemoryPeephole.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMemoryPeephole.java	Wed Apr 23 10:39:55 2014 +0200
@@ -85,7 +85,7 @@
 
     @Override
     protected Kind getMemoryKind(Access access) {
-        PlatformKind kind = gen.getLIRGenerator().getPlatformKind(access.asNode().stamp());
+        PlatformKind kind = gen.getLIRGeneratorTool().getPlatformKind(access.asNode().stamp());
         if (kind == NarrowOopStamp.NarrowOop) {
             return Kind.Int;
         } else {
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64RawNativeCallNode.java
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64RawNativeCallNode.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64RawNativeCallNode.java	Wed Apr 23 10:39:55 2014 +0200
@@ -55,7 +55,7 @@
         ResolvedJavaType returnType = stamp().javaType(gen.getLIRGeneratorTool().getMetaAccess());
         CallingConvention cc = generator.getLIRGeneratorTool().getCodeCache().getRegisterConfig().getCallingConvention(Type.NativeCall, returnType, parameterTypes,
                         generator.getLIRGeneratorTool().target(), false);
-        ((AMD64LIRGenerator) gen.getLIRGeneratorTool()).emitCCall(functionPointer.asLong(), cc, parameter, countFloatingTypeArguments(args));
+        gen.getLIRGeneratorTool().emitCCall(functionPointer.asLong(), cc, parameter, countFloatingTypeArguments(args));
         if (this.getKind() != Kind.Void) {
             generator.setResult(this, gen.getLIRGeneratorTool().emitMove(cc.getReturn()));
         }
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/NewArrayStubCall.java	Wed Apr 23 10:39:55 2014 +0200
@@ -63,7 +63,7 @@
     @Override
     public void generate(NodeLIRBuilder gen) {
         ForeignCallLinkage linkage = gen.getLIRGeneratorTool().getForeignCalls().lookupForeignCall(NEW_ARRAY);
-        Variable result = gen.getLIRGenerator().emitForeignCall(linkage, gen.state(this), gen.operand(hub), gen.operand(length));
+        Variable result = gen.getLIRGeneratorTool().emitForeignCall(linkage, gen.state(this), gen.operand(hub), gen.operand(length));
         gen.setResult(this, result);
     }
 
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java	Wed Apr 23 10:39:55 2014 +0200
@@ -48,7 +48,7 @@
 /**
  * This class traverses the HIR instructions and generates LIR instructions from them.
  */
-public abstract class LIRGenerator implements ArithmeticLIRGenerator, LIRGeneratorTool, PlatformKindTool {
+public abstract class LIRGenerator implements LIRGeneratorTool, PlatformKindTool {
 
     public static class Options {
         // @formatter:off
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java	Wed Apr 23 10:39:55 2014 +0200
@@ -22,13 +22,21 @@
  */
 package com.oracle.graal.lir.gen;
 
+import java.util.*;
+
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.compiler.common.calc.*;
+import com.oracle.graal.compiler.common.cfg.*;
+import com.oracle.graal.compiler.common.spi.*;
 import com.oracle.graal.lir.*;
+import com.oracle.graal.lir.gen.LIRGenerator.*;
 
 public interface LIRGeneratorTool extends ArithmeticLIRGenerator {
 
+    CodeGenProviders getProviders();
+
     TargetDescription target();
 
     MetaAccessProvider getMetaAccess();
@@ -37,6 +45,20 @@
 
     ForeignCallsProvider getForeignCalls();
 
+    AbstractBlock getCurrentBlock();
+
+    LIRGenerationResult getResult();
+
+    boolean hasBlockEnd(AbstractBlock block);
+
+    void doBlockStart(AbstractBlock block);
+
+    void doBlockEnd(AbstractBlock block);
+
+    Map getConstantLoads();
+
+    void setConstantLoads(Map constantLoads);
+
     Value emitLoad(PlatformKind kind, Value address, LIRFrameState state);
 
     void emitStore(PlatformKind kind, Value address, Value input, LIRFrameState state);
@@ -65,7 +87,7 @@
 
     void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state);
 
-    Value emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args);
+    Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args);
 
     /**
      * Checks whether the supplied constant can be used without loading it into a register for most
@@ -81,9 +103,9 @@
 
     RegisterAttributes attributes(Register register);
 
-    AllocatableValue newVariable(PlatformKind kind);
+    Variable newVariable(PlatformKind kind);
 
-    AllocatableValue emitMove(Value input);
+    Variable emitMove(Value input);
 
     void emitMove(AllocatableValue dst, Value src);
 
@@ -116,4 +138,62 @@
      * correct location.
      */
     void emitReturn(Value input);
+
+    AllocatableValue asAllocatable(Value value);
+
+    Variable load(Value value);
+
+    Value loadNonConst(Value value);
+
+    /**
+     * Returns true if the redundant move elimination optimization should be done after register
+     * allocation.
+     */
+    boolean canEliminateRedundantMoves();
+
+    /**
+     * Determines if only oop maps are required for the code generated from the LIR.
+     */
+    boolean needOnlyOopMaps();
+
+    /**
+     * Gets the ABI specific operand used to return a value of a given kind from a method.
+     *
+     * @param kind the kind of value being returned
+     * @return the operand representing the ABI defined location used return a value of kind
+     *         {@code kind}
+     */
+    AllocatableValue resultOperandFor(Kind kind);
+
+    void append(LIRInstruction op);
+
+    void emitJump(LabelRef label);
+
+    void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
+                    double trueDestinationProbability);
+
+    void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, double overflowProbability);
+
+    void emitIntegerTestBranch(Value left, Value right, LabelRef trueDestination, LabelRef falseDestination, double trueSuccessorProbability);
+
+    Variable emitConditionalMove(PlatformKind cmpKind, Value leftVal, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue);
+
+    Variable emitIntegerTestMove(Value leftVal, Value right, Value trueValue, Value falseValue);
+
+    void emitStrategySwitch(Constant[] keyConstants, double[] keyProbabilities, LabelRef[] keyTargets, LabelRef defaultTarget, Variable value);
+
+    void emitStrategySwitch(SwitchStrategy strategy, Variable key, LabelRef[] keyTargets, LabelRef defaultTarget);
+
+    CallingConvention getCallingConvention();
+
+    void emitBitCount(Variable result, Value operand);
+
+    void emitBitScanForward(Variable result, Value operand);
+
+    void emitBitScanReverse(Variable result, Value operand);
+
+    void emitByteSwap(Variable result, Value operand);
+
+    void emitArrayEquals(Kind kind, Variable result, Value array1, Value array2, Value length);
+
 }
diff -r cc0dde80d6df -r 71cdf5518dab graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java	Wed Apr 23 09:57:00 2014 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java	Wed Apr 23 10:39:55 2014 +0200
@@ -68,7 +68,7 @@
     @Override
     public void generate(NodeLIRBuilder gen) {
         Variable result = gen.newVariable(value.getKind());
-        gen.getLIRGenerator().emitByteSwap(result, gen.operand(value));
+        gen.getLIRGeneratorTool().emitByteSwap(result, gen.operand(value));
         gen.setResult(this, result);
     }
 }