[Mlir-commits] [mlir] initial changes (PR #146535)

Denzel-Brian Budii llvmlistbot at llvm.org
Tue Jul 1 07:10:54 PDT 2025


https://github.com/chios202 created https://github.com/llvm/llvm-project/pull/146535

None

>From 587b03604017e349cd5b2922c22d7211f4ce18a6 Mon Sep 17 00:00:00 2001
From: Denzel-Brian Budii <chio.star at yahoo.com>
Date: Tue, 1 Jul 2025 14:12:09 +0000
Subject: [PATCH] initial changes

---
 mlir/docs/Tools/mlir-query.md | 47 +++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 mlir/docs/Tools/mlir-query.md

diff --git a/mlir/docs/Tools/mlir-query.md b/mlir/docs/Tools/mlir-query.md
new file mode 100644
index 0000000000000..12e22e94b955c
--- /dev/null
+++ b/mlir/docs/Tools/mlir-query.md
@@ -0,0 +1,47 @@
+# MLIR Query
+
+[TOC]
+
+
+`mlir-query` is an interactive tool designed to simplify IR exploration and visualization. The tool provides a REPL interface and supports an interactive query language for MLIR, enabling developers to dynamically query the MLIR IR.
+The tool uses matchers as its core mechanism for peforming queries over the MLIR IR. It relies on simple matchers from `Matchers.h` and slicing-related ones from `SliceMatchers.h`.
+
+## Features
+#### Autocompletion
+
+To simplify usage, `mlir-query` provides autocompletion in the REPL interface, enabling users to ease query input by pressing the Tab key. The GIF below demonstrates an autocompletion use case. When autocompletion is first triggered, a list of available commands is displayed (e.g., `match`, `help`). Triggering autocompletion for the `match` command then shows a list of available matchers.
+
+![Autocompletion demo for mlir-query](https://i.imgur.com/3QiJgrU.gif)
+
+The next GIF illustrates an autocompletion use case for constructing queries. 
+
+![Autocompletion demo for mlir-query](https://i.imgur.com/bpMS9mf.gif)
+
+## Types of matchers
+#### Simple matchers
+
+The tool supports a variety of simple matchers, including `isConstantOp`, which finds all constant operations, and `hasOpName(String)`, which finds all operations with a given name. The next GIF demonstrates a simple query being performed on `mixedOperations` function, specifically matching all the `arith.addf` operations.
+
+```llvm
+func.func @mixedOperations(%a: f32, %b: f32, %c: f32) -> f32 {
+  %sum0 = arith.addf %a, %b : f32
+  %sub0 = arith.subf %sum0, %c : f32
+  %mul0 = arith.mulf %a, %sub0 : f32
+  %sum1 = arith.addf %b, %c : f32
+  %mul1 = arith.mulf %sum1, %mul0 : f32
+  %sub2 = arith.subf %mul1, %a : f32
+  %sum2 = arith.addf %mul1, %b : f32
+  %mul2 = arith.mulf %sub2, %sum2 : f32
+  return %mul2 : f32
+}
+```
+
+![Simple query demo for mlir-query](https://i.imgur.com/dbpn3Xo.gif)
+
+#### Slice matchers
+
+`mlir-query` includes multiple slicing matchers. These are abstractions over the methods from `SliceAnalysis`, facilitating exposure of those methods to users in query context. In contrast to simple matchers, slice matchers also introduce the concept of `nested matchers` which allows one to specify the `root operation` and the exit condition via other `matchers`.
+
+#### Variadic matchers
+
+At this moment, the tool supports two variadic matchers: `anyOf` and `allOf`. These could be conceptualized as matcher combinators, as one can group multiple matchers together to facilitate the construction of complex and powerful queries.



More information about the Mlir-commits mailing list