[LLVMdev] c-like language implementation using llvm

Sean Silva silvas at purdue.edu
Wed Feb 13 13:41:30 PST 2013


Your hardware-level instruction set doesn't need to be exactly represented
in the LLVM IR. For example, when lowering C to LLVM IR, Clang converts
`~x` to `xor %x, -1`, this is then pattern matched during instruction
selection to turn it into a hardware-level `NOT` opcode. You can do the
same for the toffoli gate: generate equivalent logical operations in the
instructions that LLVM supports, and then pattern match Toffoli gates
during instruction selection.

>From looking at Wikipedia, I see that Toffoli gate is just `c XOR (a AND
b)`. By expanding it to this, LLVM will automatically be able to apply its
full arsenal of optimizations to optimize the program. For example, it will
automatically simplify `Toffoli(a,b,c) XOR Toffoli(b,a,c)` to 0. If you add
a new toffoli intrinsic or instruction, then you will have to teach LLVM to
do these kinds of optimizations (and there are *lots* of them).

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130213/af25184d/attachment.html>


More information about the llvm-dev mailing list