The MLIR extension provides language IDE features for MLIR related languages: MLIR, PDLL, and TableGen
.mlir
- MLIR textual assembly format:The MLIR extension adds language support for the MLIR textual assembly format:
.mlir
files and mlir
markdown blocksThe language server actively runs verification on the IR as you type, showing any generated diagnostics in-place.
expected-
diagnostic checksMLIR provides infrastructure for checking expected diagnostics, which is heavily utilized when defining IR parsing and verification. The language server provides code actions for automatically inserting the checks for diagnostics it knows about.
The language server provides suggestions as you type, offering completions for dialect constructs (such as attributes, operations, and types), block names, SSA value names, keywords, and more.
Cross references allow for navigating the use/def chains of SSA values (i.e. operation results and block arguments), Symbols, and Blocks.
Jump to the definition of the IR entity under the cursor. A few examples are shown below:
The definition of an operation will also take into account the source location attached, allowing for navigating into the source file that generated the operation.
Show all references of the IR entity under the cursor.
Hover over an IR entity to see more information about it. The exact information
displayed is dependent on the type of IR entity under the cursor. For example,
hovering over an Operation
may show its generic format.
The language server will also inform the editor about the structure of symbol
tables within the IR. This allows for jumping directly to the definition of a
symbol, such as a func.func
, within the file.
The language server provides support for interacting with MLIR bytecode files,
enabling IDEs to transparently view and edit bytecode files in the same way
as textual .mlir
files.
mlir-lsp-server
The various .mlir
language features require the
mlir-lsp-server
language server.
If mlir-lsp-server
is not found within your workspace path, you must specify
the path of the server via the mlir.server_path
setting. The path of the
server may be absolute or relative within your workspace.
.pdll
- MLIR PDLL pattern files:The MLIR extension adds language support for the PDLL pattern language.
.pdll
files and pdll
markdown blocksThe language server actively runs verification as you type, showing any generated diagnostics in-place.
The language server provides suggestions as you type based on what constraints, rewrites, dialects, operations, etc are available in this context. The server also provides information about the structure of constraint and rewrite calls, operations, and more as you fill them in.
Cross references allow for navigating the code base.
Jump to the definition of a symbol under the cursor:
If ODS information is available, we can also jump to the definition of operation names and more:
Show all references of the symbol under the cursor.
Hover over a symbol to see more information about it, such as its type, documentation, and more.
If ODS information is available, we can also show information directly from the operation definitions:
The language server will also inform the editor about the structure of symbols within the IR.
The language server provides support for introspecting various intermediate
stages of compilation, such as the AST, the .mlir
containing the generated
PDL, and the generated C++ glue. This is a custom LSP extension, and is not
necessarily provided by all IDE clients.
The language server provides additional information inline with the source code. Editors usually render this using read-only virtual text snippets interspersed with code. Hints may be shown for:
mlir-pdll-lsp-server
The various .pdll
language features require the
mlir-pdll-lsp-server
language server.
If mlir-pdll-lsp-server
is not found within your workspace path, you must
specify the path of the server via the mlir.pdll_server_path
setting. The path
of the server may be absolute or relative within your workspace.
To properly understand and interact with .pdll
files, the language server must
understand how the project is built (compile flags).
pdll_compile_commands.yml
files
related to your project should be provided to ensure files are properly
processed. These files can usually be generated by the build system, and the
server will attempt to find them within your build/
directory. If not
available in or a unique location, additional pdll_compile_commands.yml
files
may be specified via the mlir.pdll_compilation_databases
setting. The paths of
these databases may be absolute or relative within your workspace.
.td
- TableGen files:The MLIR extension adds language support for the TableGen language.
.td
files and tablegen
markdown blocksThe language server actively runs verification as you type, showing any generated diagnostics in-place.
Cross references allow for navigating the code base.
Jump to the definition of a symbol under the cursor:
Show all references of the symbol under the cursor.
Hover over a symbol to see more information about it, such as its type, documentation, and more.
Hovering over an overridden field will also show you information such as documentation from the base value:
tblgen-lsp-server
The various .td
language features require the
tblgen-lsp-server
language server.
If tblgen-lsp-server
is not found within your workspace path, you must specify
the path of the server via the mlir.tablegen_server_path
setting. The path of
the server may be absolute or relative within your workspace.
To properly understand and interact with .td
files, the language server must
understand how the project is built (compile flags).
tablegen_compile_commands.yml
files
related to your project should be provided to ensure files are properly
processed. These files can usually be generated by the build system, and the
server will attempt to find them within your build/
directory. If not
available in or a unique location, additional tablegen_compile_commands.yml
files may be specified via the mlir.tablegen_compilation_databases
setting.
The paths of these databases may be absolute or relative within your workspace.
This extension is actively developed within the
LLVM monorepo, at
mlir/utils/vscode
.
As such, contributions should follow the
normal LLVM guidelines, with code
reviews sent to
GitHub.
When developing or deploying this extension within the LLVM monorepo, a few extra setup steps are required:
mlir/utils/textmate/mlir.json
to the extension directory and rename togrammar.json
.llvm/utils/textmate/tablegen.json
to the extension directory and renametablegen-grammar.json
.https://mlir.llvm.org//LogoAssets/logo/PNG/full_color/mlir-identity-03.png
icon.png
.Please follow the existing code style when contributing to the extension, we
recommend to run npm run format
before sending a patch.