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/MachineBlockPlacement.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/MachineBlockPlacement.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index 9d46c14..d0d3574 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -1729,8 +1729,9 @@ MachineBasicBlock *MachineBlockPlacement::selectBestCandidateBlock( "Found CFG-violating block"); BlockFrequency CandidateFreq = MBFI->getBlockFreq(MBB); - LLVM_DEBUG(dbgs() << " " << getBlockName(MBB) << " -> "; - MBFI->printBlockFreq(dbgs(), CandidateFreq) << " (freq)\n"); + LLVM_DEBUG(dbgs() << " " << getBlockName(MBB) << " -> " + << printBlockFreq(MBFI->getMBFI(), CandidateFreq) + << " (freq)\n"); // For ehpad, we layout the least probable first as to avoid jumping back // from least probable landingpads to more probable ones. @@ -2095,8 +2096,8 @@ MachineBlockPlacement::findBestLoopTopHelper( if (Pred == L.getHeader()) continue; LLVM_DEBUG(dbgs() << " old top pred: " << getBlockName(Pred) << ", has " - << Pred->succ_size() << " successors, "; - MBFI->printBlockFreq(dbgs(), Pred) << " freq\n"); + << Pred->succ_size() << " successors, " + << printBlockFreq(MBFI->getMBFI(), *Pred) << " freq\n"); if (Pred->succ_size() > 2) continue; @@ -2240,10 +2241,10 @@ MachineBlockPlacement::findBestLoopExit(const MachineLoop &L, } BlockFrequency ExitEdgeFreq = MBFI->getBlockFreq(MBB) * SuccProb; - LLVM_DEBUG(dbgs() << " exiting: " << getBlockName(MBB) << " -> " - << getBlockName(Succ) << " [L:" << SuccLoopDepth - << "] ("; - MBFI->printBlockFreq(dbgs(), ExitEdgeFreq) << ")\n"); + LLVM_DEBUG( + dbgs() << " exiting: " << getBlockName(MBB) << " -> " + << getBlockName(Succ) << " [L:" << SuccLoopDepth << "] (" + << printBlockFreq(MBFI->getMBFI(), ExitEdgeFreq) << ")\n"); // Note that we bias this toward an existing layout successor to retain // incoming order in the absence of better information. The exit must have // a frequency higher than the current exit before we consider breaking @@ -2537,8 +2538,8 @@ void MachineBlockPlacement::rotateLoopWithProfile( } LLVM_DEBUG(dbgs() << "The cost of loop rotation by making " - << getBlockName(*Iter) - << " to the top: " << Cost.getFrequency() << "\n"); + << getBlockName(*Iter) << " to the top: " + << printBlockFreq(MBFI->getMBFI(), Cost) << "\n"); if (Cost < SmallestRotationCost) { SmallestRotationCost = Cost; |