diff options
author | Kyle Butt <kyle+llvm@iteratee.net> | 2016-07-19 23:54:21 +0000 |
---|---|---|
committer | Kyle Butt <kyle+llvm@iteratee.net> | 2016-07-19 23:54:21 +0000 |
commit | 9e52c064c2c5104062a09b4cb1716715018f6b1d (patch) | |
tree | 8cb94a8bdd1a804e31a5480296521874c8a2d28a /llvm/lib/CodeGen/TailDuplicator.cpp | |
parent | e555763fc632a4d4877b45e67850dd7bcf0ce3ac (diff) | |
download | bcm5719-llvm-9e52c064c2c5104062a09b4cb1716715018f6b1d.tar.gz bcm5719-llvm-9e52c064c2c5104062a09b4cb1716715018f6b1d.zip |
Codegen: Factor out canTailDuplicate
canTailDuplicate accepts two blocks and returns true if the first can be
duplicated into the second successfully. Use this function to
encapsulate the heuristic.
llvm-svn: 276062
Diffstat (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TailDuplicator.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 847a09349a5..f2349f28243 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -717,6 +717,21 @@ bool TailDuplicator::duplicateSimpleBB( return Changed; } +bool TailDuplicator::canTailDuplicate(MachineBasicBlock *TailBB, + MachineBasicBlock *PredBB) { + // EH edges are ignored by AnalyzeBranch. + if (PredBB->succ_size() > 1) + return false; + + MachineBasicBlock *PredTBB, *PredFBB; + SmallVector<MachineOperand, 4> PredCond; + if (TII->analyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true)) + return false; + if (!PredCond.empty()) + return false; + return true; +} + /// If it is profitable, duplicate TailBB's contents in each /// of its predecessors. bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple, @@ -741,19 +756,12 @@ bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple, PE = Preds.end(); PI != PE; ++PI) { MachineBasicBlock *PredBB = *PI; - assert(TailBB != PredBB && "Single-block loop should have been rejected earlier!"); - // EH edges are ignored by AnalyzeBranch. - if (PredBB->succ_size() > 1) - continue; - MachineBasicBlock *PredTBB, *PredFBB; - SmallVector<MachineOperand, 4> PredCond; - if (TII->analyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true)) - continue; - if (!PredCond.empty()) + if (!canTailDuplicate(TailBB, PredBB)) continue; + // Don't duplicate into a fall-through predecessor (at least for now). if (PredBB->isLayoutSuccessor(TailBB) && PredBB->canFallThrough()) continue; @@ -788,6 +796,8 @@ bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple, appendCopies(PredBB, CopyInfos, Copies); // Simplify + MachineBasicBlock *PredTBB, *PredFBB; + SmallVector<MachineOperand, 4> PredCond; TII->analyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true); NumTailDupAdded += TailBB->size() - 1; // subtract one for removed branch |