Revision: 25010
Author:   [email protected]
Date:     Thu Oct 30 09:50:15 2014 UTC
Log:      [turbofan] move Node to vreg mapping to InstructionSelector

BUG=
[email protected]

Review URL: https://codereview.chromium.org/683933004
https://code.google.com/p/v8/source/detail?r=25010

Modified:
 /branches/bleeding_edge/src/compiler/instruction-selector-impl.h
 /branches/bleeding_edge/src/compiler/instruction-selector.cc
 /branches/bleeding_edge/src/compiler/instruction-selector.h
 /branches/bleeding_edge/src/compiler/instruction.cc
 /branches/bleeding_edge/src/compiler/instruction.h
 /branches/bleeding_edge/src/compiler/pipeline.cc
 /branches/bleeding_edge/test/cctest/compiler/test-codegen-deopt.cc
 /branches/bleeding_edge/test/cctest/compiler/test-instruction.cc
/branches/bleeding_edge/test/unittests/compiler/instruction-selector-unittest.cc

=======================================
--- /branches/bleeding_edge/src/compiler/instruction-selector-impl.h Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/instruction-selector-impl.h Thu Oct 30 09:50:15 2014 UTC
@@ -46,7 +46,8 @@

   InstructionOperand* DefineAsConstant(Node* node) {
     selector()->MarkAsDefined(node);
-    int virtual_register = sequence()->AddConstant(node, ToConstant(node));
+    int virtual_register = selector_->GetVirtualRegister(node);
+    sequence()->AddConstant(virtual_register, ToConstant(node));
     return ConstantOperand::Create(virtual_register, zone());
   }

@@ -172,8 +173,7 @@
   UnallocatedOperand* Define(Node* node, UnallocatedOperand* operand) {
     DCHECK_NOT_NULL(node);
     DCHECK_NOT_NULL(operand);
-    operand->set_virtual_register(
-        selector_->sequence()->GetVirtualRegister(node));
+    operand->set_virtual_register(selector_->GetVirtualRegister(node));
     selector()->MarkAsDefined(node);
     return operand;
   }
@@ -181,8 +181,7 @@
   UnallocatedOperand* Use(Node* node, UnallocatedOperand* operand) {
     DCHECK_NOT_NULL(node);
     DCHECK_NOT_NULL(operand);
-    operand->set_virtual_register(
-        selector_->sequence()->GetVirtualRegister(node));
+    operand->set_virtual_register(selector_->GetVirtualRegister(node));
     selector()->MarkAsUsed(node);
     return operand;
   }
=======================================
--- /branches/bleeding_edge/src/compiler/instruction-selector.cc Wed Oct 29 18:46:44 2014 UTC +++ /branches/bleeding_edge/src/compiler/instruction-selector.cc Thu Oct 30 09:50:15 2014 UTC
@@ -4,6 +4,7 @@

 #include "src/compiler/instruction-selector.h"

+#include "src/compiler/graph.h"
 #include "src/compiler/instruction-selector-impl.h"
 #include "src/compiler/node-matchers.h"
 #include "src/compiler/node-properties-inl.h"
