blob: acac4e19ffd069f9d5801e62601e5f10647ebdf3 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +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_CRANKSHAFT_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
6#define V8_CRANKSHAFT_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_
7
8#include "src/crankshaft/arm64/delayed-masm-arm64.h"
9#include "src/crankshaft/lithium.h"
10
11namespace v8 {
12namespace internal {
13
14class LCodeGen;
15class LGapResolver;
16
17class DelayedGapMasm : public DelayedMasm {
18 public:
19 DelayedGapMasm(LCodeGen* owner, MacroAssembler* masm)
20 : DelayedMasm(owner, masm, root) {
21 // We use the root register as an extra scratch register.
22 // The root register has two advantages:
23 // - It is not in crankshaft allocatable registers list, so it can't
24 // interfere with the allocatable registers.
25 // - We don't need to push it on the stack, as we can reload it with its
26 // value once we have finish.
27 }
28 void EndDelayedUse();
29};
30
31
32class LGapResolver BASE_EMBEDDED {
33 public:
34 explicit LGapResolver(LCodeGen* owner);
35
36 // Resolve a set of parallel moves, emitting assembler instructions.
37 void Resolve(LParallelMove* parallel_move);
38
39 private:
40 // Build the initial list of moves.
41 void BuildInitialMoveList(LParallelMove* parallel_move);
42
43 // Perform the move at the moves_ index in question (possibly requiring
44 // other moves to satisfy dependencies).
45 void PerformMove(int index);
46
47 // If a cycle is found in the series of moves, save the blocking value to
48 // a scratch register. The cycle must be found by hitting the root of the
49 // depth-first search.
50 void BreakCycle(int index);
51
52 // After a cycle has been resolved, restore the value from the scratch
53 // register to its proper destination.
54 void RestoreValue();
55
56 // Emit a move and remove it from the move graph.
57 void EmitMove(int index);
58
59 // Emit a move from one stack slot to another.
60 void EmitStackSlotMove(int index) {
61 masm_.StackSlotMove(moves_[index].source(), moves_[index].destination());
62 }
63
64 // Verify the move list before performing moves.
65 void Verify();
66
67 // Registers used to solve cycles.
68 const Register& SavedValueRegister() {
Ben Murdoch61f157c2016-09-16 13:49:30 +010069 DCHECK(!RegisterConfiguration::Crankshaft()->IsAllocatableGeneralCode(
70 masm_.ScratchRegister().code()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 return masm_.ScratchRegister();
72 }
73 // The scratch register is used to break cycles and to store constant.
74 // These two methods switch from one mode to the other.
75 void AcquireSavedValueRegister() { masm_.AcquireScratchRegister(); }
76 void ReleaseSavedValueRegister() { masm_.ReleaseScratchRegister(); }
77 const FPRegister& SavedFPValueRegister() {
78 // We use the Crankshaft floating-point scratch register to break a cycle
79 // involving double values as the MacroAssembler will not need it for the
80 // operations performed by the gap resolver.
Ben Murdoch61f157c2016-09-16 13:49:30 +010081 DCHECK(!RegisterConfiguration::Crankshaft()->IsAllocatableGeneralCode(
82 crankshaft_fp_scratch.code()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083 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 internal
98} // namespace v8
99
100#endif // V8_CRANKSHAFT_ARM64_LITHIUM_GAP_RESOLVER_ARM64_H_