Revision: 19713
Author:   [email protected]
Date:     Fri Mar  7 10:14:03 2014 UTC
Log:      Track global cells as special side effects in GVN.

[email protected]

Review URL: https://codereview.chromium.org/188543004
http://code.google.com/p/v8/source/detail?r=19713

Modified:
 /branches/bleeding_edge/src/handles-inl.h
 /branches/bleeding_edge/src/hydrogen-gvn.cc
 /branches/bleeding_edge/src/hydrogen-gvn.h
 /branches/bleeding_edge/src/unique.h

=======================================
--- /branches/bleeding_edge/src/handles-inl.h   Thu Jan 16 08:17:40 2014 UTC
+++ /branches/bleeding_edge/src/handles-inl.h   Fri Mar  7 10:14:03 2014 UTC
@@ -97,7 +97,8 @@
   if (!AllowHandleDereference::IsAllowed()) return false;
   if (mode == INCLUDE_DEFERRED_CHECK &&
       !AllowDeferredHandleDereference::IsAllowed()) {
-    // Accessing maps and internalized strings is safe.
+    // Accessing cells, maps and internalized strings is safe.
+    if (heap_object->IsCell()) return true;
     if (heap_object->IsMap()) return true;
     if (heap_object->IsInternalizedString()) return true;
     return !heap->isolate()->IsDeferredHandle(handle);
=======================================
--- /branches/bleeding_edge/src/hydrogen-gvn.cc Tue Feb 11 06:53:14 2014 UTC
+++ /branches/bleeding_edge/src/hydrogen-gvn.cc Fri Mar  7 10:14:03 2014 UTC
@@ -367,15 +367,28 @@


 SideEffects SideEffectsTracker::ComputeChanges(HInstruction* instr) {
+  int index;
   SideEffects result(instr->ChangesFlags());
+  if (result.ContainsFlag(kGlobalVars)) {
+    if (instr->IsStoreGlobalCell() &&
+        ComputeGlobalVar(HStoreGlobalCell::cast(instr)->cell(), &index)) {
+      result.RemoveFlag(kGlobalVars);
+      result.AddSpecial(GlobalVar(index));
+    } else {
+      for (index = 0; index < kNumberOfGlobalVars; ++index) {
+        result.AddSpecial(GlobalVar(index));
+      }
+    }
+  }
   if (result.ContainsFlag(kInobjectFields)) {
-    int index;
     if (instr->IsStoreNamedField() &&
ComputeInobjectField(HStoreNamedField::cast(instr)->access(), &index)) {
       result.RemoveFlag(kInobjectFields);
-      result.AddSpecial(index);
+      result.AddSpecial(InobjectField(index));
     } else {
-      result.AddAllSpecial();
+      for (index = 0; index < kNumberOfInobjectFields; ++index) {
+        result.AddSpecial(InobjectField(index));
+      }
     }
   }
   return result;
@@ -383,15 +396,28 @@


 SideEffects SideEffectsTracker::ComputeDependsOn(HInstruction* instr) {
+  int index;
   SideEffects result(instr->DependsOnFlags());
+  if (result.ContainsFlag(kGlobalVars)) {
+    if (instr->IsLoadGlobalCell() &&
+        ComputeGlobalVar(HLoadGlobalCell::cast(instr)->cell(), &index)) {
+      result.RemoveFlag(kGlobalVars);
+      result.AddSpecial(GlobalVar(index));
+    } else {
+      for (index = 0; index < kNumberOfGlobalVars; ++index) {
+        result.AddSpecial(GlobalVar(index));
+      }
+    }
+  }
   if (result.ContainsFlag(kInobjectFields)) {
-    int index;
     if (instr->IsLoadNamedField() &&
ComputeInobjectField(HLoadNamedField::cast(instr)->access(), &index)) {
       result.RemoveFlag(kInobjectFields);
-      result.AddSpecial(index);
+      result.AddSpecial(InobjectField(index));
     } else {
-      result.AddAllSpecial();
+      for (index = 0; index < kNumberOfInobjectFields; ++index) {
+        result.AddSpecial(InobjectField(index));
+      }
     }
   }
   return result;
@@ -420,8 +446,15 @@
       }
     }
   }
