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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 Type* const kIntegral32Types[] = {Type::UnsignedSmall(), Type::Negative32(), | 61 Type* const kIntegral32Types[] = {Type::UnsignedSmall(), Type::Negative32(), |
62 Type::Unsigned31(), Type::SignedSmall(), | 62 Type::Unsigned31(), Type::SignedSmall(), |
63 Type::Signed32(), Type::Unsigned32(), | 63 Type::Signed32(), Type::Unsigned32(), |
64 Type::Integral32()}; | 64 Type::Integral32()}; |
65 | 65 |
66 | 66 |
67 const LanguageMode kLanguageModes[] = {SLOPPY, STRICT, STRONG}; | |
68 | |
69 | |
70 // TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering. | |
71 Type* const kNumberTypes[] = { | 67 Type* const kNumberTypes[] = { |
72 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), | 68 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), |
73 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), | 69 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), |
74 Type::Integral32(), Type::MinusZero(), Type::NaN(), | 70 Type::Integral32(), Type::MinusZero(), Type::NaN(), |
75 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; | 71 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; |
76 | 72 |
77 } // namespace | 73 } // namespace |
78 | 74 |
79 | 75 |
80 // ----------------------------------------------------------------------------- | 76 // ----------------------------------------------------------------------------- |
81 // Math.max | 77 // Math.max |
82 | 78 |
83 | 79 |
84 TEST_F(JSBuiltinReducerTest, MathMax0) { | 80 TEST_F(JSBuiltinReducerTest, MathMax0) { |
85 Node* function = MathFunction("max"); | 81 Node* function = MathFunction("max"); |
86 | 82 |
87 Node* effect = graph()->start(); | 83 Node* effect = graph()->start(); |
88 Node* control = graph()->start(); | 84 Node* control = graph()->start(); |
89 Node* context = UndefinedConstant(); | 85 Node* context = UndefinedConstant(); |
90 Node* frame_state = graph()->start(); | 86 Node* frame_state = graph()->start(); |
91 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 87 Node* call = graph()->NewNode(javascript()->CallFunction(2), function, |
92 Node* call = graph()->NewNode(javascript()->CallFunction(2, language_mode), | 88 UndefinedConstant(), context, frame_state, |
93 function, UndefinedConstant(), context, | 89 frame_state, effect, control); |
94 frame_state, frame_state, effect, control); | 90 Reduction r = Reduce(call); |
95 Reduction r = Reduce(call); | |
96 | 91 |
97 ASSERT_TRUE(r.Changed()); | 92 ASSERT_TRUE(r.Changed()); |
98 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); | 93 EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY)); |
99 } | |
100 } | 94 } |
101 | 95 |
102 | 96 |
103 TEST_F(JSBuiltinReducerTest, MathMax1) { | 97 TEST_F(JSBuiltinReducerTest, MathMax1) { |
104 Node* function = MathFunction("max"); | 98 Node* function = MathFunction("max"); |
105 | 99 |
106 Node* effect = graph()->start(); | 100 Node* effect = graph()->start(); |
107 Node* control = graph()->start(); | 101 Node* control = graph()->start(); |
108 Node* context = UndefinedConstant(); | 102 Node* context = UndefinedConstant(); |
109 Node* frame_state = graph()->start(); | 103 Node* frame_state = graph()->start(); |
110 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 104 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
111 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 105 Node* p0 = Parameter(t0, 0); |
112 Node* p0 = Parameter(t0, 0); | 106 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
113 Node* call = | 107 UndefinedConstant(), p0, context, frame_state, |
114 graph()->NewNode(javascript()->CallFunction(3, language_mode), | 108 frame_state, effect, control); |
115 function, UndefinedConstant(), p0, context, | 109 Reduction r = Reduce(call); |
116 frame_state, frame_state, effect, control); | |
117 Reduction r = Reduce(call); | |
118 | 110 |
119 ASSERT_TRUE(r.Changed()); | 111 ASSERT_TRUE(r.Changed()); |
120 EXPECT_THAT(r.replacement(), p0); | 112 EXPECT_THAT(r.replacement(), p0); |
121 } | |
122 } | 113 } |
123 } | 114 } |
124 | 115 |
125 | 116 |
126 TEST_F(JSBuiltinReducerTest, MathMax2) { | 117 TEST_F(JSBuiltinReducerTest, MathMax2) { |
127 Node* function = MathFunction("max"); | 118 Node* function = MathFunction("max"); |
128 | 119 |
129 Node* effect = graph()->start(); | 120 Node* effect = graph()->start(); |
130 Node* control = graph()->start(); | 121 Node* control = graph()->start(); |
131 Node* context = UndefinedConstant(); | 122 Node* context = UndefinedConstant(); |
132 Node* frame_state = graph()->start(); | 123 Node* frame_state = graph()->start(); |
133 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 124 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
134 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 125 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
135 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 126 Node* p0 = Parameter(t0, 0); |
136 Node* p0 = Parameter(t0, 0); | 127 Node* p1 = Parameter(t1, 1); |
137 Node* p1 = Parameter(t1, 1); | 128 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
138 Node* call = | 129 UndefinedConstant(), p0, p1, context, |
139 graph()->NewNode(javascript()->CallFunction(4, language_mode), | 130 frame_state, frame_state, effect, control); |
140 function, UndefinedConstant(), p0, p1, context, | 131 Reduction r = Reduce(call); |
141 frame_state, frame_state, effect, control); | |
142 Reduction r = Reduce(call); | |
143 | 132 |
144 ASSERT_TRUE(r.Changed()); | 133 ASSERT_TRUE(r.Changed()); |
145 EXPECT_THAT(r.replacement(), | 134 EXPECT_THAT(r.replacement(), IsSelect(MachineRepresentation::kNone, |
146 IsSelect(MachineRepresentation::kNone, | 135 IsNumberLessThan(p1, p0), p0, p1)); |
147 IsNumberLessThan(p1, p0), p0, p1)); | |
148 } | |
149 } | 136 } |
150 } | 137 } |
151 } | 138 } |
152 | 139 |
153 | 140 |
154 // ----------------------------------------------------------------------------- | 141 // ----------------------------------------------------------------------------- |
155 // Math.imul | 142 // Math.imul |
156 | 143 |
157 | 144 |
158 TEST_F(JSBuiltinReducerTest, MathImul) { | 145 TEST_F(JSBuiltinReducerTest, MathImul) { |
159 Node* function = MathFunction("imul"); | 146 Node* function = MathFunction("imul"); |
160 | 147 |
161 Node* effect = graph()->start(); | 148 Node* effect = graph()->start(); |
162 Node* control = graph()->start(); | 149 Node* control = graph()->start(); |
163 Node* context = UndefinedConstant(); | 150 Node* context = UndefinedConstant(); |
164 Node* frame_state = graph()->start(); | 151 Node* frame_state = graph()->start(); |
165 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 152 TRACED_FOREACH(Type*, t0, kIntegral32Types) { |
166 TRACED_FOREACH(Type*, t0, kIntegral32Types) { | 153 TRACED_FOREACH(Type*, t1, kIntegral32Types) { |
167 TRACED_FOREACH(Type*, t1, kIntegral32Types) { | 154 Node* p0 = Parameter(t0, 0); |
168 Node* p0 = Parameter(t0, 0); | 155 Node* p1 = Parameter(t1, 1); |
169 Node* p1 = Parameter(t1, 1); | 156 Node* call = graph()->NewNode(javascript()->CallFunction(4), function, |
170 Node* call = | 157 UndefinedConstant(), p0, p1, context, |
171 graph()->NewNode(javascript()->CallFunction(4, language_mode), | 158 frame_state, frame_state, effect, control); |
172 function, UndefinedConstant(), p0, p1, context, | 159 Reduction r = Reduce(call); |
173 frame_state, frame_state, effect, control); | |
174 Reduction r = Reduce(call); | |
175 | 160 |
176 ASSERT_TRUE(r.Changed()); | 161 ASSERT_TRUE(r.Changed()); |
177 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); | 162 EXPECT_THAT(r.replacement(), IsInt32Mul(p0, p1)); |
178 } | |
179 } | 163 } |
180 } | 164 } |
181 } | 165 } |
182 | 166 |
183 | 167 |
184 // ----------------------------------------------------------------------------- | 168 // ----------------------------------------------------------------------------- |
185 // Math.fround | 169 // Math.fround |
186 | 170 |
187 | 171 |
188 TEST_F(JSBuiltinReducerTest, MathFround) { | 172 TEST_F(JSBuiltinReducerTest, MathFround) { |
189 Node* function = MathFunction("fround"); | 173 Node* function = MathFunction("fround"); |
190 | 174 |
191 Node* effect = graph()->start(); | 175 Node* effect = graph()->start(); |
192 Node* control = graph()->start(); | 176 Node* control = graph()->start(); |
193 Node* context = UndefinedConstant(); | 177 Node* context = UndefinedConstant(); |
194 Node* frame_state = graph()->start(); | 178 Node* frame_state = graph()->start(); |
195 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) { | 179 TRACED_FOREACH(Type*, t0, kNumberTypes) { |
196 TRACED_FOREACH(Type*, t0, kNumberTypes) { | 180 Node* p0 = Parameter(t0, 0); |
197 Node* p0 = Parameter(t0, 0); | 181 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, |
198 Node* call = | 182 UndefinedConstant(), p0, context, frame_state, |
199 graph()->NewNode(javascript()->CallFunction(3, language_mode), | 183 frame_state, effect, control); |
200 function, UndefinedConstant(), p0, context, | 184 Reduction r = Reduce(call); |
201 frame_state, frame_state, effect, control); | |
202 Reduction r = Reduce(call); | |
203 | 185 |
204 ASSERT_TRUE(r.Changed()); | 186 ASSERT_TRUE(r.Changed()); |
205 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 187 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
206 } | |
207 } | 188 } |
208 } | 189 } |
209 | 190 |
210 } // namespace compiler | 191 } // namespace compiler |
211 } // namespace internal | 192 } // namespace internal |
212 } // namespace v8 | 193 } // namespace v8 |
OLD | NEW |