llvm.org GIT mirror llvm / 18f2445
TargetInstrInfo: Change duplicate() to work on bundles. Adds infrastructure to clone whole instruction bundles rather than just single instructions. This fixes a bug where tail duplication would unbundle instructions while cloning. This should unbreak the "Clang Stage 1: cmake, RA, with expensive checks enabled" build on greendragon. The bot broke with r311139 hitting this pre-existing bug. A proper testcase will come next. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311511 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 3 years ago
7 changed file(s) with 74 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
624624 MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL,
625625 bool NoImp = false);
626626
627 /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
628 /// 'Orig' instruction, identical in all ways except the instruction
629 /// has no parent, prev, or next.
627 /// Create a new MachineInstr which is a copy of \p Orig, identical in all
628 /// ways except the instruction has no parent, prev, or next. Bundling flags
629 /// are reset.
630630 ///
631 /// See also TargetInstrInfo::duplicate() for target-specific fixes to cloned
632 /// instructions.
631 /// Note: Clones a single instruction, not whole instruction bundles.
632 /// Does not perform target specific adjustments; consider using
633 /// TargetInstrInfo::duplicate() instead.
633634 MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
635
636 /// Clones instruction or the whole instruction bundle \p Orig and insert
637 /// into \p MBB before \p InsertBefore.
638 ///
639 /// Note: Does not perform target specific adjustments; consider using
640 /// TargetInstrInfo::duplicate() intead.
641 MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB,
642 MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig);
634643
635644 /// DeleteMachineInstr - Delete the given MachineInstr.
636645 void DeleteMachineInstr(MachineInstr *MI);
323323 unsigned SubIdx, const MachineInstr &Orig,
324324 const TargetRegisterInfo &TRI) const;
325325
326 /// Create a duplicate of the Orig instruction in MF. This is like
327 /// MachineFunction::CloneMachineInstr(), but the target may update operands
326 /// \brief Clones instruction or the whole instruction bundle \p Orig and
327 /// insert into \p MBB before \p InsertBefore. The target may update operands
328328 /// that are required to be unique.
329329 ///
330 /// The instruction must be duplicable as indicated by isNotDuplicable().
331 virtual MachineInstr *duplicate(MachineInstr &Orig,
332 MachineFunction &MF) const;
330 /// \p Orig must not return true for MachineInstr::isNotDuplicable().
331 virtual MachineInstr &duplicate(MachineBasicBlock &MBB,
332 MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) const;
333333
334334 /// This method must be implemented by targets that
335335 /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
269269 MachineInstr(*this, *Orig);
270270 }
271271
272 MachineInstr &MachineFunction::CloneMachineInstrBundle(MachineBasicBlock &MBB,
273 MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) {
274 MachineInstr *FirstClone = nullptr;
275 MachineBasicBlock::const_instr_iterator I = Orig.getIterator();
276 for (;;) {
277 MachineInstr *Cloned = CloneMachineInstr(&*I);
278 MBB.insert(InsertBefore, Cloned);
279 if (FirstClone == nullptr) {
280 FirstClone = Cloned;
281 } else {
282 Cloned->bundleWithPred();
283 }
284
285 if (!I->isBundledWithSucc())
286 break;
287 ++I;
288 }
289 return *FirstClone;
290 }
291
272292 /// Delete the given MachineInstr.
273293 ///
274294 /// This function also serves as the MachineInstr destructor - the real
368368 MachineInstr *MI, MachineBasicBlock *TailBB, MachineBasicBlock *PredBB,
369369 DenseMap &LocalVRMap,
370370 const DenseSet &UsedByPhi) {
371 MachineInstr *NewMI = TII->duplicate(*MI, *MF);
371 MachineInstr &NewMI = TII->duplicate(*PredBB, PredBB->end(), *MI);
372372 if (PreRegAlloc) {
373 for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) {
374 MachineOperand &MO = NewMI->getOperand(i);
373 for (unsigned i = 0, e = NewMI.getNumOperands(); i != e; ++i) {
374 MachineOperand &MO = NewMI.getOperand(i);
375375 if (!MO.isReg())
376376 continue;
377377 unsigned Reg = MO.getReg();
442442 }
443443 }
444444 }
445 PredBB->insert(PredBB->instr_end(), NewMI);
446445 }
447446
448447 /// After FromBB is tail duplicated into its predecessor blocks, the successors
824823 // Clone the contents of TailBB into PredBB.
825824 DenseMap LocalVRMap;
826825 SmallVector, 4> CopyInfos;
827 // Use instr_iterator here to properly handle bundles, e.g.
828 // ARM Thumb2 IT block.
829 MachineBasicBlock::instr_iterator I = TailBB->instr_begin();
830 while (I != TailBB->instr_end()) {
826 for (MachineBasicBlock::iterator I = TailBB->begin(), E = TailBB->end();
827 I != E; /* empty */) {
831828 MachineInstr *MI = &*I;
832829 ++I;
833830 if (MI->isPHI()) {
387387 return MI0.isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs);
388388 }
389389
390 MachineInstr *TargetInstrInfo::duplicate(MachineInstr &Orig,
391 MachineFunction &MF) const {
390 MachineInstr &TargetInstrInfo::duplicate(MachineBasicBlock &MBB,
391 MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig) const {
392392 assert(!Orig.isNotDuplicable() && "Instruction cannot be duplicated");
393 return MF.CloneMachineInstr(&Orig);
393 MachineFunction &MF = *MBB.getParent();
394 return MF.CloneMachineInstrBundle(MBB, InsertBefore, Orig);
394395 }
395396
396397 // If the COPY instruction in MI can be folded to a stack operation, return
15491549 }
15501550 }
15511551
1552 MachineInstr *ARMBaseInstrInfo::duplicate(MachineInstr &Orig,
1553 MachineFunction &MF) const {
1554 MachineInstr *MI = TargetInstrInfo::duplicate(Orig, MF);
1555 switch (Orig.getOpcode()) {
1556 case ARM::tLDRpci_pic:
1557 case ARM::t2LDRpci_pic: {
1558 unsigned CPI = Orig.getOperand(1).getIndex();
1559 unsigned PCLabelId = duplicateCPV(MF, CPI);
1560 Orig.getOperand(1).setIndex(CPI);
1561 Orig.getOperand(2).setImm(PCLabelId);
1562 break;
1563 }
1564 }
1565 return MI;
1552 MachineInstr &
1553 ARMBaseInstrInfo::duplicate(MachineBasicBlock &MBB,
1554 MachineBasicBlock::iterator InsertBefore,
1555 const MachineInstr &Orig) const {
1556 MachineInstr &Cloned = TargetInstrInfo::duplicate(MBB, InsertBefore, Orig);
1557 MachineBasicBlock::instr_iterator I = Cloned.getIterator();
1558 for (;;) {
1559 switch (I->getOpcode()) {
1560 case ARM::tLDRpci_pic:
1561 case ARM::t2LDRpci_pic: {
1562 MachineFunction &MF = *MBB.getParent();
1563 unsigned CPI = I->getOperand(1).getIndex();
1564 unsigned PCLabelId = duplicateCPV(MF, CPI);
1565 I->getOperand(1).setIndex(CPI);
1566 I->getOperand(2).setImm(PCLabelId);
1567 break;
1568 }
1569 }
1570 if (!I->isBundledWithSucc())
1571 break;
1572 ++I;
1573 }
1574 return Cloned;
15661575 }
15671576
15681577 bool ARMBaseInstrInfo::produceSameValue(const MachineInstr &MI0,
219219 const MachineInstr &Orig,
220220 const TargetRegisterInfo &TRI) const override;
221221
222 MachineInstr *duplicate(MachineInstr &Orig,
223 MachineFunction &MF) const override;
222 MachineInstr &
223 duplicate(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore,
224 const MachineInstr &Orig) const override;
224225
225226 const MachineInstrBuilder &AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
226227 unsigned SubIdx, unsigned State,