[BOLT] Compare unwind and EH state in ICF (#244049)
ICF compared a CFI pseudo instruction only by its operand, an index into
the frame instruction table of its own function, but not by the frame
instruction behind it. It did not compare the rules in effect at the
entry (CIE initial instructions plus FDE instructions before the first
advance), as these don't end up in pseudo instructions. ICF also doesn't
compare the personality routine, whether the function has an LSDA, the
AArch64 return address signing state, or DW_CFA_GNU_args_size. For all
of these, BOLT keeps them outside the instruction stream. Since ICF
compares functions instruction by instruction, by opcode and operands,
and MCPlusBuilder::equals() skips annotations, so any state kept in
function fields or annotations is only compared when ICF checks for it
explicitly, like for landing pads and LSDA tables.
If two functions with identical code but different unwind info were
folded, the folded function would then always unwind with the rules of
the selected function, which could be wrong sometimes.
[12 lines not shown]
[lldb] Intern debugger-owned SB API strings in the debugger pool (#244348)
Intern strings returned by SB classes that belong to a debugger in that
debugger's pool (which currently is still the global pool).
GetDebuggerStringPool is a helper that takes a Target by reference, so
no getter can ask for a debugger's pool without a target. That was
intentional, to force the caller to think about that (and intern the
string in the global pool), making it easy to use the API correctly and
hard to do so incorrectly.
Assisted-by: Claude
[AArch64] Cluster NM form FMINNM/FMAXNM too (#239222)
Adding positive tests for the entire matrix because their I believe
their count is still reasonable while getting full coverage, plus
representative cases for the negative mixed kinds. Also move kind enum
to an anonymous namespace (slipped through in the previous patch).
tests/ssl_sendfile: size socket buffers before connecting
The :grow, :truncate and :eagain_vs_eof cases rely on the socket buffers
filling up before the whole file has been sent. :grow and :truncate shrank
SO_SNDBUF and SO_RCVBUF only after the connection was established, when
the receiver had already advertised a window based on the default buffer
size; TCP does not shrink an advertised window. :eagain_vs_eof used the
default, autosized buffers. With a large net.inet.tcp.recvspace, or once
autosizing has grown the buffers, the whole 2 MB file fits in the socket
buffers:
:grow and :truncate: sendfile(2) returns before the file is resized, and
the poll loop that waits for the sender to block spins forever on a
writable socket.
:eagain_vs_eof: the loop that keeps writing until
EAGAIN never sees it, since sendfile(2) returns 0 at EOF.
Either way kyua reports a timeout, which is why doubling the timeouts did
not help. Apply a 128 KB buffer size to the listening socket, which the
[12 lines not shown]
[KnownFPClass] Add KnownFPClass::fadd(x, CRHS) to rule out subnormal results (#237966)
Add KnownFPClass::fadd(x, CRHS) to rule out subnormal results when the
CRHS is normal and abs(CRHS) > 2^(expMin + precision - 1). Use this
overload in ValueTracking.
Fixes #234364
[lldb][RISCV] Instruction emulation should ignore bare sc.w/d (#244082)
RV32A/RV64A does compare-and-swap with a sequence like (example from
docs.riscv.org)
```
# a0 holds address of memory location
# a1 holds expected value
# a2 holds desired value
# a0 holds return value, 0 if successful, !0 otherwise
cas:
lr.w t0, (a0) # Load original value.
bne t0, a1, fail # Doesn't match, so fail.
sc.w t0, a2, (a0) # Try to update.
bnez t0, cas # Retry if store-conditional failed.
li a0, 0 # Set return to success.
jr ra # Return.
fail:
li a0, 1 # Set return to failure.
[17 lines not shown]
[dsymutil] Undo prefix mapping before resolving paths for ODR uniquing
The classic linker resolves the declaration file of a type with
realpath() to tell apart types with the same name, line and size. For
paths remapped by compilation caching, which don't exist on disk,
realpath() fails and only the file name is left, so different types
declared in headers with the same name in different directories were
merged. Undo the prefix mapping from compilation-prefix-map.json first.
[dsymutil] Support compilation-prefix-map.json from compilation caching
Compilation caching can prefix map the paths that the compiler sees, so
that cache keys don't depend on where the build happens, for example
/path/to/project becomes /^src. The build system records the mapping in
a compilation-prefix-map.json file in a parent directory of the object
files, as a JSON object from each remapped prefix to the original one.
dsymutil didn't support it, so it used the remapped paths from the
debug info as is: it failed to copy the Swift interfaces that the debug
info refers to, didn't recognize interfaces from the SDK or the
toolchain that it should skip, and wrote the remapped paths into the
dSYM.
Load the compilation-prefix-map.json closest to each object file, and
use it to find Swift interfaces and Clang modules, and to restore the
original paths in the path attributes and line tables of the linked
debug info. Clang modules use the map of the object file that refers to
them. -object-prefix-map still only applies to looking up Clang
[6 lines not shown]
[lldb] Let language plugins add formatter candidate languages (#244347)
This patch adds Language::GetAdditionalFormatterLanguages(), which
FormatManager::GetCandidateLanguages() asks every language plugin. A
plugin can use it to apply its formatters to values of another language,
or to apply the formatters of another language to its own values.
Assisted-by: Claude
[libc] Implement unshare (#244039)
Unshare is a linux specific syscall wrapper. This PR adds an
implementation and tests.
Assisted-by: Automated tooling, human reviewed.
[lldb] Fix operator!= on invalid SB type formatter objects (#244360)
With an invalid left operand, operator!= returned the result of
operator==.
Assisted-by: Claude
[mlir][SPIR-V] Add SPIRVToLLVM conversion for array and struct constants (#243896)
Arrays of scalars lower to a single llvm.mlir.constant, other aggregates
to llvm.insertvalue chains
This also enables array and struct spirv.Variable initializers
[Support] Address PrefixMapper review feedback
Match a mapping whose Old ends with a separator, such as "/=/new" or
"/old/=/new", against paths below it; it used to match only the exact
path. Append the rest of the path with its leading separator intact, so
Windows paths keep their separators: "C:/old/a" now maps to "C:/new/a"
instead of "C:/new\a".
Make the map functions const, document how separators are matched and
joined, test separators, sort() and addInverseRange(), and drop the
unused StringSaver references.
[Support] Add vfs::findFileInParentDirectories()
Several tools look for a file in a directory and its parent
directories, for example clang-format for .clang-format and clang-tidy
for .clang-tidy, and each has its own loop for that. Add a function for
it, which dsymutil will use to find the compilation-prefix-map.json
files that compilation caching writes.
[Support] Add PrefixMapper
Add a utility for remapping path prefixes, along with MappedPrefix for
parsing "old=new" mappings. Mappings are matched on whole path
components and respect the configured path style, so Windows paths are
matched case- and separator-insensitively.
This will be used by dsymutil to undo the path prefix mapping applied
by compilation caching.
[clang] Pack clang::Module's members more tightly
- `Kind` becomes a 4-bit bitfield next to the other flags: `ModuleKind` has 9
enumerators. The enum gets a fixed `unsigned` underlying type so that the
bitfield is unsigned on all ABIs.
- `UseExportAsModuleLinkName` becomes a bitfield too.
- `VisibilityID` moves next to `DefinitionLoc`, so that the two 4-byte members
share an 8-byte slot instead of each being followed by padding.
- `HeaderKindBeginIndex` holds indices into `HeadersStorage`, so it becomes a
`uint16_t` array, with an assertion against modules with 65535 or more
headers. The largest module in the scans below has 29.
`sizeof(Module)` goes from 328 to 304 bytes.
Measured with an assertions-disabled Release build of `clang-scan-deps
-format experimental-full -j 20` on 200 TUs (10 TUs importing various SDK
frameworks, each in 20 module context hashes), with an empty module cache and
with one populated by the previous scan. Each of 40 rounds runs the binaries
of the whole series in random order. Peak memory footprint from
[7 lines not shown]
[clang] Track a module's unresolved `export *` separately
Most export declarations in module maps are a plain `export *`, which
doesn't refer to any module and always resolves to a wildcard export. Instead
of storing it in `UnresolvedExports`, whose element is 96 bytes (mostly the
inline storage of the `ModuleId`), record it in a new bit,
`UnresolvedWildcardExport`, and resolve it first in
`ModuleMap::resolveExports()`.
The module statistics come from temporary instrumentation that records, for
every module, the largest size each container reaches and whether each member
is ever set, in the scans measured below; numbers are given as "empty /
populated module cache". The scanner creates 1.89M / 0.38M modules, but only
about 40-55k of them are alive at the same time, since a TU's modules are freed
once it's scanned, so the peak memory goes down by roughly the bytes saved per
module times that.
`UnresolvedWildcardExport` is set in 40.3% / 23.1% of the modules, while the
remaining (named) unresolved exports are used by only 0.4% / 0.3% of them (76%
[23 lines not shown]
[clang] Shrink the inline storage of clang::Module's containers
Most of `Module`'s containers reserve inline storage for one or two elements,
or are `std::vector`s (24 bytes instead of 16 for a `SmallVector<T, 0>`), even
though they're empty in almost every module, or almost always hold exactly
one element.
The module statistics come from temporary instrumentation that records, for
every module, the largest size each container reaches and whether each member
is ever set, in the scans measured below; numbers are given as "empty /
populated module cache". The scanner creates 1.89M / 0.38M modules, but only
about 40-55k of them are alive at the same time, since a TU's modules are freed
once it's scanned, so the peak memory goes down by roughly the bytes saved per
module times that.
These get no inline storage:
- `AffectingClangModules`, `DirectUses`, `UndeclaredUses` and `Conflicts`
are empty in every module of these scans.
[40 lines not shown]
[clang] Move clang::Module's submodule list out of line
`SubModules` and `SubModuleIndex` take 40 bytes in every module, but only the
modules that have submodules use them. Move them into a
`Module::SubmoduleMembers` struct, stored in a `Module::LazyMembers`.
`submodules()` doesn't allocate the struct for modules without submodules.
The module statistics come from temporary instrumentation that records, for
every module, the largest size each container reaches and whether each member
is ever set, in the scans measured below; numbers are given as "empty /
populated module cache". The scanner creates 1.89M / 0.38M modules, but only
about 40-55k of them are alive at the same time, since a TU's modules are freed
once it's scanned, so the peak memory goes down by roughly the bytes saved per
module times that.
91.4% / 94.5% of the modules are submodules, but most modules are leaves: only
11.4% / 8.5% have submodules (31.2% / 46.8% of the top-level modules, 9.6% /
6.3% of the submodules). The ones that do usually have several: 28% / 24% have
one, 27% / 23% two, and the rest three or more, up to 301. A module without
[36 lines not shown]
[clang] Move top-level-only members out of clang::Module
Seven members are only ever set on top-level modules, but take 200 bytes in
every module, and most modules are submodules: `PresumedModuleMapFile`,
`DirectoryDependencies`, `ASTFileName`, `ASTFileKey`, `Signature`,
`APINotesFile` and `ConfigMacros`. Move them into a `Module::TopLevelMembers`
struct, stored in a `Module::LazyMembers` like the rarely used members.
- `ASTFileName`/`ASTFileKey` were already only read and written through
`getTopLevelModule()`, and `DirectoryDependencies` only written through it.
- `PresumedModuleMapFile` is only set on the module being built (found via
`lookupModule()`, hence top-level) and on top-level modules read from a PCM;
it gets `get/setPresumedModuleMapFile()`.
- `APINotesFile` is only set by `APINotesManager` on the module being built
(`Preprocessor::getCurrentModule()`, also found via `lookupModule()`); it
gets `get/setAPINotesFile()`.
- `ConfigMacros` can only be declared on top-level modules
(`err_mmap_config_macro_submodule`); it gets `getConfigMacros()`,
`addConfigMacro(s)()` and `clearConfigMacros()`.
[39 lines not shown]
[clang] Move rarely used members out of clang::Module
Move nineteen members that are empty or unset in almost every module into a
`Module::ColdMembers` struct (584 bytes), managed by a small private helper,
`Module::LazyMembers<T>`, which holds a `std::unique_ptr<T>` and allocates it
on the first write. Reads go through `get()`, which returns a static empty
instance when nothing is allocated; `clear()` and `take()` don't allocate
either. Users go through accessors: `getX()` returns an `ArrayRef`,
`StringRef` or value (empty when the struct isn't allocated), `addX()`/`setX()`
write, `takeX()` moves a list out (for the resolve-and-re-add loops in
`ModuleMap`), and `clearX()` (which doesn't allocate) is used by the
`ASTReader` when a PCM replaces the module map's information. The member is
`mutable` because the visible modules cache is built lazily from a const
member function. The behaviour is unchanged.
The module statistics come from temporary instrumentation that records, for
every module, the largest size each container reaches and whether each member
is ever set, in the scans measured below; numbers are given as "empty /
populated module cache". The scanner creates 1.89M / 0.38M modules, but only
[40 lines not shown]