Add phase zone to CompilationInfo and use it in GVN pass.
authorbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 24 Jun 2013 13:37:46 +0000 (13:37 +0000)
committerbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 24 Jun 2013 13:37:46 +0000 (13:37 +0000)
The phase_zone of CompilationInfo is intended for local allocations that
are freed at the end of the phase.

R=danno@chromium.org
BUG=

Review URL: https://codereview.chromium.org/17573003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15294 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler.cc
src/compiler.h
src/hydrogen-gvn.cc
src/hydrogen-gvn.h
src/hydrogen.cc

index 2539f7d..87028bd 100644 (file)
@@ -53,46 +53,56 @@ namespace v8 {
 namespace internal {
 
 
-CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
+CompilationInfo::CompilationInfo(Handle<Script> script,
+                                 Zone* zone,
+                                 Zone* phase_zone)
     : flags_(LanguageModeField::encode(CLASSIC_MODE)),
       script_(script),
       osr_ast_id_(BailoutId::None()) {
-  Initialize(script->GetIsolate(), BASE, zone);
+  Initialize(script->GetIsolate(), BASE, zone, phase_zone);
 }
 
 
 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
-                                 Zone* zone)
+                                 Zone* zone,
+                                 Zone* phase_zone)
     : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)),
       shared_info_(shared_info),
       script_(Handle<Script>(Script::cast(shared_info->script()))),
       osr_ast_id_(BailoutId::None()) {
-  Initialize(script_->GetIsolate(), BASE, zone);
+  Initialize(script_->GetIsolate(), BASE, zone, phase_zone);
 }
 
 
-CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
+CompilationInfo::CompilationInfo(Handle<JSFunction> closure,
+                                 Zone* zone,
+                                 Zone* phase_zone)
     : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)),
       closure_(closure),
       shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
       script_(Handle<Script>(Script::cast(shared_info_->script()))),
       context_(closure->context()),
       osr_ast_id_(BailoutId::None()) {
-  Initialize(script_->GetIsolate(), BASE, zone);
+  Initialize(script_->GetIsolate(), BASE, zone, phase_zone);
 }
 
 
 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub,
-                                 Isolate* isolate, Zone* zone)
+                                 Isolate* isolate,
+                                 Zone* zone,
+                                 Zone* phase_zone)
     : flags_(LanguageModeField::encode(CLASSIC_MODE) |
              IsLazy::encode(true)),
       osr_ast_id_(BailoutId::None()) {
-  Initialize(isolate, STUB, zone);
+  Initialize(isolate, STUB, zone, phase_zone);
   code_stub_ = stub;
 }
 
 
