zackcquic commented on pull request #7952:
URL: https://github.com/apache/tvm/pull/7952#issuecomment-846553197


   ### Collector of pass instrumentation instance
   **Following table shows the class and API that collects a set of pass 
instrumentations in different projects:**
   
   Note:
   - [IO] = Pass instrumentations are processed in order
   - [RO] = Pass instrumentations are processed in reverse order
   - Entry empty = No mapping API
   - mlir::PassInstrumentor provides thread-safety.
   
   | This PR (PassContext.instruments)      | llvm::PassInstrumentation         
  | mlir::PassInstrumentor         |
   | -------------------------------------- | 
----------------------------------- | ------------------------------ |
   | [IO] bool InstrumentBeforePass()       | [IO] bool runBeforePass()         
  | [IO] void runBeforePass()      |
   | [IO] bool InstrumentAfterPass()        | [IO] void runAfterPass()          
  | [RO] void runAfterPass()       |
   |                                        | [IO] void 
runAfterPassInvalidated() |                                |
   |                                        |                                   
  | [RO] void runAfterPassFailed() |
   |                                        | [IO] void runBeforeAnalysis()     
  | [IO] void runBeforeAnalysis()  |
   |                                        | [IO] void runAfterAnalysis()      
  | [RO] void runAfterAnalysis()   |
   |                                        | [IO] void 
runAnalysisInvalidated()  |                                |
   |                                        | [IO] void runAnalysesCleared()    
  |                                |
   | [IO] void InstrumentEnterPassContext() |                                   
  | [IO] void runBeforePipeline()  |
   | [IO] void InstrumentExitPassContext()  |                                   
  | [RO] void runAfterPipeline()   |
   ### Pass instrumentation instance
   **Following table shows the class and API to implement a pass 
instrumentation in different projects:**
   
   Note:
   -  In LLVM, a pass instrumentation provides a set of callbacks and register 
them in ```llvm::PassInstrumentationCallbacks```,
   which will be called in collectors at different instrumentation points.
   - In MLIR and this PR, pass instrumentation subclassing base class and 
overriding methods.
   
   | This PR (instrument::PassInstrumentNode)   | 
llvm::PassInstrumentationCallbacks | mlir::PassInstrumentation |
   | -----------------------------------------  | 
---------------------------------- | --------------------------|
   |  virtual bool ShouldRun()                          | void 
registerShouldRunOptionalPassCallback(CallableT) <br> // CallableT = 
bool(StringRef, Any), called in llvm::PassInstrumentation | |
   | | void registerBeforeSkippedPassCallback(CallableT) <br> // CallableT = 
void(StringRef, Any), called in llvm::PassInstrumentation | |
   | | void registerBeforeNonSkippedPassCallback(CallableT) <br> // CallableT = 
void(StringRef, Any), called in llvm::PassInstrumentation | |
   | virtual void RunBeforePass()                       | | virtual void 
runBeforePass() |
   | virtual void RunAfterPass()  | void registerAfterPassCallback(CallableT)  
<br> // CallableT = void(StringRef, Any, const PreservedAnalyses &), called in 
llvm::PassInstrumentation | virtual void runAfterPass()
   | |void registerAfterPassInvalidatedCallback(CallableT) <br> // CallableT = 
void(StringRef, const PreservedAnalyses &), called in llvm::PassInstrumentation 
| |
   | |  void registerBeforeAnalysisCallback(CallableT)  <br> // CallableT = 
void(StringRef, Any), called in llvm::PassInstrumentation | virtual void 
runBeforeAnalysis() |
   | |  void registerAfterAnalysisCallback(CallableT) <br> // CallableT = 
void(StringRef, Any), called in llvm::PassInstrumentation | virtual void 
runAfterAnalysis() |
   | |  void registerAnalysisInvalidatedCallback(CallableT)  <br> // CallableT 
= void(StringRef, Any), called in llvm::PassInstrumentation | |
   | |  void registerAnalysesClearedCallback(CallableT) <br> // CallableT = 
void(StringRef), called in llvm::PassInstrumentation | |
   | virtual void EnterPassContext() | | virtual void runBeforePipeline() |
   | virtual void ExitPassContext() | | virtual void runAfterPipeline() |
   
   ### RunBeforePass API
   Following is the code snip from  ```bool 
llvm::PassInstrumentation::runBeforePass()```.
   It splits the ```ShouldRun()``` and ```RunBefore()``` logic from a pass 
instrumentation, like @areusch recommended.
    
   ```c++
     /// BeforePass instrumentation point - takes \p Pass instance to be 
executed
     /// and constant reference to IR it operates on. \Returns true if pass is
     /// allowed to be executed. These are only run on optional pass since 
required
     /// passes must always be run. This allows these callbacks to print info 
when
     /// they want to skip a pass.
     template <typename IRUnitT, typename PassT>
     bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const {
       if (!Callbacks)
         return true;
   
       bool ShouldRun = true;
       if (!isRequired(Pass)) {
         for (auto &C : Callbacks->ShouldRunOptionalPassCallbacks)
           ShouldRun &= C(Pass.name(), llvm::Any(&IR));
       }
   
       if (ShouldRun) {
         for (auto &C : Callbacks->BeforeNonSkippedPassCallbacks)
           C(Pass.name(), llvm::Any(&IR));
       } else {
         for (auto &C : Callbacks->BeforeSkippedPassCallbacks)
           C(Pass.name(), llvm::Any(&IR));
       }
   
       return ShouldRun;
     }
   ```
   
   In the updated commit, I use this way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to