Index: lib/Transforms/Scalar/CallSiteSplitting.cpp =================================================================== --- lib/Transforms/Scalar/CallSiteSplitting.cpp +++ lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -237,7 +237,8 @@ /// created in createCallSitesOnPredicatedArgument(). static void splitCallSite( CallSite CS, - const SmallVectorImpl> &Preds) { + const SmallVectorImpl> &Preds, + DominatorTree *DT) { Instruction *Instr = CS.getInstruction(); BasicBlock *TailBB = Instr->getParent(); @@ -249,7 +250,7 @@ for (const auto &P : Preds) { BasicBlock *PredBB = P.first; BasicBlock *SplitBlock = - SplitBlockPredecessors(TailBB, PredBB, ".predBB.split"); + SplitBlockPredecessors(TailBB, PredBB, ".predBB.split", DT); assert(SplitBlock && "Unexpected new basic block split."); Instruction *NewCI = Instr->clone(); @@ -311,18 +312,18 @@ return false; } -static bool tryToSplitOnPHIPredicatedArgument(CallSite CS) { +static bool tryToSplitOnPHIPredicatedArgument(CallSite CS, DominatorTree *DT) { if (!isPredicatedOnPHI(CS)) return false; auto Preds = getTwoPredecessors(CS.getInstruction()->getParent()); SmallVector, 2> PredsCS = { {Preds[0], {}}, {Preds[1], {}}}; - splitCallSite(CS, PredsCS); + splitCallSite(CS, PredsCS, DT); return true; } -static bool tryToSplitOnPredicatedArgument(CallSite CS) { +static bool tryToSplitOnPredicatedArgument(CallSite CS, DominatorTree *DT) { auto Preds = getTwoPredecessors(CS.getInstruction()->getParent()); if (Preds[0] == Preds[1]) return false; @@ -340,18 +341,19 @@ })) return false; - splitCallSite(CS, PredsCS); + splitCallSite(CS, PredsCS, DT); return true; } -static bool tryToSplitCallSite(CallSite CS) { +static bool tryToSplitCallSite(CallSite CS, DominatorTree *DT) { if (!CS.arg_size() || !canSplitCallSite(CS)) return false; - return tryToSplitOnPredicatedArgument(CS) || - tryToSplitOnPHIPredicatedArgument(CS); + return tryToSplitOnPredicatedArgument(CS, DT) || + tryToSplitOnPHIPredicatedArgument(CS, DT); } -static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI) { +static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI, + DominatorTree *DT) { bool Changed = false; for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) { BasicBlock &BB = *BI++; @@ -364,7 +366,7 @@ Function *Callee = CS.getCalledFunction(); if (!Callee || Callee->isDeclaration()) continue; - Changed |= tryToSplitCallSite(CS); + Changed |= tryToSplitCallSite(CS, DT); } } return Changed; @@ -379,6 +381,8 @@ void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); + + AU.addPreserved(); FunctionPass::getAnalysisUsage(AU); } @@ -387,7 +391,8 @@ return false; auto &TLI = getAnalysis().getTLI(); - return doCallSiteSplitting(F, TLI); + auto *DTWP = getAnalysisIfAvailable(); + return doCallSiteSplitting(F, TLI, DTWP ? &DTWP->getDomTree() : nullptr); } }; } // namespace @@ -405,9 +410,11 @@ PreservedAnalyses CallSiteSplittingPass::run(Function &F, FunctionAnalysisManager &AM) { auto &TLI = AM.getResult(F); + auto *DT = AM.getCachedResult(F); - if (!doCallSiteSplitting(F, TLI)) + if (!doCallSiteSplitting(F, TLI, DT)) return PreservedAnalyses::all(); PreservedAnalyses PA; + PA.preserve(); return PA; }