• 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 using Register = uint8_t;
33 using StackSlot = uint8_t;
34 using ImmTableSlot = uint8_t;
35 constexpr uint32_t MAX_NUM_STACK_SLOTS = std::numeric_limits<StackSlot>::max();
36 constexpr uint32_t MAX_NUM_IMM_SLOTS = std::numeric_limits<ImmTableSlot>::max();
37 
38 constexpr uint32_t INVALID_PC = std::numeric_limits<PcType>::max();
39 constexpr uint32_t INVALID_ID = std::numeric_limits<uint32_t>::max();
40 constexpr uint32_t INVALID_VN = std::numeric_limits<uint32_t>::max();
41 constexpr LinearNumber INVALID_LINEAR_NUM = std::numeric_limits<LinearNumber>::max();
42 constexpr Register INVALID_REG = std::numeric_limits<Register>::max();
43 constexpr StackSlot INVALID_STACK_SLOT = std::numeric_limits<StackSlot>::max();
44 constexpr ImmTableSlot INVALID_IMM_TABLE_SLOT = std::numeric_limits<ImmTableSlot>::max();
45 constexpr std::uint32_t INVALID_COLUMN_NUM = std::numeric_limits<std::uint32_t>::max();
46 constexpr std::size_t CALLEE_THRESHOLD = 2;
47 
48 constexpr Register VIRTUAL_FRAME_SIZE = INVALID_REG - 1U;
49 
50 constexpr Register INVALID_REG_ID = std::numeric_limits<Register>::max();
51 constexpr Register ACC_REG_ID = INVALID_REG_ID - 1U;
52 constexpr uint8_t MAX_NUM_REGS = 32;
53 constexpr uint8_t MAX_NUM_VREGS = 32;
54 
55 using LifeNumber = uint32_t;
56 constexpr auto INVALID_LIFE_NUMBER = std::numeric_limits<LifeNumber>::max();
57 constexpr auto LIFE_NUMBER_GAP = 2U;
58 
59 enum ShiftType : uint8_t { LSL, LSR, ASR, ROR, INVALID_SHIFT };
60 
61 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 };
62 
63 constexpr uint32_t MAX_SCALE = 3;
64 
65 constexpr int MAX_SUCCS_NUM = 2;
66 }  // namespace panda::compiler
67 
68 // TypeInfoIndex adaption
69 using BuiltinIndexType = uint8_t;
70 using TypeInfoIndex = std::variant<BuiltinIndexType, std::string>;
71 const TypeInfoIndex NO_EXPLICIT_TYPE = static_cast<BuiltinIndexType>(0);
72 constexpr const std::string_view TSTYPE_ANNO_RECORD_NAME = "_ESTypeAnnotation";
73 constexpr const std::string_view TSTYPE_ANNO_ELEMENT_NAME = "_TypeOfInstruction";
74 constexpr auto INVALID_TYPE_INDEX = std::numeric_limits<std::size_t>::max();
75 
76 #endif  // COMPILER_OPTIMIZER_IR_CONSTANTS_H
77