brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · e9f1632 Raw
51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This class keeps track of branch frequencies of newly created blocks and10// 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 18using namespace llvm;19 20BlockFrequency 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 29void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,30                               BlockFrequency F) {31  MergedBBFreq[MBB] = F;32}33 34std::optional<uint64_t>35MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const {36  auto I = MergedBBFreq.find(MBB);37 38  // Modified block frequency also impacts profile count. So we should compute39  // 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 46void MBFIWrapper::view(const Twine &Name, bool isSimple) {47  MBFI.view(Name, isSimple);48}49 50BlockFrequency MBFIWrapper::getEntryFreq() const { return MBFI.getEntryFreq(); }51