• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COMPILER_OPTIMIZER_IR_CONSTANTS_H
17 #define COMPILER_OPTIMIZER_IR_CONSTANTS_H
18 
19 #include <cstdint>
20 #include <limits>
21 #include <string>
22 #include <variant>
23 
24 namespace panda::compiler {
25 constexpr int BITS_PER_BYTE = 8;
26 constexpr int BITS_PER_INSTPTR = sizeof(intptr_t) * BITS_PER_BYTE;
27 
28 using PcType = uint32_t;
29 using LinearNumber = uint32_t;
30 
31 // Update this when it will be strictly necessary to assign more than 255 registers in bytecode optimizer.
32 #ifdef IR_FOR_LIBARK_DEFECT_SCAN_AUX
33 using Register = uint16_t;
34 using StackSlot = uint16_t;
35 using ImmTableSlot = uint16_t;
36 #else
37 using Register = uint8_t;
38 using StackSlot = uint8_t;
39 using ImmTableSlot = uint8_t;
40 #endif
41 constexpr uint32_t MAX_NUM_STACK_SLOTS = std::numeric_limits<StackSlot>::max();
42 constexpr uint32_t MAX_NUM_IMM_SLOTS = std::numeric_limits<ImmTableSlot>::max();
43 
44 constexpr uint32_t INVALID_PC = std::numeric_limits<PcType>::max();
45 constexpr uint32_t INVALID_ID = std::numeric_limits<uint32_t>::max();
46 constexpr uint32_t INVALID_VN = std::numeric_limits<uint32_t>::max();
47 constexpr LinearNumber INVALID_LINEAR_NUM = std::numeric_limits<LinearNumber>::max();
48 constexpr Register INVALID_REG = std::numeric_limits<Register>::max();
49 constexpr StackSlot INVALID_STACK_SLOT = std::numeric_limits<StackSlot>::max();
50 constexpr ImmTableSlot INVALID_IMM_TABLE_SLOT = std::numeric_limits<ImmTableSlot>::max();
51 constexpr std::uint32_t INVALID_COLUMN_NUM = std::numeric_limits<std::uint32_t>::max();
52 constexpr std::size_t CALLEE_THRESHOLD = 2;
53 
54 constexpr Register VIRTUAL_FRAME_SIZE = INVALID_REG - 1U;
55 
56 constexpr Register INVALID_REG_ID = std::numeric_limits<Register>::max();
57 constexpr Register ACC_REG_ID = INVALID_REG_ID - 1U;
58 constexpr uint8_t MAX_NUM_REGS = 32;
59 constexpr uint8_t MAX_NUM_VREGS = 32;
60 
61 using LifeNumber = uint32_t;
62 constexpr auto INVALID_LIFE_NUMBER = std::numeric_limits<LifeNumber>::max();
63 constexpr auto LIFE_NUMBER_GAP = 2U;
64 
65 enum ShiftType : uint8_t { LSL, LSR, ASR, ROR, INVALID_SHIFT };
66 
67 enum ShiftOpcode { NEG_SR, ADD_SR, SUB_SR, AND_SR, OR_SR, XOR_SR, AND_NOT_SR, OR_NOT_SR, XOR_NOT_SR, INVALID_SR };
68 
69 constexpr uint32_t MAX_SCALE = 3;
70 
71 constexpr int MAX_SUCCS_NUM = 2;
72 }  // namespace panda::compiler
73 
74 // TypeInfoIndex adaption
75 using BuiltinIndexType = uint8_t;
76 using TypeInfoIndex = std::variant<BuiltinIndexType, std::string>;
77 const TypeInfoIndex NO_EXPLICIT_TYPE = static_cast<BuiltinIndexType>(0);
78 constexpr const std::string_view TSTYPE_ANNO_RECORD_NAME = "_ESTypeAnnotation";
79 constexpr const std::string_view TSTYPE_ANNO_ELEMENT_NAME = "_TypeOfInstruction";
80 constexpr auto INVALID_TYPE_INDEX = std::numeric_limits<std::size_t>::max();
81 
82 #endif  // COMPILER_OPTIMIZER_IR_CONSTANTS_H
83