[mlir][wasm] Support for saturating FP truncations (#212709)
Add support for saturate truncation of float to int operations.
This also requires the support of parser with sub-opcodes.
This is handled by supporting parser with extra argument for sub-opcode.
---------
Co-authored-by: Ferdinand Lemaire <ferdinand.lemaire at woven-planet.global>
[libclc] Add math smoke test for cos special values (#214786)
Summary:
Basic math version of unit tests used to give reference for how these
can test the known special values. SImilar to LLVM libc's smoke math
tests on the GPU. More can be added later,
[libc++] Include range access headers in `<optional>` only since C++26 (#214688)
Inclusions of internal range access headers address LWG4131 which
patches P3168R2 "Give `std::optional` Range Support". As P3168R2 is
certainly a new feature in C++26, these includes are unnecessary in old
modes.
It was reported that these increased the size of `<optional>` by ~8%, so
probably it is better to avoid such cost in old modes.
[NVPTX] Drop cache hints on volatile loads/stores (#214830)
https://github.com/llvm/llvm-project/pull/204067 added cache hint
metadata support for NVPTX. I forgot to handle volatile loads/stores
correctly. Volatile loads only support .level::prefetch_size and
volatile stores don't support any cache hints. This PR drops unsupported
metadata for volatile loads/stores.
[libclc][test] Update cos.cl checks after fneg FP-options fix (#214906)
ceaff22ed2c3 ([Clang][CodeGen] Respect FP pragma options for fneg and
calls) scopes fneg's fast-math flags to the expression's own FPOptions
instead of the ambient IRBuilder state, so one fneg in cos.cl's
generated IR no longer carries contract. Regenerate check.
Co-authored-by: Claude Sonnet 5 <noreply at anthropic.com>
[Driver][KCFI] Forward -fsanitize-kcfi-hash= to cc1 (#214827)
-fsanitize-kcfi-hash= is a CC1Option that selects the hash algorithm
used to derive KCFI type IDs (xxHash64 or FNV-1a), but the driver never
claimed or forwarded it. As a result, invocations like
clang -fsanitize=kcfi -fsanitize-kcfi-hash=FNV-1a foo.c
silently dropped the flag with an "argument unused during compilation"
warning; users had to route it through -Xclang to reach cc1. This is
particularly awkward for build systems (e.g. the Linux kernel) that want
to select FNV-1a for -fsanitize=kcfi builds.
Handle the option in SanitizerArgs alongside -fsanitize-kcfi-arity:
capture the last-specified value when KCFI is enabled and forward it to
cc1 as -fsanitize-kcfi-hash=<value>. Values are still validated by cc1's
tablegen-driven Values<"xxHash64,FNV-1a"> checker, so bad values produce
the usual "invalid value" diagnostic. When -fsanitize=kcfi is not
specified, the flag remains unclaimed and triggers
[9 lines not shown]
[MC] Make pseudo-probe divisions ordering stable (#214803)
**Problem**
`MCPseudoProbeSections::emit` sorts probe divisions only by section
ordinal.
Functions sharing a section will have a nondeterministic `unordered_map`
iteration order, producing *different .pseudo_probe bytes for identical
inputs.*
**Solution**
Use the function symbol name as a stable tie-breaker when section
ordinals match.
Add an MC regression test that reverses pseudo-probe insertion order and
requires byte-identical object files.
[4 lines not shown]
[RISC-V] Use an optional offset operand instead of zero-offset InstAliases
Introduce OptionalMemOffsetAsmOperand, which wraps a memory-offset
operand class into a variant with `IsOptional` set so that a memory
operand written without an offset, e.g. "lb a0, (a1)", parses with a
default offset of 0, and use it for a simm12_lo_optional operand. This
replaces the hand-written "(${rs1})" zero-offset InstAlias that every
load/store-style instruction needed (scalar and FP loads/stores, Zilsd,
jr/jalr and the .insn_i/.insn_s memory forms).
OptionalMemOffsetAsmOperand is somewhat complicated, but this makes it
easier to replace all the other optional zero memory operands which I
will do in follow-up commits, removing all the InstAlias duplication.
This change was assisted by AI.
Pull Request: https://github.com/llvm/llvm-project/pull/210901
[BOLT] Page out .dwo files
Split-DWARF inputs at big binaries scale ship 100+ GiB of .dwo
files. BOLT opened a fair number of them during readDebugInfo, putting
a lot of pressure on the OS memory management: mmap'd reads always
populate the page cache; with every .dwo mapped at once those pages
accumulated, refaulted, and registered as memory pressure that got the
process oomd-killed.
Now, .dwo page-cache pages are reclaimed as soon as BOLT is done with
each file: madvise(MADV_PAGEOUT) on the live mapping, then
posix_fadvise(POSIX_FADV_DONTNEED) once it is unmapped. Controlled by
-drop-dwo-page-cache, OFF by default, as it is unlikely upstream
will be processing gigantic sets of dwo files.
[BOLT] Create and release .dwo DWARF contexts incrementally
BOLT opened a DWARFContext for every .dwo during
readDebugInfo and kept them all alive until teardown. On large
split-DWARF targets that is tens of GiB held resident through
emission, the point of peak RSS.
Make the DWOCUs map a lazily-populated cache instead:
* Use the newly added DWARFUnit::clearDWO()/hasDWO() to directly
manage DWARFUnit's DIE caching mechanism.
* BinaryContext::getDWOCU() opens a context on demand (keyed off a
stable DWOId -> skeleton CU map).
* Release contexts as soon as they are done with: all of them at the
end of readDebugInfo, and per-bucket at the DWARF rewrite merge
point.
* Remove DWOCUs map, which became redundant and whose purpose can
now be served by the new id-to-skeleton map, and then fetching
the split CU from the skeleton via getNonSkeletonUnitDIE().
[5 lines not shown]
[libclc][CMake] Add cmake cache files (#201480)
This simplifies cmake configuration without need to pass verbose
variables in cmake command line. Settings in cache file can still be
overriden by passing `-D` flags.
Update `libclc/README.md` to document the usage.
[DebugInfo] Add DWARFUnit::clearDWO()
Add DWARFUnit::clearDWO() so a skeleton unit can drop the DWO context
it owns without being destroyed itself. Also add DWARFUnit::hasDWO()
to answer if that skeleton CU is currently caching a DWO context, so
users can easily look it up.
For example, BOLT opened a DWARFContext for every .dwo during
readDebugInfo and kept them all alive until teardown. On large
split-DWARF targets that is tens of GiB held
resident. clearDWO()/hasDWO() expose to users DWARFUnit's caching
capacity, allowing them to spontaneously drop the cache/look it
up/re-load it for memory management.
[CIR] Forward-declare mlir::ModuleOp in CIRGenerator.h (#214767)
Add missing forward decl for `CIRGenerator.h` to make it self
contained..
Found this while trying to create an Clang FrontEnd action in an
out-of-tree project.
Went with a forward decl since its already done in the file +
recommendations from
https://llvm.org/docs/CodingStandards.html#minimal-list-of-includes
[BOLT] Parse .eh_frame CFI programs on demand to reduce memory
BOLT read the entire .eh_frame up front via DwCtx->getEHFrame(), which
parses and caches the CFI instruction program of every CIE/FDE in the
binary for the whole run. On a large binary, this dominated
file-object discovery: CFIProgram::parse accounted for ~6.5 GB and the
cached DWARFDebugFrame ~6.9 GB of live memory. Yet the CFI programs
are only consumed in CFIReaderWriter::fillCFIInfoFor, and only for the
functions BOLT actually disassembles. discoverFileObjects itself needs
nothing but each FDE's address and range for function-boundary checks.
Here we parse .eh_frame for its index only, and decode each function's
CFI program on demand, lazily, only for the functions that really need
it. In a large binary, DWARFDebugFrame::parse drops from 6922.2 MB
to 587.6 MB, the residual being the lightweight FDE/CIE index (entries
without instruction programs), and readSpecialSections falls from
7078.7 MB to 738.6 MB on the tested binary for which BOLT's RSS is
about 80-120GB.
[DebugInfo] Allow .eh_frame CFI programs to be parsed lazily
BOLT read the entire .eh_frame up front via DwCtx->getEHFrame(), which
parses and caches the CFI instruction program of every CIE/FDE in the
binary for the whole run. On a large binary, this dominated
file-object discovery: CFIProgram::parse accounted for ~6.5 GB and the
cached DWARFDebugFrame ~6.9 GB of live memory (from 5 to 10% of total
anon peak RSS).
This new interface allows DebugInfo's users to optionally parse CFIs
on demand, only when necessary. On BOLT, this is an important lever
to manage memory utilization when processing large binaries.
[CAS][test] Disable plugin CAS tests with HWASAN (#214881)
HWASan does not tag the globals of a dlopen'ed library on Linux/glibc,
so libCASPluginTest.so traps on the first access to one of its own
globals (https://github.com/llvm/llvm-project/issues/57206).
Disables PluginCASTest.isMaterialized and the PluginCAS instantiation of
CASTest, both introduced in #213331, under HWASAN. This matches what
a0e402d41fad did for DynamicLibraryTest for the same underlying issue.
[BOLT] Skip data-hole filling unless data reordering is enabled
BinaryContext::postProcessSymbolTable unconditionally called
fixBinaryDataHoles(), which walks every allocatable section and, for
each gap in its address space, either grows a zero-sized data symbol
or creates a synthetic "HOLEat" BinaryData (plus an MCSymbol and
GlobalSymbols/BinaryDataMap entries). This machinery was introduced
(0e4d86bf, 2017) for one purpose: to give static data reordering
(-reorder-data) a movable object covering every byte of a section. It
has no other consumer.
On a large binary, these synthetic objects are live from
buildFunctionsCFG through the end of the run and, at the RSS peak
(during debug info rewriting), fixBinaryDataHoles accounted for 1669
MB (2.5%) of peak RSS -- memory spent entirely for a feature that is
off by default.
Gate fixBinaryDataHoles() (and the zero-sized-symbol validation loop
that presumes it ran) on a non-empty opts::ReorderData, keeping
generateSymbolHashes() unconditional.
[lldb] Download to a unique temporary path in the SymStore locator (#214632)
The download path was derived only from the key and the PDB name, so two
lookups (from different threads) potentially raced the same file path.
Avoid this by creating using a unique suffix.
Assisted-by: Claude
[lldb] Report a corefile whose only image is a platform binary (#214634)
found_platform_binary was tested but never assigned, so the early return
it guards was dead and LoadCoreFileImages reported failure for a
corefile whose only image a Platform plugin had already taken care of.
The caller reads that as "no binary found in the metadata" and goes on
to scan low memory for a UUID that has no reason to be there.
While here, stop assuming the module has an object file before asking it
for its sections. A binary located by an external symbol server is
turned into a Module without checking that it parses, and
LoadBinaryInTarget guards the same dereference on the other branch.
Assisted-by: Claude
[lldb] Add AddressSpaceInfo and ProcessAddress utility classes (#206370)
This is part of larger effort to support address spaces in lldb
https://discourse.llvm.org/t/rfc-address-spaces-support-in-lldb/91222/
This PR introduces the definition of AddressSpace and ProcessAddress
classes, which are foundational for next PRs
Stack:
1. #206370 (this PR) - the classes
2. #214088 ProcessAddress adoption (NFC)
3. #214089 Generic address space support
[BOLT] Key GlobalSymbols on MCContext-owned names to reduce memory
BinaryContext::registerNameAtAddress registers every symbol name
twice. It first calls MCContext::getOrCreateSymbol(Name), which
interns the name in MCContext's symbol table (the MCSymbol owns the
string via its table entry). It then also stored the name in the
GlobalSymbols map, which was a StringMap<BinaryData *>. StringMap owns
its keys, so each global name was duplicated: one copy in MCContext
and a second copy in GlobalSymbols. Both grow with the number of
symbols and, for large binaries with long mangled names, this
duplication is a meaningful source of memory use during file
object discovery.
This change makes MCContext the single owner of these name strings and
have GlobalSymbols merely reference them. GlobalSymbols becomes a
DenseMap<StringRef, BinaryData *> keyed on the MCContext-owned name
(MCSymbol::getName() of the symbol just created/looked up). No string
is copied into the map: each entry is a fixed-size (StringRef,
pointer) pair regardless of name length. Lookups (getBinaryDataByName,
[10 lines not shown]