X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FLiveIntervalAnalysis.cpp;h=8cfc5871dcc68708f0151b3535e1c248b7ea2e30;hb=2d87734a8ffad5933edbbc15a3b643df1e8a767e;hp=eb3ac31998ac2aedee2e5b22063800b14c4b069a;hpb=d592a28ca1506f2ccd6384679d87cce4b4fd874a;p=oota-llvm.git diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index eb3ac31998a..8cfc5871dcc 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -50,11 +50,6 @@ namespace { EnableJoining("join-liveintervals", cl::desc("Coallesce copies (default=true)"), cl::init(true)); - - static cl::opt - EnableReMat("enable-rematerialization", - cl::desc("Perform trivial re-materialization"), - cl::init(false)); } void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const { @@ -169,13 +164,15 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { unsigned reg = rep(mop.getReg()); mii->getOperand(i).setReg(reg); - // If the definition instruction is re-materializable, its spill - // weight is zero. LiveInterval &RegInt = getInterval(reg); - if (!RegInt.remat) { - RegInt.weight += - (mop.isUse() + mop.isDef()) * pow(10.0F, (int)loopDepth); - } + float w = (mop.isUse()+mop.isDef()) * powf(10.0F, (float)loopDepth); + // If the definition instruction is re-materializable, its spill + // weight is half of what it would have been normally unless it's + // a load from fixed stack slot. + int Dummy; + if (RegInt.remat && !tii_->isLoadFromStackSlot(RegInt.remat, Dummy)) + w /= 2; + RegInt.weight += w; } } ++mii; @@ -435,9 +432,13 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb, // done once for the vreg. We use an empty interval to detect the first // time we see a vreg. if (interval.empty()) { - // Remember if the definition can be rematerialized. - if (EnableReMat && - vi.DefInst && tii_->isReMaterializable(vi.DefInst->getOpcode())) + // Remember if the definition can be rematerialized. All load's from fixed + // stack slots are re-materializable. + int FrameIdx = 0; + if (vi.DefInst && + (tii_->isReMaterializable(vi.DefInst->getOpcode()) || + (tii_->isLoadFromStackSlot(vi.DefInst, FrameIdx) && + mf_->getFrameInfo()->isFixedObjectIndex(FrameIdx)))) interval.remat = vi.DefInst; // Get the Idx of the defining instructions. @@ -515,7 +516,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb, } } else { - // Can't safely assume definition is rematierializable anymore. + // Can no longer safely assume definition is rematerializable. interval.remat = NULL; // If this is the second time we see a virtual register definition, it @@ -921,6 +922,7 @@ bool LiveIntervals::JoinCopy(MachineInstr *CopyMI, // Check if it is necessary to propagate "isDead" property before intervals // are joined. + MachineBasicBlock *CopyBB = CopyMI->getParent(); MachineOperand *mopd = CopyMI->findRegisterDefOperand(DstReg); bool isDead = mopd->isDead(); bool isShorten = false; @@ -947,9 +949,15 @@ bool LiveIntervals::JoinCopy(MachineInstr *CopyMI, isShorten = true; RemoveStart = getDefIndex(getInstructionIndex(LastUse)); RemoveEnd = SrcEnd; - } else if (RemoveStart > 0) - // A dead def should have a single cycle interval. - ++RemoveStart; + } else { + MachineInstr *SrcMI = getInstructionFromIndex(SrcStart); + if (SrcMI) { + MachineOperand *mops = findDefOperand(SrcMI, repSrcReg); + if (mops) + // A dead def should have a single cycle interval. + ++RemoveStart; + } + } } } @@ -965,7 +973,6 @@ bool LiveIntervals::JoinCopy(MachineInstr *CopyMI, LiveVariables::VarInfo& dvi = lv_->getVarInfo(repDstReg); // Is the value used in the current BB or any immediate successroe BB? - MachineBasicBlock *CopyBB = CopyMI->getParent(); if (dvi.UsedBlocks[CopyBB->getNumber()]) goto TryJoin; for (MachineBasicBlock::succ_iterator SI = CopyBB->succ_begin(), @@ -1022,9 +1029,8 @@ TryJoin: } else { MachineInstr *SrcMI = getInstructionFromIndex(SrcStart); if (SrcMI) { - MachineOperand *mops = SrcMI->findRegisterDefOperand(SrcReg); + MachineOperand *mops = findDefOperand(SrcMI, repSrcReg); if (mops) - // FIXME: mops == NULL means SrcMI defines a subregister? mops->setIsDead(); } } @@ -1618,6 +1624,19 @@ LiveIntervals::lastRegisterUse(unsigned Reg, unsigned Start, unsigned End, return NULL; } + +/// findDefOperand - Returns the MachineOperand that is a def of the specific +/// register. It returns NULL if the def is not found. +MachineOperand *LiveIntervals::findDefOperand(MachineInstr *MI, unsigned Reg) { + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { + MachineOperand &MO = MI->getOperand(i); + if (MO.isReg() && MO.isDef() && + mri_->regsOverlap(rep(MO.getReg()), Reg)) + return &MO; + } + return NULL; +} + /// unsetRegisterKill - Unset IsKill property of all uses of specific register /// of the specific instruction. void LiveIntervals::unsetRegisterKill(MachineInstr *MI, unsigned Reg) {