Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / CodeGen / LazyMachineBlockFrequencyInfo.cpp
blob2561f2e5c9bbb0fee61a11e7f94a2a2c93b5fb6f
1 ///===- LazyMachineBlockFrequencyInfo.cpp - Lazy Machine Block Frequency --===//
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 /// \file
9 /// This is an alternative analysis pass to MachineBlockFrequencyInfo. The
10 /// difference is that with this pass the block frequencies are not computed
11 /// when the analysis pass is executed but rather when the BFI result is
12 /// explicitly requested by the analysis client.
13 ///
14 ///===---------------------------------------------------------------------===//
16 #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
17 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
18 #include "llvm/InitializePasses.h"
20 using namespace llvm;
22 #define DEBUG_TYPE "lazy-machine-block-freq"
24 INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
25 "Lazy Machine Block Frequency Analysis", true, true)
26 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
27 INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
28 INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
29 "Lazy Machine Block Frequency Analysis", true, true)
31 char LazyMachineBlockFrequencyInfoPass::ID = 0;
33 LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
34 : MachineFunctionPass(ID) {
35 initializeLazyMachineBlockFrequencyInfoPassPass(
36 *PassRegistry::getPassRegistry());
39 void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage(
40 AnalysisUsage &AU) const {
41 AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
42 AU.setPreservesAll();
43 MachineFunctionPass::getAnalysisUsage(AU);
46 void LazyMachineBlockFrequencyInfoPass::releaseMemory() {
47 OwnedMBFI.reset();
48 OwnedMLI.reset();
49 OwnedMDT.reset();
52 MachineBlockFrequencyInfo &
53 LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
54 auto *MBFIWrapper =
55 getAnalysisIfAvailable<MachineBlockFrequencyInfoWrapperPass>();
56 if (MBFIWrapper) {
57 LLVM_DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
58 return MBFIWrapper->getMBFI();
61 auto &MBPI = getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
62 auto *MLIWrapper = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
63 auto *MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
64 auto *MDTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
65 auto *MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
66 LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
67 LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
69 if (!MLI) {
70 LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
71 // First create a dominator tree.
72 LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
74 if (!MDT) {
75 LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
76 OwnedMDT = std::make_unique<MachineDominatorTree>();
77 OwnedMDT->getBase().recalculate(*MF);
78 MDT = OwnedMDT.get();
81 // Generate LoopInfo from it.
82 OwnedMLI = std::make_unique<MachineLoopInfo>();
83 OwnedMLI->analyze(MDT->getBase());
84 MLI = OwnedMLI.get();
87 OwnedMBFI = std::make_unique<MachineBlockFrequencyInfo>();
88 OwnedMBFI->calculate(*MF, MBPI, *MLI);
89 return *OwnedMBFI;
92 bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction(
93 MachineFunction &F) {
94 MF = &F;
95 return false;