[lldb] Extract ExternalSymbolResolver from IRExecutionUnit (#241136)
IRExecutionUnit::FindSymbol finds the load addresses of symbols that an
expression refers to but does not define. Despite living on the
execution unit, it is not specific to JIT compilation. It has three
callers: IRForTarget, to rewrite Objective-C constant strings and
selectors; the IR interpreter, to resolve function constants; and the
MCJIT memory manager, to resolve external symbols while linking. The
interpreter uses it even when nothing is JIT compiled.
Move FindSymbol, its five helpers, the file-local LoadAddressResolver
and ResolveFunctionCallLabel, and the state they use (m_sym_ctx,
m_preferred_modules and m_strip_underscore) into a new
ExternalSymbolResolver class. IRExecutionUnit owns one and forwards
FindSymbol and AppendPreferredSymbolContexts to it, so no callers
change.
m_failed_lookups and ReportSymbolLookupError stay on IRExecutionUnit.
They are not part of resolution: each caller decides how to handle a
[11 lines not shown]
[flang] Fix the memcpy function type model for MinGW-w64 (#233251)
`RTBuilder.h` needs a `getModel` specialization for the runtime's
`MemcpyFct` type, `void *(*)(void *, const void *, std::size_t)`, that
matches `std::size_t`. On 64-bit Windows `std::size_t` is `unsigned long
long`, but that specialization was guarded by `_MSC_VER`, so building
flang for MinGW-w64 (windows-gnu) failed to link:
```
ld.lld: error: undefined symbol: mlir::Type (*fir::runtime::getModel<void* (*)(void*, void const*, unsigned long long)>())(mlir::MLIRContext*)
```
Guard it by `_WIN32`, which MSVC, clang-cl and MinGW-w64 all define, and
spell the size parameter `std::uint64_t` instead of the MSVC-only
`unsigned __int64`. On 64-bit Windows `std::uint64_t` is `unsigned long
long`, the same type as `std::size_t` and as `unsigned __int64` under
MSVC, so it still matches `MemcpyFct` while making the 64-bit width
explicit. It has to be unsigned: `std::int64_t` would not match
`std::size_t` on any Windows target. MSVC and non-Windows builds are
[5 lines not shown]
[lldb] Add symbol table state flags, add accessors. (#239451)
A Module's Symtab may be constructed from a DataFileCache symtab, or
from the ObjectFile binary itself. If we have a report of incorrect lldb
behavior from an end user, we may need to know which was the source of
the symbol table via lldb commands or via SB API.
This adds a bitfield `m_state` to Symtab, with getters and setters for
the currently existing fields (set-from-symtab-cache,
set-from-objectfile). It exposes the lldb-enumerations bits via
SBModule. It has `statistics dump` also print if a symtab was
constructed from an object file (it currently only notes if a symtab was
constructed from a DataFileCache symtab file). It adds an option to
`image list`, `-F/--symtab-state-flags` which will show letters for each
bit that is set for the symbol table.
```
(lldb) help image list
-F[<width>] ( --symtab-state-flags=[<width>] )
[33 lines not shown]
AMDGPU: Use ArgRange for builtin constant argument range checks
Replace the manual Sema range checks of constant builtin arguments
with the new ArgRange annotation on the builtin definitions.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
clang/AMDGPU: Check constant argument ranges of builtins
These builtins take a constant argument that the IR verifier range
checks on the corresponding intrinsic. Sema didn't enforce this, so
you could write code that failed the IR verifier. Use the new Range
annotation on the builtins to fix this.
This only covers builtins that previously had no range validation at
all. Builtins already checked by the manual switch in SemaAMDGPU will
be converted separately.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
clang: Add ArgRange builtin attribute for constant argument ranges
Many target builtins take constant arguments that must be in a
specific range. These usually correspond directly to the Range
annotation on the IR intrinsic, which the verifier enforces. Today
this requires manual verification with a large builtin ID switch in
Sema, and missed cases will emit code that fails the IR verifier.
Add an ArgRange<Index, Lo, Hi> builtin attribute declaring that a
_Constant argument must be in the half-open range [Lo, Hi), the same
as the IR declaration.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[LoongArch] Support memcmp expansion for vectors and combine for i128/i256 setcc
This commit enables memcmp expansion for lsx/lasx. After doing
this, i128 and i256 loads which are illegal types on LoongArch
will be generated. Without process, they will be splited to
legal scalar type.
So this commit also enable combination for `setcc` to bitcast
i128/i256 types to vector types before type legalization and
generate vector instructions.
Inspired by x86 and riscv.
[InstCombine] Handle commuted operands in (X|C) | V --> (X|V) | C (#241105)
The fold in visitOr only matched the inner `or X, C` as operand 0.
getComplexity() does not order two non-constant instruction/argument
operands, so `V | (X|C)` was left alone even though it is equivalent.
Use m_c_Or so both operand orders are matched; flags handling is
unchanged.
Assisted-by: GPT 6.1 Sol, Opus 5.5
[AMDGPU] Enable GEP canonicalization for dynamic LDS table lookups (#241396)
Use the default IRBuilder GEP canonicalization in
AMDGPULowerModuleLDSPass and update the checks.
Assisted by: GPT 6.1-Sol
Follow up to: https://github.com/llvm/llvm-project/pull/240885
RuntimeLibcalls: Mark noreturn and pure helper libcalls
Mark the functions which never return as noreturn. Add some nounwind
and cold, mostly following inferLibFuncAttributes. Mark
misc. functions as pure.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add attributes inferLibFuncAttributes gives libcalls
Remove more differences with the attributes the InferFunctionAttrs
pass would add to the declared libcalls.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add signatures for the Darwin sincos stret functions
__sincos_stret and __sincosf_stret return a struct holding the 2
results. Describe the C struct return type in the signature table and
lower for the target ABI. This is a vector on x86-64 for float,
through memory on x86-32 and APCS ARM, and as a struct elsewhere.
This replaces the special case that built the types in C++. Ideally we
would be using the ABI library, but it's incomplete for most targets
and it requires some relayering to use here.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Attributor: Collect the values only used by assumes on demand (#241459)
initializeInformationCache tracked the uses of the operands of every
llvm.assume to find the values only used by assumes, but only a few
abstract attributes and OpenMPOpt ask for them, none of which run in
attributor-light. Collect them for a function when they are first asked
for.
Instruction counts (callgrind) of the light passes in the ThinLTO
backend of tramp3d-v4: -5.8%.
CTMark (-attributor-enable=light): O3 -0.03%, ThinLTO -0.02%.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[AMDGPU] Enable GEP canonicalization in ctor/dtor lowering (#241309)
Use the default IRBuilder GEP canonicalization and regenerate the
constructor and destructor lowering checks. Callback array traversal
uses byte offsets of 8 and -8, with unchanged generated code.
Assisted by: GPT 6.1 Sol
Follow up to: https://github.com/llvm/llvm-project/pull/240885
RuntimeLibcalls: Add attributes inferLibFuncAttributes gives libcalls
Remove more differences with the attributes the InferFunctionAttrs
pass would add to the declared libcalls.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[LLD][LTO] Release bitcode pages earlier in distributed ThinLTO (#241536)
Under --thinlto-index-only, LLD calls markBuffersAsDontNeed() after the
lto->add() loop to MADV_DONTNEED mmap'd inputs. Two issues remain:
1. Bitcode pages stay resident across the entire lto->add() loop,
peaking alongside the growing ThinLTO summary index.
2. With split LTO units (-fsplit-lto-unit, e.g. CFI), regular LTO
modules with summaries are deferred until LTO::runRegularLTO(),
re-faulting their pages into RSS for the rest of the thin link.
Evict standalone bitcode buffers incrementally after each lto->add()
call
when skipLinkedOutput is set, clear RegularLTO.ModsWithSummaries once
linked, and add lto::Config::PostRegularLTOLinkHook so LLD can call
markBuffersAsDontNeed() again before running the LTO/ThinLTO backends.
Assisted-by: Gemini