[Clang][CFI] Emit llvm.type.checked.load for non-trapping cfi-vcall (#241647)
With `-fwhole-program-vtables`, trapping `cfi-vcall` emits
`llvm.type.checked.load`, which `WholeProgramDevirt` uses to
devirtualize calls. Non-trapping modes (full runtime, minimal runtime,
cross-DSO) emitted `llvm.type.test` without `llvm.assume` instead, so
their virtual calls were never devirtualized.
The performance gap between trapping and minimal-runtime CFI was
usually blamed on returning vs. noreturn failure handlers. It turned out
that missing devirtualization is a large part of it. With this change,
some benchmarks run about 10% faster with minimal-runtime CFI, close to
trapping CFI.
Emit `llvm.type.checked.load` for all `cfi-vcall` modes on classes with
hidden LTO visibility. Failed checks are reported the same way as
before, through `EmitVTableCheck`.
As with trapping CFI, when `WholeProgramDevirt` devirtualizes a call it
[4 lines not shown]
[compiler-rt][test] XFAIL suppressions-darwin.cpp on 27.0-27.2 iOS sims (#243975)
Certain calls from the simulator shared cache (e.g. to
memcpy/memcmp/strlen) are not interposable on 27.0-27.2 simulators, so
ASan cannot intercept them and this test fails.
Assisted-By: Claude
rdar://193139172
[VPlan] Remove dead ScalableLast handling in cloneForLane (NFC). (#244025)
Both callers pass VPLane(I), which is always Kind::First, so the
ScalableLast branch is dead since 1efa997317b7.
[Flang][OpenMP] Enable implicit mapping of allocatables inside derived types for enter/exit/update (#224145)
Currently we only allow mapper emission for implicit maps and explicit
target region maps, this PR extends it to support enter/exit/update by
removing the inhibitor we had on it, now that we can handle this type of
mapping.
[clang] Diagnose VLA types from an enclosing function in local classes and blocks (#229697)
A variably modified type whose array bound is evaluated in an enclosing
function cannot be used in a member function of a local class or in a
block: the size is only computed in the enclosing function, so CodeGen
crashed when emitting such a declaration.
Record the context in which each VLA bound is evaluated, and diagnose
uses of such a type (variable, parameter and typedef declarations,
casts, sizeof) across a local class or block boundary:
```
error: variably modified type 'X' (aka 'int[foo()]') cannot be used in a local class because its size is evaluated in an enclosing function
note: size expression is evaluated here
```
Such a declaration is now rejected even in a member function that is
never used, the same way a reference to a local variable of the
enclosing function already is.
[12 lines not shown]
[flang][OpenACC] Map OPTIONAL operands through their descriptor (#243141)
OPTIONAL data operands used to be mapped through their raw address,
which dropped the descriptor. Keep the descriptor unless the base is
neither an acc PointerLikeType nor a MappableType (e.g. a `fir.boxchar`
for `CHARACTER(*)`).
When remapping an OPTIONAL symbol in a compute region, replace the TODO
with a fir.box_addr guarded by `fir.is_present`, so an absent argument's
null descriptor is never read.
[Clang][Parse] Do not treat '::' as a decl-specifier outside C++
isCXXDeclarationSpecifier's '::' case annotates the token and then recurses to
handle whatever it got, which only makes progress when the token can actually be
annotated as a scope specifier. Outside C++ it cannot be, so in C the recursion
never advanced and the stack overflowed:
void f() { if (::0); }
Since 226b0b59bfca ([Clang][C2y] Add support for if declarations (N3356
paper)) C parses conditions through ParseCondition, so C conditions now reach
this code. Parser::isDeclarationSpecifier already guards the same case; this
adds the matching guard to its C++ twin. Objective-C is unaffected: it keeps
diagnosing '::' through TryAnnotateTypeOrScopeToken.
Fixes #243727.
[Attributor] Preserve debug locations when replacing indirect calls (#244004)
When an indirect call and its known callee have incompatible return
types, Attributor creates a replacement call without copying the
original debug location.
Copy the debug location in both the single-callee and multiple-callee
paths.
Assisted by gpt-6.1.
[libc] Fix fileno() to return EBADF for non-Linux File streams (#227760)
## Summary
`fileno()` currently assumes every `FILE*` is backed by a `LinuxFile`
and unconditionally casts to read its file descriptor. For streams
created by `fopencookie()` or `fmemopen()` (backed by
`CookieFile`/`MemoryFile`, neither of which has a file descriptor
member), this reads unrelated memory and returns a bogus "descriptor"
instead of following POSIX, which requires `fileno()` to fail with
`EBADF` when "the stream is not associated with a file."
## Fix
`File` has no RTTI/type tag by design (some `LinuxFile` instances, e.g.
`stdin`/`stdout`/`stderr`, are `constexpr` globals). Instead of adding
one, this adds `is_linux_file()`, which positively identifies a
`LinuxFile` by checking that all four of its registered I/O callbacks
(`read`/`write`/`seek`/`close`) are the known `linux_file_*` functions —
every `LinuxFile` always registers exactly these, and no other `File`
subclass does. `get_fileno()` now checks this first and returns `-1`
[17 lines not shown]
[DAGISel] Add OPC_SwitchChildInteger to dispatch on an integer child (#237647)
When every option of a Scope starts with a CheckChildInteger of the same
child, convert it to a switch like SwitchOpcode/SwitchType. This is
common for INTRINSIC_WO_CHAIN, where each pattern starts by checking the
intrinsic ID in child 0.
This still requires a linear scan to find the matching intrinsic ID, but
may reduce some repeated overhead.
Assisted-by: Claude
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
TableGen: Compute DAGISel pattern sort keys before sorting (#244009)
The pattern sort recomputed each pattern's complexity, cost and size on
every comparison. Compute them once per pattern instead.
RISCVGenDAGISel.inc tablegen run:
Gigainstructions Gigacycles CPU seconds
Before 61.5 31.4 9.8
After 57.1 (-7.1%) 27.8 (-11.4%) 8.7 (-10.9%)
AMDGPUGenDAGISel.inc tablegen run:
Gigainstructions Gigacycles CPU seconds
Before 94.6 46.1 14.3
After 91.4 (-3.4%) 44.6 (-3.3%) 13.9 (-3.1%)
All 376 tablegen runs in an LLVM build with all targets:
[4 lines not shown]
[DebugInfo][AT] Retire dead LiveIn/LiveOut state and avoid redundant RPO queuing (#234310)
AssignmentTrackingLowering and MemLocFragmentFill previously
pre-reserved and retained LiveIn/LiveOut maps for every block across the
entire pass, and re-queued forward RPO successors onto Pending even when
already scheduled on Worklist, scaling as O(Blocks * Vars).
Add BlockLivenessTracker and worklist helpers to:
- Skip storing LiveIn for acyclic blocks (unreachable from backedges),
moving a single predecessor's LiveOut when it has no other readers.
- Track remaining successor reads to erase dead predecessor LiveOut
entries eagerly, and clear LiveIn/LiveOut after traversal.
- Avoid queuing forward RPO successors (SuccRPO > RPO) already scheduled
on Worklist.
On a pathological case from glslang/SPIRV (9,049 blocks, 7,540
variables, 0 backedges; `llc -O2`):
- Peak RSS: 17.37 GB -> 354.5 MB (~49x reduction)
- Total `llc` wall time: 15.84s -> 4.97s (-68.6%)
[3 lines not shown]
[libc] Fix syscall under ASAN (#244038)
Followup to #243647 which broke the ASAN bot. Just mark the va_args
reads as ignored by the sanitizer.
Assisted-by: Automated tooling, human reviewed.
[clang] Shrink inline capacities of `Module` unresolved directives (#243156)
`Module` stores the module map directives that haven't been resolved yet
(`UnresolvedHeaders`, `UnresolvedExports`, `UnresolvedDirectUses`,
`UnresolvedConflicts`) and the headers that couldn't be found
(`MissingHeaders`) inline, with room for one or two elements each. These
lists are empty in modules deserialized from PCMs, and in modules parsed
from a module map usually only the unresolved exports (typically a
single `export *`) are non-empty. The dependency scanner creates a lot
of modules, so the inline storage adds up.
This patch drops the inline capacity of these lists:
- `UnresolvedHeaders`, `MissingHeaders`, `UnresolvedDirectUses`:
`SmallVector<T, 1/2>` -> `SmallVector<T, 0>`
- `UnresolvedExports`: `SmallVector<T, 2>` -> `SmallVector<T, 1>`, so
the common single `export *` still doesn't allocate
- `UnresolvedConflicts`: `std::vector<T>` (24 bytes) -> `SmallVector<T,
0>` (16 bytes)
[30 lines not shown]
CodeGen: Document best practices on target hooks (#243984)
Document that this is not a place to put controls for specific
transformations. This is a plea to agents to stop producing
fix-this-one-case or target virtual methods.
[Offload][NFC] Move plugin namespaces to llvm::offload and update include guards
Replace libomptarget namespaces and header guards with liboffload equivalents.
Mostly mechanical work by Claude.
Revert "[CodeGen][NFC] Factor MachineBlockPlacement::alignBlocks into reusable helper (#241995)" (#243994)
This reverts commit 6447d4dda5706f5d7946f86c1225fd964abfb39e (#241995)
at a reviewer's request while concerns about the change are addressed.
[Offload][Omp] Ensure correct teardown order
Use the new Offload API to ensure a proper libomptarget teardown
in case the process exits before reaching its `deinit` method.
Depending on different circumstances whether the shutdown happens
through `deinit` or through the liboffload `callback` everything
must be properly protected and allowed to be called safely multiple
times.
Assisted by Claude.
[Offload] Add shutdown callbacks to liboffload (#239628)
When Platforms are initialized liboffload sets an atexit handler that
ensures that is deinitialized before deinitialazing platforms.
Because this happens lazily, a library using offload that wants to
run some of its shutdown needs to properly setup its atexit handler
after the liboffload one (because they're called in reverse order).
This requires to know precisely the internal implementation of
liboffload.
Instead of requiring that, this PR adds an API that allows the users
of liboffload to register their own deinit code and be assured that it
will
be called before liboffload shutdowns independently of when platforms
are initialized.
Assisted by Claude.
[4 lines not shown]
[mlir][vector] Dispatch contraction lowering on iterator type (NFC) (#231337)
`ContractionOpLowering` chose between `lowerParallel` and
`lowerReduction` based on whether a dimension was contracting. Every
non-contracting dimension went to `lowerParallel`, which is what made
its name misleading, as noted in #228971 and #229824.
With this PR we dispatch on the iterator type instead:
* parallel dimensions go to `lowerParallel`, which no longer accepts an
iterator missing from the result map. It fails to match instead of
tolerating it.
* contracting dimensions go to `lowerReduction`, which now takes the LHS
and RHS indices of the dimension to lower instead of always using
iterator 0.
To honor what has been documented in #230458, this PR adds
`ContractionOp::getFreeDimMap` next to the existing batch and
contracting maps.
[8 lines not shown]
[clang][DebugInfo] Emit local types in their lexical block scopes (#242447)
With the background support of
https://github.com/llvm/llvm-project/pull/165032 in place, emit debug
info nodes for local types in their corresponding DILexicalBlock scopes.
This allows debug info consumers to distinguish between local types with
the same name declared in different lexical blocks. It is now done only
with `-debugger-tuning=gdb`, as lldb does not provide full support for
local types in lexical block scopes
(https://github.com/llvm/llvm-project/issues/54475).
Authored-by: Kristina Bessonova <kbessonova at accesssoftek.com>
[Offload][NFC] Move plugin namespaces to llvm::offload and update include guards
Replace libomptarget namespaces and header guards with liboffload equivalents.
Mostly mechanical work by Claude.
[Offload][NFC] Move plugins under liboffload (#242364)
Liboffload is the only library calling the plugins directly now, so move
the code inside it to reflect this change.
Also, adjust the CMake targets to also reflect this change by moving
from omptarget prefixes to LLVMOffload ones.
Assisted by Claude.
---
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>