# HG changeset patch # User Josef Eisl # Date 1395849765 -3600 # Node ID 97a0878202c2ede16abcbb35b074b0a8c41e4069 # Parent b7948d5c00923a7beb79b7f9c65b786760e824fb Apply LIRGenerator refactoring to PTX backend. diff -r b7948d5c0092 -r 97a0878202c2 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Wed Mar 26 17:02:13 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Wed Mar 26 17:02:45 2014 +0100 @@ -29,13 +29,10 @@ import static com.oracle.graal.lir.ptx.PTXBitManipulationOp.IntrinsicOpcode.*; import static com.oracle.graal.lir.ptx.PTXCompare.*; -import java.lang.reflect.*; - import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; import com.oracle.graal.compiler.gen.*; -import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.StandardOp.JumpOp; @@ -63,9 +60,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.calc.FloatConvertNode.FloatConvert; -import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.util.*; @@ -90,8 +85,8 @@ } } - public PTXLIRGenerator(StructuredGraph graph, Providers providers, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(graph, providers, cc, lirGenRes); + public PTXLIRGenerator(Providers providers, CallingConvention cc, LIRGenerationResult lirGenRes) { + super(providers, cc, lirGenRes); lirGenRes.getLIR().setSpillMoveFactory(new PTXSpillMoveFactory()); int callVariables = cc.getArgumentCount() + (cc.getReturn().equals(Value.ILLEGAL) ? 0 : 1); lirGenRes.getLIR().setFirstVariableNumber(callVariables); @@ -135,86 +130,6 @@ return value; } - @Override - public void emitPrologue(StructuredGraph graph) { - // Need to emit .param directives based on incoming arguments and return value - CallingConvention incomingArguments = getCallingConvention(); - Object returnObject = incomingArguments.getReturn(); - AllocatableValue[] params = incomingArguments.getArguments(); - int argCount = incomingArguments.getArgumentCount(); - - if (returnObject.equals(Value.ILLEGAL)) { - params = incomingArguments.getArguments(); - append(new PTXParameterOp(params, false)); - } else { - argCount = incomingArguments.getArgumentCount(); - params = new Variable[argCount + 1]; - for (int i = 0; i < argCount; i++) { - params[i] = incomingArguments.getArgument(i); - } - params[argCount] = (Variable) returnObject; - append(new PTXParameterOp(params, true)); - } - - for (ParameterNode param : graph.getNodes(ParameterNode.class)) { - int localIndex = param.index(); - Value paramValue = params[param.index()]; - int parameterIndex = localIndex; - if (!Modifier.isStatic(graph.method().getModifiers())) { - parameterIndex--; - } - Warp warpAnnotation = parameterIndex >= 0 ? MetaUtil.getParameterAnnotation(Warp.class, parameterIndex, graph.method()) : null; - if (warpAnnotation != null) { - setResult(param, emitWarpParam(paramValue.getKind().getStackKind(), warpAnnotation)); - } else { - setResult(param, emitLoadParam(paramValue.getKind().getStackKind(), paramValue, null)); - } - } - } - - @Override - protected > void emitPrologue(ResolvedJavaMethod method, BytecodeParser parser) { - // Need to emit .param directives based on incoming arguments and return value - CallingConvention incomingArguments = getCallingConvention(); - Object returnObject = incomingArguments.getReturn(); - AllocatableValue[] params = incomingArguments.getArguments(); - int argCount = incomingArguments.getArgumentCount(); - - if (returnObject.equals(Value.ILLEGAL)) { - params = incomingArguments.getArguments(); - append(new PTXParameterOp(params, false)); - } else { - argCount = incomingArguments.getArgumentCount(); - params = new Variable[argCount + 1]; - for (int i = 0; i < argCount; i++) { - params[i] = incomingArguments.getArgument(i); - } - params[argCount] = (Variable) returnObject; - append(new PTXParameterOp(params, true)); - } - - Signature sig = method.getSignature(); - boolean isStatic = Modifier.isStatic(method.getModifiers()); - - for (int i = 0; i < sig.getParameterCount(!isStatic); i++) { - Value paramValue = params[i]; - int parameterIndex = i; - if (!isStatic) { - parameterIndex--; - } - Warp warpAnnotation = parameterIndex >= 0 ? MetaUtil.getParameterAnnotation(Warp.class, parameterIndex, method) : null; - if (warpAnnotation != null) { - // setResult(param, emitWarpParam(paramValue.getKind().getStackKind(), - // warpAnnotation)); - parser.setParameter(i, emitWarpParam(paramValue.getKind().getStackKind(), warpAnnotation)); - } else { - // setResult(param, emitLoadParam(paramValue.getKind().getStackKind(), paramValue, - // null)); - parser.setParameter(i, emitLoadParam(paramValue.getKind().getStackKind(), paramValue, null)); - } - } - } - public Variable emitWarpParam(Kind kind, Warp annotation) { Variable result = newVariable(kind); Variable tid = newVariable(Kind.Char); @@ -577,12 +492,6 @@ } @Override - protected boolean peephole(ValueNode valueNode) { - // No peephole optimizations for now - return false; - } - - @Override public Value emitDiv(Value a, Value b, DeoptimizingNode deopting) { Variable result = newVariable(a.getKind()); switch (a.getKind()) { @@ -849,16 +758,6 @@ } @Override - protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitDirectCall()"); - } - - @Override - protected void emitIndirectCall(IndirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitIndirectCall()"); - } - - @Override protected void emitForeignCall(ForeignCallLinkage callTarget, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { throw GraalInternalError.unimplemented("PTXLIRGenerator.emitForeignCall()"); } @@ -924,11 +823,11 @@ } @Override - protected void emitReturn(Value input) { + public void emitReturn(Value input) { append(new ReturnOp(input)); } - private void emitReturnNoVal() { + void emitReturnNoVal() { append(new ReturnNoValOp()); } @@ -947,38 +846,10 @@ } @Override - public void visitCompareAndSwap(LoweredCompareAndSwapNode node, Value address) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.visitCompareAndSwap()"); - } - - @Override - public void visitBreakpointNode(BreakpointNode node) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.visitBreakpointNode()"); - } - - @Override - public void visitSafepointNode(SafepointNode i) { - // LIRFrameState info = state(i); - // append(new PTXSafepointOp(info, runtime().config, this)); - Debug.log("visitSafePointNode unimplemented"); - } - - @Override public void emitUnwind(Value operand) { throw GraalInternalError.unimplemented("PTXLIRGenerator.emitUnwind()"); } - @Override - public void emitNullCheck(ValueNode v, DeoptimizingNode deopting) { - assert v.getKind() == Kind.Object; - append(new PTXMove.NullCheckOp(load(operand(v)), state(deopting))); - } - - @Override - public void visitInfopointNode(InfopointNode i) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.visitInfopointNode()"); - } - public Variable emitLoadParam(Kind kind, Value address, DeoptimizingNode deopting) { PTXAddressValue loadAddress = asAddress(address); @@ -1023,16 +894,4 @@ return (new Variable(kind, 0)); } - @Override - public void visitReturn(ReturnNode x) { - AllocatableValue operand = Value.ILLEGAL; - if (x.result() != null) { - operand = resultOperandFor(x.result().getKind()); - // Load the global memory address from return parameter - Variable loadVar = emitLoadReturnAddress(operand.getKind(), operand, null); - // Store result in global memory whose location is loadVar - emitStoreReturnValue(operand.getKind(), loadVar, operand(x.result()), null); - } - emitReturnNoVal(); - } } diff -r b7948d5c0092 -r 97a0878202c2 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXNodeLIRGenerator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXNodeLIRGenerator.java Wed Mar 26 17:02:45 2014 +0100 @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2013, 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.ptx; + +import java.lang.reflect.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.debug.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.lir.*; +import com.oracle.graal.lir.ptx.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.cfg.*; +import com.oracle.graal.nodes.java.*; + +/** + * This class implements the PTX specific portion of the LIR generator. + */ +public class PTXNodeLIRGenerator extends NodeLIRGenerator { + + // Number of the predicate register that can be used when needed. + // This value will be recorded and incremented in the LIR instruction + // that sets a predicate register. (e.g., CompareOp) + private int nextPredRegNum; + + public static final ForeignCallDescriptor ARITHMETIC_FREM = new ForeignCallDescriptor("arithmeticFrem", float.class, float.class, float.class); + public static final ForeignCallDescriptor ARITHMETIC_DREM = new ForeignCallDescriptor("arithmeticDrem", double.class, double.class, double.class); + + public static class PTXSpillMoveFactory implements LIR.SpillMoveFactory { + + @Override + public LIRInstruction createMove(AllocatableValue result, Value input) { + throw GraalInternalError.unimplemented("PTXSpillMoveFactory.createMove()"); + } + } + + public PTXNodeLIRGenerator(StructuredGraph graph, LIRGenerationResult lirGenRes, LIRGenerator lirGen) { + super(graph, lirGenRes, lirGen); + } + + public int getNextPredRegNumber() { + return nextPredRegNum; + } + + @Override + public void emitPrologue(StructuredGraph graph) { + // Need to emit .param directives based on incoming arguments and return value + CallingConvention incomingArguments = gen.getCallingConvention(); + Object returnObject = incomingArguments.getReturn(); + AllocatableValue[] params = incomingArguments.getArguments(); + int argCount = incomingArguments.getArgumentCount(); + + if (returnObject.equals(Value.ILLEGAL)) { + params = incomingArguments.getArguments(); + append(new PTXParameterOp(params, false)); + } else { + argCount = incomingArguments.getArgumentCount(); + params = new Variable[argCount + 1]; + for (int i = 0; i < argCount; i++) { + params[i] = incomingArguments.getArgument(i); + } + params[argCount] = (Variable) returnObject; + append(new PTXParameterOp(params, true)); + } + + for (ParameterNode param : graph.getNodes(ParameterNode.class)) { + int localIndex = param.index(); + Value paramValue = params[param.index()]; + int parameterIndex = localIndex; + if (!Modifier.isStatic(graph.method().getModifiers())) { + parameterIndex--; + } + Warp warpAnnotation = parameterIndex >= 0 ? MetaUtil.getParameterAnnotation(Warp.class, parameterIndex, graph.method()) : null; + if (warpAnnotation != null) { + setResult(param, getGen().emitWarpParam(paramValue.getKind().getStackKind(), warpAnnotation)); + } else { + setResult(param, getGen().emitLoadParam(paramValue.getKind().getStackKind(), paramValue, null)); + } + } + } + + private PTXLIRGenerator getGen() { + return (PTXLIRGenerator) gen; + } + + @Override + protected > void emitPrologue(ResolvedJavaMethod method, BytecodeParser parser) { + // Need to emit .param directives based on incoming arguments and return value + CallingConvention incomingArguments = gen.getCallingConvention(); + Object returnObject = incomingArguments.getReturn(); + AllocatableValue[] params = incomingArguments.getArguments(); + int argCount = incomingArguments.getArgumentCount(); + + if (returnObject.equals(Value.ILLEGAL)) { + params = incomingArguments.getArguments(); + append(new PTXParameterOp(params, false)); + } else { + argCount = incomingArguments.getArgumentCount(); + params = new Variable[argCount + 1]; + for (int i = 0; i < argCount; i++) { + params[i] = incomingArguments.getArgument(i); + } + params[argCount] = (Variable) returnObject; + append(new PTXParameterOp(params, true)); + } + + Signature sig = method.getSignature(); + boolean isStatic = Modifier.isStatic(method.getModifiers()); + + for (int i = 0; i < sig.getParameterCount(!isStatic); i++) { + Value paramValue = params[i]; + int parameterIndex = i; + if (!isStatic) { + parameterIndex--; + } + Warp warpAnnotation = parameterIndex >= 0 ? MetaUtil.getParameterAnnotation(Warp.class, parameterIndex, method) : null; + if (warpAnnotation != null) { + // setResult(param, emitWarpParam(paramValue.getKind().getStackKind(), + // warpAnnotation)); + parser.setParameter(i, getGen().emitWarpParam(paramValue.getKind().getStackKind(), warpAnnotation)); + } else { + // setResult(param, emitLoadParam(paramValue.getKind().getStackKind(), paramValue, + // null)); + parser.setParameter(i, getGen().emitLoadParam(paramValue.getKind().getStackKind(), paramValue, null)); + } + } + } + + @Override + protected boolean peephole(ValueNode valueNode) { + // No peephole optimizations for now + return false; + } + + @Override + protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { + throw GraalInternalError.unimplemented("PTXLIRGenerator.emitDirectCall()"); + } + + @Override + protected void emitIndirectCall(IndirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { + throw GraalInternalError.unimplemented("PTXLIRGenerator.emitIndirectCall()"); + } + + @Override + public void visitCompareAndSwap(LoweredCompareAndSwapNode node, Value address) { + throw GraalInternalError.unimplemented("PTXLIRGenerator.visitCompareAndSwap()"); + } + + @Override + public void visitBreakpointNode(BreakpointNode node) { + throw GraalInternalError.unimplemented("PTXLIRGenerator.visitBreakpointNode()"); + } + + @Override + public void visitSafepointNode(SafepointNode i) { + // LIRFrameState info = state(i); + // append(new PTXSafepointOp(info, runtime().config, this)); + Debug.log("visitSafePointNode unimplemented"); + } + + @Override + public void emitNullCheck(ValueNode v, DeoptimizingNode deopting) { + assert v.getKind() == Kind.Object; + append(new PTXMove.NullCheckOp(gen.load(operand(v)), state(deopting))); + } + + @Override + public void visitInfopointNode(InfopointNode i) { + throw GraalInternalError.unimplemented("PTXLIRGenerator.visitInfopointNode()"); + } + + @Override + public void visitReturn(ReturnNode x) { + AllocatableValue operand = Value.ILLEGAL; + if (x.result() != null) { + operand = gen.resultOperandFor(x.result().getKind()); + // Load the global memory address from return parameter + Variable loadVar = getGen().emitLoadReturnAddress(operand.getKind(), operand, null); + // Store result in global memory whose location is loadVar + getGen().emitStoreReturnValue(operand.getKind(), loadVar, operand(x.result()), null); + } + getGen().emitReturnNoVal(); + } +} diff -r b7948d5c0092 -r 97a0878202c2 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Wed Mar 26 17:02:13 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Wed Mar 26 17:02:45 2014 +0100 @@ -352,8 +352,13 @@ } @Override - public LIRGenerator newLIRGenerator(StructuredGraph graph, CallingConvention cc, LIRGenerationResult lirGenRes) { - return new PTXHotSpotLIRGenerator(graph, getProviders(), getRuntime().getConfig(), cc, lirGenRes); + public LIRGenerator newLIRGenerator(CallingConvention cc, LIRGenerationResult lirGenRes) { + return new PTXHotSpotLIRGenerator(getProviders(), getRuntime().getConfig(), cc, lirGenRes); + } + + @Override + public NodeLIRGenerator newNodeLIRGenerator(StructuredGraph graph, LIRGenerationResult lirGenRes, LIRGenerator lirGen) { + return new PTXHotSpotNodeLIRGenerator(graph, lirGenRes, lirGen); } private static void emitKernelEntry(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod codeCacheOwner) { diff -r b7948d5c0092 -r 97a0878202c2 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLIRGenerator.java Wed Mar 26 17:02:13 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLIRGenerator.java Wed Mar 26 17:02:45 2014 +0100 @@ -30,23 +30,17 @@ import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.*; /** * LIR generator specialized for PTX HotSpot. */ public class PTXHotSpotLIRGenerator extends PTXLIRGenerator implements HotSpotLIRGenerator { - protected PTXHotSpotLIRGenerator(StructuredGraph graph, HotSpotProviders providers, HotSpotVMConfig config, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(graph, providers, cc, lirGenRes); + protected PTXHotSpotLIRGenerator(HotSpotProviders providers, HotSpotVMConfig config, CallingConvention cc, LIRGenerationResult lirGenRes) { + super(providers, cc, lirGenRes); assert config.basicLockSize == 8; } - public void emitPrefetchAllocate(ValueNode address, ValueNode distance) { - // nop - } - public void emitTailcall(Value[] args, Value address) { throw GraalInternalError.unimplemented(); } @@ -55,18 +49,6 @@ throw GraalInternalError.unimplemented(); } - public void emitPatchReturnAddress(ValueNode address) { - throw GraalInternalError.unimplemented(); - } - - public void emitJumpToExceptionHandlerInCaller(ValueNode handlerInCallerPc, ValueNode exception, ValueNode exceptionPc) { - throw GraalInternalError.unimplemented(); - } - - public void visitDirectCompareAndSwap(DirectCompareAndSwapNode x) { - throw GraalInternalError.unimplemented(); - } - public StackSlot getLockSlot(int lockDepth) { throw GraalInternalError.unimplemented(); } diff -r b7948d5c0092 -r 97a0878202c2 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotNodeLIRGenerator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotNodeLIRGenerator.java Wed Mar 26 17:02:45 2014 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 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.hotspot.ptx; + +import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.ptx.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.nodes.*; +import com.oracle.graal.nodes.*; + +/** + * LIR generator specialized for PTX HotSpot. + */ +public class PTXHotSpotNodeLIRGenerator extends PTXNodeLIRGenerator implements HotSpotNodeLIRGenerator { + + protected PTXHotSpotNodeLIRGenerator(StructuredGraph graph, LIRGenerationResult lirGenRes, LIRGenerator lirGen) { + super(graph, lirGenRes, lirGen); + } + + public void emitPrefetchAllocate(ValueNode address, ValueNode distance) { + // nop + } + + public void emitPatchReturnAddress(ValueNode address) { + throw GraalInternalError.unimplemented(); + } + + public void emitJumpToExceptionHandlerInCaller(ValueNode handlerInCallerPc, ValueNode exception, ValueNode exceptionPc) { + throw GraalInternalError.unimplemented(); + } + + public void visitDirectCompareAndSwap(DirectCompareAndSwapNode x) { + throw GraalInternalError.unimplemented(); + } + +}