blob: ca99c6c89b191f7c2a824dcdbf54bed306c16e4a [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001///===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*--===//
2///
Andrew Walbran16937d02019-10-22 13:54:20 +01003/// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006///
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///===---------------------------------------------------------------------===//
15
16#ifndef LLVM_ANALYSIS_LAZYMACHINEBLOCKFREQUENCYINFO_H
17#define LLVM_ANALYSIS_LAZYMACHINEBLOCKFREQUENCYINFO_H
18
19#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
20#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
21#include "llvm/CodeGen/MachineDominators.h"
22#include "llvm/CodeGen/MachineLoopInfo.h"
23
24namespace llvm {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010025/// This is an alternative analysis pass to MachineBlockFrequencyInfo.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010026/// The difference is that with this pass, the block frequencies are not
27/// computed when the analysis pass is executed but rather when the BFI result
28/// is explicitly requested by the analysis client.
29///
30/// This works by checking querying if MBFI is available and otherwise
31/// generating MBFI on the fly. In this case the passes required for (LI, DT)
32/// are also queried before being computed on the fly.
33///
34/// Note that it is expected that we wouldn't need this functionality for the
35/// new PM since with the new PM, analyses are executed on demand.
36
37class LazyMachineBlockFrequencyInfoPass : public MachineFunctionPass {
38private:
39 /// If generated on the fly this own the instance.
40 mutable std::unique_ptr<MachineBlockFrequencyInfo> OwnedMBFI;
41
42 /// If generated on the fly this own the instance.
43 mutable std::unique_ptr<MachineLoopInfo> OwnedMLI;
44
45 /// If generated on the fly this own the instance.
46 mutable std::unique_ptr<MachineDominatorTree> OwnedMDT;
47
48 /// The function.
49 MachineFunction *MF = nullptr;
50
Andrew Scullcdfcccc2018-10-05 20:58:37 +010051 /// Calculate MBFI and all other analyses that's not available and
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052 /// required by BFI.
53 MachineBlockFrequencyInfo &calculateIfNotAvailable() const;
54
55public:
56 static char ID;
57
58 LazyMachineBlockFrequencyInfoPass();
59
Andrew Scullcdfcccc2018-10-05 20:58:37 +010060 /// Compute and return the block frequencies.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010061 MachineBlockFrequencyInfo &getBFI() { return calculateIfNotAvailable(); }
62
Andrew Scullcdfcccc2018-10-05 20:58:37 +010063 /// Compute and return the block frequencies.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010064 const MachineBlockFrequencyInfo &getBFI() const {
65 return calculateIfNotAvailable();
66 }
67
68 void getAnalysisUsage(AnalysisUsage &AU) const override;
69
70 bool runOnMachineFunction(MachineFunction &F) override;
71 void releaseMemory() override;
72 void print(raw_ostream &OS, const Module *M) const override;
73};
74}
75#endif