695 Commits

Author SHA1 Message Date
Simon Pilgrim
bacfdcd7e0
[DAG] Add SDPatternMatch::m_BitCast matcher (#123327)
Simplifies a future patch
2025-01-17 12:22:07 +00:00
Jameson Nash
f6b0555a43
[AsmPrinter] Reintroduce full AsmPrinterHandler API (#122297)
This restores the functionality of AsmPrinterHandlers to what it was
prior to https://github.com/llvm/llvm-project/pull/96785. The attempted
hack there of adding a duplicate DebugHandlerBase handling added a lot
of hidden state and assumptions, which just segfaulted when we tried to
continuing using this API. Instead, this just goes back to the old
design, but adds a separate array for the basic EH handles. The
duplicate array is identical to the other array of handler, but which
doesn't get their begin/endInstruction callbacks called. This still
saves the negligible but measurable amount of virtual function calls as
was the goal of #96785, while restoring the API to the pre-LLVM-19
status quo.
2025-01-16 17:00:06 +01:00
Amr Hesham
1d58699f5c
[SDPatternMatch] Add Matcher m_Undef (#122521)
Add Matcher `m_Undef`

Fixes: #122439
2025-01-11 13:23:37 +01:00
Thor Preimesberger
c1c50c7a3e
[SDPatternMatch] Add matchers m_ExtractSubvector and m_InsertSubvector (#120212)
Fixes #118846
2025-01-09 15:20:48 -08:00
Aidan Goldfarb
f3bc8c34c9
Add SD matchers and unit test coverage for ISD::VECTOR_SHUFFLE (#119592)
This PR resolves #118845. I aimed to mirror the implementation
`m_Shuffle()` in
[PatternMatch.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/PatternMatch.h).

Updated
[SDPatternMatch.h](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/SDPatternMatch.h)
- Added `struct m_Mask` to match masks (`ArrayRef<int>`)
- Added two `m_Shuffle` functions. One to match independently of mask,
and one to match considering mask.
- Added `struct SDShuffle_match` to match `ISD::VECTOR_SHUFFLE`
considering mask

Updated
[SDPatternMatchTest.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp)
- Added `matchVecShuffle` test, which tests the behavior of both
`m_Shuffle()` functions

- - -

I am not sure if my test coverage is complete. I am not sure how to test
a `false` match, simply test against a different instruction? [Other
tests
](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp#L175),
such as for `VSelect`, test against `Select`. I am not sure if there is
an analogous instruction to compare against for `VECTOR_SHUFFLE`. I
would appreciate some pointers in this area. In general, please
liberally critique this PR!

---------

Co-authored-by: Aidan <aidan.goldfarb@mail.mcgill.ca>
2025-01-06 13:57:19 -05:00
Min-Yih Hsu
a74f825a7a
[MIPatternMatch] Add m_DeferredReg/Type (#121218)
This pattern does the same thing as m_SpecificReg/Type except the value
it matches against origniated from an earlier pattern in the same
mi_match expression.

This patch also changes how commutative patterns are handled: in order
to support m_DefferedReg/Type, we always have to run the LHS-pattern
before the RHS one.
2024-12-30 09:23:51 -08:00
Min-Yih Hsu
831e1ac12e
[MIPatternMatch] Add m_GUMin and m_GUMax (#121068)
And make all unsigned and signed versions of min/max matchers
commutative, since we already made a precedent of m_GAdd that is
commutative by default.
2024-12-26 09:28:17 -08:00
Min-Yih Hsu
d21f300f06
[MIPatternMatch] Fix incorrect argument type of m_Type (#121074)
m_Type is supposed to extract the underlying value type (equality type
comparison is covered by m_SpecificType), therefore it should take a LLT
reference as its argument rather than passing by value.

This was originated from de256478e61d6488db751689af82d280ba114a6f, which
refactored out a good chunk of LLT reference usages. And it's just so
happen that (for some reasons) no one is using m_Type and no test was
covering it.
2024-12-26 09:09:02 -08:00
Vikash Gupta
c21a3776c9
[GlobalIsel] [Utility] [NFC] Added isConstantOrConstantSplatVectorFP to handle float constants. (#120935)
Needed for #120104
2024-12-26 18:57:19 +05:30
NAKAMURA Takumi
d328d41061 Revert "Add a pass to collect dropped var stats for MIR (#120780)"
This reverts commit 3bf91ad2a9c75dd045961e45fdd830fd7b7a5455.
(llvmorg-20-init-16123-g3bf91ad2a9c7)

`llvm/CodeGen` should not depend on `llvm/Passes`.
2024-12-21 12:42:26 +09:00
Shubham Sandeep Rastogi
3bf91ad2a9
Add a pass to collect dropped var stats for MIR (#120780)
This patch uses the DroppedVariableStats class to add dropped variable
statistics for MIR passes.

Reland 1c082c9cd12efaa67a32c5da89a328c458ed51c5
2024-12-20 10:08:54 -08:00
Shubham Sandeep Rastogi
e7e622f153 Revert "Move DroppedVariableStats to CodeGen lib (#120650)"
This reverts commit 4307198d51487cc16f98eebb2113caf4a1905914.

Broke bot ppc64le-clang-multistage-test:

undefined reference to
`llvm::DroppedVariableStats::populateVarIDSetAndInlinedMap in
In function `llvm::DroppedVariableStatsIR::visitEveryInstruction
2024-12-19 19:59:34 -08:00
Shubham Sandeep Rastogi
4307198d51
Move DroppedVariableStats to CodeGen lib (#120650)
To get Dropped variable statistics for MIR, we need to move the base
class DroppedVariableStats code to the CodeGen library because we cannot
have CodeGen link against Passes.

Also moved the code for the virtual functions to the header because
clang/lib/CodeGen doesn't link against llvm/lib/CodeGen however it does
link against Passes which contains the `class StandardInstrumentations`
code but not the definition for the virtual functions leading to the
error about not finding vtable for `class DroppedVariableStatsIR`
2024-12-19 18:09:14 -08:00
Chris White
ecdf0dac56
[DAG] SDPatternMatch - Add m_ExtractElt and m_InsertElt matchers (#119430)
Resolves #118844
2024-12-13 15:36:53 -08:00
Shubham Sandeep Rastogi
077cc3deee Revert "Move DroppedVariableStatsIRTest.cpp to CodeGen folder"
This reverts commit 10ed7d94b52c21317a1e02ef1e2c3ff2b2d08301.

Revert "Reland 2de78815604e9027efd93cac27c517bf732587d2 (#119650)"

This reverts commit 0e80f9a1b51e0e068adeae1278d59cd7baacd5d8.

This is because the clang-ppc64le-linux-multistage bot breaks with error

undefined reference to `vtable for llvm::DroppedVariableStatsIR'
2024-12-11 23:10:14 -08:00
Shubham Sandeep Rastogi
10ed7d94b5 Move DroppedVariableStatsIRTest.cpp to CodeGen folder 2024-12-11 20:05:24 -08:00
Owen Anderson
6f3f08abdc
CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119487)
This reapplies #119122 with a fix for UBSAN errors in the X86 backend
related
to incrementing a nullptr.
2024-12-12 10:17:32 +13:00
Owen Anderson
e940353fd2 Revert "CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119122)"
Reverting due to UBSan failures in X86RegisterInfo::getLargestLegalSuperClass

This reverts commit c4873819a98f59ce4e2664f94c73c2dfec3393f8.
2024-12-11 13:45:17 +13:00
Owen Anderson
c4873819a9
CodeGen: Eliminate dynamic relocations in the register superclass tables. (#119122) 2024-12-11 12:36:51 +13:00
Jon Roelofs
b6c22a4e58
Add processor aliases back to -print-supported-cpus and -mcpu=help (#118581)
They were accidentally dropped in
https://github.com/llvm/llvm-project/pull/96249

rdar://140853882
2024-12-09 09:18:31 -08:00
Shubham Sandeep Rastogi
abc4183c73 Revert "Reland "[NFC] Move DroppedVariableStats to its own file and redesign it to be extensible (#118546)" (#119048)"
This reverts commit 37606b4c22654ab66eee8f89448a117f3534f2f4.

Broke the llvm-nvptx-nvidia-ubuntu bot with error: the vtable symbol may
 be undefined because the class is missing its key function
2024-12-06 23:19:39 -08:00
Shubham Sandeep Rastogi
37606b4c22
Reland "[NFC] Move DroppedVariableStats to its own file and redesign it to be extensible (#118546)" (#119048)
Move the virtual destructor definition to the cpp file and see if that
gets rid of the undefined vtable error.
2024-12-06 23:13:30 -08:00
Shubham Sandeep Rastogi
259bdc0033 Revert "Reland "[NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (#117042)" (#118546)"
This reverts commit 0c8928d456ac3ef23ed25bfc9e5d491dd7b62a11.

Broke Bot: https://lab.llvm.org/buildbot/#/builders/76/builds/5008

error: undefined reference to `vtable for llvm::DroppedVariableStatsIR'
2024-12-03 16:50:53 -08:00
Shubham Sandeep Rastogi
0c8928d456
Reland "[NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (#117042)" (#118546)
Removed the virtual destructor in the derived
class DroppedVariableStatsIR
2024-12-03 14:13:06 -08:00
Shubham Sandeep Rastogi
80987ef4b6 Revert "Reland [NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (#117042)"
This reverts commit acf3b1aa932b2237c181686e52bc61584a80a3ff.

Broke https://lab.llvm.org/buildbot/#/builders/76/builds/5002

tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/BackendUtil.cpp.o:(.toc+0x258): undefined reference to `vtable for llvm::DroppedVariableStatsIR'
2024-12-03 12:51:24 -08:00
Shubham Sandeep Rastogi
d8b5af4504 Revert "Reland "Add a pass to collect dropped var stats for MIR" (#117044)"
This reverts commit 249755cedb17ffa707253edcef1a388f807caa35.

Broke https://lab.llvm.org/buildbot/#/builders/160/builds/9420

Note: This is test shard 99 of 154.
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from DroppedVariableStatsMIR
[ RUN      ] DroppedVariableStatsMIR.InlinedAt

--
exit: -11
2024-12-03 12:50:13 -08:00
Shubham Sandeep Rastogi
249755cedb
Reland "Add a pass to collect dropped var stats for MIR" (#117044)
Moved the MIR Test to the unittests/CodeGen folder

This is patch is part of a stack of patches, and follows
https://github.com/llvm/llvm-project/pull/117042

I moved the MIR test to the unittests/CodeGen folder 

I am trying to reland https://github.com/llvm/llvm-project/pull/115566
2024-12-03 12:37:30 -08:00
Shubham Sandeep Rastogi
acf3b1aa93
Reland [NFC] Move DroppedVariableStats to its own file and redesign it to be extensible. (#117042)
Moved the IR unit test to the CodeGen folder to resolve linker errors:

`error: undefined reference to 'vtable for
llvm::DroppedVariableStatsIR'`

This patch is trying to reland
https://github.com/llvm/llvm-project/pull/115563
2024-12-03 10:39:40 -08:00
Matin Raayai
bb3f5e1fed
Overhaul the TargetMachine and LLVMTargetMachine Classes (#111234)
Following discussions in #110443, and the following earlier discussions
in https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html,
https://reviews.llvm.org/D38482, https://reviews.llvm.org/D38489, this
PR attempts to overhaul the `TargetMachine` and `LLVMTargetMachine`
interface classes. More specifically:
1. Makes `TargetMachine` the only class implemented under
`TargetMachine.h` in the `Target` library.
2. `TargetMachine` contains target-specific interface functions that
relate to IR/CodeGen/MC constructs, whereas before (at least on paper)
it was supposed to have only IR/MC constructs. Any Target that doesn't
want to use the independent code generator simply does not implement
them, and returns either `false` or `nullptr`.
3. Renames `LLVMTargetMachine` to `CodeGenCommonTMImpl`. This renaming
aims to make the purpose of `LLVMTargetMachine` clearer. Its interface
was moved under the CodeGen library, to further emphasis its usage in
Targets that use CodeGen directly.
4. Makes `TargetMachine` the only interface used across LLVM and its
projects. With these changes, `CodeGenCommonTMImpl` is simply a set of
shared function implementations of `TargetMachine`, and CodeGen users
don't need to static cast to `LLVMTargetMachine` every time they need a
CodeGen-specific feature of the `TargetMachine`.
5. More importantly, does not change any requirements regarding library
linking.

cc @arsenm @aeubanks
2024-11-14 13:30:05 -08:00
Phoebe Wang
c72a751dab
[X86][AMX] Support AMX-TRANSPOSE (#113532)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-11-01 16:45:03 +08:00
Yingwei Zheng
cf9d1c1486
[SDAG] Simplify SDNodeFlags with bitwise logic (#114061)
This patch allows using enumeration values directly and simplifies the
implementation with bitwise logic. It addresses the comment in
https://github.com/llvm/llvm-project/pull/113808#discussion_r1819923625.
2024-10-31 08:10:07 +08:00
David Green
83ae171722
[AArch64] Add ComputeNumSignBits for VASHR. (#113957)
As with a normal ISD::SRA node, they take the number of sign bits of the
incoming value and increase it by the shifted amount.
2024-10-29 21:02:32 +00:00
Alex Rønne Petersen
ad4a582fd9
[llvm] Consistently respect naked fn attribute in TargetFrameLowering::hasFP() (#106014)
Some targets (e.g. PPC and Hexagon) already did this. I think it's best
to do this consistently so that frontend authors don't run into
inconsistent results when they emit `naked` functions. For example, in
Zig, we had to change our emit code to also set `frame-pointer=none` to
get reliable results across targets.

Note: I don't have commit access.
2024-10-18 09:35:42 +04:00
Simon Pilgrim
49fa91edf7 [DAG] SDPatternMatch - add missing ROTL/ROTR matchers 2024-10-16 11:57:18 +01:00
Simon Pilgrim
d3d2d72549 [DAG] SDPatternMatch - add missing BSWAP/CTPOP/CTTZ matchers 2024-10-16 11:52:58 +01:00
c8ef
854ded9b24
Reapply "[DAG] Enhance SDPatternMatch to match integer minimum and maximum patterns in addition to the existing ISD nodes." (#112203)
This patch adds icmp+select patterns for integer min/max matchers in
SDPatternMatch, similar to those in IR PatternMatch.

Reapply #111774.

Closes #108218.
2024-10-15 21:07:06 +08:00
David Green
04546a0dd6
[GlobalISel] Support vector G_UNMERGE_VALUES in computeKnownBits. (#112172)
This adds computeKnownBits support for vector->vector G_UNMERGE_VALUES,
grabbing the known bits with an adjusted DemandedElts mask.
2024-10-15 08:23:05 +01:00
c8ef
a3b0c31ebc
Revert "[DAG] Enhance SDPatternMatch to match integer minimum and maximum patterns in addition to the existing ISD nodes." (#112200)
Reverts llvm/llvm-project#111774

This appears to be causing some tests to fail.
2024-10-14 21:43:49 +08:00
c8ef
11f625cb87
[DAG] Enhance SDPatternMatch to match integer minimum and maximum patterns in addition to the existing ISD nodes. (#111774)
Closes #108218.

This patch adds icmp+select patterns for integer min/max matchers in
SDPatternMatch, similar to those in IR PatternMatch.
2024-10-14 21:19:34 +08:00
Jay Foad
eb6e7e8f89
[unittests] Use {} instead of std::nullopt to initialize empty ArrayRef (#109388)
Follow up to #109133.
2024-09-21 10:59:50 +01:00
Michael Maitland
ee2add0683
[GISEL] Fix bugs and clarify spec of G_EXTRACT_SUBVECTOR (#108848)
The implementation was missing the fact that `G_EXTRACT_SUBVECTOR`
destination and source vector can be different types.

Also fix a bug in the MIR builder for `G_EXTRACT_SUBVECTOR` to generate
the correct opcode.

Clarify the G_EXTRACT_SUBVECTOR specification.
2024-09-17 10:08:39 -04:00
Robert Dazi
8837898b8d
[DAGCombine] Count leading ones: refine post DAG/Type Legalisation if promotion (#102877)
This PR is related to #99591. In this PR, instead of modifying how the
legalisation occurs depending on surrounding instructions, we refine
after legalisation.

This PR has two parts:

* `SDPatternMatch/MatchContext`: Modify a little bit the code to match
Operands (used by `m_Node(...)`) and Unary/Binary/Ternary Patterns to
make it compatible with `VPMatchContext`, instead of only `m_Opc`
supported. Some tests were added to ensure no regressions.
* `DAGCombiner`: Add a `foldSubCtlzNot` which detect and rewrite the
patterns using matching context.

Remaining Tasks:

- [ ] GlobalISel
- [ ] Currently the pattern matching will occur even before
legalisation. Should I restrict it to specific stages instead ?
- [ ] Style: Add a visitVP_SUB ?? Move `foldSubCtlzNot` in another
location for style consistency purpose ?

@topperc

---------

Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
2024-09-15 15:48:36 +04:00
JOE1994
387bee91f0 [llvm][unittests] Strip unneeded uses of raw_string_ostream::str() (NFC)
Avoid excess layer of indirection.
2024-09-13 09:42:32 -04:00
Kyungwoo Lee
38c3855c9f
[NFC] Remove unused argument (FuncName) for parseMIR (#106144)
While working on a MIR unittest, I noticed that parseMIR includes an
unused argument that sets a function name. This is not only redundant
but also irrelevant, as parseMIR is designed to parse entire module, not
specific functions, even though most unittests contain a single function
per module. To streamline the API, I have removed this unnecessary
argument from parseMIR. However, if this argument was originally
included to enhance readability or for any other purpose, please let me
know.
2024-08-26 19:19:02 -07:00
Noah Goldstein
70f3863b5f [DAG][PatternMatch] Add support for matchers with flags; NFC
Add support for matching with `SDNodeFlags` i.e `add` with `nuw`.

This patch adds helpers for `or disjoint` or `zext nneg` with the same
names as we have in IR/PatternMatch api.

Closes #103060
2024-08-18 15:37:56 -07:00
v01dXYZ
fc1b019638
[DAG] SD Pattern Match: Operands patterns with VP Context (#103308)
Currently, when using a VP match context with `sd_context_match`, only Opcode matching is possible (`m_Opc(Opcode)`).

This PR suggest a way to make patterns with Operands (eg `m_Node`, `m_Add`, ...) works with a VP context.

This PR blocks another PR https://github.com/llvm/llvm-project/pull/102877.

Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
2024-08-16 09:46:20 +01:00
Jorge Botto
05dfac23f1
[DAG] Adding m_FPToUI and m_FPToSI to SDPatternMatch.h (#104044)
Adds m_FPToUI/m_FPToSI matchers for ISD::FP_TO_UINT/ISD::FP_TO_SINT in SDPatternMatch.h with suitable test coverage.

Fixes https://github.com/llvm/llvm-project/issues/103872
2024-08-15 09:49:40 +01:00
Sergei Barannikov
6cf3e7d067
[DataLayout] Use member initialization (NFC) (#103712)
This also adds a default constructor and a few uses of it.
2024-08-14 15:02:47 +03:00
Rahul Joshi
1753008bbb
[NFC] Eliminate top-level "using namespace" from some headers. (#102751)
- Eliminate top-level "using namespace" from some headers.
2024-08-11 13:10:48 -07:00
Tobias Stadler
d2336fd75c
[RFC][GlobalISel] InstructionSelect: Allow arbitrary instruction erasure (#97670)
See https://discourse.llvm.org/t/rfc-globalisel-instructionselect-allow-arbitrary-instruction-erasure
2024-08-11 17:26:43 +02:00