[LLVMdev] c-like language implementation using llvm

Ali Javadi aj14889 at yahoo.com
Wed Feb 13 08:28:47 PST 2013


Hi there,

I asked this a few days ago and Sean gave a useful answer. Going back to the second question below, I want to clarify something.


On Feb 3, 2013, at 9:04 PM, Sean Silva <silvas at purdue.edu> wrote:

> On Sun, Feb 3, 2013 at 8:55 PM, Ali Javadi <aj14889 at yahoo.com> wrote:
>> I am keeping all the types of C, and adding my new types. I thought that,
>> for example, I can't map my new type to i32 because that's used for C
>> integers. That's what I meant by already used. Am I missing something?
> 
> If the type behaves like an i32 then use i32. For example, both signed
> and unsigned int get lowered to i32.
> 
>> That's a good point. However simple binary operations such as XOR are not
>> the only ones I'll be using. I have the Toffoli Gate for example which takes
>> in 3 operands:
>> http://en.wikipedia.org/wiki/Toffoli_gate
>> I guess I can use intrinsics for these things? If I do, can I leave its
>> behavior undefined? I would like it to appear just with the name toffoli in
>> the IR.
> 
> Just create the equivalent IR for the operation that the gate does;
> that will give LLVM the ability to optimize the operations. If you use
> an intrinsic, then LLVM won't be able to optimize the IR unless you
> change the optimization passes to recognize the intrinsic (and even
> then, the optimizations probably won't be as good).
> 

My case is a special case in that I have a totally new target (a quantum assembly language) and things like TOFFOLI, … are part of the final assembly instruction set. So "creating the equivalent IR for the operation that the gate does" doesn't really make sense, because that operation is at the most fundamental level. The question that I have is that, if I know that I need a TOFFOLI in my target assembly, should I just add that same instruction to the IR, or is there a value in creating an intrinsic function around it?
In the LLVM documentation it says that all new instructions should first be added as intrinsics. What does the intrinsic provide that simply adding the instruction doesn't?


Thanks,
Ali



More information about the llvm-dev mailing list