[WebAssembly] Add new target feature in support of 'extended-const' proposal
[llvm-project.git] / llvm / lib / CodeGen / MachineCycleAnalysis.cpp
blob42a5e2b7af01baf19d3748df7d5c75fdb1337cb9
1 //===- MachineCycleAnalysis.cpp - Compute CycleInfo for Machine IR --------===//
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 //===----------------------------------------------------------------------===//
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"
15 using namespace llvm;
17 template class llvm::GenericCycleInfo<llvm::MachineSSAContext>;
18 template class llvm::GenericCycle<llvm::MachineSSAContext>;
20 namespace {
22 /// Legacy analysis pass which computes a \ref MachineCycleInfo.
23 class MachineCycleInfoWrapperPass : public MachineFunctionPass {
24 MachineFunction *F = nullptr;
25 MachineCycleInfo CI;
27 public:
28 static char ID;
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 {
44 public:
45 static char ID;
47 MachineCycleInfoPrinterPass();
49 bool runOnMachineFunction(MachineFunction &F) override;
50 void getAnalysisUsage(AnalysisUsage &AU) const override;
53 } // namespace
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 {
68 AU.setPreservesAll();
69 MachineFunctionPass::getAnalysisUsage(AU);
72 bool MachineCycleInfoWrapperPass::runOnMachineFunction(MachineFunction &Func) {
73 CI.clear();
75 F = &Func;
76 CI.compute(Func);
77 return false;
80 void MachineCycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
81 OS << "MachineCycleInfo for function: " << F->getName() << "\n";
82 CI.print(OS);
85 void MachineCycleInfoWrapperPass::releaseMemory() {
86 CI.clear();
87 F = nullptr;
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>();
111 CI.print(errs());
112 return false;