diff options
author | Matthias Braun <matze@braunis.de> | 2023-10-05 18:26:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 18:26:50 -0700 |
commit | 2e26d091060e87629f23163433b5e2fd450b54bf (patch) | |
tree | 58dbb9dab149f9fe8199379dd9c7a7b689e507c9 /llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | |
parent | 86d1f4c538e50e8f764e7700d167ffd1d8f70102 (diff) | |
download | llvm-2e26d091060e87629f23163433b5e2fd450b54bf.zip llvm-2e26d091060e87629f23163433b5e2fd450b54bf.tar.gz llvm-2e26d091060e87629f23163433b5e2fd450b54bf.tar.bz2 |
BlockFrequencyInfo: Add PrintBlockFreq helper (#67512)
- Refactor the (Machine)BlockFrequencyInfo::printBlockFreq functions
into a `PrintBlockFreq()` function returning a `Printable` object. This
simplifies usage as it can be directly piped to a `raw_ostream` like
`dbgs() << PrintBlockFreq(MBFI, Freq) << '\n';`.
- Previously there was an interesting behavior where
`BlockFrequencyInfoImpl` stores frequencies both as a `Scaled64` number
and as an `uint64_t`. Most algorithms use the `BlockFrequency`
abstraction with the integers, the print function for basic blocks
printed the `Scaled64` number potentially showing higher accuracy than
was used by the algorithm. This changes things to only print
`BlockFrequency` values.
- Replace some instances of `dbgs() << Freq.getFrequency()` with the new
function.
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 76b7285..7ee72e2 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -75,7 +75,7 @@ static cl::opt<bool> PrintMachineBlockFreq( // Command line option to specify the name of the function for block frequency // dump. Defined in Analysis/BlockFrequencyInfo.cpp. -extern cl::opt<std::string> PrintBlockFreqFuncName; +extern cl::opt<std::string> PrintBFIFuncName; } // namespace llvm static GVDAGType getGVDT() { @@ -203,8 +203,7 @@ void MachineBlockFrequencyInfo::calculate( view("MachineBlockFrequencyDAGS." + F.getName()); } if (PrintMachineBlockFreq && - (PrintBlockFreqFuncName.empty() || - F.getName().equals(PrintBlockFreqFuncName))) { + (PrintBFIFuncName.empty() || F.getName().equals(PrintBFIFuncName))) { MBFI->print(dbgs()); } } @@ -274,18 +273,18 @@ const MachineBranchProbabilityInfo *MachineBlockFrequencyInfo::getMBPI() const { return MBFI ? &MBFI->getBPI() : nullptr; } -raw_ostream & -MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS, - const BlockFrequency Freq) const { - return MBFI ? MBFI->printBlockFreq(OS, Freq) : OS; +BlockFrequency MachineBlockFrequencyInfo::getEntryFreq() const { + return MBFI ? MBFI->getEntryFreq() : BlockFrequency(0); } -raw_ostream & -MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS, - const MachineBasicBlock *MBB) const { - return MBFI ? MBFI->printBlockFreq(OS, MBB) : OS; +Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI, + BlockFrequency Freq) { + return Printable([&MBFI, Freq](raw_ostream &OS) { + printBlockFreqImpl(OS, MBFI.getEntryFreq(), Freq); + }); } -BlockFrequency MachineBlockFrequencyInfo::getEntryFreq() const { - return MBFI ? MBFI->getEntryFreq() : BlockFrequency(0); +Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI, + const MachineBasicBlock &MBB) { + return printBlockFreq(MBFI, MBFI.getBlockFreq(&MBB)); } |