Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 10802025: Fuse compare with branch at graph building time. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/flow_graph_compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 252
253 253
254 // Loads context saved in 'context_variable' into the current context. 254 // Loads context saved in 'context_variable' into the current context.
255 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) { 255 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) {
256 Value* load_saved_context = Bind(BuildLoadLocal(variable)); 256 Value* load_saved_context = Bind(BuildLoadLocal(variable));
257 Do(new StoreContextComp(load_saved_context)); 257 Do(new StoreContextComp(load_saved_context));
258 } 258 }
259 259
260 260
261 // TODO(srdjan): This code is clumsy. Try to skip allocation of ComparisonComp
262 // and generate the right BranchInstr directly.
263 // Replaces instruction patterns:
264 // t0 <- Comparison(kind, t0, t1)
265 // t1 <- #true
266 // Branch if t0 === t1 goto (true, false)
267 // With:
268 // Branch if t0 kind t1 goto (true, false)
269 // Returns false if fusing is not possible, e.g:
270 // t0 <- LoadLocal
271 // t1 <- #true
272 // Branch if t0 === t1 goto (true, false)
273 static bool TryFuseBranchInstr(BranchInstr* branch) {
274 UseVal* use = branch->left()->AsUse();
275 if (use == NULL) return false;
276 BindInstr* compare_instr = use->definition()->AsBind();
277 if (compare_instr == NULL) return false;
278 ComparisonComp* compare = compare_instr->computation()->AsComparison();
279 Token::Kind kind;
280 if (compare == NULL) {
281 // Check if there is a BooleanNegate in between Comparison and Branch.
282 BooleanNegateComp* neg = compare_instr->computation()->AsBooleanNegate();
283 if (neg == NULL) return false;
284 if (compare_instr->previous() == NULL) return false;
285 compare_instr = compare_instr->previous()->AsBind();
286 ASSERT(compare_instr != NULL);
287 compare = compare_instr->computation()->AsComparison();
288 if (compare == NULL) return false;
289 // Negation can be handled only in connection with EqualityCompare.
290 if (!compare->IsEqualityCompare()) return false;
291 kind = Token::kNE;
292 } else {
293 kind = compare->kind();
294 }
295 branch->set_kind(kind);
296 branch->SetInputAt(0, compare->InputAt(0));
297 branch->SetInputAt(1, compare->InputAt(1));
298 // Remove elminated nodes.
299 branch->set_previous(compare_instr->previous());
300 compare_instr->previous()->set_next(branch);
301 return true;
302 }
303
261 304
262 void TestGraphVisitor::ReturnValue(Value* value) { 305 void TestGraphVisitor::ReturnValue(Value* value) {
263 if (FLAG_enable_type_checks) { 306 if (FLAG_enable_type_checks) {
264 value = Bind(new AssertBooleanComp(condition_token_pos(), 307 value = Bind(new AssertBooleanComp(condition_token_pos(),
265 owner()->try_index(), 308 owner()->try_index(),
266 value)); 309 value));
267 } 310 }
268 BranchInstr* branch = new BranchInstr(value); 311 const Bool& bool_true = Bool::ZoneHandle(Bool::True());
312 Value* constant_true = Bind(new ConstantVal(bool_true));
313 BranchInstr* branch = new BranchInstr(condition_token_pos(),
314 owner()->try_index(),
315 value,
316 constant_true,
317 Token::kEQ_STRICT);
269 AddInstruction(branch); 318 AddInstruction(branch);
270 CloseFragment(); 319 CloseFragment();
271 true_successor_address_ = branch->true_successor_address(); 320 true_successor_address_ = branch->true_successor_address();
272 false_successor_address_ = branch->false_successor_address(); 321 false_successor_address_ = branch->false_successor_address();
322 TryFuseBranchInstr(branch);
273 } 323 }
274 324
275 325
276 void EffectGraphVisitor::Bailout(const char* reason) { 326 void EffectGraphVisitor::Bailout(const char* reason) {
277 owner()->Bailout(reason); 327 owner()->Bailout(reason);
278 } 328 }
279 329
280 330
281 // <Statement> ::= Return { value: <Expression> 331 // <Statement> ::= Return { value: <Expression>
282 // inlined_finally_list: <InlinedFinally>* } 332 // inlined_finally_list: <InlinedFinally>* }
(...skipping 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 char* chars = reinterpret_cast<char*>( 2704 char* chars = reinterpret_cast<char*>(
2655 Isolate::Current()->current_zone()->Allocate(len)); 2705 Isolate::Current()->current_zone()->Allocate(len));
2656 OS::SNPrint(chars, len, kFormat, function_name, reason); 2706 OS::SNPrint(chars, len, kFormat, function_name, reason);
2657 const Error& error = Error::Handle( 2707 const Error& error = Error::Handle(
2658 LanguageError::New(String::Handle(String::New(chars)))); 2708 LanguageError::New(String::Handle(String::New(chars))));
2659 Isolate::Current()->long_jump_base()->Jump(1, error); 2709 Isolate::Current()->long_jump_base()->Jump(1, error);
2660 } 2710 }
2661 2711
2662 2712
2663 } // namespace dart 2713 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698