Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // 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 | #include "control-builders.h" |
| 6 | |
| 7 | namespace v8 { |
| 8 | namespace internal { |
| 9 | namespace compiler { |
| 10 | |
| 11 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 12 | void IfBuilder::If(Node* condition, BranchHint hint) { |
| 13 | builder_->NewBranch(condition, hint); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 14 | else_environment_ = environment()->CopyForConditional(); |
| 15 | } |
| 16 | |
| 17 | |
| 18 | void IfBuilder::Then() { builder_->NewIfTrue(); } |
| 19 | |
| 20 | |
| 21 | void IfBuilder::Else() { |
| 22 | builder_->NewMerge(); |
| 23 | then_environment_ = environment(); |
| 24 | set_environment(else_environment_); |
| 25 | builder_->NewIfFalse(); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | void IfBuilder::End() { |
| 30 | then_environment_->Merge(environment()); |
| 31 | set_environment(then_environment_); |
| 32 | } |
| 33 | |
| 34 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 35 | void LoopBuilder::BeginLoop(BitVector* assigned) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | builder_->NewLoop(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 37 | loop_environment_ = environment()->CopyForLoop(assigned); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | continue_environment_ = environment()->CopyAsUnreachable(); |
| 39 | break_environment_ = environment()->CopyAsUnreachable(); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | void LoopBuilder::Continue() { |
| 44 | continue_environment_->Merge(environment()); |
| 45 | environment()->MarkAsUnreachable(); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | void LoopBuilder::Break() { |
| 50 | break_environment_->Merge(environment()); |
| 51 | environment()->MarkAsUnreachable(); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | void LoopBuilder::EndBody() { |
| 56 | continue_environment_->Merge(environment()); |
| 57 | set_environment(continue_environment_); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void LoopBuilder::EndLoop() { |
| 62 | loop_environment_->Merge(environment()); |
| 63 | set_environment(break_environment_); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void LoopBuilder::BreakUnless(Node* condition) { |
| 68 | IfBuilder control_if(builder_); |
| 69 | control_if.If(condition); |
| 70 | control_if.Then(); |
| 71 | control_if.Else(); |
| 72 | Break(); |
| 73 | control_if.End(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | void SwitchBuilder::BeginSwitch() { |
| 78 | body_environment_ = environment()->CopyAsUnreachable(); |
| 79 | label_environment_ = environment()->CopyAsUnreachable(); |
| 80 | break_environment_ = environment()->CopyAsUnreachable(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | void SwitchBuilder::BeginLabel(int index, Node* condition) { |
| 85 | builder_->NewBranch(condition); |
| 86 | label_environment_ = environment()->CopyForConditional(); |
| 87 | builder_->NewIfTrue(); |
| 88 | body_environments_[index] = environment(); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | void SwitchBuilder::EndLabel() { |
| 93 | set_environment(label_environment_); |
| 94 | builder_->NewIfFalse(); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void SwitchBuilder::DefaultAt(int index) { |
| 99 | label_environment_ = environment()->CopyAsUnreachable(); |
| 100 | body_environments_[index] = environment(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | void SwitchBuilder::BeginCase(int index) { |
| 105 | set_environment(body_environments_[index]); |
| 106 | environment()->Merge(body_environment_); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | void SwitchBuilder::Break() { |
| 111 | break_environment_->Merge(environment()); |
| 112 | environment()->MarkAsUnreachable(); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void SwitchBuilder::EndCase() { body_environment_ = environment(); } |
| 117 | |
| 118 | |
| 119 | void SwitchBuilder::EndSwitch() { |
| 120 | break_environment_->Merge(label_environment_); |
| 121 | break_environment_->Merge(environment()); |
| 122 | set_environment(break_environment_); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void BlockBuilder::BeginBlock() { |
| 127 | break_environment_ = environment()->CopyAsUnreachable(); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | void BlockBuilder::Break() { |
| 132 | break_environment_->Merge(environment()); |
| 133 | environment()->MarkAsUnreachable(); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | void BlockBuilder::EndBlock() { |
| 138 | break_environment_->Merge(environment()); |
| 139 | set_environment(break_environment_); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } // namespace v8::internal::compiler |