1 | /** |
2 | * Copyright (c) Glow Contributors. See CONTRIBUTORS file. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | #ifndef GLOW_PASSMANAGER_PASS_H |
17 | #define GLOW_PASSMANAGER_PASS_H |
18 | |
19 | #include "glow/Optimizer/GraphOptimizer/CompilationContext.h" |
20 | #include "llvm/ADT/StringRef.h" |
21 | |
22 | namespace glow { |
23 | |
24 | class PassBase : public Named { |
25 | public: |
26 | PassBase(llvm::StringRef name) : Named(name) {} |
27 | |
28 | virtual ~PassBase() = default; |
29 | }; |
30 | |
31 | /// Class used for all passes over IR containers represented by the type \p |
32 | /// IRCONTAINER, which can be e.g. Function or IRFunction. All passes over units |
33 | /// should derive from this class, implementing the pass logic and additionally |
34 | /// can add logic for running before and after the pass runs. The pass configs |
35 | /// are represented by the type \p IRPASSCONFIG. |
36 | template <typename IRCONTAINER, typename IRPASSCONFIG> |
37 | class Pass : public PassBase { |
38 | public: |
39 | using IRContainerTy = IRCONTAINER; |
40 | using IRPassConfigTy = IRPASSCONFIG; |
41 | using PassIDTy = typename IRPassConfigTy::PassIDTy; |
42 | |
43 | public: |
44 | /// Constructor. |
45 | Pass(llvm::StringRef name) : PassBase(name) {} |
46 | |
47 | virtual ~Pass() = default; |
48 | |
49 | /// Run the pass on \p C. \returns whether the pass modifies \p C. |
50 | virtual bool run(IRContainerTy *C, const CompilationContext &cctx) = 0; |
51 | |
52 | /// \returns the id of the pass. |
53 | virtual PassIDTy getID() const = 0; |
54 | }; |
55 | |
56 | } // namespace glow |
57 | |
58 | #endif // GLOW_PASSMANAGER_PASS_H |
59 | |