My idea is to detect a multithreading and perform some transformations and get new possibilities for optimizations:
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…
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?