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