use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class ExpandLogicPhase method processConditional.
@SuppressWarnings("try")
private static void processConditional(LogicNode x, boolean xNegated, LogicNode y, boolean yNegated, ConditionalNode conditional) {
try (DebugCloseable context = conditional.withNodeSourcePosition()) {
ValueNode trueTarget = conditional.trueValue();
ValueNode falseTarget = conditional.falseValue();
Graph graph = conditional.graph();
ConditionalNode secondConditional = graph.unique(new ConditionalNode(y, yNegated ? falseTarget : trueTarget, yNegated ? trueTarget : falseTarget));
ConditionalNode firstConditional = graph.unique(new ConditionalNode(x, xNegated ? secondConditional : trueTarget, xNegated ? trueTarget : secondConditional));
conditional.replaceAndDelete(firstConditional);
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class ExpandLogicPhase method processIf.
@SuppressWarnings("try")
private static void processIf(LogicNode x, boolean xNegated, LogicNode y, boolean yNegated, IfNode ifNode, double shortCircuitProbability) {
try (DebugCloseable context = ifNode.withNodeSourcePosition()) {
/*
* this method splits an IfNode, which has a ShortCircuitOrNode as its condition, into
* two separate IfNodes: if(X) and if(Y)
*
* for computing the probabilities P(X) and P(Y), we use two different approaches. The
* first one assumes that the shortCircuitProbability and the probability on the IfNode
* were created with each other in mind. If this assumption does not hold, we fall back
* to another mechanism for computing the probabilities.
*/
AbstractBeginNode trueTarget = ifNode.trueSuccessor();
AbstractBeginNode falseTarget = ifNode.falseSuccessor();
// 1st approach
// assumption: P(originalIf.trueSuccessor) == P(X) + ((1 - P(X)) * P(Y))
double firstIfTrueProbability = shortCircuitProbability;
double secondIfTrueProbability = sanitizeProbability((ifNode.getTrueSuccessorProbability() - shortCircuitProbability) / (1 - shortCircuitProbability));
double expectedOriginalIfTrueProbability = firstIfTrueProbability + (1 - firstIfTrueProbability) * secondIfTrueProbability;
if (!doubleEquals(ifNode.getTrueSuccessorProbability(), expectedOriginalIfTrueProbability)) {
/*
* 2nd approach
*
* the assumption above did not hold, so we either used an artificial probability as
* shortCircuitProbability or the ShortCircuitOrNode was moved to some other IfNode.
*
* so, we distribute the if's trueSuccessorProbability between the newly generated
* if nodes according to the shortCircuitProbability. the following invariant is
* always true in this case: P(originalIf.trueSuccessor) == P(X) + ((1 - P(X)) *
* P(Y))
*/
firstIfTrueProbability = ifNode.getTrueSuccessorProbability() * shortCircuitProbability;
secondIfTrueProbability = sanitizeProbability(1 - (ifNode.probability(falseTarget) / (1 - firstIfTrueProbability)));
}
ifNode.clearSuccessors();
Graph graph = ifNode.graph();
AbstractMergeNode trueTargetMerge = graph.add(new MergeNode());
trueTargetMerge.setNext(trueTarget);
EndNode firstTrueEnd = graph.add(new EndNode());
EndNode secondTrueEnd = graph.add(new EndNode());
trueTargetMerge.addForwardEnd(firstTrueEnd);
trueTargetMerge.addForwardEnd(secondTrueEnd);
AbstractBeginNode firstTrueTarget = BeginNode.begin(firstTrueEnd);
AbstractBeginNode secondTrueTarget = BeginNode.begin(secondTrueEnd);
if (yNegated) {
secondIfTrueProbability = 1.0 - secondIfTrueProbability;
}
if (xNegated) {
firstIfTrueProbability = 1.0 - firstIfTrueProbability;
}
AbstractBeginNode secondIf = BeginNode.begin(graph.add(new IfNode(y, yNegated ? falseTarget : secondTrueTarget, yNegated ? secondTrueTarget : falseTarget, secondIfTrueProbability)));
IfNode firstIf = graph.add(new IfNode(x, xNegated ? secondIf : firstTrueTarget, xNegated ? firstTrueTarget : secondIf, firstIfTrueProbability));
ifNode.replaceAtPredecessor(firstIf);
ifNode.safeDelete();
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class StaticInterfaceFieldTest method eagerlyParseMethod.
@SuppressWarnings("try")
private void eagerlyParseMethod(Class<C> clazz, String methodName) {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
Plugins plugins = new Plugins(new InvocationPlugins());
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
final Method m = getMethod(clazz, methodName);
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
try (DebugCloseable s = debug.disableIntercept();
DebugContext.Scope ds = debug.scope("GraphBuilding", graph, method)) {
graphBuilderSuite.apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class VerifyBailoutUsageTest method testBailoutUsage.
@SuppressWarnings("try")
private static void testBailoutUsage(Class<?> c) {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
Plugins plugins = new Plugins(new InvocationPlugins());
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
for (Method m : c.getDeclaredMethods()) {
if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
graphBuilderSuite.apply(graph, context);
try (DebugCloseable s = debug.disableIntercept()) {
new VerifyBailoutUsage().apply(graph, context);
}
}
}
}
use of org.graalvm.compiler.debug.DebugCloseable in project graal by oracle.
the class GraalCompiler method emitFrontEnd.
/**
* Builds the graph, optimizes it.
*/
@SuppressWarnings("try")
public static void emitFrontEnd(Providers providers, TargetProvider target, StructuredGraph graph, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, Suites suites) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("FrontEnd");
DebugCloseable a = FrontEnd.start(debug)) {
HighTierContext highTierContext = new HighTierContext(providers, graphBuilderSuite, optimisticOpts);
if (graph.start().next() == null) {
graphBuilderSuite.apply(graph, highTierContext);
new DeadCodeEliminationPhase(DeadCodeEliminationPhase.Optionality.Optional).apply(graph);
debug.dump(DebugContext.BASIC_LEVEL, graph, "After parsing");
} else {
debug.dump(DebugContext.INFO_LEVEL, graph, "initial state");
}
suites.getHighTier().apply(graph, highTierContext);
graph.maybeCompress();
debug.dump(DebugContext.BASIC_LEVEL, graph, "After high tier");
MidTierContext midTierContext = new MidTierContext(providers, target, optimisticOpts, profilingInfo);
suites.getMidTier().apply(graph, midTierContext);
graph.maybeCompress();
debug.dump(DebugContext.BASIC_LEVEL, graph, "After mid tier");
LowTierContext lowTierContext = new LowTierContext(providers, target);
suites.getLowTier().apply(graph, lowTierContext);
debug.dump(DebugContext.BASIC_LEVEL, graph, "After low tier");
debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "Final HIR schedule");
graph.logInliningTree();
} catch (Throwable e) {
throw debug.handle(e);
} finally {
graph.checkCancellation();
}
}
Aggregations