From 4a8623c637b2847849ecb5a5a76af6809d152e57 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Tue, 23 Dec 2014 11:24:03 -0800 Subject: [PATCH] [turbofan] Turn IrOpcode::Mnemonic() into a table lookup. R=ishell@chromium.org Review URL: https://codereview.chromium.org/818203002 Cr-Commit-Position: refs/heads/master@{#25939} --- BUILD.gn | 1 + src/compiler/opcodes.cc | 34 ++++++++++++++++++++++++++++++++++ src/compiler/opcodes.h | 13 +------------ tools/gyp/v8.gyp | 1 + 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/compiler/opcodes.cc diff --git a/BUILD.gn b/BUILD.gn index 262e09e..6534eea 100644 --- 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 index 0000000..044395c --- /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 + +#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(value, arraysize(kMnemonics) - 1); + return kMnemonics[n]; +} + +} // namespace compiler +} // namespace internal +} // namespace v8 diff --git a/src/compiler/opcodes.h b/src/compiler/opcodes.h index ccdec4d..3f00e6a 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) { diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 16fa114..696434d 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -491,6 +491,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', -- 2.7.4