Preserving function declarations from headers to be able to iterate over them in IR


Is there a way to say to clang that we should preserve all declarations in
compile module, even if they are not used anywhere in program?

Case where we would need that is when we have original program with
overloaded functions e.g

int foo(int *bar);
int foo(float *bar);
void foo_replacement(int *bar, int *min, int *max);
void foo_replacement(float *bar, float *min, float *max);

float ret;

int main () {
  return foo(&ret);

When we compile this to IR only int foo(float *bar); declaration is preserved.
Afterwards we would like to replace call of foo -> foo_replacement.

But in IR we don't have declarations to those functions anymore and we don't
have mangler to be able to generate correct function name for replacement
functions and arguments this becomes a problem.

We wouldn't like to have all function implementations there yet, because
compiling would get too slow. We just like to link them in afterwards.

If we would have original declarations left in IR we could just iterate over all
function declarations and do mapping between
int foo(int *bar) -> int foo_replacement(int *bar, int *min, int *max) etc.

Thanks, Mikael Lepistö