# HG changeset patch # User Christian Wimmer # Date 1363660124 25200 # Node ID 55ef03d64f0361be590b35de675e582a7bcca5bc # Parent 98b90a7bb764c9a2eaec524b5f3b8a94da2f4401 Generalize read and write of fixed register for snippets. Move to HotSpot-independent project. diff -r 98b90a7bb764 -r 55ef03d64f03 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Mon Mar 18 19:21:01 2013 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Mon Mar 18 19:28:44 2013 -0700 @@ -467,7 +467,7 @@ } } - append(new ParametersOp(params)); + emitIncomingValues(params); for (LocalNode local : graph.getNodes(LocalNode.class)) { Value param = params[local.index()]; @@ -476,6 +476,10 @@ } } + public void emitIncomingValues(Value[] params) { + append(new ParametersOp(params)); + } + /** * Increases the number of currently locked monitors and makes sure that a lock data slot is * available for the new lock. diff -r 98b90a7bb764 -r 55ef03d64f03 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/RegisterNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/RegisterNode.java Mon Mar 18 19:21:01 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2012, 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.nodes; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; - -/** - * Access the value of a specific register. - */ -@NodeInfo(nameTemplate = "Register %{p#register}") -public final class RegisterNode extends FixedWithNextNode implements LIRLowerable { - - private final Register register; - - public RegisterNode(Register register, Kind kind) { - super(StampFactory.forKind(kind)); - this.register = register; - } - - public RegisterNode(Register register) { - super(StampFactory.object()); - this.register = register; - } - - @Override - public void generate(LIRGeneratorTool generator) { - Value result; - if (generator.attributes(register).isAllocatable()) { - // The register allocator would prefer us not to tie up an allocatable - // register for the complete lifetime of this node. - result = generator.newVariable(kind()); - generator.emitMove(result, register.asValue(kind())); - } else { - result = register.asValue(kind()); - } - generator.setResult(this, result); - } - - @Override - public String toString(Verbosity verbosity) { - if (verbosity == Verbosity.Name) { - return super.toString(Verbosity.Name) + "%" + register; - } else { - return super.toString(verbosity); - } - } -} diff -r 98b90a7bb764 -r 55ef03d64f03 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Mar 18 19:21:01 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Mar 18 19:28:44 2013 -0700 @@ -34,6 +34,7 @@ import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.snippets.Snippet.Fold; +import com.oracle.graal.snippets.nodes.*; import com.oracle.graal.word.*; //JaCoCo Exclude @@ -338,22 +339,22 @@ * Gets the value of the stack pointer register as a Word. */ public static Word stackPointer() { - return HotSpotSnippetUtils.registerAsWord(stackPointerRegister()); + return HotSpotSnippetUtils.registerAsWord(stackPointerRegister(), true, false); } /** * Gets the value of the thread register as a Word. */ public static Word thread() { - return HotSpotSnippetUtils.registerAsWord(threadRegister()); + return HotSpotSnippetUtils.registerAsWord(threadRegister(), true, false); } public static Word loadWordFromObject(Object object, int offset) { return loadWordFromObjectIntrinsic(object, 0, offset, wordKind()); } - @NodeIntrinsic(value = RegisterNode.class, setStampFromReturnType = true) - public static native Word registerAsWord(@ConstantNodeParameter Register register); + @NodeIntrinsic(value = ReadRegisterNode.class, setStampFromReturnType = true) + public static native Word registerAsWord(@ConstantNodeParameter Register register, @ConstantNodeParameter boolean directUse, @ConstantNodeParameter boolean incoming); @NodeIntrinsic(value = UnsafeLoadNode.class, setStampFromReturnType = true) private static native Word loadWordFromObjectIntrinsic(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind wordKind); diff -r 98b90a7bb764 -r 55ef03d64f03 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/ReadRegisterNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/ReadRegisterNode.java Mon Mar 18 19:28:44 2013 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 2013, 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.snippets.nodes; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.target.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; + +/** + * Access the value of a specific register. + */ +@NodeInfo(nameTemplate = "ReadRegister %{p#register}") +public final class ReadRegisterNode extends FixedWithNextNode implements LIRGenLowerable { + + /** + * The fixed register to access. + */ + private final Register register; + + /** + * When true, subsequent uses of this node use the fixed register; when false, the value is + * moved into a new virtual register so that the fixed register is not seen by uses. + */ + private final boolean directUse; + + /** + * When true, this node is also an implicit definition of the value for the register allocator, + * i.e., the register is an implicit incoming value; when false, the register must be defined in + * the same method or must be an register excluded from register allocation. + */ + private final boolean incoming; + + public ReadRegisterNode(Register register, Kind kind, boolean directUse, boolean incoming) { + super(StampFactory.forKind(kind)); + this.register = register; + this.directUse = directUse; + this.incoming = incoming; + } + + /** + * Constructor to be used by node intrinsics where the stamp is inferred from the intrinsic + * definition. + */ + public ReadRegisterNode(Register register, boolean directUse, boolean incoming) { + super(StampFactory.forNodeIntrinsic()); + this.register = register; + this.directUse = directUse; + this.incoming = incoming; + } + + @Override + public void generate(LIRGenerator generator) { + Value result = register.asValue(kind()); + if (incoming) { + generator.emitIncomingValues(new Value[]{result}); + } + if (!directUse) { + result = generator.emitMove(result); + } + generator.setResult(this, result); + } + + @Override + public String toString(Verbosity verbosity) { + if (verbosity == Verbosity.Name) { + return super.toString(Verbosity.Name) + "%" + register; + } else { + return super.toString(verbosity); + } + } +} diff -r 98b90a7bb764 -r 55ef03d64f03 graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/WriteRegisterNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/WriteRegisterNode.java Mon Mar 18 19:28:44 2013 -0700 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 2013, 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.snippets.nodes; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; + +/** + * Changes the value of a specific register. + */ +@NodeInfo(nameTemplate = "WriteRegister %{p#register}") +public final class WriteRegisterNode extends FixedWithNextNode implements LIRLowerable { + + /** + * The fixed register to access. + */ + private final Register register; + + /** + * The new value assigned to the register. + */ + @Input private ValueNode value; + + public WriteRegisterNode(Register register, ValueNode value) { + super(StampFactory.forVoid()); + this.register = register; + this.value = value; + } + + @Override + public void generate(LIRGeneratorTool generator) { + Value val = generator.operand(value); + generator.emitMove(val, register.asValue(val.getKind())); + } + + @Override + public String toString(Verbosity verbosity) { + if (verbosity == Verbosity.Name) { + return super.toString(Verbosity.Name) + "%" + register; + } else { + return super.toString(verbosity); + } + } +}