blob: b4a4abc87ec5cd689dd0ef1ad5d9c1e8f9e28990 [file] [log] [blame]
Artem Serov12e097c2016-08-08 15:13:26 +01001/*
2 * Copyright (C) 2016 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_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_
18#define ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_
19
20#include "base/arena_containers.h"
21#include "base/logging.h"
22#include "constants_arm.h"
23#include "offsets.h"
24#include "utils/arm/assembler_arm_shared.h"
25#include "utils/arm/managed_register_arm.h"
26#include "utils/assembler.h"
27#include "utils/jni_macro_assembler.h"
28
29// TODO(VIXL): Make VIXL compile with -Wshadow and remove pragmas.
30#pragma GCC diagnostic push
31#pragma GCC diagnostic ignored "-Wshadow"
32#include "aarch32/macro-assembler-aarch32.h"
33#pragma GCC diagnostic pop
34
35namespace vixl32 = vixl::aarch32;
36
37namespace art {
38namespace arm {
39
xueliang.zhongf51bc622016-11-04 09:23:32 +000040class ArmVIXLMacroAssembler FINAL : public vixl32::MacroAssembler {
41 public:
42 // The following interfaces can generate CMP+Bcc or Cbz/Cbnz.
43 // CMP+Bcc are generated by default.
44 // If a hint is given (is_far_target = false) and rn and label can all fit into Cbz/Cbnz,
45 // then Cbz/Cbnz is generated.
46 // Prefer following interfaces to using vixl32::MacroAssembler::Cbz/Cbnz.
47 // In T32, Cbz/Cbnz instructions have following limitations:
48 // - Far targets, which are over 126 bytes away, are not supported.
49 // - Only low registers can be encoded.
50 // - Backward branches are not supported.
51 void CompareAndBranchIfZero(vixl32::Register rn,
52 vixl32::Label* label,
53 bool is_far_target = true);
54 void CompareAndBranchIfNonZero(vixl32::Register rn,
55 vixl32::Label* label,
56 bool is_far_target = true);
57};
58
Artem Serov12e097c2016-08-08 15:13:26 +010059class ArmVIXLAssembler FINAL : public Assembler {
60 private:
61 class ArmException;
62 public:
63 explicit ArmVIXLAssembler(ArenaAllocator* arena)
64 : Assembler(arena) {
65 // Use Thumb2 instruction set.
66 vixl_masm_.UseT32();
67 }
68
69 virtual ~ArmVIXLAssembler() {}
xueliang.zhongf51bc622016-11-04 09:23:32 +000070 ArmVIXLMacroAssembler* GetVIXLAssembler() { return &vixl_masm_; }
Artem Serov12e097c2016-08-08 15:13:26 +010071 void FinalizeCode() OVERRIDE;
72
73 // Size of generated code.
74 size_t CodeSize() const OVERRIDE;
75 const uint8_t* CodeBufferBaseAddress() const OVERRIDE;
76
77 // Copy instructions out of assembly buffer into the given region of memory.
78 void FinalizeInstructions(const MemoryRegion& region) OVERRIDE;
79
80 void Bind(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
81 UNIMPLEMENTED(FATAL) << "Do not use Bind for ARM";
82 }
83 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
84 UNIMPLEMENTED(FATAL) << "Do not use Jump for ARM";
85 }
86
87 //
88 // Heap poisoning.
89 //
90 // Poison a heap reference contained in `reg`.
91 void PoisonHeapReference(vixl32::Register reg);
92 // Unpoison a heap reference contained in `reg`.
93 void UnpoisonHeapReference(vixl32::Register reg);
Anton Kirilove28d9ae2016-10-25 18:17:23 +010094 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
95 void MaybePoisonHeapReference(vixl32::Register reg);
Artem Serov12e097c2016-08-08 15:13:26 +010096 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
97 void MaybeUnpoisonHeapReference(vixl32::Register reg);
98
99 void StoreToOffset(StoreOperandType type,
100 vixl32::Register reg,
101 vixl32::Register base,
102 int32_t offset);
103 void StoreSToOffset(vixl32::SRegister source, vixl32::Register base, int32_t offset);
104 void StoreDToOffset(vixl32::DRegister source, vixl32::Register base, int32_t offset);
105
106 void LoadImmediate(vixl32::Register dest, int32_t value);
107 void LoadFromOffset(LoadOperandType type,
108 vixl32::Register reg,
109 vixl32::Register base,
110 int32_t offset);
111 void LoadSFromOffset(vixl32::SRegister reg, vixl32::Register base, int32_t offset);
112 void LoadDFromOffset(vixl32::DRegister reg, vixl32::Register base, int32_t offset);
113
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100114 void LoadRegisterList(RegList regs, size_t stack_offset);
115 void StoreRegisterList(RegList regs, size_t stack_offset);
116
Artem Serov12e097c2016-08-08 15:13:26 +0100117 bool ShifterOperandCanAlwaysHold(uint32_t immediate);
Artem Serov02109dd2016-09-23 17:17:54 +0100118 bool ShifterOperandCanHold(Opcode opcode, uint32_t immediate, SetCc set_cc = kCcDontCare);
Artem Serov12e097c2016-08-08 15:13:26 +0100119 bool CanSplitLoadStoreOffset(int32_t allowed_offset_bits,
120 int32_t offset,
121 /*out*/ int32_t* add_to_base,
122 /*out*/ int32_t* offset_for_load_store);
123 int32_t AdjustLoadStoreOffset(int32_t allowed_offset_bits,
124 vixl32::Register temp,
125 vixl32::Register base,
126 int32_t offset);
127 int32_t GetAllowedLoadOffsetBits(LoadOperandType type);
128 int32_t GetAllowedStoreOffsetBits(StoreOperandType type);
129
130 void AddConstant(vixl32::Register rd, int32_t value);
131 void AddConstant(vixl32::Register rd, vixl32::Register rn, int32_t value);
132 void AddConstantInIt(vixl32::Register rd,
133 vixl32::Register rn,
134 int32_t value,
135 vixl32::Condition cond = vixl32::al);
136
137 private:
138 // VIXL assembler.
xueliang.zhongf51bc622016-11-04 09:23:32 +0000139 ArmVIXLMacroAssembler vixl_masm_;
Artem Serov12e097c2016-08-08 15:13:26 +0100140};
141
142// Thread register declaration.
143extern const vixl32::Register tr;
144
145} // namespace arm
146} // namespace art
147
148#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_