[LLVMdev] How to calculate the address in TableGen?

Tim Northover t.p.northover at gmail.com
Sun Jul 22 08:30:24 PDT 2012


Hi Yang,

[tried:]
> def : Pat<(i32 (extloadi16_a addr:$src)), (OR (LBu addr:$src), (SLL (LBu addr:($src+1)), 8))>;

> How to calculate a new address in TableGen?

Unfortunately you can't do arithmetic like that directly in TableGen.

You might be able to apply an SDNodeXForm to the right-hand side to
calculate the "addr+1", giving something like "(OR (LBu addr:$src),
(SLL (LBU (AddOne addr:$src)), 8))". But I seem to remember trying the
same thing for a very similar issue I was having and running into
problems; I can't remember the details but I think either TableGen
ignored the XForm or didn't like the double-use of the addr on the
right-hand side.

You've also got the complication that an instruction sequence which
calculates $src may not be trivially adaptable to one that calculates
$src+1, which means even more problems for this approach since the
selection of the instruction sequence will only ever happen once, on
the left-hand side of the pattern. This could complicate the required
XForm significantly, even if the approach works.

What I ended up doing for my situation was creating a special Wrapper
during ISelLowering that, instead of having just one address operand,
had two: one evaluating to just $src, and the other to $src+1, so you
might select it with something like:

def : Pat<(i32 (extload16_a_bytewrapper addr:$src, addr:$srcplus1)),
(OR (LBu addr:$src), (SLL (LBu addr:$srcplus1), 8))>;

Hope this helps.

Tim.



More information about the llvm-dev mailing list