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

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

Issue 10542167: Inline Math.sqrt in new compilers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
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_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/flow_graph_builder.h" 7 #include "vm/flow_graph_builder.h"
8 #include "vm/il_printer.h" 8 #include "vm/il_printer.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DECLARE_FLAG(bool, enable_type_checks); 13 DECLARE_FLAG(bool, enable_type_checks);
14 DECLARE_FLAG(bool, print_flow_graph); 14 DECLARE_FLAG(bool, print_flow_graph);
15 DECLARE_FLAG(bool, trace_optimization); 15 DECLARE_FLAG(bool, trace_optimization);
16 16
17 // TODO(srdjan): Add _ByteArrayBase, get:length.
18
19 #define RECOGNIZED_LIST(V) \
20 V(ObjectArray, get:length, ObjectArrayLength) \
21 V(ImmutableArray, get:length, ImmutableArrayLength) \
22 V(GrowableObjectArray, get:length, GrowableArrayLength) \
23 V(StringBase, get:length, StringBaseLength) \
24 V(IntegerImplementation, toDouble, IntegerToDouble) \
25 V(Double, toDouble, DoubleToDouble) \
26 V(Math, sqrt, MathSqrt) \
27
28 // Class that recognizes the name and owner of a function and returns the
29 // corresponding enum. See RECOGNIZED_LIST above for list of recognizable
30 // functions.
31 class MethodRecognizer : public AllStatic {
32 public:
33 enum Kind {
34 kUnknown,
35 #define DEFINE_ENUM_LIST(class_name, function_name, enum_name) k##enum_name,
36 RECOGNIZED_LIST(DEFINE_ENUM_LIST)
37 #undef DEFINE_ENUM_LIST
38 };
39
40 static Kind RecognizeKind(const Function& function) {
41 // Only core library methods can be recognized.
42 const Library& core_lib = Library::Handle(Library::CoreLibrary());
43 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
44 const Class& function_class = Class::Handle(function.owner());
45 if ((function_class.library() != core_lib.raw()) &&
46 (function_class.library() != core_impl_lib.raw())) {
47 return kUnknown;
48 }
49 const String& recognize_name = String::Handle(function.name());
50 const String& recognize_class = String::Handle(function_class.Name());
51 String& test_function_name = String::Handle();
52 String& test_class_name = String::Handle();
53 #define RECOGNIZE_FUNCTION(class_name, function_name, enum_name) \
54 test_function_name = String::NewSymbol(#function_name); \
55 test_class_name = String::NewSymbol(#class_name); \
56 if (recognize_name.Equals(test_function_name) && \
57 recognize_class.Equals(test_class_name)) { \
58 return k##enum_name; \
59 }
60 RECOGNIZED_LIST(RECOGNIZE_FUNCTION)
61 #undef RECOGNIZE_FUNCTION
62 return kUnknown;
63 }
64
65 static const char* KindToCString(Kind kind) {
66 #define KIND_TO_STRING(class_name, function_name, enum_name) \
67 if (kind == k##enum_name) return #enum_name;
68 RECOGNIZED_LIST(KIND_TO_STRING)
69 #undef KIND_TO_STRING
70 return "?";
71 }
72 };
73
74
75 void FlowGraphOptimizer::ApplyICData() { 17 void FlowGraphOptimizer::ApplyICData() {
76 VisitBlocks(); 18 VisitBlocks();
77 if (FLAG_print_flow_graph) { 19 if (FLAG_print_flow_graph) {
78 OS::Print("After Optimizations:\n"); 20 OS::Print("After Optimizations:\n");
79 FlowGraphPrinter printer(Function::Handle(), block_order_); 21 FlowGraphPrinter printer(Function::Handle(), block_order_);
80 printer.PrintBlocks(); 22 printer.PrintBlocks();
81 } 23 }
82 } 24 }
83 25
84 26
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 comp->ReplaceWith(call); 416 comp->ReplaceWith(call);
475 } 417 }
476 } 418 }
477 } 419 }
478 420
479 421
480 void FlowGraphOptimizer::VisitStaticCall(StaticCallComp* comp) { 422 void FlowGraphOptimizer::VisitStaticCall(StaticCallComp* comp) {
481 MethodRecognizer::Kind recognized_kind = 423 MethodRecognizer::Kind recognized_kind =
482 MethodRecognizer::RecognizeKind(comp->function()); 424 MethodRecognizer::RecognizeKind(comp->function());
483 if (recognized_kind == MethodRecognizer::kMathSqrt) { 425 if (recognized_kind == MethodRecognizer::kMathSqrt) {
484 // TODO(srdjan): Implement this. 426 comp->set_recognized(MethodRecognizer::kMathSqrt);
485 } 427 }
486 } 428 }
487 429
488 430
489 bool FlowGraphOptimizer::TryInlineInstanceSetter(InstanceSetterComp* comp) { 431 bool FlowGraphOptimizer::TryInlineInstanceSetter(InstanceSetterComp* comp) {
490 ASSERT(comp->HasICData()); 432 ASSERT(comp->HasICData());
491 const ICData& ic_data = *comp->ic_data(); 433 const ICData& ic_data = *comp->ic_data();
492 if (ic_data.NumberOfChecks() == 0) { 434 if (ic_data.NumberOfChecks() == 0) {
493 // No type feedback collected. 435 // No type feedback collected.
494 return false; 436 return false;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 instr->computation()->Accept(this); 584 instr->computation()->Accept(this);
643 } 585 }
644 586
645 587
646 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { 588 void FlowGraphOptimizer::VisitBind(BindInstr* instr) {
647 instr->computation()->Accept(this); 589 instr->computation()->Accept(this);
648 } 590 }
649 591
650 592
651 } // namespace dart 593 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698