[llvm] r276062 - Codegen: Factor out canTailDuplicate
Kyle Butt via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 16:54:21 PDT 2016
Author: iteratee
Date: Tue Jul 19 18:54:21 2016
New Revision: 276062
URL: http://llvm.org/viewvc/llvm-project?rev=276062&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/CodeGen/TailDuplicator.h
llvm/trunk/lib/CodeGen/TailDuplicator.cpp
Modified: llvm/trunk/include/llvm/CodeGen/TailDuplicator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TailDuplicator.h?rev=276062&r1=276061&r2=276062&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TailDuplicator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TailDuplicator.h Tue Jul 19 18:54:21 2016
@@ -51,6 +51,8 @@ public:
static bool isSimpleBB(MachineBasicBlock *TailBB);
bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple,
MachineBasicBlock &TailBB);
+ /// Returns true if TailBB can successfully be duplicated into PredBB
+ bool canTailDuplicate(MachineBasicBlock *TailBB, MachineBasicBlock *PredBB);
bool tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
MachineBasicBlock *MBB);
Modified: llvm/trunk/lib/CodeGen/TailDuplicator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TailDuplicator.cpp?rev=276062&r1=276061&r2=276062&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TailDuplicator.cpp (original)
+++ llvm/trunk/lib/CodeGen/TailDuplicator.cpp Tue Jul 19 18:54:21 2016
@@ -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(Machi
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(Machi
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
More information about the llvm-commits
mailing list