diff options
author | Jay Foad <jay.foad@amd.com> | 2021-01-08 13:40:29 +0000 |
---|---|---|
committer | Jay Foad <jay.foad@amd.com> | 2021-01-12 10:50:14 +0000 |
commit | f264f9ad7df538357dfc8c5f318c5c8b0df3d99f (patch) | |
tree | 384092831f76016c209306c0262840975dafaa3b /llvm/unittests/MI | |
parent | c1e08f0073e35cf17c0a0343cf7efff914dbd66d (diff) | |
download | llvm-f264f9ad7df538357dfc8c5f318c5c8b0df3d99f.zip llvm-f264f9ad7df538357dfc8c5f318c5c8b0df3d99f.tar.gz llvm-f264f9ad7df538357dfc8c5f318c5c8b0df3d99f.tar.bz2 |
[SlotIndexes] Fix and simplify basic block splitting
Remove the InsertionPoint argument from SlotIndexes::insertMBBInMaps
because it was confusing: what does it mean to insert a new block
between two instructions, in the middle of an existing block?
Instead, support the case that MachineBasicBlock::splitAt really needs,
where the new block contains some instructions that are already in the
maps because they have been moved there from the tail of the previous
block.
In all other use cases the new block is empty.
Based on work by Carl Ritson!
Differential Revision: https://reviews.llvm.org/D94311
Diffstat (limited to 'llvm/unittests/MI')
-rw-r--r-- | llvm/unittests/MI/LiveIntervalTest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/unittests/MI/LiveIntervalTest.cpp b/llvm/unittests/MI/LiveIntervalTest.cpp index 3971d86..d367ee4 100644 --- a/llvm/unittests/MI/LiveIntervalTest.cpp +++ b/llvm/unittests/MI/LiveIntervalTest.cpp @@ -149,6 +149,19 @@ static void testHandleMoveIntoNewBundle(MachineFunction &MF, LiveIntervals &LIS, LIS.handleMoveIntoNewBundle(*BundleStart, true); } +/** + * Split block numbered \p BlockNum at instruction \p SplitAt using + * MachineBasicBlock::splitAt updating liveness intervals. + */ +static void testSplitAt(MachineFunction &MF, LiveIntervals &LIS, + unsigned SplitAt, unsigned BlockNum) { + MachineInstr &SplitInstr = getMI(MF, SplitAt, BlockNum); + MachineBasicBlock &MBB = *SplitInstr.getParent(); + + // Split block and update live intervals + MBB.splitAt(SplitInstr, false, &LIS); +} + static void liveIntervalTest(StringRef MIRFunc, LiveIntervalTest T) { LLVMContext Context; std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine(); @@ -608,6 +621,34 @@ TEST(LiveIntervalTest, BundleSubRegDef) { }); } +TEST(LiveIntervalTest, SplitAtOneInstruction) { + liveIntervalTest(R"MIR( + successors: %bb.1 + %0 = IMPLICIT_DEF + S_BRANCH %bb.1 + bb.1: + S_NOP 0 +)MIR", [](MachineFunction &MF, LiveIntervals &LIS) { + testSplitAt(MF, LIS, 1, 0); + }); +} + +TEST(LiveIntervalTest, SplitAtMultiInstruction) { + liveIntervalTest(R"MIR( + successors: %bb.1 + %0 = IMPLICIT_DEF + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_BRANCH %bb.1 + bb.1: + S_NOP 0 +)MIR", [](MachineFunction &MF, LiveIntervals &LIS) { + testSplitAt(MF, LIS, 0, 0); + }); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); initLLVM(); |