summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
diff options
context:
space:
mode:
authorAditya Nandakumar <aditya_nandakumar@apple.com>2018-12-11 00:48:50 +0000
committerAditya Nandakumar <aditya_nandakumar@apple.com>2018-12-11 00:48:50 +0000
commitcef44a234219e38e1c28c902ff24586150eef682 (patch)
tree2705ca0e1b39e7b3b20ead9915324c0c3a2c7f5a /llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
parenta041679d4664854eb01c6b7eef0579902befe5ef (diff)
downloadbcm5719-llvm-cef44a234219e38e1c28c902ff24586150eef682.tar.gz
bcm5719-llvm-cef44a234219e38e1c28c902ff24586150eef682.zip
[GISel]: Refactor MachineIRBuilder to allow passing additional parameters to build Instrs
https://reviews.llvm.org/D55294 Previously MachineIRBuilder::buildInstr used to accept variadic arguments for sources (which were either unsigned or MachineInstrBuilder). While this worked well in common cases, it doesn't allow us to build instructions that have multiple destinations. Additionally passing in other optional parameters in the end (such as flags) is not possible trivially. Also a trivial call such as B.buildInstr(Opc, Reg1, Reg2, Reg3) can be interpreted differently based on the opcode (2defs + 1 src for unmerge vs 1 def + 2srcs). This patch refactors the buildInstr to buildInstr(Opc, ArrayRef<DstOps>, ArrayRef<SrcOps>) where DstOps and SrcOps are typed unions that know how to add itself to MachineInstrBuilder. After this patch, most invocations would look like B.buildInstr(Opc, {s32, DstReg}, {SrcRegs..., SrcMIBs..}); Now all the other calls (such as buildAdd, buildSub etc) forward to buildInstr. It also makes it possible to build instructions with multiple defs. Additionally in a subsequent patch, we should make it possible to add flags directly while building instructions. Additionally, the main buildInstr method is now virtual and other builders now only have to override buildInstr (for say constant folding/cseing) is straightforward. Also attached here (https://reviews.llvm.org/F7675680) is a clang-tidy patch that should upgrade the API calls if necessary. llvm-svn: 348815
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
index 1f3a690ad01..466a2dd6b06 100644
--- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -204,8 +204,8 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
m_GSub(m_ICst(Cst), m_Reg(Src0)));
ASSERT_FALSE(match);
- auto MIBFMul = B.buildInstr(TargetOpcode::G_FMUL, s64, Copies[0],
- B.buildConstant(s64, 42));
+ auto MIBFMul = B.buildInstr(TargetOpcode::G_FMUL, {s64},
+ {Copies[0], B.buildConstant(s64, 42)});
// Match and test commutativity for FMUL.
match = mi_match(MIBFMul->getOperand(0).getReg(), MRI,
m_GFMul(m_ICst(Cst), m_Reg(Src0)));
@@ -214,8 +214,8 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
ASSERT_EQ(Src0, Copies[0]);
// FSUB
- auto MIBFSub = B.buildInstr(TargetOpcode::G_FSUB, s64, Copies[0],
- B.buildConstant(s64, 42));
+ auto MIBFSub = B.buildInstr(TargetOpcode::G_FSUB, {s64},
+ {Copies[0], B.buildConstant(s64, 42)});
match = mi_match(MIBFSub->getOperand(0).getReg(), MRI,
m_GFSub(m_Reg(Src0), m_Reg()));
ASSERT_TRUE(match);
@@ -249,8 +249,8 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
ASSERT_TRUE(match);
ASSERT_EQ(Cst, 1);
auto MIBCAdd1 =
- CFB.buildInstr(TargetOpcode::G_ADD, s32, CFB.buildConstant(s32, 0),
- CFB.buildConstant(s32, 1));
+ CFB.buildInstr(TargetOpcode::G_ADD, {s32},
+ {CFB.buildConstant(s32, 0), CFB.buildConstant(s32, 1)});
// This should be a constant now.
match = mi_match(MIBCAdd1->getOperand(0).getReg(), MRI, m_ICst(Cst));
ASSERT_TRUE(match);
@@ -261,8 +261,8 @@ TEST(PatternMatchInstr, MatchBinaryOp) {
ConstantFoldingMIRBuilder CFB1(*MF);
CFB1.setInsertPt(*EntryMBB, EntryMBB->end());
auto MIBCSub =
- CFB1.buildInstr(TargetOpcode::G_SUB, s32, CFB1.buildConstant(s32, 1),
- CFB1.buildConstant(s32, 1));
+ CFB1.buildInstr(TargetOpcode::G_SUB, {s32},
+ {CFB1.buildConstant(s32, 1), CFB1.buildConstant(s32, 1)});
// This should be a constant now.
match = mi_match(MIBCSub->getOperand(0).getReg(), MRI, m_ICst(Cst));
ASSERT_TRUE(match);
@@ -289,12 +289,12 @@ TEST(PatternMatchInstr, MatchFPUnaryOp) {
auto Copy0s32 = B.buildFPTrunc(s32, Copies[0]);
// Match G_FABS.
- auto MIBFabs = B.buildInstr(TargetOpcode::G_FABS, s32, Copy0s32);
+ auto MIBFabs = B.buildInstr(TargetOpcode::G_FABS, {s32}, {Copy0s32});
bool match = mi_match(MIBFabs->getOperand(0).getReg(), MRI, m_GFabs(m_Reg()));
ASSERT_TRUE(match);
unsigned Src;
- auto MIBFNeg = B.buildInstr(TargetOpcode::G_FNEG, s32, Copy0s32);
+ auto MIBFNeg = B.buildInstr(TargetOpcode::G_FNEG, {s32}, {Copy0s32});
match = mi_match(MIBFNeg->getOperand(0).getReg(), MRI, m_GFNeg(m_Reg(Src)));
ASSERT_TRUE(match);
ASSERT_EQ(Src, Copy0s32->getOperand(0).getReg());
OpenPOWER on IntegriCloud