16
16
#define LLVM_CODEGEN_ASMPRINTER_H
17
17
18
18
#include " llvm/ADT/DenseMap.h"
19
+ #include " llvm/ADT/IntrusiveRefCntPtr.h"
19
20
#include " llvm/ADT/MapVector.h"
20
21
#include " llvm/ADT/SmallVector.h"
21
22
#include " llvm/BinaryFormat/Dwarf.h"
22
23
#include " llvm/CodeGen/DwarfStringPoolEntry.h"
23
24
#include " llvm/CodeGen/MachineFunctionPass.h"
25
+ #include " llvm/CodeGen/MachinePassManager.h"
24
26
#include " llvm/CodeGen/StackMaps.h"
25
27
#include " llvm/DebugInfo/CodeView/CodeView.h"
26
28
#include " llvm/IR/InlineAsm.h"
@@ -84,7 +86,9 @@ class RemarkStreamer;
84
86
}
85
87
86
88
// / 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> {
88
92
public:
89
93
// / Target machine description.
90
94
TargetMachine &TM;
@@ -180,8 +184,6 @@ class AsmPrinter : public MachineFunctionPass {
180
184
// / List of symbols to be inserted into PC sections.
181
185
DenseMap<const MDNode *, SmallVector<const MCSymbol *>> PCSectionsSymbols;
182
186
183
- static char ID;
184
-
185
187
protected:
186
188
MCSymbol *CurrentFnBegin = nullptr ;
187
189
@@ -201,6 +203,10 @@ class AsmPrinter : public MachineFunctionPass {
201
203
202
204
StackMaps SM;
203
205
206
+ MachineFunctionPass *MFPass = nullptr ;
207
+ ModuleAnalysisManager *MAM = nullptr ;
208
+ MachineFunctionAnalysisManager *MFAM = nullptr ;
209
+
204
210
private:
205
211
// / If generated on the fly this own the instance.
206
212
std::unique_ptr<MachineDominatorTree> OwnedMDT;
@@ -235,7 +241,7 @@ class AsmPrinter : public MachineFunctionPass {
235
241
explicit AsmPrinter (TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
236
242
237
243
public:
238
- ~AsmPrinter () override ;
244
+ virtual ~AsmPrinter ();
239
245
240
246
DwarfDebug *getDwarfDebug () { return DD; }
241
247
DwarfDebug *getDwarfDebug () const { return DD; }
@@ -375,24 +381,31 @@ class AsmPrinter : public MachineFunctionPass {
375
381
// MachineFunctionPass Implementation.
376
382
// ===------------------------------------------------------------------===//
377
383
384
+ virtual StringRef getPassName () const ;
385
+
378
386
// / Record analysis usage.
379
- void getAnalysisUsage (AnalysisUsage &AU) const override ;
387
+ virtual void getAnalysisUsage (AnalysisUsage &AU) const ;
380
388
381
389
// / Set up the AsmPrinter when we are working on a new module. If your pass
382
390
// / overrides this, it must make sure to explicitly call this implementation.
383
- bool doInitialization (Module &M) override ;
391
+ virtual bool doInitialization (Module &M);
384
392
385
393
// / Shut down the asmprinter. If you override this in your pass, you must make
386
394
// / sure to call it explicitly.
387
- bool doFinalization (Module &M) override ;
395
+ virtual bool doFinalization (Module &M);
388
396
389
397
// / Emit the specified function out to the OutStreamer.
390
- bool runOnMachineFunction (MachineFunction &MF) override {
398
+ virtual bool runOnMachineFunction (MachineFunction &MF) {
391
399
SetupMachineFunction (MF);
392
400
emitFunctionBody ();
393
401
return false ;
394
402
}
395
403
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
+
396
409
// ===------------------------------------------------------------------===//
397
410
// Coarse grained IR lowering routines.
398
411
// ===------------------------------------------------------------------===//
@@ -523,6 +536,7 @@ class AsmPrinter : public MachineFunctionPass {
523
536
524
537
// / Emit the stack maps.
525
538
void emitStackMaps ();
539
+ void emitStackMaps (Module &M); // For new pass manager version.
526
540
527
541
// ===------------------------------------------------------------------===//
528
542
// Overridable Hooks
@@ -922,6 +936,78 @@ class AsmPrinter : public MachineFunctionPass {
922
936
}
923
937
};
924
938
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
+
925
1011
} // end namespace llvm
926
1012
927
1013
#endif // LLVM_CODEGEN_ASMPRINTER_H
0 commit comments