[nnc] Serialize initialization of LLVM targets (#60996)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/60996
We've had a bug report of weird LLVM initialization errors, e.g.,
```
Unexpected failure in LLVM JIT: Cannot choose between targets "x86-64" and "x86-64"
```
While I haven't repro'ed that exact message, I did run a stress-test that
compiles on many threads simultaneously, and it deadlocks in
TargetRegistry::lookupTarget. And in fact I remember debugging this before in
a different system, and finding "Clients are responsible for avoid race
conditions in registration" in
https://llvm.org/doxygen/TargetRegistry_8cpp_source.html.
So yeah, let's lock this thing.
ghstack-source-id: 132719018
Test Plan: Heavy multithreaded compilation. Not sure if it's suitable for landing.
Reviewed By: ZolotukhinM
Differential Revision: D29471343
fbshipit-source-id: b495e468b57e77796a08b627884d3efeca2d1f7c