Mercurial > hg > truffle
comparison graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java @ 13908:8f3cd93813f1
Use branch probability for emitting conditional jump.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 07 Feb 2014 15:20:59 +0100 |
parents | 6bc07d0c2682 |
children | 28b59501c7b2 |
comparison
equal
deleted
inserted
replaced
13907:6fc05ad86490 | 13908:8f3cd93813f1 |
---|---|
59 public static class BranchOp extends AMD64LIRInstruction implements StandardOp.BranchOp { | 59 public static class BranchOp extends AMD64LIRInstruction implements StandardOp.BranchOp { |
60 protected final ConditionFlag condition; | 60 protected final ConditionFlag condition; |
61 protected final LabelRef trueDestination; | 61 protected final LabelRef trueDestination; |
62 protected final LabelRef falseDestination; | 62 protected final LabelRef falseDestination; |
63 | 63 |
64 public BranchOp(Condition condition, LabelRef trueDestination, LabelRef falseDestination) { | 64 private final double trueDestinationProbability; |
65 this(intCond(condition), trueDestination, falseDestination); | 65 |
66 } | 66 public BranchOp(Condition condition, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) { |
67 | 67 this(intCond(condition), trueDestination, falseDestination, trueDestinationProbability); |
68 public BranchOp(ConditionFlag condition, LabelRef trueDestination, LabelRef falseDestination) { | 68 } |
69 | |
70 public BranchOp(ConditionFlag condition, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) { | |
69 this.condition = condition; | 71 this.condition = condition; |
70 this.trueDestination = trueDestination; | 72 this.trueDestination = trueDestination; |
71 this.falseDestination = falseDestination; | 73 this.falseDestination = falseDestination; |
74 this.trueDestinationProbability = trueDestinationProbability; | |
72 } | 75 } |
73 | 76 |
74 @Override | 77 @Override |
75 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { | 78 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
76 if (crb.isSuccessorEdge(trueDestination)) { | 79 if (crb.isSuccessorEdge(trueDestination)) { |
77 jcc(masm, true, falseDestination); | 80 jcc(masm, true, falseDestination); |
78 } else if (falseDestination.getSourceBlock() == falseDestination.getTargetBlock()) { | 81 } else if (crb.isSuccessorEdge(falseDestination)) { |
82 jcc(masm, false, trueDestination); | |
83 } else if (trueDestinationProbability < 0.5) { | |
79 jcc(masm, true, falseDestination); | 84 jcc(masm, true, falseDestination); |
80 masm.jmp(trueDestination.label()); | 85 masm.jmp(trueDestination.label()); |
81 } else { | 86 } else { |
82 jcc(masm, false, trueDestination); | 87 jcc(masm, false, trueDestination); |
83 if (!crb.isSuccessorEdge(falseDestination)) { | 88 masm.jmp(falseDestination.label()); |
84 masm.jmp(falseDestination.label()); | |
85 } | |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 protected void jcc(AMD64MacroAssembler masm, boolean negate, LabelRef target) { | 92 protected void jcc(AMD64MacroAssembler masm, boolean negate, LabelRef target) { |
90 masm.jcc(negate ? condition.negate() : condition, target.label()); | 93 masm.jcc(negate ? condition.negate() : condition, target.label()); |
92 } | 95 } |
93 | 96 |
94 public static class FloatBranchOp extends BranchOp { | 97 public static class FloatBranchOp extends BranchOp { |
95 protected boolean unorderedIsTrue; | 98 protected boolean unorderedIsTrue; |
96 | 99 |
97 public FloatBranchOp(Condition condition, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination) { | 100 public FloatBranchOp(Condition condition, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) { |
98 super(floatCond(condition), trueDestination, falseDestination); | 101 super(floatCond(condition), trueDestination, falseDestination, trueDestinationProbability); |
99 this.unorderedIsTrue = unorderedIsTrue; | 102 this.unorderedIsTrue = unorderedIsTrue; |
100 } | 103 } |
101 | 104 |
102 @Override | 105 @Override |
103 protected void jcc(AMD64MacroAssembler masm, boolean negate, LabelRef target) { | 106 protected void jcc(AMD64MacroAssembler masm, boolean negate, LabelRef target) { |