[llvm-lib] Map thumb bitcode to IMAGE_FILE_MACHINE_ARMNT (#240565)
getBitcodeFileMachine knew Triple::arm but not Triple::thumb, which is
what clang uses for 32-bit ARM Windows. So llvm-lib refused a thumbv7
bitcode file, for example from -flto=thin, with "unknown arch in target triple".
infer-machine.test now also requires the x86 target, which it already
needed.
Assisted-by: Claude Opus 5.5 (Anthropic)
axp81x: Set the maximum voltage of the AXP805 regulators
AXP805_REG() did not set voltage_max, so a regulator without
regulator-max-microvolt in the FDT got a maximum of 0 and its
initialisation failed with ERANGE. Compute it from the minimum and the
steps of the two ranges, like the value of the AXP813 DCDC7.
Reported by: llm-postcr
Tested on: H6
axp81x: Allow the interrupt handler to sleep
The interrupt handler reads and writes the registers of the PMU, which
can sleep: the I2C controller the AXP805 is on in the H6 waits for the
end of the transfer, and taking the bus waits when it is busy. The
handler runs in an interrupt thread, which cannot sleep unless the
interrupt is marked as sleepable, so the first interrupt would panic a
kernel with INVARIANTS. Mark it, the interrupt is not shared.
Reported by: llm-postcr
Tested on: A64, H6
axp81x: Always set the delay of the regulator methods
axp8xx_regnode_set_voltage() and axp8xx_regnode_enable() only set the
delay when they succeeded, so the callers could use an uninitialized
value after an error. Set it first like the default methods do.
Reported by: llm-postcr
Tested on: A64
[LLD][COFF] Use the static relocation model for ARMNT LTO (#240560)
lld used the PIC relocation model for LTO on every machine but i386.
clang's driver compiles 32-bit ARM Windows code with the static
model (isPICDefault() is only true for x86_64 and aarch64 on Windows),
and with PIC the load of the /GS stack cookie becomes a PC-relative
movw/movt pair that COFF cannot express. So every function with a
stack protector failed ThinLTO code generation with "Cannot represent
this expression". Use the static model for ARMNT too.
Assisted-by: Claude Opus 5.5 (Anthropic)
regulator: Do not delay when setting the voltage failed
regnode_set_voltage_checked() called regnode_delay() with the delay
returned by the driver even when REGNODE_SET_VOLTAGE() failed. A driver
does not have to set it on error, so the delay could be a random value
from the stack. Only wait when the voltage was set, like
regnode_set_voltage() does.
Reported by: llm-postcr
Tested on: A64
[libc] Use CheckedPtr in strdup, strndup and __sched_cpualloc (#241332)
Replace raw AllocChecker + new[] allocations in internal::strdup,
strndup and __sched_cpualloc with make_unique_for_overwrite, and update
internal::strdup to return CheckedPtr<T[]> instead of cpp::optional<T
*>.
While there, add an implicit CheckedPtr(cpp::nullptr_t) constructor so
functions returning CheckedPtr can simply `return nullptr` on error/null
input (the resulting CheckedPtr is still unchecked, so callers still
have to inspect it)
I add bazel rules for unique_ptr and CheckedPtr to as these are the
first targets that need them.
Assisted-by: Gemini
[mlir][bytecode] Support custom encodings for mutable types
The writer stored every mutable type as text, because the reader could
not read a type whose contents refer back to it. Add
DialectBytecodeReader::bindResult. A dialect reading a mutable type gets
the type from its key and binds it before reading the rest, and a
reference back to the entry then reads as the bound type. If the
reader's depth limit defers the read, the binding stays and the reader
retries the entry after its dependencies. Writer callbacks and writeType
now also run for mutable types, so a dialect that encodes a
self-referential type must call bindResult. Mutable attributes still use
text. The test dialect's recursive type gets an encoding to test this.
Assisted-by: Claude Code (Claude Opus 5.5).
[CIR] Add bytecode encodings for types
CIR types had no bytecode encoding, so the writer stored each one as its
printed form. That form spells out the body of every record the type
reaches through a pointer, and bytecode for the 45 MB of CIR from
CIRDialect.cpp came to 1.48 GB and took over an hour to read. Encode
every CIR type, and the bit-field declarations that bit-field types
hold. A named record binds itself with
DialectBytecodeReader::bindResult before reading its members. The same
module now takes 4.7 MB and reads in 0.44 s.
Assisted-by: Claude Code (Claude Opus 5.5).
[MC][DWARF] Don't deduplicate DWARF 5 root file with explicit file index (#240823)
In DWARF 5 mode, `MCDwarfLineTableHeader::tryGetFile` always
deduplicates the root file, even when a non-zero file number is passed
to the function.
This is in contrast to DWARF 4 and earlier modes, where automatic file
number assignment only happens if zero is passed as the file number,
otherwise it allocates the specified file number.
DWARF 5 mode should respect this as well, and create a new entry when a
non-zero file number is given.
Fixes #72027
[clang][ARM] Add the MSVC compiler barriers for 32-bit Arm (#240572)
_ReadWriteBarrier, _ReadBarrier and _WriteBarrier were not builtins on
32-bit Arm. intrin.h declares them for every target, so a call became a
call to an external function that doesn't exist, and #pragma intrinsic
warned about them. Add them as builtins. They lower to a single-thread
fence through MSVCIntrin, which x86 and AArch64 now use too. sqlite
uses them.
Assisted-by: Claude Opus 5.5 (Anthropic)
[clang][ARM] Accept pcs("aapcs-vfp") on Windows (#240569)
Windows on ARM always uses AAPCS-VFP, but pcs("aapcs-vfp") gave a
warning there that the calling convention is not supported, which is an
error with -Werror. Skia uses the attribute. Ignore it on Windows, like
the x86 conventions, so it means the default convention, which it is.
Assisted-by: Claude Opus 5.5 (Anthropic)
[NFC][analyzer] Simplify CheckerContext::generateNonFatalErrorNode (#241346)
The three-parameter form of `CheckerContext::generateNonFatalErrorNode`
had an early return statement which wasn't activated in any of the 6
call sites of this method, because each caller always passed a non-null
state (the state of an existing exploded node).
By the way, this early return was also logically incorrect, so a
downstream checker that relied on it would be already very buggy.
I also refactored four of the six call sites of this overload to use the
simpler two-parameter overload (without passing any argument, using the
defaults).
[NFC][clang][Sema] Move three tests to SemaCXX (#240864)
Move three C++ lit test files from `clang/test/Analysis` to
`clang/test/SemaCXX` because that is where the bulk of the tests for
these compiler warnings (`-Wthread-safety`, `-Wuninitialized`,
`-Wconsumed` and `-Wunreachable-code-aggressive`) are located.
For background information, see
https://discourse.llvm.org/t/untangle-static-analyzer-and-ssaf-tests/91835/13
[LoopIdiomVectorize] Remove unused LoopIdiomVectorize::DL (NFC) (#241688)
LoopIdiomVectorize::DL has been unused since the pass was introduced
on January 9, 2024 in commit c7148467fc08eefaaae876c7d11d629c849f42cf.
Assisted-by: Antigravity
loader: Read the partition table of md images
md is a DEVT_DISK device but never called disk_open(), so reads always started
at offset 0 of the image. A partitioned image, such as a memstick image booted
memdisk=, has its partition table there, not a filesystem, and the loader stops
with "MD not present".
Reviewed by: imp
Approved by: imp
Sponsored by: Netflix
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/99
[llvm] Remove unused local variables (NFC) (#241686)
This patch removes unused local variables across llvm/.
Note that these variables did not trigger -Wunused-variable because
their types have non-trivial constructors or destructors, and their
initializers have no side effects on surrounding state.
Assisted-by: Antigravity
[LV] Add a cost for `VPInstruction::NumActiveLanes` (#240326)
This costs `VPInstruction::NumActiveLanes` as an extended reduction and
adds some AArch64 costs/tests.
[VPlan] Remove header masks whose tail lanes aren't used
Replace a use of header-mask && x with x if the user, transitively
through freeze, logical-and, not and mask.beforefirst(freeze ...), only
reaches masks that are and'ed with the header mask again. The header
mask is a prefix and lane i of mask.beforefirst only depends on lanes
0..i, so the lanes outside of the header mask are never used.
This avoids the i1 vp.merge that EVL tail folding needs for the inner
header mask, e.g. in the early exit mask.beforefirst(freeze(header-mask
&& c)) and in switch default edges.
[VPlan] Allow tail folding early exits with side effects
Continues the work in #179595.
This allows us to tail fold e.g. the following loop:
```c
extern char a[1024], b[1024], c[1024], y[1024];
void two_guards(void) {
for (int i = 0; i < 1000; i++) {
if (a[i] == 0)
break;
if (b[i] > 3) {
if (c[i] < 9)
y[i] = 1;
}
}
}
```
[30 lines not shown]
[VPlan] Support tail folding uncountable early exits
Enables the first step towards #179595. After #237254, the MaskedHandleExitInVectorLoop early exit style uses the CFG to handle masking for early exit loops. This allows it to compose with tail folding which is also handled via the CFG in #176143.
This allows us to tail fold the following loop:
```c
extern char x[256];
int f(char * restrict y) {
for (int i = 0; i < 256; i++) {
if (x[i] == 0)
return i;
}
return -1;
}
```
Into this on RISC-V:
[18 lines not shown]
[VPlan] Use vputils::findCanonicalIVIncrement in more places. NFC
In a future patch we want to enable more scenarios with early exits and tail folding. In these scenarios the terminator will no longer be a BranchOnCount/BranchOnCond but a BranchOnTwoConds, so a bunch of canonical IV matchers break. Use vputils::findCanonicalIVIncrement instead since it searches the users of the canonical IV instead of looking at the terminator.
[VPlan] Allow early exit loops with side effects by masking in the vector loop.
When all blocks with side effects are dominated by every early exit, we can vectorize the loop if we mask off any lanes past the exit. We can do this with control flow:
```mermaid
flowchart TD
header --> exiting
exiting -->| exit mask | sideeffects --> latch --> latch.split
exiting -->| !exit mask | latch.split
```
For every early exiting block we add a branch to the latch on `!mask.beforefirst(exitcond)`. This is implemented in UncountableExitStyle::ReadOnly which is now renamed to MaskedHandleExitInVectorLoop.
This is a complementary exit style to MaskedHandleExitInScalarLoop. If any of the side effects aren't dominated by the early exit it still falls back to the scalar loop style, which is why none of the existing early exit side effect tests changed. Masking in loop is profitable for RISC-V and I'm assuming it's also profitable for AArch64 too, but if not then we can add a TTI hook for a preferred exit style.
[VPlan] Preserve SSA in early exit loops
MaskedCond is used to logically-and the condition to early exit with the current block in-mask. However because we use it in the latch block where the condition isn't defined on all paths, we have to workaround it not being in SSA in the verifier.
This fixes this by using reconstructSSA added in #212209 to preserve SSA in both the exit conditions and live outs in the exit blocks. It also means we get the right exit condition without MaskedCond and allows us to remove the MaskedCond exceptions in the verifier. MaskedCond is still kept since a followup PR will still use it.
One subtle point is that we need to freeze any branch conditions. Any lanes after and including the early exiting lane might contain poison and we can have branches on those poison lanes that didn't we didn't previously branch on in the scalar loop.
There's no miscompile on main today because we coincidentally don't keep SSA so exit conditions are read directly without being polluted by poison stemming from a branch past the early exit. But in this PR the exit conditions are polluted and we can end up with poison in the condition operand of a select, which causes an undefined result for AnyOf even if it freezes its operand. The poison in the branch will also cause problems in future if we decide to preserve uniform control flow and emit branches instead of blends. The exit_cond_merged_after_poison_branch test illustrates this.