[PATCH] D108850: [LLD] Remove global state in lldCommon

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 17 15:41:57 PDT 2021


rnk added a comment.

In D108850#3000699 <https://reviews.llvm.org/D108850#3000699>, @mehdi_amini wrote:

> Actually MLIR does not use Parallel.h anymore, especially to avoid relying on any global. We're using instead a ThreadPool owned by the MLIRContext, the client applications can inject a thread pool in the context to manage sharing threads how they see fit.
>
> Our wrappers are in https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/Threading.h and operate around llvm/Support/ThreadPool.h.
>
> The mechanism introduced in Parallel.h in this revision (wrapThreadState) seems mostly like some sort of "workaround" to be able to continue to rely on some global way to pass state around in `lld` instead of having something more explicit, which we favored in MLIR (where like in LLVM, the Context is fairly centric and not accessed through a global).

I see, I guess that is new as of June, so news to me. :)

I think there are really two key operations done throughout the linker that need the context:

- memory allocation (via BumpPtrAllocator)
- diagnostics (warnings & errors)

Conventional C++ programs use a global heap because passing around a pool or arena is too much work.

I think I would like to see central LLD context classes, but I'm open to using thread locals on the way to that restructuring.

----

As far as this iteration of the patch goes, I think it looks good, but I think other linker port owners should sign off on it too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108850/new/

https://reviews.llvm.org/D108850



More information about the llvm-commits mailing list