Reviewers: jarin,

Description:
[turbofan] Use RootIndexMap to speed up IsMaterializableFromRoot predicate.

[email protected]

Please review this at https://codereview.chromium.org/1181123002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+9, -13 lines):
  M src/compiler/code-generator.cc
  M src/snapshot/serialize.cc


Index: src/compiler/code-generator.cc
diff --git a/src/compiler/code-generator.cc b/src/compiler/code-generator.cc
index d19d21fa4a50f97707cef83542553534379e1889..59d1000113a8929545f77560554e31348fc1ea1e 100644
--- a/src/compiler/code-generator.cc
+++ b/src/compiler/code-generator.cc
@@ -7,6 +7,7 @@
 #include "src/compiler/code-generator-impl.h"
 #include "src/compiler/linkage.h"
 #include "src/compiler/pipeline.h"
+#include "src/snapshot/serialize.h"  // TODO(turbofan): RootIndexMap

 namespace v8 {
 namespace internal {
@@ -238,15 +239,11 @@ bool CodeGenerator::IsMaterializableFromFrame(Handle<HeapObject> object,
 bool CodeGenerator::IsMaterializableFromRoot(
     Handle<HeapObject> object, Heap::RootListIndex* index_return) {
   if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) {
-    // Check if {object} is one of the non-smi roots that cannot be written
-    // after initialization.
-    for (int i = 0; i < Heap::kSmiRootsStart; ++i) {
- Heap::RootListIndex const index = static_cast<Heap::RootListIndex>(i);
-      if (!Heap::RootCanBeWrittenAfterInitialization(index) &&
-          *object == isolate()->heap()->root(index)) {
-        *index_return = index;
-        return true;
-      }
+    RootIndexMap map(isolate());
+    int root_index = map.Lookup(*object);
+    if (root_index != RootIndexMap::kInvalidRootIndex) {
+      *index_return = static_cast<Heap::RootListIndex>(root_index);
+      return true;
     }
   }
   return false;
Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index 57092e1b46238336fff16a11e9a510324fbceea4..a86d2560e1b22ecd5b5a9113b622fa0ed7f36500 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -371,15 +371,14 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
   map_ = new HashMap(HashMap::PointersMatch);
   Object** root_array = isolate->heap()->roots_array_start();
   for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) {
-    Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
-    Object* root = root_array[root_index];
+    Object* const root = root_array[i];
+ Heap::RootListIndex const root_index = static_cast<Heap::RootListIndex>(i); // Omit root entries that can be written after initialization. They must
     // not be referenced through the root list in the snapshot.
     if (root->IsHeapObject() &&
         isolate->heap()->RootCanBeTreatedAsConstant(root_index)) {
       HeapObject* heap_object = HeapObject::cast(root);
-      HashMap::Entry* entry = LookupEntry(map_, heap_object, false);
-      if (entry != NULL) {
+      if (HashMap::Entry* entry = LookupEntry(map_, heap_object, false)) {
         // Some are initialized to a previous value in the root list.
         DCHECK_LT(GetValue(entry), i);
       } else {


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to