1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_PIPELINE_H
17 #define PANDA_PIPELINE_H
18 
19 #include <memory>
20 
21 #include "libpandabase/macros.h"
22 #include "compiler/compiler_task_runner.h"
23 
24 namespace ark::compiler {
25 class Graph;
26 
27 /**
28  * Run optimization pipeline.
29  * New pipeline is created by inheriting this class and overriding needed methods.
30  */
31 class Pipeline {
32 public:
Pipeline(Graph *graph)33     explicit Pipeline(Graph *graph) : graph_(graph) {}
34     virtual ~Pipeline() = default;
35 
36     NO_COPY_SEMANTIC(Pipeline);
37     NO_MOVE_SEMANTIC(Pipeline);
38 
39     virtual bool RunOptimizations();
40 
GetGraph()41     Graph *GetGraph()
42     {
43         return graph_;
44     }
45 
46     template <TaskRunnerMode RUNNER_MODE>
47     static void Run(CompilerTaskRunner<RUNNER_MODE> taskRunner);
48 
49     static std::unique_ptr<Pipeline> Create(Graph *graph);
50 
51 private:
52     template <TaskRunnerMode RUNNER_MODE>
53     static void RunRegAllocAndCodeGenPass(CompilerTaskRunner<RUNNER_MODE> taskRunner);
54 
55     Graph *graph_ {nullptr};
56 };
57 
58 }  // namespace ark::compiler
59 
60 #endif  // PANDA_PIPELINE_H
61