-void CompilationInfo::Initialize(Isolate* isolate, Mode mode, Zone* zone) {
+void CompilationInfo::Initialize(Isolate* isolate,
+                                 Mode mode,
+                                 Zone* zone,
+                                 Zone* phase_zone) {
   isolate_ = isolate;
   function_ = NULL;
   scope_ = NULL;
@@ -100,6 +110,7 @@ void CompilationInfo::Initialize(Isolate* isolate, Mode mode, Zone* zone) {
   extension_ = NULL;
   pre_parse_data_ = NULL;
   zone_ = zone;
+  phase_zone_ = phase_zone;
   deferred_handles_ = NULL;
   code_stub_ = NULL;
   prologue_offset_ = kPrologueOffsetNotSet;
index f53feb9..779acbc 100644 (file)
@@ -57,7 +57,7 @@ struct OffsetRange {
 // is constructed based on the resources available at compile-time.
 class CompilationInfo {
  public:
-  CompilationInfo(Handle<JSFunction> closure, Zone* zone);
+  CompilationInfo(Handle<JSFunction> closure, Zone* zone, Zone* phase_zone);
   virtual ~CompilationInfo();
 
   Isolate* isolate() {
@@ -65,6 +65,7 @@ class CompilationInfo {
     return isolate_;
   }
   Zone* zone() { return zone_; }
+  Zone* phase_zone() { return phase_zone_; }
   bool is_lazy() const { return IsLazy::decode(flags_); }
   bool is_eval() const { return IsEval::decode(flags_); }
   bool is_global() const { return IsGlobal::decode(flags_); }
@@ -300,9 +301,16 @@ class CompilationInfo {
   }
 
  protected:
-  CompilationInfo(Handle<Script> script, Zone* zone);
-  CompilationInfo(Handle<SharedFunctionInfo> shared_info, Zone* zone);
-  CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, Zone* zone);
+  CompilationInfo(Handle<Script> script,
+                  Zone* zone,
+                  Zone* phase_zone);
+  CompilationInfo(Handle<SharedFunctionInfo> shared_info,
+                  Zone* zone,
+                  Zone* phase_zone);
+  CompilationInfo(HydrogenCodeStub* stub,
+                  Isolate* isolate,
+                  Zone* zone,
+                  Zone* phase_zone);
 
  private:
   Isolate* isolate_;
@@ -320,7 +328,7 @@ class CompilationInfo {
     DEPENDENT_MAP_ABORT
   };
 
-  void Initialize(Isolate* isolate, Mode mode, Zone* zone);
+  void Initialize(Isolate* isolate, Mode mode, Zone* zone, Zone* phase_zone);
 
   void SetMode(Mode mode) {
     ASSERT(V8::UseCrankshaft());
@@ -394,6 +402,9 @@ class CompilationInfo {
   // The zone from which the compilation pipeline working on this
   // CompilationInfo allocates.
   Zone* zone_;
+  // The phase zone where allocations local to a specific phase are
+  // performed; be aware that this zone is cleared after each phase
+  Zone* phase_zone_;
 
   DeferredHandles* deferred_handles_;
 
@@ -428,21 +439,25 @@ class CompilationInfo {
 class CompilationInfoWithZone: public CompilationInfo {
  public:
   explicit CompilationInfoWithZone(Handle<Script> script)
-      : CompilationInfo(script, &zone_),
+      : CompilationInfo(script, &zone_, &phase_zone_),
         zone_(script->GetIsolate()),
-        zone_scope_(&zone_, DELETE_ON_EXIT) {}
+        zone_scope_(&zone_, DELETE_ON_EXIT),
+        phase_zone_(script->GetIsolate()) {}
   explicit CompilationInfoWithZone(Handle<SharedFunctionInfo> shared_info)
-      : CompilationInfo(shared_info, &zone_),
+      : CompilationInfo(shared_info, &zone_, &phase_zone_),
         zone_(shared_info->GetIsolate()),
-        zone_scope_(&zone_, DELETE_ON_EXIT) {}
+        zone_scope_(&zone_, DELETE_ON_EXIT),
+        phase_zone_(shared_info->GetIsolate()) {}
   explicit CompilationInfoWithZone(Handle<JSFunction> closure)
-      : CompilationInfo(closure, &zone_),
+      : CompilationInfo(closure, &zone_, &phase_zone_),
         zone_(closure->GetIsolate()),
-        zone_scope_(&zone_, DELETE_ON_EXIT) {}
+        zone_scope_(&zone_, DELETE_ON_EXIT),
+        phase_zone_(closure->GetIsolate()) {}
   CompilationInfoWithZone(HydrogenCodeStub* stub, Isolate* isolate)
-      : CompilationInfo(stub, isolate, &zone_),
+      : CompilationInfo(stub, isolate, &zone_, &phase_zone_),
         zone_(isolate),
-        zone_scope_(&zone_, DELETE_ON_EXIT) {}
+        zone_scope_(&zone_, DELETE_ON_EXIT),
+        phase_zone_(isolate) {}
 
   // Virtual destructor because a CompilationInfoWithZone has to exit the
   // zone scope and get rid of dependent maps even when the destructor is
@@ -454,6 +469,7 @@ class CompilationInfoWithZone: public CompilationInfo {
  private:
   Zone zone_;
   ZoneScope zone_scope_;
+  Zone phase_zone_;
 };
 
 
index aa2dff7..9d5e866 100644 (file)
@@ -365,14 +365,16 @@ HGlobalValueNumberer::HGlobalValueNumberer(HGraph* graph, CompilationInfo* info)
       : graph_(graph),
         info_(info),
         removed_side_effects_(false),
-        block_side_effects_(graph->blocks()->length(), graph->zone()),
-        loop_side_effects_(graph->blocks()->length(), graph->zone()),
-        visited_on_paths_(graph->zone(), graph->blocks()->length()) {
+        phase_zone_(info->phase_zone()),
+        phase_zone_scope_(phase_zone_, DELETE_ON_EXIT),
+        block_side_effects_(graph->blocks()->length(), phase_zone_),
+        loop_side_effects_(graph->blocks()->length(), phase_zone_),
+        visited_on_paths_(phase_zone_, graph->blocks()->length()) {
     ASSERT(!AllowHandleAllocation::IsAllowed());
     block_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(),
-                                 graph_->zone());
+                                 phase_zone_);
     loop_side_effects_.AddBlock(GVNFlagSet(), graph_->blocks()->length(),
-                                graph_->zone());
+                                phase_zone_);
   }
 
 bool HGlobalValueNumberer::Analyze() {
@@ -756,9 +758,9 @@ class GvnBasicBlockState: public ZoneObject {
 // GvnBasicBlockState instances.
 void HGlobalValueNumberer::AnalyzeGraph() {
   HBasicBlock* entry_block = graph_->entry_block();
-  HValueMap* entry_map = new(zone()) HValueMap(zone());
+  HValueMap* entry_map = new(phase_zone()) HValueMap(phase_zone());
   GvnBasicBlockState* current =
-      GvnBasicBlockState::CreateEntry(zone(), entry_block, entry_map);
+      GvnBasicBlockState::CreateEntry(phase_zone(), entry_block, entry_map);
 
   while (current != NULL) {
     HBasicBlock* block = current->block();
@@ -800,7 +802,7 @@ void HGlobalValueNumberer::AnalyzeGraph() {
           if (instr->HasSideEffects()) removed_side_effects_ = true;
           instr->DeleteAndReplaceWith(other);
         } else {
-          map->Add(instr, zone());
+          map->Add(instr, phase_zone());
         }
       }
       if (instr->IsLinked() &&
@@ -826,7 +828,8 @@ void HGlobalValueNumberer::AnalyzeGraph() {
 
     HBasicBlock* dominator_block;
     GvnBasicBlockState* next =
-        current->next_in_dominator_tree_traversal(zone(), &dominator_block);
+        current->next_in_dominator_tree_traversal(phase_zone(),
+                                                  &dominator_block);
 
     if (next != NULL) {
       HBasicBlock* dominated = next->block();
index c39765a..2d6075e 100644 (file)
@@ -100,12 +100,15 @@ class HGlobalValueNumberer BASE_EMBEDDED {
 
   HGraph* graph() { return graph_; }
   CompilationInfo* info() { return info_; }
-  Zone* zone() const { return graph_->zone(); }
+  Zone* phase_zone() const { return info_->phase_zone(); }
 
   HGraph* graph_;
   CompilationInfo* info_;
   bool removed_side_effects_;
 
+  Zone* phase_zone_;
+  ZoneScope phase_zone_scope_;
+
   // A map of block IDs to their side effects.
   ZoneList<GVNFlagSet> block_side_effects_;
 
index ab44e65..0cfb9ed 100644 (file)
@@ -7938,7 +7938,7 @@ bool HOptimizedGraphBuilder::TryInline(CallKind call_kind,
   }
 
   // Parse and allocate variables.
-  CompilationInfo target_info(target, zone());
+  CompilationInfo target_info(target, zone(), current_info()->phase_zone());
   Handle<SharedFunctionInfo> target_shared(target->shared());
   if (!Parser::Parse(&target_info) || !Scope::Analyze(&target_info)) {
     if (target_info.isolate()->has_pending_exception()) {