Revision: 12064
Author:   [email protected]
Date:     Thu Jul 12 08:10:34 2012
Log:      Break Crankshaft into phases.

Crankshaft now runs by calling CreateGraph on the HGraphBuilder, then
calling Optimize and Codegen on the HGraph.

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/10700115
http://code.google.com/p/v8/source/detail?r=12064

Modified:
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.h
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h
 /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h
 /branches/bleeding_edge/src/lithium-allocator.cc
 /branches/bleeding_edge/src/lithium-allocator.h
 /branches/bleeding_edge/src/lithium.cc
 /branches/bleeding_edge/src/lithium.h
 /branches/bleeding_edge/src/mips/lithium-codegen-mips.h
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Wed Jun 20 01:58:41 2012 +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.h Thu Jul 12 08:10:34 2012
@@ -43,9 +43,9 @@

 class LCodeGen BASE_EMBEDDED {
  public:
-  LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info)
+ LCodeGen(LChunkBase* chunk, MacroAssembler* assembler, CompilationInfo* info)
       : zone_(info->zone()),
-        chunk_(chunk),
+        chunk_(static_cast<LChunk*>(chunk)),
         masm_(assembler),
         info_(info),
         current_block_(-1),
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Mon Jul  9 01:59:03 2012
+++ /branches/bleeding_edge/src/compiler.cc     Thu Jul 12 08:10:34 2012
@@ -308,11 +308,19 @@
   }

   if (graph != NULL) {
-    Handle<Code> optimized_code = graph->Compile();
-    if (!optimized_code.is_null()) {
-      info->SetCode(optimized_code);
-      FinishOptimization(info->closure(), start);
-      return true;
+    SmartArrayPointer<char> bailout_reason;
+    if (!graph->Optimize(&bailout_reason)) {
+      if (!bailout_reason.is_empty()) builder.Bailout(*bailout_reason);
+    } else {
+      LChunkBase* chunk = LChunkBase::NewChunk(graph);
+      if (chunk != NULL) {
+        Handle<Code> optimized_code = chunk->Codegen();
+        if (!optimized_code.is_null()) {
+          info->SetCode(optimized_code);
+          FinishOptimization(info->closure(), start);
+          return true;
+        }
+      }
     }
   }

=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Thu Jul 12 02:32:26 2012
+++ /branches/bleeding_edge/src/hydrogen.cc     Thu Jul 12 08:10:34 2012
@@ -701,47 +701,6 @@
   entry_block_ = CreateBasicBlock();
   entry_block_->SetInitialEnvironment(start_environment_);
 }
-
-
-Handle<Code> HGraph::Compile() {
-  int values = GetMaximumValueID();
-  if (values > LUnallocated::kMaxVirtualRegisters) {
-    if (FLAG_trace_bailout) {
-      PrintF("Not enough virtual registers for (values).\n");
-    }
-    return Handle<Code>::null();
-  }
-  LAllocator allocator(values, this);
-  LChunkBuilder builder(info(), this, &allocator);
-  LChunk* chunk = builder.Build();
-  if (chunk == NULL) return Handle<Code>::null();
-
-  if (!allocator.Allocate(chunk)) {
-    if (FLAG_trace_bailout) {
-      PrintF("Not enough virtual registers (regalloc).\n");
-    }
-    return Handle<Code>::null();
-  }
-
-  MacroAssembler assembler(isolate(), NULL, 0);
-  LCodeGen generator(chunk, &assembler, info());
-
-  chunk->MarkEmptyBlocks();
-
-  if (generator.GenerateCode()) {
-    if (FLAG_trace_codegen) {
-      PrintF("Crankshaft Compiler - ");
-    }
-    CodeGenerator::MakeCodePrologue(info());
-    Code::Flags flags = Code::ComputeFlags(Code::OPTIMIZED_FUNCTION);
-    Handle<Code> code =
-        CodeGenerator::MakeCodeEpilogue(&assembler, flags, info());
-    generator.FinishCode(code);
-    CodeGenerator::PrintCode(code, info());
-    return code;
-  }
-  return Handle<Code>::null();
-}


 HBasicBlock* HGraph::CreateBasicBlock() {
@@ -3122,48 +3081,55 @@
     }
   }

