diff options
-rw-r--r-- | llvm/lib/CodeGen/RegAllocGreedy.cpp | 32 | ||||
-rw-r--r-- | llvm/lib/CodeGen/RegAllocGreedy.h | 13 |
2 files changed, 43 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 0df8713..9d3165b 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -2458,7 +2458,28 @@ void RAGreedy::collectHintInfo(Register Reg, HintsInfo &Out) { // Push the collected information. if (OtherPhysReg) { - Out.push_back(HintInfo(MBFI->getBlockFreq(Instr.getParent()), OtherReg, + BlockFrequency Freq = MBFI->getBlockFreq(Instr.getParent()); + + if (OtherSubReg) { + const TargetRegisterClass *OtherRC = MRI->getRegClass(OtherReg); + unsigned FullRegCopyCost = OtherRC->getCopyCost(); + + const TargetRegisterClass *OtherSubRC = TRI->getSubRegisterClass(OtherRC, OtherSubReg); + unsigned SubRegCopyCost = OtherSubRC->getCopyCost(); + + BranchProbability Scaling(SubRegCopyCost, FullRegCopyCost); + Freq *= Scaling; + } else if (SubReg) { + unsigned FullRegCopyCost = RC->getCopyCost(); + const TargetRegisterClass *SubRC = TRI->getSubRegisterClass(RC, SubReg); + unsigned SubRegCopyCost = SubRC->getCopyCost(); + + BranchProbability Scaling(SubRegCopyCost, FullRegCopyCost); + Freq *= Scaling; + + } + + Out.push_back(HintInfo(Freq, OtherReg, OtherPhysReg)); } } @@ -2471,6 +2492,13 @@ BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List, MCRegister PhysReg) { BlockFrequency Cost = BlockFrequency(0); for (const HintInfo &Info : List) { + + if (!Info.PhysReg) { + // Apply subreg hint + continue; + } + + if (Info.PhysReg != PhysReg) Cost += Info.Freq; } @@ -2536,6 +2564,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) { // non-identity copies. if (CurrPhys != PhysReg) { LLVM_DEBUG(dbgs() << "Checking profitability:\n"); + + // TODO: Scale by copy cost BlockFrequency OldCopiesCost = getBrokenHintFreq(Info, CurrPhys); BlockFrequency NewCopiesCost = getBrokenHintFreq(Info, PhysReg); LLVM_DEBUG(dbgs() << "Old Cost: " << printBlockFreq(*MBFI, OldCopiesCost) diff --git a/llvm/lib/CodeGen/RegAllocGreedy.h b/llvm/lib/CodeGen/RegAllocGreedy.h index 7f013d1..e0bb26e 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.h +++ b/llvm/lib/CodeGen/RegAllocGreedy.h @@ -385,12 +385,23 @@ private: BlockFrequency Freq; /// The virtual register or physical register. Register Reg; + unsigned SubReg = 0; + + Register HintReg; + unsigned HintSubReg = 0; + /// Its currently assigned register. /// In case of a physical register Reg == PhysReg. MCRegister PhysReg; HintInfo(BlockFrequency Freq, Register Reg, MCRegister PhysReg) - : Freq(Freq), Reg(Reg), PhysReg(PhysReg) {} + : Freq(Freq), Reg(Reg), PhysReg(PhysReg) {} + + HintInfo(BlockFrequency Freq, + Register Reg, unsigned SubReg, + Register HintReg, unsigned HintSubReg) + : Freq(Freq), Reg(Reg), SubReg(SubReg), + HintReg(HintReg), HintSubReg(HintSubReg) {} }; using HintsInfo = SmallVector<HintInfo, 4>; |