Optimization: Replace functions with thread unsafe variants + detection of multithreading

Hello,

My idea is to detect a multithreading and perform some transformations and get new possibilities for optimizations:

  1. Check pthread_create and follow CallInstr (goal: to know that we are in new thread), identify functions where fork is used and check all other CallIstr (we are in child) + check Windows variants of fork/ thread create…

  2. Check functions if they do not contain any of thread unsafe functions - if yes - mark such function as thread unsafe.

Then, we can replace some functions with thread unsafe variants in the functions, where we are sure that they are run by fork / pthread_create or already contain some thread unsafe functios.

Does anybody know if there is any such work in llvm?