[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / lib / CodeGen / MBFIWrapper.cpp
blobefebb18c99080875c0b6ee7615c00533ab18ee48
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
16 #include "llvm/CodeGen/MBFIWrapper.h"
18 using namespace llvm;
20 BlockFrequency MBFIWrapper::getBlockFreq(const MachineBasicBlock *MBB) const {
21 auto I = MergedBBFreq.find(MBB);
23 if (I != MergedBBFreq.end())
24 return I->second;
26 return MBFI.getBlockFreq(MBB);
29 void MBFIWrapper::setBlockFreq(const MachineBasicBlock *MBB,
30 BlockFrequency F) {
31 MergedBBFreq[MBB] = F;
34 Optional<uint64_t>
35 MBFIWrapper::getBlockProfileCount(const MachineBasicBlock *MBB) const {
36 auto I = MergedBBFreq.find(MBB);
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.getFrequency());
43 return MBFI.getBlockProfileCount(MBB);
46 raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
47 const MachineBasicBlock *MBB) const {
48 return MBFI.printBlockFreq(OS, getBlockFreq(MBB));
51 raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
52 const BlockFrequency Freq) const {
53 return MBFI.printBlockFreq(OS, Freq);
56 void MBFIWrapper::view(const Twine &Name, bool isSimple) {
57 MBFI.view(Name, isSimple);
60 uint64_t MBFIWrapper::getEntryFreq() const {
61 return MBFI.getEntryFreq();