Skip to content

Commit 302e91b

Browse files
committed
[llvm][NFC] Add comments and common-case API to MachineBlockFrequencyInfo
Clarify the relation between a block's BlockFrequency and the getEntryFreq() API, and added an API for the relatively common case of finding a block's frequency relative to the entrypoint. Added / moved some comments to header. Differential Revision: https://reviews.llvm.org/D84357
1 parent e3650dc commit 302e91b

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
5858
/// information. Please note that initial frequency is equal to 1024. It means
5959
/// that we should not rely on the value itself, but only on the comparison to
6060
/// the other block frequencies. We do this to avoid using of floating points.
61-
///
61+
/// For example, to get the frequency of a block relative to the entry block,
62+
/// divide the integral value returned by this function (the
63+
/// BlockFrequency::getFrequency() value) by getEntryFreq().
6264
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
6365

66+
/// Compute the frequency of the block, relative to the entry block.
67+
/// This API assumes getEntryFreq() is non-zero.
68+
float getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const {
69+
return getBlockFreq(MBB).getFrequency() * (1.0f / getEntryFreq());
70+
}
71+
6472
Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
6573
Optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
6674

@@ -70,6 +78,9 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
7078

7179
const MachineFunction *getFunction() const;
7280
const MachineBranchProbabilityInfo *getMBPI() const;
81+
82+
/// Pop up a ghostview window with the current block frequency propagation
83+
/// rendered using dot.
7384
void view(const Twine &Name, bool isSimple = true) const;
7485

7586
// Print the block frequency Freq to OS using the current functions entry
@@ -81,6 +92,8 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
8192
raw_ostream &printBlockFreq(raw_ostream &OS,
8293
const MachineBasicBlock *MBB) const;
8394

95+
/// Divide a block's BlockFrequency::getFrequency() value by this value to
96+
/// obtain the entry block - relative frequency of said block.
8497
uint64_t getEntryFreq() const;
8598
};
8699

llvm/lib/CodeGen/LiveIntervals.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,7 @@ float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
868868
float LiveIntervals::getSpillWeight(bool isDef, bool isUse,
869869
const MachineBlockFrequencyInfo *MBFI,
870870
const MachineBasicBlock *MBB) {
871-
BlockFrequency Freq = MBFI->getBlockFreq(MBB);
872-
const float Scale = 1.0f / MBFI->getEntryFreq();
873-
return (isDef + isUse) * (Freq.getFrequency() * Scale);
871+
return (isDef + isUse) * MBFI->getBlockFreqRelativeToEntryBlock(MBB);
874872
}
875873

876874
LiveRange::Segment

llvm/lib/CodeGen/RegAllocPBQP.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ class Coalescing : public PBQPRAConstraint {
451451
unsigned DstReg = CP.getDstReg();
452452
unsigned SrcReg = CP.getSrcReg();
453453

454-
const float Scale = 1.0f / MBFI.getEntryFreq();
455-
PBQP::PBQPNum CBenefit = MBFI.getBlockFreq(&MBB).getFrequency() * Scale;
454+
PBQP::PBQPNum CBenefit = MBFI.getBlockFreqRelativeToEntryBlock(&MBB);
456455

457456
if (CP.isPhys()) {
458457
if (!MF.getRegInfo().isAllocatable(DstReg))

0 commit comments

Comments
 (0)