V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
unwinding-info-writer-arm64.cc
1 // Copyright 2016 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 #include "src/compiler/backend/arm64/unwinding-info-writer-arm64.h"
6 #include "src/compiler/backend/instruction.h"
7 
8 namespace v8 {
9 namespace internal {
10 namespace compiler {
11 
12 void UnwindingInfoWriter::BeginInstructionBlock(int pc_offset,
13  const InstructionBlock* block) {
14  if (!enabled()) return;
15 
16  block_will_exit_ = false;
17 
18  DCHECK_LT(block->rpo_number().ToInt(),
19  static_cast<int>(block_initial_states_.size()));
20  const BlockInitialState* initial_state =
21  block_initial_states_[block->rpo_number().ToInt()];
22  if (initial_state) {
23  if (initial_state->saved_lr_ != saved_lr_) {
24  eh_frame_writer_.AdvanceLocation(pc_offset);
25  if (initial_state->saved_lr_) {
26  eh_frame_writer_.RecordRegisterSavedToStack(lr, kPointerSize);
27  eh_frame_writer_.RecordRegisterSavedToStack(fp, 0);
28  } else {
29  eh_frame_writer_.RecordRegisterFollowsInitialRule(lr);
30  }
31  saved_lr_ = initial_state->saved_lr_;
32  }
33  } else {
34  // The entry block always lacks an explicit initial state.
35  // The exit block may lack an explicit state, if it is only reached by
36  // the block ending in a ret.
37  // All the other blocks must have an explicit initial state.
38  DCHECK(block->predecessors().empty() || block->successors().empty());
39  }
40 }
41 
42 void UnwindingInfoWriter::EndInstructionBlock(const InstructionBlock* block) {
43  if (!enabled() || block_will_exit_) return;
44 
45  for (const RpoNumber& successor : block->successors()) {
46  int successor_index = successor.ToInt();
47  DCHECK_LT(successor_index, static_cast<int>(block_initial_states_.size()));
48  const BlockInitialState* existing_state =
49  block_initial_states_[successor_index];
50 
51  // If we already had an entry for this BB, check that the values are the
52  // same we are trying to insert.
53  if (existing_state) {
54  DCHECK_EQ(existing_state->saved_lr_, saved_lr_);
55  } else {
56  block_initial_states_[successor_index] =
57  new (zone_) BlockInitialState(saved_lr_);
58  }
59  }
60 }
61 
62 void UnwindingInfoWriter::MarkFrameConstructed(int at_pc) {
63  if (!enabled()) return;
64 
65  // Regardless of the type of frame constructed, the relevant part of the
66  // layout is always the one in the diagram:
67  //
68  // | .... | higher addresses
69  // +----------+ ^
70  // | LR | | |
71  // +----------+ | |
72  // | saved FP | | |
73  // +----------+ <-- FP v
74  // | .... | stack growth
75  //
76  // The LR is pushed on the stack, and we can record this fact at the end of
77  // the construction, since the LR itself is not modified in the process.
78  eh_frame_writer_.AdvanceLocation(at_pc);
79  eh_frame_writer_.RecordRegisterSavedToStack(lr, kPointerSize);
80  eh_frame_writer_.RecordRegisterSavedToStack(fp, 0);
81  saved_lr_ = true;
82 }
83 
84 void UnwindingInfoWriter::MarkFrameDeconstructed(int at_pc) {
85  if (!enabled()) return;
86 
87  // The lr is restored by the last operation in LeaveFrame().
88  eh_frame_writer_.AdvanceLocation(at_pc);
89  eh_frame_writer_.RecordRegisterFollowsInitialRule(lr);
90  saved_lr_ = false;
91 }
92 
93 void UnwindingInfoWriter::MarkLinkRegisterOnTopOfStack(int pc_offset,
94  const Register& sp) {
95  if (!enabled()) return;
96 
97  eh_frame_writer_.AdvanceLocation(pc_offset);
98  eh_frame_writer_.SetBaseAddressRegisterAndOffset(sp, 0);
99  eh_frame_writer_.RecordRegisterSavedToStack(lr, 0);
100 }
101 
102 void UnwindingInfoWriter::MarkPopLinkRegisterFromTopOfStack(int pc_offset) {
103  if (!enabled()) return;
104 
105  eh_frame_writer_.AdvanceLocation(pc_offset);
106  eh_frame_writer_.SetBaseAddressRegisterAndOffset(fp, 0);
107  eh_frame_writer_.RecordRegisterFollowsInitialRule(lr);
108 }
109 
110 } // namespace compiler
111 } // namespace internal
112 } // namespace v8
Definition: libplatform.h:13