1 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
2 #include "GISelMITest.h"
3 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
4 #include "llvm/CodeGen/TargetPassConfig.h"
5 #include "llvm/IR/LegacyPassManager.h"
9 class EraseMockInstructionSelector
: public InstructionSelector
{
12 SmallVector
<MachineInstr
*> MIs
;
14 bool select(MachineInstr
&MI
) override
{
16 switch (NumSelected
) {
18 EXPECT_EQ(&MI
, MIs
[8]);
19 // Erase previous instructions
20 MIs
[7]->eraseFromParent();
21 MIs
[6]->eraseFromParent();
22 // Don't erase this MI before step 3 to prevent DCE
25 EXPECT_EQ(&MI
, MIs
[5]);
26 // Erase previous instructions reversed
27 MIs
[3]->eraseFromParent();
28 MIs
[4]->eraseFromParent();
32 EXPECT_EQ(&MI
, MIs
[2]);
33 MIs
[8]->eraseFromParent();
34 // Erase first instructions
35 MIs
[0]->eraseFromParent();
36 MIs
[1]->eraseFromParent();
45 void setupGeneratedPerFunctionState(MachineFunction
&MF
) override
{}
48 TEST_F(AArch64GISelMITest
, TestInstructionSelectErase
) {
49 StringRef MIRString
= R
"(
61 legacy::PassManager PM
;
62 std::unique_ptr
<TargetPassConfig
> TPC(TM
->createPassConfig(PM
));
64 EraseMockInstructionSelector ISel
;
66 for (auto &MI
: *EntryMBB
) {
67 ISel
.MIs
.push_back(&MI
);
70 InstructionSelect ISelPass
;
71 ISelPass
.setInstructionSelector(&ISel
);
72 ISelPass
.selectMachineFunction(*MF
);
73 EXPECT_EQ(ISel
.NumSelected
, 3);