aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineSink.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineSink.cpp31
1 files changed, 12 insertions, 19 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index d0e119c..9ed6b22 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -510,30 +510,23 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
LLVM_DEBUG(dbgs() << "Sinking copy of"; MI.dump(); dbgs() << "into";
SinkDst->dump());
if (SinkDst->isCopy()) {
+ // TODO: After performing the sink-and-fold, the original instruction is
+ // deleted. Its value is still available (in a hard register), so if there
+ // are debug instructions which refer to the (now deleted) virtual
+ // register they could be updated to refer to the hard register, in
+ // principle. However, it's not clear how to do that, moreover in some
+ // cases the debug instructions may need to be replicated proportionally
+ // to the number of the COPY instructions replaced and in some extreme
+ // cases we can end up with quadratic increase in the number of debug
+ // instructions.
+
// Sink a copy of the instruction, replacing a COPY instruction.
MachineBasicBlock::iterator InsertPt = SinkDst->getIterator();
Register DstReg = SinkDst->getOperand(0).getReg();
TII->reMaterialize(*SinkDst->getParent(), InsertPt, DstReg, 0, MI, *TRI);
- // If the original instruction did not have source location, reuse a one
- // from the COPY.
+ // Reuse the source location from the COPY.
New = &*std::prev(InsertPt);
- if (const DebugLoc &NewLoc = New->getDebugLoc(); !NewLoc)
- New->setDebugLoc(SinkDst->getDebugLoc());
- // Sink DBG_VALUEs, which refer to the original instruction's destination
- // (DefReg).
- MachineBasicBlock &SinkMBB = *SinkDst->getParent();
- auto &DbgUsers = SeenDbgUsers[DefReg];
- for (auto &U : DbgUsers) {
- MachineInstr *DbgMI = U.getPointer();
- if (U.getInt())
- continue;
- MachineInstr *NewDbgMI = SinkDst->getMF()->CloneMachineInstr(DbgMI);
- SinkMBB.insertAfter(InsertPt, NewDbgMI);
- for (auto &SrcMO : DbgMI->getDebugOperandsForReg(DefReg)) {
- auto &DstMO = NewDbgMI->getOperand(SrcMO.getOperandNo());
- DstMO.setReg(DstReg);
- }
- }
+ New->setDebugLoc(SinkDst->getDebugLoc());
} else {
// Fold instruction into the addressing mode of a memory instruction.
New = TII->emitLdStWithAddr(*SinkDst, MaybeAM);