use of org.graalvm.compiler.nodes.LogicConstantNode 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.LogicConstantNode in project graal by oracle.
the class GraphChangeMonitoringPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, C context) {
/*
* Phase may add nodes but not end up using them so ignore additions. Nodes going dead and
* having their inputs change are the main interesting differences.
*/
HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug());
DebugContext debug = graph.getDebug();
try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
try (DebugContext.Scope s2 = debug.sandbox("WithoutMonitoring", null)) {
super.run(graphCopy, context);
} catch (Throwable t) {
debug.handle(t);
}
}
EconomicSet<Node> filteredNodes = EconomicSet.create(Equivalence.IDENTITY);
for (Node n : listener.getNodes()) {
if (n instanceof LogicConstantNode) {
// Ignore LogicConstantNode since those are sometimes created and deleted as part of
// running a phase.
} else {
filteredNodes.add(n);
}
}
if (!filteredNodes.isEmpty()) {
/* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
listener = new HashSetNodeEventListener();
try (NodeEventScope s = graph.trackNodeEvents(listener)) {
try (DebugContext.Scope s2 = debug.scope("WithGraphChangeMonitoring")) {
if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
}
super.run(graph, context);
if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
}
debug.log("*** %s %s %s\n", message, graph, filteredNodes);
}
}
} else {
// Go ahead and run it normally even though it should have no effect
super.run(graph, context);
}
}
use of org.graalvm.compiler.nodes.LogicConstantNode in project graal by oracle.
the class EffectsClosure method processBlock.
@Override
protected BlockT processBlock(Block block, BlockT state) {
if (!state.isDead()) {
GraphEffectList effects = blockEffects.get(block);
/*
* If we enter an if branch that is known to be unreachable, we mark it as dead and
* cease to do any more analysis on it. At merges, these dead branches will be ignored.
*/
if (block.getBeginNode().predecessor() instanceof IfNode) {
IfNode ifNode = (IfNode) block.getBeginNode().predecessor();
LogicNode condition = ifNode.condition();
Node alias = getScalarAlias(condition);
if (alias instanceof LogicConstantNode) {
LogicConstantNode constant = (LogicConstantNode) alias;
boolean isTrueSuccessor = block.getBeginNode() == ifNode.trueSuccessor();
if (constant.getValue() != isTrueSuccessor) {
state.markAsDead();
effects.killIfBranch(ifNode, constant.getValue());
return state;
}
}
}
OptionValues options = block.getBeginNode().getOptions();
VirtualUtil.trace(options, debug, "\nBlock: %s, preds: %s, succ: %s (", block, block.getPredecessors(), block.getSuccessors());
// a lastFixedNode is needed in case we want to insert fixed nodes
FixedWithNextNode lastFixedNode = null;
Iterable<? extends Node> nodes = schedule != null ? schedule.getBlockToNodesMap().get(block) : block.getNodes();
for (Node node : nodes) {
// reset the aliases (may be non-null due to iterative loop processing)
aliases.set(node, null);
if (node instanceof LoopExitNode) {
LoopExitNode loopExit = (LoopExitNode) node;
for (ProxyNode proxy : loopExit.proxies()) {
aliases.set(proxy, null);
changed |= processNode(proxy, state, effects, lastFixedNode) && isSignificantNode(node);
}
processLoopExit(loopExit, loopEntryStates.get(loopExit.loopBegin()), state, blockEffects.get(block));
}
changed |= processNode(node, state, effects, lastFixedNode) && isSignificantNode(node);
if (node instanceof FixedWithNextNode) {
lastFixedNode = (FixedWithNextNode) node;
}
if (state.isDead()) {
break;
}
}
VirtualUtil.trace(options, debug, ")\n end state: %s\n", state);
}
return state;
}
use of org.graalvm.compiler.nodes.LogicConstantNode in project graal by oracle.
the class BytecodeParser method genIf.
protected void genIf(LogicNode conditionInput, BciBlock trueBlockInput, BciBlock falseBlockInput, double probabilityInput) {
BciBlock trueBlock = trueBlockInput;
BciBlock falseBlock = falseBlockInput;
LogicNode condition = conditionInput;
double probability = probabilityInput;
FrameState stateBefore = null;
ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
}
// Remove a logic negation node.
if (condition instanceof LogicNegationNode) {
LogicNegationNode logicNegationNode = (LogicNegationNode) condition;
BciBlock tmpBlock = trueBlock;
trueBlock = falseBlock;
falseBlock = tmpBlock;
probability = 1 - probability;
condition = logicNegationNode.getValue();
}
if (condition instanceof LogicConstantNode) {
genConstantTargetIf(trueBlock, falseBlock, condition);
} else {
if (condition.graph() == null) {
condition = genUnique(condition);
}
if (isNeverExecutedCode(probability)) {
append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, true));
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
profilingPlugin.profileGoto(this, method, bci(), falseBlock.startBci, stateBefore);
}
appendGoto(falseBlock);
return;
} else if (isNeverExecutedCode(1 - probability)) {
append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, false));
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
profilingPlugin.profileGoto(this, method, bci(), trueBlock.startBci, stateBefore);
}
appendGoto(trueBlock);
return;
}
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
profilingPlugin.profileIf(this, method, bci(), condition, trueBlock.startBci, falseBlock.startBci, stateBefore);
}
int oldBci = stream.currentBCI();
int trueBlockInt = checkPositiveIntConstantPushed(trueBlock);
if (trueBlockInt != -1) {
int falseBlockInt = checkPositiveIntConstantPushed(falseBlock);
if (falseBlockInt != -1) {
if (tryGenConditionalForIf(trueBlock, falseBlock, condition, oldBci, trueBlockInt, falseBlockInt)) {
return;
}
}
}
this.controlFlowSplit = true;
FixedNode trueSuccessor = createTarget(trueBlock, frameState, false, false);
FixedNode falseSuccessor = createTarget(falseBlock, frameState, false, true);
ValueNode ifNode = genIfNode(condition, trueSuccessor, falseSuccessor, probability);
postProcessIfNode(ifNode);
append(ifNode);
}
}
use of org.graalvm.compiler.nodes.LogicConstantNode in project graal by oracle.
the class BytecodeParser method genConstantTargetIf.
private void genConstantTargetIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition) {
LogicConstantNode constantLogicNode = (LogicConstantNode) condition;
boolean value = constantLogicNode.getValue();
BciBlock nextBlock = falseBlock;
if (value) {
nextBlock = trueBlock;
}
int startBci = nextBlock.startBci;
int targetAtStart = stream.readUByte(startBci);
if (targetAtStart == Bytecodes.GOTO && nextBlock.getPredecessorCount() == 1) {
// This is an empty block. Skip it.
BciBlock successorBlock = nextBlock.successors.get(0);
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
profilingPlugin.profileGoto(this, method, bci(), successorBlock.startBci, stateBefore);
}
appendGoto(successorBlock);
assert nextBlock.numNormalSuccessors() == 1;
} else {
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
profilingPlugin.profileGoto(this, method, bci(), nextBlock.startBci, stateBefore);
}
appendGoto(nextBlock);
}
}
Aggregations