[CIR][MLIR-LLVM] Add 'thread local mode/model' attribute support (#214337)
The main purpose of this patch is to implement the 'tls_model' attribute
for ClangIR. However, this required updating the LLVM-IR dialect to ALSO
support this, not just as a bool. This patch threads it into both sides.
CIR tries to refer to it as "TLS_Model" to match the C/C++ attribute
closely, the LLVM Dialect refers to it as ThreadLocalMode to reflect
better what LLVM does.
Left as still 'not done' (in CIR only!) is the lowering of the 'other'
kinds of thread-local settings, which are intended to do various levels
of locking/initialization. Those are left for a future implementation
effort. The C++ test itself is taken directly from classic codegen.
[IVDescriptors] Implement MonotonicDescriptor
RFC link: https://discourse.llvm.org/t/rfc-loop-vectorization-of-compress-store-expand-load-patterns/86442
"Monotonic" variable is similar to induction variable, but its value is updated under some condition, e.g.:
```
int idx = 0;
for(int i = 0; i < n; ++i) {
// some uses of idx
if (cond)
++idx;
}
```
In this example, `i` is induction variable and `idx` is monotonic variable: it's updated only when cond == true. In LLVM IR, this looks like:
```
loop_header:
%monotonic_phi = [%start, %prehader], [ %chain_phi0, %latch]
step_bb:
[26 lines not shown]
[clang-tidy][docs] Rewrite bugprone check docs to Markdown [1/4] (#214413)
Tracking issue: #201242
See the [migration guide] for more information.
[migration guide]:
https://llvm.org/docs/SphinxQuickstartTemplate.html#markdown-migration-guidelines
This rewrites part 1/4 of the remaining bugprone check documentation
from reST to MyST Markdown.
AI Usage: This was prepared with rst2myst and GPT5.6-assisted cleanup.
I manually verified that the documentation renders as expected.
Preview site:
https://broken.life/llvm-staging/bugprone-markdown-port/
[clang-tidy][docs] Rename bugprone check docs to Markdown [1/4] (#214412)
Tracking issue: #201242
See the [migration guide] for more information.
[migration guide]:
https://llvm.org/docs/SphinxQuickstartTemplate.html#markdown-migration-guidelines
This is the mechanical rename for part 1/4 of the remaining `bugprone`
check documentation.
The rewrite is provided by the next PR in this stack.
[analyzer] Fix -analyzer-output=sarif crash on macro-expanded ranges
A path piece whose range ends inside a macro expansion aborted the whole
document: https://godbolt.org/z/61vWYcsWj
Cannot create a physicalLocation from invalid SourceRange!
convertTokenRangeToCharRange() built the end with
Lexer::getLocForEndOfToken(), which returns an invalid location for a macro
ID that is not at the end of its expansion, and used it unchecked. The
analyzer's own test corpus hits this in nine files; text and plist output
were unaffected because both already map such ranges to the expansion.
- Use getExpansionRangeInFile(), so the region covers the macro use like the
other two outputs.
- Fall back to a caret when the range is unusable. A thread flow needs a
location per piece, so dropping one would truncate the reported path. This
also stops reversed ranges producing regions with endColumn < startColumn.
[4 lines not shown]
[analyzer] Fix -analyzer-output=html assert on reversed and macro ranges
HTMLDiagnostics::HighlightRange guarded against a reversed range by
comparing line numbers, so a same-line reversal - which is what the piece for
an implicit copy constructor carries - reached html::HighlightRange.
Its scan walks from begin to end, ran off the end of the buffer, and asserted:
https://godbolt.org/z/sTb5qfjjd
Invalid position to insert! (RewriteRope.h)
It also added the end token's length itself and then passed a token range to
html::HighlightRange, which measured the token again, this time from the
interior. For most tokens the two cancel, but where the tail re-lexes longer
the highlight reached past the end of the range, e.g. over a trailing ';'.
Use getExpansionRangeInFile(), which rejects reversed and cross-file ranges,
then convert once and tell html::HighlightRange the range is already
char-granular.
[4 lines not shown]
[clang] Reject ranges getExpansionRangeInFile cannot represent
getExpansionRangeInFile was extracted verbatim and inherited two shortcomings
of the original loop, fixed here before the analyzer's SARIF and HTML consumers
depend on it:
- It mapped the end with getExpansionRange(SourceLocation), which always
reports a token range, so a char-range input was widened by a whole token.
Now using the getExpansionRange(CharSourceRange) overload, which keeps the flag.
- It passed reversed ranges through. Consumers walk begin->end; now returning
nullopt for those, as Lexer::makeFileCharRange already does.
Separate from the extraction so that stays NFC, and out of the consumer fixes
because it changes the shared helper's contract rather than one output.
Both contract changes, plus the invalid- and cross-file-range guards, are
covered by a GetExpansionRangeInFile unit test in
clang/unittests/Frontend/TextDiagnosticTest.cpp.
Assisted-By: claude
[clang][NFC] Extract getExpansionRangeInFile out of the diagnostic renderers
Prep for the following commits, which fix crashes in the analyzer's SARIF and
HTML output on ranges that end inside a macro expansion. Fixing them means
mapping such a range into the reported file - the normalization the frontend
text and SARIF renderers already do, and that the two analyzer consumers each
do differently and incorrectly.
Hoist that logic into getExpansionRangeInFile, beside the DiagnosticRenderer
base both frontend renderers derive from, so the fixes reuse one
implementation instead of adding two more copies. TextDiagnostic and
SARIFDiagnostic move onto it here with no behavior change; the analyzer
consumers follow in later commits.
getFileID() replaces SARIFDiagnostic's getDecomposedLoc(...).first - equivalent
here, and what TextDiagnostic has used since c113cbb51005.
Assisted-By: claude
[AArch64][CostModel] Consider some nxv1 operations as legal
This is allowing some operations on vscale x 1 types, namely:
- load/store
- masked load/store
- arithmetic instructions like add/sub/mul
For those, there is already codegen coverage. See e.g.
- llvm/test/CodeGen/AArch64/sve-int-arith.ll
- llvm/test/CodeGen/AArch64/sve-load-store-legalisation.ll
- llvm/test/CodeGen/AArch64/sve-masked-gather.ll
- llvm/test/CodeGen/AArch64/sve-masked-scatter.ll
[AArch64][CostModel] Explicitly disable histograms for nxv1 types (#214470)
Currently, histograms are not disabled for vscale x 1 types, but LV will
implicitly not generate them because surrounding arithmetic instructions
are invalid for vscale x 1.
SDAG does not implement operand widening for histograms, so this patch
explicitly disables those cases.
[AArch64][CodeGen] Fold tbx(splat(0), table, idxs) to tbl(table, idxs) (#214268)
When the destination/background vector of a TBX instruction is a splat
of zero, the operation is equivalent to a TBL instruction. TBL
implicitly zeroes out any elements where the index is out of bounds,
matching the behavior of TBX with a zero background vector.
This patch adds a DAG combine to optimize this case, reducing
instruction latency and register pressure.
Fixes #214077
[X86][AsmParser] Support parentheses around scale and index register in Intel syntax (#211003)
Old patterns and why they broke
- Decisions matching (CurrState, PrevState) tuples (e.g. CurrState ==
IES_REGISTER && PrevState != IES_MULTIPLY)
to gate committing a register to Base/Index aren't paren-transparent:
any (...) turns CurrState into IES_RPAREN, so the tuple stops matching
and
`[reg + (reg)]`, `[reg + (reg*2)]`, `[reg + 2*(reg)]` fell through the
guards.
- Duplicated commit blocks. Recognizing whether a register is Base or
Scale was placed in four
handlers (onPlus, onMinus, onRBrac, onRParen), forcing onRParen to
replay it just to catch (reg).
- Scale was committed immediately in onInteger; a parenthesized scale
like (2) * 4 or 2 * (4)
had nowhere to accumulate.
[19 lines not shown]
[analyzer] Fix -analyzer-output=html assert on reversed and macro ranges
HTMLDiagnostics::HighlightRange guarded against a reversed range by
comparing line numbers, so a same-line reversal - which is what the piece for
an implicit copy constructor carries - reached html::HighlightRange.
Its scan walks from begin to end, ran off the end of the buffer, and asserted:
https://godbolt.org/z/sTb5qfjjd
Invalid position to insert! (RewriteRope.h)
It also added the end token's length itself and then passed a token range to
html::HighlightRange, which measured the token again, this time from the
interior. For most tokens the two cancel, but where the tail re-lexes longer
the highlight reached past the end of the range, e.g. over a trailing ';'.
Use getExpansionRangeInFile(), which rejects reversed and cross-file ranges,
then convert once and tell html::HighlightRange the range is already
char-granular.
[4 lines not shown]
[NFC] Add missing <cmath> and <limits> includes across llvm, mlir, lldb, flang, and bolt (#214410)
This is basically a continuation of
https://github.com/llvm/llvm-project/pull/214349...
This change adds missing `#include <cmath>` and `#include <limits>`
headers to several files across `llvm`, `mlir`, `lldb`, `flang`, and
`bolt`.
In commit
https://github.com/llvm/llvm-project/commit/ada3786e91ca2058f3ac8255a024c12ae7d263ee,
`<random>` stopped transitively pulling in the top-level `<cmath>`
header in favor of internal granular `<__math/...>` headers.
Multiple files across the codebase were implicitly relying on transitive
`<cmath>` inclusions from headers like
`llvm/Support/RandomNumberGenerator.h` and other headers that pull in
`<random>`. I'm explicitly adding the missing dependency.
### Affected Files
[16 lines not shown]
[AMDGPU][GlobalISel] Pre-commit tests for readanylane merge regbank combine (NFC)
Add regbank-combiner tests covering a copy to vgpr whose source is a
merge or build_vector of G_AMDGPU_READANYLANE results and uniform
values. These currently keep the round trip through sgprs, and also
cover the cases where the merge has another user and where all merge
sources are uniform.
Co-authored-by: Cursor <cursoragent at cursor.com>
[analyzer] Fix -analyzer-output=sarif crash on macro-expanded ranges
A path piece whose range ends inside a macro expansion aborted the whole
document: https://godbolt.org/z/61vWYcsWj
Cannot create a physicalLocation from invalid SourceRange!
convertTokenRangeToCharRange() built the end with
Lexer::getLocForEndOfToken(), which returns an invalid location for a macro
ID that is not at the end of its expansion, and used it unchecked. The
analyzer's own test corpus hits this in nine files; text and plist output
were unaffected because both already map such ranges to the expansion.
- Use getExpansionRangeInFile(), so the region covers the macro use like the
other two outputs.
- Fall back to a caret when the range is unusable. A thread flow needs a
location per piece, so dropping one would truncate the reported path. This
also stops reversed ranges producing regions with endColumn < startColumn.
[4 lines not shown]
[clang] Reject ranges getExpansionRangeInFile cannot represent
getExpansionRangeInFile was extracted verbatim and inherited two shortcomings
of the original loop, fixed here before the analyzer's SARIF and HTML consumers
depend on it:
- It mapped the end with getExpansionRange(SourceLocation), which always
reports a token range, so a char-range input was widened by a whole token.
Now using the getExpansionRange(CharSourceRange) overload, which keeps the flag.
- It passed reversed ranges through. Consumers walk begin->end; now returning
nullopt for those, as Lexer::makeFileCharRange already does.
Separate from the extraction so that stays NFC, and out of the consumer fixes
because it changes the shared helper's contract rather than one output.
Both contract changes, plus the invalid- and cross-file-range guards, are
covered by a GetExpansionRangeInFile unit test in
clang/unittests/Frontend/TextDiagnosticTest.cpp.
Assisted-By: claude