28
28
#include " llvm/CodeGen/MachineFunctionPass.h"
29
29
#include " llvm/CodeGen/MachineInstr.h"
30
30
#include " llvm/CodeGen/MachineInstrBundle.h"
31
+ #include " llvm/CodeGen/MachinePassManager.h"
31
32
#include " llvm/Support/Allocator.h"
32
33
#include < algorithm>
33
34
#include < cassert>
@@ -293,7 +294,9 @@ class raw_ostream;
293
294
// / SlotIndexes pass.
294
295
// /
295
296
// / This pass assigns indexes to each instruction.
296
- class SlotIndexes : public MachineFunctionPass {
297
+ class SlotIndexes {
298
+ friend class SlotIndexesWrapperPass ;
299
+
297
300
private:
298
301
// IndexListEntry allocator.
299
302
BumpPtrAllocator ileAllocator;
@@ -313,6 +316,13 @@ class raw_ostream;
313
316
// / and MBB id.
314
317
SmallVector<IdxMBBPair, 8 > idx2MBBMap;
315
318
319
+ // For legacy pass manager.
320
+ SlotIndexes () = default ;
321
+
322
+ void clear ();
323
+
324
+ void analyze (MachineFunction &MF);
325
+
316
326
IndexListEntry* createEntry (MachineInstr *mi, unsigned index) {
317
327
IndexListEntry *entry =
318
328
static_cast <IndexListEntry *>(ileAllocator.Allocate (
@@ -327,16 +337,18 @@ class raw_ostream;
327
337
void renumberIndexes (IndexList::iterator curItr);
328
338
329
339
public:
330
- static char ID ;
340
+ SlotIndexes (SlotIndexes &&) = default ;
331
341
332
- SlotIndexes ();
342
+ SlotIndexes (MachineFunction &MF) { analyze (MF); }
333
343
334
- ~SlotIndexes () override ;
344
+ ~SlotIndexes ();
335
345
336
- void getAnalysisUsage (AnalysisUsage &au) const override ;
337
- void releaseMemory () override ;
346
+ void reanalyze (MachineFunction &MF) {
347
+ clear ();
348
+ analyze (MF);
349
+ }
338
350
339
- bool runOnMachineFunction (MachineFunction &fn) override ;
351
+ void print (raw_ostream &OS) const ;
340
352
341
353
// / Dump the indexes.
342
354
void dump () const ;
@@ -629,6 +641,44 @@ class raw_ostream;
629
641
struct IntervalMapInfo <SlotIndex> : IntervalMapHalfOpenInfo<SlotIndex> {
630
642
};
631
643
644
+ class SlotIndexesAnalysis : public AnalysisInfoMixin <SlotIndexesAnalysis> {
645
+ friend AnalysisInfoMixin<SlotIndexesAnalysis>;
646
+ static AnalysisKey Key;
647
+
648
+ public:
649
+ using Result = SlotIndexes;
650
+ Result run (MachineFunction &MF, MachineFunctionAnalysisManager &);
651
+ };
652
+
653
+ class SlotIndexesPrinterPass : public PassInfoMixin <SlotIndexesPrinterPass> {
654
+ raw_ostream &OS;
655
+
656
+ public:
657
+ explicit SlotIndexesPrinterPass (raw_ostream &OS) : OS(OS) {}
658
+ PreservedAnalyses run (MachineFunction &MF,
659
+ MachineFunctionAnalysisManager &MFAM);
660
+ static bool isRequired () { return true ; }
661
+ };
662
+
663
+ class SlotIndexesWrapperPass : public MachineFunctionPass {
664
+ SlotIndexes SI;
665
+
666
+ public:
667
+ static char ID;
668
+
669
+ SlotIndexesWrapperPass ();
670
+
671
+ void getAnalysisUsage (AnalysisUsage &au) const override ;
672
+ void releaseMemory () override { SI.clear (); }
673
+
674
+ bool runOnMachineFunction (MachineFunction &fn) override {
675
+ SI.analyze (fn);
676
+ return false ;
677
+ }
678
+
679
+ SlotIndexes &getSI () { return SI; }
680
+ };
681
+
632
682
} // end namespace llvm
633
683
634
684
#endif // LLVM_CODEGEN_SLOTINDEXES_H
0 commit comments