1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
|
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "DFGNonSpeculativeJIT.h"
#include "DFGSpeculativeJIT.h"
#if ENABLE(DFG_JIT)
namespace JSC { namespace DFG {
const double twoToThe32 = (double)0x100000000ull;
EntryLocation::EntryLocation(MacroAssembler::Label entry, NonSpeculativeJIT* jit)
: m_entry(entry)
, m_nodeIndex(jit->m_compileIndex)
{
for (gpr_iterator iter = jit->m_gprs.begin(); iter != jit->m_gprs.end(); ++iter) {
if (iter.name() != InvalidVirtualRegister) {
GenerationInfo& info = jit->m_generationInfo[iter.name()];
m_gprInfo[iter.index()].nodeIndex = info.nodeIndex();
m_gprInfo[iter.index()].format = info.registerFormat();
} else
m_gprInfo[iter.index()].nodeIndex = NoNode;
}
for (fpr_iterator iter = jit->m_fprs.begin(); iter != jit->m_fprs.end(); ++iter) {
if (iter.name() != InvalidVirtualRegister) {
GenerationInfo& info = jit->m_generationInfo[iter.name()];
ASSERT(info.registerFormat() == DataFormatDouble);
m_fprInfo[iter.index()] = info.nodeIndex();
} else
m_fprInfo[iter.index()] = NoNode;
}
}
void NonSpeculativeJIT::valueToNumber(JSValueOperand& operand, FPRReg fpr)
{
GPRReg jsValueGpr = operand.gpr();
GPRReg tempGpr = allocate(); // FIXME: can we skip this allocation on the last use of the virtual register?
JITCompiler::Jump isInteger = m_jit.branchPtr(MacroAssembler::AboveOrEqual, jsValueGpr, GPRInfo::tagTypeNumberRegister);
JITCompiler::Jump nonNumeric = m_jit.branchTestPtr(MacroAssembler::Zero, jsValueGpr, GPRInfo::tagTypeNumberRegister);
// First, if we get here we have a double encoded as a JSValue
m_jit.move(jsValueGpr, tempGpr);
m_jit.addPtr(GPRInfo::tagTypeNumberRegister, tempGpr);
m_jit.movePtrToDouble(tempGpr, fpr);
JITCompiler::Jump hasUnboxedDouble = m_jit.jump();
// Next handle cells (& other JS immediates)
nonNumeric.link(&m_jit);
silentSpillAllRegisters(fpr, jsValueGpr);
m_jit.move(jsValueGpr, GPRInfo::argumentGPR1);
m_jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0);
appendCallWithExceptionCheck(dfgConvertJSValueToNumber);
m_jit.moveDouble(FPRInfo::returnValueFPR, fpr);
silentFillAllRegisters(fpr);
JITCompiler::Jump hasCalledToNumber = m_jit.jump();
// Finally, handle integers.
isInteger.link(&m_jit);
m_jit.convertInt32ToDouble(jsValueGpr, fpr);
hasUnboxedDouble.link(&m_jit);
hasCalledToNumber.link(&m_jit);
m_gprs.unlock(tempGpr);
}
void NonSpeculativeJIT::valueToInt32(JSValueOperand& operand, GPRReg result)
{
GPRReg jsValueGpr = operand.gpr();
JITCompiler::Jump isInteger = m_jit.branchPtr(MacroAssembler::AboveOrEqual, jsValueGpr, GPRInfo::tagTypeNumberRegister);
// First handle non-integers
silentSpillAllRegisters(result, jsValueGpr);
m_jit.move(jsValueGpr, GPRInfo::argumentGPR1);
m_jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0);
appendCallWithExceptionCheck(dfgConvertJSValueToInt32);
m_jit.zeroExtend32ToPtr(GPRInfo::returnValueGPR, result);
silentFillAllRegisters(result);
JITCompiler::Jump hasCalledToInt32 = m_jit.jump();
// Then handle integers.
isInteger.link(&m_jit);
m_jit.zeroExtend32ToPtr(jsValueGpr, result);
hasCalledToInt32.link(&m_jit);
}
void NonSpeculativeJIT::numberToInt32(FPRReg fpr, GPRReg gpr)
{
JITCompiler::Jump truncatedToInteger = m_jit.branchTruncateDoubleToInt32(fpr, gpr, JITCompiler::BranchIfTruncateSuccessful);
silentSpillAllRegisters(gpr);
m_jit.moveDouble(fpr, FPRInfo::argumentFPR0);
appendCallWithExceptionCheck(toInt32);
m_jit.zeroExtend32ToPtr(GPRInfo::returnValueGPR, gpr);
silentFillAllRegisters(gpr);
truncatedToInteger.link(&m_jit);
}
bool NonSpeculativeJIT::isKnownInteger(NodeIndex nodeIndex)
{
GenerationInfo& info = m_generationInfo[m_jit.graph()[nodeIndex].virtualRegister()];
DataFormat registerFormat = info.registerFormat();
if (registerFormat != DataFormatNone)
return (registerFormat | DataFormatJS) == DataFormatJSInteger;
DataFormat spillFormat = info.spillFormat();
if (spillFormat != DataFormatNone)
return (spillFormat | DataFormatJS) == DataFormatJSInteger;
ASSERT(isConstant(nodeIndex));
return isInt32Constant(nodeIndex);
}
bool NonSpeculativeJIT::isKnownNumeric(NodeIndex nodeIndex)
{
GenerationInfo& info = m_generationInfo[m_jit.graph()[nodeIndex].virtualRegister()];
DataFormat registerFormat = info.registerFormat();
if (registerFormat != DataFormatNone)
return (registerFormat | DataFormatJS) == DataFormatJSInteger
|| (registerFormat | DataFormatJS) == DataFormatJSDouble;
DataFormat spillFormat = info.spillFormat();
if (spillFormat != DataFormatNone)
return (spillFormat | DataFormatJS) == DataFormatJSInteger
|| (spillFormat | DataFormatJS) == DataFormatJSDouble;
ASSERT(isConstant(nodeIndex));
return isInt32Constant(nodeIndex) || isDoubleConstant(nodeIndex);
}
void NonSpeculativeJIT::compile(SpeculationCheckIndexIterator& checkIterator, Node& node)
{
// Check for speculation checks from the corresponding instruction in the
// speculative path. Do not check for NodeIndex 0, since this is checked
// in the outermost compile layer, at the head of the non-speculative path
// (for index 0 we may need to check regardless of whether or not the node
// will be generated, since argument type speculation checks will appear
// as speculation checks at this index).
if (m_compileIndex && checkIterator.hasCheckAtIndex(m_compileIndex))
trackEntry(m_jit.label());
NodeType op = node.op;
switch (op) {
case ConvertThis: {
JSValueOperand thisValue(this, node.child1);
GPRReg thisGPR = thisValue.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationConvertThis, result.gpr(), thisGPR);
cellResult(result.gpr(), m_compileIndex);
break;
}
case Int32Constant:
case DoubleConstant:
case JSConstant:
initConstantInfo(m_compileIndex);
break;
case GetLocal: {
GPRTemporary result(this);
m_jit.loadPtr(JITCompiler::addressFor(node.local()), result.gpr());
// Like jsValueResult, but don't useChildren - our children are phi nodes,
// and don't represent values within this dataflow with virtual registers.
VirtualRegister virtualRegister = node.virtualRegister();
m_gprs.retain(result.gpr(), virtualRegister, SpillOrderJS);
m_generationInfo[virtualRegister].initJSValue(m_compileIndex, node.refCount(), result.gpr(), DataFormatJS);
break;
}
case SetLocal: {
JSValueOperand value(this, node.child1);
m_jit.storePtr(value.gpr(), JITCompiler::addressFor(node.local()));
noResult(m_compileIndex);
break;
}
case BitAnd:
case BitOr:
case BitXor:
if (isInt32Constant(node.child1)) {
IntegerOperand op2(this, node.child2);
GPRTemporary result(this, op2);
bitOp(op, valueOfInt32Constant(node.child1), op2.gpr(), result.gpr());
integerResult(result.gpr(), m_compileIndex);
} else if (isInt32Constant(node.child2)) {
IntegerOperand op1(this, node.child1);
GPRTemporary result(this, op1);
bitOp(op, valueOfInt32Constant(node.child2), op1.gpr(), result.gpr());
integerResult(result.gpr(), m_compileIndex);
} else {
IntegerOperand op1(this, node.child1);
IntegerOperand op2(this, node.child2);
GPRTemporary result(this, op1, op2);
GPRReg reg1 = op1.gpr();
GPRReg reg2 = op2.gpr();
bitOp(op, reg1, reg2, result.gpr());
integerResult(result.gpr(), m_compileIndex);
}
break;
case BitRShift:
case BitLShift:
case BitURShift:
if (isInt32Constant(node.child2)) {
IntegerOperand op1(this, node.child1);
GPRTemporary result(this, op1);
int shiftAmount = valueOfInt32Constant(node.child2) & 0x1f;
// Shifts by zero should have been optimized out of the graph!
ASSERT(shiftAmount);
shiftOp(op, op1.gpr(), shiftAmount, result.gpr());
integerResult(result.gpr(), m_compileIndex);
} else {
// Do not allow shift amount to be used as the result, MacroAssembler does not permit this.
IntegerOperand op1(this, node.child1);
IntegerOperand op2(this, node.child2);
GPRTemporary result(this, op1);
GPRReg reg1 = op1.gpr();
GPRReg reg2 = op2.gpr();
shiftOp(op, reg1, reg2, result.gpr());
integerResult(result.gpr(), m_compileIndex);
}
break;
case UInt32ToNumber: {
IntegerOperand op1(this, node.child1);
FPRTemporary result(this);
m_jit.convertInt32ToDouble(op1.gpr(), result.fpr());
MacroAssembler::Jump positive = m_jit.branch32(MacroAssembler::GreaterThanOrEqual, op1.gpr(), TrustedImm32(0));
m_jit.addDouble(JITCompiler::AbsoluteAddress(&twoToThe32), result.fpr());
positive.link(&m_jit);
doubleResult(result.fpr(), m_compileIndex);
break;
}
case Int32ToNumber: {
IntegerOperand op1(this, node.child1);
FPRTemporary result(this);
m_jit.convertInt32ToDouble(op1.gpr(), result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case NumberToInt32:
case ValueToInt32: {
ASSERT(!isInt32Constant(node.child1));
if (isKnownInteger(node.child1)) {
IntegerOperand op1(this, node.child1);
GPRTemporary result(this, op1);
m_jit.move(op1.gpr(), result.gpr());
integerResult(result.gpr(), m_compileIndex);
break;
}
if (isKnownNumeric(node.child1)) {
DoubleOperand op1(this, node.child1);
GPRTemporary result(this);
numberToInt32(op1.fpr(), result.gpr());
integerResult(result.gpr(), m_compileIndex);
break;
}
// We should have handled this via isKnownInteger, or isKnownNumeric!
ASSERT(op != NumberToInt32);
JSValueOperand op1(this, node.child1);
GPRTemporary result(this, op1);
valueToInt32(op1, result.gpr());
integerResult(result.gpr(), m_compileIndex);
break;
}
case ValueToNumber: {
ASSERT(!isInt32Constant(node.child1));
ASSERT(!isDoubleConstant(node.child1));
if (isKnownInteger(node.child1)) {
IntegerOperand op1(this, node.child1);
FPRTemporary result(this);
m_jit.convertInt32ToDouble(op1.gpr(), result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
if (isKnownNumeric(node.child1)) {
DoubleOperand op1(this, node.child1);
FPRTemporary result(this, op1);
m_jit.moveDouble(op1.fpr(), result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
JSValueOperand op1(this, node.child1);
FPRTemporary result(this);
valueToNumber(op1, result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case ValueAdd: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationValueAdd, result.gpr(), arg1GPR, arg2GPR);
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case ArithAdd: {
DoubleOperand op1(this, node.child1);
DoubleOperand op2(this, node.child2);
FPRTemporary result(this, op1, op2);
FPRReg reg1 = op1.fpr();
FPRReg reg2 = op2.fpr();
m_jit.addDouble(reg1, reg2, result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case ArithSub: {
DoubleOperand op1(this, node.child1);
DoubleOperand op2(this, node.child2);
FPRTemporary result(this, op1);
FPRReg reg1 = op1.fpr();
FPRReg reg2 = op2.fpr();
m_jit.subDouble(reg1, reg2, result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case ArithMul: {
DoubleOperand op1(this, node.child1);
DoubleOperand op2(this, node.child2);
FPRTemporary result(this, op1, op2);
FPRReg reg1 = op1.fpr();
FPRReg reg2 = op2.fpr();
m_jit.mulDouble(reg1, reg2, result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case ArithDiv: {
DoubleOperand op1(this, node.child1);
DoubleOperand op2(this, node.child2);
FPRTemporary result(this, op1);
FPRReg reg1 = op1.fpr();
FPRReg reg2 = op2.fpr();
m_jit.divDouble(reg1, reg2, result.fpr());
doubleResult(result.fpr(), m_compileIndex);
break;
}
case ArithMod: {
DoubleOperand arg1(this, node.child1);
DoubleOperand arg2(this, node.child2);
FPRReg arg1FPR = arg1.fpr();
FPRReg arg2FPR = arg2.fpr();
flushRegisters();
FPRResult result(this);
callOperation(fmod, result.fpr(), arg1FPR, arg2FPR);
doubleResult(result.fpr(), m_compileIndex);
break;
}
case LogicalNot: {
JSValueOperand arg1(this, node.child1);
GPRReg arg1GPR = arg1.gpr();
flushRegisters();
GPRResult result(this);
callOperation(dfgConvertJSValueToBoolean, result.gpr(), arg1GPR);
// If we add a DataFormatBool, we should use it here.
m_jit.xor32(TrustedImm32(ValueTrue), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case CompareLess: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationCompareLess, result.gpr(), arg1GPR, arg2GPR);
m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case CompareLessEq: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationCompareLessEq, result.gpr(), arg1GPR, arg2GPR);
m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case CompareEq: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationCompareEq, result.gpr(), arg1GPR, arg2GPR);
m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case CompareStrictEq: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationCompareStrictEq, result.gpr(), arg1GPR, arg2GPR);
m_jit.or32(TrustedImm32(ValueFalse), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case GetByVal: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationGetByVal, result.gpr(), arg1GPR, arg2GPR);
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case PutByVal:
case PutByValAlias: {
JSValueOperand arg1(this, node.child1);
JSValueOperand arg2(this, node.child2);
JSValueOperand arg3(this, node.child3);
GPRReg arg1GPR = arg1.gpr();
GPRReg arg2GPR = arg2.gpr();
GPRReg arg3GPR = arg3.gpr();
flushRegisters();
GPRResult result(this);
callOperation(m_jit.codeBlock()->isStrictMode() ? operationPutByValStrict : operationPutByValNonStrict, arg1GPR, arg2GPR, arg3GPR);
noResult(m_compileIndex);
break;
}
case GetById: {
JSValueOperand base(this, node.child1);
GPRReg baseGPR = base.gpr();
flushRegisters();
GPRResult result(this);
callOperation(operationGetById, result.gpr(), baseGPR, identifier(node.identifierNumber()));
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case PutById: {
JSValueOperand base(this, node.child1);
JSValueOperand value(this, node.child2);
GPRReg valueGPR = value.gpr();
GPRReg baseGPR = base.gpr();
flushRegisters();
callOperation(m_jit.codeBlock()->isStrictMode() ? operationPutByIdStrict : operationPutByIdNonStrict, valueGPR, baseGPR, identifier(node.identifierNumber()));
noResult(m_compileIndex);
break;
}
case PutByIdDirect: {
JSValueOperand base(this, node.child1);
JSValueOperand value(this, node.child2);
GPRReg valueGPR = value.gpr();
GPRReg baseGPR = base.gpr();
flushRegisters();
callOperation(m_jit.codeBlock()->isStrictMode() ? operationPutByIdDirectStrict : operationPutByIdDirectNonStrict, valueGPR, baseGPR, identifier(node.identifierNumber()));
noResult(m_compileIndex);
break;
}
case GetGlobalVar: {
GPRTemporary result(this);
JSVariableObject* globalObject = m_jit.codeBlock()->globalObject();
m_jit.loadPtr(globalObject->addressOfRegisters(), result.gpr());
m_jit.loadPtr(JITCompiler::addressForGlobalVar(result.gpr(), node.varNumber()), result.gpr());
jsValueResult(result.gpr(), m_compileIndex);
break;
}
case PutGlobalVar: {
JSValueOperand value(this, node.child1);
GPRTemporary temp(this);
JSVariableObject* globalObject = m_jit.codeBlock()->globalObject();
m_jit.loadPtr(globalObject->addressOfRegisters(), temp.gpr());
m_jit.storePtr(value.gpr(), JITCompiler::addressForGlobalVar(temp.gpr(), node.varNumber()));
noResult(m_compileIndex);
break;
}
case DFG::Jump: {
BlockIndex taken = m_jit.graph().blockIndexForBytecodeOffset(node.takenBytecodeOffset());
if (taken != (m_block + 1))
addBranch(m_jit.jump(), taken);
noResult(m_compileIndex);
break;
}
case Branch: {
JSValueOperand value(this, node.child1);
GPRReg valueGPR = value.gpr();
flushRegisters();
GPRResult result(this);
callOperation(dfgConvertJSValueToBoolean, result.gpr(), valueGPR);
BlockIndex taken = m_jit.graph().blockIndexForBytecodeOffset(node.takenBytecodeOffset());
BlockIndex notTaken = m_jit.graph().blockIndexForBytecodeOffset(node.notTakenBytecodeOffset());
addBranch(m_jit.branchTest8(MacroAssembler::NonZero, result.gpr()), taken);
if (notTaken != (m_block + 1))
addBranch(m_jit.jump(), notTaken);
noResult(m_compileIndex);
break;
}
case Return: {
ASSERT(GPRInfo::callFrameRegister != GPRInfo::regT1);
ASSERT(GPRInfo::regT1 != GPRInfo::returnValueGPR);
ASSERT(GPRInfo::returnValueGPR != GPRInfo::callFrameRegister);
#if DFG_SUCCESS_STATS
static SamplingCounter counter("NonSpeculativeJIT");
m_jit.emitCount(counter);
#endif
// Return the result in returnValueGPR.
JSValueOperand op1(this, node.child1);
m_jit.move(op1.gpr(), GPRInfo::returnValueGPR);
// Grab the return address.
m_jit.emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, GPRInfo::regT1);
// Restore our caller's "r".
m_jit.emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, GPRInfo::callFrameRegister);
// Return.
m_jit.restoreReturnAddressBeforeReturn(GPRInfo::regT1);
m_jit.ret();
noResult(m_compileIndex);
break;
}
case Phi:
ASSERT_NOT_REACHED();
}
if (node.hasResult() && node.mustGenerate())
use(m_compileIndex);
}
void NonSpeculativeJIT::compile(SpeculationCheckIndexIterator& checkIterator, BasicBlock& block)
{
ASSERT(m_compileIndex == block.begin);
m_blockHeads[m_block] = m_jit.label();
#if DFG_JIT_BREAK_ON_EVERY_BLOCK
m_jit.breakpoint();
#endif
for (; m_compileIndex < block.end; ++m_compileIndex) {
Node& node = m_jit.graph()[m_compileIndex];
if (!node.shouldGenerate())
continue;
#if DFG_DEBUG_VERBOSE
fprintf(stderr, "NonSpeculativeJIT generating Node @%d at code offset 0x%x\n", (int)m_compileIndex, m_jit.debugOffset());
#endif
#if DFG_JIT_BREAK_ON_EVERY_NODE
m_jit.breakpoint();
#endif
checkConsistency();
compile(checkIterator, node);
checkConsistency();
}
}
void NonSpeculativeJIT::compile(SpeculationCheckIndexIterator& checkIterator)
{
// Check for speculation checks added at function entry (checking argument types).
if (checkIterator.hasCheckAtIndex(m_compileIndex))
trackEntry(m_jit.label());
ASSERT(!m_compileIndex);
for (m_block = 0; m_block < m_jit.graph().m_blocks.size(); ++m_block)
compile(checkIterator, *m_jit.graph().m_blocks[m_block]);
linkBranches();
}
} } // namespace JSC::DFG
#endif
|