diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-09-24 18:54:59 +0900 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2025-09-27 00:48:00 +0900 |
commit | 0581982382d14b2451abfc6f2fc593d5d15e22a0 (patch) | |
tree | e2113c4030c24d66abe2258b7f9c80a9d2c3a46e | |
parent | f409ccc1223fc7965f52e522d260295cb6053e4f (diff) | |
download | llvm-users/arsenm/greedy/collectHintInfo-subreg-insert-hint.zip llvm-users/arsenm/greedy/collectHintInfo-subreg-insert-hint.tar.gz llvm-users/arsenm/greedy/collectHintInfo-subreg-insert-hint.tar.bz2 |
XXX scale block frequencies by subregusers/arsenm/greedy/collectHintInfo-subreg-insert-hint
-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>; |