Reviewers: Igor Sheludko,

Description:
[turbofan] Turn IrOpcode::Mnemonic() into a table lookup.

[email protected]

Please review this at https://codereview.chromium.org/818203002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+37, -12 lines):
  M BUILD.gn
  M src/compiler/opcodes.h
  A src/compiler/opcodes.cc
  M tools/gyp/v8.gyp


Index: BUILD.gn
diff --git a/BUILD.gn b/BUILD.gn
index 28695ddb4ac000b840b57d01e563721fe7d85615..05eb9ba421e9e899a133a8d81bdd7301748f8ef3 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -563,6 +563,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",
Index: src/compiler/opcodes.cc
diff --git a/src/compiler/opcodes.cc b/src/compiler/opcodes.cc
new file mode 100644
index 0000000000000000000000000000000000000000..044395c785960959484cbfb54e5dcf64620713c7
--- /dev/null
+++ b/src/compiler/opcodes.cc
@@ -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: src/compiler/opcodes.h
diff --git a/src/compiler/opcodes.h b/src/compiler/opcodes.h
index ccdec4d215f1ba75c825a752ce82ccdc7edd1289..3f00e6a178668a4d623e6c5855dc4a370b26d3aa 100644
--- a/src/compiler/opcodes.h
+++ b/src/compiler/opcodes.h
@@ -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: tools/gyp/v8.gyp
diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp
index 8901681c8f1b182a92995df537ec606e8734c9de..25e053fc69844a0da8590a64a8728d2d4402df5e 100644
--- a/tools/gyp/v8.gyp
+++ b/tools/gyp/v8.gyp
@@ -490,6 +490,7 @@
         '../../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',


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