Home / Alt manpages / mlir-tblgen-18(1)

  • mlir-tblgen-18(1)
  • User command
  • linux

Use mlir-tblgen-18 safely from an MLIR build

You will identify the LLVM 18 TableGen tool, check whether the MLIR-specific executable is actually installed, and run it against a .td description without losing the source file. Allow 15 to 30 minutes for a first smoke test, plus time to understand the MLIR backend you intend to invoke. This guide covers the command's documented interface, not the design of an MLIR dialect or operation definition.

The local manual describes mlir-tblgen as a translator from compiler-related target description files to C++ and other output formats. It is a developer tool. It does not compile an MLIR project by itself, and it does not infer which backend your build needs.

1. Check the package and executable

Start with read-only checks. They need no elevated privileges:

$ dpkg-query -W -f='${Package} ${Version} ${Status}\n' llvm-18
llvm-18 1:18.1.3-1ubuntu1 install ok installed
$ command -v mlir-tblgen-18
/usr/bin/mlir-tblgen-18

The version line above is specific to the Ubuntu package checked for this guide. Your installed revision may differ. If command -v prints nothing, stop here and fix the package selection or executable path. Do not substitute llvm-tblgen-18: it is a different frontend with different MLIR backends.

On the reference machine, the llvm-18 package provides the mlir-tblgen-18(1) manual and llvm-tblgen-18, but not the mlir-tblgen-18 executable. That is a useful packaging warning: a readable manual is not proof that the command is available.

Checkpoint

Continue only when the command lookup returns the executable you intend to run. If it does not, record that fact rather than testing an unrelated TableGen binary.

2. Ask the installed command for its own interface

Use the command's built-in help and version output before choosing a backend. These are ordinary, non-destructive commands:

$ mlir-tblgen-18 --version
$ mlir-tblgen-18 --help

The exact version text, option list and backend names come from the executable. The manual page deliberately points to the common tblgen documentation for the filename argument and options, so do not copy an option from an unrelated LLVM release or from an online example without checking this output.

mlir-tblgen-18 accepts one optional positional filename in its documented synopsis. In practice, that is the .td input that describes records, classes or definitions used by an MLIR build. Keep the input path explicit in scripts:

$ mlir-tblgen-18 /path/to/your-definition.td

Do not expect useful C++ merely because parsing succeeded. A generator backend normally has to be selected, and the suitable backend depends on the definitions and the build step that consumes them. Treat the help output and the surrounding MLIR build files as the authority for that selection.

3. Work from a disposable output directory

Generated output can be large and can replace a file if you direct it to an existing path. Before a real generation run, create a separate directory in your build tree and copy only the definition inputs needed for the test. For example:

$ mkdir -p build/tblgen-check
$ cp --preserve=mode,timestamps /path/to/your-definition.td build/tblgen-check/
$ cd build/tblgen-check
$ mlir-tblgen-18 --help > help.txt
$ test -s help.txt && echo 'help captured'
help captured

This changes only your working tree. No sudo is required. If you are working in a source checkout, prefer an ignored build directory so a generated file cannot be mistaken for a reviewed source change.

Safety boundary

Do not send generated output directly into a tracked header, source directory or installed system path on the first run. Redirection with > truncates its destination before the program runs. Use a new filename, inspect it, then move it into place only after review.

4. Capture and review a real generation run

Once you know the backend option from the installed help and your build documentation, write to a new path. The option spelling below is intentionally a placeholder because the manpage delegates generator-specific options to the shared TableGen reference:

$ mlir-tblgen-18 BACKEND_OPTION /path/to/your-definition.td > generated.h.new
$ status=$?
$ printf 'mlir-tblgen exit status: %s\n' "$status"
$ test "$status" -eq 0 && test -s generated.h.new && echo 'non-empty output ready for review'

Replace BACKEND_OPTION with an option printed by your installed command. Do not paste the placeholder literally. If the command fails, keep the diagnostic and inspect the first reported definition or include error. An incomplete output file may exist; leave it named .new until the run is understood.

Review the result before replacing anything:

$ file generated.h.new
$ sed -n '1,80p' generated.h.new
$ git diff --no-index -- /dev/null generated.h.new

The expected file type and text depend on the selected MLIR backend. A zero exit status tells you that the process completed; it does not prove that the generated declarations match your build's expectations.

5. Recover from a bad or unwanted output

If the run produced an unwanted new file, remove only that disposable file:

$ rm -- generated.h.new

That deletion is irreversible, so check the name with ls -l first. If you need to replace an existing generated file, retain a backup and use a separate reviewed move:

$ cp --preserve=all generated.h generated.h.bak
$ mv -- generated.h.new generated.h

Undo that replacement with mv -- generated.h.bak generated.h if the review or build fails. Do not delete the backup until the consuming build has completed successfully. Never write generated headers into /usr/include or another system directory for a local test.

Done means

  • The LLVM package version and actual mlir-tblgen-18 executable were checked separately.
  • The installed command's own help output supplied the backend option you used.
  • The original .td input remains unchanged.
  • Generated output was captured under a new name and reviewed before replacement.
  • A failed run can be removed or rolled back without touching a source or system path.