Neovim plugin for automatically folding MLIR IR dump sections with beautiful display and crash trace preservation.
- 🔍 Auto-detects MLIR IR dump markers - Works with any file containing IR dumps
- 📁 Automatic folding - Each IR dump section is foldable independently
- 🏷️ Beautiful fold display - Shows pass names (Before/After), line counts with diamond decorators
- ⚡ Zero configuration - Works out of the box
- 🚀 Optimized for large files - Fast performance even with huge log files
- 🎯 Only activates when needed - No overhead for non-MLIR files
- 🛡️ Error/crash preservation - Stack traces and error messages stay visible
- 🔄 Pass detection - Supports "Before" and "After" passes, including failed passes
- 📝 No file modifications - Pure read-only folding
- Neovim >= 0.8
- No external dependencies. Be careful with other folding plugins that may
conflict. E.g., disable
nvim-ufofor MLIR files (see Tips & Troubleshooting)
{
'hanhanW/mlir-fold.nvim',
ft = 'mlir',
}use 'hanhanW/mlir-fold.nvim'Plug 'hanhanW/mlir-fold.nvim'zo- Open fold under cursorzc- Close fold under cursorzR- Open all foldszM- Close all foldszj- Jump to next foldzk- Jump to previous foldza- Toggle fold under cursor
When you open an MLIR log file with IR dumps:
◆ IR Dump After MaterializeTargetDevicesPass (iree-hal-materialize-target-devices) ◆ 89 lines
[IR dump content FOLDED]
◆ IR Dump After ResolveDevicePromisesPass (iree-hal-resolve-device-promises) ◆ 87 lines
[IR dump content FOLDED]
iree-compile: ....: Assertion `false' failed.
Stack dump:
0. Program arguments: build/tools/iree-compile ...
#0 0x0000713fdbb0b2e8 llvm::sys::PrintStackTrace(...)
#1 0x0000713fdbb08f70 llvm::sys::RunSignalHandlers(...)
[... stack frames remain visible ...]
- Each IR dump section (from marker to next marker) is a fold
- Error messages and stack traces are never folded
- Fold level 1 (flat) - no nested folds
- IR dump markers:
// -----// IR Dump (Before|After) ... - Error messages: File path errors like
/path/file.mlir:line:col: error: - Stack traces:
Stack dump:,#0 0x...,#1 0x..., etc. - Compiler errors:
iree-compile:,iree-opt:,mlir-opt:, etc.
- ✅ Only triggers on
.mlirfiles (zero overhead for other files) - ✅ Pre-compiled regex patterns (no recompilation overhead)
- ✅ Simplified error detection with early exit strategy
- ✅ Optimized for files 10K+ lines
The plugin detects and preserves errors from:
iree-compileiree-optmlir-opt- Any tool following the pattern
<tool>: error message
If you use nvim-ufo, you should disable it for MLIR files to use mlir-fold.nvim's folding instead:
{
'kevinhwang91/nvim-ufo',
config = function()
require('ufo').setup({
provider_selector = function(bufnr, filetype, buftype)
-- Disable ufo for MLIR files (use mlir-fold.nvim instead)
if filetype == 'mlir' then
return ''
end
return { 'treesitter', 'indent' }
end,
})
end,
}This ensures mlir-fold.nvim has full control over folding for MLIR files.