diff options
author | Bob Wilson <bob.wilson@apple.com> | 2018-01-04 02:58:15 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2018-01-04 02:58:15 +0000 |
commit | 90ecac01e9dcbcaf92781a6dcffa07a27191b661 (patch) | |
tree | 8085e8c18e3845d0c93c74dd933751e54828918c /llvm/unittests/CodeGen | |
parent | 773be7b496ebc367dee432e52e55915c1a8546d7 (diff) | |
download | bcm5719-llvm-90ecac01e9dcbcaf92781a6dcffa07a27191b661.tar.gz bcm5719-llvm-90ecac01e9dcbcaf92781a6dcffa07a27191b661.zip |
support phi ranges for machine-level IR
Add iterator ranges for machine instruction phis, similar to the IR-level
phi ranges added in r303964. I updated a few places to use this. Besides
general code simplification, this change will allow removing a non-upstream
change from Swift's copy of LLVM (in a better way than my previous attempt
in http://reviews.llvm.org/D19080).
https://reviews.llvm.org/D41672
llvm-svn: 321783
Diffstat (limited to 'llvm/unittests/CodeGen')
-rw-r--r-- | llvm/unittests/CodeGen/MachineInstrTest.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index aca640ebcf3..eccf2bcfbe2 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/TargetFrameLowering.h" @@ -244,4 +245,71 @@ TEST(MachineInstrExpressionTraitTest, IsEqualAgreesWithGetHashValue) { checkHashAndIsEqualMatch(VD2PU, VD2PD); } + +TEST(MachineBasicBlockTest, PhiRange) { + auto MF = createMachineFunction(); + + // Create the main block. + auto BB = MF->CreateMachineBasicBlock(); + + // Create some predecessors of it. + auto BB1 = MF->CreateMachineBasicBlock(); + BB1->addSuccessor(BB); + auto BB2 = MF->CreateMachineBasicBlock(); + BB2->addSuccessor(BB); + + // Make sure this doesn't crash if there are no phis. + for (auto &PN : BB->phis()) { + (void)PN; + ASSERT_TRUE(false) << "empty block should have no phis"; + } + + // Make it a cycle. + BB->addSuccessor(BB); + + // Now insert some PHI nodes. + MCOperandInfo OpInfo[] = { { -1, 0, MCOI::OPERAND_UNKNOWN, 0} }; + MCInstrDesc PHIMCID = { + TargetOpcode::PHI, 1, 1, 0, 0, + (1ULL << MCID::Pseudo) | (1ULL << MCID::Variadic), 0, + nullptr, nullptr, OpInfo, -1, nullptr}; + auto P1 = BuildMI(*BB, BB->end(), DebugLoc(), PHIMCID, -101); + auto P2 = BuildMI(*BB, BB->end(), DebugLoc(), PHIMCID, -102); + auto P3 = BuildMI(*BB, BB->end(), DebugLoc(), PHIMCID, -103); + + // A non-PHI node. + MCInstrDesc ImpDefMCID = { + TargetOpcode::IMPLICIT_DEF, 1, 1, 0, 0, + (1ULL << MCID::Pseudo), 0, + nullptr, nullptr, OpInfo, -1, nullptr}; + BuildMI(*BB, BB->end(), DebugLoc(), ImpDefMCID, -104); + + // Now wire up the incoming values that are interesting. + P1.addReg(-102).addMBB(BB); + P2.addReg(-101).addMBB(BB); + P3.addReg(-104).addMBB(BB); + + // Finally, let's iterate them, which is the thing we're trying to test. + // We'll use this to wire up the rest of the incoming values. + for (auto &PN : BB->phis()) { + EXPECT_TRUE(PN.isPHI()); + PN.addOperand(*MF, MachineOperand::CreateReg(-100, /*isDef*/ false)); + PN.addOperand(*MF, MachineOperand::CreateMBB(BB1)); + PN.addOperand(*MF, MachineOperand::CreateReg(-100, /*isDef*/ false)); + PN.addOperand(*MF, MachineOperand::CreateMBB(BB2)); + } + + // Test that we can use const iterators and generally that the iterators + // behave like iterators. + MachineBasicBlock::const_iterator CI; + CI = BB->phis().begin(); + EXPECT_NE(CI, BB->phis().end()); + + // And iterate a const range. + for (const auto &PN : const_cast<const MachineBasicBlock *>(BB)->phis()) { + EXPECT_EQ(BB, PN.getOperand(2).getMBB()); + EXPECT_EQ(BB1, PN.getOperand(4).getMBB()); + EXPECT_EQ(BB2, PN.getOperand(6).getMBB()); + } +} } // end namespace |