Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/interpreter/control-flow-builders.h" | 5 #include "src/interpreter/control-flow-builders.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace interpreter { | 9 namespace interpreter { |
| 10 | 10 |
| 11 | 11 |
| 12 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() { | 12 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() { |
| 13 DCHECK(break_sites_.empty()); | 13 DCHECK(break_labels_.empty() || break_labels_.is_bound()); |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 void BreakableControlFlowBuilder::BindBreakTarget() { |
| 17 void BreakableControlFlowBuilder::SetBreakTarget(const BytecodeLabel& target) { | 17 break_labels_.Bind(builder()); |
| 18 BindLabels(target, &break_sites_); | |
| 19 } | 18 } |
| 20 | 19 |
| 21 | 20 void BreakableControlFlowBuilder::EmitJump(BytecodeLabels* sites) { |
| 22 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites) { | 21 builder()->Jump(sites->New()); |
| 23 sites->push_back(BytecodeLabel()); | |
| 24 builder()->Jump(&sites->back()); | |
| 25 } | 22 } |
| 26 | 23 |
| 27 | 24 void BreakableControlFlowBuilder::EmitJumpIfTrue(BytecodeLabels* sites) { |
| 28 void BreakableControlFlowBuilder::EmitJumpIfTrue( | 25 builder()->JumpIfTrue(sites->New()); |
| 29 ZoneVector<BytecodeLabel>* sites) { | |
| 30 sites->push_back(BytecodeLabel()); | |
| 31 builder()->JumpIfTrue(&sites->back()); | |
| 32 } | 26 } |
| 33 | 27 |
| 34 | 28 void BreakableControlFlowBuilder::EmitJumpIfFalse(BytecodeLabels* sites) { |
| 35 void BreakableControlFlowBuilder::EmitJumpIfFalse( | 29 builder()->JumpIfFalse(sites->New()); |
| 36 ZoneVector<BytecodeLabel>* sites) { | |
| 37 sites->push_back(BytecodeLabel()); | |
| 38 builder()->JumpIfFalse(&sites->back()); | |
| 39 } | 30 } |
| 40 | 31 |
| 41 | 32 void BreakableControlFlowBuilder::EmitJumpIfUndefined(BytecodeLabels* sites) { |
| 42 void BreakableControlFlowBuilder::EmitJumpIfUndefined( | 33 builder()->JumpIfUndefined(sites->New()); |
| 43 ZoneVector<BytecodeLabel>* sites) { | |
| 44 sites->push_back(BytecodeLabel()); | |
| 45 builder()->JumpIfUndefined(&sites->back()); | |
| 46 } | 34 } |
| 47 | 35 |
| 48 | 36 void BreakableControlFlowBuilder::EmitJumpIfNull(BytecodeLabels* sites) { |
| 49 void BreakableControlFlowBuilder::EmitJumpIfNull( | 37 builder()->JumpIfNull(sites->New()); |
| 50 ZoneVector<BytecodeLabel>* sites) { | |
| 51 sites->push_back(BytecodeLabel()); | |
| 52 builder()->JumpIfNull(&sites->back()); | |
| 53 } | |
| 54 | |
| 55 | |
| 56 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites, | |
| 57 int index) { | |
| 58 builder()->Jump(&sites->at(index)); | |
| 59 } | |
| 60 | |
| 61 | |
| 62 void BreakableControlFlowBuilder::EmitJumpIfTrue( | |
| 63 ZoneVector<BytecodeLabel>* sites, int index) { | |
| 64 builder()->JumpIfTrue(&sites->at(index)); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 void BreakableControlFlowBuilder::EmitJumpIfFalse( | |
| 69 ZoneVector<BytecodeLabel>* sites, int index) { | |
| 70 builder()->JumpIfFalse(&sites->at(index)); | |
| 71 } | |
| 72 | |
| 73 | |
| 74 void BreakableControlFlowBuilder::BindLabels(const BytecodeLabel& target, | |
| 75 ZoneVector<BytecodeLabel>* sites) { | |
| 76 for (size_t i = 0; i < sites->size(); i++) { | |
| 77 BytecodeLabel& site = sites->at(i); | |
| 78 builder()->Bind(target, &site); | |
| 79 } | |
| 80 sites->clear(); | |
| 81 } | 38 } |
| 82 | 39 |
| 83 | 40 |
| 84 void BlockBuilder::EndBlock() { | 41 void BlockBuilder::EndBlock() { |
| 85 builder()->Bind(&block_end_); | 42 builder()->Bind(&block_end_); |
| 86 SetBreakTarget(block_end_); | 43 BindBreakTarget(); |
| 87 } | 44 } |
| 88 | 45 |
| 89 | 46 LoopBuilder::~LoopBuilder() { |
| 90 LoopBuilder::~LoopBuilder() { DCHECK(continue_sites_.empty()); } | 47 DCHECK(continue_labels_.empty() || continue_labels_.is_bound()); |
|
rmcilroy
2016/08/17 16:20:43
Also DCHECK header labels
klaasb
2016/08/18 11:40:00
Done.
| |
| 91 | 48 } |
| 92 | 49 |
| 93 void LoopBuilder::LoopHeader(ZoneVector<BytecodeLabel>* additional_labels) { | 50 void LoopBuilder::LoopHeader(ZoneVector<BytecodeLabel>* additional_labels) { |
| 94 // Jumps from before the loop header into the loop violate ordering | 51 // Jumps from before the loop header into the loop violate ordering |
| 95 // requirements of bytecode basic blocks. The only entry into a loop | 52 // requirements of bytecode basic blocks. The only entry into a loop |
| 96 // must be the loop header. Surely breaks is okay? Not if nested | 53 // must be the loop header. Surely breaks is okay? Not if nested |
| 97 // and misplaced between the headers. | 54 // and misplaced between the headers. |
| 98 DCHECK(break_sites_.empty() && continue_sites_.empty()); | 55 DCHECK(break_labels_.empty() && continue_labels_.empty()); |
| 99 builder()->Bind(&loop_header_); | 56 builder()->Bind(&loop_header_); |
| 100 for (auto& label : *additional_labels) { | 57 for (auto& label : *additional_labels) { |
| 101 builder()->Bind(loop_header_, &label); | 58 builder()->Bind(&label); |
| 102 } | 59 } |
| 103 } | 60 } |
| 104 | 61 |
| 105 void LoopBuilder::JumpToHeader() { | 62 void LoopBuilder::JumpToHeader() { |
| 106 // Loop must have closed form, i.e. all loop elements are within the loop, | 63 // Loop must have closed form, i.e. all loop elements are within the loop, |
| 107 // the loop header precedes the body and next elements in the loop. | 64 // the loop header precedes the body and next elements in the loop. |
| 108 DCHECK(loop_header_.is_bound()); | 65 DCHECK(loop_header_.is_bound()); |
| 109 builder()->Jump(&loop_header_); | 66 builder()->Jump(&loop_header_); |
| 110 } | 67 } |
| 111 | 68 |
| 112 void LoopBuilder::JumpToHeaderIfTrue() { | 69 void LoopBuilder::JumpToHeaderIfTrue() { |
| 113 // Loop must have closed form, i.e. all loop elements are within the loop, | 70 // Loop must have closed form, i.e. all loop elements are within the loop, |
| 114 // the loop header precedes the body and next elements in the loop. | 71 // the loop header precedes the body and next elements in the loop. |
| 115 DCHECK(loop_header_.is_bound()); | 72 DCHECK(loop_header_.is_bound()); |
| 116 builder()->JumpIfTrue(&loop_header_); | 73 builder()->JumpIfTrue(&loop_header_); |
| 117 } | 74 } |
| 118 | 75 |
| 119 void LoopBuilder::EndLoop() { | 76 void LoopBuilder::EndLoop() { |
| 120 builder()->Bind(&loop_end_); | 77 BindBreakTarget(); |
| 121 SetBreakTarget(loop_end_); | 78 header_labels_.BindToLabel(builder(), loop_header_); |
| 122 } | 79 } |
| 123 | 80 |
| 124 void LoopBuilder::SetContinueTarget() { | 81 void LoopBuilder::BindContinueTarget() { continue_labels_.Bind(builder()); } |
| 125 BytecodeLabel target; | |
| 126 builder()->Bind(&target); | |
| 127 BindLabels(target, &continue_sites_); | |
| 128 } | |
| 129 | |
| 130 | 82 |
| 131 SwitchBuilder::~SwitchBuilder() { | 83 SwitchBuilder::~SwitchBuilder() { |
| 132 #ifdef DEBUG | 84 #ifdef DEBUG |
| 133 for (auto site : case_sites_) { | 85 for (auto site : case_sites_) { |
| 134 DCHECK(site.is_bound()); | 86 DCHECK(site.is_bound()); |
| 135 } | 87 } |
| 136 #endif | 88 #endif |
| 137 } | 89 } |
| 138 | 90 |
| 139 | 91 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 158 | 110 |
| 159 void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); } | 111 void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); } |
| 160 | 112 |
| 161 | 113 |
| 162 void TryFinallyBuilder::BeginTry(Register context) { | 114 void TryFinallyBuilder::BeginTry(Register context) { |
| 163 builder()->MarkTryBegin(handler_id_, context); | 115 builder()->MarkTryBegin(handler_id_, context); |
| 164 } | 116 } |
| 165 | 117 |
| 166 | 118 |
| 167 void TryFinallyBuilder::LeaveTry() { | 119 void TryFinallyBuilder::LeaveTry() { |
| 168 finalization_sites_.push_back(BytecodeLabel()); | 120 builder()->Jump(finalization_sites_.New()); |
| 169 builder()->Jump(&finalization_sites_.back()); | |
| 170 } | 121 } |
| 171 | 122 |
| 172 | 123 |
| 173 void TryFinallyBuilder::EndTry() { | 124 void TryFinallyBuilder::EndTry() { |
| 174 builder()->MarkTryEnd(handler_id_); | 125 builder()->MarkTryEnd(handler_id_); |
| 175 } | 126 } |
| 176 | 127 |
| 177 | 128 |
| 178 void TryFinallyBuilder::BeginHandler() { | 129 void TryFinallyBuilder::BeginHandler() { |
| 179 builder()->Bind(&handler_); | 130 builder()->Bind(&handler_); |
| 180 builder()->MarkHandler(handler_id_, catch_prediction_); | 131 builder()->MarkHandler(handler_id_, catch_prediction_); |
| 181 } | 132 } |
| 182 | 133 |
| 183 | 134 void TryFinallyBuilder::BeginFinally() { finalization_sites_.Bind(builder()); } |
| 184 void TryFinallyBuilder::BeginFinally() { | |
| 185 for (size_t i = 0; i < finalization_sites_.size(); i++) { | |
| 186 BytecodeLabel& site = finalization_sites_.at(i); | |
| 187 builder()->Bind(&site); | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 | 135 |
| 192 void TryFinallyBuilder::EndFinally() { | 136 void TryFinallyBuilder::EndFinally() { |
| 193 // Nothing to be done here. | 137 // Nothing to be done here. |
| 194 } | 138 } |
| 195 | 139 |
| 196 } // namespace interpreter | 140 } // namespace interpreter |
| 197 } // namespace internal | 141 } // namespace internal |
| 198 } // namespace v8 | 142 } // namespace v8 |
| OLD | NEW |