Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ |
| 18 | #define ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ |
| 19 | |
| 20 | #include "quick/quick_method_frame_info.h" |
| 21 | #include "registers_arm64.h" |
| 22 | #include "runtime.h" // for Runtime::CalleeSaveType. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 23 | #include "utils.h" // for POPCOUNT |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | namespace arm64 { |
| 27 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 28 | // Registers need to be restored but not preserved by aapcs64. |
| 29 | static constexpr uint32_t kArm64CalleeSaveAlwaysSpills = |
| 30 | // Note: ArtMethod::GetReturnPcOffsetInBytes() rely on the assumption that |
| 31 | // LR is always saved on the top of the frame for all targets. |
| 32 | // That is, lr = *(sp + framesize - pointsize). |
| 33 | (1 << art::arm64::LR); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 34 | // Callee saved registers |
| 35 | static constexpr uint32_t kArm64CalleeSaveRefSpills = |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame^] | 36 | (1 << art::arm64::X20) | (1 << art::arm64::X21) | (1 << art::arm64::X22) | |
| 37 | (1 << art::arm64::X23) | (1 << art::arm64::X24) | (1 << art::arm64::X25) | |
| 38 | (1 << art::arm64::X26) | (1 << art::arm64::X27) | (1 << art::arm64::X28) | |
| 39 | (1 << art::arm64::X29); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 40 | // X0 is the method pointer. Not saved. |
| 41 | static constexpr uint32_t kArm64CalleeSaveArgSpills = |
| 42 | (1 << art::arm64::X1) | (1 << art::arm64::X2) | (1 << art::arm64::X3) | |
| 43 | (1 << art::arm64::X4) | (1 << art::arm64::X5) | (1 << art::arm64::X6) | |
| 44 | (1 << art::arm64::X7); |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 45 | static constexpr uint32_t kArm64CalleeSaveAllSpills = |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame^] | 46 | (1 << art::arm64::X19); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 47 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 48 | static constexpr uint32_t kArm64CalleeSaveFpAlwaysSpills = 0; |
| 49 | static constexpr uint32_t kArm64CalleeSaveFpRefSpills = 0; |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 50 | static constexpr uint32_t kArm64CalleeSaveFpArgSpills = |
| 51 | (1 << art::arm64::D0) | (1 << art::arm64::D1) | (1 << art::arm64::D2) | |
| 52 | (1 << art::arm64::D3) | (1 << art::arm64::D4) | (1 << art::arm64::D5) | |
| 53 | (1 << art::arm64::D6) | (1 << art::arm64::D7); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 54 | static constexpr uint32_t kArm64CalleeSaveFpAllSpills = |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 55 | (1 << art::arm64::D8) | (1 << art::arm64::D9) | (1 << art::arm64::D10) | |
| 56 | (1 << art::arm64::D11) | (1 << art::arm64::D12) | (1 << art::arm64::D13) | |
| 57 | (1 << art::arm64::D14) | (1 << art::arm64::D15); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 58 | |
| 59 | constexpr uint32_t Arm64CalleeSaveCoreSpills(Runtime::CalleeSaveType type) { |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 60 | return kArm64CalleeSaveAlwaysSpills | kArm64CalleeSaveRefSpills | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 61 | (type == Runtime::kRefsAndArgs ? kArm64CalleeSaveArgSpills : 0) | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 62 | (type == Runtime::kSaveAll ? kArm64CalleeSaveAllSpills : 0); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | constexpr uint32_t Arm64CalleeSaveFpSpills(Runtime::CalleeSaveType type) { |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 66 | return kArm64CalleeSaveFpAlwaysSpills | kArm64CalleeSaveFpRefSpills | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 67 | (type == Runtime::kRefsAndArgs ? kArm64CalleeSaveFpArgSpills: 0) | |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 68 | (type == Runtime::kSaveAll ? kArm64CalleeSaveFpAllSpills : 0); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | constexpr uint32_t Arm64CalleeSaveFrameSize(Runtime::CalleeSaveType type) { |
| 72 | return RoundUp((POPCOUNT(Arm64CalleeSaveCoreSpills(type)) /* gprs */ + |
| 73 | POPCOUNT(Arm64CalleeSaveFpSpills(type)) /* fprs */ + |
| 74 | 1 /* Method* */) * kArm64PointerSize, kStackAlignment); |
| 75 | } |
| 76 | |
| 77 | constexpr QuickMethodFrameInfo Arm64CalleeSaveMethodFrameInfo(Runtime::CalleeSaveType type) { |
| 78 | return QuickMethodFrameInfo(Arm64CalleeSaveFrameSize(type), |
| 79 | Arm64CalleeSaveCoreSpills(type), |
| 80 | Arm64CalleeSaveFpSpills(type)); |
| 81 | } |
| 82 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 83 | constexpr size_t Arm64CalleeSaveFpr1Offset(Runtime::CalleeSaveType type) { |
| 84 | return Arm64CalleeSaveFrameSize(type) - |
| 85 | (POPCOUNT(Arm64CalleeSaveCoreSpills(type)) + |
| 86 | POPCOUNT(Arm64CalleeSaveFpSpills(type))) * kArm64PointerSize; |
| 87 | } |
| 88 | |
| 89 | constexpr size_t Arm64CalleeSaveGpr1Offset(Runtime::CalleeSaveType type) { |
| 90 | return Arm64CalleeSaveFrameSize(type) - |
| 91 | POPCOUNT(Arm64CalleeSaveCoreSpills(type)) * kArm64PointerSize; |
| 92 | } |
| 93 | |
| 94 | constexpr size_t Arm64CalleeSaveLrOffset(Runtime::CalleeSaveType type) { |
| 95 | return Arm64CalleeSaveFrameSize(type) - |
| 96 | POPCOUNT(Arm64CalleeSaveCoreSpills(type) & (-(1 << LR))) * kArm64PointerSize; |
| 97 | } |
| 98 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 99 | } // namespace arm64 |
| 100 | } // namespace art |
| 101 | |
| 102 | #endif // ART_RUNTIME_ARCH_ARM64_QUICK_METHOD_FRAME_INFO_ARM64_H_ |