|
26 | 26 | #include "llvm/ADT/TinyPtrVector.h"
|
27 | 27 | #include "llvm/CodeGen/LoopTraversal.h"
|
28 | 28 | #include "llvm/CodeGen/MachineFunctionPass.h"
|
| 29 | +#include "llvm/CodeGen/MachinePassManager.h" |
29 | 30 | #include "llvm/InitializePasses.h"
|
30 | 31 |
|
31 | 32 | namespace llvm {
|
@@ -110,7 +111,7 @@ class MBBReachingDefsInfo {
|
110 | 111 | };
|
111 | 112 |
|
112 | 113 | /// This class provides the reaching def analysis.
|
113 |
| -class ReachingDefAnalysis : public MachineFunctionPass { |
| 114 | +class ReachingDefInfo { |
114 | 115 | private:
|
115 | 116 | MachineFunction *MF = nullptr;
|
116 | 117 | const TargetRegisterInfo *TRI = nullptr;
|
@@ -156,24 +157,16 @@ class ReachingDefAnalysis : public MachineFunctionPass {
|
156 | 157 | using BlockSet = SmallPtrSetImpl<MachineBasicBlock*>;
|
157 | 158 |
|
158 | 159 | public:
|
159 |
| - static char ID; // Pass identification, replacement for typeid |
| 160 | + ReachingDefInfo(); |
| 161 | + ReachingDefInfo(ReachingDefInfo &&); |
| 162 | + ~ReachingDefInfo(); |
| 163 | + /// Handle invalidation explicitly. |
| 164 | + bool invalidate(MachineFunction &F, const PreservedAnalyses &PA, |
| 165 | + MachineFunctionAnalysisManager::Invalidator &); |
160 | 166 |
|
161 |
| - ReachingDefAnalysis() : MachineFunctionPass(ID) { |
162 |
| - initializeReachingDefAnalysisPass(*PassRegistry::getPassRegistry()); |
163 |
| - } |
164 |
| - void releaseMemory() override; |
165 |
| - |
166 |
| - void getAnalysisUsage(AnalysisUsage &AU) const override { |
167 |
| - AU.setPreservesAll(); |
168 |
| - MachineFunctionPass::getAnalysisUsage(AU); |
169 |
| - } |
170 |
| - |
171 |
| - void printAllReachingDefs(MachineFunction &MF); |
172 |
| - bool runOnMachineFunction(MachineFunction &MF) override; |
173 |
| - |
174 |
| - MachineFunctionProperties getRequiredProperties() const override { |
175 |
| - return MachineFunctionProperties().setNoVRegs().setTracksLiveness(); |
176 |
| - } |
| 167 | + void run(MachineFunction &mf); |
| 168 | + void print(raw_ostream &OS); |
| 169 | + void releaseMemory(); |
177 | 170 |
|
178 | 171 | /// Re-run the analysis.
|
179 | 172 | void reset();
|
@@ -319,6 +312,46 @@ class ReachingDefAnalysis : public MachineFunctionPass {
|
319 | 312 | MachineInstr *getReachingLocalMIDef(MachineInstr *MI, Register Reg) const;
|
320 | 313 | };
|
321 | 314 |
|
| 315 | +class ReachingDefAnalysis : public AnalysisInfoMixin<ReachingDefAnalysis> { |
| 316 | + friend AnalysisInfoMixin<ReachingDefAnalysis>; |
| 317 | + static AnalysisKey Key; |
| 318 | + |
| 319 | +public: |
| 320 | + using Result = ReachingDefInfo; |
| 321 | + |
| 322 | + Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); |
| 323 | +}; |
| 324 | + |
| 325 | +/// Printer pass for the \c ReachingDefInfo results. |
| 326 | +class ReachingDefPrinterPass : public PassInfoMixin<ReachingDefPrinterPass> { |
| 327 | + raw_ostream &OS; |
| 328 | + |
| 329 | +public: |
| 330 | + explicit ReachingDefPrinterPass(raw_ostream &OS) : OS(OS) {} |
| 331 | + |
| 332 | + PreservedAnalyses run(MachineFunction &MF, |
| 333 | + MachineFunctionAnalysisManager &MFAM); |
| 334 | + |
| 335 | + static bool isRequired() { return true; } |
| 336 | +}; |
| 337 | + |
| 338 | +class ReachingDefInfoWrapperPass : public MachineFunctionPass { |
| 339 | + ReachingDefInfo RDI; |
| 340 | + |
| 341 | +public: |
| 342 | + static char ID; |
| 343 | + |
| 344 | + ReachingDefInfoWrapperPass(); |
| 345 | + |
| 346 | + void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 347 | + MachineFunctionProperties getRequiredProperties() const override; |
| 348 | + bool runOnMachineFunction(MachineFunction &F) override; |
| 349 | + void releaseMemory() override { RDI.releaseMemory(); } |
| 350 | + |
| 351 | + ReachingDefInfo &getRDI() { return RDI; } |
| 352 | + const ReachingDefInfo &getRDI() const { return RDI; } |
| 353 | +}; |
| 354 | + |
322 | 355 | } // namespace llvm
|
323 | 356 |
|
324 | 357 | #endif // LLVM_CODEGEN_REACHINGDEFANALYSIS_H
|
0 commit comments