diff options
author | Matthias Braun <matze@braunis.de> | 2023-10-05 11:40:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 11:40:17 -0700 |
commit | 5181156b3743df29dc840e15990d9202b3501f60 (patch) | |
tree | fd52778d4b80a77887cb856ab7ec85436512abc6 /llvm/lib/CodeGen | |
parent | ea2036e1e56b720d7da8d46f62263ba46c126522 (diff) | |
download | llvm-5181156b3743df29dc840e15990d9202b3501f60.zip llvm-5181156b3743df29dc840e15990d9202b3501f60.tar.gz llvm-5181156b3743df29dc840e15990d9202b3501f60.tar.bz2 |
Use BlockFrequency type in more places (NFC) (#68266)
The `BlockFrequency` class abstracts `uint64_t` frequency values. Use it
more consistently in various APIs and disable implicit conversion to
make usage more consistent and explicit.
- Use `BlockFrequency Freq` parameter for `setBlockFreq`,
`getProfileCountFromFreq` and `setBlockFreqAndScale` functions.
- Return `BlockFrequency` in `getEntryFreq()` functions.
- While on it change some `const BlockFrequency& Freq` parameters to
plain `BlockFreqency Freq`.
- Mark `BlockFrequency(uint64_t)` constructor as explicit.
- Add missing `BlockFrequency::operator!=`.
- Remove `uint64_t BlockFreqency::getMaxFrequency()`.
- Add `BlockFrequency BlockFrequency::max()` function.
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MBFIWrapper.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 145 | ||||
-rw-r--r-- | llvm/lib/CodeGen/RegAllocGreedy.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectOptimize.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/ShrinkWrap.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SpillPlacement.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SpillPlacement.h | 2 |
10 files changed, 122 insertions, 118 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index e31b08d..371f659 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2591,9 +2591,8 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB, (void)FoldReturnIntoUncondBranch(RetI, BB, TailCallBB); assert(!VerifyBFIUpdates || BFI->getBlockFreq(BB) >= BFI->getBlockFreq(TailCallBB)); - BFI->setBlockFreq( - BB, - (BFI->getBlockFreq(BB) - BFI->getBlockFreq(TailCallBB)).getFrequency()); + BFI->setBlockFreq(BB, + (BFI->getBlockFreq(BB) - BFI->getBlockFreq(TailCallBB))); ModifiedDT = ModifyDT::ModifyBBDT; Changed = true; ++NumRetsDup; @@ -7067,7 +7066,7 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) { FreshBBs.insert(EndBlock); } - BFI->setBlockFreq(EndBlock, BFI->getBlockFreq(StartBlock).getFrequency()); + BFI->setBlockFreq(EndBlock, BFI->getBlockFreq(StartBlock)); static const unsigned MD[] = { LLVMContext::MD_prof, LLVMContext::MD_unpredictable, diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp index d201342..bb5363f 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -449,7 +449,8 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping( return MappingCost::ImpossibleCost(); // If mapped with InstrMapping, MI will have the recorded cost. - MappingCost Cost(MBFI ? MBFI->getBlockFreq(MI.getParent()) : 1); + MappingCost Cost(MBFI ? MBFI->getBlockFreq(MI.getParent()) + : BlockFrequency(1)); bool Saturated = Cost.addLocalCost(InstrMapping.getCost()); assert(!Saturated && "Possible mapping saturated the cost"); LLVM_DEBUG(dbgs() << "Evaluating mapping cost for: " << MI); @@ -971,7 +972,7 @@ bool RegBankSelect::EdgeInsertPoint::canMaterialize() const { return Src.canSplitCriticalEdge(DstOrSplit); } -RegBankSelect::MappingCost::MappingCost(const BlockFrequency &LocalFreq) +RegBankSelect::MappingCost::MappingCost(BlockFrequency LocalFreq) : LocalFreq(LocalFreq.getFrequency()) {} bool RegBankSelect::MappingCost::addLocalCost(uint64_t Cost) { diff --git a/llvm/lib/CodeGen/MBFIWrapper.cpp b/llvm/lib/CodeGen/MBFIWrapper.cpp index 5b388be..4f8b921 100644 --- a/llvm/lib/CodeGen/MBFIWrapper.cpp +++ b/llvm/lib/CodeGen/MBFIWrapper.cpp @@ -38,7 +38,7 @@ MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const { // Modified block frequency also impacts profile count. So we should compute // profile count from new block frequency if it has been changed. if (I != MergedBBFreq.end()) - return MBFI.getProfileCountFromFreq(I->second.getFrequency()); + return MBFI.getProfileCountFromFreq(I->second); return MBFI.getBlockProfileCount(MBB); } @@ -49,7 +49,7 @@ raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS, } raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS, - const BlockFrequency Freq) const { + BlockFrequency Freq) const { return MBFI.printBlockFreq(OS, Freq); } @@ -57,6 +57,4 @@ void MBFIWrapper::view(const Twine &Name, bool isSimple) { MBFI.view(Name, isSimple); } -uint64_t MBFIWrapper::getEntryFreq() const { - return MBFI.getEntryFreq(); -} +BlockFrequency MBFIWrapper::getEntryFreq() const { return MBFI.getEntryFreq(); } diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp index b1cbe52..76b7285 100644 --- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -228,7 +228,7 @@ void MachineBlockFrequencyInfo::view(const Twine &Name, bool isSimple) const { BlockFrequency MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const { - return MBFI ? MBFI->getBlockFreq(MBB) : 0; + return MBFI ? MBFI->getBlockFreq(MBB) : BlockFrequency(0); } std::optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount( @@ -241,7 +241,7 @@ std::optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount( } std::optional<uint64_t> -MachineBlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const { +MachineBlockFrequencyInfo::getProfileCountFromFreq(BlockFrequency Freq) const { if (!MBFI) return std::nullopt; @@ -263,7 +263,7 @@ void MachineBlockFrequencyInfo::onEdgeSplit( auto NewSuccFreq = MBFI->getBlockFreq(&NewPredecessor) * MBPI.getEdgeProbability(&NewPredecessor, &NewSuccessor); - MBFI->setBlockFreq(&NewSuccessor, NewSuccFreq.getFrequency()); + MBFI->setBlockFreq(&NewSuccessor, NewSuccFreq); } const MachineFunction *MachineBlockFrequencyInfo::getFunction() const { @@ -286,6 +286,6 @@ MachineBlockFrequencyInfo::printBlockFreq(raw_ostream &OS, return MBFI ? MBFI->printBlockFreq(OS, MBB) : OS; } -uint64_t MachineBlockFrequencyInfo::getEntryFreq() const { - return MBFI ? MBFI->getEntryFreq() : 0; +BlockFrequency MachineBlockFrequencyInfo::getEntryFreq() const { + return MBFI ? MBFI->getEntryFreq() : BlockFrequency(0); } diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index 603c0e9..9d46c14 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -444,9 +444,9 @@ class MachineBlockPlacement : public MachineFunctionPass { if (UseProfileCount) { auto Count = MBFI->getBlockProfileCount(BB); if (Count) - return *Count; + return BlockFrequency(*Count); else - return 0; + return BlockFrequency(0); } else return MBFI->getBlockFreq(BB); } @@ -795,10 +795,10 @@ bool MachineBlockPlacement::shouldTailDuplicate(MachineBasicBlock *BB) { /// penalty is less than 100% /// TODO(iteratee): Use 64-bit fixed point edge frequencies everywhere. static bool greaterWithBias(BlockFrequency A, BlockFrequency B, - uint64_t EntryFreq) { + BlockFrequency EntryFreq) { BranchProbability ThresholdProb(TailDupPlacementPenalty, 100); BlockFrequency Gain = A - B; - return (Gain / ThresholdProb).getFrequency() >= EntryFreq; + return (Gain / ThresholdProb) >= EntryFreq; } /// Check the edge frequencies to see if tail duplication will increase @@ -843,7 +843,7 @@ bool MachineBlockPlacement::isProfitableToTailDup( auto SuccFreq = MBFI->getBlockFreq(Succ); BlockFrequency P = BBFreq * PProb; BlockFrequency Qout = BBFreq * QProb; - uint64_t EntryFreq = MBFI->getEntryFreq(); + BlockFrequency EntryFreq = MBFI->getEntryFreq(); // If there are no more successors, it is profitable to copy, as it strictly // increases fallthrough. if (SuccSuccs.size() == 0) @@ -1927,7 +1927,7 @@ BlockFrequency MachineBlockPlacement::TopFallThroughFreq( const MachineBasicBlock *Top, const BlockFilterSet &LoopBlockSet) { - BlockFrequency MaxFreq = 0; + BlockFrequency MaxFreq = BlockFrequency(0); for (MachineBasicBlock *Pred : Top->predecessors()) { BlockChain *PredChain = BlockToChain[Pred]; if (!LoopBlockSet.count(Pred) && @@ -1986,7 +1986,7 @@ MachineBlockPlacement::FallThroughGains( const MachineBasicBlock *ExitBB, const BlockFilterSet &LoopBlockSet) { BlockFrequency FallThrough2Top = TopFallThroughFreq(OldTop, LoopBlockSet); - BlockFrequency FallThrough2Exit = 0; + BlockFrequency FallThrough2Exit = BlockFrequency(0); if (ExitBB) FallThrough2Exit = MBFI->getBlockFreq(NewTop) * MBPI->getEdgeProbability(NewTop, ExitBB); @@ -1994,58 +1994,58 @@ MachineBlockPlacement::FallThroughGains( MBPI->getEdgeProbability(NewTop, OldTop); // Find the best Pred of NewTop. - MachineBasicBlock *BestPred = nullptr; - BlockFrequency FallThroughFromPred = 0; - for (MachineBasicBlock *Pred : NewTop->predecessors()) { - if (!LoopBlockSet.count(Pred)) - continue; - BlockChain *PredChain = BlockToChain[Pred]; - if (!PredChain || Pred == *std::prev(PredChain->end())) { - BlockFrequency EdgeFreq = MBFI->getBlockFreq(Pred) * - MBPI->getEdgeProbability(Pred, NewTop); - if (EdgeFreq > FallThroughFromPred) { - FallThroughFromPred = EdgeFreq; - BestPred = Pred; - } - } - } - - // If NewTop is not placed after Pred, another successor can be placed - // after Pred. - BlockFrequency NewFreq = 0; - if (BestPred) { - for (MachineBasicBlock *Succ : BestPred->successors()) { - if ((Succ == NewTop) || (Succ == BestPred) || !LoopBlockSet.count(Succ)) - continue; - if (ComputedEdges.contains(Succ)) - continue; - BlockChain *SuccChain = BlockToChain[Succ]; - if ((SuccChain && (Succ != *SuccChain->begin())) || - (SuccChain == BlockToChain[BestPred])) - continue; - BlockFrequency EdgeFreq = MBFI->getBlockFreq(BestPred) * - MBPI->getEdgeProbability(BestPred, Succ); - if (EdgeFreq > NewFreq) - NewFreq = EdgeFreq; - } - BlockFrequency OrigEdgeFreq = MBFI->getBlockFreq(BestPred) * - MBPI->getEdgeProbability(BestPred, NewTop); - if (NewFreq > OrigEdgeFreq) { - // If NewTop is not the best successor of Pred, then Pred doesn't - // fallthrough to NewTop. So there is no FallThroughFromPred and - // NewFreq. - NewFreq = 0; - FallThroughFromPred = 0; - } - } - - BlockFrequency Result = 0; - BlockFrequency Gains = BackEdgeFreq + NewFreq; - BlockFrequency Lost = FallThrough2Top + FallThrough2Exit + - FallThroughFromPred; - if (Gains > Lost) - Result = Gains - Lost; - return Result; + MachineBasicBlock *BestPred = nullptr; + BlockFrequency FallThroughFromPred = BlockFrequency(0); + for (MachineBasicBlock *Pred : NewTop->predecessors()) { + if (!LoopBlockSet.count(Pred)) + continue; + BlockChain *PredChain = BlockToChain[Pred]; + if (!PredChain || Pred == *std::prev(PredChain->end())) { + BlockFrequency EdgeFreq = + MBFI->getBlockFreq(Pred) * MBPI->getEdgeProbability(Pred, NewTop); + if (EdgeFreq > FallThroughFromPred) { + FallThroughFromPred = EdgeFreq; + BestPred = Pred; + } + } + } + + // If NewTop is not placed after Pred, another successor can be placed + // after Pred. + BlockFrequency NewFreq = BlockFrequency(0); + if (BestPred) { + for (MachineBasicBlock *Succ : BestPred->successors()) { + if ((Succ == NewTop) || (Succ == BestPred) || !LoopBlockSet.count(Succ)) + continue; + if (ComputedEdges.contains(Succ)) + continue; + BlockChain *SuccChain = BlockToChain[Succ]; + if ((SuccChain && (Succ != *SuccChain->begin())) || + (SuccChain == BlockToChain[BestPred])) + continue; + BlockFrequency EdgeFreq = MBFI->getBlockFreq(BestPred) * + MBPI->getEdgeProbability(BestPred, Succ); + if (EdgeFreq > NewFreq) + NewFreq = EdgeFreq; + } + BlockFrequency OrigEdgeFreq = MBFI->getBlockFreq(BestPred) * + MBPI->getEdgeProbability(BestPred, NewTop); + if (NewFreq > OrigEdgeFreq) { + // If NewTop is not the best successor of Pred, then Pred doesn't + // fallthrough to NewTop. So there is no FallThroughFromPred and + // NewFreq. + NewFreq = BlockFrequency(0); + FallThroughFromPred = BlockFrequency(0); + } + } + + BlockFrequency Result = BlockFrequency(0); + BlockFrequency Gains = BackEdgeFreq + NewFreq; + BlockFrequency Lost = + FallThrough2Top + FallThrough2Exit + FallThroughFromPred; + if (Gains > Lost) + Result = Gains - Lost; + return Result; } /// Helper function of findBestLoopTop. Find the best loop top block @@ -2087,7 +2087,7 @@ MachineBlockPlacement::findBestLoopTopHelper( LLVM_DEBUG(dbgs() << "Finding best loop top for: " << getBlockName(OldTop) << "\n"); - BlockFrequency BestGains = 0; + BlockFrequency BestGains = BlockFrequency(0); MachineBasicBlock *BestPred = nullptr; for (MachineBasicBlock *Pred : OldTop->predecessors()) { if (!LoopBlockSet.count(Pred)) @@ -2112,8 +2112,9 @@ MachineBlockPlacement::findBestLoopTopHelper( BlockFrequency Gains = FallThroughGains(Pred, OldTop, OtherBB, LoopBlockSet); - if ((Gains > 0) && (Gains > BestGains || - ((Gains == BestGains) && Pred->isLayoutSuccessor(OldTop)))) { + if ((Gains > BlockFrequency(0)) && + (Gains > BestGains || + ((Gains == BestGains) && Pred->isLayoutSuccessor(OldTop)))) { BestPred = Pred; BestGains = Gains; } @@ -2425,14 +2426,14 @@ void MachineBlockPlacement::rotateLoopWithProfile( if (ChainHeaderBB->isEntryBlock()) return; - BlockFrequency SmallestRotationCost = BlockFrequency::getMaxFrequency(); + BlockFrequency SmallestRotationCost = BlockFrequency::max(); // A utility lambda that scales up a block frequency by dividing it by a // branch probability which is the reciprocal of the scale. auto ScaleBlockFrequency = [](BlockFrequency Freq, unsigned Scale) -> BlockFrequency { if (Scale == 0) - return 0; + return BlockFrequency(0); // Use operator / between BlockFrequency and BranchProbability to implement // saturating multiplication. return Freq / BranchProbability(1, Scale); @@ -2492,7 +2493,7 @@ void MachineBlockPlacement::rotateLoopWithProfile( auto TailBB = *TailIter; // Calculate the cost by putting this BB to the top. - BlockFrequency Cost = 0; + BlockFrequency Cost = BlockFrequency(0); // If the current BB is the loop header, we need to take into account the // cost of the missed fall through edge from outside of the loop to the @@ -2523,8 +2524,7 @@ void MachineBlockPlacement::rotateLoopWithProfile( if (TailBB->isSuccessor(*Iter)) { auto TailBBFreq = MBFI->getBlockFreq(TailBB); if (TailBB->succ_size() == 1) - Cost += ScaleBlockFrequency(TailBBFreq.getFrequency(), - MisfetchCost + JumpInstCost); + Cost += ScaleBlockFrequency(TailBBFreq, MisfetchCost + JumpInstCost); else if (TailBB->succ_size() == 2) { auto TailToHeadProb = MBPI->getEdgeProbability(TailBB, *Iter); auto TailToHeadFreq = TailBBFreq * TailToHeadProb; @@ -3159,7 +3159,7 @@ static uint64_t countMBBInstruction(MachineBasicBlock *MBB) { // So we should scale the threshold accordingly. But the instruction size is not // available on all targets, so we use the number of instructions instead. BlockFrequency MachineBlockPlacement::scaleThreshold(MachineBasicBlock *BB) { - return DupThreshold.getFrequency() * countMBBInstruction(BB); + return BlockFrequency(DupThreshold.getFrequency() * countMBBInstruction(BB)); } // Returns true if BB is Pred's best successor. @@ -3313,7 +3313,7 @@ void MachineBlockPlacement::findDuplicateCandidates( } void MachineBlockPlacement::initDupThreshold() { - DupThreshold = 0; + DupThreshold = BlockFrequency(0); if (!F->getFunction().hasProfileData()) return; @@ -3321,12 +3321,13 @@ void MachineBlockPlacement::initDupThreshold() { uint64_t HotThreshold = PSI->getOrCompHotCountThreshold(); if (HotThreshold != UINT64_MAX) { UseProfileCount = true; - DupThreshold = HotThreshold * TailDupProfilePercentThreshold / 100; + DupThreshold = + BlockFrequency(HotThreshold * TailDupProfilePercentThreshold / 100); return; } // Profile count is not available, we can use block frequency instead. - BlockFrequency MaxFreq = 0; + BlockFrequency MaxFreq = BlockFrequency(0); for (MachineBasicBlock &MBB : *F) { BlockFrequency Freq = MBFI->getBlockFreq(&MBB); if (Freq > MaxFreq) @@ -3334,7 +3335,7 @@ void MachineBlockPlacement::initDupThreshold() { } BranchProbability ThresholdProb(TailDupPlacementPenalty, 100); - DupThreshold = MaxFreq * ThresholdProb; + DupThreshold = BlockFrequency(MaxFreq * ThresholdProb); UseProfileCount = false; } diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 248cc1a..b8bafc9 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -607,7 +607,7 @@ bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf, // Reset interference dependent info. SplitConstraints.resize(UseBlocks.size()); - BlockFrequency StaticCost = 0; + BlockFrequency StaticCost = BlockFrequency(0); for (unsigned I = 0; I != UseBlocks.size(); ++I) { const SplitAnalysis::BlockInfo &BI = UseBlocks[I]; SpillPlacement::BlockConstraint &BC = SplitConstraints[I]; @@ -832,7 +832,7 @@ bool RAGreedy::calcCompactRegion(GlobalSplitCandidate &Cand) { /// calcSpillCost - Compute how expensive it would be to split the live range in /// SA around all use blocks instead of forming bundle regions. BlockFrequency RAGreedy::calcSpillCost() { - BlockFrequency Cost = 0; + BlockFrequency Cost = BlockFrequency(0); ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); for (const SplitAnalysis::BlockInfo &BI : UseBlocks) { unsigned Number = BI.MBB->getNumber(); @@ -852,7 +852,7 @@ BlockFrequency RAGreedy::calcSpillCost() { /// BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand, const AllocationOrder &Order) { - BlockFrequency GlobalCost = 0; + BlockFrequency GlobalCost = BlockFrequency(0); const BitVector &LiveBundles = Cand.LiveBundles; ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); for (unsigned I = 0; I != UseBlocks.size(); ++I) { @@ -1056,7 +1056,7 @@ MCRegister RAGreedy::tryRegionSplit(const LiveInterval &VirtReg, if (HasCompact) { // Yes, keep GlobalCand[0] as the compact region candidate. NumCands = 1; - BestCost = BlockFrequency::getMaxFrequency(); + BestCost = BlockFrequency::max(); } else { // No benefit from the compact region, our fallback will be per-block // splitting. Make sure we find a solution that is cheaper than spilling. @@ -1222,7 +1222,7 @@ bool RAGreedy::trySplitAroundHintReg(MCPhysReg Hint, if (ExtraInfo->getStage(VirtReg) >= RS_Split2) return false; - BlockFrequency Cost = 0; + BlockFrequency Cost = BlockFrequency(0); Register Reg = VirtReg.reg(); // Compute the cost of assigning a non Hint physical register to VirtReg. @@ -1249,7 +1249,7 @@ bool RAGreedy::trySplitAroundHintReg(MCPhysReg Hint, // Decrease the cost so it will be split in colder blocks. BranchProbability Threshold(SplitThresholdForRegWithHint, 100); Cost *= Threshold; - if (Cost == 0) + if (Cost == BlockFrequency(0)) return false; unsigned NumCands = 0; @@ -1630,8 +1630,8 @@ unsigned RAGreedy::tryLocalSplit(const LiveInterval &VirtReg, float BestDiff = 0; const float blockFreq = - SpillPlacer->getBlockFrequency(BI.MBB->getNumber()).getFrequency() * - (1.0f / MBFI->getEntryFreq()); + SpillPlacer->getBlockFrequency(BI.MBB->getNumber()).getFrequency() * + (1.0f / MBFI->getEntryFreq().getFrequency()); SmallVector<float, 8> GapWeight; for (MCPhysReg PhysReg : Order) { @@ -2199,9 +2199,9 @@ void RAGreedy::initializeCSRCost() { return; // Raw cost is relative to Entry == 2^14; scale it appropriately. - uint64_t ActualEntry = MBFI->getEntryFreq(); + uint64_t ActualEntry = MBFI->getEntryFreq().getFrequency(); if (!ActualEntry) { - CSRCost = 0; + CSRCost = BlockFrequency(0); return; } uint64_t FixedEntry = 1 << 14; @@ -2212,7 +2212,8 @@ void RAGreedy::initializeCSRCost() { CSRCost /= BranchProbability(FixedEntry, ActualEntry); else // Can't use BranchProbability in general, since it takes 32-bit numbers. - CSRCost = CSRCost.getFrequency() * (ActualEntry / FixedEntry); + CSRCost = + BlockFrequency(CSRCost.getFrequency() * (ActualEntry / FixedEntry)); } /// Collect the hint info for \p Reg. @@ -2243,7 +2244,7 @@ void RAGreedy::collectHintInfo(Register Reg, HintsInfo &Out) { /// \return The cost of \p List for \p PhysReg. BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List, MCRegister PhysReg) { - BlockFrequency Cost = 0; + BlockFrequency Cost = BlockFrequency(0); for (const HintInfo &Info : List) { if (Info.PhysReg != PhysReg) Cost += Info.Freq; diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index 65801aa..aaaee4d 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -425,7 +425,7 @@ void SelectOptimize::convertProfitableSIGroups(SelectGroups &ProfSIGroups) { BasicBlock *StartBlock = SI->getParent(); BasicBlock::iterator SplitPt = ++(BasicBlock::iterator(LastSI)); BasicBlock *EndBlock = StartBlock->splitBasicBlock(SplitPt, "select.end"); - BFI->setBlockFreq(EndBlock, BFI->getBlockFreq(StartBlock).getFrequency()); + BFI->setBlockFreq(EndBlock, BFI->getBlockFreq(StartBlock)); // Delete the unconditional branch that was just created by the split. StartBlock->getTerminator()->eraseFromParent(); diff --git a/llvm/lib/CodeGen/ShrinkWrap.cpp b/llvm/lib/CodeGen/ShrinkWrap.cpp index 4b1d363..8628e1f 100644 --- a/llvm/lib/CodeGen/ShrinkWrap.cpp +++ b/llvm/lib/CodeGen/ShrinkWrap.cpp @@ -139,7 +139,7 @@ class ShrinkWrap : public MachineFunctionPass { MachineOptimizationRemarkEmitter *ORE = nullptr; /// Frequency of the Entry block. - uint64_t EntryFreq = 0; + BlockFrequency EntryFreq; /// Current opcode for frame setup. unsigned FrameSetupOpcode = ~0u; @@ -640,7 +640,7 @@ bool ShrinkWrap::postShrinkWrapping(bool HasCandidate, MachineFunction &MF, FindIDom<>(**DirtyPreds.begin(), DirtyPreds, *MDT, false); while (NewSave && (hasDirtyPred(ReachableByDirty, *NewSave) || - EntryFreq < MBFI->getBlockFreq(NewSave).getFrequency() || + EntryFreq < MBFI->getBlockFreq(NewSave) || /*Entry freq has been observed more than a loop block in some cases*/ MLI->getLoopFor(NewSave))) @@ -675,8 +675,8 @@ bool ShrinkWrap::postShrinkWrapping(bool HasCandidate, MachineFunction &MF, "Incorrect save or restore point due to dominance relations"); assert((!MLI->getLoopFor(Save) && !MLI->getLoopFor(Restore)) && "Unexpected save or restore point in a loop"); - assert((EntryFreq >= MBFI->getBlockFreq(Save).getFrequency() && - EntryFreq >= MBFI->getBlockFreq(Restore).getFrequency()) && + assert((EntryFreq >= MBFI->getBlockFreq(Save) && + EntryFreq >= MBFI->getBlockFreq(Restore)) && "Incorrect save or restore point based on block frequency"); return true; } @@ -878,8 +878,8 @@ bool ShrinkWrap::performShrinkWrapping( return false; } - LLVM_DEBUG(dbgs() << "\n ** Results **\nFrequency of the Entry: " << EntryFreq - << '\n'); + LLVM_DEBUG(dbgs() << "\n ** Results **\nFrequency of the Entry: " + << EntryFreq.getFrequency() << '\n'); const TargetFrameLowering *TFI = MachineFunc->getSubtarget().getFrameLowering(); @@ -891,8 +891,8 @@ bool ShrinkWrap::performShrinkWrapping( << MBFI->getBlockFreq(Restore).getFrequency() << '\n'); bool IsSaveCheap, TargetCanUseSaveAsPrologue = false; - if (((IsSaveCheap = EntryFreq >= MBFI->getBlockFreq(Save).getFrequency()) && - EntryFreq >= MBFI->getBlockFreq(Restore).getFrequency()) && + if (((IsSaveCheap = EntryFreq >= MBFI->getBlockFreq(Save)) && + EntryFreq >= MBFI->getBlockFreq(Restore)) && ((TargetCanUseSaveAsPrologue = TFI->canUseAsPrologue(*Save)) && TFI->canUseAsEpilogue(*Restore))) break; diff --git a/llvm/lib/CodeGen/SpillPlacement.cpp b/llvm/lib/CodeGen/SpillPlacement.cpp index 91da5e4..6e74e51 100644 --- a/llvm/lib/CodeGen/SpillPlacement.cpp +++ b/llvm/lib/CodeGen/SpillPlacement.cpp @@ -109,8 +109,10 @@ struct SpillPlacement::Node { /// clear - Reset per-query data, but preserve frequencies that only depend on /// the CFG. - void clear(const BlockFrequency &Threshold) { - BiasN = BiasP = Value = 0; + void clear(BlockFrequency Threshold) { + BiasN = BlockFrequency(0); + BiasP = BlockFrequency(0); + Value = 0; SumLinkWeights = Threshold; Links.clear(); } @@ -142,14 +144,14 @@ struct SpillPlacement::Node { BiasN += freq; break; case MustSpill: - BiasN = BlockFrequency::getMaxFrequency(); + BiasN = BlockFrequency::max(); break; } } /// update - Recompute Value from Bias and Links. Return true when node /// preference changes. - bool update(const Node nodes[], const BlockFrequency &Threshold) { + bool update(const Node nodes[], BlockFrequency Threshold) { // Compute the weighted sum of inputs. BlockFrequency SumN = BiasN; BlockFrequency SumP = BiasP; @@ -237,8 +239,10 @@ void SpillPlacement::activate(unsigned n) { // limiting the number of blocks visited and the number of links in the // Hopfield network. if (bundles->getBlocks(n).size() > 100) { - nodes[n].BiasP = 0; - nodes[n].BiasN = (MBFI->getEntryFreq() / 16); + nodes[n].BiasP = BlockFrequency(0); + BlockFrequency BiasN = MBFI->getEntryFreq(); + BiasN >>= 4; + nodes[n].BiasN = BiasN; } } @@ -247,12 +251,12 @@ void SpillPlacement::activate(unsigned n) { /// Set the threshold relative to \c Entry. Since the threshold is used as a /// bound on the open interval (-Threshold;Threshold), 1 is the minimum /// threshold. -void SpillPlacement::setThreshold(const BlockFrequency &Entry) { +void SpillPlacement::setThreshold(BlockFrequency Entry) { // Apparently 2 is a good threshold when Entry==2^14, but we need to scale // it. Divide by 2^13, rounding as appropriate. uint64_t Freq = Entry.getFrequency(); uint64_t Scaled = (Freq >> 13) + bool(Freq & (1 << 12)); - Threshold = std::max(UINT64_C(1), Scaled); + Threshold = BlockFrequency(std::max(UINT64_C(1), Scaled)); } /// addConstraints - Compute node biases and weights from a set of constraints. diff --git a/llvm/lib/CodeGen/SpillPlacement.h b/llvm/lib/CodeGen/SpillPlacement.h index bd37d85..2a298c7 100644 --- a/llvm/lib/CodeGen/SpillPlacement.h +++ b/llvm/lib/CodeGen/SpillPlacement.h @@ -162,7 +162,7 @@ private: void releaseMemory() override; void activate(unsigned n); - void setThreshold(const BlockFrequency &Entry); + void setThreshold(BlockFrequency Entry); bool update(unsigned n); }; |