use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.
the class NormalizeCompareNode method tryConstantFold.
protected static ValueNode tryConstantFold(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
LogicNode result = CompareNode.tryConstantFold(CanonicalCondition.EQ, x, y, null, false);
if (result instanceof LogicConstantNode) {
LogicConstantNode logicConstantNode = (LogicConstantNode) result;
LogicNode resultLT = CompareNode.tryConstantFold(CanonicalCondition.LT, x, y, constantReflection, isUnorderedLess);
if (resultLT instanceof LogicConstantNode) {
LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
if (logicConstantNodeLT.getValue()) {
return ConstantNode.forIntegerKind(kind, -1);
} else if (logicConstantNode.getValue()) {
return ConstantNode.forIntegerKind(kind, 0);
} else {
return ConstantNode.forIntegerKind(kind, 1);
}
}
}
return null;
}
use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.
the class HashMapGetTest method hashMapTest.
@Test
public void hashMapTest() {
HashMap<Integer, Integer> map = new HashMap<>();
ResolvedJavaMethod get = getResolvedJavaMethod(HashMapGetTest.class, "mapGet");
for (int i = 0; i < 5000; i++) {
mapGet(map, i);
map.put(i, i);
mapGet(map, i);
}
test(get, null, map, new Integer(0));
for (IfNode ifNode : lastCompiledGraph.getNodes(IfNode.TYPE)) {
LogicNode condition = ifNode.condition();
if (ifNode.getTrueSuccessorProbability() < 0.4 && condition instanceof ObjectEqualsNode) {
assertTrue(ifNode.trueSuccessor().next() instanceof ReturnNode, "Expected return.", ifNode.trueSuccessor(), ifNode.trueSuccessor().next());
}
}
}
use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.
the class BytecodeParser method genIf.
protected void genIf(ValueNode x, Condition cond, ValueNode y) {
assert x.getStackKind() == y.getStackKind();
assert currentBlock.getSuccessorCount() == 2;
BciBlock trueBlock = currentBlock.getSuccessor(0);
BciBlock falseBlock = currentBlock.getSuccessor(1);
if (trueBlock == falseBlock) {
// The target block is the same independent of the condition.
appendGoto(trueBlock);
return;
}
ValueNode a = x;
ValueNode b = y;
BciBlock trueSuccessor = trueBlock;
BciBlock falseSuccessor = falseBlock;
CanonicalizedCondition canonicalizedCondition = cond.canonicalize();
// Check whether the condition needs to mirror the operands.
if (canonicalizedCondition.mustMirror()) {
a = y;
b = x;
}
if (canonicalizedCondition.mustNegate()) {
trueSuccessor = falseBlock;
falseSuccessor = trueBlock;
}
// Create the logic node for the condition.
LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b);
double probability = -1;
if (condition instanceof IntegerEqualsNode) {
probability = extractInjectedProbability((IntegerEqualsNode) condition);
// the probability coming from here is about the actual condition
}
if (probability == -1) {
probability = getProfileProbability(canonicalizedCondition.mustNegate());
}
probability = clampProbability(probability);
genIf(condition, trueSuccessor, falseSuccessor, probability);
}
use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.
the class BytecodeParser method emitCheckForInvokeSuperSpecial.
/**
* Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method
* declared in an interface (i.e., a default method) is assignable to the interface. If not,
* then deoptimize so that the interpreter can throw an {@link IllegalAccessError}.
*
* This is a check not performed by the verifier and so must be performed at runtime.
*
* @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a
* method in a super class
*/
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
ResolvedJavaType callingClass = method.getDeclaringClass();
if (callingClass.getHostClass() != null) {
callingClass = callingClass.getHostClass();
}
if (callingClass.isInterface()) {
ValueNode receiver = args[0];
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass);
LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null));
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false));
args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard));
}
}
use of org.graalvm.compiler.nodes.LogicNode in project graal by oracle.
the class LoopTransformations method updateMainLoopLimit.
private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
// Update the main loops limit test to be different than the post loop
StructuredGraph graph = preLimit.graph();
IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
LogicNode ifTest = mainLimit.condition();
CompareNode compareNode = (CompareNode) ifTest;
ValueNode prePhi = preIv.valueNode();
ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
ValueNode preStride = preIv.strideNode();
ValueNode mainStride;
if (preStride instanceof ConstantNode) {
mainStride = preStride;
} else {
mainStride = mainLoop.getDuplicatedNode(preStride);
}
// Fetch the bounds to pose lowering the range by one
ValueNode ub = null;
if (compareNode.getX() == mainPhi) {
ub = compareNode.getY();
} else if (compareNode.getY() == mainPhi) {
ub = compareNode.getX();
} else {
throw GraalError.shouldNotReachHere();
}
// Preloop always performs at least one iteration, so remove that from the main loop.
ValueNode newLimit = sub(graph, ub, mainStride);
// Re-wire the condition with the new limit
compareNode.replaceFirstInput(ub, newLimit);
}
Aggregations