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

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
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/il_printer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 return false;
72 }
73
74
75 static bool HasTwoSmi(const ICData& ic_data) {
76 const Class& smi_class =
77 Class::Handle(Isolate::Current()->object_store()->smi_class());
78 return ICDataHasTwoReceiverClasses(ic_data, smi_class, smi_class);
79 }
80
81
82 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp) {
83 if ((comp->ic_data() != NULL) && (!comp->ic_data()->IsNull())) {
84 Token::Kind op_kind = GetBinaryOp(comp->function_name());
85 if (op_kind == Token::kILLEGAL) {
86 // Not a recognized binary operation.
87 return;
88 }
89 if (comp->ic_data()->NumberOfChecks() != 1) {
90 // TODO(srdjan): Not yet supported.
91 return;
92 }
93 if (!HasTwoSmi(*comp->ic_data())) {
94 // TODO(srdjan): Not yet supported.
95 return;
96 }
97 ASSERT(comp->instr() != NULL);
98 ASSERT(comp->InputCount() == 2);
99 BinaryOpComp* bin_op =
100 new BinaryOpComp(op_kind, comp, comp->InputAt(0), comp->InputAt(1));
101 ASSERT(bin_op->ic_data() == NULL);
102 bin_op->set_ic_data(comp->ic_data());
103 bin_op->set_instr(comp->instr());
104 comp->instr()->replace_computation(bin_op);
105 }
106 }
107
108
109 void FlowGraphOptimizer::VisitDo(DoInstr* instr) {
110 instr->computation()->Accept(this);
111 }
112
113
114 void FlowGraphOptimizer::VisitBind(BindInstr* instr) {
115 instr->computation()->Accept(this);
116 }
117
118
119 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | runtime/vm/il_printer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698