[llvm] 7950010 - [VE][NFC] Factor out helper functions
Simon Moll via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 21 00:17:06 PST 2022
Author: Simon Moll
Date: 2022-01-21T09:15:59+01:00
New Revision: 7950010e4983a58d19a5d8a831f4c2467c04c56d
URL: https://github.com/llvm/llvm-project/commit/7950010e4983a58d19a5d8a831f4c2467c04c56d
DIFF: https://github.com/llvm/llvm-project/commit/7950010e4983a58d19a5d8a831f4c2467c04c56d.diff
LOG: [VE][NFC] Factor out helper functions
Factor out some helper functions to cleanup VEISelLowering.
Reviewed By: kaz7
Differential Revision: https://reviews.llvm.org/D117683
Added:
Modified:
llvm/lib/Target/VE/VECustomDAG.cpp
llvm/lib/Target/VE/VECustomDAG.h
llvm/lib/Target/VE/VEISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/VE/VECustomDAG.cpp b/llvm/lib/Target/VE/VECustomDAG.cpp
index 98348c504990d..2f9976e426129 100644
--- a/llvm/lib/Target/VE/VECustomDAG.cpp
+++ b/llvm/lib/Target/VE/VECustomDAG.cpp
@@ -19,9 +19,39 @@
namespace llvm {
+/// \returns the VVP_* SDNode opcode corresponsing to \p OC.
+Optional<unsigned> getVVPOpcode(unsigned Opcode) {
+ switch (Opcode) {
+#define HANDLE_VP_TO_VVP(VPOPC, VVPNAME) \
+ case ISD::VPOPC: \
+ return VEISD::VVPNAME;
+#define ADD_VVP_OP(VVPNAME, SDNAME) \
+ case VEISD::VVPNAME: \
+ case ISD::SDNAME: \
+ return VEISD::VVPNAME;
+#include "VVPNodes.def"
+ }
+ return None;
+}
+
+bool isVVPBinaryOp(unsigned VVPOpcode) {
+ switch (VVPOpcode) {
+#define ADD_BINARY_VVP_OP(VVPNAME, ...) \
+ case VEISD::VVPNAME: \
+ return true;
+#include "VVPNodes.def"
+ }
+ return false;
+}
+
SDValue VECustomDAG::getConstant(uint64_t Val, EVT VT, bool IsTarget,
bool IsOpaque) const {
return DAG.getConstant(Val, DL, VT, IsTarget, IsOpaque);
}
+SDValue VECustomDAG::getBroadcast(EVT ResultVT, SDValue Scalar,
+ SDValue AVL) const {
+ return getNode(VEISD::VEC_BROADCAST, ResultVT, {Scalar, AVL});
+}
+
} // namespace llvm
diff --git a/llvm/lib/Target/VE/VECustomDAG.h b/llvm/lib/Target/VE/VECustomDAG.h
index 05c4c603c2fa9..e78b5dda6828c 100644
--- a/llvm/lib/Target/VE/VECustomDAG.h
+++ b/llvm/lib/Target/VE/VECustomDAG.h
@@ -21,6 +21,10 @@
namespace llvm {
+Optional<unsigned> getVVPOpcode(unsigned Opcode);
+
+bool isVVPBinaryOp(unsigned Opcode);
+
class VECustomDAG {
SelectionDAG &DAG;
SDLoc DL;
@@ -64,6 +68,8 @@ class VECustomDAG {
SDValue getConstant(uint64_t Val, EVT VT, bool IsTarget = false,
bool IsOpaque = false) const;
+
+ SDValue getBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;
};
} // namespace llvm
diff --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp
index abedee4788d9d..3ab876aa05c99 100644
--- a/llvm/lib/Target/VE/VEISelLowering.cpp
+++ b/llvm/lib/Target/VE/VEISelLowering.cpp
@@ -1661,8 +1661,7 @@ SDValue VETargetLowering::lowerBUILD_VECTOR(SDValue Op,
MVT LegalResVT = MVT::getVectorVT(ElemVT, 256);
auto AVL = CDAG.getConstant(NumEls, MVT::i32);
- return CDAG.getNode(VEISD::VEC_BROADCAST, LegalResVT,
- {Op.getOperand(0), AVL});
+ return CDAG.getBroadcast(LegalResVT, Op.getOperand(0), AVL);
}
// Expand
@@ -2667,21 +2666,6 @@ bool VETargetLowering::hasAndNot(SDValue Y) const {
return true;
}
-/// \returns the VVP_* SDNode opcode corresponsing to \p OC.
-static Optional<unsigned> getVVPOpcode(unsigned Opcode) {
- switch (Opcode) {
-#define HANDLE_VP_TO_VVP(VPOPC, VVPNAME) \
- case ISD::VPOPC: \
- return VEISD::VVPNAME;
-#define ADD_VVP_OP(VVPNAME, SDNAME) \
- case VEISD::VVPNAME: \
- case ISD::SDNAME: \
- return VEISD::VVPNAME;
-#include "VVPNodes.def"
- }
- return None;
-}
-
SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
// Can we represent this as a VVP node.
const unsigned Opcode = Op->getOpcode();
@@ -2711,26 +2695,15 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
// Materialize the VL parameter.
AVL = CDAG.getConstant(OpVecVT.getVectorNumElements(), MVT::i32);
SDValue ConstTrue = CDAG.getConstant(1, MVT::i32);
- Mask = CDAG.getNode(VEISD::VEC_BROADCAST, MaskVT,
- ConstTrue); // emit a VEISD::VEC_BROADCAST here.
+ Mask = CDAG.getBroadcast(MaskVT, ConstTrue, AVL);
}
- // Categories we are interested in.
- bool IsBinaryOp = false;
-
- switch (VVPOpcode) {
-#define ADD_BINARY_VVP_OP(VVPNAME, ...) \
- case VEISD::VVPNAME: \
- IsBinaryOp = true; \
- break;
-#include "VVPNodes.def"
- }
-
- if (IsBinaryOp) {
+ if (isVVPBinaryOp(VVPOpcode)) {
assert(LegalVecVT.isSimple());
return CDAG.getNode(VVPOpcode, LegalVecVT,
{Op->getOperand(0), Op->getOperand(1), Mask, AVL});
- } else if (VVPOpcode == VEISD::VVP_SELECT) {
+ }
+ if (VVPOpcode == VEISD::VVP_SELECT) {
auto Mask = Op->getOperand(0);
auto OnTrue = Op->getOperand(1);
auto OnFalse = Op->getOperand(2);
More information about the llvm-commits
mailing list