# HG changeset patch # User Josef Eisl # Date 1396426009 -7200 # Node ID 3825cf50cc5ac6a0f7368f656f4fdd7d85540279 # Parent 31ded66cd2cb13c860be2e6f90bec7a090e270b3 AbstractBytecodeParser: make ifNode abstract. diff -r 31ded66cd2cb -r 3825cf50cc5a graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Wed Apr 02 09:59:43 2014 +0200 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Wed Apr 02 10:06:49 2014 +0200 @@ -41,6 +41,7 @@ import com.oracle.graal.java.*; import com.oracle.graal.java.BciBlockMapping.BciBlock; import com.oracle.graal.lir.*; +import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.calc.FloatConvertNode.FloatConvert; import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.phases.*; @@ -365,6 +366,48 @@ } @Override + protected void ifNode(Value x, Condition cond, Value y) { + assert currentBlock.getSuccessors().size() == 2; + BciBlock trueBlock = currentBlock.getSuccessors().get(0); + BciBlock falseBlock = currentBlock.getSuccessors().get(1); + if (trueBlock == falseBlock) { + appendGoto(createTarget(trueBlock, frameState)); + return; + } + + double probability = profilingInfo.getBranchTakenProbability(bci()); + if (probability < 0) { + assert probability == -1 : "invalid probability"; + Debug.log("missing probability in %s at bci %d", method, bci()); + probability = 0.5; + } + + if (!optimisticOpts.removeNeverExecutedCode()) { + if (probability == 0) { + probability = 0.0000001; + } else if (probability == 1) { + probability = 0.999999; + } + } + + // the mirroring and negation operations get the condition into canonical form + boolean mirror = cond.canonicalMirror(); + boolean negate = cond.canonicalNegate(); + + Value a = mirror ? y : x; + Value b = mirror ? x : y; + + LabelRef trueDestination = LabelRef.forSuccessor(lirGenRes.getLIR(), trueBlock, 0); + LabelRef falseDestination = LabelRef.forSuccessor(lirGenRes.getLIR(), falseBlock, 1); + + if (negate) { + gen.emitCompareBranch(a, b, cond, false, falseDestination, trueDestination, 1 - probability); + } else { + gen.emitCompareBranch(a, b, cond, false, trueDestination, falseDestination, probability); + } + } + + @Override protected Value genIntegerLessThan(Value x, Value y) { // TODO Auto-generated method stub throw GraalInternalError.unimplemented("Auto-generated method stub"); @@ -377,12 +420,6 @@ } @Override - protected Value genIf(Value condition, Value falseSuccessor, Value trueSuccessor, double d) { - // TODO Auto-generated method stub - throw GraalInternalError.unimplemented("Auto-generated method stub"); - } - - @Override protected void genThrow() { // TODO Auto-generated method stub throw GraalInternalError.unimplemented("Auto-generated method stub"); @@ -531,8 +568,10 @@ @Override protected Value appendConstant(Constant constant) { - // TODO Auto-generated method stub - throw GraalInternalError.unimplemented("Auto-generated method stub"); + if (gen.canInlineConstant(constant)) { + return constant; + } + return gen.emitMove(constant); } @Override diff -r 31ded66cd2cb -r 3825cf50cc5a graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java Wed Apr 02 09:59:43 2014 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/AbstractBytecodeParser.java Wed Apr 02 10:06:49 2014 +0200 @@ -519,61 +519,7 @@ protected abstract T genUnique(T x); - protected abstract T genIf(T condition, T falseSuccessor, T trueSuccessor, double d); - - private void ifNode(T x, Condition cond, T y) { - // assert !x.isDeleted() && !y.isDeleted(); - // assert currentBlock.numNormalSuccessors() == 2; - assert currentBlock.getSuccessors().size() == 2; - BciBlock trueBlock = currentBlock.getSuccessors().get(0); - BciBlock falseBlock = currentBlock.getSuccessors().get(1); - if (trueBlock == falseBlock) { - appendGoto(createTarget(trueBlock, frameState)); - return; - } - - double probability = profilingInfo.getBranchTakenProbability(bci()); - if (probability < 0) { - assert probability == -1 : "invalid probability"; - Debug.log("missing probability in %s at bci %d", method, bci()); - probability = 0.5; - } - - if (!optimisticOpts.removeNeverExecutedCode()) { - if (probability == 0) { - probability = 0.0000001; - } else if (probability == 1) { - probability = 0.999999; - } - } - - // the mirroring and negation operations get the condition into canonical form - boolean mirror = cond.canonicalMirror(); - boolean negate = cond.canonicalNegate(); - - T a = mirror ? y : x; - T b = mirror ? x : y; - - T condition; - assert !a.getKind().isNumericFloat(); - if (cond == Condition.EQ || cond == Condition.NE) { - if (a.getKind() == Kind.Object) { - condition = genObjectEquals(a, b); - } else { - condition = genIntegerEquals(a, b); - } - } else { - assert a.getKind() != Kind.Object && !cond.isUnsigned(); - condition = genIntegerLessThan(a, b); - } - condition = genUnique(condition); - - T trueSuccessor = createBlockTarget(probability, trueBlock, frameState); - T falseSuccessor = createBlockTarget(1 - probability, falseBlock, frameState); - - T ifNode = negate ? genIf(condition, falseSuccessor, trueSuccessor, 1 - probability) : genIf(condition, trueSuccessor, falseSuccessor, probability); - append(ifNode); - } + protected abstract void ifNode(T x, Condition cond, T y); private void genIfZero(Condition cond) { T y = appendConstant(Constant.INT_0); diff -r 31ded66cd2cb -r 3825cf50cc5a graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Apr 02 09:59:43 2014 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Apr 02 10:06:49 2014 +0200 @@ -588,7 +588,6 @@ return (ValueNode) currentGraph.unique((Node & ValueNumberable) x); } - @Override protected ValueNode genIf(ValueNode condition, ValueNode falseSuccessor, ValueNode trueSuccessor, double d) { return new IfNode((LogicNode) condition, (FixedNode) falseSuccessor, (FixedNode) trueSuccessor, d); } @@ -1372,6 +1371,61 @@ } } + @Override + protected void ifNode(ValueNode x, Condition cond, ValueNode y) { + // assert !x.isDeleted() && !y.isDeleted(); + // assert currentBlock.numNormalSuccessors() == 2; + assert currentBlock.getSuccessors().size() == 2; + BciBlock trueBlock = currentBlock.getSuccessors().get(0); + BciBlock falseBlock = currentBlock.getSuccessors().get(1); + if (trueBlock == falseBlock) { + appendGoto(createTarget(trueBlock, frameState)); + return; + } + + double probability = profilingInfo.getBranchTakenProbability(bci()); + if (probability < 0) { + assert probability == -1 : "invalid probability"; + Debug.log("missing probability in %s at bci %d", method, bci()); + probability = 0.5; + } + + if (!optimisticOpts.removeNeverExecutedCode()) { + if (probability == 0) { + probability = 0.0000001; + } else if (probability == 1) { + probability = 0.999999; + } + } + + // the mirroring and negation operations get the condition into canonical form + boolean mirror = cond.canonicalMirror(); + boolean negate = cond.canonicalNegate(); + + ValueNode a = mirror ? y : x; + ValueNode b = mirror ? x : y; + + ValueNode condition; + assert !a.getKind().isNumericFloat(); + if (cond == Condition.EQ || cond == Condition.NE) { + if (a.getKind() == Kind.Object) { + condition = genObjectEquals(a, b); + } else { + condition = genIntegerEquals(a, b); + } + } else { + assert a.getKind() != Kind.Object && !cond.isUnsigned(); + condition = genIntegerLessThan(a, b); + } + condition = genUnique(condition); + + ValueNode trueSuccessor = createBlockTarget(probability, trueBlock, frameState); + ValueNode falseSuccessor = createBlockTarget(1 - probability, falseBlock, frameState); + + ValueNode ifNode = negate ? genIf(condition, falseSuccessor, trueSuccessor, 1 - probability) : genIf(condition, trueSuccessor, falseSuccessor, probability); + append(ifNode); + } + } } }