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 #include "ecmascript/compiler/gate.h"
17 #include "ecmascript/compiler/mcr_gate_meta_data.h"
18 #include "ecmascript/compiler/gate_meta_data_builder.h"
19
20 namespace panda::ecmascript::kungfu {
21
GetRevCompareOp(TypedBinOp op)22 TypedBinOp TypedBinaryMetaData::GetRevCompareOp(TypedBinOp op)
23 {
24 switch (op) {
25 case TypedBinOp::TYPED_LESS:
26 return TypedBinOp::TYPED_GREATEREQ;
27 case TypedBinOp::TYPED_LESSEQ:
28 return TypedBinOp::TYPED_GREATER;
29 case TypedBinOp::TYPED_GREATER:
30 return TypedBinOp::TYPED_LESSEQ;
31 case TypedBinOp::TYPED_GREATEREQ:
32 return TypedBinOp::TYPED_LESS;
33 case TypedBinOp::TYPED_EQ:
34 return TypedBinOp::TYPED_NOTEQ;
35 case TypedBinOp::TYPED_NOTEQ:
36 return TypedBinOp::TYPED_EQ;
37 default:
38 UNREACHABLE();
39 return op;
40 }
41 }
42
GetSwapCompareOp(TypedBinOp op)43 TypedBinOp TypedBinaryMetaData::GetSwapCompareOp(TypedBinOp op)
44 {
45 switch (op) {
46 case TypedBinOp::TYPED_LESS:
47 return TypedBinOp::TYPED_GREATER;
48 case TypedBinOp::TYPED_LESSEQ:
49 return TypedBinOp::TYPED_GREATEREQ;
50 case TypedBinOp::TYPED_GREATER:
51 return TypedBinOp::TYPED_LESS;
52 case TypedBinOp::TYPED_GREATEREQ:
53 return TypedBinOp::TYPED_LESSEQ;
54 case TypedBinOp::TYPED_EQ:
55 return TypedBinOp::TYPED_EQ;
56 case TypedBinOp::TYPED_NOTEQ:
57 return TypedBinOp::TYPED_NOTEQ;
58 default:
59 UNREACHABLE();
60 return op;
61 }
62 }
63
IsTypedOperator() const64 bool GateMetaData::IsTypedOperator() const
65 {
66 return (opcode_ == OpCode::TYPED_BINARY_OP) || (opcode_ == OpCode::TYPE_CONVERT) ||
67 (opcode_ == OpCode::TYPED_UNARY_OP);
68 }
69
IsCheckWithTwoIns() const70 bool GateMetaData::IsCheckWithTwoIns() const
71 {
72 return (opcode_ == OpCode::OBJECT_TYPE_CHECK) ||
73 (opcode_ == OpCode::INDEX_CHECK) ||
74 (opcode_ == OpCode::TYPED_CALL_CHECK);
75 }
76
IsCheckWithOneIn() const77 bool GateMetaData::IsCheckWithOneIn() const
78 {
79 return (opcode_ == OpCode::PRIMITIVE_TYPE_CHECK) ||
80 (opcode_ == OpCode::HEAP_OBJECT_CHECK) ||
81 (opcode_ == OpCode::STABLE_ARRAY_CHECK) ||
82 (opcode_ == OpCode::TYPED_ARRAY_CHECK);
83 }
84
Str(TypedBinOp op)85 std::string GateMetaData::Str(TypedBinOp op)
86 {
87 const std::map<TypedBinOp, const char *> strMap = {
88 #define TYPED_BIN_OP_NAME_MAP(OP) { TypedBinOp::OP, #OP },
89 TYPED_BIN_OP_LIST(TYPED_BIN_OP_NAME_MAP)
90 #undef TYPED_BIN_OP_NAME_MAP
91 };
92 if (strMap.count(op) > 0) {
93 return strMap.at(op);
94 }
95 return "UNKNOW";
96 }
97
Str(TypedUnOp op)98 std::string GateMetaData::Str(TypedUnOp op)
99 {
100 const std::map<TypedUnOp, const char *> strMap = {
101 #define TYPED_UN_OP_NAME_MAP(OP) { TypedUnOp::OP, #OP },
102 TYPED_UN_OP_LIST(TYPED_UN_OP_NAME_MAP)
103 #undef TYPED_UN_OP_NAME_MAP
104 };
105 if (strMap.count(op) > 0) {
106 return strMap.at(op);
107 }
108 return "UNKNOW";
109 }
110
Str(TypedJumpOp op)111 std::string GateMetaData::Str(TypedJumpOp op)
112 {
113 const std::map<TypedJumpOp, const char *> strMap = {
114 #define TYPED_JUMP_OP_NAME_MAP(OP) { TypedJumpOp::OP, #OP },
115 TYPED_JUMP_OP_LIST(TYPED_JUMP_OP_NAME_MAP)
116 #undef TYPED_JUMP_OP_NAME_MAP
117 };
118 if (strMap.count(op) > 0) {
119 return strMap.at(op);
120 }
121 return "UNKNOW";
122 }
123
Str(TypedLoadOp op)124 std::string GateMetaData::Str(TypedLoadOp op)
125 {
126 const std::map<TypedLoadOp, const char *> strMap = {
127 #define TYPED_LOAD_OP_NAME_MAP(OP) { TypedLoadOp::OP, #OP },
128 TYPED_LOAD_OP_LIST(TYPED_LOAD_OP_NAME_MAP)
129 #undef TYPED_LOAD_OP_NAME_MAP
130 };
131 if (strMap.count(op) > 0) {
132 return strMap.at(op);
133 }
134 return "UNKNOW";
135 }
136
Str(TypedStoreOp op)137 std::string GateMetaData::Str(TypedStoreOp op)
138 {
139 const std::map<TypedStoreOp, const char *> strMap = {
140 #define TYPED_STORE_OP_NAME_MAP(OP) { TypedStoreOp::OP, #OP },
141 TYPED_STORE_OP_LIST(TYPED_STORE_OP_NAME_MAP)
142 #undef TYPED_STORE_OP_NAME_MAP
143 };
144 if (strMap.count(op) > 0) {
145 return strMap.at(op);
146 }
147 return "UNKNOW";
148 }
149
Str(TypedCallTargetCheckOp op)150 std::string GateMetaData::Str(TypedCallTargetCheckOp op)
151 {
152 const std::map<TypedCallTargetCheckOp, const char *> strMap = {
153 #define TYPED_CALL_TARGET_CHECK_OP_NAME_MAP(OP) { TypedCallTargetCheckOp::OP, #OP },
154 TYPED_CALL_TARGET_CHECK_OP_LIST(TYPED_CALL_TARGET_CHECK_OP_NAME_MAP)
155 #undef TYPED_CALL_TARGET_CHECK_OP_NAME_MAP
156 };
157 if (strMap.count(op) > 0) {
158 return strMap.at(op);
159 }
160 return "UNKNOW";
161 }
162
Str(ValueType type)163 std::string GateMetaData::Str(ValueType type)
164 {
165 const std::map<ValueType, const char *> strMap = {
166 #define VALUE_TYPE_NAME_MAP(TYPE) { ValueType::TYPE, #TYPE },
167 VALUE_TYPE_LIST(VALUE_TYPE_NAME_MAP)
168 #undef VALUE_TYPE_NAME_MAP
169 };
170 if (strMap.count(type) > 0) {
171 return strMap.at(type);
172 }
173 return "UNKNOW";
174 }
175 }