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_ARM_QUICK_METHOD_FRAME_INFO_ARM_H_
18 #define ART_RUNTIME_ARCH_ARM_QUICK_METHOD_FRAME_INFO_ARM_H_
19 
20 #include "arch/instruction_set.h"
21 #include "base/bit_utils.h"
22 #include "base/callee_save_type.h"
23 #include "base/enums.h"
24 #include "quick/quick_method_frame_info.h"
25 #include "registers_arm.h"
26 
27 namespace art {
28 namespace arm {
29 
30 static constexpr uint32_t kArmCalleeSaveAlwaysSpills =
31     (1 << art::arm::LR);
32 static constexpr uint32_t kArmCalleeSaveRefSpills =
33     (1 << art::arm::R5) | (1 << art::arm::R6)  | (1 << art::arm::R7) | (1 << art::arm::R8) |
34     (1 << art::arm::R10) | (1 << art::arm::R11);
35 static constexpr uint32_t kArmCalleeSaveArgSpills =
36     (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3);
37 static constexpr uint32_t kArmCalleeSaveAllSpills =
38     (1 << art::arm::R4) | (1 << art::arm::R9);
39 static constexpr uint32_t kArmCalleeSaveEverythingSpills =
40     (1 << art::arm::R0) | (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3) |
41     (1 << art::arm::R4) | (1 << art::arm::R9) | (1 << art::arm::R12);
42 
43 static constexpr uint32_t kArmCalleeSaveFpAlwaysSpills = 0;
44 static constexpr uint32_t kArmCalleeSaveFpRefSpills = 0;
45 static constexpr uint32_t kArmCalleeSaveFpArgSpills =
46     (1 << art::arm::S0)  | (1 << art::arm::S1)  | (1 << art::arm::S2)  | (1 << art::arm::S3)  |
47     (1 << art::arm::S4)  | (1 << art::arm::S5)  | (1 << art::arm::S6)  | (1 << art::arm::S7)  |
48     (1 << art::arm::S8)  | (1 << art::arm::S9)  | (1 << art::arm::S10) | (1 << art::arm::S11) |
49     (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) | (1 << art::arm::S15);
50 static constexpr uint32_t kArmCalleeSaveFpAllSpills =
51     (1 << art::arm::S16) | (1 << art::arm::S17) | (1 << art::arm::S18) | (1 << art::arm::S19) |
52     (1 << art::arm::S20) | (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) |
53     (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) | (1 << art::arm::S27) |
54     (1 << art::arm::S28) | (1 << art::arm::S29) | (1 << art::arm::S30) | (1 << art::arm::S31);
55 static constexpr uint32_t kArmCalleeSaveFpEverythingSpills =
56     kArmCalleeSaveFpArgSpills | kArmCalleeSaveFpAllSpills;
57 
ArmCalleeSaveCoreSpills(CalleeSaveType type)58 constexpr uint32_t ArmCalleeSaveCoreSpills(CalleeSaveType type) {
59   type = GetCanonicalCalleeSaveType(type);
60   return kArmCalleeSaveAlwaysSpills | kArmCalleeSaveRefSpills |
61       (type == CalleeSaveType::kSaveRefsAndArgs ? kArmCalleeSaveArgSpills : 0) |
62       (type == CalleeSaveType::kSaveAllCalleeSaves ? kArmCalleeSaveAllSpills : 0) |
63       (type == CalleeSaveType::kSaveEverything ? kArmCalleeSaveEverythingSpills : 0);
64 }
65 
ArmCalleeSaveFpSpills(CalleeSaveType type)66 constexpr uint32_t ArmCalleeSaveFpSpills(CalleeSaveType type) {
67   type = GetCanonicalCalleeSaveType(type);
68   return kArmCalleeSaveFpAlwaysSpills | kArmCalleeSaveFpRefSpills |
69       (type == CalleeSaveType::kSaveRefsAndArgs ? kArmCalleeSaveFpArgSpills : 0) |
70       (type == CalleeSaveType::kSaveAllCalleeSaves ? kArmCalleeSaveFpAllSpills : 0) |
71       (type == CalleeSaveType::kSaveEverything ? kArmCalleeSaveFpEverythingSpills : 0);
72 }
73 
ArmCalleeSaveFrameSize(CalleeSaveType type)74 constexpr uint32_t ArmCalleeSaveFrameSize(CalleeSaveType type) {
75   type = GetCanonicalCalleeSaveType(type);
76   return RoundUp((POPCOUNT(ArmCalleeSaveCoreSpills(type)) /* gprs */ +
77                   POPCOUNT(ArmCalleeSaveFpSpills(type)) /* fprs */ +
78                   1 /* Method* */) * static_cast<size_t>(kArmPointerSize), kStackAlignment);
79 }
80 
ArmCalleeSaveMethodFrameInfo(CalleeSaveType type)81 constexpr QuickMethodFrameInfo ArmCalleeSaveMethodFrameInfo(CalleeSaveType type) {
82   type = GetCanonicalCalleeSaveType(type);
83   return QuickMethodFrameInfo(ArmCalleeSaveFrameSize(type),
84                               ArmCalleeSaveCoreSpills(type),
85                               ArmCalleeSaveFpSpills(type));
86 }
87 
ArmCalleeSaveFpr1Offset(CalleeSaveType type)88 constexpr size_t ArmCalleeSaveFpr1Offset(CalleeSaveType type) {
89   type = GetCanonicalCalleeSaveType(type);
90   return ArmCalleeSaveFrameSize(type) -
91          (POPCOUNT(ArmCalleeSaveCoreSpills(type)) +
92           POPCOUNT(ArmCalleeSaveFpSpills(type))) * static_cast<size_t>(kArmPointerSize);
93 }
94 
ArmCalleeSaveGpr1Offset(CalleeSaveType type)95 constexpr size_t ArmCalleeSaveGpr1Offset(CalleeSaveType type) {
96   type = GetCanonicalCalleeSaveType(type);
97   return ArmCalleeSaveFrameSize(type) -
98          POPCOUNT(ArmCalleeSaveCoreSpills(type)) * static_cast<size_t>(kArmPointerSize);
99 }
100 
ArmCalleeSaveLrOffset(CalleeSaveType type)101 constexpr size_t ArmCalleeSaveLrOffset(CalleeSaveType type) {
102   type = GetCanonicalCalleeSaveType(type);
103   return ArmCalleeSaveFrameSize(type) -
104       POPCOUNT(ArmCalleeSaveCoreSpills(type) & (-(1 << LR))) * static_cast<size_t>(kArmPointerSize);
105 }
106 
107 }  // namespace arm
108 }  // namespace art
109 
110 #endif  // ART_RUNTIME_ARCH_ARM_QUICK_METHOD_FRAME_INFO_ARM_H_
111