Skip to content

Commit 0581982

Browse files
committed
XXX scale block frequencies by subreg
1 parent f409ccc commit 0581982

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,28 @@ void RAGreedy::collectHintInfo(Register Reg, HintsInfo &Out) {
24582458

24592459
// Push the collected information.
24602460
if (OtherPhysReg) {
2461-
Out.push_back(HintInfo(MBFI->getBlockFreq(Instr.getParent()), OtherReg,
2461+
BlockFrequency Freq = MBFI->getBlockFreq(Instr.getParent());
2462+
2463+
if (OtherSubReg) {
2464+
const TargetRegisterClass *OtherRC = MRI->getRegClass(OtherReg);
2465+
unsigned FullRegCopyCost = OtherRC->getCopyCost();
2466+
2467+
const TargetRegisterClass *OtherSubRC = TRI->getSubRegisterClass(OtherRC, OtherSubReg);
2468+
unsigned SubRegCopyCost = OtherSubRC->getCopyCost();
2469+
2470+
BranchProbability Scaling(SubRegCopyCost, FullRegCopyCost);
2471+
Freq *= Scaling;
2472+
} else if (SubReg) {
2473+
unsigned FullRegCopyCost = RC->getCopyCost();
2474+
const TargetRegisterClass *SubRC = TRI->getSubRegisterClass(RC, SubReg);
2475+
unsigned SubRegCopyCost = SubRC->getCopyCost();
2476+
2477+
BranchProbability Scaling(SubRegCopyCost, FullRegCopyCost);
2478+
Freq *= Scaling;
2479+
2480+
}
2481+
2482+
Out.push_back(HintInfo(Freq, OtherReg,
24622483
OtherPhysReg));
24632484
}
24642485
}
@@ -2471,6 +2492,13 @@ BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List,
24712492
MCRegister PhysReg) {
24722493
BlockFrequency Cost = BlockFrequency(0);
24732494
for (const HintInfo &Info : List) {
2495+
2496+
if (!Info.PhysReg) {
2497+
// Apply subreg hint
2498+
continue;
2499+
}
2500+
2501+
24742502
if (Info.PhysReg != PhysReg)
24752503
Cost += Info.Freq;
24762504
}
@@ -2536,6 +2564,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
25362564
// non-identity copies.
25372565
if (CurrPhys != PhysReg) {
25382566
LLVM_DEBUG(dbgs() << "Checking profitability:\n");
2567+
2568+
// TODO: Scale by copy cost
25392569
BlockFrequency OldCopiesCost = getBrokenHintFreq(Info, CurrPhys);
25402570
BlockFrequency NewCopiesCost = getBrokenHintFreq(Info, PhysReg);
25412571
LLVM_DEBUG(dbgs() << "Old Cost: " << printBlockFreq(*MBFI, OldCopiesCost)

llvm/lib/CodeGen/RegAllocGreedy.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,23 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public RegAllocBase,
385385
BlockFrequency Freq;
386386
/// The virtual register or physical register.
387387
Register Reg;
388+
unsigned SubReg = 0;
389+
390+
Register HintReg;
391+
unsigned HintSubReg = 0;
392+
388393
/// Its currently assigned register.
389394
/// In case of a physical register Reg == PhysReg.
390395
MCRegister PhysReg;
391396

392397
HintInfo(BlockFrequency Freq, Register Reg, MCRegister PhysReg)
393-
: Freq(Freq), Reg(Reg), PhysReg(PhysReg) {}
398+
: Freq(Freq), Reg(Reg), PhysReg(PhysReg) {}
399+
400+
HintInfo(BlockFrequency Freq,
401+
Register Reg, unsigned SubReg,
402+
Register HintReg, unsigned HintSubReg)
403+
: Freq(Freq), Reg(Reg), SubReg(SubReg),
404+
HintReg(HintReg), HintSubReg(HintSubReg) {}
394405
};
395406
using HintsInfo = SmallVector<HintInfo, 4>;
396407

0 commit comments

Comments
 (0)