[llvm-dev] How to handle ISD::STORE when both operands are FrameIndex?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 26 02:37:10 PDT 2019

On Wed, 26 Jun 2019 at 10:27, Gleb Popov <6yearold at gmail.com> wrote:
> For the sake of simplicity I decided not to bother with stack register yet and instead I just emit FrameIndex as immediate:
> bool MyBackendDAGToDAGISel::SelectAddrFI(SDValue &N, SDValue &R) {
>   if (N.getOpcode() != ISD::FrameIndex)
>     return false;
>   MachineFrameInfo &MFI = MF->getFrameInfo();
>   int FX = cast<FrameIndexSDNode>(N)->getIndex();
>   R = CurDAG->getTargetFrameIndex(FX, MVT::i32);
>   return true;
> }
> This way I end up with
> store %r1, [1]
> and handle it in my CPU emulator accordingly.
> So, instead of matching that FrameIndex in store, I really want to emit a load first and then use a register in the store instruction.

As you say, SelectAddrFI will only be used when looking into a store,
and I think that's fine: it's a specialized addressing-mode
implemented in just the right place. You need a completely separate
"case" in MyBackendDAGToDAGISel::Select to handle a bare

Since you don't use SP, your implementation of FrameIndex will
probably just be a MOV-immediate instruction. Final output would be
something like:

    mov %r1, 2     // Produced by matching the ISD::FrameIndex
    store %r1, [1]

I don't think load is going to be involved anywhere unless you meant
it in the broader sense where (e.g.) Z80 referred to its move
instructions as loads.



More information about the llvm-dev mailing list