# HG changeset patch # User Thomas Wuerthinger # Date 1310140889 -7200 # Node ID da99d8a05d9a3e28790f19f07fddd56417355966 # Parent 3d68684b7161946d4d61a3ea7d31aa087231c5d6 Simplified some of the examples. diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Fri Jul 08 18:01:29 2011 +0200 @@ -45,6 +45,7 @@ import com.oracle.max.graal.compiler.value.*; import com.oracle.max.graal.compiler.value.FrameState.ValueProcedure; import com.oracle.max.graal.graph.*; +import com.sun.cri.bytecode.*; import com.sun.cri.bytecode.Bytecodes.MemoryBarriers; import com.sun.cri.ci.*; import com.sun.cri.ri.*; @@ -1240,6 +1241,10 @@ } } + public void integerAdd(Value result, Value left, Value right) { + arithmeticOpInt(Bytecodes.IADD, createResultVariable(result), load(left), load(right), CiValue.IllegalValue); + } + public void arithmeticOpInt(int code, CiValue result, CiValue left, CiValue right, CiValue tmp) { CiValue leftOp = left; diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerAdd.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerAdd.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerAdd.java Fri Jul 08 18:01:29 2011 +0200 @@ -28,7 +28,7 @@ import com.sun.cri.ci.*; -public final class IntegerAdd extends IntegerArithmetic { +public final class IntegerAdd extends IntegerArithmeticNode { private static final IntegerAddCanonicalizerOp CANONICALIZER = new IntegerAddCanonicalizerOp(); public IntegerAdd(CiKind kind, Value x, Value y, Graph graph) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerArithmetic.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerArithmetic.java Fri Jul 08 13:41:27 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2011, 2011, 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.max.graal.compiler.ir; - -import com.oracle.max.graal.graph.*; -import com.sun.cri.ci.*; - - -public abstract class IntegerArithmetic extends Arithmetic { - - public IntegerArithmetic(CiKind kind, int opcode, Value x, Value y, Graph graph) { - super(kind, opcode, x, y, false, graph); - assert kind == CiKind.Int || kind == CiKind.Long; - } - -} diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerArithmeticNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerArithmeticNode.java Fri Jul 08 18:01:29 2011 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.compiler.ir; + +import com.oracle.max.graal.graph.*; +import com.sun.cri.ci.*; + + +public abstract class IntegerArithmeticNode extends Arithmetic { + + public IntegerArithmeticNode(CiKind kind, int opcode, Value x, Value y, Graph graph) { + super(kind, opcode, x, y, false, graph); + assert kind == CiKind.Int || kind == CiKind.Long; + } + +} diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerDiv.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerDiv.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerDiv.java Fri Jul 08 18:01:29 2011 +0200 @@ -28,7 +28,7 @@ import com.sun.cri.ci.*; -public final class IntegerDiv extends IntegerArithmetic { +public final class IntegerDiv extends IntegerArithmeticNode { private static final IntegerDivCanonicalizerOp CANONICALIZER = new IntegerDivCanonicalizerOp(); public IntegerDiv(CiKind kind, Value x, Value y, Graph graph) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerMul.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerMul.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerMul.java Fri Jul 08 18:01:29 2011 +0200 @@ -28,7 +28,7 @@ import com.sun.cri.ci.*; -public final class IntegerMul extends IntegerArithmetic { +public final class IntegerMul extends IntegerArithmeticNode { private static final IntegerMulCanonicalizerOp CANONICALIZER = new IntegerMulCanonicalizerOp(); public IntegerMul(CiKind kind, Value x, Value y, Graph graph) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerRem.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerRem.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerRem.java Fri Jul 08 18:01:29 2011 +0200 @@ -28,7 +28,7 @@ import com.sun.cri.ci.*; -public final class IntegerRem extends IntegerArithmetic { +public final class IntegerRem extends IntegerArithmeticNode { private static final IntegerRemCanonicalizerOp CANONICALIZER = new IntegerRemCanonicalizerOp(); public IntegerRem(CiKind kind, Value x, Value y, Graph graph) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerSub.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerSub.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/IntegerSub.java Fri Jul 08 18:01:29 2011 +0200 @@ -28,7 +28,7 @@ import com.sun.cri.ci.*; -public final class IntegerSub extends IntegerArithmetic { +public final class IntegerSub extends IntegerArithmeticNode { private static final IntegerSubCanonicalizerOp CANONICALIZER = new IntegerSubCanonicalizerOp(); public IntegerSub(CiKind kind, Value x, Value y, Graph graph) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Fri Jul 08 18:01:29 2011 +0200 @@ -352,9 +352,9 @@ for (InliningGuide guide : serviceLoader) { InliningHint hint = guide.getHint(iteration, caller, bci, target); - if (hint == InliningHint.ALWAYS_INLINE) { + if (hint == InliningHint.ALWAYS) { alwaysInline = true; - } else if (hint == InliningHint.NEVER_INLINE) { + } else if (hint == InliningHint.NEVER) { neverInline = true; } } diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningExample.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningExample.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningExample.java Fri Jul 08 18:01:29 2011 +0200 @@ -32,10 +32,6 @@ System.out.println(System.currentTimeMillis() - start); } - private static int test() { - return alwaysInline(30); - } - public static int testFib() { int sum = 0; for (int i = 0; i < 10000000; ++i) { @@ -44,18 +40,19 @@ return sum; } + private static int test() { + return alwaysInline(30); + } + public static int alwaysInline(int value) { - if (value == 0) { + if (value < 0) { return neverInline(value); } return alwaysInline(value - 1); } public static int neverInline(int value) { - if (value == 0) { - return 0; - } - return neverInline(value - 1); + return value; } public static int fib(int val) { diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningHint.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningHint.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningHint.java Fri Jul 08 18:01:29 2011 +0200 @@ -25,6 +25,8 @@ public enum InliningHint { NONE, - ALWAYS_INLINE, - NEVER_INLINE + NEVER, + LESS, + MORE, + ALWAYS } diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/bin/META-INF/services/com.oracle.max.graal.extensions.FrameModifier --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/bin/META-INF/services/com.oracle.max.graal.extensions.FrameModifier Fri Jul 08 18:01:29 2011 +0200 @@ -0,0 +1,1 @@ +com.oracle.max.graal.examples.deopt.FrameModifierImpl \ No newline at end of file diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/inlining/InliningGuideImpl.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/inlining/InliningGuideImpl.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/inlining/InliningGuideImpl.java Fri Jul 08 18:01:29 2011 +0200 @@ -31,11 +31,11 @@ @Override public InliningHint getHint(int depth, RiMethod caller, int bci, RiMethod target) { if (target.name().equals("neverInline")) { - return InliningHint.NEVER_INLINE; + return InliningHint.NEVER; } else if (target.name().equals("alwaysInline") && depth < 50) { - return InliningHint.ALWAYS_INLINE; + return InliningHint.ALWAYS; } else if (target.name().equals("fib") && depth < 5) { - return InliningHint.ALWAYS_INLINE; + return InliningHint.ALWAYS; } return InliningHint.NONE; } diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/IntrinsifierImpl.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/IntrinsifierImpl.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/IntrinsifierImpl.java Fri Jul 08 18:01:29 2011 +0200 @@ -38,7 +38,7 @@ public Graph intrinsicGraph(RiRuntime runtime, RiMethod caller, int bci, RiMethod method, List parameters) { if (method.holder().name().equals("Lcom/oracle/max/graal/examples/intrinsics/SafeAddExample;") && method.name().equals("safeAdd")) { CompilerGraph graph = new CompilerGraph(runtime); - Return returnNode = new Return(new SafeAdd(new Local(CiKind.Long, 0, graph), new Local(CiKind.Long, 1, graph), graph), graph); + Return returnNode = new Return(new SafeAddNode(new Local(CiKind.Long, 0, graph), new Local(CiKind.Long, 1, graph), graph), graph); graph.start().setNext(returnNode); graph.setReturn(returnNode); return graph; diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAdd.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAdd.java Fri Jul 08 13:41:27 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2011, 2011, 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.max.graal.examples.intrinsics; - -import com.oracle.max.graal.compiler.gen.*; -import com.oracle.max.graal.compiler.ir.*; -import com.oracle.max.graal.graph.*; -import com.sun.cri.bytecode.*; -import com.sun.cri.ci.*; - - -public final class SafeAdd extends IntegerArithmetic { - public SafeAdd(Value x, Value y, Graph graph) { - super(CiKind.Int, Bytecodes.LADD, x, y, graph); - } - - @Override - public Node copy(Graph into) { - return new SafeAdd(null, null, into); - } - - @Override - public String shortName() { - return "[+]"; - } - - @SuppressWarnings("unchecked") - @Override - public T lookup(Class clazz) { - if (clazz == LIRGenerator.LIRGeneratorOp.class) { - return (T) GENERATOR_OP; - } - return super.lookup(clazz); - } - - private static final LIRGenerator.LIRGeneratorOp GENERATOR_OP = new LIRGenerator.LIRGeneratorOp() { - @Override - public void generate(Node n, LIRGenerator generator) { - SafeAdd add = (SafeAdd) n; - generator.arithmeticOpInt(Bytecodes.IADD, generator.createResultVariable(add), generator.load(add.x()), generator.load(add.y()), CiValue.IllegalValue); - generator.deoptimizeOn(Condition.OF); - } - }; -} diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAddNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAddNode.java Fri Jul 08 18:01:29 2011 +0200 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.examples.intrinsics; + +import com.oracle.max.graal.compiler.gen.*; +import com.oracle.max.graal.compiler.ir.*; +import com.oracle.max.graal.graph.*; +import com.sun.cri.bytecode.*; +import com.sun.cri.ci.*; + + +public final class SafeAddNode extends IntegerArithmeticNode { + public SafeAddNode(Value x, Value y, Graph graph) { + super(CiKind.Int, Bytecodes.LADD, x, y, graph); + } + + @Override + public Node copy(Graph into) { + return new SafeAddNode(null, null, into); + } + + @Override + public String shortName() { + return "[+]"; + } + + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == LIRGenerator.LIRGeneratorOp.class) { + return (T) GENERATOR_OP; + } + return super.lookup(clazz); + } + + private static final LIRGenerator.LIRGeneratorOp GENERATOR_OP = new LIRGenerator.LIRGeneratorOp() { + @Override + public void generate(Node n, LIRGenerator generator) { + SafeAddNode add = (SafeAddNode) n; + generator.integerAdd(add, add.x(), add.y()); + generator.deoptimizeOn(Condition.OF); + } + }; +} diff -r 3d68684b7161 -r da99d8a05d9a graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/opt/OptimizerImpl.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/opt/OptimizerImpl.java Fri Jul 08 13:41:27 2011 +0200 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/opt/OptimizerImpl.java Fri Jul 08 18:01:29 2011 +0200 @@ -36,20 +36,25 @@ @Override public void optimize(RiRuntime runtime, Graph graph) { - for (SafeAdd safeAdd : graph.getNodes(SafeAdd.class)) { - if (safeAdd.y().isConstant() && safeAdd.y().asConstant().asLong() == 1) { - if (safeAdd.x() instanceof Phi) { - Phi phi = (Phi) safeAdd.x(); - if (phi.merge() instanceof LoopBegin && phi.valueAt(1) == safeAdd) { - LoopBegin loopBegin = (LoopBegin) phi.merge(); - if (!canOverflow(phi, loopBegin)) { - IntegerAdd add = new IntegerAdd(CiKind.Int, safeAdd.x(), safeAdd.y(), graph); - safeAdd.replaceAndDelete(add); - } - } + for (SafeAddNode safeAdd : graph.getNodes(SafeAddNode.class)) { + if (!canOverflow(safeAdd)) { + IntegerAdd add = new IntegerAdd(CiKind.Int, safeAdd.x(), safeAdd.y(), graph); + safeAdd.replaceAndDelete(add); + } + } + } + + private boolean canOverflow(SafeAddNode safeAdd) { + if (safeAdd.y().isConstant() && safeAdd.y().asConstant().asLong() == 1) { + if (safeAdd.x() instanceof Phi) { + Phi phi = (Phi) safeAdd.x(); + if (phi.merge() instanceof LoopBegin && phi.valueAt(1) == safeAdd) { + LoopBegin loopBegin = (LoopBegin) phi.merge(); + return canOverflow(phi, loopBegin); } } } + return true; } private boolean canOverflow(Phi phi, LoopBegin loopBegin) {