[PATCH] D61980: GlobalISel: Add DstOp version of buildIntrinsic
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 20:14:44 PDT 2019
arsenm created this revision.
arsenm added reviewers: dsanders, aditya_nandakumar, aemerson, paquette.
Herald added subscribers: Petar.Avramovic, volkan, kristof.beyls, rovka, wdng.
https://reviews.llvm.org/D61980
Files:
include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
Index: unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
+++ unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp
@@ -143,3 +143,31 @@
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+
+TEST_F(GISelMITest, BuildIntrinsic) {
+ if (!TM)
+ return;
+
+ LLT S64 = LLT::scalar(64);
+ SmallVector<unsigned, 4> Copies;
+ collectCopies(Copies, MF);
+
+ // Make sure DstOp version works. sqrt is just a placeholder intrinsic.
+ B.buildIntrinsic(Intrinsic::sqrt, {S64}, false)
+ .addUse(Copies[0]);
+
+ // Make sure register version works
+ SmallVector<unsigned, 1> Results;
+ Results.push_back(MRI->createGenericVirtualRegister(S64));
+ B.buildIntrinsic(Intrinsic::sqrt, Results, false)
+ .addUse(Copies[1]);
+
+ auto CheckStr = R"(
+ ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0
+ ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
+ ; CHECK: [[SQRT0:%[0-9]+]]:_(s64) = G_INTRINSIC intrinsic(@llvm.sqrt), [[COPY0]]:_
+ ; CHECK: [[SQRT1:%[0-9]+]]:_(s64) = G_INTRINSIC intrinsic(@llvm.sqrt), [[COPY1]]:_
+ )";
+
+ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
+}
Index: lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
===================================================================
--- lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -691,6 +691,18 @@
return MIB;
}
+MachineInstrBuilder MachineIRBuilder::buildIntrinsic(Intrinsic::ID ID,
+ ArrayRef<DstOp> Results,
+ bool HasSideEffects) {
+ auto MIB =
+ buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
+ : TargetOpcode::G_INTRINSIC);
+ for (DstOp Result : Results)
+ Result.addDefToMIB(*getMRI(), MIB);
+ MIB.addIntrinsicID(ID);
+ return MIB;
+}
+
MachineInstrBuilder MachineIRBuilder::buildTrunc(const DstOp &Res,
const SrcOp &Op) {
return buildInstr(TargetOpcode::G_TRUNC, Res, Op);
Index: include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -818,6 +818,8 @@
/// \return a MachineInstrBuilder for the newly created instruction.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<unsigned> Res,
bool HasSideEffects);
+ MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res,
+ bool HasSideEffects);
/// Build and insert \p Res = G_FPTRUNC \p Op
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61980.199722.patch
Type: text/x-patch
Size: 2842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/4c8c99fd/attachment.bin>
More information about the llvm-commits
mailing list