• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 COMPILER_OPTIMIZER_OPTIMIZATIONS_CODE_SINK_H_
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_CODE_SINK_H_
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/pass.h"
21 #include "compiler_options.h"
22 
23 namespace panda::compiler {
24 class CodeSink : public Optimization {
25     using Optimization::Optimization;
26 
27 public:
CodeSink(Graph * graph)28     explicit CodeSink(Graph *graph) : Optimization(graph) {};
29     NO_COPY_SEMANTIC(CodeSink);
30     NO_MOVE_SEMANTIC(CodeSink);
31     ~CodeSink() override = default;
32 
33     bool RunImpl() override;
34 
IsEnable()35     bool IsEnable() const override
36     {
37         return options.IsCompilerCodeSink();
38     }
39 
GetPassName()40     const char *GetPassName() const override
41     {
42         return "CodeSink";
43     }
44 
45     void InvalidateAnalyses() override;
46 
47 private:
48     bool ProcessBlock(BasicBlock *block);
49     BasicBlock *SinkInstruction(Inst *inst, InstVector *stores, bool barriered);
50     bool IsAcceptableTarget(Inst *inst, BasicBlock *candidate);
51 
52 private:
53     bool is_applied_ {false};
54 };
55 }  // namespace panda::compiler
56 
57 #endif  //  COMPILER_OPTIMIZER_OPTIMIZATIONS_CODE_SINK_H_
58