1b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith/*
2b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * Copyright (C) 2014 The Android Open Source Project
3b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith *
4b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * Licensed under the Apache License, Version 2.0 (the "License");
5b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * you may not use this file except in compliance with the License.
6b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * You may obtain a copy of the License at
7b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith *
8b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith *      http://www.apache.org/licenses/LICENSE-2.0
9b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith *
10b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * Unless required by applicable law or agreed to in writing, software
11b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * distributed under the License is distributed on an "AS IS" BASIS,
12b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * See the License for the specific language governing permissions and
14b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith * limitations under the License.
15b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith */
16b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
17b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith#ifndef ART_COMPILER_JNI_QUICK_ARM64_CALLING_CONVENTION_ARM64_H_
18b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith#define ART_COMPILER_JNI_QUICK_ARM64_CALLING_CONVENTION_ARM64_H_
19b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
20b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith#include "jni/quick/calling_convention.h"
21b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
22b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteithnamespace art {
23b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteithnamespace arm64 {
24b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
25790a6b7312979513710c366b411ba6791ddf78c2Ian Rogersconstexpr size_t kFramePointerSize = 8;
26790a6b7312979513710c366b411ba6791ddf78c2Ian Rogers
2725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampeclass Arm64ManagedRuntimeCallingConvention FINAL : public ManagedRuntimeCallingConvention {
28b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith public:
29b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  Arm64ManagedRuntimeCallingConvention(bool is_static, bool is_synchronized, const char* shorty)
30790a6b7312979513710c366b411ba6791ddf78c2Ian Rogers      : ManagedRuntimeCallingConvention(is_static, is_synchronized, shorty, kFramePointerSize) {}
3125ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ~Arm64ManagedRuntimeCallingConvention() OVERRIDE {}
32b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  // Calling convention
3325ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnRegister() OVERRIDE;
3425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister InterproceduralScratchRegister() OVERRIDE;
35b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  // Managed runtime calling convention
3625ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister MethodRegister() OVERRIDE;
3725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamInRegister() OVERRIDE;
3825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamOnStack() OVERRIDE;
3925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister CurrentParamRegister() OVERRIDE;
4025ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  FrameOffset CurrentParamStackOffset() OVERRIDE;
41fca82208f7128fcda09b6a4743199308332558a2Dmitry Petrochenko  const ManagedRegisterEntrySpills& EntrySpills() OVERRIDE;
42b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
43b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith private:
44fca82208f7128fcda09b6a4743199308332558a2Dmitry Petrochenko  ManagedRegisterEntrySpills entry_spills_;
45b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
46b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  DISALLOW_COPY_AND_ASSIGN(Arm64ManagedRuntimeCallingConvention);
47b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith};
48b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
4925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampeclass Arm64JniCallingConvention FINAL : public JniCallingConvention {
50b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith public:
513887c468d731420e929e6ad3acf190d5431e94fcRoland Levillain  Arm64JniCallingConvention(bool is_static, bool is_synchronized, const char* shorty);
5225ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ~Arm64JniCallingConvention() OVERRIDE {}
53b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  // Calling convention
5425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnRegister() OVERRIDE;
5525ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister IntReturnRegister() OVERRIDE;
5625ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister InterproceduralScratchRegister() OVERRIDE;
57b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  // JNI calling convention
5825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t FrameSize() OVERRIDE;
5925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t OutArgSize() OVERRIDE;
6025ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  const std::vector<ManagedRegister>& CalleeSaveRegisters() const OVERRIDE {
61b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith    return callee_save_regs_;
62b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  }
6325ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister ReturnScratchRegister() const OVERRIDE;
6425ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  uint32_t CoreSpillMask() const OVERRIDE;
6575b9113b2b0a5807043af2a669a93d1579af8e2cSerban Constantinescu  uint32_t FpSpillMask() const OVERRIDE;
6625ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamInRegister() OVERRIDE;
6725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  bool IsCurrentParamOnStack() OVERRIDE;
6825ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  ManagedRegister CurrentParamRegister() OVERRIDE;
6925ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  FrameOffset CurrentParamStackOffset() OVERRIDE;
70b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
71d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  // aarch64 calling convention leaves upper bits undefined.
72d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  bool RequiresSmallResultTypeExtension() const OVERRIDE {
73d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe    return true;
74d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe  }
75d1104322e5156669767e8b2c3b843ffaff173381Andreas Gampe
76b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith protected:
7725ff0048a70c79272884d5d0f8e9b9861a451afeAndreas Gampe  size_t NumberOfOutgoingStackArgs() OVERRIDE;
78b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
79b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith private:
80b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  // TODO: these values aren't unique and can be shared amongst instances
81b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  std::vector<ManagedRegister> callee_save_regs_;
82b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
83b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith  DISALLOW_COPY_AND_ASSIGN(Arm64JniCallingConvention);
84b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith};
85b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
86b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith}  // namespace arm64
87b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith}  // namespace art
88b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith
89b95a5345ae4217b70ca36f0cced92f68dda7caf5Stuart Monteith#endif  // ART_COMPILER_JNI_QUICK_ARM64_CALLING_CONVENTION_ARM64_H_
90