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