1616#define LLVM_CODEGEN_ASMPRINTER_H
1717
1818#include " llvm/ADT/DenseMap.h"
19+ #include " llvm/ADT/IntrusiveRefCntPtr.h"
1920#include " llvm/ADT/MapVector.h"
2021#include " llvm/ADT/SmallVector.h"
2122#include " llvm/BinaryFormat/Dwarf.h"
2223#include " llvm/CodeGen/DwarfStringPoolEntry.h"
2324#include " llvm/CodeGen/MachineFunctionPass.h"
25+ #include " llvm/CodeGen/MachinePassManager.h"
2426#include " llvm/CodeGen/StackMaps.h"
2527#include " llvm/DebugInfo/CodeView/CodeView.h"
2628#include " llvm/IR/InlineAsm.h"
@@ -84,7 +86,9 @@ class RemarkStreamer;
8486}
8587
8688// / This class is intended to be used as a driving class for all asm writers.
87- class AsmPrinter : public MachineFunctionPass {
89+ // / Use lightweight RefCountedBase here because AsmPrinter is shared only in
90+ // / pass manager.
91+ class AsmPrinter : public RefCountedBase <AsmPrinter> {
8892public:
8993 // / Target machine description.
9094 TargetMachine &TM;
@@ -180,8 +184,6 @@ class AsmPrinter : public MachineFunctionPass {
180184 // / List of symbols to be inserted into PC sections.
181185 DenseMap<const MDNode *, SmallVector<const MCSymbol *>> PCSectionsSymbols;
182186
183- static char ID;
184-
185187protected:
186188 MCSymbol *CurrentFnBegin = nullptr ;
187189
@@ -201,6 +203,10 @@ class AsmPrinter : public MachineFunctionPass {
201203
202204 StackMaps SM;
203205
206+ MachineFunctionPass *MFPass = nullptr ;
207+ ModuleAnalysisManager *MAM = nullptr ;
208+ MachineFunctionAnalysisManager *MFAM = nullptr ;
209+
204210private:
205211 // / If generated on the fly this own the instance.
206212 std::unique_ptr<MachineDominatorTree> OwnedMDT;
@@ -235,7 +241,7 @@ class AsmPrinter : public MachineFunctionPass {
235241 explicit AsmPrinter (TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
236242
237243public:
238- ~AsmPrinter () override ;
244+ virtual ~AsmPrinter ();
239245
240246 DwarfDebug *getDwarfDebug () { return DD; }
241247 DwarfDebug *getDwarfDebug () const { return DD; }
@@ -375,24 +381,31 @@ class AsmPrinter : public MachineFunctionPass {
375381 // MachineFunctionPass Implementation.
376382 // ===------------------------------------------------------------------===//
377383
384+ virtual StringRef getPassName () const ;
385+
378386 // / Record analysis usage.
379- void getAnalysisUsage (AnalysisUsage &AU) const override ;
387+ virtual void getAnalysisUsage (AnalysisUsage &AU) const ;
380388
381389 // / Set up the AsmPrinter when we are working on a new module. If your pass
382390 // / overrides this, it must make sure to explicitly call this implementation.
383- bool doInitialization (Module &M) override ;
391+ virtual bool doInitialization (Module &M);
384392
385393 // / Shut down the asmprinter. If you override this in your pass, you must make
386394 // / sure to call it explicitly.
387- bool doFinalization (Module &M) override ;
395+ virtual bool doFinalization (Module &M);
388396
389397 // / Emit the specified function out to the OutStreamer.
390- bool runOnMachineFunction (MachineFunction &MF) override {
398+ virtual bool runOnMachineFunction (MachineFunction &MF) {
391399 SetupMachineFunction (MF);
392400 emitFunctionBody ();
393401 return false ;
394402 }
395403
404+ void setPass (MachineFunctionPass *P) { MFPass = P; }
405+ void setMAM (ModuleAnalysisManager &AM) { MAM = &AM; }
406+ void clearMAM () { MAM = nullptr ; }
407+ void setMFAM (MachineFunctionAnalysisManager &AM) { MFAM = &AM; }
408+
396409 // ===------------------------------------------------------------------===//
397410 // Coarse grained IR lowering routines.
398411 // ===------------------------------------------------------------------===//
@@ -523,6 +536,7 @@ class AsmPrinter : public MachineFunctionPass {
523536
524537 // / Emit the stack maps.
525538 void emitStackMaps ();
539+ void emitStackMaps (Module &M); // For new pass manager version.
526540
527541 // ===------------------------------------------------------------------===//
528542 // Overridable Hooks
@@ -922,6 +936,78 @@ class AsmPrinter : public MachineFunctionPass {
922936 }
923937};
924938
939+ class AsmPrinterInitializePass
940+ : public PassInfoMixin<AsmPrinterInitializePass> {
941+ IntrusiveRefCntPtr<AsmPrinter> Printer;
942+
943+ public:
944+ explicit AsmPrinterInitializePass (IntrusiveRefCntPtr<AsmPrinter> AP)
945+ : Printer(std::move(AP)) {}
946+
947+ PreservedAnalyses run (Module &M, ModuleAnalysisManager &MAM);
948+ };
949+
950+ class AsmPrinterPass : public PassInfoMixin <AsmPrinterPass> {
951+ IntrusiveRefCntPtr<AsmPrinter> Printer;
952+
953+ public:
954+ explicit AsmPrinterPass (IntrusiveRefCntPtr<AsmPrinter> AP)
955+ : Printer(std::move(AP)) {}
956+
957+ PreservedAnalyses run (MachineFunction &MF,
958+ MachineFunctionAnalysisManager &MFAM);
959+ };
960+
961+ class AsmPrinterFinalizePass : public PassInfoMixin <AsmPrinterFinalizePass> {
962+ IntrusiveRefCntPtr<AsmPrinter> Printer;
963+
964+ public:
965+ explicit AsmPrinterFinalizePass (IntrusiveRefCntPtr<AsmPrinter> AP)
966+ : Printer(std::move(AP)) {}
967+
968+ PreservedAnalyses run (Module &M, ModuleAnalysisManager &);
969+ };
970+
971+ class AsmPrinterLegacy : public MachineFunctionPass {
972+ std::unique_ptr<AsmPrinter> Printer;
973+
974+ public:
975+ static char ID;
976+
977+ explicit AsmPrinterLegacy (std::unique_ptr<AsmPrinter> AP);
978+
979+ AsmPrinter &getPrinter () { return *Printer; }
980+
981+ // ===------------------------------------------------------------------===//
982+ // MachineFunctionPass Implementation.
983+ // ===------------------------------------------------------------------===//
984+
985+ // / Record analysis usage.
986+ void getAnalysisUsage (AnalysisUsage &AU) const override {
987+ MachineFunctionPass::getAnalysisUsage (AU);
988+ Printer->getAnalysisUsage (AU);
989+ }
990+
991+ // / Set up the AsmPrinter when we are working on a new module. If your pass
992+ // / overrides this, it must make sure to explicitly call this implementation.
993+ bool doInitialization (Module &M) override {
994+ return Printer->doInitialization (M);
995+ }
996+
997+ // / Shut down the asmprinter. If you override this in your pass, you must make
998+ // / sure to call it explicitly.
999+ bool doFinalization (Module &M) override { return Printer->doFinalization (M); }
1000+
1001+ // / Emit the specified function out to the OutStreamer.
1002+ bool runOnMachineFunction (MachineFunction &MF) override {
1003+ return Printer->runOnMachineFunction (MF);
1004+ }
1005+
1006+ StringRef getPassName () const override { return Printer->getPassName (); }
1007+ };
1008+
1009+ AsmPrinterLegacy *createAsmPrinterLegacy (std::unique_ptr<AsmPrinter> AP);
1010+
9251011} // end namespace llvm
9261012
9271013#endif // LLVM_CODEGEN_ASMPRINTER_H
0 commit comments