From 30cac02a925c9d56613711b0e77099cb7252bc9b Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 22 Feb 2007 23:03:39 +0000 Subject: [PATCH] Remove unnecessary isKill properties if a live range has been lengthened due to coalescing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34503 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveIntervalAnalysis.h | 11 +++++++++ lib/CodeGen/LiveIntervalAnalysis.cpp | 25 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index 69103a31f15..dc72807e71f 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -172,6 +172,13 @@ namespace llvm { } private: + /// isRemoved - returns true if the specified machine instr has been + /// removed. + bool isRemoved(MachineInstr* instr) const { + Mi2IndexMap::const_iterator it = mi2iMap_.find(instr); + return it == mi2iMap_.end(); + } + /// RemoveMachineInstrFromMaps - This marks the specified machine instr as /// deleted. void RemoveMachineInstrFromMaps(MachineInstr *MI) { @@ -256,6 +263,10 @@ namespace llvm { /// reg between indexes Start and End. bool hasRegisterUse(unsigned Reg, unsigned Start, unsigned End); + /// unsetRegisterKill - Unset IsKill property of all uses of specific + /// register of the specific instruction. + void unsetRegisterKill(MachineInstr *MI, unsigned Reg); + static LiveInterval createInterval(unsigned Reg); void removeInterval(unsigned Reg) { diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 29c095a1aa4..f03830ab1d3 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -959,10 +959,22 @@ bool LiveIntervals::JoinCopy(MachineInstr *CopyMI, DOUT << "\n\t\tJoined. Result = "; DestInt.print(DOUT, mri_); DOUT << "\n"; - + // If the intervals were swapped by Join, swap them back so that the register // mapping (in the r2i map) is correct. if (Swapped) SrcInt.swap(DestInt); + + // Live range has been lengthened due to colaescing, eliminate the + // unnecessary kills at the end of the source live ranges. + LiveVariables::VarInfo& vi = lv_->getVarInfo(repSrcReg); + for (unsigned i = 0, e = vi.Kills.size(); i != e; ++i) { + MachineInstr *Kill = vi.Kills[i]; + if (Kill == CopyMI || isRemoved(Kill)) + continue; + if (DestInt.liveAt(getInstructionIndex(Kill) + InstrSlots::NUM)) + unsetRegisterKill(Kill, repSrcReg); + } + removeInterval(repSrcReg); r2rMap_[repSrcReg] = repDstReg; @@ -1471,6 +1483,17 @@ LiveIntervals::hasRegisterUse(unsigned Reg, unsigned Start, unsigned End) { return false; } +/// unsetRegisterKill - Unset IsKill property of all uses of specific register +/// of the specific instruction. +void LiveIntervals::unsetRegisterKill(MachineInstr *MI, unsigned Reg) { + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { + MachineOperand &MO = MI->getOperand(i); + if (MO.isReg() && MO.isUse() && MO.isKill() && MO.getReg() && + mri_->regsOverlap(rep(MO.getReg()), Reg)) + MO.unsetIsKill(); + } +} + LiveInterval LiveIntervals::createInterval(unsigned reg) { float Weight = MRegisterInfo::isPhysicalRegister(reg) ? HUGE_VALF : 0.0F; -- 2.34.1