[turbofan] add ForTesting to pipeline entry points that are for testing only.
authorDan Carney <dcarney@chromium.org>
Mon, 17 Nov 2014 14:46:41 +0000 (15:46 +0100)
committerDan Carney <dcarney@chromium.org>
Mon, 17 Nov 2014 14:46:54 +0000 (14:46 +0000)
R=bmeurer@chromium.org

BUG=

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

Cr-Commit-Position: refs/heads/master@{#25382}

src/compiler/pipeline.cc
src/compiler/pipeline.h
test/cctest/compiler/codegen-tester.h
test/cctest/compiler/function-tester.h
test/cctest/compiler/graph-builder-tester.cc
test/cctest/compiler/test-codegen-deopt.cc
test/unittests/compiler/register-allocator-unittest.cc

index de4320a..4c76701 100644 (file)
@@ -91,15 +91,15 @@ class PipelineData {
   }
 
   // For machine graph testing entry point.
-  void Initialize(Graph* graph, Schedule* schedule) {
+  void InitializeTorTesting(Graph* graph, Schedule* schedule) {
     graph_ = graph;
     source_positions_.Reset(new SourcePositionTable(graph));
     schedule_ = schedule;
     instruction_zone_ = instruction_zone_scope_.zone();
   }
 
-  // For register allocation entry point.
-  void Initialize(InstructionSequence* sequence) {
+  // For register allocation testing entry point.
+  void InitializeTorTesting(InstructionSequence* sequence) {
     instruction_zone_ = sequence->zone();
     sequence_ = sequence;
   }
@@ -778,28 +778,48 @@ Handle<Code> Pipeline::GenerateCode() {
 }
 
 
-Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage,
-                                                   Graph* graph,
-                                                   Schedule* schedule) {
-  ZonePool zone_pool(isolate());
+Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info,
+                                              Graph* graph,
+                                              Schedule* schedule) {
+  CallDescriptor* call_descriptor =
+      Linkage::ComputeIncoming(info->zone(), info);
+  return GenerateCodeForTesting(info, call_descriptor, graph, schedule);
+}
+
+
+Handle<Code> Pipeline::GenerateCodeForTesting(CallDescriptor* call_descriptor,
+                                              Graph* graph,
+                                              Schedule* schedule) {
+  CompilationInfo info(graph->zone()->isolate(), graph->zone());
+  return GenerateCodeForTesting(&info, call_descriptor, graph, schedule);
+}
+
+
+Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info,
+                                              CallDescriptor* call_descriptor,
+                                              Graph* graph,
+                                              Schedule* schedule) {
   CHECK(SupportedBackend());
-  PipelineData data(&zone_pool, info());
-  data.Initialize(graph, schedule);
-  this->data_ = &data;
+  ZonePool zone_pool(info->isolate());
+  Pipeline pipeline(info);
+  PipelineData data(&zone_pool, info);
+  pipeline.data_ = &data;
+  data.InitializeTorTesting(graph, schedule);
   if (schedule == NULL) {
     // TODO(rossberg): Should this really be untyped?
-    RunPrintAndVerify("Machine", true);
-    Run<ComputeSchedulePhase>();
+    pipeline.RunPrintAndVerify("Machine", true);
+    pipeline.Run<ComputeSchedulePhase>();
   } else {
     TraceSchedule(schedule);
   }
 
-  GenerateCode(linkage);
+  Linkage linkage(info->zone(), call_descriptor);
+  pipeline.GenerateCode(&linkage);
   Handle<Code> code = data.code();
 
 #if ENABLE_DISASSEMBLER
   if (!code.is_null() && FLAG_print_opt_code) {
-    CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
+    CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer());
     OFStream os(tracing_scope.file());
     code->Disassemble("test code", os);
   }
@@ -808,13 +828,13 @@ Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage,
 }
 
 
