LLVM pass adding function call specific to Linux, middle-end or backend?

Hi everyone,

I have already developped some optimizer pass in the middle-end playing with the LLVM IR.

Now, I would like to write a pass that are going to add some functions calls that exist only on Linux system (both x86 and x64). I was wondering about the right way to do it. Does LLVM offer any way to obtain the current architecture in the middle-end (analysis pass maybe)? If so, should I write this pass in the middle-end using the flexibility of LLVM IR to add function call and some if/else branch to avoid transformation on unsupported OS? Or should I write my pass somewhere (where?) in the backend’s specific part for Linux x86/x64 architecture?

Thank you for your help.