Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lib/CodeGen/TailDuplicator.cpp
Show First 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | if (PreRegAlloc && MI.isReturn()) | ||||
return false; | return false; | ||||
// Avoid duplicating calls before register allocation. Calls presents a | // Avoid duplicating calls before register allocation. Calls presents a | ||||
// barrier to register allocation so duplicating them may end up increasing | // barrier to register allocation so duplicating them may end up increasing | ||||
// spills. | // spills. | ||||
if (PreRegAlloc && MI.isCall()) | if (PreRegAlloc && MI.isCall()) | ||||
return false; | return false; | ||||
if (!MI.isPHI() && !MI.isDebugValue()) | if (!MI.isPHI() && !MI.isDirective()) | ||||
InstrCount += 1; | InstrCount += 1; | ||||
if (InstrCount > MaxDuplicateCount) | if (InstrCount > MaxDuplicateCount) | ||||
return false; | return false; | ||||
} | } | ||||
// Check if any of the successors of TailBB has a PHI node in which the | // Check if any of the successors of TailBB has a PHI node in which the | ||||
// value corresponding to TailBB uses a subregister. | // value corresponding to TailBB uses a subregister. | ||||
// If a phi node uses a register paired with a subregister, the actual | // If a phi node uses a register paired with a subregister, the actual | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | for (MachineBasicBlock *PredBB : Preds) { | ||||
// Update the CFG. | // Update the CFG. | ||||
PredBB->removeSuccessor(PredBB->succ_begin()); | PredBB->removeSuccessor(PredBB->succ_begin()); | ||||
assert(PredBB->succ_empty() && | assert(PredBB->succ_empty() && | ||||
"TailDuplicate called on block with multiple successors!"); | "TailDuplicate called on block with multiple successors!"); | ||||
for (MachineBasicBlock *Succ : TailBB->successors()) | for (MachineBasicBlock *Succ : TailBB->successors()) | ||||
PredBB->addSuccessor(Succ, MBPI->getEdgeProbability(TailBB, Succ)); | PredBB->addSuccessor(Succ, MBPI->getEdgeProbability(TailBB, Succ)); | ||||
// Update the CFI info for PredBB. | |||||
PredBB->mergeCFIInfo(TailBB); | |||||
Changed = true; | Changed = true; | ||||
++NumTailDups; | ++NumTailDups; | ||||
} | } | ||||
// If TailBB was duplicated into all its predecessors except for the prior | // If TailBB was duplicated into all its predecessors except for the prior | ||||
// block, which falls through unconditionally, move the contents of this | // block, which falls through unconditionally, move the contents of this | ||||
// block into the prior block. | // block into the prior block. | ||||
MachineBasicBlock *PrevBB = ForcedLayoutPred; | MachineBasicBlock *PrevBB = ForcedLayoutPred; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (PreRegAlloc) { | ||||
// No PHIs to worry about, just splice the instructions over. | // No PHIs to worry about, just splice the instructions over. | ||||
PrevBB->splice(PrevBB->end(), TailBB, TailBB->begin(), TailBB->end()); | PrevBB->splice(PrevBB->end(), TailBB, TailBB->begin(), TailBB->end()); | ||||
} | } | ||||
PrevBB->removeSuccessor(PrevBB->succ_begin()); | PrevBB->removeSuccessor(PrevBB->succ_begin()); | ||||
assert(PrevBB->succ_empty()); | assert(PrevBB->succ_empty()); | ||||
PrevBB->transferSuccessors(TailBB); | PrevBB->transferSuccessors(TailBB); | ||||
TDBBs.push_back(PrevBB); | TDBBs.push_back(PrevBB); | ||||
Changed = true; | Changed = true; | ||||
// Update the CFI info for PrevBB. | |||||
PrevBB->mergeCFIInfo(TailBB); | |||||
} | } | ||||
// If this is after register allocation, there are no phis to fix. | // If this is after register allocation, there are no phis to fix. | ||||
if (!PreRegAlloc) | if (!PreRegAlloc) | ||||
return Changed; | return Changed; | ||||
// If we made no changes so far, we are safe. | // If we made no changes so far, we are safe. | ||||
if (!Changed) | if (!Changed) | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |