Split HPhase for Lithium and Hydrogen using common CompilationPhase base.
authorbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 25 Jun 2013 12:22:26 +0000 (12:22 +0000)
committerbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 25 Jun 2013 12:22:26 +0000 (12:22 +0000)
Add new base class CompilationPhase, which is the base for both HPhase, LPhase and LAllocatorPhase. HPhase is now for Hydrogen passes only, LPhase is for Lithium passes and LAllocatorPhase is for LAllocator phases.

R=svenpanne@chromium.org
BUG=

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

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

17 files changed:
src/arm/lithium-arm.cc
src/arm/lithium-codegen-arm.cc
src/compiler.cc
src/compiler.h
src/hydrogen.cc
src/hydrogen.h
src/ia32/lithium-codegen-ia32.cc
src/ia32/lithium-ia32.cc
src/lithium-allocator.cc
src/lithium-allocator.h
src/lithium.cc
src/lithium.h
src/mips/lithium-codegen-mips.cc
src/mips/lithium-mips.cc
src/x64/lithium-codegen-x64.cc
src/x64/lithium-x64.cc
src/zone.h

index a5b01d2..9ea572b 100644 (file)
@@ -451,7 +451,7 @@ LOperand* LPlatformChunk::GetNextSpillSlot(bool is_double)  {
 LPlatformChunk* LChunkBuilder::Build() {
   ASSERT(is_unused());
   chunk_ = new(zone()) LPlatformChunk(info(), graph());
-  HPhase phase("L_Building chunk", chunk_);
+  LPhase phase("L_Building chunk", chunk_);
   status_ = BUILDING;
   const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
   for (int i = 0; i < blocks->length(); i++) {
index b9a3a0b..ec9d718 100644 (file)
@@ -62,7 +62,7 @@ class SafepointGenerator : public CallWrapper {
 #define __ masm()->
 
 bool LCodeGen::GenerateCode() {
-  HPhase phase("Z_Code generation", chunk());
+  LPhase phase("Z_Code generation", chunk());
   ASSERT(is_unused());
   status_ = GENERATING;
 
index 87028bd..575afaa 100644 (file)
@@ -1224,4 +1224,32 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
                  info));
 }
 
+
+CompilationPhase::CompilationPhase(const char* name,
+                                   Isolate* isolate,
+                                   Zone* zone)
+    : name_(name), isolate_(isolate), zone_scope_(zone, DELETE_ON_EXIT) {
+  if (FLAG_hydrogen_stats) {
+    start_allocation_size_ = zone->allocation_size();
+    start_ticks_ = OS::Ticks();
+  }
+}
+
+
+CompilationPhase::~CompilationPhase() {
+  if (FLAG_hydrogen_stats) {
+    unsigned size = zone()->allocation_size() - start_allocation_size_;
+    int64_t ticks = OS::Ticks() - start_ticks_;
+    isolate_->GetHStatistics()->SaveTiming(name_, ticks, size);
+  }
+}
+
+
+bool CompilationPhase::ShouldProduceTraceOutput() const {
+  // Produce trace output if flag is set so that the first letter of the
+  // phase name matches the command line parameter FLAG_trace_phase.
+  return (FLAG_trace_hydrogen &&
+          OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
+}
+
 } }  // namespace v8::internal
index 779acbc..53d0690 100644 (file)
@@ -633,6 +633,29 @@ class Compiler : public AllStatic {
 };
 
 
+class CompilationPhase BASE_EMBEDDED {
+ public:
+  CompilationPhase(const char* name, Isolate* isolate, Zone* zone);
+  ~CompilationPhase();
+
+ protected:
+  bool ShouldProduceTraceOutput() const;
+
+  const char* name() const { return name_; }
+  Isolate* isolate() const { return isolate_; }
+  Zone* zone() const { return zone_scope_.zone(); }
+
+ private:
+  const char* name_;
+  Isolate* isolate_;
+  ZoneScope zone_scope_;
+  unsigned start_allocation_size_;
+  int64_t start_ticks_;
+
+  DISALLOW_COPY_AND_ASSIGN(CompilationPhase);
+};
+
+
 } }  // namespace v8::internal
 
 #endif  // V8_COMPILER_H_
