From a435513a7c9513a43aef3cc902d7578682a4aff1 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 4 Feb 2019 19:53:19 +0000 Subject: [PATCH] GlobalISel: Allow constructing SrcOp/DstOp from MachineOperand git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353080 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h | 2 ++ .../CodeGen/GlobalISel/MachineIRBuilderTest.cpp | 25 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index 44077a40975..1c5348b6cff 100644 --- a/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -66,6 +66,7 @@ class DstOp { public: enum class DstType { Ty_LLT, Ty_Reg, Ty_RC }; DstOp(unsigned R) : Reg(R), Ty(DstType::Ty_Reg) {} + DstOp(const MachineOperand &Op) : Reg(Op.getReg()), Ty(DstType::Ty_Reg) {} DstOp(const LLT &T) : LLTTy(T), Ty(DstType::Ty_LLT) {} DstOp(const TargetRegisterClass *TRC) : RC(TRC), Ty(DstType::Ty_RC) {} @@ -125,6 +126,7 @@ class SrcOp { public: enum class SrcType { Ty_Reg, Ty_MIB, Ty_Predicate }; SrcOp(unsigned R) : Reg(R), Ty(SrcType::Ty_Reg) {} + SrcOp(const MachineOperand &Op) : Reg(Op.getReg()), Ty(SrcType::Ty_Reg) {} SrcOp(const MachineInstrBuilder &MIB) : SrcMIB(MIB), Ty(SrcType::Ty_MIB) {} SrcOp(const CmpInst::Predicate P) : Pred(P), Ty(SrcType::Ty_Predicate) {} diff --git a/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp b/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp index 9a2533159be..d64f5747e72 100644 --- a/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp +++ b/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp @@ -65,3 +65,28 @@ TEST_F(GISelMITest, TestBuildConstantFConstantDeath) { #endif #endif + +TEST_F(GISelMITest, DstOpSrcOp) { + if (!TM) + return; + + SmallVector Copies; + collectCopies(Copies, MF); + + LLT s64 = LLT::scalar(64); + auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]); + + // Test SrcOp and DstOp can be constructed directly from MachineOperand by + // copying the instruction + B.buildAdd(MIBAdd->getOperand(0), MIBAdd->getOperand(1), MIBAdd->getOperand(2)); + + + auto CheckStr = R"( + ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0 + ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1 + ; CHECK: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[COPY0]]:_, [[COPY1]]:_ + ; CHECK: [[ADD]]:_(s64) = G_ADD [[COPY0]]:_, [[COPY1]]:_ + )"; + + EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; +} -- 2.11.0