diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index 597cec8e61c9..0a3d8d6000cf 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1593,8 +1593,8 @@ static void insertTrivialPHIs(CHRScope *Scope, // Insert a trivial phi for I (phi [&I, P0], [&I, P1], ...) at // ExitBlock. Replace I with the new phi in UI unless UI is another // phi at ExitBlock. - PHINode *PN = PHINode::Create(I.getType(), pred_size(ExitBlock), "", - &ExitBlock->front()); + PHINode *PN = PHINode::Create(I.getType(), pred_size(ExitBlock), ""); + PN->insertBefore(ExitBlock->begin()); for (BasicBlock *Pred : predecessors(ExitBlock)) { PN->addIncoming(&I, Pred); } @@ -1780,17 +1780,10 @@ void CHR::cloneScopeBlocks(CHRScope *Scope, // Unreachable predecessors will not be cloned and will not have an edge // to the cloned block. As such, also remove them from any phi nodes. - // To avoid iterator invalidation, first collect the dead predecessors - // from the first phi node, and then perform the actual removal. - if (auto *FirstPN = dyn_cast<PHINode>(NewBB->begin())) { - SmallVector<BasicBlock *> DeadPreds; - for (BasicBlock *Pred : FirstPN->blocks()) - if (!DT.isReachableFromEntry(Pred)) - DeadPreds.push_back(Pred); - for (PHINode &PN : make_early_inc_range(NewBB->phis())) - for (BasicBlock *Pred : DeadPreds) - PN.removeIncomingValue(Pred); - } + for (PHINode &PN : make_early_inc_range(NewBB->phis())) + PN.removeIncomingValueIf([&](unsigned Idx) { + return !DT.isReachableFromEntry(PN.getIncomingBlock(Idx)); + }); } // Place the cloned blocks right after the original blocks (right before the @@ -1885,8 +1878,7 @@ void CHR::fixupBranchesAndSelects(CHRScope *Scope, static_cast<uint32_t>(CHRBranchBias.scale(1000)), static_cast<uint32_t>(CHRBranchBias.getCompl().scale(1000)), }; - MDBuilder MDB(F.getContext()); - MergedBR->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights)); + setBranchWeights(*MergedBR, Weights); CHR_DEBUG(dbgs() << "CHR branch bias " << Weights[0] << ":" << Weights[1] << "\n"); } |
