1 //===- MBFIWrapper.cpp - MachineBlockFrequencyInfo wrapper ----------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This class keeps track of branch frequencies of newly created blocks and 10 // tail-merged blocks. Used by the TailDuplication and MachineBlockPlacement. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" 15 #include "llvm/CodeGen/MBFIWrapper.h" 16 #include <optional> 17 18 using namespace llvm; 19 20 BlockFrequency MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const { 21 auto I = MergedBBFreq.find(MBB); 22 23 if (I != MergedBBFreq.end()) 24 return I->second; 25 26 return MBFI.getBlockFreq(MBB); 27 } 28 29 void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB, 30 BlockFrequency F) { 31 MergedBBFreq[MBB] = F; 32 } 33 34 std::optional<uint64_t> 35 MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const { 36 auto I = MergedBBFreq.find(MBB); 37 38 // Modified block frequency also impacts profile count. So we should compute 39 // profile count from new block frequency if it has been changed. 40 if (I != MergedBBFreq.end()) 41 return MBFI.getProfileCountFromFreq(I->second); 42 43 return MBFI.getBlockProfileCount(MBB); 44 } 45 46 void MBFIWrapper::view(const Twine &Name, bool isSimple) { 47 MBFI.view(Name, isSimple); 48 } 49 50 BlockFrequency MBFIWrapper::getEntryFreq() const { return MBFI.getEntryFreq(); } 51