Commit dd6ce126 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Turn IrOpcode::IsXXX() into range checks.

TEST=unittests
R=dcarney@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#26079}
parent 49147163
...@@ -275,57 +275,24 @@ class IrOpcode { ...@@ -275,57 +275,24 @@ class IrOpcode {
// Returns the mnemonic name of an opcode. // Returns the mnemonic name of an opcode.
static char const* Mnemonic(Value value); static char const* Mnemonic(Value value);
static bool IsJsOpcode(Value val) { // Returns true if opcode for common operator.
switch (val) { static bool IsCommonOpcode(Value value) {
// TODO(turbofan): make this a range check. return kDead <= value && value <= kProjection;
#define RETURN_NAME(x) \
case k##x: \
return true;
JS_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
default:
return false;
}
} }
static bool IsControlOpcode(Value val) { // Returns true if opcode for control operator.
switch (val) { static bool IsControlOpcode(Value value) {
// TODO(turbofan): make this a range check. return kDead <= value && value <= kEnd;
#define RETURN_NAME(x) \
case k##x: \
return true;
CONTROL_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
default:
return false;
}
} }
static bool IsLeafOpcode(Value val) { // Returns true if opcode for JavaScript operator.
switch (val) { static bool IsJsOpcode(Value value) {
// TODO(turbofan): make this a table lookup. return kJSEqual <= value && value <= kJSDebugger;
#define RETURN_NAME(x) \
case k##x: \
return true;
LEAF_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
default:
return false;
}
} }
static bool IsCommonOpcode(Value val) { // Returns true if opcode for leaf operator.
switch (val) { static bool IsLeafOpcode(Value value) {
// TODO(turbofan): make this a table lookup or a range check. return kInt32Constant <= value && value <= kHeapConstant;
#define RETURN_NAME(x) \
case k##x: \
return true;
CONTROL_OP_LIST(RETURN_NAME)
COMMON_OP_LIST(RETURN_NAME)
#undef RETURN_NAME
default:
return false;
}
} }
}; };
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <cstring>
#include "src/compiler/opcodes.h" #include "src/compiler/opcodes.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -11,9 +9,108 @@ namespace v8 { ...@@ -11,9 +9,108 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
namespace {
bool IsCommonOpcode(IrOpcode::Value opcode) {
switch (opcode) {
#define OPCODE(Opcode) \
case IrOpcode::k##Opcode: \
return true;
COMMON_OP_LIST(OPCODE)
CONTROL_OP_LIST(OPCODE)
#undef OPCODE
default:
return false;
}
}
bool IsControlOpcode(IrOpcode::Value opcode) {
switch (opcode) {
#define OPCODE(Opcode) \
case IrOpcode::k##Opcode: \
return true;
CONTROL_OP_LIST(OPCODE)
#undef OPCODE
default:
return false;
}
}
bool IsJsOpcode(IrOpcode::Value opcode) {
switch (opcode) {
#define OPCODE(Opcode) \
case IrOpcode::k##Opcode: \
return true;
JS_OP_LIST(OPCODE)
#undef OPCODE
default:
return false;
}
}
bool IsLeafOpcode(IrOpcode::Value opcode) {
switch (opcode) {
#define OPCODE(Opcode) \
case IrOpcode::k##Opcode: \
return true;
LEAF_OP_LIST(OPCODE)
#undef OPCODE
default:
return false;
}
}
const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789);
} // namespace
TEST(IrOpcodeTest, IsCommonOpcode) {
EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode));
#define OPCODE(Opcode) \
EXPECT_EQ(IsCommonOpcode(IrOpcode::k##Opcode), \
IrOpcode::IsCommonOpcode(IrOpcode::k##Opcode));
ALL_OP_LIST(OPCODE)
#undef OPCODE
}
TEST(IrOpcodeTest, IsControlOpcode) {
EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode));
#define OPCODE(Opcode) \
EXPECT_EQ(IsControlOpcode(IrOpcode::k##Opcode), \
IrOpcode::IsControlOpcode(IrOpcode::k##Opcode));
ALL_OP_LIST(OPCODE)
#undef OPCODE
}
TEST(IrOpcodeTest, IsJsOpcode) {
EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode));
#define OPCODE(Opcode) \
EXPECT_EQ(IsJsOpcode(IrOpcode::k##Opcode), \
IrOpcode::IsJsOpcode(IrOpcode::k##Opcode));
ALL_OP_LIST(OPCODE)
#undef OPCODE
}
TEST(IrOpcodeTest, IsLeafOpcode) {
EXPECT_FALSE(IrOpcode::IsLeafOpcode(kInvalidOpcode));
#define OPCODE(Opcode) \
EXPECT_EQ(IsLeafOpcode(IrOpcode::k##Opcode), \
IrOpcode::IsLeafOpcode(IrOpcode::k##Opcode));
ALL_OP_LIST(OPCODE)
#undef OPCODE
}
TEST(IrOpcodeTest, Mnemonic) { TEST(IrOpcodeTest, Mnemonic) {
EXPECT_STREQ("UnknownOpcode", EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode));
IrOpcode::Mnemonic(static_cast<IrOpcode::Value>(123456789)));
#define OPCODE(Opcode) \ #define OPCODE(Opcode) \
EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode)); EXPECT_STREQ(#Opcode, IrOpcode::Mnemonic(IrOpcode::k##Opcode));
ALL_OP_LIST(OPCODE) ALL_OP_LIST(OPCODE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment