• 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_INSTRUCTION_COMBINE_H
17 #define ECMASCRIPT_COMPILER_INSTRUCTION_COMBINE_H
18 
19 #include "ecmascript/compiler/circuit_builder.h"
20 #include "ecmascript/compiler/combined_pass_visitor.h"
21 #include "ecmascript/compiler/gate.h"
22 #include "ecmascript/compiler/gate_accessor.h"
23 #include "ecmascript/compiler/share_gate_meta_data.h"
24 #include "ecmascript/mem/chunk_containers.h"
25 
26 namespace panda::ecmascript::kungfu {
27 class InstructionCombine : public PassVisitor {
28 public:
29     InstructionCombine(Circuit *circuit, RPOVisitor *visitor, Chunk *chunk, bool enableLog = false)
PassVisitor(circuit,chunk,visitor)30         : PassVisitor(circuit, chunk, visitor), builder_(circuit), enableLog_(enableLog)
31     {
32     }
33 
34     ~InstructionCombine() = default;
35 
36     GateRef VisitGate(GateRef gate) override;
37 
38 private:
39     GateRef VisitADD(GateRef gate);
40     GateRef VisitSUB(GateRef gate);
41     GateRef VisitMUL(GateRef gate);
42     GateRef VisitSDIV(GateRef gate);
43     GateRef VisitFDIV(GateRef gate);
44     GateRef VisitSMOD(GateRef gate);
45     GateRef VisitAND(GateRef gate);
46     GateRef VisitOR(GateRef gate);
47     GateRef VisitXOR(GateRef gate);
48     GateRef VisitLSR(GateRef gate);
49     GateRef VisitASR(GateRef gate);
50     GateRef VisitLSL(GateRef gate);
51     GateRef VisitBranch(GateRef gate);
52     GateRef VisitICMP(GateRef gate);
53     GateRef VisitREV(GateRef gate);
54     GateRef VisitConvert(GateRef gate);
55     GateRef VisitExtractValue(GateRef gate);
56     GateRef ReduceWord32And(GateRef gate);
57     GateRef ReduceWord64And(GateRef gate);
58     GateRef ReduceWord32Or(GateRef gate);
59     GateRef ReduceWord64Or(GateRef gate);
60     GateRef ReduceWord32Xor(GateRef gate);
61     GateRef ReduceWord64Xor(GateRef gate);
62     GateRef ReduceWord32Lsr(GateRef gate);
63     GateRef ReduceWord64Lsr(GateRef gate);
64     GateRef ReduceWord32Asr(GateRef gate);
65     GateRef ReduceWord64Asr(GateRef gate);
66     GateRef ReduceWord32Lsl(GateRef gate);
67     GateRef ReduceWord64Lsl(GateRef gate);
68     GateRef ReduceInt32Add(GateRef gate);
69     GateRef ReduceInt64Add(GateRef gate);
70     GateRef ReduceInt32Sub(GateRef gate);
71     GateRef ReduceInt64Sub(GateRef gate);
72     GateRef ReduceInt32Mul(GateRef gate);
73     GateRef ReduceInt64Mul(GateRef gate);
74     GateRef ReduceInt32Div(GateRef gate);
75     GateRef ReduceInt64Div(GateRef gate);
76     GateRef ReduceDoubleAdd(GateRef gate);
77     GateRef ReduceDoubleSub(GateRef gate);
78     GateRef ReduceDoubleMul(GateRef gate);
79     GateRef ReduceDoubleDiv(GateRef gate);
80     GateRef ReduceInt32Mod(GateRef gate);
81     GateRef ReduceDoubleMod(GateRef gate);
82 
83     GateRef ReplaceOld(GateRef gate, GateRef newGate);
84     CircuitBuilder builder_;
85     bool enableLog_ = false;
86 };
87 } // namespace panda::ecmascript::kungfu
88 #endif // ECMASCRIPT_COMPILER_VALUE_NUMBERING_H