use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class DefaultHotSpotLoweringProvider method lowerOSRStartNode.
private void lowerOSRStartNode(OSRStartNode osrStart) {
StructuredGraph graph = osrStart.graph();
if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
StartNode newStart = graph.add(new StartNode());
ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
migrationEnd.setStateAfter(osrStart.stateAfter());
newStart.setNext(migrationEnd);
FixedNode next = osrStart.next();
osrStart.setNext(null);
migrationEnd.setNext(next);
graph.setStart(newStart);
final int wordSize = target.wordSize;
// @formatter:off
// taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
// @formatter:on
int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
int size = osrLocal.getStackKind().getSlotCount();
int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
AddressNode address = createOffsetAddress(graph, buffer, offset);
ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
osrLocal.replaceAndDelete(load);
graph.addBeforeFixed(migrationEnd, load);
}
// @formatter:off
// taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
// @formatter:on
final int lockCount = osrStart.stateAfter().locksSize();
final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
// buffer
for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
final int index = lock.index();
final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
final int offsetLockObject = locksOffset - index * 2 * wordSize;
// load the displaced mark from the osr buffer
AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
// we need to initialize the stack slot for the lock
BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
graph.addBeforeFixed(migrationEnd, beginLockScope);
// write the displaced mark to the correct stack slot
AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
graph.addBeforeFixed(migrationEnd, writeStackSlot);
// load the lock object from the osr buffer
AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
lock.replaceAndDelete(loadObject);
graph.addBeforeFixed(migrationEnd, loadObject);
}
osrStart.replaceAtUsagesAndDelete(newStart);
}
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class SnippetTemplate method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder(snippet.toString()).append('(');
String sep = "";
for (int i = 0; i < parameters.length; i++) {
String name = "[" + i + "]";
Object value = parameters[i];
buf.append(sep);
sep = ", ";
if (value == null) {
buf.append("<null> ").append(name);
} else if (value.equals(UNUSED_PARAMETER)) {
buf.append("<unused> ").append(name);
} else if (value.equals(CONSTANT_PARAMETER)) {
buf.append("<constant> ").append(name);
} else if (value instanceof ParameterNode) {
ParameterNode param = (ParameterNode) value;
buf.append(param.getStackKind().getJavaName()).append(' ').append(name);
} else {
ParameterNode[] params = (ParameterNode[]) value;
String kind = params.length == 0 ? "?" : params[0].getStackKind().getJavaName();
buf.append(kind).append('[').append(params.length).append("] ").append(name);
}
}
return buf.append(')').toString();
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class SnippetTemplate method bind.
/**
* Gets the instantiation-time bindings to this template's parameters.
*
* @return the map that will be used to bind arguments to parameters when inlining this template
*/
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
for (int i = 0; i < parameters.length; i++) {
Object parameter = parameters[i];
assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
Object argument = args.values[i];
if (parameter instanceof ParameterNode) {
if (argument instanceof ValueNode) {
replacements.put((ParameterNode) parameter, (ValueNode) argument);
} else {
JavaKind kind = ((ParameterNode) parameter).getStackKind();
assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
JavaConstant constant = forBoxed(argument, kind);
replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
}
} else if (parameter instanceof ParameterNode[]) {
ParameterNode[] params = (ParameterNode[]) parameter;
Varargs varargs = (Varargs) argument;
int length = params.length;
List<?> list = null;
Object array = null;
if (varargs.value instanceof List) {
list = (List<?>) varargs.value;
assert list.size() == length : length + " != " + list.size();
} else {
array = varargs.value;
assert array != null && array.getClass().isArray();
assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
}
for (int j = 0; j < length; j++) {
ParameterNode param = params[j];
assert param != null;
Object value = list != null ? list.get(j) : Array.get(array, j);
if (value instanceof ValueNode) {
replacements.put(param, (ValueNode) value);
} else {
JavaConstant constant = forBoxed(value, param.getStackKind());
ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
replacements.put(param, element);
}
}
} else {
assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
}
}
return replacements;
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class SnippetTemplate method updateStamps.
private void updateStamps(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) {
for (ValueNode node : placeholderStampedNodes) {
ValueNode dup = (ValueNode) duplicates.get(node);
Stamp replaceeStamp = replacee.stamp(NodeView.DEFAULT);
if (node instanceof Placeholder) {
Placeholder placeholderDup = (Placeholder) dup;
placeholderDup.makeReplacement(replaceeStamp);
} else {
dup.setStamp(replaceeStamp);
}
}
for (ParameterNode paramNode : snippet.getNodes(ParameterNode.TYPE)) {
for (Node usage : paramNode.usages()) {
Node usageDup = duplicates.get(usage);
propagateStamp(usageDup);
}
}
}
use of org.graalvm.compiler.nodes.ParameterNode in project graal by oracle.
the class EAMergingTest method testSimpleMerge.
@Test
public void testSimpleMerge() {
testEscapeAnalysis("simpleMergeSnippet", null, false);
assertDeepEquals(1, returnNodes.size());
assertTrue(returnNodes.get(0).result() instanceof ValuePhiNode);
PhiNode phi = (PhiNode) returnNodes.get(0).result();
assertTrue(phi.valueAt(0) instanceof ParameterNode);
assertTrue(phi.valueAt(1) instanceof ParameterNode);
}
Aggregations