A short description of the goals of the project

The goal of this project was to develop an interactive query language for MLIR, similar to clang-query. An efficient tool for interactively querying the IR can largely assist debugging and testing in MLIR. The tool aims to make exploring and analyzing MLIR code easier for developers by providing a query language that allows them to search for specific patterns and operations within the MLIR codebase. This report provides an overview of the project’s progress, features implemented, challenges faced, and future directions.

The initial plan for the GSoC project was to implement basic queries for MLIR.

Project Goals:

  • Develop a command-line tool that accepts queries and MLIR files as input.
  • Implement a set of missing matchers that allow users to search for specific patterns and operations within MLIR code.
  • Support common query functionalities like matching based on operation name, attributes, properties, etc.
  • Provide helpful error diagnostics for query syntax errors or unsupported queries.
  • Implement auto-completion and history features to enhance the user experience.

Additional Features:

  • Offer a mechanism to extract matched code regions as separate functions.

What I did

Progress so far:

  • Implemented a parser and basic matching functionality, was able to adapt some of the code from clang-query
  • Used the current existing matchers in MLIR for the functionality. eg, m_Constant() matcher.
  • Autocomplete
  • Error reporting/diagnostics
  • Variadic argument matching


  • Talk at the EuroLLVM 2023 (during community bonding period): slides - recording
  • Presented during one of the MLIR open design meetings: slides - recording

Implemented most of the features internally on this branch: https://github.com/devajithvs/llvm-project/tree/devajith.14-mlir-query, just need to incrementally upstream and make changes as the reviews get merged.

Accepted patch: https://reviews.llvm.org/D155127

The current state

The tool provides the following set of basic queries:


The initial support for mlir-query with basic support is added here. This commit adds the initial version of the mlir-query tool, which makes use of the matchers already existing within the MLIR infrastructure.

Even though other features are also implemented internally, due to the initial large size of the patch, it was decided to spend some time on the initial patch and make it right so that we don’t have more changes down the line.

The patch is quite large because even a very basic functional mlir-query needs the implementation of parsing, autocomplete, and diagnostics for a working prototype. I’ve stripped down some of the features from my internal branch to make it more lean. More features will be upstreamed as the current branch get merged.


A short demo illustrating mlir-query functionality with autocomplete

What’s left to do

  • Implement more matchers for different usescases.
  • Upstream more features implemented in the internal repository (function extraction, variadic argument matching).

What code got merged (or not) upstream

Any challenges or important things learned during the project

Through the presentations and code reviews I gave and submitted, I learned a lot. Doing GSoC was a rewarding experience and I would continue contributing to LLVM project and would love to see people using mlir-query.


I would like to thank my GSoC mentor, Jacques Pienaar for providing guidance throughout the GSoC project and valuable feedback even before the program began.

I also extend my thanks to everyone who provided feedback, asked questions, and offered suggestions for the project.