LLVM  7.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) Try to a split call-site with constrained arguments, if any constraints
17 // on any argument can be found by following the single predecessors of the
18 // all site's predecessors. Currently this pass only handles call-sites with 2
19 // predecessors. For example, in the code below, we try to split the call-site
20 // since we can predicate the argument(ptr) based on the OR condition.
21 //
22 // Split from :
23 // if (!ptr || c)
24 // callee(ptr);
25 // to :
26 // if (!ptr)
27 // callee(null) // set the known constant value
28 // else if (c)
29 // callee(nonnull ptr) // set non-null attribute in the argument
30 //
31 // 2) We can also split a call-site based on constant incoming values of a PHI
32 // For example,
33 // from :
34 // Header:
35 // %c = icmp eq i32 %i1, %i2
36 // br i1 %c, label %Tail, label %TBB
37 // TBB:
38 // br label Tail%
39 // Tail:
40 // %p = phi i32 [ 0, %Header], [ 1, %TBB]
41 // call void @bar(i32 %p)
42 // to
43 // Header:
44 // %c = icmp eq i32 %i1, %i2
45 // br i1 %c, label %Tail-split0, label %TBB
46 // TBB:
47 // br label %Tail-split1
48 // Tail-split0:
49 // call void @bar(i32 0)
50 // br label %Tail
51 // Tail-split1:
52 // call void @bar(i32 1)
53 // br label %Tail
54 // Tail:
55 // %p = phi i32 [ 0, %Tail-split0 ], [ 1, %Tail-split1 ]
56 //
57 //===----------------------------------------------------------------------===//
58 
60 #include "llvm/ADT/Statistic.h"
63 #include "llvm/IR/IntrinsicInst.h"
64 #include "llvm/IR/PatternMatch.h"
65 #include "llvm/Support/Debug.h"
66 #include "llvm/Transforms/Scalar.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 
97  Constant *ConstValue) {
98  unsigned ArgNo = 0;
99  for (auto &I : CS.args()) {
100  if (&*I == Op)
101  CS.setArgument(ArgNo, ConstValue);
102  ++ArgNo;
103  }
104 }
105 
107  assert(isa<Constant>(Cmp->getOperand(1)) && "Expected a constant operand.");
108  Value *Op0 = Cmp->getOperand(0);
109  unsigned ArgNo = 0;
110  for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E;
111  ++I, ++ArgNo) {
112  // Don't consider constant or arguments that are already known non-null.
113  if (isa<Constant>(*I) || CS.paramHasAttr(ArgNo, Attribute::NonNull))
114  continue;
115 
116  if (*I == Op0)
117  return true;
118  }
119  return false;
120 }
121 
122 typedef std::pair<ICmpInst *, unsigned> ConditionTy;
124 
125 /// If From has a conditional jump to To, add the condition to Conditions,
126 /// if it is relevant to any argument at CS.
127 static void recordCondition(CallSite CS, BasicBlock *From, BasicBlock *To,
128  ConditionsTy &Conditions) {
129  auto *BI = dyn_cast<BranchInst>(From->getTerminator());
130  if (!BI || !BI->isConditional())
131  return;
132 
133  CmpInst::Predicate Pred;
134  Value *Cond = BI->getCondition();
135  if (!match(Cond, m_ICmp(Pred, m_Value(), m_Constant())))
136  return;
137 
138  ICmpInst *Cmp = cast<ICmpInst>(Cond);
139  if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE)
140  if (isCondRelevantToAnyCallArgument(Cmp, CS))
141  Conditions.push_back({Cmp, From->getTerminator()->getSuccessor(0) == To
142  ? Pred
143  : Cmp->getInversePredicate()});
144 }
145 
146 /// Record ICmp conditions relevant to any argument in CS following Pred's
147 /// single successors. If there are conflicting conditions along a path, like
148 /// x == 1 and x == 0, the first condition will be used.
149 static void recordConditions(CallSite CS, BasicBlock *Pred,
150  ConditionsTy &Conditions) {
151  recordCondition(CS, Pred, CS.getInstruction()->getParent(), Conditions);
152  BasicBlock *From = Pred;
153  BasicBlock *To = Pred;
155  while (!Visited.count(From->getSinglePredecessor()) &&
156  (From = From->getSinglePredecessor())) {
157  recordCondition(CS, From, To, Conditions);
158  Visited.insert(From);
159  To = From;
160  }
161 }
162 
163 static void addConditions(CallSite CS, const ConditionsTy &Conditions) {
164  for (auto &Cond : Conditions) {
165  Value *Arg = Cond.first->getOperand(0);
166  Constant *ConstVal = cast<Constant>(Cond.first->getOperand(1));
167  if (Cond.second == ICmpInst::ICMP_EQ)
168  setConstantInArgument(CS, Arg, ConstVal);
169  else if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue()) {
170  assert(Cond.second == ICmpInst::ICMP_NE);
171  addNonNullAttribute(CS, Arg);
172  }
173  }
174 }
175 
178  assert(Preds.size() == 2 && "Expected exactly 2 predecessors!");
179  return Preds;
180 }
181 
183  // FIXME: As of now we handle only CallInst. InvokeInst could be handled
184  // without too much effort.
185  Instruction *Instr = CS.getInstruction();
186  if (!isa<CallInst>(Instr))
187  return false;
188 
189  BasicBlock *CallSiteBB = Instr->getParent();
190  // Allow splitting a call-site only when the CodeSize cost of the
191  // instructions before the call is less then DuplicationThreshold. The
192  // instructions before the call will be duplicated in the split blocks and
193  // corresponding uses will be updated.
194  unsigned Cost = 0;
195  for (auto &InstBeforeCall :
196  llvm::make_range(CallSiteBB->begin(), Instr->getIterator())) {
197  Cost += TTI.getInstructionCost(&InstBeforeCall,
199  if (Cost >= DuplicationThreshold)
200  return false;
201  }
202 
203  // Need 2 predecessors and cannot split an edge from an IndirectBrInst.
204  SmallVector<BasicBlock *, 2> Preds(predecessors(CallSiteBB));
205  if (Preds.size() != 2 || isa<IndirectBrInst>(Preds[0]->getTerminator()) ||
206  isa<IndirectBrInst>(Preds[1]->getTerminator()))
207  return false;
208 
209  return CallSiteBB->canSplitPredecessors();
210 }
211 
212 /// Return true if the CS is split into its new predecessors.
213 ///
214 /// For each (predecessor, conditions from predecessors) pair, it will split the
215 /// basic block containing the call site, hook it up to the predecessor and
216 /// replace the call instruction with new call instructions, which contain
217 /// constraints based on the conditions from their predecessors.
218 /// For example, in the IR below with an OR condition, the call-site can
219 /// be split. In this case, Preds for Tail is [(Header, a == null),
220 /// (TBB, a != null, b == null)]. Tail is replaced by 2 split blocks, containing
221 /// CallInst1, which has constraints based on the conditions from Head and
222 /// CallInst2, which has constraints based on the conditions coming from TBB.
223 ///
224 /// From :
225 ///
226 /// Header:
227 /// %c = icmp eq i32* %a, null
228 /// br i1 %c %Tail, %TBB
229 /// TBB:
230 /// %c2 = icmp eq i32* %b, null
231 /// br i1 %c %Tail, %End
232 /// Tail:
233 /// %ca = call i1 @callee (i32* %a, i32* %b)
234 ///
235 /// to :
236 ///
237 /// Header: // PredBB1 is Header
238 /// %c = icmp eq i32* %a, null
239 /// br i1 %c %Tail-split1, %TBB
240 /// TBB: // PredBB2 is TBB
241 /// %c2 = icmp eq i32* %b, null
242 /// br i1 %c %Tail-split2, %End
243 /// Tail-split1:
244 /// %ca1 = call @callee (i32* null, i32* %b) // CallInst1
245 /// br %Tail
246 /// Tail-split2:
247 /// %ca2 = call @callee (i32* nonnull %a, i32* null) // CallInst2
248 /// br %Tail
249 /// Tail:
250 /// %p = phi i1 [%ca1, %Tail-split1],[%ca2, %Tail-split2]
251 ///
252 /// Note that in case any arguments at the call-site are constrained by its
253 /// predecessors, new call-sites with more constrained arguments will be
254 /// created in createCallSitesOnPredicatedArgument().
255 static void splitCallSite(
256  CallSite CS,
257  const SmallVectorImpl<std::pair<BasicBlock *, ConditionsTy>> &Preds) {
258  Instruction *Instr = CS.getInstruction();
259  BasicBlock *TailBB = Instr->getParent();
260 
261  PHINode *CallPN = nullptr;
262  if (Instr->getNumUses())
263  CallPN = PHINode::Create(Instr->getType(), Preds.size(), "phi.call");
264 
265  DEBUG(dbgs() << "split call-site : " << *Instr << " into \n");
266 
267  assert(Preds.size() == 2 && "The ValueToValueMaps array has size 2.");
268  // ValueToValueMapTy is neither copy nor moveable, so we use a simple array
269  // here.
270  ValueToValueMapTy ValueToValueMaps[2];
271  for (unsigned i = 0; i < Preds.size(); i++) {
272  BasicBlock *PredBB = Preds[i].first;
274  TailBB, PredBB, &*std::next(Instr->getIterator()), ValueToValueMaps[i]);
275  assert(SplitBlock && "Unexpected new basic block split.");
276 
277  Instruction *NewCI =
278  &*std::prev(SplitBlock->getTerminator()->getIterator());
279  CallSite NewCS(NewCI);
280  addConditions(NewCS, Preds[i].second);
281 
282  // Handle PHIs used as arguments in the call-site.
283  for (PHINode &PN : TailBB->phis()) {
284  unsigned ArgNo = 0;
285  for (auto &CI : CS.args()) {
286  if (&*CI == &PN) {
287  NewCS.setArgument(ArgNo, PN.getIncomingValueForBlock(SplitBlock));
288  }
289  ++ArgNo;
290  }
291  }
292  DEBUG(dbgs() << " " << *NewCI << " in " << SplitBlock->getName()
293  << "\n");
294  if (CallPN)
295  CallPN->addIncoming(NewCI, SplitBlock);
296  }
297 
298  auto *OriginalBegin = &*TailBB->begin();
299  // Replace users of the original call with a PHI mering call-sites split.
300  if (CallPN) {
301  CallPN->insertBefore(OriginalBegin);
302  Instr->replaceAllUsesWith(CallPN);
303  }
304 
305  // Remove instructions moved to split blocks from TailBB, from the duplicated
306  // call instruction to the beginning of the basic block. If an instruction
307  // has any uses, add a new PHI node to combine the values coming from the
308  // split blocks. The new PHI nodes are placed before the first original
309  // instruction, so we do not end up deleting them. By using reverse-order, we
310  // do not introduce unnecessary PHI nodes for def-use chains from the call
311  // instruction to the beginning of the block.
312  auto I = Instr->getReverseIterator();
313  while (I != TailBB->rend()) {
314  Instruction *CurrentI = &*I++;
315  if (!CurrentI->use_empty()) {
316  // If an existing PHI has users after the call, there is no need to create
317  // a new one.
318  if (isa<PHINode>(CurrentI))
319  continue;
320  PHINode *NewPN = PHINode::Create(CurrentI->getType(), Preds.size());
321  for (auto &Mapping : ValueToValueMaps)
322  NewPN->addIncoming(Mapping[CurrentI],
323  cast<Instruction>(Mapping[CurrentI])->getParent());
324  NewPN->insertBefore(&*TailBB->begin());
325  CurrentI->replaceAllUsesWith(NewPN);
326  }
327  CurrentI->eraseFromParent();
328  // We are done once we handled the first original instruction in TailBB.
329  if (CurrentI == OriginalBegin)
330  break;
331  }
332 
333  NumCallSiteSplit++;
334 }
335 
336 // Return true if the call-site has an argument which is a PHI with only
337 // constant incoming values.
338 static bool isPredicatedOnPHI(CallSite CS) {
339  Instruction *Instr = CS.getInstruction();
340  BasicBlock *Parent = Instr->getParent();
341  if (Instr != Parent->getFirstNonPHIOrDbg())
342  return false;
343 
344  for (auto &BI : *Parent) {
345  if (PHINode *PN = dyn_cast<PHINode>(&BI)) {
346  for (auto &I : CS.args())
347  if (&*I == PN) {
348  assert(PN->getNumIncomingValues() == 2 &&
349  "Unexpected number of incoming values");
350  if (PN->getIncomingBlock(0) == PN->getIncomingBlock(1))
351  return false;
352  if (PN->getIncomingValue(0) == PN->getIncomingValue(1))
353  continue;
354  if (isa<Constant>(PN->getIncomingValue(0)) &&
355  isa<Constant>(PN->getIncomingValue(1)))
356  return true;
357  }
358  }
359  break;
360  }
361  return false;
362 }
363 
365  if (!isPredicatedOnPHI(CS))
366  return false;
367 
368  auto Preds = getTwoPredecessors(CS.getInstruction()->getParent());
370  {Preds[0], {}}, {Preds[1], {}}};
371  splitCallSite(CS, PredsCS);
372  return true;
373 }
374 
376  auto Preds = getTwoPredecessors(CS.getInstruction()->getParent());
377  if (Preds[0] == Preds[1])
378  return false;
379 
381  for (auto *Pred : make_range(Preds.rbegin(), Preds.rend())) {
382  ConditionsTy Conditions;
383  recordConditions(CS, Pred, Conditions);
384  PredsCS.push_back({Pred, Conditions});
385  }
386 
387  if (std::all_of(PredsCS.begin(), PredsCS.end(),
388  [](const std::pair<BasicBlock *, ConditionsTy> &P) {
389  return P.second.empty();
390  }))
391  return false;
392 
393  splitCallSite(CS, PredsCS);
394  return true;
395 }
396 
398  if (!CS.arg_size() || !canSplitCallSite(CS, TTI))
399  return false;
400  return tryToSplitOnPredicatedArgument(CS) ||
402 }
403 
405  TargetTransformInfo &TTI) {
406  bool Changed = false;
407  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) {
408  BasicBlock &BB = *BI++;
409  for (BasicBlock::iterator II = BB.begin(), IE = BB.end(); II != IE;) {
410  Instruction *I = &*II++;
411  CallSite CS(cast<Value>(I));
412  if (!CS || isa<IntrinsicInst>(I) || isInstructionTriviallyDead(I, &TLI))
413  continue;
414 
416  if (!Callee || Callee->isDeclaration())
417  continue;
418  Changed |= tryToSplitCallSite(CS, TTI);
419  }
420  }
421  return Changed;
422 }
423 
424 namespace {
425 struct CallSiteSplittingLegacyPass : public FunctionPass {
426  static char ID;
427  CallSiteSplittingLegacyPass() : FunctionPass(ID) {
429  }
430 
431  void getAnalysisUsage(AnalysisUsage &AU) const override {
435  }
436 
437  bool runOnFunction(Function &F) override {
438  if (skipFunction(F))
439  return false;
440 
441  auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
442  auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
443  return doCallSiteSplitting(F, TLI, TTI);
444  }
445 };
446 } // namespace
447 
449 INITIALIZE_PASS_BEGIN(CallSiteSplittingLegacyPass, "callsite-splitting",
450  "Call-site splitting", false, false)
453 INITIALIZE_PASS_END(CallSiteSplittingLegacyPass, "callsite-splitting",
454  "Call-site splitting", false, false)
456  return new CallSiteSplittingLegacyPass();
457 }
458 
461  auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
462  auto &TTI = AM.getResult<TargetIRAnalysis>(F);
463 
464  if (!doCallSiteSplitting(F, TLI, TTI))
465  return PreservedAnalyses::all();
467  return PA;
468 }
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:67
void push_back(const T &Elt)
Definition: SmallVector.h:212
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:347
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:72
static bool canSplitCallSite(CallSite CS, TargetTransformInfo &TTI)
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...
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 * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the specified block at the specified instruction - everything before SplitPt stays in Old and e...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
iterator end()
Definition: Function.h:636
SmallVector< ConditionTy, 2 > ConditionsTy
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
Definition: PatternMatch.h:91
iterator_range< IterTy > args() const
Definition: CallSite.h:215
Analysis pass providing the TargetTransformInfo.
unsigned second
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:814
STATISTIC(NumFunctions, "Total number of functions")
F(f)
reverse_iterator rend()
Definition: BasicBlock.h:259
static bool tryToSplitOnPHIPredicatedArgument(CallSite CS)
static void splitCallSite(CallSite CS, const SmallVectorImpl< std::pair< BasicBlock *, ConditionsTy >> &Preds)
Return true if the CS is split into its new predecessors.
int getInstructionCost(const Instruction *I, enum TargetCostKind kind) const
Query the cost of a specified instruction.
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
static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI, TargetTransformInfo &TTI)
IterTy arg_end() const
Definition: CallSite.h:575
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
void initializeCallSiteSplittingLegacyPassPass(PassRegistry &)
InstrTy * getInstruction() const
Definition: CallSite.h:92
static cl::opt< unsigned > DuplicationThreshold("callsite-splitting-duplication-threshold", cl::Hidden, cl::desc("Only allow instructions before a call, if " "their cost is below DuplicationThreshold"), cl::init(5))
Only allow instructions before a call, if their CodeSize cost is below DuplicationThreshold.
void setArgument(unsigned ArgNo, Value *newVal)
Definition: CallSite.h:191
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Definition: Constants.cpp:85
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:439
iterator begin()
Definition: Function.h:634
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)
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
Wrapper pass for TargetTransformInfo.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
static void addNonNullAttribute(CallSite CS, Value *Op)
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:73
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Conditional or Unconditional Branch instruction.
static bool tryToSplitOnPredicatedArgument(CallSite CS)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:371
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
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
self_iterator getIterator()
Definition: ilist_node.h:82
static void setConstantInArgument(CallSite CS, Value *Op, Constant *ConstValue)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::pair< ICmpInst *, unsigned > ConditionTy
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:418
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
static bool tryToSplitCallSite(CallSite CS, TargetTransformInfo &TTI)
iterator end()
Definition: BasicBlock.h:254
IterTy arg_begin() const
Definition: CallSite.h:571
static void recordCondition(CallSite CS, BasicBlock *From, BasicBlock *To, ConditionsTy &Conditions)
If From has a conditional jump to To, add the condition to Conditions, if it is relevant to any argum...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
Provides information about what library functions are available for the current target.
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)
BasicBlock * DuplicateInstructionsInSplitBetween(BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt, ValueToValueMapTy &ValueMapping)
Split edge between BB and PredBB and duplicate all non-Phi instructions from BB between its beginning...
amdgpu Simplify well known AMD library false Value Value * Arg
unsigned getNumUses() const
This method computes the number of uses of this Value.
Definition: Value.cpp:170
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
reverse_self_iterator getReverseIterator()
Definition: ilist_node.h:85
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
#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 SmallVector< BasicBlock *, 2 > getTwoPredecessors(BasicBlock *BB)
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:308
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())
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:346
LLVM Value Representation.
Definition: Value.h:73
static void addConditions(CallSite CS, const ConditionsTy &Conditions)
static const Function * getParent(const Value *V)
#define DEBUG(X)
Definition: Debug.h:118
A container for analyses that lazily runs them and caches their results.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
Definition: BasicBlock.cpp:178
static void recordConditions(CallSite CS, BasicBlock *Pred, ConditionsTy &Conditions)
Record ICmp conditions relevant to any argument in CS following Pred&#39;s single successors.
This pass exposes codegen information to IR-level passes.
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
bool use_empty() const
Definition: Value.h:328
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Definition: CallSite.h:345
const BasicBlock * getParent() const
Definition: Instruction.h:67
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Definition: PatternMatch.h:874
FunctionPass * createCallSiteSplittingPass()