use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class ReplaceConstantNodesPhase method handleLoadMethodCounters.
/**
* Replace {@link LoadMethodCountersNode} with indirect load
* {@link ResolveMethodAndLoadCountersNode}, expose a klass constant of the holder.
*
* @param graph
* @param stateMapper
* @param node
* @param context
*/
private static void handleLoadMethodCounters(StructuredGraph graph, FrameStateMapperClosure stateMapper, LoadMethodCountersNode node, PhaseContext context) {
ResolvedJavaType type = node.getMethod().getDeclaringClass();
Stamp hubStamp = context.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
ConstantReflectionProvider constantReflection = context.getConstantReflection();
ConstantNode klassHint = ConstantNode.forConstant(hubStamp, constantReflection.asObjectHub(type), context.getMetaAccess(), graph);
FixedWithNextNode replacement = graph.add(new ResolveMethodAndLoadCountersNode(node.getMethod(), klassHint));
insertReplacement(graph, stateMapper, node, replacement);
node.replaceAtUsages(replacement, n -> !(n instanceof ResolveMethodAndLoadCountersNode));
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class ReplaceConstantNodesPhase method tryToReplaceWithExisting.
/**
* Try to find dominating node doing the resolution that can be reused.
*
* @param graph
* @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
* resolution.
*/
private static void tryToReplaceWithExisting(StructuredGraph graph, ConstantNode node) {
ScheduleResult schedule = graph.getLastSchedule();
NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
EconomicMap<Block, Node> blockToExisting = EconomicMap.create();
for (Node n : node.usages().filter(n -> isReplacementNode(n))) {
blockToExisting.put(nodeToBlock.get(n), n);
}
for (Node use : node.usages().filter(n -> !isReplacementNode(n)).snapshot()) {
boolean replaced = false;
Block b = nodeToBlock.get(use);
Node e = blockToExisting.get(b);
if (e != null) {
// the use is scheduled after it.
for (Node n : blockToNodes.get(b)) {
if (n.equals(use)) {
// Usage is before initialization, can't use it
break;
}
if (n.equals(e)) {
use.replaceFirstInput(node, e);
replaced = true;
break;
}
}
}
if (!replaced) {
// Look for dominating blocks that have existing nodes
for (Block d : blockToExisting.getKeys()) {
if (strictlyDominates(d, b)) {
use.replaceFirstInput(node, blockToExisting.get(d));
break;
}
}
}
}
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class LoadJavaMirrorWithKlassPhase method run.
@Override
protected void run(StructuredGraph graph, PhaseContext context) {
for (ConstantNode node : getConstantNodes(graph)) {
JavaConstant constant = node.asJavaConstant();
ValueNode freadNode = getClassConstantReplacement(graph, context, constant);
if (freadNode != null) {
node.replace(graph, freadNode);
}
}
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class IdentityHashCodeNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (object.isConstant()) {
assert object.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp;
JavaConstant c = (JavaConstant) object.asConstant();
if (ImmutableCode.getValue(tool.getOptions())) {
return this;
}
JavaConstant identityHashCode = null;
if (c.isNull()) {
identityHashCode = JavaConstant.forInt(0);
} else {
identityHashCode = JavaConstant.forInt(((HotSpotObjectConstant) c).getIdentityHashCode());
}
return new ConstantNode(identityHashCode, StampFactory.forConstant(identityHashCode));
}
return this;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class LoadFieldNode method asPhi.
private static PhiNode asPhi(ConstantFieldProvider constantFields, ConstantReflectionProvider constantReflection, MetaAccessProvider metaAcccess, OptionValues options, ValueNode forObject, ResolvedJavaField field, Stamp stamp) {
if (!field.isStatic() && field.isFinal() && forObject instanceof ValuePhiNode && ((ValuePhiNode) forObject).values().filter(isNotA(ConstantNode.class)).isEmpty()) {
PhiNode phi = (PhiNode) forObject;
ConstantNode[] constantNodes = new ConstantNode[phi.valueCount()];
for (int i = 0; i < phi.valueCount(); i++) {
ConstantNode constant = ConstantFoldUtil.tryConstantFold(constantFields, constantReflection, metaAcccess, field, phi.valueAt(i).asJavaConstant(), options);
if (constant == null) {
return null;
}
constantNodes[i] = constant;
}
return new ValuePhiNode(stamp, phi.merge(), constantNodes);
}
return null;
}
Aggregations