use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.
the class AMD64HotSpotAddressLowering method preProcess.
@Override
public void preProcess(StructuredGraph graph) {
if (graph.hasLoops()) {
LoopsData loopsData = new LoopsData(graph);
loopsData.detectedCountedLoops();
for (LoopEx loop : loopsData.countedLoops()) {
for (OffsetAddressNode offsetAdressNode : loop.whole().nodes().filter(OffsetAddressNode.class)) {
tryOptimize(offsetAdressNode, loop);
}
}
}
}
use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode 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.memory.address.OffsetAddressNode in project graal by oracle.
the class ArrayCopyCallNode method computeBase.
private ValueNode computeBase(ValueNode base, ValueNode pos) {
FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
graph().addBeforeFixed(this, basePtr);
Stamp wordStamp = StampFactory.forKind(runtime.getTarget().wordJavaKind);
ValueNode wordPos = IntegerConvertNode.convert(pos, wordStamp, graph(), NodeView.DEFAULT);
int shift = CodeUtil.log2(getArrayIndexScale(elementKind));
ValueNode scaledIndex = graph().unique(new LeftShiftNode(wordPos, ConstantNode.forInt(shift, graph())));
ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerStamp(wordStamp, getArrayBaseOffset(elementKind), graph())));
return graph().unique(new OffsetAddressNode(basePtr, offset));
}
use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.
the class AddressLoweringByUsePhase method run.
@Override
protected void run(StructuredGraph graph) {
// first replace address nodes hanging off known usages
for (Node node : graph.getNodes()) {
AddressNode address;
AddressNode lowered;
if (node instanceof ReadNode) {
ReadNode readNode = (ReadNode) node;
Stamp stamp = readNode.stamp(NodeView.DEFAULT);
address = readNode.getAddress();
lowered = lowering.lower(readNode, stamp, address);
} else if (node instanceof JavaReadNode) {
JavaReadNode javaReadNode = (JavaReadNode) node;
Stamp stamp = javaReadNode.stamp(NodeView.DEFAULT);
address = javaReadNode.getAddress();
lowered = lowering.lower(javaReadNode, stamp, address);
} else if (node instanceof FloatingReadNode) {
FloatingReadNode floatingReadNode = (FloatingReadNode) node;
Stamp stamp = floatingReadNode.stamp(NodeView.DEFAULT);
address = floatingReadNode.getAddress();
lowered = lowering.lower(floatingReadNode, stamp, address);
} else if (node instanceof AbstractWriteNode) {
AbstractWriteNode abstractWriteNode = (AbstractWriteNode) node;
Stamp stamp = abstractWriteNode.value().stamp(NodeView.DEFAULT);
address = abstractWriteNode.getAddress();
lowered = lowering.lower(abstractWriteNode, stamp, address);
} else if (node instanceof PrefetchAllocateNode) {
PrefetchAllocateNode prefetchAllocateNode = (PrefetchAllocateNode) node;
Stamp stamp = StampFactory.forKind(JavaKind.Object);
address = (AddressNode) prefetchAllocateNode.inputs().first();
lowered = lowering.lower(prefetchAllocateNode, stamp, address);
} else {
continue;
}
// in which case we want to use it not delete it!
if (lowered != address) {
// replace original with lowered at this usage only
// n.b. lowered is added unique so repeat lowerings will elide
node.replaceFirstInput(address, lowered);
// if that was the last reference we can kill the old (dead) node
if (address.hasNoUsages()) {
GraphUtil.killWithUnusedFloatingInputs(address);
}
}
}
// now replace any remaining unlowered address nodes
for (Node node : graph.getNodes()) {
AddressNode lowered;
if (node instanceof OffsetAddressNode) {
AddressNode address = (AddressNode) node;
lowered = lowering.lower(address);
} else {
continue;
}
// will always be a new AddresNode
node.replaceAtUsages(lowered);
GraphUtil.killWithUnusedFloatingInputs(node);
}
}
use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.
the class AddressLoweringPhase method run.
@Override
protected void run(StructuredGraph graph) {
lowering.preProcess(graph);
for (Node node : graph.getNodes()) {
AddressNode lowered;
if (node instanceof OffsetAddressNode) {
OffsetAddressNode address = (OffsetAddressNode) node;
lowered = lowering.lower(address.getBase(), address.getOffset());
lowering.postProcess(lowered);
} else {
continue;
}
node.replaceAtUsages(lowered);
GraphUtil.killWithUnusedFloatingInputs(node);
}
}
Aggregations