use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class LockEliminationTest method getGraph.
private StructuredGraph getGraph(String snippet) {
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
HighTierContext context = getDefaultHighTierContext();
new CanonicalizerPhase().apply(graph, context);
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
new CanonicalizerPhase().apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new LockEliminationPhase().apply(graph);
return graph;
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class MonitorGraphTest method parseAndProcess.
private StructuredGraph parseAndProcess(String snippet) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
ParameterNode param = graph.getNodes(ParameterNode.TYPE).first();
if (param != null) {
ConstantNode constant = ConstantNode.forInt(0, graph);
for (Node n : param.usages().snapshot()) {
if (!(n instanceof FrameState)) {
n.replaceFirstInput(param, constant);
}
}
}
Map<Invoke, Double> hints = new HashMap<>();
for (Invoke invoke : graph.getInvokes()) {
hints.put(invoke, 1000d);
}
HighTierContext context = getDefaultHighTierContext();
new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context);
new CanonicalizerPhase().apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
return graph;
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class GraphKit method inline.
/**
* Inlines a given invocation to a method. The graph of the inlined method is processed in the
* same manner as for snippets and method substitutions.
*/
public void inline(InvokeNode invoke) {
ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Plugins plugins = new Plugins(graphBuilderPlugins);
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
if (invoke.graph().trackNodeSourcePosition()) {
calleeGraph.setTrackNodeSourcePosition();
}
IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
instance.apply(calleeGraph);
// Remove all frame states from inlinee
calleeGraph.clearAllStateAfter();
new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
InliningUtil.inline(invoke, calleeGraph, false, method);
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class NoDeadCodeVerifyHandler method verify.
@Override
public void verify(DebugContext debug, Object object, String format, Object... args) {
OptionValues options = debug.getOptions();
if (Options.NDCV.getValue(options) != OFF && object instanceof StructuredGraph) {
StructuredGraph graph = (StructuredGraph) object;
List<Node> before = graph.getNodes().snapshot();
new DeadCodeEliminationPhase().run(graph);
List<Node> after = graph.getNodes().snapshot();
assert after.size() <= before.size();
if (before.size() != after.size()) {
if (discovered.put(format, Boolean.TRUE) == null) {
before.removeAll(after);
String prefix = format == null ? "" : format + ": ";
GraalError error = new GraalError("%sfound dead nodes in %s: %s", prefix, graph, before);
if (Options.NDCV.getValue(options) == INFO) {
System.out.println(error.getMessage());
} else if (Options.NDCV.getValue(options) == VERBOSE) {
error.printStackTrace(System.out);
} else {
assert Options.NDCV.getValue(options) == FATAL;
throw error;
}
}
}
}
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class BoxingEliminationTest method compareGraphs.
private void compareGraphs(final String snippet, final String referenceSnippet, final boolean loopPeeling, final boolean excludeVirtual) {
graph = parseEager(snippet, AllowAssumptions.NO);
HighTierContext context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
canonicalizer.apply(graph, context);
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
if (loopPeeling) {
new LoopPeelingPhase(new DefaultLoopPolicies()).apply(graph, context);
}
new DeadCodeEliminationPhase().apply(graph);
canonicalizer.apply(graph, context);
new PartialEscapePhase(false, canonicalizer, graph.getOptions()).apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
canonicalizer.apply(graph, context);
StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
new InliningPhase(new CanonicalizerPhase()).apply(referenceGraph, context);
new DeadCodeEliminationPhase().apply(referenceGraph);
new CanonicalizerPhase().apply(referenceGraph, context);
assertEquals(referenceGraph, graph, excludeVirtual, true);
}
Aggregations