Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: runtime/vm/instructions_arm64.cc

Issue 1343373003: Revert "VM: New calling convention for generated code." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/instructions_arm64.h ('k') | runtime/vm/instructions_arm64_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64.
6 #if defined(TARGET_ARCH_ARM64) 6 #if defined(TARGET_ARCH_ARM64)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/constants_arm64.h" 9 #include "vm/constants_arm64.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
11 #include "vm/instructions.h" 11 #include "vm/instructions.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 CallPattern::CallPattern(uword pc, const Code& code) 16 CallPattern::CallPattern(uword pc, const Code& code)
17 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), 17 : object_pool_(ObjectPool::Handle(code.GetObjectPool())),
18 end_(pc), 18 end_(pc),
19 ic_data_load_end_(0), 19 ic_data_load_end_(0),
20 target_code_pool_index_(-1), 20 target_address_pool_index_(-1),
21 ic_data_(ICData::Handle()) { 21 ic_data_(ICData::Handle()) {
22 ASSERT(code.ContainsInstructionAt(pc)); 22 ASSERT(code.ContainsInstructionAt(pc));
23 // Last instruction: blr ip0. 23 // Last instruction: blr ip0.
24 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); 24 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200);
25 25
26 Register reg; 26 Register reg;
27 ic_data_load_end_ = 27 ic_data_load_end_ =
28 InstructionPattern::DecodeLoadWordFromPool(end_ - 2 * Instr::kInstrSize, 28 InstructionPattern::DecodeLoadWordFromPool(end_ - Instr::kInstrSize,
29 &reg, 29 &reg,
30 &target_code_pool_index_); 30 &target_address_pool_index_);
31 ASSERT(reg == CODE_REG); 31 ASSERT(reg == IP0);
32 } 32 }
33 33
34 34
35 NativeCallPattern::NativeCallPattern(uword pc, const Code& code) 35 NativeCallPattern::NativeCallPattern(uword pc, const Code& code)
36 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), 36 : object_pool_(ObjectPool::Handle(code.GetObjectPool())),
37 end_(pc), 37 end_(pc),
38 native_function_pool_index_(-1), 38 native_function_pool_index_(-1),
39 target_code_pool_index_(-1) { 39 target_address_pool_index_(-1) {
40 ASSERT(code.ContainsInstructionAt(pc)); 40 ASSERT(code.ContainsInstructionAt(pc));
41 // Last instruction: blr ip0. 41 // Last instruction: blr ip0.
42 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); 42 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200);
43 43
44 Register reg; 44 Register reg;
45 uword native_function_load_end = 45 uword native_function_load_end =
46 InstructionPattern::DecodeLoadWordFromPool(end_ - 2 * Instr::kInstrSize, 46 InstructionPattern::DecodeLoadWordFromPool(end_ - Instr::kInstrSize,
47 &reg, 47 &reg,
48 &target_code_pool_index_); 48 &target_address_pool_index_);
49 ASSERT(reg == CODE_REG); 49 ASSERT(reg == IP0);
50 InstructionPattern::DecodeLoadWordFromPool(native_function_load_end, 50 InstructionPattern::DecodeLoadWordFromPool(native_function_load_end,
51 &reg, 51 &reg,
52 &native_function_pool_index_); 52 &native_function_pool_index_);
53 ASSERT(reg == R5); 53 ASSERT(reg == R5);
54 } 54 }
55 55
56 56
57 RawCode* NativeCallPattern::target() const { 57 uword NativeCallPattern::target() const {
58 return reinterpret_cast<RawCode*>( 58 return object_pool_.RawValueAt(target_address_pool_index_);
59 object_pool_.ObjectAt(target_code_pool_index_));
60 } 59 }
61 60
62 61
63 void NativeCallPattern::set_target(const Code& target) const { 62 void NativeCallPattern::set_target(uword target_address) const {
64 object_pool_.SetObjectAt(target_code_pool_index_, target); 63 object_pool_.SetRawValueAt(target_address_pool_index_, target_address);
65 // No need to flush the instruction cache, since the code is not modified. 64 // No need to flush the instruction cache, since the code is not modified.
66 } 65 }
67 66
68 67
69 NativeFunction NativeCallPattern::native_function() const { 68 NativeFunction NativeCallPattern::native_function() const {
70 return reinterpret_cast<NativeFunction>( 69 return reinterpret_cast<NativeFunction>(
71 object_pool_.RawValueAt(native_function_pool_index_)); 70 object_pool_.RawValueAt(native_function_pool_index_));
72 } 71 }
73 72
74 73
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 InstructionPattern::DecodeLoadObject(ic_data_load_end_, 285 InstructionPattern::DecodeLoadObject(ic_data_load_end_,
287 object_pool_, 286 object_pool_,
288 &reg, 287 &reg,
289 &ic_data_); 288 &ic_data_);
290 ASSERT(reg == R5); 289 ASSERT(reg == R5);
291 } 290 }
292 return ic_data_.raw(); 291 return ic_data_.raw();
293 } 292 }
294 293
295 294
296 RawCode* CallPattern::TargetCode() const { 295 uword CallPattern::TargetAddress() const {
297 return reinterpret_cast<RawCode*>( 296 return object_pool_.RawValueAt(target_address_pool_index_);
298 object_pool_.ObjectAt(target_code_pool_index_));
299 } 297 }
300 298
301 299
302 void CallPattern::SetTargetCode(const Code& target) const { 300 void CallPattern::SetTargetAddress(uword target_address) const {
303 object_pool_.SetObjectAt(target_code_pool_index_, target); 301 object_pool_.SetRawValueAt(target_address_pool_index_, target_address);
304 // No need to flush the instruction cache, since the code is not modified. 302 // No need to flush the instruction cache, since the code is not modified.
305 } 303 }
306 304
307 305
308 void CallPattern::InsertDeoptCallAt(uword pc, uword target_address) { 306 void CallPattern::InsertAt(uword pc, uword target_address) {
309 Instr* movz0 = Instr::At(pc + (0 * Instr::kInstrSize)); 307 Instr* movz0 = Instr::At(pc + (0 * Instr::kInstrSize));
310 Instr* movk1 = Instr::At(pc + (1 * Instr::kInstrSize)); 308 Instr* movk1 = Instr::At(pc + (1 * Instr::kInstrSize));
311 Instr* movk2 = Instr::At(pc + (2 * Instr::kInstrSize)); 309 Instr* movk2 = Instr::At(pc + (2 * Instr::kInstrSize));
312 Instr* movk3 = Instr::At(pc + (3 * Instr::kInstrSize)); 310 Instr* movk3 = Instr::At(pc + (3 * Instr::kInstrSize));
313 Instr* blr = Instr::At(pc + (4 * Instr::kInstrSize)); 311 Instr* blr = Instr::At(pc + (4 * Instr::kInstrSize));
314 const uint32_t w0 = Utils::Low32Bits(target_address); 312 const uint32_t w0 = Utils::Low32Bits(target_address);
315 const uint32_t w1 = Utils::High32Bits(target_address); 313 const uint32_t w1 = Utils::High32Bits(target_address);
316 const uint16_t h0 = Utils::Low16Bits(w0); 314 const uint16_t h0 = Utils::Low16Bits(w0);
317 const uint16_t h1 = Utils::High16Bits(w0); 315 const uint16_t h1 = Utils::High16Bits(w0);
318 const uint16_t h2 = Utils::Low16Bits(w1); 316 const uint16_t h2 = Utils::Low16Bits(w1);
319 const uint16_t h3 = Utils::High16Bits(w1); 317 const uint16_t h3 = Utils::High16Bits(w1);
320 318
321 movz0->SetMoveWideBits(MOVZ, IP0, h0, 0, kDoubleWord); 319 movz0->SetMoveWideBits(MOVZ, IP0, h0, 0, kDoubleWord);
322 movk1->SetMoveWideBits(MOVK, IP0, h1, 1, kDoubleWord); 320 movk1->SetMoveWideBits(MOVK, IP0, h1, 1, kDoubleWord);
323 movk2->SetMoveWideBits(MOVK, IP0, h2, 2, kDoubleWord); 321 movk2->SetMoveWideBits(MOVK, IP0, h2, 2, kDoubleWord);
324 movk3->SetMoveWideBits(MOVK, IP0, h3, 3, kDoubleWord); 322 movk3->SetMoveWideBits(MOVK, IP0, h3, 3, kDoubleWord);
325 blr->SetUnconditionalBranchRegBits(BLR, IP0); 323 blr->SetUnconditionalBranchRegBits(BLR, IP0);
326 324
327 ASSERT(kDeoptCallLengthInBytes == 5 * Instr::kInstrSize); 325 ASSERT(kLengthInBytes == 5 * Instr::kInstrSize);
328 CPU::FlushICache(pc, kDeoptCallLengthInBytes); 326 CPU::FlushICache(pc, kLengthInBytes);
329 } 327 }
330 328
331 329
330 JumpPattern::JumpPattern(uword pc, const Code& code) : pc_(pc) { }
331
332
333 bool JumpPattern::IsValid() const {
334 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize));
335 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize));
336 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize));
337 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize));
338 Instr* br = Instr::At(pc_ + (4 * Instr::kInstrSize));
339 return (movz0->IsMoveWideOp()) && (movz0->Bits(29, 2) == 2) &&
340 (movk1->IsMoveWideOp()) && (movk1->Bits(29, 2) == 3) &&
341 (movk2->IsMoveWideOp()) && (movk2->Bits(29, 2) == 3) &&
342 (movk3->IsMoveWideOp()) && (movk3->Bits(29, 2) == 3) &&
343 (br->IsUnconditionalBranchRegOp()) && (br->Bits(16, 5) == 31);
344 }
345
346
347 uword JumpPattern::TargetAddress() const {
348 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize));
349 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize));
350 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize));
351 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize));
352 const uint16_t imm0 = movz0->Imm16Field();
353 const uint16_t imm1 = movk1->Imm16Field();
354 const uint16_t imm2 = movk2->Imm16Field();
355 const uint16_t imm3 = movk3->Imm16Field();
356 const int64_t target =
357 (static_cast<int64_t>(imm0)) |
358 (static_cast<int64_t>(imm1) << 16) |
359 (static_cast<int64_t>(imm2) << 32) |
360 (static_cast<int64_t>(imm3) << 48);
361 return target;
362 }
363
364
365 void JumpPattern::SetTargetAddress(uword target_address) const {
366 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize));
367 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize));
368 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize));
369 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize));
370 const int32_t movz0_bits = movz0->InstructionBits();
371 const int32_t movk1_bits = movk1->InstructionBits();
372 const int32_t movk2_bits = movk2->InstructionBits();
373 const int32_t movk3_bits = movk3->InstructionBits();
374
375 const uint32_t w0 = Utils::Low32Bits(target_address);
376 const uint32_t w1 = Utils::High32Bits(target_address);
377 const uint16_t h0 = Utils::Low16Bits(w0);
378 const uint16_t h1 = Utils::High16Bits(w0);
379 const uint16_t h2 = Utils::Low16Bits(w1);
380 const uint16_t h3 = Utils::High16Bits(w1);
381
382 movz0->SetInstructionBits((movz0_bits & ~kImm16Mask) | (h0 << kImm16Shift));
383 movk1->SetInstructionBits((movk1_bits & ~kImm16Mask) | (h1 << kImm16Shift));
384 movk2->SetInstructionBits((movk2_bits & ~kImm16Mask) | (h2 << kImm16Shift));
385 movk3->SetInstructionBits((movk3_bits & ~kImm16Mask) | (h3 << kImm16Shift));
386 CPU::FlushICache(pc_, 4 * Instr::kInstrSize);
387 }
388
389
332 ReturnPattern::ReturnPattern(uword pc) 390 ReturnPattern::ReturnPattern(uword pc)
333 : pc_(pc) { 391 : pc_(pc) {
334 } 392 }
335 393
336 394
337 bool ReturnPattern::IsValid() const { 395 bool ReturnPattern::IsValid() const {
338 Instr* bx_lr = Instr::At(pc_); 396 Instr* bx_lr = Instr::At(pc_);
339 const Register crn = ConcreteRegister(LR); 397 const Register crn = ConcreteRegister(LR);
340 const int32_t instruction = RET | (static_cast<int32_t>(crn) << kRnShift); 398 const int32_t instruction = RET | (static_cast<int32_t>(crn) << kRnShift);
341 return bx_lr->InstructionBits() == instruction; 399 return bx_lr->InstructionBits() == instruction;
342 } 400 }
343 401
344 } // namespace dart 402 } // namespace dart
345 403
346 #endif // defined TARGET_ARCH_ARM64 404 #endif // defined TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « runtime/vm/instructions_arm64.h ('k') | runtime/vm/instructions_arm64_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698