use of org.graalvm.compiler.lir.LabelRef in project graal by oracle.
the class AMD64NodeMatchRules method ifCompareLogicCas.
@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
JavaConstant constant = value.asJavaConstant();
assert compare.condition() == CanonicalCondition.EQ;
if (constant != null && cas.usages().count() == 1) {
long constantValue = constant.asLong();
boolean successIsTrue;
if (constantValue == 0) {
successIsTrue = false;
} else if (constantValue == 1) {
successIsTrue = true;
} else {
return null;
}
return builder -> {
LIRKind kind = getLirKind(cas);
LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
double trueLabelProbability = root.probability(root.trueSuccessor());
Value expectedValue = operand(cas.getExpectedValue());
Value newValue = operand(cas.getNewValue());
AMD64AddressValue address = (AMD64AddressValue) operand(cas.getAddress());
Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
getLIRGeneratorTool().emitCompareAndSwapBranch(kind, address, expectedValue, newValue, condition, trueLabel, falseLabel, trueLabelProbability);
return null;
};
}
return null;
}
use of org.graalvm.compiler.lir.LabelRef in project graal by oracle.
the class NodeLIRBuilder method emitSwitch.
/**
* This method tries to create a switch implementation that is optimal for the given switch. It
* will either generate a sequential if/then/else cascade, a set of range tests or a table
* switch.
*
* If the given switch does not contain int keys, it will always create a sequential
* implementation.
*/
@Override
public void emitSwitch(SwitchNode x) {
assert x.defaultSuccessor() != null;
LabelRef defaultTarget = getLIRBlock(x.defaultSuccessor());
int keyCount = x.keyCount();
if (keyCount == 0) {
gen.emitJump(defaultTarget);
} else {
Variable value = gen.load(operand(x.value()));
if (keyCount == 1) {
assert defaultTarget != null;
double probability = x.probability(x.keySuccessor(0));
LIRKind kind = gen.getLIRKind(x.value().stamp(NodeView.DEFAULT));
Value key = gen.emitConstant(kind, x.keyAt(0));
gen.emitCompareBranch(kind.getPlatformKind(), gen.load(operand(x.value())), key, Condition.EQ, false, getLIRBlock(x.keySuccessor(0)), defaultTarget, probability);
} else if (x instanceof IntegerSwitchNode && x.isSorted()) {
IntegerSwitchNode intSwitch = (IntegerSwitchNode) x;
LabelRef[] keyTargets = new LabelRef[keyCount];
JavaConstant[] keyConstants = new JavaConstant[keyCount];
double[] keyProbabilities = new double[keyCount];
JavaKind keyKind = intSwitch.keyAt(0).getJavaKind();
for (int i = 0; i < keyCount; i++) {
keyTargets[i] = getLIRBlock(intSwitch.keySuccessor(i));
keyConstants[i] = intSwitch.keyAt(i);
keyProbabilities[i] = intSwitch.keyProbability(i);
assert keyConstants[i].getJavaKind() == keyKind;
}
gen.emitStrategySwitch(keyConstants, keyProbabilities, keyTargets, defaultTarget, value);
} else {
// keyKind != JavaKind.Int || !x.isSorted()
LabelRef[] keyTargets = new LabelRef[keyCount];
Constant[] keyConstants = new Constant[keyCount];
double[] keyProbabilities = new double[keyCount];
for (int i = 0; i < keyCount; i++) {
keyTargets[i] = getLIRBlock(x.keySuccessor(i));
keyConstants[i] = x.keyAt(i);
keyProbabilities[i] = x.keyProbability(i);
}
// hopefully only a few entries
gen.emitStrategySwitch(new SwitchStrategy.SequentialStrategy(keyProbabilities, keyConstants), value, keyTargets, defaultTarget);
}
}
}
use of org.graalvm.compiler.lir.LabelRef in project graal by oracle.
the class NodeLIRBuilder method emitInvoke.
@Override
public void emitInvoke(Invoke x) {
LoweredCallTargetNode callTarget = (LoweredCallTargetNode) x.callTarget();
FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
CallingConvention invokeCc = frameMapBuilder.getRegisterConfig().getCallingConvention(callTarget.callType(), x.asNode().stamp(NodeView.DEFAULT).javaType(gen.getMetaAccess()), callTarget.signature(), gen);
frameMapBuilder.callsMethod(invokeCc);
Value[] parameters = visitInvokeArguments(invokeCc, callTarget.arguments());
LabelRef exceptionEdge = null;
if (x instanceof InvokeWithExceptionNode) {
exceptionEdge = getLIRBlock(((InvokeWithExceptionNode) x).exceptionEdge());
}
LIRFrameState callState = stateWithExceptionEdge(x, exceptionEdge);
Value result = invokeCc.getReturn();
if (callTarget instanceof DirectCallTargetNode) {
emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
} else if (callTarget instanceof IndirectCallTargetNode) {
emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
} else {
throw GraalError.shouldNotReachHere();
}
if (isLegal(result)) {
setResult(x.asNode(), gen.emitMove(result));
}
if (x instanceof InvokeWithExceptionNode) {
gen.emitJump(getLIRBlock(((InvokeWithExceptionNode) x).next()));
}
}
Aggregations