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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/compiler/control-builders.h" | 7 #include "src/compiler/control-builders.h" |
8 #include "src/compiler/generic-node-inl.h" | 8 #include "src/compiler/generic-node-inl.h" |
9 #include "src/compiler/graph-visualizer.h" | 9 #include "src/compiler/graph-visualizer.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "test/cctest/compiler/codegen-tester.h" | 22 #include "test/cctest/compiler/codegen-tester.h" |
23 #include "test/cctest/compiler/graph-builder-tester.h" | 23 #include "test/cctest/compiler/graph-builder-tester.h" |
24 #include "test/cctest/compiler/value-helper.h" | 24 #include "test/cctest/compiler/value-helper.h" |
25 | 25 |
26 using namespace v8::internal; | 26 using namespace v8::internal; |
27 using namespace v8::internal::compiler; | 27 using namespace v8::internal::compiler; |
28 | 28 |
29 template <typename ReturnType> | 29 template <typename ReturnType> |
30 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { | 30 class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> { |
31 public: | 31 public: |
32 SimplifiedLoweringTester(MachineType p0 = kMachineLast, | 32 SimplifiedLoweringTester(MachineType p0 = mNone, MachineType p1 = mNone, |
33 MachineType p1 = kMachineLast, | 33 MachineType p2 = mNone, MachineType p3 = mNone, |
34 MachineType p2 = kMachineLast, | 34 MachineType p4 = mNone) |
35 MachineType p3 = kMachineLast, | |
36 MachineType p4 = kMachineLast) | |
37 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), | 35 : GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4), |
38 typer(this->zone()), | 36 typer(this->zone()), |
39 source_positions(this->graph()), | 37 source_positions(this->graph()), |
40 jsgraph(this->graph(), this->common(), &typer), | 38 jsgraph(this->graph(), this->common(), &typer), |
41 lowering(&jsgraph, &source_positions) {} | 39 lowering(&jsgraph, &source_positions) {} |
42 | 40 |
43 Typer typer; | 41 Typer typer; |
44 SourcePositionTable source_positions; | 42 SourcePositionTable source_positions; |
45 JSGraph jsgraph; | 43 JSGraph jsgraph; |
46 SimplifiedLowering lowering; | 44 SimplifiedLowering lowering; |
47 | 45 |
48 void LowerAllNodes() { | 46 void LowerAllNodes() { |
49 this->End(); | 47 this->End(); |
50 lowering.LowerAllNodes(); | 48 lowering.LowerAllNodes(); |
51 } | 49 } |
52 | 50 |
53 Factory* factory() { return this->isolate()->factory(); } | 51 Factory* factory() { return this->isolate()->factory(); } |
54 Heap* heap() { return this->isolate()->heap(); } | 52 Heap* heap() { return this->isolate()->heap(); } |
55 }; | 53 }; |
56 | 54 |
57 | 55 |
58 // TODO(dcarney): find a home for these functions. | 56 // TODO(dcarney): find a home for these functions. |
59 namespace { | 57 namespace { |
60 | 58 |
61 FieldAccess ForJSObjectMap() { | 59 FieldAccess ForJSObjectMap() { |
62 FieldAccess access = {kTaggedBase, JSObject::kMapOffset, Handle<Name>(), | 60 FieldAccess access = {kTaggedBase, JSObject::kMapOffset, Handle<Name>(), |
63 Type::Any(), kMachineTagged}; | 61 Type::Any(), mAnyTagged}; |
64 return access; | 62 return access; |
65 } | 63 } |
66 | 64 |
67 | 65 |
68 FieldAccess ForJSObjectProperties() { | 66 FieldAccess ForJSObjectProperties() { |
69 FieldAccess access = {kTaggedBase, JSObject::kPropertiesOffset, | 67 FieldAccess access = {kTaggedBase, JSObject::kPropertiesOffset, |
70 Handle<Name>(), Type::Any(), kMachineTagged}; | 68 Handle<Name>(), Type::Any(), mAnyTagged}; |
71 return access; | 69 return access; |
72 } | 70 } |
73 | 71 |
74 | 72 |
75 FieldAccess ForArrayBufferBackingStore() { | 73 FieldAccess ForArrayBufferBackingStore() { |
76 FieldAccess access = { | 74 FieldAccess access = { |
77 kTaggedBase, JSArrayBuffer::kBackingStoreOffset, | 75 kTaggedBase, JSArrayBuffer::kBackingStoreOffset, |
78 Handle<Name>(), Type::UntaggedPtr(), | 76 Handle<Name>(), Type::UntaggedPtr(), |
79 MachineOperatorBuilder::pointer_rep(), | 77 MachineOperatorBuilder::pointer_rep(), |
80 }; | 78 }; |
81 return access; | 79 return access; |
82 } | 80 } |
83 | 81 |
84 | 82 |
85 ElementAccess ForFixedArrayElement() { | 83 ElementAccess ForFixedArrayElement() { |
86 ElementAccess access = {kTaggedBase, FixedArray::kHeaderSize, Type::Any(), | 84 ElementAccess access = {kTaggedBase, FixedArray::kHeaderSize, Type::Any(), |
87 kMachineTagged}; | 85 mAnyTagged}; |
88 return access; | 86 return access; |
89 } | 87 } |
90 | 88 |
91 | 89 |
92 ElementAccess ForBackingStoreElement(MachineType rep) { | 90 ElementAccess ForBackingStoreElement(MachineType rep) { |
93 ElementAccess access = {kUntaggedBase, | 91 ElementAccess access = {kUntaggedBase, |
94 kNonHeapObjectHeaderSize - kHeapObjectTag, | 92 kNonHeapObjectHeaderSize - kHeapObjectTag, |
95 Type::Any(), rep}; | 93 Type::Any(), rep}; |
96 return access; | 94 return access; |
97 } | 95 } |
98 } | 96 } |
99 | 97 |
100 | 98 |
101 // Create a simple JSObject with a unique map. | 99 // Create a simple JSObject with a unique map. |
102 static Handle<JSObject> TestObject() { | 100 static Handle<JSObject> TestObject() { |
103 static int index = 0; | 101 static int index = 0; |
104 char buffer[50]; | 102 char buffer[50]; |
105 v8::base::OS::SNPrintF(buffer, 50, "({'a_%d':1})", index++); | 103 v8::base::OS::SNPrintF(buffer, 50, "({'a_%d':1})", index++); |
106 return Handle<JSObject>::cast(v8::Utils::OpenHandle(*CompileRun(buffer))); | 104 return Handle<JSObject>::cast(v8::Utils::OpenHandle(*CompileRun(buffer))); |
107 } | 105 } |
108 | 106 |
109 | 107 |
110 TEST(RunLoadMap) { | 108 TEST(RunLoadMap) { |
111 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 109 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
112 FieldAccess access = ForJSObjectMap(); | 110 FieldAccess access = ForJSObjectMap(); |
113 Node* load = t.LoadField(access, t.Parameter(0)); | 111 Node* load = t.LoadField(access, t.Parameter(0)); |
114 t.Return(load); | 112 t.Return(load); |
115 | 113 |
116 t.LowerAllNodes(); | 114 t.LowerAllNodes(); |
117 t.GenerateCode(); | 115 t.GenerateCode(); |
118 | 116 |
119 if (Pipeline::SupportedTarget()) { | 117 if (Pipeline::SupportedTarget()) { |
120 Handle<JSObject> src = TestObject(); | 118 Handle<JSObject> src = TestObject(); |
121 Handle<Map> src_map(src->map()); | 119 Handle<Map> src_map(src->map()); |
122 Object* result = t.Call(*src); // TODO(titzer): raw pointers in call | 120 Object* result = t.Call(*src); // TODO(titzer): raw pointers in call |
123 CHECK_EQ(*src_map, result); | 121 CHECK_EQ(*src_map, result); |
124 } | 122 } |
125 } | 123 } |
126 | 124 |
127 | 125 |
128 TEST(RunStoreMap) { | 126 TEST(RunStoreMap) { |
129 SimplifiedLoweringTester<int32_t> t(kMachineTagged, kMachineTagged); | 127 SimplifiedLoweringTester<int32_t> t(mAnyTagged, mAnyTagged); |
130 FieldAccess access = ForJSObjectMap(); | 128 FieldAccess access = ForJSObjectMap(); |
131 t.StoreField(access, t.Parameter(1), t.Parameter(0)); | 129 t.StoreField(access, t.Parameter(1), t.Parameter(0)); |
132 t.Return(t.jsgraph.TrueConstant()); | 130 t.Return(t.jsgraph.TrueConstant()); |
133 | 131 |
134 t.LowerAllNodes(); | 132 t.LowerAllNodes(); |
135 t.GenerateCode(); | 133 t.GenerateCode(); |
136 | 134 |
137 if (Pipeline::SupportedTarget()) { | 135 if (Pipeline::SupportedTarget()) { |
138 Handle<JSObject> src = TestObject(); | 136 Handle<JSObject> src = TestObject(); |
139 Handle<Map> src_map(src->map()); | 137 Handle<Map> src_map(src->map()); |
140 Handle<JSObject> dst = TestObject(); | 138 Handle<JSObject> dst = TestObject(); |
141 CHECK(src->map() != dst->map()); | 139 CHECK(src->map() != dst->map()); |
142 t.Call(*src_map, *dst); // TODO(titzer): raw pointers in call | 140 t.Call(*src_map, *dst); // TODO(titzer): raw pointers in call |
143 CHECK(*src_map == dst->map()); | 141 CHECK(*src_map == dst->map()); |
144 } | 142 } |
145 } | 143 } |
146 | 144 |
147 | 145 |
148 TEST(RunLoadProperties) { | 146 TEST(RunLoadProperties) { |
149 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 147 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
150 FieldAccess access = ForJSObjectProperties(); | 148 FieldAccess access = ForJSObjectProperties(); |
151 Node* load = t.LoadField(access, t.Parameter(0)); | 149 Node* load = t.LoadField(access, t.Parameter(0)); |
152 t.Return(load); | 150 t.Return(load); |
153 | 151 |
154 t.LowerAllNodes(); | 152 t.LowerAllNodes(); |
155 t.GenerateCode(); | 153 t.GenerateCode(); |
156 | 154 |
157 if (Pipeline::SupportedTarget()) { | 155 if (Pipeline::SupportedTarget()) { |
158 Handle<JSObject> src = TestObject(); | 156 Handle<JSObject> src = TestObject(); |
159 Handle<FixedArray> src_props(src->properties()); | 157 Handle<FixedArray> src_props(src->properties()); |
160 Object* result = t.Call(*src); // TODO(titzer): raw pointers in call | 158 Object* result = t.Call(*src); // TODO(titzer): raw pointers in call |
161 CHECK_EQ(*src_props, result); | 159 CHECK_EQ(*src_props, result); |
162 } | 160 } |
163 } | 161 } |
164 | 162 |
165 | 163 |
166 TEST(RunLoadStoreMap) { | 164 TEST(RunLoadStoreMap) { |
167 SimplifiedLoweringTester<Object*> t(kMachineTagged, kMachineTagged); | 165 SimplifiedLoweringTester<Object*> t(mAnyTagged, mAnyTagged); |
168 FieldAccess access = ForJSObjectMap(); | 166 FieldAccess access = ForJSObjectMap(); |
169 Node* load = t.LoadField(access, t.Parameter(0)); | 167 Node* load = t.LoadField(access, t.Parameter(0)); |
170 t.StoreField(access, t.Parameter(1), load); | 168 t.StoreField(access, t.Parameter(1), load); |
171 t.Return(load); | 169 t.Return(load); |
172 | 170 |
173 t.LowerAllNodes(); | 171 t.LowerAllNodes(); |
174 t.GenerateCode(); | 172 t.GenerateCode(); |
175 | 173 |
176 if (Pipeline::SupportedTarget()) { | 174 if (Pipeline::SupportedTarget()) { |
177 Handle<JSObject> src = TestObject(); | 175 Handle<JSObject> src = TestObject(); |
178 Handle<Map> src_map(src->map()); | 176 Handle<Map> src_map(src->map()); |
179 Handle<JSObject> dst = TestObject(); | 177 Handle<JSObject> dst = TestObject(); |
180 CHECK(src->map() != dst->map()); | 178 CHECK(src->map() != dst->map()); |
181 Object* result = t.Call(*src, *dst); // TODO(titzer): raw pointers in call | 179 Object* result = t.Call(*src, *dst); // TODO(titzer): raw pointers in call |
182 CHECK(result->IsMap()); | 180 CHECK(result->IsMap()); |
183 CHECK_EQ(*src_map, result); | 181 CHECK_EQ(*src_map, result); |
184 CHECK(*src_map == dst->map()); | 182 CHECK(*src_map == dst->map()); |
185 } | 183 } |
186 } | 184 } |
187 | 185 |
188 | 186 |
189 TEST(RunLoadStoreFixedArrayIndex) { | 187 TEST(RunLoadStoreFixedArrayIndex) { |
190 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 188 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
191 ElementAccess access = ForFixedArrayElement(); | 189 ElementAccess access = ForFixedArrayElement(); |
192 Node* load = t.LoadElement(access, t.Parameter(0), t.Int32Constant(0)); | 190 Node* load = t.LoadElement(access, t.Parameter(0), t.Int32Constant(0)); |
193 t.StoreElement(access, t.Parameter(0), t.Int32Constant(1), load); | 191 t.StoreElement(access, t.Parameter(0), t.Int32Constant(1), load); |
194 t.Return(load); | 192 t.Return(load); |
195 | 193 |
196 t.LowerAllNodes(); | 194 t.LowerAllNodes(); |
197 t.GenerateCode(); | 195 t.GenerateCode(); |
198 | 196 |
199 if (Pipeline::SupportedTarget()) { | 197 if (Pipeline::SupportedTarget()) { |
200 Handle<FixedArray> array = t.factory()->NewFixedArray(2); | 198 Handle<FixedArray> array = t.factory()->NewFixedArray(2); |
201 Handle<JSObject> src = TestObject(); | 199 Handle<JSObject> src = TestObject(); |
202 Handle<JSObject> dst = TestObject(); | 200 Handle<JSObject> dst = TestObject(); |
203 array->set(0, *src); | 201 array->set(0, *src); |
204 array->set(1, *dst); | 202 array->set(1, *dst); |
205 Object* result = t.Call(*array); | 203 Object* result = t.Call(*array); |
206 CHECK_EQ(*src, result); | 204 CHECK_EQ(*src, result); |
207 CHECK_EQ(*src, array->get(0)); | 205 CHECK_EQ(*src, array->get(0)); |
208 CHECK_EQ(*src, array->get(1)); | 206 CHECK_EQ(*src, array->get(1)); |
209 } | 207 } |
210 } | 208 } |
211 | 209 |
212 | 210 |
213 TEST(RunLoadStoreArrayBuffer) { | 211 TEST(RunLoadStoreArrayBuffer) { |
214 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 212 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
215 const int index = 12; | 213 const int index = 12; |
216 ElementAccess buffer_access = ForBackingStoreElement(kMachineWord8); | 214 ElementAccess buffer_access = ForBackingStoreElement(mInt8); |
217 Node* backing_store = | 215 Node* backing_store = |
218 t.LoadField(ForArrayBufferBackingStore(), t.Parameter(0)); | 216 t.LoadField(ForArrayBufferBackingStore(), t.Parameter(0)); |
219 Node* load = | 217 Node* load = |
220 t.LoadElement(buffer_access, backing_store, t.Int32Constant(index)); | 218 t.LoadElement(buffer_access, backing_store, t.Int32Constant(index)); |
221 t.StoreElement(buffer_access, backing_store, t.Int32Constant(index + 1), | 219 t.StoreElement(buffer_access, backing_store, t.Int32Constant(index + 1), |
222 load); | 220 load); |
223 t.Return(t.jsgraph.TrueConstant()); | 221 t.Return(t.jsgraph.TrueConstant()); |
224 | 222 |
225 t.LowerAllNodes(); | 223 t.LowerAllNodes(); |
226 t.GenerateCode(); | 224 t.GenerateCode(); |
(...skipping 18 matching lines...) Expand all Loading... |
245 } | 243 } |
246 } | 244 } |
247 | 245 |
248 | 246 |
249 TEST(RunLoadFieldFromUntaggedBase) { | 247 TEST(RunLoadFieldFromUntaggedBase) { |
250 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)}; | 248 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)}; |
251 | 249 |
252 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { | 250 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { |
253 int offset = static_cast<int>(i * sizeof(Smi*)); | 251 int offset = static_cast<int>(i * sizeof(Smi*)); |
254 FieldAccess access = {kUntaggedBase, offset, Handle<Name>(), | 252 FieldAccess access = {kUntaggedBase, offset, Handle<Name>(), |
255 Type::Integral32(), kMachineTagged}; | 253 Type::Integral32(), mAnyTagged}; |
256 | 254 |
257 SimplifiedLoweringTester<Object*> t; | 255 SimplifiedLoweringTester<Object*> t; |
258 Node* load = t.LoadField(access, t.PointerConstant(smis)); | 256 Node* load = t.LoadField(access, t.PointerConstant(smis)); |
259 t.Return(load); | 257 t.Return(load); |
260 t.LowerAllNodes(); | 258 t.LowerAllNodes(); |
261 | 259 |
262 if (!Pipeline::SupportedTarget()) continue; | 260 if (!Pipeline::SupportedTarget()) continue; |
263 | 261 |
264 for (int j = -5; j <= 5; j++) { | 262 for (int j = -5; j <= 5; j++) { |
265 Smi* expected = Smi::FromInt(j); | 263 Smi* expected = Smi::FromInt(j); |
266 smis[i] = expected; | 264 smis[i] = expected; |
267 CHECK_EQ(expected, t.Call()); | 265 CHECK_EQ(expected, t.Call()); |
268 } | 266 } |
269 } | 267 } |
270 } | 268 } |
271 | 269 |
272 | 270 |
273 TEST(RunStoreFieldToUntaggedBase) { | 271 TEST(RunStoreFieldToUntaggedBase) { |
274 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)}; | 272 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3)}; |
275 | 273 |
276 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { | 274 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { |
277 int offset = static_cast<int>(i * sizeof(Smi*)); | 275 int offset = static_cast<int>(i * sizeof(Smi*)); |
278 FieldAccess access = {kUntaggedBase, offset, Handle<Name>(), | 276 FieldAccess access = {kUntaggedBase, offset, Handle<Name>(), |
279 Type::Integral32(), kMachineTagged}; | 277 Type::Integral32(), mAnyTagged}; |
280 | 278 |
281 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 279 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
282 Node* p0 = t.Parameter(0); | 280 Node* p0 = t.Parameter(0); |
283 t.StoreField(access, t.PointerConstant(smis), p0); | 281 t.StoreField(access, t.PointerConstant(smis), p0); |
284 t.Return(p0); | 282 t.Return(p0); |
285 t.LowerAllNodes(); | 283 t.LowerAllNodes(); |
286 | 284 |
287 if (!Pipeline::SupportedTarget()) continue; | 285 if (!Pipeline::SupportedTarget()) continue; |
288 | 286 |
289 for (int j = -5; j <= 5; j++) { | 287 for (int j = -5; j <= 5; j++) { |
290 Smi* expected = Smi::FromInt(j); | 288 Smi* expected = Smi::FromInt(j); |
291 smis[i] = Smi::FromInt(-100); | 289 smis[i] = Smi::FromInt(-100); |
292 CHECK_EQ(expected, t.Call(expected)); | 290 CHECK_EQ(expected, t.Call(expected)); |
293 CHECK_EQ(expected, smis[i]); | 291 CHECK_EQ(expected, smis[i]); |
294 } | 292 } |
295 } | 293 } |
296 } | 294 } |
297 | 295 |
298 | 296 |
299 TEST(RunLoadElementFromUntaggedBase) { | 297 TEST(RunLoadElementFromUntaggedBase) { |
300 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3), | 298 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3), |
301 Smi::FromInt(4), Smi::FromInt(5)}; | 299 Smi::FromInt(4), Smi::FromInt(5)}; |
302 | 300 |
303 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { // for header sizes | 301 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { // for header sizes |
304 for (size_t j = 0; (i + j) < ARRAY_SIZE(smis); j++) { // for element index | 302 for (size_t j = 0; (i + j) < ARRAY_SIZE(smis); j++) { // for element index |
305 int offset = static_cast<int>(i * sizeof(Smi*)); | 303 int offset = static_cast<int>(i * sizeof(Smi*)); |
306 ElementAccess access = {kUntaggedBase, offset, Type::Integral32(), | 304 ElementAccess access = {kUntaggedBase, offset, Type::Integral32(), |
307 kMachineTagged}; | 305 mAnyTagged}; |
308 | 306 |
309 SimplifiedLoweringTester<Object*> t; | 307 SimplifiedLoweringTester<Object*> t; |
310 Node* load = t.LoadElement(access, t.PointerConstant(smis), | 308 Node* load = t.LoadElement(access, t.PointerConstant(smis), |
311 t.Int32Constant(static_cast<int>(j))); | 309 t.Int32Constant(static_cast<int>(j))); |
312 t.Return(load); | 310 t.Return(load); |
313 t.LowerAllNodes(); | 311 t.LowerAllNodes(); |
314 | 312 |
315 if (!Pipeline::SupportedTarget()) continue; | 313 if (!Pipeline::SupportedTarget()) continue; |
316 | 314 |
317 for (int k = -5; k <= 5; k++) { | 315 for (int k = -5; k <= 5; k++) { |
318 Smi* expected = Smi::FromInt(k); | 316 Smi* expected = Smi::FromInt(k); |
319 smis[i + j] = expected; | 317 smis[i + j] = expected; |
320 CHECK_EQ(expected, t.Call()); | 318 CHECK_EQ(expected, t.Call()); |
321 } | 319 } |
322 } | 320 } |
323 } | 321 } |
324 } | 322 } |
325 | 323 |
326 | 324 |
327 TEST(RunStoreElementFromUntaggedBase) { | 325 TEST(RunStoreElementFromUntaggedBase) { |
328 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3), | 326 Smi* smis[] = {Smi::FromInt(1), Smi::FromInt(2), Smi::FromInt(3), |
329 Smi::FromInt(4), Smi::FromInt(5)}; | 327 Smi::FromInt(4), Smi::FromInt(5)}; |
330 | 328 |
331 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { // for header sizes | 329 for (size_t i = 0; i < ARRAY_SIZE(smis); i++) { // for header sizes |
332 for (size_t j = 0; (i + j) < ARRAY_SIZE(smis); j++) { // for element index | 330 for (size_t j = 0; (i + j) < ARRAY_SIZE(smis); j++) { // for element index |
333 int offset = static_cast<int>(i * sizeof(Smi*)); | 331 int offset = static_cast<int>(i * sizeof(Smi*)); |
334 ElementAccess access = {kUntaggedBase, offset, Type::Integral32(), | 332 ElementAccess access = {kUntaggedBase, offset, Type::Integral32(), |
335 kMachineTagged}; | 333 mAnyTagged}; |
336 | 334 |
337 SimplifiedLoweringTester<Object*> t(kMachineTagged); | 335 SimplifiedLoweringTester<Object*> t(mAnyTagged); |
338 Node* p0 = t.Parameter(0); | 336 Node* p0 = t.Parameter(0); |
339 t.StoreElement(access, t.PointerConstant(smis), | 337 t.StoreElement(access, t.PointerConstant(smis), |
340 t.Int32Constant(static_cast<int>(j)), p0); | 338 t.Int32Constant(static_cast<int>(j)), p0); |
341 t.Return(p0); | 339 t.Return(p0); |
342 t.LowerAllNodes(); | 340 t.LowerAllNodes(); |
343 | 341 |
344 if (!Pipeline::SupportedTarget()) continue; | 342 if (!Pipeline::SupportedTarget()) continue; |
345 | 343 |
346 for (int k = -5; k <= 5; k++) { | 344 for (int k = -5; k <= 5; k++) { |
347 Smi* expected = Smi::FromInt(k); | 345 Smi* expected = Smi::FromInt(k); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 550 } |
553 } | 551 } |
554 } | 552 } |
555 } | 553 } |
556 } | 554 } |
557 | 555 |
558 | 556 |
559 TEST(RunAccessTests_uint8) { | 557 TEST(RunAccessTests_uint8) { |
560 uint8_t data[] = {0x07, 0x16, 0x25, 0x34, 0x43, 0x99, | 558 uint8_t data[] = {0x07, 0x16, 0x25, 0x34, 0x43, 0x99, |
561 0xab, 0x78, 0x89, 0x19, 0x2b, 0x38}; | 559 0xab, 0x78, 0x89, 0x19, 0x2b, 0x38}; |
562 RunAccessTest<uint8_t>(kMachineWord8, data, ARRAY_SIZE(data)); | 560 RunAccessTest<uint8_t>(mInt8, data, ARRAY_SIZE(data)); |
563 } | 561 } |
564 | 562 |
565 | 563 |
566 TEST(RunAccessTests_uint16) { | 564 TEST(RunAccessTests_uint16) { |
567 uint16_t data[] = {0x071a, 0x162b, 0x253c, 0x344d, 0x435e, 0x7777}; | 565 uint16_t data[] = {0x071a, 0x162b, 0x253c, 0x344d, 0x435e, 0x7777}; |
568 RunAccessTest<uint16_t>(kMachineWord16, data, ARRAY_SIZE(data)); | 566 RunAccessTest<uint16_t>(mInt16, data, ARRAY_SIZE(data)); |
569 } | 567 } |
570 | 568 |
571 | 569 |
572 TEST(RunAccessTests_int32) { | 570 TEST(RunAccessTests_int32) { |
573 int32_t data[] = {-211, 211, 628347, 2000000000, -2000000000, -1, -100000034}; | 571 int32_t data[] = {-211, 211, 628347, 2000000000, -2000000000, -1, -100000034}; |
574 RunAccessTest<int32_t>(kMachineWord32, data, ARRAY_SIZE(data)); | 572 RunAccessTest<int32_t>(mInt32, data, ARRAY_SIZE(data)); |
575 } | 573 } |
576 | 574 |
577 | 575 |
578 #define V8_2PART_INT64(a, b) (((static_cast<int64_t>(a) << 32) + 0x##b##u)) | 576 #define V8_2PART_INT64(a, b) (((static_cast<int64_t>(a) << 32) + 0x##b##u)) |
579 | 577 |
580 | 578 |
581 TEST(RunAccessTests_int64) { | 579 TEST(RunAccessTests_int64) { |
582 if (kPointerSize != 8) return; | 580 if (kPointerSize != 8) return; |
583 int64_t data[] = {V8_2PART_INT64(0x10111213, 14151617), | 581 int64_t data[] = {V8_2PART_INT64(0x10111213, 14151617), |
584 V8_2PART_INT64(0x20212223, 24252627), | 582 V8_2PART_INT64(0x20212223, 24252627), |
585 V8_2PART_INT64(0x30313233, 34353637), | 583 V8_2PART_INT64(0x30313233, 34353637), |
586 V8_2PART_INT64(0xa0a1a2a3, a4a5a6a7), | 584 V8_2PART_INT64(0xa0a1a2a3, a4a5a6a7), |
587 V8_2PART_INT64(0xf0f1f2f3, f4f5f6f7)}; | 585 V8_2PART_INT64(0xf0f1f2f3, f4f5f6f7)}; |
588 RunAccessTest<int64_t>(kMachineWord64, data, ARRAY_SIZE(data)); | 586 RunAccessTest<int64_t>(mInt64, data, ARRAY_SIZE(data)); |
589 } | 587 } |
590 | 588 |
591 | 589 |
592 TEST(RunAccessTests_float64) { | 590 TEST(RunAccessTests_float64) { |
593 double data[] = {1.25, -1.25, 2.75, 11.0, 11100.8}; | 591 double data[] = {1.25, -1.25, 2.75, 11.0, 11100.8}; |
594 RunAccessTest<double>(kMachineFloat64, data, ARRAY_SIZE(data)); | 592 RunAccessTest<double>(mFloat64, data, ARRAY_SIZE(data)); |
595 } | 593 } |
596 | 594 |
597 | 595 |
598 TEST(RunAccessTests_Smi) { | 596 TEST(RunAccessTests_Smi) { |
599 Smi* data[] = {Smi::FromInt(-1), Smi::FromInt(-9), | 597 Smi* data[] = {Smi::FromInt(-1), Smi::FromInt(-9), |
600 Smi::FromInt(0), Smi::FromInt(666), | 598 Smi::FromInt(0), Smi::FromInt(666), |
601 Smi::FromInt(77777), Smi::FromInt(Smi::kMaxValue)}; | 599 Smi::FromInt(77777), Smi::FromInt(Smi::kMaxValue)}; |
602 RunAccessTest<Smi*>(kMachineTagged, data, ARRAY_SIZE(data)); | 600 RunAccessTest<Smi*>(mAnyTagged, data, ARRAY_SIZE(data)); |
603 } | 601 } |
604 | 602 |
605 | 603 |
606 // Fills in most of the nodes of the graph in order to make tests shorter. | 604 // Fills in most of the nodes of the graph in order to make tests shorter. |
607 class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders { | 605 class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders { |
608 public: | 606 public: |
609 Typer typer; | 607 Typer typer; |
610 JSGraph jsgraph; | 608 JSGraph jsgraph; |
611 Node* p0; | 609 Node* p0; |
612 Node* p1; | 610 Node* p1; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 649 |
652 // Inserts the node as the return value of the graph. | 650 // Inserts the node as the return value of the graph. |
653 Node* Return(Node* node) { | 651 Node* Return(Node* node) { |
654 ret->ReplaceInput(0, node); | 652 ret->ReplaceInput(0, node); |
655 return node; | 653 return node; |
656 } | 654 } |
657 | 655 |
658 // Inserts the node as the effect input to the return of the graph. | 656 // Inserts the node as the effect input to the return of the graph. |
659 void Effect(Node* node) { ret->ReplaceInput(1, node); } | 657 void Effect(Node* node) { ret->ReplaceInput(1, node); } |
660 | 658 |
661 Node* ExampleWithOutput(RepType type) { | 659 Node* ExampleWithOutput(MachineType type) { |
662 // TODO(titzer): use parameters with guaranteed representations. | 660 // TODO(titzer): use parameters with guaranteed representations. |
663 if (type & tInt32) { | 661 if (type & tInt32) { |
664 return graph()->NewNode(machine()->Int32Add(), jsgraph.Int32Constant(1), | 662 return graph()->NewNode(machine()->Int32Add(), jsgraph.Int32Constant(1), |
665 jsgraph.Int32Constant(1)); | 663 jsgraph.Int32Constant(1)); |
666 } else if (type & tUint32) { | 664 } else if (type & tUint32) { |
667 return graph()->NewNode(machine()->Word32Shr(), jsgraph.Int32Constant(1), | 665 return graph()->NewNode(machine()->Word32Shr(), jsgraph.Int32Constant(1), |
668 jsgraph.Int32Constant(1)); | 666 jsgraph.Int32Constant(1)); |
669 } else if (type & rFloat64) { | 667 } else if (type & rFloat64) { |
670 return graph()->NewNode(machine()->Float64Add(), | 668 return graph()->NewNode(machine()->Float64Add(), |
671 jsgraph.Float64Constant(1), | 669 jsgraph.Float64Constant(1), |
672 jsgraph.Float64Constant(1)); | 670 jsgraph.Float64Constant(1)); |
673 } else if (type & rBit) { | 671 } else if (type & rBit) { |
674 return graph()->NewNode(machine()->Word32Equal(), | 672 return graph()->NewNode(machine()->Word32Equal(), |
675 jsgraph.Int32Constant(1), | 673 jsgraph.Int32Constant(1), |
676 jsgraph.Int32Constant(1)); | 674 jsgraph.Int32Constant(1)); |
677 } else if (type & rWord64) { | 675 } else if (type & rWord64) { |
678 return graph()->NewNode(machine()->Int64Add(), Int64Constant(1), | 676 return graph()->NewNode(machine()->Int64Add(), Int64Constant(1), |
679 Int64Constant(1)); | 677 Int64Constant(1)); |
680 } else { | 678 } else { |
681 CHECK(type & rTagged); | 679 CHECK(type & rTagged); |
682 return p0; | 680 return p0; |
683 } | 681 } |
684 } | 682 } |
685 | 683 |
686 Node* Use(Node* node, RepType type) { | 684 Node* Use(Node* node, MachineType type) { |
687 if (type & tInt32) { | 685 if (type & tInt32) { |
688 return graph()->NewNode(machine()->Int32LessThan(), node, | 686 return graph()->NewNode(machine()->Int32LessThan(), node, |
689 jsgraph.Int32Constant(1)); | 687 jsgraph.Int32Constant(1)); |
690 } else if (type & tUint32) { | 688 } else if (type & tUint32) { |
691 return graph()->NewNode(machine()->Uint32LessThan(), node, | 689 return graph()->NewNode(machine()->Uint32LessThan(), node, |
692 jsgraph.Int32Constant(1)); | 690 jsgraph.Int32Constant(1)); |
693 } else if (type & rFloat64) { | 691 } else if (type & rFloat64) { |
694 return graph()->NewNode(machine()->Float64Add(), node, | 692 return graph()->NewNode(machine()->Float64Add(), node, |
695 jsgraph.Float64Constant(1)); | 693 jsgraph.Float64Constant(1)); |
696 } else if (type & rWord64) { | 694 } else if (type & rWord64) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 TestingGraph t(Type::String(), Type::String()); | 985 TestingGraph t(Type::String(), Type::String()); |
988 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringEqual()); | 986 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringEqual()); |
989 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringLessThan()); | 987 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringLessThan()); |
990 t.CheckLoweringBinop(IrOpcode::kCall, | 988 t.CheckLoweringBinop(IrOpcode::kCall, |
991 t.simplified()->StringLessThanOrEqual()); | 989 t.simplified()->StringLessThanOrEqual()); |
992 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringAdd()); | 990 t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringAdd()); |
993 } | 991 } |
994 } | 992 } |
995 | 993 |
996 | 994 |
997 void CheckChangeInsertion(IrOpcode::Value expected, RepType from, RepType to) { | 995 void CheckChangeInsertion(IrOpcode::Value expected, MachineType from, |
| 996 MachineType to) { |
998 TestingGraph t(Type::Any()); | 997 TestingGraph t(Type::Any()); |
999 Node* in = t.ExampleWithOutput(from); | 998 Node* in = t.ExampleWithOutput(from); |
1000 Node* use = t.Use(in, to); | 999 Node* use = t.Use(in, to); |
1001 t.Return(use); | 1000 t.Return(use); |
1002 t.Lower(); | 1001 t.Lower(); |
1003 CHECK_EQ(expected, use->InputAt(0)->opcode()); | 1002 CHECK_EQ(expected, use->InputAt(0)->opcode()); |
1004 CHECK_EQ(in, use->InputAt(0)->InputAt(0)); | 1003 CHECK_EQ(in, use->InputAt(0)->InputAt(0)); |
1005 } | 1004 } |
1006 | 1005 |
1007 | 1006 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 Int32Matcher index = Int32Matcher(load_or_store->InputAt(1)); | 1115 Int32Matcher index = Int32Matcher(load_or_store->InputAt(1)); |
1117 CHECK(index.Is(access.offset - access.tag())); | 1116 CHECK(index.Is(access.offset - access.tag())); |
1118 } | 1117 } |
1119 | 1118 |
1120 | 1119 |
1121 Node* CheckElementAccessArithmetic(ElementAccess access, Node* load_or_store) { | 1120 Node* CheckElementAccessArithmetic(ElementAccess access, Node* load_or_store) { |
1122 Int32BinopMatcher index(load_or_store->InputAt(1)); | 1121 Int32BinopMatcher index(load_or_store->InputAt(1)); |
1123 CHECK_EQ(IrOpcode::kInt32Add, index.node()->opcode()); | 1122 CHECK_EQ(IrOpcode::kInt32Add, index.node()->opcode()); |
1124 CHECK(index.right().Is(access.header_size - access.tag())); | 1123 CHECK(index.right().Is(access.header_size - access.tag())); |
1125 | 1124 |
1126 int element_size = 0; | 1125 int element_size = ElementSizeOf(access.machine_type); |
1127 switch (access.representation) { | |
1128 case kMachineTagged: | |
1129 element_size = kPointerSize; | |
1130 break; | |
1131 case kMachineWord8: | |
1132 element_size = 1; | |
1133 break; | |
1134 case kMachineWord16: | |
1135 element_size = 2; | |
1136 break; | |
1137 case kMachineWord32: | |
1138 element_size = 4; | |
1139 break; | |
1140 case kMachineWord64: | |
1141 case kMachineFloat64: | |
1142 element_size = 8; | |
1143 break; | |
1144 case kMachineLast: | |
1145 UNREACHABLE(); | |
1146 break; | |
1147 } | |
1148 | 1126 |
1149 if (element_size != 1) { | 1127 if (element_size != 1) { |
1150 Int32BinopMatcher mul(index.left().node()); | 1128 Int32BinopMatcher mul(index.left().node()); |
1151 CHECK_EQ(IrOpcode::kInt32Mul, mul.node()->opcode()); | 1129 CHECK_EQ(IrOpcode::kInt32Mul, mul.node()->opcode()); |
1152 CHECK(mul.right().Is(element_size)); | 1130 CHECK(mul.right().Is(element_size)); |
1153 return mul.left().node(); | 1131 return mul.left().node(); |
1154 } else { | 1132 } else { |
1155 return index.left().node(); | 1133 return index.left().node(); |
1156 } | 1134 } |
1157 } | 1135 } |
1158 | 1136 |
1159 | 1137 |
1160 static const MachineType machine_reps[] = {kMachineWord8, kMachineWord16, | 1138 static const MachineType machine_reps[] = {rBit, mInt8, mInt16, mInt32, |
1161 kMachineWord32, kMachineWord64, | 1139 mInt64, mFloat64, mAnyTagged}; |
1162 kMachineFloat64, kMachineTagged}; | |
1163 | |
1164 | |
1165 // Representation types corresponding to those above. | |
1166 static const RepType rep_types[] = {static_cast<RepType>(rWord32 | tUint32), | |
1167 static_cast<RepType>(rWord32 | tUint32), | |
1168 static_cast<RepType>(rWord32 | tInt32), | |
1169 static_cast<RepType>(rWord64), | |
1170 static_cast<RepType>(rFloat64 | tNumber), | |
1171 static_cast<RepType>(rTagged | tAny)}; | |
1172 | 1140 |
1173 | 1141 |
1174 TEST(LowerLoadField_to_load) { | 1142 TEST(LowerLoadField_to_load) { |
1175 TestingGraph t(Type::Any(), Type::Signed32()); | 1143 TestingGraph t(Type::Any(), Type::Signed32()); |
1176 | 1144 |
1177 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { | 1145 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { |
1178 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1146 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1179 Handle<Name>::null(), Type::Any(), machine_reps[i]}; | 1147 Handle<Name>::null(), Type::Any(), machine_reps[i]}; |
1180 | 1148 |
1181 Node* load = | 1149 Node* load = |
1182 t.graph()->NewNode(t.simplified()->LoadField(access), t.p0, t.start); | 1150 t.graph()->NewNode(t.simplified()->LoadField(access), t.p0, t.start); |
1183 Node* use = t.Use(load, rep_types[i]); | 1151 Node* use = t.Use(load, machine_reps[i]); |
1184 t.Return(use); | 1152 t.Return(use); |
1185 t.Lower(); | 1153 t.Lower(); |
1186 CHECK_EQ(IrOpcode::kLoad, load->opcode()); | 1154 CHECK_EQ(IrOpcode::kLoad, load->opcode()); |
1187 CHECK_EQ(t.p0, load->InputAt(0)); | 1155 CHECK_EQ(t.p0, load->InputAt(0)); |
1188 CheckFieldAccessArithmetic(access, load); | 1156 CheckFieldAccessArithmetic(access, load); |
1189 | 1157 |
1190 MachineType rep = OpParameter<MachineType>(load); | 1158 MachineType rep = OpParameter<MachineType>(load); |
1191 CHECK_EQ(machine_reps[i], rep); | 1159 CHECK_EQ(machine_reps[i], rep); |
1192 } | 1160 } |
1193 } | 1161 } |
1194 | 1162 |
1195 | 1163 |
1196 TEST(LowerStoreField_to_store) { | 1164 TEST(LowerStoreField_to_store) { |
1197 TestingGraph t(Type::Any(), Type::Signed32()); | 1165 TestingGraph t(Type::Any(), Type::Signed32()); |
1198 | 1166 |
1199 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { | 1167 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { |
1200 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1168 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1201 Handle<Name>::null(), Type::Any(), machine_reps[i]}; | 1169 Handle<Name>::null(), Type::Any(), machine_reps[i]}; |
1202 | 1170 |
1203 | 1171 |
1204 Node* val = t.ExampleWithOutput(rep_types[i]); | 1172 Node* val = t.ExampleWithOutput(machine_reps[i]); |
1205 Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0, | 1173 Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0, |
1206 val, t.start, t.start); | 1174 val, t.start, t.start); |
1207 t.Effect(store); | 1175 t.Effect(store); |
1208 t.Lower(); | 1176 t.Lower(); |
1209 CHECK_EQ(IrOpcode::kStore, store->opcode()); | 1177 CHECK_EQ(IrOpcode::kStore, store->opcode()); |
1210 CHECK_EQ(val, store->InputAt(2)); | 1178 CHECK_EQ(val, store->InputAt(2)); |
1211 CheckFieldAccessArithmetic(access, store); | 1179 CheckFieldAccessArithmetic(access, store); |
1212 | 1180 |
1213 StoreRepresentation rep = OpParameter<StoreRepresentation>(store); | 1181 StoreRepresentation rep = OpParameter<StoreRepresentation>(store); |
1214 if (rep_types[i] & rTagged) { | 1182 if (machine_reps[i] & rTagged) { |
1215 CHECK_EQ(kFullWriteBarrier, rep.write_barrier_kind); | 1183 CHECK_EQ(kFullWriteBarrier, rep.write_barrier_kind); |
1216 } | 1184 } |
1217 CHECK_EQ(machine_reps[i], rep.rep); | 1185 CHECK_EQ(machine_reps[i], rep.machine_type); |
1218 } | 1186 } |
1219 } | 1187 } |
1220 | 1188 |
1221 | 1189 |
1222 TEST(LowerLoadElement_to_load) { | 1190 TEST(LowerLoadElement_to_load) { |
1223 TestingGraph t(Type::Any(), Type::Signed32()); | 1191 TestingGraph t(Type::Any(), Type::Signed32()); |
1224 | 1192 |
1225 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { | 1193 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { |
1226 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1194 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1227 Type::Any(), machine_reps[i]}; | 1195 Type::Any(), machine_reps[i]}; |
1228 | 1196 |
1229 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, | 1197 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, |
1230 t.p1, t.start); | 1198 t.p1, t.start); |
1231 Node* use = t.Use(load, rep_types[i]); | 1199 Node* use = t.Use(load, machine_reps[i]); |
1232 t.Return(use); | 1200 t.Return(use); |
1233 t.Lower(); | 1201 t.Lower(); |
1234 CHECK_EQ(IrOpcode::kLoad, load->opcode()); | 1202 CHECK_EQ(IrOpcode::kLoad, load->opcode()); |
1235 CHECK_EQ(t.p0, load->InputAt(0)); | 1203 CHECK_EQ(t.p0, load->InputAt(0)); |
1236 CheckElementAccessArithmetic(access, load); | 1204 CheckElementAccessArithmetic(access, load); |
1237 | 1205 |
1238 MachineType rep = OpParameter<MachineType>(load); | 1206 MachineType rep = OpParameter<MachineType>(load); |
1239 CHECK_EQ(machine_reps[i], rep); | 1207 CHECK_EQ(machine_reps[i], rep); |
1240 } | 1208 } |
1241 } | 1209 } |
1242 | 1210 |
1243 | 1211 |
1244 TEST(LowerStoreElement_to_store) { | 1212 TEST(LowerStoreElement_to_store) { |
1245 TestingGraph t(Type::Any(), Type::Signed32()); | 1213 TestingGraph t(Type::Any(), Type::Signed32()); |
1246 | 1214 |
1247 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { | 1215 for (size_t i = 0; i < ARRAY_SIZE(machine_reps); i++) { |
1248 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1216 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1249 Type::Any(), machine_reps[i]}; | 1217 Type::Any(), machine_reps[i]}; |
1250 | 1218 |
1251 Node* val = t.ExampleWithOutput(rep_types[i]); | 1219 Node* val = t.ExampleWithOutput(machine_reps[i]); |
1252 Node* store = t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, | 1220 Node* store = t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, |
1253 t.p1, val, t.start, t.start); | 1221 t.p1, val, t.start, t.start); |
1254 t.Effect(store); | 1222 t.Effect(store); |
1255 t.Lower(); | 1223 t.Lower(); |
1256 CHECK_EQ(IrOpcode::kStore, store->opcode()); | 1224 CHECK_EQ(IrOpcode::kStore, store->opcode()); |
1257 CHECK_EQ(val, store->InputAt(2)); | 1225 CHECK_EQ(val, store->InputAt(2)); |
1258 CheckElementAccessArithmetic(access, store); | 1226 CheckElementAccessArithmetic(access, store); |
1259 | 1227 |
1260 StoreRepresentation rep = OpParameter<StoreRepresentation>(store); | 1228 StoreRepresentation rep = OpParameter<StoreRepresentation>(store); |
1261 if (rep_types[i] & rTagged) { | 1229 if (machine_reps[i] & rTagged) { |
1262 CHECK_EQ(kFullWriteBarrier, rep.write_barrier_kind); | 1230 CHECK_EQ(kFullWriteBarrier, rep.write_barrier_kind); |
1263 } | 1231 } |
1264 CHECK_EQ(machine_reps[i], rep.rep); | 1232 CHECK_EQ(machine_reps[i], rep.machine_type); |
1265 } | 1233 } |
1266 } | 1234 } |
1267 | 1235 |
1268 | 1236 |
1269 TEST(InsertChangeForLoadElementIndex) { | 1237 TEST(InsertChangeForLoadElementIndex) { |
1270 // LoadElement(obj: Tagged, index: tInt32 | rTagged) => | 1238 // LoadElement(obj: Tagged, index: tInt32 | rTagged) => |
1271 // Load(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k)) | 1239 // Load(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k)) |
1272 TestingGraph t(Type::Any(), Type::Signed32()); | 1240 TestingGraph t(Type::Any(), Type::Signed32()); |
1273 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), | 1241 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
1274 kMachineTagged}; | 1242 mAnyTagged}; |
1275 | 1243 |
1276 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, | 1244 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, |
1277 t.p1, t.start); | 1245 t.p1, t.start); |
1278 t.Return(load); | 1246 t.Return(load); |
1279 t.Lower(); | 1247 t.Lower(); |
1280 CHECK_EQ(IrOpcode::kLoad, load->opcode()); | 1248 CHECK_EQ(IrOpcode::kLoad, load->opcode()); |
1281 CHECK_EQ(t.p0, load->InputAt(0)); | 1249 CHECK_EQ(t.p0, load->InputAt(0)); |
1282 | 1250 |
1283 Node* index = CheckElementAccessArithmetic(access, load); | 1251 Node* index = CheckElementAccessArithmetic(access, load); |
1284 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, index); | 1252 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, index); |
1285 } | 1253 } |
1286 | 1254 |
1287 | 1255 |
1288 TEST(InsertChangeForStoreElementIndex) { | 1256 TEST(InsertChangeForStoreElementIndex) { |
1289 // StoreElement(obj: Tagged, index: tInt32 | rTagged, val) => | 1257 // StoreElement(obj: Tagged, index: tInt32 | rTagged, val) => |
1290 // Store(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k), val) | 1258 // Store(obj, Int32Add(Int32Mul(ChangeTaggedToInt32(index), #k), #k), val) |
1291 TestingGraph t(Type::Any(), Type::Signed32()); | 1259 TestingGraph t(Type::Any(), Type::Signed32()); |
1292 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), | 1260 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
1293 kMachineTagged}; | 1261 mAnyTagged}; |
1294 | 1262 |
1295 Node* store = | 1263 Node* store = |
1296 t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, t.p1, | 1264 t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, t.p1, |
1297 t.jsgraph.TrueConstant(), t.start, t.start); | 1265 t.jsgraph.TrueConstant(), t.start, t.start); |
1298 t.Effect(store); | 1266 t.Effect(store); |
1299 t.Lower(); | 1267 t.Lower(); |
1300 CHECK_EQ(IrOpcode::kStore, store->opcode()); | 1268 CHECK_EQ(IrOpcode::kStore, store->opcode()); |
1301 CHECK_EQ(t.p0, store->InputAt(0)); | 1269 CHECK_EQ(t.p0, store->InputAt(0)); |
1302 | 1270 |
1303 Node* index = CheckElementAccessArithmetic(access, store); | 1271 Node* index = CheckElementAccessArithmetic(access, store); |
1304 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, index); | 1272 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p1, index); |
1305 } | 1273 } |
1306 | 1274 |
1307 | 1275 |
1308 TEST(InsertChangeForLoadElement) { | 1276 TEST(InsertChangeForLoadElement) { |
1309 // TODO(titzer): test all load/store representation change insertions. | 1277 // TODO(titzer): test all load/store representation change insertions. |
1310 TestingGraph t(Type::Any(), Type::Signed32()); | 1278 TestingGraph t(Type::Any(), Type::Signed32()); |
1311 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), | 1279 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
1312 kMachineFloat64}; | 1280 mFloat64}; |
1313 | 1281 |
1314 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, | 1282 Node* load = t.graph()->NewNode(t.simplified()->LoadElement(access), t.p0, |
1315 t.p1, t.start); | 1283 t.p1, t.start); |
1316 t.Return(load); | 1284 t.Return(load); |
1317 t.Lower(); | 1285 t.Lower(); |
1318 CHECK_EQ(IrOpcode::kLoad, load->opcode()); | 1286 CHECK_EQ(IrOpcode::kLoad, load->opcode()); |
1319 CHECK_EQ(t.p0, load->InputAt(0)); | 1287 CHECK_EQ(t.p0, load->InputAt(0)); |
1320 CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0)); | 1288 CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0)); |
1321 } | 1289 } |
1322 | 1290 |
1323 | 1291 |
1324 TEST(InsertChangeForLoadField) { | 1292 TEST(InsertChangeForLoadField) { |
1325 // TODO(titzer): test all load/store representation change insertions. | 1293 // TODO(titzer): test all load/store representation change insertions. |
1326 TestingGraph t(Type::Any(), Type::Signed32()); | 1294 TestingGraph t(Type::Any(), Type::Signed32()); |
1327 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1295 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1328 Handle<Name>::null(), Type::Any(), kMachineFloat64}; | 1296 Handle<Name>::null(), Type::Any(), mFloat64}; |
1329 | 1297 |
1330 Node* load = | 1298 Node* load = |
1331 t.graph()->NewNode(t.simplified()->LoadField(access), t.p0, t.start); | 1299 t.graph()->NewNode(t.simplified()->LoadField(access), t.p0, t.start); |
1332 t.Return(load); | 1300 t.Return(load); |
1333 t.Lower(); | 1301 t.Lower(); |
1334 CHECK_EQ(IrOpcode::kLoad, load->opcode()); | 1302 CHECK_EQ(IrOpcode::kLoad, load->opcode()); |
1335 CHECK_EQ(t.p0, load->InputAt(0)); | 1303 CHECK_EQ(t.p0, load->InputAt(0)); |
1336 CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0)); | 1304 CheckChangeOf(IrOpcode::kChangeFloat64ToTagged, load, t.ret->InputAt(0)); |
1337 } | 1305 } |
1338 | 1306 |
1339 | 1307 |
1340 TEST(InsertChangeForStoreElement) { | 1308 TEST(InsertChangeForStoreElement) { |
1341 // TODO(titzer): test all load/store representation change insertions. | 1309 // TODO(titzer): test all load/store representation change insertions. |
1342 TestingGraph t(Type::Any(), Type::Signed32()); | 1310 TestingGraph t(Type::Any(), Type::Signed32()); |
1343 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), | 1311 ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(), |
1344 kMachineFloat64}; | 1312 mFloat64}; |
1345 | 1313 |
1346 Node* store = | 1314 Node* store = |
1347 t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, | 1315 t.graph()->NewNode(t.simplified()->StoreElement(access), t.p0, |
1348 t.jsgraph.Int32Constant(0), t.p1, t.start, t.start); | 1316 t.jsgraph.Int32Constant(0), t.p1, t.start, t.start); |
1349 t.Effect(store); | 1317 t.Effect(store); |
1350 t.Lower(); | 1318 t.Lower(); |
1351 | 1319 |
1352 CHECK_EQ(IrOpcode::kStore, store->opcode()); | 1320 CHECK_EQ(IrOpcode::kStore, store->opcode()); |
1353 CHECK_EQ(t.p0, store->InputAt(0)); | 1321 CHECK_EQ(t.p0, store->InputAt(0)); |
1354 CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(2)); | 1322 CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(2)); |
1355 } | 1323 } |
1356 | 1324 |
1357 | 1325 |
1358 TEST(InsertChangeForStoreField) { | 1326 TEST(InsertChangeForStoreField) { |
1359 // TODO(titzer): test all load/store representation change insertions. | 1327 // TODO(titzer): test all load/store representation change insertions. |
1360 TestingGraph t(Type::Any(), Type::Signed32()); | 1328 TestingGraph t(Type::Any(), Type::Signed32()); |
1361 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, | 1329 FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, |
1362 Handle<Name>::null(), Type::Any(), kMachineFloat64}; | 1330 Handle<Name>::null(), Type::Any(), mFloat64}; |
1363 | 1331 |
1364 Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0, | 1332 Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0, |
1365 t.p1, t.start, t.start); | 1333 t.p1, t.start, t.start); |
1366 t.Effect(store); | 1334 t.Effect(store); |
1367 t.Lower(); | 1335 t.Lower(); |
1368 | 1336 |
1369 CHECK_EQ(IrOpcode::kStore, store->opcode()); | 1337 CHECK_EQ(IrOpcode::kStore, store->opcode()); |
1370 CHECK_EQ(t.p0, store->InputAt(0)); | 1338 CHECK_EQ(t.p0, store->InputAt(0)); |
1371 CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(2)); | 1339 CheckChangeOf(IrOpcode::kChangeTaggedToFloat64, t.p1, store->InputAt(2)); |
1372 } | 1340 } |
OLD | NEW |