• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLE_PHASE_INCLUDE_PHASE_IMPL_H
17 #define MAPLE_PHASE_INCLUDE_PHASE_IMPL_H
18 #include "mir_builder.h"
19 #include "mpl_scheduler.h"
20 #include "utils.h"
21 
22 namespace maple {
23 class FuncOptimizeImpl : public MplTaskParam {
24 public:
25     FuncOptimizeImpl(MIRModule &mod, bool trace = false);
26     virtual ~FuncOptimizeImpl();
27     // Each phase needs to implement its own Clone
28     virtual FuncOptimizeImpl *Clone() = 0;
GetMIRModule()29     MIRModule &GetMIRModule()
30     {
31         return *module;
32     }
33 
GetMIRModule()34     const MIRModule &GetMIRModule() const
35     {
36         return *module;
37     }
38 
SetDump(bool dumpFunc)39     void SetDump(bool dumpFunc)
40     {
41         dump = dumpFunc;
42     }
43 
Finish()44     virtual void Finish() {}
45 
46 protected:
SetCurrentFunction(MIRFunction & func)47     void SetCurrentFunction(MIRFunction &func)
48     {
49         currFunc = &func;
50         DEBUG_ASSERT(builder != nullptr, "builder is null in FuncOptimizeImpl::SetCurrentFunction");
51         builder->SetCurrentFunction(func);
52         module->SetCurFunction(&func);
53     }
54 
SetCurrentBlock(BlockNode & block)55     void SetCurrentBlock(BlockNode &block)
56     {
57         currBlock = █
58     }
59 
60     MIRFunction *currFunc = nullptr;
61     BlockNode *currBlock = nullptr;
62     MIRBuilderExt *builder = nullptr;
63     bool trace = false;
64     bool dump = false;
65 
66 private:
67     MIRModule *module = nullptr;
68 };
69 
70 class FuncOptimizeIterator : public MplScheduler {
71 public:
72     FuncOptimizeIterator(const std::string &phaseName, std::unique_ptr<FuncOptimizeImpl> phaseImpl);
73     virtual ~FuncOptimizeIterator();
74     virtual void Run(uint32 threadNum = 1, bool isSeq = false);
75 
76 protected:
77     thread_local static FuncOptimizeImpl *phaseImplLocal;
CallbackGetTaskRunParam()78     virtual MplTaskParam *CallbackGetTaskRunParam() const
79     {
80         return phaseImplLocal;
81     }
82 
CallbackGetTaskFinishParam()83     virtual MplTaskParam *CallbackGetTaskFinishParam() const
84     {
85         return phaseImplLocal;
86     }
87 
CallbackThreadMainEnd()88     virtual void CallbackThreadMainEnd()
89     {
90         delete phaseImplLocal;
91         phaseImplLocal = nullptr;
92     }
93 
94 private:
95     bool mplDumpTime = false;
96     std::unique_ptr<FuncOptimizeImpl> phaseImpl;
97     std::vector<std::unique_ptr<MplTask>> tasksUniquePtr;
98 };
99 }  // namespace maple
100 #endif  // MAPLE_PHASE_INCLUDE_PHASE_IMPL_H
101