use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class BytecodeParser method createStateAfterStartOfReplacementGraph.
/**
* Creates the frame state after the start node of a graph for an {@link IntrinsicContext
* intrinsic} that is the parse root (either for root compiling or for post-parse inlining).
*/
private FrameState createStateAfterStartOfReplacementGraph() {
assert parent == null;
assert frameState.getMethod().equals(intrinsicContext.getIntrinsicMethod());
assert bci() == 0;
assert frameState.stackSize() == 0;
FrameState stateAfterStart;
if (intrinsicContext.isPostParseInlined()) {
stateAfterStart = graph.add(new FrameState(BytecodeFrame.BEFORE_BCI));
} else {
ResolvedJavaMethod original = intrinsicContext.getOriginalMethod();
ValueNode[] locals;
if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) {
locals = new ValueNode[original.getMaxLocals()];
for (int i = 0; i < locals.length; i++) {
ValueNode node = frameState.locals[i];
if (node == FrameState.TWO_SLOT_MARKER) {
node = null;
}
locals[i] = node;
}
} else {
locals = new ValueNode[original.getMaxLocals()];
int parameterCount = original.getSignature().getParameterCount(!original.isStatic());
for (int i = 0; i < parameterCount; i++) {
ValueNode param = frameState.locals[i];
if (param == FrameState.TWO_SLOT_MARKER) {
param = null;
}
locals[i] = param;
assert param == null || param instanceof ParameterNode || param.isConstant();
}
}
ValueNode[] stack = {};
int stackSize = 0;
ValueNode[] locks = {};
List<MonitorIdNode> monitorIds = Collections.emptyList();
stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
}
return stateAfterStart;
}
use of org.graalvm.compiler.nodes.ParameterNode 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.nodes.ParameterNode in project graal by oracle.
the class IntegerExactFoldTest method testFolding.
@Test
public void testFolding() {
StructuredGraph graph = prepareGraph();
IntegerStamp a = StampFactory.forInteger(bits, lowerBoundA, upperBoundA);
IntegerStamp b = StampFactory.forInteger(bits, lowerBoundB, upperBoundB);
List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
params.get(0).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(0), a)), x -> x instanceof IntegerExactArithmeticNode);
params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
assertNotNull("original node must be in the graph", originalNode);
new CanonicalizerPhase().apply(graph, getDefaultHighTierContext());
ValueNode node = findNode(graph);
boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class SystemArrayCopyTest method parse.
@Override
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
StructuredGraph graph = super.parse(builder, graphBuilderSuite);
if (argsToBind != null) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (args[index] != null) {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
}
}
return graph;
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class InstalledCodeExecuteHelperTest method parse.
@Override
protected StructuredGraph parse(Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
StructuredGraph graph = super.parse(builder, graphBuilderSuite);
if (argsToBind != null) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
for (int i = 0; i < argsToBind.length; i++) {
ParameterNode param = graph.getParameter(i);
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
}
return graph;
}
Aggregations