[turbofan] Cache the Branch operator(s).
authorBenedikt Meurer <bmeurer@chromium.org>
Tue, 2 Dec 2014 12:41:31 +0000 (13:41 +0100)
committerBenedikt Meurer <bmeurer@chromium.org>
Tue, 2 Dec 2014 12:41:44 +0000 (12:41 +0000)
TEST=unittests
R=dcarney@chromium.org

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

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

src/compiler/common-operator.cc

index b0af2fd..58f62c8 100644 (file)
@@ -124,6 +124,19 @@ struct CommonOperatorGlobalCache FINAL {
   Name##Operator k##Name##Operator;
   CACHED_OP_LIST(CACHED)
 #undef CACHED
+
+  template <BranchHint kBranchHint>
+  struct BranchOperator FINAL : public Operator1<BranchHint> {
+    BranchOperator()
+        : Operator1<BranchHint>(                       // --
+              IrOpcode::kBranch, Operator::kFoldable,  // opcode
+              "Branch",                                // name
+              1, 0, 1, 0, 0, 2,                        // counts
+              kBranchHint) {}                          // parameter
+  };
+  BranchOperator<BranchHint::kNone> kBranchNoneOperator;
+  BranchOperator<BranchHint::kTrue> kBranchTrueOperator;
+  BranchOperator<BranchHint::kFalse> kBranchFalseOperator;
 };
 
 
@@ -145,8 +158,16 @@ CACHED_OP_LIST(CACHED)
 
 
 const Operator* CommonOperatorBuilder::Branch(BranchHint hint) {
-  return new (zone()) Operator1<BranchHint>(
-      IrOpcode::kBranch, Operator::kFoldable, "Branch", 1, 0, 1, 0, 0, 2, hint);
+  switch (hint) {
+    case BranchHint::kNone:
+      return &cache_.kBranchNoneOperator;
+    case BranchHint::kTrue:
+      return &cache_.kBranchTrueOperator;
+    case BranchHint::kFalse:
+      return &cache_.kBranchFalseOperator;
+  }
+  UNREACHABLE();
+  return nullptr;
 }