| Index: test/unittests/compiler/simplified-lowering-unittest.cc
|
| diff --git a/test/unittests/compiler/simplified-lowering-unittest.cc b/test/unittests/compiler/simplified-lowering-unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5a0d2d28312834c8348ca87b0b1a5167f1a9822a
|
| --- /dev/null
|
| +++ b/test/unittests/compiler/simplified-lowering-unittest.cc
|
| @@ -0,0 +1,156 @@
|
| +// 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/code-stubs.h"
|
| +#include "src/compiler/graph-visualizer.h"
|
| +#include "src/compiler/js-graph.h"
|
| +#include "src/compiler/linkage.h"
|
| +#include "src/compiler/node-properties.h"
|
| +#include "src/compiler/simplified-lowering.h"
|
| +#include "src/compiler/simplified-operator.h"
|
| +#include "src/compiler/source-position.h"
|
| +#include "test/unittests/compiler/compiler-test-utils.h"
|
| +#include "test/unittests/compiler/graph-unittest.h"
|
| +#include "test/unittests/compiler/node-test-utils.h"
|
| +#include "testing/gmock-support.h"
|
| +
|
| +using testing::_;
|
| +using testing::AllOf;
|
| +using testing::BitEq;
|
| +using testing::Capture;
|
| +using testing::CaptureEq;
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +namespace compiler {
|
| +
|
| +class SimplifiedLoweringTest
|
| + : public TypedGraphTest,
|
| + public ::testing::WithParamInterface<MachineType> {
|
| + public:
|
| + SimplifiedLoweringTest()
|
| + : simplified_(zone()),
|
| + machine_(zone(), GetParam()),
|
| + javascript_(zone()),
|
| + jsgraph_(isolate(), graph(), common(), &javascript_, &machine_) {}
|
| +
|
| + MachineType WordRepresentation() const { return GetParam(); }
|
| +
|
| + protected:
|
| + JSGraph* jsgraph() { return &jsgraph_; }
|
| + SimplifiedOperatorBuilder* simplified() { return &simplified_; }
|
| +
|
| + bool Is32() const { return WordRepresentation() == kRepWord32; }
|
| + bool Is64() const { return WordRepresentation() == kRepWord64; }
|
| +
|
| + void RunLowering() {
|
| + SourcePositionTable source_positions(graph());
|
| + SimplifiedLowering lowering(jsgraph(), zone(), &source_positions);
|
| + lowering.LowerAllNodes();
|
| + if (FLAG_trace_turbo_graph) {
|
| + OFStream os(stdout);
|
| + os << AsRPO(*graph());
|
| + }
|
| + }
|
| +
|
| + Matcher<Node*> IsAllocateHeapNumber(const Matcher<Node*>& effect_matcher,
|
| + const Matcher<Node*>& control_matcher) {
|
| + return IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable(
|
| + AllocateHeapNumberStub(isolate()).GetCode())),
|
| + IsNumberConstant(BitEq(0.0)), effect_matcher,
|
| + control_matcher);
|
| + }
|
| + Matcher<Node*> IsChangeInt32ToSmi(const Matcher<Node*>& value_matcher) {
|
| + return Is64() ? IsWord64Shl(IsChangeInt32ToInt64(value_matcher),
|
| + IsSmiShiftBitsConstant())
|
| + : IsWord32Shl(value_matcher, IsSmiShiftBitsConstant());
|
| + }
|
| + Matcher<Node*> IsChangeSmiToInt32(const Matcher<Node*>& value_matcher) {
|
| + return Is64() ? IsTruncateInt64ToInt32(
|
| + IsWord64Sar(value_matcher, IsSmiShiftBitsConstant()))
|
| + : IsWord32Sar(value_matcher, IsSmiShiftBitsConstant());
|
| + }
|
| + Matcher<Node*> IsChangeUint32ToSmi(const Matcher<Node*>& value_matcher) {
|
| + return Is64() ? IsWord64Shl(IsChangeUint32ToUint64(value_matcher),
|
| + IsSmiShiftBitsConstant())
|
| + : IsWord32Shl(value_matcher, IsSmiShiftBitsConstant());
|
| + }
|
| + Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher,
|
| + const Matcher<Node*>& control_matcher) {
|
| + return IsLoad(kMachFloat64, value_matcher,
|
| + IsIntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag),
|
| + graph()->start(), control_matcher);
|
| + }
|
| + Matcher<Node*> IsIntPtrConstant(int value) {
|
| + return Is32() ? IsInt32Constant(value) : IsInt64Constant(value);
|
| + }
|
| + Matcher<Node*> IsSmiShiftBitsConstant() {
|
| + return IsIntPtrConstant(kSmiShiftSize + kSmiTagSize);
|
| + }
|
| + Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher,
|
| + const Matcher<Node*>& rhs_matcher) {
|
| + return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher)
|
| + : IsWord64Equal(lhs_matcher, rhs_matcher);
|
| + }
|
| + Matcher<Node*> IsWordAnd(const Matcher<Node*>& lhs_matcher,
|
| + const Matcher<Node*>& rhs_matcher) {
|
| + return Is32() ? IsWord32And(lhs_matcher, rhs_matcher)
|
| + : IsWord64And(lhs_matcher, rhs_matcher);
|
| + }
|
| +
|
| + private:
|
| + SimplifiedOperatorBuilder simplified_;
|
| + MachineOperatorBuilder machine_;
|
| + JSOperatorBuilder javascript_;
|
| + JSGraph jsgraph_;
|
| +};
|
| +
|
| +
|
| +TARGET_TEST_P(SimplifiedLoweringTest, CheckMaps1) {
|
| + Node* start = graph()->start();
|
| + Node* receiver = Parameter(Type::Any());
|
| + Node* map = Parameter(Type::Any());
|
| + Node* frame_state = jsgraph()->EmptyFrameState();
|
| + Node* map_check = graph()->NewNode(simplified()->CheckMaps(1), receiver, map,
|
| + frame_state, start, start);
|
| +
|
| + Node* end = graph()->NewNode(common()->End(), map_check);
|
| + graph()->SetEnd(end);
|
| +
|
| + RunLowering();
|
| +
|
| + // Check the deoptimizations merge to end.
|
| + Capture<Node*> is_smi_branch;
|
| + Capture<Node*> map_cmp_branch;
|
| + EXPECT_THAT(
|
| + graph()->end(),
|
| + IsEnd(IsMerge(
|
| + IsIfTrue(CaptureEq(&map_cmp_branch)),
|
| + IsDeoptimize(frame_state, start, IsIfTrue(CaptureEq(&is_smi_branch))),
|
| + IsDeoptimize(frame_state, start,
|
| + IsIfFalse(CaptureEq(&map_cmp_branch))))));
|
| +
|
| + // Check the IsSmi branch.
|
| + EXPECT_THAT(
|
| + is_smi_branch.value(),
|
| + IsBranch(IsWordEqual(IsWordAnd(receiver, IsIntPtrConstant(kSmiTagMask)),
|
| + IsIntPtrConstant(kSmiTag)),
|
| + start));
|
| +
|
| + // Check the load and map compare branch.
|
| + EXPECT_THAT(map_cmp_branch.value(),
|
| + IsBranch(IsWordEqual(IsLoad(kMachAnyTagged, receiver,
|
| + IsIntPtrConstant(-1), start,
|
| + IsIfFalse(is_smi_branch.value())),
|
| + map),
|
| + IsIfFalse(is_smi_branch.value())));
|
| +}
|
| +
|
| +
|
| +INSTANTIATE_TEST_CASE_P(SimplifiedLoweringTest, SimplifiedLoweringTest,
|
| + ::testing::Values(kRepWord32, kRepWord64));
|
| +
|
| +} // namespace compiler
|
| +} // namespace internal
|
| +} // namespace v8
|
|
|