diff options
author | Dmitry Makogon <d.makogon@g.nsu.ru> | 2021-11-02 23:09:37 +0700 |
---|---|---|
committer | Dmitry Makogon <d.makogon@g.nsu.ru> | 2021-11-02 23:12:04 +0700 |
commit | e09958d5eb74a9ca0e1bda93e1e292c1a3cfadb3 (patch) | |
tree | dddec0393b98b8999ee8144358693cd15916a1ae /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | e2024d72fae778e0369127e078a40b4d6eb6c7bd (diff) | |
download | llvm-e09958d5eb74a9ca0e1bda93e1e292c1a3cfadb3.zip llvm-e09958d5eb74a9ca0e1bda93e1e292c1a3cfadb3.tar.gz llvm-e09958d5eb74a9ca0e1bda93e1e292c1a3cfadb3.tar.bz2 |
[LoopPeel] Peel loops with exits followed by an unreachable or deopt block
Added support for peeling loops with exits that are followed either by an
unreachable-terminated block or block that has a terminatnig deoptimize call.
All blocks in the sequence must have an unique successor, maybe except
for the last one.
Reviewed By: mkazantsev
Differential Revision: https://reviews.llvm.org/D110922
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 1a07697..6469c89 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -39,6 +39,7 @@ #include "llvm/IR/Value.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Local.h" @@ -52,6 +53,12 @@ using namespace llvm; #define DEBUG_TYPE "basicblock-utils" +static cl::opt<unsigned> MaxDeoptOrUnreachableSuccessorCheckDepth( + "max-deopt-or-unreachable-succ-check-depth", cl::init(8), cl::Hidden, + cl::desc("Set the maximum path length when checking whether a basic block " + "is followed by a block that either has a terminating " + "deoptimizing call or is terminated with an unreachable")); + void llvm::DetatchDeadBlocks( ArrayRef<BasicBlock *> BBs, SmallVectorImpl<DominatorTree::UpdateType> *Updates, @@ -485,6 +492,20 @@ void llvm::ReplaceInstWithInst(BasicBlock::InstListType &BIL, BI = New; } +bool llvm::IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB) { + // Remember visited blocks to avoid infinite loop + SmallPtrSet<const BasicBlock *, 8> VisitedBlocks; + unsigned Depth = 0; + while (BB && Depth++ < MaxDeoptOrUnreachableSuccessorCheckDepth && + VisitedBlocks.insert(BB).second) { + if (BB->getTerminatingDeoptimizeCall() || + isa<UnreachableInst>(BB->getTerminator())) + return true; + BB = BB->getUniqueSuccessor(); + } + return false; +} + void llvm::ReplaceInstWithInst(Instruction *From, Instruction *To) { BasicBlock::iterator BI(From); ReplaceInstWithInst(From->getParent()->getInstList(), BI, To); |