532342 Commits

Author SHA1 Message Date
Orlando Cazalet-Hyams
e2d5b6ee48 [KeyInstr][SimplifyCFG] Remap atoms after duplication for threading
Given the same branch condition in `a` and `c` SimplifyCFG converts:

      +> b -+
      |     v
  --> a --> c --> e -->
            |     ^
            +> d -+

into:

      +--> bcd ---+
      |           v
  --> a --> c --> e -->

Remap source atoms on instructions duplicated from `c` into `bcd`.
2025-03-28 17:07:04 +00:00
Orlando Cazalet-Hyams
b848c42133 [KeyInstr][debugify] Add --debugify-atoms to add key instructions metadata 2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
eeb24e30bb [KeyInstr][SimplifyCFG] Remap atoms when folding br to common succ into pred
SimplifyCFG folds `b` into `a`.

            +-----------+
            |           v
  --> a --> b --> c --> d -->
      |                 ^
      +-----------------+

Remap source atoms in `b` so that the duplicated instructions are analysed
independently to determine is_stmt positions. This is necessary as the
contents of `b` may be folded into multiple preds in this way.

Add multi-pred test.
2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
a6f7a923dd [KeyInstr] Inline atom info
Source atom groups are identified by an atom group number and inlined-at pair,
so we simply can copy the atom numbers into the caller when inlining.
2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
0335154ef8 [KeyInstr] Merge atoms in DILocation::getMergedLocation
NFC for builds with LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS=OFF (default).

In an ideal world we would be able to track that the merged location is used in
multiple source atoms. We can't do this though, so instead we arbitrarily but
deterministically pick one.

In cases where the InlinedAt field is unchanged we keep the atom with the
lowest non-zero rank (highest precedence). If the ranks are equal we choose
the smaller non-zero group number (arbitrary choice).

In cases where the InlinedAt field is adjusted we generate a new atom group.
Keeping the group wouldn't make sense (a source atom is identified by the
group number and InlinedAt pair) but discarding the atom info could result
in missed is_stmts.

Add unittest in MetadataTest.cpp.
2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
07f9c1f2f8 [NFC][KeyInstr] Add Atom Group (re)mapping
Add:
   mapAtomInstance - map the atom group number to a new group.
   RemapSourceAtom - apply the mapped atom group number to this instruction.

Modify:
  CloneBasicBlock - Call mapAtomInstance on cloned instruction's DebugLocs
                    if MapAtoms is true (default). Setting to false could
		    lead to a degraded debugging experience. See code comment.

Optimisations like loop unroll that duplicate instructions need to remap source
atom groups so that each duplicated source construct instance is considered
distinct when determining is_stmt locations.

This commit adds the remapping functionality and a unittest.
2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
d12e993d5e [KeyInstr] Add Atom Group waterline to LLVMContext
The waterline is managed through DILocation creation,
LLVMContext::incNextAtomGroup, and LLVMContext::updateAtomGroupWaterline.

Add unittest.
2025-03-28 17:07:03 +00:00
Orlando Cazalet-Hyams
a124bd2afc [KeyInstr] Add fields to DILocation behind compile time flag
The definition EXPERIMENTAL_KEY_INSTRUCTIONS is controlled by cmake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS.

