• 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_IR_BUILDER_H
17 #define ECMASCRIPT_COMPILER_IR_BUILDER_H
18 
19 #include <set>
20 
21 #include "ecmascript/compiler/lcr_gate_meta_data.h"
22 
23 namespace panda::ecmascript::kungfu {
24 using OperandsVector = std::set<int>;
25 enum class MachineRep {
26     K_NONE,
27     K_BIT,
28     K_WORD8,
29     K_WORD16,
30     K_WORD32,
31     K_WORD64,
32     // FP representations must be last, and in order of increasing size.
33     K_FLOAT32,
34     K_FLOAT64,
35     K_SIMD128,
36     K_PTR_1, // Tagged Pointer
37     K_META,
38 };
39 
40 enum class CallInputs : size_t {
41     DEPEND = 0,
42     TARGET,
43     GLUE,
44     FIRST_PARAMETER
45 };
46 
47 enum class CallInfoKind : bool {
48     HAS_FRAME_STATE = true,
49     NO_FRAME_STATE = false
50 };
51 
52 #define OPCODES(V)                                                                        \
53     V(Call, (GateRef gate, const std::vector<GateRef> &inList, OpCode op))                \
54     V(RuntimeCall, (GateRef gate, const std::vector<GateRef> &inList))                    \
55     V(RuntimeCallWithArgv, (GateRef gate, const std::vector<GateRef> &inList))            \
56     V(ASMCallBarrier, (GateRef gate, const std::vector<GateRef> &inList))                 \
57     V(NoGcRuntimeCall, (GateRef gate, const std::vector<GateRef> &inList))                \
58     V(BytecodeCall, (GateRef gate, const std::vector<GateRef> &inList))                   \
59     V(Alloca, (GateRef gate))                                                             \
60     V(Block, (int id, const OperandsVector &predecessors))                                \
61     V(Goto, (int block, int bbout))                                                       \
62     V(Parameter, (GateRef gate))                                                          \
63     V(Constant, (GateRef gate, std::bitset<64> value))                                    \
64     V(ConstString, (GateRef gate, const ChunkVector<char> &str))                          \
65     V(RelocatableData, (GateRef gate, uint64_t value))                                    \
66     V(ZExtInt, (GateRef gate, GateRef e1))                                                \
67     V(SExtInt, (GateRef gate, GateRef e1))                                                \
68     V(FPExt, (GateRef gate, GateRef e1))                                                  \
69     V(FPTrunc, (GateRef gate, GateRef e1))                                                \
70     V(Load, (GateRef gate, GateRef base))                                                 \
71     V(Store, (GateRef gate, GateRef base, GateRef value))                                 \
72     V(IntRev, (GateRef gate, GateRef e1))                                                 \
73     V(Add, (GateRef gate, GateRef e1, GateRef e2))                                        \
74     V(Sub, (GateRef gate, GateRef e1, GateRef e2))                                        \
75     V(Mul, (GateRef gate, GateRef e1, GateRef e2))                                        \
76     V(FloatDiv, (GateRef gate, GateRef e1, GateRef e2))                                   \
77     V(IntDiv, (GateRef gate, GateRef e1, GateRef e2))                                     \
78     V(UDiv, (GateRef gate, GateRef e1, GateRef e2))                                       \
79     V(IntOr, (GateRef gate, GateRef e1, GateRef e2))                                      \
80     V(IntAnd, (GateRef gate, GateRef e1, GateRef e2))                                     \
81     V(IntXor, (GateRef gate, GateRef e1, GateRef e2))                                     \
82     V(IntLsr, (GateRef gate, GateRef e1, GateRef e2))                                     \
83     V(IntAsr, (GateRef gate, GateRef e1, GateRef e2))                                     \
84     V(Int32LessThanOrEqual, (GateRef gate, GateRef e1, GateRef e2))                       \
85     V(Cmp, (GateRef gate, GateRef e1, GateRef e2))                                        \
86     V(Branch, (GateRef gate, GateRef cmp, GateRef btrue, GateRef bfalse))                 \
87     V(Switch, (GateRef gate, GateRef input, const std::vector<GateRef> &outList))         \
88     V(SwitchCase, (GateRef gate, GateRef switchBranch, GateRef out))                      \
89     V(Phi, (GateRef gate, const std::vector<GateRef> &srcGates))                          \
90     V(Return, (GateRef gate, GateRef popCount, const std::vector<GateRef> &operands))     \
91     V(ReturnVoid, (GateRef gate))                                                         \
92     V(CastIntXToIntY, (GateRef gate, GateRef e1))                                         \
93     V(ChangeInt32ToDouble, (GateRef gate, GateRef e1))                                    \
94     V(ChangeUInt32ToDouble, (GateRef gate, GateRef e1))                                   \
95     V(ChangeDoubleToInt32, (GateRef gate, GateRef e1))                                    \
96     V(BitCast, (GateRef gate, GateRef e1))                                                \
97     V(IntLsl, (GateRef gate, GateRef e1, GateRef e2))                                     \
98     V(Mod, (GateRef gate, GateRef e1, GateRef e2))                                        \
99     V(ChangeTaggedPointerToInt64, (GateRef gate, GateRef e1))                             \
100     V(ChangeInt64ToTagged, (GateRef gate, GateRef e1))                                    \
101     V(DeoptCheck, (GateRef gate))                                                         \
102     V(HeapConstant, (GateRef gate, GateRef heapConstant))                                 \
103     V(TruncFloatToInt, (GateRef gate, GateRef e1))                                        \
104     V(AddWithOverflow, (GateRef gate, GateRef e1, GateRef e2))                            \
105     V(SubWithOverflow, (GateRef gate, GateRef e1, GateRef e2))                            \
106     V(MulWithOverflow, (GateRef gate, GateRef e1, GateRef e2))                            \
107     V(ExtractValue, (GateRef gate, GateRef e1, GateRef e2))                               \
108     V(Sqrt, (GateRef gate, GateRef e1))                                                   \
109     V(Exp, (GateRef gate, GateRef e1, GateRef e2))                                        \
110     V(Abs, (GateRef gate, GateRef e1))                                                    \
111     V(Min, (GateRef gate, GateRef e1, GateRef e2))                                        \
112     V(Max, (GateRef gate, GateRef e1, GateRef e2))                                        \
113     V(Clz32, (GateRef gate, GateRef e1))                                                  \
114     V(DoubleTrunc, (GateRef gate, GateRef e1))                                            \
115     V(Ceil, (GateRef gate, GateRef e1))                                                   \
116     V(Floor, (GateRef gate, GateRef e1))                                                  \
117     V(ReadSp, (GateRef gate))                                                             \
118     V(InitVreg, (GateRef gate))                                                           \
119     V(BitRev, (GateRef gate, GateRef e1))                                                 \
120     V(FinishAllocate, (GateRef gate, GateRef e1))                                         \
121     V(TaggedIsHeapObjectIntrinsic, (GateRef gate))                                        \
122     V(IsStableElementsIntrinsic, (GateRef gate))                                          \
123     V(HasPendingExceptionIntrinsic, (GateRef gate))                                       \
124     V(CheckObjectIsStringIntrinsic, (GateRef gate, GateRef e1, GateRef e2))               \
125     V(IsJsCOWArrayIntrinsic, (GateRef gate, GateRef e1, GateRef e2))                      \
126     V(FetchOr, (GateRef gate, GateRef e1, GateRef e2))
127 
128 bool IsAddIntergerType(MachineType machineType);
129 bool IsMulIntergerType(MachineType machineType);
130 }  // namespace panda::ecmascript::kungfu
131 #endif  // ECMASCRIPT_COMPILER_IR_BUILDER_H
132