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