Revision: 23289
Author: [email protected]
Date: Fri Aug 22 04:47:55 2014 UTC
Log: [turbofan] Initial import of SimplifiedOperatorReducer.
TEST=compiler-unittests
[email protected]
Review URL: https://codereview.chromium.org/479793004
https://code.google.com/p/v8/source/detail?r=23289
Added:
/branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc
/branches/bleeding_edge/src/compiler/simplified-operator-reducer.h
/branches/bleeding_edge/test/compiler-unittests/simplified-operator-reducer-unittest.cc
Modified:
/branches/bleeding_edge/BUILD.gn
/branches/bleeding_edge/src/compiler/graph-reducer.h
/branches/bleeding_edge/src/compiler/node-matchers.h
/branches/bleeding_edge/src/unique.h
/branches/bleeding_edge/test/compiler-unittests/change-lowering-unittest.cc
/branches/bleeding_edge/test/compiler-unittests/compiler-unittests.gyp
/branches/bleeding_edge/test/compiler-unittests/graph-unittest.cc
/branches/bleeding_edge/test/compiler-unittests/graph-unittest.h
/branches/bleeding_edge/test/compiler-unittests/machine-operator-reducer-unittest.cc
/branches/bleeding_edge/tools/gyp/v8.gyp
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc Fri
Aug 22 04:47:55 2014 UTC
@@ -0,0 +1,135 @@
+// 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/js-graph.h"
+#include "src/compiler/node-matchers.h"
+#include "src/compiler/simplified-operator-reducer.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {}
+
+
+Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
+ switch (node->opcode()) {
+ case IrOpcode::kBooleanNot: {
+ HeapObjectMatcher m(node->InputAt(0));
+ if (m.IsKnownGlobal(heap()->false_value())) {
+ return Replace(jsgraph()->TrueConstant());
+ }
+ if (m.IsKnownGlobal(heap()->true_value())) {
+ return Replace(jsgraph()->FalseConstant());
+ }
+ if (m.IsBooleanNot()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeBitToBool: {
+ Int32Matcher m(node->InputAt(0));
+ if (m.Is(0)) return Replace(jsgraph()->FalseConstant());
+ if (m.Is(1)) return Replace(jsgraph()->TrueConstant());
+ if (m.IsChangeBoolToBit()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeBoolToBit: {
+ HeapObjectMatcher m(node->InputAt(0));
+ if (m.IsKnownGlobal(heap()->false_value())) return ReplaceInt32(0);
+ if (m.IsKnownGlobal(heap()->true_value())) return ReplaceInt32(1);
+ if (m.IsChangeBitToBool()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeFloat64ToTagged: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(m.Value());
+ break;
+ }
+ case IrOpcode::kChangeInt32ToTagged: {
+ Int32Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(m.Value());
+ break;
+ }
+ case IrOpcode::kChangeTaggedToFloat64: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceFloat64(m.Value());
+ if (m.IsChangeFloat64ToTagged()) return
Replace(m.node()->InputAt(0));
+ if (m.IsChangeInt32ToTagged()) {
+ return Change(node, machine()->ChangeInt32ToFloat64(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeUint32ToTagged()) {
+ return Change(node, machine()->ChangeUint32ToFloat64(),
+ m.node()->InputAt(0));
+ }
+ break;
+ }
+ case IrOpcode::kChangeTaggedToInt32: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
+ if (m.IsChangeFloat64ToTagged()) {
+ return Change(node, machine()->TruncateFloat64ToInt32(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeInt32ToTagged()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeTaggedToUint32: {
+ Float64Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceUint32(DoubleToUint32(m.Value()));
+ if (m.IsChangeFloat64ToTagged()) {
+ return Change(node, machine()->TruncateFloat64ToInt32(),
+ m.node()->InputAt(0));
+ }
+ if (m.IsChangeUint32ToTagged()) return Replace(m.node()->InputAt(0));
+ break;
+ }
+ case IrOpcode::kChangeUint32ToTagged: {
+ Uint32Matcher m(node->InputAt(0));
+ if (m.HasValue()) return ReplaceNumber(FastUI2D(m.Value()));
+ break;
+ }
+ default:
+ break;
+ }
+ return NoChange();
+}
+
+
+Reduction SimplifiedOperatorReducer::Change(Node* node, Operator* op,
Node* a) {
+ graph()->ChangeOperator(node, op);
+ node->ReplaceInput(0, a);
+ return Changed(node);
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceFloat64(double value) {
+ return Replace(jsgraph()->Float64Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceInt32(int32_t value) {
+ return Replace(jsgraph()->Int32Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceNumber(double value) {
+ return Replace(jsgraph()->Constant(value));
+}
+
+
+Reduction SimplifiedOperatorReducer::ReplaceNumber(int32_t value) {
+ return Replace(jsgraph()->Constant(value));
+}
+
+
+Graph* SimplifiedOperatorReducer::graph() const { return
jsgraph()->graph(); }
+
+
+Heap* SimplifiedOperatorReducer::heap() const {
+ return jsgraph()->isolate()->heap();
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/compiler/simplified-operator-reducer.h Fri
Aug 22 04:47:55 2014 UTC
@@ -0,0 +1,55 @@
+// 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.
+
+#ifndef V8_COMPILER_SIMPLIFIED_OPERATOR_REDUCER_H_
+#define V8_COMPILER_SIMPLIFIED_OPERATOR_REDUCER_H_
+
+#include "src/compiler/graph-reducer.h"
+
+namespace v8 {
+namespace internal {
+
+// Forward declarations.
+class Heap;
+
+namespace compiler {
+
+// Forward declarations.
+class JSGraph;
+class MachineOperatorBuilder;
+
+class SimplifiedOperatorReducer V8_FINAL : public Reducer {
+ public:
+ SimplifiedOperatorReducer(JSGraph* jsgraph, MachineOperatorBuilder*
machine)
+ : jsgraph_(jsgraph), machine_(machine) {}
+ virtual ~SimplifiedOperatorReducer();
+
+ virtual Reduction Reduce(Node* node) V8_OVERRIDE;
+
+ private:
+ Reduction Change(Node* node, Operator* op, Node* a);
+ Reduction ReplaceFloat64(double value);
+ Reduction ReplaceInt32(int32_t value);
+ Reduction ReplaceUint32(uint32_t value) {
+ return ReplaceInt32(static_cast<int32_t>(value));
+ }
+ Reduction ReplaceNumber(double value);
+ Reduction ReplaceNumber(int32_t value);
+
+ Graph* graph() const;
+ Heap* heap() const;
+ JSGraph* jsgraph() const { return jsgraph_; }
+ MachineOperatorBuilder* machine() const { return machine_; }
+
+ JSGraph* jsgraph_;
+ MachineOperatorBuilder* machine_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimplifiedOperatorReducer);
+};
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
+
+#endif // V8_COMPILER_SIMPLIFIED_OPERATOR_REDUCER_H_
=======================================
--- /dev/null
+++
/branches/bleeding_edge/test/compiler-unittests/simplified-operator-reducer-unittest.cc
Fri Aug 22 04:47:55 2014 UTC
@@ -0,0 +1,481 @@
+// 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/js-graph.h"
+#include "src/compiler/simplified-operator.h"
+#include "src/compiler/simplified-operator-reducer.h"
+#include "src/compiler/typer.h"
+#include "src/conversions.h"
+#include "test/compiler-unittests/graph-unittest.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+class SimplifiedOperatorReducerTest : public GraphTest {
+ public:
+ explicit SimplifiedOperatorReducerTest(int num_parameters = 1)
+ : GraphTest(num_parameters), simplified_(zone()) {}
+ virtual ~SimplifiedOperatorReducerTest() {}
+
+ protected:
+ Reduction Reduce(Node* node) {
+ Typer typer(zone());
+ MachineOperatorBuilder machine(zone());
+ JSGraph jsgraph(graph(), common(), &typer);
+ SimplifiedOperatorReducer reducer(&jsgraph, &machine);
+ return reducer.Reduce(node);
+ }
+
+ SimplifiedOperatorBuilder* simplified() { return &simplified_; }
+
+ private:
+ SimplifiedOperatorBuilder simplified_;
+};
+
+
+template <typename T>
+class SimplifiedOperatorReducerTestWithParam
+ : public SimplifiedOperatorReducerTest,
+ public ::testing::WithParamInterface<T> {
+ public:
+ explicit SimplifiedOperatorReducerTestWithParam(int num_parameters = 1)
+ : SimplifiedOperatorReducerTest(num_parameters) {}
+ virtual ~SimplifiedOperatorReducerTestWithParam() {}
+};
+
+
+namespace {
+
+static const double kFloat64Values[] = {
+ -V8_INFINITY, -6.52696e+290, -1.05768e+290, -5.34203e+268,
-1.01997e+268,
+ -8.22758e+266, -1.58402e+261, -5.15246e+241, -5.92107e+226,
-1.21477e+226,
+ -1.67913e+188, -1.6257e+184, -2.60043e+170, -2.52941e+168,
-3.06033e+116,
+ -4.56201e+52, -3.56788e+50, -9.9066e+38, -3.07261e+31,
-2.1271e+09,
+ -1.91489e+09, -1.73053e+09, -9.30675e+08, -26030, -20453,
+ -15790, -11699, -111, -97, -78,
+ -63, -58, -1.53858e-06, -2.98914e-12,
-1.14741e-39,
+ -8.20347e-57, -1.48932e-59, -3.17692e-66, -8.93103e-81,
-3.91337e-83,
+ -6.0489e-92, -8.83291e-113, -4.28266e-117, -1.92058e-178,
-2.0567e-192,
+ -1.68167e-194, -1.51841e-214, -3.98738e-234, -7.31851e-242,
-2.21875e-253,
+ -1.11612e-293, -0.0, 0.0, 2.22507e-308,
1.06526e-307,
+ 4.16643e-227, 6.76624e-223, 2.0432e-197, 3.16254e-184,
1.37315e-173,
+ 2.88603e-172, 1.54155e-99, 4.42923e-81, 1.40539e-73, 5.4462e-73,
+ 1.24064e-58, 3.11167e-58, 2.75826e-39, 0.143815, 58,
+ 67, 601, 7941, 11644, 13697,
+ 25680, 29882, 1.32165e+08, 1.62439e+08,
4.16837e+08,
+ 9.59097e+08, 1.32491e+09, 1.8728e+09, 1.0672e+17,
2.69606e+46,
+ 1.98285e+79, 1.0098e+82, 7.93064e+88, 3.67444e+121,
9.36506e+123,
+ 7.27954e+162, 3.05316e+168, 1.16171e+175, 1.64771e+189,
1.1622e+202,
+ 2.00748e+239, 2.51778e+244, 3.90282e+306, 1.79769e+308,
V8_INFINITY};
+
+
+static const int32_t kInt32Values[] = {
+ -2147483647 - 1, -2104508227, -2103151830, -1435284490, -1378926425,
+ -1318814539, -1289388009, -1287537572, -1279026536, -1241605942,
+ -1226046939, -941837148, -779818051, -413830641, -245798087,
+ -184657557, -127145950, -105483328, -32325, -26653,
+ -23858, -23834, -22363, -19858, -19044,
+ -18744, -15528, -5309, -3372, -2093,
+ -104, -98, -97, -93, -84,
+ -80, -78, -76, -72, -58,
+ -57, -56, -55, -45, -40,
+ -34, -32, -25, -24, -5,
+ -2, 0, 3, 10, 24,
+ 34, 42, 46, 47, 48,
+ 52, 56, 64, 65, 71,
+ 76, 79, 81, 82, 97,
+ 102, 103, 104, 106, 107,
+ 109, 116, 122, 3653, 4485,
+ 12405, 16504, 26262, 28704, 29755,
+ 30554, 16476817, 605431957, 832401070, 873617242,
+ 914205764, 1062628108, 1087581664, 1488498068, 1534668023,
+ 1661587028, 1696896187, 1866841746, 2032089723, 2147483647};
+
+
+static const uint32_t kUint32Values[] = {
+ 0x0, 0x5, 0x8, 0xc, 0xd, 0x26,
+ 0x28, 0x29, 0x30, 0x34, 0x3e, 0x42,
+ 0x50, 0x5b, 0x63, 0x71, 0x77, 0x7c,
+ 0x83, 0x88, 0x96, 0x9c, 0xa3, 0xfa,
+ 0x7a7, 0x165d, 0x234d, 0x3acb, 0x43a5, 0x4573,
+ 0x5b4f, 0x5f14, 0x6996, 0x6c6e, 0x7289, 0x7b9a,
+ 0x7bc9, 0x86bb, 0xa839, 0xaa41, 0xb03b, 0xc942,
+ 0xce68, 0xcf4c, 0xd3ad, 0xdea3, 0xe90c, 0xed86,
+ 0xfba5, 0x172dcc6, 0x114d8fc1, 0x182d6c9d, 0x1b1e3fad, 0x1db033bf,
+ 0x1e1de755, 0x1f625c80, 0x28f6cf00, 0x2acb6a94, 0x2c20240e, 0x2f0fe54e,
+ 0x31863a7c, 0x33325474, 0x3532fae3, 0x3bab82ea, 0x4c4b83a2, 0x4cd93d1e,
+ 0x4f7331d4, 0x5491b09b, 0x57cc6ff9, 0x60d3b4dc, 0x653f5904, 0x690ae256,
+ 0x69fe3276, 0x6bebf0ba, 0x6e2c69a3, 0x73b84ff7, 0x7b3a1924, 0x7ed032d9,
+ 0x84dd734b, 0x8552ea53, 0x8680754f, 0x8e9660eb, 0x94fe2b9c, 0x972d30cf,
+ 0x9b98c482, 0xb158667e, 0xb432932c, 0xb5b70989, 0xb669971a, 0xb7c359d1,
+ 0xbeb15c0d, 0xc171c53d, 0xc743dd38, 0xc8e2af50, 0xc98e2df0, 0xd9d1cdf9,
+ 0xdcc91049, 0xe46f396d, 0xee991950, 0xef64e521, 0xf7aeefc9,
0xffffffff};
+
+
+MATCHER(IsNaN, std::string(negation ? "isn't" : "is") + " NaN") {
+ return std::isnan(arg);
+}
+
+} // namespace
+
+
+//
-----------------------------------------------------------------------------
+// Unary operators
+
+
+namespace {
+
+struct UnaryOperator {
+ Operator* (SimplifiedOperatorBuilder::*constructor)() const;
+ const char* constructor_name;
+};
+
+
+std::ostream& operator<<(std::ostream& os, const UnaryOperator& unop) {
+ return os << unop.constructor_name;
+}
+
+
+static const UnaryOperator kUnaryOperators[] = {
+ {&SimplifiedOperatorBuilder::BooleanNot, "BooleanNot"},
+ {&SimplifiedOperatorBuilder::ChangeBitToBool, "ChangeBitToBool"},
+ {&SimplifiedOperatorBuilder::ChangeBoolToBit, "ChangeBoolToBit"},
+ {&SimplifiedOperatorBuilder::ChangeFloat64ToTagged,
+ "ChangeFloat64ToTagged"},
+
{&SimplifiedOperatorBuilder::ChangeInt32ToTagged, "ChangeInt32ToTagged"},
+ {&SimplifiedOperatorBuilder::ChangeTaggedToFloat64,
+ "ChangeTaggedToFloat64"},
+
{&SimplifiedOperatorBuilder::ChangeTaggedToInt32, "ChangeTaggedToInt32"},
+
{&SimplifiedOperatorBuilder::ChangeTaggedToUint32, "ChangeTaggedToUint32"},
+
{&SimplifiedOperatorBuilder::ChangeUint32ToTagged, "ChangeUint32ToTagged"}};
+
+} // namespace
+
+
+typedef SimplifiedOperatorReducerTestWithParam<UnaryOperator>
+ SimplifiedUnaryOperatorTest;
+
+
+TEST_P(SimplifiedUnaryOperatorTest, Parameter) {
+ const UnaryOperator& unop = GetParam();
+ Reduction reduction = Reduce(
+ graph()->NewNode((simplified()->*unop.constructor)(), Parameter(0)));
+ EXPECT_FALSE(reduction.Changed());
+}
+
+
+INSTANTIATE_TEST_CASE_P(SimplifiedOperatorTest,
SimplifiedUnaryOperatorTest,
+ ::testing::ValuesIn(kUnaryOperators));
+
+
+//
-----------------------------------------------------------------------------
+// BooleanNot
+
+
+TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithBooleanNot) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(
+ graph()->NewNode(simplified()->BooleanNot(),
+ graph()->NewNode(simplified()->BooleanNot(),
param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithFalseConstant) {
+ Reduction reduction0 =
+ Reduce(graph()->NewNode(simplified()->BooleanNot(),
FalseConstant()));
+ ASSERT_TRUE(reduction0.Changed());
+ EXPECT_THAT(reduction0.replacement(), IsTrueConstant());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, BooleanNotWithTrueConstant) {
+ Reduction reduction1 =
+ Reduce(graph()->NewNode(simplified()->BooleanNot(), TrueConstant()));
+ ASSERT_TRUE(reduction1.Changed());
+ EXPECT_THAT(reduction1.replacement(), IsFalseConstant());
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeBoolToBit
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithChangeBoolToBit) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeBitToBool(),
+ graph()->NewNode(simplified()->ChangeBoolToBit(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithZeroConstant) {
+ Reduction reduction = Reduce(
+ graph()->NewNode(simplified()->ChangeBitToBool(), Int32Constant(0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsFalseConstant());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBitToBoolWithOneConstant) {
+ Reduction reduction = Reduce(
+ graph()->NewNode(simplified()->ChangeBitToBool(), Int32Constant(1)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsTrueConstant());
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeBoolToBit
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithFalseConstant) {
+ Reduction reduction = Reduce(
+ graph()->NewNode(simplified()->ChangeBoolToBit(), FalseConstant()));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithTrueConstant) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeBoolToBit(),
TrueConstant()));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(1));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeBoolToBitWithChangeBitToBool) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeBoolToBit(),
+ graph()->NewNode(simplified()->ChangeBitToBool(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeFloat64ToTagged
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeFloat64ToTaggedWithConstant) {
+ TRACED_FOREACH(double, n, kFloat64Values) {
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeFloat64ToTagged(), Float64Constant(n)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsNumberConstant(n));
+ }
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeInt32ToTagged
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeInt32ToTaggedWithConstant) {
+ TRACED_FOREACH(int32_t, n, kInt32Values) {
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeInt32ToTagged(), Int32Constant(n)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastI2D(n)));
+ }
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeTaggedToFloat64
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToFloat64WithChangeFloat64ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToFloat64(),
+ graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToFloat64WithChangeInt32ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToFloat64(),
+ graph()->NewNode(simplified()->ChangeInt32ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsChangeInt32ToFloat64(param0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToFloat64WithChangeUint32ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToFloat64(),
+ graph()->NewNode(simplified()->ChangeUint32ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsChangeUint32ToFloat64(param0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithConstant) {
+ TRACED_FOREACH(double, n, kFloat64Values) {
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToFloat64(), NumberConstant(n)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsFloat64Constant(n));
+ }
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
ChangeTaggedToFloat64WithNaNConstant1) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
+ NumberConstant(-base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
ChangeTaggedToFloat64WithNaNConstant2) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
+ NumberConstant(base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeTaggedToInt32
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToInt32WithChangeFloat64ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToInt32(),
+ graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsTruncateFloat64ToInt32(param0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToInt32WithChangeInt32ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToInt32(),
+ graph()->NewNode(simplified()->ChangeInt32ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithConstant) {
+ TRACED_FOREACH(double, n, kFloat64Values) {
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToInt32(), NumberConstant(n)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(),
IsInt32Constant(DoubleToInt32(n)));
+ }
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithNaNConstant1)
{
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(),
+ NumberConstant(-base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToInt32WithNaNConstant2)
{
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(),
+ NumberConstant(base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeTaggedToUint32
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToUint32WithChangeFloat64ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToUint32(),
+ graph()->NewNode(simplified()->ChangeFloat64ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsTruncateFloat64ToInt32(param0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
+ ChangeTaggedToUint32WithChangeUint32ToTagged) {
+ Node* param0 = Parameter(0);
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToUint32(),
+ graph()->NewNode(simplified()->ChangeUint32ToTagged(), param0)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_EQ(param0, reduction.replacement());
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToUint32WithConstant) {
+ TRACED_FOREACH(double, n, kFloat64Values) {
+ Reduction reduction = Reduce(graph()->NewNode(
+ simplified()->ChangeTaggedToUint32(), NumberConstant(n)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(),
+ IsInt32Constant(BitCast<int32_t>(DoubleToUint32(n))));
+ }
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
ChangeTaggedToUint32WithNaNConstant1) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(),
+ NumberConstant(-base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
+}
+
+
+TEST_F(SimplifiedOperatorReducerTest,
ChangeTaggedToUint32WithNaNConstant2) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(),
+ NumberConstant(base::OS::nan_value())));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsInt32Constant(0));
+}
+
+
+//
-----------------------------------------------------------------------------
+// ChangeUint32ToTagged
+
+
+TEST_F(SimplifiedOperatorReducerTest, ChangeUint32ToTagged) {
+ TRACED_FOREACH(uint32_t, n, kUint32Values) {
+ Reduction reduction =
+ Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(),
+ Int32Constant(BitCast<int32_t>(n))));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastUI2D(n)));
+ }
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
=======================================
--- /branches/bleeding_edge/BUILD.gn Thu Aug 21 12:39:33 2014 UTC
+++ /branches/bleeding_edge/BUILD.gn Fri Aug 22 04:47:55 2014 UTC
@@ -542,6 +542,8 @@
"src/compiler/simplified-lowering.cc",
"src/compiler/simplified-lowering.h",
"src/compiler/simplified-node-factory.h",
+ "src/compiler/simplified-operator-reducer.cc",
+ "src/compiler/simplified-operator-reducer.h",
"src/compiler/simplified-operator.h",
"src/compiler/source-position.cc",
"src/compiler/source-position.h",
=======================================
--- /branches/bleeding_edge/src/compiler/graph-reducer.h Wed Jul 30
13:54:45 2014 UTC
+++ /branches/bleeding_edge/src/compiler/graph-reducer.h Fri Aug 22
04:47:55 2014 UTC
@@ -38,6 +38,7 @@
// phase.
class Reducer {
public:
+ Reducer() {}
virtual ~Reducer() {}
// Try to reduce a node if possible.
@@ -47,6 +48,9 @@
static Reduction NoChange() { return Reduction(); }
static Reduction Replace(Node* node) { return Reduction(node); }
static Reduction Changed(Node* node) { return Reduction(node); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Reducer);
};
@@ -69,9 +73,12 @@
Graph* graph_;
Reducers reducers_;
+
+ DISALLOW_COPY_AND_ASSIGN(GraphReducer);
};
-}
-}
-} // namespace v8::internal::compiler
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
#endif // V8_COMPILER_GRAPH_REDUCER_H_
=======================================
--- /branches/bleeding_edge/src/compiler/node-matchers.h Mon Aug 4
11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/compiler/node-matchers.h Fri Aug 22
04:47:55 2014 UTC
@@ -6,6 +6,7 @@
#define V8_COMPILER_NODE_MATCHERS_H_
#include "src/compiler/common-operator.h"
+#include "src/compiler/node.h"
namespace v8 {
namespace internal {
@@ -92,6 +93,18 @@
typedef FloatMatcher<double> Float64Matcher;
+// A pattern matcher for heap object constants.
+struct HeapObjectMatcher V8_FINAL
+ : public ValueMatcher<PrintableUnique<HeapObject> > {
+ explicit HeapObjectMatcher(Node* node)
+ : ValueMatcher<PrintableUnique<HeapObject> >(node) {}
+
+ bool IsKnownGlobal(HeapObject* global) const {
+ return HasValue() && Value().IsKnownGlobal(global);
+ }
+};
+
+
// For shorter pattern matching code, this struct matches both the left and
// right hand sides of a binary operation and can put constants on the
right
// if they appear on the left hand side of a commutative operation.
=======================================
--- /branches/bleeding_edge/src/unique.h Tue Aug 12 08:24:20 2014 UTC
+++ /branches/bleeding_edge/src/unique.h Fri Aug 22 04:47:55 2014 UTC
@@ -137,6 +137,9 @@
template <class T>
class PrintableUnique : public Unique<T> {
public:
+ // TODO(titzer): make private and introduce a uniqueness scope.
+ PrintableUnique() : string_("null") {}
+
// TODO(titzer): make private and introduce a uniqueness scope.
explicit PrintableUnique(Zone* zone, Handle<T> handle) :
Unique<T>(handle) {
InitializeString(zone);
=======================================
---
/branches/bleeding_edge/test/compiler-unittests/change-lowering-unittest.cc
Wed Aug 20 08:13:00 2014 UTC
+++
/branches/bleeding_edge/test/compiler-unittests/change-lowering-unittest.cc
Fri Aug 22 04:47:55 2014 UTC
@@ -105,14 +105,6 @@
IsInt32Constant(0), IsNumberConstant(0.0), effect_matcher,
control_matcher);
}
- Matcher<Node*> IsFalse() {
- return IsHeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
- zone(), factory()->false_value()));
- }
- Matcher<Node*> IsTrue() {
- return IsHeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
- zone(), factory()->true_value()));
- }
Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher) {
return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher)
@@ -149,7 +141,7 @@
Node* phi = reduction.replacement();
Capture<Node*> branch;
EXPECT_THAT(phi,
- IsPhi(IsTrue(), IsFalse(),
+ IsPhi(IsTrueConstant(), IsFalseConstant(),
IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
IsBranch(val,
graph()->start()))),
IsIfFalse(CaptureEq(&branch)))));
@@ -162,7 +154,7 @@
Reduction reduction = Reduce(node);
ASSERT_TRUE(reduction.Changed());
- EXPECT_THAT(reduction.replacement(), IsWordEqual(val, IsTrue()));
+ EXPECT_THAT(reduction.replacement(), IsWordEqual(val, IsTrueConstant()));
}
=======================================
--- /branches/bleeding_edge/test/compiler-unittests/compiler-unittests.gyp
Tue Aug 19 08:48:41 2014 UTC
+++ /branches/bleeding_edge/test/compiler-unittests/compiler-unittests.gyp
Fri Aug 22 04:47:55 2014 UTC
@@ -29,6 +29,7 @@
'instruction-selector-unittest.cc',
'machine-operator-reducer-unittest.cc',
'machine-operator-unittest.cc',
+ 'simplified-operator-reducer-unittest.cc',
],
'conditions': [
['v8_target_arch=="arm"', {
=======================================
--- /branches/bleeding_edge/test/compiler-unittests/graph-unittest.cc Wed
Aug 20 04:01:36 2014 UTC
+++ /branches/bleeding_edge/test/compiler-unittests/graph-unittest.cc Fri
Aug 22 04:47:55 2014 UTC
@@ -40,6 +40,54 @@
GraphTest::~GraphTest() {}
+Node* GraphTest::Parameter(int32_t index) {
+ return graph()->NewNode(common()->Parameter(index), graph()->start());
+}
+
+
+Node* GraphTest::Float64Constant(double value) {
+ return graph()->NewNode(common()->Float64Constant(value));
+}
+
+
+Node* GraphTest::Int32Constant(int32_t value) {
+ return graph()->NewNode(common()->Int32Constant(value));
+}
+
+
+Node* GraphTest::NumberConstant(double value) {
+ return graph()->NewNode(common()->NumberConstant(value));
+}
+
+
+Node* GraphTest::HeapConstant(const PrintableUnique<HeapObject>& value) {
+ return graph()->NewNode(common()->HeapConstant(value));
+}
+
+
+Node* GraphTest::FalseConstant() {
+ return HeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
+ zone(), factory()->false_value()));
+}
+
+
+Node* GraphTest::TrueConstant() {
+ return HeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
+ zone(), factory()->true_value()));
+}
+
+
+Matcher<Node*> GraphTest::IsFalseConstant() {
+ return IsHeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
+ zone(), factory()->false_value()));
+}
+
+
+Matcher<Node*> GraphTest::IsTrueConstant() {
+ return IsHeapConstant(PrintableUnique<HeapObject>::CreateImmovable(
+ zone(), factory()->true_value()));
+}
+
namespace {
template <typename T>
@@ -597,6 +645,12 @@
return MakeMatcher(
new IsConstantMatcher<int32_t>(IrOpcode::kInt32Constant,
value_matcher));
}
+
+
+Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher) {
+ return MakeMatcher(
+ new IsConstantMatcher<double>(IrOpcode::kFloat64Constant,
value_matcher));
+}
Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher) {
=======================================
--- /branches/bleeding_edge/test/compiler-unittests/graph-unittest.h Wed
Aug 20 04:01:36 2014 UTC
+++ /branches/bleeding_edge/test/compiler-unittests/graph-unittest.h Fri
Aug 22 04:47:55 2014 UTC
@@ -20,12 +20,26 @@
namespace compiler {
+using ::testing::Matcher;
+
+
class GraphTest : public CommonOperatorTest {
public:
explicit GraphTest(int parameters = 1);
virtual ~GraphTest();
protected:
+ Node* Parameter(int32_t index);
+ Node* Float64Constant(double value);
+ Node* Int32Constant(int32_t value);
+ Node* NumberConstant(double value);
+ Node* HeapConstant(const PrintableUnique<HeapObject>& value);
+ Node* FalseConstant();
+ Node* TrueConstant();
+
+ Matcher<Node*> IsFalseConstant();
+ Matcher<Node*> IsTrueConstant();
+
Graph* graph() { return &graph_; }
private:
@@ -33,9 +47,6 @@
};
-using ::testing::Matcher;
-
-
Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& control_matcher);
Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
@@ -50,6 +61,7 @@
const Matcher<ExternalReference>& value_matcher);
Matcher<Node*> IsHeapConstant(
const Matcher<PrintableUnique<HeapObject> >& value_matcher);
+Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher);
Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher);
Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher);
Matcher<Node*> IsPhi(const Matcher<Node*>& value0_matcher,
=======================================
---
/branches/bleeding_edge/test/compiler-unittests/machine-operator-reducer-unittest.cc
Mon Aug 18 06:54:07 2014 UTC
+++
/branches/bleeding_edge/test/compiler-unittests/machine-operator-reducer-unittest.cc
Fri Aug 22 04:47:55 2014 UTC
@@ -17,13 +17,6 @@
virtual ~MachineOperatorReducerTest() {}
protected:
- Node* Parameter(int32_t index) {
- return graph()->NewNode(common()->Parameter(index), graph()->start());
- }
- Node* Int32Constant(int32_t value) {
- return graph()->NewNode(common()->Int32Constant(value));
- }
-
Reduction Reduce(Node* node) {
MachineOperatorReducer reducer(graph());
return reducer.Reduce(node);
=======================================
--- /branches/bleeding_edge/tools/gyp/v8.gyp Thu Aug 21 12:39:33 2014 UTC
+++ /branches/bleeding_edge/tools/gyp/v8.gyp Fri Aug 22 04:47:55 2014 UTC
@@ -426,6 +426,8 @@
'../../src/compiler/simplified-lowering.cc',
'../../src/compiler/simplified-lowering.h',
'../../src/compiler/simplified-node-factory.h',
+ '../../src/compiler/simplified-operator-reducer.cc',
+ '../../src/compiler/simplified-operator-reducer.h',
'../../src/compiler/simplified-operator.h',
'../../src/compiler/source-position.cc',
'../../src/compiler/source-position.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.