LLVM  5.0.0
CoroSplit.cpp
Go to the documentation of this file.
1 //===- CoroSplit.cpp - Converts a coroutine into a state machine ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // This pass builds the coroutine frame and outlines resume and destroy parts
10 // of the coroutine into separate functions.
11 //
12 // We present a coroutine to an LLVM as an ordinary function with suspension
13 // points marked up with intrinsics. We let the optimizer party on the coroutine
14 // as a single function for as long as possible. Shortly before the coroutine is
15 // eligible to be inlined into its callers, we split up the coroutine into parts
16 // corresponding to an initial, resume and destroy invocations of the coroutine,
17 // add them to the current SCC and restart the IPO pipeline to optimize the
18 // coroutine subfunctions we extracted before proceeding to the caller of the
19 // coroutine.
20 //===----------------------------------------------------------------------===//
21 
22 #include "CoroInternal.h"
25 #include "llvm/IR/IRBuilder.h"
26 #include "llvm/IR/InstIterator.h"
28 #include "llvm/IR/Verifier.h"
29 #include "llvm/Transforms/Scalar.h"
33 
34 using namespace llvm;
35 
36 #define DEBUG_TYPE "coro-split"
37 
38 // Create an entry block for a resume function with a switch that will jump to
39 // suspend points.
41  LLVMContext &C = F.getContext();
42 
43  // resume.entry:
44  // %index.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0,
45  // i32 2
46  // % index = load i32, i32* %index.addr
47  // switch i32 %index, label %unreachable [
48  // i32 0, label %resume.0
49  // i32 1, label %resume.1
50  // ...
51  // ]
52 
53  auto *NewEntry = BasicBlock::Create(C, "resume.entry", &F);
54  auto *UnreachBB = BasicBlock::Create(C, "unreachable", &F);
55 
56  IRBuilder<> Builder(NewEntry);
57  auto *FramePtr = Shape.FramePtr;
58  auto *FrameTy = Shape.FrameTy;
59  auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(
60  FrameTy, FramePtr, 0, coro::Shape::IndexField, "index.addr");
61  auto *Index = Builder.CreateLoad(GepIndex, "index");
62  auto *Switch =
63  Builder.CreateSwitch(Index, UnreachBB, Shape.CoroSuspends.size());
64  Shape.ResumeSwitch = Switch;
65 
66  size_t SuspendIndex = 0;
67  for (CoroSuspendInst *S : Shape.CoroSuspends) {
68  ConstantInt *IndexVal = Shape.getIndex(SuspendIndex);
69 
70  // Replace CoroSave with a store to Index:
71  // %index.addr = getelementptr %f.frame... (index field number)
72  // store i32 0, i32* %index.addr1
73  auto *Save = S->getCoroSave();
74  Builder.SetInsertPoint(Save);
75  if (S->isFinal()) {
76  // Final suspend point is represented by storing zero in ResumeFnAddr.
77  auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0,
78  0, "ResumeFn.addr");
79  auto *NullPtr = ConstantPointerNull::get(cast<PointerType>(
80  cast<PointerType>(GepIndex->getType())->getElementType()));
81  Builder.CreateStore(NullPtr, GepIndex);
82  } else {
83  auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(
84  FrameTy, FramePtr, 0, coro::Shape::IndexField, "index.addr");
85  Builder.CreateStore(IndexVal, GepIndex);
86  }
88  Save->eraseFromParent();
89 
90  // Split block before and after coro.suspend and add a jump from an entry
91  // switch:
92  //
93  // whateverBB:
94  // whatever
95  // %0 = call i8 @llvm.coro.suspend(token none, i1 false)
96  // switch i8 %0, label %suspend[i8 0, label %resume
97  // i8 1, label %cleanup]
98  // becomes:
99  //
100  // whateverBB:
101  // whatever
102  // br label %resume.0.landing
103  //
104  // resume.0: ; <--- jump from the switch in the resume.entry
105  // %0 = tail call i8 @llvm.coro.suspend(token none, i1 false)
106  // br label %resume.0.landing
107  //
108  // resume.0.landing:
109  // %1 = phi i8[-1, %whateverBB], [%0, %resume.0]
110  // switch i8 % 1, label %suspend [i8 0, label %resume
111  // i8 1, label %cleanup]
112 
113  auto *SuspendBB = S->getParent();
114  auto *ResumeBB =
115  SuspendBB->splitBasicBlock(S, "resume." + Twine(SuspendIndex));
116  auto *LandingBB = ResumeBB->splitBasicBlock(
117  S->getNextNode(), ResumeBB->getName() + Twine(".landing"));
118  Switch->addCase(IndexVal, ResumeBB);
119 
120  cast<BranchInst>(SuspendBB->getTerminator())->setSuccessor(0, LandingBB);
121  auto *PN = PHINode::Create(Builder.getInt8Ty(), 2, "", &LandingBB->front());
122  S->replaceAllUsesWith(PN);
123  PN->addIncoming(Builder.getInt8(-1), SuspendBB);
124  PN->addIncoming(S, ResumeBB);
125 
126  ++SuspendIndex;
127  }
128 
129  Builder.SetInsertPoint(UnreachBB);
130  Builder.CreateUnreachable();
131 
132  return NewEntry;
133 }
134 
135 // In Resumers, we replace fallthrough coro.end with ret void and delete the
136 // rest of the block.
138  ValueToValueMapTy &VMap) {
139  auto *NewE = cast<IntrinsicInst>(VMap[End]);
140  ReturnInst::Create(NewE->getContext(), nullptr, NewE);
141 
142  // Remove the rest of the block, by splitting it into an unreachable block.
143  auto *BB = NewE->getParent();
144  BB->splitBasicBlock(NewE);
146 }
147 
148 // In Resumers, we replace unwind coro.end with True to force the immediate
149 // unwind to caller.
151  if (Shape.CoroEnds.empty())
152  return;
153 
154  LLVMContext &Context = Shape.CoroEnds.front()->getContext();
155  auto *True = ConstantInt::getTrue(Context);
156  for (CoroEndInst *CE : Shape.CoroEnds) {
157  if (!CE->isUnwind())
158  continue;
159 
160  auto *NewCE = cast<IntrinsicInst>(VMap[CE]);
161 
162  // If coro.end has an associated bundle, add cleanupret instruction.
163  if (auto Bundle = NewCE->getOperandBundle(LLVMContext::OB_funclet)) {
164  Value *FromPad = Bundle->Inputs[0];
165  auto *CleanupRet = CleanupReturnInst::Create(FromPad, nullptr, NewCE);
166  NewCE->getParent()->splitBasicBlock(NewCE);
167  CleanupRet->getParent()->getTerminator()->eraseFromParent();
168  }
169 
170  NewCE->replaceAllUsesWith(True);
171  NewCE->eraseFromParent();
172  }
173 }
174 
175 // Rewrite final suspend point handling. We do not use suspend index to
176 // represent the final suspend point. Instead we zero-out ResumeFnAddr in the
177 // coroutine frame, since it is undefined behavior to resume a coroutine
178 // suspended at the final suspend point. Thus, in the resume function, we can
179 // simply remove the last case (when coro::Shape is built, the final suspend
180 // point (if present) is always the last element of CoroSuspends array).
181 // In the destroy function, we add a code sequence to check if ResumeFnAddress
182 // is Null, and if so, jump to the appropriate label to handle cleanup from the
183 // final suspend point.
185  coro::Shape &Shape, SwitchInst *Switch,
186  bool IsDestroy) {
187  assert(Shape.HasFinalSuspend);
188  auto FinalCaseIt = std::prev(Switch->case_end());
189  BasicBlock *ResumeBB = FinalCaseIt->getCaseSuccessor();
190  Switch->removeCase(FinalCaseIt);
191  if (IsDestroy) {
192  BasicBlock *OldSwitchBB = Switch->getParent();
193  auto *NewSwitchBB = OldSwitchBB->splitBasicBlock(Switch, "Switch");
194  Builder.SetInsertPoint(OldSwitchBB->getTerminator());
195  auto *GepIndex = Builder.CreateConstInBoundsGEP2_32(Shape.FrameTy, FramePtr,
196  0, 0, "ResumeFn.addr");
197  auto *Load = Builder.CreateLoad(GepIndex);
198  auto *NullPtr =
199  ConstantPointerNull::get(cast<PointerType>(Load->getType()));
200  auto *Cond = Builder.CreateICmpEQ(Load, NullPtr);
201  Builder.CreateCondBr(Cond, ResumeBB, NewSwitchBB);
202  OldSwitchBB->getTerminator()->eraseFromParent();
203  }
204 }
205 
206 // Create a resume clone by cloning the body of the original function, setting
207 // new entry block and replacing coro.suspend an appropriate value to force
208 // resume or cleanup pass for every suspend point.
209 static Function *createClone(Function &F, Twine Suffix, coro::Shape &Shape,
210  BasicBlock *ResumeEntry, int8_t FnIndex) {
211  Module *M = F.getParent();
212  auto *FrameTy = Shape.FrameTy;
213  auto *FnPtrTy = cast<PointerType>(FrameTy->getElementType(0));
214  auto *FnTy = cast<FunctionType>(FnPtrTy->getElementType());
215 
216  Function *NewF =
217  Function::Create(FnTy, GlobalValue::LinkageTypes::InternalLinkage,
218  F.getName() + Suffix, M);
219  NewF->addParamAttr(0, Attribute::NonNull);
220  NewF->addParamAttr(0, Attribute::NoAlias);
221 
222  ValueToValueMapTy VMap;
223  // Replace all args with undefs. The buildCoroutineFrame algorithm already
224  // rewritten access to the args that occurs after suspend points with loads
225  // and stores to/from the coroutine frame.
226  for (Argument &A : F.args())
227  VMap[&A] = UndefValue::get(A.getType());
228 
230 
231  CloneFunctionInto(NewF, &F, VMap, /*ModuleLevelChanges=*/true, Returns);
232 
233  // Remove old returns.
234  for (ReturnInst *Return : Returns)
235  changeToUnreachable(Return, /*UseLLVMTrap=*/false);
236 
237  // Remove old return attributes.
238  NewF->removeAttributes(
240  AttributeFuncs::typeIncompatible(NewF->getReturnType()));
241 
242  // Make AllocaSpillBlock the new entry block.
243  auto *SwitchBB = cast<BasicBlock>(VMap[ResumeEntry]);
244  auto *Entry = cast<BasicBlock>(VMap[Shape.AllocaSpillBlock]);
245  Entry->moveBefore(&NewF->getEntryBlock());
246  Entry->getTerminator()->eraseFromParent();
247  BranchInst::Create(SwitchBB, Entry);
248  Entry->setName("entry" + Suffix);
249 
250  // Clear all predecessors of the new entry block.
251  auto *Switch = cast<SwitchInst>(VMap[Shape.ResumeSwitch]);
252  Entry->replaceAllUsesWith(Switch->getDefaultDest());
253 
254  IRBuilder<> Builder(&NewF->getEntryBlock().front());
255 
256  // Remap frame pointer.
257  Argument *NewFramePtr = &*NewF->arg_begin();
258  Value *OldFramePtr = cast<Value>(VMap[Shape.FramePtr]);
259  NewFramePtr->takeName(OldFramePtr);
260  OldFramePtr->replaceAllUsesWith(NewFramePtr);
261 
262  // Remap vFrame pointer.
263  auto *NewVFrame = Builder.CreateBitCast(
264  NewFramePtr, Type::getInt8PtrTy(Builder.getContext()), "vFrame");
265  Value *OldVFrame = cast<Value>(VMap[Shape.CoroBegin]);
266  OldVFrame->replaceAllUsesWith(NewVFrame);
267 
268  // Rewrite final suspend handling as it is not done via switch (allows to
269  // remove final case from the switch, since it is undefined behavior to resume
270  // the coroutine suspended at the final suspend point.
271  if (Shape.HasFinalSuspend) {
272  auto *Switch = cast<SwitchInst>(VMap[Shape.ResumeSwitch]);
273  bool IsDestroy = FnIndex != 0;
274  handleFinalSuspend(Builder, NewFramePtr, Shape, Switch, IsDestroy);
275  }
276 
277  // Replace coro suspend with the appropriate resume index.
278  // Replacing coro.suspend with (0) will result in control flow proceeding to
279  // a resume label associated with a suspend point, replacing it with (1) will
280  // result in control flow proceeding to a cleanup label associated with this
281  // suspend point.
282  auto *NewValue = Builder.getInt8(FnIndex ? 1 : 0);
283  for (CoroSuspendInst *CS : Shape.CoroSuspends) {
284  auto *MappedCS = cast<CoroSuspendInst>(VMap[CS]);
285  MappedCS->replaceAllUsesWith(NewValue);
286  MappedCS->eraseFromParent();
287  }
288 
289  // Remove coro.end intrinsics.
290  replaceFallthroughCoroEnd(Shape.CoroEnds.front(), VMap);
291  replaceUnwindCoroEnds(Shape, VMap);
292  // Eliminate coro.free from the clones, replacing it with 'null' in cleanup,
293  // to suppress deallocation code.
294  coro::replaceCoroFree(cast<CoroIdInst>(VMap[Shape.CoroBegin->getId()]),
295  /*Elide=*/FnIndex == 2);
296 
297  NewF->setCallingConv(CallingConv::Fast);
298 
299  return NewF;
300 }
301 
302 static void removeCoroEnds(coro::Shape &Shape) {
303  if (Shape.CoroEnds.empty())
304  return;
305 
306  LLVMContext &Context = Shape.CoroEnds.front()->getContext();
307  auto *False = ConstantInt::getFalse(Context);
308 
309  for (CoroEndInst *CE : Shape.CoroEnds) {
310  CE->replaceAllUsesWith(False);
311  CE->eraseFromParent();
312  }
313 }
314 
315 static void replaceFrameSize(coro::Shape &Shape) {
316  if (Shape.CoroSizes.empty())
317  return;
318 
319  // In the same function all coro.sizes should have the same result type.
320  auto *SizeIntrin = Shape.CoroSizes.back();
321  Module *M = SizeIntrin->getModule();
322  const DataLayout &DL = M->getDataLayout();
323  auto Size = DL.getTypeAllocSize(Shape.FrameTy);
324  auto *SizeConstant = ConstantInt::get(SizeIntrin->getType(), Size);
325 
326  for (CoroSizeInst *CS : Shape.CoroSizes) {
327  CS->replaceAllUsesWith(SizeConstant);
328  CS->eraseFromParent();
329  }
330 }
331 
332 // Create a global constant array containing pointers to functions provided and
333 // set Info parameter of CoroBegin to point at this constant. Example:
334 //
335 // @f.resumers = internal constant [2 x void(%f.frame*)*]
336 // [void(%f.frame*)* @f.resume, void(%f.frame*)* @f.destroy]
337 // define void @f() {
338 // ...
339 // call i8* @llvm.coro.begin(i8* null, i32 0, i8* null,
340 // i8* bitcast([2 x void(%f.frame*)*] * @f.resumers to i8*))
341 //
342 // Assumes that all the functions have the same signature.
343 static void setCoroInfo(Function &F, CoroBeginInst *CoroBegin,
344  std::initializer_list<Function *> Fns) {
345 
346  SmallVector<Constant *, 4> Args(Fns.begin(), Fns.end());
347  assert(!Args.empty());
348  Function *Part = *Fns.begin();
349  Module *M = Part->getParent();
350  auto *ArrTy = ArrayType::get(Part->getType(), Args.size());
351 
352  auto *ConstVal = ConstantArray::get(ArrTy, Args);
353  auto *GV = new GlobalVariable(*M, ConstVal->getType(), /*isConstant=*/true,
355  F.getName() + Twine(".resumers"));
356 
357  // Update coro.begin instruction to refer to this constant.
358  LLVMContext &C = F.getContext();
360  CoroBegin->getId()->setInfo(BC);
361 }
362 
363 // Store addresses of Resume/Destroy/Cleanup functions in the coroutine frame.
364 static void updateCoroFrame(coro::Shape &Shape, Function *ResumeFn,
365  Function *DestroyFn, Function *CleanupFn) {
366 
367  IRBuilder<> Builder(Shape.FramePtr->getNextNode());
368  auto *ResumeAddr = Builder.CreateConstInBoundsGEP2_32(
369  Shape.FrameTy, Shape.FramePtr, 0, coro::Shape::ResumeField,
370  "resume.addr");
371  Builder.CreateStore(ResumeFn, ResumeAddr);
372 
373  Value *DestroyOrCleanupFn = DestroyFn;
374 
375  CoroIdInst *CoroId = Shape.CoroBegin->getId();
376  if (CoroAllocInst *CA = CoroId->getCoroAlloc()) {
377  // If there is a CoroAlloc and it returns false (meaning we elide the
378  // allocation, use CleanupFn instead of DestroyFn).
379  DestroyOrCleanupFn = Builder.CreateSelect(CA, DestroyFn, CleanupFn);
380  }
381 
382  auto *DestroyAddr = Builder.CreateConstInBoundsGEP2_32(
383  Shape.FrameTy, Shape.FramePtr, 0, coro::Shape::DestroyField,
384  "destroy.addr");
385  Builder.CreateStore(DestroyOrCleanupFn, DestroyAddr);
386 }
387 
388 static void postSplitCleanup(Function &F) {
391 
392  FPM.add(createVerifierPass());
393  FPM.add(createSCCPPass());
394  FPM.add(createCFGSimplificationPass());
395  FPM.add(createEarlyCSEPass());
396  FPM.add(createCFGSimplificationPass());
397 
398  FPM.doInitialization();
399  FPM.run(F);
400  FPM.doFinalization();
401 }
402 
403 // Coroutine has no suspend points. Remove heap allocation for the coroutine
404 // frame if possible.
405 static void handleNoSuspendCoroutine(CoroBeginInst *CoroBegin, Type *FrameTy) {
406  auto *CoroId = CoroBegin->getId();
407  auto *AllocInst = CoroId->getCoroAlloc();
408  coro::replaceCoroFree(CoroId, /*Elide=*/AllocInst != nullptr);
409  if (AllocInst) {
410  IRBuilder<> Builder(AllocInst);
411  // FIXME: Need to handle overaligned members.
412  auto *Frame = Builder.CreateAlloca(FrameTy);
413  auto *VFrame = Builder.CreateBitCast(Frame, Builder.getInt8PtrTy());
414  AllocInst->replaceAllUsesWith(Builder.getFalse());
415  AllocInst->eraseFromParent();
416  CoroBegin->replaceAllUsesWith(VFrame);
417  } else {
418  CoroBegin->replaceAllUsesWith(CoroBegin->getMem());
419  }
420  CoroBegin->eraseFromParent();
421 }
422 
423 // look for a very simple pattern
424 // coro.save
425 // no other calls
426 // resume or destroy call
427 // coro.suspend
428 //
429 // If there are other calls between coro.save and coro.suspend, they can
430 // potentially resume or destroy the coroutine, so it is unsafe to eliminate a
431 // suspend point.
433  CoroBeginInst *CoroBegin) {
434  auto *Save = Suspend->getCoroSave();
435  auto *BB = Suspend->getParent();
436  if (BB != Save->getParent())
437  return false;
438 
439  CallSite SingleCallSite;
440 
441  // Check that we have only one CallSite.
442  for (Instruction *I = Save->getNextNode(); I != Suspend;
443  I = I->getNextNode()) {
444  if (isa<CoroFrameInst>(I))
445  continue;
446  if (isa<CoroSubFnInst>(I))
447  continue;
448  if (CallSite CS = CallSite(I)) {
449  if (SingleCallSite)
450  return false;
451  else
452  SingleCallSite = CS;
453  }
454  }
455  auto *CallInstr = SingleCallSite.getInstruction();
456  if (!CallInstr)
457  return false;
458 
459  auto *Callee = SingleCallSite.getCalledValue()->stripPointerCasts();
460 
461  // See if the callsite is for resumption or destruction of the coroutine.
462  auto *SubFn = dyn_cast<CoroSubFnInst>(Callee);
463  if (!SubFn)
464  return false;
465 
466  // Does not refer to the current coroutine, we cannot do anything with it.
467  if (SubFn->getFrame() != CoroBegin)
468  return false;
469 
470  // Replace llvm.coro.suspend with the value that results in resumption over
471  // the resume or cleanup path.
472  Suspend->replaceAllUsesWith(SubFn->getRawIndex());
473  Suspend->eraseFromParent();
474  Save->eraseFromParent();
475 
476  // No longer need a call to coro.resume or coro.destroy.
477  CallInstr->eraseFromParent();
478 
479  if (SubFn->user_empty())
480  SubFn->eraseFromParent();
481 
482  return true;
483 }
484 
485 // Remove suspend points that are simplified.
486 static void simplifySuspendPoints(coro::Shape &Shape) {
487  auto &S = Shape.CoroSuspends;
488  size_t I = 0, N = S.size();
489  if (N == 0)
490  return;
491  for (;;) {
492  if (simplifySuspendPoint(S[I], Shape.CoroBegin)) {
493  if (--N == I)
494  break;
495  std::swap(S[I], S[N]);
496  continue;
497  }
498  if (++I == N)
499  break;
500  }
501  S.resize(N);
502 }
503 
505  // Collect all blocks that we need to look for instructions to relocate.
506  SmallPtrSet<BasicBlock *, 4> RelocBlocks;
508  Work.push_back(CB->getParent());
509 
510  do {
511  BasicBlock *Current = Work.pop_back_val();
512  for (BasicBlock *BB : predecessors(Current))
513  if (RelocBlocks.count(BB) == 0) {
514  RelocBlocks.insert(BB);
515  Work.push_back(BB);
516  }
517  } while (!Work.empty());
518  return RelocBlocks;
519 }
520 
523  SmallPtrSetImpl<BasicBlock *> &RelocBlocks) {
524  SmallPtrSet<Instruction *, 8> DoNotRelocate;
525  // Collect all instructions that we should not relocate
527 
528  // Start with CoroBegin and terminators of all preceding blocks.
529  Work.push_back(CoroBegin);
530  BasicBlock *CoroBeginBB = CoroBegin->getParent();
531  for (BasicBlock *BB : RelocBlocks)
532  if (BB != CoroBeginBB)
533  Work.push_back(BB->getTerminator());
534 
535  // For every instruction in the Work list, place its operands in DoNotRelocate
536  // set.
537  do {
538  Instruction *Current = Work.pop_back_val();
539  DoNotRelocate.insert(Current);
540  for (Value *U : Current->operands()) {
541  auto *I = dyn_cast<Instruction>(U);
542  if (!I)
543  continue;
544  if (isa<AllocaInst>(U))
545  continue;
546  if (DoNotRelocate.count(I) == 0) {
547  Work.push_back(I);
548  DoNotRelocate.insert(I);
549  }
550  }
551  } while (!Work.empty());
552  return DoNotRelocate;
553 }
554 
556  // Analyze which non-alloca instructions are needed for allocation and
557  // relocate the rest to after coro.begin. We need to do it, since some of the
558  // targets of those instructions may be placed into coroutine frame memory
559  // for which becomes available after coro.begin intrinsic.
560 
561  auto BlockSet = getCoroBeginPredBlocks(CoroBegin);
562  auto DoNotRelocateSet = getNotRelocatableInstructions(CoroBegin, BlockSet);
563 
564  Instruction *InsertPt = CoroBegin->getNextNode();
565  BasicBlock &BB = F.getEntryBlock(); // TODO: Look at other blocks as well.
566  for (auto B = BB.begin(), E = BB.end(); B != E;) {
567  Instruction &I = *B++;
568  if (isa<AllocaInst>(&I))
569  continue;
570  if (&I == CoroBegin)
571  break;
572  if (DoNotRelocateSet.count(&I))
573  continue;
574  I.moveBefore(InsertPt);
575  }
576 }
577 
578 static void splitCoroutine(Function &F, CallGraph &CG, CallGraphSCC &SCC) {
579  coro::Shape Shape(F);
580  if (!Shape.CoroBegin)
581  return;
582 
583  simplifySuspendPoints(Shape);
585  buildCoroutineFrame(F, Shape);
586  replaceFrameSize(Shape);
587 
588  // If there are no suspend points, no split required, just remove
589  // the allocation and deallocation blocks, they are not needed.
590  if (Shape.CoroSuspends.empty()) {
592  removeCoroEnds(Shape);
593  postSplitCleanup(F);
594  coro::updateCallGraph(F, {}, CG, SCC);
595  return;
596  }
597 
598  auto *ResumeEntry = createResumeEntryBlock(F, Shape);
599  auto ResumeClone = createClone(F, ".resume", Shape, ResumeEntry, 0);
600  auto DestroyClone = createClone(F, ".destroy", Shape, ResumeEntry, 1);
601  auto CleanupClone = createClone(F, ".cleanup", Shape, ResumeEntry, 2);
602 
603  // We no longer need coro.end in F.
604  removeCoroEnds(Shape);
605 
606  postSplitCleanup(F);
607  postSplitCleanup(*ResumeClone);
608  postSplitCleanup(*DestroyClone);
609  postSplitCleanup(*CleanupClone);
610 
611  // Store addresses resume/destroy/cleanup functions in the coroutine frame.
612  updateCoroFrame(Shape, ResumeClone, DestroyClone, CleanupClone);
613 
614  // Create a constant array referring to resume/destroy/clone functions pointed
615  // by the last argument of @llvm.coro.info, so that CoroElide pass can
616  // determined correct function to call.
617  setCoroInfo(F, Shape.CoroBegin, {ResumeClone, DestroyClone, CleanupClone});
618 
619  // Update call graph and add the functions we created to the SCC.
620  coro::updateCallGraph(F, {ResumeClone, DestroyClone, CleanupClone}, CG, SCC);
621 }
622 
623 // When we see the coroutine the first time, we insert an indirect call to a
624 // devirt trigger function and mark the coroutine that it is now ready for
625 // split.
626 static void prepareForSplit(Function &F, CallGraph &CG) {
627  Module &M = *F.getParent();
628 #ifndef NDEBUG
630  assert(DevirtFn && "coro.devirt.trigger function not found");
631 #endif
632 
634 
635  // Insert an indirect call sequence that will be devirtualized by CoroElide
636  // pass:
637  // %0 = call i8* @llvm.coro.subfn.addr(i8* null, i8 -1)
638  // %1 = bitcast i8* %0 to void(i8*)*
639  // call void %1(i8* null)
640  coro::LowererBase Lowerer(M);
641  Instruction *InsertPt = F.getEntryBlock().getTerminator();
642  auto *Null = ConstantPointerNull::get(Type::getInt8PtrTy(F.getContext()));
643  auto *DevirtFnAddr =
644  Lowerer.makeSubFnCall(Null, CoroSubFnInst::RestartTrigger, InsertPt);
645  auto *IndirectCall = CallInst::Create(DevirtFnAddr, Null, "", InsertPt);
646 
647  // Update CG graph with an indirect call we just added.
648  CG[&F]->addCalledFunction(IndirectCall, CG.getCallsExternalNode());
649 }
650 
651 // Make sure that there is a devirtualization trigger function that CoroSplit
652 // pass uses the force restart CGSCC pipeline. If devirt trigger function is not
653 // found, we will create one and add it to the current SCC.
655  Module &M = CG.getModule();
657  return;
658 
659  LLVMContext &C = M.getContext();
660  auto *FnTy = FunctionType::get(Type::getVoidTy(C), Type::getInt8PtrTy(C),
661  /*IsVarArgs=*/false);
662  Function *DevirtFn =
663  Function::Create(FnTy, GlobalValue::LinkageTypes::PrivateLinkage,
665  DevirtFn->addFnAttr(Attribute::AlwaysInline);
666  auto *Entry = BasicBlock::Create(C, "entry", DevirtFn);
667  ReturnInst::Create(C, Entry);
668 
669  auto *Node = CG.getOrInsertFunction(DevirtFn);
670 
671  SmallVector<CallGraphNode *, 8> Nodes(SCC.begin(), SCC.end());
672  Nodes.push_back(Node);
673  SCC.initialize(Nodes);
674 }
675 
676 //===----------------------------------------------------------------------===//
677 // Top Level Driver
678 //===----------------------------------------------------------------------===//
679 
680 namespace {
681 
682 struct CoroSplit : public CallGraphSCCPass {
683  static char ID; // Pass identification, replacement for typeid
684  CoroSplit() : CallGraphSCCPass(ID) {
685  initializeCoroSplitPass(*PassRegistry::getPassRegistry());
686  }
687 
688  bool Run = false;
689 
690  // A coroutine is identified by the presence of coro.begin intrinsic, if
691  // we don't have any, this pass has nothing to do.
692  bool doInitialization(CallGraph &CG) override {
693  Run = coro::declaresIntrinsics(CG.getModule(), {"llvm.coro.begin"});
695  }
696 
697  bool runOnSCC(CallGraphSCC &SCC) override {
698  if (!Run)
699  return false;
700 
701  // Find coroutines for processing.
702  SmallVector<Function *, 4> Coroutines;
703  for (CallGraphNode *CGN : SCC)
704  if (auto *F = CGN->getFunction())
705  if (F->hasFnAttribute(CORO_PRESPLIT_ATTR))
706  Coroutines.push_back(F);
707 
708  if (Coroutines.empty())
709  return false;
710 
711  CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
712  createDevirtTriggerFunc(CG, SCC);
713 
714  for (Function *F : Coroutines) {
715  Attribute Attr = F->getFnAttribute(CORO_PRESPLIT_ATTR);
717  DEBUG(dbgs() << "CoroSplit: Processing coroutine '" << F->getName()
718  << "' state: " << Value << "\n");
719  if (Value == UNPREPARED_FOR_SPLIT) {
720  prepareForSplit(*F, CG);
721  continue;
722  }
723  F->removeFnAttr(CORO_PRESPLIT_ATTR);
724  splitCoroutine(*F, CG, SCC);
725  }
726  return true;
727  }
728 
729  void getAnalysisUsage(AnalysisUsage &AU) const override {
731  }
732  StringRef getPassName() const override { return "Coroutine Splitting"; }
733 };
734 }
735 
736 char CoroSplit::ID = 0;
738  CoroSplit, "coro-split",
739  "Split coroutine into a set of functions driving its state machine", false,
740  false)
741 
742 Pass *llvm::createCoroSplitPass() { return new CoroSplit(); }
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:69
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:523
static void createDevirtTriggerFunc(CallGraph &CG, CallGraphSCC &SCC)
Definition: CoroSplit.cpp:654
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Definition: IRBuilder.h:775
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
Instruction * FramePtr
Definition: CoroInternal.h:83
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
LLVMContext & Context
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition: IRBuilder.h:1152
CoroBeginInst * CoroBegin
Definition: CoroInternal.h:68
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
This represents the llvm.coro.alloc instruction.
Definition: CoroInstr.h:82
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition: Function.cpp:365
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
static void splitCoroutine(Function &F, CallGraph &CG, CallGraphSCC &SCC)
Definition: CoroSplit.cpp:578
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:527
static void setCoroInfo(Function &F, CoroBeginInst *CoroBegin, std::initializer_list< Function * > Fns)
Definition: CoroSplit.cpp:343
DataLayout DL
Pass * createCoroSplitPass()
Split up coroutines into multiple functions driving their state machines.
INITIALIZE_PASS(CoroSplit,"coro-split","Split coroutine into a set of functions driving its state machine", false, false) Pass *llvm
Definition: CoroSplit.cpp:737
static void relocateInstructionBefore(CoroBeginInst *CoroBegin, Function &F)
Definition: CoroSplit.cpp:555
virtual bool doInitialization(CallGraph &CG)
doInitialization - This method is called before the SCC's of the program has been processed...
FunctionPass * createVerifierPass(bool FatalErrors=true)
Definition: Verifier.cpp:4974
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:57
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:67
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
static void replaceFrameSize(coro::Shape &Shape)
Definition: CoroSplit.cpp:315
void initialize(ArrayRef< CallGraphNode * > NewNodes)
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:1393
A node in the call graph for a module.
Definition: CallGraph.h:161
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
Module & getModule() const
Returns the module the call graph corresponds to.
Definition: CallGraph.h:110
ConstantInt * getIndex(uint64_t Value) const
Definition: CoroInternal.h:93
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:218
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:345
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:252
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
static bool simplifySuspendPoint(CoroSuspendInst *Suspend, CoroBeginInst *CoroBegin)
Definition: CoroSplit.cpp:432
iterator end() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static void handleNoSuspendCoroutine(CoroBeginInst *CoroBegin, Type *FrameTy)
Definition: CoroSplit.cpp:405
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:97
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values...
This represents the llvm.coro.suspend instruction.
Definition: CoroInstr.h:266
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
FunctionPass * createSCCPPass()
Definition: SCCP.cpp:1700
CoroIdInst * getId() const
Definition: CoroInstr.h:219
This class represents the llvm.coro.subfn.addr instruction.
Definition: CoroInstr.h:35
#define PREPARED_FOR_SPLIT
Definition: CoroInternal.h:40
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
FunctionPass * createCFGSimplificationPass(int Threshold=-1, std::function< bool(const Function &)> Ftor=nullptr)
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition: IRBuilder.h:1176
void updateCallGraph(Function &Caller, ArrayRef< Function * > Funcs, CallGraph &CG, CallGraphSCC &SCC)
Definition: Coroutines.cpp:173
void initializeCoroSplitPass(PassRegistry &)
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1444
#define F(x, y, z)
Definition: MD5.cpp:55
static void replaceFallthroughCoroEnd(IntrinsicInst *End, ValueToValueMapTy &VMap)
Definition: CoroSplit.cpp:137
This represents the llvm.coro.alloc instruction.
Definition: CoroInstr.h:70
SmallVector< CoroSizeInst *, 2 > CoroSizes
Definition: CoroInternal.h:70
void add(Pass *P) override
Add a pass to the queue of passes to run.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:428
CoroSaveInst * getCoroSave() const
Definition: CoroInstr.h:270
static void simplifySuspendPoints(coro::Shape &Shape)
Definition: CoroSplit.cpp:486
SmallVector< CoroSuspendInst *, 4 > CoroSuspends
Definition: CoroInternal.h:71
iterator begin()
Definition: Function.h:580
int Switch(int a)
Definition: Switch2Test.cpp:11
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Definition: IRBuilder.h:128
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
LoadInst * CreateLoad(Value *Ptr, const char *Name)
Definition: IRBuilder.h:1164
This represents the llvm.coro.size instruction.
Definition: CoroInstr.h:291
static void postSplitCleanup(Function &F)
Definition: CoroSplit.cpp:388
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1306
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
#define CORO_PRESPLIT_ATTR
Definition: CoroInternal.h:38
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:859
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:888
#define A
Definition: LargeTest.cpp:12
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:372
static void prepareForSplit(Function &F, CallGraph &CG)
Definition: CoroSplit.cpp:626
Represent the analysis usage information of a pass.
This represents the llvm.coro.end instruction.
Definition: CoroInstr.h:303
static const unsigned End
Value * getMem() const
Definition: CoroInstr.h:221
op_range operands()
Definition: User.h:222
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:101
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1546
CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
static void replaceUnwindCoroEnds(coro::Shape &Shape, ValueToValueMapTy &VMap)
Definition: CoroSplit.cpp:150
FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
static Function * createClone(Function &F, Twine Suffix, coro::Shape &Shape, BasicBlock *ResumeEntry, int8_t FnIndex)
Definition: CoroSplit.cpp:209
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1320
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:386
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
static SmallPtrSet< BasicBlock *, 4 > getCoroBeginPredBlocks(CoroBeginInst *CB)
Definition: CoroSplit.cpp:504
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:1492
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:423
StructType * FrameTy
Definition: CoroInternal.h:82
#define E
Definition: LargeTest.cpp:27
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
InstrTy * getInstruction() const
Definition: CallSite.h:89
#define B
Definition: LargeTest.cpp:24
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:405
iterator end()
Definition: BasicBlock.h:254
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function's entry.
Definition: Local.cpp:1669
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:383
bool isFinal() const
Definition: CoroInstr.h:277
const size_t N
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:382
void buildCoroutineFrame(Function &F, Shape &Shape)
Definition: CoroFrame.cpp:784
#define UNPREPARED_FOR_SPLIT
Definition: CoroInternal.h:39
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:560
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
Definition: CFG.h:110
const BasicBlock & getEntryBlock() const
Definition: Function.h:564
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:516
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
This class represents the llvm.coro.begin instruction.
Definition: CoroInstr.h:215
Value * makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt)
Definition: Coroutines.cpp:87
iterator begin() const
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition: IRBuilder.h:338
static void updateCoroFrame(coro::Shape &Shape, Function *ResumeFn, Function *DestroyFn, Function *CleanupFn)
Definition: CoroSplit.cpp:364
static BasicBlock * createResumeEntryBlock(Function &F, coro::Shape &Shape)
Definition: CoroSplit.cpp:40
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
ConstantInt * getFalse()
Get the constant value for i1 false.
Definition: IRBuilder.h:293
SwitchInst * CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases=10, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a switch instruction with the specified value, default dest, and with a hint for the number of...
Definition: IRBuilder.h:798
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:361
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:70
SwitchInst * ResumeSwitch
Definition: CoroInternal.h:85
#define C
Definition: LargeTest.cpp:25
static void handleFinalSuspend(IRBuilder<> &Builder, Value *FramePtr, coro::Shape &Shape, SwitchInst *Switch, bool IsDestroy)
Definition: CoroSplit.cpp:184
#define I(x, y, z)
Definition: MD5.cpp:58
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
Definition: IRBuilder.h:1307
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:568
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:43
#define CORO_DEVIRT_TRIGGER_FN
Definition: CoroInternal.h:42
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
Definition: Constants.cpp:1035
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:382
bool isUnwind() const
Definition: CoroInstr.h:308
void replaceCoroFree(CoroIdInst *CoroId, bool Elide)
Definition: Coroutines.cpp:132
Multiway switch.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:195
virtual bool runOnSCC(CallGraphSCC &SCC)=0
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< CoroEndInst *, 4 > CoroEnds
Definition: CoroInternal.h:69
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
LLVM Value Representation.
Definition: Value.h:73
void setInfo(Constant *C)
Definition: CoroInstr.h:164
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
CallGraphNode * getOrInsertFunction(const Function *F)
Similar to operator[], but this will insert a new CallGraphNode for F if one does not already exist...
Definition: CallGraph.cpp:142
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Definition: Instruction.cpp:88
static const unsigned FramePtr
bool declaresIntrinsics(Module &M, std::initializer_list< StringRef >)
Definition: Coroutines.cpp:118
#define DEBUG(X)
Definition: Debug.h:118
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:203
FunctionPass * createEarlyCSEPass(bool UseMemorySSA=false)
Definition: EarlyCSE.cpp:1086
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:298
static void removeCoroEnds(coro::Shape &Shape)
Definition: CoroSplit.cpp:302
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:128
CoroAllocInst * getCoroAlloc()
Definition: CoroInstr.h:86
BasicBlock * AllocaSpillBlock
Definition: CoroInternal.h:84
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.cpp:120
static volatile int * Null
static SmallPtrSet< Instruction *, 8 > getNotRelocatableInstructions(CoroBeginInst *CoroBegin, SmallPtrSetImpl< BasicBlock * > &RelocBlocks)
Definition: CoroSplit.cpp:522
const BasicBlock * getParent() const
Definition: Instruction.h:66
iterator_range< arg_iterator > args()
Definition: Function.h:613
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
CallGraphNode * getCallsExternalNode() const
Definition: CallGraph.h:135