14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_MCR_GATE_META_DATA_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_MCR_GATE_META_DATA_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include <string> 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_ci#include "ecmascript/compiler/bytecodes.h" 224514f5e3Sopenharmony_ci#include "ecmascript/compiler/type.h" 234514f5e3Sopenharmony_ci#include "ecmascript/mem/chunk.h" 244514f5e3Sopenharmony_ci#include "ecmascript/mem/chunk_containers.h" 254514f5e3Sopenharmony_ci 264514f5e3Sopenharmony_ci#include "ecmascript/elements.h" 274514f5e3Sopenharmony_ci#include "ecmascript/pgo_profiler/types/pgo_profiler_type.h" 284514f5e3Sopenharmony_ci#include "libpandabase/macros.h" 294514f5e3Sopenharmony_ci 304514f5e3Sopenharmony_ci#include "ecmascript/compiler/share_gate_meta_data.h" 314514f5e3Sopenharmony_ci 324514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu { 334514f5e3Sopenharmony_ci 344514f5e3Sopenharmony_ci#define TYPED_BIN_OP_LIST(V) \ 354514f5e3Sopenharmony_ci V(TYPED_ADD) \ 364514f5e3Sopenharmony_ci V(TYPED_SUB) \ 374514f5e3Sopenharmony_ci V(TYPED_MUL) \ 384514f5e3Sopenharmony_ci V(TYPED_DIV) \ 394514f5e3Sopenharmony_ci V(TYPED_MOD) \ 404514f5e3Sopenharmony_ci V(TYPED_LESS) \ 414514f5e3Sopenharmony_ci V(TYPED_LESSEQ) \ 424514f5e3Sopenharmony_ci V(TYPED_GREATER) \ 434514f5e3Sopenharmony_ci V(TYPED_GREATEREQ) \ 444514f5e3Sopenharmony_ci V(TYPED_EQ) \ 454514f5e3Sopenharmony_ci V(TYPED_NOTEQ) \ 464514f5e3Sopenharmony_ci V(TYPED_STRICTEQ) \ 474514f5e3Sopenharmony_ci V(TYPED_STRICTNOTEQ) \ 484514f5e3Sopenharmony_ci V(TYPED_SHL) \ 494514f5e3Sopenharmony_ci V(TYPED_SHR) \ 504514f5e3Sopenharmony_ci V(TYPED_ASHR) \ 514514f5e3Sopenharmony_ci V(TYPED_AND) \ 524514f5e3Sopenharmony_ci V(TYPED_OR) \ 534514f5e3Sopenharmony_ci V(TYPED_XOR) \ 544514f5e3Sopenharmony_ci V(TYPED_EXP) 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ci#define TYPED_UN_OP_LIST(V) \ 574514f5e3Sopenharmony_ci V(TYPED_NEG) \ 584514f5e3Sopenharmony_ci V(TYPED_NOT) \ 594514f5e3Sopenharmony_ci V(TYPED_INC) \ 604514f5e3Sopenharmony_ci V(TYPED_DEC) \ 614514f5e3Sopenharmony_ci V(TYPED_ISFALSE) \ 624514f5e3Sopenharmony_ci V(TYPED_ISTRUE) 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_ci#define TYPED_JUMP_OP_LIST(V) \ 654514f5e3Sopenharmony_ci V(TYPED_JEQZ) \ 664514f5e3Sopenharmony_ci V(TYPED_JNEZ) 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ci#define TYPED_LOAD_OP_LIST(V) \ 694514f5e3Sopenharmony_ci V(ARRAY_LOAD_INT_ELEMENT) \ 704514f5e3Sopenharmony_ci V(ARRAY_LOAD_DOUBLE_ELEMENT) \ 714514f5e3Sopenharmony_ci V(ARRAY_LOAD_OBJECT_ELEMENT) \ 724514f5e3Sopenharmony_ci V(ARRAY_LOAD_TAGGED_ELEMENT) \ 734514f5e3Sopenharmony_ci V(ARRAY_LOAD_HOLE_TAGGED_ELEMENT) \ 744514f5e3Sopenharmony_ci V(ARRAY_LOAD_HOLE_INT_ELEMENT) \ 754514f5e3Sopenharmony_ci V(ARRAY_LOAD_HOLE_DOUBLE_ELEMENT) \ 764514f5e3Sopenharmony_ci V(INT8ARRAY_LOAD_ELEMENT) \ 774514f5e3Sopenharmony_ci V(UINT8ARRAY_LOAD_ELEMENT) \ 784514f5e3Sopenharmony_ci V(UINT8CLAMPEDARRAY_LOAD_ELEMENT) \ 794514f5e3Sopenharmony_ci V(INT16ARRAY_LOAD_ELEMENT) \ 804514f5e3Sopenharmony_ci V(UINT16ARRAY_LOAD_ELEMENT) \ 814514f5e3Sopenharmony_ci V(INT32ARRAY_LOAD_ELEMENT) \ 824514f5e3Sopenharmony_ci V(UINT32ARRAY_LOAD_ELEMENT) \ 834514f5e3Sopenharmony_ci V(FLOAT32ARRAY_LOAD_ELEMENT) \ 844514f5e3Sopenharmony_ci V(FLOAT64ARRAY_LOAD_ELEMENT) \ 854514f5e3Sopenharmony_ci V(STRING_LOAD_ELEMENT) 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_ci#define TYPED_STORE_OP_LIST(V) \ 884514f5e3Sopenharmony_ci V(ARRAY_STORE_ELEMENT) \ 894514f5e3Sopenharmony_ci V(ARRAY_STORE_INT_ELEMENT) \ 904514f5e3Sopenharmony_ci V(ARRAY_STORE_DOUBLE_ELEMENT) \ 914514f5e3Sopenharmony_ci V(INT8ARRAY_STORE_ELEMENT) \ 924514f5e3Sopenharmony_ci V(UINT8ARRAY_STORE_ELEMENT) \ 934514f5e3Sopenharmony_ci V(UINT8CLAMPEDARRAY_STORE_ELEMENT) \ 944514f5e3Sopenharmony_ci V(INT16ARRAY_STORE_ELEMENT) \ 954514f5e3Sopenharmony_ci V(UINT16ARRAY_STORE_ELEMENT) \ 964514f5e3Sopenharmony_ci V(INT32ARRAY_STORE_ELEMENT) \ 974514f5e3Sopenharmony_ci V(UINT32ARRAY_STORE_ELEMENT) \ 984514f5e3Sopenharmony_ci V(FLOAT32ARRAY_STORE_ELEMENT) \ 994514f5e3Sopenharmony_ci V(FLOAT64ARRAY_STORE_ELEMENT) 1004514f5e3Sopenharmony_ci 1014514f5e3Sopenharmony_ci#define TYPED_CALL_TARGET_CHECK_OP_LIST(V) \ 1024514f5e3Sopenharmony_ci V(JSCALL) \ 1034514f5e3Sopenharmony_ci V(JSCALL_FAST) \ 1044514f5e3Sopenharmony_ci V(JSCALLTHIS) \ 1054514f5e3Sopenharmony_ci V(JSCALLTHIS_FAST) \ 1064514f5e3Sopenharmony_ci V(JSCALLTHIS_NOGC) \ 1074514f5e3Sopenharmony_ci V(JSCALLTHIS_FAST_NOGC) \ 1084514f5e3Sopenharmony_ci V(JS_NEWOBJRANGE) 1094514f5e3Sopenharmony_ci 1104514f5e3Sopenharmony_cienum class TypedBinOp : uint8_t { 1114514f5e3Sopenharmony_ci#define DECLARE_TYPED_BIN_OP(OP) OP, 1124514f5e3Sopenharmony_ci TYPED_BIN_OP_LIST(DECLARE_TYPED_BIN_OP) 1134514f5e3Sopenharmony_ci#undef DECLARE_TYPED_BIN_OP 1144514f5e3Sopenharmony_ci}; 1154514f5e3Sopenharmony_ci 1164514f5e3Sopenharmony_cienum class TypedUnOp : uint8_t { 1174514f5e3Sopenharmony_ci#define DECLARE_TYPED_UN_OP(OP) OP, 1184514f5e3Sopenharmony_ci TYPED_UN_OP_LIST(DECLARE_TYPED_UN_OP) 1194514f5e3Sopenharmony_ci#undef DECLARE_TYPED_UN_OP 1204514f5e3Sopenharmony_ci}; 1214514f5e3Sopenharmony_ci 1224514f5e3Sopenharmony_cienum class TypedJumpOp : uint8_t { 1234514f5e3Sopenharmony_ci#define DECLARE_TYPED_JUMP_OP(OP) OP, 1244514f5e3Sopenharmony_ci TYPED_JUMP_OP_LIST(DECLARE_TYPED_JUMP_OP) 1254514f5e3Sopenharmony_ci#undef DECLARE_TYPED_JUMP_OP 1264514f5e3Sopenharmony_ci}; 1274514f5e3Sopenharmony_ci 1284514f5e3Sopenharmony_cienum class TypedLoadOp : uint8_t { 1294514f5e3Sopenharmony_ci#define DECLARE_TYPED_LOAD_OP(OP) OP, 1304514f5e3Sopenharmony_ci TYPED_LOAD_OP_LIST(DECLARE_TYPED_LOAD_OP) 1314514f5e3Sopenharmony_ci#undef DECLARE_TYPED_LOAD_OP 1324514f5e3Sopenharmony_ci TYPED_ARRAY_FIRST = INT8ARRAY_LOAD_ELEMENT, 1334514f5e3Sopenharmony_ci TYPED_ARRAY_LAST = FLOAT64ARRAY_LOAD_ELEMENT, 1344514f5e3Sopenharmony_ci}; 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_cienum class TypedStoreOp : uint8_t { 1374514f5e3Sopenharmony_ci#define DECLARE_TYPED_STORE_OP(OP) OP, 1384514f5e3Sopenharmony_ci TYPED_STORE_OP_LIST(DECLARE_TYPED_STORE_OP) 1394514f5e3Sopenharmony_ci#undef DECLARE_TYPED_STORE_OP 1404514f5e3Sopenharmony_ci TYPED_ARRAY_FIRST = INT8ARRAY_STORE_ELEMENT, 1414514f5e3Sopenharmony_ci TYPED_ARRAY_LAST = FLOAT64ARRAY_STORE_ELEMENT, 1424514f5e3Sopenharmony_ci}; 1434514f5e3Sopenharmony_ci 1444514f5e3Sopenharmony_cienum class TypedCallTargetCheckOp : uint8_t { 1454514f5e3Sopenharmony_ci#define DECLARE_TYPED_CALL_TARGET_CHECK_OP(OP) OP, 1464514f5e3Sopenharmony_ci TYPED_CALL_TARGET_CHECK_OP_LIST(DECLARE_TYPED_CALL_TARGET_CHECK_OP) 1474514f5e3Sopenharmony_ci#undef DECLARE_TYPED_CALL_TARGET_CHECK_OP 1484514f5e3Sopenharmony_ci}; 1494514f5e3Sopenharmony_ci 1504514f5e3Sopenharmony_cienum class BranchKind : uint8_t { 1514514f5e3Sopenharmony_ci NORMAL_BRANCH = 0, 1524514f5e3Sopenharmony_ci TRUE_BRANCH, 1534514f5e3Sopenharmony_ci FALSE_BRANCH, 1544514f5e3Sopenharmony_ci STRONG_TRUE_BRANCH, 1554514f5e3Sopenharmony_ci STRONG_FALSE_BRANCH, 1564514f5e3Sopenharmony_ci}; 1574514f5e3Sopenharmony_ci 1584514f5e3Sopenharmony_cienum class TypedOpKind : uint8_t { 1594514f5e3Sopenharmony_ci TYPED_BIN_OP, 1604514f5e3Sopenharmony_ci TYPED_CALL_TARGET_CHECK_OP, 1614514f5e3Sopenharmony_ci TYPED_UN_OP, 1624514f5e3Sopenharmony_ci TYPED_JUMP_OP, 1634514f5e3Sopenharmony_ci TYPED_STORE_OP, 1644514f5e3Sopenharmony_ci TYPED_LOAD_OP, 1654514f5e3Sopenharmony_ci}; 1664514f5e3Sopenharmony_ci 1674514f5e3Sopenharmony_cienum class MemoryType : uint8_t { 1684514f5e3Sopenharmony_ci ELEMENT_TYPE = 0, 1694514f5e3Sopenharmony_ci}; 1704514f5e3Sopenharmony_ci 1714514f5e3Sopenharmony_ciclass TypedCallMetaData : public OneParameterMetaData { 1724514f5e3Sopenharmony_cipublic: 1734514f5e3Sopenharmony_ci TypedCallMetaData(OpCode opcode, GateFlags flags, uint32_t statesIn, 1744514f5e3Sopenharmony_ci uint16_t dependsIn, uint32_t valuesIn, uint64_t value, bool noGC) 1754514f5e3Sopenharmony_ci : OneParameterMetaData(opcode, flags, statesIn, dependsIn, valuesIn, value), 1764514f5e3Sopenharmony_ci noGC_(noGC) 1774514f5e3Sopenharmony_ci { 1784514f5e3Sopenharmony_ci SetKind(GateMetaData::Kind::TYPED_CALL); 1794514f5e3Sopenharmony_ci } 1804514f5e3Sopenharmony_ci 1814514f5e3Sopenharmony_ci bool equal(const GateMetaData &other) const override 1824514f5e3Sopenharmony_ci { 1834514f5e3Sopenharmony_ci if (!OneParameterMetaData::equal(other)) { 1844514f5e3Sopenharmony_ci return false; 1854514f5e3Sopenharmony_ci } 1864514f5e3Sopenharmony_ci auto cast_other = static_cast<const TypedCallMetaData *>(&other); 1874514f5e3Sopenharmony_ci if (noGC_ == cast_other->noGC_) { 1884514f5e3Sopenharmony_ci return true; 1894514f5e3Sopenharmony_ci } 1904514f5e3Sopenharmony_ci return false; 1914514f5e3Sopenharmony_ci } 1924514f5e3Sopenharmony_ci 1934514f5e3Sopenharmony_ci static const TypedCallMetaData* Cast(const GateMetaData* meta) 1944514f5e3Sopenharmony_ci { 1954514f5e3Sopenharmony_ci meta->AssertKind(GateMetaData::Kind::TYPED_CALL); 1964514f5e3Sopenharmony_ci return static_cast<const TypedCallMetaData*>(meta); 1974514f5e3Sopenharmony_ci } 1984514f5e3Sopenharmony_ci 1994514f5e3Sopenharmony_ci bool IsNoGC() const 2004514f5e3Sopenharmony_ci { 2014514f5e3Sopenharmony_ci return noGC_; 2024514f5e3Sopenharmony_ci } 2034514f5e3Sopenharmony_ciprivate: 2044514f5e3Sopenharmony_ci bool noGC_; 2054514f5e3Sopenharmony_ci}; 2064514f5e3Sopenharmony_ci 2074514f5e3Sopenharmony_ciclass NewConstructMetaData : public OneParameterMetaData { 2084514f5e3Sopenharmony_cipublic: 2094514f5e3Sopenharmony_ci static constexpr int NEED_PUSH_ARGV_BIT_SIZE = 1; 2104514f5e3Sopenharmony_ci NewConstructMetaData(OpCode opcode, GateFlags flags, uint32_t statesIn, 2114514f5e3Sopenharmony_ci uint16_t dependsIn, uint32_t valuesIn, uint64_t value, bool needPushArgv) 2124514f5e3Sopenharmony_ci : OneParameterMetaData(opcode, flags, statesIn, dependsIn, valuesIn, value) 2134514f5e3Sopenharmony_ci { 2144514f5e3Sopenharmony_ci bitField_ = NeedPushArgvBit::Encode(needPushArgv); 2154514f5e3Sopenharmony_ci } 2164514f5e3Sopenharmony_ci 2174514f5e3Sopenharmony_ci static const NewConstructMetaData* Cast(const GateMetaData* meta) 2184514f5e3Sopenharmony_ci { 2194514f5e3Sopenharmony_ci meta->AssertKind(GateMetaData::Kind::CALL_NEW); 2204514f5e3Sopenharmony_ci return static_cast<const NewConstructMetaData*>(meta); 2214514f5e3Sopenharmony_ci } 2224514f5e3Sopenharmony_ci 2234514f5e3Sopenharmony_ci bool NeedPushArgv() const 2244514f5e3Sopenharmony_ci { 2254514f5e3Sopenharmony_ci return NeedPushArgvBit::Get(bitField_); 2264514f5e3Sopenharmony_ci } 2274514f5e3Sopenharmony_ci 2284514f5e3Sopenharmony_ci uint64_t GetValue() const 2294514f5e3Sopenharmony_ci { 2304514f5e3Sopenharmony_ci return bitField_; 2314514f5e3Sopenharmony_ci } 2324514f5e3Sopenharmony_ci 2334514f5e3Sopenharmony_ciprivate: 2344514f5e3Sopenharmony_ci using NeedPushArgvBit = panda::BitField<bool, 0, NEED_PUSH_ARGV_BIT_SIZE>; 2354514f5e3Sopenharmony_ci 2364514f5e3Sopenharmony_ci uint64_t bitField_; 2374514f5e3Sopenharmony_ci}; 2384514f5e3Sopenharmony_ci 2394514f5e3Sopenharmony_ciclass TypedUnaryAccessor { 2404514f5e3Sopenharmony_cipublic: 2414514f5e3Sopenharmony_ci // type bits shift 2424514f5e3Sopenharmony_ci static constexpr int OPRAND_TYPE_BITS = 32; 2434514f5e3Sopenharmony_ci explicit TypedUnaryAccessor(uint64_t value) : bitField_(value) {} 2444514f5e3Sopenharmony_ci 2454514f5e3Sopenharmony_ci ParamType GetParamType() const 2464514f5e3Sopenharmony_ci { 2474514f5e3Sopenharmony_ci return ParamType(TypedValueBits::Get(bitField_)); 2484514f5e3Sopenharmony_ci } 2494514f5e3Sopenharmony_ci 2504514f5e3Sopenharmony_ci TypedUnOp GetTypedUnOp() const 2514514f5e3Sopenharmony_ci { 2524514f5e3Sopenharmony_ci return TypedUnOpBits::Get(bitField_); 2534514f5e3Sopenharmony_ci } 2544514f5e3Sopenharmony_ci 2554514f5e3Sopenharmony_ci static uint64_t ToValue(ParamType paramType, TypedUnOp unaryOp) 2564514f5e3Sopenharmony_ci { 2574514f5e3Sopenharmony_ci return TypedValueBits::Encode(paramType.Value()) | TypedUnOpBits::Encode(unaryOp); 2584514f5e3Sopenharmony_ci } 2594514f5e3Sopenharmony_ci 2604514f5e3Sopenharmony_ciprivate: 2614514f5e3Sopenharmony_ci using TypedValueBits = panda::BitField<uint32_t, 0, OPRAND_TYPE_BITS>; 2624514f5e3Sopenharmony_ci using TypedUnOpBits = TypedValueBits::NextField<TypedUnOp, OPRAND_TYPE_BITS>; 2634514f5e3Sopenharmony_ci 2644514f5e3Sopenharmony_ci uint64_t bitField_; 2654514f5e3Sopenharmony_ci}; 2664514f5e3Sopenharmony_ci 2674514f5e3Sopenharmony_ciclass TypedBinaryAccessor { 2684514f5e3Sopenharmony_cipublic: 2694514f5e3Sopenharmony_ci // type bits shift 2704514f5e3Sopenharmony_ci static constexpr int OPRAND_TYPE_BITS = 32; 2714514f5e3Sopenharmony_ci explicit TypedBinaryAccessor(uint64_t value) : bitField_(value) {} 2724514f5e3Sopenharmony_ci 2734514f5e3Sopenharmony_ci ParamType GetParamType() const 2744514f5e3Sopenharmony_ci { 2754514f5e3Sopenharmony_ci return ParamType(TypedValueBits::Get(bitField_)); 2764514f5e3Sopenharmony_ci } 2774514f5e3Sopenharmony_ci 2784514f5e3Sopenharmony_ci TypedBinOp GetTypedBinOp() const 2794514f5e3Sopenharmony_ci { 2804514f5e3Sopenharmony_ci return TypedBinOpBits::Get(bitField_); 2814514f5e3Sopenharmony_ci } 2824514f5e3Sopenharmony_ci 2834514f5e3Sopenharmony_ci static uint64_t ToValue(ParamType operandType, TypedBinOp binOp) 2844514f5e3Sopenharmony_ci { 2854514f5e3Sopenharmony_ci return TypedValueBits::Encode(operandType.Value()) | TypedBinOpBits::Encode(binOp); 2864514f5e3Sopenharmony_ci } 2874514f5e3Sopenharmony_ci 2884514f5e3Sopenharmony_ciprivate: 2894514f5e3Sopenharmony_ci using TypedValueBits = panda::BitField<uint32_t, 0, OPRAND_TYPE_BITS>; 2904514f5e3Sopenharmony_ci using TypedBinOpBits = TypedValueBits::NextField<TypedBinOp, OPRAND_TYPE_BITS>; 2914514f5e3Sopenharmony_ci 2924514f5e3Sopenharmony_ci uint64_t bitField_; 2934514f5e3Sopenharmony_ci}; 2944514f5e3Sopenharmony_ci 2954514f5e3Sopenharmony_ciclass TypedCallTargetCheckAccessor { 2964514f5e3Sopenharmony_cipublic: 2974514f5e3Sopenharmony_ci // type bits shift 2984514f5e3Sopenharmony_ci static constexpr int CALLTARGETCHECK_OP_BITS = 32; 2994514f5e3Sopenharmony_ci explicit TypedCallTargetCheckAccessor(uint64_t value) : bitField_(value) {} 3004514f5e3Sopenharmony_ci 3014514f5e3Sopenharmony_ci TypedCallTargetCheckOp GetCallTargetCheckOp() const 3024514f5e3Sopenharmony_ci { 3034514f5e3Sopenharmony_ci return CallTargetCheckOpBits::Get(bitField_); 3044514f5e3Sopenharmony_ci } 3054514f5e3Sopenharmony_ci 3064514f5e3Sopenharmony_ci static uint64_t ToValue(TypedCallTargetCheckOp op) 3074514f5e3Sopenharmony_ci { 3084514f5e3Sopenharmony_ci return CallTargetCheckOpBits::Encode(op); 3094514f5e3Sopenharmony_ci } 3104514f5e3Sopenharmony_ci 3114514f5e3Sopenharmony_ciprivate: 3124514f5e3Sopenharmony_ci using CallTargetCheckOpBits = panda::BitField<TypedCallTargetCheckOp, 0, CALLTARGETCHECK_OP_BITS>; 3134514f5e3Sopenharmony_ci 3144514f5e3Sopenharmony_ci uint64_t bitField_; 3154514f5e3Sopenharmony_ci}; 3164514f5e3Sopenharmony_ci 3174514f5e3Sopenharmony_ciclass BranchAccessor { 3184514f5e3Sopenharmony_cipublic: 3194514f5e3Sopenharmony_ci // type bits shift 3204514f5e3Sopenharmony_ci static constexpr int OPRAND_TYPE_BITS = 32; 3214514f5e3Sopenharmony_ci explicit BranchAccessor(uint64_t value) : bitField_(value) {} 3224514f5e3Sopenharmony_ci 3234514f5e3Sopenharmony_ci int32_t GetTrueWeight() const 3244514f5e3Sopenharmony_ci { 3254514f5e3Sopenharmony_ci return TrueWeightBits::Get(bitField_); 3264514f5e3Sopenharmony_ci } 3274514f5e3Sopenharmony_ci 3284514f5e3Sopenharmony_ci int32_t GetFalseWeight() const 3294514f5e3Sopenharmony_ci { 3304514f5e3Sopenharmony_ci return FalseWeightBits::Get(bitField_); 3314514f5e3Sopenharmony_ci } 3324514f5e3Sopenharmony_ci 3334514f5e3Sopenharmony_ci static uint64_t ToValue(uint32_t trueWeight, uint32_t falseWeight) 3344514f5e3Sopenharmony_ci { 3354514f5e3Sopenharmony_ci return TrueWeightBits::Encode(trueWeight) 3364514f5e3Sopenharmony_ci | FalseWeightBits::Encode(falseWeight); 3374514f5e3Sopenharmony_ci } 3384514f5e3Sopenharmony_ciprivate: 3394514f5e3Sopenharmony_ci using TrueWeightBits = panda::BitField<uint32_t, 0, OPRAND_TYPE_BITS>; 3404514f5e3Sopenharmony_ci using FalseWeightBits = TrueWeightBits::NextField<uint32_t, OPRAND_TYPE_BITS>; 3414514f5e3Sopenharmony_ci 3424514f5e3Sopenharmony_ci uint64_t bitField_; 3434514f5e3Sopenharmony_ci}; 3444514f5e3Sopenharmony_ci 3454514f5e3Sopenharmony_ciclass MemoryAttribute { 3464514f5e3Sopenharmony_cipublic: 3474514f5e3Sopenharmony_ci MemoryAttribute() = default; 3484514f5e3Sopenharmony_ci ~MemoryAttribute() = default; 3494514f5e3Sopenharmony_ci explicit MemoryAttribute(uint32_t v) : value_(v) {} 3504514f5e3Sopenharmony_ci 3514514f5e3Sopenharmony_ci enum Order { 3524514f5e3Sopenharmony_ci NOT_ATOMIC = 0, 3534514f5e3Sopenharmony_ci MEMORY_ORDER_RELEASE 3544514f5e3Sopenharmony_ci }; 3554514f5e3Sopenharmony_ci 3564514f5e3Sopenharmony_ci enum Barrier { 3574514f5e3Sopenharmony_ci NEED_BARRIER = 0, 3584514f5e3Sopenharmony_ci NO_BARRIER, 3594514f5e3Sopenharmony_ci UNKNOWN_BARRIER 3604514f5e3Sopenharmony_ci }; 3614514f5e3Sopenharmony_ci 3624514f5e3Sopenharmony_ci enum ShareFlag { 3634514f5e3Sopenharmony_ci UNKNOWN = 0, 3644514f5e3Sopenharmony_ci NON_SHARE, 3654514f5e3Sopenharmony_ci SHARED 3664514f5e3Sopenharmony_ci }; 3674514f5e3Sopenharmony_ci 3684514f5e3Sopenharmony_ci static MemoryAttribute Default() 3694514f5e3Sopenharmony_ci { 3704514f5e3Sopenharmony_ci return Create(NOT_ATOMIC); 3714514f5e3Sopenharmony_ci } 3724514f5e3Sopenharmony_ci 3734514f5e3Sopenharmony_ci static MemoryAttribute NeedBarrier() 3744514f5e3Sopenharmony_ci { 3754514f5e3Sopenharmony_ci return Create(NOT_ATOMIC, NEED_BARRIER); 3764514f5e3Sopenharmony_ci } 3774514f5e3Sopenharmony_ci 3784514f5e3Sopenharmony_ci static MemoryAttribute UnknownBarrier() 3794514f5e3Sopenharmony_ci { 3804514f5e3Sopenharmony_ci return Create(NOT_ATOMIC, UNKNOWN_BARRIER); 3814514f5e3Sopenharmony_ci } 3824514f5e3Sopenharmony_ci 3834514f5e3Sopenharmony_ci static MemoryAttribute DefaultWithShareBarrier() 3844514f5e3Sopenharmony_ci { 3854514f5e3Sopenharmony_ci return Create(NOT_ATOMIC, UNKNOWN_BARRIER, SHARED); 3864514f5e3Sopenharmony_ci } 3874514f5e3Sopenharmony_ci 3884514f5e3Sopenharmony_ci static MemoryAttribute NeedNotShareBarrier() 3894514f5e3Sopenharmony_ci { 3904514f5e3Sopenharmony_ci return Create(NOT_ATOMIC, NEED_BARRIER, NON_SHARE); 3914514f5e3Sopenharmony_ci } 3924514f5e3Sopenharmony_ci 3934514f5e3Sopenharmony_ci static MemoryAttribute NeedBarrierAndAtomic() 3944514f5e3Sopenharmony_ci { 3954514f5e3Sopenharmony_ci return Create(MEMORY_ORDER_RELEASE, NEED_BARRIER); 3964514f5e3Sopenharmony_ci } 3974514f5e3Sopenharmony_ci 3984514f5e3Sopenharmony_ci static MemoryAttribute NoBarrier() 3994514f5e3Sopenharmony_ci { 4004514f5e3Sopenharmony_ci return Create(NOT_ATOMIC, NO_BARRIER); 4014514f5e3Sopenharmony_ci } 4024514f5e3Sopenharmony_ci 4034514f5e3Sopenharmony_ci void SetBarrier(Barrier barrier) 4044514f5e3Sopenharmony_ci { 4054514f5e3Sopenharmony_ci BarrierField::Set<uint32_t>(barrier, &value_); 4064514f5e3Sopenharmony_ci } 4074514f5e3Sopenharmony_ci 4084514f5e3Sopenharmony_ci Barrier GetBarrier() const 4094514f5e3Sopenharmony_ci { 4104514f5e3Sopenharmony_ci return BarrierField::Get(value_); 4114514f5e3Sopenharmony_ci } 4124514f5e3Sopenharmony_ci 4134514f5e3Sopenharmony_ci void SetShare(ShareFlag share) 4144514f5e3Sopenharmony_ci { 4154514f5e3Sopenharmony_ci ShareField::Set<uint32_t>(share, &value_); 4164514f5e3Sopenharmony_ci } 4174514f5e3Sopenharmony_ci 4184514f5e3Sopenharmony_ci ShareFlag GetShare() const 4194514f5e3Sopenharmony_ci { 4204514f5e3Sopenharmony_ci return ShareField::Get(value_); 4214514f5e3Sopenharmony_ci } 4224514f5e3Sopenharmony_ci 4234514f5e3Sopenharmony_ci void SetOrder(Order order) 4244514f5e3Sopenharmony_ci { 4254514f5e3Sopenharmony_ci OrderField::Set<uint32_t>(order, &value_); 4264514f5e3Sopenharmony_ci } 4274514f5e3Sopenharmony_ci 4284514f5e3Sopenharmony_ci Order GetOrder() const 4294514f5e3Sopenharmony_ci { 4304514f5e3Sopenharmony_ci return OrderField::Get(value_); 4314514f5e3Sopenharmony_ci } 4324514f5e3Sopenharmony_ci 4334514f5e3Sopenharmony_ci uint32_t Value() const 4344514f5e3Sopenharmony_ci { 4354514f5e3Sopenharmony_ci return value_; 4364514f5e3Sopenharmony_ci } 4374514f5e3Sopenharmony_ci 4384514f5e3Sopenharmony_ciprivate: 4394514f5e3Sopenharmony_ci static MemoryAttribute Create(Order order, Barrier barrier = UNKNOWN_BARRIER, ShareFlag share = UNKNOWN) 4404514f5e3Sopenharmony_ci { 4414514f5e3Sopenharmony_ci uint32_t value = OrderField::Encode(order) | BarrierField::Encode(barrier) | ShareField::Encode(share); 4424514f5e3Sopenharmony_ci return MemoryAttribute(value); 4434514f5e3Sopenharmony_ci } 4444514f5e3Sopenharmony_ci 4454514f5e3Sopenharmony_ci static constexpr uint32_t ORDER_BITS = 8; 4464514f5e3Sopenharmony_ci static constexpr uint32_t BARRIER_BITS = 8; 4474514f5e3Sopenharmony_ci static constexpr uint32_t SHARE_BITS = 8; 4484514f5e3Sopenharmony_ci using OrderField = panda::BitField<Order, 0, ORDER_BITS>; 4494514f5e3Sopenharmony_ci using BarrierField = OrderField::NextField<Barrier, BARRIER_BITS>; 4504514f5e3Sopenharmony_ci using ShareField = BarrierField::NextField<ShareFlag, SHARE_BITS>; 4514514f5e3Sopenharmony_ci 4524514f5e3Sopenharmony_ci uint32_t value_; 4534514f5e3Sopenharmony_ci}; 4544514f5e3Sopenharmony_ci 4554514f5e3Sopenharmony_ciclass LoadStoreAccessor { 4564514f5e3Sopenharmony_cipublic: 4574514f5e3Sopenharmony_ci static constexpr int MEMORY_ORDER_BITS = 32; 4584514f5e3Sopenharmony_ci explicit LoadStoreAccessor(uint64_t value) : bitField_(value) {} 4594514f5e3Sopenharmony_ci 4604514f5e3Sopenharmony_ci MemoryAttribute GetMemoryAttribute() const 4614514f5e3Sopenharmony_ci { 4624514f5e3Sopenharmony_ci return MemoryAttribute(MemoryAttributeBits::Get(bitField_)); 4634514f5e3Sopenharmony_ci } 4644514f5e3Sopenharmony_ci 4654514f5e3Sopenharmony_ci static uint64_t ToValue(MemoryAttribute mAttr) 4664514f5e3Sopenharmony_ci { 4674514f5e3Sopenharmony_ci return MemoryAttributeBits::Encode(mAttr.Value()); 4684514f5e3Sopenharmony_ci } 4694514f5e3Sopenharmony_ciprivate: 4704514f5e3Sopenharmony_ci using MemoryAttributeBits = panda::BitField<uint32_t, 0, MEMORY_ORDER_BITS>; 4714514f5e3Sopenharmony_ci 4724514f5e3Sopenharmony_ci uint64_t bitField_; 4734514f5e3Sopenharmony_ci}; 4744514f5e3Sopenharmony_ci 4754514f5e3Sopenharmony_ciclass LoadStoreConstOffsetAccessor { 4764514f5e3Sopenharmony_cipublic: 4774514f5e3Sopenharmony_ci static constexpr int OPRAND_OFFSET_BITS = 32; 4784514f5e3Sopenharmony_ci static constexpr int MEMORY_ATTRIBUTE_BITS = 32; 4794514f5e3Sopenharmony_ci explicit LoadStoreConstOffsetAccessor(uint64_t value) : bitField_(value) {} 4804514f5e3Sopenharmony_ci 4814514f5e3Sopenharmony_ci MemoryAttribute GetMemoryAttribute() const 4824514f5e3Sopenharmony_ci { 4834514f5e3Sopenharmony_ci return MemoryAttribute(MemoryAttributeBits::Get(bitField_)); 4844514f5e3Sopenharmony_ci } 4854514f5e3Sopenharmony_ci 4864514f5e3Sopenharmony_ci size_t GetOffset() const 4874514f5e3Sopenharmony_ci { 4884514f5e3Sopenharmony_ci return static_cast<size_t>(OprandOffsetBits::Get(bitField_)); 4894514f5e3Sopenharmony_ci } 4904514f5e3Sopenharmony_ci 4914514f5e3Sopenharmony_ci static uint64_t ToValue(size_t offset, MemoryAttribute mAttr) 4924514f5e3Sopenharmony_ci { 4934514f5e3Sopenharmony_ci return OprandOffsetBits::Encode(static_cast<uint32_t>(offset)) | 4944514f5e3Sopenharmony_ci MemoryAttributeBits::Encode(mAttr.Value()); 4954514f5e3Sopenharmony_ci } 4964514f5e3Sopenharmony_ciprivate: 4974514f5e3Sopenharmony_ci using OprandOffsetBits = panda::BitField<uint32_t, 0, OPRAND_OFFSET_BITS>; 4984514f5e3Sopenharmony_ci using MemoryAttributeBits = OprandOffsetBits::NextField<uint32_t, MEMORY_ATTRIBUTE_BITS>; 4994514f5e3Sopenharmony_ci 5004514f5e3Sopenharmony_ci uint64_t bitField_; 5014514f5e3Sopenharmony_ci}; 5024514f5e3Sopenharmony_ci 5034514f5e3Sopenharmony_ciclass TypedJumpAccessor { 5044514f5e3Sopenharmony_cipublic: 5054514f5e3Sopenharmony_ci // type bits shift 5064514f5e3Sopenharmony_ci static constexpr int OPRAND_TYPE_BITS = 32; 5074514f5e3Sopenharmony_ci static constexpr int JUMP_OP_BITS = 8; 5084514f5e3Sopenharmony_ci explicit TypedJumpAccessor(uint64_t value) : bitField_(value) {} 5094514f5e3Sopenharmony_ci 5104514f5e3Sopenharmony_ci ParamType GetParamType() const 5114514f5e3Sopenharmony_ci { 5124514f5e3Sopenharmony_ci return ParamType(TypedValueBits::Get(bitField_)); 5134514f5e3Sopenharmony_ci } 5144514f5e3Sopenharmony_ci 5154514f5e3Sopenharmony_ci TypedJumpOp GetTypedJumpOp() const 5164514f5e3Sopenharmony_ci { 5174514f5e3Sopenharmony_ci return TypedJumpOpBits::Get(bitField_); 5184514f5e3Sopenharmony_ci } 5194514f5e3Sopenharmony_ci 5204514f5e3Sopenharmony_ci uint32_t GetTrueWeight() const 5214514f5e3Sopenharmony_ci { 5224514f5e3Sopenharmony_ci return TrueWeightBits::Get(bitField_); 5234514f5e3Sopenharmony_ci } 5244514f5e3Sopenharmony_ci 5254514f5e3Sopenharmony_ci uint32_t GetFalseWeight() const 5264514f5e3Sopenharmony_ci { 5274514f5e3Sopenharmony_ci return FalseWeightBits::Get(bitField_); 5284514f5e3Sopenharmony_ci } 5294514f5e3Sopenharmony_ci 5304514f5e3Sopenharmony_ci static uint64_t ToValue(ParamType paramType, TypedJumpOp jumpOp, uint32_t weight) 5314514f5e3Sopenharmony_ci { 5324514f5e3Sopenharmony_ci return TypedValueBits::Encode(paramType.Value()) 5334514f5e3Sopenharmony_ci | TypedJumpOpBits::Encode(jumpOp) 5344514f5e3Sopenharmony_ci | WeightBits::Encode(weight); 5354514f5e3Sopenharmony_ci } 5364514f5e3Sopenharmony_ci 5374514f5e3Sopenharmony_ciprivate: 5384514f5e3Sopenharmony_ci using TypedValueBits = panda::BitField<uint32_t, 0, OPRAND_TYPE_BITS>; 5394514f5e3Sopenharmony_ci using TypedJumpOpBits = TypedValueBits::NextField<TypedJumpOp, JUMP_OP_BITS>; 5404514f5e3Sopenharmony_ci using WeightBits = TypedJumpOpBits::NextField<uint32_t, PGOSampleType::WEIGHT_BITS + PGOSampleType::WEIGHT_BITS>; 5414514f5e3Sopenharmony_ci using FalseWeightBits = TypedJumpOpBits::NextField<uint32_t, PGOSampleType::WEIGHT_BITS>; 5424514f5e3Sopenharmony_ci using TrueWeightBits = FalseWeightBits::NextField<uint32_t, PGOSampleType::WEIGHT_BITS>; 5434514f5e3Sopenharmony_ci 5444514f5e3Sopenharmony_ci uint64_t bitField_; 5454514f5e3Sopenharmony_ci}; 5464514f5e3Sopenharmony_ci 5474514f5e3Sopenharmony_ci} 5484514f5e3Sopenharmony_ci 5494514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_MCR_GATE_META_DATA_H 550