diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp | 75 | 
1 files changed, 42 insertions, 33 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp index 4d29e883d879..f433c4b6c90b 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -39,6 +39,12 @@ using namespace llvm;  #define DEBUG_TYPE "codegen" +static cl::opt<bool> PrintSlotIndexes( +    "print-slotindexes", +    cl::desc("When printing machine IR, annotate instructions and blocks with " +             "SlotIndexes when available"), +    cl::init(true), cl::Hidden); +  MachineBasicBlock::MachineBasicBlock(MachineFunction &MF, const BasicBlock *B)      : BB(B), Number(-1), xParent(&MF) {    Insts.Parent = this; @@ -291,7 +297,7 @@ void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST,      return;    } -  if (Indexes) +  if (Indexes && PrintSlotIndexes)      OS << Indexes->getMBBStartIdx(this) << '\t';    OS << "bb." << getNumber(); @@ -320,9 +326,9 @@ void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST,      OS << "landing-pad";      HasAttributes = true;    } -  if (getAlignment()) { +  if (getAlignment() != Align::None()) {      OS << (HasAttributes ? ", " : " ("); -    OS << "align " << getAlignment(); +    OS << "align " << Log2(getAlignment());      HasAttributes = true;    }    if (HasAttributes) @@ -402,7 +408,7 @@ void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST,    bool IsInBundle = false;    for (const MachineInstr &MI : instrs()) { -    if (Indexes) { +    if (Indexes && PrintSlotIndexes) {        if (Indexes->hasIndex(MI))          OS << Indexes->getInstructionIndex(MI);        OS << '\t'; @@ -484,9 +490,9 @@ void MachineBasicBlock::sortUniqueLiveIns() {  }  unsigned -MachineBasicBlock::addLiveIn(MCPhysReg PhysReg, const TargetRegisterClass *RC) { +MachineBasicBlock::addLiveIn(MCRegister PhysReg, const TargetRegisterClass *RC) {    assert(getParent() && "MBB must be inserted in function"); -  assert(TargetRegisterInfo::isPhysicalRegister(PhysReg) && "Expected physreg"); +  assert(PhysReg.isPhysical() && "Expected physreg");    assert(RC && "Register class is required");    assert((isEHPad() || this == &getParent()->front()) &&           "Only the entry block and landing pads can have physreg live ins"); @@ -500,14 +506,14 @@ MachineBasicBlock::addLiveIn(MCPhysReg PhysReg, const TargetRegisterClass *RC) {    if (LiveIn)      for (;I != E && I->isCopy(); ++I)        if (I->getOperand(1).getReg() == PhysReg) { -        unsigned VirtReg = I->getOperand(0).getReg(); +        Register VirtReg = I->getOperand(0).getReg();          if (!MRI.constrainRegClass(VirtReg, RC))            llvm_unreachable("Incompatible live-in register class.");          return VirtReg;        }    // No luck, create a virtual register. -  unsigned VirtReg = MRI.createVirtualRegister(RC); +  Register VirtReg = MRI.createVirtualRegister(RC);    BuildMI(*this, I, DebugLoc(), TII.get(TargetOpcode::COPY), VirtReg)      .addReg(PhysReg, RegState::Kill);    if (!LiveIn) @@ -772,7 +778,8 @@ void MachineBasicBlock::transferSuccessors(MachineBasicBlock *FromMBB) {    while (!FromMBB->succ_empty()) {      MachineBasicBlock *Succ = *FromMBB->succ_begin(); -    // If probability list is empty it means we don't use it (disabled optimization). +    // If probability list is empty it means we don't use it (disabled +    // optimization).      if (!FromMBB->Probs.empty()) {        auto Prob = *FromMBB->Probs.begin();        addSuccessor(Succ, Prob); @@ -798,13 +805,7 @@ MachineBasicBlock::transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB) {      FromMBB->removeSuccessor(Succ);      // Fix up any PHI nodes in the successor. -    for (MachineBasicBlock::instr_iterator MI = Succ->instr_begin(), -           ME = Succ->instr_end(); MI != ME && MI->isPHI(); ++MI) -      for (unsigned i = 2, e = MI->getNumOperands()+1; i != e; i += 2) { -        MachineOperand &MO = MI->getOperand(i); -        if (MO.getMBB() == FromMBB) -          MO.setMBB(this); -      } +    Succ->replacePhiUsesWith(FromMBB, this);    }    normalizeSuccProbs();  } @@ -907,8 +908,8 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,          if (!OI->isReg() || OI->getReg() == 0 ||              !OI->isUse() || !OI->isKill() || OI->isUndef())            continue; -        unsigned Reg = OI->getReg(); -        if (TargetRegisterInfo::isPhysicalRegister(Reg) || +        Register Reg = OI->getReg(); +        if (Register::isPhysicalRegister(Reg) ||              LV->getVarInfo(Reg).removeKill(*MI)) {            KilledRegs.push_back(Reg);            LLVM_DEBUG(dbgs() << "Removing terminator kill: " << *MI); @@ -928,7 +929,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,          if (!OI->isReg() || OI->getReg() == 0)            continue; -        unsigned Reg = OI->getReg(); +        Register Reg = OI->getReg();          if (!is_contained(UsedRegs, Reg))            UsedRegs.push_back(Reg);        } @@ -979,13 +980,8 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,      }    } -  // Fix PHI nodes in Succ so they refer to NMBB instead of this -  for (MachineBasicBlock::instr_iterator -         i = Succ->instr_begin(),e = Succ->instr_end(); -       i != e && i->isPHI(); ++i) -    for (unsigned ni = 1, ne = i->getNumOperands(); ni != ne; ni += 2) -      if (i->getOperand(ni+1).getMBB() == this) -        i->getOperand(ni+1).setMBB(NMBB); +  // Fix PHI nodes in Succ so they refer to NMBB instead of this. +  Succ->replacePhiUsesWith(this, NMBB);    // Inherit live-ins from the successor    for (const auto &LI : Succ->liveins()) @@ -1000,7 +996,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,        for (instr_iterator I = instr_end(), E = instr_begin(); I != E;) {          if (!(--I)->addRegisterKilled(Reg, TRI, /* AddIfNotFound= */ false))            continue; -        if (TargetRegisterInfo::isVirtualRegister(Reg)) +        if (Register::isVirtualRegister(Reg))            LV->getVarInfo(Reg).Kills.push_back(&*I);          LLVM_DEBUG(dbgs() << "Restored terminator kill: " << *I);          break; @@ -1033,7 +1029,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,        for (unsigned ni = 1, ne = I->getNumOperands(); ni != ne; ni += 2) {          if (I->getOperand(ni+1).getMBB() == NMBB) {            MachineOperand &MO = I->getOperand(ni); -          unsigned Reg = MO.getReg(); +          Register Reg = MO.getReg();            PHISrcRegs.insert(Reg);            if (MO.isUndef())              continue; @@ -1049,7 +1045,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ,      MachineRegisterInfo *MRI = &getParent()->getRegInfo();      for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { -      unsigned Reg = TargetRegisterInfo::index2VirtReg(i); +      unsigned Reg = Register::index2VirtReg(i);        if (PHISrcRegs.count(Reg) || !LIS->hasInterval(Reg))          continue; @@ -1217,6 +1213,16 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old,    replaceSuccessor(Old, New);  } +void MachineBasicBlock::replacePhiUsesWith(MachineBasicBlock *Old, +                                           MachineBasicBlock *New) { +  for (MachineInstr &MI : phis()) +    for (unsigned i = 2, e = MI.getNumOperands() + 1; i != e; i += 2) { +      MachineOperand &MO = MI.getOperand(i); +      if (MO.getMBB() == Old) +        MO.setMBB(New); +    } +} +  /// Various pieces of code can cause excess edges in the CFG to be inserted.  If  /// we have proven that MBB can only branch to DestA and DestB, remove any other  /// MBB successors from the CFG.  DestA and DestB can be null. @@ -1389,8 +1395,7 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,      --N; -    MachineOperandIteratorBase::PhysRegInfo Info = -        ConstMIOperands(*I).analyzePhysReg(Reg, TRI); +    PhysRegInfo Info = AnalyzePhysRegInBundle(*I, Reg, TRI);      // Register is live when we read it here.      if (Info.Read) @@ -1428,8 +1433,7 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,        --N; -      MachineOperandIteratorBase::PhysRegInfo Info = -          ConstMIOperands(*I).analyzePhysReg(Reg, TRI); +      PhysRegInfo Info = AnalyzePhysRegInBundle(*I, Reg, TRI);        // Defs happen after uses so they take precedence if both are present. @@ -1456,6 +1460,11 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,      } while (I != begin() && N > 0);    } +  // If all the instructions before this in the block are debug instructions, +  // skip over them. +  while (I != begin() && std::prev(I)->isDebugInstr()) +    --I; +    // Did we get to the start of the block?    if (I == begin()) {      // If so, the register's state is definitely defined by the live-in state.  | 
