blob: c8f3a9b86325464bdd8b4fbdd77608514b6ba0b4 [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);
75 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
76 void MaybeUnpoisonHeapReference(vixl32::Register reg);
77
78 void StoreToOffset(StoreOperandType type,
79 vixl32::Register reg,
80 vixl32::Register base,
81 int32_t offset);
82 void StoreSToOffset(vixl32::SRegister source, vixl32::Register base, int32_t offset);
83 void StoreDToOffset(vixl32::DRegister source, vixl32::Register base, int32_t offset);
84
85 void LoadImmediate(vixl32::Register dest, int32_t value);
86 void LoadFromOffset(LoadOperandType type,
87 vixl32::Register reg,
88 vixl32::Register base,
89 int32_t offset);
90 void LoadSFromOffset(vixl32::SRegister reg, vixl32::Register base, int32_t offset);
91 void LoadDFromOffset(vixl32::DRegister reg, vixl32::Register base, int32_t offset);
92
93 bool ShifterOperandCanAlwaysHold(uint32_t immediate);
94 bool ShifterOperandCanHold(Opcode opcode, uint32_t immediate, SetCc set_cc);
95 bool CanSplitLoadStoreOffset(int32_t allowed_offset_bits,
96 int32_t offset,
97 /*out*/ int32_t* add_to_base,
98 /*out*/ int32_t* offset_for_load_store);
99 int32_t AdjustLoadStoreOffset(int32_t allowed_offset_bits,
100 vixl32::Register temp,
101 vixl32::Register base,
102 int32_t offset);
103 int32_t GetAllowedLoadOffsetBits(LoadOperandType type);
104 int32_t GetAllowedStoreOffsetBits(StoreOperandType type);
105
106 void AddConstant(vixl32::Register rd, int32_t value);
107 void AddConstant(vixl32::Register rd, vixl32::Register rn, int32_t value);
108 void AddConstantInIt(vixl32::Register rd,
109 vixl32::Register rn,
110 int32_t value,
111 vixl32::Condition cond = vixl32::al);
112
113 private:
114 // VIXL assembler.
115 vixl32::MacroAssembler vixl_masm_;
116};
117
118// Thread register declaration.
119extern const vixl32::Register tr;
120
121} // namespace arm
122} // namespace art
123
124#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_ARM_VIXL_H_