1 /** 2 * Copyright (c) 2021-2022 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 PANDA_CODE_INFO_TABLES_H 17 #define PANDA_CODE_INFO_TABLES_H 18 19 #include "utils/bit_field.h" 20 #include "utils/bit_table.h" 21 #include "utils/arch.h" 22 #include "vreg_info.h" 23 24 namespace panda::compiler { 25 26 class StackMap : public BitTableRow<8U, StackMap> { 27 public: 28 BIT_TABLE_HEADER(8, StackMap) 29 BIT_TABLE_COLUMN(0, Properties, PROPERTIES) 30 BIT_TABLE_COLUMN(1, NativePc, NATIVE_PC) 31 BIT_TABLE_COLUMN(2, BytecodePc, BYTECODE_PC) 32 BIT_TABLE_COLUMN(3, RootsRegMaskIndex, ROOTS_REG_MASK_INDEX) 33 BIT_TABLE_COLUMN(4, RootsStackMaskIndex, ROOTS_STACK_MASK_INDEX) 34 BIT_TABLE_COLUMN(5, InlineInfoIndex, INLINE_INFO_INDEX) 35 BIT_TABLE_COLUMN(6, VRegMaskIndex, VREG_MASK_INDEX) 36 BIT_TABLE_COLUMN(7, VRegMapIndex, VREG_MAP_INDEX) 37 38 DEFAULT_MOVE_SEMANTIC(StackMap); 39 DEFAULT_COPY_SEMANTIC(StackMap); 40 ~StackMap() = default; 41 GetColumnStr(size_t column)42 std::string GetColumnStr(size_t column) const 43 { 44 if (column != COLUMN_NATIVE_PC) { 45 return Base::GetColumnStr(column); 46 } 47 if (Get(column) == NO_VALUE) { 48 return "-"; 49 } 50 return std::to_string(GetNativePcUnpacked()); 51 } 52 PackAddress(uintptr_t address,Arch arch)53 static constexpr uintptr_t PackAddress(uintptr_t address, Arch arch) 54 { 55 ASSERT(IsAligned(address, GetInstructionAlignment(arch))); 56 return address / GetInstructionAlignment(arch); 57 } 58 59 uint32_t GetNativePcUnpacked(Arch arch = RUNTIME_ARCH) const 60 { 61 return UnpackAddress(GetNativePc(), arch); 62 } 63 UnpackAddress(uintptr_t address,Arch arch)64 static constexpr uintptr_t UnpackAddress(uintptr_t address, Arch arch) 65 { 66 return address * GetInstructionAlignment(arch); 67 } 68 CreateProperties(bool is_osr,bool has_regmap)69 static constexpr uint32_t CreateProperties(bool is_osr, bool has_regmap) 70 { 71 return FieldIsOsr::Encode(is_osr) | FieldHasRegMap::Encode(has_regmap); 72 } 73 IsOsr()74 bool IsOsr() const 75 { 76 return FieldIsOsr::Get(GetProperties()); 77 } 78 HasRegMap()79 bool HasRegMap() const 80 { 81 return FieldHasRegMap::Get(GetProperties()); 82 } 83 84 private: 85 using FieldIsOsr = BitField<bool, 0, 1>; 86 using FieldHasRegMap = FieldIsOsr::NextFlag; 87 }; 88 89 class InlineInfo : public BitTableRow<6U, InlineInfo> { 90 public: 91 BIT_TABLE_HEADER(6, InlineInfo) 92 BIT_TABLE_COLUMN(0, IsLast, IS_LAST) 93 BIT_TABLE_COLUMN(1, BytecodePc, BYTECODE_PC) 94 BIT_TABLE_COLUMN(2, MethodIdIndex, METHOD_ID_INDEX) 95 BIT_TABLE_COLUMN(3, MethodHi, METHOD_HI) 96 BIT_TABLE_COLUMN(4, MethodLow, METHOD_LOW) 97 BIT_TABLE_COLUMN(5, VRegsCount, VREGS_COUNT) 98 99 DEFAULT_MOVE_SEMANTIC(InlineInfo); 100 DEFAULT_COPY_SEMANTIC(InlineInfo); 101 ~InlineInfo() = default; 102 }; 103 104 class RegisterMask : public BitTableRow<1, RegisterMask> { 105 public: 106 BIT_TABLE_HEADER(1, RegisterMask) 107 BIT_TABLE_COLUMN(0, Mask, MASK) 108 109 DEFAULT_MOVE_SEMANTIC(RegisterMask); 110 DEFAULT_COPY_SEMANTIC(RegisterMask); 111 ~RegisterMask() = default; 112 }; 113 114 class StackMask : public BitTableRow<1, StackMask> { 115 public: 116 BIT_TABLE_HEADER(1, StackMask) 117 BIT_TABLE_COLUMN(0, Mask, MASK) 118 119 DEFAULT_MOVE_SEMANTIC(StackMask); 120 DEFAULT_COPY_SEMANTIC(StackMask); 121 ~StackMask() = default; 122 }; 123 124 class VRegisterMask : public BitTableRow<1, VRegisterMask> { 125 public: 126 BIT_TABLE_HEADER(1, VRegisterMask) 127 BIT_TABLE_COLUMN(0, Mask, MASK) 128 129 DEFAULT_MOVE_SEMANTIC(VRegisterMask); 130 DEFAULT_COPY_SEMANTIC(VRegisterMask); 131 ~VRegisterMask() = default; 132 }; 133 134 class MethodId : public BitTableRow<1, MethodId> { 135 public: 136 BIT_TABLE_HEADER(1, MethodId) 137 BIT_TABLE_COLUMN(0, Id, ID) 138 139 DEFAULT_MOVE_SEMANTIC(MethodId); 140 DEFAULT_COPY_SEMANTIC(MethodId); 141 ~MethodId() = default; 142 }; 143 144 class VRegisterCatalogueIndex : public BitTableRow<1, VRegisterCatalogueIndex> { 145 public: 146 BIT_TABLE_HEADER(1, VRegisterCatalogueIndex) 147 BIT_TABLE_COLUMN(0, Index, INDEX) 148 149 DEFAULT_MOVE_SEMANTIC(VRegisterCatalogueIndex); 150 DEFAULT_COPY_SEMANTIC(VRegisterCatalogueIndex); 151 ~VRegisterCatalogueIndex() = default; 152 }; 153 154 class VRegisterInfo : public BitTableRow<2U, VRegisterInfo> { 155 public: 156 BIT_TABLE_HEADER(2, VRegisterInfo) 157 BIT_TABLE_COLUMN(0, Info, INFO) 158 BIT_TABLE_COLUMN(1, Value, VALUE) 159 160 DEFAULT_MOVE_SEMANTIC(VRegisterInfo); 161 DEFAULT_COPY_SEMANTIC(VRegisterInfo); 162 ~VRegisterInfo() = default; 163 GetColumnStr(size_t column)164 std::string GetColumnStr(size_t column) const 165 { 166 if (column != COLUMN_INFO || Get(column) == NO_VALUE) { 167 return Base::GetColumnStr(column); 168 } 169 auto vreg = GetVRegInfo(); 170 return std::string(vreg.GetLocationString()) + ":" + vreg.GetTypeString(); 171 } 172 GetVRegInfo()173 VRegInfo GetVRegInfo() const 174 { 175 return VRegInfo(GetValue(), GetInfo()); 176 } 177 GetConstantLowIndex()178 uint32_t GetConstantLowIndex() const 179 { 180 ASSERT(GetVRegInfo().GetLocation() == VRegInfo::Location::CONSTANT); 181 return GetValue() & ((1U << BITS_PER_UINT16) - 1); 182 } 183 GetConstantHiIndex()184 uint32_t GetConstantHiIndex() const 185 { 186 ASSERT(GetVRegInfo().GetLocation() == VRegInfo::Location::CONSTANT); 187 return (GetValue() >> BITS_PER_UINT16) & ((1U << BITS_PER_UINT16) - 1); 188 } 189 }; 190 191 class ImplicitNullChecks : public BitTableRow<2U, ImplicitNullChecks> { 192 public: 193 BIT_TABLE_HEADER(2, ImplicitNullChecks) 194 BIT_TABLE_COLUMN(0, InstNativePc, INST_NATIVE_PC) 195 BIT_TABLE_COLUMN(1, Offset, OFFSET) 196 197 DEFAULT_MOVE_SEMANTIC(ImplicitNullChecks); 198 DEFAULT_COPY_SEMANTIC(ImplicitNullChecks); 199 ~ImplicitNullChecks() = default; 200 }; 201 202 class ConstantTable : public BitTableRow<1, ConstantTable> { 203 public: 204 BIT_TABLE_HEADER(1, ConstantTable) 205 BIT_TABLE_COLUMN(0, Value, VALUE) 206 207 DEFAULT_MOVE_SEMANTIC(ConstantTable); 208 DEFAULT_COPY_SEMANTIC(ConstantTable); 209 ~ConstantTable() = default; 210 }; 211 212 } // namespace panda::compiler 213 214 #endif // PANDA_CODE_INFO_TABLES_H 215