[llvm-dev] Expanding a PseudoOp and accessing the DAG

Phil Tomson via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 13 12:26:17 PST 2016


I've got this PseudoOp defined:

def SDT_RELADDR       : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisInt<1>]>;
def XSTGRELADDR       : SDNode<"XSTGISD::RELADDR", SDT_RELADDR>;


let Constraints = "$dst = $addr" in { //, Uses= [GRP] in {
  def RelAddr           : XSTGPseudo< (outs GPRC:$dst),
                                      (ins i64imm:$spoff, i64imm:$addr),
                                      "! RELADDR $spoff, $dst",
                                      [(set GPRC:$dst, (XSTGRELADDR
i64:$spoff,
                                                                    (i64
(XSTGMVINI i64:$addr))
                                                       )
                                      )]>;
}

GlobalAddresses get lowered to RelAddr nodes in our ISelLowering code. Now
I just need to be able to expand this in our overridden expandPostRAPseudo
function, however, I'm a bit worried that expansion happens too late (after
things should already be MI's, it seems). So things like patterns that try
to  match on that XSTGMVINI would have already been matched.

[as an aside, we've got patterns like:

def : Pat<(XSTGMVINI tglobaladdr:$off),
          (MOVIMMZ_I64 tglobaladdr:$off)>;

]

So, first off, if I wanted to expand that DAG for the RelAddr Node, and I
want something like (the first BuildMI below is pseudo code as I'm not sure
how to accomplish it):

case  XSTG::RelAddr:
    BuildMI(MBB, MI, DL, MI->getOperand(1).DAG...) ???
    BuildMI(MBB, MI, DL, get(XSTG::LOADI32_RI), MI->getOperand(0).getReg())
          .addReg(MI->getOperand(0).getReg())
          .addReg(XSTG::GRP);

Basically, I want to grab the XSTGMVINI that is the second operand to the
XSTGRELADDR node from the psuedo op pattern above and then build an MI
based on that DAG.

The resulting assembly for that DAG would be:
    movimm       rX, %rel(SYMBOL) #offset to SYMBOL
    load             rX, rX, GRP # rX <- mem[rx+GRP]

Where the 'movimm' corresponds to the first BuildMI above (and is the
XSTGMVINI part of the DAG) and the 'load' corresponds to the second BuildMI
above (I have that one working).

And secondly,

Would this RelAddr DAG:

[(set GPRC:$dst, (XSTGRELADDR i64:$spoff,
                                                         (i64 (XSTGMVINI
i64:$addr)
)]

Have been pattern matched (as per the PAT above) such that the XSTGMVINI
would have been transformed into:

MOVIMMZ_I64 tglobaladdr:$addr)

?

Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160113/b972b845/attachment.html>


More information about the llvm-dev mailing list