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

Side by Side Diff: src/lithium.cc

Issue 6128007: Reuse the gap move resolver. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge/build/ia32
Patch Set: Created 9 years, 11 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 | « src/lithium.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void set_assigned_from(LGapNode* n) { assigned_from_.set(n); } 53 void set_assigned_from(LGapNode* n) { assigned_from_.set(n); }
54 54
55 private: 55 private:
56 LOperand* operand_; 56 LOperand* operand_;
57 SetOncePointer<LGapNode> assigned_from_; 57 SetOncePointer<LGapNode> assigned_from_;
58 bool resolved_; 58 bool resolved_;
59 int visited_id_; 59 int visited_id_;
60 }; 60 };
61 61
62 62
63 LGapResolver::LGapResolver(const ZoneList<LMoveOperands>* moves, 63 LGapResolver::LGapResolver()
64 LOperand* marker_operand) 64 : nodes_(32),
65 : nodes_(4),
66 identified_cycles_(4), 65 identified_cycles_(4),
67 result_(4), 66 result_(16),
68 marker_operand_(marker_operand),
69 next_visited_id_(0) { 67 next_visited_id_(0) {
68 }
69
70
71 const ZoneList<LMoveOperands>* LGapResolver::Resolve(
72 const ZoneList<LMoveOperands>* moves,
73 LOperand* marker_operand) {
74 nodes_.Rewind(0);
75 identified_cycles_.Rewind(0);
76 result_.Rewind(0);
77 next_visited_id_ = 0;
78
70 for (int i = 0; i < moves->length(); ++i) { 79 for (int i = 0; i < moves->length(); ++i) {
71 LMoveOperands move = moves->at(i); 80 LMoveOperands move = moves->at(i);
72 if (!move.IsRedundant()) RegisterMove(move); 81 if (!move.IsRedundant()) RegisterMove(move);
73 } 82 }
74 }
75 83
76
77 const ZoneList<LMoveOperands>* LGapResolver::ResolveInReverseOrder() {
78 for (int i = 0; i < identified_cycles_.length(); ++i) { 84 for (int i = 0; i < identified_cycles_.length(); ++i) {
79 ResolveCycle(identified_cycles_[i]); 85 ResolveCycle(identified_cycles_[i], marker_operand);
80 } 86 }
81 87
82 int unresolved_nodes; 88 int unresolved_nodes;
83 do { 89 do {
84 unresolved_nodes = 0; 90 unresolved_nodes = 0;
85 for (int j = 0; j < nodes_.length(); j++) { 91 for (int j = 0; j < nodes_.length(); j++) {
86 LGapNode* node = nodes_[j]; 92 LGapNode* node = nodes_[j];
87 if (!node->IsResolved() && node->assigned_from()->IsResolved()) { 93 if (!node->IsResolved() && node->assigned_from()->IsResolved()) {
88 AddResultMove(node->assigned_from(), node); 94 AddResultMove(node->assigned_from(), node);
89 node->MarkResolved(); 95 node->MarkResolved();
90 } 96 }
91 if (!node->IsResolved()) ++unresolved_nodes; 97 if (!node->IsResolved()) ++unresolved_nodes;
92 } 98 }
93 } while (unresolved_nodes > 0); 99 } while (unresolved_nodes > 0);
94 return &result_; 100 return &result_;
95 } 101 }
96 102
97 103
98 void LGapResolver::AddResultMove(LGapNode* from, LGapNode* to) { 104 void LGapResolver::AddResultMove(LGapNode* from, LGapNode* to) {
99 AddResultMove(from->operand(), to->operand()); 105 AddResultMove(from->operand(), to->operand());
100 } 106 }
101 107
102 108
103 void LGapResolver::AddResultMove(LOperand* from, LOperand* to) { 109 void LGapResolver::AddResultMove(LOperand* from, LOperand* to) {
104 result_.Add(LMoveOperands(from, to)); 110 result_.Add(LMoveOperands(from, to));
105 } 111 }
106 112
107 113
108 void LGapResolver::ResolveCycle(LGapNode* start) { 114 void LGapResolver::ResolveCycle(LGapNode* start, LOperand* marker_operand) {
109 ZoneList<LOperand*> circle_operands(8); 115 ZoneList<LOperand*> cycle_operands(8);
110 circle_operands.Add(marker_operand_); 116 cycle_operands.Add(marker_operand);
111 LGapNode* cur = start; 117 LGapNode* cur = start;
112 do { 118 do {
113 cur->MarkResolved(); 119 cur->MarkResolved();
114 circle_operands.Add(cur->operand()); 120 cycle_operands.Add(cur->operand());
115 cur = cur->assigned_from(); 121 cur = cur->assigned_from();
116 } while (cur != start); 122 } while (cur != start);
117 circle_operands.Add(marker_operand_); 123 cycle_operands.Add(marker_operand);
118 124
119 for (int i = circle_operands.length() - 1; i > 0; --i) { 125 for (int i = cycle_operands.length() - 1; i > 0; --i) {
120 LOperand* from = circle_operands[i]; 126 LOperand* from = cycle_operands[i];
121 LOperand* to = circle_operands[i - 1]; 127 LOperand* to = cycle_operands[i - 1];
122 AddResultMove(from, to); 128 AddResultMove(from, to);
123 } 129 }
124 } 130 }
125 131
126 132
127 bool LGapResolver::CanReach(LGapNode* a, LGapNode* b, int visited_id) { 133 bool LGapResolver::CanReach(LGapNode* a, LGapNode* b, int visited_id) {
128 ASSERT(a != b); 134 ASSERT(a != b);
129 LGapNode* cur = a; 135 LGapNode* cur = a;
130 while (cur != b && cur->visited_id() != visited_id && cur->IsAssigned()) { 136 while (cur != b && cur->visited_id() != visited_id && cur->IsAssigned()) {
131 cur->set_visited_id(visited_id); 137 cur->set_visited_id(visited_id);
(...skipping 17 matching lines...) Expand all
149 AddResultMove(move.from(), move.to()); 155 AddResultMove(move.from(), move.to());
150 } else { 156 } else {
151 LGapNode* from = LookupNode(move.from()); 157 LGapNode* from = LookupNode(move.from());
152 LGapNode* to = LookupNode(move.to()); 158 LGapNode* to = LookupNode(move.to());
153 if (to->IsAssigned() && to->assigned_from() == from) { 159 if (to->IsAssigned() && to->assigned_from() == from) {
154 move.Eliminate(); 160 move.Eliminate();
155 return; 161 return;
156 } 162 }
157 ASSERT(!to->IsAssigned()); 163 ASSERT(!to->IsAssigned());
158 if (CanReach(from, to)) { 164 if (CanReach(from, to)) {
159 // This introduces a circle. Save. 165 // This introduces a cycle. Save.
160 identified_cycles_.Add(from); 166 identified_cycles_.Add(from);
161 } 167 }
162 to->set_assigned_from(from); 168 to->set_assigned_from(from);
163 } 169 }
164 } 170 }
165 171
166 172
167 LGapNode* LGapResolver::LookupNode(LOperand* operand) { 173 LGapNode* LGapResolver::LookupNode(LOperand* operand) {
168 for (int i = 0; i < nodes_.length(); ++i) { 174 for (int i = 0; i < nodes_.length(); ++i) {
169 if (nodes_[i]->operand()->Equals(operand)) return nodes_[i]; 175 if (nodes_[i]->operand()->Equals(operand)) return nodes_[i];
(...skipping 26 matching lines...) Expand all
196 stream->Add(" = "); 202 stream->Add(" = ");
197 from->PrintTo(stream); 203 from->PrintTo(stream);
198 } 204 }
199 stream->Add("; "); 205 stream->Add("; ");
200 } 206 }
201 } 207 }
202 } 208 }
203 209
204 210
205 } } // namespace v8::internal 211 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/lithium.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698