index 28eeeb3..fdb5665 100644 (file)
@@ -963,7 +963,7 @@ void HGraphBuilder::LoopBuilder::EndBody() {
 HGraph* HGraphBuilder::CreateGraph() {
   graph_ = new(zone()) HGraph(info_);
   if (FLAG_hydrogen_stats) isolate()->GetHStatistics()->Initialize(info_);
-  HPhase phase("H_Block building", isolate(), zone());
+  CompilationPhase phase("H_Block building", isolate(), zone());
   set_current_block(graph()->entry_block());
   if (!BuildGraph()) return NULL;
   graph()->FinalizeUniqueValueIds();
@@ -2384,7 +2384,7 @@ class PostorderProcessor : public ZoneObject {
 
 
 void HGraph::OrderBlocks() {
-  HPhase phase("H_Block ordering", isolate(), zone());
+  CompilationPhase phase("H_Block ordering", isolate(), zone());
   BitVector visited(blocks_.length(), zone());
 
   ZoneList<HBasicBlock*> reverse_result(8, zone());
@@ -11554,73 +11554,13 @@ void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) {
 }
 
 
-HPhase::HPhase(const char* name, Isolate* isolate, Zone* zone) {
-  Init(isolate, name, zone, NULL, NULL, NULL);
-}
-
-
-HPhase::HPhase(const char* name, HGraph* graph) {
-  Init(graph->isolate(), name, graph->zone(), graph, NULL, NULL);
-}
-
-
-HPhase::HPhase(const char* name, LChunk* chunk) {
-  Init(chunk->isolate(), name, chunk->zone(), NULL, chunk, NULL);
-}
-
-
-HPhase::HPhase(const char* name, LAllocator* allocator) {
-  Init(allocator->isolate(), name, allocator->zone(), NULL, NULL, allocator);
-}
-
-
-void HPhase::Init(Isolate* isolate,
-                  const char* name,
-                  Zone* zone,
-                  HGraph* graph,
-                  LChunk* chunk,
-                  LAllocator* allocator) {
-  isolate_ = isolate;
-  name_ = name;
-  zone_ = zone;
-  graph_ = graph;
-  chunk_ = chunk;
-  allocator_ = allocator;
-  if (allocator != NULL && chunk_ == NULL) {
-    chunk_ = allocator->chunk();
-  }
-  if (FLAG_hydrogen_stats) {
-    start_ticks_ = OS::Ticks();
-    start_allocation_size_ = zone_->allocation_size();
-  }
-}
-
-
 HPhase::~HPhase() {
-  if (FLAG_hydrogen_stats) {
-    int64_t ticks = OS::Ticks() - start_ticks_;
-    unsigned size = zone_->allocation_size() - start_allocation_size_;
-    isolate_->GetHStatistics()->SaveTiming(name_, ticks, size);
-  }
-
-  // Produce trace output if flag is set so that the first letter of the
-  // phase name matches the command line parameter FLAG_trace_phase.
-  if (FLAG_trace_hydrogen &&
-      OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL) {
-    if (graph_ != NULL) {
-      isolate_->GetHTracer()->TraceHydrogen(name_, graph_);
-    }
-    if (chunk_ != NULL) {
-      isolate_->GetHTracer()->TraceLithium(name_, chunk_);
-    }
-    if (allocator_ != NULL) {
-      isolate_->GetHTracer()->TraceLiveRanges(name_, allocator_);
-    }
+  if (ShouldProduceTraceOutput()) {
+    isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
   }
 
 #ifdef DEBUG
-  if (graph_ != NULL) graph_->Verify(false);  // No full verify.
-  if (allocator_ != NULL) allocator_->Verify();
+  graph_->Verify(false);  // No full verify.
 #endif
 }
 
index 2297af2..fdd2f75 100644 (file)
@@ -1955,30 +1955,17 @@ class HStatistics: public Malloced {
 };
 
 
-class HPhase BASE_EMBEDDED {
+class HPhase : public CompilationPhase {
  public:
-  HPhase(const char* name, Isolate* isolate, Zone* zone);
-  HPhase(const char* name, HGraph* graph);
-  HPhase(const char* name, LChunk* chunk);
-  HPhase(const char* name, LAllocator* allocator);
+  HPhase(const char* name, HGraph* graph)
+      : CompilationPhase(name, graph->isolate(), graph->zone()),
+        graph_(graph) { }
   ~HPhase();
 
  private:
-  void Init(Isolate* isolate,
-            const char* name,
-            Zone* zone,
-            HGraph* graph,
-            LChunk* chunk,
-            LAllocator* allocator);
-
-  Isolate* isolate_;
-  const char* name_;
-  Zone* zone_;
   HGraph* graph_;
-  LChunk* chunk_;
-  LAllocator* allocator_;
-  int64_t start_ticks_;
-  unsigned start_allocation_size_;
+
+  DISALLOW_COPY_AND_ASSIGN(HPhase);
 };
 
 
index b67441f..cffc0d1 100644 (file)
@@ -74,7 +74,7 @@ class SafepointGenerator : public CallWrapper {
 #define __ masm()->
 
 bool LCodeGen::GenerateCode() {
-  HPhase phase("Z_Code generation", chunk());
+  LPhase phase("Z_Code generation", chunk());
   ASSERT(is_unused());
   status_ = GENERATING;
 
index 5e40842..ae0a198 100644 (file)
@@ -481,7 +481,7 @@ void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
 LPlatformChunk* LChunkBuilder::Build() {
   ASSERT(is_unused());
   chunk_ = new(zone()) LPlatformChunk(info(), graph());
-  HPhase phase("L_Building chunk", chunk_);
+  LPhase phase("L_Building chunk", chunk_);
   status_ = BUILDING;
 
   // Reserve the first spill slot for the state of dynamic alignment.
index 1fd921f..5e2474c 100644 (file)
@@ -1101,7 +1101,7 @@ bool LAllocator::Allocate(LChunk* chunk) {
 
 
 void LAllocator::MeetRegisterConstraints() {
-  HPhase phase("L_Register constraints", chunk_);
+  LAllocatorPhase phase("L_Register constraints", this);
   first_artificial_register_ = next_virtual_register_;
   const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
   for (int i = 0; i < blocks->length(); ++i) {
@@ -1113,7 +1113,7 @@ void LAllocator::MeetRegisterConstraints() {
 
 
 void LAllocator::ResolvePhis() {
-  HPhase phase("L_Resolve phis", chunk_);
+  LAllocatorPhase phase("L_Resolve phis", this);
 
   // Process the blocks in reverse order.
   const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
@@ -1204,7 +1204,7 @@ HBasicBlock* LAllocator::GetBlock(LifetimePosition pos) {
 
 
 void LAllocator::ConnectRanges() {
-  HPhase phase("L_Connect ranges", this);
+  LAllocatorPhase phase("L_Connect ranges", this);
   for (int i = 0; i < live_ranges()->length(); ++i) {
     LiveRange* first_range = live_ranges()->at(i);
     if (first_range == NULL || first_range->parent() != NULL) continue;
@@ -1244,7 +1244,7 @@ bool LAllocator::CanEagerlyResolveControlFlow(HBasicBlock* block) const {
 
 
 void LAllocator::ResolveControlFlow() {
-  HPhase phase("L_Resolve control flow", this);
+  LAllocatorPhase phase("L_Resolve control flow", this);
   const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
   for (int block_id = 1; block_id < blocks->length(); ++block_id) {
     HBasicBlock* block = blocks->at(block_id);
@@ -1265,7 +1265,7 @@ void LAllocator::ResolveControlFlow() {
 
 
 void LAllocator::BuildLiveRanges() {
-  HPhase phase("L_Build live ranges", this);
+  LAllocatorPhase phase("L_Build live ranges", this);
   InitializeLivenessAnalysis();
   // Process the blocks in reverse order.
   const ZoneList<HBasicBlock*>* blocks = graph_->blocks();
@@ -1377,7 +1377,7 @@ bool LAllocator::SafePointsAreInOrder() const {
 
 
 void LAllocator::PopulatePointerMaps() {
-  HPhase phase("L_Populate pointer maps", this);
+  LAllocatorPhase phase("L_Populate pointer maps", this);
   const ZoneList<LPointerMap*>* pointer_maps = chunk_->pointer_maps();
 
   ASSERT(SafePointsAreInOrder());
@@ -1496,14 +1496,14 @@ void LAllocator::ProcessOsrEntry() {
 
 
 void LAllocator::AllocateGeneralRegisters() {
-  HPhase phase("L_Allocate general registers", this);
+  LAllocatorPhase phase("L_Allocate general registers", this);
   num_registers_ = Register::NumAllocatableRegisters();
   AllocateRegisters();
 }
 
 
 void LAllocator::AllocateDoubleRegisters() {
-  HPhase phase("L_Allocate double registers", this);
+  LAllocatorPhase phase("L_Allocate double registers", this);
   num_registers_ = DoubleRegister::NumAllocatableRegisters();
   mode_ = DOUBLE_REGISTERS;
   AllocateRegisters();
@@ -2192,4 +2192,16 @@ void LAllocator::Verify() const {
 #endif
 
 
+LAllocatorPhase::~LAllocatorPhase() {
+  if (ShouldProduceTraceOutput()) {
+    isolate()->GetHTracer()->TraceLithium(name(), allocator_->chunk());
+    isolate()->GetHTracer()->TraceLiveRanges(name(), allocator_);
+  }
+
+#ifdef DEBUG
+  if (allocator_ != NULL) allocator_->Verify();
+#endif
+}
+
+
 } }  // namespace v8::internal
index 552ebdd..afcf2da 100644 (file)
@@ -646,6 +646,20 @@ class LAllocator BASE_EMBEDDED {
 };
 
 
+class LAllocatorPhase : public CompilationPhase {
+ public:
+  LAllocatorPhase(const char* name, LAllocator* allocator)
+      : CompilationPhase(name, allocator->isolate(), allocator->zone()),
+        allocator_(allocator) { }
+  ~LAllocatorPhase();
+
+ private:
+  LAllocator* allocator_;
+
+  DISALLOW_COPY_AND_ASSIGN(LAllocatorPhase);
+};
+
+
 } }  // namespace v8::internal
 
 #endif  // V8_LITHIUM_ALLOCATOR_H_
index 2993c9a..b22fdf6 100644 (file)
@@ -307,7 +307,7 @@ Label* LChunk::GetAssemblyLabel(int block_id) const {
 }
 
 void LChunk::MarkEmptyBlocks() {
-  HPhase phase("L_Mark empty blocks", this);
+  LPhase phase("L_Mark empty blocks", this);
   for (int i = 0; i < graph()->blocks()->length(); ++i) {
     HBasicBlock* block = graph()->blocks()->at(i);
     int first = block->first_instruction_index();
@@ -491,4 +491,11 @@ void LChunk::set_allocated_double_registers(BitVector* allocated_registers) {
 }
 
 
+LPhase::~LPhase() {
+  if (ShouldProduceTraceOutput()) {
+    isolate()->GetHTracer()->TraceLithium(name(), chunk_);
+  }
+}
+
+
 } }  // namespace v8::internal
index ab34453..200773a 100644 (file)
@@ -778,6 +778,20 @@ enum NumberUntagDMode {
 };
 
 
+class LPhase : public CompilationPhase {
+ public:
+  LPhase(const char* name, LChunk* chunk)
+      : CompilationPhase(name, chunk->isolate(), chunk->zone()),
+        chunk_(chunk) { }
+  ~LPhase();
+
+ private:
+  LChunk* chunk_;
+
+  DISALLOW_COPY_AND_ASSIGN(LPhase);
+};
+
+
 } }  // namespace v8::internal
 
 #endif  // V8_LITHIUM_H_
index 9b371ad..acc0d66 100644 (file)
@@ -62,7 +62,7 @@ class SafepointGenerator : public CallWrapper {
 #define __ masm()->
 
 bool LCodeGen::GenerateCode() {
-  HPhase phase("Z_Code generation", chunk());
+  LPhase phase("Z_Code generation", chunk());
   ASSERT(is_unused());
   status_ = GENERATING;
 
index c784f91..324381f 100644 (file)
@@ -455,7 +455,7 @@ LOperand* LPlatformChunk::GetNextSpillSlot(bool is_double)  {
 LPlatformChunk* LChunkBuilder::Build() {
   ASSERT(is_unused());
   chunk_ = new(zone()) LPlatformChunk(info(), graph());
-  HPhase phase("L_Building chunk", chunk_);
+  LPhase phase("L_Building chunk", chunk_);
   status_ = BUILDING;
   const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
   for (int i = 0; i < blocks->length(); i++) {
index 0ce4486..09b76e4 100644 (file)
@@ -67,7 +67,7 @@ class SafepointGenerator : public CallWrapper {
 #define __ masm()->
 
 bool LCodeGen::GenerateCode() {
-  HPhase phase("Z_Code generation", chunk());
+  LPhase phase("Z_Code generation", chunk());
   ASSERT(is_unused());
   status_ = GENERATING;
 
index 1569d9a..de76741 100644 (file)
@@ -456,7 +456,7 @@ void LTransitionElementsKind::PrintDataTo(StringStream* stream) {
 LPlatformChunk* LChunkBuilder::Build() {
   ASSERT(is_unused());
   chunk_ = new(zone()) LPlatformChunk(info(), graph());
-  HPhase phase("L_Building chunk", chunk_);
+  LPhase phase("L_Building chunk", chunk_);
   status_ = BUILDING;
   const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
   for (int i = 0; i < blocks->length(); i++) {
index 6d94754..128552a 100644 (file)
@@ -241,6 +241,8 @@ class ZoneScope BASE_EMBEDDED {
 
   virtual ~ZoneScope();
 
+  Zone* zone() const { return zone_; }
+
   inline bool ShouldDeleteOnExit();
 
   // For ZoneScopes that do not delete on exit by default, call this