Query about materializable functions and passes


I know I'm a bit late to the table, but I've come across a problem with the new (mid-October last year) changes made to materializable functions.

When developing OpenCL and other on-line compilation models we often want to link in a large set of kernel library functions for use by the user program. There's so many of these functions that we don't want to run passes on them, as most of them will be discarded later in the compilation pipeline. This is where materializable functions came in handy. We could lazy-load the kernel library module and link it in to the user program, knowing only that declarations were being linked in for the time being, e.g:

; Materializable
; Function Attrs: nounwind readnone
declarespir_func i32 @_Z5mul24ii(i32 %s1, i32 %s2) #4

Then several passes would run that determined which functions were needed, and would materialize the function bodies. Once all the required functions were determined, we could strip the dead prototypes and continue on our way.

Now it seems that materializable functions are treated like empty function declarations:

; Materializable
; Function Attrs: nounwind readnone
define spir_func i32 @_Z5mul24ii(i32 %s1, i32 %s2) #4 {}

This means that if we keep them around in a module beyond passes that we control, a function pass will run and assert because the function doesn't contain basic blocks, or crash for some other reason.

Is there something that can be done about this? I know the changes were made for a reason (seems like it was LTO), but is there a way we can bring this functionality back in some form?