xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MachineCycleAnalysis.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- MachineCycleAnalysis.h - Cycle Info for Machine IR -------*- C++ -*-===//
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 file defines the MachineCycleInfo class, which is a thin wrapper over
10 // the Machine IR instance of GenericCycleInfo.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACHINECYCLEANALYSIS_H
15 #define LLVM_CODEGEN_MACHINECYCLEANALYSIS_H
16 
17 #include "llvm/ADT/GenericCycleInfo.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/MachinePassManager.h"
20 #include "llvm/CodeGen/MachineSSAContext.h"
21 #include "llvm/Support/Compiler.h"
22 
23 namespace llvm {
24 
25 using MachineCycleInfo = GenericCycleInfo<MachineSSAContext>;
26 using MachineCycle = MachineCycleInfo::CycleT;
27 
28 /// Legacy analysis pass which computes a \ref MachineCycleInfo.
29 class LLVM_ABI MachineCycleInfoWrapperPass : public MachineFunctionPass {
30   MachineFunction *F = nullptr;
31   MachineCycleInfo CI;
32 
33 public:
34   static char ID;
35 
36   MachineCycleInfoWrapperPass();
37 
getCycleInfo()38   MachineCycleInfo &getCycleInfo() { return CI; }
getCycleInfo()39   const MachineCycleInfo &getCycleInfo() const { return CI; }
40 
41   bool runOnMachineFunction(MachineFunction &F) override;
42   void getAnalysisUsage(AnalysisUsage &AU) const override;
43   void releaseMemory() override;
44   void print(raw_ostream &OS, const Module *M = nullptr) const override;
45 };
46 
47 // TODO: add this function to GenericCycle template after implementing IR
48 //       version.
49 LLVM_ABI bool isCycleInvariant(const MachineCycle *Cycle, MachineInstr &I);
50 
51 class MachineCycleAnalysis : public AnalysisInfoMixin<MachineCycleAnalysis> {
52   friend AnalysisInfoMixin<MachineCycleAnalysis>;
53   LLVM_ABI static AnalysisKey Key;
54 
55 public:
56   using Result = MachineCycleInfo;
57 
58   LLVM_ABI Result run(MachineFunction &MF,
59                       MachineFunctionAnalysisManager &MFAM);
60 };
61 
62 class MachineCycleInfoPrinterPass
63     : public PassInfoMixin<MachineCycleInfoPrinterPass> {
64   raw_ostream &OS;
65 
66 public:
MachineCycleInfoPrinterPass(raw_ostream & OS)67   explicit MachineCycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
68   LLVM_ABI PreservedAnalyses run(MachineFunction &MF,
69                                  MachineFunctionAnalysisManager &MFAM);
isRequired()70   static bool isRequired() { return true; }
71 };
72 
73 } // end namespace llvm
74 
75 #endif // LLVM_CODEGEN_MACHINECYCLEANALYSIS_H
76