+  for (int index = 0; index < num_global_vars_; ++index) {
+    if (side_effects.ContainsSpecial(GlobalVar(index))) {
+      stream->Add(separator);
+      separator = ", ";
+      stream->Add("[%p]", *global_vars_[index].handle());
+    }
+  }
   for (int index = 0; index < num_inobject_fields_; ++index) {
-    if (side_effects.ContainsSpecial(index)) {
+    if (side_effects.ContainsSpecial(InobjectField(index))) {
       stream->Add(separator);
       separator = ", ";
       inobject_fields_[index].PrintTo(stream);
@@ -429,6 +462,29 @@
   }
   stream->Add("]");
 }
+
+
+bool SideEffectsTracker::ComputeGlobalVar(Unique<Cell> cell, int* index) {
+  for (int i = 0; i < num_global_vars_; ++i) {
+    if (cell == global_vars_[i]) {
+      *index = i;
+      return true;
+    }
+  }
+  if (num_global_vars_ < kNumberOfGlobalVars) {
+    if (FLAG_trace_gvn) {
+      HeapStringAllocator allocator;
+      StringStream stream(&allocator);
+      stream.Add("Tracking global var [%p] (mapped to index %d)\n",
+                 *cell.handle(), num_global_vars_);
+      stream.OutputToStdOut();
+    }
+    *index = num_global_vars_;
+    global_vars_[num_global_vars_++] = cell;
+    return true;
+  }
+  return false;
+}


 bool SideEffectsTracker::ComputeInobjectField(HObjectAccess access,
@@ -439,13 +495,13 @@
       return true;
     }
   }
-  if (num_inobject_fields_ < SideEffects::kNumberOfSpecials) {
+  if (num_inobject_fields_ < kNumberOfInobjectFields) {
     if (FLAG_trace_gvn) {
       HeapStringAllocator allocator;
       StringStream stream(&allocator);
       stream.Add("Tracking inobject field access ");
       access.PrintTo(&stream);
-      stream.Add(" (mapped to special index %d)\n", num_inobject_fields_);
+      stream.Add(" (mapped to index %d)\n", num_inobject_fields_);
       stream.OutputToStdOut();
     }
     *index = num_inobject_fields_;
=======================================
--- /branches/bleeding_edge/src/hydrogen-gvn.h  Tue Feb 11 07:05:47 2014 UTC
+++ /branches/bleeding_edge/src/hydrogen-gvn.h  Fri Mar  7 10:14:03 2014 UTC
@@ -58,7 +58,6 @@
bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; }
   void Add(SideEffects set) { bits_ |= set.bits_; }
   void AddSpecial(int special) { bits_ |= MaskSpecial(special); }
- void AddAllSpecial() { bits_ |= ~static_cast<uint64_t>(0) << kNumberOfFlags; }
   void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); }
   void RemoveAll() { bits_ = 0; }
   uint64_t ToIntegral() const { return bits_; }
@@ -79,21 +78,42 @@
 };


-// Tracks inobject field loads/stores in a fine grained fashion, and represents -// them using the "special" dynamic side effects of the SideEffects class (see -// above). This way unrelated inobject field stores don't prevent hoisting and
-// merging of inobject field loads.
+// Tracks global variable and inobject field loads/stores in a fine grained
+// fashion, and represents them using the "special" dynamic side effects of the +// SideEffects class (see above). This way unrelated global variable/inobject +// field stores don't prevent hoisting and merging of global variable/inobject
+// field loads.
 class SideEffectsTracker V8_FINAL BASE_EMBEDDED {
  public:
-  SideEffectsTracker() : num_inobject_fields_(0) {}
+  SideEffectsTracker() : num_global_vars_(0), num_inobject_fields_(0) {}
   SideEffects ComputeChanges(HInstruction* instr);
   SideEffects ComputeDependsOn(HInstruction* instr);
void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const;

  private:
+  bool ComputeGlobalVar(Unique<Cell> cell, int* index);
   bool ComputeInobjectField(HObjectAccess access, int* index);

-  HObjectAccess inobject_fields_[SideEffects::kNumberOfSpecials];
+  static int GlobalVar(int index) {
+    ASSERT(index >= 0);
+    ASSERT(index < kNumberOfGlobalVars);
+    return index;
+  }
+  static int InobjectField(int index) {
+    ASSERT(index >= 0);
+    ASSERT(index < kNumberOfInobjectFields);
+    return index + kNumberOfGlobalVars;
+  }
+
+  // Track up to four global vars.
+  static const int kNumberOfGlobalVars = 4;
+  Unique<Cell> global_vars_[kNumberOfGlobalVars];
+  int num_global_vars_;
+
+  // Track up to n inobject fields.
+  static const int kNumberOfInobjectFields =
+      SideEffects::kNumberOfSpecials - kNumberOfGlobalVars;
+  HObjectAccess inobject_fields_[kNumberOfInobjectFields];
   int num_inobject_fields_;
 };

=======================================
--- /branches/bleeding_edge/src/unique.h        Thu Dec 19 17:42:21 2013 UTC
+++ /branches/bleeding_edge/src/unique.h        Fri Mar  7 10:14:03 2014 UTC
@@ -142,8 +142,12 @@
   friend class Unique;  // For comparing raw_address values.

  private:
+  Unique<T>() : raw_address_(NULL) { }
+
   Address raw_address_;
   Handle<T> handle_;
+
+  friend class SideEffectsTracker;
 };


--
--
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