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

Side by Side Diff: runtime/vm/flow_graph_compiler_x64.cc

Issue 18807007: Fix wrong type test optimization when testing against a signature class: we must always consider th… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | « runtime/vm/flow_graph_compiler_mips.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/flow_graph_compiler.h" 8 #include "vm/flow_graph_compiler.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // Clobbers R10. 220 // Clobbers R10.
221 RawSubtypeTestCache* 221 RawSubtypeTestCache*
222 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( 222 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest(
223 intptr_t token_pos, 223 intptr_t token_pos,
224 const AbstractType& type, 224 const AbstractType& type,
225 Label* is_instance_lbl, 225 Label* is_instance_lbl,
226 Label* is_not_instance_lbl) { 226 Label* is_not_instance_lbl) {
227 __ Comment("InstantiatedTypeWithArgumentsTest"); 227 __ Comment("InstantiatedTypeWithArgumentsTest");
228 ASSERT(type.IsInstantiated()); 228 ASSERT(type.IsInstantiated());
229 const Class& type_class = Class::ZoneHandle(type.type_class()); 229 const Class& type_class = Class::ZoneHandle(type.type_class());
230 ASSERT(type_class.HasTypeArguments()); 230 ASSERT(type_class.HasTypeArguments() || type_class.IsSignatureClass());
231 const Register kInstanceReg = RAX; 231 const Register kInstanceReg = RAX;
232 Error& malformed_error = Error::Handle(); 232 Error& malformed_error = Error::Handle();
233 const Type& int_type = Type::Handle(Type::IntType()); 233 const Type& int_type = Type::Handle(Type::IntType());
234 const bool smi_is_ok = int_type.IsSubtypeOf(type, &malformed_error); 234 const bool smi_is_ok = int_type.IsSubtypeOf(type, &malformed_error);
235 // Malforrmed type should have been handled at graph construction time. 235 // Malformed type should have been handled at graph construction time.
236 ASSERT(smi_is_ok || malformed_error.IsNull()); 236 ASSERT(smi_is_ok || malformed_error.IsNull());
237 __ testq(kInstanceReg, Immediate(kSmiTagMask)); 237 __ testq(kInstanceReg, Immediate(kSmiTagMask));
238 if (smi_is_ok) { 238 if (smi_is_ok) {
239 __ j(ZERO, is_instance_lbl); 239 __ j(ZERO, is_instance_lbl);
240 } else { 240 } else {
241 __ j(ZERO, is_not_instance_lbl); 241 __ j(ZERO, is_not_instance_lbl);
242 } 242 }
243 const AbstractTypeArguments& type_arguments = 243 const AbstractTypeArguments& type_arguments =
244 AbstractTypeArguments::ZoneHandle(type.arguments()); 244 AbstractTypeArguments::ZoneHandle(type.arguments());
245 const bool is_raw_type = type_arguments.IsNull() || 245 const bool is_raw_type = type_arguments.IsNull() ||
246 type_arguments.IsRaw(type_arguments.Length()); 246 type_arguments.IsRaw(type_arguments.Length());
247 if (is_raw_type) { 247 // Signature class is an instantiated parameterized type.
248 const Register kClassIdReg = R10; 248 if (!type_class.IsSignatureClass()) {
249 // dynamic type argument, check only classes. 249 if (is_raw_type) {
250 __ LoadClassId(kClassIdReg, kInstanceReg); 250 const Register kClassIdReg = R10;
251 __ cmpl(kClassIdReg, Immediate(type_class.id())); 251 // dynamic type argument, check only classes.
252 __ j(EQUAL, is_instance_lbl); 252 __ LoadClassId(kClassIdReg, kInstanceReg);
253 // List is a very common case. 253 __ cmpl(kClassIdReg, Immediate(type_class.id()));
254 if (IsListClass(type_class)) { 254 __ j(EQUAL, is_instance_lbl);
255 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); 255 // List is a very common case.
256 if (IsListClass(type_class)) {
257 GenerateListTypeCheck(kClassIdReg, is_instance_lbl);
258 }
259 return GenerateSubtype1TestCacheLookup(
260 token_pos, type_class, is_instance_lbl, is_not_instance_lbl);
256 } 261 }
257 return GenerateSubtype1TestCacheLookup( 262 // If one type argument only, check if type argument is Object or dynamic.
258 token_pos, type_class, is_instance_lbl, is_not_instance_lbl); 263 if (type_arguments.Length() == 1) {
259 } 264 const AbstractType& tp_argument = AbstractType::ZoneHandle(
260 // If one type argument only, check if type argument is Object or dynamic. 265 type_arguments.TypeAt(0));
261 if (type_arguments.Length() == 1) { 266 ASSERT(!tp_argument.IsMalformed());
262 const AbstractType& tp_argument = AbstractType::ZoneHandle( 267 if (tp_argument.IsType()) {
263 type_arguments.TypeAt(0)); 268 ASSERT(tp_argument.HasResolvedTypeClass());
264 ASSERT(!tp_argument.IsMalformed()); 269 // Check if type argument is dynamic or Object.
265 if (tp_argument.IsType()) { 270 const Type& object_type = Type::Handle(Type::ObjectType());
266 ASSERT(tp_argument.HasResolvedTypeClass()); 271 if (object_type.IsSubtypeOf(tp_argument, NULL)) {
267 // Check if type argument is dynamic or Object. 272 // Instance class test only necessary.
268 const Type& object_type = Type::Handle(Type::ObjectType()); 273 return GenerateSubtype1TestCacheLookup(
269 if (object_type.IsSubtypeOf(tp_argument, NULL)) { 274 token_pos, type_class, is_instance_lbl, is_not_instance_lbl);
270 // Instance class test only necessary. 275 }
271 return GenerateSubtype1TestCacheLookup(
272 token_pos, type_class, is_instance_lbl, is_not_instance_lbl);
273 } 276 }
274 } 277 }
275 } 278 }
276 // Regular subtype test cache involving instance's type arguments. 279 // Regular subtype test cache involving instance's type arguments.
277 const Register kTypeArgumentsReg = kNoRegister; 280 const Register kTypeArgumentsReg = kNoRegister;
278 const Register kTempReg = R10; 281 const Register kTempReg = R10;
279 return GenerateCallSubtypeTestStub(kTestTypeTwoArgs, 282 return GenerateCallSubtypeTestStub(kTestTypeTwoArgs,
280 kInstanceReg, 283 kInstanceReg,
281 kTypeArgumentsReg, 284 kTypeArgumentsReg,
282 kTempReg, 285 kTempReg,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 __ j(ZERO, is_not_instance_lbl); 515 __ j(ZERO, is_not_instance_lbl);
513 __ CompareClassId(kInstanceReg, type_cid); 516 __ CompareClassId(kInstanceReg, type_cid);
514 __ j(EQUAL, is_instance_lbl); 517 __ j(EQUAL, is_instance_lbl);
515 } 518 }
516 __ jmp(is_not_instance_lbl); 519 __ jmp(is_not_instance_lbl);
517 return SubtypeTestCache::null(); 520 return SubtypeTestCache::null();
518 } 521 }
519 if (type.IsInstantiated()) { 522 if (type.IsInstantiated()) {
520 const Class& type_class = Class::ZoneHandle(type.type_class()); 523 const Class& type_class = Class::ZoneHandle(type.type_class());
521 // A class equality check is only applicable with a dst type of a 524 // A class equality check is only applicable with a dst type of a
522 // non-parameterized class or with a raw dst type of a parameterized class. 525 // non-parameterized class, non-signature class, or with a raw dst type of
523 if (type_class.HasTypeArguments()) { 526 // a parameterized class.
527 if (type_class.IsSignatureClass() || type_class.HasTypeArguments()) {
524 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, 528 return GenerateInstantiatedTypeWithArgumentsTest(token_pos,
525 type, 529 type,
526 is_instance_lbl, 530 is_instance_lbl,
527 is_not_instance_lbl); 531 is_not_instance_lbl);
528 // Fall through to runtime call. 532 // Fall through to runtime call.
529 } 533 }
530 const bool has_fall_through = 534 const bool has_fall_through =
531 GenerateInstantiatedTypeNoArgumentsTest(token_pos, 535 GenerateInstantiatedTypeNoArgumentsTest(token_pos,
532 type, 536 type,
533 is_instance_lbl, 537 is_instance_lbl,
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 __ movups(reg, Address(RSP, 0)); 1889 __ movups(reg, Address(RSP, 0));
1886 __ addq(RSP, Immediate(kFpuRegisterSize)); 1890 __ addq(RSP, Immediate(kFpuRegisterSize));
1887 } 1891 }
1888 1892
1889 1893
1890 #undef __ 1894 #undef __
1891 1895
1892 } // namespace dart 1896 } // namespace dart
1893 1897
1894 #endif // defined TARGET_ARCH_X64 1898 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698