irsmith 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. irsmith-0.1.0/.github/workflows/release.yml +40 -0
  2. irsmith-0.1.0/.github/workflows/test.yml +21 -0
  3. irsmith-0.1.0/.gitignore +5 -0
  4. irsmith-0.1.0/.python-version +1 -0
  5. irsmith-0.1.0/LICENSE-APACHE +176 -0
  6. irsmith-0.1.0/LICENSE-MIT +21 -0
  7. irsmith-0.1.0/PKG-INFO +140 -0
  8. irsmith-0.1.0/README.md +110 -0
  9. irsmith-0.1.0/demo/README.md +111 -0
  10. irsmith-0.1.0/demo/pr248058.ll +109 -0
  11. irsmith-0.1.0/demo/run_demo.py +155 -0
  12. irsmith-0.1.0/docs/clients.md +147 -0
  13. irsmith-0.1.0/pyproject.toml +55 -0
  14. irsmith-0.1.0/server.json +36 -0
  15. irsmith-0.1.0/src/irsmith/__init__.py +1 -0
  16. irsmith-0.1.0/src/irsmith/__main__.py +3 -0
  17. irsmith-0.1.0/src/irsmith/app.py +64 -0
  18. irsmith-0.1.0/src/irsmith/bisect/__init__.py +0 -0
  19. irsmith-0.1.0/src/irsmith/bisect/driver.py +264 -0
  20. irsmith-0.1.0/src/irsmith/bisect/git.py +198 -0
  21. irsmith-0.1.0/src/irsmith/config.py +240 -0
  22. irsmith-0.1.0/src/irsmith/errors.py +19 -0
  23. irsmith-0.1.0/src/irsmith/jobs.py +123 -0
  24. irsmith-0.1.0/src/irsmith/limits_exec.py +50 -0
  25. irsmith-0.1.0/src/irsmith/models.py +290 -0
  26. irsmith-0.1.0/src/irsmith/oracle/__init__.py +0 -0
  27. irsmith-0.1.0/src/irsmith/oracle/__main__.py +18 -0
  28. irsmith-0.1.0/src/irsmith/oracle/spec.py +94 -0
  29. irsmith-0.1.0/src/irsmith/pipeline/__init__.py +0 -0
  30. irsmith-0.1.0/src/irsmith/pipeline/diff.py +40 -0
  31. irsmith-0.1.0/src/irsmith/pipeline/dumps.py +62 -0
  32. irsmith-0.1.0/src/irsmith/pipeline/passes.py +82 -0
  33. irsmith-0.1.0/src/irsmith/pipeline/run.py +58 -0
  34. irsmith-0.1.0/src/irsmith/proc.py +313 -0
  35. irsmith-0.1.0/src/irsmith/py.typed +0 -0
  36. irsmith-0.1.0/src/irsmith/reduce/__init__.py +1 -0
  37. irsmith-0.1.0/src/irsmith/reduce/driver.py +139 -0
  38. irsmith-0.1.0/src/irsmith/server.py +211 -0
  39. irsmith-0.1.0/src/irsmith/signature/__init__.py +4 -0
  40. irsmith-0.1.0/src/irsmith/signature/normalize.py +91 -0
  41. irsmith-0.1.0/src/irsmith/signature/parse.py +112 -0
  42. irsmith-0.1.0/src/irsmith/store.py +185 -0
  43. irsmith-0.1.0/src/irsmith/triage/__init__.py +0 -0
  44. irsmith-0.1.0/src/irsmith/triage/github.py +147 -0
  45. irsmith-0.1.0/src/irsmith/triage/search.py +200 -0
  46. irsmith-0.1.0/tests/__init__.py +0 -0
  47. irsmith-0.1.0/tests/conftest.py +51 -0
  48. irsmith-0.1.0/tests/fakes/fake_gh.py +33 -0
  49. irsmith-0.1.0/tests/fakes/fake_llvm_reduce.py +61 -0
  50. irsmith-0.1.0/tests/fakes/fake_ninja.py +55 -0
  51. irsmith-0.1.0/tests/fakes/fake_opt.py +155 -0
  52. irsmith-0.1.0/tests/fixtures/bad.ll +3 -0
  53. irsmith-0.1.0/tests/fixtures/bad.mlir +4 -0
  54. irsmith-0.1.0/tests/fixtures/bad_verify.mlir +4 -0
  55. irsmith-0.1.0/tests/fixtures/github/api_frame.json +21 -0
  56. irsmith-0.1.0/tests/fixtures/github/api_message.json +138 -0
  57. irsmith-0.1.0/tests/fixtures/github/api_pass.json +141 -0
  58. irsmith-0.1.0/tests/fixtures/github/gh_message.json +128 -0
  59. irsmith-0.1.0/tests/fixtures/github/gh_pass.json +134 -0
  60. irsmith-0.1.0/tests/fixtures/many_functions.ll +155 -0
  61. irsmith-0.1.0/tests/fixtures/print_changed.txt +45 -0
  62. irsmith-0.1.0/tests/fixtures/small.ll +4 -0
  63. irsmith-0.1.0/tests/fixtures/stderr/darwin_lcssa_nested_pipeline.txt +34 -0
  64. irsmith-0.1.0/tests/fixtures/stderr/darwin_trigger_crash.txt +20 -0
  65. irsmith-0.1.0/tests/fixtures/stderr/darwin_verifier_error.txt +22 -0
  66. irsmith-0.1.0/tests/fixtures/stderr/fake_darwin.txt +18 -0
  67. irsmith-0.1.0/tests/fixtures/stderr/fake_glibc.txt +22 -0
  68. irsmith-0.1.0/tests/fixtures/stderr/fake_mlir.txt +14 -0
  69. irsmith-0.1.0/tests/fixtures/stderr/mlir_diagnostic.txt +6 -0
  70. irsmith-0.1.0/tests/fixtures/stderr/mlir_op_verifier.txt +4 -0
  71. irsmith-0.1.0/tests/fixtures/stderr/parse_error.txt +3 -0
  72. irsmith-0.1.0/tests/fixtures/two_functions.ll +10 -0
  73. irsmith-0.1.0/tests/integration/__init__.py +0 -0
  74. irsmith-0.1.0/tests/integration/test_real_tools.py +120 -0
  75. irsmith-0.1.0/tests/integration/test_stdio.py +62 -0
  76. irsmith-0.1.0/tests/unit/__init__.py +0 -0
  77. irsmith-0.1.0/tests/unit/test_bisect.py +199 -0
  78. irsmith-0.1.0/tests/unit/test_config.py +59 -0
  79. irsmith-0.1.0/tests/unit/test_proc.py +123 -0
  80. irsmith-0.1.0/tests/unit/test_reduce.py +81 -0
  81. irsmith-0.1.0/tests/unit/test_signature.py +113 -0
  82. irsmith-0.1.0/tests/unit/test_store.py +52 -0
  83. irsmith-0.1.0/tests/unit/test_tools.py +86 -0
  84. irsmith-0.1.0/tests/unit/test_triage.py +174 -0
  85. irsmith-0.1.0/uv.lock +861 -0
