static void replaceFrameIndexes(MachineFunction &MF, SmallVector<std::pair<int,int64_t>, 16> &FR) { MachineFrameInfo *MFI = MF.getFrameInfo(); MBlazeFunctionInfo *MBlazeFI = MF.getInfo<MBlazeFunctionInfo>(); const SmallVector<std::pair<int,int64_t>, 16>::iterator FRB = FR.begin(); const SmallVector<std::pair<int,int64_t>, 16>::iterator FRE = FR.end(); SmallVector<std::pair<int,int64_t>, 16>::iterator FRI = FRB; for (; FRI != FRE; ++FRI) { MFI->RemoveStackObject(FRI->first); int NFI = MFI->CreateFixedObject(4, FRI->second, true); MBlazeFI->recordReplacement(FRI->first, NFI); for (MachineFunction::iterator MB=MF.begin(), ME=MF.end(); MB!=ME; ++MB) { MachineBasicBlock::iterator MBB = MB->begin(); const MachineBasicBlock::iterator MBE = MB->end(); for (; MBB != MBE; ++MBB) { MachineInstr::mop_iterator MIB = MBB->operands_begin(); const MachineInstr::mop_iterator MIE = MBB->operands_end(); for (MachineInstr::mop_iterator MII = MIB; MII != MIE; ++MII) { if (!MII->isFI() || MII->getIndex() != FRI->first) continue; DEBUG(dbgs() << "FOUND FI#" << MII->getIndex() << "\n"); MII->setIndex(NFI); } } } } }
/// addNewBlock - Add a new basic block BB as an empty succcessor to DomBB. All /// variables that are live out of DomBB will be marked as passing live through /// BB. void LiveVariables::addNewBlock(MachineBasicBlock *BB, MachineBasicBlock *DomBB, MachineBasicBlock *SuccBB) { const unsigned NumNew = BB->getNumber(); SmallSet<unsigned, 16> Defs, Kills; MachineBasicBlock::iterator BBI = SuccBB->begin(), BBE = SuccBB->end(); for (; BBI != BBE && BBI->isPHI(); ++BBI) { // Record the def of the PHI node. Defs.insert(BBI->getOperand(0).getReg()); // All registers used by PHI nodes in SuccBB must be live through BB. for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) if (BBI->getOperand(i+1).getMBB() == BB) getVarInfo(BBI->getOperand(i).getReg()).AliveBlocks.set(NumNew); } // Record all vreg defs and kills of all instructions in SuccBB. for (; BBI != BBE; ++BBI) { for (MachineInstr::mop_iterator I = BBI->operands_begin(), E = BBI->operands_end(); I != E; ++I) { if (I->isReg() && TargetRegisterInfo::isVirtualRegister(I->getReg())) { if (I->isDef()) Defs.insert(I->getReg()); else if (I->isKill()) Kills.insert(I->getReg()); } } } // Update info for all live variables for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { unsigned Reg = TargetRegisterInfo::index2VirtReg(i); // If the Defs is defined in the successor it can't be live in BB. if (Defs.count(Reg)) continue; // If the register is either killed in or live through SuccBB it's also live // through BB. VarInfo &VI = getVarInfo(Reg); if (Kills.count(Reg) || VI.AliveBlocks.test(SuccBB->getNumber())) VI.AliveBlocks.set(NumNew); } }