1 //===- CallSiteSplitting.cpp ----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements a transformation that tries to split a call-site to pass 10 // more constrained arguments if its argument is predicated in the control flow 11 // so that we can expose better context to the later passes (e.g, inliner, jump 12 // threading, or IPA-CP based function cloning, etc.). 13 // As of now we support two cases : 14 // 15 // 1) Try to a split call-site with constrained arguments, if any constraints 16 // on any argument can be found by following the single predecessors of the 17 // all site's predecessors. Currently this pass only handles call-sites with 2 18 // predecessors. For example, in the code below, we try to split the call-site 19 // since we can predicate the argument(ptr) based on the OR condition. 20 // 21 // Split from : 22 // if (!ptr || c) 23 // callee(ptr); 24 // to : 25 // if (!ptr) 26 // callee(null) // set the known constant value 27 // else if (c) 28 // callee(nonnull ptr) // set non-null attribute in the argument 29 // 30 // 2) We can also split a call-site based on constant incoming values of a PHI 31 // For example, 32 // from : 33 // Header: 34 // %c = icmp eq i32 %i1, %i2 35 // br i1 %c, label %Tail, label %TBB 36 // TBB: 37 // br label Tail% 38 // Tail: 39 // %p = phi i32 [ 0, %Header], [ 1, %TBB] 40 // call void @bar(i32 %p) 41 // to 42 // Header: 43 // %c = icmp eq i32 %i1, %i2 44 // br i1 %c, label %Tail-split0, label %TBB 45 // TBB: 46 // br label %Tail-split1 47 // Tail-split0: 48 // call void @bar(i32 0) 49 // br label %Tail 50 // Tail-split1: 51 // call void @bar(i32 1) 52 // br label %Tail 53 // Tail: 54 // %p = phi i32 [ 0, %Tail-split0 ], [ 1, %Tail-split1 ] 55 // 56 //===----------------------------------------------------------------------===// 57 58 #include "llvm/Transforms/Scalar/CallSiteSplitting.h" 59 #include "llvm/ADT/Statistic.h" 60 #include "llvm/Analysis/TargetLibraryInfo.h" 61 #include "llvm/Analysis/TargetTransformInfo.h" 62 #include "llvm/IR/IntrinsicInst.h" 63 #include "llvm/IR/PatternMatch.h" 64 #include "llvm/InitializePasses.h" 65 #include "llvm/Support/Debug.h" 66 #include "llvm/Transforms/Scalar.h" 67 #include "llvm/Transforms/Utils/BasicBlockUtils.h" 68 #include "llvm/Transforms/Utils/Cloning.h" 69 #include "llvm/Transforms/Utils/Local.h" 70 71 using namespace llvm; 72 using namespace PatternMatch; 73 74 #define DEBUG_TYPE "callsite-splitting" 75 76 STATISTIC(NumCallSiteSplit, "Number of call-site split"); 77 78 /// Only allow instructions before a call, if their CodeSize cost is below 79 /// DuplicationThreshold. Those instructions need to be duplicated in all 80 /// split blocks. 81 static cl::opt<unsigned> 82 DuplicationThreshold("callsite-splitting-duplication-threshold", cl::Hidden, 83 cl::desc("Only allow instructions before a call, if " 84 "their cost is below DuplicationThreshold"), 85 cl::init(5)); 86 87 static void addNonNullAttribute(CallSite CS, Value *Op) { 88 unsigned ArgNo = 0; 89 for (auto &I : CS.args()) { 90 if (&*I == Op) 91 CS.addParamAttr(ArgNo, Attribute::NonNull); 92 ++ArgNo; 93 } 94 } 95 96 static void setConstantInArgument(CallSite CS, Value *Op, 97 Constant *ConstValue) { 98 unsigned ArgNo = 0; 99 for (auto &I : CS.args()) { 100 if (&*I == Op) { 101 // It is possible we have already added the non-null attribute to the 102 // parameter by using an earlier constraining condition. 103 CS.removeParamAttr(ArgNo, Attribute::NonNull); 104 CS.setArgument(ArgNo, ConstValue); 105 } 106 ++ArgNo; 107 } 108 } 109 110 static bool isCondRelevantToAnyCallArgument(ICmpInst *Cmp, CallSite CS) { 111 assert(isa<Constant>(Cmp->getOperand(1)) && "Expected a constant operand."); 112 Value *Op0 = Cmp->getOperand(0); 113 unsigned ArgNo = 0; 114 for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E; 115 ++I, ++ArgNo) { 116 // Don't consider constant or arguments that are already known non-null. 117 if (isa<Constant>(*I) || CS.paramHasAttr(ArgNo, Attribute::NonNull)) 118 continue; 119 120 if (*I == Op0) 121 return true; 122 } 123 return false; 124 } 125 126 typedef std::pair<ICmpInst *, unsigned> ConditionTy; 127 typedef SmallVector<ConditionTy, 2> ConditionsTy; 128 129 /// If From has a conditional jump to To, add the condition to Conditions, 130 /// if it is relevant to any argument at CS. 131 static void recordCondition(CallSite CS, BasicBlock *From, BasicBlock *To, 132 ConditionsTy &Conditions) { 133 auto *BI = dyn_cast<BranchInst>(From->getTerminator()); 134 if (!BI || !BI->isConditional()) 135 return; 136 137 CmpInst::Predicate Pred; 138 Value *Cond = BI->getCondition(); 139 if (!match(Cond, m_ICmp(Pred, m_Value(), m_Constant()))) 140 return; 141 142 ICmpInst *Cmp = cast<ICmpInst>(Cond); 143 if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE) 144 if (isCondRelevantToAnyCallArgument(Cmp, CS)) 145 Conditions.push_back({Cmp, From->getTerminator()->getSuccessor(0) == To 146 ? Pred 147 : Cmp->getInversePredicate()}); 148 } 149 150 /// Record ICmp conditions relevant to any argument in CS following Pred's 151 /// single predecessors. If there are conflicting conditions along a path, like 152 /// x == 1 and x == 0, the first condition will be used. We stop once we reach 153 /// an edge to StopAt. 154 static void recordConditions(CallSite CS, BasicBlock *Pred, 155 ConditionsTy &Conditions, BasicBlock *StopAt) { 156 BasicBlock *From = Pred; 157 BasicBlock *To = Pred; 158 SmallPtrSet<BasicBlock *, 4> Visited; 159 while (To != StopAt && !Visited.count(From->getSinglePredecessor()) && 160 (From = From->getSinglePredecessor())) { 161 recordCondition(CS, From, To, Conditions); 162 Visited.insert(From); 163 To = From; 164 } 165 } 166 167 static void addConditions(CallSite CS, const ConditionsTy &Conditions) { 168 for (auto &Cond : Conditions) { 169 Value *Arg = Cond.first->getOperand(0); 170 Constant *ConstVal = cast<Constant>(Cond.first->getOperand(1)); 171 if (Cond.second == ICmpInst::ICMP_EQ) 172 setConstantInArgument(CS, Arg, ConstVal); 173 else if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue()) { 174 assert(Cond.second == ICmpInst::ICMP_NE); 175 addNonNullAttribute(CS, Arg); 176 } 177 } 178 } 179 180 static SmallVector<BasicBlock *, 2> getTwoPredecessors(BasicBlock *BB) { 181 SmallVector<BasicBlock *, 2> Preds(predecessors((BB))); 182 assert(Preds.size() == 2 && "Expected exactly 2 predecessors!"); 183 return Preds; 184 } 185 186 static bool canSplitCallSite(CallSite CS, TargetTransformInfo &TTI) { 187 if (CS.isConvergent() || CS.cannotDuplicate()) 188 return false; 189 190 // FIXME: As of now we handle only CallInst. InvokeInst could be handled 191 // without too much effort. 192 Instruction *Instr = CS.getInstruction(); 193 if (!isa<CallInst>(Instr)) 194 return false; 195 196 BasicBlock *CallSiteBB = Instr->getParent(); 197 // Need 2 predecessors and cannot split an edge from an IndirectBrInst. 198 SmallVector<BasicBlock *, 2> Preds(predecessors(CallSiteBB)); 199 if (Preds.size() != 2 || isa<IndirectBrInst>(Preds[0]->getTerminator()) || 200 isa<IndirectBrInst>(Preds[1]->getTerminator())) 201 return false; 202 203 // BasicBlock::canSplitPredecessors is more aggressive, so checking for 204 // BasicBlock::isEHPad as well. 205 if (!CallSiteBB->canSplitPredecessors() || CallSiteBB->isEHPad()) 206 return false; 207 208 // Allow splitting a call-site only when the CodeSize cost of the 209 // instructions before the call is less then DuplicationThreshold. The 210 // instructions before the call will be duplicated in the split blocks and 211 // corresponding uses will be updated. 212 unsigned Cost = 0; 213 for (auto &InstBeforeCall : 214 llvm::make_range(CallSiteBB->begin(), Instr->getIterator())) { 215 Cost += TTI.getInstructionCost(&InstBeforeCall, 216 TargetTransformInfo::TCK_CodeSize); 217 if (Cost >= DuplicationThreshold) 218 return false; 219 } 220 221 return true; 222 } 223 224 static Instruction *cloneInstForMustTail(Instruction *I, Instruction *Before, 225 Value *V) { 226 Instruction *Copy = I->clone(); 227 Copy->setName(I->getName()); 228 Copy->insertBefore(Before); 229 if (V) 230 Copy->setOperand(0, V); 231 return Copy; 232 } 233 234 /// Copy mandatory `musttail` return sequence that follows original `CI`, and 235 /// link it up to `NewCI` value instead: 236 /// 237 /// * (optional) `bitcast NewCI to ...` 238 /// * `ret bitcast or NewCI` 239 /// 240 /// Insert this sequence right before `SplitBB`'s terminator, which will be 241 /// cleaned up later in `splitCallSite` below. 242 static void copyMustTailReturn(BasicBlock *SplitBB, Instruction *CI, 243 Instruction *NewCI) { 244 bool IsVoid = SplitBB->getParent()->getReturnType()->isVoidTy(); 245 auto II = std::next(CI->getIterator()); 246 247 BitCastInst* BCI = dyn_cast<BitCastInst>(&*II); 248 if (BCI) 249 ++II; 250 251 ReturnInst* RI = dyn_cast<ReturnInst>(&*II); 252 assert(RI && "`musttail` call must be followed by `ret` instruction"); 253 254 Instruction *TI = SplitBB->getTerminator(); 255 Value *V = NewCI; 256 if (BCI) 257 V = cloneInstForMustTail(BCI, TI, V); 258 cloneInstForMustTail(RI, TI, IsVoid ? nullptr : V); 259 260 // FIXME: remove TI here, `DuplicateInstructionsInSplitBetween` has a bug 261 // that prevents doing this now. 262 } 263 264 /// For each (predecessor, conditions from predecessors) pair, it will split the 265 /// basic block containing the call site, hook it up to the predecessor and 266 /// replace the call instruction with new call instructions, which contain 267 /// constraints based on the conditions from their predecessors. 268 /// For example, in the IR below with an OR condition, the call-site can 269 /// be split. In this case, Preds for Tail is [(Header, a == null), 270 /// (TBB, a != null, b == null)]. Tail is replaced by 2 split blocks, containing 271 /// CallInst1, which has constraints based on the conditions from Head and 272 /// CallInst2, which has constraints based on the conditions coming from TBB. 273 /// 274 /// From : 275 /// 276 /// Header: 277 /// %c = icmp eq i32* %a, null 278 /// br i1 %c %Tail, %TBB 279 /// TBB: 280 /// %c2 = icmp eq i32* %b, null 281 /// br i1 %c %Tail, %End 282 /// Tail: 283 /// %ca = call i1 @callee (i32* %a, i32* %b) 284 /// 285 /// to : 286 /// 287 /// Header: // PredBB1 is Header 288 /// %c = icmp eq i32* %a, null 289 /// br i1 %c %Tail-split1, %TBB 290 /// TBB: // PredBB2 is TBB 291 /// %c2 = icmp eq i32* %b, null 292 /// br i1 %c %Tail-split2, %End 293 /// Tail-split1: 294 /// %ca1 = call @callee (i32* null, i32* %b) // CallInst1 295 /// br %Tail 296 /// Tail-split2: 297 /// %ca2 = call @callee (i32* nonnull %a, i32* null) // CallInst2 298 /// br %Tail 299 /// Tail: 300 /// %p = phi i1 [%ca1, %Tail-split1],[%ca2, %Tail-split2] 301 /// 302 /// Note that in case any arguments at the call-site are constrained by its 303 /// predecessors, new call-sites with more constrained arguments will be 304 /// created in createCallSitesOnPredicatedArgument(). 305 static void splitCallSite( 306 CallSite CS, 307 const SmallVectorImpl<std::pair<BasicBlock *, ConditionsTy>> &Preds, 308 DomTreeUpdater &DTU) { 309 Instruction *Instr = CS.getInstruction(); 310 BasicBlock *TailBB = Instr->getParent(); 311 bool IsMustTailCall = CS.isMustTailCall(); 312 313 PHINode *CallPN = nullptr; 314 315 // `musttail` calls must be followed by optional `bitcast`, and `ret`. The 316 // split blocks will be terminated right after that so there're no users for 317 // this phi in a `TailBB`. 318 if (!IsMustTailCall && !Instr->use_empty()) { 319 CallPN = PHINode::Create(Instr->getType(), Preds.size(), "phi.call"); 320 CallPN->setDebugLoc(Instr->getDebugLoc()); 321 } 322 323 LLVM_DEBUG(dbgs() << "split call-site : " << *Instr << " into \n"); 324 325 assert(Preds.size() == 2 && "The ValueToValueMaps array has size 2."); 326 // ValueToValueMapTy is neither copy nor moveable, so we use a simple array 327 // here. 328 ValueToValueMapTy ValueToValueMaps[2]; 329 for (unsigned i = 0; i < Preds.size(); i++) { 330 BasicBlock *PredBB = Preds[i].first; 331 BasicBlock *SplitBlock = DuplicateInstructionsInSplitBetween( 332 TailBB, PredBB, &*std::next(Instr->getIterator()), ValueToValueMaps[i], 333 DTU); 334 assert(SplitBlock && "Unexpected new basic block split."); 335 336 Instruction *NewCI = 337 &*std::prev(SplitBlock->getTerminator()->getIterator()); 338 CallSite NewCS(NewCI); 339 addConditions(NewCS, Preds[i].second); 340 341 // Handle PHIs used as arguments in the call-site. 342 for (PHINode &PN : TailBB->phis()) { 343 unsigned ArgNo = 0; 344 for (auto &CI : CS.args()) { 345 if (&*CI == &PN) { 346 NewCS.setArgument(ArgNo, PN.getIncomingValueForBlock(SplitBlock)); 347 } 348 ++ArgNo; 349 } 350 } 351 LLVM_DEBUG(dbgs() << " " << *NewCI << " in " << SplitBlock->getName() 352 << "\n"); 353 if (CallPN) 354 CallPN->addIncoming(NewCI, SplitBlock); 355 356 // Clone and place bitcast and return instructions before `TI` 357 if (IsMustTailCall) 358 copyMustTailReturn(SplitBlock, Instr, NewCI); 359 } 360 361 NumCallSiteSplit++; 362 363 // FIXME: remove TI in `copyMustTailReturn` 364 if (IsMustTailCall) { 365 // Remove superfluous `br` terminators from the end of the Split blocks 366 // NOTE: Removing terminator removes the SplitBlock from the TailBB's 367 // predecessors. Therefore we must get complete list of Splits before 368 // attempting removal. 369 SmallVector<BasicBlock *, 2> Splits(predecessors((TailBB))); 370 assert(Splits.size() == 2 && "Expected exactly 2 splits!"); 371 for (unsigned i = 0; i < Splits.size(); i++) { 372 Splits[i]->getTerminator()->eraseFromParent(); 373 DTU.applyUpdatesPermissive({{DominatorTree::Delete, Splits[i], TailBB}}); 374 } 375 376 // Erase the tail block once done with musttail patching 377 DTU.deleteBB(TailBB); 378 return; 379 } 380 381 auto *OriginalBegin = &*TailBB->begin(); 382 // Replace users of the original call with a PHI mering call-sites split. 383 if (CallPN) { 384 CallPN->insertBefore(OriginalBegin); 385 Instr->replaceAllUsesWith(CallPN); 386 } 387 388 // Remove instructions moved to split blocks from TailBB, from the duplicated 389 // call instruction to the beginning of the basic block. If an instruction 390 // has any uses, add a new PHI node to combine the values coming from the 391 // split blocks. The new PHI nodes are placed before the first original 392 // instruction, so we do not end up deleting them. By using reverse-order, we 393 // do not introduce unnecessary PHI nodes for def-use chains from the call 394 // instruction to the beginning of the block. 395 auto I = Instr->getReverseIterator(); 396 while (I != TailBB->rend()) { 397 Instruction *CurrentI = &*I++; 398 if (!CurrentI->use_empty()) { 399 // If an existing PHI has users after the call, there is no need to create 400 // a new one. 401 if (isa<PHINode>(CurrentI)) 402 continue; 403 PHINode *NewPN = PHINode::Create(CurrentI->getType(), Preds.size()); 404 NewPN->setDebugLoc(CurrentI->getDebugLoc()); 405 for (auto &Mapping : ValueToValueMaps) 406 NewPN->addIncoming(Mapping[CurrentI], 407 cast<Instruction>(Mapping[CurrentI])->getParent()); 408 NewPN->insertBefore(&*TailBB->begin()); 409 CurrentI->replaceAllUsesWith(NewPN); 410 } 411 CurrentI->eraseFromParent(); 412 // We are done once we handled the first original instruction in TailBB. 413 if (CurrentI == OriginalBegin) 414 break; 415 } 416 } 417 418 // Return true if the call-site has an argument which is a PHI with only 419 // constant incoming values. 420 static bool isPredicatedOnPHI(CallSite CS) { 421 Instruction *Instr = CS.getInstruction(); 422 BasicBlock *Parent = Instr->getParent(); 423 if (Instr != Parent->getFirstNonPHIOrDbg()) 424 return false; 425 426 for (auto &BI : *Parent) { 427 if (PHINode *PN = dyn_cast<PHINode>(&BI)) { 428 for (auto &I : CS.args()) 429 if (&*I == PN) { 430 assert(PN->getNumIncomingValues() == 2 && 431 "Unexpected number of incoming values"); 432 if (PN->getIncomingBlock(0) == PN->getIncomingBlock(1)) 433 return false; 434 if (PN->getIncomingValue(0) == PN->getIncomingValue(1)) 435 continue; 436 if (isa<Constant>(PN->getIncomingValue(0)) && 437 isa<Constant>(PN->getIncomingValue(1))) 438 return true; 439 } 440 } 441 break; 442 } 443 return false; 444 } 445 446 using PredsWithCondsTy = SmallVector<std::pair<BasicBlock *, ConditionsTy>, 2>; 447 448 // Check if any of the arguments in CS are predicated on a PHI node and return 449 // the set of predecessors we should use for splitting. 450 static PredsWithCondsTy shouldSplitOnPHIPredicatedArgument(CallSite CS) { 451 if (!isPredicatedOnPHI(CS)) 452 return {}; 453 454 auto Preds = getTwoPredecessors(CS.getInstruction()->getParent()); 455 return {{Preds[0], {}}, {Preds[1], {}}}; 456 } 457 458 // Checks if any of the arguments in CS are predicated in a predecessor and 459 // returns a list of predecessors with the conditions that hold on their edges 460 // to CS. 461 static PredsWithCondsTy shouldSplitOnPredicatedArgument(CallSite CS, 462 DomTreeUpdater &DTU) { 463 auto Preds = getTwoPredecessors(CS.getInstruction()->getParent()); 464 if (Preds[0] == Preds[1]) 465 return {}; 466 467 // We can stop recording conditions once we reached the immediate dominator 468 // for the block containing the call site. Conditions in predecessors of the 469 // that node will be the same for all paths to the call site and splitting 470 // is not beneficial. 471 assert(DTU.hasDomTree() && "We need a DTU with a valid DT!"); 472 auto *CSDTNode = DTU.getDomTree().getNode(CS.getInstruction()->getParent()); 473 BasicBlock *StopAt = CSDTNode ? CSDTNode->getIDom()->getBlock() : nullptr; 474 475 SmallVector<std::pair<BasicBlock *, ConditionsTy>, 2> PredsCS; 476 for (auto *Pred : make_range(Preds.rbegin(), Preds.rend())) { 477 ConditionsTy Conditions; 478 // Record condition on edge BB(CS) <- Pred 479 recordCondition(CS, Pred, CS.getInstruction()->getParent(), Conditions); 480 // Record conditions following Pred's single predecessors. 481 recordConditions(CS, Pred, Conditions, StopAt); 482 PredsCS.push_back({Pred, Conditions}); 483 } 484 485 if (all_of(PredsCS, [](const std::pair<BasicBlock *, ConditionsTy> &P) { 486 return P.second.empty(); 487 })) 488 return {}; 489 490 return PredsCS; 491 } 492 493 static bool tryToSplitCallSite(CallSite CS, TargetTransformInfo &TTI, 494 DomTreeUpdater &DTU) { 495 // Check if we can split the call site. 496 if (!CS.arg_size() || !canSplitCallSite(CS, TTI)) 497 return false; 498 499 auto PredsWithConds = shouldSplitOnPredicatedArgument(CS, DTU); 500 if (PredsWithConds.empty()) 501 PredsWithConds = shouldSplitOnPHIPredicatedArgument(CS); 502 if (PredsWithConds.empty()) 503 return false; 504 505 splitCallSite(CS, PredsWithConds, DTU); 506 return true; 507 } 508 509 static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI, 510 TargetTransformInfo &TTI, DominatorTree &DT) { 511 512 DomTreeUpdater DTU(&DT, DomTreeUpdater::UpdateStrategy::Lazy); 513 bool Changed = false; 514 for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) { 515 BasicBlock &BB = *BI++; 516 auto II = BB.getFirstNonPHIOrDbg()->getIterator(); 517 auto IE = BB.getTerminator()->getIterator(); 518 // Iterate until we reach the terminator instruction. tryToSplitCallSite 519 // can replace BB's terminator in case BB is a successor of itself. In that 520 // case, IE will be invalidated and we also have to check the current 521 // terminator. 522 while (II != IE && &*II != BB.getTerminator()) { 523 Instruction *I = &*II++; 524 CallSite CS(cast<Value>(I)); 525 if (!CS || isa<IntrinsicInst>(I) || isInstructionTriviallyDead(I, &TLI)) 526 continue; 527 528 Function *Callee = CS.getCalledFunction(); 529 if (!Callee || Callee->isDeclaration()) 530 continue; 531 532 // Successful musttail call-site splits result in erased CI and erased BB. 533 // Check if such path is possible before attempting the splitting. 534 bool IsMustTail = CS.isMustTailCall(); 535 536 Changed |= tryToSplitCallSite(CS, TTI, DTU); 537 538 // There're no interesting instructions after this. The call site 539 // itself might have been erased on splitting. 540 if (IsMustTail) 541 break; 542 } 543 } 544 return Changed; 545 } 546 547 namespace { 548 struct CallSiteSplittingLegacyPass : public FunctionPass { 549 static char ID; 550 CallSiteSplittingLegacyPass() : FunctionPass(ID) { 551 initializeCallSiteSplittingLegacyPassPass(*PassRegistry::getPassRegistry()); 552 } 553 554 void getAnalysisUsage(AnalysisUsage &AU) const override { 555 AU.addRequired<TargetLibraryInfoWrapperPass>(); 556 AU.addRequired<TargetTransformInfoWrapperPass>(); 557 AU.addRequired<DominatorTreeWrapperPass>(); 558 AU.addPreserved<DominatorTreeWrapperPass>(); 559 FunctionPass::getAnalysisUsage(AU); 560 } 561 562 bool runOnFunction(Function &F) override { 563 if (skipFunction(F)) 564 return false; 565 566 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F); 567 auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F); 568 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); 569 return doCallSiteSplitting(F, TLI, TTI, DT); 570 } 571 }; 572 } // namespace 573 574 char CallSiteSplittingLegacyPass::ID = 0; 575 INITIALIZE_PASS_BEGIN(CallSiteSplittingLegacyPass, "callsite-splitting", 576 "Call-site splitting", false, false) 577 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) 578 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) 579 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) 580 INITIALIZE_PASS_END(CallSiteSplittingLegacyPass, "callsite-splitting", 581 "Call-site splitting", false, false) 582 FunctionPass *llvm::createCallSiteSplittingPass() { 583 return new CallSiteSplittingLegacyPass(); 584 } 585 586 PreservedAnalyses CallSiteSplittingPass::run(Function &F, 587 FunctionAnalysisManager &AM) { 588 auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); 589 auto &TTI = AM.getResult<TargetIRAnalysis>(F); 590 auto &DT = AM.getResult<DominatorTreeAnalysis>(F); 591 592 if (!doCallSiteSplitting(F, TLI, TTI, DT)) 593 return PreservedAnalyses::all(); 594 PreservedAnalyses PA; 595 PA.preserve<DominatorTreeAnalysis>(); 596 return PA; 597 } 598