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

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

Issue 12852007: Improve code for !identical(a, b): (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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/intermediate_language.cc » ('j') | runtime/vm/intermediate_language.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/flow_graph_builder.h" 9 #include "vm/flow_graph_builder.h"
10 #include "vm/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
11 #include "vm/hash_map.h" 11 #include "vm/hash_map.h"
12 #include "vm/il_printer.h" 12 #include "vm/il_printer.h"
13 #include "vm/intermediate_language.h" 13 #include "vm/intermediate_language.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/parser.h" 15 #include "vm/parser.h"
16 #include "vm/resolver.h" 16 #include "vm/resolver.h"
17 #include "vm/scopes.h" 17 #include "vm/scopes.h"
18 #include "vm/symbols.h" 18 #include "vm/symbols.h"
19 19
20 namespace dart { 20 namespace dart {
21 21
22 DECLARE_FLAG(bool, eliminate_type_checks);
23 DECLARE_FLAG(bool, enable_type_checks);
24 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details.");
25 DECLARE_FLAG(bool, trace_type_check_elimination);
26 DEFINE_FLAG(bool, use_cha, true, "Use class hierarchy analysis.");
27 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination.");
28 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress");
29 DEFINE_FLAG(bool, trace_constant_propagation, false,
30 "Print constant propagation and useless code elimination.");
31 DEFINE_FLAG(bool, array_bounds_check_elimination, true, 22 DEFINE_FLAG(bool, array_bounds_check_elimination, true,
32 "Eliminate redundant bounds checks."); 23 "Eliminate redundant bounds checks.");
24 DEFINE_FLAG(bool, load_cse, true, "Use redundant load elimination.");
33 DEFINE_FLAG(int, max_polymorphic_checks, 4, 25 DEFINE_FLAG(int, max_polymorphic_checks, 4,
34 "Maximum number of polymorphic check, otherwise it is megamorphic."); 26 "Maximum number of polymorphic check, otherwise it is megamorphic.");
35 DEFINE_FLAG(bool, remove_redundant_phis, true, "Remove redundant phis."); 27 DEFINE_FLAG(bool, remove_redundant_phis, true, "Remove redundant phis.");
28 DEFINE_FLAG(bool, trace_constant_propagation, false,
29 "Print constant propagation and useless code elimination.");
30 DEFINE_FLAG(bool, trace_optimization, false, "Print optimization details.");
31 DEFINE_FLAG(bool, trace_range_analysis, false, "Trace range analysis progress");
36 DEFINE_FLAG(bool, truncating_left_shift, true, 32 DEFINE_FLAG(bool, truncating_left_shift, true,
37 "Optimize left shift to truncate if possible"); 33 "Optimize left shift to truncate if possible");
34 DEFINE_FLAG(bool, use_cha, true, "Use class hierarchy analysis.");
35 DECLARE_FLAG(bool, eliminate_type_checks);
36 DECLARE_FLAG(bool, enable_type_checks);
37 DECLARE_FLAG(bool, trace_type_check_elimination);
38
38 39
39 40
40 void FlowGraphOptimizer::ApplyICData() { 41 void FlowGraphOptimizer::ApplyICData() {
41 VisitBlocks(); 42 VisitBlocks();
42 } 43 }
43 44
44 45
45 // Attempts to convert an instance call (IC call) using propagated class-ids, 46 // Attempts to convert an instance call (IC call) using propagated class-ids,
46 // e.g., receiver class id. 47 // e.g., receiver class id.
47 void FlowGraphOptimizer::ApplyClassIds() { 48 void FlowGraphOptimizer::ApplyClassIds() {
(...skipping 2290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 case Token::kLT: return Token::kGT; 2339 case Token::kLT: return Token::kGT;
2339 case Token::kGT: return Token::kLT; 2340 case Token::kGT: return Token::kLT;
2340 case Token::kLTE: return Token::kGTE; 2341 case Token::kLTE: return Token::kGTE;
2341 case Token::kGTE: return Token::kLTE; 2342 case Token::kGTE: return Token::kLTE;
2342 default: 2343 default:
2343 UNREACHABLE(); 2344 UNREACHABLE();
2344 return Token::kILLEGAL; 2345 return Token::kILLEGAL;
2345 } 2346 }
2346 } 2347 }
2347 2348
2348 // For a comparison operation return an operation for the negated comparison:
2349 // !(a (op) b) === a (op') b
2350 static Token::Kind NegateComparison(Token::Kind op) {
2351 switch (op) {
2352 case Token::kEQ: return Token::kNE;
2353 case Token::kNE: return Token::kEQ;
2354 case Token::kLT: return Token::kGTE;
2355 case Token::kGT: return Token::kLTE;
2356 case Token::kLTE: return Token::kGT;
2357 case Token::kGTE: return Token::kLT;
2358 default:
2359 UNREACHABLE();
2360 return Token::kILLEGAL;
2361 }
2362 }
2363
2364 2349
2365 // Given a boundary (right operand) and a comparison operation return 2350 // Given a boundary (right operand) and a comparison operation return
2366 // a symbolic range constraint for the left operand of the comparison assuming 2351 // a symbolic range constraint for the left operand of the comparison assuming
2367 // that it evaluated to true. 2352 // that it evaluated to true.
2368 // For example for the comparison a < b symbol a is constrained with range 2353 // For example for the comparison a < b symbol a is constrained with range
2369 // [Smi::kMinValue, b - 1]. 2354 // [Smi::kMinValue, b - 1].
2370 static Range* ConstraintRange(Token::Kind op, Definition* boundary) { 2355 static Range* ConstraintRange(Token::Kind op, Definition* boundary) {
2371 switch (op) { 2356 switch (op) {
2372 case Token::kEQ: 2357 case Token::kEQ:
2373 return new Range(RangeBoundary::FromDefinition(boundary), 2358 return new Range(RangeBoundary::FromDefinition(boundary),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 ConstraintRange(op_kind, boundary), 2418 ConstraintRange(op_kind, boundary),
2434 branch->true_successor()); 2419 branch->true_successor());
2435 // Mark true_constraint an artificial use of boundary. This ensures 2420 // Mark true_constraint an artificial use of boundary. This ensures
2436 // that constraint's range is recalculated if boundary's range changes. 2421 // that constraint's range is recalculated if boundary's range changes.
2437 if (true_constraint != NULL) true_constraint->AddDependency(boundary); 2422 if (true_constraint != NULL) true_constraint->AddDependency(boundary);
2438 2423
2439 // Constrain definition with a negated condition at the false successor. 2424 // Constrain definition with a negated condition at the false successor.
2440 ConstraintInstr* false_constraint = 2425 ConstraintInstr* false_constraint =
2441 InsertConstraintFor( 2426 InsertConstraintFor(
2442 defn, 2427 defn,
2443 ConstraintRange(NegateComparison(op_kind), boundary), 2428 ConstraintRange(Token::NegateComparison(op_kind), boundary),
2444 branch->false_successor()); 2429 branch->false_successor());
2445 // Mark false_constraint an artificial use of boundary. This ensures 2430 // Mark false_constraint an artificial use of boundary. This ensures
2446 // that constraint's range is recalculated if boundary's range changes. 2431 // that constraint's range is recalculated if boundary's range changes.
2447 if (false_constraint != NULL) false_constraint->AddDependency(boundary); 2432 if (false_constraint != NULL) false_constraint->AddDependency(boundary);
2448 } 2433 }
2449 } 2434 }
2450 2435
2451 void RangeAnalysis::InsertConstraintsFor(Definition* defn) { 2436 void RangeAnalysis::InsertConstraintsFor(Definition* defn) {
2452 for (Value* use = defn->input_use_list(); 2437 for (Value* use = defn->input_use_list();
2453 use != NULL; 2438 use != NULL;
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
4627 if (changed) { 4612 if (changed) {
4628 // We may have changed the block order and the dominator tree. 4613 // We may have changed the block order and the dominator tree.
4629 flow_graph->DiscoverBlocks(); 4614 flow_graph->DiscoverBlocks();
4630 GrowableArray<BitVector*> dominance_frontier; 4615 GrowableArray<BitVector*> dominance_frontier;
4631 flow_graph->ComputeDominators(&dominance_frontier); 4616 flow_graph->ComputeDominators(&dominance_frontier);
4632 } 4617 }
4633 } 4618 }
4634 4619
4635 4620
4636 } // namespace dart 4621 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language.cc » ('j') | runtime/vm/intermediate_language.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698