The MLIR extension provides language IDE features for MLIR related languages: MLIR, PDLL, and TableGen
The MLIR extension adds language support for the MLIR textual assembly format:
- Syntax highlighting for
.mlir
files andmlir
markdown blocks - go-to-definition and cross references
- Detailed information when hovering over IR entities
- Outline and navigation of symbols and symbol tables
- Code completion
- Live parser and verifier diagnostics
The language server actively runs verification on the IR as you type, showing any generated diagnostics in-place.
MLIR 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:
- SSA Values
- Symbol References
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.
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.
The MLIR extension adds language support for the PDLL pattern language.
- Syntax highlighting for
.pdll
files andpdll
markdown blocks - go-to-definition and cross references
- Types and documentation on hover
- Code completion and signature help
- View intermediate AST, MLIR, or C++ output
The 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:
- types of local variables
- names of operand and result groups
- constraint and rewrite arguments
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.
The MLIR extension adds language support for the TableGen language.
- Syntax highlighting for
.td
files andtablegen
markdown blocks - go-to-definition and cross references
- Types and documentation on hover
The 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:
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:
- Copy
mlir/utils/textmate/mlir.json
to the extension directory and rename togrammar.json
. - Copy
llvm/utils/textmate/tablegen.json
to the extension directory and rename totablegen-grammar.json
. - Copy
https://mlir.llvm.org//LogoAssets/logo/PNG/full_color/mlir-identity-03.png
to the extension directory and rename toicon.png
.
Please follow the existing code style when contributing to the extension, we
recommend to run npm run format
before sending a patch.