58161 Commits

Author SHA1 Message Date
Craig Topper
6053ca004a
[MC][CodeGen] Move FirstStackSlot and VirtualRegFlag from MCRegister to Register. NFC (#128444)
These concepts don't exist for MCRegister.

I think there is a need for virtual registers in MCRegister for NVPTX,
SPIR-V and WebAssembly, but those should not be confused with Register's
virtual register. I will try to make a separate proposal for that with a
real interface.
2025-02-23 19:56:49 -08:00
Fangrui Song
78bac7f0a6 [MC] Remove unneeded getMemtagAttr() 2025-02-23 10:56:59 -08:00
Jonas Hahnfeld
9e82ee5274
[Support] Remove AlignedCharArrayUnion from Expected and ErrorOr, NFCI. (#127407)
They were instantiated with only a single type and union-members
themselves. By putting the types directly into a union, they are still
left uninitialized by default.
2025-02-23 12:34:44 +01:00
Kazu Hirata
9dd8c14443
[IR] Avoid repeated map lookups (NFC) (#128396) 2025-02-23 01:03:46 -08:00
Lang Hames
21939c4c2e [ORC] Fix type name in comments. NFC. 2025-02-23 18:16:10 +11:00
Craig Topper
57b445862d
[LiveRegUnits] Use MCRegister instead of MCPhysReg in interface. NFC (#128232) 2025-02-22 21:20:45 -08:00
Craig Topper
a26fd0b75f
[LivePhysReg] Fix off by 1 error in an assert. NFC (#128379)
Reg should not be equal to the number of registers.
2025-02-22 21:13:46 -08:00
Mikhail Gudim
f5d153ef26
[VectorCombine] Fold binary op of reductions. (#121567)
Replace binary of of two reductions with one reduction of the binary op
applied to vectors. For example:

```
%v0_red = tail call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %v0)
%v1_red = tail call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %v1)
%res = add i32 %v0_red, %v1_red
```
gets transformed to:

```
%1 = add <16 x i32> %v0, %v1
%res = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %1)
```
2025-02-22 06:11:33 -05:00
Antonio Frighetto
48a6df3604 Reapply "[Utils] Consolidate LockstepReverseIterator into own header (NFC)"
Common code has been unified and generalized.

Original commit: 123dca9b56e1359d8ec7771ea3bd0afd4b1ea6af

Previously reverted due to accidentally merged incompletely. The issue has
been addressed by restoring missing code.
2025-02-22 11:21:36 +01:00
Florian Hahn
236fa506d4 Revert "[Utils] Consolidate LockstepReverseIterator into own header (NFC) (#116657)"
This reverts commit 123dca9b56e1359d8ec7771ea3bd0afd4b1ea6af.

This breaks building on macOS with clang and multiple build bots,
including https://lab.llvm.org/buildbot/#/builders/175/builds/13585

    llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp: In function ‘bool sinkCommonCodeFromPredecessors(llvm::BasicBlock*, llvm::DomTreeUpdater*)’:
    /b/ml-opt-devrel-x86-64-b1/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:2503:3: error: reference to ‘LockstepReverseIterator’ is ambiguous
     2503 |   LockstepReverseIterator<true> LRI(UnconditionalPreds);
          |   ^~~~~~~~~~~~~~~~~~~~~~~
2025-02-21 21:00:28 +00:00
Tom Tromey
c0a6f7acf8
Use precise types in DWARF BestForm methods (#126309)
I noticed that DIEInteger::BestForm used a cast to char:

      if ((char)Int == SignedInt)

If 'char' happens to be unsigned, this will not behave correctly. Then I
also noticed that this code assumes the size of 'short' and 'int'.

This patch changes this code to use more precise types. No functional
change should be visible on ordinary hosts.
2025-02-21 12:23:47 -08:00
Antonio Frighetto
123dca9b56
[Utils] Consolidate LockstepReverseIterator into own header (NFC) (#116657)
Common code has been unified and generalized. Not sure if it may be
worth to generalize this further, since it looks closely tied to Blocks
(might make sense to rename it in `LockstepReverseInstructionIterator`).
2025-02-21 12:21:33 -08:00
Jonas Hahnfeld
e65d3882af
[Support] Ensure complete type DelimitedScope (#127459)
`JSONScopedPrinter` has a `std::unique_ptr<DelimitedScope>` member and
defaulted constructor argument, so it needs a complete type. This
resolves one of the many build errors with C++23 using Clang.
2025-02-21 12:19:56 -08:00
Tom Tromey
b0f0ac3cad
Add overload of DIBuilder::createArrayType (#125229)
DICompositeType has an attribute representing the name of a type, but
currently it isn't possible to set this for array types via the
DIBuilder method. This patch adds a new overload of
DIBuilder::createArrayType that allows "full" construction of an array
type. This is useful for Ada, where arrays are a bit more first-class
than C.
2025-02-21 12:17:06 -08:00
Jordan Rupprecht
45ca39d8e1
[Support] Fix for non-constexpr __PRETTY_FUNCTION__ on older gcc (#128212)
Prior to gcc version 9, the `__PRETTY_FUNCTION__` macro was not declared
constexpr. In that case, don't declare this as constexpr, and switch the
static asserts to runtime asserts.

Verified this should work on all supported compilers:
https://godbolt.org/z/T77rvPW5z

Followup to #127893 / 8a39214b7e6e79e65135b7dbcc98b427a032d5fb
2025-02-21 14:05:21 -06:00
Jordan Rupprecht
8a39214b7e
[Support] Apply constexpr to getTypeName (#127893)
This is a followup to 003a721c1c9e3a99d6d0c1a6755443b260235537, which we
noticed increased binary size a small but noticable amount. The increase
seems to be due to code size from each `llvm::getTypeName<T>` wrapper,
which adds up if there are a lot of types.

The original motivation was to improve runtime and avoid `getTypeName`
being recomputed each time. The implementation is simple enough that we
can make it fully constexpr, which addresses the size increase, but also
further improves runtime: we directly reference the data instead of
jumping through a guard variable to see if we've computed it already.
2025-02-21 10:13:01 -06:00
Craig Topper
af64f0a6c2
[FrameLowering] Use MCRegister instead of Register in CalleeSavedInfo. NFC (#128095)
Callee saved registers should always be phyiscal registers. They are
often passed directly to other functions that take MCRegister like
getMinimalPhysRegClass or TargetRegisterClass::contains.

Unfortunately, sometimes the MCRegister is compared to a Register which
gave an ambiguous comparison error when the MCRegister is on the LHS.
Adding a MCRegister==Register comparison operator created more ambiguous
comparison errors elsewhere. These cases were usually comparing against
a base or frame pointer register that is a physical register in a
Register. For those I added an explicit conversion of Register to
MCRegister to fix the error.
2025-02-20 23:44:05 -08:00
Akshat Oke
36d304d214
[RegAllocFast][NPM] Make RegAllocFastPassOptions a nested class (#127984)
Making all reg alloc classes have an `::Option` class makes things nicer
to construct them.
2025-02-21 11:51:57 +05:30
vporpo
4d92975b5c
[SandboxVec][Scheduler] Don't allow rescheduling of already scheduled (#128050)
This patch implements the check for not allowing re-scheduling of
instructions that have already been scheduled in a scheduling bundle.
Rescheduling should only happen if the instructions were temporarily
scheduled in singleton bundles during a previous call to
`trySchedule()`.
2025-02-20 16:16:34 -08:00
Vasileios Porpodas
2ff80d2448 [SandboxVec][Scheduler] Fix reassignment of SchedBundle to DGNode
When assigning a bundle to a DAG Node that is already assigned to a
SchedBundle we need to remove the node from the old bundle.
2025-02-20 15:28:16 -08:00
Vasileios Porpodas
a1a10732e4 [SandboxVec][DAG] Remove all matching nodes from bundle
This fixes a bug where `SchedBundle::eraseFromBundle()` would not erase all
matching nodes but just the first one.
2025-02-20 15:13:52 -08:00
Christopher Di Bella
08c69b2ef6 Revert "[CodeGen] Remove static member function Register::isVirtualRegister. NFC (#127968)"
This reverts commit ff99af7ea03b3be46bec7203bd2b74048d29a52a.
2025-02-20 22:06:21 +00:00
Christopher Di Bella
309e3ca081 Revert "[CodeGen] Remove static member function Register::isPhysicalRegister. NFC"
This reverts commit 5fadb3d680909ab30b37eb559f80046b5a17045e.
2025-02-20 22:06:21 +00:00
Craig Topper
5fadb3d680 [CodeGen] Remove static member function Register::isPhysicalRegister. NFC
Prefer the nonstatic member by converting unsigned to Register instead.
2025-02-20 10:49:53 -08:00
vporpo
10b99e97ff
[SandboxVec][BottomUpVec] Separate vectorization decisions from code generation (#127727)
Up until now the generation of vector instructions was taking place
during the top-down post-order traversal of vectorizeRec(). The issue
with this approach is that the vector instructions emitted during the
traversal can be reordered by the scheduler, making it challenging to
place them without breaking the def-before-uses rule.

With this patch we separate the vectorization decisions (done in
`vectorizeRec()`) from the code generation phase (`emitVectors()`). The
vectorization decisions are stored in the `Actions` vector and are used
by `emitVectors()` to drive code generation.
2025-02-20 10:21:25 -08:00
Craig Topper
ff99af7ea0
[CodeGen] Remove static member function Register::isVirtualRegister. NFC (#127968)
Use nonstatic member instead. This requires explicit conversions, but
many will go away as we continue converting unsigned to Register.

In a few places where it was simple, I changed unsigned to Register.
2025-02-20 08:35:50 -08:00
Teresa Johnson
60c620272d
[ADT] Add set_intersects to check if there is any intersection (#127907)
Add a facility to check if there is any intersection between 2 sets.
This will be used in some follow on changes to MemProf.
2025-02-20 08:02:13 -08:00
Ramkumar Ramachandra
6eba2775e2
[LAA] Scale strides using type-size (NFC) (#124529)
Change getDependenceDistanceStrideAndSize to scale strides by
TypeByteSize, scaling the returned CommonStride and MaxStride. Even
though there is a seemingly-functional change of setting CommonStride
when scaled strides are equal, it ends up being a non-functional change
due to aggressive HasSameSize checking.
2025-02-20 15:19:17 +00:00
David
e09fc394b7
[llvm] Make target triple in TLII const reference (#127718) 2025-02-20 11:06:35 +01:00
Narayan
3df03db689
[CodeGen] Refactor warn() to use StringRef (NFCI) (#127537)
closes #100064
2025-02-20 08:34:21 +00:00
Diana Picus
611a648327
[AMDGPU] Add llvm.amdgcn.dead intrinsic (#123190)
Shaders that use the llvm.amdgcn.init.whole.wave intrinsic need to
explicitly preserve the inactive lanes of VGPRs of interest by adding
them as dummy arguments. The code usually looks something like this:

```
define amdgcn_cs_chain void f(active vgpr args..., i32 %inactive.vgpr1, ..., i32 %inactive.vgprN) {
entry:
  %c = call i1 @llvm.amdgcn.init.whole.wave()
  br i1 %c, label %shader, label %tail

shader:
  [...]

tail:
  %inactive.vgpr.arg1 = phi i32 [ %inactive.vgpr1, %entry], [poison, %shader]
  [...]
  ; %inactive.vgpr* then get passed into a llvm.amdgcn.cs.chain call
```

Unfortunately, this kind of phi node will get optimized away and the
backend won't be able to figure out that it's ok to use the active lanes
of `%inactive.vgpr*` inside `shader`.

This patch fixes the issue by introducing a llvm.amdgcn.dead intrinsic,
whose result can be used as a PHI operand instead of the poison. This
will be selected to an IMPLICIT_DEF, which the backend can work with.

At the moment, the llvm.amdgcn.dead intrinsic works only on i32 values.
Support for other types can be added later if needed.
2025-02-20 09:25:48 +01:00
Craig Topper
77183a46a5
[CodeGen] Remove static member function Register::virtReg2Index. NFC (#127962)
Use the nonstatic member instead.

I'm pretty sure the code in SPRIV is a layering violation. MC layer
files are using a CodeGen header.
2025-02-19 23:34:55 -08:00
Piotr Fusik
8b58cb853a
[SelectionDAG][NFC] Refactor duplicate code into SDNode::bitcastToAPInt() (#127503) 2025-02-20 13:23:00 +07:00
Craig Topper
92ddbbd89f [CodeGen] Remove static member functions Register::stackSlot2Index/isStackSlot. NFC
Migrate the few users to the nonstatic member functions.
2025-02-19 21:54:43 -08:00
Akshat Oke
557628dbe6
[CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (#118462)
Similar to #117309.

The advisor and logger are accessed through the provider, which is
served by the new PM. Legacy PM forwards calls to the provider.
New PM is a machine function analysis that lazily initializes the
provider.
2025-02-20 09:35:49 +05:30
Matt Arsenault
37c341df28 Revert "AMDGPU: Don't canonicalize fminnum/fmaxnum if targets support IEEE fminimum(maximum)_num (#127711)"
This reverts commit 36eaf0daf5d6dd665d7c7a9ec38ea22f27709fed.

This is not a sound approach to dealing with this instruction change.
The new behavior is a different opcode pair, not a modifier on the
existing opcode.
2025-02-20 10:19:14 +07:00
Slava Zakharin
75bd46e01f
[globals-aa] Improved isNonEscapingGlobalNoAlias. (#127707)
A non-escaping global should never alias with non-pointer values
and `ptr null`. This should improve disambiguation of global
pointers with relation to Flang runtime calls (given that
`nosync nocallback` attributes are properly set).
It also seems to be an obvious improvement with little overhead.
2025-02-19 17:09:29 -08:00
vporpo
1987f93d03
[SandboxIR] OpaqueValue (#127699)
This patch implements a new subclass of the Value class used for Sandbox
IR Values that we don't support, like metadata or inline asm. The goal
is to never have null sandboxir::Value objects, because this is not the
expected behavior.
2025-02-19 11:54:44 -08:00
Changpeng Fang
36eaf0daf5
AMDGPU: Don't canonicalize fminnum/fmaxnum if targets support IEEE fminimum(maximum)_num (#127711)
For targets that support IEEE fminimum_num/fmaximum_num, the
corresponding *_min_num_fXY/*_max_num_fXY instructions themselves
already did the canonicalization for the inputs. As a result, we do not
need to explicitly canonicalize the inputs for fminnum/fmaxnum.
2025-02-19 11:16:43 -08:00
Craig Topper
a6f48ed012
[MC] Remove MCRegister::isStackSlot. (#127755)
Stack slots should only be stored in Register. The only caller was
Register::isStackSlot so just inline it there.
2025-02-19 10:19:40 -08:00
Nico Weber
e2ba1b6ffd Revert "Reapply [CaptureTracking][FunctionAttrs] Add support for CaptureInfo (#125880)"
This reverts commit 0fab404ee874bc5b0c442d1841c7d2005c3f8729.
Seems to break LTO builds of clang on Windows, see comments on
https://github.com/llvm/llvm-project/pull/125880
2025-02-19 11:32:57 -05:00
Kazu Hirata
bb75a96900
[Support] Avoid repeated hash lookups (NFC) (#127747) 2025-02-19 08:21:33 -08:00
zhijian lin
1ac0db44fd
[NFC] using isUndef() instead of getOpcode() == ISD::UNDEF (#127713)
[NFC] using isUndef() instead of getOpcode() == ISD::UNDEF
2025-02-19 08:42:38 -05:00
Durgadoss R
3ce2e4df5d
[NVPTX] Add tcgen05.cp/shift intrinsics (#127669)
This patch adds intrinsics for tcgen05.cp and
tcgen05.shift instructions.

lit tests are added and verified with a
ptxas-12.8 executable.

Docs are updated in the NVPTXUsage.rst file.

Signed-off-by: Durgadoss R <durgadossr@nvidia.com>
2025-02-19 17:55:25 +05:30
Fabian Ritter
8615f9aaff
[AMDGPU] Replace gfx940 and gfx941 with gfx942 in llvm (#126763)
gfx940 and gfx941 are no longer supported. This is one of a series of
PRs to remove them from the code base.

This PR removes all non-documentation occurrences of gfx940/gfx941 from
the llvm directory, and the remaining occurrences in clang.

Documentation changes will follow.

For SWDEV-512631
2025-02-19 10:20:48 +01:00
Nikita Popov
cc539138ac
[CodeGen] Use __extendhfsf2 and __truncsfhf2 by default (#126880)
The standard libcalls for half to float and float to half conversion are
__extendhfsf2 and __truncsfhf2. However, LLVM currently uses
__gnu_h2f_ieee and __gnu_f2h_ieee instead. As far as I can tell, these
libcalls are an ARM-ism and only provided by libgcc on that platform.
compiler-rt always provides both libcalls.

Use the standard libcalls by default, and only use the __gnu libcalls on
ARM.
2025-02-19 10:16:57 +01:00
Ashley Coleman
02c9dae814
[HLSL] Add support to lookup a ResourceBindingInfo from its use (#126556)
Adds `findByUse` which takes a `llvm::Value` from a use and resolves it
(as best as possible) back to the creation of that resource.

It may return multiple ResourceBindingInfo if the use comes from
branched control flow.

Fixes #125746
2025-02-18 17:29:23 -07:00
vporpo
0cc7381543
[SandboxVec][Scheduler] Don't insert scheduled instrs into the ready list (#127688)
In a particular scenario (see test) we used to insert scheduled
instructions into the ready list. This patch fixes this by fixing the
trimSchedule() function.
2025-02-18 16:17:46 -08:00
vporpo
0f6c18e8c6
[SandboxVec] Replace hard-coded context save() with transaction-save pass (#127690)
This patch implements a small region pass that saves the context's
state. The patch is now used in the default pipeline to save the context
state instead of the hard-coded call to Context::save().

The concept behind this is that the passes themselves should not have to
do the actual saving/restoring of the IR state, because that would make
it challenging to reorder them in the pipeline. Having separate
save/restore passes makes the transformation passes more composable as
parts of arbitrary pipelines.
2025-02-18 13:34:51 -08:00
Krzysztof Drewniak
f7d03707d1
[AMDGPU] Generalize amdgcn.make.buffer.rsrc to fat pointers (#126828)
Attempting to pass a `ptr addrspace(7)` to functions that take `ptr`
arguments produces undesirable `addrspacecast(addrspacecast(p8 x to p7)
to p0) => addrspacecast(p8 x to p0)` folds. This results in illegal GEP
operations on buffer resources, which can't be GEP'd. (However, note
that, while unimplemneted, addressspacecast from ptr addrspace(7) to ptr
is legal - it's just an effective address computation)

To resolve this problem, and thus prevent illegal
`getelementptr T, ptr addrspace(8) %x, ...` s from being produces, this
commit extends amdgcn.make.buffer.rsrc to also be variadic in its result
type, auto-upgrading old manglings.

The logic for handling a make.buffer.rsrc in instruction selection
remains untouched and expects the output type to be a ptr addrspace(8),
as does the Clang lowering for its builtin (the pointer-to-pointer
version might want a different name in clang). LowerBufferFatPointers
has been updated to lower
amdgcn.make.buffer.rsrc.p7.p* to amdgcn.make.buffer.rsrc.p8.p* .

This'll also make exposing buffer fat pointers in Clang easier, since
you don't have to cast between a `__amdgcn_rsrc_t` and a pointer.
2025-02-18 14:15:28 -06:00