[turbofan] Cache common Loop, Merge and Parameter operators.
authorbmeurer <bmeurer@chromium.org>
Fri, 2 Jan 2015 14:16:42 +0000 (06:16 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 2 Jan 2015 14:16:57 +0000 (14:16 +0000)
R=jarin@chromium.org
BUG=v8:3792
LOG=n

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

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

src/compiler/common-operator.cc
src/compiler/common-operator.h

index 460c47b..a6cca45 100644 (file)
@@ -112,6 +112,32 @@ std::ostream& operator<<(std::ostream& os, FrameStateCallInfo const& info) {
   V(Return, Operator::kNoProperties, 1, 1, 1, 1)
 
 
+#define CACHED_LOOP_LIST(V) \
+  V(1)                      \
+  V(2)
+
+
+#define CACHED_MERGE_LIST(V) \
+  V(1)                       \
+  V(2)                       \
+  V(3)                       \
+  V(4)                       \
+  V(5)                       \
+  V(6)                       \
+  V(7)                       \
+  V(8)
+
+
+#define CACHED_PARAMETER_LIST(V) \
+  V(0)                           \
+  V(1)                           \
+  V(2)                           \
+  V(3)                           \
+  V(4)                           \
+  V(5)                           \
+  V(6)
+
+
 struct CommonOperatorGlobalCache FINAL {
 #define CACHED(Name, properties, value_input_count, effect_input_count,     \
                control_input_count, control_output_count)                   \
@@ -137,6 +163,46 @@ struct CommonOperatorGlobalCache FINAL {
   BranchOperator<BranchHint::kNone> kBranchNoneOperator;
   BranchOperator<BranchHint::kTrue> kBranchTrueOperator;
   BranchOperator<BranchHint::kFalse> kBranchFalseOperator;
+
+  template <size_t kInputCount>
+  struct LoopOperator FINAL : public Operator {
+    LoopOperator()
+        : Operator(                                  // --
+              IrOpcode::kLoop, Operator::kFoldable,  // opcode
+              "Loop",                                // name
+              0, 0, kInputCount, 0, 0, 1) {}         // counts
+  };
+#define CACHED_LOOP(input_count) \
+  LoopOperator<input_count> kLoop##input_count##Operator;
+  CACHED_LOOP_LIST(CACHED_LOOP)
+#undef CACHED_LOOP
+
+  template <size_t kInputCount>
+  struct MergeOperator FINAL : public Operator {
+    MergeOperator()
+        : Operator(                                   // --
+              IrOpcode::kMerge, Operator::kFoldable,  // opcode
+              "Merge",                                // name
+              0, 0, kInputCount, 0, 0, 1) {}          // counts
+  };
+#define CACHED_MERGE(input_count) \
+  MergeOperator<input_count> kMerge##input_count##Operator;
+  CACHED_MERGE_LIST(CACHED_MERGE)
+#undef CACHED_MERGE
+
+  template <int kIndex>
+  struct ParameterOperator FINAL : public Operator1<int> {
+    ParameterOperator()
+        : Operator1<int>(                             // --
+              IrOpcode::kParameter, Operator::kPure,  // opcode
+              "Parameter",                            // name
+              1, 0, 0, 1, 0, 0,                       // counts,
+              kIndex) {}                              // parameter
+  };
+#define CACHED_PARAMETER(index) \
+  ParameterOperator<index> kParameter##index##Operator;
+  CACHED_PARAMETER_LIST(CACHED_PARAMETER)
+#undef CACHED_PARAMETER
 };
 
 
@@ -181,19 +247,39 @@ const Operator* CommonOperatorBuilder::Start(int num_formal_parameters) {
 }
 
 
-const Operator* CommonOperatorBuilder::Merge(int controls) {
-  return new (zone()) Operator(               // --
-      IrOpcode::kMerge, Operator::kFoldable,  // opcode
-      "Merge",                                // name
-      0, 0, controls, 0, 0, 1);               // counts
-}
-
-
-const Operator* CommonOperatorBuilder::Loop(int controls) {
+const Operator* CommonOperatorBuilder::Loop(int control_input_count) {
+  switch (control_input_count) {
+#define CACHED_LOOP(input_count) \
+  case input_count:              \
+    return &cache_.kLoop##input_count##Operator;
+    CACHED_LOOP_LIST(CACHED_LOOP)
+#undef CACHED_LOOP
+    default:
+      break;
+  }
+  // Uncached.
   return new (zone()) Operator(              // --
       IrOpcode::kLoop, Operator::kFoldable,  // opcode
       "Loop",                                // name
-      0, 0, controls, 0, 0, 1);              // counts
+      0, 0, control_input_count, 0, 0, 1);   // counts
+}
+
+
+const Operator* CommonOperatorBuilder::Merge(int control_input_count) {
+  switch (control_input_count) {
+#define CACHED_MERGE(input_count) \
+  case input_count:               \
+    return &cache_.kMerge##input_count##Operator;
+    CACHED_MERGE_LIST(CACHED_MERGE)
+#undef CACHED_MERGE
+    default:
+      break;
+  }
+  // Uncached.
+  return new (zone()) Operator(               // --
+      IrOpcode::kMerge, Operator::kFoldable,  // opcode
+      "Merge",                                // name
+      0, 0, control_input_count, 0, 0, 1);    // counts
 }
 
 
@@ -206,6 +292,16 @@ const Operator* CommonOperatorBuilder::Terminate(int effects) {
 
 
 const Operator* CommonOperatorBuilder::Parameter(int index) {
+  switch (index) {
+#define CACHED_PARAMETER(index) \
+  case index:                   \
+    return &cache_.kParameter##index##Operator;
+    CACHED_PARAMETER_LIST(CACHED_PARAMETER)
+#undef CACHED_PARAMETER
+    default:
+      break;
+  }
+  // Uncached.
   return new (zone()) Operator1<int>(         // --
       IrOpcode::kParameter, Operator::kPure,  // opcode
       "Parameter",                            // name
index 9938989..af6066b 100644 (file)
@@ -169,8 +169,8 @@ class CommonOperatorBuilder FINAL : public ZoneObject {
   const Operator* Return();
 
   const Operator* Start(int num_formal_parameters);
-  const Operator* Merge(int controls);
-  const Operator* Loop(int controls);
+  const Operator* Loop(int control_input_count);
+  const Operator* Merge(int control_input_count);
   const Operator* Parameter(int index);
 
   const Operator* Int32Constant(int32_t);