blob: 2eb651b92419556c3e7cbfa06b9dfd0e5d00848c [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
6#define V8_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
7
8#include "src/v8.h"
9
10#include "src/arm64/delayed-masm-arm64.h"
11#include "src/lithium.h"
12
13namespace v8 {
14namespace internal {
15
16class LCodeGen;
17class LGapResolver;
18
19class DelayedGapMasm : public DelayedMasm {
20 public:
21 DelayedGapMasm(LCodeGen* owner, MacroAssembler* masm)
22 : DelayedMasm(owner, masm, root) {
23 // We use the root register as an extra scratch register.
24 // The root register has two advantages:
25 // - It is not in crankshaft allocatable registers list, so it can't
26 // interfere with the allocatable registers.
27 // - We don't need to push it on the stack, as we can reload it with its
28 // value once we have finish.
29 }
30 void EndDelayedUse();
31};
32
33
34class LGapResolver BASE_EMBEDDED {
35 public:
36 explicit LGapResolver(LCodeGen* owner);
37
38 // Resolve a set of parallel moves, emitting assembler instructions.
39 void Resolve(LParallelMove* parallel_move);
40
41 private:
42 // Build the initial list of moves.
43 void BuildInitialMoveList(LParallelMove* parallel_move);
44
45 // Perform the move at the moves_ index in question (possibly requiring
46 // other moves to satisfy dependencies).
47 void PerformMove(int index);
48
49 // If a cycle is found in the series of moves, save the blocking value to
50 // a scratch register. The cycle must be found by hitting the root of the
51 // depth-first search.
52 void BreakCycle(int index);
53
54 // After a cycle has been resolved, restore the value from the scratch
55 // register to its proper destination.
56 void RestoreValue();
57
58 // Emit a move and remove it from the move graph.
59 void EmitMove(int index);
60
61 // Emit a move from one stack slot to another.
62 void EmitStackSlotMove(int index) {
63 masm_.StackSlotMove(moves_[index].source(), moves_[index].destination());
64 }
65
66 // Verify the move list before performing moves.
67 void Verify();
68
69 // Registers used to solve cycles.
70 const Register& SavedValueRegister() {
71 DCHECK(!masm_.ScratchRegister().IsAllocatable());
72 return masm_.ScratchRegister();
73 }
74 // The scratch register is used to break cycles and to store constant.
75 // These two methods switch from one mode to the other.
76 void AcquireSavedValueRegister() { masm_.AcquireScratchRegister(); }
77 void ReleaseSavedValueRegister() { masm_.ReleaseScratchRegister(); }
78 const FPRegister& SavedFPValueRegister() {
79 // We use the Crankshaft floating-point scratch register to break a cycle
80 // involving double values as the MacroAssembler will not need it for the
81 // operations performed by the gap resolver.
82 DCHECK(!crankshaft_fp_scratch.IsAllocatable());
83 return crankshaft_fp_scratch;
84 }
85
86 LCodeGen* cgen_;
87 DelayedGapMasm masm_;
88
89 // List of moves not yet resolved.
90 ZoneList<LMoveOperands> moves_;
91
92 int root_index_;
93 bool in_cycle_;
94 LOperand* saved_destination_;
95};
96
97} } // namespace v8::internal
98
99#endif // V8_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_