llvm.org GIT mirror llvm / b487e72
Move some functionality for adding flags to MachineInstr's into methods on MachineInstr rather than LiveVariables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46295 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
5 changed file(s) with 126 addition(s) and 130 deletion(s). Raw diff Collapse all Expand all
195195 /// the records for NewMI.
196196 void instructionChanged(MachineInstr *OldMI, MachineInstr *NewMI);
197197
198 /// transferKillDeadInfo - Similar to instructionChanged except it does not
199 /// update live variables internal data structures.
200 static void transferKillDeadInfo(MachineInstr *OldMI, MachineInstr *NewMI,
201 const MRegisterInfo *RegInfo);
202
203 /// addRegisterKilled - We have determined MI kills a register. Look for the
204 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
205 /// add a implicit operand if it's not found. Returns true if the operand
206 /// exists / is added.
207 static bool addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
208 const MRegisterInfo *RegInfo,
209 bool AddIfNotFound = false);
210
211198 /// addVirtualRegisterKilled - Add information about the fact that the
212199 /// specified register is killed after being used by the specified
213200 /// instruction. If AddIfNotFound is true, add a implicit operand if it's
214201 /// not found.
215202 void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
216203 bool AddIfNotFound = false) {
217 if (addRegisterKilled(IncomingReg, MI, RegInfo, AddIfNotFound))
204 if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound))
218205 getVarInfo(IncomingReg).Kills.push_back(MI);
219206 }
220207
245232 /// removeVirtualRegistersKilled - Remove all killed info for the specified
246233 /// instruction.
247234 void removeVirtualRegistersKilled(MachineInstr *MI);
248
249 /// addRegisterDead - We have determined MI defined a register without a use.
250 /// Look for the operand that defines it and mark it as IsDead. If
251 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
252 /// true if the operand exists / is added.
253 static bool addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
254 const MRegisterInfo *RegInfo,
255 bool AddIfNotFound = false);
256235
257236 /// addVirtualRegisterDead - Add information about the fact that the specified
258237 /// register is dead after being used by the specified instruction. If
259238 /// AddIfNotFound is true, add a implicit operand if it's not found.
260239 void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
261240 bool AddIfNotFound = false) {
262 if (addRegisterDead(IncomingReg, MI, RegInfo, AddIfNotFound))
241 if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound))
263242 getVarInfo(IncomingReg).Kills.push_back(MI);
264243 }
265244
2020 namespace llvm {
2121
2222 class TargetInstrDesc;
23 class MRegisterInfo;
2324
2425 template struct ilist_traits;
2526 template struct ilist;
143144 /// copyPredicates - Copies predicate operand(s) from MI.
144145 void copyPredicates(const MachineInstr *MI);
145146
147 /// addRegisterKilled - We have determined MI kills a register. Look for the
148 /// operand that uses it and mark it as IsKill. If AddIfNotFound is true,
149 /// add a implicit operand if it's not found. Returns true if the operand
150 /// exists / is added.
151 bool addRegisterKilled(unsigned IncomingReg, const MRegisterInfo *RegInfo,
152 bool AddIfNotFound = false);
153
154 /// addRegisterDead - We have determined MI defined a register without a use.
155 /// Look for the operand that defines it and mark it as IsDead. If
156 /// AddIfNotFound is true, add a implicit operand if it's not found. Returns
157 /// true if the operand exists / is added.
158 bool addRegisterDead(unsigned IncomingReg, const MRegisterInfo *RegInfo,
159 bool AddIfNotFound = false);
160
161 /// copyKillDeadInfo - copies killed/dead information from one instr to another
162 void copyKillDeadInfo(MachineInstr *OldMI,
163 const MRegisterInfo *RegInfo);
164
146165 //
147166 // Debugging support
148167 //
716716 if (lv_)
717717 lv_->instructionChanged(MI, fmi);
718718 else
719 LiveVariables::transferKillDeadInfo(MI, fmi, mri_);
719 fmi->copyKillDeadInfo(MI, mri_);
720720 MachineBasicBlock &MBB = *MI->getParent();
721721 if (isSS && !mf_->getFrameInfo()->isImmutableObjectIndex(Slot))
722722 vrm.virtFolded(Reg, MI, fmi, (VirtRegMap::ModRef)MRInfo);
191191 MarkVirtRegAliveInBlock(VRInfo, MRI.getVRegDef(reg)->getParent(), *PI);
192192 }
193193
194 bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
195 const MRegisterInfo *RegInfo,
196 bool AddIfNotFound) {
197 bool Found = false;
198 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
199 MachineOperand &MO = MI->getOperand(i);
200 if (MO.isRegister() && MO.isUse()) {
201 unsigned Reg = MO.getReg();
202 if (!Reg)
203 continue;
204 if (Reg == IncomingReg) {
205 MO.setIsKill();
206 Found = true;
207 break;
208 } else if (MRegisterInfo::isPhysicalRegister(Reg) &&
209 MRegisterInfo::isPhysicalRegister(IncomingReg) &&
210 RegInfo->isSuperRegister(IncomingReg, Reg) &&
211 MO.isKill())
212 // A super-register kill already exists.
213 Found = true;
214 }
215 }
216
217 // If not found, this means an alias of one of the operand is killed. Add a
218 // new implicit operand if required.
219 if (!Found && AddIfNotFound) {
220 MI->addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/,
221 true/*IsImp*/,true/*IsKill*/));
222 return true;
223 }
224 return Found;
225 }
226
227 bool LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI,
228 const MRegisterInfo *RegInfo,
229 bool AddIfNotFound) {
230 bool Found = false;
231 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
232 MachineOperand &MO = MI->getOperand(i);
233 if (MO.isRegister() && MO.isDef()) {
234 unsigned Reg = MO.getReg();
235 if (!Reg)
236 continue;
237 if (Reg == IncomingReg) {
238 MO.setIsDead();
239 Found = true;
240 break;
241 } else if (MRegisterInfo::isPhysicalRegister(Reg) &&
242 MRegisterInfo::isPhysicalRegister(IncomingReg) &&
243 RegInfo->isSuperRegister(IncomingReg, Reg) &&
244 MO.isDead())
245 // There exists a super-register that's marked dead.
246 return true;
247 }
248 }
249
250 // If not found, this means an alias of one of the operand is dead. Add a
251 // new implicit operand.
252 if (!Found && AddIfNotFound) {
253 MI->addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/,
254 true/*IsImp*/,false/*IsKill*/,
255 true/*IsDead*/));
256 return true;
257 }
258 return Found;
259 }
260
261194 void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) {
262195 // Turn previous partial def's into read/mod/write.
263196 for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) {
336269 void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
337270 SmallSet &SubKills) {
338271 if (SubKills.count(Reg) == 0)
339 addRegisterKilled(Reg, MI, RegInfo, true);
272 MI->addRegisterKilled(Reg, RegInfo, true);
340273 else {
341274 for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg);
342275 unsigned SubReg = *SubRegs; ++SubRegs)
347280 bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) {
348281 SmallSet SubKills;
349282 if (HandlePhysRegKill(Reg, RefMI, SubKills)) {
350 addRegisterKilled(Reg, RefMI, RegInfo, true);
283 RefMI->addRegisterKilled(Reg, RegInfo, true);
351284 return true;
352285 } else {
353286 // Some sub-registers are killed by another MI.
364297 if (PhysRegUsed[Reg]) {
365298 if (!HandlePhysRegKill(Reg, LastRef)) {
366299 if (PhysRegPartUse[Reg])
367 addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true);
300 PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
368301 }
369302 } else if (PhysRegPartUse[Reg])
370303 // Add implicit use / kill to last partial use.
371 addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true);
304 PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true);
372305 else if (LastRef != MI)
373306 // Defined, but not used. However, watch out for cases where a super-reg
374307 // is also defined on the same MI.
375 addRegisterDead(Reg, LastRef, RegInfo);
308 LastRef->addRegisterDead(Reg, RegInfo);
376309 }
377310
378311 for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg);
381314 if (PhysRegUsed[SubReg]) {
382315 if (!HandlePhysRegKill(SubReg, LastRef)) {
383316 if (PhysRegPartUse[SubReg])
384 addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true);
317 PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true);
385318 }
386319 } else if (PhysRegPartUse[SubReg])
387320 // Add implicit use / kill to last use of a sub-register.
388 addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true);
321 PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true);
389322 else if (LastRef != MI)
390323 // This must be a def of the subreg on the same MI.
391 addRegisterDead(SubReg, LastRef, RegInfo);
324 LastRef->addRegisterDead(SubReg, RegInfo);
392325 }
393326 }
394327
564497 for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) {
565498 if (VirtRegInfo[i].Kills[j] == MRI.getVRegDef(i +
566499 MRegisterInfo::FirstVirtualRegister))
567 addRegisterDead(i + MRegisterInfo::FirstVirtualRegister,
568 VirtRegInfo[i].Kills[j], RegInfo);
500 VirtRegInfo[i].Kills[j]->addRegisterDead(i +
501 MRegisterInfo::FirstVirtualRegister,
502 RegInfo);
569503 else
570 addRegisterKilled(i + MRegisterInfo::FirstVirtualRegister,
571 VirtRegInfo[i].Kills[j], RegInfo);
504 VirtRegInfo[i].Kills[j]->addRegisterKilled(i +
505 MRegisterInfo::FirstVirtualRegister,
506 RegInfo);
572507 }
573508
574509 // Check to make sure there are no unreachable blocks in the MC CFG for the
619554 }
620555 }
621556
622 /// transferKillDeadInfo - Similar to instructionChanged except it does not
623 /// update live variables internal data structures.
624 void LiveVariables::transferKillDeadInfo(MachineInstr *OldMI,
625 MachineInstr *NewMI,
626 const MRegisterInfo *RegInfo) {
627 // If the instruction defines any virtual registers, update the VarInfo,
628 // kill and dead information for the instruction.
629 for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) {
630 MachineOperand &MO = OldMI->getOperand(i);
631 if (MO.isRegister() && MO.getReg() &&
632 MRegisterInfo::isVirtualRegister(MO.getReg())) {
633 unsigned Reg = MO.getReg();
634 if (MO.isDef()) {
635 if (MO.isDead()) {
636 MO.setIsDead(false);
637 addRegisterDead(Reg, NewMI, RegInfo);
638 }
639 }
640 if (MO.isKill()) {
641 MO.setIsKill(false);
642 addRegisterKilled(Reg, NewMI, RegInfo);
643 }
644 }
645 }
646 }
647
648
649557 /// removeVirtualRegistersKilled - Remove all killed info for the specified
650558 /// instruction.
651559 void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) {
622622 OS << "\n";
623623 }
624624
625 bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
626 const MRegisterInfo *RegInfo,
627 bool AddIfNotFound) {
628 bool Found = false;
629 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
630 MachineOperand &MO = getOperand(i);
631 if (MO.isRegister() && MO.isUse()) {
632 unsigned Reg = MO.getReg();
633 if (!Reg)
634 continue;
635 if (Reg == IncomingReg) {
636 MO.setIsKill();
637 Found = true;
638 break;
639 } else if (MRegisterInfo::isPhysicalRegister(Reg) &&
640 MRegisterInfo::isPhysicalRegister(IncomingReg) &&
641 RegInfo->isSuperRegister(IncomingReg, Reg) &&
642 MO.isKill())
643 // A super-register kill already exists.
644 Found = true;
645 }
646 }
647
648 // If not found, this means an alias of one of the operand is killed. Add a
649 // new implicit operand if required.
650 if (!Found && AddIfNotFound) {
651 addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/,
652 true/*IsImp*/,true/*IsKill*/));
653 return true;
654 }
655 return Found;
656 }
657
658 bool MachineInstr::addRegisterDead(unsigned IncomingReg,
659 const MRegisterInfo *RegInfo,
660 bool AddIfNotFound) {
661 bool Found = false;
662 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
663 MachineOperand &MO = getOperand(i);
664 if (MO.isRegister() && MO.isDef()) {
665 unsigned Reg = MO.getReg();
666 if (!Reg)
667 continue;
668 if (Reg == IncomingReg) {
669 MO.setIsDead();
670 Found = true;
671 break;
672 } else if (MRegisterInfo::isPhysicalRegister(Reg) &&
673 MRegisterInfo::isPhysicalRegister(IncomingReg) &&
674 RegInfo->isSuperRegister(IncomingReg, Reg) &&
675 MO.isDead())
676 // There exists a super-register that's marked dead.
677 return true;
678 }
679 }
680
681 // If not found, this means an alias of one of the operand is dead. Add a
682 // new implicit operand.
683 if (!Found && AddIfNotFound) {
684 addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/,
685 true/*IsImp*/,false/*IsKill*/,
686 true/*IsDead*/));
687 return true;
688 }
689 return Found;
690 }
691
692 /// copyKillDeadInfo - copies killed/dead information from one instr to another
693 void MachineInstr::copyKillDeadInfo(MachineInstr *OldMI,
694 const MRegisterInfo *RegInfo) {
695 // If the instruction defines any virtual registers, update the VarInfo,
696 // kill and dead information for the instruction.
697 for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) {
698 MachineOperand &MO = OldMI->getOperand(i);
699 if (MO.isRegister() && MO.getReg() &&
700 MRegisterInfo::isVirtualRegister(MO.getReg())) {
701 unsigned Reg = MO.getReg();
702 if (MO.isDef()) {
703 if (MO.isDead()) {
704 MO.setIsDead(false);
705 addRegisterDead(Reg, RegInfo);
706 }
707 }
708 if (MO.isKill()) {
709 MO.setIsKill(false);
710 addRegisterKilled(Reg, RegInfo);
711 }
712 }
713 }
714 }