use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class IntegerSwitchNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
NodeView view = NodeView.from(tool);
if (blockSuccessorCount() == 1) {
tool.addToWorkList(defaultSuccessor());
graph().removeSplitPropagate(this, defaultSuccessor());
} else if (value() instanceof ConstantNode) {
killOtherSuccessors(tool, successorIndexAtKey(value().asJavaConstant().asInt()));
} else if (tryOptimizeEnumSwitch(tool)) {
return;
} else if (tryRemoveUnreachableKeys(tool, value().stamp(view))) {
return;
}
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class RawLoadNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
ValueNode targetObject = object();
if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
ConstantNode objectConstant = (ConstantNode) targetObject;
ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
if (type != null && type.isArray()) {
JavaConstant arrayConstant = objectConstant.asJavaConstant();
if (arrayConstant != null) {
int stableDimension = objectConstant.getStableDimension();
if (stableDimension > 0) {
NodeView view = NodeView.from(tool);
long constantOffset = offset().asJavaConstant().asLong();
Constant constant = stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
boolean isDefaultStable = objectConstant.isDefaultStable();
if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
return ConstantNode.forConstant(stamp(view), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
}
}
}
}
}
}
return super.canonical(tool);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class VirtualFrameAccessorNode method insertDeoptimization.
protected void insertDeoptimization(VirtualizerTool tool) {
/*
* Escape analysis does not allow insertion of a DeoptimizeNode. We work around this
* restriction by inserting an always-failing guard, which will be canonicalized to a
* DeoptimizeNode later on.
*/
LogicNode condition = LogicConstantNode.contradiction();
tool.addNode(condition);
JavaConstant speculation = graph().getSpeculationLog().speculate(frame.getIntrinsifyAccessorsSpeculation());
tool.addNode(new FixedGuardNode(condition, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.InvalidateRecompile, speculation, false));
if (getStackKind() == JavaKind.Void) {
tool.delete();
} else {
/*
* Even though all usages will be eventually dead, we need to provide a valid
* replacement value for now.
*/
ConstantNode unusedValue = ConstantNode.forConstant(JavaConstant.defaultForKind(getStackKind()), tool.getMetaAccessProvider());
tool.addNode(unusedValue);
tool.replaceWith(unusedValue);
}
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.
private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
if (constant instanceof HotSpotObjectConstant) {
ConstantReflectionProvider constantReflection = context.getConstantReflection();
ResolvedJavaType type = constantReflection.asJavaType(constant);
if (type != null) {
MetaAccessProvider metaAccess = context.getMetaAccess();
Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
if (type instanceof HotSpotResolvedObjectType) {
ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
if (((HotSpotObjectConstant) constant).isCompressed()) {
return HotSpotCompressionNode.compress(getClass, oopEncoding);
} else {
return getClass;
}
} else {
/*
* Primitive classes are more difficult since they don't have a corresponding
* Klass* so get them from Class.TYPE for the java box type.
*/
HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
HotSpotResolvedJavaField typeField = null;
for (HotSpotResolvedJavaField f : a) {
if (f.getName().equals("TYPE")) {
typeField = f;
break;
}
}
if (typeField == null) {
throw new GraalError("Can't find TYPE field in class");
}
if (oopEncoding != null) {
stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
}
AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
return read;
} else {
return HotSpotCompressionNode.uncompress(read, oopEncoding);
}
}
}
}
return null;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CallSiteTargetNode method lower.
@Override
public void lower(LoweringTool tool) {
ConstantNode target = tryFold(getCallSite(), tool.getMetaAccess(), graph().getAssumptions());
if (target != null) {
graph().replaceFixedWithFloating(this, target);
} else {
InvokeNode invoke = createInvoke();
graph().replaceFixedWithFixed(this, invoke);
invoke.lower(tool);
}
}
Aggregations