[all-commits] [llvm/llvm-project] 3a2594: [mlir-translate] Move InitLLVM ownership to the st...
Anutosh Bhat via All-commits
all-commits at lists.llvm.org
Thu Sep 10 03:05:56 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 3a25949882c3ee496b523bcc816974c6ddfa9850
https://github.com/llvm/llvm-project/commit/3a25949882c3ee496b523bcc816974c6ddfa9850
Author: Anutosh Bhat <andersonbhat491 at gmail.com>
Date: 2026-09-10 (Thu, 10 Sep 2026)
Changed paths:
M mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
M mlir/tools/mlir-translate/mlir-translate.cpp
Log Message:
-----------
[mlir-translate] Move InitLLVM ownership to the standalone tool (#222570)
Please Read: [RFC: Embeddable LLVM tool drivers for long-lived
hosts](https://discourse.llvm.org/t/rfc-embeddable-llvm-tool-drivers-for-long-lived-hosts/91754)
and [Why `InitLLVM` ownership matters section in the
RFC](https://discourse.llvm.org/t/rfc-embeddable-llvm-tool-drivers-for-long-lived-hosts/91754#p-367966-why-initllvm-ownership-matters-7)
`mlirTranslateMain` currently constructs `InitLLVM` internally. This is
fine when `mlir-translate` runs once as a standalone executable, but it
does not work for an in-process setting where the host remains alive and
invokes multiple LLVM tools. When `mlirTranslateMain` returns, the
`InitLLVM` destructor calls `llvm_shutdown()` and destroys
process-global `ManagedStatic` state that may still be needed by the
host and subsequent tool invocations.
[WasmBolt](https://github.com/anutosh491/WasmBolt) (try
[here](https://anutosh21.github.io/WasmBolt/)) is a concrete example of
such a host. It runs Clang, `mlir-opt`, `opt`, `llc` and LLD inside one
browser-hosted LLVM process, allowing users to inspect and transform
code without a remote compilation server.
As described in the [MLIR section of the
RFC](https://discourse.llvm.org/t/rfc-embeddable-llvm-tool-drivers-for-long-lived-hosts/91754#p-367966-mlir-13),
the real `mlir-opt` driver already works in this environment.
`MlirOptMain` does not own `InitLLVM`, so the surrounding host can
control the process lifetime. `mlirTranslateMain` does not currently
provide the same ownership boundary, which prevents us from integrating
it in the same clean way.
The working `mlir-opt` pipeline can be seen here:
https://www.youtube.com/watch?v=yga2lWelne4
This patch makes the two MLIR driver interfaces consistent by moving
`InitLLVM` from the reusable `mlirTranslateMain` entry point into the
standalone `mlir-translate` executable:
```text
standalone:
main -> InitLLVM -> mlirTranslateMain -> process exit
embedded:
host-owned InitLLVM / LLVMToolSession -> mlirTranslateMain
```
Standalone behaviour remains unchanged, while MLIRTranslateLib can now
borrow the process lifetime owned by a long-lived host.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list