[LLVMdev] Help regarding ad new functionality in Backend

Tim Northover t.p.northover at gmail.com
Wed Jun 11 02:02:15 PDT 2014


Hi Pratik

On 11 June 2014 09:30, pratik dand <pratikdand143 at gmail.com> wrote:
> Note: gcd is just an example.

gcd is very difficult, because an implementation in terms of LLVM
primitive nodes involves control flow. For that one, I'd create an
"@llvm.mytarget.gcd" intrinsic, and spot it earlier somehow (possibly
with an IR-level pass).

For simpler cases, this is just what PatFrag was created for. For
example, AArch64 has an add that sign extends both its arguments
before doing the addition, so we can write:

    def extending_add : PatFrag<(ops node:$LHS, node:$RHS), (add (sext
node:$LHS), (sext node:$RHS))>;

and then use this in the pattern as normal:

   [(set GPR64:$Rd, (extending_add GPR32:$Rn, GPR32:$Rm))]

what happens is TableGen pastes the definition of the PatFrag "(add
(sext ...), ...)" into the pattern where we've written extending_add.
It's mostly as if we'd written the "(add (sext ...), ...)" one
ourselves. This only works within a single basic block though, and has
some slight edge-cases around type-inference that can be annoying.

Cheers.

Tim.



More information about the llvm-dev mailing list