• 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 BYTECODE_OPTIMIZER_REG_ACC_ALLOC_H
17 #define BYTECODE_OPTIMIZER_REG_ACC_ALLOC_H
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/pass.h"
21 #include "compiler_options.h"
22 
23 namespace panda::bytecodeopt {
24 
25 class RegAccAlloc : public compiler::Optimization {
26     using Optimization::Optimization;
27 
28 public:
RegAccAlloc(compiler::Graph * graph)29     explicit RegAccAlloc(compiler::Graph *graph) : compiler::Optimization(graph), acc_marker_(graph->NewMarker()) {};
30 
31     ~RegAccAlloc() override = default;
32 
IsEnable()33     bool IsEnable() const override
34     {
35         return compiler::options.IsCompilerRegAccAlloc();
36     }
37 
GetPassName()38     const char *GetPassName() const override
39     {
40         return "RegAccAlloc";
41     }
42 
43     bool RunImpl() override;
44 
45 private:
46     bool IsPhiOptimizable(compiler::Inst *phi) const;
47     bool IsAccRead(compiler::Inst *inst) const;
48     bool IsAccWrite(compiler::Inst *inst) const;
49 
50     bool CanUserReadAcc(compiler::Inst *inst, compiler::Inst *user) const;
51     bool IsPhiAccReady(compiler::Inst *phi) const;
52     void SetNeedLda(compiler::Inst *inst, bool need);
53 
54     compiler::Marker acc_marker_ {0};
55 };
56 
57 }  // namespace panda::bytecodeopt
58 
59 #endif  // BYTECODE_OPTIMIZER_REG_ACC_ALLOC_H
60