-bool Pipeline::AllocateRegisters(const RegisterConfiguration* config,
-                                 InstructionSequence* sequence,
-                                 bool run_verifier) {
+bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
+                                           InstructionSequence* sequence,
+                                           bool run_verifier) {
   CompilationInfo info(sequence->zone()->isolate(), sequence->zone());
   ZonePool zone_pool(sequence->zone()->isolate());
   PipelineData data(&zone_pool, &info);
-  data.Initialize(sequence);
+  data.InitializeTorTesting(sequence);
   Pipeline pipeline(&info);
   pipeline.data_ = &data;
   pipeline.AllocateRegisters(config, run_verifier);
index 5941251..73053dc 100644 (file)
@@ -17,6 +17,7 @@ namespace internal {
 namespace compiler {
 
 // Clients of this interface shouldn't depend on lots of compiler internals.
+class CallDescriptor;
 class Graph;
 class InstructionSequence;
 class Linkage;
@@ -31,14 +32,22 @@ class Pipeline {
   // Run the entire pipeline and generate a handle to a code object.
   Handle<Code> GenerateCode();
 
-  // Run the pipeline on a machine graph and generate code. If {schedule}
-  // is {NULL}, then compute a new schedule for code generation.
-  Handle<Code> GenerateCodeForMachineGraph(Linkage* linkage, Graph* graph,
-                                           Schedule* schedule = NULL);
+  // Run the pipeline on a machine graph and generate code. If {schedule} is
+  // {nullptr}, then compute a new schedule for code generation.
+  static Handle<Code> GenerateCodeForTesting(CompilationInfo* info,
+                                             Graph* graph,
+                                             Schedule* schedule = nullptr);
 
-  static bool AllocateRegisters(const RegisterConfiguration* config,
-                                InstructionSequence* sequence,
-                                bool run_verifier);
+  // Run the pipeline on a machine graph and generate code. If {schedule} is
+  // {nullptr}, then compute a new schedule for code generation.
+  static Handle<Code> GenerateCodeForTesting(CallDescriptor* call_descriptor,
+                                             Graph* graph,
+                                             Schedule* schedule = nullptr);
+
+  // Run just the register allocator phases.
+  static bool AllocateRegistersForTesting(const RegisterConfiguration* config,
+                                          InstructionSequence* sequence,
+                                          bool run_verifier);
 
   static inline bool SupportedBackend() { return V8_TURBOFAN_BACKEND != 0; }
   static inline bool SupportedTarget() { return V8_TURBOFAN_TARGET != 0; }
@@ -47,6 +56,10 @@ class Pipeline {
   static void TearDown();
 
  private:
+  static Handle<Code> GenerateCodeForTesting(CompilationInfo* info,
+                                             CallDescriptor* call_descriptor,
+                                             Graph* graph, Schedule* schedule);
+
   CompilationInfo* info_;
   PipelineData* data_;
 
index 72d658f..283d533 100644 (file)
@@ -68,10 +68,8 @@ class MachineAssemblerTester : public HandleAndZoneScope,
       Schedule* schedule = this->Export();
       CallDescriptor* call_descriptor = this->call_descriptor();
       Graph* graph = this->graph();
-      CompilationInfo info(graph->zone()->isolate(), graph->zone());
-      Linkage linkage(graph->zone(), call_descriptor);
-      Pipeline pipeline(&info);
-      code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph, schedule);
+      code_ =
+          Pipeline::GenerateCodeForTesting(call_descriptor, graph, schedule);
     }
     return this->code_.ToHandleChecked()->entry();
   }
index 600f6a3..7e16eea 100644 (file)
@@ -216,9 +216,7 @@ class FunctionTester : public InitializedHandleScope {
     CHECK(Compiler::Analyze(&info));
     CHECK(Compiler::EnsureDeoptimizationSupport(&info));
 
-    Pipeline pipeline(&info);
-    Linkage linkage(info.zone(), &info);
-    Handle<Code> code = pipeline.GenerateCodeForMachineGraph(&linkage, graph);
+    Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
     CHECK(!code.is_null());
     function->ReplaceCode(*code);
     return function;
index 9c4379c..b0f470b 100644 (file)
@@ -35,11 +35,9 @@ byte* MachineCallHelper::Generate() {
   if (!Pipeline::SupportedBackend()) return NULL;
   if (code_.is_null()) {
     Zone* zone = graph_->zone();
-    CompilationInfo info(zone->isolate(), zone);
-    Linkage linkage(zone,
-                    Linkage::GetSimplifiedCDescriptor(zone, machine_sig_));
-    Pipeline pipeline(&info);
-    code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph_);
+    CallDescriptor* desc =
+        Linkage::GetSimplifiedCDescriptor(zone, machine_sig_);
+    code_ = Pipeline::GenerateCodeForTesting(desc, graph_);
   }
   return code_.ToHandleChecked()->entry();
 }
index 3b68470..56afe7b 100644 (file)
@@ -63,12 +63,7 @@ class DeoptCodegenTester {
     if (FLAG_trace_turbo) {
       os << *schedule;
     }
-
-    Linkage* linkage = new (scope_->main_zone()) Linkage(info.zone(), &info);
-    Pipeline pipeline(&info);
-    result_code =
-        pipeline.GenerateCodeForMachineGraph(linkage, graph, schedule);
-
+    result_code = Pipeline::GenerateCodeForTesting(&info, graph, schedule);
 #ifdef OBJECT_PRINT
     if (FLAG_print_opt_code || FLAG_trace_turbo) {
       result_code->Print();
index 546b253..290c285 100644 (file)
@@ -219,7 +219,7 @@ class RegisterAllocatorTest : public TestWithZone {
   void Allocate() {
     CHECK_EQ(nullptr, current_block_);
     WireBlocks();
-    Pipeline::AllocateRegisters(config(), sequence(), true);
+    Pipeline::AllocateRegistersForTesting(config(), sequence(), true);
   }
 
   TestOperand Imm(int32_t imm = 0) {