use of org.graalvm.compiler.nodes.calc.AddNode in project graal by oracle.
the class AArch64AddressLoweringByUse method improve.
protected boolean improve(AArch64Kind kind, AArch64AddressNode ret) {
AArch64Address.AddressingMode mode = ret.getAddressingMode();
// if we have already set a displacement or set to base only mode then we are done
if (isDisplacementMode(mode) || isBaseOnlyMode(mode)) {
return false;
}
ValueNode base = ret.getBase();
ValueNode index = ret.getIndex();
// avoid a constant or null base if possible
if (base == null) {
ret.setBase(index);
ret.setIndex(base);
return true;
}
// as we ought not to see two JavaConstant values
if (base.isJavaConstant() && base.asJavaConstant().getJavaKind().isNumericInteger() && index != null && !index.isJavaConstant()) {
ret.setBase(index);
ret.setIndex(base);
return true;
}
// if the base is an add then move it up
if (index == null && base instanceof AddNode) {
AddNode add = (AddNode) base;
ret.setBase(add.getX());
ret.setIndex(add.getY());
return true;
}
// we can try to fold a JavaConstant index into a displacement
if (index != null && index.isJavaConstant()) {
JavaConstant javaConstant = index.asJavaConstant();
if (javaConstant.getJavaKind().isNumericInteger()) {
long disp = javaConstant.asLong();
mode = immediateMode(kind, disp);
if (isDisplacementMode(mode)) {
index = null;
// we can fold this in as a displacement
// but first see if we can pull up any additional
// constants added into the base
boolean tryNextBase = (base instanceof AddNode);
while (tryNextBase) {
AddNode add = (AddNode) base;
tryNextBase = false;
ValueNode child = add.getX();
if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
long newDisp = disp + child.asJavaConstant().asLong();
AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
disp = newDisp;
mode = newMode;
base = add.getY();
ret.setBase(base);
tryNextBase = (base instanceof AddNode);
}
} else {
child = add.getY();
if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
long newDisp = disp + child.asJavaConstant().asLong();
AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
disp = newDisp;
mode = newMode;
base = add.getX();
ret.setBase(base);
tryNextBase = (base instanceof AddNode);
}
}
}
}
if (disp != 0) {
// ok now set the displacement in place of an index
ret.setIndex(null);
int scaleFactor = computeScaleFactor(kind, mode);
ret.setDisplacement(disp, scaleFactor, mode);
} else {
// reset to base register only
ret.setIndex(null);
ret.setDisplacement(0, 1, AArch64Address.AddressingMode.BASE_REGISTER_ONLY);
}
return true;
}
}
}
// nope cannot improve this any more
return false;
}
use of org.graalvm.compiler.nodes.calc.AddNode in project graal by oracle.
the class InstrumentPhase method insertCounter.
protected static void insertCounter(StructuredGraph graph, PhaseContext context, JavaConstant tableConstant, FixedWithNextNode targetNode, int slotIndex) {
assert (tableConstant != null);
TypeReference typeRef = TypeReference.createExactTrusted(context.getMetaAccess().lookupJavaType(tableConstant));
ConstantNode table = graph.unique(new ConstantNode(tableConstant, StampFactory.object(typeRef, true)));
ConstantNode rawIndex = graph.unique(ConstantNode.forInt(slotIndex));
LoadIndexedNode load = graph.add(new LoadIndexedNode(null, table, rawIndex, JavaKind.Long));
ConstantNode one = graph.unique(ConstantNode.forLong(1L));
ValueNode add = graph.unique(new AddNode(load, one));
StoreIndexedNode store = graph.add(new StoreIndexedNode(table, rawIndex, JavaKind.Long, add));
graph.addAfterFixed(targetNode, load);
graph.addAfterFixed(load, store);
}
use of org.graalvm.compiler.nodes.calc.AddNode in project graal by oracle.
the class CheckcastArrayCopyCallNode method computeBase.
private ValueNode computeBase(ValueNode base, ValueNode pos) {
FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
graph().addBeforeFixed(this, basePtr);
int shift = CodeUtil.log2(getArrayIndexScale(JavaKind.Object));
ValueNode extendedPos = IntegerConvertNode.convert(pos, StampFactory.forKind(runtime.getTarget().wordJavaKind), graph(), NodeView.DEFAULT);
ValueNode scaledIndex = graph().unique(new LeftShiftNode(extendedPos, ConstantNode.forInt(shift, graph())));
ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerBits(PrimitiveStamp.getBits(scaledIndex.stamp(NodeView.DEFAULT)), getArrayBaseOffset(JavaKind.Object), graph())));
return graph().unique(new OffsetAddressNode(basePtr, offset));
}
use of org.graalvm.compiler.nodes.calc.AddNode in project graal by oracle.
the class AddressOfVMThreadLocalNode method lower.
@Override
public void lower(LoweringTool tool) {
assert threadLocalInfo.offset >= 0;
ValueNode base = holder;
if (base.getStackKind() == JavaKind.Object) {
base = graph().unique(new FloatingWordCastNode(FrameAccess.getWordStamp(), base));
}
assert base.getStackKind() == FrameAccess.getWordKind();
ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, graph());
ValueNode address = graph().unique(new AddNode(base, offset));
replaceAtUsagesAndDelete(address);
}
use of org.graalvm.compiler.nodes.calc.AddNode in project graal by oracle.
the class CEntryPointSupport method registerEntryPointContextPlugins.
private static void registerEntryPointContextPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, CEntryPointContext.class);
r.register0("getCurrentIsolateThread", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (SubstrateOptions.MultiThreaded.getValue()) {
b.addPush(JavaKind.Object, ReadRegisterFixedNode.forIsolateThread());
} else if (SubstrateOptions.SpawnIsolates.getValue()) {
ValueNode heapBase = b.add(ReadRegisterFixedNode.forHeapBase());
ConstantNode addend = b.add(ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_ISOLATE_TO_SINGLE_THREAD_ADDEND));
b.addPush(JavaKind.Object, new AddNode(heapBase, addend));
} else {
b.addPush(JavaKind.Object, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_THREAD_SENTINEL.rawValue()));
}
return true;
}
});
r.register0("getCurrentIsolate", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (SubstrateOptions.SpawnIsolates.getValue()) {
b.addPush(JavaKind.Object, ReadRegisterFixedNode.forHeapBase());
} else {
b.addPush(JavaKind.Object, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_ISOLATE_SENTINEL.rawValue()));
}
return true;
}
});
r.register1("isCurrentThreadAttachedTo", Isolate.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
b.addPush(JavaKind.Boolean, new CEntryPointUtilityNode(UtilityAction.IsAttached, isolate));
return true;
}
});
}
Aggregations