Skip to content

Commit 7950010

Browse files
author
Simon Moll
committed
[VE][NFC] Factor out helper functions
Factor out some helper functions to cleanup VEISelLowering. Reviewed By: kaz7 Differential Revision: https://reviews.llvm.org/D117683
1 parent 6a19cb8 commit 7950010

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

llvm/lib/Target/VE/VECustomDAG.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,39 @@
1919

2020
namespace llvm {
2121

22+
/// \returns the VVP_* SDNode opcode corresponsing to \p OC.
23+
Optional<unsigned> getVVPOpcode(unsigned Opcode) {
24+
switch (Opcode) {
25+
#define HANDLE_VP_TO_VVP(VPOPC, VVPNAME) \
26+
case ISD::VPOPC: \
27+
return VEISD::VVPNAME;
28+
#define ADD_VVP_OP(VVPNAME, SDNAME) \
29+
case VEISD::VVPNAME: \
30+
case ISD::SDNAME: \
31+
return VEISD::VVPNAME;
32+
#include "VVPNodes.def"
33+
}
34+
return None;
35+
}
36+
37+
bool isVVPBinaryOp(unsigned VVPOpcode) {
38+
switch (VVPOpcode) {
39+
#define ADD_BINARY_VVP_OP(VVPNAME, ...) \
40+
case VEISD::VVPNAME: \
41+
return true;
42+
#include "VVPNodes.def"
43+
}
44+
return false;
45+
}
46+
2247
SDValue VECustomDAG::getConstant(uint64_t Val, EVT VT, bool IsTarget,
2348
bool IsOpaque) const {
2449
return DAG.getConstant(Val, DL, VT, IsTarget, IsOpaque);
2550
}
2651

52+
SDValue VECustomDAG::getBroadcast(EVT ResultVT, SDValue Scalar,
53+
SDValue AVL) const {
54+
return getNode(VEISD::VEC_BROADCAST, ResultVT, {Scalar, AVL});
55+
}
56+
2757
} // namespace llvm

llvm/lib/Target/VE/VECustomDAG.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
namespace llvm {
2323

24+
Optional<unsigned> getVVPOpcode(unsigned Opcode);
25+
26+
bool isVVPBinaryOp(unsigned Opcode);
27+
2428
class VECustomDAG {
2529
SelectionDAG &DAG;
2630
SDLoc DL;
@@ -64,6 +68,8 @@ class VECustomDAG {
6468

6569
SDValue getConstant(uint64_t Val, EVT VT, bool IsTarget = false,
6670
bool IsOpaque = false) const;
71+
72+
SDValue getBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;
6773
};
6874

6975
} // namespace llvm

llvm/lib/Target/VE/VEISelLowering.cpp

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,8 +1661,7 @@ SDValue VETargetLowering::lowerBUILD_VECTOR(SDValue Op,
16611661
MVT LegalResVT = MVT::getVectorVT(ElemVT, 256);
16621662

16631663
auto AVL = CDAG.getConstant(NumEls, MVT::i32);
1664-
return CDAG.getNode(VEISD::VEC_BROADCAST, LegalResVT,
1665-
{Op.getOperand(0), AVL});
1664+
return CDAG.getBroadcast(LegalResVT, Op.getOperand(0), AVL);
16661665
}
16671666

16681667
// Expand
@@ -2667,21 +2666,6 @@ bool VETargetLowering::hasAndNot(SDValue Y) const {
26672666
return true;
26682667
}
26692668

2670-
/// \returns the VVP_* SDNode opcode corresponsing to \p OC.
2671-
static Optional<unsigned> getVVPOpcode(unsigned Opcode) {
2672-
switch (Opcode) {
2673-
#define HANDLE_VP_TO_VVP(VPOPC, VVPNAME) \
2674-
case ISD::VPOPC: \
2675-
return VEISD::VVPNAME;
2676-
#define ADD_VVP_OP(VVPNAME, SDNAME) \
2677-
case VEISD::VVPNAME: \
2678-
case ISD::SDNAME: \
2679-
return VEISD::VVPNAME;
2680-
#include "VVPNodes.def"
2681-
}
2682-
return None;
2683-
}
2684-
26852669
SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
26862670
// Can we represent this as a VVP node.
26872671
const unsigned Opcode = Op->getOpcode();
@@ -2711,26 +2695,15 @@ SDValue VETargetLowering::lowerToVVP(SDValue Op, SelectionDAG &DAG) const {
27112695
// Materialize the VL parameter.
27122696
AVL = CDAG.getConstant(OpVecVT.getVectorNumElements(), MVT::i32);
27132697
SDValue ConstTrue = CDAG.getConstant(1, MVT::i32);
2714-
Mask = CDAG.getNode(VEISD::VEC_BROADCAST, MaskVT,
2715-
ConstTrue); // emit a VEISD::VEC_BROADCAST here.
2698+
Mask = CDAG.getBroadcast(MaskVT, ConstTrue, AVL);
27162699
}
27172700

2718-
// Categories we are interested in.
2719-
bool IsBinaryOp = false;
2720-
2721-
switch (VVPOpcode) {
2722-
#define ADD_BINARY_VVP_OP(VVPNAME, ...) \
2723-
case VEISD::VVPNAME: \
2724-
IsBinaryOp = true; \
2725-
break;
2726-
#include "VVPNodes.def"
2727-
}
2728-
2729-
if (IsBinaryOp) {
2701+
if (isVVPBinaryOp(VVPOpcode)) {
27302702
assert(LegalVecVT.isSimple());
27312703
return CDAG.getNode(VVPOpcode, LegalVecVT,
27322704
{Op->getOperand(0), Op->getOperand(1), Mask, AVL});
2733-
} else if (VVPOpcode == VEISD::VVP_SELECT) {
2705+
}
2706+
if (VVPOpcode == VEISD::VVP_SELECT) {
27342707
auto Mask = Op->getOperand(0);
27352708
auto OnTrue = Op->getOperand(1);
27362709
auto OnFalse = Op->getOperand(2);

0 commit comments

Comments
 (0)