Commit 924468e
authored
[Frontend][Diagnostics] Improve emitting diagnostic information (#5581)
### Summary
This PR enhances the current implementation for emitting diagnostic
remarks by introducing a unified handler in `ir.cc`. This handler
manages diagnostic information more effectively and disables the
emission of IRs unless explicitly requested by the user. The
`MLIR_ENABLE_DIAGNOSTICS` environment variable now controls all
diagnostic emission settings, accepting one or more values from
`{warnings, remarks, stacktraces, operations}`, separated by commas.
Detailed usage instructions are available in the README.
### Background
Previously, a new default LLVM `SourceManager` was configured in
`nvidia/backend/compiler.py` to support remarks, applied in both
`make_ttgir` and `make_llir`. However, a custom handler already existed
in `ir.cc`, and a more robust design should extend this handler rather
than create a new one.
### Changes
- **Unified Handler**: Inspired by LLVM upstream [[PR
117669](https://github.com/llvm/llvm-project/pull/117669)](https://github.com/llvm/llvm-project/pull/117669),
this PR implements a similar custom handler that supports various
severity levels. The `MLIR_ENABLE_DIAGNOSTICS` environment variable now
specifies the severity level: `warnings` for warnings and errors, and
`remarks` for remarks, warnings, and errors.
- **IR Emission Control**: By default, the MLIR diagnostic API emits
IRs, which can clutter error messages or performance remarks. This PR
suppresses IR emission unless explicitly enabled by the user, improving
the readability of error messages and performance remarks. Users can
specify `MLIR_ENABLE_DIAGNOSTICS=remarks,operations` to include IR
operations in remarks.
- **Stacktraces**: Previously, setting `MLIR_ENABLE_DIAGNOSTICS=1`
enabled all diagnostic information with stacktraces. Now, the
`stacktraces` parameter specifically enables stacktraces. For example,
`MLIR_ENABLE_DIAGNOSTICS=remarks,operations,stacktraces` enables IR
operations and stacktraces, displaying all remarks, warnings, and
errors.
- **Testing**: Updated existing Python tests to verify that combinations
of operations and stacktraces are emitted successfully.
### Future Work
- With the new handler in place, there is an opportunity to further
enhance the readability of existing warnings and remarks. This will be a
focus in future updates.
# New contributor declaration
- [x] I am not making a trivial change, such as fixing a typo in a
comment.
- [x] I have written a PR description following these
[rules](https://cbea.ms/git-commit/#why-not-how).
- [x] I have run `pre-commit run --from-ref origin/main --to-ref HEAD`.
- Select one of the following.
- [x] I have added tests.
- `/python/test` for end-to-end tests
- [ ] This PR does not need a test.
- Select one of the following.
- [x] I have not added any `lit` tests.
- [ ] The `lit` tests I have added follow these [best
practices](https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices),
including the "tests should be minimal" section. (Usually running Python
code
and using the instructions it generates is not minimal.)1 parent 1186806 commit 924468e
File tree
4 files changed
+161
-97
lines changed- python
- src
- test/unit
- third_party/nvidia/backend
4 files changed
+161
-97
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
236 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
143 | 179 | | |
144 | 180 | | |
145 | 181 | | |
| |||
148 | 184 | | |
149 | 185 | | |
150 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
151 | 204 | | |
152 | 205 | | |
153 | 206 | | |
| |||
1691 | 1744 | | |
1692 | 1745 | | |
1693 | 1746 | | |
1694 | | - | |
1695 | | - | |
1696 | 1747 | | |
1697 | 1748 | | |
1698 | 1749 | | |
1699 | 1750 | | |
1700 | 1751 | | |
1701 | 1752 | | |
1702 | 1753 | | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | 1754 | | |
| 1755 | + | |
1715 | 1756 | | |
1716 | 1757 | | |
1717 | 1758 | | |
| |||
1741 | 1782 | | |
1742 | 1783 | | |
1743 | 1784 | | |
| 1785 | + | |
| 1786 | + | |
1744 | 1787 | | |
1745 | 1788 | | |
1746 | 1789 | | |
| |||
1752 | 1795 | | |
1753 | 1796 | | |
1754 | 1797 | | |
1755 | | - | |
| 1798 | + | |
1756 | 1799 | | |
1757 | 1800 | | |
1758 | 1801 | | |
| |||
1763 | 1806 | | |
1764 | 1807 | | |
1765 | 1808 | | |
1766 | | - | |
1767 | 1809 | | |
1768 | | - | |
1769 | | - | |
1770 | | - | |
1771 | | - | |
1772 | | - | |
1773 | | - | |
1774 | | - | |
1775 | | - | |
1776 | | - | |
1777 | | - | |
1778 | | - | |
1779 | | - | |
| 1810 | + | |
| 1811 | + | |
1780 | 1812 | | |
1781 | 1813 | | |
1782 | 1814 | | |
| |||
1787 | 1819 | | |
1788 | 1820 | | |
1789 | 1821 | | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
1803 | 1842 | | |
| 1843 | + | |
1804 | 1844 | | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
1808 | 1849 | | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
1809 | 1857 | | |
1810 | 1858 | | |
1811 | 1859 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
| |||
74 | 70 | | |
75 | 71 | | |
76 | 72 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| |||
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
129 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
130 | 150 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 151 | + | |
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
146 | 155 | | |
147 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
148 | 168 | | |
149 | 169 | | |
150 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | 241 | | |
248 | 242 | | |
249 | 243 | | |
| |||
299 | 293 | | |
300 | 294 | | |
301 | 295 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
| 296 | + | |
307 | 297 | | |
308 | 298 | | |
309 | 299 | | |
| |||
0 commit comments