@@ -0,0 +1,40 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions: {}
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v6
17
+ - run: uv sync --locked
18
+ - name: Check that the tag matches the package version
19
+ run: |
20
+ version=$(uv run python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')
21
+ test "$GITHUB_REF_NAME" = "v$version" || { echo "tag $GITHUB_REF_NAME does not match version $version"; exit 1; }
22
+ - run: uv run pytest -q
23
+ - run: uv build
24
+ - uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write
35
+ steps:
36
+ - uses: actions/download-artifact@v4
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,21 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ os: [ubuntu-latest, macos-latest]
13
+ python: ["3.11", "3.13"]
14
+ runs-on: ${{ matrix.os }}
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v6
18
+ with:
19
+ python-version: ${{ matrix.python }}
20
+ - run: uv sync --locked
21
+ - run: uv run pytest -q
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ dist/
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ambuj Agrawal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
irsmith-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.5
2
+ Name: irsmith
3
+ Version: 0.1.0
4
+ Summary: MCP server that helps coding agents debug LLVM, MLIR and CIRCT crashes and pass pipelines
5
+ Project-URL: Homepage, https://github.com/ambujone/irsmith
6
+ Project-URL: Issues, https://github.com/ambujone/irsmith/issues
7
+ Project-URL: Source, https://github.com/ambujone/irsmith
8
+ Author-email: Ambuj Agrawal <ambujone@gmail.com>
9
+ License-Expression: MIT OR Apache-2.0
10
+ License-File: LICENSE-APACHE
11
+ License-File: LICENSE-MIT
12
+ Keywords: bisect,circt,compiler,crash,debugging,llvm,mcp,mcp-server,mlir,reduce
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Compilers
24
+ Classifier: Topic :: Software Development :: Debuggers
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: anyio>=4.5
28
+ Requires-Dist: mcp>=2.3.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # irsmith
32
+
33
+ irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how.
34
+
35
+ <!-- mcp-name: io.github.ambujone/irsmith -->
36
+
37
+ Status: early (v0.1). Tested on macOS (Apple silicon) and Linux, with Python 3.11 and 3.13 in CI.
38
+
39
+ ## Demo
40
+
41
+ [demo/pr248058.ll](https://github.com/ambujone/irsmith/blob/main/demo/pr248058.ll) is the C test from [llvm/llvm-project#248058](https://github.com/llvm/llvm-project/issues/248058), an open LICM crash, compiled to IR at -O0. [demo/run_demo.py](https://github.com/ambujone/irsmith/blob/main/demo/run_demo.py) drives irsmith over MCP stdio the way an agent would. One run, against an LLVM build with assertions from 2026-12-03, on an M4 Mac with other jobs running:
42
+
43
+ ```
44
+ $ uv run python demo/run_demo.py --build $IRSMITH_LLVM_BUILD
45
+ run 0.1s opt -passes=default<O2> -disable-output pr248058.ll
46
+ SIGABRT, assertion at LoopPassManager.cpp:265, pass loop-mssa, sig:d48af5be
47
+ L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LCSSA form!"
48
+ reduce 273.0s 109 -> 38 lines (llvm-reduce, 1449 tests), same signature in 3 of 3 checks
49
+ diff_passes 0.2s 45 passes finished before the crash, the last was LoopSimplifyCFGPass on loop %do.body.outer
50
+ find_duplicates 7.8s #248058 0.63 open [LICM] Crash at -O2 and above: Assertion `L->isRecursivelyLCSSAForm(...)`
51
+ #156334 0.62 closed Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain...`
52
+ ```
53
+
54
+ The full transcript, with the reduced file, is in [demo/README.md](https://github.com/ambujone/irsmith/blob/main/demo/README.md).
55
+
56
+ ## Quickstart
57
+
58
+ ```sh
59
+ claude mcp add irsmith -e IRSMITH_LLVM_BUILD=/path/to/llvm-project/build -- uvx irsmith
60
+ ```
61
+
62
+ This needs [uv](https://docs.astral.sh/uv/getting-started/installation/). Ask the agent to call `doctor` first. It lists the toolchains and tools it found. For Claude Desktop, Cursor, VS Code, Codex CLI and Windsurf, see [docs/clients.md](https://github.com/ambujone/irsmith/blob/main/docs/clients.md). Without an LLVM build, irsmith uses Homebrew LLVM, with some limits that the same page lists.
63
+
64
+ To run from source instead:
65
+
66
+ ```sh
67
+ git clone https://github.com/ambujone/irsmith && cd irsmith && uv sync
68
+ export IRSMITH_LLVM_BUILD=/path/to/llvm-project/build
69
+ claude mcp add irsmith -- uv --directory "$PWD" run irsmith
70
+ ```
71
+
72
+ Any MCP client that can launch a stdio server works the same way: the command is `uv --directory /path/to/irsmith run irsmith`.
73
+
74
+ ## Tools
75
+
76
+ | Tool | What it does |
77
+ |---|---|
78
+ | `doctor` | Lists toolchains (version, git revision, assertions on or off), optional tools (alive-tv, cvise, gh) and state dir usage. |
79
+ | `run` | Runs one command under time, memory and output limits. Returns the exit status, peak memory and a crash signature: kind, message, pass, function and top stack frames, with a stable id. |
80
+ | `diff_passes` | Runs a pipeline with `opt -print-changed`, or with `--mlir-print-ir-after-all --mlir-print-ir-after-change` for `mlir-opt` and `circt-opt`, and returns one diff hunk per pass that changed the IR, within a token budget. If the tool crashes partway, it returns the passes that finished and the crash signature. |
81
+ | `reduce` | Shrinks a crashing `.ll`, `.bc` or `.mir` file with llvm-reduce, or a `.mlir` file with circt-reduce. Each candidate must crash with the same signature as the original, so the reducer cannot drift to a different bug. Runs as a job. |
82
+ | `bisect` | Finds the commit that introduced a crash, or with `find: "fix"` the commit that fixed it. At each step it checks out the commit, runs `ninja -C <build> <targets>` in your build dir and runs the command. A failed build or an unclear result skips the commit. Runs as a job. |
83
+ | `find_duplicates` | Searches GitHub issues for the same crash, given a signature id, a stderr handle or pasted text. Runs up to 3 searches (the assertion text, the top frame, the pass) and ranks the issues by how well they match. Uses `gh` when it is logged in, else the public API. Results are cached for 24 hours. |
84
+ | `job_status`, `job_cancel` | Follow or stop a `reduce` or `bisect` job. Calls wait at most 55 seconds, because many clients drop longer calls. |
85
+ | `read_artifact` | Reads part of a stored output (stderr, IR dumps, the reduced file) by handle, with offset, limit and grep. |
86
+
87
+ Commands are argv arrays, never shell strings. The first element must be a tool found in a configured toolchain, such as `opt` or `circt-opt`. Use `{input}`, `{out}` and `{tmp}` as placeholders.
88
+
89
+ ## Configuration
90
+
91
+ Environment variables: `IRSMITH_LLVM_BUILD`, `IRSMITH_CIRCT_BUILD`, `IRSMITH_STATE_DIR` (default `~/.cache/irsmith`), `IRSMITH_ALIVE_TV` and `IRSMITH_CONFIG`. Without them, irsmith looks for Homebrew LLVM, `/usr/lib/llvm-*` and tools on `PATH`. When `gh` is not logged in, `GITHUB_TOKEN` raises the GitHub search rate limit.
92
+
93
+ The config file is `$IRSMITH_CONFIG`, else `.irsmith.toml` in the working directory or a parent, else `~/.config/irsmith/config.toml`:
94
+
95
+ ```toml
96
+ [limits]
97
+ timeout_s = 120
98
+ memory_mb = 8192
99
+ disk_quota_mb = 4096
100
+ max_heavy_jobs = 2
101
+
102
+ [toolchains.llvm]
103
+ build_dir = "/path/to/llvm-project/build"
104
+
105
+ [toolchains.circt]
106
+ build_dir = "/path/to/circt/build"
107
+
108
+ [env]
109
+ # extra variables passed to every child
110
+ ```
111
+
112
+ ## Safety
113
+
114
+ - Every child runs in its own process group. Timeouts, cancellation and server shutdown kill the whole tree, including children that called `setsid`.
115
+ - Memory is limited by sampling the tree's RSS once a second, because macOS ignores memory rlimits.
116
+ - Children get an allowlisted environment (`PATH`, `HOME`, `LANG`, `CCACHE_*` and your `[env]` table). Tokens in the server's environment are not passed on.
117
+ - Output streams are capped at 64 MiB each. Each job has a disk quota, and the state dir is capped at 10 GiB, with the oldest finished jobs removed first.
118
+ - If the server dies, the next one kills the process groups it left behind.
119
+ - `bisect` refuses to start on a tree with uncommitted changes to tracked files, during a bisect, rebase or merge, or with a build that is not Ninja. It checks that the tree is still clean before each checkout and stops if you edited a file. At the end, including on cancel, it puts HEAD back on your branch. Only one bisect runs per repository. If the server dies mid-bisect, the next server restores the branch on startup.
120
+ - GitHub access is read-only. `gh` runs only `auth status` and `search issues`, and HTTP requests are GET requests to the issue search endpoint. `gh` is the only child that receives `GH_TOKEN` or `GITHUB_TOKEN`.
121
+
122
+ ## Planned
123
+
124
+ Not done yet:
125
+
126
+ - `prove`: check a transformation with Alive2. The `reduce` oracle for miscompiles also needs it.
127
+ - cvise for C and C++ inputs, and `.fir` input for circt-reduce.
128
+ - Testing on Linux.
129
+
130
+ ## Development
131
+
132
+ ```sh
133
+ uv run pytest
134
+ ```
135
+
136
+ The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing.
137
+
138
+ ## License
139
+
140
+ MIT or Apache-2.0, at your option.
@@ -0,0 +1,110 @@
1
+ # irsmith
2
+
3
+ irsmith is an MCP server that lets coding agents debug LLVM, MLIR and CIRCT tools using your own local builds. It runs a compiler command and reads the crash signature, shrinks a crashing input to a small reproducer, and shows which pass changed the IR and how.
4
+
5
+ <!-- mcp-name: io.github.ambujone/irsmith -->
6
+
7
+ Status: early (v0.1). Tested on macOS (Apple silicon) and Linux, with Python 3.11 and 3.13 in CI.
8
+
9
+ ## Demo
10
+
11
+ [demo/pr248058.ll](https://github.com/ambujone/irsmith/blob/main/demo/pr248058.ll) is the C test from [llvm/llvm-project#248058](https://github.com/llvm/llvm-project/issues/248058), an open LICM crash, compiled to IR at -O0. [demo/run_demo.py](https://github.com/ambujone/irsmith/blob/main/demo/run_demo.py) drives irsmith over MCP stdio the way an agent would. One run, against an LLVM build with assertions from 2026-12-03, on an M4 Mac with other jobs running:
12
+
13
+ ```
14
+ $ uv run python demo/run_demo.py --build $IRSMITH_LLVM_BUILD
15
+ run 0.1s opt -passes=default<O2> -disable-output pr248058.ll
16
+ SIGABRT, assertion at LoopPassManager.cpp:265, pass loop-mssa, sig:d48af5be
17
+ L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LCSSA form!"
18
+ reduce 273.0s 109 -> 38 lines (llvm-reduce, 1449 tests), same signature in 3 of 3 checks
19
+ diff_passes 0.2s 45 passes finished before the crash, the last was LoopSimplifyCFGPass on loop %do.body.outer
20
+ find_duplicates 7.8s #248058 0.63 open [LICM] Crash at -O2 and above: Assertion `L->isRecursivelyLCSSAForm(...)`
21
+ #156334 0.62 closed Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain...`
22
+ ```
23
+
24
+ The full transcript, with the reduced file, is in [demo/README.md](https://github.com/ambujone/irsmith/blob/main/demo/README.md).
25
+
26
+ ## Quickstart
27
+
28
+ ```sh
29
+ claude mcp add irsmith -e IRSMITH_LLVM_BUILD=/path/to/llvm-project/build -- uvx irsmith
30
+ ```
31
+
32
+ This needs [uv](https://docs.astral.sh/uv/getting-started/installation/). Ask the agent to call `doctor` first. It lists the toolchains and tools it found. For Claude Desktop, Cursor, VS Code, Codex CLI and Windsurf, see [docs/clients.md](https://github.com/ambujone/irsmith/blob/main/docs/clients.md). Without an LLVM build, irsmith uses Homebrew LLVM, with some limits that the same page lists.
33
+
34
+ To run from source instead:
35
+
36
+ ```sh
37
+ git clone https://github.com/ambujone/irsmith && cd irsmith && uv sync
38
+ export IRSMITH_LLVM_BUILD=/path/to/llvm-project/build
39
+ claude mcp add irsmith -- uv --directory "$PWD" run irsmith
40
+ ```
41
+
42
+ Any MCP client that can launch a stdio server works the same way: the command is `uv --directory /path/to/irsmith run irsmith`.
43
+
44
+ ## Tools
45
+
46
+ | Tool | What it does |
47
+ |---|---|
48
+ | `doctor` | Lists toolchains (version, git revision, assertions on or off), optional tools (alive-tv, cvise, gh) and state dir usage. |
49
+ | `run` | Runs one command under time, memory and output limits. Returns the exit status, peak memory and a crash signature: kind, message, pass, function and top stack frames, with a stable id. |
50
+ | `diff_passes` | Runs a pipeline with `opt -print-changed`, or with `--mlir-print-ir-after-all --mlir-print-ir-after-change` for `mlir-opt` and `circt-opt`, and returns one diff hunk per pass that changed the IR, within a token budget. If the tool crashes partway, it returns the passes that finished and the crash signature. |
51
+ | `reduce` | Shrinks a crashing `.ll`, `.bc` or `.mir` file with llvm-reduce, or a `.mlir` file with circt-reduce. Each candidate must crash with the same signature as the original, so the reducer cannot drift to a different bug. Runs as a job. |
52
+ | `bisect` | Finds the commit that introduced a crash, or with `find: "fix"` the commit that fixed it. At each step it checks out the commit, runs `ninja -C <build> <targets>` in your build dir and runs the command. A failed build or an unclear result skips the commit. Runs as a job. |
53
+ | `find_duplicates` | Searches GitHub issues for the same crash, given a signature id, a stderr handle or pasted text. Runs up to 3 searches (the assertion text, the top frame, the pass) and ranks the issues by how well they match. Uses `gh` when it is logged in, else the public API. Results are cached for 24 hours. |
54
+ | `job_status`, `job_cancel` | Follow or stop a `reduce` or `bisect` job. Calls wait at most 55 seconds, because many clients drop longer calls. |
55
+ | `read_artifact` | Reads part of a stored output (stderr, IR dumps, the reduced file) by handle, with offset, limit and grep. |
56
+
57
+ Commands are argv arrays, never shell strings. The first element must be a tool found in a configured toolchain, such as `opt` or `circt-opt`. Use `{input}`, `{out}` and `{tmp}` as placeholders.
58
+
59
+ ## Configuration
60
+
61
+ Environment variables: `IRSMITH_LLVM_BUILD`, `IRSMITH_CIRCT_BUILD`, `IRSMITH_STATE_DIR` (default `~/.cache/irsmith`), `IRSMITH_ALIVE_TV` and `IRSMITH_CONFIG`. Without them, irsmith looks for Homebrew LLVM, `/usr/lib/llvm-*` and tools on `PATH`. When `gh` is not logged in, `GITHUB_TOKEN` raises the GitHub search rate limit.
62
+
63
+ The config file is `$IRSMITH_CONFIG`, else `.irsmith.toml` in the working directory or a parent, else `~/.config/irsmith/config.toml`:
64
+
65
+ ```toml
66
+ [limits]
67
+ timeout_s = 120
68
+ memory_mb = 8192
69
+ disk_quota_mb = 4096
70
+ max_heavy_jobs = 2
71
+
72
+ [toolchains.llvm]
73
+ build_dir = "/path/to/llvm-project/build"
74
+
75
+ [toolchains.circt]
76
+ build_dir = "/path/to/circt/build"
77
+
78
+ [env]
79
+ # extra variables passed to every child
80
+ ```
81
+
82
+ ## Safety
83
+
84
+ - Every child runs in its own process group. Timeouts, cancellation and server shutdown kill the whole tree, including children that called `setsid`.
85
+ - Memory is limited by sampling the tree's RSS once a second, because macOS ignores memory rlimits.
86
+ - Children get an allowlisted environment (`PATH`, `HOME`, `LANG`, `CCACHE_*` and your `[env]` table). Tokens in the server's environment are not passed on.
87
+ - Output streams are capped at 64 MiB each. Each job has a disk quota, and the state dir is capped at 10 GiB, with the oldest finished jobs removed first.
88
+ - If the server dies, the next one kills the process groups it left behind.
89
+ - `bisect` refuses to start on a tree with uncommitted changes to tracked files, during a bisect, rebase or merge, or with a build that is not Ninja. It checks that the tree is still clean before each checkout and stops if you edited a file. At the end, including on cancel, it puts HEAD back on your branch. Only one bisect runs per repository. If the server dies mid-bisect, the next server restores the branch on startup.
90
+ - GitHub access is read-only. `gh` runs only `auth status` and `search issues`, and HTTP requests are GET requests to the issue search endpoint. `gh` is the only child that receives `GH_TOKEN` or `GITHUB_TOKEN`.
91
+
92
+ ## Planned
93
+
94
+ Not done yet:
95
+
96
+ - `prove`: check a transformation with Alive2. The `reduce` oracle for miscompiles also needs it.
97
+ - cvise for C and C++ inputs, and `.fir` input for circt-reduce.
98
+ - Testing on Linux.
99
+
100
+ ## Development
101
+
102
+ ```sh
103
+ uv run pytest
104
+ ```
105
+
106
+ The integration tests use the builds in `IRSMITH_LLVM_BUILD` and `IRSMITH_CIRCT_BUILD` and are skipped when those are missing.
107
+
108
+ ## License
109
+
110
+ MIT or Apache-2.0, at your option.
@@ -0,0 +1,111 @@
1
+ # Demo: a real LICM crash
2
+
3
+ `run_demo.py` starts irsmith over stdio with the MCP Python client and calls its tools in the order an agent would: `doctor`, `run`, `reduce` (followed with `job_status` until it finishes), `diff_passes` on the reduced file and `find_duplicates`. It prints a short transcript. `--json FILE` also saves every call's arguments, time and structured result.
4
+
5
+ ## The input
6
+
7
+ `pr248058.ll` comes from [llvm/llvm-project#248058](https://github.com/llvm/llvm-project/issues/248058), an open issue: LICM breaks LCSSA form when a computed goto reaches labels in two nested loops, and `opt -passes='default<O2>'` hits the assertion `Loops must remain in LCSSA form!`. The file is the issue's C test compiled without optimization:
8
+
9
+ ```sh
10
+ clang -O0 -Xclang -disable-O0-optnone -target x86_64-unknown-linux-gnu -S -emit-llvm 248058.c
11
+ ```
12
+
13
+ It was not enlarged. The four comment lines at the top say where it came from.
14
+
15
+ ## Running it
16
+
17
+ You need an LLVM build with assertions that still has the bug. For `find_duplicates`, `gh` logged in or network access to the GitHub search API.
18
+
19
+ ```sh
20
+ uv run python demo/run_demo.py --build /path/to/llvm-project/build
21
+ ```
22
+
23
+ Options: `--passes` (default `default<O2>`), `--jobs` for llvm-reduce workers (default 3), `--state-dir` (default a fresh temporary directory, so the GitHub search is not served from an earlier run's cache), `--server-log` and `--json`.
24
+
25
+ ## Transcript
26
+
27
+ Recorded on 2026-12-04 on an M4 MacBook with other jobs running, against a Release build with assertions of llvm-project main from 2026-12-03 plus one unrelated SCEVExpander patch. Times depend on load.
28
+
29
+ ```
30
+ input: pr248058.ll (109 lines)
31
+ command: opt -passes=default<O2> -disable-output {input}
32
+
33
+ [doctor] 0.4s
34
+ llvm: LLVM version 24.0.0git, rev 098e381e6758, assertions on
35
+ path: Apple clang version 21.0.0 (clang-2100.1.1.101), rev None, assertions off
36
+ warning: path: assertions are off, so most assertion crashes will not show up
37
+ warning: llvm, path: no llvm-symbolizer in the bin dir or on PATH, so stack frames are unnamed, or on macOS often name the wrong function. Build it with ninja llvm-symbolizer
38
+
39
+ [run] 0.1s
40
+ SIGABRT, assertion at LoopPassManager.cpp:265, pass loop-mssa
41
+ message: L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LCSSA form!"
42
+ signature: sig:d48af5be
43
+
44
+ [reduce] 273.0s, job r-611e9a succeeded
45
+ 109 -> 38 lines, 1449 tests, 0 rejected for another crash
46
+ verified 3 times: crashes, same signature
47
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
48
+ target triple = "x86_64-unknown-linux-gnu"
49
+
50
+ @a = global [1 x i32] zeroinitializer
51
+
52
+ define void @d(i32 %0) {
53
+ entry:
54
+ br label %do.body
55
+
56
+ do.body: ; preds = %h, %if.else, %do.cond, %entry
57
+ %f.0 = phi i32 [ %0, %entry ], [ 0, %do.cond ], [ %inc, %h ], [ 0, %if.else ]
58
+ %p.01 = phi ptr [ blockaddress(@d, %do.cond), %entry ], [ %p.01, %do.cond ], [ null, %if.else ], [ null, %h ]
59
+ %inc = or i32 %f.0, 1
60
+ indirectbr ptr %p.01, [label %do.cond, label %h]
61
+
62
+ do.cond: ; preds = %do.body
63
+ %tobool.not = icmp eq i32 %f.0, 0
64
+ br i1 %tobool.not, label %do.end, label %do.body
65
+
66
+ do.end: ; preds = %do.cond
67
+ %and1 = and i32 %0, 1
68
+ %idxprom2 = zext i32 %and1 to i64
69
+ %arrayidx3 = getelementptr nusw [4 x i8], ptr @a, i64 %idxprom2
70
+ %1 = load i32, ptr %arrayidx3, align 4
71
+ %cmp.not = icmp ugt i32 1, %1
72
+ br i1 %cmp.not, label %if.else, label %if.then
73
+
74
+ if.then: ; preds = %do.end
75
+ ret void
76
+
77
+ if.else: ; preds = %do.end
78
+ %cmp8 = icmp ult i32 %and1, 1
79
+ br i1 %cmp8, label %do.body, label %h
80
+
81
+ h: ; preds = %if.else, %do.body
82
+ %p.1 = phi ptr [ null, %do.body ], [ blockaddress(@d, %h), %if.else ]
83
+ br label %do.body
84
+ }
85
+
86
+ [diff_passes] 0.2s, 45 passes finished, 8 changed the IR
87
+ crash: assertion in loop-mssa, sig:d48af5be
88
+ note: unnamed values were named with instnamer first, so names differ from the input
89
+ note: opt crashed (assertion) before the pipeline finished, so only passes that finished are shown. The last one was LoopSimplifyCFGPass on loop %do.body.outer in function d.
90
+ last passes that changed the IR:
91
+ LoopSimplifyPass on d: +17 -9
92
+ LCSSAPass on d: +3 -1
93
+ LoopSimplifyCFGPass on loop %do.body.outer in function d: +5 -6
94
+
95
+ [find_duplicates] 7.8s, llvm/llvm-project via gh
96
+ query: "L->isRecursivelyLCSSAForm(LAR.DT, LI) && Loops must remain"
97
+ query: runOnLoop crash
98
+ query: loop-mssa isRecursivelyLCSSAForm LAR Loops must remain
99
+ #248058 0.63 open [LICM] Crash at -O2 and above: Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops
100
+ matched: message, pass
101
+ #156334 0.62 closed Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LCSSA form!"' fa
102
+ matched: message, closed
103
+ #61182 0.62 closed [loop-reduce] Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LC
104
+ matched: message, closed
105
+ #75938 0.61 closed llvm crash: Assertion `L->isRecursivelyLCSSAForm(LAR.DT, LI) && "Loops must remain in LCSS
106
+ matched: message, closed
107
+ #191652 0.56 closed [LSR] Fails to preserve LCSSA
108
+ matched: message, closed
109
+
110
+ total 282.1s
111
+ ```