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

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

Issue 10431006: First step toward an optimizing compiler: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/flow_graph_optimizer.h"
6
7 #include "vm/flow_graph_builder.h"
8 #include "vm/il_printer.h"
9 #include "vm/object_store.h"
10
11 namespace dart {
12
13 DECLARE_FLAG(bool, print_flow_graph);
14 DECLARE_FLAG(bool, trace_optimization);
15
16 void FlowGraphOptimizer::ApplyICData() {
17 VisitBlocks();
18 if (FLAG_print_flow_graph) {
19 OS::Print("After Optimizations:\n");
20 intptr_t length = block_order_.length();
21 GrowableArray<BlockEntryInstr*> reverse_postorder(length);
22 for (intptr_t i = length - 1; i >= 0; --i) {
23 reverse_postorder.Add(block_order_[i]);
24 }
25 FlowGraphPrinter printer(Function::Handle(), reverse_postorder);
26 printer.PrintBlocks();
27 }
28 }
29
30
31 void FlowGraphOptimizer::VisitBlocks() {
32 for (intptr_t i = 0; i < block_order_.length(); ++i) {
33 Instruction* instr = block_order_[i]->Accept(this);
34 // Compile all successors until an exit, branch, or a block entry.
35 while ((instr != NULL) && !instr->IsBlockEntry()) {
36 instr = instr->Accept(this);
37 }
38 }
39 }
40
41
42 static Token::Kind GetBinaryOp(const String& name) {
43 if (name.Length() == 1) {
44 switch (name.CharAt(0)) {
45 case '+' : return Token::kADD;
46 default: return Token::kILLEGAL;
47 }
48 }
49 return Token::kILLEGAL;
50 }
51
52
53 static bool ICDataHasTwoReceiverClasses(const ICData& ic_data,
54 const Class& cls1,
55 const Class& cls2) {
56 ASSERT(!cls1.IsNull() && !cls2.IsNull());
57 if (ic_data.num_args_tested() != 2) {
58 return false;
59 }
60 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) {
61 GrowableArray<const Class*> classes;
62 Function& target = Function::Handle();
63 ic_data.GetCheckAt(i, &classes, &target);
64 if (!classes.is_empty()) {
Florian Schneider 2012/05/24 02:13:30 It seems that after the check (ic_data.num_args_te
srdjan 2012/05/24 16:41:19 Converted to assert: ASSERT(classes.length() == 2)
65 if (classes[0]->raw() == cls1.raw()) {
66 if (classes[1]->raw() == cls2.raw()) {
67 return true;
68 }
69 }
70 }
71 }
72 return false;
73 }
74
75
76 static bool HasTwoSmi(const ICData& ic_data) {
77 const Class& smi_class =
78 Class::Handle(Isolate::Current()->object_store()->smi_class());
79 return ICDataHasTwoReceiverClasses(ic_data, smi_class, smi_class);
80 }
81
82
83 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp) {
84 if ((comp->ic_data() != NULL) && (!comp->ic_data()->IsNull())) {
85 Token::Kind op_kind = GetBinaryOp(comp->function_name());
86 if (op_kind == Token::kILLEGAL) {
87 // Not a recognized binary operation.
88 return;
89 }
90 if (comp->ic_data()->NumberOfChecks() != 1) {
91 // TODO(srdjan): Not yet supported.
92 return;
93 }
94 if (!HasTwoSmi(*comp->ic_data())) {
95 // TODO(srdjan): Not yet supported.
96 return;
97 }
98 ASSERT(comp->instr() != NULL);
99 ASSERT(comp->InputCount() == 2);
100 BinaryOpComp* bin_op =
101 new BinaryOpComp(op_kind, comp, comp->InputAt(0), comp->InputAt(1));
102 ASSERT(bin_op->ic_data() == NULL);
103 bin_op->set_ic_data(comp->ic_data());
104 bin_op->set_instr(comp->instr());
105 comp->instr()->replace_computation(bin_op);
106 }
107 }
108
109
110 void FlowGraphOptimizer::VisitDo(DoInstr* instr) {
111 instr->computation()->Accept(this);
112 }
113
114
115 void FlowGraphOptimizer::VisitBind(BindInstr* instr) {
116 instr->computation()->Accept(this);
117 }
118
119
120 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698