/* * users should call the integerSubtractAnalyser or integerSubtractAnalyserWithExplicitOperands APIs instead of calling this one directly */ TR::Register* TR_X86SubtractAnalyser::integerSubtractAnalyserImpl(TR::Node *root, TR::Node *firstChild, TR::Node *secondChild, TR_X86OpCodes regRegOpCode, TR_X86OpCodes regMemOpCode, TR_X86OpCodes copyOpCode, bool needsEflags, TR::Node *borrow) { TR::Register *targetRegister = NULL; TR::Register *firstRegister = firstChild->getRegister(); TR::Register *secondRegister = secondChild->getRegister(); setInputs(firstChild, firstRegister, secondChild, secondRegister); bool loadedConst = false; needsEflags = needsEflags || NEED_CC(root); if (getEvalChild1()) { // if firstChild and secondChild are the same node, then we should // evaluate (take the else path) so that the evaluate for the secondChild // below will get the correct/already-allocated register. if (firstRegister == 0 && firstChild->getOpCodeValue() == TR::iconst && (firstChild != secondChild)) { // An iconst may have to be generated. The iconst will be generated after the // secondChild is evaluated. Set the loadedConst flag to true. loadedConst = true; } else { firstRegister = _cg->evaluate(firstChild); } } if (getEvalChild2()) { secondRegister = _cg->evaluate(secondChild); if (firstChild->getRegister()) { firstRegister = firstChild->getRegister(); } else if (!loadedConst) { firstRegister = _cg->evaluate(firstChild); } } if (loadedConst) { if (firstRegister == 0) { // firstchild is an inconst and it has not been evaluated. // Generate the code for an iconst. firstRegister = _cg->allocateRegister(); TR::TreeEvaluator::insertLoadConstant(firstChild, firstRegister, firstChild->getInt(), TR_RematerializableInt, _cg); } else { // firstchild was evaluated. The code for an iconst does not need to be generated. // Set the loadConst flag to false. loadedConst = false; } } if (borrow != 0) TR_X86ComputeCC::setCarryBorrow(borrow, true, _cg); if (getCopyReg1()) { if (firstChild->getReferenceCount() > 1) { TR::Register *thirdReg; if (firstChild->getOpCodeValue() == TR::iconst && loadedConst) { thirdReg = firstRegister; } else { if (secondChild->getReferenceCount() == 1 && secondRegister != 0 && !needsEflags && (borrow == 0)) { // use one fewer registers if we negate the clobberable secondRegister and add // Don't do this though if condition codes are needed. The sequence // depends on the carry flag being valid as if a sub was done. // bool nodeIs64Bit = TR_X86OpCode(regRegOpCode).hasLongSource(); generateRegInstruction(NEGReg(nodeIs64Bit), secondChild, secondRegister, _cg); thirdReg = secondRegister; secondRegister = firstRegister; regRegOpCode = ADDRegReg(nodeIs64Bit); } else { thirdReg = _cg->allocateRegister(); generateRegRegInstruction(copyOpCode, root, thirdReg, firstRegister, _cg); } } targetRegister = thirdReg; if (getSubReg3Reg2()) { generateRegRegInstruction(regRegOpCode, root, thirdReg, secondRegister, _cg); } else // assert getSubReg3Mem2() == true { TR::MemoryReference *tempMR = generateX86MemoryReference(secondChild, _cg); generateRegMemInstruction(regMemOpCode, root, thirdReg, tempMR, _cg); tempMR->decNodeReferenceCounts(_cg); } } else { if (getSubReg3Reg2()) { generateRegRegInstruction(regRegOpCode, root, firstRegister, secondRegister, _cg); } else // assert getSubReg3Mem2() == true { TR::MemoryReference *tempMR = generateX86MemoryReference(secondChild, _cg); generateRegMemInstruction(regMemOpCode, root, firstRegister, tempMR, _cg); tempMR->decNodeReferenceCounts(_cg); } targetRegister = firstRegister; } } else if (getSubReg1Reg2()) { generateRegRegInstruction(regRegOpCode, root, firstRegister, secondRegister, _cg); targetRegister = firstRegister; } else // assert getSubReg1Mem2() == true { TR::MemoryReference *tempMR = generateX86MemoryReference(secondChild, _cg); generateRegMemInstruction(regMemOpCode, root, firstRegister, tempMR, _cg); targetRegister = firstRegister; tempMR->decNodeReferenceCounts(_cg); } return targetRegister; }
extern TR_X86OpCodes ADDRegReg() { return ADDRegReg ( TR::Compiler->target.is64Bit() ? true : false ); }