AddLocationNode question

Deneau, Tom tom.deneau at amd.com
Mon Apr 21 20:33:54 UTC 2014


Looking for advice from someone more knowledgeable about the graal Nodes...

This is for the host-based trampoline code that Gilles designed to handle hsail deoptimization.  The original code handled only registers in the hsail frame and I was trying to add support for stack slots.

The hsail frame looks like
    byte  num_s_regs;    // 32 bit registers, rounded up to an even number
    byte  num_d_regs;    // 64-bit registers
    short num_stack_slots;
    char _save_area[xxx];    // save area starts here
    // s_regs stored first
    // followed by dregs
    // followed by stackslots


The original code (which worked fine) to get a particular d register was as follows, using an IndexedLocationNode, indexed by the number of s registers...

            int longSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Long);
            long offset = config.hsailFrameSaveAreaOffset + longSize * (regNumber - HSAIL.d0.number);
            LocationNode numSRegsLocation = ConstantLocationNode.create(FINAL_LOCATION, Kind.Byte, config.hsailFrameNumSRegOffset, hostGraph);
            ValueNode numSRegs = hostGraph.unique(new FloatingReadNode(hsailFrame, numSRegsLocation, null, StampFactory.forInteger(8, false)));
            numSRegs = SignExtendNode.convert(numSRegs, StampFactory.forKind(Kind.Byte));
            location = IndexedLocationNode.create(FINAL_LOCATION, valueKind, offset, numSRegs, hostGraph, 4);

To get a particular stackslot I need to access 
    _save_area + num_s_regs * 4 + num_d_regs * 8  + slot.offset.

I thought this could perhaps be done by creating two IndexedLocationNodes (one using num_s_regs, one for num_d_regs) and then creating an AddLocationNode, combining the two IndexedLocationNodes.

but I am getting
com.oracle.graal.graph.GraalInternalError: java.lang.AssertionError: invalid input of type Value from 14|AddLocation to 10|IndexedLocation (x)

What is the recommended way to do this?  Here is the code I was using:

		int sizeInBits = (valueKind.isObject() || valueKind.getByteCount() == 8 ? 64 : 32);
		int slotStartOffset = HSAIL.getStackOffsetStart(slot, sizeInBits);
		int slotStartOffset = offsetToSaveArea + (numSRegs * 4) + (numDRegs * 8) + HSAIL.getStackOffsetStart(slot, sizeInBits);
		int longSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Long);
		long offset = config.hsailFrameSaveAreaOffset + slotStartOffset;

		LocationNode numSRegsLocation = ConstantLocationNode.create(FINAL_LOCATION, Kind.Byte, config.hsailFrameNumSRegOffset, hostGraph);
		ValueNode numSRegs = hostGraph.unique(new FloatingReadNode(hsailFrame, numSRegsLocation, null, StampFactory.forInteger(8, false)));
		numSRegs = SignExtendNode.convert(numSRegs, StampFactory.forKind(Kind.Byte));
		LocationNode locationSRegsPart = IndexedLocationNode.create(FINAL_LOCATION, valueKind, offset, numSRegs, hostGraph, 4);

		LocationNode numDRegsLocation = ConstantLocationNode.create(FINAL_LOCATION, Kind.Byte, config.hsailFrameNumDRegOffset, hostGraph);
		ValueNode numDRegs = hostGraph.unique(new FloatingReadNode(hsailFrame, numDRegsLocation, null, StampFactory.forInteger(8, false)));
		numDRegs = SignExtendNode.convert(numSRegs, StampFactory.forKind(Kind.Byte));
		LocationNode locationDRegsPart = IndexedLocationNode.create(FINAL_LOCATION, valueKind, 0, numDRegs, hostGraph, 8);

		LocationNode location = AddLocationNode.create(locationSRegsPart, locationDRegsPart, hostGraph);
        ValueNode valueNode = hostGraph.unique(new FloatingReadNode(hsailFrame, location, null, StampFactory.forKind(valueKind)));
        return valueNode;


A related question, could this have all been done with snippets?

-- Tom


More information about the graal-dev mailing list