diff options
author | Serguei Katkov <serguei.katkov@azul.com> | 2019-07-15 05:51:10 +0000 |
---|---|---|
committer | Serguei Katkov <serguei.katkov@azul.com> | 2019-07-15 05:51:10 +0000 |
commit | f1ee04c42a431d88cd66b884570ca7928cffd0cd (patch) | |
tree | b03a56ba843ebe73213bfb0964f69d3d65039934 /llvm/unittests/Analysis/LoopInfoTest.cpp | |
parent | 335f955dc4942d6956e759b8c2686c52914c36b6 (diff) | |
download | bcm5719-llvm-f1ee04c42a431d88cd66b884570ca7928cffd0cd.tar.gz bcm5719-llvm-f1ee04c42a431d88cd66b884570ca7928cffd0cd.zip |
[LoopInfo] Introduce getUniqueNonLatchExitBlocks utility function
Extract the code from LoopUnrollRuntime into utility function to
re-use it in D63923.
Reviewers: reames, mkuper
Reviewed By: reames
Subscribers: fhahn, hiraditya, zzheng, dmgreen, llvm-commits
Differential Revision: https://reviews.llvm.org/D64548
llvm-svn: 366040
Diffstat (limited to 'llvm/unittests/Analysis/LoopInfoTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/LoopInfoTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/LoopInfoTest.cpp b/llvm/unittests/Analysis/LoopInfoTest.cpp index 005e1dc405b..953a72aee8e 100644 --- a/llvm/unittests/Analysis/LoopInfoTest.cpp +++ b/llvm/unittests/Analysis/LoopInfoTest.cpp @@ -1110,3 +1110,49 @@ TEST(LoopInfoTest, AuxiliaryIV) { L->isAuxiliaryInductionVariable(Instruction_mulopcode, SE)); }); } + +// Examine getUniqueExitBlocks/getUniqueNonLatchExitBlocks functions. +TEST(LoopInfoTest, LoopUniqueExitBlocks) { + const char *ModuleStr = + "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n" + "define void @foo(i32 %n, i1 %cond) {\n" + "entry:\n" + " br label %for.cond\n" + "for.cond:\n" + " %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n" + " %cmp = icmp slt i32 %i.0, %n\n" + " br i1 %cond, label %for.inc, label %for.end1\n" + "for.inc:\n" + " %inc = add nsw i32 %i.0, 1\n" + " br i1 %cmp, label %for.cond, label %for.end2, !llvm.loop !0\n" + "for.end1:\n" + " br label %for.end\n" + "for.end2:\n" + " br label %for.end\n" + "for.end:\n" + " ret void\n" + "}\n" + "!0 = distinct !{!0, !1}\n" + "!1 = !{!\"llvm.loop.distribute.enable\", i1 true}\n"; + + // Parse the module. + LLVMContext Context; + std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleStr); + + runWithLoopInfo(*M, "foo", [&](Function &F, LoopInfo &LI) { + Function::iterator FI = F.begin(); + // First basic block is entry - skip it. + BasicBlock *Header = &*(++FI); + assert(Header->getName() == "for.cond"); + Loop *L = LI.getLoopFor(Header); + + SmallVector<BasicBlock *, 2> Exits; + // This loop has 2 unique exits. + L->getUniqueExitBlocks(Exits); + EXPECT_TRUE(Exits.size() == 2); + // And one unique non latch exit. + Exits.clear(); + L->getUniqueNonLatchExitBlocks(Exits); + EXPECT_TRUE(Exits.size() == 1); + }); +} |