@@ -32,11 +32,18 @@ class SILModuleTransform;
3232class SILOptions ;
3333class SILTransform ;
3434
35+ namespace irgen {
36+ class IRGenModule ;
37+ }
38+
3539// / \brief The SIL pass manager.
3640class SILPassManager {
3741 // / The module that the pass manager will transform.
3842 SILModule *Mod;
3943
44+ // / An optional IRGenModule associated with this PassManager.
45+ irgen::IRGenModule *IRMod;
46+
4047 // / The list of transformations to run.
4148 llvm::SmallVector<SILTransform *, 16 > Transformations;
4249
@@ -90,11 +97,20 @@ class SILPassManager {
9097 // / same function.
9198 bool RestartPipeline = false ;
9299
100+
101+ // / The IRGen SIL passes. These have to be dynamically added by IRGen.
102+ llvm::DenseMap<unsigned , SILFunctionTransform *> IRGenPasses;
103+
93104public:
94105 // / C'tor. It creates and registers all analysis passes, which are defined
95106 // / in Analysis.def.
96107 SILPassManager (SILModule *M, llvm::StringRef Stage = " " );
97108
109+ // / C'tor. It creates an IRGen pass manager. Passes can query for the
110+ // / IRGenModule.
111+ SILPassManager (SILModule *M, irgen::IRGenModule *IRMod,
112+ llvm::StringRef Stage = " " );
113+
98114 const SILOptions &getOptions () const ;
99115
100116 // / \brief Searches for an analysis of type T in the list of registered
@@ -111,6 +127,10 @@ class SILPassManager {
111127 // / \returns the module that the pass manager owns.
112128 SILModule *getModule () { return Mod; }
113129
130+ // / \returns the associated IGenModule or null if this is not an IRGen
131+ // / pass manager.
132+ irgen::IRGenModule *getIRGenModule () { return IRMod; }
133+
114134 // / \brief Run one iteration of the optimization pipeline.
115135 void runOneIteration ();
116136
@@ -218,6 +238,15 @@ class SILPassManager {
218238 }
219239 }
220240
241+ void registerIRGenPass (PassKind Kind, SILFunctionTransform *Transform) {
242+ assert (IRGenPasses.find (unsigned (Kind)) == IRGenPasses.end () &&
243+ " Pass already registered" );
244+ assert (
245+ IRMod &&
246+ " Attempting to register an IRGen pass with a non-IRGen pass manager" );
247+ IRGenPasses[unsigned (Kind)] = Transform;
248+ }
249+
221250private:
222251 void execute () {
223252 runOneIteration ();
0 commit comments