use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.
the class SnippetStub method getGraph.
@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
Plugins defaultPlugins = providers.getGraphBuilderPlugins();
MetaAccessProvider metaAccess = providers.getMetaAccess();
SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
Plugins plugins = new Plugins(defaultPlugins);
plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
// Stubs cannot have optimistic assumptions since they have
// to be valid for the entire run of the VM.
final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
graph.disableUnsafeAccessTracking();
IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
instance.apply(graph);
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
}
}
new RemoveValueProxyPhase().apply(graph);
graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext context = new PhaseContext(providers);
canonicalizer.apply(graph, context);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
return graph;
}
use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.
the class SubstrateReplacements method getSnippet.
@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
Integer startOffset = snippetStartOffsets.get(method);
if (startOffset == null) {
throw VMError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
}
ParameterPlugin parameterPlugin = null;
if (args != null) {
parameterPlugin = new ConstantBindingParameterPlugin(args, providers.getMetaAccess(), snippetReflection);
}
EncodedGraph encodedGraph = new EncodedGraph(snippetEncoding, startOffset, snippetObjects, snippetNodeClasses, null, null, null, false, trackNodeSourcePosition);
try (DebugContext debug = openDebugContext("SVMSnippet_", method)) {
StructuredGraph result = new StructuredGraph.Builder(options, debug).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
PEGraphDecoder graphDecoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, result, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), null, snippetInvocationPlugins, new InlineInvokePlugin[0], parameterPlugin, null, null, null) {
@Override
protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean track) {
if (lookupMethod.equals(method)) {
assert !track || encodedGraph.trackNodeSourcePosition();
return encodedGraph;
} else {
throw VMError.shouldNotReachHere(method.format("%H.%n(%p)"));
}
}
};
graphDecoder.decode(method, trackNodeSourcePosition);
assert result.verify();
return result;
}
}
use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.
the class StringIndexOfConstantTest method editGraphBuilderConfiguration.
@Override
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
if (constantArgs != null) {
ConstantBindingParameterPlugin constantBinding = new ConstantBindingParameterPlugin(constantArgs, this.getMetaAccess(), this.getSnippetReflection());
conf.getPlugins().appendParameterPlugin(constantBinding);
}
return super.editGraphBuilderConfiguration(conf);
}
Aggregations