blob: 111a6b09d7ed6cd3848fd8f1bb3bb074fd0eb9c0 [file] [log] [blame]
Dave Allison65fcc2c2014-04-28 13:45:27 -07001/*
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_COMPILER_UTILS_ARM_ASSEMBLER_THUMB2_H_
18#define ART_COMPILER_UTILS_ARM_ASSEMBLER_THUMB2_H_
19
Vladimir Markocf93a5c2015-06-16 11:33:24 +000020#include <deque>
Andreas Gampe7cffc3b2015-10-19 21:31:53 -070021#include <utility>
Dave Allison65fcc2c2014-04-28 13:45:27 -070022#include <vector>
23
Vladimir Marko93205e32016-04-13 11:59:46 +010024#include "base/arena_containers.h"
Dave Allison65fcc2c2014-04-28 13:45:27 -070025#include "base/logging.h"
26#include "constants_arm.h"
27#include "utils/arm/managed_register_arm.h"
28#include "utils/arm/assembler_arm.h"
Vladimir Marko6b756b52015-07-14 11:58:38 +010029#include "utils/array_ref.h"
Dave Allison65fcc2c2014-04-28 13:45:27 -070030#include "offsets.h"
Dave Allison65fcc2c2014-04-28 13:45:27 -070031
32namespace art {
33namespace arm {
34
Dave Allison65fcc2c2014-04-28 13:45:27 -070035class Thumb2Assembler FINAL : public ArmAssembler {
36 public:
Vladimir Marko93205e32016-04-13 11:59:46 +010037 explicit Thumb2Assembler(ArenaAllocator* arena, bool can_relocate_branches = true)
38 : ArmAssembler(arena),
39 can_relocate_branches_(can_relocate_branches),
Nicolas Geoffray8d486732014-07-16 16:23:40 +010040 force_32bit_(false),
41 it_cond_index_(kNoItCondition),
Vladimir Markocf93a5c2015-06-16 11:33:24 +000042 next_condition_(AL),
Vladimir Marko93205e32016-04-13 11:59:46 +010043 fixups_(arena->Adapter(kArenaAllocAssembler)),
44 fixup_dependents_(arena->Adapter(kArenaAllocAssembler)),
45 literals_(arena->Adapter(kArenaAllocAssembler)),
46 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Vladimir Markocf93a5c2015-06-16 11:33:24 +000047 last_position_adjustment_(0u),
48 last_old_position_(0u),
49 last_fixup_id_(0u) {
Vladimir Marko10ef6942015-10-22 15:25:54 +010050 cfi().DelayEmittingAdvancePCs();
Dave Allison65fcc2c2014-04-28 13:45:27 -070051 }
52
53 virtual ~Thumb2Assembler() {
Dave Allison65fcc2c2014-04-28 13:45:27 -070054 }
55
56 bool IsThumb() const OVERRIDE {
57 return true;
58 }
59
60 bool IsForced32Bit() const {
61 return force_32bit_;
62 }
63
Nicolas Geoffrayd126ba12015-05-20 11:25:27 +010064 bool CanRelocateBranches() const {
65 return can_relocate_branches_;
Nicolas Geoffray8d486732014-07-16 16:23:40 +010066 }
67
Vladimir Markocf93a5c2015-06-16 11:33:24 +000068 void FinalizeCode() OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070069
70 // Data-processing instructions.
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010071 virtual void and_(Register rd, Register rn, const ShifterOperand& so,
72 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070073
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010074 virtual void eor(Register rd, Register rn, const ShifterOperand& so,
75 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070076
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010077 virtual void sub(Register rd, Register rn, const ShifterOperand& so,
78 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070079
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010080 virtual void rsb(Register rd, Register rn, const ShifterOperand& so,
81 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070082
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010083 virtual void add(Register rd, Register rn, const ShifterOperand& so,
84 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070085
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010086 virtual void adc(Register rd, Register rn, const ShifterOperand& so,
87 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070088
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010089 virtual void sbc(Register rd, Register rn, const ShifterOperand& so,
90 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070091
Vladimir Marko73cf0fb2015-07-30 15:07:22 +010092 virtual void rsc(Register rd, Register rn, const ShifterOperand& so,
93 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -070094
95 void tst(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
96
97 void teq(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
98
99 void cmp(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
100
101 void cmn(Register rn, const ShifterOperand& so, Condition cond = AL) OVERRIDE;
102
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100103 virtual void orr(Register rd, Register rn, const ShifterOperand& so,
104 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700105
Vladimir Markod2b4ca22015-09-14 15:13:26 +0100106 virtual void orn(Register rd, Register rn, const ShifterOperand& so,
107 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
108
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100109 virtual void mov(Register rd, const ShifterOperand& so,
110 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700111
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100112 virtual void bic(Register rd, Register rn, const ShifterOperand& so,
113 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700114
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100115 virtual void mvn(Register rd, const ShifterOperand& so,
116 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700117
118 // Miscellaneous data-processing instructions.
119 void clz(Register rd, Register rm, Condition cond = AL) OVERRIDE;
120 void movw(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE;
121 void movt(Register rd, uint16_t imm16, Condition cond = AL) OVERRIDE;
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100122 void rbit(Register rd, Register rm, Condition cond = AL) OVERRIDE;
Artem Serovc257da72016-02-02 13:49:43 +0000123 void rev(Register rd, Register rm, Condition cond = AL) OVERRIDE;
124 void rev16(Register rd, Register rm, Condition cond = AL) OVERRIDE;
125 void revsh(Register rd, Register rm, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700126
127 // Multiply instructions.
128 void mul(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
129 void mla(Register rd, Register rn, Register rm, Register ra,
130 Condition cond = AL) OVERRIDE;
131 void mls(Register rd, Register rn, Register rm, Register ra,
132 Condition cond = AL) OVERRIDE;
Zheng Xuc6667102015-05-15 16:08:45 +0800133 void smull(Register rd_lo, Register rd_hi, Register rn, Register rm,
134 Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700135 void umull(Register rd_lo, Register rd_hi, Register rn, Register rm,
136 Condition cond = AL) OVERRIDE;
137
138 void sdiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
139 void udiv(Register rd, Register rn, Register rm, Condition cond = AL) OVERRIDE;
140
Roland Levillain981e4542014-11-14 11:47:14 +0000141 // Bit field extract instructions.
Roland Levillain51d3fc42014-11-13 14:11:42 +0000142 void sbfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE;
Roland Levillain981e4542014-11-14 11:47:14 +0000143 void ubfx(Register rd, Register rn, uint32_t lsb, uint32_t width, Condition cond = AL) OVERRIDE;
Roland Levillain51d3fc42014-11-13 14:11:42 +0000144
Dave Allison65fcc2c2014-04-28 13:45:27 -0700145 // Load/store instructions.
146 void ldr(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
147 void str(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
148
149 void ldrb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
150 void strb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
151
152 void ldrh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
153 void strh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
154
155 void ldrsb(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
156 void ldrsh(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
157
Roland Levillain4af147e2015-04-07 13:54:49 +0100158 // Load/store register dual instructions using registers `rd` and `rd` + 1.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700159 void ldrd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
160 void strd(Register rd, const Address& ad, Condition cond = AL) OVERRIDE;
161
Roland Levillain4af147e2015-04-07 13:54:49 +0100162 // Load/store register dual instructions using registers `rd` and `rd2`.
163 // Note that contrary to the ARM A1 encoding, the Thumb-2 T1 encoding
164 // does not require `rd` to be even, nor `rd2' to be equal to `rd` + 1.
165 void ldrd(Register rd, Register rd2, const Address& ad, Condition cond);
166 void strd(Register rd, Register rd2, const Address& ad, Condition cond);
167
168
Dave Allison65fcc2c2014-04-28 13:45:27 -0700169 void ldm(BlockAddressMode am, Register base,
170 RegList regs, Condition cond = AL) OVERRIDE;
171 void stm(BlockAddressMode am, Register base,
172 RegList regs, Condition cond = AL) OVERRIDE;
173
174 void ldrex(Register rd, Register rn, Condition cond = AL) OVERRIDE;
175 void strex(Register rd, Register rt, Register rn, Condition cond = AL) OVERRIDE;
176
177 void ldrex(Register rd, Register rn, uint16_t imm, Condition cond = AL);
178 void strex(Register rd, Register rt, Register rn, uint16_t imm, Condition cond = AL);
179
Calin Juravle52c48962014-12-16 17:02:57 +0000180 void ldrexd(Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE;
181 void strexd(Register rd, Register rt, Register rt2, Register rn, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700182
183 // Miscellaneous instructions.
184 void clrex(Condition cond = AL) OVERRIDE;
185 void nop(Condition cond = AL) OVERRIDE;
186
187 void bkpt(uint16_t imm16) OVERRIDE;
188 void svc(uint32_t imm24) OVERRIDE;
189
190 // If-then
191 void it(Condition firstcond, ItState i1 = kItOmitted,
192 ItState i2 = kItOmitted, ItState i3 = kItOmitted) OVERRIDE;
193
194 void cbz(Register rn, Label* target) OVERRIDE;
195 void cbnz(Register rn, Label* target) OVERRIDE;
196
197 // Floating point instructions (VFPv3-D16 and VFPv3-D32 profiles).
198 void vmovsr(SRegister sn, Register rt, Condition cond = AL) OVERRIDE;
199 void vmovrs(Register rt, SRegister sn, Condition cond = AL) OVERRIDE;
200 void vmovsrr(SRegister sm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
201 void vmovrrs(Register rt, Register rt2, SRegister sm, Condition cond = AL) OVERRIDE;
202 void vmovdrr(DRegister dm, Register rt, Register rt2, Condition cond = AL) OVERRIDE;
203 void vmovrrd(Register rt, Register rt2, DRegister dm, Condition cond = AL) OVERRIDE;
204 void vmovs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
205 void vmovd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
206
207 // Returns false if the immediate cannot be encoded.
208 bool vmovs(SRegister sd, float s_imm, Condition cond = AL) OVERRIDE;
209 bool vmovd(DRegister dd, double d_imm, Condition cond = AL) OVERRIDE;
210
211 void vldrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
212 void vstrs(SRegister sd, const Address& ad, Condition cond = AL) OVERRIDE;
213 void vldrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
214 void vstrd(DRegister dd, const Address& ad, Condition cond = AL) OVERRIDE;
215
216 void vadds(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
217 void vaddd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
218 void vsubs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
219 void vsubd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
220 void vmuls(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
221 void vmuld(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
222 void vmlas(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
223 void vmlad(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
224 void vmlss(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
225 void vmlsd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
226 void vdivs(SRegister sd, SRegister sn, SRegister sm, Condition cond = AL) OVERRIDE;
227 void vdivd(DRegister dd, DRegister dn, DRegister dm, Condition cond = AL) OVERRIDE;
228
229 void vabss(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
230 void vabsd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
231 void vnegs(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
232 void vnegd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
233 void vsqrts(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
234 void vsqrtd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
235
236 void vcvtsd(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
237 void vcvtds(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
238 void vcvtis(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
239 void vcvtid(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
240 void vcvtsi(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
241 void vcvtdi(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
242 void vcvtus(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
243 void vcvtud(SRegister sd, DRegister dm, Condition cond = AL) OVERRIDE;
244 void vcvtsu(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
245 void vcvtdu(DRegister dd, SRegister sm, Condition cond = AL) OVERRIDE;
246
247 void vcmps(SRegister sd, SRegister sm, Condition cond = AL) OVERRIDE;
248 void vcmpd(DRegister dd, DRegister dm, Condition cond = AL) OVERRIDE;
249 void vcmpsz(SRegister sd, Condition cond = AL) OVERRIDE;
250 void vcmpdz(DRegister dd, Condition cond = AL) OVERRIDE;
251 void vmstat(Condition cond = AL) OVERRIDE; // VMRS APSR_nzcv, FPSCR
252
253 void vpushs(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
254 void vpushd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
255 void vpops(SRegister reg, int nregs, Condition cond = AL) OVERRIDE;
256 void vpopd(DRegister reg, int nregs, Condition cond = AL) OVERRIDE;
257
258 // Branch instructions.
259 void b(Label* label, Condition cond = AL);
260 void bl(Label* label, Condition cond = AL);
261 void blx(Label* label);
262 void blx(Register rm, Condition cond = AL) OVERRIDE;
263 void bx(Register rm, Condition cond = AL) OVERRIDE;
264
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100265 virtual void Lsl(Register rd, Register rm, uint32_t shift_imm,
266 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
267 virtual void Lsr(Register rd, Register rm, uint32_t shift_imm,
268 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
269 virtual void Asr(Register rd, Register rm, uint32_t shift_imm,
270 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
271 virtual void Ror(Register rd, Register rm, uint32_t shift_imm,
272 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
273 virtual void Rrx(Register rd, Register rm,
274 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison45fdb932014-06-25 12:37:10 -0700275
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100276 virtual void Lsl(Register rd, Register rm, Register rn,
277 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
278 virtual void Lsr(Register rd, Register rm, Register rn,
279 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
280 virtual void Asr(Register rd, Register rm, Register rn,
281 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
282 virtual void Ror(Register rd, Register rm, Register rn,
283 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700284
285 void Push(Register rd, Condition cond = AL) OVERRIDE;
286 void Pop(Register rd, Condition cond = AL) OVERRIDE;
287
288 void PushList(RegList regs, Condition cond = AL) OVERRIDE;
289 void PopList(RegList regs, Condition cond = AL) OVERRIDE;
290
291 void Mov(Register rd, Register rm, Condition cond = AL) OVERRIDE;
292
293 void CompareAndBranchIfZero(Register r, Label* label) OVERRIDE;
294 void CompareAndBranchIfNonZero(Register r, Label* label) OVERRIDE;
295
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100296 // Memory barriers.
297 void dmb(DmbOptions flavor) OVERRIDE;
298
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000299 // Get the final position of a label after local fixup based on the old position
300 // recorded before FinalizeCode().
301 uint32_t GetAdjustedPosition(uint32_t old_position) OVERRIDE;
302
303 using ArmAssembler::NewLiteral; // Make the helper template visible.
304
305 Literal* NewLiteral(size_t size, const uint8_t* data) OVERRIDE;
306 void LoadLiteral(Register rt, Literal* literal) OVERRIDE;
307 void LoadLiteral(Register rt, Register rt2, Literal* literal) OVERRIDE;
308 void LoadLiteral(SRegister sd, Literal* literal) OVERRIDE;
309 void LoadLiteral(DRegister dd, Literal* literal) OVERRIDE;
310
Dave Allison65fcc2c2014-04-28 13:45:27 -0700311 // Add signed constant value to rd. May clobber IP.
Dave Allison65fcc2c2014-04-28 13:45:27 -0700312 void AddConstant(Register rd, Register rn, int32_t value,
Vladimir Marko449b1092015-09-08 12:16:45 +0100313 Condition cond = AL, SetCc set_cc = kCcDontCare) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700314
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700315 void CmpConstant(Register rn, int32_t value, Condition cond = AL) OVERRIDE;
316
Dave Allison65fcc2c2014-04-28 13:45:27 -0700317 // Load and Store. May clobber IP.
318 void LoadImmediate(Register rd, int32_t value, Condition cond = AL) OVERRIDE;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700319 void MarkExceptionHandler(Label* label) OVERRIDE;
320 void LoadFromOffset(LoadOperandType type,
321 Register reg,
322 Register base,
323 int32_t offset,
324 Condition cond = AL) OVERRIDE;
325 void StoreToOffset(StoreOperandType type,
326 Register reg,
327 Register base,
328 int32_t offset,
329 Condition cond = AL) OVERRIDE;
330 void LoadSFromOffset(SRegister reg,
331 Register base,
332 int32_t offset,
333 Condition cond = AL) OVERRIDE;
334 void StoreSToOffset(SRegister reg,
335 Register base,
336 int32_t offset,
337 Condition cond = AL) OVERRIDE;
338 void LoadDFromOffset(DRegister reg,
339 Register base,
340 int32_t offset,
341 Condition cond = AL) OVERRIDE;
342 void StoreDToOffset(DRegister reg,
343 Register base,
344 int32_t offset,
345 Condition cond = AL) OVERRIDE;
346
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000347 bool ShifterOperandCanHold(Register rd,
348 Register rn,
349 Opcode opcode,
350 uint32_t immediate,
Vladimir Markof5c09c32015-12-17 12:08:08 +0000351 SetCc set_cc,
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000352 ShifterOperand* shifter_op) OVERRIDE;
Vladimir Markof5c09c32015-12-17 12:08:08 +0000353 using ArmAssembler::ShifterOperandCanHold; // Don't hide the non-virtual override.
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000354
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +0100355 bool ShifterOperandCanAlwaysHold(uint32_t immediate) OVERRIDE;
356
Dave Allison65fcc2c2014-04-28 13:45:27 -0700357
Ian Rogers13735952014-10-08 12:43:28 -0700358 static bool IsInstructionForExceptionHandling(uintptr_t pc);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700359
360 // Emit data (e.g. encoded instruction or immediate) to the.
361 // instruction stream.
362 void Emit32(int32_t value); // Emit a 32 bit instruction in thumb format.
363 void Emit16(int16_t value); // Emit a 16 bit instruction in little endian format.
364 void Bind(Label* label) OVERRIDE;
365
366 void MemoryBarrier(ManagedRegister scratch) OVERRIDE;
367
368 // Force the assembler to generate 32 bit instructions.
369 void Force32Bit() {
370 force_32bit_ = true;
371 }
372
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700373 // Emit an ADR (or a sequence of instructions) to load the jump table address into base_reg. This
374 // will generate a fixup.
375 JumpTable* CreateJumpTable(std::vector<Label*>&& labels, Register base_reg) OVERRIDE;
376 // Emit an ADD PC, X to dispatch a jump-table jump. This will generate a fixup.
377 void EmitJumpTableDispatch(JumpTable* jump_table, Register displacement_reg) OVERRIDE;
378
Dave Allison65fcc2c2014-04-28 13:45:27 -0700379 private:
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000380 typedef uint16_t FixupId;
381
382 // Fixup: branches and literal pool references.
383 //
384 // The thumb2 architecture allows branches to be either 16 or 32 bit instructions. This
385 // depends on both the type of branch and the offset to which it is branching. The 16-bit
386 // cbz and cbnz instructions may also need to be replaced with a separate 16-bit compare
387 // instruction and a 16- or 32-bit branch instruction. Load from a literal pool can also be
388 // 16-bit or 32-bit instruction and, if the method is large, we may need to use a sequence
389 // of instructions to make up for the limited range of load literal instructions (up to
390 // 4KiB for the 32-bit variant). When generating code for these insns we don't know the
391 // size before hand, so we assume it is the smallest available size and determine the final
392 // code offsets and sizes and emit code in FinalizeCode().
393 //
394 // To handle this, we keep a record of every branch and literal pool load in the program.
395 // The actual instruction encoding for these is delayed until we know the final size of
396 // every instruction. When we bind a label to a branch we don't know the final location yet
397 // as some preceding instructions may need to be expanded, so we record a non-final offset.
398 // In FinalizeCode(), we expand the sizes of branches and literal loads that are out of
399 // range. With each expansion, we need to update dependent Fixups, i.e. insntructios with
400 // target on the other side of the expanded insn, as their offsets change and this may
401 // trigger further expansion.
402 //
403 // All Fixups have a 'fixup id' which is a 16 bit unsigned number used to identify the
404 // Fixup. For each unresolved label we keep a singly-linked list of all Fixups pointing
405 // to it, using the fixup ids as links. The first link is stored in the label's position
406 // (the label is linked but not bound), the following links are stored in the code buffer,
407 // in the placeholder where we will eventually emit the actual code.
408
409 class Fixup {
410 public:
411 // Branch type.
412 enum Type : uint8_t {
413 kConditional, // B<cond>.
414 kUnconditional, // B.
415 kUnconditionalLink, // BL.
416 kUnconditionalLinkX, // BLX.
417 kCompareAndBranchXZero, // cbz/cbnz.
418 kLoadLiteralNarrow, // Load narrrow integer literal.
419 kLoadLiteralWide, // Load wide integer literal.
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700420 kLoadLiteralAddr, // Load address of literal (used for jump table).
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000421 kLoadFPLiteralSingle, // Load FP literal single.
422 kLoadFPLiteralDouble, // Load FP literal double.
423 };
424
425 // Calculated size of branch instruction based on type and offset.
426 enum Size : uint8_t {
427 // Branch variants.
428 kBranch16Bit,
429 kBranch32Bit,
430 // NOTE: We don't support branches which would require multiple instructions, i.e.
431 // conditinoal branches beyond +-1MiB and unconditional branches beyond +-16MiB.
432
433 // CBZ/CBNZ variants.
434 kCbxz16Bit, // CBZ/CBNZ rX, label; X < 8; 7-bit positive offset.
435 kCbxz32Bit, // CMP rX, #0 + Bcc label; X < 8; 16-bit Bcc; +-8-bit offset.
436 kCbxz48Bit, // CMP rX, #0 + Bcc label; X < 8; 32-bit Bcc; up to +-1MiB offset.
437
438 // Load integer literal variants.
439 // LDR rX, label; X < 8; 16-bit variant up to 1KiB offset; 2 bytes.
440 kLiteral1KiB,
441 // LDR rX, label; 32-bit variant up to 4KiB offset; 4 bytes.
442 kLiteral4KiB,
443 // MOV rX, imm16 + ADD rX, pc + LDR rX, [rX]; X < 8; up to 64KiB offset; 8 bytes.
444 kLiteral64KiB,
445 // MOV rX, modimm + ADD rX, pc + LDR rX, [rX, #imm12]; up to 1MiB offset; 10 bytes.
446 kLiteral1MiB,
447 // NOTE: We don't provide the 12-byte version of kLiteralFar below where the LDR is 16-bit.
448 // MOV rX, imm16 + MOVT rX, imm16 + ADD rX, pc + LDR rX, [rX]; any offset; 14 bytes.
449 kLiteralFar,
450
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700451 // Load literal base addr.
452 // ADR rX, label; X < 8; 8 bit immediate, shifted to 10 bit. 2 bytes.
453 kLiteralAddr1KiB,
454 // ADR rX, label; 4KiB offset. 4 bytes.
455 kLiteralAddr4KiB,
456 // MOV rX, imm16 + ADD rX, pc; 64KiB offset. 6 bytes.
457 kLiteralAddr64KiB,
458 // MOV rX, imm16 + MOVT rX, imm16 + ADD rX, pc; any offset; 10 bytes.
459 kLiteralAddrFar,
460
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000461 // Load long or FP literal variants.
462 // VLDR s/dX, label; 32-bit insn, up to 1KiB offset; 4 bytes.
463 kLongOrFPLiteral1KiB,
464 // MOV ip, modimm + ADD ip, pc + VLDR s/dX, [IP, #imm8*4]; up to 256KiB offset; 10 bytes.
465 kLongOrFPLiteral256KiB,
466 // MOV ip, imm16 + MOVT ip, imm16 + ADD ip, pc + VLDR s/dX, [IP]; any offset; 14 bytes.
467 kLongOrFPLiteralFar,
468 };
469
470 // Unresolved branch possibly with a condition.
471 static Fixup Branch(uint32_t location, Type type, Size size = kBranch16Bit,
472 Condition cond = AL) {
473 DCHECK(type == kConditional || type == kUnconditional ||
474 type == kUnconditionalLink || type == kUnconditionalLinkX);
475 DCHECK(size == kBranch16Bit || size == kBranch32Bit);
476 DCHECK(size == kBranch32Bit || (type == kConditional || type == kUnconditional));
477 return Fixup(kNoRegister, kNoRegister, kNoSRegister, kNoDRegister,
478 cond, type, size, location);
479 }
480
481 // Unresolved compare-and-branch instruction with a register and condition (EQ or NE).
482 static Fixup CompareAndBranch(uint32_t location, Register rn, Condition cond) {
483 DCHECK(cond == EQ || cond == NE);
484 return Fixup(rn, kNoRegister, kNoSRegister, kNoDRegister,
485 cond, kCompareAndBranchXZero, kCbxz16Bit, location);
486 }
487
488 // Load narrow literal.
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700489 static Fixup LoadNarrowLiteral(uint32_t location, Register rt, Size size) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000490 DCHECK(size == kLiteral1KiB || size == kLiteral4KiB || size == kLiteral64KiB ||
491 size == kLiteral1MiB || size == kLiteralFar);
492 DCHECK(!IsHighRegister(rt) || (size != kLiteral1KiB && size != kLiteral64KiB));
493 return Fixup(rt, kNoRegister, kNoSRegister, kNoDRegister,
494 AL, kLoadLiteralNarrow, size, location);
495 }
496
497 // Load wide literal.
498 static Fixup LoadWideLiteral(uint32_t location, Register rt, Register rt2,
499 Size size = kLongOrFPLiteral1KiB) {
500 DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB ||
501 size == kLongOrFPLiteralFar);
502 DCHECK(!IsHighRegister(rt) || (size != kLiteral1KiB && size != kLiteral64KiB));
503 return Fixup(rt, rt2, kNoSRegister, kNoDRegister,
504 AL, kLoadLiteralWide, size, location);
505 }
506
507 // Load FP single literal.
508 static Fixup LoadSingleLiteral(uint32_t location, SRegister sd,
509 Size size = kLongOrFPLiteral1KiB) {
510 DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB ||
511 size == kLongOrFPLiteralFar);
512 return Fixup(kNoRegister, kNoRegister, sd, kNoDRegister,
513 AL, kLoadFPLiteralSingle, size, location);
514 }
515
516 // Load FP double literal.
517 static Fixup LoadDoubleLiteral(uint32_t location, DRegister dd,
518 Size size = kLongOrFPLiteral1KiB) {
519 DCHECK(size == kLongOrFPLiteral1KiB || size == kLongOrFPLiteral256KiB ||
520 size == kLongOrFPLiteralFar);
521 return Fixup(kNoRegister, kNoRegister, kNoSRegister, dd,
522 AL, kLoadFPLiteralDouble, size, location);
523 }
524
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700525 static Fixup LoadLiteralAddress(uint32_t location, Register rt, Size size) {
526 DCHECK(size == kLiteralAddr1KiB || size == kLiteralAddr4KiB || size == kLiteralAddr64KiB ||
527 size == kLiteralAddrFar);
528 DCHECK(!IsHighRegister(rt) || size != kLiteralAddr1KiB);
529 return Fixup(rt, kNoRegister, kNoSRegister, kNoDRegister,
530 AL, kLoadLiteralAddr, size, location);
531 }
532
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000533 Type GetType() const {
534 return type_;
535 }
536
Vladimir Marko663c9342015-07-22 11:28:14 +0100537 bool IsLoadLiteral() const {
538 return GetType() >= kLoadLiteralNarrow;
539 }
540
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000541 Size GetOriginalSize() const {
542 return original_size_;
543 }
544
545 Size GetSize() const {
546 return size_;
547 }
548
549 uint32_t GetOriginalSizeInBytes() const;
550
551 uint32_t GetSizeInBytes() const;
552
553 uint32_t GetLocation() const {
554 return location_;
555 }
556
557 uint32_t GetAdjustment() const {
558 return adjustment_;
559 }
560
Vladimir Marko6b756b52015-07-14 11:58:38 +0100561 // Prepare the assembler->fixup_dependents_ and each Fixup's dependents_start_/count_.
562 static void PrepareDependents(Thumb2Assembler* assembler);
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000563
Vladimir Marko93205e32016-04-13 11:59:46 +0100564 ArrayRef<const FixupId> Dependents(const Thumb2Assembler& assembler) const {
565 return ArrayRef<const FixupId>(assembler.fixup_dependents_).SubArray(dependents_start_,
566 dependents_count_);
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000567 }
568
569 // Resolve a branch when the target is known.
570 void Resolve(uint32_t target) {
571 DCHECK_EQ(target_, kUnresolved);
572 DCHECK_NE(target, kUnresolved);
573 target_ = target;
574 }
575
576 // Check if the current size is OK for current location_, target_ and adjustment_.
577 // If not, increase the size. Return the size increase, 0 if unchanged.
578 // If the target if after this Fixup, also add the difference to adjustment_,
579 // so that we don't need to consider forward Fixups as their own dependencies.
580 uint32_t AdjustSizeIfNeeded(uint32_t current_code_size);
581
582 // Increase adjustments. This is called for dependents of a Fixup when its size changes.
583 void IncreaseAdjustment(uint32_t increase) {
584 adjustment_ += increase;
585 }
586
587 // Finalize the branch with an adjustment to the location. Both location and target are updated.
588 void Finalize(uint32_t location_adjustment) {
589 DCHECK_NE(target_, kUnresolved);
590 location_ += location_adjustment;
591 target_ += location_adjustment;
592 }
593
594 // Emit the branch instruction into the assembler buffer. This does the
595 // encoding into the thumb instruction.
596 void Emit(AssemblerBuffer* buffer, uint32_t code_size) const;
597
598 private:
599 Fixup(Register rn, Register rt2, SRegister sd, DRegister dd,
600 Condition cond, Type type, Size size, uint32_t location)
601 : rn_(rn),
602 rt2_(rt2),
603 sd_(sd),
604 dd_(dd),
605 cond_(cond),
606 type_(type),
607 original_size_(size), size_(size),
608 location_(location),
609 target_(kUnresolved),
610 adjustment_(0u),
Vladimir Marko6b756b52015-07-14 11:58:38 +0100611 dependents_count_(0u),
612 dependents_start_(0u) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000613 }
614 static size_t SizeInBytes(Size size);
615
616 // The size of padding added before the literal pool.
617 static size_t LiteralPoolPaddingSize(uint32_t current_code_size);
618
619 // Returns the offset from the PC-using insn to the target.
620 int32_t GetOffset(uint32_t current_code_size) const;
621
622 size_t IncreaseSize(Size new_size);
623
624 int32_t LoadWideOrFpEncoding(Register rbase, int32_t offset) const;
625
626 static constexpr uint32_t kUnresolved = 0xffffffff; // Value for target_ for unresolved.
627
628 const Register rn_; // Rn for cbnz/cbz, Rt for literal loads.
629 Register rt2_; // For kLoadLiteralWide.
630 SRegister sd_; // For kLoadFPLiteralSingle.
631 DRegister dd_; // For kLoadFPLiteralDouble.
632 const Condition cond_;
633 const Type type_;
634 Size original_size_;
635 Size size_;
636 uint32_t location_; // Offset into assembler buffer in bytes.
637 uint32_t target_; // Offset into assembler buffer in bytes.
638 uint32_t adjustment_; // The number of extra bytes inserted between location_ and target_.
Vladimir Marko6b756b52015-07-14 11:58:38 +0100639 // Fixups that require adjustment when current size changes are stored in a single
640 // array in the assembler and we store only the start index and count here.
641 uint32_t dependents_count_;
642 uint32_t dependents_start_;
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000643 };
644
Dave Allison65fcc2c2014-04-28 13:45:27 -0700645 // Emit a single 32 or 16 bit data processing instruction.
646 void EmitDataProcessing(Condition cond,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700647 Opcode opcode,
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100648 SetCc set_cc,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700649 Register rn,
650 Register rd,
651 const ShifterOperand& so);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700652
Artem Serovc257da72016-02-02 13:49:43 +0000653 // Emit a single 32 bit miscellaneous instruction.
654 void Emit32Miscellaneous(uint8_t op1,
655 uint8_t op2,
656 uint32_t rest_encoding);
657
658 // Emit reverse byte instructions: rev, rev16, revsh.
659 void EmitReverseBytes(Register rd, Register rm, uint32_t op);
660
661 // Emit a single 16 bit miscellaneous instruction.
662 void Emit16Miscellaneous(uint32_t rest_encoding);
663
Dave Allison65fcc2c2014-04-28 13:45:27 -0700664 // Must the instruction be 32 bits or can it possibly be encoded
665 // in 16 bits?
666 bool Is32BitDataProcessing(Condition cond,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700667 Opcode opcode,
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100668 SetCc set_cc,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700669 Register rn,
670 Register rd,
671 const ShifterOperand& so);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700672
673 // Emit a 32 bit data processing instruction.
674 void Emit32BitDataProcessing(Condition cond,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700675 Opcode opcode,
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100676 SetCc set_cc,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700677 Register rn,
678 Register rd,
679 const ShifterOperand& so);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700680
681 // Emit a 16 bit data processing instruction.
682 void Emit16BitDataProcessing(Condition cond,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700683 Opcode opcode,
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100684 SetCc set_cc,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700685 Register rn,
686 Register rd,
687 const ShifterOperand& so);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700688
689 void Emit16BitAddSub(Condition cond,
690 Opcode opcode,
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100691 SetCc set_cc,
Dave Allison65fcc2c2014-04-28 13:45:27 -0700692 Register rn,
693 Register rd,
694 const ShifterOperand& so);
695
696 uint16_t EmitCompareAndBranch(Register rn, uint16_t prev, bool n);
697
698 void EmitLoadStore(Condition cond,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700699 bool load,
700 bool byte,
701 bool half,
702 bool is_signed,
703 Register rd,
704 const Address& ad);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700705
706 void EmitMemOpAddressMode3(Condition cond,
707 int32_t mode,
708 Register rd,
709 const Address& ad);
710
711 void EmitMultiMemOp(Condition cond,
712 BlockAddressMode am,
713 bool load,
714 Register base,
715 RegList regs);
716
717 void EmitMulOp(Condition cond,
718 int32_t opcode,
719 Register rd,
720 Register rn,
721 Register rm,
722 Register rs);
723
724 void EmitVFPsss(Condition cond,
725 int32_t opcode,
726 SRegister sd,
727 SRegister sn,
728 SRegister sm);
729
730 void EmitVFPddd(Condition cond,
731 int32_t opcode,
732 DRegister dd,
733 DRegister dn,
734 DRegister dm);
735
736 void EmitVFPsd(Condition cond,
737 int32_t opcode,
738 SRegister sd,
739 DRegister dm);
740
741 void EmitVFPds(Condition cond,
742 int32_t opcode,
743 DRegister dd,
744 SRegister sm);
745
746 void EmitVPushPop(uint32_t reg, int nregs, bool push, bool dbl, Condition cond);
747
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000748 void EmitBranch(Condition cond, Label* label, bool link, bool x);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700749 static int32_t EncodeBranchOffset(int32_t offset, int32_t inst);
750 static int DecodeBranchOffset(int32_t inst);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +0100751 void EmitShift(Register rd, Register rm, Shift shift, uint8_t amount,
752 Condition cond = AL, SetCc set_cc = kCcDontCare);
753 void EmitShift(Register rd, Register rn, Shift shift, Register rm,
754 Condition cond = AL, SetCc set_cc = kCcDontCare);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700755
Vladimir Marko6fd0ffe2015-11-19 21:13:52 +0000756 static int32_t GetAllowedLoadOffsetBits(LoadOperandType type);
757 static int32_t GetAllowedStoreOffsetBits(StoreOperandType type);
758 bool CanSplitLoadStoreOffset(int32_t allowed_offset_bits,
759 int32_t offset,
760 /*out*/ int32_t* add_to_base,
761 /*out*/ int32_t* offset_for_load_store);
762 int32_t AdjustLoadStoreOffset(int32_t allowed_offset_bits,
763 Register temp,
764 Register base,
765 int32_t offset,
766 Condition cond);
767
Nicolas Geoffrayd126ba12015-05-20 11:25:27 +0100768 // Whether the assembler can relocate branches. If false, unresolved branches will be
769 // emitted on 32bits.
770 bool can_relocate_branches_;
771
772 // Force the assembler to use 32 bit thumb2 instructions.
773 bool force_32bit_;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700774
775 // IfThen conditions. Used to check that conditional instructions match the preceding IT.
776 Condition it_conditions_[4];
777 uint8_t it_cond_index_;
778 Condition next_condition_;
779
780 void SetItCondition(ItState s, Condition cond, uint8_t index);
781
782 void CheckCondition(Condition cond) {
783 CHECK_EQ(cond, next_condition_);
784
785 // Move to the next condition if there is one.
786 if (it_cond_index_ < 3) {
787 ++it_cond_index_;
788 next_condition_ = it_conditions_[it_cond_index_];
789 } else {
790 next_condition_ = AL;
791 }
792 }
793
794 void CheckConditionLastIt(Condition cond) {
795 if (it_cond_index_ < 3) {
796 // Check that the next condition is AL. This means that the
797 // current condition is the last in the IT block.
798 CHECK_EQ(it_conditions_[it_cond_index_ + 1], AL);
799 }
800 CheckCondition(cond);
801 }
802
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000803 FixupId AddFixup(Fixup fixup) {
804 FixupId fixup_id = static_cast<FixupId>(fixups_.size());
805 fixups_.push_back(fixup);
806 // For iterating using FixupId, we need the next id to be representable.
807 DCHECK_EQ(static_cast<size_t>(static_cast<FixupId>(fixups_.size())), fixups_.size());
808 return fixup_id;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700809 }
810
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000811 Fixup* GetFixup(FixupId fixup_id) {
812 DCHECK_LT(fixup_id, fixups_.size());
813 return &fixups_[fixup_id];
Dave Allison65fcc2c2014-04-28 13:45:27 -0700814 }
815
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000816 void BindLabel(Label* label, uint32_t bound_pc);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700817 uint32_t BindLiterals();
818 void BindJumpTables(uint32_t code_size);
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000819 void AdjustFixupIfNeeded(Fixup* fixup, uint32_t* current_code_size,
820 std::deque<FixupId>* fixups_to_recalculate);
821 uint32_t AdjustFixups();
822 void EmitFixups(uint32_t adjusted_code_size);
823 void EmitLiterals();
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700824 void EmitJumpTables();
Vladimir Marko10ef6942015-10-22 15:25:54 +0100825 void PatchCFI();
Dave Allison65fcc2c2014-04-28 13:45:27 -0700826
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000827 static int16_t BEncoding16(int32_t offset, Condition cond);
828 static int32_t BEncoding32(int32_t offset, Condition cond);
829 static int16_t CbxzEncoding16(Register rn, int32_t offset, Condition cond);
830 static int16_t CmpRnImm8Encoding16(Register rn, int32_t value);
831 static int16_t AddRdnRmEncoding16(Register rdn, Register rm);
832 static int32_t MovwEncoding32(Register rd, int32_t value);
833 static int32_t MovtEncoding32(Register rd, int32_t value);
834 static int32_t MovModImmEncoding32(Register rd, int32_t value);
835 static int16_t LdrLitEncoding16(Register rt, int32_t offset);
836 static int32_t LdrLitEncoding32(Register rt, int32_t offset);
837 static int32_t LdrdEncoding32(Register rt, Register rt2, Register rn, int32_t offset);
838 static int32_t VldrsEncoding32(SRegister sd, Register rn, int32_t offset);
839 static int32_t VldrdEncoding32(DRegister dd, Register rn, int32_t offset);
840 static int16_t LdrRtRnImm5Encoding16(Register rt, Register rn, int32_t offset);
841 static int32_t LdrRtRnImm12Encoding(Register rt, Register rn, int32_t offset);
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700842 static int16_t AdrEncoding16(Register rd, int32_t offset);
843 static int32_t AdrEncoding32(Register rd, int32_t offset);
Dave Allison65fcc2c2014-04-28 13:45:27 -0700844
Vladimir Marko93205e32016-04-13 11:59:46 +0100845 ArenaVector<Fixup> fixups_;
846 ArenaVector<FixupId> fixup_dependents_;
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000847
848 // Use std::deque<> for literal labels to allow insertions at the end
849 // without invalidating pointers and references to existing elements.
Vladimir Marko93205e32016-04-13 11:59:46 +0100850 ArenaDeque<Literal> literals_;
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000851
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700852 // Jump table list.
Vladimir Marko93205e32016-04-13 11:59:46 +0100853 ArenaDeque<JumpTable> jump_tables_;
Andreas Gampe7cffc3b2015-10-19 21:31:53 -0700854
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000855 // Data for AdjustedPosition(), see the description there.
856 uint32_t last_position_adjustment_;
857 uint32_t last_old_position_;
858 FixupId last_fixup_id_;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700859};
860
861} // namespace arm
862} // namespace art
863
864#endif // ART_COMPILER_UTILS_ARM_ASSEMBLER_THUMB2_H_