1 //===- MachineCycleAnalysis.cpp - Compute CycleInfo for Machine IR --------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/MachineCycleAnalysis.h"
10 #include "llvm/ADT/GenericCycleImpl.h"
11 #include "llvm/CodeGen/MachineFunctionPass.h"
12 #include "llvm/CodeGen/MachineSSAContext.h"
13 #include "llvm/InitializePasses.h"
17 template class llvm::GenericCycleInfo
<llvm::MachineSSAContext
>;
18 template class llvm::GenericCycle
<llvm::MachineSSAContext
>;
22 /// Legacy analysis pass which computes a \ref MachineCycleInfo.
23 class MachineCycleInfoWrapperPass
: public MachineFunctionPass
{
24 MachineFunction
*F
= nullptr;
30 MachineCycleInfoWrapperPass();
32 MachineCycleInfo
&getCycleInfo() { return CI
; }
33 const MachineCycleInfo
&getCycleInfo() const { return CI
; }
35 bool runOnMachineFunction(MachineFunction
&F
) override
;
36 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
37 void releaseMemory() override
;
38 void print(raw_ostream
&OS
, const Module
*M
= nullptr) const override
;
40 // TODO: verify analysis
43 class MachineCycleInfoPrinterPass
: public MachineFunctionPass
{
47 MachineCycleInfoPrinterPass();
49 bool runOnMachineFunction(MachineFunction
&F
) override
;
50 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
55 char MachineCycleInfoWrapperPass::ID
= 0;
57 MachineCycleInfoWrapperPass::MachineCycleInfoWrapperPass()
58 : MachineFunctionPass(ID
) {
59 initializeMachineCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
62 INITIALIZE_PASS_BEGIN(MachineCycleInfoWrapperPass
, "machine-cycles",
63 "Machine Cycle Info Analysis", true, true)
64 INITIALIZE_PASS_END(MachineCycleInfoWrapperPass
, "machine-cycles",
65 "Machine Cycle Info Analysis", true, true)
67 void MachineCycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
69 MachineFunctionPass::getAnalysisUsage(AU
);
72 bool MachineCycleInfoWrapperPass::runOnMachineFunction(MachineFunction
&Func
) {
80 void MachineCycleInfoWrapperPass::print(raw_ostream
&OS
, const Module
*) const {
81 OS
<< "MachineCycleInfo for function: " << F
->getName() << "\n";
85 void MachineCycleInfoWrapperPass::releaseMemory() {
90 char MachineCycleInfoPrinterPass::ID
= 0;
92 MachineCycleInfoPrinterPass::MachineCycleInfoPrinterPass()
93 : MachineFunctionPass(ID
) {
94 initializeMachineCycleInfoPrinterPassPass(*PassRegistry::getPassRegistry());
97 INITIALIZE_PASS_BEGIN(MachineCycleInfoPrinterPass
, "print-machine-cycles",
98 "Print Machine Cycle Info Analysis", true, true)
99 INITIALIZE_PASS_DEPENDENCY(MachineCycleInfoWrapperPass
)
100 INITIALIZE_PASS_END(MachineCycleInfoPrinterPass
, "print-machine-cycles",
101 "Print Machine Cycle Info Analysis", true, true)
103 void MachineCycleInfoPrinterPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
104 AU
.setPreservesAll();
105 AU
.addRequired
<MachineCycleInfoWrapperPass
>();
106 MachineFunctionPass::getAnalysisUsage(AU
);
109 bool MachineCycleInfoPrinterPass::runOnMachineFunction(MachineFunction
&F
) {
110 auto &CI
= getAnalysis
<MachineCycleInfoWrapperPass
>();