1 /*
2 * Copyright (c) 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 #include "ecmascript/deoptimizer/calleeReg.h"
16
17 namespace panda::ecmascript::kungfu {
CalleeReg()18 CalleeReg::CalleeReg()
19 {
20 #if defined(PANDA_TARGET_AMD64)
21 reg2Location_ = {
22 {DwarfReg::RBX, 0},
23 {DwarfReg::R15, 1},
24 {DwarfReg::R14, 2},
25 {DwarfReg::R13, 3},
26 {DwarfReg::R12, 4},
27 };
28 #elif defined(PANDA_TARGET_ARM64)
29 reg2Location_ = {
30 {DwarfReg::D8, 0},
31 {DwarfReg::D9, 1},
32 {DwarfReg::D10, 2},
33 {DwarfReg::D11, 3},
34 {DwarfReg::D12, 4},
35 {DwarfReg::D13, 5},
36 {DwarfReg::D14, 6},
37 {DwarfReg::D15, 7},
38
39 {DwarfReg::X19, 8},
40 {DwarfReg::X20, 9},
41 {DwarfReg::X21, 10},
42 {DwarfReg::X22, 11},
43 {DwarfReg::X23, 12},
44 {DwarfReg::X24, 13},
45 {DwarfReg::X25, 14},
46 {DwarfReg::X26, 15},
47 {DwarfReg::X27, 16},
48 {DwarfReg::X28, 17},
49 };
50 #endif
51 }
52
FindCallRegOrder(const LLVMStackMapType::DwarfRegType reg) const53 int CalleeReg::FindCallRegOrder(const LLVMStackMapType::DwarfRegType reg) const
54 {
55 auto it = reg2Location_.find(static_cast<DwarfReg>(reg));
56 if (it != reg2Location_.end()) {
57 return it->second;
58 } else {
59 LOG_FULL(FATAL) << "reg:" << std::dec << reg;
60 UNREACHABLE();
61 }
62 }
63
FindCallRegOrder(const DwarfReg reg) const64 int CalleeReg::FindCallRegOrder(const DwarfReg reg) const
65 {
66 auto order = FindCallRegOrder(static_cast<LLVMStackMapType::DwarfRegType>(reg));
67 return order;
68 }
69
GetCallRegNum() const70 int CalleeReg::GetCallRegNum() const
71 {
72 return reg2Location_.size();
73 }
74 } // namespace panda::ecmascript::kungfu
75