-  graph()->OrderBlocks();
-  graph()->AssignDominators();
+  return graph();
+}
+
+bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) {
+  *bailout_reason = SmartArrayPointer<char>();
+  OrderBlocks();
+  AssignDominators();

 #ifdef DEBUG
   // Do a full verify after building the graph and computing dominators.
-  graph()->Verify(true);
+  Verify(true);
 #endif

-  graph()->PropagateDeoptimizingMark();
-  if (!graph()->CheckConstPhiUses()) {
-    Bailout("Unsupported phi use of const variable");
-    return NULL;
-  }
-  graph()->EliminateRedundantPhis();
-  if (!graph()->CheckArgumentsPhiUses()) {
-    Bailout("Unsupported phi use of arguments");
-    return NULL;
-  }
-  if (FLAG_eliminate_dead_phis) graph()->EliminateUnreachablePhis();
-  graph()->CollectPhis();
-
-  if (graph()->has_osr_loop_entry()) {
-    const ZoneList<HPhi*>* phis = graph()->osr_loop_entry()->phis();
+  PropagateDeoptimizingMark();
+  if (!CheckConstPhiUses()) {
+    *bailout_reason = SmartArrayPointer<char>(StrDup(
+        "Unsupported phi use of const variable"));
+    return false;
+  }
+  EliminateRedundantPhis();
+  if (!CheckArgumentsPhiUses()) {
+    *bailout_reason = SmartArrayPointer<char>(StrDup(
+        "Unsupported phi use of arguments"));
+    return false;
+  }
+  if (FLAG_eliminate_dead_phis) EliminateUnreachablePhis();
+  CollectPhis();
+
+  if (has_osr_loop_entry()) {
+    const ZoneList<HPhi*>* phis = osr_loop_entry()->phis();
     for (int j = 0; j < phis->length(); j++) {
       HPhi* phi = phis->at(j);
- graph()->osr_values()->at(phi->merged_index())->set_incoming_value(phi);
+      osr_values()->at(phi->merged_index())->set_incoming_value(phi);
     }
   }

-  HInferRepresentation rep(graph());
+  HInferRepresentation rep(this);
   rep.Analyze();

-  graph()->MarkDeoptimizeOnUndefined();
-  graph()->InsertRepresentationChanges();
-
-  graph()->InitializeInferredTypes();
-  graph()->Canonicalize();
+  MarkDeoptimizeOnUndefined();
+  InsertRepresentationChanges();
+
+  InitializeInferredTypes();
+  Canonicalize();

// Perform common subexpression elimination and loop-invariant code motion.
   if (FLAG_use_gvn) {
-    HPhase phase("H_Global value numbering", graph());
-    HGlobalValueNumberer gvn(graph(), info());
+    HPhase phase("H_Global value numbering", this);
+    HGlobalValueNumberer gvn(this, info());
     bool removed_side_effects = gvn.Analyze();
// Trigger a second analysis pass to further eliminate duplicate values that // could only be discovered by removing side-effect-generating instructions
@@ -3175,19 +3141,19 @@
   }

   if (FLAG_use_range) {
-    HRangeAnalysis rangeAnalysis(graph());
+    HRangeAnalysis rangeAnalysis(this);
     rangeAnalysis.Analyze();
   }
-  graph()->ComputeMinusZeroChecks();
+  ComputeMinusZeroChecks();

   // Eliminate redundant stack checks on backwards branches.
-  HStackCheckEliminator sce(graph());
+  HStackCheckEliminator sce(this);
   sce.Process();

-  graph()->EliminateRedundantBoundsChecks();
-  graph()->DehoistSimpleArrayIndexComputations();
-
-  return graph();
+  EliminateRedundantBoundsChecks();
+  DehoistSimpleArrayIndexComputations();
+
+  return true;
 }


=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Wed Jul 11 09:17:02 2012
+++ /branches/bleeding_edge/src/hydrogen.h      Thu Jul 12 08:10:34 2012
@@ -281,8 +281,6 @@

   void CollectPhis();

-  Handle<Code> Compile();
-
   void set_undefined_constant(HConstant* constant) {
     undefined_constant_.set(constant);
   }
@@ -312,6 +310,8 @@
     if (id >= 0 && id < values_.length()) return values_[id];
     return NULL;
   }
