use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class UnsafeVirtualizationTest method testPartialEscapeReadElimination.
public void testPartialEscapeReadElimination(String snippet, boolean canonicalizeBefore, boolean shouldEscapeRead, boolean shouldEscapeWrite, Object... args) {
assert TestClassInt.fieldOffset1 % 8 == 0 : "First of the two int-fields must be 8-byte aligned";
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
OptionValues options = graph.getOptions();
CoreProviders context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
if (canonicalizeBefore) {
canonicalizer.apply(graph, context);
}
Result r = executeExpected(method, null, args);
int readCount = graph.getNodes().filter(RawLoadNode.class).count();
int writeCount = graph.getNodes().filter(RawStoreNode.class).count();
new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
boolean canVirtualize = true;
assert graph.getNodes().filter(VirtualObjectNode.class).count() == 1;
VirtualObjectNode virtual = graph.getNodes().filter(VirtualObjectNode.class).first();
if (virtual instanceof VirtualArrayNode) {
VirtualArrayNode array = (VirtualArrayNode) virtual;
if (array.isVirtualByteArray(context.getMetaAccessExtensionProvider())) {
canVirtualize = context.getPlatformConfigurationProvider().canVirtualizeLargeByteArrayAccess();
}
}
boolean escapeReads = shouldEscapeRead && canVirtualize;
boolean escapeWrites = shouldEscapeWrite && canVirtualize;
if (escapeReads) {
int newCount = graph.getNodes().filter(RawLoadNode.class).count();
assertTrue(readCount > newCount, "PEA did not escape reads. before: " + readCount + ", after " + newCount);
}
if (escapeWrites) {
int newCount = graph.getNodes().filter(RawStoreNode.class).count();
assertTrue(writeCount > newCount, "PEA did not escape writes, before: " + writeCount + ", after: " + newCount);
}
try {
InstalledCode code = getCode(method, graph);
Object result = code.executeVarargs(args);
assertEquals(r, new Result(result, null));
} catch (Throwable e) {
assertFalse(true, e.toString());
}
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class UnsafeReadEliminationTest method testPartialEscapeReadElimination.
public void testPartialEscapeReadElimination(StructuredGraph graph, int reads, int writes) {
OptionValues options = graph.getOptions();
CoreProviders context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
canonicalizer.apply(graph, context);
new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
// after lowering the same applies for reads and writes
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
canonicalizer.apply(graph, context);
new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class IfNodeCanonicalizationTest method test.
public void test(String name, Class<? extends Node> expectedClass, int expectedCount) {
StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
CoreProviders context = getProviders();
CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
new ConvertDeoptimizeToGuardPhase().apply(graph, context);
graph.clearAllStateAfterForTestingOnly();
graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
canonicalizer.apply(graph, context);
new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
canonicalizer.apply(graph, context);
canonicalizer.apply(graph, context);
Assert.assertEquals(expectedCount, graph.getNodes().filter(expectedClass).count());
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class ConditionAnchoringTest method test.
public void test(String name, int ids) {
StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
assertThat(unsafeNodes, hasCount(1));
// lower unsafe load
CoreProviders context = getProviders();
LoweringPhase lowering = new LoweringPhase(createCanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
lowering.apply(graph, context);
unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
assertThat(unsafeNodes, isEmpty());
assertThat(conditionAnchors, hasCount(1));
// 2 * ids id reads, 1 'field' access
assertThat(reads, hasCount(2 * ids + 1));
// float reads and canonicalize to give a chance to conditions to GVN
FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
floatingReadPhase.apply(graph);
CanonicalizerPhase canonicalizerPhase = createCanonicalizerPhase();
canonicalizerPhase.apply(graph, context);
NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
// 1 id read, 1 'field' access
assertThat(floatingReads, hasCount(ids + 1));
new ConditionalEliminationPhase(false).apply(graph, context);
floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
assertThat(floatingReads, hasCount(1));
assertThat(conditionAnchors, isEmpty());
FloatingReadNode readNode = floatingReads.first();
assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class NativeImageGenerator method modifySuites.
@SuppressWarnings("unused")
private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted, boolean firstTier) {
Providers runtimeCallProviders = backend.getProviders();
PhaseSuite<HighTierContext> highTier = suites.getHighTier();
PhaseSuite<MidTierContext> midTier = suites.getMidTier();
PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
final boolean economy = firstTier || SubstrateOptions.useEconomyCompilerConfig();
ListIterator<BasePhase<? super HighTierContext>> position;
if (hosted) {
position = GraalConfiguration.hostedInstance().createHostedInliners(highTier);
} else {
/* Find the runtime inliner. */
position = highTier.findPhase(InliningPhase.class);
}
if (position != null) {
/* These two phases must be after all method inlining. */
position.add(new DeadStoreRemovalPhase());
position.add(new RemoveUnwindPhase());
} else {
/* There is no inlining, so prepend them in reverse order. */
highTier.prependPhase(new RemoveUnwindPhase());
highTier.prependPhase(new DeadStoreRemovalPhase());
}
lowTier.addBeforeLast(new OptimizeExceptionPathsPhase());
BasePhase<CoreProviders> addressLoweringPhase = backend.newAddressLoweringPhase(runtimeCallProviders.getCodeCache());
if (economy) {
lowTier.findPhase(ExpandLogicPhase.class, true).add(addressLoweringPhase);
} else {
lowTier.findPhase(UseTrappingNullChecksPhase.class).add(addressLoweringPhase);
}
if (SubstrateOptions.MultiThreaded.getValue()) {
/*
* Graal inserts only loop safepoints. We want a SafepointNode also before every return.
* Our safepoint insertion phase inserts both kinds of safepoints.
*/
midTier.findPhase(LoopSafepointInsertionPhase.class).set(new SubstrateSafepointInsertionPhase());
} else {
/* No need for safepoints when we have only one thread. */
VMError.guarantee(midTier.removePhase(LoopSafepointInsertionPhase.class));
}
if (hosted) {
lowTier.appendPhase(new VerifyNoGuardsPhase());
/* Disable the Graal method inlining, since we have our own inlining system. */
highTier.removePhase(InliningPhase.class);
/* Remove phases that are not suitable for AOT compilation. */
highTier.removePhase(ConvertDeoptimizeToGuardPhase.class);
midTier.removePhase(DeoptimizationGroupingPhase.class);
} else {
if (economy) {
ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(FrameStateAssignmentPhase.class);
it.add(new CollectDeoptimizationSourcePositionsPhase());
// On SVM, the economy configuration requires a canonicalization run at the end of
// mid tier.
it = midTier.findLastPhase();
it.add(CanonicalizerPhase.create());
} else {
ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(DeoptimizationGroupingPhase.class);
it.previous();
it.add(new CollectDeoptimizationSourcePositionsPhase());
}
}
featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, snippetReflection, suites, hosted));
if (hosted && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(HostedOptionValues.singleton())) {
highTier.prependPhase(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.BEFORE_HIGH_TIER));
highTier.prependPhase(CanonicalizerPhase.create());
highTier.findLastPhase().add(CanonicalizerPhase.create());
highTier.findLastPhase().add(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.AFTER_HIGH_TIER));
}
return suites;
}
Aggregations