diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -113,11 +113,13 @@ /// PHI for EH values from landingpad insts. PHINode *InnerEHValuesPHI = nullptr; + BlockFrequencyInfo *BFI; + SmallVector UnwindDestPHIValues; public: - LandingPadInliningInfo(InvokeInst *II) - : OuterResumeDest(II->getUnwindDest()) { + LandingPadInliningInfo(InvokeInst *II, BlockFrequencyInfo *BFI) + : OuterResumeDest(II->getUnwindDest()), BFI(BFI) { // If there are PHI nodes in the unwind destination block, we need to keep // track of which values came into them from the invoke before removing // the edge from this block. @@ -176,6 +178,10 @@ InnerResumeDest = OuterResumeDest->splitBasicBlock(SplitPoint, OuterResumeDest->getName() + ".body"); + // Copy OuterResumeDest's block frequency to InnerResumeDest + if (BFI) + BFI->setBlockFreq(InnerResumeDest, + BFI->getBlockFreq(OuterResumeDest).getFrequency()); // The number of incoming edges we expect to the inner landing pad. const unsigned PHICapacity = 2; @@ -528,7 +534,7 @@ /// it rewrites them to be invokes that jump to InvokeDest and fills in the PHI /// nodes in that block with the values specified in InvokeDestPHIValues. static BasicBlock *HandleCallsInBlockInlinedThroughInvoke( - BasicBlock *BB, BasicBlock *UnwindEdge, + BasicBlock *BB, BasicBlock *UnwindEdge, BlockFrequencyInfo *BFI, UnwindDestMemoTy *FuncletUnwindMap = nullptr) { for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) { Instruction *I = &*BBI++; @@ -576,7 +582,10 @@ #endif // NDEBUG } - changeToInvokeAndSplitBasicBlock(CI, UnwindEdge); + BasicBlock *Split = changeToInvokeAndSplitBasicBlock(CI, UnwindEdge); + // Copy BB's block frequency to Split + if (BFI) + BFI->setBlockFreq(Split, BFI->getBlockFreq(BB).getFrequency()); return BB; } return nullptr; @@ -589,6 +598,7 @@ /// block of the inlined code (the last block is the end of the function), /// and InlineCodeInfo is information about the code that got inlined. static void HandleInlinedLandingPad(InvokeInst *II, BasicBlock *FirstNewBlock, + BlockFrequencyInfo *BFI, ClonedCodeInfo &InlinedCodeInfo) { BasicBlock *InvokeDest = II->getUnwindDest(); @@ -597,7 +607,7 @@ // The inlined code is currently at the end of the function, scan from the // start of the inlined code to its end, checking for stuff we need to // rewrite. - LandingPadInliningInfo Invoke(II); + LandingPadInliningInfo Invoke(II, BFI); // Get all of the inlined landing pad instructions. SmallPtrSet InlinedLPads; @@ -622,7 +632,7 @@ BB != E; ++BB) { if (InlinedCodeInfo.ContainsCalls) if (BasicBlock *NewBB = HandleCallsInBlockInlinedThroughInvoke( - &*BB, Invoke.getOuterResumeDest())) + &*BB, Invoke.getOuterResumeDest(), BFI)) // Update any PHI nodes in the exceptional block to indicate that there // is now a new entry in them. Invoke.addIncomingPHIValuesFor(NewBB); @@ -646,6 +656,7 @@ /// block of the inlined code (the last block is the end of the function), /// and InlineCodeInfo is information about the code that got inlined. static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock, + BlockFrequencyInfo *BFI, ClonedCodeInfo &InlinedCodeInfo) { BasicBlock *UnwindDest = II->getUnwindDest(); Function *Caller = FirstNewBlock->getParent(); @@ -759,7 +770,7 @@ E = Caller->end(); BB != E; ++BB) if (BasicBlock *NewBB = HandleCallsInBlockInlinedThroughInvoke( - &*BB, UnwindDest, &FuncletUnwindMap)) + &*BB, UnwindDest, BFI, &FuncletUnwindMap)) // Update any PHI nodes in the exceptional block to indicate that there // is now a new entry in them. UpdatePHINodes(NewBB); @@ -2128,9 +2139,11 @@ BasicBlock *UnwindDest = II->getUnwindDest(); Instruction *FirstNonPHI = UnwindDest->getFirstNonPHI(); if (isa(FirstNonPHI)) { - HandleInlinedLandingPad(II, &*FirstNewBlock, InlinedFunctionInfo); + HandleInlinedLandingPad(II, &*FirstNewBlock, IFI.CallerBFI, + InlinedFunctionInfo); } else { - HandleInlinedEHPad(II, &*FirstNewBlock, InlinedFunctionInfo); + HandleInlinedEHPad(II, &*FirstNewBlock, IFI.CallerBFI, + InlinedFunctionInfo); } }