blob: 923ecdbd9dfc37c1621e33c50472a9e23f48a145 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_ASSEMBLER_H_
18#define ART_COMPILER_UTILS_ASSEMBLER_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Ian Rogers2c8f6532011-09-02 17:16:34 -070020#include <vector>
21
Ian Rogersd582fa42014-11-05 23:46:43 -080022#include "arch/instruction_set.h"
Elliott Hughes07ed66b2012-12-12 18:34:25 -080023#include "base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Ian Rogers166db042013-07-26 12:05:57 -070025#include "arm/constants_arm.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "managed_register.h"
27#include "memory_region.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080028#include "mips/constants_mips.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "offsets.h"
Ian Rogersd582fa42014-11-05 23:46:43 -080030#include "x86/constants_x86.h"
31#include "x86_64/constants_x86_64.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070032
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070033namespace art {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070034
35class Assembler;
36class AssemblerBuffer;
37class AssemblerFixup;
38
Ian Rogers2c8f6532011-09-02 17:16:34 -070039namespace arm {
40 class ArmAssembler;
Dave Allison65fcc2c2014-04-28 13:45:27 -070041 class Arm32Assembler;
42 class Thumb2Assembler;
Ian Rogers2c8f6532011-09-02 17:16:34 -070043}
Stuart Monteithb95a5342014-03-12 13:32:32 +000044namespace arm64 {
45 class Arm64Assembler;
46}
jeffhao7fbee072012-08-24 17:56:54 -070047namespace mips {
48 class MipsAssembler;
49}
Andreas Gampe57b34292015-01-14 15:45:59 -080050namespace mips64 {
51 class Mips64Assembler;
52}
Ian Rogers2c8f6532011-09-02 17:16:34 -070053namespace x86 {
54 class X86Assembler;
55}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070056namespace x86_64 {
57 class X86_64Assembler;
58}
Ian Rogers2c8f6532011-09-02 17:16:34 -070059
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000060class ExternalLabel {
61 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080062 ExternalLabel(const char* name_in, uintptr_t address_in)
63 : name_(name_in), address_(address_in) {
64 DCHECK(name_in != nullptr);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000065 }
66
67 const char* name() const { return name_; }
Ian Rogers13735952014-10-08 12:43:28 -070068 uintptr_t address() const {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000069 return address_;
70 }
71
72 private:
73 const char* name_;
Ian Rogers13735952014-10-08 12:43:28 -070074 const uintptr_t address_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000075};
76
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070077class Label {
78 public:
79 Label() : position_(0) {}
80
81 ~Label() {
82 // Assert if label is being destroyed with unresolved branches pending.
83 CHECK(!IsLinked());
84 }
85
86 // Returns the position for bound and linked labels. Cannot be used
87 // for unused labels.
88 int Position() const {
89 CHECK(!IsUnused());
Ian Rogers13735952014-10-08 12:43:28 -070090 return IsBound() ? -position_ - sizeof(void*) : position_ - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070091 }
92
93 int LinkPosition() const {
94 CHECK(IsLinked());
Ian Rogers13735952014-10-08 12:43:28 -070095 return position_ - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070096 }
97
98 bool IsBound() const { return position_ < 0; }
99 bool IsUnused() const { return position_ == 0; }
100 bool IsLinked() const { return position_ > 0; }
101
102 private:
103 int position_;
104
105 void Reinitialize() {
106 position_ = 0;
107 }
108
109 void BindTo(int position) {
110 CHECK(!IsBound());
Ian Rogers13735952014-10-08 12:43:28 -0700111 position_ = -position - sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700112 CHECK(IsBound());
113 }
114
115 void LinkTo(int position) {
116 CHECK(!IsBound());
Ian Rogers13735952014-10-08 12:43:28 -0700117 position_ = position + sizeof(void*);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700118 CHECK(IsLinked());
119 }
120
Ian Rogers2c8f6532011-09-02 17:16:34 -0700121 friend class arm::ArmAssembler;
Dave Allison65fcc2c2014-04-28 13:45:27 -0700122 friend class arm::Arm32Assembler;
123 friend class arm::Thumb2Assembler;
Alexandre Rames5319def2014-10-23 10:03:10 +0100124 friend class arm64::Arm64Assembler;
jeffhao7fbee072012-08-24 17:56:54 -0700125 friend class mips::MipsAssembler;
Andreas Gampe57b34292015-01-14 15:45:59 -0800126 friend class mips64::Mips64Assembler;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700127 friend class x86::X86Assembler;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700128 friend class x86_64::X86_64Assembler;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700129
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700130 DISALLOW_COPY_AND_ASSIGN(Label);
131};
132
133
134// Assembler fixups are positions in generated code that require processing
135// after the code has been copied to executable memory. This includes building
136// relocation information.
137class AssemblerFixup {
138 public:
139 virtual void Process(const MemoryRegion& region, int position) = 0;
140 virtual ~AssemblerFixup() {}
141
142 private:
143 AssemblerFixup* previous_;
144 int position_;
145
146 AssemblerFixup* previous() const { return previous_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800147 void set_previous(AssemblerFixup* previous_in) { previous_ = previous_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700148
149 int position() const { return position_; }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800150 void set_position(int position_in) { position_ = position_in; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700151
152 friend class AssemblerBuffer;
153};
154
Ian Rogers45a76cb2011-07-21 22:00:15 -0700155// Parent of all queued slow paths, emitted during finalization
156class SlowPath {
157 public:
158 SlowPath() : next_(NULL) {}
159 virtual ~SlowPath() {}
160
161 Label* Continuation() { return &continuation_; }
162 Label* Entry() { return &entry_; }
163 // Generate code for slow path
164 virtual void Emit(Assembler *sp_asm) = 0;
165
166 protected:
167 // Entry branched to by fast path
168 Label entry_;
169 // Optional continuation that is branched to at the end of the slow path
170 Label continuation_;
171 // Next in linked list of slow paths
172 SlowPath *next_;
173
Mathieu Chartier02e25112013-08-14 16:14:24 -0700174 private:
Ian Rogers45a76cb2011-07-21 22:00:15 -0700175 friend class AssemblerBuffer;
176 DISALLOW_COPY_AND_ASSIGN(SlowPath);
177};
178
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700179class AssemblerBuffer {
180 public:
181 AssemblerBuffer();
182 ~AssemblerBuffer();
183
184 // Basic support for emitting, loading, and storing.
185 template<typename T> void Emit(T value) {
186 CHECK(HasEnsuredCapacity());
187 *reinterpret_cast<T*>(cursor_) = value;
188 cursor_ += sizeof(T);
189 }
190
191 template<typename T> T Load(size_t position) {
192 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
193 return *reinterpret_cast<T*>(contents_ + position);
194 }
195
196 template<typename T> void Store(size_t position, T value) {
197 CHECK_LE(position, Size() - static_cast<int>(sizeof(T)));
198 *reinterpret_cast<T*>(contents_ + position) = value;
199 }
200
Dave Allison65fcc2c2014-04-28 13:45:27 -0700201 void Move(size_t newposition, size_t oldposition) {
202 CHECK(HasEnsuredCapacity());
203 // Move the contents of the buffer from oldposition to
204 // newposition by nbytes.
205 size_t nbytes = Size() - oldposition;
206 memmove(contents_ + newposition, contents_ + oldposition, nbytes);
207 cursor_ += newposition - oldposition;
208 }
209
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700210 // Emit a fixup at the current location.
211 void EmitFixup(AssemblerFixup* fixup) {
212 fixup->set_previous(fixup_);
213 fixup->set_position(Size());
214 fixup_ = fixup;
215 }
216
Ian Rogers45a76cb2011-07-21 22:00:15 -0700217 void EnqueueSlowPath(SlowPath* slowpath) {
218 if (slow_path_ == NULL) {
219 slow_path_ = slowpath;
220 } else {
221 SlowPath* cur = slow_path_;
222 for ( ; cur->next_ != NULL ; cur = cur->next_) {}
223 cur->next_ = slowpath;
224 }
225 }
226
227 void EmitSlowPaths(Assembler* sp_asm) {
228 SlowPath* cur = slow_path_;
229 SlowPath* next = NULL;
230 slow_path_ = NULL;
231 for ( ; cur != NULL ; cur = next) {
232 cur->Emit(sp_asm);
233 next = cur->next_;
234 delete cur;
235 }
236 }
237
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700238 // Get the size of the emitted code.
239 size_t Size() const {
240 CHECK_GE(cursor_, contents_);
241 return cursor_ - contents_;
242 }
243
Ian Rogers13735952014-10-08 12:43:28 -0700244 uint8_t* contents() const { return contents_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700245
246 // Copy the assembled instructions into the specified memory block
247 // and apply all fixups.
248 void FinalizeInstructions(const MemoryRegion& region);
249
250 // To emit an instruction to the assembler buffer, the EnsureCapacity helper
251 // must be used to guarantee that the underlying data area is big enough to
252 // hold the emitted instruction. Usage:
253 //
254 // AssemblerBuffer buffer;
255 // AssemblerBuffer::EnsureCapacity ensured(&buffer);
256 // ... emit bytes for single instruction ...
257
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700258#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700259
260 class EnsureCapacity {
261 public:
262 explicit EnsureCapacity(AssemblerBuffer* buffer) {
Elliott Hughes31f1f4f2012-03-12 13:57:36 -0700263 if (buffer->cursor() >= buffer->limit()) {
264 buffer->ExtendCapacity();
265 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700266 // In debug mode, we save the assembler buffer along with the gap
267 // size before we start emitting to the buffer. This allows us to
268 // check that any single generated instruction doesn't overflow the
269 // limit implied by the minimum gap size.
270 buffer_ = buffer;
271 gap_ = ComputeGap();
272 // Make sure that extending the capacity leaves a big enough gap
273 // for any kind of instruction.
274 CHECK_GE(gap_, kMinimumGap);
275 // Mark the buffer as having ensured the capacity.
276 CHECK(!buffer->HasEnsuredCapacity()); // Cannot nest.
277 buffer->has_ensured_capacity_ = true;
278 }
279
280 ~EnsureCapacity() {
281 // Unmark the buffer, so we cannot emit after this.
282 buffer_->has_ensured_capacity_ = false;
283 // Make sure the generated instruction doesn't take up more
284 // space than the minimum gap.
285 int delta = gap_ - ComputeGap();
Ian Rogersb033c752011-07-20 12:22:35 -0700286 CHECK_LE(delta, kMinimumGap);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700287 }
288
289 private:
290 AssemblerBuffer* buffer_;
291 int gap_;
292
293 int ComputeGap() { return buffer_->Capacity() - buffer_->Size(); }
294 };
295
296 bool has_ensured_capacity_;
297 bool HasEnsuredCapacity() const { return has_ensured_capacity_; }
298
299#else
300
301 class EnsureCapacity {
302 public:
303 explicit EnsureCapacity(AssemblerBuffer* buffer) {
304 if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity();
305 }
306 };
307
308 // When building the C++ tests, assertion code is enabled. To allow
309 // asserting that the user of the assembler buffer has ensured the
310 // capacity needed for emitting, we add a dummy method in non-debug mode.
311 bool HasEnsuredCapacity() const { return true; }
312
313#endif
314
315 // Returns the position in the instruction stream.
316 int GetPosition() { return cursor_ - contents_; }
317
318 private:
319 // The limit is set to kMinimumGap bytes before the end of the data area.
320 // This leaves enough space for the longest possible instruction and allows
321 // for a single, fast space check per instruction.
322 static const int kMinimumGap = 32;
323
Ian Rogers13735952014-10-08 12:43:28 -0700324 uint8_t* contents_;
325 uint8_t* cursor_;
326 uint8_t* limit_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700327 AssemblerFixup* fixup_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800328#ifndef NDEBUG
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700329 bool fixups_processed_;
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800330#endif
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700331
Ian Rogers45a76cb2011-07-21 22:00:15 -0700332 // Head of linked list of slow paths
333 SlowPath* slow_path_;
334
Ian Rogers13735952014-10-08 12:43:28 -0700335 uint8_t* cursor() const { return cursor_; }
336 uint8_t* limit() const { return limit_; }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700337 size_t Capacity() const {
338 CHECK_GE(limit_, contents_);
339 return (limit_ - contents_) + kMinimumGap;
340 }
341
342 // Process the fixup chain starting at the given fixup. The offset is
343 // non-zero for fixups in the body if the preamble is non-empty.
344 void ProcessFixups(const MemoryRegion& region);
345
346 // Compute the limit based on the data area and the capacity. See
347 // description of kMinimumGap for the reasoning behind the value.
Ian Rogers13735952014-10-08 12:43:28 -0700348 static uint8_t* ComputeLimit(uint8_t* data, size_t capacity) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700349 return data + capacity - kMinimumGap;
350 }
351
352 void ExtendCapacity();
353
354 friend class AssemblerFixup;
355};
356
Ian Rogers2c8f6532011-09-02 17:16:34 -0700357class Assembler {
358 public:
359 static Assembler* Create(InstructionSet instruction_set);
360
361 // Emit slow paths queued during assembly
Serban Constantinescued8dd492014-02-11 14:15:10 +0000362 virtual void EmitSlowPaths() { buffer_.EmitSlowPaths(this); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700363
364 // Size of generated code
Serban Constantinescued8dd492014-02-11 14:15:10 +0000365 virtual size_t CodeSize() const { return buffer_.Size(); }
Ian Rogers2c8f6532011-09-02 17:16:34 -0700366
367 // Copy instructions out of assembly buffer into the given region of memory
Serban Constantinescued8dd492014-02-11 14:15:10 +0000368 virtual void FinalizeInstructions(const MemoryRegion& region) {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700369 buffer_.FinalizeInstructions(region);
370 }
371
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000372 // TODO: Implement with disassembler.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700373 virtual void Comment(const char* format, ...) { UNUSED(format); }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000374
Ian Rogers2c8f6532011-09-02 17:16:34 -0700375 // Emit code that will create an activation on the stack
376 virtual void BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersb5d09b22012-03-06 22:14:17 -0800377 const std::vector<ManagedRegister>& callee_save_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700378 const ManagedRegisterEntrySpills& entry_spills) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700379
380 // Emit code that will remove an activation from the stack
381 virtual void RemoveFrame(size_t frame_size,
Ian Rogersbdb03912011-09-14 00:55:44 -0700382 const std::vector<ManagedRegister>& callee_save_regs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700383
384 virtual void IncreaseFrameSize(size_t adjust) = 0;
385 virtual void DecreaseFrameSize(size_t adjust) = 0;
386
387 // Store routines
388 virtual void Store(FrameOffset offs, ManagedRegister src, size_t size) = 0;
389 virtual void StoreRef(FrameOffset dest, ManagedRegister src) = 0;
390 virtual void StoreRawPtr(FrameOffset dest, ManagedRegister src) = 0;
391
392 virtual void StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
393 ManagedRegister scratch) = 0;
394
Ian Rogersdd7624d2014-03-14 17:43:00 -0700395 virtual void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm,
396 ManagedRegister scratch);
397 virtual void StoreImmediateToThread64(ThreadOffset<8> dest, uint32_t imm,
398 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700399
Ian Rogersdd7624d2014-03-14 17:43:00 -0700400 virtual void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs,
401 FrameOffset fr_offs,
402 ManagedRegister scratch);
403 virtual void StoreStackOffsetToThread64(ThreadOffset<8> thr_offs,
404 FrameOffset fr_offs,
405 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700406
Ian Rogersdd7624d2014-03-14 17:43:00 -0700407 virtual void StoreStackPointerToThread32(ThreadOffset<4> thr_offs);
408 virtual void StoreStackPointerToThread64(ThreadOffset<8> thr_offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700409
410 virtual void StoreSpanning(FrameOffset dest, ManagedRegister src,
411 FrameOffset in_off, ManagedRegister scratch) = 0;
412
413 // Load routines
414 virtual void Load(ManagedRegister dest, FrameOffset src, size_t size) = 0;
415
Ian Rogersdd7624d2014-03-14 17:43:00 -0700416 virtual void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size);
417 virtual void LoadFromThread64(ManagedRegister dest, ThreadOffset<8> src, size_t size);
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700418
Ian Rogers2c8f6532011-09-02 17:16:34 -0700419 virtual void LoadRef(ManagedRegister dest, FrameOffset src) = 0;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700420 virtual void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700421
Ian Rogersdd7624d2014-03-14 17:43:00 -0700422 virtual void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700423
Ian Rogersdd7624d2014-03-14 17:43:00 -0700424 virtual void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs);
425 virtual void LoadRawPtrFromThread64(ManagedRegister dest, ThreadOffset<8> offs);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700426
427 // Copying routines
Ian Rogersb5d09b22012-03-06 22:14:17 -0800428 virtual void Move(ManagedRegister dest, ManagedRegister src, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700429
Ian Rogersdd7624d2014-03-14 17:43:00 -0700430 virtual void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
431 ManagedRegister scratch);
432 virtual void CopyRawPtrFromThread64(FrameOffset fr_offs, ThreadOffset<8> thr_offs,
433 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700434
Ian Rogersdd7624d2014-03-14 17:43:00 -0700435 virtual void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
436 ManagedRegister scratch);
437 virtual void CopyRawPtrToThread64(ThreadOffset<8> thr_offs, FrameOffset fr_offs,
438 ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700439
440 virtual void CopyRef(FrameOffset dest, FrameOffset src,
441 ManagedRegister scratch) = 0;
442
Elliott Hughesa09aea22012-01-06 18:58:27 -0800443 virtual void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700444
Ian Rogersdc51b792011-09-22 20:41:37 -0700445 virtual void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
446 ManagedRegister scratch, size_t size) = 0;
447
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700448 virtual void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
449 ManagedRegister scratch, size_t size) = 0;
450
Ian Rogersdc51b792011-09-22 20:41:37 -0700451 virtual void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
452 ManagedRegister scratch, size_t size) = 0;
453
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700454 virtual void Copy(ManagedRegister dest, Offset dest_offset,
455 ManagedRegister src, Offset src_offset,
456 ManagedRegister scratch, size_t size) = 0;
457
458 virtual void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
459 ManagedRegister scratch, size_t size) = 0;
Ian Rogersdc51b792011-09-22 20:41:37 -0700460
Ian Rogerse5de95b2011-09-18 20:31:38 -0700461 virtual void MemoryBarrier(ManagedRegister scratch) = 0;
462
jeffhao58136ca2012-05-24 13:40:11 -0700463 // Sign extension
464 virtual void SignExtend(ManagedRegister mreg, size_t size) = 0;
465
jeffhaocee4d0c2012-06-15 14:42:01 -0700466 // Zero extension
467 virtual void ZeroExtend(ManagedRegister mreg, size_t size) = 0;
468
Ian Rogers2c8f6532011-09-02 17:16:34 -0700469 // Exploit fast access in managed code to Thread::Current()
470 virtual void GetCurrentThread(ManagedRegister tr) = 0;
471 virtual void GetCurrentThread(FrameOffset dest_offset,
472 ManagedRegister scratch) = 0;
473
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700474 // Set up out_reg to hold a Object** into the handle scope, or to be NULL if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700475 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700476 // that can be used to avoid loading the handle scope entry to see if the value is
Ian Rogers2c8f6532011-09-02 17:16:34 -0700477 // NULL.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700478 virtual void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700479 ManagedRegister in_reg, bool null_allowed) = 0;
480
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700481 // Set up out_off to hold a Object** into the handle scope, or to be NULL if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700482 // value is null and null_allowed.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700483 virtual void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700484 ManagedRegister scratch, bool null_allowed) = 0;
485
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700486 // src holds a handle scope entry (Object**) load this into dst
487 virtual void LoadReferenceFromHandleScope(ManagedRegister dst,
Ian Rogers2c8f6532011-09-02 17:16:34 -0700488 ManagedRegister src) = 0;
489
490 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
491 // know that src may not be null.
492 virtual void VerifyObject(ManagedRegister src, bool could_be_null) = 0;
493 virtual void VerifyObject(FrameOffset src, bool could_be_null) = 0;
494
495 // Call to address held at [base+offset]
496 virtual void Call(ManagedRegister base, Offset offset,
497 ManagedRegister scratch) = 0;
498 virtual void Call(FrameOffset base, Offset offset,
499 ManagedRegister scratch) = 0;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700500 virtual void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch);
501 virtual void CallFromThread64(ThreadOffset<8> offset, ManagedRegister scratch);
Ian Rogers2c8f6532011-09-02 17:16:34 -0700502
Ian Rogers2c8f6532011-09-02 17:16:34 -0700503 // Generate code to check if Thread::Current()->exception_ is non-null
504 // and branch to a ExceptionSlowPath if it is.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700505 virtual void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) = 0;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700506
Tong Shen547cdfd2014-08-05 01:54:19 -0700507 virtual void InitializeFrameDescriptionEntry() {}
508 virtual void FinalizeFrameDescriptionEntry() {}
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800509 // Give a vector containing FDE data, or null if not used. Note: the assembler must take care
510 // of handling the lifecycle.
Tong Shen547cdfd2014-08-05 01:54:19 -0700511 virtual std::vector<uint8_t>* GetFrameDescriptionEntry() { return nullptr; }
512
Ian Rogers2c8f6532011-09-02 17:16:34 -0700513 virtual ~Assembler() {}
514
515 protected:
516 Assembler() : buffer_() {}
517
518 AssemblerBuffer buffer_;
519};
520
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700521} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700522
Ian Rogers166db042013-07-26 12:05:57 -0700523#endif // ART_COMPILER_UTILS_ASSEMBLER_H_