• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- PassDetail.h - MLIR Pass details -------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef MLIR_PASS_PASSDETAIL_H_
9 #define MLIR_PASS_PASSDETAIL_H_
10 
11 #include "mlir/Pass/Pass.h"
12 #include "mlir/Pass/PassManager.h"
13 
14 namespace mlir {
15 namespace detail {
16 
17 //===----------------------------------------------------------------------===//
18 // OpToOpPassAdaptor
19 //===----------------------------------------------------------------------===//
20 
21 /// An adaptor pass used to run operation passes over nested operations.
22 class OpToOpPassAdaptor
23     : public PassWrapper<OpToOpPassAdaptor, OperationPass<>> {
24 public:
25   OpToOpPassAdaptor(OpPassManager &&mgr);
26   OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs) = default;
27 
28   /// Run the held pipeline over all operations.
29   void runOnOperation(bool verifyPasses);
30   void runOnOperation() override;
31 
32   /// Merge the current pass adaptor into given 'rhs'.
33   void mergeInto(OpToOpPassAdaptor &rhs);
34 
35   /// Returns the pass managers held by this adaptor.
getPassManagers()36   MutableArrayRef<OpPassManager> getPassManagers() { return mgrs; }
37 
38   /// Populate the set of dependent dialects for the passes in the current
39   /// adaptor.
40   void getDependentDialects(DialectRegistry &dialects) const override;
41 
42   /// Return the async pass managers held by this parallel adaptor.
getParallelPassManagers()43   MutableArrayRef<SmallVector<OpPassManager, 1>> getParallelPassManagers() {
44     return asyncExecutors;
45   }
46 
47   /// Returns the adaptor pass name.
48   std::string getAdaptorName();
49 
50 private:
51   /// Run this pass adaptor synchronously.
52   void runOnOperationImpl(bool verifyPasses);
53 
54   /// Run this pass adaptor asynchronously.
55   void runOnOperationAsyncImpl(bool verifyPasses);
56 
57   /// Run the given operation and analysis manager on a single pass.
58   static LogicalResult run(Pass *pass, Operation *op, AnalysisManager am,
59                            bool verifyPasses);
60 
61   /// Run the given operation and analysis manager on a provided op pass
62   /// manager.
63   static LogicalResult
64   runPipeline(iterator_range<OpPassManager::pass_iterator> passes,
65               Operation *op, AnalysisManager am, bool verifyPasses);
66 
67   /// A set of adaptors to run.
68   SmallVector<OpPassManager, 1> mgrs;
69 
70   /// A set of executors, cloned from the main executor, that run asynchronously
71   /// on different threads. This is used when threading is enabled.
72   SmallVector<SmallVector<OpPassManager, 1>, 8> asyncExecutors;
73 
74   // For accessing "runPipeline".
75   friend class mlir::PassManager;
76 };
77 
78 } // end namespace detail
79 } // end namespace mlir
80 #endif // MLIR_PASS_PASSDETAIL_H_
81