| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/code-stubs.h" |
| 6 #include "src/compiler/graph-visualizer.h" |
| 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/linkage.h" |
| 9 #include "src/compiler/node-properties.h" |
| 10 #include "src/compiler/simplified-lowering.h" |
| 11 #include "src/compiler/simplified-operator.h" |
| 12 #include "src/compiler/source-position.h" |
| 13 #include "test/unittests/compiler/compiler-test-utils.h" |
| 14 #include "test/unittests/compiler/graph-unittest.h" |
| 15 #include "test/unittests/compiler/node-test-utils.h" |
| 16 #include "testing/gmock-support.h" |
| 17 |
| 18 using testing::_; |
| 19 using testing::AllOf; |
| 20 using testing::BitEq; |
| 21 using testing::Capture; |
| 22 using testing::CaptureEq; |
| 23 |
| 24 namespace v8 { |
| 25 namespace internal { |
| 26 namespace compiler { |
| 27 |
| 28 class SimplifiedLoweringTest |
| 29 : public TypedGraphTest, |
| 30 public ::testing::WithParamInterface<MachineType> { |
| 31 public: |
| 32 SimplifiedLoweringTest() |
| 33 : simplified_(zone()), |
| 34 machine_(zone(), GetParam()), |
| 35 javascript_(zone()), |
| 36 jsgraph_(isolate(), graph(), common(), &javascript_, &machine_) {} |
| 37 |
| 38 MachineType WordRepresentation() const { return GetParam(); } |
| 39 |
| 40 protected: |
| 41 JSGraph* jsgraph() { return &jsgraph_; } |
| 42 SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
| 43 |
| 44 bool Is32() const { return WordRepresentation() == kRepWord32; } |
| 45 bool Is64() const { return WordRepresentation() == kRepWord64; } |
| 46 |
| 47 void RunLowering() { |
| 48 SourcePositionTable source_positions(graph()); |
| 49 SimplifiedLowering lowering(jsgraph(), zone(), &source_positions); |
| 50 lowering.LowerAllNodes(); |
| 51 if (FLAG_trace_turbo_graph) { |
| 52 OFStream os(stdout); |
| 53 os << AsRPO(*graph()); |
| 54 } |
| 55 } |
| 56 |
| 57 Matcher<Node*> IsAllocateHeapNumber(const Matcher<Node*>& effect_matcher, |
| 58 const Matcher<Node*>& control_matcher) { |
| 59 return IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable( |
| 60 AllocateHeapNumberStub(isolate()).GetCode())), |
| 61 IsNumberConstant(BitEq(0.0)), effect_matcher, |
| 62 control_matcher); |
| 63 } |
| 64 Matcher<Node*> IsChangeInt32ToSmi(const Matcher<Node*>& value_matcher) { |
| 65 return Is64() ? IsWord64Shl(IsChangeInt32ToInt64(value_matcher), |
| 66 IsSmiShiftBitsConstant()) |
| 67 : IsWord32Shl(value_matcher, IsSmiShiftBitsConstant()); |
| 68 } |
| 69 Matcher<Node*> IsChangeSmiToInt32(const Matcher<Node*>& value_matcher) { |
| 70 return Is64() ? IsTruncateInt64ToInt32( |
| 71 IsWord64Sar(value_matcher, IsSmiShiftBitsConstant())) |
| 72 : IsWord32Sar(value_matcher, IsSmiShiftBitsConstant()); |
| 73 } |
| 74 Matcher<Node*> IsChangeUint32ToSmi(const Matcher<Node*>& value_matcher) { |
| 75 return Is64() ? IsWord64Shl(IsChangeUint32ToUint64(value_matcher), |
| 76 IsSmiShiftBitsConstant()) |
| 77 : IsWord32Shl(value_matcher, IsSmiShiftBitsConstant()); |
| 78 } |
| 79 Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher, |
| 80 const Matcher<Node*>& control_matcher) { |
| 81 return IsLoad(kMachFloat64, value_matcher, |
| 82 IsIntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag), |
| 83 graph()->start(), control_matcher); |
| 84 } |
| 85 Matcher<Node*> IsIntPtrConstant(int value) { |
| 86 return Is32() ? IsInt32Constant(value) : IsInt64Constant(value); |
| 87 } |
| 88 Matcher<Node*> IsSmiShiftBitsConstant() { |
| 89 return IsIntPtrConstant(kSmiShiftSize + kSmiTagSize); |
| 90 } |
| 91 Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher, |
| 92 const Matcher<Node*>& rhs_matcher) { |
| 93 return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher) |
| 94 : IsWord64Equal(lhs_matcher, rhs_matcher); |
| 95 } |
| 96 Matcher<Node*> IsWordAnd(const Matcher<Node*>& lhs_matcher, |
| 97 const Matcher<Node*>& rhs_matcher) { |
| 98 return Is32() ? IsWord32And(lhs_matcher, rhs_matcher) |
| 99 : IsWord64And(lhs_matcher, rhs_matcher); |
| 100 } |
| 101 |
| 102 private: |
| 103 SimplifiedOperatorBuilder simplified_; |
| 104 MachineOperatorBuilder machine_; |
| 105 JSOperatorBuilder javascript_; |
| 106 JSGraph jsgraph_; |
| 107 }; |
| 108 |
| 109 |
| 110 TARGET_TEST_P(SimplifiedLoweringTest, CheckMaps1) { |
| 111 Node* start = graph()->start(); |
| 112 Node* receiver = Parameter(Type::Any()); |
| 113 Node* map = Parameter(Type::Any()); |
| 114 Node* frame_state = jsgraph()->EmptyFrameState(); |
| 115 Node* map_check = graph()->NewNode(simplified()->CheckMaps(1), receiver, map, |
| 116 frame_state, start, start); |
| 117 |
| 118 Node* end = graph()->NewNode(common()->End(), map_check); |
| 119 graph()->SetEnd(end); |
| 120 |
| 121 RunLowering(); |
| 122 |
| 123 // Check the deoptimizations merge to end. |
| 124 Capture<Node*> is_smi_branch; |
| 125 Capture<Node*> map_cmp_branch; |
| 126 EXPECT_THAT( |
| 127 graph()->end(), |
| 128 IsEnd(IsMerge( |
| 129 IsIfTrue(CaptureEq(&map_cmp_branch)), |
| 130 IsDeoptimize(frame_state, start, IsIfTrue(CaptureEq(&is_smi_branch))), |
| 131 IsDeoptimize(frame_state, start, |
| 132 IsIfFalse(CaptureEq(&map_cmp_branch)))))); |
| 133 |
| 134 // Check the IsSmi branch. |
| 135 EXPECT_THAT( |
| 136 is_smi_branch.value(), |
| 137 IsBranch(IsWordEqual(IsWordAnd(receiver, IsIntPtrConstant(kSmiTagMask)), |
| 138 IsIntPtrConstant(kSmiTag)), |
| 139 start)); |
| 140 |
| 141 // Check the load and map compare branch. |
| 142 EXPECT_THAT(map_cmp_branch.value(), |
| 143 IsBranch(IsWordEqual(IsLoad(kMachAnyTagged, receiver, |
| 144 IsIntPtrConstant(-1), start, |
| 145 IsIfFalse(is_smi_branch.value())), |
| 146 map), |
| 147 IsIfFalse(is_smi_branch.value()))); |
| 148 } |
| 149 |
| 150 |
| 151 INSTANTIATE_TEST_CASE_P(SimplifiedLoweringTest, SimplifiedLoweringTest, |
| 152 ::testing::Values(kRepWord32, kRepWord64)); |
| 153 |
| 154 } // namespace compiler |
| 155 } // namespace internal |
| 156 } // namespace v8 |
| OLD | NEW |