blob: e0206287eb4fb2c84197b49598d722b6bf2f21a8 [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
40class ArmVIXLAssembler FINAL : public Assembler {
41 private:
42 class ArmException;
43 public:
44 explicit ArmVIXLAssembler(ArenaAllocator* arena)
45 : Assembler(arena) {
46 // Use Thumb2 instruction set.
47 vixl_masm_.UseT32();
48 }
49
50 virtual ~ArmVIXLAssembler() {}
51 vixl32::MacroAssembler* GetVIXLAssembler() { return &vixl_masm_; }
52 void FinalizeCode() OVERRIDE;
53
54 // Size of generated code.
55 size_t CodeSize() const OVERRIDE;
56 const uint8_t* CodeBufferBaseAddress() const OVERRIDE;
57
58 // Copy instructions out of assembly buffer into the given region of memory.
59 void FinalizeInstructions(const MemoryRegion& region) OVERRIDE;
60
61 void Bind(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
62 UNIMPLEMENTED(FATAL) << "Do not use Bind for ARM";
63 }
64 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
65 UNIMPLEMENTED(FATAL) << "Do not use Jump for ARM";
66 }
67
68 //
69 // Heap poisoning.
70 //
71 // Poison a heap reference contained in `reg`.
72 void PoisonHeapReference(vixl32::Register reg);
73 // Unpoison a heap reference contained in `reg`.
74 void UnpoisonHeapReference(vixl32::Register reg);
Anton Kirilove28d9ae2016-10-25 18:17:23 +010075 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
76 void MaybePoisonHeapReference(vixl32::Register reg);
Artem Serov12e097c2016-08-08 15:13:26 +010077 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
78 void MaybeUnpoisonHeapReference(vixl32::Register reg);
79
80 void StoreToOffset(StoreOperandType type,
81 vixl32::Register reg,
82 vixl32::Register base,
83 int32_t offset);
84 void StoreSToOffset(vixl32::SRegister source, vixl32::Register base, int32_t offset);
85 void StoreDToOffset(vixl32::DRegister source, vixl32::Register base, int32_t offset);
86
87 void LoadImmediate(vixl32::Register dest, int32_t value);
88 void LoadFromOffset(LoadOperandType type,
89 vixl32::Register reg,
90 vixl32::Register base,
91 int32_t offset);
92 void LoadSFromOffset(vixl32::SRegister reg, vixl32::Register base, int32_t offset);
93 void LoadDFromOffset(vixl32::DRegister reg, vixl32::Register base, int32_t offset);
94
Scott Wakelinga7812ae2016-10-17 10:03:36 +010095 void LoadRegisterList(RegList regs, size_t stack_offset);
96 void StoreRegisterList(RegList regs, size_t stack_offset);
97
Artem Serov12e097c2016-08-08 15:13:26 +010098 bool ShifterOperandCanAlwaysHold(uint32_t immediate);
Artem Serov02109dd2016-09-23 17:17:54 +010099 bool ShifterOperandCanHold(Opcode opcode, uint32_t immediate, SetCc set_cc = kCcDontCare);
Artem Serov12e097c2016-08-08 15:13:26 +0100100 bool CanSplitLoadStoreOffset(int32_t allowed_offset_bits,
101 int32_t offset,
102 /*out*/ int32_t* add_to_base,
103 /*out*/ int32_t* offset_for_load_store);
104 int32_t AdjustLoadStoreOffset(int32_t allowed_offset_bits,
105 vixl32::Register temp,
106 vixl32::Register base,
107 int32_t offset);
108 int32_t GetAllowedLoadOffsetBits(LoadOperandType type);
109 int32_t GetAllowedStoreOffsetBits(StoreOperandType type);
110
111 void AddConstant(vixl32::Register rd, int32_t value);
112 void AddConstant(vixl32::Register rd, vixl32::Register rn, int32_t value);
113 void AddConstantInIt(vixl32::Register rd,
114 vixl32::Register rn,
115 int32_t value,
116 vixl32::Condition cond = vixl32::al);
117
118 private:
119 // VIXL assembler.
120 vixl32::MacroAssembler vixl_masm_;
121};
122
123// Thread register declaration.
124extern const vixl32::Register tr;
125
126} // namespace arm
127} // namespace art
128
129#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_