Hi Sean,>> Can I just utilize the i1 type? Is the >> i1 type already used for something, and thus might create a conflict? > > I think you are very confused. LLVM's types are meant to be used to > represent *your* program :) They can't be "already used".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?> >> 2) Can I use LLVM's intrinsic functions for my gates, something like >> @llvm.NOT(i1 %val)? Would the fact that the implementation of these external >> functions is not defined, create a problem in translation down to IR? I have >> used Clang's "built-ins" in the front-end and that seems to do the job at >> the parser level. > > Again, I think you are confused. Just use the operations that are > built into LLVM, such as > <http://llvm.org/docs/LangRef.html#bitwise-binary-operations>. One > slight point of confusion is that LLVM tries to be minimal so there is > no NOT instruction; `NOT X` is represented as `XOR X, -1`. You > probably won't need to add an intrinsic unless you are doing something > _very_ exotic. >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. Thanks, Ali -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130203/e7691633/attachment.html>
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). -- Sean Silva
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
Maybe Matching Threads
- [LLVMdev] c-like language implementation using llvm
- [LLVMdev] c-like language implementation using llvm
- [LLVMdev] c-like language implementation using llvm
- [LLVMdev] c-like language implementation using llvm
- [LLVMdev] freeing alloca'd variables before function exits