+
+  bool Optimize(SmartArrayPointer<char>* bailout_reason);

 #ifdef DEBUG
   void Verify(bool do_full_verify) const;
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Wed Jun 20 01:58:41 2012 +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.h Thu Jul 12 08:10:34 2012
@@ -46,9 +46,9 @@

 class LCodeGen BASE_EMBEDDED {
  public:
-  LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info)
+ LCodeGen(LChunkBase* chunk, MacroAssembler* assembler, CompilationInfo* info)
       : zone_(info->zone()),
-        chunk_(chunk),
+        chunk_(static_cast<LChunk*>(chunk)),
         masm_(assembler),
         info_(info),
         current_block_(-1),
=======================================
--- /branches/bleeding_edge/src/lithium-allocator.cc Mon Jun 11 05:42:31 2012 +++ /branches/bleeding_edge/src/lithium-allocator.cc Thu Jul 12 08:10:34 2012
@@ -1062,9 +1062,9 @@
 }


-bool LAllocator::Allocate(LChunk* chunk) {
+bool LAllocator::Allocate(LChunkBase* chunk) {
   ASSERT(chunk_ == NULL);
-  chunk_ = chunk;
+  chunk_ = static_cast<LChunk*>(chunk);
   MeetRegisterConstraints();
   if (!AllocationOk()) return false;
   ResolvePhis();
=======================================
--- /branches/bleeding_edge/src/lithium-allocator.h     Mon Jun 11 05:42:31 2012
+++ /branches/bleeding_edge/src/lithium-allocator.h     Thu Jul 12 08:10:34 2012
@@ -445,7 +445,7 @@
   // Returns the register kind required by the given virtual register.
   RegisterKind RequiredRegisterKind(int virtual_register) const;

-  bool Allocate(LChunk* chunk);
+  bool Allocate(LChunkBase* chunk);

   const ZoneList<LiveRange*>* live_ranges() const { return &live_ranges_; }
   const Vector<LiveRange*>* fixed_live_ranges() const {
=======================================
--- /branches/bleeding_edge/src/lithium.cc      Wed Jul 11 09:17:02 2012
+++ /branches/bleeding_edge/src/lithium.cc      Thu Jul 12 08:10:34 2012
@@ -31,12 +31,16 @@

 #if V8_TARGET_ARCH_IA32
 #include "ia32/lithium-ia32.h"
+#include "ia32/lithium-codegen-ia32.h"
 #elif V8_TARGET_ARCH_X64
 #include "x64/lithium-x64.h"
+#include "x64/lithium-codegen-x64.h"
 #elif V8_TARGET_ARCH_ARM
 #include "arm/lithium-arm.h"
+#include "arm/lithium-codegen-arm.h"
 #elif V8_TARGET_ARCH_MIPS
 #include "mips/lithium-mips.h"
+#include "mips/lithium-codegen-mips.h"
 #else
 #error "Unknown architecture."
 #endif
@@ -384,6 +388,52 @@
     LConstantOperand* operand) const {
   return graph_->LookupValue(operand->index())->representation();
 }
+
+
+LChunkBase* LChunkBase::NewChunk(HGraph* graph) {
+  int values = graph->GetMaximumValueID();
+  if (values > LUnallocated::kMaxVirtualRegisters) {
+    if (FLAG_trace_bailout) {
+      PrintF("Not enough virtual registers for (values).\n");
+    }
+    return NULL;
+  }
+  LAllocator allocator(values, graph);
+  LChunkBuilder builder(graph->info(), graph, &allocator);
+  LChunkBase* chunk = builder.Build();
+  if (chunk == NULL) return NULL;
+
+  if (!allocator.Allocate(chunk)) {
+    if (FLAG_trace_bailout) {
+      PrintF("Not enough virtual registers (regalloc).\n");
+    }
+    return NULL;
+  }
+
+  return chunk;
+}
+
+
+Handle<Code> LChunkBase::Codegen() {
+  MacroAssembler assembler(info()->isolate(), NULL, 0);
+  LCodeGen generator(this, &assembler, info());
+
+  MarkEmptyBlocks();
+
+  if (generator.GenerateCode()) {
+    if (FLAG_trace_codegen) {
+      PrintF("Crankshaft Compiler - ");
+    }
+    CodeGenerator::MakeCodePrologue(info());
+    Code::Flags flags = Code::ComputeFlags(Code::OPTIMIZED_FUNCTION);
+    Handle<Code> code =
+        CodeGenerator::MakeCodeEpilogue(&assembler, flags, info());
+    generator.FinishCode(code);
+    CodeGenerator::PrintCode(code, info());
+    return code;
+  }
+  return Handle<Code>::null();
+}


 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/lithium.h       Wed Jul 11 09:17:02 2012
+++ /branches/bleeding_edge/src/lithium.h       Thu Jul 12 08:10:34 2012
@@ -622,6 +622,7 @@
 };


+class LChunk;
 class LGap;
 class LLabel;

@@ -629,13 +630,7 @@
 // arch-specific LChunk classes.
 class LChunkBase: public ZoneObject {
  public:
-  LChunkBase(CompilationInfo* info, HGraph* graph)
-    : spill_slot_count_(0),
-      info_(info),
-      graph_(graph),
-      instructions_(32, graph->zone()),
-      pointer_maps_(8, graph->zone()),
-      inlined_closures_(1, graph->zone()) { }
+  static LChunkBase* NewChunk(HGraph* graph);

   void AddInstruction(LInstruction* instruction, HBasicBlock* block);
   LConstantOperand* DefineConstantOperand(HConstant* constant);
@@ -667,8 +662,18 @@
   }

   Zone* zone() const { return info_->zone(); }
+
+  Handle<Code> Codegen();

  protected:
+  LChunkBase(CompilationInfo* info, HGraph* graph)
+      : spill_slot_count_(0),
+        info_(info),
+        graph_(graph),
+        instructions_(32, graph->zone()),
+        pointer_maps_(8, graph->zone()),
+        inlined_closures_(1, graph->zone()) { }
+
   int spill_slot_count_;

  private:
=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.h Wed Jun 20 01:58:41 2012 +++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.h Thu Jul 12 08:10:34 2012
@@ -43,9 +43,9 @@

 class LCodeGen BASE_EMBEDDED {
  public:
-  LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info)
+ LCodeGen(LChunkBase* chunk, MacroAssembler* assembler, CompilationInfo* info)
       : zone_(info->zone()),
-        chunk_(chunk),
+        chunk_(static_cast<LChunk*>(chunk)),
         masm_(assembler),
         info_(info),
         current_block_(-1),
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Wed Jun 20 01:58:41 2012 +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.h Thu Jul 12 08:10:34 2012
@@ -45,9 +45,9 @@

 class LCodeGen BASE_EMBEDDED {
  public:
-  LCodeGen(LChunk* chunk, MacroAssembler* assembler, CompilationInfo* info)
+ LCodeGen(LChunkBase* chunk, MacroAssembler* assembler, CompilationInfo* info)
       : zone_(info->zone()),
-        chunk_(chunk),
+        chunk_(static_cast<LChunk*>(chunk)),
         masm_(assembler),
         info_(info),
         current_block_(-1),

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to