OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 24 matching lines...) Expand all Loading... |
35 #include "zone-inl.h" | 35 #include "zone-inl.h" |
36 | 36 |
37 namespace v8 { | 37 namespace v8 { |
38 namespace internal { | 38 namespace internal { |
39 | 39 |
40 // Forward declarations. | 40 // Forward declarations. |
41 class Node; | 41 class Node; |
42 | 42 |
43 class BitVector: public ZoneObject { | 43 class BitVector: public ZoneObject { |
44 public: | 44 public: |
45 explicit BitVector(int length) | 45 BitVector() : length_(0), data_length_(0), data_(NULL) { } |
46 : length_(length), | 46 |
47 data_length_(SizeFor(length)), | 47 explicit BitVector(int length) { |
48 data_(Zone::NewArray<uint32_t>(data_length_)) { | 48 ExpandTo(length); |
49 ASSERT(length > 0); | |
50 Clear(); | |
51 } | 49 } |
52 | 50 |
53 BitVector(const BitVector& other) | 51 BitVector(const BitVector& other) |
54 : length_(other.length()), | 52 : length_(other.length()), |
55 data_length_(SizeFor(length_)), | 53 data_length_(SizeFor(length_)), |
56 data_(Zone::NewArray<uint32_t>(data_length_)) { | 54 data_(Zone::NewArray<uint32_t>(data_length_)) { |
57 CopyFrom(other); | 55 CopyFrom(other); |
58 } | 56 } |
59 | 57 |
60 static int SizeFor(int length) { | 58 void ExpandTo(int length) { |
61 return 1 + ((length - 1) / 32); | 59 ASSERT(length > 0); |
| 60 length_ = length; |
| 61 data_length_ = SizeFor(length); |
| 62 data_ = Zone::NewArray<uint32_t>(data_length_); |
| 63 Clear(); |
62 } | 64 } |
63 | 65 |
64 BitVector& operator=(const BitVector& rhs) { | 66 BitVector& operator=(const BitVector& rhs) { |
65 if (this != &rhs) CopyFrom(rhs); | 67 if (this != &rhs) CopyFrom(rhs); |
66 return *this; | 68 return *this; |
67 } | 69 } |
68 | 70 |
69 void CopyFrom(const BitVector& other) { | 71 void CopyFrom(const BitVector& other) { |
70 ASSERT(other.length() == length()); | 72 ASSERT(other.length() == length()); |
71 for (int i = 0; i < data_length_; i++) { | 73 for (int i = 0; i < data_length_; i++) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return true; | 132 return true; |
131 } | 133 } |
132 | 134 |
133 int length() const { return length_; } | 135 int length() const { return length_; } |
134 | 136 |
135 #ifdef DEBUG | 137 #ifdef DEBUG |
136 void Print(); | 138 void Print(); |
137 #endif | 139 #endif |
138 | 140 |
139 private: | 141 private: |
| 142 static int SizeFor(int length) { |
| 143 return 1 + ((length - 1) / 32); |
| 144 } |
| 145 |
140 int length_; | 146 int length_; |
141 int data_length_; | 147 int data_length_; |
142 uint32_t* data_; | 148 uint32_t* data_; |
143 }; | 149 }; |
144 | 150 |
145 | 151 |
146 // Simple fixed-capacity list-based worklist (managed as a queue) of | 152 // Simple fixed-capacity list-based worklist (managed as a queue) of |
147 // pointers to T. | 153 // pointers to T. |
148 template<typename T> | 154 template<typename T> |
149 class WorkList BASE_EMBEDDED { | 155 class WorkList BASE_EMBEDDED { |
(...skipping 30 matching lines...) Expand all Loading... |
180 } | 186 } |
181 | 187 |
182 private: | 188 private: |
183 int capacity_; // Including one empty slot. | 189 int capacity_; // Including one empty slot. |
184 int head_; // Where the first item is. | 190 int head_; // Where the first item is. |
185 int tail_; // Where the next inserted item will go. | 191 int tail_; // Where the next inserted item will go. |
186 List<T*> queue_; | 192 List<T*> queue_; |
187 }; | 193 }; |
188 | 194 |
189 | 195 |
190 struct ReachingDefinitionsData BASE_EMBEDDED { | |
191 public: | |
192 ReachingDefinitionsData() : rd_in_(NULL), kill_(NULL), gen_(NULL) {} | |
193 | |
194 void Initialize(int definition_count) { | |
195 rd_in_ = new BitVector(definition_count); | |
196 kill_ = new BitVector(definition_count); | |
197 gen_ = new BitVector(definition_count); | |
198 } | |
199 | |
200 BitVector* rd_in() { return rd_in_; } | |
201 BitVector* kill() { return kill_; } | |
202 BitVector* gen() { return gen_; } | |
203 | |
204 private: | |
205 BitVector* rd_in_; | |
206 BitVector* kill_; | |
207 BitVector* gen_; | |
208 }; | |
209 | |
210 | |
211 // This class is used to number all expressions in the AST according to | |
212 // their evaluation order (post-order left-to-right traversal). | |
213 class AstLabeler: public AstVisitor { | |
214 public: | |
215 AstLabeler() : next_number_(0) {} | |
216 | |
217 void Label(CompilationInfo* info); | |
218 | |
219 private: | |
220 CompilationInfo* info() { return info_; } | |
221 | |
222 void VisitDeclarations(ZoneList<Declaration*>* decls); | |
223 void VisitStatements(ZoneList<Statement*>* stmts); | |
224 | |
225 // AST node visit functions. | |
226 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | |
227 AST_NODE_LIST(DECLARE_VISIT) | |
228 #undef DECLARE_VISIT | |
229 | |
230 // Traversal number for labelling AST nodes. | |
231 int next_number_; | |
232 | |
233 CompilationInfo* info_; | |
234 | |
235 DISALLOW_COPY_AND_ASSIGN(AstLabeler); | |
236 }; | |
237 | |
238 | |
239 // Computes the set of assigned variables and annotates variables proxies | 196 // Computes the set of assigned variables and annotates variables proxies |
240 // that are trivial sub-expressions and for-loops where the loop variable | 197 // that are trivial sub-expressions and for-loops where the loop variable |
241 // is guaranteed to be a smi. | 198 // is guaranteed to be a smi. |
242 class AssignedVariablesAnalyzer : public AstVisitor { | 199 class AssignedVariablesAnalyzer : public AstVisitor { |
243 public: | 200 public: |
244 explicit AssignedVariablesAnalyzer(FunctionLiteral* fun); | 201 explicit AssignedVariablesAnalyzer(FunctionLiteral* fun) : fun_(fun) { } |
245 | 202 bool Analyze(); |
246 void Analyze(); | |
247 | 203 |
248 private: | 204 private: |
249 Variable* FindSmiLoopVariable(ForStatement* stmt); | 205 Variable* FindSmiLoopVariable(ForStatement* stmt); |
250 | 206 |
251 int BitIndex(Variable* var); | 207 int BitIndex(Variable* var); |
252 | 208 |
253 void RecordAssignedVar(Variable* var); | 209 void RecordAssignedVar(Variable* var); |
254 | 210 |
255 void MarkIfTrivial(Expression* expr); | 211 void MarkIfTrivial(Expression* expr); |
256 | 212 |
(...skipping 12 matching lines...) Expand all Loading... |
269 BitVector av_; | 225 BitVector av_; |
270 | 226 |
271 DISALLOW_COPY_AND_ASSIGN(AssignedVariablesAnalyzer); | 227 DISALLOW_COPY_AND_ASSIGN(AssignedVariablesAnalyzer); |
272 }; | 228 }; |
273 | 229 |
274 | 230 |
275 } } // namespace v8::internal | 231 } } // namespace v8::internal |
276 | 232 |
277 | 233 |
278 #endif // V8_DATAFLOW_H_ | 234 #endif // V8_DATAFLOW_H_ |
OLD | NEW |