Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 // Loads context saved in 'context_variable' into the current context. | 239 // Loads context saved in 'context_variable' into the current context. |
| 240 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) { | 240 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) { |
| 241 Value* load_saved_context = Bind(BuildLoadLocal(variable)); | 241 Value* load_saved_context = Bind(BuildLoadLocal(variable)); |
| 242 Do(new StoreContextComp(load_saved_context)); | 242 Do(new StoreContextComp(load_saved_context)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 | 245 |
| 246 // TODO(srdjan): This code is clumsy. Try to skip allocation of ComparisonComp | |
|
Kevin Millikin (Google)
2012/07/19 12:28:05
A way to do this is to implement TestGraphVisitor:
| |
| 247 // and generate the right BranchInstr directly. | |
| 248 // Replaces instruction patterns: | |
| 249 // t0 <- Comparison(kind, t0, t1) | |
| 250 // t1 <- #true | |
| 251 // Branch if t0 === t1 goto (true, false) | |
| 252 // With: | |
| 253 // Branch if t0 kind t1 goto (true, false) | |
| 254 // Returns false if fusing is not possible, e.g: | |
| 255 // t0 <- LoadLocal | |
| 256 // t1 <- #true | |
| 257 // Branch if t0 === t1 goto (true, false) | |
| 258 static bool TryFuseBranchInstr(BranchInstr* branch) { | |
| 259 UseVal* use = branch->left()->AsUse(); | |
| 260 if (use == NULL) return false; | |
| 261 BindInstr* compare_instr = use->definition()->AsBind(); | |
| 262 if (compare_instr == NULL) return false; | |
| 263 ComparisonComp* compare = compare_instr->computation()->AsComparison(); | |
| 264 Token::Kind kind; | |
| 265 if (compare == NULL) { | |
| 266 // Check if there is a BooleanNegate in between Comparison and Branch. | |
| 267 BooleanNegateComp* neg = compare_instr->computation()->AsBooleanNegate(); | |
| 268 if (neg == NULL) return false; | |
| 269 compare_instr = compare_instr->previous()->AsBind(); | |
|
Kevin Millikin (Google)
2012/07/19 12:28:05
I guess previous() is non-NULL because boolean neg
srdjan
2012/07/19 15:33:58
Agree.
Added another test:
if (compare_instr->pre
| |
| 270 ASSERT(compare_instr != NULL); | |
| 271 compare = compare_instr->computation()->AsComparison(); | |
| 272 if (compare == NULL) return false; | |
| 273 // Negation can be handled only in connection with EqualityCompare. | |
| 274 if (!compare->IsEqualityCompare()) return false; | |
| 275 kind = Token::kNE; | |
| 276 } else { | |
| 277 kind = compare->kind(); | |
| 278 } | |
| 279 branch->set_kind(kind); | |
| 280 branch->SetInputAt(0, compare->InputAt(0)); | |
| 281 branch->SetInputAt(1, compare->InputAt(1)); | |
| 282 // Remove elminated nodes. | |
| 283 branch->set_previous(compare_instr->previous()); | |
| 284 compare_instr->previous()->set_next(branch); | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 246 | 288 |
| 247 void TestGraphVisitor::ReturnValue(Value* value) { | 289 void TestGraphVisitor::ReturnValue(Value* value) { |
| 248 if (FLAG_enable_type_checks) { | 290 if (FLAG_enable_type_checks) { |
| 249 value = Bind(new AssertBooleanComp(condition_token_pos(), | 291 value = Bind(new AssertBooleanComp(condition_token_pos(), |
| 250 owner()->try_index(), | 292 owner()->try_index(), |
| 251 value)); | 293 value)); |
| 252 } | 294 } |
| 253 BranchInstr* branch = new BranchInstr(value); | 295 const Bool& bool_true = Bool::ZoneHandle(Bool::True()); |
| 296 Value* constant_true = Bind(new ConstantVal(bool_true)); | |
| 297 BranchInstr* branch = new BranchInstr(condition_token_pos(), | |
| 298 owner()->try_index(), | |
| 299 value, | |
| 300 constant_true, | |
| 301 Token::kEQ_STRICT); | |
| 254 AddInstruction(branch); | 302 AddInstruction(branch); |
| 255 CloseFragment(); | 303 CloseFragment(); |
| 256 true_successor_address_ = branch->true_successor_address(); | 304 true_successor_address_ = branch->true_successor_address(); |
| 257 false_successor_address_ = branch->false_successor_address(); | 305 false_successor_address_ = branch->false_successor_address(); |
| 306 TryFuseBranchInstr(branch); | |
| 258 } | 307 } |
| 259 | 308 |
| 260 | 309 |
| 261 void EffectGraphVisitor::Bailout(const char* reason) { | 310 void EffectGraphVisitor::Bailout(const char* reason) { |
| 262 owner()->Bailout(reason); | 311 owner()->Bailout(reason); |
| 263 } | 312 } |
| 264 | 313 |
| 265 | 314 |
| 266 // <Statement> ::= Return { value: <Expression> | 315 // <Statement> ::= Return { value: <Expression> |
| 267 // inlined_finally_list: <InlinedFinally>* } | 316 // inlined_finally_list: <InlinedFinally>* } |
| (...skipping 2403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2671 char* chars = reinterpret_cast<char*>( | 2720 char* chars = reinterpret_cast<char*>( |
| 2672 Isolate::Current()->current_zone()->Allocate(len)); | 2721 Isolate::Current()->current_zone()->Allocate(len)); |
| 2673 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2722 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2674 const Error& error = Error::Handle( | 2723 const Error& error = Error::Handle( |
| 2675 LanguageError::New(String::Handle(String::New(chars)))); | 2724 LanguageError::New(String::Handle(String::New(chars)))); |
| 2676 Isolate::Current()->long_jump_base()->Jump(1, error); | 2725 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2677 } | 2726 } |
| 2678 | 2727 |
| 2679 | 2728 |
| 2680 } // namespace dart | 2729 } // namespace dart |
| OLD | NEW |