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

Unified Diff: src/hydrogen.cc

Issue 779173010: Create optimized inline versions of Map and Set initialization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Switch to StoreNamedField, shorten constant names Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 5947643733d67e6835047cc3eb5f6a3d799a980b..f3d0849462493b35d21e213cfaacc5fdd8a81958 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -12648,6 +12648,85 @@ void HOptimizedGraphBuilder::GenerateMapGetSize(CallRuntime* call) {
}
+template <typename CollectionType>
+HValue* HOptimizedGraphBuilder::BuildAllocateOrderedHashTable() {
+ static const int kCapacity = CollectionType::kMinCapacity;
+ static const int kBucketCount = kCapacity / CollectionType::kLoadFactor;
+ static const int kFixedArrayLength = CollectionType::kHashTableStartIndex +
+ kBucketCount +
+ (kCapacity * CollectionType::kEntrySize);
+ static const int kSizeInBytes =
+ FixedArray::kHeaderSize + (kFixedArrayLength * kPointerSize);
+
+ // Allocate the table and add the proper map.
+ HValue* table =
+ Add<HAllocate>(Add<HConstant>(kSizeInBytes), HType::HeapObject(),
+ NOT_TENURED, FIXED_ARRAY_TYPE);
+ AddStoreMapConstant(table, isolate()->factory()->ordered_hash_table_map());
+
+ // Initialize the FixedArray...
+ HValue* length = Add<HConstant>(kFixedArrayLength);
+ Add<HStoreNamedField>(table, HObjectAccess::ForFixedArrayLength(), length);
+
+ // ...and the OrderedHashTable fields.
+ Add<HStoreNamedField>(
+ table,
+ HObjectAccess::ForOrderedHashTableNumberOfBuckets<CollectionType>(),
+ Add<HConstant>(kBucketCount));
+ Add<HStoreNamedField>(
+ table,
+ HObjectAccess::ForOrderedHashTableNumberOfElements<CollectionType>(),
+ graph()->GetConstant0());
+ Add<HStoreNamedField>(
+ table, HObjectAccess::ForOrderedHashTableNumberOfDeletedElements<
+ CollectionType>(),
+ graph()->GetConstant0());
+
+ // Fill the buckets with kNotFound.
+ HValue* not_found = Add<HConstant>(CollectionType::kNotFound);
+ for (int i = 0; i < kBucketCount; ++i) {
+ Add<HStoreNamedField>(
+ table, HObjectAccess::ForOrderedHashTableBucket<CollectionType>(i),
+ not_found);
+ }
+
+ // Fill the data table with undefined.
+ HValue* undefined = graph()->GetConstantUndefined();
+ for (int i = 0; i < (kCapacity * CollectionType::kEntrySize); ++i) {
+ Add<HStoreNamedField>(table,
+ HObjectAccess::ForOrderedHashTableDataTableIndex<
+ CollectionType, kBucketCount>(i),
+ undefined);
+ }
+
+ return table;
+}
+
+
+void HOptimizedGraphBuilder::GenerateSetInitialize(CallRuntime* call) {
+ DCHECK(call->arguments()->length() == 1);
+ CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
+ HValue* receiver = Pop();
+
+ NoObservableSideEffectsScope no_effects(this);
+ HValue* table = BuildAllocateOrderedHashTable<OrderedHashSet>();
+ Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table);
+ return ast_context()->ReturnValue(receiver);
+}
+
+
+void HOptimizedGraphBuilder::GenerateMapInitialize(CallRuntime* call) {
+ DCHECK(call->arguments()->length() == 1);
+ CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
+ HValue* receiver = Pop();
+
+ NoObservableSideEffectsScope no_effects(this);
+ HValue* table = BuildAllocateOrderedHashTable<OrderedHashMap>();
+ Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table);
+ return ast_context()->ReturnValue(receiver);
+}
+
+
void HOptimizedGraphBuilder::GenerateGetCachedArrayIndex(CallRuntime* call) {
DCHECK(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698