[clangd] Extend FeatureModule hooks (#221054)
Feature modules may need to participate at points in AST construction
that `beforeExecute()` and `sawDiagnostic()` cannot represent.
This PR adds:
- `beforePPCallbacks()` for installing preprocessing observers before
clangd starts collecting include and macro events.
- `afterExecute()` for work that needs a completed AST after token
collection and traversal-scope restriction.
- `finalizeDiagnostic()` for transformations that need the complete
diagnostic, including its notes and fixes.
For example, clang-tidy needs to register preprocessing callbacks before
preamble events are replayed, run AST matchers after clangd restricts
the traversal scope, and process diagnostics after their notes and fixes
are attached.
These changes prepare moving the clang-tidy implementation into a
[2 lines not shown]
[Clang] Do not apply inaccessiblememonly to ::operator new() (#224316)
Do not apply `memory(inaccessiblemem: readwrite, errnomem: write)` to
`::operator new()` style calls (as opposed to `new T`). This matches the
cases where we mark the call as `builtin`, i.e. we only consider it
inaccessiblememonly in the cases where the allocation is also elidable.
I've left the old `noalias` handling alone, so that part keeps being
applied to `::operator new()` as before. Let me know if I should move
that to EmitNewDeleteCall() as well.
DAG: Handle load in SimplifyDemandedVectorElts
This improves some AMDGPU cases and avoids future regressions.
The combiner likes to form shuffles for cases where an extract_vector_elt
would do perfectly well, and this recovers some of the regressions from
losing load narrowing.
AMDGPU, Arch64 and RISCV test changes look broadly better. Other targets have
some improvements, but mostly regressions. In particular X86 looks much
worse. I'm guessing this is because it's shouldReduceLoadWidth is wrong.
I mostly just regenerated the checks. I assume some set of them should
switch to use volatile loads to defeat the optimization.
[SystemZ] Try to align globals to at least 2 bytes (#224586)
s390x has a minimum ABI alignment of 2 for globals. However, private
globals introduced by optimizations (including directly in the frontend
in the case of promotion of large const variables) are not required to
respect this ABI alignment. To avoid having to go through GOT to load an
unaligned addressed, we should try to raise the alignment of such
globals in the backend. This is done through a new SystemZ-specific
module pass.
[Clang][OpenMP][NFC] Use `getLimitedValue` for loop transform counts (#224940)
Use `getLimitedValue()` when reading integer counts for `unroll, split,
interchange, fuse` transforms.
It avoids direct `getZExtValue()` calls and follows the existing OpenMP
count handling style.
[Clang][OpenMP] NFC: Eliminate `Create/CreateEmpty` for scalar clause (#224935)
Use a normal constructor when the clause has a fixed size.
Keep `Create/CreateEmpty` only when the object needs extra tail storage.
Covers: `looprange, full, partial, bind, depobj, align`
[CIR] Read a non-byval parameter back out of its spill slot
CallConvLowering recognizes a forwarded non-byval indirect argument by the slot
its operand was loaded from. At -O1 and above cir-simplify folds that load
away when the slot is a constant alloca, which is what CIRGen emits for a
const-qualified by-value parameter. The walk that gives each such parameter's
slot the alignment the ABI promises now also reads the record back out of the
slot at the spill and points the parameter's call-argument uses at that load,
so an Expand, byval or coerced argument reads it too.
Assisted-by: Cursor / claude-opus-5
[Support] Remove cl::Sink (#224953)
Nothing uses it: the last users, clang's offloading linker wrappers,
moved to OptTable. The feature would block migration to TableGen based
representation. An unknown option is now always an error.
LLM-aided
[AMDGPU][InstCombine] Fold zero dot operands to accumulator
Fold AMDGPU dot intrinsics when either operand is zero.
`dot(a, 0) = 0` and `dot(0, b) = 0`, so replace the intrinsic with its accumulator.
This avoids unrelated clamp and add/sub reassociation cases.
[AMDGPU][InstCombine] Fold constant add/sub into the dot accumulator
`amdgcn.{s,u}dot{2,4,8}(a, b, C) +/- K -> dot(a, b, C +/- K)` when both the
accumulator C and K are constants. The new constant is computed with
wrapping APInt arithmetic to match the non-clamping accumulate.
Only applies when clamp is false (the saturating accumulate does not
reassociate) and the dot has a single use. K - dot is left alone since it
would need the dot product negated.
[AMDGPU][InstCombine] Fold zero dot operands to accumulator
Fold AMDGPU dot intrinsics when either operand is zero.
`dot(a, 0) = 0` and `dot(0, b) = 0`, so replace the intrinsic with its accumulator.
This avoids unrelated clamp and add/sub reassociation cases.
[AMDGPU][InstCombine] Fold constant add/sub into the dot accumulator
`amdgcn.{s,u}dot{2,4,8}(a, b, C) +/- K -> dot(a, b, C +/- K)` when both the
accumulator C and K are constants. The new constant is computed with
wrapping APInt arithmetic to match the non-clamping accumulate.
Only applies when clamp is false (the saturating accumulate does not
reassociate) and the dot has a single use. K - dot is left alone since it
would need the dot product negated.
[flang][cuda] Record implicit managed attribution in module files
An attribute the compiler applied under -gpu=mem:managed is written into the
module file the same way a user-written one is, so a reader cannot tell them
apart. It then treats the attribute as a user requirement: allocating such a
component in a DEVICE object is rejected, and the memory space the user did
ask for on the object no longer wins.
Spell the distinction in the module file as MANAGED(IMPLICIT), modelled on
INTENT(IN): CUDA-data-attr gains an optional parenthesized qualifier, carried
by a new CUDADataAttrSpec parse-tree node in AttrSpec and ComponentAttrSpec.
ATTRIBUTES(...) keeps the bare attribute, so the qualifier cannot be written
there.
The attribute itself is still written out, so a component keeps the same
memory space no matter which options a consumer is compiled with.
Also stop an implicitly applied attribute from making a module a definer of
CUDA symbols. Without this, adding -gpu=mem:managed to a module's build
rejects its OpenACC-only consumers over an attribute the user never wrote.
[flang][cuda] Implicitly attribute ALLOCATABLE/POINTER components as managed (#223087)
Under `-gpu=mem:managed`, `resolve-names` implicitly attributes
allocatables and
pointers declared in an ordinary scope as managed.
Apply the same attribution to components in `Post(ComponentDecl)`. An
explicitly
attributed component keeps its own attribute, and a translation unit
without
CUDA Fortran enabled is left alone.
[SandboxVec][LoadStoreVec] Support mixed type vectorization of loads
vectorizeLoads() bailed out unless every load in the chain had the same
element type. Vectorize mixed-type chains too: the chain is loaded with a
single vector load of its combined vector type, whose element type is an
integer when the types differ, and each lane is reinterpreted as the type of
the load it replaces. A load wider than one lane, e.g. a double in a
<N x i32>, spans several lanes and is unpacked with a shuffle.
Lanes are counted in bits rather than elements, since with mixed types a lane
no longer corresponds to one load. Chains whose loads do not cover a whole
number of lanes, or that involve non-integral pointers, are left alone.
Assisted by Claude Opus 5