[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
pcc wrote: > Could we have a test that demonstrates the new better instruction sequence > (by precommiting to show the diff here)? Done, see #143189 https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
https://github.com/fmayer approved this pull request. https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
@@ -2627,6 +2629,93 @@ SDValue DAGCombiner::foldSubToAvg(SDNode *N, const SDLoc &DL) { return SDValue(); } +/// Try to fold a pointer arithmetic node. +/// This needs to be done separately from normal addition, because pointer +/// addition is not commutative. +SDValue DAGCombiner::visitPTRADD(SDNode *N) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT PtrVT = N0.getValueType(); + EVT IntVT = N1.getValueType(); + SDLoc DL(N); + + // This is already ensured by an assert in SelectionDAG::getNode(). Several + // combines here depend on this assumption. + assert(PtrVT == IntVT && + "PTRADD with different operand types is not supported"); + + // fold (ptradd undef, y) -> undef + if (N0.isUndef()) arichardson wrote: Nice, I was not aware of those folds. Do we already have tests for them? If not it would be nice to add one here (but don't consider this a blocker). https://github.com/llvm/llvm-project/pull/142739 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU][SDAG] Add ISD::PTRADD DAG combines (PR #142739)
@@ -2627,6 +2629,93 @@ SDValue DAGCombiner::foldSubToAvg(SDNode *N, const SDLoc &DL) { return SDValue(); } +/// Try to fold a pointer arithmetic node. +/// This needs to be done separately from normal addition, because pointer +/// addition is not commutative. +SDValue DAGCombiner::visitPTRADD(SDNode *N) { + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT PtrVT = N0.getValueType(); + EVT IntVT = N1.getValueType(); + SDLoc DL(N); + + // This is already ensured by an assert in SelectionDAG::getNode(). Several + // combines here depend on this assumption. + assert(PtrVT == IntVT && + "PTRADD with different operand types is not supported"); + + // fold (ptradd undef, y) -> undef + if (N0.isUndef()) +return N0; + + // fold (ptradd x, undef) -> undef + if (N1.isUndef()) +return DAG.getUNDEF(PtrVT); + + // fold (ptradd x, 0) -> x + if (isNullConstant(N1)) +return N0; + + // fold (ptradd 0, x) -> x + if (isNullConstant(N0)) arichardson wrote: We already know this condition is needed, so I'd prefer adding here so we don't need to make this change once we relax the existing assertions. But I don't feel strongly about this so happy with either. https://github.com/llvm/llvm-project/pull/142739 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Shrink check size by 1 instruction on x86. (PR #142887)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142887 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Move soft float predicate management into RuntimeLibcalls (PR #142905)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142905 >From b7f272ac4eabec9781dc5634f485ab4e55451272 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 14:22:55 +0900 Subject: [PATCH] DAG: Move soft float predicate management into RuntimeLibcalls Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate. --- llvm/include/llvm/CodeGen/TargetLowering.h| 14 +- llvm/include/llvm/IR/RuntimeLibcalls.h| 25 +++ .../CodeGen/SelectionDAG/TargetLowering.cpp | 5 +- llvm/lib/IR/RuntimeLibcalls.cpp | 36 llvm/lib/Target/ARM/ARMISelLowering.cpp | 178 +- llvm/lib/Target/MSP430/MSP430ISelLowering.cpp | 130 ++--- 6 files changed, 224 insertions(+), 164 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 9c453f51e129d..0d157de479141 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -3572,20 +3572,18 @@ class LLVM_ABI TargetLoweringBase { /// Override the default CondCode to be used to test the result of the /// comparison libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { -CmpLibcallCCs[Call] = CC; + /// FIXME: This should be removed + void setCmpLibcallCC(RTLIB::Libcall Call, CmpInst::Predicate Pred) { +Libcalls.setSoftFloatCmpLibcallPredicate(Call, Pred); } - /// Get the CondCode that's to be used to test the result of the comparison /// libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { -return CmpLibcallCCs[Call]; + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return Libcalls.getSoftFloatCmpLibcallPredicate(Call); } - /// Set the CallingConv that should be used for the specified libcall. void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { Libcalls.setLibcallCallingConv(Call, CC); diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 26c085031a48a..6cc65fabfcc99 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -16,6 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/Triple.h" @@ -73,6 +74,20 @@ struct RuntimeLibcallsInfo { LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL); } + /// Get the comparison predicate that's to be used to test the result of the + /// comparison libcall against zero. This should only be used with + /// floating-point compare libcalls. + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return SoftFloatCompareLibcallPredicates[Call]; + } + + // FIXME: This should be removed. This should be private constant. + void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call, + CmpInst::Predicate Pred) { +SoftFloatCompareLibcallPredicates[Call] = Pred; + } + private: /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; @@ -80,6 +95,14 @@ struct RuntimeLibcallsInfo { /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + /// The condition type that should be used to test the result of each of the + /// soft floating-point comparison libcall against integer zero. + /// + // FIXME: This is only relevant for the handful of floating-point comparison + // runtime calls; it's excessive to have a table entry for every single + // opcode. + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + static bool darwinHasSinCos(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. @@ -95,6 +118,8 @@ struct RuntimeLibcallsInfo { return true; } + void initSoftFloatCmpLibcallPredicates(); + /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. LLVM_ABI void initLibcalls(const Triple &TT); diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 4472a031c39f6..5105c4a515fbe 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ValueTrackin
[llvm-branch-commits] [llvm] CodeGen: Move ABI option enums to support (PR #142912)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142912 >From 652f127a73b802cda717980206af343fef7b16ea Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 16:08:26 +0900 Subject: [PATCH] CodeGen: Move ABI option enums to support Move these out of TargetOptions and into Support to avoid the dependency on Target. There are similar ABI options already in Support/CodeGen.h. --- llvm/include/llvm/Support/CodeGen.h | 16 llvm/include/llvm/Target/TargetOptions.h | 17 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h index 0e42789ba932e..b7896ae5d0f83 100644 --- a/llvm/include/llvm/Support/CodeGen.h +++ b/llvm/include/llvm/Support/CodeGen.h @@ -50,6 +50,22 @@ namespace llvm { }; } + namespace FloatABI { + enum ABIType { +Default, // Target-specific (either soft or hard depending on triple, etc). +Soft,// Soft float. +Hard // Hard float. + }; + } + + enum class EABI { +Unknown, +Default, // Default means not specified +EABI4, // Target-specific (either 4, 5 or gnu depending on triple). +EABI5, +GNU + }; + /// Code generation optimization level. enum class CodeGenOptLevel { None = 0, ///< -O0 diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index fd8dad4f6f791..08d6aa36e19d8 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -16,6 +16,7 @@ #include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" +#include "llvm/Support/CodeGen.h" #include @@ -24,14 +25,6 @@ namespace llvm { class MachineFunction; class MemoryBuffer; - namespace FloatABI { -enum ABIType { - Default, // Target-specific (either soft or hard depending on triple, etc). - Soft,// Soft float. - Hard // Hard float. -}; - } - namespace FPOpFusion { enum FPOpFusionMode { Fast, // Enable fusion of FP ops wherever it's profitable. @@ -70,14 +63,6 @@ namespace llvm { None// Do not use Basic Block Sections. }; - enum class EABI { -Unknown, -Default, // Default means not specified -EABI4, // Target-specific (either 4, 5 or gnu depending on triple). -EABI5, -GNU - }; - /// Identify a debugger for "tuning" the debug info. /// /// The "debugger tuning" concept allows us to present a more intuitive ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082 >From 0e8bba5f220c3e605fd055f618b87404fec63791 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 14:50:57 +0900 Subject: [PATCH] RuntimeLibcalls: Use array initializers for default values --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +--- llvm/lib/IR/RuntimeLibcalls.cpp| 10 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index d2704d5aa2616..d67430968edf1 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -90,10 +90,11 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. @@ -101,7 +102,8 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index a6fda0cfeadd2..01978b7ae39e3 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -12,9 +12,6 @@ using namespace llvm; using namespace RTLIB; void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { - std::fill(SoftFloatCompareLibcallPredicates, -SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL, -CmpInst::BAD_ICMP_PREDICATE); SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ; @@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { - std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), -nullptr); - initSoftFloatCmpLibcallPredicates(); #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name); #include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL - // Initialize calling conventions to their default. - for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) -setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C); - // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) { setLibcallName(RTLIB::REM_F128, "fmodf128"); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Move soft float predicate management into RuntimeLibcalls (PR #142905)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142905 >From b7f272ac4eabec9781dc5634f485ab4e55451272 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 14:22:55 +0900 Subject: [PATCH] DAG: Move soft float predicate management into RuntimeLibcalls Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate. --- llvm/include/llvm/CodeGen/TargetLowering.h| 14 +- llvm/include/llvm/IR/RuntimeLibcalls.h| 25 +++ .../CodeGen/SelectionDAG/TargetLowering.cpp | 5 +- llvm/lib/IR/RuntimeLibcalls.cpp | 36 llvm/lib/Target/ARM/ARMISelLowering.cpp | 178 +- llvm/lib/Target/MSP430/MSP430ISelLowering.cpp | 130 ++--- 6 files changed, 224 insertions(+), 164 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 9c453f51e129d..0d157de479141 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -3572,20 +3572,18 @@ class LLVM_ABI TargetLoweringBase { /// Override the default CondCode to be used to test the result of the /// comparison libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { -CmpLibcallCCs[Call] = CC; + /// FIXME: This should be removed + void setCmpLibcallCC(RTLIB::Libcall Call, CmpInst::Predicate Pred) { +Libcalls.setSoftFloatCmpLibcallPredicate(Call, Pred); } - /// Get the CondCode that's to be used to test the result of the comparison /// libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { -return CmpLibcallCCs[Call]; + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return Libcalls.getSoftFloatCmpLibcallPredicate(Call); } - /// Set the CallingConv that should be used for the specified libcall. void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { Libcalls.setLibcallCallingConv(Call, CC); diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 26c085031a48a..6cc65fabfcc99 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -16,6 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/Triple.h" @@ -73,6 +74,20 @@ struct RuntimeLibcallsInfo { LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL); } + /// Get the comparison predicate that's to be used to test the result of the + /// comparison libcall against zero. This should only be used with + /// floating-point compare libcalls. + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return SoftFloatCompareLibcallPredicates[Call]; + } + + // FIXME: This should be removed. This should be private constant. + void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call, + CmpInst::Predicate Pred) { +SoftFloatCompareLibcallPredicates[Call] = Pred; + } + private: /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; @@ -80,6 +95,14 @@ struct RuntimeLibcallsInfo { /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + /// The condition type that should be used to test the result of each of the + /// soft floating-point comparison libcall against integer zero. + /// + // FIXME: This is only relevant for the handful of floating-point comparison + // runtime calls; it's excessive to have a table entry for every single + // opcode. + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + static bool darwinHasSinCos(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. @@ -95,6 +118,8 @@ struct RuntimeLibcallsInfo { return true; } + void initSoftFloatCmpLibcallPredicates(); + /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. LLVM_ABI void initLibcalls(const Triple &TT); diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 4472a031c39f6..5105c4a515fbe 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ValueTrackin
[llvm-branch-commits] [llvm] RuntimeLibcalls: Cleanup sincos predicate functions (PR #143081)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143081 >From 65cb831537a4c11c063a57a30afb3549b70a84ca Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 15:15:53 +0900 Subject: [PATCH] RuntimeLibcalls: Cleanup sincos predicate functions The darwinHasSinCos wasn't actually used for sincos, only the stret variant. Rename this to reflect that, and introduce a new one for enabling sincos. --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +++- llvm/lib/IR/RuntimeLibcalls.cpp| 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 6cc65fabfcc99..d2704d5aa2616 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -103,7 +103,7 @@ struct RuntimeLibcallsInfo { // opcode. CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; - static bool darwinHasSinCos(const Triple &TT) { + static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. if (TT.getArch() == Triple::x86) @@ -118,6 +118,12 @@ struct RuntimeLibcallsInfo { return true; } + /// Return true if the target has sincosf/sincos/sincosl functions + static bool hasSinCos(const Triple &TT) { +return TT.isGNUEnvironment() || TT.isOSFuchsia() || + (TT.isAndroid() && !TT.isAndroidVersionLT(9)); + } + void initSoftFloatCmpLibcallPredicates(); /// Set default libcall names. If a target wants to opt-out of a libcall it diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 91f303c9e3d3c..a6fda0cfeadd2 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -170,7 +170,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { break; } -if (darwinHasSinCos(TT)) { +if (darwinHasSinCosStret(TT)) { setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret"); setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret"); if (TT.isWatchABI()) { @@ -214,8 +214,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { setLibcallName(RTLIB::EXP10_F64, "__exp10"); } - if (TT.isGNUEnvironment() || TT.isOSFuchsia() || - (TT.isAndroid() && !TT.isAndroidVersionLT(9))) { + if (hasSinCos(TT)) { setLibcallName(RTLIB::SINCOS_F32, "sincosf"); setLibcallName(RTLIB::SINCOS_F64, "sincos"); setLibcallName(RTLIB::SINCOS_F80, "sincosl"); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] CodeGen: Move ABI option enums to support (PR #142912)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142912 >From 652f127a73b802cda717980206af343fef7b16ea Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 16:08:26 +0900 Subject: [PATCH] CodeGen: Move ABI option enums to support Move these out of TargetOptions and into Support to avoid the dependency on Target. There are similar ABI options already in Support/CodeGen.h. --- llvm/include/llvm/Support/CodeGen.h | 16 llvm/include/llvm/Target/TargetOptions.h | 17 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h index 0e42789ba932e..b7896ae5d0f83 100644 --- a/llvm/include/llvm/Support/CodeGen.h +++ b/llvm/include/llvm/Support/CodeGen.h @@ -50,6 +50,22 @@ namespace llvm { }; } + namespace FloatABI { + enum ABIType { +Default, // Target-specific (either soft or hard depending on triple, etc). +Soft,// Soft float. +Hard // Hard float. + }; + } + + enum class EABI { +Unknown, +Default, // Default means not specified +EABI4, // Target-specific (either 4, 5 or gnu depending on triple). +EABI5, +GNU + }; + /// Code generation optimization level. enum class CodeGenOptLevel { None = 0, ///< -O0 diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index fd8dad4f6f791..08d6aa36e19d8 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -16,6 +16,7 @@ #include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" +#include "llvm/Support/CodeGen.h" #include @@ -24,14 +25,6 @@ namespace llvm { class MachineFunction; class MemoryBuffer; - namespace FloatABI { -enum ABIType { - Default, // Target-specific (either soft or hard depending on triple, etc). - Soft,// Soft float. - Hard // Hard float. -}; - } - namespace FPOpFusion { enum FPOpFusionMode { Fast, // Enable fusion of FP ops wherever it's profitable. @@ -70,14 +63,6 @@ namespace llvm { None// Do not use Basic Block Sections. }; - enum class EABI { -Unknown, -Default, // Default means not specified -EABI4, // Target-specific (either 4, 5 or gnu depending on triple). -EABI5, -GNU - }; - /// Identify a debugger for "tuning" the debug info. /// /// The "debugger tuning" concept allows us to present a more intuitive ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082 >From 0e8bba5f220c3e605fd055f618b87404fec63791 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 14:50:57 +0900 Subject: [PATCH] RuntimeLibcalls: Use array initializers for default values --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +--- llvm/lib/IR/RuntimeLibcalls.cpp| 10 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index d2704d5aa2616..d67430968edf1 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -90,10 +90,11 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. @@ -101,7 +102,8 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index a6fda0cfeadd2..01978b7ae39e3 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -12,9 +12,6 @@ using namespace llvm; using namespace RTLIB; void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { - std::fill(SoftFloatCompareLibcallPredicates, -SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL, -CmpInst::BAD_ICMP_PREDICATE); SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ; @@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { - std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), -nullptr); - initSoftFloatCmpLibcallPredicates(); #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name); #include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL - // Initialize calling conventions to their default. - for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) -setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C); - // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) { setLibcallName(RTLIB::REM_F128, "fmodf128"); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
@@ -90,18 +90,20 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. /// // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; DanielKristofKiss wrote: CmpInst::BAD_ICMP_PREDICATE is not zero (42) so only the first element of the array will be initialized to `CmpInst::BAD_ICMP_PREDICATE` rest will be zero. https://github.com/llvm/llvm-project/pull/143082 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Cleanup sincos predicate functions (PR #143081)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143081 >From 65cb831537a4c11c063a57a30afb3549b70a84ca Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 15:15:53 +0900 Subject: [PATCH] RuntimeLibcalls: Cleanup sincos predicate functions The darwinHasSinCos wasn't actually used for sincos, only the stret variant. Rename this to reflect that, and introduce a new one for enabling sincos. --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +++- llvm/lib/IR/RuntimeLibcalls.cpp| 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 6cc65fabfcc99..d2704d5aa2616 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -103,7 +103,7 @@ struct RuntimeLibcallsInfo { // opcode. CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; - static bool darwinHasSinCos(const Triple &TT) { + static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. if (TT.getArch() == Triple::x86) @@ -118,6 +118,12 @@ struct RuntimeLibcallsInfo { return true; } + /// Return true if the target has sincosf/sincos/sincosl functions + static bool hasSinCos(const Triple &TT) { +return TT.isGNUEnvironment() || TT.isOSFuchsia() || + (TT.isAndroid() && !TT.isAndroidVersionLT(9)); + } + void initSoftFloatCmpLibcallPredicates(); /// Set default libcall names. If a target wants to opt-out of a libcall it diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 91f303c9e3d3c..a6fda0cfeadd2 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -170,7 +170,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { break; } -if (darwinHasSinCos(TT)) { +if (darwinHasSinCosStret(TT)) { setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret"); setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret"); if (TT.isWatchABI()) { @@ -214,8 +214,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { setLibcallName(RTLIB::EXP10_F64, "__exp10"); } - if (TT.isGNUEnvironment() || TT.isOSFuchsia() || - (TT.isAndroid() && !TT.isAndroidVersionLT(9))) { + if (hasSinCos(TT)) { setLibcallName(RTLIB::SINCOS_F32, "sincosf"); setLibcallName(RTLIB::SINCOS_F64, "sincos"); setLibcallName(RTLIB::SINCOS_F80, "sincosl"); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
@@ -630,7 +639,10 @@ class FlattenContiguousRowMajorTransferReadPattern if (transferReadOp.getMask()) return failure(); -int64_t firstDimToCollapse = sourceType.getRank() - vectorType.getRank(); momchil-velikov wrote: With leading unit dimensions of a vector, the memref might not even be contiguous on that many dimensions. Example: `memref<2x2x2xi8, strided<[8, 4, 1]>` and `vector<1x1x2xi8>` Another consideration, in principle a memref can be collapsed in several different ways for given memref and vector types, anywhere from losing just one dimension to just one dimension remaining. I've chosen to do maximum collapsing, as it seems simpler to do, and the resulting IR is arguably simpler. https://github.com/llvm/llvm-project/pull/142422 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors (PR #143146)
llvmbot wrote: @llvm/pr-subscribers-mlir-sve Author: Momchil Velikov (momchil-velikov) Changes THis patch add a transform of `transfer_read` operation to change the vector type to one that can be mapped to an LLVM type. This is done by collapsing trailing dimensions so we obtain a vector type with a single scalable dimension in the rightmost position. --- Full diff: https://github.com/llvm/llvm-project/pull/143146.diff 3 Files Affected: - (modified) mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp (+109-1) - (added) mlir/test/Dialect/ArmSVE/legalize-transfer-read.mlir (+226) - (added) mlir/test/Integration/Dialect/Vector/CPU/ArmSVE/transfer-read-scalable-not-rightmost.mlir (+72) ``diff diff --git a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp index d2ac850a5f70b..f16d33c004fec 100644 --- a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp +++ b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp @@ -298,6 +298,113 @@ struct LegalizeSVEMaskLoadConversion : public OpRewritePattern { } }; +/// Transforms a `transfer_read` operation so it reads vector of a type that +/// can be mapped to an LLVM type. This is done by collapsing trailing +/// dimensions so we obtain a vector type with a single scalable dimension in +/// the rightmost position. +/// +/// Example: +/// ``` +/// %v = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 +/// {in_bounds = [false, true, true, true]} +/// : memref, vector<2x[4]x2x8xi8> +/// ``` +/// is rewriten to +/// ``` +/// %collapse_shape = memref.collapse_shape %M [[0], [1, 2, 3]] +/// : memref into memref +/// %0 = vector.transfer_read %collapse_shape[%i, %j], %c0_i8 +/// {in_bounds = [false, true]} +/// : memref, vector<2x[64]xi8> +/// %1 = vector.shape_cast %0 : vector<2x[64]xi8> to vector<2x[4]x2x8xi8> +/// ``` +struct LegalizeTransferRead : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(vector::TransferReadOp readOp, +PatternRewriter &rewriter) const override { + +if (!readOp.getPermutationMap().isMinorIdentity()) + return rewriter.notifyMatchFailure(readOp, "non-identity permutation"); + +// We handle transfers of vectors with rank >= 2 and a single scalable +// dimension. +VectorType origVT = readOp.getVectorType(); +ArrayRef origScalableDims = origVT.getScalableDims(); +const int64_t origVRank = origVT.getRank(); +if (origVRank < 2 || llvm::count(origScalableDims, true) != 1) + return rewriter.notifyMatchFailure(readOp, "wrong dimensions"); + +// Number of trailing dimensions to collapse, including the scalable +// dimension. Nothing to do if the single scalable dimension is already the +// last one. +const int64_t numCollapseDims = std::distance( +llvm::find(origScalableDims, true), origScalableDims.end()); +if (numCollapseDims < 2) + return rewriter.notifyMatchFailure(readOp, + "scalable dimension is trailing"); + +// We want a simple memref (not a tensor) with contiguous elements for at +// least all the trailing dimensions up to and including the scalable one. +auto memTy = dyn_cast(readOp.getBase().getType()); +if (!(memTy && memTy.areTrailingDimsContiguous(numCollapseDims))) + return rewriter.notifyMatchFailure( + readOp, "non-contiguous memref dimensions to collapse"); + +// The collapsed dimensions (excluding the scalable one) of the vector and +// the memref must match and the corresponding indices must be in-bounds (it +// follows these indices would be zero). This guarantees that the operation +// transfers a contiguous block. +if (!llvm::equal(memTy.getShape().take_back(numCollapseDims - 1), + origVT.getShape().take_back(numCollapseDims - 1))) + return rewriter.notifyMatchFailure( + readOp, "memref and vector dimensions do not match"); + +SmallVector origInBounds = readOp.getInBoundsValues(); +if (!llvm::all_of( +ArrayRef(origInBounds).take_back(numCollapseDims - 1), +[](bool v) { return v; })) + return rewriter.notifyMatchFailure(readOp, + "out-if-bounds index to collapse"); + +// Collapse the trailing dimensions of the memref. +SmallVector reassoc; +for (int64_t i = 0; i < memTy.getRank() - numCollapseDims + 1; ++i) + reassoc.push_back({i}); +for (int64_t i = memTy.getRank() - numCollapseDims + 1; i < memTy.getRank(); + ++i) + reassoc.back().push_back(i); +if (!memref::CollapseShapeOp::isGuaranteedCollapsible(memTy, reassoc)) + return failure(); +Value collapsedMem = rewriter.create( +readOp.getLoc(), readOp.getBase(), reassoc); + +// Get a vector type with collapsed trailing dimens
[llvm-branch-commits] [mlir] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors (PR #143146)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp -- mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp `` View the diff from clang-format here. ``diff diff --git a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp index f16d33c00..da36f346c 100644 --- a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp +++ b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp @@ -409,13 +409,13 @@ struct LegalizeTransferRead : public OpRewritePattern { void mlir::arm_sve::populateLegalizeVectorStoragePatterns( RewritePatternSet &patterns) { - patterns.add, - LegalizeSVEMaskAllocation, - LegalizeSVEMaskTypeCastConversion, - LegalizeSVEMaskStoreConversion, LegalizeSVEMaskLoadConversion, - LegalizeTransferRead>( - patterns.getContext()); + patterns + .add, + LegalizeSVEMaskAllocation, + LegalizeSVEMaskTypeCastConversion, LegalizeSVEMaskStoreConversion, + LegalizeSVEMaskLoadConversion, LegalizeTransferRead>( + patterns.getContext()); } namespace { `` https://github.com/llvm/llvm-project/pull/143146 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors (PR #143146)
https://github.com/momchil-velikov created https://github.com/llvm/llvm-project/pull/143146 THis patch add a transform of `transfer_read` operation to change the vector type to one that can be mapped to an LLVM type. This is done by collapsing trailing dimensions so we obtain a vector type with a single scalable dimension in the rightmost position. >From 62ad29ddc4d8c1ffa7c5af5dbadd9bb0647964ea Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Wed, 14 May 2025 09:03:49 + Subject: [PATCH] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors THis patch add a transform of `transfer_read` operation to change the vector type to one that can be mapped to an LLVM type. This is done by collapsing trailing dimensions so we obtain a vector type with a single scalable dimension in the rightmost position. --- .../Transforms/LegalizeVectorStorage.cpp | 110 - .../ArmSVE/legalize-transfer-read.mlir| 226 ++ .../transfer-read-scalable-not-rightmost.mlir | 72 ++ 3 files changed, 407 insertions(+), 1 deletion(-) create mode 100644 mlir/test/Dialect/ArmSVE/legalize-transfer-read.mlir create mode 100644 mlir/test/Integration/Dialect/Vector/CPU/ArmSVE/transfer-read-scalable-not-rightmost.mlir diff --git a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp index d2ac850a5f70b..f16d33c004fec 100644 --- a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp +++ b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp @@ -298,6 +298,113 @@ struct LegalizeSVEMaskLoadConversion : public OpRewritePattern { } }; +/// Transforms a `transfer_read` operation so it reads vector of a type that +/// can be mapped to an LLVM type. This is done by collapsing trailing +/// dimensions so we obtain a vector type with a single scalable dimension in +/// the rightmost position. +/// +/// Example: +/// ``` +/// %v = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 +/// {in_bounds = [false, true, true, true]} +/// : memref, vector<2x[4]x2x8xi8> +/// ``` +/// is rewriten to +/// ``` +/// %collapse_shape = memref.collapse_shape %M [[0], [1, 2, 3]] +/// : memref into memref +/// %0 = vector.transfer_read %collapse_shape[%i, %j], %c0_i8 +/// {in_bounds = [false, true]} +/// : memref, vector<2x[64]xi8> +/// %1 = vector.shape_cast %0 : vector<2x[64]xi8> to vector<2x[4]x2x8xi8> +/// ``` +struct LegalizeTransferRead : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(vector::TransferReadOp readOp, +PatternRewriter &rewriter) const override { + +if (!readOp.getPermutationMap().isMinorIdentity()) + return rewriter.notifyMatchFailure(readOp, "non-identity permutation"); + +// We handle transfers of vectors with rank >= 2 and a single scalable +// dimension. +VectorType origVT = readOp.getVectorType(); +ArrayRef origScalableDims = origVT.getScalableDims(); +const int64_t origVRank = origVT.getRank(); +if (origVRank < 2 || llvm::count(origScalableDims, true) != 1) + return rewriter.notifyMatchFailure(readOp, "wrong dimensions"); + +// Number of trailing dimensions to collapse, including the scalable +// dimension. Nothing to do if the single scalable dimension is already the +// last one. +const int64_t numCollapseDims = std::distance( +llvm::find(origScalableDims, true), origScalableDims.end()); +if (numCollapseDims < 2) + return rewriter.notifyMatchFailure(readOp, + "scalable dimension is trailing"); + +// We want a simple memref (not a tensor) with contiguous elements for at +// least all the trailing dimensions up to and including the scalable one. +auto memTy = dyn_cast(readOp.getBase().getType()); +if (!(memTy && memTy.areTrailingDimsContiguous(numCollapseDims))) + return rewriter.notifyMatchFailure( + readOp, "non-contiguous memref dimensions to collapse"); + +// The collapsed dimensions (excluding the scalable one) of the vector and +// the memref must match and the corresponding indices must be in-bounds (it +// follows these indices would be zero). This guarantees that the operation +// transfers a contiguous block. +if (!llvm::equal(memTy.getShape().take_back(numCollapseDims - 1), + origVT.getShape().take_back(numCollapseDims - 1))) + return rewriter.notifyMatchFailure( + readOp, "memref and vector dimensions do not match"); + +SmallVector origInBounds = readOp.getInBoundsValues(); +if (!llvm::all_of( +ArrayRef(origInBounds).take_back(numCollapseDims - 1), +[](bool v) { return v; })) + return rewriter.notifyMatchFailure(readOp, + "out-if-bounds index to collapse"); + +// Collapse the trailing dimension
[llvm-branch-commits] [llvm] WebAssembly: Stop directly using RuntimeLibcalls.def (PR #143054)
@@ -528,23 +528,20 @@ RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() { // constructor for use with a static variable struct StaticLibcallNameMap { StringMap Map; - StaticLibcallNameMap() { -static const std::pair NameLibcalls[] = { -#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code}, -#include "llvm/IR/RuntimeLibcalls.def" -#undef HANDLE_LIBCALL -}; -for (const auto &NameLibcall : NameLibcalls) { - if (NameLibcall.first != nullptr && - getRuntimeLibcallSignatures().Table[NameLibcall.second] != - unsupported) { -assert(!Map.contains(NameLibcall.first) && + StaticLibcallNameMap(const Triple &TT) { +// FIXME: This is broken if there are ever different triples compiled with +// different libcalls. arsenm wrote: This belongs in TargetLowering, which is owned by the subtarget. I'll probably end up fixing this in the next step after moving the definitions to tablegen https://github.com/llvm/llvm-project/pull/143054 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
@@ -90,18 +90,20 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. /// // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; arsenm wrote: There's no actual reason to initialize this, the only fields that are used are explicitly initialized separately. We should shrink the array as the FIXME says https://github.com/llvm/llvm-project/pull/143082 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] CodeGen: Move ABI option enums to support (PR #142912)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142912 >From 2168b667f1655c8be75afe887ad1df3d93477b66 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 16:08:26 +0900 Subject: [PATCH] CodeGen: Move ABI option enums to support Move these out of TargetOptions and into Support to avoid the dependency on Target. There are similar ABI options already in Support/CodeGen.h. --- llvm/include/llvm/Support/CodeGen.h | 16 llvm/include/llvm/Target/TargetOptions.h | 17 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h index 0e42789ba932e..b7896ae5d0f83 100644 --- a/llvm/include/llvm/Support/CodeGen.h +++ b/llvm/include/llvm/Support/CodeGen.h @@ -50,6 +50,22 @@ namespace llvm { }; } + namespace FloatABI { + enum ABIType { +Default, // Target-specific (either soft or hard depending on triple, etc). +Soft,// Soft float. +Hard // Hard float. + }; + } + + enum class EABI { +Unknown, +Default, // Default means not specified +EABI4, // Target-specific (either 4, 5 or gnu depending on triple). +EABI5, +GNU + }; + /// Code generation optimization level. enum class CodeGenOptLevel { None = 0, ///< -O0 diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index fd8dad4f6f791..08d6aa36e19d8 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -16,6 +16,7 @@ #include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" +#include "llvm/Support/CodeGen.h" #include @@ -24,14 +25,6 @@ namespace llvm { class MachineFunction; class MemoryBuffer; - namespace FloatABI { -enum ABIType { - Default, // Target-specific (either soft or hard depending on triple, etc). - Soft,// Soft float. - Hard // Hard float. -}; - } - namespace FPOpFusion { enum FPOpFusionMode { Fast, // Enable fusion of FP ops wherever it's profitable. @@ -70,14 +63,6 @@ namespace llvm { None// Do not use Basic Block Sections. }; - enum class EABI { -Unknown, -Default, // Default means not specified -EABI4, // Target-specific (either 4, 5 or gnu depending on triple). -EABI5, -GNU - }; - /// Identify a debugger for "tuning" the debug info. /// /// The "debugger tuning" concept allows us to present a more intuitive ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082 >From 67d040367f97806e16a658acff3427aa2396e8e4 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 14:50:57 +0900 Subject: [PATCH 1/2] RuntimeLibcalls: Use array initializers for default values --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +--- llvm/lib/IR/RuntimeLibcalls.cpp| 10 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 6d8f007136153..c98a63a41d2bd 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -103,10 +103,11 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. @@ -114,7 +115,8 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 7c0ffe170e196..b85a878887dec 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -12,9 +12,6 @@ using namespace llvm; using namespace RTLIB; void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { - std::fill(SoftFloatCompareLibcallPredicates, -SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL, -CmpInst::BAD_ICMP_PREDICATE); SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ; @@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { - std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), -nullptr); - initSoftFloatCmpLibcallPredicates(); #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name); #include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL - // Initialize calling conventions to their default. - for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) -setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C); - // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) { setLibcallName(RTLIB::REM_F128, "fmodf128"); >From f991879aeb7fc4c3f30dd142154bb2f063acaaa0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 22:59:15 +0900 Subject: [PATCH 2/2] Revert for compare predicate case --- llvm/include/llvm/IR/RuntimeLibcalls.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index c98a63a41d2bd..bf29b03a18ab2 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -105,6 +105,9 @@ struct RuntimeLibcallsInfo { /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; + static_assert(static_cast(CallingConv::C) == 0, +"default calling conv should be encoded as 0"); + /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { CallingConv::C}; @@ -115,8 +118,7 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = - {CmpInst::BAD_ICMP_PREDICATE}; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); ___ llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Move soft float predicate management into RuntimeLibcalls (PR #142905)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142905 >From e245a542fc0b5210f84dcae77875d97024954464 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 14:22:55 +0900 Subject: [PATCH] DAG: Move soft float predicate management into RuntimeLibcalls Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate. --- llvm/include/llvm/CodeGen/TargetLowering.h| 14 +- llvm/include/llvm/IR/RuntimeLibcalls.h| 25 +++ .../CodeGen/SelectionDAG/TargetLowering.cpp | 5 +- llvm/lib/IR/RuntimeLibcalls.cpp | 36 llvm/lib/Target/ARM/ARMISelLowering.cpp | 178 +- llvm/lib/Target/MSP430/MSP430ISelLowering.cpp | 130 ++--- 6 files changed, 224 insertions(+), 164 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 9c453f51e129d..0d157de479141 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -3572,20 +3572,18 @@ class LLVM_ABI TargetLoweringBase { /// Override the default CondCode to be used to test the result of the /// comparison libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { -CmpLibcallCCs[Call] = CC; + /// FIXME: This should be removed + void setCmpLibcallCC(RTLIB::Libcall Call, CmpInst::Predicate Pred) { +Libcalls.setSoftFloatCmpLibcallPredicate(Call, Pred); } - /// Get the CondCode that's to be used to test the result of the comparison /// libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { -return CmpLibcallCCs[Call]; + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return Libcalls.getSoftFloatCmpLibcallPredicate(Call); } - /// Set the CallingConv that should be used for the specified libcall. void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { Libcalls.setLibcallCallingConv(Call, CC); diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 89e466ee5933d..e5adcd33411c5 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -17,6 +17,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Sequence.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/Triple.h" @@ -86,6 +87,20 @@ struct RuntimeLibcallsInfo { LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL); } + /// Get the comparison predicate that's to be used to test the result of the + /// comparison libcall against zero. This should only be used with + /// floating-point compare libcalls. + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return SoftFloatCompareLibcallPredicates[Call]; + } + + // FIXME: This should be removed. This should be private constant. + void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call, + CmpInst::Predicate Pred) { +SoftFloatCompareLibcallPredicates[Call] = Pred; + } + private: /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; @@ -93,6 +108,14 @@ struct RuntimeLibcallsInfo { /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + /// The condition type that should be used to test the result of each of the + /// soft floating-point comparison libcall against integer zero. + /// + // FIXME: This is only relevant for the handful of floating-point comparison + // runtime calls; it's excessive to have a table entry for every single + // opcode. + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + static bool darwinHasSinCos(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. @@ -108,6 +131,8 @@ struct RuntimeLibcallsInfo { return true; } + void initSoftFloatCmpLibcallPredicates(); + /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. LLVM_ABI void initLibcalls(const Triple &TT); diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 4472a031c39f6..5105c4a515fbe 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/STLExtras.h" #inc
[llvm-branch-commits] [llvm] RuntimeLibcalls: Cleanup sincos predicate functions (PR #143081)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143081 >From 6e17ae5561d94e7da70fd1dee50b5c484f6ec34e Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 15:15:53 +0900 Subject: [PATCH] RuntimeLibcalls: Cleanup sincos predicate functions The darwinHasSinCos wasn't actually used for sincos, only the stret variant. Rename this to reflect that, and introduce a new one for enabling sincos. --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +++- llvm/lib/IR/RuntimeLibcalls.cpp| 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index e5adcd33411c5..6d8f007136153 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -116,7 +116,7 @@ struct RuntimeLibcallsInfo { // opcode. CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; - static bool darwinHasSinCos(const Triple &TT) { + static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. if (TT.getArch() == Triple::x86) @@ -131,6 +131,12 @@ struct RuntimeLibcallsInfo { return true; } + /// Return true if the target has sincosf/sincos/sincosl functions + static bool hasSinCos(const Triple &TT) { +return TT.isGNUEnvironment() || TT.isOSFuchsia() || + (TT.isAndroid() && !TT.isAndroidVersionLT(9)); + } + void initSoftFloatCmpLibcallPredicates(); /// Set default libcall names. If a target wants to opt-out of a libcall it diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 586b9721cdd32..7c0ffe170e196 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -170,7 +170,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { break; } -if (darwinHasSinCos(TT)) { +if (darwinHasSinCosStret(TT)) { setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret"); setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret"); if (TT.isWatchABI()) { @@ -214,8 +214,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { setLibcallName(RTLIB::EXP10_F64, "__exp10"); } - if (TT.isGNUEnvironment() || TT.isOSFuchsia() || - (TT.isAndroid() && !TT.isAndroidVersionLT(9))) { + if (hasSinCos(TT)) { setLibcallName(RTLIB::SINCOS_F32, "sincosf"); setLibcallName(RTLIB::SINCOS_F64, "sincos"); setLibcallName(RTLIB::SINCOS_F80, "sincosl"); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082 >From 67d040367f97806e16a658acff3427aa2396e8e4 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 14:50:57 +0900 Subject: [PATCH 1/2] RuntimeLibcalls: Use array initializers for default values --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +--- llvm/lib/IR/RuntimeLibcalls.cpp| 10 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 6d8f007136153..c98a63a41d2bd 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -103,10 +103,11 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. @@ -114,7 +115,8 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 7c0ffe170e196..b85a878887dec 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -12,9 +12,6 @@ using namespace llvm; using namespace RTLIB; void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { - std::fill(SoftFloatCompareLibcallPredicates, -SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL, -CmpInst::BAD_ICMP_PREDICATE); SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ; @@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { - std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), -nullptr); - initSoftFloatCmpLibcallPredicates(); #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name); #include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL - // Initialize calling conventions to their default. - for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) -setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C); - // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) { setLibcallName(RTLIB::REM_F128, "fmodf128"); >From f991879aeb7fc4c3f30dd142154bb2f063acaaa0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 22:59:15 +0900 Subject: [PATCH 2/2] Revert for compare predicate case --- llvm/include/llvm/IR/RuntimeLibcalls.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index c98a63a41d2bd..bf29b03a18ab2 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -105,6 +105,9 @@ struct RuntimeLibcallsInfo { /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; + static_assert(static_cast(CallingConv::C) == 0, +"default calling conv should be encoded as 0"); + /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { CallingConv::C}; @@ -115,8 +118,7 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = - {CmpInst::BAD_ICMP_PREDICATE}; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); ___ llvm-branch-commits
[llvm-branch-commits] [llvm] CodeGen: Move ABI option enums to support (PR #142912)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142912 >From 2168b667f1655c8be75afe887ad1df3d93477b66 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 16:08:26 +0900 Subject: [PATCH] CodeGen: Move ABI option enums to support Move these out of TargetOptions and into Support to avoid the dependency on Target. There are similar ABI options already in Support/CodeGen.h. --- llvm/include/llvm/Support/CodeGen.h | 16 llvm/include/llvm/Target/TargetOptions.h | 17 + 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Support/CodeGen.h b/llvm/include/llvm/Support/CodeGen.h index 0e42789ba932e..b7896ae5d0f83 100644 --- a/llvm/include/llvm/Support/CodeGen.h +++ b/llvm/include/llvm/Support/CodeGen.h @@ -50,6 +50,22 @@ namespace llvm { }; } + namespace FloatABI { + enum ABIType { +Default, // Target-specific (either soft or hard depending on triple, etc). +Soft,// Soft float. +Hard // Hard float. + }; + } + + enum class EABI { +Unknown, +Default, // Default means not specified +EABI4, // Target-specific (either 4, 5 or gnu depending on triple). +EABI5, +GNU + }; + /// Code generation optimization level. enum class CodeGenOptLevel { None = 0, ///< -O0 diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index fd8dad4f6f791..08d6aa36e19d8 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -16,6 +16,7 @@ #include "llvm/ADT/FloatingPointMode.h" #include "llvm/MC/MCTargetOptions.h" +#include "llvm/Support/CodeGen.h" #include @@ -24,14 +25,6 @@ namespace llvm { class MachineFunction; class MemoryBuffer; - namespace FloatABI { -enum ABIType { - Default, // Target-specific (either soft or hard depending on triple, etc). - Soft,// Soft float. - Hard // Hard float. -}; - } - namespace FPOpFusion { enum FPOpFusionMode { Fast, // Enable fusion of FP ops wherever it's profitable. @@ -70,14 +63,6 @@ namespace llvm { None// Do not use Basic Block Sections. }; - enum class EABI { -Unknown, -Default, // Default means not specified -EABI4, // Target-specific (either 4, 5 or gnu depending on triple). -EABI5, -GNU - }; - /// Identify a debugger for "tuning" the debug info. /// /// The "debugger tuning" concept allows us to present a more intuitive ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Move soft float predicate management into RuntimeLibcalls (PR #142905)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/142905 >From e245a542fc0b5210f84dcae77875d97024954464 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 5 Jun 2025 14:22:55 +0900 Subject: [PATCH] DAG: Move soft float predicate management into RuntimeLibcalls Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate. --- llvm/include/llvm/CodeGen/TargetLowering.h| 14 +- llvm/include/llvm/IR/RuntimeLibcalls.h| 25 +++ .../CodeGen/SelectionDAG/TargetLowering.cpp | 5 +- llvm/lib/IR/RuntimeLibcalls.cpp | 36 llvm/lib/Target/ARM/ARMISelLowering.cpp | 178 +- llvm/lib/Target/MSP430/MSP430ISelLowering.cpp | 130 ++--- 6 files changed, 224 insertions(+), 164 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 9c453f51e129d..0d157de479141 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -3572,20 +3572,18 @@ class LLVM_ABI TargetLoweringBase { /// Override the default CondCode to be used to test the result of the /// comparison libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { -CmpLibcallCCs[Call] = CC; + /// FIXME: This should be removed + void setCmpLibcallCC(RTLIB::Libcall Call, CmpInst::Predicate Pred) { +Libcalls.setSoftFloatCmpLibcallPredicate(Call, Pred); } - /// Get the CondCode that's to be used to test the result of the comparison /// libcall against zero. - /// FIXME: This can't be merged with 'RuntimeLibcallsInfo' because of the ISD. - ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { -return CmpLibcallCCs[Call]; + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return Libcalls.getSoftFloatCmpLibcallPredicate(Call); } - /// Set the CallingConv that should be used for the specified libcall. void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { Libcalls.setLibcallCallingConv(Call, CC); diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 89e466ee5933d..e5adcd33411c5 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -17,6 +17,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Sequence.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/InstrTypes.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Compiler.h" #include "llvm/TargetParser/Triple.h" @@ -86,6 +87,20 @@ struct RuntimeLibcallsInfo { LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL); } + /// Get the comparison predicate that's to be used to test the result of the + /// comparison libcall against zero. This should only be used with + /// floating-point compare libcalls. + CmpInst::Predicate + getSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call) const { +return SoftFloatCompareLibcallPredicates[Call]; + } + + // FIXME: This should be removed. This should be private constant. + void setSoftFloatCmpLibcallPredicate(RTLIB::Libcall Call, + CmpInst::Predicate Pred) { +SoftFloatCompareLibcallPredicates[Call] = Pred; + } + private: /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; @@ -93,6 +108,14 @@ struct RuntimeLibcallsInfo { /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + /// The condition type that should be used to test the result of each of the + /// soft floating-point comparison libcall against integer zero. + /// + // FIXME: This is only relevant for the handful of floating-point comparison + // runtime calls; it's excessive to have a table entry for every single + // opcode. + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + static bool darwinHasSinCos(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. @@ -108,6 +131,8 @@ struct RuntimeLibcallsInfo { return true; } + void initSoftFloatCmpLibcallPredicates(); + /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. LLVM_ABI void initLibcalls(const Triple &TT); diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 4472a031c39f6..5105c4a515fbe 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/STLExtras.h" #inc
[llvm-branch-commits] [llvm] WebAssembly: Stop directly using RuntimeLibcalls.def (PR #143054)
@@ -528,23 +528,20 @@ RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() { // constructor for use with a static variable struct StaticLibcallNameMap { StringMap Map; - StaticLibcallNameMap() { -static const std::pair NameLibcalls[] = { -#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code}, -#include "llvm/IR/RuntimeLibcalls.def" -#undef HANDLE_LIBCALL -}; -for (const auto &NameLibcall : NameLibcalls) { - if (NameLibcall.first != nullptr && - getRuntimeLibcallSignatures().Table[NameLibcall.second] != - unsupported) { -assert(!Map.contains(NameLibcall.first) && + StaticLibcallNameMap(const Triple &TT) { +// FIXME: This is broken if there are ever different triples compiled with +// different libcalls. nikic wrote: Can we store the map in the subtarget instead? https://github.com/llvm/llvm-project/pull/143054 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
@@ -582,6 +582,15 @@ static SmallVector getCollapsedIndices(RewriterBase &rewriter, namespace { +/// Helper functon to return the index of the last dynamic dimension in `shape`. momchil-velikov wrote: `std::distance` returns a `ptrdiff_t`, there's a chance it's not the same as `int64_t` (e.g. `long long` vs. `long`). https://github.com/llvm/llvm-project/pull/142422 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
@@ -203,21 +206,21 @@ func.func @transfer_read_dynamic_dim_to_flatten( return %res : vector<1x2x6xi32> } -// CHECK: #[[$MAP:.*]] = affine_map<()[s0, s1] -> (s0 * 24 + s1 * 6)> +// CHECK: #[[$MAP:.+]] = affine_map<()[s0, s1] -> (s0 * 24 + s1 * 6)> // CHECK-LABEL: func.func @transfer_read_dynamic_dim_to_flatten // CHECK-SAME:%[[IDX_1:arg0]] // CHECK-SAME:%[[IDX_2:arg1]] // CHECK-SAME:%[[MEM:arg2]] -// CHECK: %[[C0_I32:.*]] = arith.constant 0 : i32 momchil-velikov wrote: I don't think it maters, I wouldn't bother changing `*` to `+` unless I'm modifying the line anyway, in which case the `+` is "more correct" as we're in fact expecting a non-empty variable name. https://github.com/llvm/llvm-project/pull/142422 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/142422 >From 4c1207b4f72314683eed7d5f8672c6d83db1ef54 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Mon, 2 Jun 2025 15:13:13 + Subject: [PATCH 1/5] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` Previously, slices were sometimes marked as non-contiguous when they were actually contiguous. This occurred when the vector type had leading unit dimensions, e.g., `vector<1x1x...x1xd0xd1x...xdn-1xT>``. In such cases, only the trailing n dimensions of the memref need to be contiguous, not the entire vector rank. This affects how `FlattenContiguousRowMajorTransfer{Read,Write}Pattern` flattens `transfer_read` and `transfer_write`` ops. The pattern used to collapse a number of dimensions equal the vector rank, which may be is incorrect when leading dimensions are unit-sized. This patch fixes the issue by collapsing only as many trailing memref dimensions as are actually contiguous. --- .../mlir/Dialect/Vector/Utils/VectorUtils.h | 54 - .../Transforms/VectorTransferOpTransforms.cpp | 8 +- mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp | 25 ++-- .../Vector/vector-transfer-flatten.mlir | 108 +- 4 files changed, 120 insertions(+), 75 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h index 6609b28d77b6c..ed06d7a029494 100644 --- a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h +++ b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h @@ -49,35 +49,37 @@ FailureOr> isTranspose2DSlice(vector::TransposeOp op); /// Return true if `vectorType` is a contiguous slice of `memrefType`. /// -/// Only the N = vectorType.getRank() trailing dims of `memrefType` are -/// checked (the other dims are not relevant). Note that for `vectorType` to be -/// a contiguous slice of `memrefType`, the trailing dims of the latter have -/// to be contiguous - this is checked by looking at the corresponding strides. +/// The leading unit dimensions of the vector type are ignored as they +/// are not relevant to the result. Let N be the number of the vector +/// dimensions after ignoring a leading sequence of unit ones. /// -/// There might be some restriction on the leading dim of `VectorType`: +/// For `vectorType` to be a contiguous slice of `memrefType` +/// a) the N trailing dimensions of the latter must be contiguous, and +/// b) the trailing N dimensions of `vectorType` and `memrefType`, +/// except the first of them, must match. /// -/// Case 1. If all the trailing dims of `vectorType` match the trailing dims -/// of `memrefType` then the leading dim of `vectorType` can be -/// arbitrary. -/// -///Ex. 1.1 contiguous slice, perfect match -/// vector<4x3x2xi32> from memref<5x4x3x2xi32> -///Ex. 1.2 contiguous slice, the leading dim does not match (2 != 4) -/// vector<2x3x2xi32> from memref<5x4x3x2xi32> -/// -/// Case 2. If an "internal" dim of `vectorType` does not match the -/// corresponding trailing dim in `memrefType` then the remaining -/// leading dims of `vectorType` have to be 1 (the first non-matching -/// dim can be arbitrary). +/// Examples: /// -///Ex. 2.1 non-contiguous slice, 2 != 3 and the leading dim != <1> -/// vector<2x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.2 contiguous slice, 2 != 3 and the leading dim == <1> -/// vector<1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.3. contiguous slice, 2 != 3 and the leading dims == <1x1> -/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.4. non-contiguous slice, 2 != 3 and the leading dims != <1x1> -/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.1 contiguous slice, perfect match +/// vector<4x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.2 contiguous slice, the leading dim does not match (2 != 4) +/// vector<2x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.3 non-contiguous slice, 2 != 3 +/// vector<2x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.4 contiguous slice, leading unit dimension of the vector ignored, +///2 != 3 (allowed) +/// vector<1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.5. contiguous slice, leasing two unit dims of the vector ignored, +/// 2 != 3 (allowed) +/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.6. non-contiguous slice, 2 != 3, no leading sequence of unit dims +/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.7 contiguous slice, memref needs to be contiguous only on the last +///dimension +/// vector<1x1x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> +/// Ex.8 non-contiguous slice, memref needs to be contiguous one the last +///two dimensions, and it isn't +/// vector<1x2x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> bool isContiguo
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/142422 >From 4c1207b4f72314683eed7d5f8672c6d83db1ef54 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Mon, 2 Jun 2025 15:13:13 + Subject: [PATCH 1/5] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` Previously, slices were sometimes marked as non-contiguous when they were actually contiguous. This occurred when the vector type had leading unit dimensions, e.g., `vector<1x1x...x1xd0xd1x...xdn-1xT>``. In such cases, only the trailing n dimensions of the memref need to be contiguous, not the entire vector rank. This affects how `FlattenContiguousRowMajorTransfer{Read,Write}Pattern` flattens `transfer_read` and `transfer_write`` ops. The pattern used to collapse a number of dimensions equal the vector rank, which may be is incorrect when leading dimensions are unit-sized. This patch fixes the issue by collapsing only as many trailing memref dimensions as are actually contiguous. --- .../mlir/Dialect/Vector/Utils/VectorUtils.h | 54 - .../Transforms/VectorTransferOpTransforms.cpp | 8 +- mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp | 25 ++-- .../Vector/vector-transfer-flatten.mlir | 108 +- 4 files changed, 120 insertions(+), 75 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h index 6609b28d77b6c..ed06d7a029494 100644 --- a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h +++ b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h @@ -49,35 +49,37 @@ FailureOr> isTranspose2DSlice(vector::TransposeOp op); /// Return true if `vectorType` is a contiguous slice of `memrefType`. /// -/// Only the N = vectorType.getRank() trailing dims of `memrefType` are -/// checked (the other dims are not relevant). Note that for `vectorType` to be -/// a contiguous slice of `memrefType`, the trailing dims of the latter have -/// to be contiguous - this is checked by looking at the corresponding strides. +/// The leading unit dimensions of the vector type are ignored as they +/// are not relevant to the result. Let N be the number of the vector +/// dimensions after ignoring a leading sequence of unit ones. /// -/// There might be some restriction on the leading dim of `VectorType`: +/// For `vectorType` to be a contiguous slice of `memrefType` +/// a) the N trailing dimensions of the latter must be contiguous, and +/// b) the trailing N dimensions of `vectorType` and `memrefType`, +/// except the first of them, must match. /// -/// Case 1. If all the trailing dims of `vectorType` match the trailing dims -/// of `memrefType` then the leading dim of `vectorType` can be -/// arbitrary. -/// -///Ex. 1.1 contiguous slice, perfect match -/// vector<4x3x2xi32> from memref<5x4x3x2xi32> -///Ex. 1.2 contiguous slice, the leading dim does not match (2 != 4) -/// vector<2x3x2xi32> from memref<5x4x3x2xi32> -/// -/// Case 2. If an "internal" dim of `vectorType` does not match the -/// corresponding trailing dim in `memrefType` then the remaining -/// leading dims of `vectorType` have to be 1 (the first non-matching -/// dim can be arbitrary). +/// Examples: /// -///Ex. 2.1 non-contiguous slice, 2 != 3 and the leading dim != <1> -/// vector<2x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.2 contiguous slice, 2 != 3 and the leading dim == <1> -/// vector<1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.3. contiguous slice, 2 != 3 and the leading dims == <1x1> -/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.4. non-contiguous slice, 2 != 3 and the leading dims != <1x1> -/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.1 contiguous slice, perfect match +/// vector<4x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.2 contiguous slice, the leading dim does not match (2 != 4) +/// vector<2x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.3 non-contiguous slice, 2 != 3 +/// vector<2x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.4 contiguous slice, leading unit dimension of the vector ignored, +///2 != 3 (allowed) +/// vector<1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.5. contiguous slice, leasing two unit dims of the vector ignored, +/// 2 != 3 (allowed) +/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.6. non-contiguous slice, 2 != 3, no leading sequence of unit dims +/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.7 contiguous slice, memref needs to be contiguous only on the last +///dimension +/// vector<1x1x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> +/// Ex.8 non-contiguous slice, memref needs to be contiguous one the last +///two dimensions, and it isn't +/// vector<1x2x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> bool isContiguo
[llvm-branch-commits] [mlir] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors (PR #143146)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/143146 >From 4d13aa2c48a24e5a76618e78adde41713115f895 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Wed, 14 May 2025 09:03:49 + Subject: [PATCH] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors THis patch add a transform of `transfer_read` operation to change the vector type to one that can be mapped to an LLVM type. This is done by collapsing trailing dimensions so we obtain a vector type with a single scalable dimension in the rightmost position. --- .../Transforms/LegalizeVectorStorage.cpp | 110 - .../ArmSVE/legalize-transfer-read.mlir| 226 ++ .../transfer-read-scalable-not-rightmost.mlir | 72 ++ 3 files changed, 407 insertions(+), 1 deletion(-) create mode 100644 mlir/test/Dialect/ArmSVE/legalize-transfer-read.mlir create mode 100644 mlir/test/Integration/Dialect/Vector/CPU/ArmSVE/transfer-read-scalable-not-rightmost.mlir diff --git a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp index d2ac850a5f70b..f16d33c004fec 100644 --- a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp +++ b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp @@ -298,6 +298,113 @@ struct LegalizeSVEMaskLoadConversion : public OpRewritePattern { } }; +/// Transforms a `transfer_read` operation so it reads vector of a type that +/// can be mapped to an LLVM type. This is done by collapsing trailing +/// dimensions so we obtain a vector type with a single scalable dimension in +/// the rightmost position. +/// +/// Example: +/// ``` +/// %v = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 +/// {in_bounds = [false, true, true, true]} +/// : memref, vector<2x[4]x2x8xi8> +/// ``` +/// is rewriten to +/// ``` +/// %collapse_shape = memref.collapse_shape %M [[0], [1, 2, 3]] +/// : memref into memref +/// %0 = vector.transfer_read %collapse_shape[%i, %j], %c0_i8 +/// {in_bounds = [false, true]} +/// : memref, vector<2x[64]xi8> +/// %1 = vector.shape_cast %0 : vector<2x[64]xi8> to vector<2x[4]x2x8xi8> +/// ``` +struct LegalizeTransferRead : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(vector::TransferReadOp readOp, +PatternRewriter &rewriter) const override { + +if (!readOp.getPermutationMap().isMinorIdentity()) + return rewriter.notifyMatchFailure(readOp, "non-identity permutation"); + +// We handle transfers of vectors with rank >= 2 and a single scalable +// dimension. +VectorType origVT = readOp.getVectorType(); +ArrayRef origScalableDims = origVT.getScalableDims(); +const int64_t origVRank = origVT.getRank(); +if (origVRank < 2 || llvm::count(origScalableDims, true) != 1) + return rewriter.notifyMatchFailure(readOp, "wrong dimensions"); + +// Number of trailing dimensions to collapse, including the scalable +// dimension. Nothing to do if the single scalable dimension is already the +// last one. +const int64_t numCollapseDims = std::distance( +llvm::find(origScalableDims, true), origScalableDims.end()); +if (numCollapseDims < 2) + return rewriter.notifyMatchFailure(readOp, + "scalable dimension is trailing"); + +// We want a simple memref (not a tensor) with contiguous elements for at +// least all the trailing dimensions up to and including the scalable one. +auto memTy = dyn_cast(readOp.getBase().getType()); +if (!(memTy && memTy.areTrailingDimsContiguous(numCollapseDims))) + return rewriter.notifyMatchFailure( + readOp, "non-contiguous memref dimensions to collapse"); + +// The collapsed dimensions (excluding the scalable one) of the vector and +// the memref must match and the corresponding indices must be in-bounds (it +// follows these indices would be zero). This guarantees that the operation +// transfers a contiguous block. +if (!llvm::equal(memTy.getShape().take_back(numCollapseDims - 1), + origVT.getShape().take_back(numCollapseDims - 1))) + return rewriter.notifyMatchFailure( + readOp, "memref and vector dimensions do not match"); + +SmallVector origInBounds = readOp.getInBoundsValues(); +if (!llvm::all_of( +ArrayRef(origInBounds).take_back(numCollapseDims - 1), +[](bool v) { return v; })) + return rewriter.notifyMatchFailure(readOp, + "out-if-bounds index to collapse"); + +// Collapse the trailing dimensions of the memref. +SmallVector reassoc; +for (int64_t i = 0; i < memTy.getRank() - numCollapseDims + 1; ++i) + reassoc.push_back({i}); +for (int64_t i = memTy.getRank() - numCollapseDims + 1; i < memTy.getRank(); + ++i) + reassoc.back
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
@@ -585,5 +592,47 @@ func.func @negative_out_of_bound_transfer_write( vector<1x1x3x2xi8>, memref> return } -// CHECK: func.func @negative_out_of_bound_transfer_write -// CHECK-NOT: memref.collapse_shape +// CHECK-LABEL: func.func @negative_out_of_bound_transfer_write +// CHECK-NOT: memref.collapse_shape newling wrote: CHECK: vector.shape_cast https://github.com/llvm/llvm-project/pull/142422 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
@@ -630,7 +639,10 @@ class FlattenContiguousRowMajorTransferReadPattern if (transferReadOp.getMask()) return failure(); -int64_t firstDimToCollapse = sourceType.getRank() - vectorType.getRank(); newling wrote: Thanks for the (additional!) explanation, I think I understand now In ``` int64_t firstDimToCollapse = std::max( lastDynIndex(sourceType.getShape()), sourceType.getRank() - sourceType.getNumContiguousTrailingDims()); ``` when might `lastDynIndex(sourceType.getShape())` be larger than `sourceType.getRank() - sourceType.getNumContiguousTrailingDims())` ? > I've chosen to do maximum collapsing, as it seems simpler to do, and the > resulting IR is arguably simpler. Ok. Maybe it is simpler in these 2 senses. I guess minimising change (compared to pre-PR and to pre-pass) could be another metric. https://github.com/llvm/llvm-project/pull/142422 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [CVP] Keep `ReachableCaseCount` in sync with range of condition (#142302) (PR #142730)
https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/142730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
@@ -103,10 +103,14 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; + + static_assert(static_cast(CallingConv::C) == 0, +"default calling conv should be encoded as 0"); /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; efriedma-quic wrote: Explicitly writing "CallingConv::C" here is confusing; either just use `{}`, or use something like SmallVector that actually has a constructor which fills an arbitrary value. https://github.com/llvm/llvm-project/pull/143082 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/143082 >From 67d040367f97806e16a658acff3427aa2396e8e4 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 14:50:57 +0900 Subject: [PATCH 1/3] RuntimeLibcalls: Use array initializers for default values --- llvm/include/llvm/IR/RuntimeLibcalls.h | 8 +--- llvm/lib/IR/RuntimeLibcalls.cpp| 10 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 6d8f007136153..c98a63a41d2bd 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -103,10 +103,11 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; /// The condition type that should be used to test the result of each of the /// soft floating-point comparison libcall against integer zero. @@ -114,7 +115,8 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = + {CmpInst::BAD_ICMP_PREDICATE}; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 7c0ffe170e196..b85a878887dec 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -12,9 +12,6 @@ using namespace llvm; using namespace RTLIB; void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { - std::fill(SoftFloatCompareLibcallPredicates, -SoftFloatCompareLibcallPredicates + RTLIB::UNKNOWN_LIBCALL, -CmpInst::BAD_ICMP_PREDICATE); SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F32] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F64] = CmpInst::ICMP_EQ; SoftFloatCompareLibcallPredicates[RTLIB::OEQ_F128] = CmpInst::ICMP_EQ; @@ -48,19 +45,12 @@ void RuntimeLibcallsInfo::initSoftFloatCmpLibcallPredicates() { /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) { - std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames), -nullptr); - initSoftFloatCmpLibcallPredicates(); #define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name); #include "llvm/IR/RuntimeLibcalls.def" #undef HANDLE_LIBCALL - // Initialize calling conventions to their default. - for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC) -setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C); - // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) { setLibcallName(RTLIB::REM_F128, "fmodf128"); >From f991879aeb7fc4c3f30dd142154bb2f063acaaa0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 6 Jun 2025 22:59:15 +0900 Subject: [PATCH 2/3] Revert for compare predicate case --- llvm/include/llvm/IR/RuntimeLibcalls.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index c98a63a41d2bd..bf29b03a18ab2 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -105,6 +105,9 @@ struct RuntimeLibcallsInfo { /// Stores the name each libcall. const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; + static_assert(static_cast(CallingConv::C) == 0, +"default calling conv should be encoded as 0"); + /// Stores the CallingConv that should be used for each libcall. CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { CallingConv::C}; @@ -115,8 +118,7 @@ struct RuntimeLibcallsInfo { // FIXME: This is only relevant for the handful of floating-point comparison // runtime calls; it's excessive to have a table entry for every single // opcode. - CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL] = - {CmpInst::BAD_ICMP_PREDICATE}; + CmpInst::Predicate SoftFloatCompareLibcallPredicates[RTLIB::UNKNOWN_LIBCALL]; static bool darwinHasSinCosStret(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); >From 540bdadf7797f30b41daa847c8f5d9d985a79954 Mon Sep 17 00:00:00
[llvm-branch-commits] [llvm] RuntimeLibcalls: Use array initializers for default values (PR #143082)
@@ -103,10 +103,14 @@ struct RuntimeLibcallsInfo { private: /// Stores the name each libcall. - const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1]; + const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1] = {nullptr}; + + static_assert(static_cast(CallingConv::C) == 0, +"default calling conv should be encoded as 0"); /// Stores the CallingConv that should be used for each libcall. - CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; + CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = { + CallingConv::C}; arsenm wrote: ```suggestion CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL] = {}; ``` https://github.com/llvm/llvm-project/pull/143082 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement validation of resource ranges for `RootDescriptors` (PR #140962)
https://github.com/inbelic edited https://github.com/llvm/llvm-project/pull/140962 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement validation of resource ranges for `RootDescriptors` (PR #140962)
@@ -973,6 +1076,8 @@ void SemaHLSL::handleRootSignatureAttr(Decl *D, const ParsedAttr &AL) { if (auto *SignatureDecl = dyn_cast(R.getFoundDecl())) { // Perform validation of constructs here + if (handleRootSignatureDecl(SignatureDecl, AL.getLoc())) +return; inbelic wrote: In light of moving the semantic work from parsing here: https://github.com/llvm/llvm-project/issues/142834. It seems we could hook the validation to actually occur there once per decl? https://github.com/llvm/llvm-project/pull/140962 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors (PR #143146)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/143146 >From 4d13aa2c48a24e5a76618e78adde41713115f895 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Wed, 14 May 2025 09:03:49 + Subject: [PATCH] [MLIR] Legalize certain `vector.transfer_read` ops of scalable vectors THis patch add a transform of `transfer_read` operation to change the vector type to one that can be mapped to an LLVM type. This is done by collapsing trailing dimensions so we obtain a vector type with a single scalable dimension in the rightmost position. --- .../Transforms/LegalizeVectorStorage.cpp | 110 - .../ArmSVE/legalize-transfer-read.mlir| 226 ++ .../transfer-read-scalable-not-rightmost.mlir | 72 ++ 3 files changed, 407 insertions(+), 1 deletion(-) create mode 100644 mlir/test/Dialect/ArmSVE/legalize-transfer-read.mlir create mode 100644 mlir/test/Integration/Dialect/Vector/CPU/ArmSVE/transfer-read-scalable-not-rightmost.mlir diff --git a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp index d2ac850a5f70b..f16d33c004fec 100644 --- a/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp +++ b/mlir/lib/Dialect/ArmSVE/Transforms/LegalizeVectorStorage.cpp @@ -298,6 +298,113 @@ struct LegalizeSVEMaskLoadConversion : public OpRewritePattern { } }; +/// Transforms a `transfer_read` operation so it reads vector of a type that +/// can be mapped to an LLVM type. This is done by collapsing trailing +/// dimensions so we obtain a vector type with a single scalable dimension in +/// the rightmost position. +/// +/// Example: +/// ``` +/// %v = vector.transfer_read %M[%i, %j, %c0, %c0], %c0_i8 +/// {in_bounds = [false, true, true, true]} +/// : memref, vector<2x[4]x2x8xi8> +/// ``` +/// is rewriten to +/// ``` +/// %collapse_shape = memref.collapse_shape %M [[0], [1, 2, 3]] +/// : memref into memref +/// %0 = vector.transfer_read %collapse_shape[%i, %j], %c0_i8 +/// {in_bounds = [false, true]} +/// : memref, vector<2x[64]xi8> +/// %1 = vector.shape_cast %0 : vector<2x[64]xi8> to vector<2x[4]x2x8xi8> +/// ``` +struct LegalizeTransferRead : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(vector::TransferReadOp readOp, +PatternRewriter &rewriter) const override { + +if (!readOp.getPermutationMap().isMinorIdentity()) + return rewriter.notifyMatchFailure(readOp, "non-identity permutation"); + +// We handle transfers of vectors with rank >= 2 and a single scalable +// dimension. +VectorType origVT = readOp.getVectorType(); +ArrayRef origScalableDims = origVT.getScalableDims(); +const int64_t origVRank = origVT.getRank(); +if (origVRank < 2 || llvm::count(origScalableDims, true) != 1) + return rewriter.notifyMatchFailure(readOp, "wrong dimensions"); + +// Number of trailing dimensions to collapse, including the scalable +// dimension. Nothing to do if the single scalable dimension is already the +// last one. +const int64_t numCollapseDims = std::distance( +llvm::find(origScalableDims, true), origScalableDims.end()); +if (numCollapseDims < 2) + return rewriter.notifyMatchFailure(readOp, + "scalable dimension is trailing"); + +// We want a simple memref (not a tensor) with contiguous elements for at +// least all the trailing dimensions up to and including the scalable one. +auto memTy = dyn_cast(readOp.getBase().getType()); +if (!(memTy && memTy.areTrailingDimsContiguous(numCollapseDims))) + return rewriter.notifyMatchFailure( + readOp, "non-contiguous memref dimensions to collapse"); + +// The collapsed dimensions (excluding the scalable one) of the vector and +// the memref must match and the corresponding indices must be in-bounds (it +// follows these indices would be zero). This guarantees that the operation +// transfers a contiguous block. +if (!llvm::equal(memTy.getShape().take_back(numCollapseDims - 1), + origVT.getShape().take_back(numCollapseDims - 1))) + return rewriter.notifyMatchFailure( + readOp, "memref and vector dimensions do not match"); + +SmallVector origInBounds = readOp.getInBoundsValues(); +if (!llvm::all_of( +ArrayRef(origInBounds).take_back(numCollapseDims - 1), +[](bool v) { return v; })) + return rewriter.notifyMatchFailure(readOp, + "out-if-bounds index to collapse"); + +// Collapse the trailing dimensions of the memref. +SmallVector reassoc; +for (int64_t i = 0; i < memTy.getRank() - numCollapseDims + 1; ++i) + reassoc.push_back({i}); +for (int64_t i = memTy.getRank() - numCollapseDims + 1; i < memTy.getRank(); + ++i) + reassoc.back
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/142422 >From 937afe27b55fb6a61ccef6252eeb33159bca3e99 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Mon, 2 Jun 2025 15:13:13 + Subject: [PATCH 1/5] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` Previously, slices were sometimes marked as non-contiguous when they were actually contiguous. This occurred when the vector type had leading unit dimensions, e.g., `vector<1x1x...x1xd0xd1x...xdn-1xT>``. In such cases, only the trailing n dimensions of the memref need to be contiguous, not the entire vector rank. This affects how `FlattenContiguousRowMajorTransfer{Read,Write}Pattern` flattens `transfer_read` and `transfer_write`` ops. The pattern used to collapse a number of dimensions equal the vector rank, which may be is incorrect when leading dimensions are unit-sized. This patch fixes the issue by collapsing only as many trailing memref dimensions as are actually contiguous. --- .../mlir/Dialect/Vector/Utils/VectorUtils.h | 54 - .../Transforms/VectorTransferOpTransforms.cpp | 8 +- mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp | 25 ++-- .../Vector/vector-transfer-flatten.mlir | 108 +- 4 files changed, 120 insertions(+), 75 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h index 6609b28d77b6c..ed06d7a029494 100644 --- a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h +++ b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h @@ -49,35 +49,37 @@ FailureOr> isTranspose2DSlice(vector::TransposeOp op); /// Return true if `vectorType` is a contiguous slice of `memrefType`. /// -/// Only the N = vectorType.getRank() trailing dims of `memrefType` are -/// checked (the other dims are not relevant). Note that for `vectorType` to be -/// a contiguous slice of `memrefType`, the trailing dims of the latter have -/// to be contiguous - this is checked by looking at the corresponding strides. +/// The leading unit dimensions of the vector type are ignored as they +/// are not relevant to the result. Let N be the number of the vector +/// dimensions after ignoring a leading sequence of unit ones. /// -/// There might be some restriction on the leading dim of `VectorType`: +/// For `vectorType` to be a contiguous slice of `memrefType` +/// a) the N trailing dimensions of the latter must be contiguous, and +/// b) the trailing N dimensions of `vectorType` and `memrefType`, +/// except the first of them, must match. /// -/// Case 1. If all the trailing dims of `vectorType` match the trailing dims -/// of `memrefType` then the leading dim of `vectorType` can be -/// arbitrary. -/// -///Ex. 1.1 contiguous slice, perfect match -/// vector<4x3x2xi32> from memref<5x4x3x2xi32> -///Ex. 1.2 contiguous slice, the leading dim does not match (2 != 4) -/// vector<2x3x2xi32> from memref<5x4x3x2xi32> -/// -/// Case 2. If an "internal" dim of `vectorType` does not match the -/// corresponding trailing dim in `memrefType` then the remaining -/// leading dims of `vectorType` have to be 1 (the first non-matching -/// dim can be arbitrary). +/// Examples: /// -///Ex. 2.1 non-contiguous slice, 2 != 3 and the leading dim != <1> -/// vector<2x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.2 contiguous slice, 2 != 3 and the leading dim == <1> -/// vector<1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.3. contiguous slice, 2 != 3 and the leading dims == <1x1> -/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.4. non-contiguous slice, 2 != 3 and the leading dims != <1x1> -/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.1 contiguous slice, perfect match +/// vector<4x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.2 contiguous slice, the leading dim does not match (2 != 4) +/// vector<2x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.3 non-contiguous slice, 2 != 3 +/// vector<2x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.4 contiguous slice, leading unit dimension of the vector ignored, +///2 != 3 (allowed) +/// vector<1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.5. contiguous slice, leasing two unit dims of the vector ignored, +/// 2 != 3 (allowed) +/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.6. non-contiguous slice, 2 != 3, no leading sequence of unit dims +/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.7 contiguous slice, memref needs to be contiguous only on the last +///dimension +/// vector<1x1x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> +/// Ex.8 non-contiguous slice, memref needs to be contiguous one the last +///two dimensions, and it isn't +/// vector<1x2x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> bool isContiguo
[llvm-branch-commits] [mlir] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` (PR #142422)
https://github.com/momchil-velikov updated https://github.com/llvm/llvm-project/pull/142422 >From 937afe27b55fb6a61ccef6252eeb33159bca3e99 Mon Sep 17 00:00:00 2001 From: Momchil Velikov Date: Mon, 2 Jun 2025 15:13:13 + Subject: [PATCH 1/5] [MLIR] Fix incorrect slice contiguity inference in `vector::isContiguousSlice` Previously, slices were sometimes marked as non-contiguous when they were actually contiguous. This occurred when the vector type had leading unit dimensions, e.g., `vector<1x1x...x1xd0xd1x...xdn-1xT>``. In such cases, only the trailing n dimensions of the memref need to be contiguous, not the entire vector rank. This affects how `FlattenContiguousRowMajorTransfer{Read,Write}Pattern` flattens `transfer_read` and `transfer_write`` ops. The pattern used to collapse a number of dimensions equal the vector rank, which may be is incorrect when leading dimensions are unit-sized. This patch fixes the issue by collapsing only as many trailing memref dimensions as are actually contiguous. --- .../mlir/Dialect/Vector/Utils/VectorUtils.h | 54 - .../Transforms/VectorTransferOpTransforms.cpp | 8 +- mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp | 25 ++-- .../Vector/vector-transfer-flatten.mlir | 108 +- 4 files changed, 120 insertions(+), 75 deletions(-) diff --git a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h index 6609b28d77b6c..ed06d7a029494 100644 --- a/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h +++ b/mlir/include/mlir/Dialect/Vector/Utils/VectorUtils.h @@ -49,35 +49,37 @@ FailureOr> isTranspose2DSlice(vector::TransposeOp op); /// Return true if `vectorType` is a contiguous slice of `memrefType`. /// -/// Only the N = vectorType.getRank() trailing dims of `memrefType` are -/// checked (the other dims are not relevant). Note that for `vectorType` to be -/// a contiguous slice of `memrefType`, the trailing dims of the latter have -/// to be contiguous - this is checked by looking at the corresponding strides. +/// The leading unit dimensions of the vector type are ignored as they +/// are not relevant to the result. Let N be the number of the vector +/// dimensions after ignoring a leading sequence of unit ones. /// -/// There might be some restriction on the leading dim of `VectorType`: +/// For `vectorType` to be a contiguous slice of `memrefType` +/// a) the N trailing dimensions of the latter must be contiguous, and +/// b) the trailing N dimensions of `vectorType` and `memrefType`, +/// except the first of them, must match. /// -/// Case 1. If all the trailing dims of `vectorType` match the trailing dims -/// of `memrefType` then the leading dim of `vectorType` can be -/// arbitrary. -/// -///Ex. 1.1 contiguous slice, perfect match -/// vector<4x3x2xi32> from memref<5x4x3x2xi32> -///Ex. 1.2 contiguous slice, the leading dim does not match (2 != 4) -/// vector<2x3x2xi32> from memref<5x4x3x2xi32> -/// -/// Case 2. If an "internal" dim of `vectorType` does not match the -/// corresponding trailing dim in `memrefType` then the remaining -/// leading dims of `vectorType` have to be 1 (the first non-matching -/// dim can be arbitrary). +/// Examples: /// -///Ex. 2.1 non-contiguous slice, 2 != 3 and the leading dim != <1> -/// vector<2x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.2 contiguous slice, 2 != 3 and the leading dim == <1> -/// vector<1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.3. contiguous slice, 2 != 3 and the leading dims == <1x1> -/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> -///Ex. 2.4. non-contiguous slice, 2 != 3 and the leading dims != <1x1> -/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.1 contiguous slice, perfect match +/// vector<4x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.2 contiguous slice, the leading dim does not match (2 != 4) +/// vector<2x3x2xi32> from memref<5x4x3x2xi32> +/// Ex.3 non-contiguous slice, 2 != 3 +/// vector<2x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.4 contiguous slice, leading unit dimension of the vector ignored, +///2 != 3 (allowed) +/// vector<1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.5. contiguous slice, leasing two unit dims of the vector ignored, +/// 2 != 3 (allowed) +/// vector<1x1x2x2xi32> from memref<5x4x3x2xi32> +/// Ex.6. non-contiguous slice, 2 != 3, no leading sequence of unit dims +/// vector<2x1x2x2xi32> from memref<5x4x3x2xi32>) +/// Ex.7 contiguous slice, memref needs to be contiguous only on the last +///dimension +/// vector<1x1x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> +/// Ex.8 non-contiguous slice, memref needs to be contiguous one the last +///two dimensions, and it isn't +/// vector<1x2x2xi32> from memref<2x2x2xi32, strided<[8, 4, 1]>> bool isContiguo
[llvm-branch-commits] [llvm] release/20.x: [AArch64] Handle XAR with v1i64 operand types (#141754) (PR #143163)
https://github.com/nikic milestoned https://github.com/llvm/llvm-project/pull/143163 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [AArch64] Handle XAR with v1i64 operand types (#141754) (PR #143163)
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/143163 Backport of https://github.com/llvm/llvm-project/commit/32837f376f3c795d3ae6e632adc4f1a60180a646. >From 2c1c9730974c384b10bccc9f4a4f63c94377d302 Mon Sep 17 00:00:00 2001 From: David Green Date: Thu, 29 May 2025 10:22:24 +0100 Subject: [PATCH] release/20.x: [AArch64] Handle XAR with v1i64 operand types (#141754) When converting ROTR(XOR(a, b)) to XAR(a, b), or ROTR(a, a) to XAR(a, zero) we were not handling v1i64 types, meaning illegal copies get generated. This addresses that by generating insert_subreg and extract_subreg for v1i64 to keep the values with the correct types. Fixes #141746 --- .../Target/AArch64/AArch64ISelDAGToDAG.cpp| 24 ++- llvm/test/CodeGen/AArch64/xar.ll | 20 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp index 1387a224fa660..0aad7665f6216 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp @@ -4608,9 +4608,31 @@ bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) { if (ShAmt + HsAmt != 64) return false; + // If the input is a v1i64, widen to a v2i64 to use XAR. + assert((VT == MVT::v1i64 || VT == MVT::v2i64) && "Unexpected XAR type!"); + if (VT == MVT::v1i64) { +EVT SVT = MVT::v2i64; +SDValue Undef = +SDValue(CurDAG->getMachineNode(AArch64::IMPLICIT_DEF, DL, SVT), 0); +SDValue DSub = CurDAG->getTargetConstant(AArch64::dsub, DL, MVT::i32); +R1 = SDValue(CurDAG->getMachineNode(AArch64::INSERT_SUBREG, DL, SVT, Undef, +R1, DSub), + 0); +if (R2.getValueType() == MVT::v1i64) + R2 = SDValue(CurDAG->getMachineNode(AArch64::INSERT_SUBREG, DL, SVT, + Undef, R2, DSub), + 0); + } + SDValue Ops[] = {R1, R2, Imm}; - CurDAG->SelectNodeTo(N, AArch64::XAR, N0.getValueType(), Ops); + SDNode *XAR = CurDAG->getMachineNode(AArch64::XAR, DL, MVT::v2i64, Ops); + if (VT == MVT::v1i64) { +SDValue DSub = CurDAG->getTargetConstant(AArch64::dsub, DL, MVT::i32); +XAR = CurDAG->getMachineNode(AArch64::EXTRACT_SUBREG, DL, VT, + SDValue(XAR, 0), DSub); + } + ReplaceNode(N, XAR); return true; } diff --git a/llvm/test/CodeGen/AArch64/xar.ll b/llvm/test/CodeGen/AArch64/xar.ll index d050eaf6646de..5666ab35cde48 100644 --- a/llvm/test/CodeGen/AArch64/xar.ll +++ b/llvm/test/CodeGen/AArch64/xar.ll @@ -19,4 +19,24 @@ define <2 x i64> @xar(<2 x i64> %x, <2 x i64> %y) { ret <2 x i64> %b } +define <1 x i64> @xar_v1i64(<1 x i64> %a, <1 x i64> %b) { +; SHA3-LABEL: xar_v1i64: +; SHA3: // %bb.0: +; SHA3-NEXT:// kill: def $d0 killed $d0 def $q0 +; SHA3-NEXT:// kill: def $d1 killed $d1 def $q1 +; SHA3-NEXT:xar v0.2d, v0.2d, v1.2d, #63 +; SHA3-NEXT:// kill: def $d0 killed $d0 killed $q0 +; SHA3-NEXT:ret +; +; NOSHA3-LABEL: xar_v1i64: +; NOSHA3: // %bb.0: +; NOSHA3-NEXT:eor v1.8b, v0.8b, v1.8b +; NOSHA3-NEXT:shl d0, d1, #1 +; NOSHA3-NEXT:usra d0, d1, #63 +; NOSHA3-NEXT:ret + %v.val = xor <1 x i64> %a, %b + %fshl = tail call <1 x i64> @llvm.fshl.v1i64(<1 x i64> %v.val, <1 x i64> %v.val, <1 x i64> splat (i64 1)) + ret <1 x i64> %fshl +} + declare <2 x i64> @llvm.fshl.v2i64(<2 x i64>, <2 x i64>, <2 x i64>) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/20.x: [AArch64] Handle XAR with v1i64 operand types (#141754) (PR #143163)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 Author: Nikita Popov (nikic) Changes Backport of https://github.com/llvm/llvm-project/commit/32837f376f3c795d3ae6e632adc4f1a60180a646. --- Full diff: https://github.com/llvm/llvm-project/pull/143163.diff 2 Files Affected: - (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+23-1) - (modified) llvm/test/CodeGen/AArch64/xar.ll (+20) ``diff diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp index 1387a224fa660..0aad7665f6216 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp @@ -4608,9 +4608,31 @@ bool AArch64DAGToDAGISel::trySelectXAR(SDNode *N) { if (ShAmt + HsAmt != 64) return false; + // If the input is a v1i64, widen to a v2i64 to use XAR. + assert((VT == MVT::v1i64 || VT == MVT::v2i64) && "Unexpected XAR type!"); + if (VT == MVT::v1i64) { +EVT SVT = MVT::v2i64; +SDValue Undef = +SDValue(CurDAG->getMachineNode(AArch64::IMPLICIT_DEF, DL, SVT), 0); +SDValue DSub = CurDAG->getTargetConstant(AArch64::dsub, DL, MVT::i32); +R1 = SDValue(CurDAG->getMachineNode(AArch64::INSERT_SUBREG, DL, SVT, Undef, +R1, DSub), + 0); +if (R2.getValueType() == MVT::v1i64) + R2 = SDValue(CurDAG->getMachineNode(AArch64::INSERT_SUBREG, DL, SVT, + Undef, R2, DSub), + 0); + } + SDValue Ops[] = {R1, R2, Imm}; - CurDAG->SelectNodeTo(N, AArch64::XAR, N0.getValueType(), Ops); + SDNode *XAR = CurDAG->getMachineNode(AArch64::XAR, DL, MVT::v2i64, Ops); + if (VT == MVT::v1i64) { +SDValue DSub = CurDAG->getTargetConstant(AArch64::dsub, DL, MVT::i32); +XAR = CurDAG->getMachineNode(AArch64::EXTRACT_SUBREG, DL, VT, + SDValue(XAR, 0), DSub); + } + ReplaceNode(N, XAR); return true; } diff --git a/llvm/test/CodeGen/AArch64/xar.ll b/llvm/test/CodeGen/AArch64/xar.ll index d050eaf6646de..5666ab35cde48 100644 --- a/llvm/test/CodeGen/AArch64/xar.ll +++ b/llvm/test/CodeGen/AArch64/xar.ll @@ -19,4 +19,24 @@ define <2 x i64> @xar(<2 x i64> %x, <2 x i64> %y) { ret <2 x i64> %b } +define <1 x i64> @xar_v1i64(<1 x i64> %a, <1 x i64> %b) { +; SHA3-LABEL: xar_v1i64: +; SHA3: // %bb.0: +; SHA3-NEXT:// kill: def $d0 killed $d0 def $q0 +; SHA3-NEXT:// kill: def $d1 killed $d1 def $q1 +; SHA3-NEXT:xar v0.2d, v0.2d, v1.2d, #63 +; SHA3-NEXT:// kill: def $d0 killed $d0 killed $q0 +; SHA3-NEXT:ret +; +; NOSHA3-LABEL: xar_v1i64: +; NOSHA3: // %bb.0: +; NOSHA3-NEXT:eor v1.8b, v0.8b, v1.8b +; NOSHA3-NEXT:shl d0, d1, #1 +; NOSHA3-NEXT:usra d0, d1, #63 +; NOSHA3-NEXT:ret + %v.val = xor <1 x i64> %a, %b + %fshl = tail call <1 x i64> @llvm.fshl.v1i64(<1 x i64> %v.val, <1 x i64> %v.val, <1 x i64> splat (i64 1)) + ret <1 x i64> %fshl +} + declare <2 x i64> @llvm.fshl.v2i64(<2 x i64>, <2 x i64>, <2 x i64>) `` https://github.com/llvm/llvm-project/pull/143163 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen] Limit number of analyzed predecessors (PR #142584)
kyulee-com wrote: Can we add a LIT test case using this flag? I think you could set it with a smaller number to create a test case. https://github.com/llvm/llvm-project/pull/142584 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement serialization of remaining Root Elements (PR #143198)
https://github.com/inbelic created https://github.com/llvm/llvm-project/pull/143198 Implements serialization of the remaining completely defined `RootElement`s, namely `RootDescriptor`s and `RootFlag`s. - Adds unit testing for the serialization methods Resolves https://github.com/llvm/llvm-project/issues/138191 Resolves https://github.com/llvm/llvm-project/issues/138193 >From 749c7626701c9479a27648e76b070e7aa8eed0d4 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Fri, 6 Jun 2025 18:39:55 + Subject: [PATCH 1/6] [HLSL][RootSignature] Implement serialization of `RootDescriptor`s --- .../Frontend/HLSL/HLSLRootSignatureUtils.h| 3 + .../Frontend/HLSL/HLSLRootSignatureUtils.cpp | 46 +++ .../Frontend/HLSLRootSignatureDumpTest.cpp| 56 +++ 3 files changed, 105 insertions(+) diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h index ca20e6719f3a4..20114abcf74a8 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h @@ -32,6 +32,9 @@ LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags); LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants); +LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, + const RootDescriptor &Descriptor); + LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause); diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp index 24486a55ecf6a..d32765377e55e 100644 --- a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp +++ b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp @@ -132,6 +132,42 @@ static raw_ostream &operator<<(raw_ostream &OS, return OS; } +static raw_ostream &operator<<(raw_ostream &OS, + const RootDescriptorFlags &Flags) { + bool FlagSet = false; + unsigned Remaining = llvm::to_underlying(Flags); + while (Remaining) { +unsigned Bit = 1u << llvm::countr_zero(Remaining); +if (Remaining & Bit) { + if (FlagSet) +OS << " | "; + + switch (static_cast(Bit)) { + case RootDescriptorFlags::DataVolatile: +OS << "DataVolatile"; +break; + case RootDescriptorFlags::DataStaticWhileSetAtExecute: +OS << "DataStaticWhileSetAtExecute"; +break; + case RootDescriptorFlags::DataStatic: +OS << "DataStatic"; +break; + default: +OS << "invalid: " << Bit; +break; + } + + FlagSet = true; +} +Remaining &= ~Bit; + } + + if (!FlagSet) +OS << "None"; + + return OS; +} + raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) { OS << "RootFlags("; bool FlagSet = false; @@ -205,6 +241,16 @@ raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants) { return OS; } +raw_ostream &operator<<(raw_ostream &OS, const RootDescriptor &Descriptor) { + ClauseType Type = ClauseType(llvm::to_underlying(Descriptor.Type)); + OS << "Root" << Type << "(" << Descriptor.Reg + << ", space = " << Descriptor.Space + << ", visibility = " << Descriptor.Visibility + << ", flags = " << Descriptor.Flags << ")"; + + return OS; +} + raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table) { OS << "DescriptorTable(numClauses = " << Table.NumClauses << ", visibility = " << Table.Visibility << ")"; diff --git a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp index 1a0c8e2a16396..6379bdd02c638 100644 --- a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp +++ b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp @@ -177,4 +177,60 @@ TEST(HLSLRootSignatureTest, AllRootFlagsDump) { EXPECT_EQ(Out, Expected); } +TEST(HLSLRootSignatureTest, RootCBVDump) { + RootDescriptor Descriptor; + Descriptor.Type = DescriptorType::CBuffer; + Descriptor.Reg = {RegisterType::BReg, 0}; + Descriptor.setDefaultFlags(); + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Descriptor; + OS.flush(); + + std::string Expected = "RootCBV(b0, space = 0, " + "visibility = All, " + "flags = DataStaticWhileSetAtExecute)"; + EXPECT_EQ(Out, Expected); +} + +TEST(HLSLRootSignatureTest, RootSRVDump) { + RootDescriptor Descriptor; + Descriptor.Type = DescriptorType::SRV; + Descriptor.Reg = {RegisterType::TReg, 0}; + Descriptor.Space = 42; + Descriptor.Visibility = ShaderVisibility::Geometry; + Descriptor.Flags = RootDescriptorFlags::None; + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Descriptor; + OS.flush(); + + std::string Expected = + "RootSRV(t0, space = 42, visibility = Geometry, flags = None)"; + EXPECT_E
[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement serialization of remaining Root Elements (PR #143198)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Finn Plummer (inbelic) Changes Implements serialization of the remaining completely defined `RootElement`s, namely `RootDescriptor`s and `RootFlag`s. - Adds unit testing for the serialization methods Resolves https://github.com/llvm/llvm-project/issues/138191 Resolves https://github.com/llvm/llvm-project/issues/138193 --- Full diff: https://github.com/llvm/llvm-project/pull/143198.diff 3 Files Affected: - (modified) llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h (+6) - (modified) llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp (+254) - (modified) llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp (+121) ``diff diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h index ca20e6719f3a4..7489777670703 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h @@ -32,6 +32,12 @@ LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags); LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants); +LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, + const RootDescriptor &Descriptor); + +LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, + const StaticSampler &StaticSampler); + LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause); diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp index 24486a55ecf6a..70c3e72c1f806 100644 --- a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp +++ b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp @@ -71,6 +71,199 @@ static raw_ostream &operator<<(raw_ostream &OS, return OS; } +static raw_ostream &operator<<(raw_ostream &OS, const SamplerFilter &Filter) { + switch (Filter) { + case SamplerFilter::MinMagMipPoint: +OS << "MinMagMipPoint"; +break; + case SamplerFilter::MinMagPointMipLinear: +OS << "MinMagPointMipLinear"; +break; + case SamplerFilter::MinPointMagLinearMipPoint: +OS << "MinPointMagLinearMipPoint"; +break; + case SamplerFilter::MinPointMagMipLinear: +OS << "MinPointMagMipLinear"; +break; + case SamplerFilter::MinLinearMagMipPoint: +OS << "MinLinearMagMipPoint"; +break; + case SamplerFilter::MinLinearMagPointMipLinear: +OS << "MinLinearMagPointMipLinear"; +break; + case SamplerFilter::MinMagLinearMipPoint: +OS << "MinMagLinearMipPoint"; +break; + case SamplerFilter::MinMagMipLinear: +OS << "MinMagMipLinear"; +break; + case SamplerFilter::Anisotropic: +OS << "Anisotropic"; +break; + case SamplerFilter::ComparisonMinMagMipPoint: +OS << "ComparisonMinMagMipPoint"; +break; + case SamplerFilter::ComparisonMinMagPointMipLinear: +OS << "ComparisonMinMagPointMipLinear"; +break; + case SamplerFilter::ComparisonMinPointMagLinearMipPoint: +OS << "ComparisonMinPointMagLinearMipPoint"; +break; + case SamplerFilter::ComparisonMinPointMagMipLinear: +OS << "ComparisonMinPointMagMipLinear"; +break; + case SamplerFilter::ComparisonMinLinearMagMipPoint: +OS << "ComparisonMinLinearMagMipPoint"; +break; + case SamplerFilter::ComparisonMinLinearMagPointMipLinear: +OS << "ComparisonMinLinearMagPointMipLinear"; +break; + case SamplerFilter::ComparisonMinMagLinearMipPoint: +OS << "ComparisonMinMagLinearMipPoint"; +break; + case SamplerFilter::ComparisonMinMagMipLinear: +OS << "ComparisonMinMagMipLinear"; +break; + case SamplerFilter::ComparisonAnisotropic: +OS << "ComparisonAnisotropic"; +break; + case SamplerFilter::MinimumMinMagMipPoint: +OS << "MinimumMinMagMipPoint"; +break; + case SamplerFilter::MinimumMinMagPointMipLinear: +OS << "MinimumMinMagPointMipLinear"; +break; + case SamplerFilter::MinimumMinPointMagLinearMipPoint: +OS << "MinimumMinPointMagLinearMipPoint"; +break; + case SamplerFilter::MinimumMinPointMagMipLinear: +OS << "MinimumMinPointMagMipLinear"; +break; + case SamplerFilter::MinimumMinLinearMagMipPoint: +OS << "MinimumMinLinearMagMipPoint"; +break; + case SamplerFilter::MinimumMinLinearMagPointMipLinear: +OS << "MinimumMinLinearMagPointMipLinear"; +break; + case SamplerFilter::MinimumMinMagLinearMipPoint: +OS << "MinimumMinMagLinearMipPoint"; +break; + case SamplerFilter::MinimumMinMagMipLinear: +OS << "MinimumMinMagMipLinear"; +break; + case SamplerFilter::MinimumAnisotropic: +OS << "MinimumAnisotropic"; +break; + case SamplerFilter::MaximumMinMagMipPoint: +OS << "MaximumMinMagMipPoint"; +break; + case SamplerFilter::MaximumMinMagPointMipLinear: +OS << "MaximumMinMagPointMipLinear"; +break; + case Sa
[llvm-branch-commits] [llvm] Vocab changes1 (PR #143200)
svkeerthy wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/143200?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#143200** https://app.graphite.dev/github/pr/llvm/llvm-project/143200?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/143200?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#143197** https://app.graphite.dev/github/pr/llvm/llvm-project/143197?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Vocab changes1 (PR #143200)
https://github.com/svkeerthy created https://github.com/llvm/llvm-project/pull/143200 None >From d62a38bb0784972e363a7408ba362c31e404f02c Mon Sep 17 00:00:00 2001 From: svkeerthy Date: Fri, 6 Jun 2025 20:32:32 + Subject: [PATCH] Vocab changes1 --- llvm/include/llvm/Analysis/IR2Vec.h| 10 ++ llvm/lib/Analysis/IR2Vec.cpp | 81 ++- llvm/unittests/Analysis/IR2VecTest.cpp | 137 ++--- 3 files changed, 165 insertions(+), 63 deletions(-) diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 930b13f079796..1bd80ed65d434 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -31,7 +31,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/IR/PassManager.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/JSON.h" #include namespace llvm { @@ -43,6 +45,7 @@ class Function; class Type; class Value; class raw_ostream; +class LLVMContext; /// IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware. /// Symbolic embeddings capture the "syntactic" and "statistical correlation" @@ -53,6 +56,11 @@ class raw_ostream; enum class IR2VecKind { Symbolic }; namespace ir2vec { + +LLVM_ABI extern cl::opt OpcWeight; +LLVM_ABI extern cl::opt TypeWeight; +LLVM_ABI extern cl::opt ArgWeight; + /// Embedding is a ADT that wraps std::vector. It provides /// additional functionality for arithmetic and comparison operations. struct Embedding : public std::vector { @@ -187,10 +195,12 @@ class IR2VecVocabResult { class IR2VecVocabAnalysis : public AnalysisInfoMixin { ir2vec::Vocab Vocabulary; Error readVocabulary(); + void emitError(Error Err, LLVMContext &Ctx); public: static AnalysisKey Key; IR2VecVocabAnalysis() = default; + explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab); using Result = IR2VecVocabResult; Result run(Module &M, ModuleAnalysisManager &MAM); }; diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 8ee8e5b0ff74e..e751f10b8 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -16,13 +16,11 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" -#include "llvm/Support/JSON.h" #include "llvm/Support/MemoryBuffer.h" using namespace llvm; @@ -33,6 +31,8 @@ using namespace ir2vec; STATISTIC(VocabMissCounter, "Number of lookups to entites not present in the vocabulary"); +namespace llvm { +namespace ir2vec { static cl::OptionCategory IR2VecCategory("IR2Vec Options"); // FIXME: Use a default vocab when not specified @@ -40,18 +40,20 @@ static cl::opt VocabFile("ir2vec-vocab-path", cl::Optional, cl::desc("Path to the vocabulary file for IR2Vec"), cl::init(""), cl::cat(IR2VecCategory)); -static cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, -cl::init(1.0), -cl::desc("Weight for opcode embeddings"), -cl::cat(IR2VecCategory)); -static cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, - cl::init(0.5), - cl::desc("Weight for type embeddings"), - cl::cat(IR2VecCategory)); -static cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, -cl::init(0.2), -cl::desc("Weight for argument embeddings"), -cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, + cl::init(1.0), + cl::desc("Weight for opcode embeddings"), + cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, + cl::init(0.5), + cl::desc("Weight for type embeddings"), + cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, + cl::init(0.2), + cl::desc("Weight for argument embeddings"), + cl::cat(IR2VecCategory)); +} // namespace ir2vec +} // namespace llvm AnalysisKey IR2VecVocabAnalysis::Key; @@ -83,9 +85,10 @@ void Embedding::scaleAndAdd(const Embedding &Src, float Factor) { bool Embedding::approximatelyEquals(const Embedding &RHS, double Tolerance) const { assert(this->size() == RHS.size() && "Vectors must have the same dimension"); - for (size_t
[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement serialization of remaining Root Elements (PR #143198)
@@ -71,6 +71,199 @@ static raw_ostream &operator<<(raw_ostream &OS, return OS; } +static raw_ostream &operator<<(raw_ostream &OS, const SamplerFilter &Filter) { + switch (Filter) { + case SamplerFilter::MinMagMipPoint: +OS << "MinMagMipPoint"; llvm-beanz wrote: Could we instead use `llvm::EnumEntry` from `llvm::ScopedPrinter` to translate enums to strings? That allows the mechanism to be reused rather than single purpose. https://github.com/llvm/llvm-project/pull/143198 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement serialization of remaining Root Elements (PR #143198)
@@ -71,6 +71,199 @@ static raw_ostream &operator<<(raw_ostream &OS, return OS; } +static raw_ostream &operator<<(raw_ostream &OS, const SamplerFilter &Filter) { + switch (Filter) { + case SamplerFilter::MinMagMipPoint: +OS << "MinMagMipPoint"; inbelic wrote: Yes! Thank you https://github.com/llvm/llvm-project/pull/143198 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
https://github.com/svkeerthy edited https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
llvmbot wrote: @llvm/pr-subscribers-mlgo Author: S. VenkataKeerthy (svkeerthy) Changes This PR changes some asserts in Vocab to hard checks that emit error and exposes flags and constructor to help in unit tests. (Tracking issue - #141817) --- Full diff: https://github.com/llvm/llvm-project/pull/143200.diff 3 Files Affected: - (modified) llvm/include/llvm/Analysis/IR2Vec.h (+10) - (modified) llvm/lib/Analysis/IR2Vec.cpp (+53-28) - (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+102-35) ``diff diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 930b13f079796..1bd80ed65d434 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -31,7 +31,9 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/IR/PassManager.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/JSON.h" #include namespace llvm { @@ -43,6 +45,7 @@ class Function; class Type; class Value; class raw_ostream; +class LLVMContext; /// IR2Vec computes two kinds of embeddings: Symbolic and Flow-aware. /// Symbolic embeddings capture the "syntactic" and "statistical correlation" @@ -53,6 +56,11 @@ class raw_ostream; enum class IR2VecKind { Symbolic }; namespace ir2vec { + +LLVM_ABI extern cl::opt OpcWeight; +LLVM_ABI extern cl::opt TypeWeight; +LLVM_ABI extern cl::opt ArgWeight; + /// Embedding is a ADT that wraps std::vector. It provides /// additional functionality for arithmetic and comparison operations. struct Embedding : public std::vector { @@ -187,10 +195,12 @@ class IR2VecVocabResult { class IR2VecVocabAnalysis : public AnalysisInfoMixin { ir2vec::Vocab Vocabulary; Error readVocabulary(); + void emitError(Error Err, LLVMContext &Ctx); public: static AnalysisKey Key; IR2VecVocabAnalysis() = default; + explicit IR2VecVocabAnalysis(ir2vec::Vocab &&Vocab); using Result = IR2VecVocabResult; Result run(Module &M, ModuleAnalysisManager &MAM); }; diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 8ee8e5b0ff74e..e751f10b8 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -16,13 +16,11 @@ #include "llvm/ADT/Statistic.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" -#include "llvm/Support/JSON.h" #include "llvm/Support/MemoryBuffer.h" using namespace llvm; @@ -33,6 +31,8 @@ using namespace ir2vec; STATISTIC(VocabMissCounter, "Number of lookups to entites not present in the vocabulary"); +namespace llvm { +namespace ir2vec { static cl::OptionCategory IR2VecCategory("IR2Vec Options"); // FIXME: Use a default vocab when not specified @@ -40,18 +40,20 @@ static cl::opt VocabFile("ir2vec-vocab-path", cl::Optional, cl::desc("Path to the vocabulary file for IR2Vec"), cl::init(""), cl::cat(IR2VecCategory)); -static cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, -cl::init(1.0), -cl::desc("Weight for opcode embeddings"), -cl::cat(IR2VecCategory)); -static cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, - cl::init(0.5), - cl::desc("Weight for type embeddings"), - cl::cat(IR2VecCategory)); -static cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, -cl::init(0.2), -cl::desc("Weight for argument embeddings"), -cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt OpcWeight("ir2vec-opc-weight", cl::Optional, + cl::init(1.0), + cl::desc("Weight for opcode embeddings"), + cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt TypeWeight("ir2vec-type-weight", cl::Optional, + cl::init(0.5), + cl::desc("Weight for type embeddings"), + cl::cat(IR2VecCategory)); +LLVM_ABI cl::opt ArgWeight("ir2vec-arg-weight", cl::Optional, + cl::init(0.2), + cl::desc("Weight for argument embeddings"), + cl::cat(IR2VecCategory)); +} // namespace ir2vec +} // namespace llvm AnalysisKey IR2VecVocabAnalysis::Key; @@ -83,9 +85,10 @@ void Embedding::scaleAndAdd(const Embedding &Src, float Factor) { bool Embedding::approximatelyEquals(const Embedding &RHS, double Tolerance) const { assert(this->size() == RHS.size() && "Vectors must have th
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
https://github.com/svkeerthy ready_for_review https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
https://github.com/svkeerthy edited https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL][RootSignature] Implement serialization of remaining Root Elements (PR #143198)
https://github.com/inbelic converted_to_draft https://github.com/llvm/llvm-project/pull/143198 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/143209?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#143209** https://app.graphite.dev/github/pr/llvm/llvm-project/143209?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/143209?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#142483** https://app.graphite.dev/github/pr/llvm/llvm-project/142483?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/143209 None >From b542436d77152cb8f5301da48ab77f687bd2f79b Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 3 Jun 2025 11:39:48 -0700 Subject: [PATCH] [clang-doc] add namespaces to JSON generator --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 34 ++ clang-tools-extra/clang-doc/Serialize.cpp | 1 + .../clang-doc/json/function-specifiers.cpp| 26 + .../test/clang-doc/json/namespace.cpp | 108 ++ .../unittests/clang-doc/JSONGeneratorTest.cpp | 73 5 files changed, 242 insertions(+) create mode 100644 clang-tools-extra/test/clang-doc/json/function-specifiers.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/namespace.cpp diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 0459d061cd138..4d6b4c43c3d2d 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -372,6 +372,39 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj, serializeCommonChildren(I.Children, Obj, RepositoryUrl); } +static void serializeInfo(const NamespaceInfo &I, json::Object &Obj, + std::optional RepositoryUrl) { + serializeCommonAttributes(I, Obj, RepositoryUrl); + SmallString<64> BasePath = I.getRelativeFilePath(""); + Obj["NamespacePath"] = BasePath; + + if (!I.Children.Namespaces.empty()) { +json::Value NamespacesArray = Array(); +auto &NamespacesArrayRef = *NamespacesArray.getAsArray(); +for (auto &Namespace : I.Children.Namespaces) { + json::Value NamespaceVal = Object(); + auto &NamespaceObj = *NamespaceVal.getAsObject(); + serializeReference(Namespace, NamespaceObj, BasePath); + NamespacesArrayRef.push_back(NamespaceVal); +} +Obj["Namespaces"] = NamespacesArray; + } + + if (!I.Children.Functions.empty()) { +json::Value FunctionsArray = Array(); +auto &FunctionsArrayRef = *FunctionsArray.getAsArray(); +for (const auto &Function : I.Children.Functions) { + json::Value FunctionVal = Object(); + auto &FunctionObj = *FunctionVal.getAsObject(); + serializeInfo(Function, FunctionObj, RepositoryUrl); + FunctionsArrayRef.push_back(FunctionVal); +} +Obj["Functions"] = FunctionsArray; + } + + serializeCommonChildren(I.Children, Obj, RepositoryUrl); +} + Error JSONGenerator::generateDocs( StringRef RootDir, llvm::StringMap> Infos, const ClangDocContext &CDCtx) { @@ -414,6 +447,7 @@ Error JSONGenerator::generateDocForInfo(Info *I, raw_ostream &OS, switch (I->IT) { case InfoType::IT_namespace: +serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); break; case InfoType::IT_record: serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 3932a939de973..863b1894abbbf 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -742,6 +742,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, I.ReturnType = getTypeInfoForType(D->getReturnType(), LO); I.Prototype = getFunctionPrototype(D); parseParameters(I, D); + I.IsStatic = D->isStatic(); populateTemplateParameters(I.Template, D); diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp new file mode 100644 index 0..dab4c559d0b6e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp @@ -0,0 +1,26 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, +// COM:FIXME: Emit ExceptionSpecificationType +// CHECK-NOT: "ExceptionSpecifcation" : "noexcept", +// COM:FIXME: Emit inline +// CHECK-NOT: "IsInline": true, +// COM:FIXME: Emit extern +// CHECK-NOT: "IsExtern": true, +// COM:FIXME: Emit constexpr +// CHECK-NOT: "IsConstexpr": true, +// CHECK-NOT: "IsConstexpr": true, diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp new file mode 100644 index 0..885dbd841ac2e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -0,0 +1,108 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileChe
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
https://github.com/svkeerthy edited https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
@@ -83,9 +85,10 @@ void Embedding::scaleAndAdd(const Embedding &Src, float Factor) { bool Embedding::approximatelyEquals(const Embedding &RHS, double Tolerance) const { assert(this->size() == RHS.size() && "Vectors must have the same dimension"); - for (size_t i = 0; i < this->size(); ++i) + for (size_t i = 0; i < this->size(); ++i) { mtrofin wrote: I not i https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
@@ -83,9 +85,10 @@ void Embedding::scaleAndAdd(const Embedding &Src, float Factor) { bool Embedding::approximatelyEquals(const Embedding &RHS, double Tolerance) const { assert(this->size() == RHS.size() && "Vectors must have the same dimension"); - for (size_t i = 0; i < this->size(); ++i) + for (size_t i = 0; i < this->size(); ++i) { mtrofin wrote: or... wait. This is from the PR below this in the stack... why the `{}`? https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
@@ -254,35 +257,57 @@ Error IR2VecVocabAnalysis::readVocabulary() { return createStringError(errc::illegal_byte_sequence, "Unable to parse the vocabulary"); } - assert(Vocabulary.size() > 0 && "Vocabulary is empty"); + + if (Vocabulary.empty()) { mtrofin wrote: you can avoid `{}` for simple cases like these https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [IR2Vec] Minor vocab changes and exposing weights (PR #143200)
mtrofin wrote: is it a nfc? (as in, add the tag if so - `[NFC]`) https://github.com/llvm/llvm-project/pull/143200 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [SPARC][IAS] Add definitions for cryptographic instructions (PR #139451)
koachan wrote: Ping? https://github.com/llvm/llvm-project/pull/139451 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT][NFC] Simplify doTrace in BAT mode (PR #143233)
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/143233 `BoltAddressTranslation::getFallthroughsInTrace` iterates over address translation map entries and therefore has direct access to both original and translated offsets. Return the translated offsets in fall-throughs list to avoid duplicate address translation inside `doTrace`. Test Plan: NFC ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT][NFC] Simplify doTrace in BAT mode (PR #143233)
https://github.com/aaupov ready_for_review https://github.com/llvm/llvm-project/pull/143233 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [BOLT][NFC] Simplify doTrace in BAT mode (PR #143233)
llvmbot wrote: @llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) Changes `BoltAddressTranslation::getFallthroughsInTrace` iterates over address translation map entries and therefore has direct access to both original and translated offsets. Return the translated offsets in fall-throughs list to avoid duplicate address translation inside `doTrace`. Test Plan: NFC --- Full diff: https://github.com/llvm/llvm-project/pull/143233.diff 2 Files Affected: - (modified) bolt/lib/Profile/BoltAddressTranslation.cpp (+2-2) - (modified) bolt/lib/Profile/DataAggregator.cpp (+1-6) ``diff diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp b/bolt/lib/Profile/BoltAddressTranslation.cpp index a253522e4fb15..7ad4e6a2e1411 100644 --- a/bolt/lib/Profile/BoltAddressTranslation.cpp +++ b/bolt/lib/Profile/BoltAddressTranslation.cpp @@ -546,7 +546,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress, return Res; for (auto Iter = FromIter; Iter != ToIter;) { -const uint32_t Src = Iter->first; +const uint32_t Src = Iter->second >> 1; if (Iter->second & BRANCHENTRY) { ++Iter; continue; @@ -557,7 +557,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress, ++Iter; if (Iter->second & BRANCHENTRY) break; -Res.emplace_back(Src, Iter->first); +Res.emplace_back(Src, Iter->second >> 1); } return Res; diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index 752b00c7de4e8..52452a3bb0d46 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -827,13 +827,8 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second, << FromFunc->getPrintName() << ":" << Twine::utohexstr(First.To) << " to " << Twine::utohexstr(Second.From) << ".\n"); - for (auto [From, To] : *FTs) { -if (BAT) { - From = BAT->translate(FromFunc->getAddress(), From, /*IsBranchSrc=*/true); - To = BAT->translate(FromFunc->getAddress(), To, /*IsBranchSrc=*/false); -} + for (auto [From, To] : *FTs) doIntraBranch(*ParentFunc, From, To, Count, false); - } return true; } `` https://github.com/llvm/llvm-project/pull/143233 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits