LLVM  8.0.0svn
CoroFrame.cpp
Go to the documentation of this file.
1 //===- CoroFrame.cpp - Builds and manipulates coroutine frame -------------===//
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 file contains classes used to discover if for a particular value
10 // there from sue to definition that crosses a suspend block.
11 //
12 // Using the information discovered we form a Coroutine Frame structure to
13 // contain those values. All uses of those values are replaced with appropriate
14 // GEP + load from the coroutine frame. At the point of the definition we spill
15 // the value into the coroutine frame.
16 //
17 // TODO: pack values tightly using liveness info.
18 //===----------------------------------------------------------------------===//
19 
20 #include "CoroInternal.h"
21 #include "llvm/ADT/BitVector.h"
23 #include "llvm/Config/llvm-config.h"
24 #include "llvm/IR/CFG.h"
25 #include "llvm/IR/Dominators.h"
26 #include "llvm/IR/IRBuilder.h"
27 #include "llvm/IR/InstIterator.h"
28 #include "llvm/Support/Debug.h"
32 
33 using namespace llvm;
34 
35 // The "coro-suspend-crossing" flag is very noisy. There is another debug type,
36 // "coro-frame", which results in leaner debug spew.
37 #define DEBUG_TYPE "coro-suspend-crossing"
38 
39 enum { SmallVectorThreshold = 32 };
40 
41 // Provides two way mapping between the blocks and numbers.
42 namespace {
43 class BlockToIndexMapping {
45 
46 public:
47  size_t size() const { return V.size(); }
48 
49  BlockToIndexMapping(Function &F) {
50  for (BasicBlock &BB : F)
51  V.push_back(&BB);
52  llvm::sort(V.begin(), V.end());
53  }
54 
55  size_t blockToIndex(BasicBlock *BB) const {
56  auto *I = std::lower_bound(V.begin(), V.end(), BB);
57  assert(I != V.end() && *I == BB && "BasicBlockNumberng: Unknown block");
58  return I - V.begin();
59  }
60 
61  BasicBlock *indexToBlock(unsigned Index) const { return V[Index]; }
62 };
63 } // end anonymous namespace
64 
65 // The SuspendCrossingInfo maintains data that allows to answer a question
66 // whether given two BasicBlocks A and B there is a path from A to B that
67 // passes through a suspend point.
68 //
69 // For every basic block 'i' it maintains a BlockData that consists of:
70 // Consumes: a bit vector which contains a set of indices of blocks that can
71 // reach block 'i'
72 // Kills: a bit vector which contains a set of indices of blocks that can
73 // reach block 'i', but one of the path will cross a suspend point
74 // Suspend: a boolean indicating whether block 'i' contains a suspend point.
75 // End: a boolean indicating whether block 'i' contains a coro.end intrinsic.
76 //
77 namespace {
78 struct SuspendCrossingInfo {
79  BlockToIndexMapping Mapping;
80 
81  struct BlockData {
82  BitVector Consumes;
83  BitVector Kills;
84  bool Suspend = false;
85  bool End = false;
86  };
88 
89  iterator_range<succ_iterator> successors(BlockData const &BD) const {
90  BasicBlock *BB = Mapping.indexToBlock(&BD - &Block[0]);
91  return llvm::successors(BB);
92  }
93 
94  BlockData &getBlockData(BasicBlock *BB) {
95  return Block[Mapping.blockToIndex(BB)];
96  }
97 
98  void dump() const;
99  void dump(StringRef Label, BitVector const &BV) const;
100 
101  SuspendCrossingInfo(Function &F, coro::Shape &Shape);
102 
103  bool hasPathCrossingSuspendPoint(BasicBlock *DefBB, BasicBlock *UseBB) const {
104  size_t const DefIndex = Mapping.blockToIndex(DefBB);
105  size_t const UseIndex = Mapping.blockToIndex(UseBB);
106 
107  assert(Block[UseIndex].Consumes[DefIndex] && "use must consume def");
108  bool const Result = Block[UseIndex].Kills[DefIndex];
109  LLVM_DEBUG(dbgs() << UseBB->getName() << " => " << DefBB->getName()
110  << " answer is " << Result << "\n");
111  return Result;
112  }
113 
114  bool isDefinitionAcrossSuspend(BasicBlock *DefBB, User *U) const {
115  auto *I = cast<Instruction>(U);
116 
117  // We rewrote PHINodes, so that only the ones with exactly one incoming
118  // value need to be analyzed.
119  if (auto *PN = dyn_cast<PHINode>(I))
120  if (PN->getNumIncomingValues() > 1)
121  return false;
122 
123  BasicBlock *UseBB = I->getParent();
124  return hasPathCrossingSuspendPoint(DefBB, UseBB);
125  }
126 
127  bool isDefinitionAcrossSuspend(Argument &A, User *U) const {
128  return isDefinitionAcrossSuspend(&A.getParent()->getEntryBlock(), U);
129  }
130 
131  bool isDefinitionAcrossSuspend(Instruction &I, User *U) const {
132  return isDefinitionAcrossSuspend(I.getParent(), U);
133  }
134 };
135 } // end anonymous namespace
136 
137 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
139  BitVector const &BV) const {
140  dbgs() << Label << ":";
141  for (size_t I = 0, N = BV.size(); I < N; ++I)
142  if (BV[I])
143  dbgs() << " " << Mapping.indexToBlock(I)->getName();
144  dbgs() << "\n";
145 }
146 
148  for (size_t I = 0, N = Block.size(); I < N; ++I) {
149  BasicBlock *const B = Mapping.indexToBlock(I);
150  dbgs() << B->getName() << ":\n";
151  dump(" Consumes", Block[I].Consumes);
152  dump(" Kills", Block[I].Kills);
153  }
154  dbgs() << "\n";
155 }
156 #endif
157 
158 SuspendCrossingInfo::SuspendCrossingInfo(Function &F, coro::Shape &Shape)
159  : Mapping(F) {
160  const size_t N = Mapping.size();
161  Block.resize(N);
162 
163  // Initialize every block so that it consumes itself
164  for (size_t I = 0; I < N; ++I) {
165  auto &B = Block[I];
166  B.Consumes.resize(N);
167  B.Kills.resize(N);
168  B.Consumes.set(I);
169  }
170 
171  // Mark all CoroEnd Blocks. We do not propagate Kills beyond coro.ends as
172  // the code beyond coro.end is reachable during initial invocation of the
173  // coroutine.
174  for (auto *CE : Shape.CoroEnds)
175  getBlockData(CE->getParent()).End = true;
176 
177  // Mark all suspend blocks and indicate that they kill everything they
178  // consume. Note, that crossing coro.save also requires a spill, as any code
179  // between coro.save and coro.suspend may resume the coroutine and all of the
180  // state needs to be saved by that time.
181  auto markSuspendBlock = [&](IntrinsicInst *BarrierInst) {
182  BasicBlock *SuspendBlock = BarrierInst->getParent();
183  auto &B = getBlockData(SuspendBlock);
184  B.Suspend = true;
185  B.Kills |= B.Consumes;
186  };
187  for (CoroSuspendInst *CSI : Shape.CoroSuspends) {
188  markSuspendBlock(CSI);
189  markSuspendBlock(CSI->getCoroSave());
190  }
191 
192  // Iterate propagating consumes and kills until they stop changing.
193  int Iteration = 0;
194  (void)Iteration;
195 
196  bool Changed;
197  do {
198  LLVM_DEBUG(dbgs() << "iteration " << ++Iteration);
199  LLVM_DEBUG(dbgs() << "==============\n");
200 
201  Changed = false;
202  for (size_t I = 0; I < N; ++I) {
203  auto &B = Block[I];
204  for (BasicBlock *SI : successors(B)) {
205 
206  auto SuccNo = Mapping.blockToIndex(SI);
207 
208  // Saved Consumes and Kills bitsets so that it is easy to see
209  // if anything changed after propagation.
210  auto &S = Block[SuccNo];
211  auto SavedConsumes = S.Consumes;
212  auto SavedKills = S.Kills;
213 
214  // Propagate Kills and Consumes from block B into its successor S.
215  S.Consumes |= B.Consumes;
216  S.Kills |= B.Kills;
217 
218  // If block B is a suspend block, it should propagate kills into the
219  // its successor for every block B consumes.
220  if (B.Suspend) {
221  S.Kills |= B.Consumes;
222  }
223  if (S.Suspend) {
224  // If block S is a suspend block, it should kill all of the blocks it
225  // consumes.
226  S.Kills |= S.Consumes;
227  } else if (S.End) {
228  // If block S is an end block, it should not propagate kills as the
229  // blocks following coro.end() are reached during initial invocation
230  // of the coroutine while all the data are still available on the
231  // stack or in the registers.
232  S.Kills.reset();
233  } else {
234  // This is reached when S block it not Suspend nor coro.end and it
235  // need to make sure that it is not in the kill set.
236  S.Kills.reset(SuccNo);
237  }
238 
239  // See if anything changed.
240  Changed |= (S.Kills != SavedKills) || (S.Consumes != SavedConsumes);
241 
242  if (S.Kills != SavedKills) {
243  LLVM_DEBUG(dbgs() << "\nblock " << I << " follower " << SI->getName()
244  << "\n");
245  LLVM_DEBUG(dump("S.Kills", S.Kills));
246  LLVM_DEBUG(dump("SavedKills", SavedKills));
247  }
248  if (S.Consumes != SavedConsumes) {
249  LLVM_DEBUG(dbgs() << "\nblock " << I << " follower " << SI << "\n");
250  LLVM_DEBUG(dump("S.Consume", S.Consumes));
251  LLVM_DEBUG(dump("SavedCons", SavedConsumes));
252  }
253  }
254  }
255  } while (Changed);
256  LLVM_DEBUG(dump());
257 }
258 
259 #undef DEBUG_TYPE // "coro-suspend-crossing"
260 #define DEBUG_TYPE "coro-frame"
261 
262 // We build up the list of spills for every case where a use is separated
263 // from the definition by a suspend point.
264 
265 namespace {
266 class Spill {
267  Value *Def = nullptr;
268  Instruction *User = nullptr;
269  unsigned FieldNo = 0;
270 
271 public:
272  Spill(Value *Def, llvm::User *U) : Def(Def), User(cast<Instruction>(U)) {}
273 
274  Value *def() const { return Def; }
275  Instruction *user() const { return User; }
276  BasicBlock *userBlock() const { return User->getParent(); }
277 
278  // Note that field index is stored in the first SpillEntry for a particular
279  // definition. Subsequent mentions of a defintion do not have fieldNo
280  // assigned. This works out fine as the users of Spills capture the info about
281  // the definition the first time they encounter it. Consider refactoring
282  // SpillInfo into two arrays to normalize the spill representation.
283  unsigned fieldIndex() const {
284  assert(FieldNo && "Accessing unassigned field");
285  return FieldNo;
286  }
287  void setFieldIndex(unsigned FieldNumber) {
288  assert(!FieldNo && "Reassigning field number");
289  FieldNo = FieldNumber;
290  }
291 };
292 } // namespace
293 
294 // Note that there may be more than one record with the same value of Def in
295 // the SpillInfo vector.
297 
298 #ifndef NDEBUG
299 static void dump(StringRef Title, SpillInfo const &Spills) {
300  dbgs() << "------------- " << Title << "--------------\n";
301  Value *CurrentValue = nullptr;
302  for (auto const &E : Spills) {
303  if (CurrentValue != E.def()) {
304  CurrentValue = E.def();
305  CurrentValue->dump();
306  }
307  dbgs() << " user: ";
308  E.user()->dump();
309  }
310 }
311 #endif
312 
313 namespace {
314 // We cannot rely solely on natural alignment of a type when building a
315 // coroutine frame and if the alignment specified on the Alloca instruction
316 // differs from the natural alignment of the alloca type we will need to insert
317 // padding.
318 struct PaddingCalculator {
319  const DataLayout &DL;
321  unsigned StructSize = 0;
322 
323  PaddingCalculator(LLVMContext &Context, DataLayout const &DL)
324  : DL(DL), Context(Context) {}
325 
326  // Replicate the logic from IR/DataLayout.cpp to match field offset
327  // computation for LLVM structs.
328  void addType(Type *Ty) {
329  unsigned TyAlign = DL.getABITypeAlignment(Ty);
330  if ((StructSize & (TyAlign - 1)) != 0)
331  StructSize = alignTo(StructSize, TyAlign);
332 
333  StructSize += DL.getTypeAllocSize(Ty); // Consume space for this data item.
334  }
335 
336  void addTypes(SmallVectorImpl<Type *> const &Types) {
337  for (auto *Ty : Types)
338  addType(Ty);
339  }
340 
341  unsigned computePadding(Type *Ty, unsigned ForcedAlignment) {
342  unsigned TyAlign = DL.getABITypeAlignment(Ty);
343  auto Natural = alignTo(StructSize, TyAlign);
344  auto Forced = alignTo(StructSize, ForcedAlignment);
345 
346  // Return how many bytes of padding we need to insert.
347  if (Natural != Forced)
348  return std::max(Natural, Forced) - StructSize;
349 
350  // Rely on natural alignment.
351  return 0;
352  }
353 
354  // If padding required, return the padding field type to insert.
355  ArrayType *getPaddingType(Type *Ty, unsigned ForcedAlignment) {
356  if (auto Padding = computePadding(Ty, ForcedAlignment))
357  return ArrayType::get(Type::getInt8Ty(Context), Padding);
358 
359  return nullptr;
360  }
361 };
362 } // namespace
363 
364 // Build a struct that will keep state for an active coroutine.
365 // struct f.frame {
366 // ResumeFnTy ResumeFnAddr;
367 // ResumeFnTy DestroyFnAddr;
368 // int ResumeIndex;
369 // ... promise (if present) ...
370 // ... spills ...
371 // };
373  SpillInfo &Spills) {
374  LLVMContext &C = F.getContext();
375  const DataLayout &DL = F.getParent()->getDataLayout();
376  PaddingCalculator Padder(C, DL);
378  Name.append(".Frame");
379  StructType *FrameTy = StructType::create(C, Name);
380  auto *FramePtrTy = FrameTy->getPointerTo();
381  auto *FnTy = FunctionType::get(Type::getVoidTy(C), FramePtrTy,
382  /*IsVarArgs=*/false);
383  auto *FnPtrTy = FnTy->getPointerTo();
384 
385  // Figure out how wide should be an integer type storing the suspend index.
386  unsigned IndexBits = std::max(1U, Log2_64_Ceil(Shape.CoroSuspends.size()));
387  Type *PromiseType = Shape.PromiseAlloca
388  ? Shape.PromiseAlloca->getType()->getElementType()
389  : Type::getInt1Ty(C);
390  SmallVector<Type *, 8> Types{FnPtrTy, FnPtrTy, PromiseType,
391  Type::getIntNTy(C, IndexBits)};
392  Value *CurrentDef = nullptr;
393 
394  Padder.addTypes(Types);
395 
396  // Create an entry for every spilled value.
397  for (auto &S : Spills) {
398  if (CurrentDef == S.def())
399  continue;
400 
401  CurrentDef = S.def();
402  // PromiseAlloca was already added to Types array earlier.
403  if (CurrentDef == Shape.PromiseAlloca)
404  continue;
405 
406  Type *Ty = nullptr;
407  if (auto *AI = dyn_cast<AllocaInst>(CurrentDef)) {
408  Ty = AI->getAllocatedType();
409  if (unsigned AllocaAlignment = AI->getAlignment()) {
410  // If alignment is specified in alloca, see if we need to insert extra
411  // padding.
412  if (auto PaddingTy = Padder.getPaddingType(Ty, AllocaAlignment)) {
413  Types.push_back(PaddingTy);
414  Padder.addType(PaddingTy);
415  }
416  }
417  } else {
418  Ty = CurrentDef->getType();
419  }
420  S.setFieldIndex(Types.size());
421  Types.push_back(Ty);
422  Padder.addType(Ty);
423  }
424  FrameTy->setBody(Types);
425 
426  return FrameTy;
427 }
428 
429 // We need to make room to insert a spill after initial PHIs, but before
430 // catchswitch instruction. Placing it before violates the requirement that
431 // catchswitch, like all other EHPads must be the first nonPHI in a block.
432 //
433 // Split away catchswitch into a separate block and insert in its place:
434 //
435 // cleanuppad <InsertPt> cleanupret.
436 //
437 // cleanupret instruction will act as an insert point for the spill.
439  BasicBlock *CurrentBlock = CatchSwitch->getParent();
440  BasicBlock *NewBlock = CurrentBlock->splitBasicBlock(CatchSwitch);
441  CurrentBlock->getTerminator()->eraseFromParent();
442 
443  auto *CleanupPad =
444  CleanupPadInst::Create(CatchSwitch->getParentPad(), {}, "", CurrentBlock);
445  auto *CleanupRet =
446  CleanupReturnInst::Create(CleanupPad, NewBlock, CurrentBlock);
447  return CleanupRet;
448 }
449 
450 // Replace all alloca and SSA values that are accessed across suspend points
451 // with GetElementPointer from coroutine frame + loads and stores. Create an
452 // AllocaSpillBB that will become the new entry block for the resume parts of
453 // the coroutine:
454 //
455 // %hdl = coro.begin(...)
456 // whatever
457 //
458 // becomes:
459 //
460 // %hdl = coro.begin(...)
461 // %FramePtr = bitcast i8* hdl to %f.frame*
462 // br label %AllocaSpillBB
463 //
464 // AllocaSpillBB:
465 // ; geps corresponding to allocas that were moved to coroutine frame
466 // br label PostSpill
467 //
468 // PostSpill:
469 // whatever
470 //
471 //
472 static Instruction *insertSpills(SpillInfo &Spills, coro::Shape &Shape) {
473  auto *CB = Shape.CoroBegin;
474  IRBuilder<> Builder(CB->getNextNode());
475  PointerType *FramePtrTy = Shape.FrameTy->getPointerTo();
476  auto *FramePtr =
477  cast<Instruction>(Builder.CreateBitCast(CB, FramePtrTy, "FramePtr"));
478  Type *FrameTy = FramePtrTy->getElementType();
479 
480  Value *CurrentValue = nullptr;
481  BasicBlock *CurrentBlock = nullptr;
482  Value *CurrentReload = nullptr;
483  unsigned Index = 0; // Proper field number will be read from field definition.
484 
485  // We need to keep track of any allocas that need "spilling"
486  // since they will live in the coroutine frame now, all access to them
487  // need to be changed, not just the access across suspend points
488  // we remember allocas and their indices to be handled once we processed
489  // all the spills.
491  // Promise alloca (if present) has a fixed field number (Shape::PromiseField)
492  if (Shape.PromiseAlloca)
494 
495  // Create a load instruction to reload the spilled value from the coroutine
496  // frame.
497  auto CreateReload = [&](Instruction *InsertBefore) {
498  assert(Index && "accessing unassigned field number");
499  Builder.SetInsertPoint(InsertBefore);
500  auto *G = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, Index,
501  CurrentValue->getName() +
502  Twine(".reload.addr"));
503  return isa<AllocaInst>(CurrentValue)
504  ? G
505  : Builder.CreateLoad(G,
506  CurrentValue->getName() + Twine(".reload"));
507  };
508 
509  for (auto const &E : Spills) {
510  // If we have not seen the value, generate a spill.
511  if (CurrentValue != E.def()) {
512  CurrentValue = E.def();
513  CurrentBlock = nullptr;
514  CurrentReload = nullptr;
515 
516  Index = E.fieldIndex();
517 
518  if (auto *AI = dyn_cast<AllocaInst>(CurrentValue)) {
519  // Spilled AllocaInst will be replaced with GEP from the coroutine frame
520  // there is no spill required.
521  Allocas.emplace_back(AI, Index);
522  if (!AI->isStaticAlloca())
523  report_fatal_error("Coroutines cannot handle non static allocas yet");
524  } else {
525  // Otherwise, create a store instruction storing the value into the
526  // coroutine frame.
527 
528  Instruction *InsertPt = nullptr;
529  if (isa<Argument>(CurrentValue)) {
530  // For arguments, we will place the store instruction right after
531  // the coroutine frame pointer instruction, i.e. bitcast of
532  // coro.begin from i8* to %f.frame*.
533  InsertPt = FramePtr->getNextNode();
534  } else if (auto *II = dyn_cast<InvokeInst>(CurrentValue)) {
535  // If we are spilling the result of the invoke instruction, split the
536  // normal edge and insert the spill in the new block.
537  auto NewBB = SplitEdge(II->getParent(), II->getNormalDest());
538  InsertPt = NewBB->getTerminator();
539  } else if (dyn_cast<PHINode>(CurrentValue)) {
540  // Skip the PHINodes and EH pads instructions.
541  BasicBlock *DefBlock = cast<Instruction>(E.def())->getParent();
542  if (auto *CSI = dyn_cast<CatchSwitchInst>(DefBlock->getTerminator()))
543  InsertPt = splitBeforeCatchSwitch(CSI);
544  else
545  InsertPt = &*DefBlock->getFirstInsertionPt();
546  } else {
547  // For all other values, the spill is placed immediately after
548  // the definition.
549  assert(!cast<Instruction>(E.def())->isTerminator() &&
550  "unexpected terminator");
551  InsertPt = cast<Instruction>(E.def())->getNextNode();
552  }
553 
554  Builder.SetInsertPoint(InsertPt);
555  auto *G = Builder.CreateConstInBoundsGEP2_32(
556  FrameTy, FramePtr, 0, Index,
557  CurrentValue->getName() + Twine(".spill.addr"));
558  Builder.CreateStore(CurrentValue, G);
559  }
560  }
561 
562  // If we have not seen the use block, generate a reload in it.
563  if (CurrentBlock != E.userBlock()) {
564  CurrentBlock = E.userBlock();
565  CurrentReload = CreateReload(&*CurrentBlock->getFirstInsertionPt());
566  }
567 
568  // If we have a single edge PHINode, remove it and replace it with a reload
569  // from the coroutine frame. (We already took care of multi edge PHINodes
570  // by rewriting them in the rewritePHIs function).
571  if (auto *PN = dyn_cast<PHINode>(E.user())) {
572  assert(PN->getNumIncomingValues() == 1 && "unexpected number of incoming "
573  "values in the PHINode");
574  PN->replaceAllUsesWith(CurrentReload);
575  PN->eraseFromParent();
576  continue;
577  }
578 
579  // Replace all uses of CurrentValue in the current instruction with reload.
580  E.user()->replaceUsesOfWith(CurrentValue, CurrentReload);
581  }
582 
583  BasicBlock *FramePtrBB = FramePtr->getParent();
584  Shape.AllocaSpillBlock =
585  FramePtrBB->splitBasicBlock(FramePtr->getNextNode(), "AllocaSpillBB");
587  "PostSpill");
588 
589  Builder.SetInsertPoint(&Shape.AllocaSpillBlock->front());
590  // If we found any allocas, replace all of their remaining uses with Geps.
591  for (auto &P : Allocas) {
592  auto *G =
593  Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, P.second);
594  // We are not using ReplaceInstWithInst(P.first, cast<Instruction>(G)) here,
595  // as we are changing location of the instruction.
596  G->takeName(P.first);
597  P.first->replaceAllUsesWith(G);
598  P.first->eraseFromParent();
599  }
600  return FramePtr;
601 }
602 
603 // Sets the unwind edge of an instruction to a particular successor.
604 static void setUnwindEdgeTo(TerminatorInst *TI, BasicBlock *Succ) {
605  if (auto *II = dyn_cast<InvokeInst>(TI))
606  II->setUnwindDest(Succ);
607  else if (auto *CS = dyn_cast<CatchSwitchInst>(TI))
608  CS->setUnwindDest(Succ);
609  else if (auto *CR = dyn_cast<CleanupReturnInst>(TI))
610  CR->setUnwindDest(Succ);
611  else
612  llvm_unreachable("unexpected terminator instruction");
613 }
614 
615 // Replaces all uses of OldPred with the NewPred block in all PHINodes in a
616 // block.
617 static void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred,
618  BasicBlock *NewPred,
619  PHINode *LandingPadReplacement) {
620  unsigned BBIdx = 0;
621  for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
622  PHINode *PN = cast<PHINode>(I);
623 
624  // We manually update the LandingPadReplacement PHINode and it is the last
625  // PHI Node. So, if we find it, we are done.
626  if (LandingPadReplacement == PN)
627  break;
628 
629  // Reuse the previous value of BBIdx if it lines up. In cases where we
630  // have multiple phi nodes with *lots* of predecessors, this is a speed
631  // win because we don't have to scan the PHI looking for TIBB. This
632  // happens because the BB list of PHI nodes are usually in the same
633  // order.
634  if (PN->getIncomingBlock(BBIdx) != OldPred)
635  BBIdx = PN->getBasicBlockIndex(OldPred);
636 
637  assert(BBIdx != (unsigned)-1 && "Invalid PHI Index!");
638  PN->setIncomingBlock(BBIdx, NewPred);
639  }
640 }
641 
642 // Uses SplitEdge unless the successor block is an EHPad, in which case do EH
643 // specific handling.
645  LandingPadInst *OriginalPad,
646  PHINode *LandingPadReplacement) {
647  auto *PadInst = Succ->getFirstNonPHI();
648  if (!LandingPadReplacement && !PadInst->isEHPad())
649  return SplitEdge(BB, Succ);
650 
651  auto *NewBB = BasicBlock::Create(BB->getContext(), "", BB->getParent(), Succ);
652  setUnwindEdgeTo(BB->getTerminator(), NewBB);
653  updatePhiNodes(Succ, BB, NewBB, LandingPadReplacement);
654 
655  if (LandingPadReplacement) {
656  auto *NewLP = OriginalPad->clone();
657  auto *Terminator = BranchInst::Create(Succ, NewBB);
658  NewLP->insertBefore(Terminator);
659  LandingPadReplacement->addIncoming(NewLP, NewBB);
660  return NewBB;
661  }
662  Value *ParentPad = nullptr;
663  if (auto *FuncletPad = dyn_cast<FuncletPadInst>(PadInst))
664  ParentPad = FuncletPad->getParentPad();
665  else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(PadInst))
666  ParentPad = CatchSwitch->getParentPad();
667  else
668  llvm_unreachable("handling for other EHPads not implemented yet");
669 
670  auto *NewCleanupPad = CleanupPadInst::Create(ParentPad, {}, "", NewBB);
671  CleanupReturnInst::Create(NewCleanupPad, Succ, NewBB);
672  return NewBB;
673 }
674 
675 static void rewritePHIs(BasicBlock &BB) {
676  // For every incoming edge we will create a block holding all
677  // incoming values in a single PHI nodes.
678  //
679  // loop:
680  // %n.val = phi i32[%n, %entry], [%inc, %loop]
681  //
682  // It will create:
683  //
684  // loop.from.entry:
685  // %n.loop.pre = phi i32 [%n, %entry]
686  // br %label loop
687  // loop.from.loop:
688  // %inc.loop.pre = phi i32 [%inc, %loop]
689  // br %label loop
690  //
691  // After this rewrite, further analysis will ignore any phi nodes with more
692  // than one incoming edge.
693 
694  // TODO: Simplify PHINodes in the basic block to remove duplicate
695  // predecessors.
696 
697  LandingPadInst *LandingPad = nullptr;
698  PHINode *ReplPHI = nullptr;
699  if ((LandingPad = dyn_cast_or_null<LandingPadInst>(BB.getFirstNonPHI()))) {
700  // ehAwareSplitEdge will clone the LandingPad in all the edge blocks.
701  // We replace the original landing pad with a PHINode that will collect the
702  // results from all of them.
703  ReplPHI = PHINode::Create(LandingPad->getType(), 1, "", LandingPad);
704  ReplPHI->takeName(LandingPad);
705  LandingPad->replaceAllUsesWith(ReplPHI);
706  // We will erase the original landing pad at the end of this function after
707  // ehAwareSplitEdge cloned it in the transition blocks.
708  }
709 
711  for (BasicBlock *Pred : Preds) {
712  auto *IncomingBB = ehAwareSplitEdge(Pred, &BB, LandingPad, ReplPHI);
713  IncomingBB->setName(BB.getName() + Twine(".from.") + Pred->getName());
714  auto *PN = cast<PHINode>(&BB.front());
715  do {
716  int Index = PN->getBasicBlockIndex(IncomingBB);
717  Value *V = PN->getIncomingValue(Index);
718  PHINode *InputV = PHINode::Create(
719  V->getType(), 1, V->getName() + Twine(".") + BB.getName(),
720  &IncomingBB->front());
721  InputV->addIncoming(V, Pred);
722  PN->setIncomingValue(Index, InputV);
723  PN = dyn_cast<PHINode>(PN->getNextNode());
724  } while (PN != ReplPHI); // ReplPHI is either null or the PHI that replaced
725  // the landing pad.
726  }
727 
728  if (LandingPad) {
729  // Calls to ehAwareSplitEdge function cloned the original lading pad.
730  // No longer need it.
731  LandingPad->eraseFromParent();
732  }
733 }
734 
735 static void rewritePHIs(Function &F) {
737 
738  for (BasicBlock &BB : F)
739  if (auto *PN = dyn_cast<PHINode>(&BB.front()))
740  if (PN->getNumIncomingValues() > 1)
741  WorkList.push_back(&BB);
742 
743  for (BasicBlock *BB : WorkList)
744  rewritePHIs(*BB);
745 }
746 
747 // Check for instructions that we can recreate on resume as opposed to spill
748 // the result into a coroutine frame.
749 static bool materializable(Instruction &V) {
750  return isa<CastInst>(&V) || isa<GetElementPtrInst>(&V) ||
751  isa<BinaryOperator>(&V) || isa<CmpInst>(&V) || isa<SelectInst>(&V);
752 }
753 
754 // Check for structural coroutine intrinsics that should not be spilled into
755 // the coroutine frame.
757  return isa<CoroIdInst>(&I) || isa<CoroSaveInst>(&I) ||
758  isa<CoroSuspendInst>(&I);
759 }
760 
761 // For every use of the value that is across suspend point, recreate that value
762 // after a suspend point.
764  SpillInfo const &Spills) {
765  BasicBlock *CurrentBlock = nullptr;
766  Instruction *CurrentMaterialization = nullptr;
767  Instruction *CurrentDef = nullptr;
768 
769  for (auto const &E : Spills) {
770  // If it is a new definition, update CurrentXXX variables.
771  if (CurrentDef != E.def()) {
772  CurrentDef = cast<Instruction>(E.def());
773  CurrentBlock = nullptr;
774  CurrentMaterialization = nullptr;
775  }
776 
777  // If we have not seen this block, materialize the value.
778  if (CurrentBlock != E.userBlock()) {
779  CurrentBlock = E.userBlock();
780  CurrentMaterialization = cast<Instruction>(CurrentDef)->clone();
781  CurrentMaterialization->setName(CurrentDef->getName());
782  CurrentMaterialization->insertBefore(
783  &*CurrentBlock->getFirstInsertionPt());
784  }
785 
786  if (auto *PN = dyn_cast<PHINode>(E.user())) {
787  assert(PN->getNumIncomingValues() == 1 && "unexpected number of incoming "
788  "values in the PHINode");
789  PN->replaceAllUsesWith(CurrentMaterialization);
790  PN->eraseFromParent();
791  continue;
792  }
793 
794  // Replace all uses of CurrentDef in the current instruction with the
795  // CurrentMaterialization for the block.
796  E.user()->replaceUsesOfWith(CurrentDef, CurrentMaterialization);
797  }
798 }
799 
800 // Move early uses of spilled variable after CoroBegin.
801 // For example, if a parameter had address taken, we may end up with the code
802 // like:
803 // define @f(i32 %n) {
804 // %n.addr = alloca i32
805 // store %n, %n.addr
806 // ...
807 // call @coro.begin
808 // we need to move the store after coro.begin
809 static void moveSpillUsesAfterCoroBegin(Function &F, SpillInfo const &Spills,
810  CoroBeginInst *CoroBegin) {
811  DominatorTree DT(F);
812  SmallVector<Instruction *, 8> NeedsMoving;
813 
814  Value *CurrentValue = nullptr;
815 
816  for (auto const &E : Spills) {
817  if (CurrentValue == E.def())
818  continue;
819 
820  CurrentValue = E.def();
821 
822  for (User *U : CurrentValue->users()) {
823  Instruction *I = cast<Instruction>(U);
824  if (!DT.dominates(CoroBegin, I)) {
825  LLVM_DEBUG(dbgs() << "will move: " << *I << "\n");
826 
827  // TODO: Make this more robust. Currently if we run into a situation
828  // where simple instruction move won't work we panic and
829  // report_fatal_error.
830  for (User *UI : I->users()) {
831  if (!DT.dominates(CoroBegin, cast<Instruction>(UI)))
832  report_fatal_error("cannot move instruction since its users are not"
833  " dominated by CoroBegin");
834  }
835 
836  NeedsMoving.push_back(I);
837  }
838  }
839  }
840 
841  Instruction *InsertPt = CoroBegin->getNextNode();
842  for (Instruction *I : NeedsMoving)
843  I->moveBefore(InsertPt);
844 }
845 
846 // Splits the block at a particular instruction unless it is the first
847 // instruction in the block with a single predecessor.
849  auto *BB = I->getParent();
850  if (&BB->front() == I) {
851  if (BB->getSinglePredecessor()) {
852  BB->setName(Name);
853  return BB;
854  }
855  }
856  return BB->splitBasicBlock(I, Name);
857 }
858 
859 // Split above and below a particular instruction so that it
860 // will be all alone by itself in a block.
861 static void splitAround(Instruction *I, const Twine &Name) {
862  splitBlockIfNotFirst(I, Name);
863  splitBlockIfNotFirst(I->getNextNode(), "After" + Name);
864 }
865 
866 void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
867  // Lower coro.dbg.declare to coro.dbg.value, since we are going to rewrite
868  // access to local variables.
869  LowerDbgDeclare(F);
870 
871  Shape.PromiseAlloca = Shape.CoroBegin->getId()->getPromise();
872  if (Shape.PromiseAlloca) {
873  Shape.CoroBegin->getId()->clearPromise();
874  }
875 
876  // Make sure that all coro.save, coro.suspend and the fallthrough coro.end
877  // intrinsics are in their own blocks to simplify the logic of building up
878  // SuspendCrossing data.
879  for (CoroSuspendInst *CSI : Shape.CoroSuspends) {
880  splitAround(CSI->getCoroSave(), "CoroSave");
881  splitAround(CSI, "CoroSuspend");
882  }
883 
884  // Put CoroEnds into their own blocks.
885  for (CoroEndInst *CE : Shape.CoroEnds)
886  splitAround(CE, "CoroEnd");
887 
888  // Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will
889  // never has its definition separated from the PHI by the suspend point.
890  rewritePHIs(F);
891 
892  // Build suspend crossing info.
893  SuspendCrossingInfo Checker(F, Shape);
894 
895  IRBuilder<> Builder(F.getContext());
896  SpillInfo Spills;
897 
898  for (int Repeat = 0; Repeat < 4; ++Repeat) {
899  // See if there are materializable instructions across suspend points.
900  for (Instruction &I : instructions(F))
901  if (materializable(I))
902  for (User *U : I.users())
903  if (Checker.isDefinitionAcrossSuspend(I, U))
904  Spills.emplace_back(&I, U);
905 
906  if (Spills.empty())
907  break;
908 
909  // Rewrite materializable instructions to be materialized at the use point.
910  LLVM_DEBUG(dump("Materializations", Spills));
911  rewriteMaterializableInstructions(Builder, Spills);
912  Spills.clear();
913  }
914 
915  // Collect the spills for arguments and other not-materializable values.
916  for (Argument &A : F.args())
917  for (User *U : A.users())
918  if (Checker.isDefinitionAcrossSuspend(A, U))
919  Spills.emplace_back(&A, U);
920 
921  for (Instruction &I : instructions(F)) {
922  // Values returned from coroutine structure intrinsics should not be part
923  // of the Coroutine Frame.
924  if (isCoroutineStructureIntrinsic(I) || &I == Shape.CoroBegin)
925  continue;
926  // The Coroutine Promise always included into coroutine frame, no need to
927  // check for suspend crossing.
928  if (Shape.PromiseAlloca == &I)
929  continue;
930 
931  for (User *U : I.users())
932  if (Checker.isDefinitionAcrossSuspend(I, U)) {
933  // We cannot spill a token.
934  if (I.getType()->isTokenTy())
936  "token definition is separated from the use by a suspend point");
937  Spills.emplace_back(&I, U);
938  }
939  }
940  LLVM_DEBUG(dump("Spills", Spills));
941  moveSpillUsesAfterCoroBegin(F, Spills, Shape.CoroBegin);
942  Shape.FrameTy = buildFrameType(F, Shape, Spills);
943  Shape.FramePtr = insertSpills(Spills, Shape);
944 }
uint64_t CallInst * C
static Instruction * splitBeforeCatchSwitch(CatchSwitchInst *CatchSwitch)
Definition: CoroFrame.cpp:438
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:68
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
Instruction * FramePtr
Definition: CoroInternal.h:82
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
LLVMContext & Context
CoroBeginInst * CoroBegin
Definition: CoroInternal.h:68
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *LandingPadReplacement)
Definition: CoroFrame.cpp:617
static void rewritePHIs(BasicBlock &BB)
Definition: CoroFrame.cpp:675
static void dump(StringRef Title, SpillInfo const &Spills)
Definition: CoroFrame.cpp:299
F(f)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:685
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:264
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Split the edge connecting specified block.
void dump() const
Support for debugging, callable in GDB: V->dump()
Definition: AsmWriter.cpp:4243
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:363
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
PointerType * getType() const
Overload to return most specific pointer type.
Definition: Instructions.h:97
Class to represent struct types.
Definition: DerivedTypes.h:201
static bool materializable(Instruction &V)
Definition: CoroFrame.cpp:749
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Definition: Type.cpp:639
This represents the llvm.coro.suspend instruction.
Definition: CoroInstr.h:266
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:731
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:295
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
AllocaInst * getPromise() const
Definition: CoroInstr.h:101
Instruction * clone() const
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
Class to represent array types.
Definition: DerivedTypes.h:369
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1138
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:439
Value * getParentPad() const
SmallVector< CoroSuspendInst *, 4 > CoroSuspends
Definition: CoroInternal.h:71
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Definition: Type.cpp:356
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:301
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
Class to represent pointers.
Definition: DerivedTypes.h:467
const BasicBlock & getEntryBlock() const
Definition: Function.h:640
#define P(N)
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:189
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Subclasses of this class are all able to terminate a basic block.
Definition: InstrTypes.h:55
static void moveSpillUsesAfterCoroBegin(Function &F, SpillInfo const &Spills, CoroBeginInst *CoroBegin)
Definition: CoroFrame.cpp:809
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:218
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:74
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
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:69
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
const Instruction & front() const
Definition: BasicBlock.h:276
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:113
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
This represents the llvm.coro.end instruction.
Definition: CoroInstr.h:303
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:297
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:116
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:101
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
size_t size() const
Definition: SmallVector.h:53
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
Definition: Local.cpp:1391
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isCoroutineStructureIntrinsic(Instruction &I)
Definition: CoroFrame.cpp:756
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:972
Iterator for intrusive lists based on ilist_node.
StructType * FrameTy
Definition: CoroInternal.h:81
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1023
void setIncomingBlock(unsigned i, BasicBlock *BB)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Definition: Dominators.cpp:249
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Definition: DataLayout.cpp:722
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:180
void buildCoroutineFrame(Function &F, Shape &Shape)
Definition: CoroFrame.cpp:866
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...
unsigned Log2_64_Ceil(uint64_t Value)
Return the ceil log base 2 of the specified value, 64 if the value is zero.
Definition: MathExtras.h:558
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
This class represents the llvm.coro.begin instruction.
Definition: CoroInstr.h:215
A range adaptor for a pair of iterators.
iterator_range< user_iterator > users()
Definition: Value.h:400
static BasicBlock * splitBlockIfNotFirst(Instruction *I, const Twine &Name)
Definition: CoroFrame.cpp:848
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:428
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
void clearPromise()
Definition: CoroInstr.h:108
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
static void rewriteMaterializableInstructions(IRBuilder<> &IRB, SpillInfo const &Spills)
Definition: CoroFrame.cpp:763
const Function * getParent() const
Definition: Argument.h:42
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:108
static Instruction * insertSpills(SpillInfo &Spills, coro::Shape &Shape)
Definition: CoroFrame.cpp:472
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:568
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
size_type size() const
size - Returns the number of bits in this bitvector.
Definition: BitVector.h:170
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:401
CoroIdInst * getId() const
Definition: CoroInstr.h:219
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< CoroEndInst *, 4 > CoroEnds
Definition: CoroInternal.h:69
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:142
AllocaInst * PromiseAlloca
Definition: CoroInternal.h:85
static BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad, PHINode *LandingPadReplacement)
Definition: CoroFrame.cpp:644
static StructType * buildFrameType(Function &F, coro::Shape &Shape, SpillInfo &Spills)
Definition: CoroFrame.cpp:372
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:566
LLVM Value Representation.
Definition: Value.h:73
succ_range successors(Instruction *I)
Definition: CFG.h:262
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:424
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static const Function * getParent(const Value *V)
static const unsigned FramePtr
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:569
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
inst_range instructions(Function *F)
Definition: InstIterator.h:134
BasicBlock * AllocaSpillBlock
Definition: CoroInternal.h:83
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:138
static void setUnwindEdgeTo(TerminatorInst *TI, BasicBlock *Succ)
Definition: CoroFrame.cpp:604
#define LLVM_DEBUG(X)
Definition: Debug.h:123
static void splitAround(Instruction *I, const Twine &Name)
Definition: CoroFrame.cpp:861
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:174
CoroSaveInst * getCoroSave() const
Definition: CoroInstr.h:270
Type * getElementType() const
Definition: DerivedTypes.h:486
iterator_range< arg_iterator > args()
Definition: Function.h:689
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
const BasicBlock * getParent() const
Definition: Instruction.h:67