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

Side by Side Diff: src/ast.cc

Issue 1321993004: Vector ICs: ObjectLiteral refactoring for Oracle feedback (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE, turned off flag. Created 5 years, 3 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
« no previous file with comments | « src/ast.h ('k') | src/ast-numbering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast.h" 5 #include "src/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "src/builtins.h" 8 #include "src/builtins.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/contexts.h" 10 #include "src/contexts.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope()); 244 DCHECK_NOT_NULL(expr->AsFunctionLiteral()->scope());
245 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject(); 245 return expr->AsFunctionLiteral()->scope()->NeedsHomeObject();
246 } 246 }
247 247
248 248
249 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value, 249 ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value,
250 Kind kind, bool is_static, 250 Kind kind, bool is_static,
251 bool is_computed_name) 251 bool is_computed_name)
252 : key_(key), 252 : key_(key),
253 value_(value), 253 value_(value),
254 ic_slot_or_count_(FeedbackVectorICSlot::Invalid().ToInt()),
254 kind_(kind), 255 kind_(kind),
255 emit_store_(true), 256 emit_store_(true),
256 is_static_(is_static), 257 is_static_(is_static),
257 is_computed_name_(is_computed_name) {} 258 is_computed_name_(is_computed_name) {}
258 259
259 260
260 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, 261 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory,
261 Expression* key, Expression* value, 262 Expression* key, Expression* value,
262 bool is_static, 263 bool is_static,
263 bool is_computed_name) 264 bool is_computed_name)
264 : key_(key), 265 : key_(key),
265 value_(value), 266 value_(value),
267 ic_slot_or_count_(FeedbackVectorICSlot::Invalid().ToInt()),
266 emit_store_(true), 268 emit_store_(true),
267 is_static_(is_static), 269 is_static_(is_static),
268 is_computed_name_(is_computed_name) { 270 is_computed_name_(is_computed_name) {
269 if (!is_computed_name && 271 if (!is_computed_name &&
270 key->AsLiteral()->raw_value()->EqualsString( 272 key->AsLiteral()->raw_value()->EqualsString(
271 ast_value_factory->proto_string())) { 273 ast_value_factory->proto_string())) {
272 kind_ = PROTOTYPE; 274 kind_ = PROTOTYPE;
273 } else if (value_->AsMaterializedLiteral() != NULL) { 275 } else if (value_->AsMaterializedLiteral() != NULL) {
274 kind_ = MATERIALIZED_LITERAL; 276 kind_ = MATERIALIZED_LITERAL;
275 } else if (value_->IsLiteral()) { 277 } else if (value_->IsLiteral()) {
276 kind_ = CONSTANT; 278 kind_ = CONSTANT;
277 } else { 279 } else {
278 kind_ = COMPUTED; 280 kind_ = COMPUTED;
279 } 281 }
280 } 282 }
281 283
282 284
283 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements( 285 FeedbackVectorRequirements ClassLiteral::ComputeFeedbackRequirements(
284 Isolate* isolate, const ICSlotCache* cache) { 286 Isolate* isolate, const ICSlotCache* cache) {
285 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); 287 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0);
286 288
287 // This logic that computes the number of slots needed for vector store 289 // This logic that computes the number of slots needed for vector store
288 // ICs must mirror FullCodeGenerator::VisitClassLiteral. 290 // ICs must mirror FullCodeGenerator::VisitClassLiteral.
289 int ic_slots = 0; 291 int ic_slots = 0;
290 for (int i = 0; i < properties()->length(); i++) { 292 if (NeedsProxySlot()) {
291 ObjectLiteral::Property* property = properties()->at(i);
292
293 Expression* value = property->value();
294 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++;
295 }
296
297 if (scope() != NULL && class_variable_proxy()->var()->IsUnallocated()) {
298 ic_slots++; 293 ic_slots++;
299 } 294 }
300 295
301 #ifdef DEBUG 296 for (int i = 0; i < properties()->length(); i++) {
302 // FullCodeGenerator::VisitClassLiteral verifies that it consumes slot_count_ 297 ObjectLiteral::Property* property = properties()->at(i);
303 // slots. 298 // In case we don't end up using any slots.
304 slot_count_ = ic_slots; 299 property->set_ic_slot_count(0);
305 #endif 300
301 Expression* value = property->value();
302 if (FunctionLiteral::NeedsHomeObject(value)) {
303 property->set_ic_slot_count(1);
304 ic_slots++;
305 }
306 }
307
306 return FeedbackVectorRequirements(0, ic_slots); 308 return FeedbackVectorRequirements(0, ic_slots);
307 } 309 }
308 310
309 311
310 FeedbackVectorICSlot ClassLiteral::SlotForHomeObject(Expression* value, 312 void ClassLiteral::LayoutFeedbackSlots() {
311 int* slot_index) const { 313 int base_slot = slot_.ToInt();
312 if (FLAG_vector_stores && FunctionLiteral::NeedsHomeObject(value)) { 314 if (NeedsProxySlot()) base_slot++;
313 DCHECK(slot_index != NULL && *slot_index >= 0 && *slot_index < slot_count_); 315
314 FeedbackVectorICSlot slot = GetNthSlot(*slot_index); 316 for (int i = 0; i < properties()->length(); i++) {
315 *slot_index += 1; 317 ObjectLiteral::Property* property = properties()->at(i);
316 return slot; 318 base_slot += property->set_base_slot(base_slot);
317 } 319 }
318 return FeedbackVectorICSlot::Invalid();
319 } 320 }
320 321
321 322
322 bool ObjectLiteral::Property::IsCompileTimeValue() { 323 bool ObjectLiteral::Property::IsCompileTimeValue() {
323 return kind_ == CONSTANT || 324 return kind_ == CONSTANT ||
324 (kind_ == MATERIALIZED_LITERAL && 325 (kind_ == MATERIALIZED_LITERAL &&
325 CompileTimeValue::IsCompileTimeValue(value_)); 326 CompileTimeValue::IsCompileTimeValue(value_));
326 } 327 }
327 328
328 329
329 void ObjectLiteral::Property::set_emit_store(bool emit_store) { 330 void ObjectLiteral::Property::set_emit_store(bool emit_store) {
330 emit_store_ = emit_store; 331 emit_store_ = emit_store;
331 } 332 }
332 333
333 334
334 bool ObjectLiteral::Property::emit_store() { 335 bool ObjectLiteral::Property::emit_store() {
335 return emit_store_; 336 return emit_store_;
336 } 337 }
337 338
338 339
340 void ObjectLiteral::LayoutFeedbackSlots() {
341 int base_slot = slot_.ToInt();
342 for (int i = 0; i < properties()->length(); i++) {
343 ObjectLiteral::Property* property = properties()->at(i);
344 base_slot += property->set_base_slot(base_slot);
345 }
346 }
347
348
339 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements( 349 FeedbackVectorRequirements ObjectLiteral::ComputeFeedbackRequirements(
340 Isolate* isolate, const ICSlotCache* cache) { 350 Isolate* isolate, const ICSlotCache* cache) {
341 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0); 351 if (!FLAG_vector_stores) return FeedbackVectorRequirements(0, 0);
342 352
343 // This logic that computes the number of slots needed for vector store 353 // This logic that computes the number of slots needed for vector store
344 // ics must mirror FullCodeGenerator::VisitObjectLiteral. 354 // ics must mirror FullCodeGenerator::VisitObjectLiteral.
345 int ic_slots = 0; 355 int property_index = 0;
346 bool saw_computed_name = false; 356 for (; property_index < properties()->length(); property_index++) {
347 for (int i = 0; i < properties()->length(); i++) { 357 ObjectLiteral::Property* property = properties()->at(property_index);
348 ObjectLiteral::Property* property = properties()->at(i); 358 // In case we don't end up using any slots.
359 property->set_ic_slot_count(0);
360
361 if (property->is_computed_name()) break;
349 if (property->IsCompileTimeValue()) continue; 362 if (property->IsCompileTimeValue()) continue;
350 saw_computed_name |= property->is_computed_name(); 363
364 Literal* key = property->key()->AsLiteral();
365 Expression* value = property->value();
366 switch (property->kind()) {
367 case ObjectLiteral::Property::CONSTANT:
368 UNREACHABLE();
369 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
370 // Fall through.
371 case ObjectLiteral::Property::COMPUTED:
372 // It is safe to use [[Put]] here because the boilerplate already
373 // contains computed properties with an uninitialized value.
374 if (key->value()->IsInternalizedString()) {
375 if (property->emit_store()) {
376 int slot_count = 1;
377 if (FunctionLiteral::NeedsHomeObject(value)) {
378 slot_count++;
379 }
380 property->set_ic_slot_count(slot_count);
381 }
382 break;
383 }
384 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) {
385 property->set_ic_slot_count(1);
386 }
387 break;
388 case ObjectLiteral::Property::PROTOTYPE:
389 break;
390 case ObjectLiteral::Property::GETTER:
391 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) {
392 property->set_ic_slot_count(1);
393 }
394 break;
395 case ObjectLiteral::Property::SETTER:
396 if (property->emit_store() && FunctionLiteral::NeedsHomeObject(value)) {
397 property->set_ic_slot_count(1);
398 }
399 break;
400 }
401 }
402
403 for (; property_index < properties()->length(); property_index++) {
404 ObjectLiteral::Property* property = properties()->at(property_index);
351 405
352 Expression* value = property->value(); 406 Expression* value = property->value();
353 if (saw_computed_name && 407 if (property->kind() != ObjectLiteral::Property::PROTOTYPE) {
354 property->kind() != ObjectLiteral::Property::PROTOTYPE) { 408 if (FunctionLiteral::NeedsHomeObject(value)) {
355 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++; 409 property->set_ic_slot_count(1);
356 } else if (property->emit_store()) {
357 if (property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL ||
358 property->kind() == ObjectLiteral::Property::COMPUTED) {
359 Literal* key = property->key()->AsLiteral();
360 if (key->value()->IsInternalizedString()) ic_slots++;
361 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++;
362 } else if (property->kind() == ObjectLiteral::Property::GETTER ||
363 property->kind() == ObjectLiteral::Property::SETTER) {
364 // We might need a slot for the home object.
365 if (FunctionLiteral::NeedsHomeObject(value)) ic_slots++;
366 } 410 }
367 } 411 }
368 } 412 }
369 413
370 #ifdef DEBUG 414 // How many slots did we allocate?
371 // FullCodeGenerator::VisitObjectLiteral verifies that it consumes slot_count_ 415 int ic_slots = 0;
372 // slots. 416 for (int i = 0; i < properties()->length(); i++) {
373 slot_count_ = ic_slots; 417 ObjectLiteral::Property* property = properties()->at(i);
374 #endif 418 ic_slots += property->ic_slot_count();
419 }
420
375 return FeedbackVectorRequirements(0, ic_slots); 421 return FeedbackVectorRequirements(0, ic_slots);
376 } 422 }
377 423
378 424
379 FeedbackVectorICSlot ObjectLiteral::SlotForHomeObject(Expression* value,
380 int* slot_index) const {
381 if (FLAG_vector_stores && FunctionLiteral::NeedsHomeObject(value)) {
382 DCHECK(slot_index != NULL && *slot_index >= 0 && *slot_index < slot_count_);
383 FeedbackVectorICSlot slot = GetNthSlot(*slot_index);
384 *slot_index += 1;
385 return slot;
386 }
387 return FeedbackVectorICSlot::Invalid();
388 }
389
390
391 void ObjectLiteral::CalculateEmitStore(Zone* zone) { 425 void ObjectLiteral::CalculateEmitStore(Zone* zone) {
392 const auto GETTER = ObjectLiteral::Property::GETTER; 426 const auto GETTER = ObjectLiteral::Property::GETTER;
393 const auto SETTER = ObjectLiteral::Property::SETTER; 427 const auto SETTER = ObjectLiteral::Property::SETTER;
394 428
395 ZoneAllocationPolicy allocator(zone); 429 ZoneAllocationPolicy allocator(zone);
396 430
397 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, 431 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity,
398 allocator); 432 allocator);
399 for (int i = properties()->length() - 1; i >= 0; i--) { 433 for (int i = properties()->length() - 1; i >= 0; i--) {
400 ObjectLiteral::Property* property = properties()->at(i); 434 ObjectLiteral::Property* property = properties()->at(i);
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 bool Literal::Match(void* literal1, void* literal2) { 1187 bool Literal::Match(void* literal1, void* literal2) {
1154 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1188 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1155 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1189 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1156 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 1190 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
1157 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1191 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1158 } 1192 }
1159 1193
1160 1194
1161 } // namespace internal 1195 } // namespace internal
1162 } // namespace v8 1196 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/ast-numbering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698