OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 #include "src/compiler/common-operator.h" | 6 #include "src/compiler/common-operator.h" |
7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 8 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 Graph graph_; | 59 Graph graph_; |
60 CommonOperatorBuilder common_; | 60 CommonOperatorBuilder common_; |
61 SimplifiedOperatorBuilder simplified_; | 61 SimplifiedOperatorBuilder simplified_; |
62 }; | 62 }; |
63 | 63 |
64 | 64 |
65 typedef ::testing::Types<int32_t, int64_t> ChangeLoweringTypes; | 65 typedef ::testing::Types<int32_t, int64_t> ChangeLoweringTypes; |
66 TYPED_TEST_CASE(ChangeLoweringTest, ChangeLoweringTypes); | 66 TYPED_TEST_CASE(ChangeLoweringTest, ChangeLoweringTypes); |
67 | 67 |
68 | 68 |
69 TYPED_TEST(ChangeLoweringTest, ChangeBitToBool) { | 69 TARGET_TYPED_TEST(ChangeLoweringTest, ChangeBitToBool) { |
70 Node* val = this->Parameter(0); | 70 Node* val = this->Parameter(0); |
71 Node* node = | 71 Node* node = |
72 this->graph()->NewNode(this->simplified()->ChangeBitToBool(), val); | 72 this->graph()->NewNode(this->simplified()->ChangeBitToBool(), val); |
73 Reduction reduction = this->Reduce(node); | 73 Reduction reduction = this->Reduce(node); |
74 ASSERT_TRUE(reduction.Changed()); | 74 ASSERT_TRUE(reduction.Changed()); |
75 | 75 |
76 Node* phi = reduction.replacement(); | 76 Node* phi = reduction.replacement(); |
77 EXPECT_THAT(phi, IsPhi(IsHeapConstant(this->true_unique()), | 77 EXPECT_THAT(phi, IsPhi(IsHeapConstant(this->true_unique()), |
78 IsHeapConstant(this->false_unique()), _)); | 78 IsHeapConstant(this->false_unique()), _)); |
79 | 79 |
80 Node* merge = NodeProperties::GetControlInput(phi); | 80 Node* merge = NodeProperties::GetControlInput(phi); |
81 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); | 81 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); |
82 | 82 |
83 Node* if_true = NodeProperties::GetControlInput(merge, 0); | 83 Node* if_true = NodeProperties::GetControlInput(merge, 0); |
84 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); | 84 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); |
85 | 85 |
86 Node* if_false = NodeProperties::GetControlInput(merge, 1); | 86 Node* if_false = NodeProperties::GetControlInput(merge, 1); |
87 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); | 87 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); |
88 | 88 |
89 Node* branch = NodeProperties::GetControlInput(if_true); | 89 Node* branch = NodeProperties::GetControlInput(if_true); |
90 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); | 90 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); |
91 EXPECT_THAT(branch, IsBranch(val, this->graph()->start())); | 91 EXPECT_THAT(branch, IsBranch(val, this->graph()->start())); |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 TYPED_TEST(ChangeLoweringTest, StringAdd) { | 95 TARGET_TYPED_TEST(ChangeLoweringTest, StringAdd) { |
96 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(), | 96 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(), |
97 this->Parameter(0), this->Parameter(1)); | 97 this->Parameter(0), this->Parameter(1)); |
98 Reduction reduction = this->Reduce(node); | 98 Reduction reduction = this->Reduce(node); |
99 EXPECT_FALSE(reduction.Changed()); | 99 EXPECT_FALSE(reduction.Changed()); |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 class ChangeLowering32Test : public ChangeLoweringTest<int32_t> { | 103 class ChangeLowering32Test : public ChangeLoweringTest<int32_t> { |
104 public: | 104 public: |
105 virtual ~ChangeLowering32Test() {} | 105 virtual ~ChangeLowering32Test() {} |
106 }; | 106 }; |
107 | 107 |
108 | 108 |
109 TEST_F(ChangeLowering32Test, ChangeBoolToBit) { | 109 TARGET_TEST_F(ChangeLowering32Test, ChangeBoolToBit) { |
110 Node* val = Parameter(0); | 110 Node* val = Parameter(0); |
111 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); | 111 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); |
112 Reduction reduction = Reduce(node); | 112 Reduction reduction = Reduce(node); |
113 ASSERT_TRUE(reduction.Changed()); | 113 ASSERT_TRUE(reduction.Changed()); |
114 | 114 |
115 EXPECT_THAT(reduction.replacement(), | 115 EXPECT_THAT(reduction.replacement(), |
116 IsWord32Equal(val, IsHeapConstant(true_unique()))); | 116 IsWord32Equal(val, IsHeapConstant(true_unique()))); |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { | 120 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { |
121 Node* val = Parameter(0); | 121 Node* val = Parameter(0); |
122 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 122 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
123 Reduction reduction = Reduce(node); | 123 Reduction reduction = Reduce(node); |
124 ASSERT_TRUE(reduction.Changed()); | 124 ASSERT_TRUE(reduction.Changed()); |
125 | 125 |
126 Node* phi = reduction.replacement(); | 126 Node* phi = reduction.replacement(); |
127 ASSERT_EQ(IrOpcode::kPhi, phi->opcode()); | 127 ASSERT_EQ(IrOpcode::kPhi, phi->opcode()); |
128 | 128 |
129 Node* smi = NodeProperties::GetValueInput(phi, 1); | 129 Node* smi = NodeProperties::GetValueInput(phi, 1); |
130 ASSERT_THAT(smi, IsProjection(0, IsInt32AddWithOverflow(val, val))); | 130 ASSERT_THAT(smi, IsProjection(0, IsInt32AddWithOverflow(val, val))); |
(...skipping 17 matching lines...) Expand all Loading... |
148 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); | 148 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); |
149 | 149 |
150 Node* branch = NodeProperties::GetControlInput(if_true); | 150 Node* branch = NodeProperties::GetControlInput(if_true); |
151 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); | 151 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); |
152 EXPECT_THAT(branch, | 152 EXPECT_THAT(branch, |
153 IsBranch(IsProjection(1, IsInt32AddWithOverflow(val, val)), | 153 IsBranch(IsProjection(1, IsInt32AddWithOverflow(val, val)), |
154 graph()->start())); | 154 graph()->start())); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { | 158 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { |
159 Node* val = Parameter(0); | 159 Node* val = Parameter(0); |
160 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 160 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
161 Reduction reduction = Reduce(node); | 161 Reduction reduction = Reduce(node); |
162 ASSERT_TRUE(reduction.Changed()); | 162 ASSERT_TRUE(reduction.Changed()); |
163 | 163 |
164 const int32_t kShiftAmount = | 164 const int32_t kShiftAmount = |
165 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; | 165 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; |
166 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; | 166 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; |
167 Node* phi = reduction.replacement(); | 167 Node* phi = reduction.replacement(); |
168 ASSERT_THAT( | 168 ASSERT_THAT( |
(...skipping 19 matching lines...) Expand all Loading... |
188 graph()->start())); | 188 graph()->start())); |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { | 192 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { |
193 public: | 193 public: |
194 virtual ~ChangeLowering64Test() {} | 194 virtual ~ChangeLowering64Test() {} |
195 }; | 195 }; |
196 | 196 |
197 | 197 |
198 TEST_F(ChangeLowering64Test, ChangeBoolToBit) { | 198 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) { |
199 Node* val = Parameter(0); | 199 Node* val = Parameter(0); |
200 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); | 200 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); |
201 Reduction reduction = Reduce(node); | 201 Reduction reduction = Reduce(node); |
202 ASSERT_TRUE(reduction.Changed()); | 202 ASSERT_TRUE(reduction.Changed()); |
203 | 203 |
204 EXPECT_THAT(reduction.replacement(), | 204 EXPECT_THAT(reduction.replacement(), |
205 IsWord64Equal(val, IsHeapConstant(true_unique()))); | 205 IsWord64Equal(val, IsHeapConstant(true_unique()))); |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { | 209 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { |
210 Node* val = Parameter(0); | 210 Node* val = Parameter(0); |
211 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 211 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
212 Reduction reduction = Reduce(node); | 212 Reduction reduction = Reduce(node); |
213 ASSERT_TRUE(reduction.Changed()); | 213 ASSERT_TRUE(reduction.Changed()); |
214 | 214 |
215 const int32_t kShiftAmount = | 215 const int32_t kShiftAmount = |
216 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; | 216 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; |
217 EXPECT_THAT(reduction.replacement(), | 217 EXPECT_THAT(reduction.replacement(), |
218 IsWord64Shl(val, IsInt32Constant(kShiftAmount))); | 218 IsWord64Shl(val, IsInt32Constant(kShiftAmount))); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { | 222 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { |
223 Node* val = Parameter(0); | 223 Node* val = Parameter(0); |
224 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 224 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
225 Reduction reduction = Reduce(node); | 225 Reduction reduction = Reduce(node); |
226 ASSERT_TRUE(reduction.Changed()); | 226 ASSERT_TRUE(reduction.Changed()); |
227 | 227 |
228 const int32_t kShiftAmount = | 228 const int32_t kShiftAmount = |
229 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; | 229 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; |
230 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; | 230 const int32_t kValueOffset = HeapNumber::kValueOffset - kHeapObjectTag; |
231 Node* phi = reduction.replacement(); | 231 Node* phi = reduction.replacement(); |
232 ASSERT_THAT( | 232 ASSERT_THAT( |
(...skipping 15 matching lines...) Expand all Loading... |
248 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); | 248 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); |
249 STATIC_ASSERT(kSmiTag == 0); | 249 STATIC_ASSERT(kSmiTag == 0); |
250 STATIC_ASSERT(kSmiTagSize == 1); | 250 STATIC_ASSERT(kSmiTagSize == 1); |
251 EXPECT_THAT(branch, IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 251 EXPECT_THAT(branch, IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), |
252 graph()->start())); | 252 graph()->start())); |
253 } | 253 } |
254 | 254 |
255 } // namespace compiler | 255 } // namespace compiler |
256 } // namespace internal | 256 } // namespace internal |
257 } // namespace v8 | 257 } // namespace v8 |
OLD | NEW |