CodeGen: Read the exception model from the module flag
Module::getExceptionModel() now falls back to the triple's default
model instead of falling back to the TargetMachine.
The pass pipeline is built before the module is known, so schedule each
EH preparation pass when the target supports a model, and let the pass
check the module's model. Add TargetMachine::supportsExceptionModel so
the pass config can skip definitely irrelevant passes. SjLjEHPrepare is
now scheduled on every target with exception handling, and WinEHPrepare
only on COFF and Wasm targets. WinEHPrepare and WasmEHPrepare are
scheduled for Wasm by the base pass configs, replacing the WebAssembly
override.
This is almost the last step towards removing TargetOptions::ExceptionModel.
Co-authored-by: Claude Opus <noreply at anthropic.com>
[lldb] Rename common register metadata providers (#232566)
These files are not specific to POSIX. For example, Windows plugins use
these as RegisterInfoInterface while Darwin does not make use of these
even though it is a POSIX-compliant OS.
Update wineh-empty-seh-scope.ll for the Windows trap change
An unreachable that does not follow a call no longer traps, so the empty
function gets the generic zero-length function nop, as on X86.
AArch64: Move the Windows trap after noreturn calls into the AsmPrinter
With Windows unwind info, the unwinder finds the function or funclet
for a frame from its return address, so a call must not be the last
instruction of one.
This was hackily handled by overwriting TrapUnreachable in the
TargetMachine constructor which inserts traps after every
unreachable. X86 handles the same problem by padding calls in the
AsmPrinter, so do the same here: emit a trap only after a noreturn
call that would end a function or funclet. This addresses the FIXME
about eliding the trap when the next instruction is in the same
region, so noreturn calls in the middle of a function no longer get a
trap.
This removes one of the last obstacles to removing ExceptionModel from
TargetOptions.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[scudo] Avoid QuarantineBatch leak in GlobalQuarantineRecycleInvalidCount (#232905)
In GlobalQuarantineRecycleInvalidCount,
Quarantine.drainAndRecycle(&Cache, Cb)
dequeues B from Cache before hitting the CHECK failure on B->Count. On
platforms where death tests execute in a thread within the same address
space
(such as Fuchsia zxtest), Cache is already empty after
SCUDO_EXPECT_DEATH
returns, so deallocateCache(&Cache) fails to free B and triggers a
LeakSanitizer failure.
Deallocate B directly via Cb.deallocate(B) instead.
Attributor: Don't crash on indirect calls in AAInvariantLoadPointer (#231519)
AAInvariantLoadPointerCallSiteReturned assumed every call has a known
callee, and dereferenced the missing function of an indirect call. This
crashed on most of CTMark with -attributor-enable=full. Nothing is known
about the result of an indirect call, so give up on it.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[OpenMP][flang] Score unknown context selector properties by selector
Flang records an unknown property such as kind(bogus) or vendor(bogus)
as TraitProperty::invalid, which belongs to no selector. Under
match_any or match_none, where such a variant can still be selected,
the property therefore lost its selector's weight: kind(bogus) added
nothing, while an unmatched kind(gpu) adds 2^l. A score on a selector
that mixes known and unknown properties was also added twice, once for
the known property and once for invalid, and unknown properties in
different selectors shared a single score.
Add VariantMatchInfo::addUnknownTrait, which keeps the property
unmatched and records its selector and score, and score that selector
like any other. Use it in Flang. Clang drops unknown properties while
parsing and is unaffected.
Assisted-by: GitHub Copilot (Claude Opus 5.5)
[VPlan] Derive extend kind and types in canFoldOuterExtendIntoMul (NFC) (#232903)
Look up the inner extends from the operands of the mul instead of
passing the extend kind and source types separately. A non-extend RHS is
a constant that fits in the source type of the LHS.
Both callers already require the inner extends to have the same kind as
the outer extend, so using the inner kind does not change behavior.
[clang][Driver] Use the Windows ARM64 defaults for aarch64-unknown-uefi
Match the Windows ARM64 driver defaults for aarch64-unknown-uefi, which
follows the same ABI:
* char is signed, so do not pass -fno-signed-char,
* the frame chain must stay valid even when frame pointers are omitted,
so -fomit-frame-pointer yields -mframe-pointer=reserved rather than
none, as the backend reserves the frame pointer for UEFI as well.
Assisted-by: Claude
[clang] Add aarch64-unknown-uefi target
Add the aarch64-unknown-uefi target to clang, building on the backend
support added in the preceding patches. Like x86_64-unknown-uefi it
follows the Microsoft ABI conventions, matching the Windows ARM64 target
which is the only way EFI applications for AArch64 can be built with
Clang/LLVM today:
* add UEFIAArch64TargetInfo: LLP64 types, Microsoft C++ ABI, char*
based va_list and the Win64 calling convention kind,
* use the Windows AArch64 ABI info in CodeGen for UEFI,
* accept aarch64 for *-uefi triples in the driver.
The UEFI toolchain already handles the linker invocation (lld-link with
/subsystem:efi_application), so no further driver changes are needed.
Assisted-by: Claude
[AArch64] Apply the Windows SEH and CRT codegen constraints to UEFI
aarch64-unknown-uefi uses SEH unwind information and has no C runtime
library, so the remaining Windows specific codegen decisions that follow
from this apply to it too:
* do not align loops or basic blocks, since SEH unwind info generation
needs the exact function layout before alignment padding is inserted,
* sign return addresses with the B key by default and reject A key
signing, matching the pac_sign_lr unwind code used by the unwinder,
* do not lower wide shifts to libcalls at -Oz, as those helpers are not
available.
The corresponding Windows tests gain aarch64-unknown-uefi run lines and
the LLVM release notes announce the new target, which completes the
backend side of aarch64-unknown-uefi support.
Assisted-by: Claude
[AArch64] Classify global references on UEFI like Windows COFF
Apply the Windows COFF rules for global references to
aarch64-unknown-uefi, which produces the same PE/COFF images:
* classify dllimport and non-dso-local globals with MO_DLLIMPORT /
MO_COFFSTUB, so extern_weak symbols are referenced through a stub that
can be resolved to zero by the linker,
* keep the existing SelectionDAG, FastISel and GlobalISel handling of
calls and tail calls to extern_weak functions in sync with that,
* default to the PIC relocation model, so jump tables and other
references stay position independent in relocatable PE images,
* lower ifuncs on UEFI as COFF has no support for them.
The extern weak and jump table tests gain aarch64-unknown-uefi run lines.
Assisted-by: Claude
[AArch64] Use Windows style stack probing on UEFI
Like Windows, and like x86_64-unknown-uefi already does, probe large
stack frames and dynamic allocas through the __chkstk helper on
aarch64-unknown-uefi instead of the inline stack probe loop:
* make the __chkstk STACK_PROBE libcall available for AArch64 UEFI,
* select the Windows stack probe paths in frame lowering,
LowerDYNAMIC_STACKALLOC and the SME state buffer allocation, honouring
the "no-stack-arg-probe" attribute as on Windows,
* fall back from GlobalISel to SelectionDAG for dynamic allocas, as is
done for Windows, since the IRTranslator does not implement the probing.
The existing chkstk and alloca tests gain aarch64-unknown-uefi run lines.
Assisted-by: Claude
[AArch64] Reserve x18 as the platform register on UEFI
Both the Windows ARM64 ABI, which UEFI follows, and the firmware
ecosystem (EDK2 builds AArch64 with -ffixed-x18) treat x18 as a reserved
platform register. Reserve it by default for aarch64-unknown-uefi, as is
already done for Windows, Darwin, Android, Fuchsia and OHOS.
Assisted-by: Claude
[AArch64] Use the Windows ARM64 ABI for UEFI targets
UEFI follows the Windows ARM64 procedure call standard (the UEFI
specification defines AArch64 EFI images in terms of the Microsoft
toolchain, and that is how EDK2 and clang-built firmware are linked
today), and x86_64-unknown-uefi likewise uses the Win64 ABI. Introduce
AArch64Subtarget::isTargetUEFI() and isTargetWindowsOrUEFI() and use the
latter for the core ABI decisions that currently key off
isTargetWindows():
* the Win64 calling convention for C/Fast/Swift calls, including the
Windows variadic convention which homes all argument registers and
passes floating point variadic arguments in GPRs,
* the char* based va_list (va_copy size and getVaListSizeInBits),
* the Windows callee saved register list and the matching frame record
pairing rules in AArch64FrameLowering, which have to agree so that the
SEH save_regp/save_fplr unwind codes describe consecutive registers,
* the requirement that the frame chain stays valid in every function.
[11 lines not shown]
[AArch64] Use the Microsoft COFF MCAsmInfo for UEFI targets
UEFI follows the MSVC toolchain conventions and lld-link is used to
produce the PE/COFF images, so aarch64-unknown-uefi should use the
Microsoft COFF MCAsmInfo like the X86 backend already does for
x86_64-unknown-uefi, rather than the GNU (MinGW) flavour it currently
gets by virtue of being a non-MSVC COFF triple. This enables associative
COMDATs and COMDAT constant pool entries (which AsmPrinter already
expects for UEFI, see GetCPISymbol).
Also relax the AArch64MCInstLower assertion that only Windows COFF
targets exist.
This is the first in a series of patches adding aarch64-unknown-uefi
support to the AArch64 backend and clang.
Assisted-by: Claude
[CodeGen][NVPTXISelLowering] Fix missing lowering of smul_lohi and umul_lohi (#230234)
NVPTX ISelLowering was missing legalization rules for i16/i32 umul_lohi
and smul_lohi. This would cause codegen failure when the combiner was
disabled as they are not legal in ptx. Adds custom lowering to mul.wide.
Adds a test with combiner disabled.
[libc++] Disable automatic module scanning on ARM CI builders
The ARM Buildkite toolchains do not expose clang-scan-deps to CMake.
When CMP0155 enables automatic scanning for libc++abi C++23 sources,
these standalone runtimes builds fail with the scanner set to NOTFOUND.
Pass CMAKE_CXX_SCAN_FOR_MODULES=OFF in the eight ARM job invocations,
including the no-exceptions variants, until their toolchains provide a
matching scanner. Keep the other CI configurations on their defaults.
Validated bash syntax, git diff --check, and argument dispatch for all
eight ARM jobs with generic C++20, C++23, and modules jobs as controls.
Assisted-by: Codex
[mlir][DLTI] Introduce an operation interface for scoped DLTI queries (#232733)
So far, DLTI queries have relied on scanning discardable attributes for
values implementing DLTIQueryInterface. This is problematic when that
data is used to determine operation semantics: semantic information
belongs in an operation's inherent attributes/properties, and should
have an explicit contract rather than depend on arbitrary discardable
attribute attachments.
Introduce DLTIQueryOpInterface, an OpInterface instead of the existing
AttributeInterface, with symmetric queryDlti and setDlti methods for
individual keys. Provide default implementations backed by an inherent
dlti attribute. Updates preserve unrelated map entries, a null value
removes a key, and attempts to mutate non-map representations fail.
Resolve the first query key by walking the operation and its ancestors
that implement the new interface, continuing upward when a scope cannot
answer that key. Resolve subsequent keys recursively through the
returned attribute's DLTIQueryInterface without restarting the ancestor
[27 lines not shown]
[X86] LowerFunnelShift - handle fsh*(x,y,0) case (#232923)
Normally DAGCombine handles this, but we might end up with an all-zero shift amount during legalization (via splitting etc.)
Fixes #232596
[DAGCombiner] Allow (sub 0, (max X, (sub 0, X))) --> (min X, (sub 0, X)) when neither min/max are legal/custom. (#232486)
If the max isn't legal/custom and the min isn't legal/custom it really
doesn't matter if we keep the max. They'll be expanded very similarly
with different condition codes on the select/branch. Might as well
remove the neg.
Note this code really should take type legalization promotion into
account, but that's a separate problem.
[flang][OpenMP] Match variant selectors in the source construct context
The construct context for METADIRECTIVE and DECLARE VARIANT came from
enclosing MLIR operations. It recognized only a few operations, followed
operation nesting instead of source nesting, kept constructs outside an
enclosing TARGET, and used the body context for clause expressions and
loop bounds.
Build the context from the evaluation's source ancestors and from frames
for construct regions entered during lowering:
- A selected METADIRECTIVE replacement stands in for its source construct.
- TARGET discards the outer context.
- Constructs without a selector property still add a nesting level.
- Clause expressions see only enclosing constructs.
- Loop bounds see the leaves that precede the first loop-associated leaf.
- Specification expressions see no construct.
Add llvm::omp::getConstructTraits, which returns the construct traits a
directive adds in source order, with an invalid placeholder for a
[10 lines not shown]
[SelectionDAG][RISCV] Use SExtOrZExtPromotedOperands to promote ABDU in PromoteIntegerResult. (#232037)
Similar to UMIN/UMAX, ABDU can be promoted using sext or zext. Use to
SExtOrZExtPromotedOperands to pick whatever is profitable for the
target. For RISC-V, this means we can use sext.w instead of pair of
shifts.
This covers part of what #231881 was trying to do.
[RISCV][P-ext] Use concat_vectors with 0 in widenPackedVectorWithZeros.
This will be legalized and combined to a vector_shuffle. That
shuffle can then be matched to a pack with x0 after #232892.
This changes the zext.w to a pack, but that's not obviously worse.
If we need to canonicalize we can add a DAG combine later.