[turbofan] Turn IrOpcode::Mnemonic() into a table lookup.
authorbmeurer <bmeurer@chromium.org>
Tue, 23 Dec 2014 19:24:03 +0000 (11:24 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 23 Dec 2014 19:24:15 +0000 (19:24 +0000)
R=ishell@chromium.org

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

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

BUILD.gn
src/compiler/opcodes.cc [new file with mode: 0644]
src/compiler/opcodes.h
tools/gyp/v8.gyp

index 262e09e..6534eea 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -564,6 +564,7 @@ source_set("v8_base") {
     "src/compiler/node-properties.h",
     "src/compiler/node.cc",
     "src/compiler/node.h",
+    "src/compiler/opcodes.cc",
     "src/compiler/opcodes.h",
     "src/compiler/operator-properties.cc",
     "src/compiler/operator-properties.h",
diff --git a/src/compiler/opcodes.cc b/src/compiler/opcodes.cc
new file mode 100644 (file)
index 0000000..044395c
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/compiler/opcodes.h"
+
+#include <algorithm>
+
+#include "src/base/macros.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+namespace {
+
+char const* const kMnemonics[] = {
+#define DECLARE_MNEMONIC(x) #x,
+    ALL_OP_LIST(DECLARE_MNEMONIC)
+#undef DECLARE_MNEMONIC
+        "UnknownOpcode"};
+
+}  // namespace
+
+
+// static
+char const* IrOpcode::Mnemonic(Value value) {
+  size_t const n = std::max<size_t>(value, arraysize(kMnemonics) - 1);
+  return kMnemonics[n];
+}
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8
index ccdec4d..3f00e6a 100644 (file)
@@ -268,18 +268,7 @@ class IrOpcode {
   };
 
   // Returns the mnemonic name of an opcode.
-  static const char* Mnemonic(Value val) {
-    // TODO(turbofan): make this a table lookup.
-    switch (val) {
-#define RETURN_NAME(x) \
-  case k##x:           \
-    return #x;
-      ALL_OP_LIST(RETURN_NAME)
-#undef RETURN_NAME
-      default:
-        return "UnknownOpcode";
-    }
-  }
+  static char const* Mnemonic(Value value);
 
   static bool IsJsOpcode(Value val) {
     switch (val) {
index 16fa114..696434d 100644 (file)
         '../../src/compiler/node-properties.h',
         '../../src/compiler/node.cc',
         '../../src/compiler/node.h',
+        '../../src/compiler/opcodes.cc',
         '../../src/compiler/opcodes.h',
         '../../src/compiler/operator-properties.cc',
         '../../src/compiler/operator-properties.h',