• 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 ECMASCRIPT_COMPILER_LATER_ELIMINATION_H
17 #define ECMASCRIPT_COMPILER_LATER_ELIMINATION_H
18 
19 #include "ecmascript/compiler/circuit_builder.h"
20 #include "ecmascript/compiler/gate_accessor.h"
21 #include "ecmascript/compiler/graph_visitor.h"
22 #include "ecmascript/compiler/base/depend_chain_helper.h"
23 #include "ecmascript/mem/chunk_containers.h"
24 
25 namespace panda::ecmascript::kungfu {
26 class DependChains;
27 class LaterElimination : public GraphVisitor {
28 public:
LaterElimination(Circuit * circuit,bool enableLog,const std::string & name,Chunk * chunk)29     LaterElimination(Circuit *circuit, bool enableLog, const std::string& name, Chunk* chunk)
30         : GraphVisitor(circuit, chunk), enableLog_(enableLog),
31         methodName_(name), dependChains_(chunk) {}
32 
33     ~LaterElimination() = default;
34 
35     void Run();
36 
37     GateRef VisitGate(GateRef gate) override;
38     bool CheckReplacement(GateRef lhs, GateRef rhs);
39 private:
IsLogEnabled()40     bool IsLogEnabled() const
41     {
42         return enableLog_;
43     }
44 
GetMethodName()45     const std::string& GetMethodName() const
46     {
47         return methodName_;
48     }
49 
GetDependChain(GateRef dependIn)50     DependChains* GetDependChain(GateRef dependIn)
51     {
52         size_t idx = acc_.GetId(dependIn);
53         ASSERT(idx <= circuit_->GetMaxGateId());
54         return dependChains_[idx];
55     }
56 
57     GateRef VisitDependEntry(GateRef gate);
58     GateRef UpdateDependChain(GateRef gate, DependChains* dependInfo);
59     GateRef TryEliminateGate(GateRef gate);
60     GateRef TryEliminateOther(GateRef gate);
61     GateRef TryEliminateDependSelector(GateRef gate);
62 
63     bool enableLog_ {false};
64     std::string methodName_;
65     ChunkVector<DependChains*> dependChains_;
66 };
67 }  // panda::ecmascript::kungfu
68 #endif  // ECMASCRIPT_COMPILER_LATER_ELIMINATION_H