LLVM  16.0.0git
InlineFunction.cpp
Go to the documentation of this file.
1 //===- InlineFunction.cpp - Code to perform function inlining -------------===//
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 inlining of a function into a call site, resolving
10 // parameters and the return value as appropriate.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/None.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SetVector.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringExtras.h"
36 #include "llvm/IR/Argument.h"
37 #include "llvm/IR/BasicBlock.h"
38 #include "llvm/IR/CFG.h"
39 #include "llvm/IR/Constant.h"
40 #include "llvm/IR/Constants.h"
41 #include "llvm/IR/DataLayout.h"
42 #include "llvm/IR/DebugInfo.h"
44 #include "llvm/IR/DebugLoc.h"
45 #include "llvm/IR/DerivedTypes.h"
46 #include "llvm/IR/Dominators.h"
47 #include "llvm/IR/Function.h"
48 #include "llvm/IR/IRBuilder.h"
49 #include "llvm/IR/InlineAsm.h"
50 #include "llvm/IR/InstrTypes.h"
51 #include "llvm/IR/Instruction.h"
52 #include "llvm/IR/Instructions.h"
53 #include "llvm/IR/IntrinsicInst.h"
54 #include "llvm/IR/Intrinsics.h"
55 #include "llvm/IR/LLVMContext.h"
56 #include "llvm/IR/MDBuilder.h"
57 #include "llvm/IR/Metadata.h"
58 #include "llvm/IR/Module.h"
59 #include "llvm/IR/Type.h"
60 #include "llvm/IR/User.h"
61 #include "llvm/IR/Value.h"
62 #include "llvm/Support/Casting.h"
69 #include <algorithm>
70 #include <cassert>
71 #include <cstdint>
72 #include <iterator>
73 #include <limits>
74 #include <string>
75 #include <utility>
76 #include <vector>
77 
78 #define DEBUG_TYPE "inline-function"
79 
80 using namespace llvm;
81 using namespace llvm::memprof;
83 
84 static cl::opt<bool>
85 EnableNoAliasConversion("enable-noalias-to-md-conversion", cl::init(true),
86  cl::Hidden,
87  cl::desc("Convert noalias attributes to metadata during inlining."));
88 
89 static cl::opt<bool>
90  UseNoAliasIntrinsic("use-noalias-intrinsic-during-inlining", cl::Hidden,
91  cl::init(true),
92  cl::desc("Use the llvm.experimental.noalias.scope.decl "
93  "intrinsic during inlining."));
94 
95 // Disabled by default, because the added alignment assumptions may increase
96 // compile-time and block optimizations. This option is not suitable for use
97 // with frontends that emit comprehensive parameter alignment annotations.
98 static cl::opt<bool>
99 PreserveAlignmentAssumptions("preserve-alignment-assumptions-during-inlining",
100  cl::init(false), cl::Hidden,
101  cl::desc("Convert align attributes to assumptions during inlining."));
102 
104  "update-return-attrs", cl::init(true), cl::Hidden,
105  cl::desc("Update return attributes on calls within inlined body"));
106 
108  "max-inst-checked-for-throw-during-inlining", cl::Hidden,
109  cl::desc("the maximum number of instructions analyzed for may throw during "
110  "attribute inference in inlined body"),
111  cl::init(4));
112 
113 namespace {
114 
115  /// A class for recording information about inlining a landing pad.
116  class LandingPadInliningInfo {
117  /// Destination of the invoke's unwind.
118  BasicBlock *OuterResumeDest;
119 
120  /// Destination for the callee's resume.
121  BasicBlock *InnerResumeDest = nullptr;
122 
123  /// LandingPadInst associated with the invoke.
124  LandingPadInst *CallerLPad = nullptr;
125 
126  /// PHI for EH values from landingpad insts.
127  PHINode *InnerEHValuesPHI = nullptr;
128 
129  SmallVector<Value*, 8> UnwindDestPHIValues;
130 
131  public:
132  LandingPadInliningInfo(InvokeInst *II)
133  : OuterResumeDest(II->getUnwindDest()) {
134  // If there are PHI nodes in the unwind destination block, we need to keep
135  // track of which values came into them from the invoke before removing
136  // the edge from this block.
137  BasicBlock *InvokeBB = II->getParent();
138  BasicBlock::iterator I = OuterResumeDest->begin();
139  for (; isa<PHINode>(I); ++I) {
140  // Save the value to use for this edge.
141  PHINode *PHI = cast<PHINode>(I);
142  UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
143  }
144 
145  CallerLPad = cast<LandingPadInst>(I);
146  }
147 
148  /// The outer unwind destination is the target of
149  /// unwind edges introduced for calls within the inlined function.
150  BasicBlock *getOuterResumeDest() const {
151  return OuterResumeDest;
152  }
153 
154  BasicBlock *getInnerResumeDest();
155 
156  LandingPadInst *getLandingPadInst() const { return CallerLPad; }
157 
158  /// Forward the 'resume' instruction to the caller's landing pad block.
159  /// When the landing pad block has only one predecessor, this is
160  /// a simple branch. When there is more than one predecessor, we need to
161  /// split the landing pad block after the landingpad instruction and jump
162  /// to there.
163  void forwardResume(ResumeInst *RI,
164  SmallPtrSetImpl<LandingPadInst*> &InlinedLPads);
165 
166  /// Add incoming-PHI values to the unwind destination block for the given
167  /// basic block, using the values for the original invoke's source block.
168  void addIncomingPHIValuesFor(BasicBlock *BB) const {
169  addIncomingPHIValuesForInto(BB, OuterResumeDest);
170  }
171 
172  void addIncomingPHIValuesForInto(BasicBlock *src, BasicBlock *dest) const {
173  BasicBlock::iterator I = dest->begin();
174  for (unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++I) {
175  PHINode *phi = cast<PHINode>(I);
176  phi->addIncoming(UnwindDestPHIValues[i], src);
177  }
178  }
179  };
180 
181 } // end anonymous namespace
182 
183 /// Get or create a target for the branch from ResumeInsts.
184 BasicBlock *LandingPadInliningInfo::getInnerResumeDest() {
185  if (InnerResumeDest) return InnerResumeDest;
186 
187  // Split the landing pad.
188  BasicBlock::iterator SplitPoint = ++CallerLPad->getIterator();
189  InnerResumeDest =
190  OuterResumeDest->splitBasicBlock(SplitPoint,
191  OuterResumeDest->getName() + ".body");
192 
193  // The number of incoming edges we expect to the inner landing pad.
194  const unsigned PHICapacity = 2;
195 
196  // Create corresponding new PHIs for all the PHIs in the outer landing pad.
197  Instruction *InsertPoint = &InnerResumeDest->front();
198  BasicBlock::iterator I = OuterResumeDest->begin();
199  for (unsigned i = 0, e = UnwindDestPHIValues.size(); i != e; ++i, ++I) {
200  PHINode *OuterPHI = cast<PHINode>(I);
201  PHINode *InnerPHI = PHINode::Create(OuterPHI->getType(), PHICapacity,
202  OuterPHI->getName() + ".lpad-body",
203  InsertPoint);
204  OuterPHI->replaceAllUsesWith(InnerPHI);
205  InnerPHI->addIncoming(OuterPHI, OuterResumeDest);
206  }
207 
208  // Create a PHI for the exception values.
209  InnerEHValuesPHI = PHINode::Create(CallerLPad->getType(), PHICapacity,
210  "eh.lpad-body", InsertPoint);
211  CallerLPad->replaceAllUsesWith(InnerEHValuesPHI);
212  InnerEHValuesPHI->addIncoming(CallerLPad, OuterResumeDest);
213 
214  // All done.
215  return InnerResumeDest;
216 }
217 
218 /// Forward the 'resume' instruction to the caller's landing pad block.
219 /// When the landing pad block has only one predecessor, this is a simple
220 /// branch. When there is more than one predecessor, we need to split the
221 /// landing pad block after the landingpad instruction and jump to there.
222 void LandingPadInliningInfo::forwardResume(
223  ResumeInst *RI, SmallPtrSetImpl<LandingPadInst *> &InlinedLPads) {
224  BasicBlock *Dest = getInnerResumeDest();
225  BasicBlock *Src = RI->getParent();
226 
227  BranchInst::Create(Dest, Src);
228 
229  // Update the PHIs in the destination. They were inserted in an order which
230  // makes this work.
231  addIncomingPHIValuesForInto(Src, Dest);
232 
233  InnerEHValuesPHI->addIncoming(RI->getOperand(0), Src);
234  RI->eraseFromParent();
235 }
236 
237 /// Helper for getUnwindDestToken/getUnwindDestTokenHelper.
238 static Value *getParentPad(Value *EHPad) {
239  if (auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
240  return FPI->getParentPad();
241  return cast<CatchSwitchInst>(EHPad)->getParentPad();
242 }
243 
245 
246 /// Helper for getUnwindDestToken that does the descendant-ward part of
247 /// the search.
249  UnwindDestMemoTy &MemoMap) {
250  SmallVector<Instruction *, 8> Worklist(1, EHPad);
251 
252  while (!Worklist.empty()) {
253  Instruction *CurrentPad = Worklist.pop_back_val();
254  // We only put pads on the worklist that aren't in the MemoMap. When
255  // we find an unwind dest for a pad we may update its ancestors, but
256  // the queue only ever contains uncles/great-uncles/etc. of CurrentPad,
257  // so they should never get updated while queued on the worklist.
258  assert(!MemoMap.count(CurrentPad));
259  Value *UnwindDestToken = nullptr;
260  if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(CurrentPad)) {
261  if (CatchSwitch->hasUnwindDest()) {
262  UnwindDestToken = CatchSwitch->getUnwindDest()->getFirstNonPHI();
263  } else {
264  // Catchswitch doesn't have a 'nounwind' variant, and one might be
265  // annotated as "unwinds to caller" when really it's nounwind (see
266  // e.g. SimplifyCFGOpt::SimplifyUnreachable), so we can't infer the
267  // parent's unwind dest from this. We can check its catchpads'
268  // descendants, since they might include a cleanuppad with an
269  // "unwinds to caller" cleanupret, which can be trusted.
270  for (auto HI = CatchSwitch->handler_begin(),
271  HE = CatchSwitch->handler_end();
272  HI != HE && !UnwindDestToken; ++HI) {
273  BasicBlock *HandlerBlock = *HI;
274  auto *CatchPad = cast<CatchPadInst>(HandlerBlock->getFirstNonPHI());
275  for (User *Child : CatchPad->users()) {
276  // Intentionally ignore invokes here -- since the catchswitch is
277  // marked "unwind to caller", it would be a verifier error if it
278  // contained an invoke which unwinds out of it, so any invoke we'd
279  // encounter must unwind to some child of the catch.
280  if (!isa<CleanupPadInst>(Child) && !isa<CatchSwitchInst>(Child))
281  continue;
282 
283  Instruction *ChildPad = cast<Instruction>(Child);
284  auto Memo = MemoMap.find(ChildPad);
285  if (Memo == MemoMap.end()) {
286  // Haven't figured out this child pad yet; queue it.
287  Worklist.push_back(ChildPad);
288  continue;
289  }
290  // We've already checked this child, but might have found that
291  // it offers no proof either way.
292  Value *ChildUnwindDestToken = Memo->second;
293  if (!ChildUnwindDestToken)
294  continue;
295  // We already know the child's unwind dest, which can either
296  // be ConstantTokenNone to indicate unwind to caller, or can
297  // be another child of the catchpad. Only the former indicates
298  // the unwind dest of the catchswitch.
299  if (isa<ConstantTokenNone>(ChildUnwindDestToken)) {
300  UnwindDestToken = ChildUnwindDestToken;
301  break;
302  }
303  assert(getParentPad(ChildUnwindDestToken) == CatchPad);
304  }
305  }
306  }
307  } else {
308  auto *CleanupPad = cast<CleanupPadInst>(CurrentPad);
309  for (User *U : CleanupPad->users()) {
310  if (auto *CleanupRet = dyn_cast<CleanupReturnInst>(U)) {
311  if (BasicBlock *RetUnwindDest = CleanupRet->getUnwindDest())
312  UnwindDestToken = RetUnwindDest->getFirstNonPHI();
313  else
314  UnwindDestToken = ConstantTokenNone::get(CleanupPad->getContext());
315  break;
316  }
317  Value *ChildUnwindDestToken;
318  if (auto *Invoke = dyn_cast<InvokeInst>(U)) {
319  ChildUnwindDestToken = Invoke->getUnwindDest()->getFirstNonPHI();
320  } else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U)) {
321  Instruction *ChildPad = cast<Instruction>(U);
322  auto Memo = MemoMap.find(ChildPad);
323  if (Memo == MemoMap.end()) {
324  // Haven't resolved this child yet; queue it and keep searching.
325  Worklist.push_back(ChildPad);
326  continue;
327  }
328  // We've checked this child, but still need to ignore it if it
329  // had no proof either way.
330  ChildUnwindDestToken = Memo->second;
331  if (!ChildUnwindDestToken)
332  continue;
333  } else {
334  // Not a relevant user of the cleanuppad
335  continue;
336  }
337  // In a well-formed program, the child/invoke must either unwind to
338  // an(other) child of the cleanup, or exit the cleanup. In the
339  // first case, continue searching.
340  if (isa<Instruction>(ChildUnwindDestToken) &&
341  getParentPad(ChildUnwindDestToken) == CleanupPad)
342  continue;
343  UnwindDestToken = ChildUnwindDestToken;
344  break;
345  }
346  }
347  // If we haven't found an unwind dest for CurrentPad, we may have queued its
348  // children, so move on to the next in the worklist.
349  if (!UnwindDestToken)
350  continue;
351 
352  // Now we know that CurrentPad unwinds to UnwindDestToken. It also exits
353  // any ancestors of CurrentPad up to but not including UnwindDestToken's
354  // parent pad. Record this in the memo map, and check to see if the
355  // original EHPad being queried is one of the ones exited.
356  Value *UnwindParent;
357  if (auto *UnwindPad = dyn_cast<Instruction>(UnwindDestToken))
358  UnwindParent = getParentPad(UnwindPad);
359  else
360  UnwindParent = nullptr;
361  bool ExitedOriginalPad = false;
362  for (Instruction *ExitedPad = CurrentPad;
363  ExitedPad && ExitedPad != UnwindParent;
364  ExitedPad = dyn_cast<Instruction>(getParentPad(ExitedPad))) {
365  // Skip over catchpads since they just follow their catchswitches.
366  if (isa<CatchPadInst>(ExitedPad))
367  continue;
368  MemoMap[ExitedPad] = UnwindDestToken;
369  ExitedOriginalPad |= (ExitedPad == EHPad);
370  }
371 
372  if (ExitedOriginalPad)
373  return UnwindDestToken;
374 
375  // Continue the search.
376  }
377 
378  // No definitive information is contained within this funclet.
379  return nullptr;
380 }
381 
382 /// Given an EH pad, find where it unwinds. If it unwinds to an EH pad,
383 /// return that pad instruction. If it unwinds to caller, return
384 /// ConstantTokenNone. If it does not have a definitive unwind destination,
385 /// return nullptr.
386 ///
387 /// This routine gets invoked for calls in funclets in inlinees when inlining
388 /// an invoke. Since many funclets don't have calls inside them, it's queried
389 /// on-demand rather than building a map of pads to unwind dests up front.
390 /// Determining a funclet's unwind dest may require recursively searching its
391 /// descendants, and also ancestors and cousins if the descendants don't provide
392 /// an answer. Since most funclets will have their unwind dest immediately
393 /// available as the unwind dest of a catchswitch or cleanupret, this routine
394 /// searches top-down from the given pad and then up. To avoid worst-case
395 /// quadratic run-time given that approach, it uses a memo map to avoid
396 /// re-processing funclet trees. The callers that rewrite the IR as they go
397 /// take advantage of this, for correctness, by checking/forcing rewritten
398 /// pads' entries to match the original callee view.
400  UnwindDestMemoTy &MemoMap) {
401  // Catchpads unwind to the same place as their catchswitch;
402  // redirct any queries on catchpads so the code below can
403  // deal with just catchswitches and cleanuppads.
404  if (auto *CPI = dyn_cast<CatchPadInst>(EHPad))
405  EHPad = CPI->getCatchSwitch();
406 
407  // Check if we've already determined the unwind dest for this pad.
408  auto Memo = MemoMap.find(EHPad);
409  if (Memo != MemoMap.end())
410  return Memo->second;
411 
412  // Search EHPad and, if necessary, its descendants.
413  Value *UnwindDestToken = getUnwindDestTokenHelper(EHPad, MemoMap);
414  assert((UnwindDestToken == nullptr) != (MemoMap.count(EHPad) != 0));
415  if (UnwindDestToken)
416  return UnwindDestToken;
417 
418  // No information is available for this EHPad from itself or any of its
419  // descendants. An unwind all the way out to a pad in the caller would
420  // need also to agree with the unwind dest of the parent funclet, so
421  // search up the chain to try to find a funclet with information. Put
422  // null entries in the memo map to avoid re-processing as we go up.
423  MemoMap[EHPad] = nullptr;
424 #ifndef NDEBUG
426  TempMemos.insert(EHPad);
427 #endif
428  Instruction *LastUselessPad = EHPad;
429  Value *AncestorToken;
430  for (AncestorToken = getParentPad(EHPad);
431  auto *AncestorPad = dyn_cast<Instruction>(AncestorToken);
432  AncestorToken = getParentPad(AncestorToken)) {
433  // Skip over catchpads since they just follow their catchswitches.
434  if (isa<CatchPadInst>(AncestorPad))
435  continue;
436  // If the MemoMap had an entry mapping AncestorPad to nullptr, since we
437  // haven't yet called getUnwindDestTokenHelper for AncestorPad in this
438  // call to getUnwindDestToken, that would mean that AncestorPad had no
439  // information in itself, its descendants, or its ancestors. If that
440  // were the case, then we should also have recorded the lack of information
441  // for the descendant that we're coming from. So assert that we don't
442  // find a null entry in the MemoMap for AncestorPad.
443  assert(!MemoMap.count(AncestorPad) || MemoMap[AncestorPad]);
444  auto AncestorMemo = MemoMap.find(AncestorPad);
445  if (AncestorMemo == MemoMap.end()) {
446  UnwindDestToken = getUnwindDestTokenHelper(AncestorPad, MemoMap);
447  } else {
448  UnwindDestToken = AncestorMemo->second;
449  }
450  if (UnwindDestToken)
451  break;
452  LastUselessPad = AncestorPad;
453  MemoMap[LastUselessPad] = nullptr;
454 #ifndef NDEBUG
455  TempMemos.insert(LastUselessPad);
456 #endif
457  }
458 
459  // We know that getUnwindDestTokenHelper was called on LastUselessPad and
460  // returned nullptr (and likewise for EHPad and any of its ancestors up to
461  // LastUselessPad), so LastUselessPad has no information from below. Since
462  // getUnwindDestTokenHelper must investigate all downward paths through
463  // no-information nodes to prove that a node has no information like this,
464  // and since any time it finds information it records it in the MemoMap for
465  // not just the immediately-containing funclet but also any ancestors also
466  // exited, it must be the case that, walking downward from LastUselessPad,
467  // visiting just those nodes which have not been mapped to an unwind dest
468  // by getUnwindDestTokenHelper (the nullptr TempMemos notwithstanding, since
469  // they are just used to keep getUnwindDestTokenHelper from repeating work),
470  // any node visited must have been exhaustively searched with no information
471  // for it found.
472  SmallVector<Instruction *, 8> Worklist(1, LastUselessPad);
473  while (!Worklist.empty()) {
474  Instruction *UselessPad = Worklist.pop_back_val();
475  auto Memo = MemoMap.find(UselessPad);
476  if (Memo != MemoMap.end() && Memo->second) {
477  // Here the name 'UselessPad' is a bit of a misnomer, because we've found
478  // that it is a funclet that does have information about unwinding to
479  // a particular destination; its parent was a useless pad.
480  // Since its parent has no information, the unwind edge must not escape
481  // the parent, and must target a sibling of this pad. This local unwind
482  // gives us no information about EHPad. Leave it and the subtree rooted
483  // at it alone.
484  assert(getParentPad(Memo->second) == getParentPad(UselessPad));
485  continue;
486  }
487  // We know we don't have information for UselesPad. If it has an entry in
488  // the MemoMap (mapping it to nullptr), it must be one of the TempMemos
489  // added on this invocation of getUnwindDestToken; if a previous invocation
490  // recorded nullptr, it would have had to prove that the ancestors of
491  // UselessPad, which include LastUselessPad, had no information, and that
492  // in turn would have required proving that the descendants of
493  // LastUselesPad, which include EHPad, have no information about
494  // LastUselessPad, which would imply that EHPad was mapped to nullptr in
495  // the MemoMap on that invocation, which isn't the case if we got here.
496  assert(!MemoMap.count(UselessPad) || TempMemos.count(UselessPad));
497  // Assert as we enumerate users that 'UselessPad' doesn't have any unwind
498  // information that we'd be contradicting by making a map entry for it
499  // (which is something that getUnwindDestTokenHelper must have proved for
500  // us to get here). Just assert on is direct users here; the checks in
501  // this downward walk at its descendants will verify that they don't have
502  // any unwind edges that exit 'UselessPad' either (i.e. they either have no
503  // unwind edges or unwind to a sibling).
504  MemoMap[UselessPad] = UnwindDestToken;
505  if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(UselessPad)) {
506  assert(CatchSwitch->getUnwindDest() == nullptr && "Expected useless pad");
507  for (BasicBlock *HandlerBlock : CatchSwitch->handlers()) {
508  auto *CatchPad = HandlerBlock->getFirstNonPHI();
509  for (User *U : CatchPad->users()) {
510  assert(
511  (!isa<InvokeInst>(U) ||
512  (getParentPad(
513  cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHI()) ==
514  CatchPad)) &&
515  "Expected useless pad");
516  if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
517  Worklist.push_back(cast<Instruction>(U));
518  }
519  }
520  } else {
521  assert(isa<CleanupPadInst>(UselessPad));
522  for (User *U : UselessPad->users()) {
523  assert(!isa<CleanupReturnInst>(U) && "Expected useless pad");
524  assert((!isa<InvokeInst>(U) ||
525  (getParentPad(
526  cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHI()) ==
527  UselessPad)) &&
528  "Expected useless pad");
529  if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
530  Worklist.push_back(cast<Instruction>(U));
531  }
532  }
533  }
534 
535  return UnwindDestToken;
536 }
537 
538 /// When we inline a basic block into an invoke,
539 /// we have to turn all of the calls that can throw into invokes.
540 /// This function analyze BB to see if there are any calls, and if so,
541 /// it rewrites them to be invokes that jump to InvokeDest and fills in the PHI
542 /// nodes in that block with the values specified in InvokeDestPHIValues.
544  BasicBlock *BB, BasicBlock *UnwindEdge,
545  UnwindDestMemoTy *FuncletUnwindMap = nullptr) {
547  // We only need to check for function calls: inlined invoke
548  // instructions require no special handling.
549  CallInst *CI = dyn_cast<CallInst>(&I);
550 
551  if (!CI || CI->doesNotThrow())
552  continue;
553 
554  if (CI->isInlineAsm()) {
555  InlineAsm *IA = cast<InlineAsm>(CI->getCalledOperand());
556  if (!IA->canThrow()) {
557  continue;
558  }
559  }
560 
561  // We do not need to (and in fact, cannot) convert possibly throwing calls
562  // to @llvm.experimental_deoptimize (resp. @llvm.experimental.guard) into
563  // invokes. The caller's "segment" of the deoptimization continuation
564  // attached to the newly inlined @llvm.experimental_deoptimize
565  // (resp. @llvm.experimental.guard) call should contain the exception
566  // handling logic, if any.
567  if (auto *F = CI->getCalledFunction())
568  if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize ||
569  F->getIntrinsicID() == Intrinsic::experimental_guard)
570  continue;
571 
572  if (auto FuncletBundle = CI->getOperandBundle(LLVMContext::OB_funclet)) {
573  // This call is nested inside a funclet. If that funclet has an unwind
574  // destination within the inlinee, then unwinding out of this call would
575  // be UB. Rewriting this call to an invoke which targets the inlined
576  // invoke's unwind dest would give the call's parent funclet multiple
577  // unwind destinations, which is something that subsequent EH table
578  // generation can't handle and that the veirifer rejects. So when we
579  // see such a call, leave it as a call.
580  auto *FuncletPad = cast<Instruction>(FuncletBundle->Inputs[0]);
581  Value *UnwindDestToken =
582  getUnwindDestToken(FuncletPad, *FuncletUnwindMap);
583  if (UnwindDestToken && !isa<ConstantTokenNone>(UnwindDestToken))
584  continue;
585 #ifndef NDEBUG
586  Instruction *MemoKey;
587  if (auto *CatchPad = dyn_cast<CatchPadInst>(FuncletPad))
588  MemoKey = CatchPad->getCatchSwitch();
589  else
590  MemoKey = FuncletPad;
591  assert(FuncletUnwindMap->count(MemoKey) &&
592  (*FuncletUnwindMap)[MemoKey] == UnwindDestToken &&
593  "must get memoized to avoid confusing later searches");
594 #endif // NDEBUG
595  }
596 
597  changeToInvokeAndSplitBasicBlock(CI, UnwindEdge);
598  return BB;
599  }
600  return nullptr;
601 }
602 
603 /// If we inlined an invoke site, we need to convert calls
604 /// in the body of the inlined function into invokes.
605 ///
606 /// II is the invoke instruction being inlined. FirstNewBlock is the first
607 /// block of the inlined code (the last block is the end of the function),
608 /// and InlineCodeInfo is information about the code that got inlined.
609 static void HandleInlinedLandingPad(InvokeInst *II, BasicBlock *FirstNewBlock,
610  ClonedCodeInfo &InlinedCodeInfo) {
611  BasicBlock *InvokeDest = II->getUnwindDest();
612 
613  Function *Caller = FirstNewBlock->getParent();
614 
615  // The inlined code is currently at the end of the function, scan from the
616  // start of the inlined code to its end, checking for stuff we need to
617  // rewrite.
618  LandingPadInliningInfo Invoke(II);
619 
620  // Get all of the inlined landing pad instructions.
622  for (Function::iterator I = FirstNewBlock->getIterator(), E = Caller->end();
623  I != E; ++I)
624  if (InvokeInst *II = dyn_cast<InvokeInst>(I->getTerminator()))
625  InlinedLPads.insert(II->getLandingPadInst());
626 
627  // Append the clauses from the outer landing pad instruction into the inlined
628  // landing pad instructions.
629  LandingPadInst *OuterLPad = Invoke.getLandingPadInst();
630  for (LandingPadInst *InlinedLPad : InlinedLPads) {
631  unsigned OuterNum = OuterLPad->getNumClauses();
632  InlinedLPad->reserveClauses(OuterNum);
633  for (unsigned OuterIdx = 0; OuterIdx != OuterNum; ++OuterIdx)
634  InlinedLPad->addClause(OuterLPad->getClause(OuterIdx));
635  if (OuterLPad->isCleanup())
636  InlinedLPad->setCleanup(true);
637  }
638 
639  for (Function::iterator BB = FirstNewBlock->getIterator(), E = Caller->end();
640  BB != E; ++BB) {
641  if (InlinedCodeInfo.ContainsCalls)
643  &*BB, Invoke.getOuterResumeDest()))
644  // Update any PHI nodes in the exceptional block to indicate that there
645  // is now a new entry in them.
646  Invoke.addIncomingPHIValuesFor(NewBB);
647 
648  // Forward any resumes that are remaining here.
649  if (ResumeInst *RI = dyn_cast<ResumeInst>(BB->getTerminator()))
650  Invoke.forwardResume(RI, InlinedLPads);
651  }
652 
653  // Now that everything is happy, we have one final detail. The PHI nodes in
654  // the exception destination block still have entries due to the original
655  // invoke instruction. Eliminate these entries (which might even delete the
656  // PHI node) now.
657  InvokeDest->removePredecessor(II->getParent());
658 }
659 
660 /// If we inlined an invoke site, we need to convert calls
661 /// in the body of the inlined function into invokes.
662 ///
663 /// II is the invoke instruction being inlined. FirstNewBlock is the first
664 /// block of the inlined code (the last block is the end of the function),
665 /// and InlineCodeInfo is information about the code that got inlined.
666 static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
667  ClonedCodeInfo &InlinedCodeInfo) {
668  BasicBlock *UnwindDest = II->getUnwindDest();
669  Function *Caller = FirstNewBlock->getParent();
670 
671  assert(UnwindDest->getFirstNonPHI()->isEHPad() && "unexpected BasicBlock!");
672 
673  // If there are PHI nodes in the unwind destination block, we need to keep
674  // track of which values came into them from the invoke before removing the
675  // edge from this block.
676  SmallVector<Value *, 8> UnwindDestPHIValues;
677  BasicBlock *InvokeBB = II->getParent();
678  for (PHINode &PHI : UnwindDest->phis()) {
679  // Save the value to use for this edge.
680  UnwindDestPHIValues.push_back(PHI.getIncomingValueForBlock(InvokeBB));
681  }
682 
683  // Add incoming-PHI values to the unwind destination block for the given basic
684  // block, using the values for the original invoke's source block.
685  auto UpdatePHINodes = [&](BasicBlock *Src) {
686  BasicBlock::iterator I = UnwindDest->begin();
687  for (Value *V : UnwindDestPHIValues) {
688  PHINode *PHI = cast<PHINode>(I);
689  PHI->addIncoming(V, Src);
690  ++I;
691  }
692  };
693 
694  // This connects all the instructions which 'unwind to caller' to the invoke
695  // destination.
696  UnwindDestMemoTy FuncletUnwindMap;
697  for (Function::iterator BB = FirstNewBlock->getIterator(), E = Caller->end();
698  BB != E; ++BB) {
699  if (auto *CRI = dyn_cast<CleanupReturnInst>(BB->getTerminator())) {
700  if (CRI->unwindsToCaller()) {
701  auto *CleanupPad = CRI->getCleanupPad();
702  CleanupReturnInst::Create(CleanupPad, UnwindDest, CRI);
703  CRI->eraseFromParent();
704  UpdatePHINodes(&*BB);
705  // Finding a cleanupret with an unwind destination would confuse
706  // subsequent calls to getUnwindDestToken, so map the cleanuppad
707  // to short-circuit any such calls and recognize this as an "unwind
708  // to caller" cleanup.
709  assert(!FuncletUnwindMap.count(CleanupPad) ||
710  isa<ConstantTokenNone>(FuncletUnwindMap[CleanupPad]));
711  FuncletUnwindMap[CleanupPad] =
712  ConstantTokenNone::get(Caller->getContext());
713  }
714  }
715 
716  Instruction *I = BB->getFirstNonPHI();
717  if (!I->isEHPad())
718  continue;
719 
720  Instruction *Replacement = nullptr;
721  if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
722  if (CatchSwitch->unwindsToCaller()) {
723  Value *UnwindDestToken;
724  if (auto *ParentPad =
725  dyn_cast<Instruction>(CatchSwitch->getParentPad())) {
726  // This catchswitch is nested inside another funclet. If that
727  // funclet has an unwind destination within the inlinee, then
728  // unwinding out of this catchswitch would be UB. Rewriting this
729  // catchswitch to unwind to the inlined invoke's unwind dest would
730  // give the parent funclet multiple unwind destinations, which is
731  // something that subsequent EH table generation can't handle and
732  // that the veirifer rejects. So when we see such a call, leave it
733  // as "unwind to caller".
734  UnwindDestToken = getUnwindDestToken(ParentPad, FuncletUnwindMap);
735  if (UnwindDestToken && !isa<ConstantTokenNone>(UnwindDestToken))
736  continue;
737  } else {
738  // This catchswitch has no parent to inherit constraints from, and
739  // none of its descendants can have an unwind edge that exits it and
740  // targets another funclet in the inlinee. It may or may not have a
741  // descendant that definitively has an unwind to caller. In either
742  // case, we'll have to assume that any unwinds out of it may need to
743  // be routed to the caller, so treat it as though it has a definitive
744  // unwind to caller.
745  UnwindDestToken = ConstantTokenNone::get(Caller->getContext());
746  }
747  auto *NewCatchSwitch = CatchSwitchInst::Create(
748  CatchSwitch->getParentPad(), UnwindDest,
749  CatchSwitch->getNumHandlers(), CatchSwitch->getName(),
750  CatchSwitch);
751  for (BasicBlock *PadBB : CatchSwitch->handlers())
752  NewCatchSwitch->addHandler(PadBB);
753  // Propagate info for the old catchswitch over to the new one in
754  // the unwind map. This also serves to short-circuit any subsequent
755  // checks for the unwind dest of this catchswitch, which would get
756  // confused if they found the outer handler in the callee.
757  FuncletUnwindMap[NewCatchSwitch] = UnwindDestToken;
758  Replacement = NewCatchSwitch;
759  }
760  } else if (!isa<FuncletPadInst>(I)) {
761  llvm_unreachable("unexpected EHPad!");
762  }
763 
764  if (Replacement) {
765  Replacement->takeName(I);
766  I->replaceAllUsesWith(Replacement);
767  I->eraseFromParent();
768  UpdatePHINodes(&*BB);
769  }
770  }
771 
772  if (InlinedCodeInfo.ContainsCalls)
773  for (Function::iterator BB = FirstNewBlock->getIterator(),
774  E = Caller->end();
775  BB != E; ++BB)
777  &*BB, UnwindDest, &FuncletUnwindMap))
778  // Update any PHI nodes in the exceptional block to indicate that there
779  // is now a new entry in them.
780  UpdatePHINodes(NewBB);
781 
782  // Now that everything is happy, we have one final detail. The PHI nodes in
783  // the exception destination block still have entries due to the original
784  // invoke instruction. Eliminate these entries (which might even delete the
785  // PHI node) now.
786  UnwindDest->removePredecessor(InvokeBB);
787 }
788 
789 static bool haveCommonPrefix(MDNode *MIBStackContext,
790  MDNode *CallsiteStackContext) {
791  assert(MIBStackContext->getNumOperands() > 0 &&
792  CallsiteStackContext->getNumOperands() > 0);
793  // Because of the context trimming performed during matching, the callsite
794  // context could have more stack ids than the MIB. We match up to the end of
795  // the shortest stack context.
796  for (auto MIBStackIter = MIBStackContext->op_begin(),
797  CallsiteStackIter = CallsiteStackContext->op_begin();
798  MIBStackIter != MIBStackContext->op_end() &&
799  CallsiteStackIter != CallsiteStackContext->op_end();
800  MIBStackIter++, CallsiteStackIter++) {
801  auto *Val1 = mdconst::dyn_extract<ConstantInt>(*MIBStackIter);
802  auto *Val2 = mdconst::dyn_extract<ConstantInt>(*CallsiteStackIter);
803  assert(Val1 && Val2);
804  if (Val1->getZExtValue() != Val2->getZExtValue())
805  return false;
806  }
807  return true;
808 }
809 
810 static void removeMemProfMetadata(CallBase *Call) {
811  Call->setMetadata(LLVMContext::MD_memprof, nullptr);
812 }
813 
814 static void removeCallsiteMetadata(CallBase *Call) {
815  Call->setMetadata(LLVMContext::MD_callsite, nullptr);
816 }
817 
819  const std::vector<Metadata *> &MIBList) {
820  assert(!MIBList.empty());
821  // Remove existing memprof, which will either be replaced or may not be needed
822  // if we are able to use a single allocation type function attribute.
825  for (Metadata *MIB : MIBList)
826  CallStack.addCallStack(cast<MDNode>(MIB));
827  bool MemprofMDAttached = CallStack.buildAndAttachMIBMetadata(CI);
828  assert(MemprofMDAttached == CI->hasMetadata(LLVMContext::MD_memprof));
829  if (!MemprofMDAttached)
830  // If we used a function attribute remove the callsite metadata as well.
832 }
833 
834 // Update the metadata on the inlined copy ClonedCall of a call OrigCall in the
835 // inlined callee body, based on the callsite metadata InlinedCallsiteMD from
836 // the call that was inlined.
837 static void
838 propagateMemProfHelper(const CallBase *OrigCall, CallBase *ClonedCall,
839  MDNode *InlinedCallsiteMD,
840  std::map<const CallBase *, std::vector<Metadata *>>
841  &OrigCallToNewMemProfMDMap) {
842  MDNode *OrigCallsiteMD = ClonedCall->getMetadata(LLVMContext::MD_callsite);
843  MDNode *ClonedCallsiteMD = nullptr;
844  // Check if the call originally had callsite metadata, and update it for the
845  // new call in the inlined body.
846  if (OrigCallsiteMD) {
847  // The cloned call's context is now the concatenation of the original call's
848  // callsite metadata and the callsite metadata on the call where it was
849  // inlined.
850  ClonedCallsiteMD = MDNode::concatenate(OrigCallsiteMD, InlinedCallsiteMD);
851  ClonedCall->setMetadata(LLVMContext::MD_callsite, ClonedCallsiteMD);
852  }
853 
854  // Update any memprof metadata on the cloned call.
855  MDNode *OrigMemProfMD = ClonedCall->getMetadata(LLVMContext::MD_memprof);
856  if (!OrigMemProfMD)
857  return;
858  // We currently expect that allocations with memprof metadata also have
859  // callsite metadata for the allocation's part of the context.
860  assert(OrigCallsiteMD);
861 
862  // New call's MIB list.
863  std::vector<Metadata *> NewMIBList;
864  // Updated MIB list for the original call in the out-of-line callee.
865  std::vector<Metadata *> UpdatedOrigMIBList;
866 
867  // For each MIB metadata, check if its call stack context starts with the
868  // new clone's callsite metadata. If so, that MIB goes onto the cloned call in
869  // the inlined body. If not, it stays on the out-of-line original call.
870  for (auto &MIBOp : OrigMemProfMD->operands()) {
871  MDNode *MIB = dyn_cast<MDNode>(MIBOp);
872  // Stack is first operand of MIB.
873  MDNode *StackMD = getMIBStackNode(MIB);
874  assert(StackMD);
875  // See if the new cloned callsite context matches this profiled context.
876  if (haveCommonPrefix(StackMD, ClonedCallsiteMD))
877  // Add it to the cloned call's MIB list.
878  NewMIBList.push_back(MIB);
879  else
880  // Keep it on the original call.
881  UpdatedOrigMIBList.push_back(MIB);
882  }
883  if (NewMIBList.empty()) {
884  removeMemProfMetadata(ClonedCall);
885  removeCallsiteMetadata(ClonedCall);
886  return;
887  }
888  if (NewMIBList.size() < OrigMemProfMD->getNumOperands()) {
889  assert(!UpdatedOrigMIBList.empty());
890  OrigCallToNewMemProfMDMap[OrigCall] = UpdatedOrigMIBList;
891  updateMemprofMetadata(ClonedCall, NewMIBList);
892  } else
893  OrigCallToNewMemProfMDMap[OrigCall] = {};
894 }
895 
896 // Update memprof related metadata (!memprof and !callsite) based on the
897 // inlining of Callee into the callsite at CB. The updates include merging the
898 // inlined callee's callsite metadata with that of the inlined call,
899 // and moving the subset of any memprof contexts to the inlined callee
900 // allocations if they match the new inlined call stack.
901 // FIXME: Replace memprof metadata with function attribute if all MIB end up
902 // having the same behavior. Do other context trimming/merging optimizations
903 // too.
904 static void
906  bool ContainsMemProfMetadata,
908  MDNode *CallsiteMD = CB.getMetadata(LLVMContext::MD_callsite);
909  // Only need to update if the inlined callsite had callsite metadata, or if
910  // there was any memprof metadata inlined.
911  if (!CallsiteMD && !ContainsMemProfMetadata)
912  return;
913 
914  // Propagate metadata onto the cloned calls in the inlined callee.
915  // Can't update the original call using the VMap since it holds a const
916  // pointer, those will be updated in the subsequent loop.
917  std::map<const CallBase *, std::vector<Metadata *>> OrigCallToNewMemProfMDMap;
918  for (const auto &Entry : VMap) {
919  // See if this is a call that has been inlined and remapped, and not
920  // simplified away in the process.
921  auto *OrigCall = dyn_cast_or_null<CallBase>(Entry.first);
922  auto *ClonedCall = dyn_cast_or_null<CallBase>(Entry.second);
923  if (!OrigCall || !ClonedCall)
924  continue;
925  // If the inlined callsite did not have any callsite metadata, then it isn't
926  // involved in any profiled call contexts, and we can remove any memprof
927  // metadata on the cloned call.
928  if (!CallsiteMD) {
929  removeMemProfMetadata(ClonedCall);
930  removeCallsiteMetadata(ClonedCall);
931  continue;
932  }
933  propagateMemProfHelper(OrigCall, ClonedCall, CallsiteMD,
934  OrigCallToNewMemProfMDMap);
935  }
936 
937  // Update memprof MD on calls within the original callee function to remove
938  // MIB with stacks that matched the inlined context (those moved to a new
939  // memprof MD on the inlined version of the call).
940  for (BasicBlock &BB : *Callee) {
941  for (Instruction &I : BB) {
942  CallBase *Call = dyn_cast<CallBase>(&I);
943  if (!Call || !OrigCallToNewMemProfMDMap.count(Call))
944  continue;
945  std::vector<Metadata *> &UpdatedMemProfMD =
946  OrigCallToNewMemProfMDMap[Call];
947  if (!UpdatedMemProfMD.empty())
948  updateMemprofMetadata(Call, UpdatedMemProfMD);
949  else {
950  removeMemProfMetadata(Call);
952  }
953  }
954  }
955 }
956 
957 /// When inlining a call site that has !llvm.mem.parallel_loop_access,
958 /// !llvm.access.group, !alias.scope or !noalias metadata, that metadata should
959 /// be propagated to all memory-accessing cloned instructions.
961  Function::iterator FEnd) {
962  MDNode *MemParallelLoopAccess =
963  CB.getMetadata(LLVMContext::MD_mem_parallel_loop_access);
964  MDNode *AccessGroup = CB.getMetadata(LLVMContext::MD_access_group);
965  MDNode *AliasScope = CB.getMetadata(LLVMContext::MD_alias_scope);
966  MDNode *NoAlias = CB.getMetadata(LLVMContext::MD_noalias);
967  if (!MemParallelLoopAccess && !AccessGroup && !AliasScope && !NoAlias)
968  return;
969 
970  for (BasicBlock &BB : make_range(FStart, FEnd)) {
971  for (Instruction &I : BB) {
972  // This metadata is only relevant for instructions that access memory.
973  if (!I.mayReadOrWriteMemory())
974  continue;
975 
976  if (MemParallelLoopAccess) {
977  // TODO: This probably should not overwrite MemParalleLoopAccess.
978  MemParallelLoopAccess = MDNode::concatenate(
979  I.getMetadata(LLVMContext::MD_mem_parallel_loop_access),
980  MemParallelLoopAccess);
981  I.setMetadata(LLVMContext::MD_mem_parallel_loop_access,
982  MemParallelLoopAccess);
983  }
984 
985  if (AccessGroup)
986  I.setMetadata(LLVMContext::MD_access_group, uniteAccessGroups(
987  I.getMetadata(LLVMContext::MD_access_group), AccessGroup));
988 
989  if (AliasScope)
990  I.setMetadata(LLVMContext::MD_alias_scope, MDNode::concatenate(
991  I.getMetadata(LLVMContext::MD_alias_scope), AliasScope));
992 
993  if (NoAlias)
994  I.setMetadata(LLVMContext::MD_noalias, MDNode::concatenate(
995  I.getMetadata(LLVMContext::MD_noalias), NoAlias));
996  }
997  }
998 }
999 
1000 /// Bundle operands of the inlined function must be added to inlined call sites.
1002  Instruction *CallSiteEHPad) {
1003  for (Instruction &II : llvm::make_early_inc_range(*InlinedBB)) {
1004  CallBase *I = dyn_cast<CallBase>(&II);
1005  if (!I)
1006  continue;
1007  // Skip call sites which already have a "funclet" bundle.
1008  if (I->getOperandBundle(LLVMContext::OB_funclet))
1009  continue;
1010  // Skip call sites which are nounwind intrinsics (as long as they don't
1011  // lower into regular function calls in the course of IR transformations).
1012  auto *CalledFn =
1013  dyn_cast<Function>(I->getCalledOperand()->stripPointerCasts());
1014  if (CalledFn && CalledFn->isIntrinsic() && I->doesNotThrow() &&
1015  !IntrinsicInst::mayLowerToFunctionCall(CalledFn->getIntrinsicID()))
1016  continue;
1017 
1019  I->getOperandBundlesAsDefs(OpBundles);
1020  OpBundles.emplace_back("funclet", CallSiteEHPad);
1021 
1022  Instruction *NewInst = CallBase::Create(I, OpBundles, I);
1023  NewInst->takeName(I);
1024  I->replaceAllUsesWith(NewInst);
1025  I->eraseFromParent();
1026  }
1027 }
1028 
1029 namespace {
1030 /// Utility for cloning !noalias and !alias.scope metadata. When a code region
1031 /// using scoped alias metadata is inlined, the aliasing relationships may not
1032 /// hold between the two version. It is necessary to create a deep clone of the
1033 /// metadata, putting the two versions in separate scope domains.
1034 class ScopedAliasMetadataDeepCloner {
1035  using MetadataMap = DenseMap<const MDNode *, TrackingMDNodeRef>;
1037  MetadataMap MDMap;
1038  void addRecursiveMetadataUses();
1039 
1040 public:
1041  ScopedAliasMetadataDeepCloner(const Function *F);
1042 
1043  /// Create a new clone of the scoped alias metadata, which will be used by
1044  /// subsequent remap() calls.
1045  void clone();
1046 
1047  /// Remap instructions in the given range from the original to the cloned
1048  /// metadata.
1049  void remap(Function::iterator FStart, Function::iterator FEnd);
1050 };
1051 } // namespace
1052 
1053 ScopedAliasMetadataDeepCloner::ScopedAliasMetadataDeepCloner(
1054  const Function *F) {
1055  for (const BasicBlock &BB : *F) {
1056  for (const Instruction &I : BB) {
1057  if (const MDNode *M = I.getMetadata(LLVMContext::MD_alias_scope))
1058  MD.insert(M);
1059  if (const MDNode *M = I.getMetadata(LLVMContext::MD_noalias))
1060  MD.insert(M);
1061 
1062  // We also need to clone the metadata in noalias intrinsics.
1063  if (const auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
1064  MD.insert(Decl->getScopeList());
1065  }
1066  }
1067  addRecursiveMetadataUses();
1068 }
1069 
1070 void ScopedAliasMetadataDeepCloner::addRecursiveMetadataUses() {
1071  SmallVector<const Metadata *, 16> Queue(MD.begin(), MD.end());
1072  while (!Queue.empty()) {
1073  const MDNode *M = cast<MDNode>(Queue.pop_back_val());
1074  for (const Metadata *Op : M->operands())
1075  if (const MDNode *OpMD = dyn_cast<MDNode>(Op))
1076  if (MD.insert(OpMD))
1077  Queue.push_back(OpMD);
1078  }
1079 }
1080 
1081 void ScopedAliasMetadataDeepCloner::clone() {
1082  assert(MDMap.empty() && "clone() already called ?");
1083 
1084  SmallVector<TempMDTuple, 16> DummyNodes;
1085  for (const MDNode *I : MD) {
1086  DummyNodes.push_back(MDTuple::getTemporary(I->getContext(), None));
1087  MDMap[I].reset(DummyNodes.back().get());
1088  }
1089 
1090  // Create new metadata nodes to replace the dummy nodes, replacing old
1091  // metadata references with either a dummy node or an already-created new
1092  // node.
1094  for (const MDNode *I : MD) {
1095  for (const Metadata *Op : I->operands()) {
1096  if (const MDNode *M = dyn_cast<MDNode>(Op))
1097  NewOps.push_back(MDMap[M]);
1098  else
1099  NewOps.push_back(const_cast<Metadata *>(Op));
1100  }
1101 
1102  MDNode *NewM = MDNode::get(I->getContext(), NewOps);
1103  MDTuple *TempM = cast<MDTuple>(MDMap[I]);
1104  assert(TempM->isTemporary() && "Expected temporary node");
1105 
1106  TempM->replaceAllUsesWith(NewM);
1107  NewOps.clear();
1108  }
1109 }
1110 
1111 void ScopedAliasMetadataDeepCloner::remap(Function::iterator FStart,
1112  Function::iterator FEnd) {
1113  if (MDMap.empty())
1114  return; // Nothing to do.
1115 
1116  for (BasicBlock &BB : make_range(FStart, FEnd)) {
1117  for (Instruction &I : BB) {
1118  // TODO: The null checks for the MDMap.lookup() results should no longer
1119  // be necessary.
1120  if (MDNode *M = I.getMetadata(LLVMContext::MD_alias_scope))
1121  if (MDNode *MNew = MDMap.lookup(M))
1122  I.setMetadata(LLVMContext::MD_alias_scope, MNew);
1123 
1124  if (MDNode *M = I.getMetadata(LLVMContext::MD_noalias))
1125  if (MDNode *MNew = MDMap.lookup(M))
1126  I.setMetadata(LLVMContext::MD_noalias, MNew);
1127 
1128  if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
1129  if (MDNode *MNew = MDMap.lookup(Decl->getScopeList()))
1130  Decl->setScopeList(MNew);
1131  }
1132  }
1133 }
1134 
1135 /// If the inlined function has noalias arguments,
1136 /// then add new alias scopes for each noalias argument, tag the mapped noalias
1137 /// parameters with noalias metadata specifying the new scope, and tag all
1138 /// non-derived loads, stores and memory intrinsics with the new alias scopes.
1140  const DataLayout &DL, AAResults *CalleeAAR,
1141  ClonedCodeInfo &InlinedFunctionInfo) {
1143  return;
1144 
1145  const Function *CalledFunc = CB.getCalledFunction();
1147 
1148  for (const Argument &Arg : CalledFunc->args())
1149  if (CB.paramHasAttr(Arg.getArgNo(), Attribute::NoAlias) && !Arg.use_empty())
1150  NoAliasArgs.push_back(&Arg);
1151 
1152  if (NoAliasArgs.empty())
1153  return;
1154 
1155  // To do a good job, if a noalias variable is captured, we need to know if
1156  // the capture point dominates the particular use we're considering.
1157  DominatorTree DT;
1158  DT.recalculate(const_cast<Function&>(*CalledFunc));
1159 
1160  // noalias indicates that pointer values based on the argument do not alias
1161  // pointer values which are not based on it. So we add a new "scope" for each
1162  // noalias function argument. Accesses using pointers based on that argument
1163  // become part of that alias scope, accesses using pointers not based on that
1164  // argument are tagged as noalias with that scope.
1165 
1167  MDBuilder MDB(CalledFunc->getContext());
1168 
1169  // Create a new scope domain for this function.
1170  MDNode *NewDomain =
1171  MDB.createAnonymousAliasScopeDomain(CalledFunc->getName());
1172  for (unsigned i = 0, e = NoAliasArgs.size(); i != e; ++i) {
1173  const Argument *A = NoAliasArgs[i];
1174 
1175  std::string Name = std::string(CalledFunc->getName());
1176  if (A->hasName()) {
1177  Name += ": %";
1178  Name += A->getName();
1179  } else {
1180  Name += ": argument ";
1181  Name += utostr(i);
1182  }
1183 
1184  // Note: We always create a new anonymous root here. This is true regardless
1185  // of the linkage of the callee because the aliasing "scope" is not just a
1186  // property of the callee, but also all control dependencies in the caller.
1187  MDNode *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name);
1188  NewScopes.insert(std::make_pair(A, NewScope));
1189 
1190  if (UseNoAliasIntrinsic) {
1191  // Introduce a llvm.experimental.noalias.scope.decl for the noalias
1192  // argument.
1193  MDNode *AScopeList = MDNode::get(CalledFunc->getContext(), NewScope);
1194  auto *NoAliasDecl =
1195  IRBuilder<>(&CB).CreateNoAliasScopeDeclaration(AScopeList);
1196  // Ignore the result for now. The result will be used when the
1197  // llvm.noalias intrinsic is introduced.
1198  (void)NoAliasDecl;
1199  }
1200  }
1201 
1202  // Iterate over all new instructions in the map; for all memory-access
1203  // instructions, add the alias scope metadata.
1204  for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end();
1205  VMI != VMIE; ++VMI) {
1206  if (const Instruction *I = dyn_cast<Instruction>(VMI->first)) {
1207  if (!VMI->second)
1208  continue;
1209 
1210  Instruction *NI = dyn_cast<Instruction>(VMI->second);
1211  if (!NI || InlinedFunctionInfo.isSimplified(I, NI))
1212  continue;
1213 
1214  bool IsArgMemOnlyCall = false, IsFuncCall = false;
1216 
1217  if (const LoadInst *LI = dyn_cast<LoadInst>(I))
1218  PtrArgs.push_back(LI->getPointerOperand());
1219  else if (const StoreInst *SI = dyn_cast<StoreInst>(I))
1220  PtrArgs.push_back(SI->getPointerOperand());
1221  else if (const VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
1222  PtrArgs.push_back(VAAI->getPointerOperand());
1223  else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I))
1224  PtrArgs.push_back(CXI->getPointerOperand());
1225  else if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I))
1226  PtrArgs.push_back(RMWI->getPointerOperand());
1227  else if (const auto *Call = dyn_cast<CallBase>(I)) {
1228  // If we know that the call does not access memory, then we'll still
1229  // know that about the inlined clone of this call site, and we don't
1230  // need to add metadata.
1231  if (Call->doesNotAccessMemory())
1232  continue;
1233 
1234  IsFuncCall = true;
1235  if (CalleeAAR) {
1236  MemoryEffects ME = CalleeAAR->getMemoryEffects(Call);
1237 
1238  // We'll retain this knowledge without additional metadata.
1239  if (ME.onlyAccessesInaccessibleMem())
1240  continue;
1241 
1242  if (ME.onlyAccessesArgPointees())
1243  IsArgMemOnlyCall = true;
1244  }
1245 
1246  for (Value *Arg : Call->args()) {
1247  // Only care about pointer arguments. If a noalias argument is
1248  // accessed through a non-pointer argument, it must be captured
1249  // first (e.g. via ptrtoint), and we protect against captures below.
1250  if (!Arg->getType()->isPointerTy())
1251  continue;
1252 
1253  PtrArgs.push_back(Arg);
1254  }
1255  }
1256 
1257  // If we found no pointers, then this instruction is not suitable for
1258  // pairing with an instruction to receive aliasing metadata.
1259  // However, if this is a call, this we might just alias with none of the
1260  // noalias arguments.
1261  if (PtrArgs.empty() && !IsFuncCall)
1262  continue;
1263 
1264  // It is possible that there is only one underlying object, but you
1265  // need to go through several PHIs to see it, and thus could be
1266  // repeated in the Objects list.
1269 
1271  for (const Value *V : PtrArgs) {
1273  getUnderlyingObjects(V, Objects, /* LI = */ nullptr);
1274 
1275  for (const Value *O : Objects)
1276  ObjSet.insert(O);
1277  }
1278 
1279  // Figure out if we're derived from anything that is not a noalias
1280  // argument.
1281  bool RequiresNoCaptureBefore = false, UsesAliasingPtr = false,
1282  UsesUnknownObject = false;
1283  for (const Value *V : ObjSet) {
1284  // Is this value a constant that cannot be derived from any pointer
1285  // value (we need to exclude constant expressions, for example, that
1286  // are formed from arithmetic on global symbols).
1287  bool IsNonPtrConst = isa<ConstantInt>(V) || isa<ConstantFP>(V) ||
1288  isa<ConstantPointerNull>(V) ||
1289  isa<ConstantDataVector>(V) || isa<UndefValue>(V);
1290  if (IsNonPtrConst)
1291  continue;
1292 
1293  // If this is anything other than a noalias argument, then we cannot
1294  // completely describe the aliasing properties using alias.scope
1295  // metadata (and, thus, won't add any).
1296  if (const Argument *A = dyn_cast<Argument>(V)) {
1297  if (!CB.paramHasAttr(A->getArgNo(), Attribute::NoAlias))
1298  UsesAliasingPtr = true;
1299  } else {
1300  UsesAliasingPtr = true;
1301  }
1302 
1303  if (isEscapeSource(V)) {
1304  // An escape source can only alias with a noalias argument if it has
1305  // been captured beforehand.
1306  RequiresNoCaptureBefore = true;
1307  } else if (!isa<Argument>(V) && !isIdentifiedObject(V)) {
1308  // If this is neither an escape source, nor some identified object
1309  // (which cannot directly alias a noalias argument), nor some other
1310  // argument (which, by definition, also cannot alias a noalias
1311  // argument), conservatively do not make any assumptions.
1312  UsesUnknownObject = true;
1313  }
1314  }
1315 
1316  // Nothing we can do if the used underlying object cannot be reliably
1317  // determined.
1318  if (UsesUnknownObject)
1319  continue;
1320 
1321  // A function call can always get captured noalias pointers (via other
1322  // parameters, globals, etc.).
1323  if (IsFuncCall && !IsArgMemOnlyCall)
1324  RequiresNoCaptureBefore = true;
1325 
1326  // First, we want to figure out all of the sets with which we definitely
1327  // don't alias. Iterate over all noalias set, and add those for which:
1328  // 1. The noalias argument is not in the set of objects from which we
1329  // definitely derive.
1330  // 2. The noalias argument has not yet been captured.
1331  // An arbitrary function that might load pointers could see captured
1332  // noalias arguments via other noalias arguments or globals, and so we
1333  // must always check for prior capture.
1334  for (const Argument *A : NoAliasArgs) {
1335  if (ObjSet.contains(A))
1336  continue; // May be based on a noalias argument.
1337 
1338  // It might be tempting to skip the PointerMayBeCapturedBefore check if
1339  // A->hasNoCaptureAttr() is true, but this is incorrect because
1340  // nocapture only guarantees that no copies outlive the function, not
1341  // that the value cannot be locally captured.
1342  if (!RequiresNoCaptureBefore ||
1343  !PointerMayBeCapturedBefore(A, /* ReturnCaptures */ false,
1344  /* StoreCaptures */ false, I, &DT))
1345  NoAliases.push_back(NewScopes[A]);
1346  }
1347 
1348  if (!NoAliases.empty())
1349  NI->setMetadata(LLVMContext::MD_noalias,
1351  NI->getMetadata(LLVMContext::MD_noalias),
1352  MDNode::get(CalledFunc->getContext(), NoAliases)));
1353 
1354  // Next, we want to figure out all of the sets to which we might belong.
1355  // We might belong to a set if the noalias argument is in the set of
1356  // underlying objects. If there is some non-noalias argument in our list
1357  // of underlying objects, then we cannot add a scope because the fact
1358  // that some access does not alias with any set of our noalias arguments
1359  // cannot itself guarantee that it does not alias with this access
1360  // (because there is some pointer of unknown origin involved and the
1361  // other access might also depend on this pointer). We also cannot add
1362  // scopes to arbitrary functions unless we know they don't access any
1363  // non-parameter pointer-values.
1364  bool CanAddScopes = !UsesAliasingPtr;
1365  if (CanAddScopes && IsFuncCall)
1366  CanAddScopes = IsArgMemOnlyCall;
1367 
1368  if (CanAddScopes)
1369  for (const Argument *A : NoAliasArgs) {
1370  if (ObjSet.count(A))
1371  Scopes.push_back(NewScopes[A]);
1372  }
1373 
1374  if (!Scopes.empty())
1375  NI->setMetadata(
1376  LLVMContext::MD_alias_scope,
1377  MDNode::concatenate(NI->getMetadata(LLVMContext::MD_alias_scope),
1378  MDNode::get(CalledFunc->getContext(), Scopes)));
1379  }
1380  }
1381 }
1382 
1384  Instruction *End) {
1385 
1386  assert(Begin->getParent() == End->getParent() &&
1387  "Expected to be in same basic block!");
1389  Begin->getIterator(), End->getIterator(), InlinerAttributeWindow + 1);
1390 }
1391 
1393 
1395  if (!AB.hasAttributes())
1396  return AB;
1397  AttrBuilder Valid(CB.getContext());
1398  // Only allow these white listed attributes to be propagated back to the
1399  // callee. This is because other attributes may only be valid on the call
1400  // itself, i.e. attributes such as signext and zeroext.
1401  if (auto DerefBytes = AB.getDereferenceableBytes())
1402  Valid.addDereferenceableAttr(DerefBytes);
1403  if (auto DerefOrNullBytes = AB.getDereferenceableOrNullBytes())
1404  Valid.addDereferenceableOrNullAttr(DerefOrNullBytes);
1405  if (AB.contains(Attribute::NoAlias))
1406  Valid.addAttribute(Attribute::NoAlias);
1407  if (AB.contains(Attribute::NonNull))
1408  Valid.addAttribute(Attribute::NonNull);
1409  return Valid;
1410 }
1411 
1414  return;
1415 
1417  if (!Valid.hasAttributes())
1418  return;
1419  auto *CalledFunction = CB.getCalledFunction();
1420  auto &Context = CalledFunction->getContext();
1421 
1422  for (auto &BB : *CalledFunction) {
1423  auto *RI = dyn_cast<ReturnInst>(BB.getTerminator());
1424  if (!RI || !isa<CallBase>(RI->getOperand(0)))
1425  continue;
1426  auto *RetVal = cast<CallBase>(RI->getOperand(0));
1427  // Check that the cloned RetVal exists and is a call, otherwise we cannot
1428  // add the attributes on the cloned RetVal. Simplification during inlining
1429  // could have transformed the cloned instruction.
1430  auto *NewRetVal = dyn_cast_or_null<CallBase>(VMap.lookup(RetVal));
1431  if (!NewRetVal)
1432  continue;
1433  // Backward propagation of attributes to the returned value may be incorrect
1434  // if it is control flow dependent.
1435  // Consider:
1436  // @callee {
1437  // %rv = call @foo()
1438  // %rv2 = call @bar()
1439  // if (%rv2 != null)
1440  // return %rv2
1441  // if (%rv == null)
1442  // exit()
1443  // return %rv
1444  // }
1445  // caller() {
1446  // %val = call nonnull @callee()
1447  // }
1448  // Here we cannot add the nonnull attribute on either foo or bar. So, we
1449  // limit the check to both RetVal and RI are in the same basic block and
1450  // there are no throwing/exiting instructions between these instructions.
1451  if (RI->getParent() != RetVal->getParent() ||
1452  MayContainThrowingOrExitingCall(RetVal, RI))
1453  continue;
1454  // Add to the existing attributes of NewRetVal, i.e. the cloned call
1455  // instruction.
1456  // NB! When we have the same attribute already existing on NewRetVal, but
1457  // with a differing value, the AttributeList's merge API honours the already
1458  // existing attribute value (i.e. attributes such as dereferenceable,
1459  // dereferenceable_or_null etc). See AttrBuilder::merge for more details.
1460  AttributeList AL = NewRetVal->getAttributes();
1461  AttributeList NewAL = AL.addRetAttributes(Context, Valid);
1462  NewRetVal->setAttributes(NewAL);
1463  }
1464 }
1465 
1466 /// If the inlined function has non-byval align arguments, then
1467 /// add @llvm.assume-based alignment assumptions to preserve this information.
1470  return;
1471 
1472  AssumptionCache *AC = &IFI.GetAssumptionCache(*CB.getCaller());
1473  auto &DL = CB.getCaller()->getParent()->getDataLayout();
1474 
1475  // To avoid inserting redundant assumptions, we should check for assumptions
1476  // already in the caller. To do this, we might need a DT of the caller.
1477  DominatorTree DT;
1478  bool DTCalculated = false;
1479 
1480  Function *CalledFunc = CB.getCalledFunction();
1481  for (Argument &Arg : CalledFunc->args()) {
1482  unsigned Align = Arg.getType()->isPointerTy() ? Arg.getParamAlignment() : 0;
1483  if (Align && !Arg.hasPassPointeeByValueCopyAttr() && !Arg.hasNUses(0)) {
1484  if (!DTCalculated) {
1485  DT.recalculate(*CB.getCaller());
1486  DTCalculated = true;
1487  }
1488 
1489  // If we can already prove the asserted alignment in the context of the
1490  // caller, then don't bother inserting the assumption.
1491  Value *ArgVal = CB.getArgOperand(Arg.getArgNo());
1492  if (getKnownAlignment(ArgVal, DL, &CB, AC, &DT) >= Align)
1493  continue;
1494 
1495  CallInst *NewAsmp =
1497  AC->registerAssumption(cast<AssumeInst>(NewAsmp));
1498  }
1499  }
1500 }
1501 
1502 /// Once we have cloned code over from a callee into the caller,
1503 /// update the specified callgraph to reflect the changes we made.
1504 /// Note that it's possible that not all code was copied over, so only
1505 /// some edges of the callgraph may remain.
1507  Function::iterator FirstNewBlock,
1508  ValueToValueMapTy &VMap,
1509  InlineFunctionInfo &IFI) {
1510  CallGraph &CG = *IFI.CG;
1511  const Function *Caller = CB.getCaller();
1512  const Function *Callee = CB.getCalledFunction();
1513  CallGraphNode *CalleeNode = CG[Callee];
1514  CallGraphNode *CallerNode = CG[Caller];
1515 
1516  // Since we inlined some uninlined call sites in the callee into the caller,
1517  // add edges from the caller to all of the callees of the callee.
1518  CallGraphNode::iterator I = CalleeNode->begin(), E = CalleeNode->end();
1519 
1520  // Consider the case where CalleeNode == CallerNode.
1522  if (CalleeNode == CallerNode) {
1523  CallCache.assign(I, E);
1524  I = CallCache.begin();
1525  E = CallCache.end();
1526  }
1527 
1528  for (; I != E; ++I) {
1529  // Skip 'refererence' call records.
1530  if (!I->first)
1531  continue;
1532 
1533  const Value *OrigCall = *I->first;
1534 
1535  ValueToValueMapTy::iterator VMI = VMap.find(OrigCall);
1536  // Only copy the edge if the call was inlined!
1537  if (VMI == VMap.end() || VMI->second == nullptr)
1538  continue;
1539 
1540  // If the call was inlined, but then constant folded, there is no edge to
1541  // add. Check for this case.
1542  auto *NewCall = dyn_cast<CallBase>(VMI->second);
1543  if (!NewCall)
1544  continue;
1545 
1546  // We do not treat intrinsic calls like real function calls because we
1547  // expect them to become inline code; do not add an edge for an intrinsic.
1548  if (NewCall->getCalledFunction() &&
1549  NewCall->getCalledFunction()->isIntrinsic())
1550  continue;
1551 
1552  // Remember that this call site got inlined for the client of
1553  // InlineFunction.
1554  IFI.InlinedCalls.push_back(NewCall);
1555 
1556  // It's possible that inlining the callsite will cause it to go from an
1557  // indirect to a direct call by resolving a function pointer. If this
1558  // happens, set the callee of the new call site to a more precise
1559  // destination. This can also happen if the call graph node of the caller
1560  // was just unnecessarily imprecise.
1561  if (!I->second->getFunction())
1562  if (Function *F = NewCall->getCalledFunction()) {
1563  // Indirect call site resolved to direct call.
1564  CallerNode->addCalledFunction(NewCall, CG[F]);
1565 
1566  continue;
1567  }
1568 
1569  CallerNode->addCalledFunction(NewCall, I->second);
1570  }
1571 
1572  // Update the call graph by deleting the edge from Callee to Caller. We must
1573  // do this after the loop above in case Caller and Callee are the same.
1574  CallerNode->removeCallEdgeFor(*cast<CallBase>(&CB));
1575 }
1576 
1577 static void HandleByValArgumentInit(Type *ByValType, Value *Dst, Value *Src,
1578  Module *M, BasicBlock *InsertBlock,
1579  InlineFunctionInfo &IFI) {
1580  IRBuilder<> Builder(InsertBlock, InsertBlock->begin());
1581 
1582  Value *Size =
1583  Builder.getInt64(M->getDataLayout().getTypeStoreSize(ByValType));
1584 
1585  // Always generate a memcpy of alignment 1 here because we don't know
1586  // the alignment of the src pointer. Other optimizations can infer
1587  // better alignment.
1588  Builder.CreateMemCpy(Dst, /*DstAlign*/ Align(1), Src,
1589  /*SrcAlign*/ Align(1), Size);
1590 }
1591 
1592 /// When inlining a call site that has a byval argument,
1593 /// we have to make the implicit memcpy explicit by adding it.
1594 static Value *HandleByValArgument(Type *ByValType, Value *Arg,
1595  Instruction *TheCall,
1596  const Function *CalledFunc,
1597  InlineFunctionInfo &IFI,
1598  unsigned ByValAlignment) {
1599  assert(cast<PointerType>(Arg->getType())
1600  ->isOpaqueOrPointeeTypeMatches(ByValType));
1601  Function *Caller = TheCall->getFunction();
1602  const DataLayout &DL = Caller->getParent()->getDataLayout();
1603 
1604  // If the called function is readonly, then it could not mutate the caller's
1605  // copy of the byval'd memory. In this case, it is safe to elide the copy and
1606  // temporary.
1607  if (CalledFunc->onlyReadsMemory()) {
1608  // If the byval argument has a specified alignment that is greater than the
1609  // passed in pointer, then we either have to round up the input pointer or
1610  // give up on this transformation.
1611  if (ByValAlignment <= 1) // 0 = unspecified, 1 = no particular alignment.
1612  return Arg;
1613 
1614  AssumptionCache *AC =
1615  IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;
1616 
1617  // If the pointer is already known to be sufficiently aligned, or if we can
1618  // round it up to a larger alignment, then we don't need a temporary.
1619  if (getOrEnforceKnownAlignment(Arg, Align(ByValAlignment), DL, TheCall,
1620  AC) >= ByValAlignment)
1621  return Arg;
1622 
1623  // Otherwise, we have to make a memcpy to get a safe alignment. This is bad
1624  // for code quality, but rarely happens and is required for correctness.
1625  }
1626 
1627  // Create the alloca. If we have DataLayout, use nice alignment.
1628  Align Alignment(DL.getPrefTypeAlignment(ByValType));
1629 
1630  // If the byval had an alignment specified, we *must* use at least that
1631  // alignment, as it is required by the byval argument (and uses of the
1632  // pointer inside the callee).
1633  if (ByValAlignment > 0)
1634  Alignment = std::max(Alignment, Align(ByValAlignment));
1635 
1636  Value *NewAlloca =
1637  new AllocaInst(ByValType, DL.getAllocaAddrSpace(), nullptr, Alignment,
1638  Arg->getName(), &*Caller->begin()->begin());
1639  IFI.StaticAllocas.push_back(cast<AllocaInst>(NewAlloca));
1640 
1641  // Uses of the argument in the function should use our new alloca
1642  // instead.
1643  return NewAlloca;
1644 }
1645 
1646 // Check whether this Value is used by a lifetime intrinsic.
1648  for (User *U : V->users())
1649  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U))
1650  if (II->isLifetimeStartOrEnd())
1651  return true;
1652  return false;
1653 }
1654 
1655 // Check whether the given alloca already has
1656 // lifetime.start or lifetime.end intrinsics.
1657 static bool hasLifetimeMarkers(AllocaInst *AI) {
1658  Type *Ty = AI->getType();
1659  Type *Int8PtrTy = Type::getInt8PtrTy(Ty->getContext(),
1660  Ty->getPointerAddressSpace());
1661  if (Ty == Int8PtrTy)
1662  return isUsedByLifetimeMarker(AI);
1663 
1664  // Do a scan to find all the casts to i8*.
1665  for (User *U : AI->users()) {
1666  if (U->getType() != Int8PtrTy) continue;
1667  if (U->stripPointerCasts() != AI) continue;
1668  if (isUsedByLifetimeMarker(U))
1669  return true;
1670  }
1671  return false;
1672 }
1673 
1674 /// Return the result of AI->isStaticAlloca() if AI were moved to the entry
1675 /// block. Allocas used in inalloca calls and allocas of dynamic array size
1676 /// cannot be static.
1677 static bool allocaWouldBeStaticInEntry(const AllocaInst *AI ) {
1678  return isa<Constant>(AI->getArraySize()) && !AI->isUsedWithInAlloca();
1679 }
1680 
1681 /// Returns a DebugLoc for a new DILocation which is a clone of \p OrigDL
1682 /// inlined at \p InlinedAt. \p IANodes is an inlined-at cache.
1683 static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
1684  LLVMContext &Ctx,
1686  auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
1687  return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
1688  OrigDL.getScope(), IA);
1689 }
1690 
1691 /// Update inlined instructions' line numbers to
1692 /// to encode location where these instructions are inlined.
1694  Instruction *TheCall, bool CalleeHasDebugInfo) {
1695  const DebugLoc &TheCallDL = TheCall->getDebugLoc();
1696  if (!TheCallDL)
1697  return;
1698 
1699  auto &Ctx = Fn->getContext();
1700  DILocation *InlinedAtNode = TheCallDL;
1701 
1702  // Create a unique call site, not to be confused with any other call from the
1703  // same location.
1704  InlinedAtNode = DILocation::getDistinct(
1705  Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(),
1706  InlinedAtNode->getScope(), InlinedAtNode->getInlinedAt());
1707 
1708  // Cache the inlined-at nodes as they're built so they are reused, without
1709  // this every instruction's inlined-at chain would become distinct from each
1710  // other.
1712 
1713  // Check if we are not generating inline line tables and want to use
1714  // the call site location instead.
1715  bool NoInlineLineTables = Fn->hasFnAttribute("no-inline-line-tables");
1716 
1717  for (; FI != Fn->end(); ++FI) {
1718  for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
1719  BI != BE; ++BI) {
1720  // Loop metadata needs to be updated so that the start and end locs
1721  // reference inlined-at locations.
1722  auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode,
1723  &IANodes](Metadata *MD) -> Metadata * {
1724  if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
1725  return inlineDebugLoc(Loc, InlinedAtNode, Ctx, IANodes).get();
1726  return MD;
1727  };
1728  updateLoopMetadataDebugLocations(*BI, updateLoopInfoLoc);
1729 
1730  if (!NoInlineLineTables)
1731  if (DebugLoc DL = BI->getDebugLoc()) {
1732  DebugLoc IDL =
1733  inlineDebugLoc(DL, InlinedAtNode, BI->getContext(), IANodes);
1734  BI->setDebugLoc(IDL);
1735  continue;
1736  }
1737 
1738  if (CalleeHasDebugInfo && !NoInlineLineTables)
1739  continue;
1740 
1741  // If the inlined instruction has no line number, or if inline info
1742  // is not being generated, make it look as if it originates from the call
1743  // location. This is important for ((__always_inline, __nodebug__))
1744  // functions which must use caller location for all instructions in their
1745  // function body.
1746 
1747  // Don't update static allocas, as they may get moved later.
1748  if (auto *AI = dyn_cast<AllocaInst>(BI))
1750  continue;
1751 
1752  BI->setDebugLoc(TheCallDL);
1753  }
1754 
1755  // Remove debug info intrinsics if we're not keeping inline info.
1756  if (NoInlineLineTables) {
1757  BasicBlock::iterator BI = FI->begin();
1758  while (BI != FI->end()) {
1759  if (isa<DbgInfoIntrinsic>(BI)) {
1760  BI = BI->eraseFromParent();
1761  continue;
1762  }
1763  ++BI;
1764  }
1765  }
1766 
1767  }
1768 }
1769 
1770 #undef DEBUG_TYPE
1771 #define DEBUG_TYPE "assignment-tracking"
1772 /// Find Alloca and linked DbgAssignIntrinsic for locals escaped by \p CB.
1774  const CallBase &CB) {
1775  at::StorageToVarsMap EscapedLocals;
1777 
1778  LLVM_DEBUG(
1779  errs() << "# Finding caller local variables escaped by callee\n");
1780  for (const Value *Arg : CB.args()) {
1781  LLVM_DEBUG(errs() << "INSPECT: " << *Arg << "\n");
1782  if (!Arg->getType()->isPointerTy()) {
1783  LLVM_DEBUG(errs() << " | SKIP: Not a pointer\n");
1784  continue;
1785  }
1786 
1787  const Instruction *I = dyn_cast<Instruction>(Arg);
1788  if (!I) {
1789  LLVM_DEBUG(errs() << " | SKIP: Not result of instruction\n");
1790  continue;
1791  }
1792 
1793  // Walk back to the base storage.
1794  assert(Arg->getType()->isPtrOrPtrVectorTy());
1795  APInt TmpOffset(DL.getIndexTypeSizeInBits(Arg->getType()), 0, false);
1796  const AllocaInst *Base = dyn_cast<AllocaInst>(
1797  Arg->stripAndAccumulateConstantOffsets(DL, TmpOffset, true));
1798  if (!Base) {
1799  LLVM_DEBUG(errs() << " | SKIP: Couldn't walk back to base storage\n");
1800  continue;
1801  }
1802 
1803  assert(Base);
1804  LLVM_DEBUG(errs() << " | BASE: " << *Base << "\n");
1805  // We only need to process each base address once - skip any duplicates.
1806  if (!SeenBases.insert(Base).second)
1807  continue;
1808 
1809  // Find all local variables associated with the backing storage.
1810  for (auto *DAI : at::getAssignmentMarkers(Base)) {
1811  // Skip variables from inlined functions - they are not local variables.
1812  if (DAI->getDebugLoc().getInlinedAt())
1813  continue;
1814  LLVM_DEBUG(errs() << " > DEF : " << *DAI << "\n");
1815  EscapedLocals[Base].insert(at::VarRecord(DAI));
1816  }
1817  }
1818  return EscapedLocals;
1819 }
1820 
1822  const CallBase &CB) {
1823  LLVM_DEBUG(errs() << "trackInlinedStores into "
1824  << Start->getParent()->getName() << " from "
1825  << CB.getCalledFunction()->getName() << "\n");
1826  std::unique_ptr<DataLayout> DL = std::make_unique<DataLayout>(CB.getModule());
1827  at::trackAssignments(Start, End, collectEscapedLocals(*DL, CB), *DL);
1828 }
1829 
1830 /// Update inlined instructions' DIAssignID metadata. We need to do this
1831 /// otherwise a function inlined more than once into the same function
1832 /// will cause DIAssignID to be shared by many instructions.
1834  // Map {Old, New} metadata. Not used directly - use GetNewID.
1836  auto GetNewID = [&Map](Metadata *Old) {
1837  DIAssignID *OldID = cast<DIAssignID>(Old);
1838  if (DIAssignID *NewID = Map.lookup(OldID))
1839  return NewID;
1840  DIAssignID *NewID = DIAssignID::getDistinct(OldID->getContext());
1841  Map[OldID] = NewID;
1842  return NewID;
1843  };
1844  // Loop over all the inlined instructions. If we find a DIAssignID
1845  // attachment or use, replace it with a new version.
1846  for (auto BBI = Start; BBI != End; ++BBI) {
1847  for (Instruction &I : *BBI) {
1848  if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID))
1849  I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID));
1850  else if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I))
1851  DAI->setAssignId(GetNewID(DAI->getAssignID()));
1852  }
1853  }
1854 }
1855 #undef DEBUG_TYPE
1856 #define DEBUG_TYPE "inline-function"
1857 
1858 /// Update the block frequencies of the caller after a callee has been inlined.
1859 ///
1860 /// Each block cloned into the caller has its block frequency scaled by the
1861 /// ratio of CallSiteFreq/CalleeEntryFreq. This ensures that the cloned copy of
1862 /// callee's entry block gets the same frequency as the callsite block and the
1863 /// relative frequencies of all cloned blocks remain the same after cloning.
1864 static void updateCallerBFI(BasicBlock *CallSiteBlock,
1865  const ValueToValueMapTy &VMap,
1866  BlockFrequencyInfo *CallerBFI,
1867  BlockFrequencyInfo *CalleeBFI,
1868  const BasicBlock &CalleeEntryBlock) {
1870  for (auto Entry : VMap) {
1871  if (!isa<BasicBlock>(Entry.first) || !Entry.second)
1872  continue;
1873  auto *OrigBB = cast<BasicBlock>(Entry.first);
1874  auto *ClonedBB = cast<BasicBlock>(Entry.second);
1875  uint64_t Freq = CalleeBFI->getBlockFreq(OrigBB).getFrequency();
1876  if (!ClonedBBs.insert(ClonedBB).second) {
1877  // Multiple blocks in the callee might get mapped to one cloned block in
1878  // the caller since we prune the callee as we clone it. When that happens,
1879  // we want to use the maximum among the original blocks' frequencies.
1880  uint64_t NewFreq = CallerBFI->getBlockFreq(ClonedBB).getFrequency();
1881  if (NewFreq > Freq)
1882  Freq = NewFreq;
1883  }
1884  CallerBFI->setBlockFreq(ClonedBB, Freq);
1885  }
1886  BasicBlock *EntryClone = cast<BasicBlock>(VMap.lookup(&CalleeEntryBlock));
1887  CallerBFI->setBlockFreqAndScale(
1888  EntryClone, CallerBFI->getBlockFreq(CallSiteBlock).getFrequency(),
1889  ClonedBBs);
1890 }
1891 
1892 /// Update the branch metadata for cloned call instructions.
1893 static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap,
1894  const ProfileCount &CalleeEntryCount,
1895  const CallBase &TheCall, ProfileSummaryInfo *PSI,
1896  BlockFrequencyInfo *CallerBFI) {
1897  if (CalleeEntryCount.isSynthetic() || CalleeEntryCount.getCount() < 1)
1898  return;
1899  auto CallSiteCount = PSI ? PSI->getProfileCount(TheCall, CallerBFI) : None;
1900  int64_t CallCount =
1901  std::min(CallSiteCount.value_or(0), CalleeEntryCount.getCount());
1902  updateProfileCallee(Callee, -CallCount, &VMap);
1903 }
1904 
1906  Function *Callee, int64_t EntryDelta,
1908  auto CalleeCount = Callee->getEntryCount();
1909  if (!CalleeCount)
1910  return;
1911 
1912  const uint64_t PriorEntryCount = CalleeCount->getCount();
1913 
1914  // Since CallSiteCount is an estimate, it could exceed the original callee
1915  // count and has to be set to 0 so guard against underflow.
1916  const uint64_t NewEntryCount =
1917  (EntryDelta < 0 && static_cast<uint64_t>(-EntryDelta) > PriorEntryCount)
1918  ? 0
1919  : PriorEntryCount + EntryDelta;
1920 
1921  // During inlining ?
1922  if (VMap) {
1923  uint64_t CloneEntryCount = PriorEntryCount - NewEntryCount;
1924  for (auto Entry : *VMap)
1925  if (isa<CallInst>(Entry.first))
1926  if (auto *CI = dyn_cast_or_null<CallInst>(Entry.second))
1927  CI->updateProfWeight(CloneEntryCount, PriorEntryCount);
1928  }
1929 
1930  if (EntryDelta) {
1931  Callee->setEntryCount(NewEntryCount);
1932 
1933  for (BasicBlock &BB : *Callee)
1934  // No need to update the callsite if it is pruned during inlining.
1935  if (!VMap || VMap->count(&BB))
1936  for (Instruction &I : BB)
1937  if (CallInst *CI = dyn_cast<CallInst>(&I))
1938  CI->updateProfWeight(NewEntryCount, PriorEntryCount);
1939  }
1940 }
1941 
1942 /// An operand bundle "clang.arc.attachedcall" on a call indicates the call
1943 /// result is implicitly consumed by a call to retainRV or claimRV immediately
1944 /// after the call. This function inlines the retainRV/claimRV calls.
1945 ///
1946 /// There are three cases to consider:
1947 ///
1948 /// 1. If there is a call to autoreleaseRV that takes a pointer to the returned
1949 /// object in the callee return block, the autoreleaseRV call and the
1950 /// retainRV/claimRV call in the caller cancel out. If the call in the caller
1951 /// is a claimRV call, a call to objc_release is emitted.
1952 ///
1953 /// 2. If there is a call in the callee return block that doesn't have operand
1954 /// bundle "clang.arc.attachedcall", the operand bundle on the original call
1955 /// is transferred to the call in the callee.
1956 ///
1957 /// 3. Otherwise, a call to objc_retain is inserted if the call in the caller is
1958 /// a retainRV call.
1959 static void
1961  const SmallVectorImpl<ReturnInst *> &Returns) {
1962  Module *Mod = CB.getModule();
1963  assert(objcarc::isRetainOrClaimRV(RVCallKind) && "unexpected ARC function");
1964  bool IsRetainRV = RVCallKind == objcarc::ARCInstKind::RetainRV,
1965  IsUnsafeClaimRV = !IsRetainRV;
1966 
1967  for (auto *RI : Returns) {
1968  Value *RetOpnd = objcarc::GetRCIdentityRoot(RI->getOperand(0));
1969  bool InsertRetainCall = IsRetainRV;
1971 
1972  // Walk backwards through the basic block looking for either a matching
1973  // autoreleaseRV call or an unannotated call.
1974  auto InstRange = llvm::make_range(++(RI->getIterator().getReverse()),
1975  RI->getParent()->rend());
1976  for (Instruction &I : llvm::make_early_inc_range(InstRange)) {
1977  // Ignore casts.
1978  if (isa<CastInst>(I))
1979  continue;
1980 
1981  if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
1982  if (II->getIntrinsicID() != Intrinsic::objc_autoreleaseReturnValue ||
1983  !II->hasNUses(0) ||
1984  objcarc::GetRCIdentityRoot(II->getOperand(0)) != RetOpnd)
1985  break;
1986 
1987  // If we've found a matching authoreleaseRV call:
1988  // - If claimRV is attached to the call, insert a call to objc_release
1989  // and erase the autoreleaseRV call.
1990  // - If retainRV is attached to the call, just erase the autoreleaseRV
1991  // call.
1992  if (IsUnsafeClaimRV) {
1993  Builder.SetInsertPoint(II);
1994  Function *IFn =
1995  Intrinsic::getDeclaration(Mod, Intrinsic::objc_release);
1996  Value *BC = Builder.CreateBitCast(RetOpnd, IFn->getArg(0)->getType());
1997  Builder.CreateCall(IFn, BC, "");
1998  }
1999  II->eraseFromParent();
2000  InsertRetainCall = false;
2001  break;
2002  }
2003 
2004  auto *CI = dyn_cast<CallInst>(&I);
2005 
2006  if (!CI)
2007  break;
2008 
2009  if (objcarc::GetRCIdentityRoot(CI) != RetOpnd ||
2011  break;
2012 
2013  // If we've found an unannotated call that defines RetOpnd, add a
2014  // "clang.arc.attachedcall" operand bundle.
2015  Value *BundleArgs[] = {*objcarc::getAttachedARCFunction(&CB)};
2016  OperandBundleDef OB("clang.arc.attachedcall", BundleArgs);
2017  auto *NewCall = CallBase::addOperandBundle(
2019  NewCall->copyMetadata(*CI);
2020  CI->replaceAllUsesWith(NewCall);
2021  CI->eraseFromParent();
2022  InsertRetainCall = false;
2023  break;
2024  }
2025 
2026  if (InsertRetainCall) {
2027  // The retainRV is attached to the call and we've failed to find a
2028  // matching autoreleaseRV or an annotated call in the callee. Emit a call
2029  // to objc_retain.
2030  Builder.SetInsertPoint(RI);
2031  Function *IFn = Intrinsic::getDeclaration(Mod, Intrinsic::objc_retain);
2032  Value *BC = Builder.CreateBitCast(RetOpnd, IFn->getArg(0)->getType());
2033  Builder.CreateCall(IFn, BC, "");
2034  }
2035  }
2036 }
2037 
2038 /// This function inlines the called function into the basic block of the
2039 /// caller. This returns false if it is not possible to inline this call.
2040 /// The program is still in a well defined state if this occurs though.
2041 ///
2042 /// Note that this only does one level of inlining. For example, if the
2043 /// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
2044 /// exists in the instruction stream. Similarly this will inline a recursive
2045 /// function by one level.
2047  bool MergeAttributes,
2048  AAResults *CalleeAAR,
2049  bool InsertLifetime,
2050  Function *ForwardVarArgsTo) {
2051  assert(CB.getParent() && CB.getFunction() && "Instruction not in function!");
2052 
2053  // FIXME: we don't inline callbr yet.
2054  if (isa<CallBrInst>(CB))
2055  return InlineResult::failure("We don't inline callbr yet.");
2056 
2057  // If IFI has any state in it, zap it before we fill it in.
2058  IFI.reset();
2059 
2060  Function *CalledFunc = CB.getCalledFunction();
2061  if (!CalledFunc || // Can't inline external function or indirect
2062  CalledFunc->isDeclaration()) // call!
2063  return InlineResult::failure("external or indirect");
2064 
2065  // The inliner does not know how to inline through calls with operand bundles
2066  // in general ...
2067  if (CB.hasOperandBundles()) {
2068  for (int i = 0, e = CB.getNumOperandBundles(); i != e; ++i) {
2070  // ... but it knows how to inline through "deopt" operand bundles ...
2071  if (Tag == LLVMContext::OB_deopt)
2072  continue;
2073  // ... and "funclet" operand bundles.
2075  continue;
2077  continue;
2078  if (Tag == LLVMContext::OB_kcfi)
2079  continue;
2080 
2081  return InlineResult::failure("unsupported operand bundle");
2082  }
2083  }
2084 
2085  // If the call to the callee cannot throw, set the 'nounwind' flag on any
2086  // calls that we inline.
2087  bool MarkNoUnwind = CB.doesNotThrow();
2088 
2089  BasicBlock *OrigBB = CB.getParent();
2090  Function *Caller = OrigBB->getParent();
2091 
2092  // Do not inline strictfp function into non-strictfp one. It would require
2093  // conversion of all FP operations in host function to constrained intrinsics.
2094  if (CalledFunc->getAttributes().hasFnAttr(Attribute::StrictFP) &&
2095  !Caller->getAttributes().hasFnAttr(Attribute::StrictFP)) {
2096  return InlineResult::failure("incompatible strictfp attributes");
2097  }
2098 
2099  // GC poses two hazards to inlining, which only occur when the callee has GC:
2100  // 1. If the caller has no GC, then the callee's GC must be propagated to the
2101  // caller.
2102  // 2. If the caller has a differing GC, it is invalid to inline.
2103  if (CalledFunc->hasGC()) {
2104  if (!Caller->hasGC())
2105  Caller->setGC(CalledFunc->getGC());
2106  else if (CalledFunc->getGC() != Caller->getGC())
2107  return InlineResult::failure("incompatible GC");
2108  }
2109 
2110  // Get the personality function from the callee if it contains a landing pad.
2111  Constant *CalledPersonality =
2112  CalledFunc->hasPersonalityFn()
2113  ? CalledFunc->getPersonalityFn()->stripPointerCasts()
2114  : nullptr;
2115 
2116  // Find the personality function used by the landing pads of the caller. If it
2117  // exists, then check to see that it matches the personality function used in
2118  // the callee.
2119  Constant *CallerPersonality =
2120  Caller->hasPersonalityFn()
2121  ? Caller->getPersonalityFn()->stripPointerCasts()
2122  : nullptr;
2123  if (CalledPersonality) {
2124  if (!CallerPersonality)
2125  Caller->setPersonalityFn(CalledPersonality);
2126  // If the personality functions match, then we can perform the
2127  // inlining. Otherwise, we can't inline.
2128  // TODO: This isn't 100% true. Some personality functions are proper
2129  // supersets of others and can be used in place of the other.
2130  else if (CalledPersonality != CallerPersonality)
2131  return InlineResult::failure("incompatible personality");
2132  }
2133 
2134  // We need to figure out which funclet the callsite was in so that we may
2135  // properly nest the callee.
2136  Instruction *CallSiteEHPad = nullptr;
2137  if (CallerPersonality) {
2138  EHPersonality Personality = classifyEHPersonality(CallerPersonality);
2139  if (isScopedEHPersonality(Personality)) {
2140  Optional<OperandBundleUse> ParentFunclet =
2142  if (ParentFunclet)
2143  CallSiteEHPad = cast<FuncletPadInst>(ParentFunclet->Inputs.front());
2144 
2145  // OK, the inlining site is legal. What about the target function?
2146 
2147  if (CallSiteEHPad) {
2148  if (Personality == EHPersonality::MSVC_CXX) {
2149  // The MSVC personality cannot tolerate catches getting inlined into
2150  // cleanup funclets.
2151  if (isa<CleanupPadInst>(CallSiteEHPad)) {
2152  // Ok, the call site is within a cleanuppad. Let's check the callee
2153  // for catchpads.
2154  for (const BasicBlock &CalledBB : *CalledFunc) {
2155  if (isa<CatchSwitchInst>(CalledBB.getFirstNonPHI()))
2156  return InlineResult::failure("catch in cleanup funclet");
2157  }
2158  }
2159  } else if (isAsynchronousEHPersonality(Personality)) {
2160  // SEH is even less tolerant, there may not be any sort of exceptional
2161  // funclet in the callee.
2162  for (const BasicBlock &CalledBB : *CalledFunc) {
2163  if (CalledBB.isEHPad())
2164  return InlineResult::failure("SEH in cleanup funclet");
2165  }
2166  }
2167  }
2168  }
2169  }
2170 
2171  // Determine if we are dealing with a call in an EHPad which does not unwind
2172  // to caller.
2173  bool EHPadForCallUnwindsLocally = false;
2174  if (CallSiteEHPad && isa<CallInst>(CB)) {
2175  UnwindDestMemoTy FuncletUnwindMap;
2176  Value *CallSiteUnwindDestToken =
2177  getUnwindDestToken(CallSiteEHPad, FuncletUnwindMap);
2178 
2179  EHPadForCallUnwindsLocally =
2180  CallSiteUnwindDestToken &&
2181  !isa<ConstantTokenNone>(CallSiteUnwindDestToken);
2182  }
2183 
2184  // Get an iterator to the last basic block in the function, which will have
2185  // the new function inlined after it.
2186  Function::iterator LastBlock = --Caller->end();
2187 
2188  // Make sure to capture all of the return instructions from the cloned
2189  // function.
2191  ClonedCodeInfo InlinedFunctionInfo;
2192  Function::iterator FirstNewBlock;
2193 
2194  { // Scope to destroy VMap after cloning.
2195  ValueToValueMapTy VMap;
2196  struct ByValInit {
2197  Value *Dst;
2198  Value *Src;
2199  Type *Ty;
2200  };
2201  // Keep a list of pair (dst, src) to emit byval initializations.
2202  SmallVector<ByValInit, 4> ByValInits;
2203 
2204  // When inlining a function that contains noalias scope metadata,
2205  // this metadata needs to be cloned so that the inlined blocks
2206  // have different "unique scopes" at every call site.
2207  // Track the metadata that must be cloned. Do this before other changes to
2208  // the function, so that we do not get in trouble when inlining caller ==
2209  // callee.
2210  ScopedAliasMetadataDeepCloner SAMetadataCloner(CB.getCalledFunction());
2211 
2212  auto &DL = Caller->getParent()->getDataLayout();
2213 
2214  // Calculate the vector of arguments to pass into the function cloner, which
2215  // matches up the formal to the actual argument values.
2216  auto AI = CB.arg_begin();
2217  unsigned ArgNo = 0;
2218  for (Function::arg_iterator I = CalledFunc->arg_begin(),
2219  E = CalledFunc->arg_end(); I != E; ++I, ++AI, ++ArgNo) {
2220  Value *ActualArg = *AI;
2221 
2222  // When byval arguments actually inlined, we need to make the copy implied
2223  // by them explicit. However, we don't do this if the callee is readonly
2224  // or readnone, because the copy would be unneeded: the callee doesn't
2225  // modify the struct.
2226  if (CB.isByValArgument(ArgNo)) {
2227  ActualArg = HandleByValArgument(CB.getParamByValType(ArgNo), ActualArg,
2228  &CB, CalledFunc, IFI,
2229  CalledFunc->getParamAlignment(ArgNo));
2230  if (ActualArg != *AI)
2231  ByValInits.push_back(
2232  {ActualArg, (Value *)*AI, CB.getParamByValType(ArgNo)});
2233  }
2234 
2235  VMap[&*I] = ActualArg;
2236  }
2237 
2238  // TODO: Remove this when users have been updated to the assume bundles.
2239  // Add alignment assumptions if necessary. We do this before the inlined
2240  // instructions are actually cloned into the caller so that we can easily
2241  // check what will be known at the start of the inlined code.
2242  AddAlignmentAssumptions(CB, IFI);
2243 
2244  AssumptionCache *AC =
2245  IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;
2246 
2247  /// Preserve all attributes on of the call and its parameters.
2248  salvageKnowledge(&CB, AC);
2249 
2250  // We want the inliner to prune the code as it copies. We would LOVE to
2251  // have no dead or constant instructions leftover after inlining occurs
2252  // (which can happen, e.g., because an argument was constant), but we'll be
2253  // happy with whatever the cloner can do.
2254  CloneAndPruneFunctionInto(Caller, CalledFunc, VMap,
2255  /*ModuleLevelChanges=*/false, Returns, ".i",
2256  &InlinedFunctionInfo);
2257  // Remember the first block that is newly cloned over.
2258  FirstNewBlock = LastBlock; ++FirstNewBlock;
2259 
2260  // Insert retainRV/clainRV runtime calls.
2262  if (RVCallKind != objcarc::ARCInstKind::None)
2263  inlineRetainOrClaimRVCalls(CB, RVCallKind, Returns);
2264 
2265  // Updated caller/callee profiles only when requested. For sample loader
2266  // inlining, the context-sensitive inlinee profile doesn't need to be
2267  // subtracted from callee profile, and the inlined clone also doesn't need
2268  // to be scaled based on call site count.
2269  if (IFI.UpdateProfile) {
2270  if (IFI.CallerBFI != nullptr && IFI.CalleeBFI != nullptr)
2271  // Update the BFI of blocks cloned into the caller.
2272  updateCallerBFI(OrigBB, VMap, IFI.CallerBFI, IFI.CalleeBFI,
2273  CalledFunc->front());
2274 
2275  if (auto Profile = CalledFunc->getEntryCount())
2276  updateCallProfile(CalledFunc, VMap, *Profile, CB, IFI.PSI,
2277  IFI.CallerBFI);
2278  }
2279 
2280  // Inject byval arguments initialization.
2281  for (ByValInit &Init : ByValInits)
2282  HandleByValArgumentInit(Init.Ty, Init.Dst, Init.Src, Caller->getParent(),
2283  &*FirstNewBlock, IFI);
2284 
2285  Optional<OperandBundleUse> ParentDeopt =
2287  if (ParentDeopt) {
2289 
2290  for (auto &VH : InlinedFunctionInfo.OperandBundleCallSites) {
2291  CallBase *ICS = dyn_cast_or_null<CallBase>(VH);
2292  if (!ICS)
2293  continue; // instruction was DCE'd or RAUW'ed to undef
2294 
2295  OpDefs.clear();
2296 
2297  OpDefs.reserve(ICS->getNumOperandBundles());
2298 
2299  for (unsigned COBi = 0, COBe = ICS->getNumOperandBundles(); COBi < COBe;
2300  ++COBi) {
2301  auto ChildOB = ICS->getOperandBundleAt(COBi);
2302  if (ChildOB.getTagID() != LLVMContext::OB_deopt) {
2303  // If the inlined call has other operand bundles, let them be
2304  OpDefs.emplace_back(ChildOB);
2305  continue;
2306  }
2307 
2308  // It may be useful to separate this logic (of handling operand
2309  // bundles) out to a separate "policy" component if this gets crowded.
2310  // Prepend the parent's deoptimization continuation to the newly
2311  // inlined call's deoptimization continuation.
2312  std::vector<Value *> MergedDeoptArgs;
2313  MergedDeoptArgs.reserve(ParentDeopt->Inputs.size() +
2314  ChildOB.Inputs.size());
2315 
2316  llvm::append_range(MergedDeoptArgs, ParentDeopt->Inputs);
2317  llvm::append_range(MergedDeoptArgs, ChildOB.Inputs);
2318 
2319  OpDefs.emplace_back("deopt", std::move(MergedDeoptArgs));
2320  }
2321 
2322  Instruction *NewI = CallBase::Create(ICS, OpDefs, ICS);
2323 
2324  // Note: the RAUW does the appropriate fixup in VMap, so we need to do
2325  // this even if the call returns void.
2326  ICS->replaceAllUsesWith(NewI);
2327 
2328  VH = nullptr;
2329  ICS->eraseFromParent();
2330  }
2331  }
2332 
2333  // Update the callgraph if requested.
2334  if (IFI.CG)
2335  UpdateCallGraphAfterInlining(CB, FirstNewBlock, VMap, IFI);
2336 
2337  // For 'nodebug' functions, the associated DISubprogram is always null.
2338  // Conservatively avoid propagating the callsite debug location to
2339  // instructions inlined from a function whose DISubprogram is not null.
2340  fixupLineNumbers(Caller, FirstNewBlock, &CB,
2341  CalledFunc->getSubprogram() != nullptr);
2342 
2344  // Interpret inlined stores to caller-local variables as assignments.
2345  trackInlinedStores(FirstNewBlock, Caller->end(), CB);
2346 
2347  // Update DIAssignID metadata attachments and uses so that they are
2348  // unique to this inlined instance.
2349  fixupAssignments(FirstNewBlock, Caller->end());
2350  }
2351 
2352  // Now clone the inlined noalias scope metadata.
2353  SAMetadataCloner.clone();
2354  SAMetadataCloner.remap(FirstNewBlock, Caller->end());
2355 
2356  // Add noalias metadata if necessary.
2357  AddAliasScopeMetadata(CB, VMap, DL, CalleeAAR, InlinedFunctionInfo);
2358 
2359  // Clone return attributes on the callsite into the calls within the inlined
2360  // function which feed into its return value.
2361  AddReturnAttributes(CB, VMap);
2362 
2363  propagateMemProfMetadata(CalledFunc, CB,
2364  InlinedFunctionInfo.ContainsMemProfMetadata, VMap);
2365 
2366  // Propagate metadata on the callsite if necessary.
2367  PropagateCallSiteMetadata(CB, FirstNewBlock, Caller->end());
2368 
2369  // Register any cloned assumptions.
2370  if (IFI.GetAssumptionCache)
2371  for (BasicBlock &NewBlock :
2372  make_range(FirstNewBlock->getIterator(), Caller->end()))
2373  for (Instruction &I : NewBlock)
2374  if (auto *II = dyn_cast<AssumeInst>(&I))
2375  IFI.GetAssumptionCache(*Caller).registerAssumption(II);
2376  }
2377 
2378  // If there are any alloca instructions in the block that used to be the entry
2379  // block for the callee, move them to the entry block of the caller. First
2380  // calculate which instruction they should be inserted before. We insert the
2381  // instructions at the end of the current alloca list.
2382  {
2383  BasicBlock::iterator InsertPoint = Caller->begin()->begin();
2384  for (BasicBlock::iterator I = FirstNewBlock->begin(),
2385  E = FirstNewBlock->end(); I != E; ) {
2386  AllocaInst *AI = dyn_cast<AllocaInst>(I++);
2387  if (!AI) continue;
2388 
2389  // If the alloca is now dead, remove it. This often occurs due to code
2390  // specialization.
2391  if (AI->use_empty()) {
2392  AI->eraseFromParent();
2393  continue;
2394  }
2395 
2396  if (!allocaWouldBeStaticInEntry(AI))
2397  continue;
2398 
2399  // Keep track of the static allocas that we inline into the caller.
2400  IFI.StaticAllocas.push_back(AI);
2401 
2402  // Scan for the block of allocas that we can move over, and move them
2403  // all at once.
2404  while (isa<AllocaInst>(I) &&
2405  !cast<AllocaInst>(I)->use_empty() &&
2406  allocaWouldBeStaticInEntry(cast<AllocaInst>(I))) {
2407  IFI.StaticAllocas.push_back(cast<AllocaInst>(I));
2408  ++I;
2409  }
2410 
2411  // Transfer all of the allocas over in a block. Using splice means
2412  // that the instructions aren't removed from the symbol table, then
2413  // reinserted.
2414  Caller->getEntryBlock().getInstList().splice(
2415  InsertPoint, FirstNewBlock->getInstList(), AI->getIterator(), I);
2416  }
2417  }
2418 
2419  SmallVector<Value*,4> VarArgsToForward;
2420  SmallVector<AttributeSet, 4> VarArgsAttrs;
2421  for (unsigned i = CalledFunc->getFunctionType()->getNumParams();
2422  i < CB.arg_size(); i++) {
2423  VarArgsToForward.push_back(CB.getArgOperand(i));
2424  VarArgsAttrs.push_back(CB.getAttributes().getParamAttrs(i));
2425  }
2426 
2427  bool InlinedMustTailCalls = false, InlinedDeoptimizeCalls = false;
2428  if (InlinedFunctionInfo.ContainsCalls) {
2429  CallInst::TailCallKind CallSiteTailKind = CallInst::TCK_None;
2430  if (CallInst *CI = dyn_cast<CallInst>(&CB))
2431  CallSiteTailKind = CI->getTailCallKind();
2432 
2433  // For inlining purposes, the "notail" marker is the same as no marker.
2434  if (CallSiteTailKind == CallInst::TCK_NoTail)
2435  CallSiteTailKind = CallInst::TCK_None;
2436 
2437  for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E;
2438  ++BB) {
2440  CallInst *CI = dyn_cast<CallInst>(&I);
2441  if (!CI)
2442  continue;
2443 
2444  // Forward varargs from inlined call site to calls to the
2445  // ForwardVarArgsTo function, if requested, and to musttail calls.
2446  if (!VarArgsToForward.empty() &&
2447  ((ForwardVarArgsTo &&
2448  CI->getCalledFunction() == ForwardVarArgsTo) ||
2449  CI->isMustTailCall())) {
2450  // Collect attributes for non-vararg parameters.
2453  if (!Attrs.isEmpty() || !VarArgsAttrs.empty()) {
2454  for (unsigned ArgNo = 0;
2455  ArgNo < CI->getFunctionType()->getNumParams(); ++ArgNo)
2456  ArgAttrs.push_back(Attrs.getParamAttrs(ArgNo));
2457  }
2458 
2459  // Add VarArg attributes.
2460  ArgAttrs.append(VarArgsAttrs.begin(), VarArgsAttrs.end());
2461  Attrs = AttributeList::get(CI->getContext(), Attrs.getFnAttrs(),
2462  Attrs.getRetAttrs(), ArgAttrs);
2463  // Add VarArgs to existing parameters.
2464  SmallVector<Value *, 6> Params(CI->args());
2465  Params.append(VarArgsToForward.begin(), VarArgsToForward.end());
2466  CallInst *NewCI = CallInst::Create(
2467  CI->getFunctionType(), CI->getCalledOperand(), Params, "", CI);
2468  NewCI->setDebugLoc(CI->getDebugLoc());
2469  NewCI->setAttributes(Attrs);
2470  NewCI->setCallingConv(CI->getCallingConv());
2471  CI->replaceAllUsesWith(NewCI);
2472  CI->eraseFromParent();
2473  CI = NewCI;
2474  }
2475 
2476  if (Function *F = CI->getCalledFunction())
2477  InlinedDeoptimizeCalls |=
2478  F->getIntrinsicID() == Intrinsic::experimental_deoptimize;
2479 
2480  // We need to reduce the strength of any inlined tail calls. For
2481  // musttail, we have to avoid introducing potential unbounded stack
2482  // growth. For example, if functions 'f' and 'g' are mutually recursive
2483  // with musttail, we can inline 'g' into 'f' so long as we preserve
2484  // musttail on the cloned call to 'f'. If either the inlined call site
2485  // or the cloned call site is *not* musttail, the program already has
2486  // one frame of stack growth, so it's safe to remove musttail. Here is
2487  // a table of example transformations:
2488  //
2489  // f -> musttail g -> musttail f ==> f -> musttail f
2490  // f -> musttail g -> tail f ==> f -> tail f
2491  // f -> g -> musttail f ==> f -> f
2492  // f -> g -> tail f ==> f -> f
2493  //
2494  // Inlined notail calls should remain notail calls.
2495  CallInst::TailCallKind ChildTCK = CI->getTailCallKind();
2496  if (ChildTCK != CallInst::TCK_NoTail)
2497  ChildTCK = std::min(CallSiteTailKind, ChildTCK);
2498  CI->setTailCallKind(ChildTCK);
2499  InlinedMustTailCalls |= CI->isMustTailCall();
2500 
2501  // Call sites inlined through a 'nounwind' call site should be
2502  // 'nounwind' as well. However, avoid marking call sites explicitly
2503  // where possible. This helps expose more opportunities for CSE after
2504  // inlining, commonly when the callee is an intrinsic.
2505  if (MarkNoUnwind && !CI->doesNotThrow())
2506  CI->setDoesNotThrow();
2507  }
2508  }
2509  }
2510 
2511  // Leave lifetime markers for the static alloca's, scoping them to the
2512  // function we just inlined.
2513  // We need to insert lifetime intrinsics even at O0 to avoid invalid
2514  // access caused by multithreaded coroutines. The check
2515  // `Caller->isPresplitCoroutine()` would affect AlwaysInliner at O0 only.
2516  if ((InsertLifetime || Caller->isPresplitCoroutine()) &&
2517  !IFI.StaticAllocas.empty()) {
2518  IRBuilder<> builder(&FirstNewBlock->front());
2519  for (unsigned ai = 0, ae = IFI.StaticAllocas.size(); ai != ae; ++ai) {
2520  AllocaInst *AI = IFI.StaticAllocas[ai];
2521  // Don't mark swifterror allocas. They can't have bitcast uses.
2522  if (AI->isSwiftError())
2523  continue;
2524 
2525  // If the alloca is already scoped to something smaller than the whole
2526  // function then there's no need to add redundant, less accurate markers.
2527  if (hasLifetimeMarkers(AI))
2528  continue;
2529 
2530  // Try to determine the size of the allocation.
2531  ConstantInt *AllocaSize = nullptr;
2532  if (ConstantInt *AIArraySize =
2533  dyn_cast<ConstantInt>(AI->getArraySize())) {
2534  auto &DL = Caller->getParent()->getDataLayout();
2535  Type *AllocaType = AI->getAllocatedType();
2536  TypeSize AllocaTypeSize = DL.getTypeAllocSize(AllocaType);
2537  uint64_t AllocaArraySize = AIArraySize->getLimitedValue();
2538 
2539  // Don't add markers for zero-sized allocas.
2540  if (AllocaArraySize == 0)
2541  continue;
2542 
2543  // Check that array size doesn't saturate uint64_t and doesn't
2544  // overflow when it's multiplied by type size.
2545  if (!AllocaTypeSize.isScalable() &&
2546  AllocaArraySize != std::numeric_limits<uint64_t>::max() &&
2547  std::numeric_limits<uint64_t>::max() / AllocaArraySize >=
2548  AllocaTypeSize.getFixedSize()) {
2549  AllocaSize = ConstantInt::get(Type::getInt64Ty(AI->getContext()),
2550  AllocaArraySize * AllocaTypeSize);
2551  }
2552  }
2553 
2554  builder.CreateLifetimeStart(AI, AllocaSize);
2555  for (ReturnInst *RI : Returns) {
2556  // Don't insert llvm.lifetime.end calls between a musttail or deoptimize
2557  // call and a return. The return kills all local allocas.
2558  if (InlinedMustTailCalls &&
2560  continue;
2561  if (InlinedDeoptimizeCalls &&
2563  continue;
2564  IRBuilder<>(RI).CreateLifetimeEnd(AI, AllocaSize);
2565  }
2566  }
2567  }
2568 
2569  // If the inlined code contained dynamic alloca instructions, wrap the inlined
2570  // code with llvm.stacksave/llvm.stackrestore intrinsics.
2571  if (InlinedFunctionInfo.ContainsDynamicAllocas) {
2572  Module *M = Caller->getParent();
2573  // Get the two intrinsics we care about.
2574  Function *StackSave = Intrinsic::getDeclaration(M, Intrinsic::stacksave);
2575  Function *StackRestore=Intrinsic::getDeclaration(M,Intrinsic::stackrestore);
2576 
2577  // Insert the llvm.stacksave.
2578  CallInst *SavedPtr = IRBuilder<>(&*FirstNewBlock, FirstNewBlock->begin())
2579  .CreateCall(StackSave, {}, "savedstack");
2580 
2581  // Insert a call to llvm.stackrestore before any return instructions in the
2582  // inlined function.
2583  for (ReturnInst *RI : Returns) {
2584  // Don't insert llvm.stackrestore calls between a musttail or deoptimize
2585  // call and a return. The return will restore the stack pointer.
2586  if (InlinedMustTailCalls && RI->getParent()->getTerminatingMustTailCall())
2587  continue;
2588  if (InlinedDeoptimizeCalls && RI->getParent()->getTerminatingDeoptimizeCall())
2589  continue;
2590  IRBuilder<>(RI).CreateCall(StackRestore, SavedPtr);
2591  }
2592  }
2593 
2594  // If we are inlining for an invoke instruction, we must make sure to rewrite
2595  // any call instructions into invoke instructions. This is sensitive to which
2596  // funclet pads were top-level in the inlinee, so must be done before
2597  // rewriting the "parent pad" links.
2598  if (auto *II = dyn_cast<InvokeInst>(&CB)) {
2599  BasicBlock *UnwindDest = II->getUnwindDest();
2600  Instruction *FirstNonPHI = UnwindDest->getFirstNonPHI();
2601  if (isa<LandingPadInst>(FirstNonPHI)) {
2602  HandleInlinedLandingPad(II, &*FirstNewBlock, InlinedFunctionInfo);
2603  } else {
2604  HandleInlinedEHPad(II, &*FirstNewBlock, InlinedFunctionInfo);
2605  }
2606  }
2607 
2608  // Update the lexical scopes of the new funclets and callsites.
2609  // Anything that had 'none' as its parent is now nested inside the callsite's
2610  // EHPad.
2611  if (CallSiteEHPad) {
2612  for (Function::iterator BB = FirstNewBlock->getIterator(),
2613  E = Caller->end();
2614  BB != E; ++BB) {
2615  // Add bundle operands to inlined call sites.
2616  PropagateOperandBundles(BB, CallSiteEHPad);
2617 
2618  // It is problematic if the inlinee has a cleanupret which unwinds to
2619  // caller and we inline it into a call site which doesn't unwind but into
2620  // an EH pad that does. Such an edge must be dynamically unreachable.
2621  // As such, we replace the cleanupret with unreachable.
2622  if (auto *CleanupRet = dyn_cast<CleanupReturnInst>(BB->getTerminator()))
2623  if (CleanupRet->unwindsToCaller() && EHPadForCallUnwindsLocally)
2624  changeToUnreachable(CleanupRet);
2625 
2626  Instruction *I = BB->getFirstNonPHI();
2627  if (!I->isEHPad())
2628  continue;
2629 
2630  if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I)) {
2631  if (isa<ConstantTokenNone>(CatchSwitch->getParentPad()))
2632  CatchSwitch->setParentPad(CallSiteEHPad);
2633  } else {
2634  auto *FPI = cast<FuncletPadInst>(I);
2635  if (isa<ConstantTokenNone>(FPI->getParentPad()))
2636  FPI->setParentPad(CallSiteEHPad);
2637  }
2638  }
2639  }
2640 
2641  if (InlinedDeoptimizeCalls) {
2642  // We need to at least remove the deoptimizing returns from the Return set,
2643  // so that the control flow from those returns does not get merged into the
2644  // caller (but terminate it instead). If the caller's return type does not
2645  // match the callee's return type, we also need to change the return type of
2646  // the intrinsic.
2647  if (Caller->getReturnType() == CB.getType()) {
2648  llvm::erase_if(Returns, [](ReturnInst *RI) {
2649  return RI->getParent()->getTerminatingDeoptimizeCall() != nullptr;
2650  });
2651  } else {
2652  SmallVector<ReturnInst *, 8> NormalReturns;
2653  Function *NewDeoptIntrinsic = Intrinsic::getDeclaration(
2654  Caller->getParent(), Intrinsic::experimental_deoptimize,
2655  {Caller->getReturnType()});
2656 
2657  for (ReturnInst *RI : Returns) {
2658  CallInst *DeoptCall = RI->getParent()->getTerminatingDeoptimizeCall();
2659  if (!DeoptCall) {
2660  NormalReturns.push_back(RI);
2661  continue;
2662  }
2663 
2664  // The calling convention on the deoptimize call itself may be bogus,
2665  // since the code we're inlining may have undefined behavior (and may
2666  // never actually execute at runtime); but all
2667  // @llvm.experimental.deoptimize declarations have to have the same
2668  // calling convention in a well-formed module.
2669  auto CallingConv = DeoptCall->getCalledFunction()->getCallingConv();
2670  NewDeoptIntrinsic->setCallingConv(CallingConv);
2671  auto *CurBB = RI->getParent();
2672  RI->eraseFromParent();
2673 
2674  SmallVector<Value *, 4> CallArgs(DeoptCall->args());
2675 
2677  DeoptCall->getOperandBundlesAsDefs(OpBundles);
2678  auto DeoptAttributes = DeoptCall->getAttributes();
2679  DeoptCall->eraseFromParent();
2680  assert(!OpBundles.empty() &&
2681  "Expected at least the deopt operand bundle");
2682 
2683  IRBuilder<> Builder(CurBB);
2684  CallInst *NewDeoptCall =
2685  Builder.CreateCall(NewDeoptIntrinsic, CallArgs, OpBundles);
2686  NewDeoptCall->setCallingConv(CallingConv);
2687  NewDeoptCall->setAttributes(DeoptAttributes);
2688  if (NewDeoptCall->getType()->isVoidTy())
2689  Builder.CreateRetVoid();
2690  else
2691  Builder.CreateRet(NewDeoptCall);
2692  }
2693 
2694  // Leave behind the normal returns so we can merge control flow.
2695  std::swap(Returns, NormalReturns);
2696  }
2697  }
2698 
2699  // Handle any inlined musttail call sites. In order for a new call site to be
2700  // musttail, the source of the clone and the inlined call site must have been
2701  // musttail. Therefore it's safe to return without merging control into the
2702  // phi below.
2703  if (InlinedMustTailCalls) {
2704  // Check if we need to bitcast the result of any musttail calls.
2705  Type *NewRetTy = Caller->getReturnType();
2706  bool NeedBitCast = !CB.use_empty() && CB.getType() != NewRetTy;
2707 
2708  // Handle the returns preceded by musttail calls separately.
2709  SmallVector<ReturnInst *, 8> NormalReturns;
2710  for (ReturnInst *RI : Returns) {
2711  CallInst *ReturnedMustTail =
2713  if (!ReturnedMustTail) {
2714  NormalReturns.push_back(RI);
2715  continue;
2716  }
2717  if (!NeedBitCast)
2718  continue;
2719 
2720  // Delete the old return and any preceding bitcast.
2721  BasicBlock *CurBB = RI->getParent();
2722  auto *OldCast = dyn_cast_or_null<BitCastInst>(RI->getReturnValue());
2723  RI->eraseFromParent();
2724  if (OldCast)
2725  OldCast->eraseFromParent();
2726 
2727  // Insert a new bitcast and return with the right type.
2728  IRBuilder<> Builder(CurBB);
2729  Builder.CreateRet(Builder.CreateBitCast(ReturnedMustTail, NewRetTy));
2730  }
2731 
2732  // Leave behind the normal returns so we can merge control flow.
2733  std::swap(Returns, NormalReturns);
2734  }
2735 
2736  // Now that all of the transforms on the inlined code have taken place but
2737  // before we splice the inlined code into the CFG and lose track of which
2738  // blocks were actually inlined, collect the call sites. We only do this if
2739  // call graph updates weren't requested, as those provide value handle based
2740  // tracking of inlined call sites instead. Calls to intrinsics are not
2741  // collected because they are not inlineable.
2742  if (InlinedFunctionInfo.ContainsCalls && !IFI.CG) {
2743  // Otherwise just collect the raw call sites that were inlined.
2744  for (BasicBlock &NewBB :
2745  make_range(FirstNewBlock->getIterator(), Caller->end()))
2746  for (Instruction &I : NewBB)
2747  if (auto *CB = dyn_cast<CallBase>(&I))
2748  if (!(CB->getCalledFunction() &&
2749  CB->getCalledFunction()->isIntrinsic()))
2750  IFI.InlinedCallSites.push_back(CB);
2751  }
2752 
2753  // If we cloned in _exactly one_ basic block, and if that block ends in a
2754  // return instruction, we splice the body of the inlined callee directly into
2755  // the calling basic block.
2756  if (Returns.size() == 1 && std::distance(FirstNewBlock, Caller->end()) == 1) {
2757  // Move all of the instructions right before the call.
2758  OrigBB->getInstList().splice(CB.getIterator(), FirstNewBlock->getInstList(),
2759  FirstNewBlock->begin(), FirstNewBlock->end());
2760  // Remove the cloned basic block.
2761  Caller->getBasicBlockList().pop_back();
2762 
2763  // If the call site was an invoke instruction, add a branch to the normal
2764  // destination.
2765  if (InvokeInst *II = dyn_cast<InvokeInst>(&CB)) {
2766  BranchInst *NewBr = BranchInst::Create(II->getNormalDest(), &CB);
2767  NewBr->setDebugLoc(Returns[0]->getDebugLoc());
2768  }
2769 
2770  // If the return instruction returned a value, replace uses of the call with
2771  // uses of the returned value.
2772  if (!CB.use_empty()) {
2773  ReturnInst *R = Returns[0];
2774  if (&CB == R->getReturnValue())
2776  else
2777  CB.replaceAllUsesWith(R->getReturnValue());
2778  }
2779  // Since we are now done with the Call/Invoke, we can delete it.
2780  CB.eraseFromParent();
2781 
2782  // Since we are now done with the return instruction, delete it also.
2783  Returns[0]->eraseFromParent();
2784 
2785  if (MergeAttributes)
2786  AttributeFuncs::mergeAttributesForInlining(*Caller, *CalledFunc);
2787 
2788  // We are now done with the inlining.
2789  return InlineResult::success();
2790  }
2791 
2792  // Otherwise, we have the normal case, of more than one block to inline or
2793  // multiple return sites.
2794 
2795  // We want to clone the entire callee function into the hole between the
2796  // "starter" and "ender" blocks. How we accomplish this depends on whether
2797  // this is an invoke instruction or a call instruction.
2798  BasicBlock *AfterCallBB;
2799  BranchInst *CreatedBranchToNormalDest = nullptr;
2800  if (InvokeInst *II = dyn_cast<InvokeInst>(&CB)) {
2801 
2802  // Add an unconditional branch to make this look like the CallInst case...
2803  CreatedBranchToNormalDest = BranchInst::Create(II->getNormalDest(), &CB);
2804 
2805  // Split the basic block. This guarantees that no PHI nodes will have to be
2806  // updated due to new incoming edges, and make the invoke case more
2807  // symmetric to the call case.
2808  AfterCallBB =
2809  OrigBB->splitBasicBlock(CreatedBranchToNormalDest->getIterator(),
2810  CalledFunc->getName() + ".exit");
2811 
2812  } else { // It's a call
2813  // If this is a call instruction, we need to split the basic block that
2814  // the call lives in.
2815  //
2816  AfterCallBB = OrigBB->splitBasicBlock(CB.getIterator(),
2817  CalledFunc->getName() + ".exit");
2818  }
2819 
2820  if (IFI.CallerBFI) {
2821  // Copy original BB's block frequency to AfterCallBB
2822  IFI.CallerBFI->setBlockFreq(
2823  AfterCallBB, IFI.CallerBFI->getBlockFreq(OrigBB).getFrequency());
2824  }
2825 
2826  // Change the branch that used to go to AfterCallBB to branch to the first
2827  // basic block of the inlined function.
2828  //
2829  Instruction *Br = OrigBB->getTerminator();
2830  assert(Br && Br->getOpcode() == Instruction::Br &&
2831  "splitBasicBlock broken!");
2832  Br->setOperand(0, &*FirstNewBlock);
2833 
2834  // Now that the function is correct, make it a little bit nicer. In
2835  // particular, move the basic blocks inserted from the end of the function
2836  // into the space made by splitting the source basic block.
2837  Caller->getBasicBlockList().splice(AfterCallBB->getIterator(),
2838  Caller->getBasicBlockList(), FirstNewBlock,
2839  Caller->end());
2840 
2841  // Handle all of the return instructions that we just cloned in, and eliminate
2842  // any users of the original call/invoke instruction.
2843  Type *RTy = CalledFunc->getReturnType();
2844 
2845  PHINode *PHI = nullptr;
2846  if (Returns.size() > 1) {
2847  // The PHI node should go at the front of the new basic block to merge all
2848  // possible incoming values.
2849  if (!CB.use_empty()) {
2850  PHI = PHINode::Create(RTy, Returns.size(), CB.getName(),
2851  &AfterCallBB->front());
2852  // Anything that used the result of the function call should now use the
2853  // PHI node as their operand.
2854  CB.replaceAllUsesWith(PHI);
2855  }
2856 
2857  // Loop over all of the return instructions adding entries to the PHI node
2858  // as appropriate.
2859  if (PHI) {
2860  for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
2861  ReturnInst *RI = Returns[i];
2862  assert(RI->getReturnValue()->getType() == PHI->getType() &&
2863  "Ret value not consistent in function!");
2864  PHI->addIncoming(RI->getReturnValue(), RI->getParent());
2865  }
2866  }
2867 
2868  // Add a branch to the merge points and remove return instructions.
2869  DebugLoc Loc;
2870  for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
2871  ReturnInst *RI = Returns[i];
2872  BranchInst* BI = BranchInst::Create(AfterCallBB, RI);
2873  Loc = RI->getDebugLoc();
2874  BI->setDebugLoc(Loc);
2875  RI->eraseFromParent();
2876  }
2877  // We need to set the debug location to *somewhere* inside the
2878  // inlined function. The line number may be nonsensical, but the
2879  // instruction will at least be associated with the right
2880  // function.
2881  if (CreatedBranchToNormalDest)
2882  CreatedBranchToNormalDest->setDebugLoc(Loc);
2883  } else if (!Returns.empty()) {
2884  // Otherwise, if there is exactly one return value, just replace anything
2885  // using the return value of the call with the computed value.
2886  if (!CB.use_empty()) {
2887  if (&CB == Returns[0]->getReturnValue())
2889  else
2890  CB.replaceAllUsesWith(Returns[0]->getReturnValue());
2891  }
2892 
2893  // Update PHI nodes that use the ReturnBB to use the AfterCallBB.
2894  BasicBlock *ReturnBB = Returns[0]->getParent();
2895  ReturnBB->replaceAllUsesWith(AfterCallBB);
2896 
2897  // Splice the code from the return block into the block that it will return
2898  // to, which contains the code that was after the call.
2899  AfterCallBB->getInstList().splice(AfterCallBB->begin(),
2900  ReturnBB->getInstList());
2901 
2902  if (CreatedBranchToNormalDest)
2903  CreatedBranchToNormalDest->setDebugLoc(Returns[0]->getDebugLoc());
2904 
2905  // Delete the return instruction now and empty ReturnBB now.
2906  Returns[0]->eraseFromParent();
2907  ReturnBB->eraseFromParent();
2908  } else if (!CB.use_empty()) {
2909  // No returns, but something is using the return value of the call. Just
2910  // nuke the result.
2912  }
2913 
2914  // Since we are now done with the Call/Invoke, we can delete it.
2915  CB.eraseFromParent();
2916 
2917  // If we inlined any musttail calls and the original return is now
2918  // unreachable, delete it. It can only contain a bitcast and ret.
2919  if (InlinedMustTailCalls && pred_empty(AfterCallBB))
2920  AfterCallBB->eraseFromParent();
2921 
2922  // We should always be able to fold the entry block of the function into the
2923  // single predecessor of the block...
2924  assert(cast<BranchInst>(Br)->isUnconditional() && "splitBasicBlock broken!");
2925  BasicBlock *CalleeEntry = cast<BranchInst>(Br)->getSuccessor(0);
2926 
2927  // Splice the code entry block into calling block, right before the
2928  // unconditional branch.
2929  CalleeEntry->replaceAllUsesWith(OrigBB); // Update PHI nodes
2930  OrigBB->getInstList().splice(Br->getIterator(), CalleeEntry->getInstList());
2931 
2932  // Remove the unconditional branch.
2933  Br->eraseFromParent();
2934 
2935  // Now we can remove the CalleeEntry block, which is now empty.
2936  Caller->getBasicBlockList().erase(CalleeEntry);
2937 
2938  // If we inserted a phi node, check to see if it has a single value (e.g. all
2939  // the entries are the same or undef). If so, remove the PHI so it doesn't
2940  // block other optimizations.
2941  if (PHI) {
2942  AssumptionCache *AC =
2943  IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;
2944  auto &DL = Caller->getParent()->getDataLayout();
2945  if (Value *V = simplifyInstruction(PHI, {DL, nullptr, nullptr, AC})) {
2946  PHI->replaceAllUsesWith(V);
2947  PHI->eraseFromParent();
2948  }
2949  }
2950 
2951  if (MergeAttributes)
2952  AttributeFuncs::mergeAttributesForInlining(*Caller, *CalledFunc);
2953 
2954  return InlineResult::success();
2955 }
llvm::EHPersonality::MSVC_CXX
@ MSVC_CXX
llvm::AttrBuilder::addDereferenceableOrNullAttr
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
Definition: Attributes.cpp:1771
i
i
Definition: README.txt:29
llvm::InvokeInst::getNormalDest
BasicBlock * getNormalDest() const
Definition: Instructions.h:3942
llvm::LLVMContext::OB_deopt
@ OB_deopt
Definition: LLVMContext.h:89
llvm::BasicBlock::getTerminatingDeoptimizeCall
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:182
llvm::CallBase::getNumOperandBundles
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
Definition: InstrTypes.h:1930
IdentifyValidAttributes
static AttrBuilder IdentifyValidAttributes(CallBase &CB)
Definition: InlineFunction.cpp:1392
llvm::isAsynchronousEHPersonality
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
Definition: EHPersonalities.h:49
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
AssumptionCache.h
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::InlineResult::success
static InlineResult success()
Definition: InlineCost.h:182
llvm::Function::isIntrinsic
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:210
llvm::CatchSwitchInst::Create
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:4354
llvm::CallGraphNode::CalledFunctionsVector
std::vector< CallRecord > CalledFunctionsVector
Definition: CallGraph.h:181
llvm::AArch64CC::HI
@ HI
Definition: AArch64BaseInfo.h:263
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
HandleInlinedEHPad
static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock, ClonedCodeInfo &InlinedCodeInfo)
If we inlined an invoke site, we need to convert calls in the body of the inlined function into invok...
Definition: InlineFunction.cpp:666
llvm::objcarc::hasAttachedCallOpBundle
bool hasAttachedCallOpBundle(const CallBase *CB)
Definition: ObjCARCUtil.h:29
llvm::LandingPadInst::isCleanup
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
Definition: Instructions.h:2997
getUnwindDestToken
static Value * getUnwindDestToken(Instruction *EHPad, UnwindDestMemoTy &MemoMap)
Given an EH pad, find where it unwinds.
Definition: InlineFunction.cpp:399
llvm::CallBase::getOperandBundlesAsDefs
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: Instructions.cpp:416
removeMemProfMetadata
static void removeMemProfMetadata(CallBase *Call)
Definition: InlineFunction.cpp:810
llvm::Function::args
iterator_range< arg_iterator > args()
Definition: Function.h:746
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Instruction::getModule
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:69
llvm::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:269
llvm::objcarc::getAttachedARCFunction
Optional< Function * > getAttachedARCFunction(const CallBase *CB)
This function returns operand bundle clang_arc_attachedcall's argument, which is the address of the A...
Definition: ObjCARCUtil.h:43
llvm::CallGraphNode::iterator
std::vector< CallRecord >::iterator iterator
Definition: CallGraph.h:193
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::LLVMContext::OB_clang_arc_attachedcall
@ OB_clang_arc_attachedcall
Definition: LLVMContext.h:95
llvm::AssumptionCache::registerAssumption
void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
Definition: AssumptionCache.cpp:224
llvm::ReturnInst
Return a value (possibly void), from a function.
Definition: Instructions.h:3051
llvm::VAArgInst
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
Definition: Instructions.h:1831
llvm::ClonedCodeInfo
This struct can be used to capture information about code being cloned, while it is being cloned.
Definition: Cloning.h:62
llvm::CallBase::getOperandBundle
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:2017
Optional.h
ValueMapper.h
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
allocaWouldBeStaticInEntry
static bool allocaWouldBeStaticInEntry(const AllocaInst *AI)
Return the result of AI->isStaticAlloca() if AI were moved to the entry block.
Definition: InlineFunction.cpp:1677
propagateMemProfMetadata
static void propagateMemProfMetadata(Function *Callee, CallBase &CB, bool ContainsMemProfMetadata, const ValueMap< const Value *, WeakTrackingVH > &VMap)
Definition: InlineFunction.cpp:905
llvm::IRBuilderBase::CreateLifetimeEnd
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
Definition: IRBuilder.cpp:493
MayContainThrowingOrExitingCall
static bool MayContainThrowingOrExitingCall(Instruction *Begin, Instruction *End)
Definition: InlineFunction.cpp:1383
llvm::Intrinsic::getDeclaration
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1481
Metadata.h
llvm::Type::getInt8PtrTy
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:291
llvm::Function::end
iterator end()
Definition: Function.h:709
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
PHI
Rewrite undef for PHI
Definition: AMDGPURewriteUndefForPHI.cpp:101
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
IntrinsicInst.h
DebugInfoMetadata.h
llvm::ClonedCodeInfo::ContainsMemProfMetadata
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
Definition: Cloning.h:68
llvm::ValueMap::end
iterator end()
Definition: ValueMap.h:136
llvm::TypeSize::getFixedSize
ScalarTy getFixedSize() const
Definition: TypeSize.h:444
llvm::Function
Definition: Function.h:60
fixupLineNumbers
static void fixupLineNumbers(Function *Fn, Function::iterator FI, Instruction *TheCall, bool CalleeHasDebugInfo)
Update inlined instructions' line numbers to to encode location where these instructions are inlined.
Definition: InlineFunction.cpp:1693
getUnwindDestTokenHelper
static Value * getUnwindDestTokenHelper(Instruction *EHPad, UnwindDestMemoTy &MemoMap)
Helper for getUnwindDestToken that does the descendant-ward part of the search.
Definition: InlineFunction.cpp:248
llvm::ReturnInst::getReturnValue
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Definition: Instructions.h:3096
llvm::AllocaInst::getType
PointerType * getType() const
Overload to return most specific pointer type.
Definition: Instructions.h:100
llvm::InlineFunction
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr)
This function inlines the called function into the basic block of the caller.
Definition: InlineFunction.cpp:2046
llvm::SmallVector< Value *, 8 >
llvm::CallInst::setTailCallKind
void setTailCallKind(TailCallKind TCK)
Definition: Instructions.h:1676
InlineAsm.h
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition: Instructions.h:2950
CaptureTracking.h
llvm::CallGraphNode::removeCallEdgeFor
void removeCallEdgeFor(CallBase &Call)
Removes the edge in the node for the specified call site.
Definition: CallGraph.cpp:213
llvm::CallBase::isInlineAsm
bool isInlineAsm() const
Check if this call is an inline asm statement.
Definition: InstrTypes.h:1464
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1626
ErrorHandling.h
builder
assume builder
Definition: AssumeBundleBuilder.cpp:650
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:729
llvm::IRBuilder<>
llvm::getEnableAssignmentTracking
bool getEnableAssignmentTracking()
Return true if assignment tracking is enabled.
Definition: DebugInfo.cpp:48
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1972
ValueTracking.h
Local.h
llvm::AttributeList::get
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:1132
llvm::CallGraph
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:72
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:140
removeCallsiteMetadata
static void removeCallsiteMetadata(CallBase *Call)
Definition: InlineFunction.cpp:814
llvm::CallBase::addOperandBundle
static CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, Instruction *InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
Definition: Instructions.cpp:495
HandleByValArgument
static Value * HandleByValArgument(Type *ByValType, Value *Arg, Instruction *TheCall, const Function *CalledFunc, InlineFunctionInfo &IFI, unsigned ByValAlignment)
When inlining a call site that has a byval argument, we have to make the implicit memcpy explicit by ...
Definition: InlineFunction.cpp:1594
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1595
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:321
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
Module.h
llvm::BasicBlock::eraseFromParent
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
Definition: BasicBlock.cpp:132
llvm::AttributeList
Definition: Attributes.h:430
llvm::getOrEnforceKnownAlignment
Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
Definition: Local.cpp:1417
llvm::CallBase::getAttributes
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1474
llvm::OperandBundleDefT
A container for an operand bundle being viewed as a set of values rather than a set of uses.
Definition: AutoUpgrade.h:32
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1254
EHPersonalities.h
llvm::BasicBlock::splitBasicBlock
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:402
llvm::objcarc::isRetainOrClaimRV
bool isRetainOrClaimRV(ARCInstKind Kind)
Check whether the function is retainRV/unsafeClaimRV.
Definition: ObjCARCUtil.h:52
llvm::Optional
Definition: APInt.h:33
llvm::LLVMContext::OB_funclet
@ OB_funclet
Definition: LLVMContext.h:90
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
PropagateOperandBundles
static void PropagateOperandBundles(Function::iterator InlinedBB, Instruction *CallSiteEHPad)
Bundle operands of the inlined function must be added to inlined call sites.
Definition: InlineFunction.cpp:1001
llvm::ProfileSummaryInfo::getProfileCount
Optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const
Returns the profile count for CallInst.
Definition: ProfileSummaryInfo.cpp:78
llvm::SmallPtrSet< Instruction *, 4 >
llvm::CallBase::isByValArgument
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
Definition: InstrTypes.h:1678
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:891
llvm::FunctionType::getNumParams
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
llvm::Function::ProfileCount::isSynthetic
bool isSynthetic() const
Definition: Function.h:263
HandleCallsInBlockInlinedThroughInvoke
static BasicBlock * HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, BasicBlock *UnwindEdge, UnwindDestMemoTy *FuncletUnwindMap=nullptr)
When we inline a basic block into an invoke, we have to turn all of the calls that can throw into inv...
Definition: InlineFunction.cpp:543
STLExtras.h
llvm::CallBase::arg_begin
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1316
llvm::CallInst::TCK_None
@ TCK_None
Definition: Instructions.h:1651
llvm::CallBase::setDoesNotThrow
void setDoesNotThrow()
Definition: InstrTypes.h:1890
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:105
llvm::MemoryEffects::onlyAccessesInaccessibleMem
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
Definition: ModRef.h:210
llvm::uniteAccessGroups
MDNode * uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2)
Compute the union of two access-group lists.
Definition: VectorUtils.cpp:809
llvm::BasicBlock::rend
reverse_iterator rend()
Definition: BasicBlock.h:313
llvm::LinearPolySize::isScalable
bool isScalable() const
Returns whether the size is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:298
llvm::CallGraphNode::addCalledFunction
void addCalledFunction(CallBase *Call, CallGraphNode *M)
Adds a function to the list of functions called by this one.
Definition: CallGraph.h:242
llvm::MDBuilder::createAnonymousAliasScope
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
Definition: MDBuilder.h:159
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::AMDGPU::HSAMD::ValueKind::Queue
@ Queue
llvm::at::getAssignmentMarkers
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
Definition: DebugInfo.cpp:1692
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1400
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::InlineFunctionInfo::CallerBFI
BlockFrequencyInfo * CallerBFI
Definition: Cloning.h:220
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1456
llvm::InlineFunctionInfo::PSI
ProfileSummaryInfo * PSI
Definition: Cloning.h:219
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1298
AliasAnalysis.h
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MemoryEffects
Summary of how a function affects memory in the program.
Definition: ModRef.h:63
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition: EHPersonalities.cpp:22
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
Instruction.h
CommandLine.h
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
AddAliasScopeMetadata
static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap, const DataLayout &DL, AAResults *CalleeAAR, ClonedCodeInfo &InlinedFunctionInfo)
If the inlined function has noalias arguments, then add new alias scopes for each noalias argument,...
Definition: InlineFunction.cpp:1139
llvm::Instruction::getOpcode
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:164
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
PropagateCallSiteMetadata
static void PropagateCallSiteMetadata(CallBase &CB, Function::iterator FStart, Function::iterator FEnd)
When inlining a call site that has !llvm.mem.parallel_loop_access, !llvm.access.group,...
Definition: InlineFunction.cpp:960
llvm::Instruction::isLifetimeStartOrEnd
bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
Definition: Instruction.cpp:748
llvm::CallGraphNode::end
iterator end()
Definition: CallGraph.h:200
llvm::InlineFunctionInfo::CG
CallGraph * CG
If non-null, InlineFunction will update the callgraph to reflect the changes it makes.
Definition: Cloning.h:217
llvm::ms_demangle::CallingConv
CallingConv
Definition: MicrosoftDemangleNodes.h:58
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:271
Constants.h
llvm::AAResults
Definition: AliasAnalysis.h:294
llvm::memprof::CallStack
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
Definition: MemoryProfileInfo.h:108
llvm::AllocaInst::getAllocatedType
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Definition: Instructions.h:114
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
UpdateReturnAttributes
static cl::opt< bool > UpdateReturnAttributes("update-return-attrs", cl::init(true), cl::Hidden, cl::desc("Update return attributes on calls within inlined body"))
llvm::DebugLoc::getCol
unsigned getCol() const
Definition: DebugLoc.cpp:29
llvm::InvokeInst::getLandingPadInst
LandingPadInst * getLandingPadInst() const
Get the landingpad instruction from the landing pad block (the unwind destination).
Definition: Instructions.cpp:1015
llvm::User
Definition: User.h:44
llvm::getKnownAlignment
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Definition: Local.h:222
Intrinsics.h
llvm::CleanupReturnInst::Create
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:4681
llvm::LandingPadInst::getNumClauses
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
Definition: Instructions.h:3022
InstrTypes.h
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
llvm::CallBase::setAttributes
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1478
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:306
UpdatePHINodes
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
Definition: BasicBlockUtils.cpp:1093
llvm::MDNode::operands
ArrayRef< MDOperand > operands() const
Definition: Metadata.h:1290
llvm::CallInst::Create
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1516
SI
@ SI
Definition: SIInstrInfo.cpp:7882
llvm::MDTuple
Tuple of metadata.
Definition: Metadata.h:1329
llvm::updateProfileCallee
void updateProfileCallee(Function *Callee, int64_t EntryDelta, const ValueMap< const Value *, WeakTrackingVH > *VMap=nullptr)
Updates profile information by adjusting the entry count by adding EntryDelta then scaling callsite i...
Definition: InlineFunction.cpp:1905
llvm::objcarc::ARCInstKind::RetainRV
@ RetainRV
objc_retainAutoreleasedReturnValue
AssumeBundleBuilder.h
llvm::BlockFrequencyInfo::setBlockFreq
void setBlockFreq(const BasicBlock *BB, uint64_t Freq)
Definition: BlockFrequencyInfo.cpp:228
llvm::ClonedCodeInfo::OperandBundleCallSites
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.
Definition: Cloning.h:78
llvm::Function::arg_end
arg_iterator arg_end()
Definition: Function.h:731
llvm::AAResults::getMemoryEffects
MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
Definition: AliasAnalysis.cpp:388
llvm::Instruction
Definition: Instruction.h:42
UseNoAliasIntrinsic
static cl::opt< bool > UseNoAliasIntrinsic("use-noalias-intrinsic-during-inlining", cl::Hidden, cl::init(true), cl::desc("Use the llvm.experimental.noalias.scope.decl " "intrinsic during inlining."))
llvm::AttributeList::hasFnAttr
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
Definition: Attributes.cpp:1487
llvm::ClonedCodeInfo::isSimplified
bool isSimplified(const Value *From, const Value *To) const
Definition: Cloning.h:87
MDBuilder.h
llvm::AllocaInst::getArraySize
const Value * getArraySize() const
Get the number of elements allocated.
Definition: Instructions.h:96
HandleInlinedLandingPad
static void HandleInlinedLandingPad(InvokeInst *II, BasicBlock *FirstNewBlock, ClonedCodeInfo &InlinedCodeInfo)
If we inlined an invoke site, we need to convert calls in the body of the inlined function into invok...
Definition: InlineFunction.cpp:609
llvm::BasicBlock::phis
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:364
llvm::Function::hasPersonalityFn
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:759
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1713
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:879
llvm::CallBase::getParamByValType
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
Definition: InstrTypes.h:1751
llvm::AArch64PACKey::IA
@ IA
Definition: AArch64BaseInfo.h:819
DebugLoc.h
SmallPtrSet.h
llvm::CallGraphNode
A node in the call graph for a module.
Definition: CallGraph.h:166
llvm::ValueMap::begin
iterator begin()
Definition: ValueMap.h:135
llvm::SmallVectorImpl::append
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:687
isUsedByLifetimeMarker
static bool isUsedByLifetimeMarker(Value *V)
Definition: InlineFunction.cpp:1647
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::BasicBlock::getFirstNonPHI
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:209
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1455
llvm::ValueMap::count
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: ValueMap.h:152
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
llvm::objcarc::ARCInstKind
ARCInstKind
Definition: ObjCARCInstKind.h:28
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
getParentPad
static Value * getParentPad(Value *EHPad)
Helper for getUnwindDestToken/getUnwindDestTokenHelper.
Definition: InlineFunction.cpp:238
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:284
llvm::DebugLoc::appendInlinedAt
static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inlined-at chain for this instruction so that the top of the chain now is inlined-...
Definition: DebugLoc.cpp:70
llvm::MDBuilder::createAnonymousAliasScopeDomain
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
Definition: MDBuilder.h:152
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:271
llvm::OperandBundleUse::getTagID
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
Definition: InstrTypes.h:1097
CFG.h
llvm::AllocaInst::isSwiftError
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Definition: Instructions.h:146
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::Function::getAttributes
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:314
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3810
llvm::Function::getGC
const std::string & getGC() const
Definition: Function.cpp:690
llvm::AttrBuilder::addAttribute
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
Definition: Attributes.cpp:1702
llvm::InlineAsm
Definition: InlineAsm.h:33
VectorUtils.h
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:629
BasicBlock.h
llvm::cl::opt< bool >
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::Function::getEntryCount
Optional< ProfileCount > getEntryCount(bool AllowSynthetic=false) const
Get the entry count for this function.
Definition: Function.cpp:2054
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:297
llvm::AttributeList::getRetAttrs
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
Definition: Attributes.cpp:1466
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::getUnderlyingObjects
void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
Definition: ValueTracking.cpp:4544
llvm::Instruction::eraseFromParent
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:81
llvm::Function::getReturnType
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:180
inlineDebugLoc
static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &IANodes)
Returns a DebugLoc for a new DILocation which is a clone of OrigDL inlined at InlinedAt.
Definition: InlineFunction.cpp:1683
llvm::InlineFunctionInfo::InlinedCalls
SmallVector< WeakTrackingVH, 8 > InlinedCalls
InlineFunction fills this in with callsites that were inlined from the callee.
Definition: Cloning.h:228
uint64_t
ProfileSummaryInfo.h
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:238
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:650
propagateMemProfHelper
static void propagateMemProfHelper(const CallBase *OrigCall, CallBase *ClonedCall, MDNode *InlinedCallsiteMD, std::map< const CallBase *, std::vector< Metadata * >> &OrigCallToNewMemProfMDMap)
Definition: InlineFunction.cpp:838
llvm::CallInst::TailCallKind
TailCallKind
Definition: Instructions.h:1650
hasLifetimeMarkers
static bool hasLifetimeMarkers(AllocaInst *AI)
Definition: InlineFunction.cpp:1657
llvm::Function::hasGC
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:306
llvm::PHINode::addIncoming
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Definition: Instructions.h:2848
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::BranchInst::Create
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3189
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition: DebugLoc.cpp:20
llvm::AttrBuilder
Definition: Attributes.h:1038
Cloning.h
StringExtras.h
updateMemprofMetadata
static void updateMemprofMetadata(CallBase *CI, const std::vector< Metadata * > &MIBList)
Definition: InlineFunction.cpp:818
llvm::BlockFrequency::getFrequency
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Definition: BlockFrequency.h:34
llvm::isScopedEHPersonality
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
Definition: EHPersonalities.h:79
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:447
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:716
llvm::at::trackAssignments
void trackAssignments(Function::iterator Start, Function::iterator End, const StorageToVarsMap &Vars, const DataLayout &DL, bool DebugPrints=false)
Track assignments to Vars between Start and End.
Definition: DebugInfo.cpp:1811
UpdateCallGraphAfterInlining
static void UpdateCallGraphAfterInlining(CallBase &CB, Function::iterator FirstNewBlock, ValueToValueMapTy &VMap, InlineFunctionInfo &IFI)
Once we have cloned code over from a callee into the caller, update the specified callgraph to reflec...
Definition: InlineFunction.cpp:1506
llvm::simplifyInstruction
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
Definition: InstructionSimplify.cpp:6530
llvm::Instruction::setDebugLoc
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:351
llvm::LandingPadInst::getClause
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Definition: Instructions.h:3007
AddAlignmentAssumptions
static void AddAlignmentAssumptions(CallBase &CB, InlineFunctionInfo &IFI)
If the inlined function has non-byval align arguments, then add @llvm.assume-based alignment assumpti...
Definition: InlineFunction.cpp:1468
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ValueMapIterator::ValueTypeProxy::second
ValueT & second
Definition: ValueMap.h:346
llvm::Instruction::hasMetadata
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
Definition: Instruction.h:253
llvm::CallBase::hasOperandBundles
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Definition: InstrTypes.h:1935
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:853
iterator_range.h
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
llvm::salvageKnowledge
void salvageKnowledge(Instruction *I, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert if before I.
Definition: AssumeBundleBuilder.cpp:293
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:806
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::CallBase::Create
static CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, Instruction *InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
Definition: Instructions.cpp:257
llvm::changeToInvokeAndSplitBasicBlock
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
Definition: Local.cpp:2300
llvm::isEscapeSource
bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNonEscapingLocalOb...
Definition: AliasAnalysis.cpp:907
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:383
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::User::setOperand
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
fixupAssignments
static void fixupAssignments(Function::iterator Start, Function::iterator End)
Update inlined instructions' DIAssignID metadata.
Definition: InlineFunction.cpp:1833
llvm::IRBuilderBase::CreateNoAliasScopeDeclaration
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
Definition: IRBuilder.cpp:572
llvm::CallBase::getIntrinsicID
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
Definition: Instructions.cpp:313
getDebugLoc
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
Definition: MachineInstrBundle.cpp:110
llvm::DominatorTreeBase::recalculate
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Definition: GenericDomTree.h:778
llvm::CloneAndPruneFunctionInto
void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)
This works exactly like CloneFunctionInto, except that it does some simple constant prop and DCE on t...
Definition: CloneFunction.cpp:916
llvm::memprof::getMIBStackNode
MDNode * getMIBStackNode(const MDNode *MIB)
Returns the stack node from an MIB metadata node.
Definition: MemoryProfileInfo.cpp:55
None.h
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
DataLayout.h
llvm::Function::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:242
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::CallBase::getOperandBundleAt
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
Definition: InstrTypes.h:1986
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::MDNode::concatenate
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
Definition: Metadata.cpp:1006
llvm::Instruction::getFunction
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:73
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:532
uint32_t
AddReturnAttributes
static void AddReturnAttributes(CallBase &CB, ValueToValueMapTy &VMap)
Definition: InlineFunction.cpp:1412
llvm::LLVMContext::OB_kcfi
@ OB_kcfi
Definition: LLVMContext.h:97
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1988
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Function::onlyReadsMemory
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.cpp:747
PreserveAlignmentAssumptions
static cl::opt< bool > PreserveAlignmentAssumptions("preserve-alignment-assumptions-during-inlining", cl::init(false), cl::Hidden, cl::desc("Convert align attributes to assumptions during inlining."))
llvm::objcarc::getAttachedARCFunctionKind
ARCInstKind getAttachedARCFunctionKind(const CallBase *CB)
This function returns the ARCInstKind of the function attached to operand bundle clang_arc_attachedca...
Definition: ObjCARCUtil.h:60
Profile
Load MIR Sample Profile
Definition: MIRSampleProfile.cpp:70
llvm::pred_empty
bool pred_empty(const BasicBlock *BB)
Definition: CFG.h:118
llvm::updateLoopMetadataDebugLocations
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
Definition: DebugInfo.cpp:395
llvm::IntrinsicInst::mayLowerToFunctionCall
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
Definition: IntrinsicInst.cpp:36
llvm::CallInst::isMustTailCall
bool isMustTailCall() const
Definition: Instructions.h:1672
llvm::MDTuple::getTemporary
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1377
BlockFrequencyInfo.h
llvm::MDNode::getDistinct
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1408
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:173
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:207
llvm::EHPersonality
EHPersonality
Definition: EHPersonalities.h:21
llvm::CallBase::paramHasAttr
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
Definition: Instructions.cpp:343
llvm::objcarc::GetRCIdentityRoot
const Value * GetRCIdentityRoot(const Value *V)
The RCIdentity root of a value V is a dominating value U for which retaining or releasing U is equiva...
Definition: ObjCARCAnalysisUtils.h:110
llvm::Constant::stripPointerCasts
const Constant * stripPointerCasts() const
Definition: Constant.h:209
llvm::Init
Definition: Record.h:281
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:714
llvm::ClonedCodeInfo::ContainsCalls
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
Definition: Cloning.h:64
ObjCARCAnalysisUtils.h
llvm::CallBase::doesNotThrow
bool doesNotThrow() const
Determine if the call cannot unwind.
Definition: InstrTypes.h:1889
llvm::Function::ProfileCount::getCount
uint64_t getCount() const
Definition: Function.h:261
llvm::OperandBundleUse::Inputs
ArrayRef< Use > Inputs
Definition: InstrTypes.h:1070
llvm::InlineFunctionInfo::InlinedCallSites
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
Definition: Cloning.h:235
Argument.h
HandleByValArgumentInit
static void HandleByValArgumentInit(Type *ByValType, Value *Dst, Value *Src, Module *M, BasicBlock *InsertBlock, InlineFunctionInfo &IFI)
Definition: InlineFunction.cpp:1577
llvm::BasicBlock::front
const Instruction & front() const
Definition: BasicBlock.h:318
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
llvm::MDNode::getContext
LLVMContext & getContext() const
Definition: Metadata.h:1108
ObjCARCUtil.h
llvm::BlockFrequencyInfo::setBlockFreqAndScale
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, uint64_t Freq, SmallPtrSetImpl< BasicBlock * > &BlocksToScale)
Set the frequency of ReferenceBB to Freq and scale the frequencies of the blocks in BlocksToScale suc...
Definition: BlockFrequencyInfo.cpp:233
llvm::InlineFunctionInfo::reset
void reset()
Definition: Cloning.h:241
llvm::memprof
Definition: MemoryProfileInfo.h:24
llvm::Function::getParamAlignment
uint64_t getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: Function.h:435
Constant.h
llvm::ResumeInst
Resume the propagation of an exception.
Definition: Instructions.h:4254
llvm::MDNode::replaceAllUsesWith
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:1133
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
llvm::isIdentifiedObject
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
Definition: AliasAnalysis.cpp:891
llvm::ValueMapIterator
Definition: ValueMap.h:49
llvm::None
constexpr std::nullopt_t None
Definition: None.h:27
MemoryProfileInfo.h
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:84
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::PHINode::Create
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...
Definition: Instructions.h:2740
llvm::Function::getArg
Argument * getArg(unsigned i) const
Definition: Function.h:740
llvm::CallBase::arg_size
unsigned arg_size() const
Definition: InstrTypes.h:1339
ProfileCount
Function::ProfileCount ProfileCount
Definition: InlineFunction.cpp:82
llvm::at::VarRecord
Helper struct for trackAssignments, below.
Definition: DebugInfo.h:237
llvm::isGuaranteedToTransferExecutionToSuccessor
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
Definition: ValueTracking.cpp:5471
llvm::TypeSize
Definition: TypeSize.h:435
llvm::ConstantTokenNone::get
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
Definition: Constants.cpp:1421
Casting.h
Function.h
updateCallProfile
static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap, const ProfileCount &CalleeEntryCount, const CallBase &TheCall, ProfileSummaryInfo *PSI, BlockFrequencyInfo *CallerBFI)
Update the branch metadata for cloned call instructions.
Definition: InlineFunction.cpp:1893
llvm::Value::hasNUses
bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
Definition: Value.cpp:148
llvm::InlineFunctionInfo
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
Definition: Cloning.h:203
llvm::DIAssignID::getDistinct
static DIAssignID * getDistinct(LLVMContext &Context)
Definition: DebugInfoMetadata.h:321
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:175
llvm::ValueMap::find
iterator find(const KeyT &Val)
Definition: ValueMap.h:156
llvm::Instruction::isEHPad
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:664
llvm::InlineResult::failure
static InlineResult failure(const char *Reason)
Definition: InlineCost.h:183
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:614
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition: InstrTypes.h:1389
llvm::BlockFrequencyInfo::getBlockFreq
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Definition: BlockFrequencyInfo.cpp:203
llvm::Function::getPersonalityFn
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1968
llvm::Function::arg_begin
arg_iterator arg_begin()
Definition: Function.h:722
EnableNoAliasConversion
static cl::opt< bool > EnableNoAliasConversion("enable-noalias-to-md-conversion", cl::init(true), cl::Hidden, cl::desc("Convert noalias attributes to metadata during inlining."))
llvm::IntrinsicInst
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:46
llvm::AttrBuilder::addDereferenceableAttr
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
Definition: Attributes.cpp:1765
llvm::MDBuilder
Definition: MDBuilder.h:36
llvm::Function::front
const BasicBlock & front() const
Definition: Function.h:714
CallGraph.h
llvm::DebugLoc::getLine
unsigned getLine() const
Definition: DebugLoc.cpp:24
llvm::MemoryEffects::onlyAccessesArgPointees
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
Definition: ModRef.h:200
llvm::changeToUnreachable
unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:2215
llvm::BasicBlock::getInstList
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:373
llvm::InlineFunctionInfo::StaticAllocas
SmallVector< AllocaInst *, 4 > StaticAllocas
InlineFunction fills this in with all static allocas that get copied into the caller.
Definition: Cloning.h:224
llvm::MDNode::isTemporary
bool isTemporary() const
Definition: Metadata.h:1128
Instructions.h
llvm::numbers::phi
constexpr double phi
Definition: MathExtras.h:67
llvm::AllocaInst::isUsedWithInAlloca
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
Definition: Instructions.h:136
llvm::objcarc::ARCInstKind::None
@ None
anything that is inert from an ARC perspective.
SmallVector.h
llvm::AttrBuilder::hasAttributes
bool hasAttributes() const
Return true if the builder has IR-level attributes.
Definition: Attributes.h:1097
llvm::ilist_iterator::getReverse
ilist_iterator< OptionsT, !IsReverse, IsConst > getReverse() const
Get a reverse iterator to the same node.
Definition: ilist_iterator.h:121
llvm::Instruction::getDebugLoc
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:354
User.h
llvm::InlineFunctionInfo::UpdateProfile
bool UpdateProfile
Update profile for callee as well as cloned version.
Definition: Cloning.h:239
llvm::memprof::CallStackTrie
Class to build a trie of call stack contexts for a particular profiled allocation call,...
Definition: MemoryProfileInfo.h:45
trackInlinedStores
static void trackInlinedStores(Function::iterator Start, Function::iterator End, const CallBase &CB)
Definition: InlineFunction.cpp:1821
Dominators.h
llvm::DIAssignID
Assignment ID.
Definition: DebugInfoMetadata.h:303
NoAliases
static cl::opt< bool > NoAliases("csky-no-aliases", cl::desc("Disable the emission of assembler pseudo instructions"), cl::init(false), cl::Hidden)
updateCallerBFI
static void updateCallerBFI(BasicBlock *CallSiteBlock, const ValueToValueMapTy &VMap, BlockFrequencyInfo *CallerBFI, BlockFrequencyInfo *CalleeBFI, const BasicBlock &CalleeEntryBlock)
Update the block frequencies of the caller after a callee has been inlined.
Definition: InlineFunction.cpp:1864
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1341
haveCommonPrefix
static bool haveCommonPrefix(MDNode *MIBStackContext, MDNode *CallsiteStackContext)
Definition: InlineFunction.cpp:789
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::MDNode::op_end
op_iterator op_end() const
Definition: Metadata.h:1286
InstructionSimplify.h
llvm::SmallVectorImpl::pop_back_val
T pop_back_val()
Definition: SmallVector.h:677
llvm::PHINode
Definition: Instructions.h:2698
llvm::BasicBlock::getTerminator
const Instruction * 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.h:119
llvm::BasicBlock::removePredecessor
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Definition: BasicBlock.cpp:342
inlineRetainOrClaimRVCalls
static void inlineRetainOrClaimRVCalls(CallBase &CB, objcarc::ARCInstKind RVCallKind, const SmallVectorImpl< ReturnInst * > &Returns)
An operand bundle "clang.arc.attachedcall" on a call indicates the call result is implicitly consumed...
Definition: InlineFunction.cpp:1960
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:399
DerivedTypes.h
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1473
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::ValueMap::lookup
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: ValueMap.h:165
LLVMContext.h
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:381
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::AttributeFuncs::mergeAttributesForInlining
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
Definition: Attributes.cpp:2134
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:58
llvm::Function::ProfileCount
Class to represent profile counts.
Definition: Function.h:253
llvm::DebugLoc::getScope
MDNode * getScope() const
Definition: DebugLoc.cpp:34
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::InlineFunctionInfo::GetAssumptionCache
function_ref< AssumptionCache &(Function &)> GetAssumptionCache
Definition: Cloning.h:218
llvm::BasicBlock::getTerminatingMustTailCall
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:151
llvm::cl::desc
Definition: CommandLine.h:413
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition: Instructions.h:3133
InlinerAttributeWindow
static cl::opt< unsigned > InlinerAttributeWindow("max-inst-checked-for-throw-during-inlining", cl::Hidden, cl::desc("the maximum number of instructions analyzed for may throw during " "attribute inference in inlined body"), cl::init(4))
llvm::ClonedCodeInfo::ContainsDynamicAllocas
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
Definition: Cloning.h:73
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
collectEscapedLocals
static at::StorageToVarsMap collectEscapedLocals(const DataLayout &DL, const CallBase &CB)
Find Alloca and linked DbgAssignIntrinsic for locals escaped by CB.
Definition: InlineFunction.cpp:1773
llvm::AttributeList::getParamAttrs
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
Definition: Attributes.cpp:1462
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:667
llvm::CallInst::TCK_NoTail
@ TCK_NoTail
Definition: Instructions.h:1654
llvm::IRBuilderBase::CreateAlignmentAssumption
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
Definition: IRBuilder.cpp:1382
Value.h
llvm::InvokeInst::getUnwindDest
BasicBlock * getUnwindDest() const
Definition: Instructions.h:3945
llvm::InlineFunctionInfo::CalleeBFI
BlockFrequencyInfo * CalleeBFI
Definition: Cloning.h:220
llvm::MDNode::op_begin
op_iterator op_begin() const
Definition: Metadata.h:1282
llvm::PointerMayBeCapturedBefore
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, const DominatorTree *DT, bool IncludeI=false, unsigned MaxUsesToExplore=0, const LoopInfo *LI=nullptr)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...
Definition: CaptureTracking.cpp:269
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::AtomicCmpXchgInst
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:509
llvm::InlineResult
InlineResult is basically true or false.
Definition: InlineCost.h:177
llvm::Value::users
iterator_range< user_iterator > users()
Definition: Value.h:421
llvm::CallInst::getTailCallKind
TailCallKind getTailCallKind() const
Definition: Instructions.h:1663
llvm::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2269
llvm::CallBase::args
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
Definition: InstrTypes.h:1332
SetVector.h
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1459
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
llvm::Function::iterator
BasicBlockListType::iterator iterator
Definition: Function.h:66
llvm::SmallPtrSetImpl::insert
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:365
llvm::CallGraphNode::begin
iterator begin()
Definition: CallGraph.h:199
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1732