Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: src/compiler/js-builtin-reducer-unittest.cc

Issue 613683002: [turbofan] Some javascript operators are globally shared singletons. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/compiler.gyp ('k') | src/compiler/js-context-specialization.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(3, NO_CALL_FUNCTION_FLAGS),
74 fun, UndefinedConstant(), p0);
74 Reduction r = Reduce(call); 75 Reduction r = Reduce(call);
75 76
76 if (t0->Is(Type::Unsigned32())) { 77 if (t0->Is(Type::Unsigned32())) {
77 ASSERT_TRUE(r.Changed()); 78 ASSERT_TRUE(r.Changed());
78 EXPECT_THAT(r.replacement(), p0); 79 EXPECT_THAT(r.replacement(), p0);
79 } else { 80 } else {
80 Capture<Node*> branch; 81 Capture<Node*> branch;
81 ASSERT_TRUE(r.Changed()); 82 ASSERT_TRUE(r.Changed());
82 EXPECT_THAT( 83 EXPECT_THAT(
83 r.replacement(), 84 r.replacement(),
(...skipping 11 matching lines...) Expand all
95 // ----------------------------------------------------------------------------- 96 // -----------------------------------------------------------------------------
96 // Math.sqrt 97 // Math.sqrt
97 98
98 99
99 TEST_F(JSBuiltinReducerTest, MathSqrt) { 100 TEST_F(JSBuiltinReducerTest, MathSqrt) {
100 Handle<JSFunction> f(isolate()->context()->math_sqrt_fun()); 101 Handle<JSFunction> f(isolate()->context()->math_sqrt_fun());
101 102
102 TRACED_FOREACH(Type*, t0, kNumberTypes) { 103 TRACED_FOREACH(Type*, t0, kNumberTypes) {
103 Node* p0 = Parameter(t0, 0); 104 Node* p0 = Parameter(t0, 0);
104 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 105 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
105 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 106 Node* call =
106 fun, UndefinedConstant(), p0); 107 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
108 fun, UndefinedConstant(), p0);
107 Reduction r = Reduce(call); 109 Reduction r = Reduce(call);
108 110
109 ASSERT_TRUE(r.Changed()); 111 ASSERT_TRUE(r.Changed());
110 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0)); 112 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0));
111 } 113 }
112 } 114 }
113 115
114 116
115 // ----------------------------------------------------------------------------- 117 // -----------------------------------------------------------------------------
116 // Math.max 118 // Math.max
117 119
118 120
119 TEST_F(JSBuiltinReducerTest, MathMax0) { 121 TEST_F(JSBuiltinReducerTest, MathMax0) {
120 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 122 Handle<JSFunction> f(isolate()->context()->math_max_fun());
121 123
122 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 124 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
123 Node* call = graph()->NewNode(javascript()->Call(2, NO_CALL_FUNCTION_FLAGS), 125 Node* call =
124 fun, UndefinedConstant()); 126 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS),
127 fun, UndefinedConstant());
125 Reduction r = Reduce(call); 128 Reduction r = Reduce(call);
126 129
127 ASSERT_TRUE(r.Changed()); 130 ASSERT_TRUE(r.Changed());
128 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); 131 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY));
129 } 132 }
130 133
131 134
132 TEST_F(JSBuiltinReducerTest, MathMax1) { 135 TEST_F(JSBuiltinReducerTest, MathMax1) {
133 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 136 Handle<JSFunction> f(isolate()->context()->math_max_fun());
134 137
135 TRACED_FOREACH(Type*, t0, kNumberTypes) { 138 TRACED_FOREACH(Type*, t0, kNumberTypes) {
136 Node* p0 = Parameter(t0, 0); 139 Node* p0 = Parameter(t0, 0);
137 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 140 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
138 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 141 Node* call =
139 fun, UndefinedConstant(), p0); 142 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
143 fun, UndefinedConstant(), p0);
140 Reduction r = Reduce(call); 144 Reduction r = Reduce(call);
141 145
142 ASSERT_TRUE(r.Changed()); 146 ASSERT_TRUE(r.Changed());
143 EXPECT_THAT(r.replacement(), p0); 147 EXPECT_THAT(r.replacement(), p0);
144 } 148 }
145 } 149 }
146 150
147 151
148 TEST_F(JSBuiltinReducerTest, MathMax2) { 152 TEST_F(JSBuiltinReducerTest, MathMax2) {
149 Handle<JSFunction> f(isolate()->context()->math_max_fun()); 153 Handle<JSFunction> f(isolate()->context()->math_max_fun());
150 154
151 TRACED_FOREACH(Type*, t0, kNumberTypes) { 155 TRACED_FOREACH(Type*, t0, kNumberTypes) {
152 TRACED_FOREACH(Type*, t1, kNumberTypes) { 156 TRACED_FOREACH(Type*, t1, kNumberTypes) {
153 Node* p0 = Parameter(t0, 0); 157 Node* p0 = Parameter(t0, 0);
154 Node* p1 = Parameter(t1, 1); 158 Node* p1 = Parameter(t1, 1);
155 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 159 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
156 Node* call = 160 Node* call = graph()->NewNode(
157 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, 161 javascript()->CallFunction(4, NO_CALL_FUNCTION_FLAGS), fun,
158 UndefinedConstant(), p0, p1); 162 UndefinedConstant(), p0, p1);
159 Reduction r = Reduce(call); 163 Reduction r = Reduce(call);
160 164
161 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { 165 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
162 Capture<Node*> branch; 166 Capture<Node*> branch;
163 ASSERT_TRUE(r.Changed()); 167 ASSERT_TRUE(r.Changed());
164 EXPECT_THAT( 168 EXPECT_THAT(
165 r.replacement(), 169 r.replacement(),
166 IsPhi(kMachNone, p1, p0, 170 IsPhi(kMachNone, p1, p0,
167 IsMerge(IsIfTrue(CaptureEq(&branch)), 171 IsMerge(IsIfTrue(CaptureEq(&branch)),
168 IsIfFalse(AllOf(CaptureEq(&branch), 172 IsIfFalse(AllOf(CaptureEq(&branch),
(...skipping 13 matching lines...) Expand all
182 186
183 187
184 TEST_F(JSBuiltinReducerTest, MathImul) { 188 TEST_F(JSBuiltinReducerTest, MathImul) {
185 Handle<JSFunction> f(isolate()->context()->math_imul_fun()); 189 Handle<JSFunction> f(isolate()->context()->math_imul_fun());
186 190
187 TRACED_FOREACH(Type*, t0, kNumberTypes) { 191 TRACED_FOREACH(Type*, t0, kNumberTypes) {
188 TRACED_FOREACH(Type*, t1, kNumberTypes) { 192 TRACED_FOREACH(Type*, t1, kNumberTypes) {
189 Node* p0 = Parameter(t0, 0); 193 Node* p0 = Parameter(t0, 0);
190 Node* p1 = Parameter(t1, 1); 194 Node* p1 = Parameter(t1, 1);
191 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 195 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
192 Node* call = 196 Node* call = graph()->NewNode(
193 graph()->NewNode(javascript()->Call(4, NO_CALL_FUNCTION_FLAGS), fun, 197 javascript()->CallFunction(4, NO_CALL_FUNCTION_FLAGS), fun,
194 UndefinedConstant(), p0, p1); 198 UndefinedConstant(), p0, p1);
195 Reduction r = Reduce(call); 199 Reduction r = Reduce(call);
196 200
197 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { 201 if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
198 ASSERT_TRUE(r.Changed()); 202 ASSERT_TRUE(r.Changed());
199 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); 203 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1));
200 } else { 204 } else {
201 ASSERT_FALSE(r.Changed()); 205 ASSERT_FALSE(r.Changed());
202 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); 206 EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
203 } 207 }
204 } 208 }
(...skipping 10 matching lines...) Expand all
215 JSObject::GetProperty(isolate()->global_object(), 219 JSObject::GetProperty(isolate()->global_object(),
216 isolate()->factory()->NewStringFromAsciiChecked( 220 isolate()->factory()->NewStringFromAsciiChecked(
217 "Math")).ToHandleChecked(); 221 "Math")).ToHandleChecked();
218 Handle<JSFunction> f = Handle<JSFunction>::cast( 222 Handle<JSFunction> f = Handle<JSFunction>::cast(
219 JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked( 223 JSObject::GetProperty(m, isolate()->factory()->NewStringFromAsciiChecked(
220 "fround")).ToHandleChecked()); 224 "fround")).ToHandleChecked());
221 225
222 TRACED_FOREACH(Type*, t0, kNumberTypes) { 226 TRACED_FOREACH(Type*, t0, kNumberTypes) {
223 Node* p0 = Parameter(t0, 0); 227 Node* p0 = Parameter(t0, 0);
224 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); 228 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
225 Node* call = graph()->NewNode(javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 229 Node* call =
226 fun, UndefinedConstant(), p0); 230 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
231 fun, UndefinedConstant(), p0);
227 Reduction r = Reduce(call); 232 Reduction r = Reduce(call);
228 233
229 ASSERT_TRUE(r.Changed()); 234 ASSERT_TRUE(r.Changed());
230 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); 235 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0));
231 } 236 }
232 } 237 }
233 238
234 } // namespace compiler 239 } // namespace compiler
235 } // namespace internal 240 } // namespace internal
236 } // namespace v8 241 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/compiler.gyp ('k') | src/compiler/js-context-specialization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698