Dan Bailey
2011-Mar-10 18:43 UTC
[LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
Hi, I've written an IR->IR translation as part of a high-level language I've designed. It replaces my own specific functions in LLVM passes with custom logic. As part of the process, it needs to perform constant propagation and inlining prior to doing any translation. Initially I just used simple function declarations to define these specific functions, but the verification pass requires that each function declaration also has a definition. Without wanting to create dummy function definitions, I found I had to introduce new intrinsics, which does what I want but is obviously not desired. How can I do this without using intrinsics? I looked for function attributes to see if I can flag a function as not requiring a definition, but there doesn't seem to be any. It would be useful to ignore a function as if it was an intrinsic during this prior stage of passes. Any suggestions would be welcome? Thanks, Dan
John McCall
2011-Mar-10 18:51 UTC
[LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
On Mar 10, 2011, at 10:43 AM, Dan Bailey wrote:> I've written an IR->IR translation as part of a high-level language I've > designed. It replaces my own specific functions in LLVM passes with > custom logic. > > As part of the process, it needs to perform constant propagation and > inlining prior to doing any translation. Initially I just used simple > function declarations to define these specific functions, but the > verification pass requires that each function declaration also has a > definition. Without wanting to create dummy function definitions, I > found I had to introduce new intrinsics, which does what I want but is > obviously not desired. > > How can I do this without using intrinsics? I looked for function > attributes to see if I can flag a function as not requiring a > definition, but there doesn't seem to be any. It would be useful to > ignore a function as if it was an intrinsic during this prior stage of > passes. Any suggestions would be welcome?The verifier certainly doesn't object in general to function declarations. I'm guessing that the problem is that you're giving your declarations internal linkage, which is indeed an error for normal functions. The solution is to not give these "intrinsics" internal linkage when you declare them. John.
Dan Bailey
2011-Mar-10 19:11 UTC
[LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> John McCall wrote: <blockquote cite="mid:FAB334D8-72D0-40FB-B133-A9430870B701@apple.com" type="cite"> <pre wrap="">On Mar 10, 2011, at 10:43 AM, Dan Bailey wrote: </pre> <blockquote type="cite"> <pre wrap="">I've written an IR->IR translation as part of a high-level language I've designed. It replaces my own specific functions in LLVM passes with custom logic. As part of the process, it needs to perform constant propagation and inlining prior to doing any translation. Initially I just used simple function declarations to define these specific functions, but the verification pass requires that each function declaration also has a definition. Without wanting to create dummy function definitions, I found I had to introduce new intrinsics, which does what I want but is obviously not desired. How can I do this without using intrinsics? I looked for function attributes to see if I can flag a function as not requiring a definition, but there doesn't seem to be any. It would be useful to ignore a function as if it was an intrinsic during this prior stage of passes. Any suggestions would be welcome? </pre> </blockquote> <pre wrap=""><!----> The verifier certainly doesn't object in general to function declarations. I'm guessing that the problem is that you're giving your declarations internal linkage, which is indeed an error for normal functions. The solution is to not give these "intrinsics" internal linkage when you declare them. John. </pre> </blockquote> <br> That makes sense, but it's not working for me. All the functions are defined as ExternalLinkage, this is (a simplified version of) the pre-optimised ir:<br> <br> declare i32 @_function(i32, i32, i32)<br> <br> define i32 @Test() {<br> entry:<br> %value = call i32 @_function(i32 0, i32 0, i32 0)<br> }<br> <br> Which generates this error in the verifying stage:<br> <br> Referencing function in another module!<br> %value = call i32 @_function(i32 0, i32 0, i32 0)<br> <br> Thanks,<br> Dan<br> <br> </body> </html>
Reasonably Related Threads
- [LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
- [LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
- [LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
- [LLVMdev] [ptx] Propose a register class naming convention change
- [LLVMdev] [llvm-commits] [PATCH][RFC] NVPTX Backend