@@ -13,7 +14,8 @@
 namespace internal {
 namespace compiler {

-InstructionSelector::InstructionSelector(Zone* local_zone, Linkage* linkage,
+InstructionSelector::InstructionSelector(Zone* local_zone, Graph* graph,
+                                         Linkage* linkage,
                                          InstructionSequence* sequence,
                                          Schedule* schedule,
SourcePositionTable* source_positions,
@@ -24,10 +26,11 @@
       source_positions_(source_positions),
       features_(features),
       schedule_(schedule),
+      node_map_(graph->NodeCount(), kNodeUnmapped, zone()),
       current_block_(NULL),
       instructions_(zone()),
-      defined_(sequence->node_count(), false, zone()),
-      used_(sequence->node_count(), false, zone()) {}
+      defined_(graph->NodeCount(), false, zone()),
+      used_(graph->NodeCount(), false, zone()) {}


 void InstructionSelector::SelectInstructions() {
@@ -155,6 +158,19 @@
   return node->OwnedBy(user) &&
          schedule()->block(node) == schedule()->block(user);
 }
+
+
+int InstructionSelector::GetVirtualRegister(const Node* node) {
+  if (node_map_[node->id()] == kNodeUnmapped) {
+    node_map_[node->id()] = sequence()->NextVirtualRegister();
+  }
+  return node_map_[node->id()];
+}
+
+
+int InstructionSelector::GetMappedVirtualRegister(const Node* node) const {
+  return node_map_[node->id()];
+}


 bool InstructionSelector::IsDefined(Node* node) const {
@@ -195,27 +211,31 @@

 bool InstructionSelector::IsDouble(const Node* node) const {
   DCHECK_NOT_NULL(node);
-  return sequence()->IsDouble(sequence()->GetVirtualRegister(node));
+  int virtual_register = GetMappedVirtualRegister(node);
+  if (virtual_register == kNodeUnmapped) return false;
+  return sequence()->IsDouble(virtual_register);
 }


 void InstructionSelector::MarkAsDouble(Node* node) {
   DCHECK_NOT_NULL(node);
   DCHECK(!IsReference(node));
-  sequence()->MarkAsDouble(sequence()->GetVirtualRegister(node));
+  sequence()->MarkAsDouble(GetVirtualRegister(node));
 }


 bool InstructionSelector::IsReference(const Node* node) const {
   DCHECK_NOT_NULL(node);
-  return sequence()->IsReference(sequence()->GetVirtualRegister(node));
+  int virtual_register = GetMappedVirtualRegister(node);
+  if (virtual_register == kNodeUnmapped) return false;
+  return sequence()->IsReference(virtual_register);
 }


 void InstructionSelector::MarkAsReference(Node* node) {
   DCHECK_NOT_NULL(node);
   DCHECK(!IsDouble(node));
-  sequence()->MarkAsReference(sequence()->GetVirtualRegister(node));
+  sequence()->MarkAsReference(GetVirtualRegister(node));
 }


@@ -892,14 +912,14 @@
 void InstructionSelector::VisitPhi(Node* node) {
   // TODO(bmeurer): Emit a PhiInstruction here.
   PhiInstruction* phi = new (instruction_zone())
- PhiInstruction(instruction_zone(), sequence()->GetVirtualRegister(node));
+      PhiInstruction(instruction_zone(), GetVirtualRegister(node));
sequence()->InstructionBlockAt(current_block_->GetRpoNumber())->AddPhi(phi);
   const int input_count = node->op()->InputCount();
   phi->operands().reserve(static_cast<size_t>(input_count));
   for (int i = 0; i < input_count; ++i) {
     Node* const input = node->InputAt(i);
     MarkAsUsed(input);
-    phi->operands().push_back(sequence()->GetVirtualRegister(input));
+    phi->operands().push_back(GetVirtualRegister(input));
   }
 }

=======================================
--- /branches/bleeding_edge/src/compiler/instruction-selector.h Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/instruction-selector.h Thu Oct 30 09:50:15 2014 UTC
@@ -21,12 +21,17 @@
 class FlagsContinuation;
 class Linkage;

+typedef IntVector NodeToVregMap;
+
 class InstructionSelector FINAL {
  public:
+  static const int kNodeUnmapped = -1;
+
   // Forward declarations.
   class Features;

-  InstructionSelector(Zone* local_zone, Linkage* linkage,
+  // TODO(dcarney): pass in vreg mapping instead of graph.
+  InstructionSelector(Zone* local_zone, Graph* graph, Linkage* linkage,
                       InstructionSequence* sequence, Schedule* schedule,
                       SourcePositionTable* source_positions,
                       Features features = SupportedFeatures());
@@ -109,6 +114,11 @@

   // Checks if {node} is currently live.
bool IsLive(Node* node) const { return !IsDefined(node) && IsUsed(node); }
+
+  int GetVirtualRegister(const Node* node);
+  // Gets the current mapping if it exists, kNodeUnmapped otherwise.
+  int GetMappedVirtualRegister(const Node* node) const;
+  const NodeToVregMap& GetNodeMapForTesting() const { return node_map_; }

  private:
   friend class OperandGenerator;
@@ -206,6 +216,7 @@
   SourcePositionTable* const source_positions_;
   Features features_;
   Schedule* const schedule_;
+  NodeToVregMap node_map_;
   BasicBlock* current_block_;
   ZoneDeque<Instruction*> instructions_;
   BoolVector defined_;
=======================================
--- /branches/bleeding_edge/src/compiler/instruction.cc Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/instruction.cc Thu Oct 30 09:50:15 2014 UTC
@@ -387,10 +387,8 @@


 InstructionSequence::InstructionSequence(Zone* instruction_zone,
-                                         const Graph* graph,
                                          const Schedule* schedule)
     : zone_(instruction_zone),
-      node_map_(graph->NodeCount(), kNodeUnmapped, zone()),
instruction_blocks_(static_cast<int>(schedule->rpo_order()->size()), NULL,
                           zone()),
       constants_(ConstantMap::key_compare(),
@@ -404,14 +402,6 @@
       deoptimization_entries_(zone()) {
   InitializeInstructionBlocks(zone(), schedule, &instruction_blocks_);
 }
-
-
-int InstructionSequence::GetVirtualRegister(const Node* node) {
-  if (node_map_[node->id()] == kNodeUnmapped) {
-    node_map_[node->id()] = NextVirtualRegister();
-  }
-  return node_map_[node->id()];
-}


 Label* InstructionSequence::GetLabel(BasicBlock::RpoNumber rpo) {
=======================================
--- /branches/bleeding_edge/src/compiler/instruction.h Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/instruction.h Thu Oct 30 09:50:15 2014 UTC
@@ -842,21 +842,16 @@
 typedef ZoneDeque<PointerMap*> PointerMapDeque;
 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector;
 typedef ZoneVector<InstructionBlock*> InstructionBlocks;
-typedef IntVector NodeToVregMap;

// Represents architecture-specific generated code before, during, and after
 // register allocation.
 // TODO(titzer): s/IsDouble/IsFloat64/
 class InstructionSequence FINAL {
  public:
-  static const int kNodeUnmapped = -1;
-
- InstructionSequence(Zone* zone, const Graph* graph, const Schedule* schedule);
+  InstructionSequence(Zone* zone, const Schedule* schedule);

   int NextVirtualRegister() { return next_virtual_register_++; }
   int VirtualRegisterCount() const { return next_virtual_register_; }
-
-  int node_count() const { return static_cast<int>(node_map_.size()); }

   const InstructionBlocks& instruction_blocks() const {
     return instruction_blocks_;
@@ -881,9 +876,6 @@
   }

   const InstructionBlock* GetInstructionBlock(int instruction_index) const;
-
-  int GetVirtualRegister(const Node* node);
-  const NodeToVregMap& GetNodeMapForTesting() const { return node_map_; }

   bool IsReference(int virtual_register) const;
   bool IsDouble(int virtual_register) const;
@@ -919,8 +911,8 @@
   void StartBlock(BasicBlock* block);
   void EndBlock(BasicBlock* block);

-  int AddConstant(Node* node, Constant constant) {
-    int virtual_register = GetVirtualRegister(node);
+  int AddConstant(int virtual_register, Constant constant) {
+ DCHECK(virtual_register >= 0 && virtual_register < next_virtual_register_);
     DCHECK(constants_.find(virtual_register) == constants_.end());
     constants_.insert(std::make_pair(virtual_register, constant));
     return virtual_register;
@@ -967,7 +959,6 @@
typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet;

   Zone* const zone_;
-  NodeToVregMap node_map_;
   InstructionBlocks instruction_blocks_;
   ConstantMap constants_;
   ConstantDeque immediates_;
=======================================
--- /branches/bleeding_edge/src/compiler/pipeline.cc Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/pipeline.cc Thu Oct 30 09:50:15 2014 UTC
@@ -538,15 +538,15 @@
                                                        data->schedule());
   }

-  InstructionSequence sequence(data->instruction_zone(), data->graph(),
-                               data->schedule());
+  InstructionSequence sequence(data->instruction_zone(), data->schedule());

   // Select and schedule instructions covering the scheduled graph.
   {
PhaseScope phase_scope(data->pipeline_statistics(), "select instructions");
     ZonePool::Scope zone_scope(data->zone_pool());
-    InstructionSelector selector(zone_scope.zone(), linkage, &sequence,
- data->schedule(), data->source_positions());
+    InstructionSelector selector(zone_scope.zone(), data->graph(), linkage,
+                                 &sequence, data->schedule(),
+                                 data->source_positions());
     selector.SelectInstructions();
   }

=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-codegen-deopt.cc Thu Oct 30 09:00:58 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-codegen-deopt.cc Thu Oct 30 09:50:15 2014 UTC
@@ -66,10 +66,10 @@
     // Initialize the codegen and generate code.
Linkage* linkage = new (scope_->main_zone()) Linkage(info.zone(), &info); code = new v8::internal::compiler::InstructionSequence(scope_->main_zone(), - graph, schedule);
+                                                           schedule);
     SourcePositionTable source_positions(graph);
- InstructionSelector selector(scope_->main_zone(), linkage, code, schedule,
-                                 &source_positions);
+    InstructionSelector selector(scope_->main_zone(), graph, linkage, code,
+                                 schedule, &source_positions);
     selector.SelectInstructions();

     if (FLAG_trace_turbo) {
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-instruction.cc Mon Oct 27 12:39:20 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-instruction.cc Thu Oct 30 09:50:15 2014 UTC
@@ -55,7 +55,7 @@
       Scheduler::ComputeSpecialRPO(&zone_pool, &schedule);
       DCHECK(schedule.rpo_order()->size() > 0);
     }
-    code = new TestInstrSeq(main_zone(), &graph, &schedule);
+    code = new TestInstrSeq(main_zone(), &schedule);
   }

   Node* Int32Constant(int32_t val) {
@@ -128,8 +128,6 @@

   R.allocCode();

-  CHECK_EQ(R.graph.NodeCount(), R.code->node_count());
-
   BasicBlockVector* blocks = R.schedule.rpo_order();
CHECK_EQ(static_cast<int>(blocks->size()), R.code->InstructionBlockCount());

=======================================
--- /branches/bleeding_edge/test/unittests/compiler/instruction-selector-unittest.cc Mon Oct 27 12:39:20 2014 UTC +++ /branches/bleeding_edge/test/unittests/compiler/instruction-selector-unittest.cc Thu Oct 30 09:50:15 2014 UTC
@@ -37,10 +37,10 @@
   EXPECT_NE(0, graph()->NodeCount());
   int initial_node_count = graph()->NodeCount();
   Linkage linkage(test_->zone(), call_descriptor());
-  InstructionSequence sequence(test_->zone(), graph(), schedule);
+  InstructionSequence sequence(test_->zone(), schedule);
   SourcePositionTable source_position_table(graph());
- InstructionSelector selector(test_->zone(), &linkage, &sequence, schedule,
-                               &source_position_table, features);
+  InstructionSelector selector(test_->zone(), graph(), &linkage, &sequence,
+                               schedule, &source_position_table, features);
   selector.SelectInstructions();
   if (FLAG_trace_turbo) {
     OFStream out(stdout);
@@ -50,9 +50,9 @@
   Stream s;
   // Map virtual registers.
   {
-    const NodeToVregMap& node_map = sequence.GetNodeMapForTesting();
+    const NodeToVregMap& node_map = selector.GetNodeMapForTesting();
     for (int i = 0; i < initial_node_count; ++i) {
-      if (node_map[i] != InstructionSequence::kNodeUnmapped) {
+      if (node_map[i] != InstructionSelector::kNodeUnmapped) {
         s.virtual_registers_.insert(std::make_pair(i, node_map[i]));
       }
     }

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