[PATCH] D117378: [RISCV] [NFC] Use macro to reduce repetive switch cases
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 18:07:04 PST 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: craig.topper, LevyHsu, benshi001, Jimerlife.
Chenbing.Zheng added a project: LLVM.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan, MaskRay.
These cases follows the same pattern,Use a macro to reduce
the number of source code lines.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117378
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -6229,20 +6229,6 @@
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
return;
}
- case Intrinsic::riscv_grev:
- case Intrinsic::riscv_gorc: {
- assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
- "Unexpected custom legalisation");
- SDValue NewOp1 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
- SDValue NewOp2 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(2));
- unsigned Opc =
- IntNo == Intrinsic::riscv_grev ? RISCVISD::GREVW : RISCVISD::GORCW;
- SDValue Res = DAG.getNode(Opc, DL, MVT::i64, NewOp1, NewOp2);
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
- break;
- }
case Intrinsic::riscv_shfl:
case Intrinsic::riscv_unshfl: {
assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
@@ -6263,32 +6249,6 @@
Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
break;
}
- case Intrinsic::riscv_bcompress:
- case Intrinsic::riscv_bdecompress: {
- assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
- "Unexpected custom legalisation");
- SDValue NewOp1 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
- SDValue NewOp2 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(2));
- unsigned Opc = IntNo == Intrinsic::riscv_bcompress
- ? RISCVISD::BCOMPRESSW
- : RISCVISD::BDECOMPRESSW;
- SDValue Res = DAG.getNode(Opc, DL, MVT::i64, NewOp1, NewOp2);
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
- break;
- }
- case Intrinsic::riscv_bfp: {
- assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() &&
- "Unexpected custom legalisation");
- SDValue NewOp1 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1));
- SDValue NewOp2 =
- DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(2));
- SDValue Res = DAG.getNode(RISCVISD::BFPW, DL, MVT::i64, NewOp1, NewOp2);
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res));
- break;
- }
case Intrinsic::riscv_vmv_x_s: {
EVT VT = N->getValueType(0);
MVT XLenVT = Subtarget.getXLenVT();
@@ -6325,8 +6285,25 @@
DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, EltLo, EltHi));
break;
}
- }
+#define CASE_EXTEND_TWO_OPERAND(intrinsic, opcode) \
+ case Intrinsic::intrinsic: { \
+ assert(N->getValueType(0) == MVT::i32 && Subtarget.is64Bit() && \
+ "Unexpected custom legalisation"); \
+ SDValue NewOp1 = \
+ DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(1)); \
+ SDValue NewOp2 = \
+ DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, N->getOperand(2)); \
+ SDValue Res = DAG.getNode(RISCVISD::opcode, DL, MVT::i64, NewOp1, NewOp2); \
+ Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Res)); \
break;
+ }
+ CASE_EXTEND_TWO_OPERAND(riscv_grev, GREVW)
+ CASE_EXTEND_TWO_OPERAND(riscv_gorc, GORCW)
+ CASE_EXTEND_TWO_OPERAND(riscv_bcompress, BCOMPRESSW)
+ CASE_EXTEND_TWO_OPERAND(riscv_bdecompress, BDECOMPRESSW)
+ CASE_EXTEND_TWO_OPERAND(riscv_bfp, BFPW)
+#undef CASE_EXTEND_TWO_OPERAND
+ } break;
}
case ISD::VECREDUCE_ADD:
case ISD::VECREDUCE_AND:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117378.400215.patch
Type: text/x-patch
Size: 3919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220115/07ed643a/attachment.bin>
More information about the llvm-commits
mailing list