Skip to content

Commit 27ac840

Browse files
committed
GlobalISel: Add DstOp version of buildIntrinsic
llvm-svn: 360879
1 parent 4da9ff9 commit 27ac840

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

+2
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ class MachineIRBuilder {
797797
/// \return a MachineInstrBuilder for the newly created instruction.
798798
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<unsigned> Res,
799799
bool HasSideEffects);
800+
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res,
801+
bool HasSideEffects);
800802

801803
/// Build and insert \p Res = G_FPTRUNC \p Op
802804
///

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ MachineInstrBuilder MachineIRBuilder::buildIntrinsic(Intrinsic::ID ID,
634634
return MIB;
635635
}
636636

637+
MachineInstrBuilder MachineIRBuilder::buildIntrinsic(Intrinsic::ID ID,
638+
ArrayRef<DstOp> Results,
639+
bool HasSideEffects) {
640+
auto MIB =
641+
buildInstr(HasSideEffects ? TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS
642+
: TargetOpcode::G_INTRINSIC);
643+
for (DstOp Result : Results)
644+
Result.addDefToMIB(*getMRI(), MIB);
645+
MIB.addIntrinsicID(ID);
646+
return MIB;
647+
}
648+
637649
MachineInstrBuilder MachineIRBuilder::buildTrunc(const DstOp &Res,
638650
const SrcOp &Op) {
639651
return buildInstr(TargetOpcode::G_TRUNC, Res, Op);

llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,31 @@ TEST_F(GISelMITest, TestBuildFPInsts) {
143143

144144
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
145145
}
146+
147+
TEST_F(GISelMITest, BuildIntrinsic) {
148+
if (!TM)
149+
return;
150+
151+
LLT S64 = LLT::scalar(64);
152+
SmallVector<unsigned, 4> Copies;
153+
collectCopies(Copies, MF);
154+
155+
// Make sure DstOp version works. sqrt is just a placeholder intrinsic.
156+
B.buildIntrinsic(Intrinsic::sqrt, {S64}, false)
157+
.addUse(Copies[0]);
158+
159+
// Make sure register version works
160+
SmallVector<unsigned, 1> Results;
161+
Results.push_back(MRI->createGenericVirtualRegister(S64));
162+
B.buildIntrinsic(Intrinsic::sqrt, Results, false)
163+
.addUse(Copies[1]);
164+
165+
auto CheckStr = R"(
166+
; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0
167+
; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
168+
; CHECK: [[SQRT0:%[0-9]+]]:_(s64) = G_INTRINSIC intrinsic(@llvm.sqrt), [[COPY0]]:_
169+
; CHECK: [[SQRT1:%[0-9]+]]:_(s64) = G_INTRINSIC intrinsic(@llvm.sqrt), [[COPY1]]:_
170+
)";
171+
172+
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
173+
}

0 commit comments

Comments
 (0)