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

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

Issue 10808035: Apply Kevin's suggestions, make branch-compare generation more robust (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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/intermediate_language.h ('k') | runtime/vm/intermediate_language_x64.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 try_index(), 185 try_index(),
186 kConditionTypeErrorRuntimeEntry); 186 kConditionTypeErrorRuntimeEntry);
187 // We should never return here. 187 // We should never return here.
188 __ int3(); 188 __ int3();
189 189
190 __ Bind(&done); 190 __ Bind(&done);
191 ASSERT(obj == result); 191 ASSERT(obj == result);
192 } 192 }
193 193
194 194
195 static Condition TokenKindToSmiCondition(Token::Kind kind) {
196 switch (kind) {
197 case Token::kEQ: return EQUAL;
198 case Token::kNE: return NOT_EQUAL;
199 case Token::kLT: return LESS;
200 case Token::kGT: return GREATER;
201 case Token::kLTE: return LESS_EQUAL;
202 case Token::kGTE: return GREATER_EQUAL;
203 default:
204 UNREACHABLE();
205 return OVERFLOW;
206 }
207 }
208
209
195 LocationSummary* EqualityCompareComp::MakeLocationSummary() const { 210 LocationSummary* EqualityCompareComp::MakeLocationSummary() const {
196 const intptr_t kNumInputs = 2; 211 const intptr_t kNumInputs = 2;
197 if (receiver_class_id() != kObject) { 212 if (receiver_class_id() != kObject) {
198 ASSERT((receiver_class_id() == kSmi) || (receiver_class_id() == kDouble)); 213 ASSERT((receiver_class_id() == kSmi) || (receiver_class_id() == kDouble));
199 const intptr_t kNumTemps = 1; 214 const intptr_t kNumTemps = 1;
200 LocationSummary* locs = new LocationSummary(kNumInputs, 215 LocationSummary* locs = new LocationSummary(kNumInputs,
201 kNumTemps, 216 kNumTemps,
202 LocationSummary::kNoCall); 217 LocationSummary::kNoCall);
203 locs->set_in(0, Location::RequiresRegister()); 218 locs->set_in(0, Location::RequiresRegister());
204 locs->set_in(1, Location::RequiresRegister()); 219 locs->set_in(1, Location::RequiresRegister());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 kDeoptSmiCompareSmi, 256 kDeoptSmiCompareSmi,
242 left, 257 left,
243 right); 258 right);
244 __ movl(temp, left); 259 __ movl(temp, left);
245 __ orl(temp, right); 260 __ orl(temp, right);
246 __ testl(temp, Immediate(kSmiTagMask)); 261 __ testl(temp, Immediate(kSmiTagMask));
247 __ j(NOT_ZERO, deopt); 262 __ j(NOT_ZERO, deopt);
248 __ cmpl(left, right); 263 __ cmpl(left, right);
249 Register result = comp->locs()->out().reg(); 264 Register result = comp->locs()->out().reg();
250 Label load_true, done; 265 Label load_true, done;
251 __ j(EQUAL, &load_true, Assembler::kNearJump); 266 __ j(TokenKindToSmiCondition(comp->kind()), &load_true, Assembler::kNearJump);
252 __ LoadObject(result, compiler->bool_false()); 267 __ LoadObject(result, compiler->bool_false());
253 __ jmp(&done, Assembler::kNearJump); 268 __ jmp(&done, Assembler::kNearJump);
254 __ Bind(&load_true); 269 __ Bind(&load_true);
255 __ LoadObject(result, compiler->bool_true()); 270 __ LoadObject(result, compiler->bool_true());
256 __ Bind(&done); 271 __ Bind(&done);
257 } 272 }
258 273
259 274
260 // TODO(srdjan): Add support for mixed Smi/Double equality 275 // TODO(srdjan): Add support for mixed Smi/Double equality
261 // (see LoadDoubleOrSmiToXmm). 276 // (see LoadDoubleOrSmiToXmm).
262 static void EmitDoubleEqualityCompare(FlowGraphCompiler* compiler, 277 static void EmitDoubleEqualityCompare(FlowGraphCompiler* compiler,
263 EqualityCompareComp* comp) { 278 EqualityCompareComp* comp) {
264 Register left = comp->locs()->in(0).reg(); 279 Register left = comp->locs()->in(0).reg();
265 Register right = comp->locs()->in(1).reg(); 280 Register right = comp->locs()->in(1).reg();
266 Register temp = comp->locs()->temp(0).reg(); 281 Register temp = comp->locs()->temp(0).reg();
267 Label* deopt = compiler->AddDeoptStub(comp->cid(), 282 Label* deopt = compiler->AddDeoptStub(comp->cid(),
268 comp->token_pos(), 283 comp->token_pos(),
269 comp->try_index(), 284 comp->try_index(),
270 kDeoptDoubleCompareDouble, 285 kDeoptDoubleCompareDouble,
271 left, 286 left,
272 right); 287 right);
273 Label done, is_false, is_true; 288 Label done, is_false, is_true;
274 __ CompareClassId(left, kDouble, temp); 289 __ CompareClassId(left, kDouble, temp);
275 __ j(NOT_EQUAL, deopt); 290 __ j(NOT_EQUAL, deopt);
276 __ CompareClassId(right, kDouble, temp); 291 __ CompareClassId(right, kDouble, temp);
277 __ j(NOT_EQUAL, deopt); 292 __ j(NOT_EQUAL, deopt);
278 __ movsd(XMM0, FieldAddress(left, Double::value_offset())); 293 __ movsd(XMM0, FieldAddress(left, Double::value_offset()));
279 __ movsd(XMM1, FieldAddress(right, Double::value_offset())); 294 __ movsd(XMM1, FieldAddress(right, Double::value_offset()));
280 compiler->EmitDoubleCompareBool( 295 compiler->EmitDoubleCompareBool(TokenKindToSmiCondition(comp->kind()),
281 EQUAL, XMM0, XMM1, comp->locs()->out().reg()); 296 XMM0, XMM1,
297 comp->locs()->out().reg());
282 } 298 }
283 299
284 300
285 static void EmitEqualityAsInstanceCall(FlowGraphCompiler* compiler, 301 static void EmitEqualityAsInstanceCall(FlowGraphCompiler* compiler,
286 EqualityCompareComp* comp) { 302 EqualityCompareComp* comp) {
287 compiler->AddCurrentDescriptor(PcDescriptors::kDeopt, 303 compiler->AddCurrentDescriptor(PcDescriptors::kDeopt,
288 comp->cid(), 304 comp->cid(),
289 comp->token_pos(), 305 comp->token_pos(),
290 comp->try_index()); 306 comp->try_index());
291 const String& operator_name = String::ZoneHandle(String::NewSymbol("==")); 307 const String& operator_name = String::ZoneHandle(String::NewSymbol("=="));
292 const int kNumberOfArguments = 2; 308 const int kNumberOfArguments = 2;
293 const Array& kNoArgumentNames = Array::Handle(); 309 const Array& kNoArgumentNames = Array::Handle();
294 const int kNumArgumentsChecked = 2; 310 const int kNumArgumentsChecked = 2;
295 311
296 compiler->GenerateInstanceCall(comp->cid(), 312 compiler->GenerateInstanceCall(comp->cid(),
297 comp->token_pos(), 313 comp->token_pos(),
298 comp->try_index(), 314 comp->try_index(),
299 operator_name, 315 operator_name,
300 kNumberOfArguments, 316 kNumberOfArguments,
301 kNoArgumentNames, 317 kNoArgumentNames,
302 kNumArgumentsChecked); 318 kNumArgumentsChecked);
303 ASSERT(comp->locs()->out().reg() == EAX); 319 ASSERT(comp->locs()->out().reg() == EAX);
320 if (comp->kind() == Token::kNE) {
321 Label done, false_label;
322 __ CompareObject(EAX, compiler->bool_true());
323 __ j(EQUAL, &false_label, Assembler::kNearJump);
324 __ LoadObject(EAX, compiler->bool_true());
325 __ jmp(&done, Assembler::kNearJump);
326 __ Bind(&false_label);
327 __ LoadObject(EAX, compiler->bool_false());
328 __ Bind(&done);
329 }
304 } 330 }
305 331
306 332
307 static void EmitEqualityAsPolymorphicCall(FlowGraphCompiler* compiler, 333 static void EmitEqualityAsPolymorphicCall(FlowGraphCompiler* compiler,
308 const ICData& orig_ic_data, 334 const ICData& orig_ic_data,
309 const LocationSummary& locs, 335 const LocationSummary& locs,
310 BranchInstr* branch, 336 BranchInstr* branch,
311 Token::Kind kind, 337 Token::Kind kind,
312 intptr_t cid, 338 intptr_t cid,
313 intptr_t token_pos, 339 intptr_t token_pos,
314 intptr_t try_index) { 340 intptr_t try_index) {
341 ASSERT((kind == Token::kEQ) || (kind == Token::kNE));
315 const ICData& ic_data = ICData::Handle(orig_ic_data.AsUnaryClassChecks()); 342 const ICData& ic_data = ICData::Handle(orig_ic_data.AsUnaryClassChecks());
316 ASSERT(ic_data.NumberOfChecks() > 0); 343 ASSERT(ic_data.NumberOfChecks() > 0);
317 ASSERT(ic_data.num_args_tested() == 1); 344 ASSERT(ic_data.num_args_tested() == 1);
318 Label* deopt = compiler->AddDeoptStub(cid, 345 Label* deopt = compiler->AddDeoptStub(cid,
319 token_pos, 346 token_pos,
320 try_index, 347 try_index,
321 kDeoptEquality); 348 kDeoptEquality);
322 Register left = locs.in(0).reg(); 349 Register left = locs.in(0).reg();
323 Register right = locs.in(1).reg(); 350 Register right = locs.in(1).reg();
324 __ testl(left, Immediate(kSmiTagMask)); 351 __ testl(left, Immediate(kSmiTagMask));
325 Register temp = locs.temp(0).reg(); 352 Register temp = locs.temp(0).reg();
326 if (ic_data.GetReceiverClassIdAt(0) == kSmi) { 353 if (ic_data.GetReceiverClassIdAt(0) == kSmi) {
327 Label done, load_class_id; 354 Label done, load_class_id;
328 __ j(NOT_ZERO, &load_class_id, Assembler::kNearJump); 355 __ j(NOT_ZERO, &load_class_id, Assembler::kNearJump);
329 __ movl(temp, Immediate(kSmi)); 356 __ movl(temp, Immediate(kSmi));
330 __ jmp(&done, Assembler::kNearJump); 357 __ jmp(&done, Assembler::kNearJump);
331 __ Bind(&load_class_id); 358 __ Bind(&load_class_id);
332 __ LoadClassId(temp, left); 359 __ LoadClassId(temp, left);
333 __ Bind(&done); 360 __ Bind(&done);
334 } else { 361 } else {
335 __ j(ZERO, deopt); // Smi deopts. 362 __ j(ZERO, deopt); // Smi deopts.
336 __ LoadClassId(temp, left); 363 __ LoadClassId(temp, left);
337 } 364 }
338 Condition cond = (kind == Token::kEQ) ? EQUAL : NOT_EQUAL; 365 Condition cond = TokenKindToSmiCondition(kind);
339 Label done; 366 Label done;
340 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) { 367 for (intptr_t i = 0; i < ic_data.NumberOfChecks(); i++) {
341 ASSERT((ic_data.GetReceiverClassIdAt(i) != kSmi) || (i == 0)); 368 ASSERT((ic_data.GetReceiverClassIdAt(i) != kSmi) || (i == 0));
342 Label next_test; 369 Label next_test;
343 __ cmpl(temp, Immediate(ic_data.GetReceiverClassIdAt(i))); 370 __ cmpl(temp, Immediate(ic_data.GetReceiverClassIdAt(i)));
344 __ j(NOT_EQUAL, &next_test, Assembler::kNearJump); 371 __ j(NOT_EQUAL, &next_test, Assembler::kNearJump);
345 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(i)); 372 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(i));
346 ObjectStore* object_store = Isolate::Current()->object_store(); 373 ObjectStore* object_store = Isolate::Current()->object_store();
347 if (target.owner() == object_store->object_class()) { 374 if (target.owner() == object_store->object_class()) {
348 // Object.== is same as ===. 375 // Object.== is same as ===.
(...skipping 13 matching lines...) Expand all
362 } 389 }
363 } else { 390 } else {
364 const int kNumberOfArguments = 2; 391 const int kNumberOfArguments = 2;
365 const Array& kNoArgumentNames = Array::Handle(); 392 const Array& kNoArgumentNames = Array::Handle();
366 compiler->GenerateStaticCall(cid, 393 compiler->GenerateStaticCall(cid,
367 token_pos, 394 token_pos,
368 try_index, 395 try_index,
369 target, 396 target,
370 kNumberOfArguments, 397 kNumberOfArguments,
371 kNoArgumentNames); 398 kNoArgumentNames);
372 if (branch != NULL) { 399 if (branch == NULL) {
400 if (kind == Token::kNE) {
401 Label false_label;
402 __ CompareObject(EAX, compiler->bool_true());
403 __ j(EQUAL, &false_label, Assembler::kNearJump);
404 __ LoadObject(EAX, compiler->bool_true());
405 __ jmp(&done, Assembler::kNearJump);
406 __ Bind(&false_label);
407 __ LoadObject(EAX, compiler->bool_false());
408 __ jmp(&done);
409 }
410 } else {
373 __ CompareObject(EAX, compiler->bool_true()); 411 __ CompareObject(EAX, compiler->bool_true());
374 branch->EmitBranchOnCondition(compiler, cond); 412 branch->EmitBranchOnCondition(compiler, cond);
375 } 413 }
376 } 414 }
377 __ jmp(&done); 415 __ jmp(&done);
378 __ Bind(&next_test); 416 __ Bind(&next_test);
379 } 417 }
380 // Fall through leads to deoptimization 418 // Fall through leads to deoptimization
381 __ jmp(deopt); 419 __ jmp(deopt);
382 __ Bind(&done); 420 __ Bind(&done);
383 } 421 }
384 422
385 423
386 // First test if receiver is NULL, in which case === is applied. 424 // First test if receiver is NULL, in which case === is applied.
387 // If type feedback was provided (lists of <class-id, target>), do a 425 // If type feedback was provided (lists of <class-id, target>), do a
388 // type by type check (either === or static call to the operator. 426 // type by type check (either === or static call to the operator.
389 static void EmitGenericEqualityCompare(FlowGraphCompiler* compiler, 427 static void EmitGenericEqualityCompare(FlowGraphCompiler* compiler,
390 const LocationSummary& locs, 428 const LocationSummary& locs,
391 Token::Kind kind, 429 Token::Kind kind,
392 BranchInstr* branch, 430 BranchInstr* branch,
393 const ICData& ic_data, 431 const ICData& ic_data,
394 intptr_t cid, 432 intptr_t cid,
395 intptr_t token_pos, 433 intptr_t token_pos,
396 intptr_t try_index) { 434 intptr_t try_index) {
435 ASSERT((kind == Token::kEQ) || (kind == Token::kNE));
397 ASSERT(!ic_data.IsNull() && (ic_data.NumberOfChecks() > 0)); 436 ASSERT(!ic_data.IsNull() && (ic_data.NumberOfChecks() > 0));
398 Register left = locs.in(0).reg(); 437 Register left = locs.in(0).reg();
399 Register right = locs.in(1).reg(); 438 Register right = locs.in(1).reg();
400 const Immediate raw_null = 439 const Immediate raw_null =
401 Immediate(reinterpret_cast<intptr_t>(Object::null())); 440 Immediate(reinterpret_cast<intptr_t>(Object::null()));
402 Label done, non_null_compare; 441 Label done, non_null_compare;
403 __ cmpl(left, raw_null); 442 __ cmpl(left, raw_null);
404 __ j(NOT_EQUAL, &non_null_compare, Assembler::kNearJump); 443 __ j(NOT_EQUAL, &non_null_compare, Assembler::kNearJump);
405 // Comparison with NULL is "===". 444 // Comparison with NULL is "===".
406 __ cmpl(left, right); 445 __ cmpl(left, right);
407 Condition cond = (kind == Token::kEQ) ? EQUAL : NOT_EQUAL; 446 Condition cond = TokenKindToSmiCondition(kind);
408 if (branch != NULL) { 447 if (branch != NULL) {
409 branch->EmitBranchOnCondition(compiler, cond); 448 branch->EmitBranchOnCondition(compiler, cond);
410 } else { 449 } else {
411 Register result = locs.out().reg(); 450 Register result = locs.out().reg();
412 Label load_true; 451 Label load_true;
413 __ j(cond, &load_true, Assembler::kNearJump); 452 __ j(cond, &load_true, Assembler::kNearJump);
414 __ LoadObject(result, compiler->bool_false()); 453 __ LoadObject(result, compiler->bool_false());
415 __ jmp(&done); 454 __ jmp(&done);
416 __ Bind(&load_true); 455 __ Bind(&load_true);
417 __ LoadObject(result, compiler->bool_true()); 456 __ LoadObject(result, compiler->bool_true());
(...skipping 11 matching lines...) Expand all
429 void EqualityCompareComp::EmitNativeCode(FlowGraphCompiler* compiler) { 468 void EqualityCompareComp::EmitNativeCode(FlowGraphCompiler* compiler) {
430 if (receiver_class_id() == kSmi) { 469 if (receiver_class_id() == kSmi) {
431 EmitSmiEqualityCompare(compiler, this); 470 EmitSmiEqualityCompare(compiler, this);
432 return; 471 return;
433 } 472 }
434 if (receiver_class_id() == kDouble) { 473 if (receiver_class_id() == kDouble) {
435 EmitDoubleEqualityCompare(compiler, this); 474 EmitDoubleEqualityCompare(compiler, this);
436 return; 475 return;
437 } 476 }
438 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) { 477 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) {
439 EmitGenericEqualityCompare(compiler, *locs(), Token::kEQ, NULL, 478 EmitGenericEqualityCompare(compiler, *locs(), kind(), NULL,
440 *ic_data(), cid(), token_pos(), try_index()); 479 *ic_data(), cid(), token_pos(), try_index());
441 } else { 480 } else {
442 Register left = locs()->in(0).reg(); 481 Register left = locs()->in(0).reg();
443 Register right = locs()->in(1).reg(); 482 Register right = locs()->in(1).reg();
444 __ pushl(left); 483 __ pushl(left);
445 __ pushl(right); 484 __ pushl(right);
446 EmitEqualityAsInstanceCall(compiler, this); 485 EmitEqualityAsInstanceCall(compiler, this);
447 } 486 }
448 } 487 }
449 488
450 489
451 LocationSummary* RelationalOpComp::MakeLocationSummary() const { 490 LocationSummary* RelationalOpComp::MakeLocationSummary() const {
452 if ((operands_class_id() == kSmi) || (operands_class_id() == kDouble)) { 491 if ((operands_class_id() == kSmi) || (operands_class_id() == kDouble)) {
453 const intptr_t kNumInputs = 2; 492 const intptr_t kNumInputs = 2;
454 const intptr_t kNumTemps = 1; 493 const intptr_t kNumTemps = 1;
455 LocationSummary* summary = new LocationSummary(kNumInputs, 494 LocationSummary* summary = new LocationSummary(kNumInputs,
456 kNumTemps, 495 kNumTemps,
457 LocationSummary::kNoCall); 496 LocationSummary::kNoCall);
458 summary->set_in(0, Location::RequiresRegister()); 497 summary->set_in(0, Location::RequiresRegister());
459 summary->set_in(1, Location::RequiresRegister()); 498 summary->set_in(1, Location::RequiresRegister());
460 summary->set_out(Location::RequiresRegister()); 499 summary->set_out(Location::RequiresRegister());
461 summary->set_temp(0, Location::RequiresRegister()); 500 summary->set_temp(0, Location::RequiresRegister());
462 return summary; 501 return summary;
463 } 502 }
464 ASSERT(operands_class_id() == kObject); 503 ASSERT(operands_class_id() == kObject);
465 return MakeCallSummary(); 504 return MakeCallSummary();
466 } 505 }
467 506
468 507
469 static Condition TokenKindToSmiCondition(Token::Kind kind) {
470 switch (kind) {
471 case Token::kEQ: return EQUAL;
472 case Token::kNE: return NOT_EQUAL;
473 case Token::kLT: return LESS;
474 case Token::kGT: return GREATER;
475 case Token::kLTE: return LESS_EQUAL;
476 case Token::kGTE: return GREATER_EQUAL;
477 default:
478 UNREACHABLE();
479 return OVERFLOW;
480 }
481 }
482
483
484 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler, 508 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler,
485 const LocationSummary& locs, 509 const LocationSummary& locs,
486 Token::Kind kind, 510 Token::Kind kind,
487 BranchInstr* branch, 511 BranchInstr* branch,
488 intptr_t cid, 512 intptr_t cid,
489 intptr_t token_pos, 513 intptr_t token_pos,
490 intptr_t try_index) { 514 intptr_t try_index) {
491 Register left = locs.in(0).reg(); 515 Register left = locs.in(0).reg();
492 Register right = locs.in(1).reg(); 516 Register right = locs.in(1).reg();
493 Register temp = locs.temp(0).reg(); 517 Register temp = locs.temp(0).reg();
(...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 ASSERT(locs()->out().reg() == EAX); 2165 ASSERT(locs()->out().reg() == EAX);
2142 __ CompareObject(locs()->out().reg(), compiler->bool_true()); 2166 __ CompareObject(locs()->out().reg(), compiler->bool_true());
2143 EmitBranchOnCondition(compiler, branch_condition); 2167 EmitBranchOnCondition(compiler, branch_condition);
2144 } 2168 }
2145 2169
2146 } // namespace dart 2170 } // namespace dart
2147 2171
2148 #undef __ 2172 #undef __
2149 2173
2150 #endif // defined TARGET_ARCH_X64 2174 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698