diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-31 21:22:58 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-31 21:22:58 +0000 |
commit | 5ffd83dbcc34f10e07f6d3e968ae6365869615f4 (patch) | |
tree | 0e9f5cf729dde39f949698fddef45a34e2bc7f44 /contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp | |
parent | 1799696096df87b52968b8996d00c91e0a5de8d9 (diff) | |
parent | cfca06d7963fa0909f90483b42a6d7d194d01e08 (diff) | |
download | src-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.tar.gz src-5ffd83dbcc34f10e07f6d3e968ae6365869615f4.zip |
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
master 2e10b7a39b9, the last commit before the llvmorg-12-init tag, from
which release/11.x was branched.
Note that for now, I rolled back all our local changes to make merging
easier, and I will reapply the still-relevant ones after updating to
11.0.0-rc1.
Notes
Notes:
svn path=/projects/clang1100-import/; revision=363742
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp index 239b6fd6fd68..5f958bbc31b7 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineSink.cpp @@ -91,7 +91,7 @@ namespace { MachineDominatorTree *DT; // Machine dominator tree MachinePostDominatorTree *PDT; // Machine post dominator tree MachineLoopInfo *LI; - const MachineBlockFrequencyInfo *MBFI; + MachineBlockFrequencyInfo *MBFI; const MachineBranchProbabilityInfo *MBPI; AliasAnalysis *AA; @@ -279,7 +279,7 @@ MachineSinking::AllUsesDominatedByBlock(unsigned Reg, // // %bb.2: // %p = PHI %y, %bb.0, %def, %bb.1 - if (llvm::all_of(MRI->use_nodbg_operands(Reg), [&](MachineOperand &MO) { + if (all_of(MRI->use_nodbg_operands(Reg), [&](MachineOperand &MO) { MachineInstr *UseInst = MO.getParent(); unsigned OpNo = UseInst->getOperandNo(&MO); MachineBasicBlock *UseBlock = UseInst->getParent(); @@ -347,6 +347,11 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { << printMBBReference(*Pair.first) << " -- " << printMBBReference(*NewSucc) << " -- " << printMBBReference(*Pair.second) << '\n'); + if (MBFI) { + auto NewSuccFreq = MBFI->getBlockFreq(Pair.first) * + MBPI->getEdgeProbability(Pair.first, NewSucc); + MBFI->setBlockFreq(NewSucc, NewSuccFreq.getFrequency()); + } MadeChange = true; ++NumSplit; } else @@ -427,7 +432,7 @@ void MachineSinking::ProcessDbgInst(MachineInstr &MI) { MI.getDebugLoc()->getInlinedAt()); bool SeenBefore = SeenDbgVars.count(Var) != 0; - MachineOperand &MO = MI.getOperand(0); + MachineOperand &MO = MI.getDebugOperand(0); if (MO.isReg() && MO.getReg().isVirtual()) SeenDbgUsers[MO.getReg()].push_back(SeenDbgUser(&MI, SeenBefore)); @@ -618,14 +623,13 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB, // if () {} else {} // use x // - const std::vector<MachineDomTreeNode *> &Children = - DT->getNode(MBB)->getChildren(); - for (const auto &DTChild : Children) + for (MachineDomTreeNode *DTChild : DT->getNode(MBB)->children()) { // DomTree children of MBB that have MBB as immediate dominator are added. if (DTChild->getIDom()->getBlock() == MI.getParent() && // Skip MBBs already added to the AllSuccs vector above. !MBB->isSuccessor(DTChild->getBlock())) AllSuccs.push_back(DTChild->getBlock()); + } // Sort Successors according to their loop depth or block frequency info. llvm::stable_sort( @@ -729,6 +733,13 @@ MachineSinking::FindSuccToSinkTo(MachineInstr &MI, MachineBasicBlock *MBB, if (SuccToSinkTo && SuccToSinkTo->isEHPad()) return nullptr; + // It ought to be okay to sink instructions into an INLINEASM_BR target, but + // only if we make sure that MI occurs _before_ an INLINEASM_BR instruction in + // the source block (which this code does not yet do). So for now, forbid + // doing so. + if (SuccToSinkTo && SuccToSinkTo->isInlineAsmBrIndirectTarget()) + return nullptr; + return SuccToSinkTo; } @@ -760,7 +771,8 @@ static bool SinkingPreventsImplicitNullCheck(MachineInstr &MI, const MachineOperand *BaseOp; int64_t Offset; - if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, TRI)) + bool OffsetIsScalable; + if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, OffsetIsScalable, TRI)) return false; if (!BaseOp->isReg()) @@ -790,7 +802,7 @@ static bool attemptDebugCopyProp(MachineInstr &SinkInst, MachineInstr &DbgMI) { // Copy DBG_VALUE operand and set the original to undef. We then check to // see whether this is something that can be copy-forwarded. If it isn't, // continue around the loop. - MachineOperand DbgMO = DbgMI.getOperand(0); + MachineOperand &DbgMO = DbgMI.getDebugOperand(0); const MachineOperand *SrcMO = nullptr, *DstMO = nullptr; auto CopyOperands = TII.isCopyInstr(SinkInst); @@ -824,8 +836,8 @@ static bool attemptDebugCopyProp(MachineInstr &SinkInst, MachineInstr &DbgMI) { if (PostRA && DbgMO.getReg() != DstMO->getReg()) return false; - DbgMI.getOperand(0).setReg(SrcMO->getReg()); - DbgMI.getOperand(0).setSubReg(SrcMO->getSubReg()); + DbgMO.setReg(SrcMO->getReg()); + DbgMO.setSubReg(SrcMO->getSubReg()); return true; } @@ -860,7 +872,7 @@ static void performSink(MachineInstr &MI, MachineBasicBlock &SuccToSinkTo, SuccToSinkTo.insert(InsertPos, NewDbgMI); if (!attemptDebugCopyProp(MI, *DbgMI)) - DbgMI->getOperand(0).setReg(0); + DbgMI->setDebugValueUndef(); } } @@ -994,7 +1006,7 @@ bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore, // This DBG_VALUE would re-order assignments. If we can't copy-propagate // it, it can't be recovered. Set it undef. if (!attemptDebugCopyProp(MI, *DbgMI)) - DbgMI->getOperand(0).setReg(0); + DbgMI->setDebugValueUndef(); } else { DbgUsersToSink.push_back(DbgMI); } @@ -1043,7 +1055,7 @@ void MachineSinking::SalvageUnsunkDebugUsersOfCopy( if (User.getParent() == MI.getParent()) continue; - assert(User.getOperand(0).isReg() && + assert(User.getDebugOperand(0).isReg() && "DBG_VALUE user of vreg, but non reg operand?"); DbgDefUsers.push_back(&User); } @@ -1052,8 +1064,8 @@ void MachineSinking::SalvageUnsunkDebugUsersOfCopy( // Point the users of this copy that are no longer dominated, at the source // of the copy. for (auto *User : DbgDefUsers) { - User->getOperand(0).setReg(MI.getOperand(1).getReg()); - User->getOperand(0).setSubReg(MI.getOperand(1).getSubReg()); + User->getDebugOperand(0).setReg(MI.getOperand(1).getReg()); + User->getDebugOperand(0).setSubReg(MI.getOperand(1).getSubReg()); } } @@ -1299,7 +1311,7 @@ bool PostRAMachineSinking::tryToSinkCopy(MachineBasicBlock &CurBB, // We must sink this DBG_VALUE if its operand is sunk. To avoid searching // for DBG_VALUEs later, record them when they're encountered. if (MI->isDebugValue()) { - auto &MO = MI->getOperand(0); + auto &MO = MI->getDebugOperand(0); if (MO.isReg() && Register::isPhysicalRegister(MO.getReg())) { // Bail if we can already tell the sink would be rejected, rather // than needlessly accumulating lots of DBG_VALUEs. |