Line data Source code
1 : // Copyright 2015 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/interpreter/control-flow-builders.h"
6 : #include "src/objects-inl.h"
7 :
8 : namespace v8 {
9 : namespace internal {
10 : namespace interpreter {
11 :
12 :
13 5443346 : BreakableControlFlowBuilder::~BreakableControlFlowBuilder() {
14 : DCHECK(break_labels_.empty() || break_labels_.is_bound());
15 5183159 : }
16 :
17 18873 : void BreakableControlFlowBuilder::BindBreakTarget() {
18 213127 : break_labels_.Bind(builder());
19 18873 : }
20 :
21 100281 : void BreakableControlFlowBuilder::EmitJump(BytecodeLabels* sites) {
22 100281 : builder()->Jump(sites->New());
23 100281 : }
24 :
25 31823 : void BreakableControlFlowBuilder::EmitJumpIfTrue(
26 : BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
27 31823 : builder()->JumpIfTrue(mode, sites->New());
28 31823 : }
29 :
30 5764 : void BreakableControlFlowBuilder::EmitJumpIfFalse(
31 : BytecodeArrayBuilder::ToBooleanMode mode, BytecodeLabels* sites) {
32 5764 : builder()->JumpIfFalse(mode, sites->New());
33 5764 : }
34 :
35 5764 : void BreakableControlFlowBuilder::EmitJumpIfUndefined(BytecodeLabels* sites) {
36 5764 : builder()->JumpIfUndefined(sites->New());
37 5764 : }
38 :
39 0 : void BreakableControlFlowBuilder::EmitJumpIfNull(BytecodeLabels* sites) {
40 0 : builder()->JumpIfNull(sites->New());
41 0 : }
42 :
43 1206 : void BlockBuilder::EndBlock() {
44 1206 : builder()->Bind(&block_end_);
45 : BindBreakTarget();
46 1206 : }
47 :
48 193048 : LoopBuilder::~LoopBuilder() {
49 : DCHECK(continue_labels_.empty() || continue_labels_.is_bound());
50 : DCHECK(header_labels_.empty() || header_labels_.is_bound());
51 193048 : }
52 :
53 192744 : void LoopBuilder::LoopHeader(ZoneVector<BytecodeLabel>* additional_labels) {
54 : // Jumps from before the loop header into the loop violate ordering
55 : // requirements of bytecode basic blocks. The only entry into a loop
56 : // must be the loop header. Surely breaks is okay? Not if nested
57 : // and misplaced between the headers.
58 : DCHECK(break_labels_.empty() && continue_labels_.empty());
59 193982 : builder()->Bind(&loop_header_);
60 192744 : if (additional_labels != nullptr) {
61 3306 : for (auto& label : *additional_labels) {
62 1238 : builder()->Bind(&label);
63 : }
64 : }
65 192744 : }
66 :
67 192744 : void LoopBuilder::JumpToHeader(int loop_depth) {
68 : // Pass the proper loop nesting level to the backwards branch, to trigger
69 : // on-stack replacement when armed for the given loop nesting depth.
70 : int level = Min(loop_depth, AbstractCode::kMaxLoopNestingMarker - 1);
71 : // Loop must have closed form, i.e. all loop elements are within the loop,
72 : // the loop header precedes the body and next elements in the loop.
73 : DCHECK(loop_header_.is_bound());
74 192744 : builder()->JumpLoop(&loop_header_, level);
75 192744 : }
76 :
77 193048 : void LoopBuilder::EndLoop() {
78 : BindBreakTarget();
79 193048 : header_labels_.BindToLabel(builder(), loop_header_);
80 193048 : }
81 :
82 193048 : void LoopBuilder::BindContinueTarget() { continue_labels_.Bind(builder()); }
83 :
84 67139 : SwitchBuilder::~SwitchBuilder() {
85 : #ifdef DEBUG
86 : for (auto site : case_sites_) {
87 : DCHECK(site.is_bound());
88 : }
89 : #endif
90 67139 : }
91 :
92 :
93 250769 : void SwitchBuilder::SetCaseTarget(int index) {
94 250769 : BytecodeLabel& site = case_sites_.at(index);
95 250769 : builder()->Bind(&site);
96 250769 : }
97 :
98 :
99 128266 : void TryCatchBuilder::BeginTry(Register context) {
100 128266 : builder()->MarkTryBegin(handler_id_, context);
101 128267 : }
102 :
103 :
104 128267 : void TryCatchBuilder::EndTry() {
105 513068 : builder()->MarkTryEnd(handler_id_);
106 256534 : builder()->Jump(&exit_);
107 256534 : builder()->Bind(&handler_);
108 256534 : builder()->MarkHandler(handler_id_, catch_prediction_);
109 128267 : }
110 :
111 :
112 128267 : void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); }
113 :
114 :
115 48266 : void TryFinallyBuilder::BeginTry(Register context) {
116 48266 : builder()->MarkTryBegin(handler_id_, context);
117 48266 : }
118 :
119 :
120 88961 : void TryFinallyBuilder::LeaveTry() {
121 88961 : builder()->Jump(finalization_sites_.New());
122 88961 : }
123 :
124 :
125 48266 : void TryFinallyBuilder::EndTry() {
126 48266 : builder()->MarkTryEnd(handler_id_);
127 48266 : }
128 :
129 :
130 48266 : void TryFinallyBuilder::BeginHandler() {
131 96532 : builder()->Bind(&handler_);
132 96532 : builder()->MarkHandler(handler_id_, catch_prediction_);
133 48266 : }
134 :
135 48266 : void TryFinallyBuilder::BeginFinally() { finalization_sites_.Bind(builder()); }
136 :
137 48266 : void TryFinallyBuilder::EndFinally() {
138 : // Nothing to be done here.
139 48266 : }
140 :
141 : } // namespace interpreter
142 : } // namespace internal
143 : } // namespace v8
|