15ffd83dbSDimitry Andric //===- MBFIWrapper.cpp - MachineBlockFrequencyInfo wrapper ----------------===// 25ffd83dbSDimitry Andric // 35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ffd83dbSDimitry Andric // 75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 85ffd83dbSDimitry Andric // 95ffd83dbSDimitry Andric // This class keeps track of branch frequencies of newly created blocks and 105ffd83dbSDimitry Andric // tail-merged blocks. Used by the TailDuplication and MachineBlockPlacement. 115ffd83dbSDimitry Andric // 125ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 135ffd83dbSDimitry Andric 145ffd83dbSDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" 15fe6060f1SDimitry Andric #include "llvm/CodeGen/MBFIWrapper.h" 16bdd1243dSDimitry Andric #include <optional> 175ffd83dbSDimitry Andric 185ffd83dbSDimitry Andric using namespace llvm; 195ffd83dbSDimitry Andric getBlockFreq(const MachineBasicBlock * MBB) const205ffd83dbSDimitry AndricBlockFrequency MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const { 215ffd83dbSDimitry Andric auto I = MergedBBFreq.find(MBB); 225ffd83dbSDimitry Andric 235ffd83dbSDimitry Andric if (I != MergedBBFreq.end()) 245ffd83dbSDimitry Andric return I->second; 255ffd83dbSDimitry Andric 265ffd83dbSDimitry Andric return MBFI.getBlockFreq(MBB); 275ffd83dbSDimitry Andric } 285ffd83dbSDimitry Andric setBlockFreq(const MachineBasicBlock * MBB,BlockFrequency F)295ffd83dbSDimitry Andricvoid MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB, 305ffd83dbSDimitry Andric BlockFrequency F) { 315ffd83dbSDimitry Andric MergedBBFreq[MBB] = F; 325ffd83dbSDimitry Andric } 335ffd83dbSDimitry Andric 34bdd1243dSDimitry Andric std::optional<uint64_t> getBlockProfileCount(const MachineBasicBlock * MBB) const35e8d8bef9SDimitry AndricMBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const { 36e8d8bef9SDimitry Andric auto I = MergedBBFreq.find(MBB); 37e8d8bef9SDimitry Andric 38e8d8bef9SDimitry Andric // Modified block frequency also impacts profile count. So we should compute 39e8d8bef9SDimitry Andric // profile count from new block frequency if it has been changed. 40e8d8bef9SDimitry Andric if (I != MergedBBFreq.end()) 41*5f757f3fSDimitry Andric return MBFI.getProfileCountFromFreq(I->second); 42e8d8bef9SDimitry Andric 43e8d8bef9SDimitry Andric return MBFI.getBlockProfileCount(MBB); 44e8d8bef9SDimitry Andric } 45e8d8bef9SDimitry Andric view(const Twine & Name,bool isSimple)465ffd83dbSDimitry Andricvoid MBFIWrapper::view(const Twine &Name, bool isSimple) { 475ffd83dbSDimitry Andric MBFI.view(Name, isSimple); 485ffd83dbSDimitry Andric } 495ffd83dbSDimitry Andric getEntryFreq() const50*5f757f3fSDimitry AndricBlockFrequency MBFIWrapper::getEntryFreq() const { return MBFI.getEntryFreq(); } 51