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/graph-unittest.h" | 5 #include "src/compiler/graph-unittest.h" |
6 #include "src/compiler/js-builtin-reducer.h" | 6 #include "src/compiler/js-builtin-reducer.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 8 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "testing/gmock-support.h" | 10 #include "testing/gmock-support.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // ----------------------------------------------------------------------------- | 62 // ----------------------------------------------------------------------------- |
63 // Math.abs | 63 // Math.abs |
64 | 64 |
65 | 65 |
66 TEST_F(JSBuiltinReducerTest, MathAbs) { | 66 TEST_F(JSBuiltinReducerTest, MathAbs) { |
67 Handle<JSFunction> f(isolate()->context()->math_abs_fun()); | 67 Handle<JSFunction> f(isolate()->context()->math_abs_fun()); |
68 | 68 |
69 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 69 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
70 Node* p0 = Parameter(t0, 0); | 70 Node* p0 = Parameter(t0, 0); |
71 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 71 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
72 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), | 72 Node* call = |
73 fun, UndefinedConstant(), p0); | 73 graph()->NewNode(javascript()->CallFunction( |
| 74 CallFunctionParameters(3, NO_CALL_FUNCTION_FLAGS)), |
| 75 fun, UndefinedConstant(), p0); |
74 Reduction r = Reduce(call); | 76 Reduction r = Reduce(call); |
75 | 77 |
76 if (t0->Is(Type::Unsigned32())) { | 78 if (t0->Is(Type::Unsigned32())) { |
77 ASSERT_TRUE(r.Changed()); | 79 ASSERT_TRUE(r.Changed()); |
78 EXPECT_THAT(r.replacement(), p0); | 80 EXPECT_THAT(r.replacement(), p0); |
79 } else { | 81 } else { |
80 Capture<Node*> branch; | 82 Capture<Node*> branch; |
81 ASSERT_TRUE(r.Changed()); | 83 ASSERT_TRUE(r.Changed()); |
82 EXPECT_THAT( | 84 EXPECT_THAT( |
83 r.replacement(), | 85 r.replacement(), |
(...skipping 11 matching lines...) Expand all Loading... |
95 // ----------------------------------------------------------------------------- | 97 // ----------------------------------------------------------------------------- |
96 // Math.sqrt | 98 // Math.sqrt |
97 | 99 |
98 | 100 |
99 TEST_F(JSBuiltinReducerTest, MathSqrt) { | 101 TEST_F(JSBuiltinReducerTest, MathSqrt) { |
100 Handle<JSFunction> f(isolate()->context()->math_sqrt_fun()); | 102 Handle<JSFunction> f(isolate()->context()->math_sqrt_fun()); |
101 | 103 |
102 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 104 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
103 Node* p0 = Parameter(t0, 0); | 105 Node* p0 = Parameter(t0, 0); |
104 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 106 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
105 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), | 107 Node* call = |
106 fun, UndefinedConstant(), p0); | 108 graph()->NewNode(javascript()->CallFunction( |
| 109 CallFunctionParameters(3, NO_CALL_FUNCTION_FLAGS)), |
| 110 fun, UndefinedConstant(), p0); |
107 Reduction r = Reduce(call); | 111 Reduction r = Reduce(call); |
108 | 112 |
109 ASSERT_TRUE(r.Changed()); | 113 ASSERT_TRUE(r.Changed()); |
110 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0)); | 114 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0)); |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 | 118 |
115 // ----------------------------------------------------------------------------- | 119 // ----------------------------------------------------------------------------- |
116 // Math.max | 120 // Math.max |
117 | 121 |
118 | 122 |
119 TEST_F(JSBuiltinReducerTest, MathMax0) { | 123 TEST_F(JSBuiltinReducerTest, MathMax0) { |
120 Handle<JSFunction> f(isolate()->context()->math_max_fun()); | 124 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
121 | 125 |
122 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 126 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
123 Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS), | 127 Node* call = |
124 fun, UndefinedConstant()); | 128 graph()->NewNode(javascript()->CallFunction( |
| 129 CallFunctionParameters(2, NO_CALL_FUNCTION_FLAGS)), |
| 130 fun, UndefinedConstant()); |
125 Reduction r = Reduce(call); | 131 Reduction r = Reduce(call); |
126 | 132 |
127 ASSERT_TRUE(r.Changed()); | 133 ASSERT_TRUE(r.Changed()); |
128 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); | 134 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); |
129 } | 135 } |
130 | 136 |
131 | 137 |
132 TEST_F(JSBuiltinReducerTest, MathMax1) { | 138 TEST_F(JSBuiltinReducerTest, MathMax1) { |
133 Handle<JSFunction> f(isolate()->context()->math_max_fun()); | 139 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
134 | 140 |
135 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 141 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
136 Node* p0 = Parameter(t0, 0); | 142 Node* p0 = Parameter(t0, 0); |
137 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 143 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
138 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), | 144 Node* call = |
139 fun, UndefinedConstant(), p0); | 145 graph()->NewNode(javascript()->CallFunction( |
| 146 CallFunctionParameters(3, NO_CALL_FUNCTION_FLAGS)), |
| 147 fun, UndefinedConstant(), p0); |
140 Reduction r = Reduce(call); | 148 Reduction r = Reduce(call); |
141 | 149 |
142 ASSERT_TRUE(r.Changed()); | 150 ASSERT_TRUE(r.Changed()); |
143 EXPECT_THAT(r.replacement(), p0); | 151 EXPECT_THAT(r.replacement(), p0); |
144 } | 152 } |
145 } | 153 } |
146 | 154 |
147 | 155 |
148 TEST_F(JSBuiltinReducerTest, MathMax2) { | 156 TEST_F(JSBuiltinReducerTest, MathMax2) { |
149 Handle<JSFunction> f(isolate()->context()->math_max_fun()); | 157 Handle<JSFunction> f(isolate()->context()->math_max_fun()); |
150 | 158 |
151 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 159 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
152 TRACED_FOREACH(Type*, t1, kNumberTypes) { | 160 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
153 Node* p0 = Parameter(t0, 0); | 161 Node* p0 = Parameter(t0, 0); |
154 Node* p1 = Parameter(t1, 1); | 162 Node* p1 = Parameter(t1, 1); |
155 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 163 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
156 Node* call = | 164 Node* call = |
157 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, | 165 graph()->NewNode(javascript()->CallFunction(CallFunctionParameters( |
158 UndefinedConstant(), p0, p1); | 166 4, NO_CALL_FUNCTION_FLAGS)), |
| 167 fun, UndefinedConstant(), p0, p1); |
159 Reduction r = Reduce(call); | 168 Reduction r = Reduce(call); |
160 | 169 |
161 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { | 170 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { |
162 Capture<Node*> branch; | 171 Capture<Node*> branch; |
163 ASSERT_TRUE(r.Changed()); | 172 ASSERT_TRUE(r.Changed()); |
164 EXPECT_THAT( | 173 EXPECT_THAT( |
165 r.replacement(), | 174 r.replacement(), |
166 IsPhi(kMachNone, p1, p0, | 175 IsPhi(kMachNone, p1, p0, |
167 IsMerge(IsIfTrue(CaptureEq(&branch)), | 176 IsMerge(IsIfTrue(CaptureEq(&branch)), |
168 IsIfFalse(AllOf(CaptureEq(&branch), | 177 IsIfFalse(AllOf(CaptureEq(&branch), |
(...skipping 14 matching lines...) Expand all Loading... |
183 | 192 |
184 TEST_F(JSBuiltinReducerTest, MathImul) { | 193 TEST_F(JSBuiltinReducerTest, MathImul) { |
185 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); | 194 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); |
186 | 195 |
187 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 196 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
188 TRACED_FOREACH(Type*, t1, kNumberTypes) { | 197 TRACED_FOREACH(Type*, t1, kNumberTypes) { |
189 Node* p0 = Parameter(t0, 0); | 198 Node* p0 = Parameter(t0, 0); |
190 Node* p1 = Parameter(t1, 1); | 199 Node* p1 = Parameter(t1, 1); |
191 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 200 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
192 Node* call = | 201 Node* call = |
193 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, | 202 graph()->NewNode(javascript()->CallFunction(CallFunctionParameters( |
194 UndefinedConstant(), p0, p1); | 203 4, NO_CALL_FUNCTION_FLAGS)), |
| 204 fun, UndefinedConstant(), p0, p1); |
195 Reduction r = Reduce(call); | 205 Reduction r = Reduce(call); |
196 | 206 |
197 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { | 207 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { |
198 ASSERT_TRUE(r.Changed()); | 208 ASSERT_TRUE(r.Changed()); |
199 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); | 209 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); |
200 } else { | 210 } else { |
201 ASSERT_FALSE(r.Changed()); | 211 ASSERT_FALSE(r.Changed()); |
202 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); | 212 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); |
203 } | 213 } |
204 } | 214 } |
(...skipping 10 matching lines...) Expand all Loading... |
215 JSObject::GetProperty(isolate()->global_object(), | 225 JSObject::GetProperty(isolate()->global_object(), |
216 isolate()->factory()->NewStringFromAsciiChecked( | 226 isolate()->factory()->NewStringFromAsciiChecked( |
217 "Math")).ToHandleChecked(); | 227 "Math")).ToHandleChecked(); |
218 Handle<JSFunction> f = Handle<JSFunction>::cast( | 228 Handle<JSFunction> f = Handle<JSFunction>::cast( |
219 JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked( | 229 JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked( |
220 "fround")).ToHandleChecked()); | 230 "fround")).ToHandleChecked()); |
221 | 231 |
222 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 232 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
223 Node* p0 = Parameter(t0, 0); | 233 Node* p0 = Parameter(t0, 0); |
224 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 234 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
225 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), | 235 Node* call = |
226 fun, UndefinedConstant(), p0); | 236 graph()->NewNode(javascript()->CallFunction( |
| 237 CallFunctionParameters(3, NO_CALL_FUNCTION_FLAGS)), |
| 238 fun, UndefinedConstant(), p0); |
227 Reduction r = Reduce(call); | 239 Reduction r = Reduce(call); |
228 | 240 |
229 ASSERT_TRUE(r.Changed()); | 241 ASSERT_TRUE(r.Changed()); |
230 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 242 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
231 } | 243 } |
232 } | 244 } |
233 | 245 |
234 } // namespace compiler | 246 } // namespace compiler |
235 } // namespace internal | 247 } // namespace internal |
236 } // namespace v8 | 248 } // namespace v8 |
OLD | NEW |