Add IR read-write roundtrip test in a directory that is unsupported unless
the CMake flag is enabled.
2025-03-28 17:07:03 +00:00
Matt Arsenault
133c1afa8e
llvm-reduce: Filter function based on uses before removing arguments (#133412)
Invokes and others are not handled, so this was leaving broken callsites
behind for anything other than CallInst
2025-03-29 00:01:14 +07:00
Matt Arsenault
44e3735ac1
llvm-reduce: Preserve original callsite calling conv when removing arguments (#133411)
In undefined mismatch cases, this was fixing the callsite to use the calling
convention of the new function. Preserve the original wrong callsite's calling
convention.
2025-03-28 23:51:09 +07:00
LU-JOHN
827f2ad643
AMDGPU: Convert vector 64-bit shl to 32-bit if shift amt >= 32 (#132964)
Convert vector 64-bit shl to 32-bit if shift amt is known to be >= 32.

---------

Signed-off-by: John Lu <John.Lu@amd.com>
2025-03-28 23:46:35 +07:00
Matt Arsenault
6b1acdb818
llvm-reduce: Fix losing operand bundles when removing arguments (#133410) 2025-03-28 23:41:47 +07:00
Jan Svoboda
277ab85d1c [clang] Make PreprocessorOptions reference const 2025-03-28 09:34:19 -07:00
Matt Arsenault
115a77df9d
llvm-reduce: Fix losing metadata when removing arguments (#133409) 2025-03-28 23:28:03 +07:00
Matt Arsenault
688df34634
llvm-reduce: Fix losing fast math flags when removing arguments (#133408) 2025-03-28 23:24:49 +07:00
Matt Arsenault
1b86867ab3
llvm-reduce: Fix losing callsite attributes when removing arguments (#133407)
The attribute APIs make this cumbersome. There seem to be missing
overloads using AttrBuilder for the function attrs. Plus there doesn't
seem to be a direct way to set the function attrs on the call.
2025-03-28 23:20:56 +07:00
Jonas Devlieghere
ea8573aca5
[lldb] Add statusline to the release notes (#133281)
Add a release note for the LLDB statusline: #121860
2025-03-28 09:16:55 -07:00
Joseph Huber
4abe47c6fc
[libc] Enable 'mktime' for the GPU (#133437)
Summary:
This is a dependency on `strftime` which we provide, so we should have
this.
2025-03-28 11:14:51 -05:00
John Harrison
6526cda5d8
[lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (#133007)
This adds new types and helpers to support the 'initialize' request with
the new typed RequestHandler. While working on this I found there were a
few cases where we incorrectly treated initialize arguments as
capabilities. The new `lldb_dap::protocol::InitializeRequestArguments`
and `lldb_dap::protocol::Capabilities` uncovered the inconsistencies.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-28 09:13:10 -07:00
Matt Arsenault
a33d789bb7
llvm-reduce: Avoid invalid reductions on x86_intrcc (#133396)
If there are arguments, the first one must be byval.
2025-03-28 23:11:28 +07:00
Craig Topper
f7f479b2a3
[RISCV] Use templates to reduce duplicated code for assembler operand predicates. (#133351)
We already had a template isUImm function. This patch adds isSImm,
isShiftedUImm, and 2 helpers that take a predicate function to validate
the immediate with. I'm using a template for the predicate function.
2025-03-28 09:03:31 -07:00
Jay Foad
a983c3b209
[TableGen] Make more use of CodeGenRegisterClass::EnumValue. NFC. (#132749) 2025-03-28 15:54:53 +00:00
Alex Bradbury
71a977d0d6
[RISCV] Add shift-add (SH1ADD, ...) to isCopyInstrImpl (#133443)
As with #132002, these do show up in a compilation of llvm-test-suite
(including SPEC 2017). We remove 30-40 static instances so this isn't
anything earth shattering.

rs2 is always added to the other shifted (and potentially extended)
operand unmodified, so rs1==zero is equivalent to a copy.
2025-03-28 15:46:50 +00:00
Michael Buch
8ea3f818de [lldb][test] TestCCallingConventions.py: skip on older AArch64 compilers
With our Clang-15 arm64 CI this test-case crashes when compiling the test program:
```
user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c
Unexpected callee-save save/restore opcode!
UNREACHABLE executed at /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1501/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1129!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1501_build/bin/clang -g -O0 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -arch arm64 -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/lldb-build/tools/lldb/include -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -Werror=ignored-attributes -MT ms_abi.o -MD -MP -MF ms_abi.d -c -o ms_abi.o /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c'.
4.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@func'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-15                 0x0000000105d512b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  clang-15                 0x0000000105d500e4 llvm::sys::RunSignalHandlers() + 112
2  clang-15                 0x0000000105d507c4 llvm::sys::CleanupOnSignal(unsigned long) + 232
3  clang-15                 0x0000000105c79d78 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 128
4  clang-15                 0x0000000105c79f94 CrashRecoverySignalHandler(int) + 124
5  libsystem_platform.dylib 0x0000000185ecba24 _sigtramp + 56
6  libsystem_pthread.dylib  0x0000000185e9ccc0 pthread_kill + 288
7  libsystem_c.dylib        0x0000000185daca40 abort + 180
8  clang-15                 0x0000000105c88508 llvm::install_out_of_memory_new_handler() + 0
9  clang-15                 0x0000000104af7404 fixupCalleeSaveRestoreStackOffset(llvm::MachineInstr&, unsigned long long, bool, bool*) + 0
10 clang-15                 0x0000000104af53e0 llvm::AArch64FrameLowering::emitPrologue(llvm::MachineFunction&, llvm::MachineBasicBlock&) const + 3564
```
2025-03-28 15:32:18 +00:00
Matt Arsenault
2213872002
llvm-reduce: Use isCallee helper (#133419) 2025-03-28 22:24:42 +07:00
swatheesh-mcw
fe30cf18ab
Revert "Revert "[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses."" (#132343)
Reverts llvm/llvm-project#132005
2025-03-28 15:21:52 +00:00
YunQiang Su
2218587b5b
MIPS: Support isLegalICmpImmediate and isLegalAddImmediate (#133400)
Set it to true only if isInt<16>.
By default implemention defines them to true always. For most cases,
MIPS uses 16bit IMM, and for microMIPS, ICMP and ADDiu have 16bit IMM
flavors.
2025-03-28 23:03:52 +08:00
Antonio Frighetto
460d628d90 [GVN] Clean up unused argument, unify style, modernize syntax (NFC)
Finalize code style overhaul in GVN, following up to
2a0946bc0dffca89d16cd9d5208ec9416ed8100e and 9deed7d2ef3a147c4e8410910967fde601359039.
2025-03-28 15:59:28 +01:00
Kazu Hirata
0ae9c65d4a
[tools] Use *Set::insert_range (NFC) (#133384)
We can use *Set::insert_range to replace "for" loop-based insertions.
In some cases, we can further fold insert_range into the set
declaration.
2025-03-28 07:53:09 -07:00
Kazu Hirata
43829039c9
[Format] Use a range constructor of DenseSet (NFC) (#133382) 2025-03-28 07:52:43 -07:00
Cassandra Beckley
9ce77255b9
[HLSL] Add __spirv__ macro (#132848)
This macro can be used by HLSL code to detect that it is being compiled
for the SPIR-V target.
2025-03-28 10:49:19 -04:00
Hari Limaye
bf5627c85e
[LV] Optimize VPWidenIntOrFpInductionRecipe for known TC (#118828)
Optimize the IR generated for a VPWidenIntOrFpInductionRecipe to use the
narrowest type necessary, when the trip-count of a loop is known to be
constant and the only use of the recipe is the condition used by the
vector loop's backedge branch.
2025-03-28 14:47:40 +00:00
Haojian Wu
db04c3e4b3
[clang] Implement some missing interfaces for DelegatingDeserializationListener (#133424)
Split from the https://github.com/llvm/llvm-project/pull/133395 per the
review comment.

This patch also moves the `DelegatingDeserializationListener` close to
`ASTDeserializationListener`.
2025-03-28 15:31:21 +01:00
David Spickett
1f90a88b80
[libcxx] Remove clang-18 workaround in picolib build (#133254)
clang-19 changed how Arm triples were normalised and so while we
supported 18 and 19, we could not hard code the path here.

Now that Linaro's bots are running clang-19, and libcxx is going to drop
clang-18 support (https://github.com/llvm/llvm-project/pull/130142) I
have simplified it by hard coding the path again.

I also looked into why this exists in the first place. It was added in
https://reviews.llvm.org/D154246 but not questioned at the time.

It is due to the way we build compiler-rt, which is due to the final
layout we need in the install:
1. The builtins library must be called libclang_rt.builtins.a for clang
to find it. There must not be an architecture name in the filename.
2. That builtins library must be directly in lib/, next to picolib's
installed files.

To achieve number 1 we must set LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON.
However, that causes the file to be installed in a per-target dir which
breaks number 2. So to fix that, we move the builtins library up one
level into lib/.

The alternative is to turn off per-target dirs, which results in a
builtin file with an arch in the name, then rename and move that file
(since it gets installed into lib/generic/).

So in the end, it's the same amount of hacks. I think it's best to keep
the one that uses LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, as this is the
recommended way to built these days.
2025-03-28 14:30:38 +00:00
Nick Sarnie
48b7530273
[clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU function to Triple (#126956)
I'm adding support for SPIR-V, so let's consolidate these checks.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-03-28 14:19:20 +00:00
Paschalis Mpeis
427725508b
[BOLT] Add getter for optional relocations (#133085)
Minor refactoring on comments.
2025-03-28 14:07:51 +00:00
Philip Reames
b6569cce40
[RISCV] Refine location size for segment spill and fill (#133268)
This is a follow up to #133171. I realized we could assume the structure
of the previous MMO, and thus the split is much simpler than I'd
initially pictured.
2025-03-28 07:06:17 -07:00
Andras Gemes
579379cf7f
[Nomination] Add HighTec representatives to the Security Group (#124142)
I would like to nominate Mario Cupelli (@mariocup) and myself to join
the LLVM Security Group as representatives (vendor contacts) of [HighTec
EDV Systeme](https://github.com/hightec-rt).

Mario is the CTO of HighTec and has a strong background in compiler
safety qualification. I am a SW engineer with a focus on cybersecurity
and a goal to contribute to the LLVM Security Group.

HighTec collaborates with major silicon vendors and offers
safety-qualified C/C++ and Rust compilers based on LLVM. Our active
contributions to LLVM include work on the linker and various patches and
we are committed to further improving LLVM’s security.

Our motivation for joining the LLVM Security Group is to collaborate
with LLVM security experts, stay informed about the latest CVEs in LLVM
and meet the cybersecurity requirements of the automotive industry.
2025-03-28 14:02:57 +00:00
Jay Foad
53b48301eb
[AMDGPU] Tweak address space definitions. NFC. (#133442)
Define address spaces in numerical order. Fix comments to refer to
"local" instead of "group" address space.
2025-03-28 13:43:31 +00:00
Baranov Victor
d6dcd985c0
[clang-tidy] Fix thread_local false positives in misc-use-internal-linkage check (#132573)
Based on C++ standard (see issue
https://github.com/llvm/llvm-project/issues/131679) and
[StackOverflow](https://stackoverflow.com/questions/22794382/are-c11-thread-local-variables-automatically-static)
`thread_local` variables are implicitly `static` so we should not
suggest adding `static` on a `thread_local` variables. I'd appreciate if
someone else will confirm this too because reading standard is tricky.

However, many people still use `static` and `thread_local` together:
[github
code-search](https://github.com/search?type=code&q=%22static+thread_local%22+language%3AC%2B%2B).
Maybe disabling warnings on `thread_local` should be made as a flag?
WDYT?

Closes https://github.com/llvm/llvm-project/issues/131679.
2025-03-28 21:33:58 +08:00
Baranov Victor
ecdbd26ba4
[clang-tidy][NFC] improve documentation for bugprone-argument-comment check (#133436)
Improve docs for `bugprone-argument-comment` check by writing explicitly
default values for options.
Before this change, it was unclear what values are default.
2025-03-28 14:33:53 +01:00
Daniel Chen
316bb89c94
[Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (#132821)
In the wake of discussion in PR #131200 and internal discussion after,
we will add support for `LLVM_ENABLE_PER_TARGET_RUNTIME=ON` for AIX
instead of disable it. I already reverted the change in PR #131200.

The default value of the option is still OFF on AIX.
2025-03-28 09:22:02 -04:00
Matthias Springer
4abff4d7b2
[mlir][Transforms] Improve replaceOpWithMultiple API (#132608)
This commit adds an additional overload to `replaceOpWithMultiple` that
accepts additional container types. This has been brought up by users of
the new `replaceOpWithMultiple` API.

In particular, one missing container type was
`SmallVector<SmallVector<Value>>`. The "default" `ArrayRef<ValueRange>`
container type can lead to use-after-scope errors in cases such as:
```c++
// Compute the replacement value ranges. Some replacements are single
// values, some are value ranges.
SmallVector<ValueRange> repl;
repl.push_back(someValueRange);  // OK
for (...) {
  // push_back(Value) triggers an implicit conversion to ValueRange,
  // which does not own the range.
  repl.push_back(someValue);  // triggers use-after-scope later
}
rewriter.replaceOpWithMultiple(op, repl);
```

In this example, users should use `SmallVector<SmallVector<Value>>
repl;`.
2025-03-28 14:18:54 +01:00
Krzysztof Parzyszek
33cd00f8c8
[flang] Use more generic overload for Operation in Traverse (#133305)
Currently there are two specific overloads: for unary operations, i.e.
`Operation<D, R, O>`, and binary ones `Operation<D, R, LO, RO>`.

This makes it impossible for a derived class to use a single overload to
handle all types of operations: `Operation<D, R, O...>`. Since the base
overloads need to be included in the derived class's scope, via `using
Base::operator()` either one of the specific overloads will always be a
better candidate than the more generic derived one.

```
class MyVisitor : public Traverse<...> {
  using Traverse<...>::operator();

  template <typename D, typename R, typename... O>
  Result operator()(const Operation<D, R, O...> &op) const {
    // Will never be used.
  }
};
```
This patch replaces the two specific overloads for Operation in Traverse
with a single generic overload, while preserving the existing
functionality, and allowing derived classes to use a single overload as
well.
2025-03-28 08:17:31 -05:00
Alex Bradbury
a481452cd8
[RISCV] Add OR/XOR/SUB to RISCVInstrInfo::isCopyInstrImpl (#132002)
This adds coverage for additional instructions in isCopyInstrImpl, for
now picking just those where I can observe that there is a codegen
difference for SPEC.

This allows MachineCopyPropagation to successfully eliminate no-op moves in this form.
2025-03-28 12:59:18 +00:00
Simon Pilgrim
212a48b4da [X86] combine-bitselect.ll - regenerate VPTERNLOG comments 2025-03-28 12:47:02 +00:00
Joseph Huber
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Nico Weber
c4bc1b1d81
[clang] Update Mach-O ptrauth driver defaults (#132834)
Xcode clang default-enables a bunch of ptrauth flags when targeting
arm64e. Let's match that.
2025-03-28 08:34:25 -04:00
Veera
4cdcf3b193
[InstCombine] Fold (trunc nuw A to i1) == (trunc nuw B to i1) to A == B (#133368)
Fixes #133344

Proof: https://alive2.llvm.org/ce/z/X3Uh23 

InstCombine couldn't optimize `i1` because `canonicalizeICmpBool()` was
transforming the comparison into bitwise operations before
`foldICmpTruncWithTruncOrExt()` was called.

This PR solves the ordering issue by placing
`foldICmpTruncWithTruncOrExt()` before `canonicalizeICmpBool()`.

I believe this will not cause any regressions since all tests are
passing.
2025-03-28 08:32:45 -04:00
Jesse D
f76254d9b2
[libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
This is the same fix that was recently applied to
as_mantissa_type_rounded(), but for as_mantissa_type().
2025-03-28 08:31:17 -04:00