File indexing completed on 2026-05-10 08:43:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef LLVM_CODEGEN_MACHINELOOPINFO_H
0030 #define LLVM_CODEGEN_MACHINELOOPINFO_H
0031
0032 #include "llvm/CodeGen/MachineBasicBlock.h"
0033 #include "llvm/CodeGen/MachineFunctionPass.h"
0034 #include "llvm/CodeGen/MachinePassManager.h"
0035 #include "llvm/IR/CFG.h"
0036 #include "llvm/IR/DebugLoc.h"
0037 #include "llvm/Support/GenericLoopInfo.h"
0038
0039 namespace llvm {
0040
0041 class MachineDominatorTree;
0042
0043 class MachineLoop;
0044 extern template class LoopBase<MachineBasicBlock, MachineLoop>;
0045
0046 class MachineLoop : public LoopBase<MachineBasicBlock, MachineLoop> {
0047 public:
0048
0049
0050
0051 MachineBasicBlock *getTopBlock();
0052
0053
0054
0055
0056 MachineBasicBlock *getBottomBlock();
0057
0058
0059
0060
0061
0062 MachineBasicBlock *findLoopControlBlock() const;
0063
0064
0065
0066
0067
0068
0069 DebugLoc getStartLoc() const;
0070
0071
0072
0073
0074
0075
0076
0077 MDNode *getLoopID() const;
0078
0079
0080
0081
0082
0083
0084
0085
0086 bool isLoopInvariant(MachineInstr &I, const Register ExcludeReg = 0) const;
0087
0088 void dump() const;
0089
0090 private:
0091 friend class LoopInfoBase<MachineBasicBlock, MachineLoop>;
0092
0093
0094 bool isLoopInvariantImplicitPhysReg(Register Reg) const;
0095
0096 explicit MachineLoop(MachineBasicBlock *MBB)
0097 : LoopBase<MachineBasicBlock, MachineLoop>(MBB) {}
0098
0099 MachineLoop() = default;
0100 };
0101
0102
0103 extern template class LoopInfoBase<MachineBasicBlock, MachineLoop>;
0104
0105 class MachineLoopInfo : public LoopInfoBase<MachineBasicBlock, MachineLoop> {
0106 friend class LoopBase<MachineBasicBlock, MachineLoop>;
0107 friend class MachineLoopInfoWrapperPass;
0108
0109 public:
0110 MachineLoopInfo() = default;
0111 explicit MachineLoopInfo(MachineDominatorTree &MDT) { calculate(MDT); }
0112 MachineLoopInfo(MachineLoopInfo &&) = default;
0113 MachineLoopInfo(const MachineLoopInfo &) = delete;
0114 MachineLoopInfo &operator=(const MachineLoopInfo &) = delete;
0115
0116
0117 bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
0118 MachineFunctionAnalysisManager::Invalidator &);
0119
0120
0121
0122
0123
0124
0125
0126
0127 MachineBasicBlock *
0128 findLoopPreheader(MachineLoop *L, bool SpeculativePreheader = false,
0129 bool FindMultiLoopPreheader = false) const;
0130
0131
0132 void calculate(MachineDominatorTree &MDT);
0133 };
0134
0135
0136 class MachineLoopAnalysis : public AnalysisInfoMixin<MachineLoopAnalysis> {
0137 friend AnalysisInfoMixin<MachineLoopAnalysis>;
0138 static AnalysisKey Key;
0139
0140 public:
0141 using Result = MachineLoopInfo;
0142 Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
0143 };
0144
0145
0146 class MachineLoopPrinterPass : public PassInfoMixin<MachineLoopPrinterPass> {
0147 raw_ostream &OS;
0148
0149 public:
0150 explicit MachineLoopPrinterPass(raw_ostream &OS) : OS(OS) {}
0151 PreservedAnalyses run(MachineFunction &MF,
0152 MachineFunctionAnalysisManager &MFAM);
0153 static bool isRequired() { return true; }
0154 };
0155
0156 class MachineLoopInfoWrapperPass : public MachineFunctionPass {
0157 MachineLoopInfo LI;
0158
0159 public:
0160 static char ID;
0161
0162 MachineLoopInfoWrapperPass();
0163
0164 bool runOnMachineFunction(MachineFunction &F) override;
0165
0166 void releaseMemory() override { LI.releaseMemory(); }
0167
0168 void getAnalysisUsage(AnalysisUsage &AU) const override;
0169
0170 MachineLoopInfo &getLI() { return LI; }
0171 };
0172
0173
0174 template <> struct GraphTraits<const MachineLoop*> {
0175 using NodeRef = const MachineLoop *;
0176 using ChildIteratorType = MachineLoopInfo::iterator;
0177
0178 static NodeRef getEntryNode(const MachineLoop *L) { return L; }
0179 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
0180 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
0181 };
0182
0183 template <> struct GraphTraits<MachineLoop*> {
0184 using NodeRef = MachineLoop *;
0185 using ChildIteratorType = MachineLoopInfo::iterator;
0186
0187 static NodeRef getEntryNode(MachineLoop *L) { return L; }
0188 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
0189 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
0190 };
0191
0192 }
0193
0194 #endif