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>
John McCall
2011-Mar-10 19:50 UTC
[LLVMdev] Alternative to Adding New Intrinsics for Code-Generation?
On Mar 10, 2011, at 11:11 AM, Dan Bailey wrote:> John McCall wrote: >> >> 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. >> > > 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: > > declare i32 @_function(i32, i32, i32) > > define i32 @Test() { > entry: > %value = call i32 @_function(i32 0, i32 0, i32 0) > } > > Which generates this error in the verifying stage: > > Referencing function in another module! > %value = call i32 @_function(i32 0, i32 0, i32 0)That's asserting that @Test and @_function are in different llvm::Modules. That's a memory well-formedness constraints, not an IR constraint. That should honestly be getting checked for intrinsic functions, too. John.
Dan Bailey
2011-Mar-11 09:43 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"> <br> John McCall wrote: <blockquote cite="mid:740A4399-9628-4898-A10A-A0A72FE6E464@apple.com" type="cite"> <pre wrap="">On Mar 10, 2011, at 11:11 AM, Dan Bailey wrote: </pre> <blockquote type="cite"> <pre wrap="">John McCall wrote: </pre> <blockquote 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> <pre wrap="">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: declare i32 @_function(i32, i32, i32) define i32 @Test() { entry: %value = call i32 @_function(i32 0, i32 0, i32 0) } Which generates this error in the verifying stage: Referencing function in another module! %value = call i32 @_function(i32 0, i32 0, i32 0) </pre> </blockquote> <pre wrap=""><!----> That's asserting that @Test and @_function are in different llvm::Modules. That's a memory well-formedness constraints, not an IR constraint. That should honestly be getting checked for intrinsic functions, too. John. </pre> </blockquote> I wasn't aware of this restriction, but that does make sense, and looking at the error message, that seems really obvious now.<br> <br> Thanks for your help.<br> <br> </body> </html>
Apparently Analagous 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] RFC: Exception Handling Proposal II
- [LLVMdev] RFC: Exception Handling Proposal II