OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 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/hydrogen.h" | 5 #include "src/hydrogen.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 current->block_->FinishExit( | 1030 current->block_->FinishExit( |
1031 HAbnormalExit::New(builder_->zone(), NULL), | 1031 HAbnormalExit::New(builder_->zone(), NULL), |
1032 HSourcePosition::Unknown()); | 1032 HSourcePosition::Unknown()); |
1033 } | 1033 } |
1034 current = current->next_; | 1034 current = current->next_; |
1035 } | 1035 } |
1036 builder_->set_current_block(merge_block); | 1036 builder_->set_current_block(merge_block); |
1037 } | 1037 } |
1038 | 1038 |
1039 | 1039 |
1040 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, | 1040 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder) { |
1041 HValue* context, | 1041 Initialize(builder, NULL, kWhileTrue, NULL); |
1042 LoopBuilder::Direction direction) | 1042 } |
1043 : builder_(builder), | 1043 |
1044 context_(context), | 1044 |
1045 direction_(direction), | 1045 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, HValue* context, |
1046 finished_(false) { | 1046 LoopBuilder::Direction direction) { |
| 1047 Initialize(builder, context, direction, builder->graph()->GetConstant1()); |
| 1048 } |
| 1049 |
| 1050 |
| 1051 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, HValue* context, |
| 1052 LoopBuilder::Direction direction, |
| 1053 HValue* increment_amount) { |
| 1054 Initialize(builder, context, direction, increment_amount); |
| 1055 increment_amount_ = increment_amount; |
| 1056 } |
| 1057 |
| 1058 |
| 1059 void HGraphBuilder::LoopBuilder::Initialize(HGraphBuilder* builder, |
| 1060 HValue* context, |
| 1061 Direction direction, |
| 1062 HValue* increment_amount) { |
| 1063 builder_ = builder; |
| 1064 context_ = context; |
| 1065 direction_ = direction; |
| 1066 increment_amount_ = increment_amount; |
| 1067 |
| 1068 finished_ = false; |
1047 header_block_ = builder->CreateLoopHeaderBlock(); | 1069 header_block_ = builder->CreateLoopHeaderBlock(); |
1048 body_block_ = NULL; | 1070 body_block_ = NULL; |
1049 exit_block_ = NULL; | 1071 exit_block_ = NULL; |
1050 exit_trampoline_block_ = NULL; | 1072 exit_trampoline_block_ = NULL; |
1051 increment_amount_ = builder_->graph()->GetConstant1(); | |
1052 } | 1073 } |
1053 | 1074 |
1054 | 1075 |
1055 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, | |
1056 HValue* context, | |
1057 LoopBuilder::Direction direction, | |
1058 HValue* increment_amount) | |
1059 : builder_(builder), | |
1060 context_(context), | |
1061 direction_(direction), | |
1062 finished_(false) { | |
1063 header_block_ = builder->CreateLoopHeaderBlock(); | |
1064 body_block_ = NULL; | |
1065 exit_block_ = NULL; | |
1066 exit_trampoline_block_ = NULL; | |
1067 increment_amount_ = increment_amount; | |
1068 } | |
1069 | |
1070 | |
1071 HValue* HGraphBuilder::LoopBuilder::BeginBody( | 1076 HValue* HGraphBuilder::LoopBuilder::BeginBody( |
1072 HValue* initial, | 1077 HValue* initial, |
1073 HValue* terminating, | 1078 HValue* terminating, |
1074 Token::Value token) { | 1079 Token::Value token) { |
| 1080 ASSERT(direction_ != kWhileTrue); |
1075 HEnvironment* env = builder_->environment(); | 1081 HEnvironment* env = builder_->environment(); |
1076 phi_ = header_block_->AddNewPhi(env->values()->length()); | 1082 phi_ = header_block_->AddNewPhi(env->values()->length()); |
1077 phi_->AddInput(initial); | 1083 phi_->AddInput(initial); |
1078 env->Push(initial); | 1084 env->Push(initial); |
1079 builder_->GotoNoSimulate(header_block_); | 1085 builder_->GotoNoSimulate(header_block_); |
1080 | 1086 |
1081 HEnvironment* body_env = env->Copy(); | 1087 HEnvironment* body_env = env->Copy(); |
1082 HEnvironment* exit_env = env->Copy(); | 1088 HEnvironment* exit_env = env->Copy(); |
1083 // Remove the phi from the expression stack | 1089 // Remove the phi from the expression stack |
1084 body_env->Pop(); | 1090 body_env->Pop(); |
(...skipping 16 matching lines...) Expand all Loading... |
1101 } | 1107 } |
1102 increment_->ClearFlag(HValue::kCanOverflow); | 1108 increment_->ClearFlag(HValue::kCanOverflow); |
1103 builder_->AddInstruction(increment_); | 1109 builder_->AddInstruction(increment_); |
1104 return increment_; | 1110 return increment_; |
1105 } else { | 1111 } else { |
1106 return phi_; | 1112 return phi_; |
1107 } | 1113 } |
1108 } | 1114 } |
1109 | 1115 |
1110 | 1116 |
| 1117 void HGraphBuilder::LoopBuilder::BeginBody(int drop_count) { |
| 1118 ASSERT(direction_ == kWhileTrue); |
| 1119 HEnvironment* env = builder_->environment(); |
| 1120 builder_->GotoNoSimulate(header_block_); |
| 1121 builder_->set_current_block(header_block_); |
| 1122 env->Drop(drop_count); |
| 1123 } |
| 1124 |
| 1125 |
1111 void HGraphBuilder::LoopBuilder::Break() { | 1126 void HGraphBuilder::LoopBuilder::Break() { |
1112 if (exit_trampoline_block_ == NULL) { | 1127 if (exit_trampoline_block_ == NULL) { |
1113 // Its the first time we saw a break. | 1128 // Its the first time we saw a break. |
1114 HEnvironment* env = exit_block_->last_environment()->Copy(); | 1129 if (direction_ == kWhileTrue) { |
1115 exit_trampoline_block_ = builder_->CreateBasicBlock(env); | 1130 HEnvironment* env = builder_->environment()->Copy(); |
1116 builder_->GotoNoSimulate(exit_block_, exit_trampoline_block_); | 1131 exit_trampoline_block_ = builder_->CreateBasicBlock(env); |
| 1132 } else { |
| 1133 HEnvironment* env = exit_block_->last_environment()->Copy(); |
| 1134 exit_trampoline_block_ = builder_->CreateBasicBlock(env); |
| 1135 builder_->GotoNoSimulate(exit_block_, exit_trampoline_block_); |
| 1136 } |
1117 } | 1137 } |
1118 | 1138 |
1119 builder_->GotoNoSimulate(exit_trampoline_block_); | 1139 builder_->GotoNoSimulate(exit_trampoline_block_); |
1120 builder_->set_current_block(NULL); | 1140 builder_->set_current_block(NULL); |
1121 } | 1141 } |
1122 | 1142 |
1123 | 1143 |
1124 void HGraphBuilder::LoopBuilder::EndBody() { | 1144 void HGraphBuilder::LoopBuilder::EndBody() { |
1125 ASSERT(!finished_); | 1145 ASSERT(!finished_); |
1126 | 1146 |
1127 if (direction_ == kPostIncrement || direction_ == kPostDecrement) { | 1147 if (direction_ == kPostIncrement || direction_ == kPostDecrement) { |
1128 if (direction_ == kPostIncrement) { | 1148 if (direction_ == kPostIncrement) { |
1129 increment_ = HAdd::New(zone(), context_, phi_, increment_amount_); | 1149 increment_ = HAdd::New(zone(), context_, phi_, increment_amount_); |
1130 } else { | 1150 } else { |
1131 increment_ = HSub::New(zone(), context_, phi_, increment_amount_); | 1151 increment_ = HSub::New(zone(), context_, phi_, increment_amount_); |
1132 } | 1152 } |
1133 increment_->ClearFlag(HValue::kCanOverflow); | 1153 increment_->ClearFlag(HValue::kCanOverflow); |
1134 builder_->AddInstruction(increment_); | 1154 builder_->AddInstruction(increment_); |
1135 } | 1155 } |
1136 | 1156 |
1137 // Push the new increment value on the expression stack to merge into the phi. | 1157 if (direction_ != kWhileTrue) { |
1138 builder_->environment()->Push(increment_); | 1158 // Push the new increment value on the expression stack to merge into |
| 1159 // the phi. |
| 1160 builder_->environment()->Push(increment_); |
| 1161 } |
1139 HBasicBlock* last_block = builder_->current_block(); | 1162 HBasicBlock* last_block = builder_->current_block(); |
1140 builder_->GotoNoSimulate(last_block, header_block_); | 1163 builder_->GotoNoSimulate(last_block, header_block_); |
1141 header_block_->loop_information()->RegisterBackEdge(last_block); | 1164 header_block_->loop_information()->RegisterBackEdge(last_block); |
1142 | 1165 |
1143 if (exit_trampoline_block_ != NULL) { | 1166 if (exit_trampoline_block_ != NULL) { |
1144 builder_->set_current_block(exit_trampoline_block_); | 1167 builder_->set_current_block(exit_trampoline_block_); |
1145 } else { | 1168 } else { |
1146 builder_->set_current_block(exit_block_); | 1169 builder_->set_current_block(exit_block_); |
1147 } | 1170 } |
1148 finished_ = true; | 1171 finished_ = true; |
(...skipping 11227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12376 if (ShouldProduceTraceOutput()) { | 12399 if (ShouldProduceTraceOutput()) { |
12377 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 12400 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
12378 } | 12401 } |
12379 | 12402 |
12380 #ifdef DEBUG | 12403 #ifdef DEBUG |
12381 graph_->Verify(false); // No full verify. | 12404 graph_->Verify(false); // No full verify. |
12382 #endif | 12405 #endif |
12383 } | 12406 } |
12384 | 12407 |
12385 } } // namespace v8::internal | 12408 } } // namespace v8::internal |
OLD | NEW |