LLVM  6.0.0svn
CallSiteSplitting.cpp
Go to the documentation of this file.
1 //===- CallSiteSplitting.cpp ----------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a transformation that tries to split a call-site to pass
11 // more constrained arguments if its argument is predicated in the control flow
12 // so that we can expose better context to the later passes (e.g, inliner, jump
13 // threading, or IPA-CP based function cloning, etc.).
14 // As of now we support two cases :
15 //
16 // 1) If a call site is dominated by an OR condition and if any of its arguments
17 // are predicated on this OR condition, try to split the condition with more
18 // constrained arguments. For example, in the code below, we try to split the
19 // call site 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 
59 #include "llvm/ADT/Statistic.h"
61 #include "llvm/IR/IntrinsicInst.h"
62 #include "llvm/IR/PatternMatch.h"
63 #include "llvm/Support/Debug.h"
64 #include "llvm/Transforms/Scalar.h"
67 
68 using namespace llvm;
69 using namespace PatternMatch;
70 
71 #define DEBUG_TYPE "callsite-splitting"
72 
73 STATISTIC(NumCallSiteSplit, "Number of call-site split");
74 
75 static void addNonNullAttribute(Instruction *CallI, Instruction *&NewCallI,
76  Value *Op) {
77  if (!NewCallI)
78  NewCallI = CallI->clone();
79  CallSite CS(NewCallI);
80  unsigned ArgNo = 0;
81  for (auto &I : CS.args()) {
82  if (&*I == Op)
83  CS.addParamAttr(ArgNo, Attribute::NonNull);
84  ++ArgNo;
85  }
86 }
87 
88 static void setConstantInArgument(Instruction *CallI, Instruction *&NewCallI,
89  Value *Op, Constant *ConstValue) {
90  if (!NewCallI)
91  NewCallI = CallI->clone();
92  CallSite CS(NewCallI);
93  unsigned ArgNo = 0;
94  for (auto &I : CS.args()) {
95  if (&*I == Op)
96  CS.setArgument(ArgNo, ConstValue);
97  ++ArgNo;
98  }
99 }
100 
102  assert(isa<Constant>(Cmp->getOperand(1)) && "Expected a constant operand.");
103  Value *Op0 = Cmp->getOperand(0);
104  unsigned ArgNo = 0;
105  for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E;
106  ++I, ++ArgNo) {
107  // Don't consider constant or arguments that are already known non-null.
108  if (isa<Constant>(*I) || CS.paramHasAttr(ArgNo, Attribute::NonNull))
109  continue;
110 
111  if (*I == Op0)
112  return true;
113  }
114  return false;
115 }
116 
119  SmallVector<BranchInst *, 2> BranchInsts;
120  for (auto PredBB : predecessors(CS.getInstruction()->getParent())) {
121  auto *PBI = dyn_cast<BranchInst>(PredBB->getTerminator());
122  if (!PBI || !PBI->isConditional())
123  continue;
124 
125  CmpInst::Predicate Pred;
126  Value *Cond = PBI->getCondition();
127  if (!match(Cond, m_ICmp(Pred, m_Value(), m_Constant())))
128  continue;
129  ICmpInst *Cmp = cast<ICmpInst>(Cond);
130  if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE)
131  if (isCondRelevantToAnyCallArgument(Cmp, CS))
132  BranchInsts.push_back(PBI);
133  }
134  return BranchInsts;
135 }
136 
138  CallSite CS, Instruction *&NewCSTakenFromHeader,
139  Instruction *&NewCSTakenFromNextCond, BasicBlock *HeaderBB) {
140  auto BranchInsts = findOrCondRelevantToCallArgument(CS);
141  assert(BranchInsts.size() <= 2 &&
142  "Unexpected number of blocks in the OR predicated condition");
143  Instruction *Instr = CS.getInstruction();
144  BasicBlock *CallSiteBB = Instr->getParent();
145  TerminatorInst *HeaderTI = HeaderBB->getTerminator();
146  bool IsCSInTakenPath = CallSiteBB == HeaderTI->getSuccessor(0);
147 
148  for (auto *PBI : BranchInsts) {
149  assert(isa<ICmpInst>(PBI->getCondition()) &&
150  "Unexpected condition in a conditional branch.");
151  ICmpInst *Cmp = cast<ICmpInst>(PBI->getCondition());
152  Value *Arg = Cmp->getOperand(0);
153  assert(isa<Constant>(Cmp->getOperand(1)) &&
154  "Expected op1 to be a constant.");
155  Constant *ConstVal = cast<Constant>(Cmp->getOperand(1));
156  CmpInst::Predicate Pred = Cmp->getPredicate();
157 
158  if (PBI->getParent() == HeaderBB) {
159  Instruction *&CallTakenFromHeader =
160  IsCSInTakenPath ? NewCSTakenFromHeader : NewCSTakenFromNextCond;
161  Instruction *&CallUntakenFromHeader =
162  IsCSInTakenPath ? NewCSTakenFromNextCond : NewCSTakenFromHeader;
163 
164  assert((Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE) &&
165  "Unexpected predicate in an OR condition");
166 
167  // Set the constant value for agruments in the call predicated based on
168  // the OR condition.
169  Instruction *&CallToSetConst = Pred == ICmpInst::ICMP_EQ
170  ? CallTakenFromHeader
171  : CallUntakenFromHeader;
172  setConstantInArgument(Instr, CallToSetConst, Arg, ConstVal);
173 
174  // Add the NonNull attribute if compared with the null pointer.
175  if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue()) {
176  Instruction *&CallToSetAttr = Pred == ICmpInst::ICMP_EQ
177  ? CallUntakenFromHeader
178  : CallTakenFromHeader;
179  addNonNullAttribute(Instr, CallToSetAttr, Arg);
180  }
181  continue;
182  }
183 
184  if (Pred == ICmpInst::ICMP_EQ) {
185  if (PBI->getSuccessor(0) == Instr->getParent()) {
186  // Set the constant value for the call taken from the second block in
187  // the OR condition.
188  setConstantInArgument(Instr, NewCSTakenFromNextCond, Arg, ConstVal);
189  } else {
190  // Add the NonNull attribute if compared with the null pointer for the
191  // call taken from the second block in the OR condition.
192  if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue())
193  addNonNullAttribute(Instr, NewCSTakenFromNextCond, Arg);
194  }
195  } else {
196  if (PBI->getSuccessor(0) == Instr->getParent()) {
197  // Add the NonNull attribute if compared with the null pointer for the
198  // call taken from the second block in the OR condition.
199  if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue())
200  addNonNullAttribute(Instr, NewCSTakenFromNextCond, Arg);
201  } else if (Pred == ICmpInst::ICMP_NE) {
202  // Set the constant value for the call in the untaken path from the
203  // header block.
204  setConstantInArgument(Instr, NewCSTakenFromNextCond, Arg, ConstVal);
205  } else
206  llvm_unreachable("Unexpected condition");
207  }
208  }
209  return NewCSTakenFromHeader || NewCSTakenFromNextCond;
210 }
211 
212 static bool canSplitCallSite(CallSite CS) {
213  // FIXME: As of now we handle only CallInst. InvokeInst could be handled
214  // without too much effort.
215  Instruction *Instr = CS.getInstruction();
216  if (!isa<CallInst>(Instr))
217  return false;
218 
219  // Allow splitting a call-site only when there is no instruction before the
220  // call-site in the basic block. Based on this constraint, we only clone the
221  // call instruction, and we do not move a call-site across any other
222  // instruction.
223  BasicBlock *CallSiteBB = Instr->getParent();
224  if (Instr != CallSiteBB->getFirstNonPHI())
225  return false;
226 
227  // Need 2 predecessors and cannot split an edge from an IndirectBrInst.
228  SmallVector<BasicBlock *, 2> Preds(predecessors(CallSiteBB));
229  if (Preds.size() != 2 || isa<IndirectBrInst>(Preds[0]->getTerminator()) ||
230  isa<IndirectBrInst>(Preds[1]->getTerminator()))
231  return false;
232 
233  return CallSiteBB->canSplitPredecessors();
234 }
235 
236 /// Return true if the CS is split into its new predecessors which are directly
237 /// hooked to each of its orignial predecessors pointed by PredBB1 and PredBB2.
238 /// In OR predicated case, PredBB1 will point the header, and PredBB2 will point
239 /// to the second compare block. CallInst1 and CallInst2 will be the new
240 /// call-sites placed in the new predecessors split for PredBB1 and PredBB2,
241 /// repectively. Therefore, CallInst1 will be the call-site placed
242 /// between Header and Tail, and CallInst2 will be the call-site between TBB and
243 /// Tail. For example, in the IR below with an OR condition, the call-site can
244 /// be split
245 ///
246 /// from :
247 ///
248 /// Header:
249 /// %c = icmp eq i32* %a, null
250 /// br i1 %c %Tail, %TBB
251 /// TBB:
252 /// %c2 = icmp eq i32* %b, null
253 /// br i1 %c %Tail, %End
254 /// Tail:
255 /// %ca = call i1 @callee (i32* %a, i32* %b)
256 ///
257 /// to :
258 ///
259 /// Header: // PredBB1 is Header
260 /// %c = icmp eq i32* %a, null
261 /// br i1 %c %Tail-split1, %TBB
262 /// TBB: // PredBB2 is TBB
263 /// %c2 = icmp eq i32* %b, null
264 /// br i1 %c %Tail-split2, %End
265 /// Tail-split1:
266 /// %ca1 = call @callee (i32* null, i32* %b) // CallInst1
267 /// br %Tail
268 /// Tail-split2:
269 /// %ca2 = call @callee (i32* nonnull %a, i32* null) // CallInst2
270 /// br %Tail
271 /// Tail:
272 /// %p = phi i1 [%ca1, %Tail-split1],[%ca2, %Tail-split2]
273 ///
274 /// Note that for an OR predicated case, CallInst1 and CallInst2 should be
275 /// created with more constrained arguments in
276 /// createCallSitesOnOrPredicatedArgument().
277 static void splitCallSite(CallSite CS, BasicBlock *PredBB1, BasicBlock *PredBB2,
278  Instruction *CallInst1, Instruction *CallInst2) {
279  Instruction *Instr = CS.getInstruction();
280  BasicBlock *TailBB = Instr->getParent();
281  assert(Instr == (TailBB->getFirstNonPHI()) && "Unexpected call-site");
282 
283  BasicBlock *SplitBlock1 =
284  SplitBlockPredecessors(TailBB, PredBB1, ".predBB1.split");
285  BasicBlock *SplitBlock2 =
286  SplitBlockPredecessors(TailBB, PredBB2, ".predBB2.split");
287 
288  assert((SplitBlock1 && SplitBlock2) && "Unexpected new basic block split.");
289 
290  if (!CallInst1)
291  CallInst1 = Instr->clone();
292  if (!CallInst2)
293  CallInst2 = Instr->clone();
294 
295  CallInst1->insertBefore(&*SplitBlock1->getFirstInsertionPt());
296  CallInst2->insertBefore(&*SplitBlock2->getFirstInsertionPt());
297 
298  CallSite CS1(CallInst1);
299  CallSite CS2(CallInst2);
300 
301  // Handle PHIs used as arguments in the call-site.
302  for (auto &PI : *TailBB) {
303  PHINode *PN = dyn_cast<PHINode>(&PI);
304  if (!PN)
305  break;
306  unsigned ArgNo = 0;
307  for (auto &CI : CS.args()) {
308  if (&*CI == PN) {
309  CS1.setArgument(ArgNo, PN->getIncomingValueForBlock(SplitBlock1));
310  CS2.setArgument(ArgNo, PN->getIncomingValueForBlock(SplitBlock2));
311  }
312  ++ArgNo;
313  }
314  }
315 
316  // Replace users of the original call with a PHI mering call-sites split.
317  if (Instr->getNumUses()) {
318  PHINode *PN = PHINode::Create(Instr->getType(), 2, "phi.call", Instr);
319  PN->addIncoming(CallInst1, SplitBlock1);
320  PN->addIncoming(CallInst2, SplitBlock2);
321  Instr->replaceAllUsesWith(PN);
322  }
323  DEBUG(dbgs() << "split call-site : " << *Instr << " into \n");
324  DEBUG(dbgs() << " " << *CallInst1 << " in " << SplitBlock1->getName()
325  << "\n");
326  DEBUG(dbgs() << " " << *CallInst2 << " in " << SplitBlock2->getName()
327  << "\n");
328  Instr->eraseFromParent();
329  NumCallSiteSplit++;
330 }
331 
332 // Return true if the call-site has an argument which is a PHI with only
333 // constant incoming values.
334 static bool isPredicatedOnPHI(CallSite CS) {
335  Instruction *Instr = CS.getInstruction();
336  BasicBlock *Parent = Instr->getParent();
337  if (Instr != Parent->getFirstNonPHI())
338  return false;
339 
340  for (auto &BI : *Parent) {
341  if (PHINode *PN = dyn_cast<PHINode>(&BI)) {
342  for (auto &I : CS.args())
343  if (&*I == PN) {
344  assert(PN->getNumIncomingValues() == 2 &&
345  "Unexpected number of incoming values");
346  if (PN->getIncomingBlock(0) == PN->getIncomingBlock(1))
347  return false;
348  if (PN->getIncomingValue(0) == PN->getIncomingValue(1))
349  continue;
350  if (isa<Constant>(PN->getIncomingValue(0)) &&
351  isa<Constant>(PN->getIncomingValue(1)))
352  return true;
353  }
354  }
355  break;
356  }
357  return false;
358 }
359 
362  assert(Preds.size() == 2 && "Expected exactly 2 predecessors!");
363  return Preds;
364 }
365 
367  if (!isPredicatedOnPHI(CS))
368  return false;
369 
370  auto Preds = getTwoPredecessors(CS.getInstruction()->getParent());
371  splitCallSite(CS, Preds[0], Preds[1], nullptr, nullptr);
372  return true;
373 }
374 // Check if one of the predecessors is a single predecessors of the other.
375 // This is a requirement for control flow modeling an OR. HeaderBB points to
376 // the single predecessor and OrBB points to other node. HeaderBB potentially
377 // contains the first compare of the OR and OrBB the second.
378 static bool isOrHeader(BasicBlock *HeaderBB, BasicBlock *OrBB) {
379  return OrBB->getSinglePredecessor() == HeaderBB &&
380  HeaderBB->getTerminator()->getNumSuccessors() == 2;
381 }
382 
384  auto Preds = getTwoPredecessors(CS.getInstruction()->getParent());
385  BasicBlock *HeaderBB = nullptr;
386  BasicBlock *OrBB = nullptr;
387  if (isOrHeader(Preds[0], Preds[1])) {
388  HeaderBB = Preds[0];
389  OrBB = Preds[1];
390  } else if (isOrHeader(Preds[1], Preds[0])) {
391  HeaderBB = Preds[1];
392  OrBB = Preds[0];
393  } else
394  return false;
395 
396  Instruction *CallInst1 = nullptr;
397  Instruction *CallInst2 = nullptr;
398  if (!tryCreateCallSitesOnOrPredicatedArgument(CS, CallInst1, CallInst2,
399  HeaderBB)) {
400  assert(!CallInst1 && !CallInst2 && "Unexpected new call-sites cloned.");
401  return false;
402  }
403 
404  splitCallSite(CS, HeaderBB, OrBB, CallInst1, CallInst2);
405  return true;
406 }
407 
408 static bool tryToSplitCallSite(CallSite CS) {
409  if (!CS.arg_size() || !canSplitCallSite(CS))
410  return false;
413 }
414 
416  bool Changed = false;
417  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) {
418  BasicBlock &BB = *BI++;
419  for (BasicBlock::iterator II = BB.begin(), IE = BB.end(); II != IE;) {
420  Instruction *I = &*II++;
421  CallSite CS(cast<Value>(I));
422  if (!CS || isa<IntrinsicInst>(I) || isInstructionTriviallyDead(I, &TLI))
423  continue;
424 
426  if (!Callee || Callee->isDeclaration())
427  continue;
428  Changed |= tryToSplitCallSite(CS);
429  }
430  }
431  return Changed;
432 }
433 
434 namespace {
435 struct CallSiteSplittingLegacyPass : public FunctionPass {
436  static char ID;
437  CallSiteSplittingLegacyPass() : FunctionPass(ID) {
439  }
440 
441  void getAnalysisUsage(AnalysisUsage &AU) const override {
444  }
445 
446  bool runOnFunction(Function &F) override {
447  if (skipFunction(F))
448  return false;
449 
450  auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
451  return doCallSiteSplitting(F, TLI);
452  }
453 };
454 } // namespace
455 
457 INITIALIZE_PASS_BEGIN(CallSiteSplittingLegacyPass, "callsite-splitting",
458  "Call-site splitting", false, false)
460 INITIALIZE_PASS_END(CallSiteSplittingLegacyPass, "callsite-splitting",
461  "Call-site splitting", false, false)
463  return new CallSiteSplittingLegacyPass();
464 }
465 
468  auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
469 
470  if (!doCallSiteSplitting(F, TLI))
471  return PreservedAnalyses::all();
473  return PA;
474 }
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
Definition: CallSite.h:213
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:69
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:346
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:72
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static bool canSplitCallSite(CallSite CS)
unsigned arg_size() const
Definition: CallSite.h:219
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:687
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
iterator end()
Definition: Function.h:590
static SmallVector< BranchInst *, 2 > findOrCondRelevantToCallArgument(CallSite CS)
static void setConstantInArgument(Instruction *CallI, Instruction *&NewCallI, Value *Op, Constant *ConstValue)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:91
static void addNonNullAttribute(Instruction *CallI, Instruction *&NewCallI, Value *Op)
iterator_range< IterTy > args() const
Definition: CallSite.h:215
static bool tryToSplitCallSite(CallSite CS)
STATISTIC(NumFunctions, "Total number of functions")
F(f)
static bool tryToSplitOnPHIPredicatedArgument(CallSite CS)
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:252
INITIALIZE_PASS_BEGIN(CallSiteSplittingLegacyPass, "callsite-splitting", "Call-site splitting", false, false) INITIALIZE_PASS_END(CallSiteSplittingLegacyPass
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
IterTy arg_end() const
Definition: CallSite.h:575
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
InstrTy * getInstruction() const
Definition: CallSite.h:92
static void splitCallSite(CallSite CS, BasicBlock *PredBB1, BasicBlock *PredBB2, Instruction *CallInst1, Instruction *CallInst2)
Return true if the CS is split into its new predecessors which are directly hooked to each of its ori...
void setArgument(unsigned ArgNo, Value *newVal)
Definition: CallSite.h:191
Instruction * clone() const
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:86
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:91
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
Definition: CallSite.h:377
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:430
iterator begin()
Definition: Function.h:588
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
Definition: User.h:154
static bool runOnFunction(Function &F, bool PostInlining)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:171
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:54
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:200
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:217
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:75
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Conditional or Unconditional Branch instruction.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
static bool tryToSplitOnOrPredicatedArgument(CallSite CS)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Represent the analysis usage information of a pass.
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:853
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock *> Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Iterator for intrusive lists based on ilist_node.
iterator end()
Definition: BasicBlock.h:254
IterTy arg_begin() const
Definition: CallSite.h:571
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
Provides information about what library functions are available for the current target.
static bool isOrHeader(BasicBlock *HeaderBB, BasicBlock *OrBB)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
Definition: CFG.h:110
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
static bool isCondRelevantToAnyCallArgument(ICmpInst *Cmp, CallSite CS)
amdgpu Simplify well known AMD library false Value Value * Arg
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:927
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:166
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
#define I(x, y, z)
Definition: MD5.cpp:58
callsite splitting
static bool isPredicatedOnPHI(CallSite CS)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static bool tryCreateCallSitesOnOrPredicatedArgument(CallSite CS, Instruction *&NewCSTakenFromHeader, Instruction *&NewCSTakenFromNextCond, BasicBlock *HeaderBB)
static SmallVector< BasicBlock *, 2 > getTwoPredecessors(BasicBlock *BB)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:201
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:107
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
Definition: Local.cpp:324
LLVM Value Representation.
Definition: Value.h:73
#define DEBUG(X)
Definition: Debug.h:118
A container for analyses that lazily runs them and caches their results.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Definition: CallSite.h:345
const BasicBlock * getParent() const
Definition: Instruction.h:66
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Definition: PatternMatch.h:837
FunctionPass * createCallSiteSplittingPass()