summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-09-25 15:05:08 +0000
committerFlorian Hahn <flo@fhahn.com>2019-09-25 15:05:08 +0000
commit5c3bc3c930d3993a2c5f581112c18a9eb0ba6838 (patch)
tree9092f22afd1040a07a47e77b59c8b822997d609d /llvm/unittests/IR
parentae834ba52d644088319f7be746c944d67688091f (diff)
downloadbcm5719-llvm-5c3bc3c930d3993a2c5f581112c18a9eb0ba6838.tar.gz
bcm5719-llvm-5c3bc3c930d3993a2c5f581112c18a9eb0ba6838.zip
[PatternMatch] Make m_Br more flexible, add matchers for BB values.
Currently m_Br only takes references to BasicBlock*, which limits its flexibility. For example, you have to declare a variable, even if you ignore the result or you have to have additional checks to make sure the matched BB matches an expected one. This patch adds m_BasicBlock and m_SpecificBB matchers, which can be used like the existing matchers for constants or values. I also had a look at the existing uses and updated a few. IMO it makes the code a bit more explicit. Reviewers: spatel, craig.topper, RKSimon, majnemer, lebedev.ri Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D68013 llvm-svn: 372885
Diffstat (limited to 'llvm/unittests/IR')
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index fe8c518fa82..d52d4fe980f 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -1045,6 +1045,34 @@ TEST_F(PatternMatchTest, FloatingPointFNeg) {
EXPECT_FALSE(match(V3, m_FNeg(m_Value(Match))));
}
+TEST_F(PatternMatchTest, CondBranchTest) {
+ BasicBlock *TrueBB = BasicBlock::Create(Ctx, "TrueBB", F);
+ BasicBlock *FalseBB = BasicBlock::Create(Ctx, "FalseBB", F);
+ Value *Br1 = IRB.CreateCondBr(IRB.getTrue(), TrueBB, FalseBB);
+
+ EXPECT_TRUE(match(Br1, m_Br(m_Value(), m_BasicBlock(), m_BasicBlock())));
+
+ BasicBlock *A, *B;
+ EXPECT_TRUE(match(Br1, m_Br(m_Value(), m_BasicBlock(A), m_BasicBlock(B))));
+ EXPECT_EQ(TrueBB, A);
+ EXPECT_EQ(FalseBB, B);
+
+ EXPECT_FALSE(
+ match(Br1, m_Br(m_Value(), m_SpecificBB(FalseBB), m_BasicBlock())));
+ EXPECT_FALSE(
+ match(Br1, m_Br(m_Value(), m_BasicBlock(), m_SpecificBB(TrueBB))));
+ EXPECT_FALSE(
+ match(Br1, m_Br(m_Value(), m_SpecificBB(FalseBB), m_BasicBlock(TrueBB))));
+ EXPECT_TRUE(
+ match(Br1, m_Br(m_Value(), m_SpecificBB(TrueBB), m_BasicBlock(FalseBB))));
+
+ // Check we can use m_Deferred with branches.
+ EXPECT_FALSE(match(Br1, m_Br(m_Value(), m_BasicBlock(A), m_Deferred(A))));
+ Value *Br2 = IRB.CreateCondBr(IRB.getTrue(), TrueBB, TrueBB);
+ A = nullptr;
+ EXPECT_TRUE(match(Br2, m_Br(m_Value(), m_BasicBlock(A), m_Deferred(A))));
+}
+
template <typename T> struct MutableConstTest : PatternMatchTest { };
typedef ::testing::Types<std::tuple<Value*, Instruction*>,
OpenPOWER on IntegriCloud