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/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/simplified-operator.h" | 8 #include "src/compiler/simplified-operator.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 | 82 |
83 TEST_F(JSBuiltinReducerTest, MathMax0) { | 83 TEST_F(JSBuiltinReducerTest, MathMax0) { |
84 Node* function = MathFunction("max"); | 84 Node* function = MathFunction("max"); |
85 | 85 |
86 Node* effect = graph()->start(); | 86 Node* effect = graph()->start(); |
87 Node* control = graph()->start(); | 87 Node* control = graph()->start(); |
88 Node* context = UndefinedConstant(); | 88 Node* context = UndefinedConstant(); |
89 Node* frame_state = graph()->start(); | 89 Node* frame_state = graph()->start(); |
90 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 90 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
91 Node* call = graph()->NewNode( | 91 Node* call = graph()->NewNode(javascript()->CallFunction(2, language_mode), |
92 javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, language_mode), | 92 function, UndefinedConstant(), context, |
93 function, UndefinedConstant(), context, frame_state, frame_state, | 93 frame_state, frame_state, effect, control); |
94 effect, control); | |
95 Reduction r = Reduce(call); | 94 Reduction r = Reduce(call); |
96 | 95 |
97 ASSERT_TRUE(r.Changed()); | 96 ASSERT_TRUE(r.Changed()); |
98 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); | 97 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 | 101 |
103 TEST_F(JSBuiltinReducerTest, MathMax1) { | 102 TEST_F(JSBuiltinReducerTest, MathMax1) { |
104 Node* function = MathFunction("max"); | 103 Node* function = MathFunction("max"); |
105 | 104 |
106 Node* effect = graph()->start(); | 105 Node* effect = graph()->start(); |
107 Node* control = graph()->start(); | 106 Node* control = graph()->start(); |
108 Node* context = UndefinedConstant(); | 107 Node* context = UndefinedConstant(); |
109 Node* frame_state = graph()->start(); | 108 Node* frame_state = graph()->start(); |
110 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 109 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
111 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 110 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
112 Node* p0 = Parameter(t0, 0); | 111 Node* p0 = Parameter(t0, 0); |
113 Node* call = graph()->NewNode( | 112 Node* call = |
114 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), | 113 graph()->NewNode(javascript()->CallFunction(3, language_mode), |
115 function, UndefinedConstant(), p0, context, frame_state, frame_state, | 114 function, UndefinedConstant(), p0, context, |
116 effect, control); | 115 frame_state, frame_state, effect, control); |
117 Reduction r = Reduce(call); | 116 Reduction r = Reduce(call); |
118 | 117 |
119 ASSERT_TRUE(r.Changed()); | 118 ASSERT_TRUE(r.Changed()); |
120 EXPECT_THAT(r.replacement(), p0); | 119 EXPECT_THAT(r.replacement(), p0); |
121 } | 120 } |
122 } | 121 } |
123 } | 122 } |
124 | 123 |
125 | 124 |
126 TEST_F(JSBuiltinReducerTest, MathMax2) { | 125 TEST_F(JSBuiltinReducerTest, MathMax2) { |
127 Node* function = MathFunction("max"); | 126 Node* function = MathFunction("max"); |
128 | 127 |
129 Node* effect = graph()->start(); | 128 Node* effect = graph()->start(); |
130 Node* control = graph()->start(); | 129 Node* control = graph()->start(); |
131 Node* context = UndefinedConstant(); | 130 Node* context = UndefinedConstant(); |
132 Node* frame_state = graph()->start(); | 131 Node* frame_state = graph()->start(); |
133 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 132 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
134 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 133 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
135 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 134 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
136 Node* p0 = Parameter(t0, 0); | 135 Node* p0 = Parameter(t0, 0); |
137 Node* p1 = Parameter(t1, 1); | 136 Node* p1 = Parameter(t1, 1); |
138 Node* call = | 137 Node* call = |
139 graph()->NewNode(javascript()->CallFunction( | 138 graph()->NewNode(javascript()->CallFunction(4, language_mode), |
140 4, NO_CALL_FUNCTION_FLAGS, language_mode), | |
141 function, UndefinedConstant(), p0, p1, context, | 139 function, UndefinedConstant(), p0, p1, context, |
142 frame_state, frame_state, effect, control); | 140 frame_state, frame_state, effect, control); |
143 Reduction r = Reduce(call); | 141 Reduction r = Reduce(call); |
144 | 142 |
145 ASSERT_TRUE(r.Changed()); | 143 ASSERT_TRUE(r.Changed()); |
146 EXPECT_THAT(r.replacement(), | 144 EXPECT_THAT(r.replacement(), |
147 IsSelect(kMachNone, IsNumberLessThan(p1, p0), p0, p1)); | 145 IsSelect(kMachNone, IsNumberLessThan(p1, p0), p0, p1)); |
148 } | 146 } |
149 } | 147 } |
150 } | 148 } |
(...skipping 10 matching lines...) Expand all Loading... |
161 Node* effect = graph()->start(); | 159 Node* effect = graph()->start(); |
162 Node* control = graph()->start(); | 160 Node* control = graph()->start(); |
163 Node* context = UndefinedConstant(); | 161 Node* context = UndefinedConstant(); |
164 Node* frame_state = graph()->start(); | 162 Node* frame_state = graph()->start(); |
165 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 163 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
166 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 164 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
167 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 165 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
168 Node* p0 = Parameter(t0, 0); | 166 Node* p0 = Parameter(t0, 0); |
169 Node* p1 = Parameter(t1, 1); | 167 Node* p1 = Parameter(t1, 1); |
170 Node* call = | 168 Node* call = |
171 graph()->NewNode(javascript()->CallFunction( | 169 graph()->NewNode(javascript()->CallFunction(4, language_mode), |
172 4, NO_CALL_FUNCTION_FLAGS, language_mode), | |
173 function, UndefinedConstant(), p0, p1, context, | 170 function, UndefinedConstant(), p0, p1, context, |
174 frame_state, frame_state, effect, control); | 171 frame_state, frame_state, effect, control); |
175 Reduction r = Reduce(call); | 172 Reduction r = Reduce(call); |
176 | 173 |
177 ASSERT_TRUE(r.Changed()); | 174 ASSERT_TRUE(r.Changed()); |
178 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); | 175 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); |
179 } | 176 } |
180 } | 177 } |
181 } | 178 } |
182 } | 179 } |
183 | 180 |
184 | 181 |
185 // ----------------------------------------------------------------------------- | 182 // ----------------------------------------------------------------------------- |
186 // Math.fround | 183 // Math.fround |
187 | 184 |
188 | 185 |
189 TEST_F(JSBuiltinReducerTest, MathFround) { | 186 TEST_F(JSBuiltinReducerTest, MathFround) { |
190 Node* function = MathFunction("fround"); | 187 Node* function = MathFunction("fround"); |
191 | 188 |
192 Node* effect = graph()->start(); | 189 Node* effect = graph()->start(); |
193 Node* control = graph()->start(); | 190 Node* control = graph()->start(); |
194 Node* context = UndefinedConstant(); | 191 Node* context = UndefinedConstant(); |
195 Node* frame_state = graph()->start(); | 192 Node* frame_state = graph()->start(); |
196 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 193 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { |
197 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 194 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
198 Node* p0 = Parameter(t0, 0); | 195 Node* p0 = Parameter(t0, 0); |
199 Node* call = graph()->NewNode( | 196 Node* call = |
200 javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS, language_mode), | 197 graph()->NewNode(javascript()->CallFunction(3, language_mode), |
201 function, UndefinedConstant(), p0, context, frame_state, frame_state, | 198 function, UndefinedConstant(), p0, context, |
202 effect, control); | 199 frame_state, frame_state, effect, control); |
203 Reduction r = Reduce(call); | 200 Reduction r = Reduce(call); |
204 | 201 |
205 ASSERT_TRUE(r.Changed()); | 202 ASSERT_TRUE(r.Changed()); |
206 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 203 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
207 } | 204 } |
208 } | 205 } |
209 } | 206 } |
210 | 207 |
211 } // namespace compiler | 208 } // namespace compiler |
212 } // namespace internal | 209 } // namespace internal |
213 } // namespace v8 | 210 } // namespace v8 |
OLD | NEW |